]> Git Repo - VerusCoin.git/blob - src/qt/optionsdialog.cpp
Merge branch 'dbenv' into tmp
[VerusCoin.git] / src / qt / optionsdialog.cpp
1 #include "optionsdialog.h"
2 #include "optionsmodel.h"
3 #include "bitcoinamountfield.h"
4 #include "monitoreddatamapper.h"
5 #include "guiutil.h"
6 #include "bitcoinunits.h"
7 #include "qvaluecombobox.h"
8
9 #include <QHBoxLayout>
10 #include <QVBoxLayout>
11 #include <QPushButton>
12 #include <QListWidget>
13 #include <QStackedWidget>
14
15 #include <QCheckBox>
16 #include <QLabel>
17 #include <QLineEdit>
18 #include <QIntValidator>
19 #include <QDoubleValidator>
20 #include <QRegExpValidator>
21 #include <QDialogButtonBox>
22 #include <QDir>
23 #include <QMessageBox>
24
25 class OptionsPage: public QWidget
26 {
27     Q_OBJECT
28 public:
29     explicit OptionsPage(QWidget *parent=0): QWidget(parent) {}
30
31     virtual void setMapper(MonitoredDataMapper *mapper) = 0;
32 };
33
34 class MainOptionsPage: public OptionsPage
35 {
36     Q_OBJECT
37 public:
38     explicit MainOptionsPage(QWidget *parent=0);
39
40     virtual void setMapper(MonitoredDataMapper *mapper);
41 private:
42     BitcoinAmountField *fee_edit;
43     QCheckBox *bitcoin_at_startup;
44     QCheckBox *detach_database;
45 };
46
47 class WindowOptionsPage: public OptionsPage
48 {
49     Q_OBJECT
50 public:
51     explicit WindowOptionsPage(QWidget *parent=0);
52
53     virtual void setMapper(MonitoredDataMapper *mapper);
54 private:
55 #ifndef Q_WS_MAC
56     QCheckBox *minimize_to_tray;
57     QCheckBox *minimize_on_close;
58 #endif
59 };
60
61 class DisplayOptionsPage: public OptionsPage
62 {
63     Q_OBJECT
64 public:
65     explicit DisplayOptionsPage(QWidget *parent=0);
66
67     virtual void setMapper(MonitoredDataMapper *mapper);
68 private:
69     QValueComboBox *lang;
70     QValueComboBox *unit;
71     QCheckBox *display_addresses;
72     bool restart_warning_displayed;
73 private slots:
74     void showRestartWarning();
75 };
76
77 class NetworkOptionsPage: public OptionsPage
78 {
79     Q_OBJECT
80 public:
81     explicit NetworkOptionsPage(QWidget *parent=0);
82
83     virtual void setMapper(MonitoredDataMapper *mapper);
84 private:
85     QCheckBox *map_port_upnp;
86     QCheckBox *connect_socks4;
87     QLineEdit *proxy_ip;
88     QLineEdit *proxy_port;
89 };
90
91
92 #include "optionsdialog.moc"
93
94 OptionsDialog::OptionsDialog(QWidget *parent):
95     QDialog(parent), contents_widget(0), pages_widget(0),
96     model(0)
97 {
98     contents_widget = new QListWidget();
99     contents_widget->setMaximumWidth(128);
100
101     pages_widget = new QStackedWidget();
102     pages_widget->setMinimumWidth(500);
103     pages_widget->setMinimumHeight(300);
104
105     pages.append(new MainOptionsPage(this));
106     pages.append(new NetworkOptionsPage(this));
107 #ifndef Q_WS_MAC
108     /* Hide Window options on Mac as there are currently none available */
109     pages.append(new WindowOptionsPage(this));
110 #endif
111     pages.append(new DisplayOptionsPage(this));
112
113     foreach(OptionsPage *page, pages)
114     {
115         QListWidgetItem *item = new QListWidgetItem(page->windowTitle());
116         contents_widget->addItem(item);
117         pages_widget->addWidget(page);
118     }
119
120     contents_widget->setCurrentRow(0);
121
122     QHBoxLayout *main_layout = new QHBoxLayout();
123     main_layout->addWidget(contents_widget);
124     main_layout->addWidget(pages_widget, 1);
125
126     QVBoxLayout *layout = new QVBoxLayout();
127     layout->addLayout(main_layout);
128
129     QDialogButtonBox *buttonbox = new QDialogButtonBox();
130     buttonbox->setStandardButtons(QDialogButtonBox::Apply|QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
131     apply_button = buttonbox->button(QDialogButtonBox::Apply);
132     layout->addWidget(buttonbox);
133
134     setLayout(layout);
135     setWindowTitle(tr("Options"));
136
137     /* Widget-to-option mapper */
138     mapper = new MonitoredDataMapper(this);
139     mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
140     mapper->setOrientation(Qt::Vertical);
141     /* enable apply button when data modified */
142     connect(mapper, SIGNAL(viewModified()), this, SLOT(enableApply()));
143     /* disable apply button when new data loaded */
144     connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(disableApply()));
145
146     /* Event bindings */
147     connect(contents_widget, SIGNAL(currentRowChanged(int)), this, SLOT(changePage(int)));
148     connect(buttonbox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(okClicked()));
149     connect(buttonbox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(cancelClicked()));
150     connect(buttonbox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(applyClicked()));
151 }
152
153 void OptionsDialog::setModel(OptionsModel *model)
154 {
155     this->model = model;
156
157     mapper->setModel(model);
158
159     foreach(OptionsPage *page, pages)
160     {
161         page->setMapper(mapper);
162     }
163
164     mapper->toFirst();
165 }
166
167 void OptionsDialog::changePage(int index)
168 {
169     pages_widget->setCurrentIndex(index);
170 }
171
172 void OptionsDialog::okClicked()
173 {
174     mapper->submit();
175     accept();
176 }
177
178 void OptionsDialog::cancelClicked()
179 {
180     reject();
181 }
182
183 void OptionsDialog::applyClicked()
184 {
185     mapper->submit();
186     apply_button->setEnabled(false);
187 }
188
189 void OptionsDialog::enableApply()
190 {
191     apply_button->setEnabled(true);
192 }
193
194 void OptionsDialog::disableApply()
195 {
196     apply_button->setEnabled(false);
197 }
198
199 /* Main options */
200 MainOptionsPage::MainOptionsPage(QWidget *parent):
201         OptionsPage(parent)
202 {
203     QVBoxLayout *layout = new QVBoxLayout();
204     setWindowTitle(tr("Main"));
205
206     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."));
207     fee_help->setWordWrap(true);
208     layout->addWidget(fee_help);
209
210     QHBoxLayout *fee_hbox = new QHBoxLayout();
211     fee_hbox->addSpacing(18);
212     QLabel *fee_label = new QLabel(tr("Pay transaction &fee"));
213     fee_hbox->addWidget(fee_label);
214     fee_edit = new BitcoinAmountField();
215
216     fee_label->setBuddy(fee_edit);
217     fee_hbox->addWidget(fee_edit);
218     fee_hbox->addStretch(1);
219
220     layout->addLayout(fee_hbox);
221
222     bitcoin_at_startup = new QCheckBox(tr("&Start Bitcoin on system login"));
223     bitcoin_at_startup->setToolTip(tr("Automatically start Bitcoin after logging in to the system"));
224     layout->addWidget(bitcoin_at_startup);
225
226     detach_database = new QCheckBox(tr("&Detach databases at shutdown"));
227     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."));
228     layout->addWidget(detach_database);
229
230     layout->addStretch(1); // Extra space at bottom
231     setLayout(layout);
232 }
233
234 void MainOptionsPage::setMapper(MonitoredDataMapper *mapper)
235 {
236     // Map model to widgets
237     mapper->addMapping(fee_edit, OptionsModel::Fee);
238     mapper->addMapping(bitcoin_at_startup, OptionsModel::StartAtStartup);
239     mapper->addMapping(detach_database, OptionsModel::DetachDatabases);
240 }
241
242 /* Display options */
243 DisplayOptionsPage::DisplayOptionsPage(QWidget *parent):
244     OptionsPage(parent), restart_warning_displayed(false)
245 {
246     setWindowTitle(tr("Display"));
247
248     QVBoxLayout *layout = new QVBoxLayout();
249
250     QHBoxLayout *lang_hbox = new QHBoxLayout();
251     lang_hbox->addSpacing(18);
252     QLabel *lang_label = new QLabel(tr("User Interface &Language:"));
253     lang_hbox->addWidget(lang_label);
254     lang = new QValueComboBox(this);
255     // Make list of languages
256     QDir translations(":translations");
257     lang->addItem(QString("(") + tr("default") + QString(")"), QVariant(""));
258     foreach(const QString &langStr, translations.entryList())
259     {
260         lang->addItem(langStr, QVariant(langStr));
261     }
262
263     lang->setToolTip(tr("The user interface language can be set here. This setting will only take effect after restarting Bitcoin."));
264     connect(lang, SIGNAL(activated(int)), this, SLOT(showRestartWarning()));
265
266     lang_label->setBuddy(lang);
267     lang_hbox->addWidget(lang);
268
269     layout->addLayout(lang_hbox);
270
271     QHBoxLayout *unit_hbox = new QHBoxLayout();
272     unit_hbox->addSpacing(18);
273     QLabel *unit_label = new QLabel(tr("&Unit to show amounts in:"));
274     unit_hbox->addWidget(unit_label);
275     unit = new QValueComboBox(this);
276     unit->setModel(new BitcoinUnits(this));
277     unit->setToolTip(tr("Choose the default subdivision unit to show in the interface, and when sending coins"));
278
279     unit_label->setBuddy(unit);
280     unit_hbox->addWidget(unit);
281
282     layout->addLayout(unit_hbox);
283
284     display_addresses = new QCheckBox(tr("&Display addresses in transaction list"), this);
285     display_addresses->setToolTip(tr("Whether to show Bitcoin addresses in the transaction list"));
286     layout->addWidget(display_addresses);
287
288     layout->addStretch();
289     setLayout(layout);
290 }
291
292 void DisplayOptionsPage::setMapper(MonitoredDataMapper *mapper)
293 {
294     mapper->addMapping(lang, OptionsModel::Language);
295     mapper->addMapping(unit, OptionsModel::DisplayUnit);
296     mapper->addMapping(display_addresses, OptionsModel::DisplayAddresses);
297 }
298
299 void DisplayOptionsPage::showRestartWarning()
300 {
301     if(!restart_warning_displayed)
302     {
303         QMessageBox::warning(this, tr("Warning"), tr("This setting will take effect after restarting Bitcoin."), QMessageBox::Ok);
304         restart_warning_displayed = true;
305     }
306 }
307
308 /* Window options */
309 WindowOptionsPage::WindowOptionsPage(QWidget *parent):
310         OptionsPage(parent)
311 {
312     QVBoxLayout *layout = new QVBoxLayout();
313     setWindowTitle(tr("Window"));
314
315 #ifndef Q_WS_MAC
316     minimize_to_tray = new QCheckBox(tr("&Minimize to the tray instead of the taskbar"));
317     minimize_to_tray->setToolTip(tr("Show only a tray icon after minimizing the window"));
318     layout->addWidget(minimize_to_tray);
319
320     minimize_on_close = new QCheckBox(tr("M&inimize on close"));
321     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."));
322     layout->addWidget(minimize_on_close);
323 #endif
324
325     layout->addStretch(1); // Extra space at bottom
326     setLayout(layout);
327 }
328
329 void WindowOptionsPage::setMapper(MonitoredDataMapper *mapper)
330 {
331     // Map model to widgets
332 #ifndef Q_WS_MAC
333     mapper->addMapping(minimize_to_tray, OptionsModel::MinimizeToTray);
334 #endif
335 #ifndef Q_WS_MAC
336     mapper->addMapping(minimize_on_close, OptionsModel::MinimizeOnClose);
337 #endif
338 }
339
340 /* Network options */
341 NetworkOptionsPage::NetworkOptionsPage(QWidget *parent):
342         OptionsPage(parent)
343 {
344     QVBoxLayout *layout = new QVBoxLayout();
345     setWindowTitle(tr("Network"));
346
347     map_port_upnp = new QCheckBox(tr("Map port using &UPnP"));
348     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."));
349     layout->addWidget(map_port_upnp);
350
351     connect_socks4 = new QCheckBox(tr("&Connect through SOCKS4 proxy:"));
352     connect_socks4->setToolTip(tr("Connect to the Bitcon network through a SOCKS4 proxy (e.g. when connecting through Tor)"));
353     layout->addWidget(connect_socks4);
354
355     QHBoxLayout *proxy_hbox = new QHBoxLayout();
356     proxy_hbox->addSpacing(18);
357     QLabel *proxy_ip_label = new QLabel(tr("Proxy &IP:"));
358     proxy_hbox->addWidget(proxy_ip_label);
359     proxy_ip = new QLineEdit();
360     proxy_ip->setMaximumWidth(140);
361     proxy_ip->setEnabled(false);
362     proxy_ip->setValidator(new QRegExpValidator(QRegExp("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"), this));
363     proxy_ip->setToolTip(tr("IP address of the proxy (e.g. 127.0.0.1)"));
364     proxy_ip_label->setBuddy(proxy_ip);
365     proxy_hbox->addWidget(proxy_ip);
366     QLabel *proxy_port_label = new QLabel(tr("&Port:"));
367     proxy_hbox->addWidget(proxy_port_label);
368     proxy_port = new QLineEdit();
369     proxy_port->setMaximumWidth(55);
370     proxy_port->setValidator(new QIntValidator(0, 65535, this));
371     proxy_port->setEnabled(false);
372     proxy_port->setToolTip(tr("Port of the proxy (e.g. 1234)"));
373     proxy_port_label->setBuddy(proxy_port);
374     proxy_hbox->addWidget(proxy_port);
375     proxy_hbox->addStretch(1);
376     layout->addLayout(proxy_hbox);
377
378     layout->addStretch(1); // Extra space at bottom
379     setLayout(layout);
380
381     connect(connect_socks4, SIGNAL(toggled(bool)), proxy_ip, SLOT(setEnabled(bool)));
382     connect(connect_socks4, SIGNAL(toggled(bool)), proxy_port, SLOT(setEnabled(bool)));
383
384 #ifndef USE_UPNP
385     map_port_upnp->setDisabled(true);
386 #endif
387 }
388
389 void NetworkOptionsPage::setMapper(MonitoredDataMapper *mapper)
390 {
391     // Map model to widgets
392     mapper->addMapping(map_port_upnp, OptionsModel::MapPortUPnP);
393     mapper->addMapping(connect_socks4, OptionsModel::ConnectSOCKS4);
394     mapper->addMapping(proxy_ip, OptionsModel::ProxyIP);
395     mapper->addMapping(proxy_port, OptionsModel::ProxyPort);
396 }
This page took 0.04669 seconds and 4 git commands to generate.