1 #include "optionsdialog.h"
2 #include "optionsmodel.h"
3 #include "bitcoinamountfield.h"
4 #include "monitoreddatamapper.h"
10 #include <QListWidget>
11 #include <QStackedWidget>
16 #include <QIntValidator>
17 #include <QDoubleValidator>
18 #include <QRegExpValidator>
20 /* First (currently only) page of options */
21 class MainOptionsPage : public QWidget
24 explicit MainOptionsPage(QWidget *parent=0);
26 void setMapper(MonitoredDataMapper *mapper);
28 QCheckBox *bitcoin_at_startup;
29 QCheckBox *minimize_to_tray;
30 QCheckBox *map_port_upnp;
31 QCheckBox *minimize_on_close;
32 QCheckBox *connect_socks4;
34 QLineEdit *proxy_port;
35 BitcoinAmountField *fee_edit;
43 OptionsDialog::OptionsDialog(QWidget *parent):
44 QDialog(parent), contents_widget(0), pages_widget(0),
45 main_options_page(0), model(0)
47 contents_widget = new QListWidget();
48 contents_widget->setMaximumWidth(128);
50 pages_widget = new QStackedWidget();
51 pages_widget->setMinimumWidth(300);
53 QListWidgetItem *item_main = new QListWidgetItem(tr("Main"));
54 contents_widget->addItem(item_main);
55 main_options_page = new MainOptionsPage(this);
56 pages_widget->addWidget(main_options_page);
58 contents_widget->setCurrentRow(0);
60 QHBoxLayout *main_layout = new QHBoxLayout();
61 main_layout->addWidget(contents_widget);
62 main_layout->addWidget(pages_widget, 1);
64 QVBoxLayout *layout = new QVBoxLayout();
65 layout->addLayout(main_layout);
67 QHBoxLayout *buttons = new QHBoxLayout();
68 buttons->addStretch(1);
69 QPushButton *ok_button = new QPushButton(tr("OK"));
70 buttons->addWidget(ok_button);
71 QPushButton *cancel_button = new QPushButton(tr("Cancel"));
72 buttons->addWidget(cancel_button);
73 apply_button = new QPushButton(tr("Apply"));
74 apply_button->setEnabled(false);
75 buttons->addWidget(apply_button);
77 layout->addLayout(buttons);
80 setWindowTitle(tr("Options"));
82 /* Widget-to-option mapper */
83 mapper = new MonitoredDataMapper(this);
84 mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
85 mapper->setOrientation(Qt::Vertical);
86 /* enable apply button when data modified */
87 connect(mapper, SIGNAL(viewModified()), this, SLOT(enableApply()));
88 /* disable apply button when new data loaded */
89 connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(disableApply()));
92 connect(ok_button, SIGNAL(clicked()), this, SLOT(okClicked()));
93 connect(cancel_button, SIGNAL(clicked()), this, SLOT(cancelClicked()));
94 connect(apply_button, SIGNAL(clicked()), this, SLOT(applyClicked()));
97 void OptionsDialog::setModel(OptionsModel *model)
101 mapper->setModel(model);
102 main_options_page->setMapper(mapper);
107 void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
112 pages_widget->setCurrentIndex(contents_widget->row(current));
116 void OptionsDialog::okClicked()
122 void OptionsDialog::cancelClicked()
127 void OptionsDialog::applyClicked()
130 apply_button->setEnabled(false);
133 void OptionsDialog::enableApply()
135 apply_button->setEnabled(true);
138 void OptionsDialog::disableApply()
140 apply_button->setEnabled(false);
143 MainOptionsPage::MainOptionsPage(QWidget *parent):
146 QVBoxLayout *layout = new QVBoxLayout();
148 bitcoin_at_startup = new QCheckBox(tr("&Start Bitcoin on window system startup"));
149 bitcoin_at_startup->setToolTip(tr("Automatically start Bitcoin after the computer is turned on"));
150 layout->addWidget(bitcoin_at_startup);
152 minimize_to_tray = new QCheckBox(tr("&Minimize to the tray instead of the taskbar"));
153 minimize_to_tray->setToolTip(tr("Show only a tray icon after minimizing the window"));
154 layout->addWidget(minimize_to_tray);
156 map_port_upnp = new QCheckBox(tr("Map port using &UPnP"));
157 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."));
158 layout->addWidget(map_port_upnp);
160 minimize_on_close = new QCheckBox(tr("M&inimize on close"));
161 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."));
162 layout->addWidget(minimize_on_close);
164 connect_socks4 = new QCheckBox(tr("&Connect through SOCKS4 proxy:"));
165 connect_socks4->setToolTip(tr("Connect to the Bitcon network through a SOCKS4 proxy (e.g. when connecting through Tor)"));
166 layout->addWidget(connect_socks4);
168 QHBoxLayout *proxy_hbox = new QHBoxLayout();
169 proxy_hbox->addSpacing(18);
170 QLabel *proxy_ip_label = new QLabel(tr("Proxy &IP: "));
171 proxy_hbox->addWidget(proxy_ip_label);
172 proxy_ip = new QLineEdit();
173 proxy_ip->setMaximumWidth(140);
174 proxy_ip->setEnabled(false);
175 proxy_ip->setValidator(new QRegExpValidator(QRegExp("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"), this));
176 proxy_ip->setToolTip(tr("IP address of the proxy (e.g. 127.0.0.1)"));
177 proxy_ip_label->setBuddy(proxy_ip);
178 proxy_hbox->addWidget(proxy_ip);
179 QLabel *proxy_port_label = new QLabel(tr("&Port: "));
180 proxy_hbox->addWidget(proxy_port_label);
181 proxy_port = new QLineEdit();
182 proxy_port->setMaximumWidth(55);
183 proxy_port->setValidator(new QIntValidator(0, 65535, this));
184 proxy_port->setEnabled(false);
185 proxy_port->setToolTip(tr("Port of the proxy (e.g. 1234)"));
186 proxy_port_label->setBuddy(proxy_port);
187 proxy_hbox->addWidget(proxy_port);
188 proxy_hbox->addStretch(1);
190 layout->addLayout(proxy_hbox);
191 QLabel *fee_help = new QLabel(tr("Optional transaction fee per KB that helps make sure your transactions are processed quickly. Most transactions are 1KB. Fee 0.01 recommended."));
192 fee_help->setWordWrap(true);
193 layout->addWidget(fee_help);
195 QHBoxLayout *fee_hbox = new QHBoxLayout();
196 fee_hbox->addSpacing(18);
197 QLabel *fee_label = new QLabel(tr("Pay transaction &fee"));
198 fee_hbox->addWidget(fee_label);
199 fee_edit = new BitcoinAmountField();
200 fee_edit->setToolTip(tr("Optional transaction fee per KB that helps make sure your transactions are processed quickly. Most transactions are 1KB. Fee 0.01 recommended."));
202 fee_label->setBuddy(fee_edit);
203 fee_hbox->addWidget(fee_edit);
204 fee_hbox->addStretch(1);
206 layout->addLayout(fee_hbox);
208 layout->addStretch(1); // Extra space at bottom
212 connect(connect_socks4, SIGNAL(toggled(bool)), proxy_ip, SLOT(setEnabled(bool)));
213 connect(connect_socks4, SIGNAL(toggled(bool)), proxy_port, SLOT(setEnabled(bool)));
216 map_port_upnp->setDisabled(true);
220 void MainOptionsPage::setMapper(MonitoredDataMapper *mapper)
222 // Map model to widgets
223 mapper->addMapping(bitcoin_at_startup, OptionsModel::StartAtStartup);
224 mapper->addMapping(minimize_to_tray, OptionsModel::MinimizeToTray);
225 mapper->addMapping(map_port_upnp, OptionsModel::MapPortUPnP);
226 mapper->addMapping(minimize_on_close, OptionsModel::MinimizeOnClose);
227 mapper->addMapping(connect_socks4, OptionsModel::ConnectSOCKS4);
228 mapper->addMapping(proxy_ip, OptionsModel::ProxyIP);
229 mapper->addMapping(proxy_port, OptionsModel::ProxyPort);
230 mapper->addMapping(fee_edit, OptionsModel::Fee);