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.0KB

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