2011-05-12 14:49:42 +02:00
# include "optionsdialog.h"
2011-05-31 22:24:53 +02:00
# include "optionsmodel.h"
2011-06-20 21:31:42 +02:00
# include "bitcoinamountfield.h"
2011-06-01 14:40:06 +02:00
# include "monitoreddatamapper.h"
2011-06-11 12:46:09 +02:00
# include "guiutil.h"
2011-07-29 14:36:35 +02:00
# include "bitcoinunits.h"
# include "qvaluecombobox.h"
2011-05-12 14:44:52 +02:00
# include <QHBoxLayout>
# include <QVBoxLayout>
# include <QPushButton>
2011-05-13 22:00:27 +02:00
# include <QListWidget>
# include <QStackedWidget>
2011-06-01 14:40:06 +02:00
# include <QCheckBox>
# include <QLabel>
# include <QLineEdit>
# include <QIntValidator>
# include <QDoubleValidator>
# include <QRegExpValidator>
2011-06-24 21:23:43 +02:00
# include <QDialogButtonBox>
2012-05-08 23:03:41 +02:00
# include <QDir>
# include <QMessageBox>
2011-06-01 14:40:06 +02:00
2012-05-07 21:49:22 +02:00
class OptionsPage : public QWidget
{
Q_OBJECT
public :
explicit OptionsPage ( QWidget * parent = 0 ) : QWidget ( parent ) { }
virtual void setMapper ( MonitoredDataMapper * mapper ) = 0 ;
} ;
class MainOptionsPage : public OptionsPage
2011-06-01 14:40:06 +02:00
{
2011-09-19 12:40:23 +02:00
Q_OBJECT
2011-06-01 14:40:06 +02:00
public :
explicit MainOptionsPage ( QWidget * parent = 0 ) ;
2012-05-07 21:49:22 +02:00
virtual void setMapper ( MonitoredDataMapper * mapper ) ;
private :
BitcoinAmountField * fee_edit ;
2012-05-10 15:33:01 +02:00
QCheckBox * bitcoin_at_startup ;
QCheckBox * detach_database ;
2012-05-07 21:49:22 +02:00
} ;
class WindowOptionsPage : public OptionsPage
{
Q_OBJECT
public :
explicit WindowOptionsPage ( QWidget * parent = 0 ) ;
virtual void setMapper ( MonitoredDataMapper * mapper ) ;
2011-06-01 14:40:06 +02:00
private :
2011-10-07 13:21:45 +02:00
# ifndef Q_WS_MAC
2011-06-01 14:40:06 +02:00
QCheckBox * minimize_to_tray ;
QCheckBox * minimize_on_close ;
2011-10-07 13:21:45 +02:00
# endif
2011-06-01 14:40:06 +02:00
} ;
2011-05-12 14:44:52 +02:00
2012-05-07 21:49:22 +02:00
class DisplayOptionsPage : public OptionsPage
2011-07-25 21:35:45 +02:00
{
2011-09-19 12:40:23 +02:00
Q_OBJECT
2011-07-25 21:35:45 +02:00
public :
explicit DisplayOptionsPage ( QWidget * parent = 0 ) ;
2012-05-07 21:49:22 +02:00
virtual void setMapper ( MonitoredDataMapper * mapper ) ;
2011-07-25 21:35:45 +02:00
private :
2012-05-08 23:03:41 +02:00
QValueComboBox * lang ;
2011-07-29 14:36:35 +02:00
QValueComboBox * unit ;
2011-07-30 17:42:02 +02:00
QCheckBox * display_addresses ;
2012-05-08 23:03:41 +02:00
bool restart_warning_displayed ;
private slots :
void showRestartWarning ( ) ;
2012-05-07 21:49:22 +02:00
} ;
2011-07-25 21:35:45 +02:00
2012-05-07 21:49:22 +02:00
class NetworkOptionsPage : public OptionsPage
{
Q_OBJECT
public :
explicit NetworkOptionsPage ( QWidget * parent = 0 ) ;
2011-07-25 21:35:45 +02:00
2012-05-07 21:49:22 +02:00
virtual void setMapper ( MonitoredDataMapper * mapper ) ;
private :
QCheckBox * map_port_upnp ;
QCheckBox * connect_socks4 ;
QLineEdit * proxy_ip ;
QLineEdit * proxy_port ;
2011-07-25 21:35:45 +02:00
} ;
2012-05-07 21:49:22 +02:00
2011-09-19 12:40:23 +02:00
# include "optionsdialog.moc"
2011-05-31 22:24:53 +02:00
OptionsDialog : : OptionsDialog ( QWidget * parent ) :
QDialog ( parent ) , contents_widget ( 0 ) , pages_widget ( 0 ) ,
2012-05-07 21:49:22 +02:00
model ( 0 )
2011-05-12 14:44:52 +02:00
{
contents_widget = new QListWidget ( ) ;
contents_widget - > setMaximumWidth ( 128 ) ;
pages_widget = new QStackedWidget ( ) ;
2012-05-07 21:49:22 +02:00
pages_widget - > setMinimumWidth ( 500 ) ;
pages_widget - > setMinimumHeight ( 300 ) ;
2011-05-12 14:44:52 +02:00
2012-05-07 21:49:22 +02:00
pages . append ( new MainOptionsPage ( this ) ) ;
pages . append ( new NetworkOptionsPage ( this ) ) ;
2012-05-10 15:33:01 +02:00
# ifndef Q_WS_MAC
/* Hide Window options on Mac as there are currently none available */
2012-05-07 21:49:22 +02:00
pages . append ( new WindowOptionsPage ( this ) ) ;
2012-05-10 15:33:01 +02:00
# endif
2012-05-07 21:49:22 +02:00
pages . append ( new DisplayOptionsPage ( this ) ) ;
2011-07-25 21:35:45 +02:00
2012-05-07 21:49:22 +02:00
foreach ( OptionsPage * page , pages )
{
QListWidgetItem * item = new QListWidgetItem ( page - > windowTitle ( ) ) ;
contents_widget - > addItem ( item ) ;
pages_widget - > addWidget ( page ) ;
}
2011-05-12 14:44:52 +02:00
contents_widget - > setCurrentRow ( 0 ) ;
QHBoxLayout * main_layout = new QHBoxLayout ( ) ;
main_layout - > addWidget ( contents_widget ) ;
main_layout - > addWidget ( pages_widget , 1 ) ;
QVBoxLayout * layout = new QVBoxLayout ( ) ;
layout - > addLayout ( main_layout ) ;
2011-06-24 21:23:43 +02:00
QDialogButtonBox * buttonbox = new QDialogButtonBox ( ) ;
buttonbox - > setStandardButtons ( QDialogButtonBox : : Apply | QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ;
apply_button = buttonbox - > button ( QDialogButtonBox : : Apply ) ;
layout - > addWidget ( buttonbox ) ;
2011-05-12 14:44:52 +02:00
setLayout ( layout ) ;
setWindowTitle ( tr ( " Options " ) ) ;
2011-06-01 09:33:48 +02:00
/* Widget-to-option mapper */
2011-06-01 14:40:06 +02:00
mapper = new MonitoredDataMapper ( this ) ;
2011-05-31 22:24:53 +02:00
mapper - > setSubmitPolicy ( QDataWidgetMapper : : ManualSubmit ) ;
mapper - > setOrientation ( Qt : : Vertical ) ;
2011-06-01 14:40:06 +02:00
/* enable apply button when data modified */
connect ( mapper , SIGNAL ( viewModified ( ) ) , this , SLOT ( enableApply ( ) ) ) ;
/* disable apply button when new data loaded */
connect ( mapper , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( disableApply ( ) ) ) ;
2011-06-01 09:33:48 +02:00
/* Event bindings */
2011-07-25 21:35:45 +02:00
connect ( contents_widget , SIGNAL ( currentRowChanged ( int ) ) , this , SLOT ( changePage ( int ) ) ) ;
2011-06-24 21:23:43 +02:00
connect ( buttonbox - > button ( QDialogButtonBox : : Ok ) , SIGNAL ( clicked ( ) ) , this , SLOT ( okClicked ( ) ) ) ;
connect ( buttonbox - > button ( QDialogButtonBox : : Cancel ) , SIGNAL ( clicked ( ) ) , this , SLOT ( cancelClicked ( ) ) ) ;
connect ( buttonbox - > button ( QDialogButtonBox : : Apply ) , SIGNAL ( clicked ( ) ) , this , SLOT ( applyClicked ( ) ) ) ;
2011-05-31 22:24:53 +02:00
}
void OptionsDialog : : setModel ( OptionsModel * model )
{
this - > model = model ;
mapper - > setModel ( model ) ;
2012-05-07 21:49:22 +02:00
foreach ( OptionsPage * page , pages )
{
page - > setMapper ( mapper ) ;
}
2011-05-12 14:44:52 +02:00
2011-05-31 22:24:53 +02:00
mapper - > toFirst ( ) ;
2011-05-12 14:44:52 +02:00
}
2011-07-25 21:35:45 +02:00
void OptionsDialog : : changePage ( int index )
2011-05-12 14:44:52 +02:00
{
2011-07-25 21:35:45 +02:00
pages_widget - > setCurrentIndex ( index ) ;
2011-05-12 14:44:52 +02:00
}
2011-06-01 09:33:48 +02:00
void OptionsDialog : : okClicked ( )
{
mapper - > submit ( ) ;
accept ( ) ;
}
void OptionsDialog : : cancelClicked ( )
{
reject ( ) ;
}
void OptionsDialog : : applyClicked ( )
{
mapper - > submit ( ) ;
apply_button - > setEnabled ( false ) ;
}
void OptionsDialog : : enableApply ( )
{
apply_button - > setEnabled ( true ) ;
}
2011-06-01 14:40:06 +02:00
void OptionsDialog : : disableApply ( )
{
apply_button - > setEnabled ( false ) ;
}
2012-05-07 21:49:22 +02:00
/* Main options */
2011-06-01 14:40:06 +02:00
MainOptionsPage : : MainOptionsPage ( QWidget * parent ) :
2012-05-07 21:49:22 +02:00
OptionsPage ( parent )
{
QVBoxLayout * layout = new QVBoxLayout ( ) ;
setWindowTitle ( tr ( " Main " ) ) ;
QLabel * fee_help = new QLabel ( tr ( " Optional transaction fee per kB that helps make sure your transactions are processed quickly. Most transactions are 1 kB. Fee 0.01 recommended. " ) ) ;
fee_help - > setWordWrap ( true ) ;
layout - > addWidget ( fee_help ) ;
QHBoxLayout * fee_hbox = new QHBoxLayout ( ) ;
fee_hbox - > addSpacing ( 18 ) ;
QLabel * fee_label = new QLabel ( tr ( " Pay transaction &fee " ) ) ;
fee_hbox - > addWidget ( fee_label ) ;
fee_edit = new BitcoinAmountField ( ) ;
fee_label - > setBuddy ( fee_edit ) ;
fee_hbox - > addWidget ( fee_edit ) ;
fee_hbox - > addStretch ( 1 ) ;
layout - > addLayout ( fee_hbox ) ;
2012-05-10 15:33:01 +02:00
bitcoin_at_startup = new QCheckBox ( tr ( " &Start Bitcoin on system login " ) ) ;
bitcoin_at_startup - > setToolTip ( tr ( " Automatically start Bitcoin after logging in to the system " ) ) ;
layout - > addWidget ( bitcoin_at_startup ) ;
detach_database = new QCheckBox ( tr ( " &Detach databases at shutdown " ) ) ;
2012-05-07 21:49:22 +02:00
detach_database - > setToolTip ( tr ( " Detach block and address databases at shutdown. This means they can be moved to another data directory, but it slows down shutdown. The wallet is always detached. " ) ) ;
layout - > addWidget ( detach_database ) ;
layout - > addStretch ( 1 ) ; // Extra space at bottom
setLayout ( layout ) ;
}
void MainOptionsPage : : setMapper ( MonitoredDataMapper * mapper )
{
// Map model to widgets
mapper - > addMapping ( fee_edit , OptionsModel : : Fee ) ;
2012-05-10 15:33:01 +02:00
mapper - > addMapping ( bitcoin_at_startup , OptionsModel : : StartAtStartup ) ;
2012-05-07 21:49:22 +02:00
mapper - > addMapping ( detach_database , OptionsModel : : DetachDatabases ) ;
}
/* Display options */
DisplayOptionsPage : : DisplayOptionsPage ( QWidget * parent ) :
2012-05-08 23:03:41 +02:00
OptionsPage ( parent ) , restart_warning_displayed ( false )
2011-06-01 14:40:06 +02:00
{
2012-05-07 21:49:22 +02:00
setWindowTitle ( tr ( " Display " ) ) ;
2011-06-01 14:40:06 +02:00
QVBoxLayout * layout = new QVBoxLayout ( ) ;
2012-05-08 23:03:41 +02:00
QHBoxLayout * lang_hbox = new QHBoxLayout ( ) ;
lang_hbox - > addSpacing ( 18 ) ;
2012-05-16 15:34:29 +02:00
QLabel * lang_label = new QLabel ( tr ( " User Interface &Language: " ) ) ;
2012-05-08 23:03:41 +02:00
lang_hbox - > addWidget ( lang_label ) ;
lang = new QValueComboBox ( this ) ;
// Make list of languages
QDir translations ( " :translations " ) ;
2012-05-10 15:33:01 +02:00
lang - > addItem ( QString ( " ( " ) + tr ( " default " ) + QString ( " ) " ) , QVariant ( " " ) ) ;
2012-05-08 23:03:41 +02:00
foreach ( const QString & langStr , translations . entryList ( ) )
{
lang - > addItem ( langStr , QVariant ( langStr ) ) ;
}
lang - > setToolTip ( tr ( " The user interface language can be set here. This setting will only take effect after restarting Bitcoin. " ) ) ;
connect ( lang , SIGNAL ( activated ( int ) ) , this , SLOT ( showRestartWarning ( ) ) ) ;
lang_label - > setBuddy ( lang ) ;
lang_hbox - > addWidget ( lang ) ;
layout - > addLayout ( lang_hbox ) ;
2012-05-07 21:49:22 +02:00
QHBoxLayout * unit_hbox = new QHBoxLayout ( ) ;
unit_hbox - > addSpacing ( 18 ) ;
2012-05-16 15:34:29 +02:00
QLabel * unit_label = new QLabel ( tr ( " &Unit to show amounts in: " ) ) ;
2012-05-07 21:49:22 +02:00
unit_hbox - > addWidget ( unit_label ) ;
unit = new QValueComboBox ( this ) ;
unit - > setModel ( new BitcoinUnits ( this ) ) ;
unit - > setToolTip ( tr ( " Choose the default subdivision unit to show in the interface, and when sending coins " ) ) ;
unit_label - > setBuddy ( unit ) ;
unit_hbox - > addWidget ( unit ) ;
layout - > addLayout ( unit_hbox ) ;
display_addresses = new QCheckBox ( tr ( " &Display addresses in transaction list " ) , this ) ;
display_addresses - > setToolTip ( tr ( " Whether to show Bitcoin addresses in the transaction list " ) ) ;
layout - > addWidget ( display_addresses ) ;
layout - > addStretch ( ) ;
setLayout ( layout ) ;
}
void DisplayOptionsPage : : setMapper ( MonitoredDataMapper * mapper )
{
2012-05-08 23:03:41 +02:00
mapper - > addMapping ( lang , OptionsModel : : Language ) ;
2012-05-07 21:49:22 +02:00
mapper - > addMapping ( unit , OptionsModel : : DisplayUnit ) ;
mapper - > addMapping ( display_addresses , OptionsModel : : DisplayAddresses ) ;
}
2012-05-08 23:03:41 +02:00
void DisplayOptionsPage : : showRestartWarning ( )
{
if ( ! restart_warning_displayed )
{
QMessageBox : : warning ( this , tr ( " Warning " ) , tr ( " This setting will take effect after restarting Bitcoin. " ) , QMessageBox : : Ok ) ;
restart_warning_displayed = true ;
}
}
2012-05-07 21:49:22 +02:00
/* Window options */
WindowOptionsPage : : WindowOptionsPage ( QWidget * parent ) :
OptionsPage ( parent )
{
QVBoxLayout * layout = new QVBoxLayout ( ) ;
setWindowTitle ( tr ( " Window " ) ) ;
2011-10-07 13:21:45 +02:00
# ifndef Q_WS_MAC
2011-06-01 14:40:06 +02:00
minimize_to_tray = new QCheckBox ( tr ( " &Minimize to the tray instead of the taskbar " ) ) ;
2011-06-11 12:46:09 +02:00
minimize_to_tray - > setToolTip ( tr ( " Show only a tray icon after minimizing the window " ) ) ;
2011-06-01 14:40:06 +02:00
layout - > addWidget ( minimize_to_tray ) ;
minimize_on_close = new QCheckBox ( tr ( " M&inimize on close " ) ) ;
2011-06-11 12:46:09 +02:00
minimize_on_close - > setToolTip ( tr ( " Minimize instead of exit the application when the window is closed. When this option is enabled, the application will be closed only after selecting Quit in the menu. " ) ) ;
2011-06-01 14:40:06 +02:00
layout - > addWidget ( minimize_on_close ) ;
2011-10-07 13:21:45 +02:00
# endif
2011-06-01 14:40:06 +02:00
2012-05-07 21:49:22 +02:00
layout - > addStretch ( 1 ) ; // Extra space at bottom
setLayout ( layout ) ;
}
void WindowOptionsPage : : setMapper ( MonitoredDataMapper * mapper )
{
// Map model to widgets
# ifndef Q_WS_MAC
mapper - > addMapping ( minimize_to_tray , OptionsModel : : MinimizeToTray ) ;
# endif
# ifndef Q_WS_MAC
mapper - > addMapping ( minimize_on_close , OptionsModel : : MinimizeOnClose ) ;
# endif
}
/* Network options */
NetworkOptionsPage : : NetworkOptionsPage ( QWidget * parent ) :
OptionsPage ( parent )
{
QVBoxLayout * layout = new QVBoxLayout ( ) ;
setWindowTitle ( tr ( " Network " ) ) ;
2012-02-17 15:34:53 +01:00
map_port_upnp = new QCheckBox ( tr ( " Map port using &UPnP " ) ) ;
map_port_upnp - > setToolTip ( tr ( " Automatically open the Bitcoin client port on the router. This only works when your router supports UPnP and it is enabled. " ) ) ;
layout - > addWidget ( map_port_upnp ) ;
2011-06-11 12:46:09 +02:00
connect_socks4 = new QCheckBox ( tr ( " &Connect through SOCKS4 proxy: " ) ) ;
connect_socks4 - > setToolTip ( tr ( " Connect to the Bitcon network through a SOCKS4 proxy (e.g. when connecting through Tor) " ) ) ;
2011-06-01 14:40:06 +02:00
layout - > addWidget ( connect_socks4 ) ;
QHBoxLayout * proxy_hbox = new QHBoxLayout ( ) ;
proxy_hbox - > addSpacing ( 18 ) ;
2012-05-16 15:34:29 +02:00
QLabel * proxy_ip_label = new QLabel ( tr ( " Proxy &IP: " ) ) ;
2011-06-01 14:40:06 +02:00
proxy_hbox - > addWidget ( proxy_ip_label ) ;
proxy_ip = new QLineEdit ( ) ;
proxy_ip - > setMaximumWidth ( 140 ) ;
proxy_ip - > setEnabled ( false ) ;
proxy_ip - > setValidator ( new QRegExpValidator ( QRegExp ( " [0-9]{1,3} \\ .[0-9]{1,3} \\ .[0-9]{1,3} \\ .[0-9]{1,3} " ) , this ) ) ;
2011-06-11 12:46:09 +02:00
proxy_ip - > setToolTip ( tr ( " IP address of the proxy (e.g. 127.0.0.1) " ) ) ;
2011-06-01 14:40:06 +02:00
proxy_ip_label - > setBuddy ( proxy_ip ) ;
proxy_hbox - > addWidget ( proxy_ip ) ;
2012-05-16 15:34:29 +02:00
QLabel * proxy_port_label = new QLabel ( tr ( " &Port: " ) ) ;
2011-06-01 14:40:06 +02:00
proxy_hbox - > addWidget ( proxy_port_label ) ;
proxy_port = new QLineEdit ( ) ;
proxy_port - > setMaximumWidth ( 55 ) ;
proxy_port - > setValidator ( new QIntValidator ( 0 , 65535 , this ) ) ;
proxy_port - > setEnabled ( false ) ;
2011-06-11 12:46:09 +02:00
proxy_port - > setToolTip ( tr ( " Port of the proxy (e.g. 1234) " ) ) ;
2011-06-01 14:40:06 +02:00
proxy_port_label - > setBuddy ( proxy_port ) ;
proxy_hbox - > addWidget ( proxy_port ) ;
proxy_hbox - > addStretch ( 1 ) ;
layout - > addLayout ( proxy_hbox ) ;
2012-04-17 23:03:24 +02:00
2011-06-18 11:53:25 +02:00
layout - > addStretch ( 1 ) ; // Extra space at bottom
2011-06-01 14:40:06 +02:00
setLayout ( layout ) ;
connect ( connect_socks4 , SIGNAL ( toggled ( bool ) ) , proxy_ip , SLOT ( setEnabled ( bool ) ) ) ;
connect ( connect_socks4 , SIGNAL ( toggled ( bool ) ) , proxy_port , SLOT ( setEnabled ( bool ) ) ) ;
2011-06-05 12:43:18 +02:00
# ifndef USE_UPNP
map_port_upnp - > setDisabled ( true ) ;
# endif
2011-06-01 14:40:06 +02:00
}
2012-05-07 21:49:22 +02:00
void NetworkOptionsPage : : setMapper ( MonitoredDataMapper * mapper )
2011-06-01 14:40:06 +02:00
{
2011-06-18 11:53:25 +02:00
// Map model to widgets
2011-06-01 14:40:06 +02:00
mapper - > addMapping ( map_port_upnp , OptionsModel : : MapPortUPnP ) ;
2012-05-24 19:02:21 +02:00
mapper - > addMapping ( connect_socks4 , OptionsModel : : ProxyUse ) ;
2011-06-01 14:40:06 +02:00
mapper - > addMapping ( proxy_ip , OptionsModel : : ProxyIP ) ;
mapper - > addMapping ( proxy_port , OptionsModel : : ProxyPort ) ;
2011-07-25 21:35:45 +02:00
}