You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

optionsdialog.cpp 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. #include <QHBoxLayout>
  9. #include <QVBoxLayout>
  10. #include <QPushButton>
  11. #include <QListWidget>
  12. #include <QStackedWidget>
  13. #include <QCheckBox>
  14. #include <QLabel>
  15. #include <QLineEdit>
  16. #include <QIntValidator>
  17. #include <QDoubleValidator>
  18. #include <QRegExpValidator>
  19. #include <QDialogButtonBox>
  20. /* First page of options */
  21. class MainOptionsPage : public QWidget
  22. {
  23. Q_OBJECT
  24. public:
  25. explicit MainOptionsPage(QWidget *parent=0);
  26. void setMapper(MonitoredDataMapper *mapper);
  27. private:
  28. QCheckBox *bitcoin_at_startup;
  29. #ifndef Q_WS_MAC
  30. QCheckBox *minimize_to_tray;
  31. #endif
  32. QCheckBox *map_port_upnp;
  33. #ifndef Q_WS_MAC
  34. QCheckBox *minimize_on_close;
  35. #endif
  36. QCheckBox *connect_socks4;
  37. QCheckBox *detach_database;
  38. QLineEdit *proxy_ip;
  39. QLineEdit *proxy_port;
  40. BitcoinAmountField *fee_edit;
  41. signals:
  42. public slots:
  43. };
  44. class DisplayOptionsPage : public QWidget
  45. {
  46. Q_OBJECT
  47. public:
  48. explicit DisplayOptionsPage(QWidget *parent=0);
  49. void setMapper(MonitoredDataMapper *mapper);
  50. private:
  51. QValueComboBox *unit;
  52. QCheckBox *display_addresses;
  53. signals:
  54. public slots:
  55. };
  56. #include "optionsdialog.moc"
  57. OptionsDialog::OptionsDialog(QWidget *parent):
  58. QDialog(parent), contents_widget(0), pages_widget(0),
  59. model(0), main_page(0), display_page(0)
  60. {
  61. contents_widget = new QListWidget();
  62. contents_widget->setMaximumWidth(128);
  63. pages_widget = new QStackedWidget();
  64. pages_widget->setMinimumWidth(300);
  65. QListWidgetItem *item_main = new QListWidgetItem(tr("Main"));
  66. contents_widget->addItem(item_main);
  67. main_page = new MainOptionsPage(this);
  68. pages_widget->addWidget(main_page);
  69. QListWidgetItem *item_display = new QListWidgetItem(tr("Display"));
  70. contents_widget->addItem(item_display);
  71. display_page = new DisplayOptionsPage(this);
  72. pages_widget->addWidget(display_page);
  73. contents_widget->setCurrentRow(0);
  74. QHBoxLayout *main_layout = new QHBoxLayout();
  75. main_layout->addWidget(contents_widget);
  76. main_layout->addWidget(pages_widget, 1);
  77. QVBoxLayout *layout = new QVBoxLayout();
  78. layout->addLayout(main_layout);
  79. QDialogButtonBox *buttonbox = new QDialogButtonBox();
  80. buttonbox->setStandardButtons(QDialogButtonBox::Apply|QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
  81. apply_button = buttonbox->button(QDialogButtonBox::Apply);
  82. layout->addWidget(buttonbox);
  83. setLayout(layout);
  84. setWindowTitle(tr("Options"));
  85. /* Widget-to-option mapper */
  86. mapper = new MonitoredDataMapper(this);
  87. mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
  88. mapper->setOrientation(Qt::Vertical);
  89. /* enable apply button when data modified */
  90. connect(mapper, SIGNAL(viewModified()), this, SLOT(enableApply()));
  91. /* disable apply button when new data loaded */
  92. connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(disableApply()));
  93. /* Event bindings */
  94. connect(contents_widget, SIGNAL(currentRowChanged(int)), this, SLOT(changePage(int)));
  95. connect(buttonbox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(okClicked()));
  96. connect(buttonbox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(cancelClicked()));
  97. connect(buttonbox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(applyClicked()));
  98. }
  99. void OptionsDialog::setModel(OptionsModel *model)
  100. {
  101. this->model = model;
  102. mapper->setModel(model);
  103. main_page->setMapper(mapper);
  104. display_page->setMapper(mapper);
  105. mapper->toFirst();
  106. }
  107. void OptionsDialog::changePage(int index)
  108. {
  109. pages_widget->setCurrentIndex(index);
  110. }
  111. void OptionsDialog::okClicked()
  112. {
  113. mapper->submit();
  114. accept();
  115. }
  116. void OptionsDialog::cancelClicked()
  117. {
  118. reject();
  119. }
  120. void OptionsDialog::applyClicked()
  121. {
  122. mapper->submit();
  123. apply_button->setEnabled(false);
  124. }
  125. void OptionsDialog::enableApply()
  126. {
  127. apply_button->setEnabled(true);
  128. }
  129. void OptionsDialog::disableApply()
  130. {
  131. apply_button->setEnabled(false);
  132. }
  133. MainOptionsPage::MainOptionsPage(QWidget *parent):
  134. QWidget(parent)
  135. {
  136. QVBoxLayout *layout = new QVBoxLayout();
  137. bitcoin_at_startup = new QCheckBox(tr("&Start Bitcoin on window system startup"));
  138. bitcoin_at_startup->setToolTip(tr("Automatically start Bitcoin after the computer is turned on"));
  139. layout->addWidget(bitcoin_at_startup);
  140. #ifndef Q_WS_MAC
  141. minimize_to_tray = new QCheckBox(tr("&Minimize to the tray instead of the taskbar"));
  142. minimize_to_tray->setToolTip(tr("Show only a tray icon after minimizing the window"));
  143. layout->addWidget(minimize_to_tray);
  144. minimize_on_close = new QCheckBox(tr("M&inimize on close"));
  145. 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."));
  146. layout->addWidget(minimize_on_close);
  147. #endif
  148. map_port_upnp = new QCheckBox(tr("Map port using &UPnP"));
  149. 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."));
  150. layout->addWidget(map_port_upnp);
  151. connect_socks4 = new QCheckBox(tr("&Connect through SOCKS4 proxy:"));
  152. connect_socks4->setToolTip(tr("Connect to the Bitcon network through a SOCKS4 proxy (e.g. when connecting through Tor)"));
  153. layout->addWidget(connect_socks4);
  154. QHBoxLayout *proxy_hbox = new QHBoxLayout();
  155. proxy_hbox->addSpacing(18);
  156. QLabel *proxy_ip_label = new QLabel(tr("Proxy &IP: "));
  157. proxy_hbox->addWidget(proxy_ip_label);
  158. proxy_ip = new QLineEdit();
  159. proxy_ip->setMaximumWidth(140);
  160. proxy_ip->setEnabled(false);
  161. proxy_ip->setValidator(new QRegExpValidator(QRegExp("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"), this));
  162. proxy_ip->setToolTip(tr("IP address of the proxy (e.g. 127.0.0.1)"));
  163. proxy_ip_label->setBuddy(proxy_ip);
  164. proxy_hbox->addWidget(proxy_ip);
  165. QLabel *proxy_port_label = new QLabel(tr("&Port: "));
  166. proxy_hbox->addWidget(proxy_port_label);
  167. proxy_port = new QLineEdit();
  168. proxy_port->setMaximumWidth(55);
  169. proxy_port->setValidator(new QIntValidator(0, 65535, this));
  170. proxy_port->setEnabled(false);
  171. proxy_port->setToolTip(tr("Port of the proxy (e.g. 1234)"));
  172. proxy_port_label->setBuddy(proxy_port);
  173. proxy_hbox->addWidget(proxy_port);
  174. proxy_hbox->addStretch(1);
  175. layout->addLayout(proxy_hbox);
  176. 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."));
  177. fee_help->setWordWrap(true);
  178. layout->addWidget(fee_help);
  179. QHBoxLayout *fee_hbox = new QHBoxLayout();
  180. fee_hbox->addSpacing(18);
  181. QLabel *fee_label = new QLabel(tr("Pay transaction &fee"));
  182. fee_hbox->addWidget(fee_label);
  183. fee_edit = new BitcoinAmountField();
  184. fee_label->setBuddy(fee_edit);
  185. fee_hbox->addWidget(fee_edit);
  186. fee_hbox->addStretch(1);
  187. layout->addLayout(fee_hbox);
  188. detach_database = new QCheckBox(tr("Detach databases at shutdown"));
  189. 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."));
  190. layout->addWidget(detach_database);
  191. layout->addStretch(1); // Extra space at bottom
  192. setLayout(layout);
  193. connect(connect_socks4, SIGNAL(toggled(bool)), proxy_ip, SLOT(setEnabled(bool)));
  194. connect(connect_socks4, SIGNAL(toggled(bool)), proxy_port, SLOT(setEnabled(bool)));
  195. #ifndef USE_UPNP
  196. map_port_upnp->setDisabled(true);
  197. #endif
  198. }
  199. void MainOptionsPage::setMapper(MonitoredDataMapper *mapper)
  200. {
  201. // Map model to widgets
  202. mapper->addMapping(bitcoin_at_startup, OptionsModel::StartAtStartup);
  203. #ifndef Q_WS_MAC
  204. mapper->addMapping(minimize_to_tray, OptionsModel::MinimizeToTray);
  205. #endif
  206. mapper->addMapping(map_port_upnp, OptionsModel::MapPortUPnP);
  207. #ifndef Q_WS_MAC
  208. mapper->addMapping(minimize_on_close, OptionsModel::MinimizeOnClose);
  209. #endif
  210. mapper->addMapping(connect_socks4, OptionsModel::ConnectSOCKS4);
  211. mapper->addMapping(proxy_ip, OptionsModel::ProxyIP);
  212. mapper->addMapping(proxy_port, OptionsModel::ProxyPort);
  213. mapper->addMapping(fee_edit, OptionsModel::Fee);
  214. mapper->addMapping(detach_database, OptionsModel::DetachDatabases);
  215. }
  216. DisplayOptionsPage::DisplayOptionsPage(QWidget *parent):
  217. QWidget(parent)
  218. {
  219. QVBoxLayout *layout = new QVBoxLayout();
  220. QHBoxLayout *unit_hbox = new QHBoxLayout();
  221. unit_hbox->addSpacing(18);
  222. QLabel *unit_label = new QLabel(tr("&Unit to show amounts in: "));
  223. unit_hbox->addWidget(unit_label);
  224. unit = new QValueComboBox(this);
  225. unit->setModel(new BitcoinUnits(this));
  226. unit->setToolTip(tr("Choose the default subdivision unit to show in the interface, and when sending coins"));
  227. unit_label->setBuddy(unit);
  228. unit_hbox->addWidget(unit);
  229. layout->addLayout(unit_hbox);
  230. display_addresses = new QCheckBox(tr("&Display addresses in transaction list"), this);
  231. display_addresses->setToolTip(tr("Whether to show Bitcoin addresses in the transaction list"));
  232. layout->addWidget(display_addresses);
  233. layout->addStretch();
  234. setLayout(layout);
  235. }
  236. void DisplayOptionsPage::setMapper(MonitoredDataMapper *mapper)
  237. {
  238. mapper->addMapping(unit, OptionsModel::DisplayUnit);
  239. mapper->addMapping(display_addresses, OptionsModel::DisplayAddresses);
  240. }