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.

bitcoingui.cpp 44KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. // Copyright (c) 2011-2017 The Bitcoin Core developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #include <qt/bitcoingui.h>
  5. #include <qt/bitcoinunits.h>
  6. #include <qt/clientmodel.h>
  7. #include <qt/guiconstants.h>
  8. #include <qt/guiutil.h>
  9. #include <qt/modaloverlay.h>
  10. #include <qt/networkstyle.h>
  11. #include <qt/notificator.h>
  12. #include <qt/openuridialog.h>
  13. #include <qt/optionsdialog.h>
  14. #include <qt/optionsmodel.h>
  15. #include <qt/platformstyle.h>
  16. #include <qt/rpcconsole.h>
  17. #include <qt/utilitydialog.h>
  18. #ifdef ENABLE_WALLET
  19. #include <qt/walletframe.h>
  20. #include <qt/walletmodel.h>
  21. #endif // ENABLE_WALLET
  22. #ifdef Q_OS_MAC
  23. #include <qt/macdockiconhandler.h>
  24. #endif
  25. #include <chainparams.h>
  26. #include <init.h>
  27. #include <ui_interface.h>
  28. #include <util.h>
  29. #include <iostream>
  30. #include <QAction>
  31. #include <QApplication>
  32. #include <QDateTime>
  33. #include <QDesktopWidget>
  34. #include <QDragEnterEvent>
  35. #include <QListWidget>
  36. #include <QMenuBar>
  37. #include <QMessageBox>
  38. #include <QMimeData>
  39. #include <QProgressDialog>
  40. #include <QSettings>
  41. #include <QShortcut>
  42. #include <QStackedWidget>
  43. #include <QStatusBar>
  44. #include <QStyle>
  45. #include <QTimer>
  46. #include <QToolBar>
  47. #include <QVBoxLayout>
  48. #if QT_VERSION < 0x050000
  49. #include <QTextDocument>
  50. #include <QUrl>
  51. #else
  52. #include <QUrlQuery>
  53. #endif
  54. const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
  55. #if defined(Q_OS_MAC)
  56. "macosx"
  57. #elif defined(Q_OS_WIN)
  58. "windows"
  59. #else
  60. "other"
  61. #endif
  62. ;
  63. /** Display name for default wallet name. Uses tilde to avoid name
  64. * collisions in the future with additional wallets */
  65. const QString BitcoinGUI::DEFAULT_WALLET = "~Default";
  66. BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
  67. QMainWindow(parent),
  68. enableWallet(false),
  69. clientModel(0),
  70. walletFrame(0),
  71. unitDisplayControl(0),
  72. labelWalletEncryptionIcon(0),
  73. labelWalletHDStatusIcon(0),
  74. connectionsControl(0),
  75. labelBlocksIcon(0),
  76. progressBarLabel(0),
  77. progressBar(0),
  78. progressDialog(0),
  79. appMenuBar(0),
  80. overviewAction(0),
  81. historyAction(0),
  82. quitAction(0),
  83. sendCoinsAction(0),
  84. sendCoinsMenuAction(0),
  85. usedSendingAddressesAction(0),
  86. usedReceivingAddressesAction(0),
  87. signMessageAction(0),
  88. verifyMessageAction(0),
  89. aboutAction(0),
  90. receiveCoinsAction(0),
  91. receiveCoinsMenuAction(0),
  92. optionsAction(0),
  93. toggleHideAction(0),
  94. encryptWalletAction(0),
  95. backupWalletAction(0),
  96. changePassphraseAction(0),
  97. aboutQtAction(0),
  98. openRPCConsoleAction(0),
  99. openAction(0),
  100. showHelpMessageAction(0),
  101. trayIcon(0),
  102. trayIconMenu(0),
  103. notificator(0),
  104. rpcConsole(0),
  105. helpMessageDialog(0),
  106. modalOverlay(0),
  107. prevBlocks(0),
  108. spinnerFrame(0),
  109. platformStyle(_platformStyle)
  110. {
  111. QSettings settings;
  112. if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
  113. // Restore failed (perhaps missing setting), center the window
  114. move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
  115. }
  116. QString windowTitle = tr(PACKAGE_NAME) + " - ";
  117. #ifdef ENABLE_WALLET
  118. enableWallet = WalletModel::isWalletEnabled();
  119. #endif // ENABLE_WALLET
  120. if(enableWallet)
  121. {
  122. windowTitle += tr("Wallet");
  123. } else {
  124. windowTitle += tr("Node");
  125. }
  126. windowTitle += " " + networkStyle->getTitleAddText();
  127. #ifndef Q_OS_MAC
  128. QApplication::setWindowIcon(networkStyle->getTrayAndWindowIcon());
  129. setWindowIcon(networkStyle->getTrayAndWindowIcon());
  130. #else
  131. MacDockIconHandler::instance()->setIcon(networkStyle->getAppIcon());
  132. #endif
  133. setWindowTitle(windowTitle);
  134. #if defined(Q_OS_MAC) && QT_VERSION < 0x050000
  135. // This property is not implemented in Qt 5. Setting it has no effect.
  136. // A replacement API (QtMacUnifiedToolBar) is available in QtMacExtras.
  137. setUnifiedTitleAndToolBarOnMac(true);
  138. #endif
  139. rpcConsole = new RPCConsole(_platformStyle, 0);
  140. helpMessageDialog = new HelpMessageDialog(this, false);
  141. #ifdef ENABLE_WALLET
  142. if(enableWallet)
  143. {
  144. /** Create wallet frame and make it the central widget */
  145. walletFrame = new WalletFrame(_platformStyle, this);
  146. setCentralWidget(walletFrame);
  147. } else
  148. #endif // ENABLE_WALLET
  149. {
  150. /* When compiled without wallet or -disablewallet is provided,
  151. * the central widget is the rpc console.
  152. */
  153. setCentralWidget(rpcConsole);
  154. }
  155. // Accept D&D of URIs
  156. setAcceptDrops(true);
  157. // Create actions for the toolbar, menu bar and tray/dock icon
  158. // Needs walletFrame to be initialized
  159. createActions();
  160. // Create application menu bar
  161. createMenuBar();
  162. // Create the toolbars
  163. createToolBars();
  164. // Create system tray icon and notification
  165. createTrayIcon(networkStyle);
  166. // Create status bar
  167. statusBar();
  168. // Disable size grip because it looks ugly and nobody needs it
  169. statusBar()->setSizeGripEnabled(false);
  170. // Status bar notification icons
  171. QFrame *frameBlocks = new QFrame();
  172. frameBlocks->setContentsMargins(0,0,0,0);
  173. frameBlocks->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
  174. QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
  175. frameBlocksLayout->setContentsMargins(3,0,3,0);
  176. frameBlocksLayout->setSpacing(3);
  177. unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle);
  178. labelWalletEncryptionIcon = new QLabel();
  179. labelWalletHDStatusIcon = new QLabel();
  180. connectionsControl = new GUIUtil::ClickableLabel();
  181. labelBlocksIcon = new GUIUtil::ClickableLabel();
  182. if(enableWallet)
  183. {
  184. frameBlocksLayout->addStretch();
  185. frameBlocksLayout->addWidget(unitDisplayControl);
  186. frameBlocksLayout->addStretch();
  187. frameBlocksLayout->addWidget(labelWalletEncryptionIcon);
  188. frameBlocksLayout->addWidget(labelWalletHDStatusIcon);
  189. }
  190. frameBlocksLayout->addStretch();
  191. frameBlocksLayout->addWidget(connectionsControl);
  192. frameBlocksLayout->addStretch();
  193. frameBlocksLayout->addWidget(labelBlocksIcon);
  194. frameBlocksLayout->addStretch();
  195. // Progress bar and label for blocks download
  196. progressBarLabel = new QLabel();
  197. progressBarLabel->setVisible(false);
  198. progressBar = new GUIUtil::ProgressBar();
  199. progressBar->setAlignment(Qt::AlignCenter);
  200. progressBar->setVisible(false);
  201. // Override style sheet for progress bar for styles that have a segmented progress bar,
  202. // as they make the text unreadable (workaround for issue #1071)
  203. // See https://qt-project.org/doc/qt-4.8/gallery.html
  204. QString curStyle = QApplication::style()->metaObject()->className();
  205. if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
  206. {
  207. progressBar->setStyleSheet("QProgressBar { background-color: #e8e8e8; border: 1px solid grey; border-radius: 7px; padding: 1px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF8000, stop: 1 orange); border-radius: 7px; margin: 0px; }");
  208. }
  209. statusBar()->addWidget(progressBarLabel);
  210. statusBar()->addWidget(progressBar);
  211. statusBar()->addPermanentWidget(frameBlocks);
  212. // Install event filter to be able to catch status tip events (QEvent::StatusTip)
  213. this->installEventFilter(this);
  214. // Initially wallet actions should be disabled
  215. setWalletActionsEnabled(false);
  216. // Subscribe to notifications from core
  217. subscribeToCoreSignals();
  218. connect(connectionsControl, SIGNAL(clicked(QPoint)), this, SLOT(toggleNetworkActive()));
  219. modalOverlay = new ModalOverlay(this->centralWidget());
  220. #ifdef ENABLE_WALLET
  221. if(enableWallet) {
  222. connect(walletFrame, SIGNAL(requestedSyncWarningInfo()), this, SLOT(showModalOverlay()));
  223. connect(labelBlocksIcon, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
  224. connect(progressBar, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
  225. }
  226. #endif
  227. }
  228. BitcoinGUI::~BitcoinGUI()
  229. {
  230. // Unsubscribe from notifications from core
  231. unsubscribeFromCoreSignals();
  232. QSettings settings;
  233. settings.setValue("MainWindowGeometry", saveGeometry());
  234. if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
  235. trayIcon->hide();
  236. #ifdef Q_OS_MAC
  237. delete appMenuBar;
  238. MacDockIconHandler::cleanup();
  239. #endif
  240. delete rpcConsole;
  241. }
  242. void BitcoinGUI::createActions()
  243. {
  244. QActionGroup *tabGroup = new QActionGroup(this);
  245. overviewAction = new QAction(platformStyle->SingleColorIcon(":/icons/overview"), tr("&Overview"), this);
  246. overviewAction->setStatusTip(tr("Show general overview of wallet"));
  247. overviewAction->setToolTip(overviewAction->statusTip());
  248. overviewAction->setCheckable(true);
  249. overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
  250. tabGroup->addAction(overviewAction);
  251. sendCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/send"), tr("&Send"), this);
  252. sendCoinsAction->setStatusTip(tr("Send coins to a Bitcoin address"));
  253. sendCoinsAction->setToolTip(sendCoinsAction->statusTip());
  254. sendCoinsAction->setCheckable(true);
  255. sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
  256. tabGroup->addAction(sendCoinsAction);
  257. sendCoinsMenuAction = new QAction(platformStyle->TextColorIcon(":/icons/send"), sendCoinsAction->text(), this);
  258. sendCoinsMenuAction->setStatusTip(sendCoinsAction->statusTip());
  259. sendCoinsMenuAction->setToolTip(sendCoinsMenuAction->statusTip());
  260. receiveCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/receiving_addresses"), tr("&Receive"), this);
  261. receiveCoinsAction->setStatusTip(tr("Request payments (generates QR codes and bitcoin: URIs)"));
  262. receiveCoinsAction->setToolTip(receiveCoinsAction->statusTip());
  263. receiveCoinsAction->setCheckable(true);
  264. receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
  265. tabGroup->addAction(receiveCoinsAction);
  266. receiveCoinsMenuAction = new QAction(platformStyle->TextColorIcon(":/icons/receiving_addresses"), receiveCoinsAction->text(), this);
  267. receiveCoinsMenuAction->setStatusTip(receiveCoinsAction->statusTip());
  268. receiveCoinsMenuAction->setToolTip(receiveCoinsMenuAction->statusTip());
  269. historyAction = new QAction(platformStyle->SingleColorIcon(":/icons/history"), tr("&Transactions"), this);
  270. historyAction->setStatusTip(tr("Browse transaction history"));
  271. historyAction->setToolTip(historyAction->statusTip());
  272. historyAction->setCheckable(true);
  273. historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
  274. tabGroup->addAction(historyAction);
  275. #ifdef ENABLE_WALLET
  276. // These showNormalIfMinimized are needed because Send Coins and Receive Coins
  277. // can be triggered from the tray menu, and need to show the GUI to be useful.
  278. connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
  279. connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
  280. connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
  281. connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
  282. connect(sendCoinsMenuAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
  283. connect(sendCoinsMenuAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
  284. connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
  285. connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
  286. connect(receiveCoinsMenuAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
  287. connect(receiveCoinsMenuAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
  288. connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
  289. connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
  290. #endif // ENABLE_WALLET
  291. quitAction = new QAction(platformStyle->TextColorIcon(":/icons/quit"), tr("E&xit"), this);
  292. quitAction->setStatusTip(tr("Quit application"));
  293. quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
  294. quitAction->setMenuRole(QAction::QuitRole);
  295. aboutAction = new QAction(platformStyle->TextColorIcon(":/icons/about"), tr("&About %1").arg(tr(PACKAGE_NAME)), this);
  296. aboutAction->setStatusTip(tr("Show information about %1").arg(tr(PACKAGE_NAME)));
  297. aboutAction->setMenuRole(QAction::AboutRole);
  298. aboutAction->setEnabled(false);
  299. aboutQtAction = new QAction(platformStyle->TextColorIcon(":/icons/about_qt"), tr("About &Qt"), this);
  300. aboutQtAction->setStatusTip(tr("Show information about Qt"));
  301. aboutQtAction->setMenuRole(QAction::AboutQtRole);
  302. optionsAction = new QAction(platformStyle->TextColorIcon(":/icons/options"), tr("&Options..."), this);
  303. optionsAction->setStatusTip(tr("Modify configuration options for %1").arg(tr(PACKAGE_NAME)));
  304. optionsAction->setMenuRole(QAction::PreferencesRole);
  305. optionsAction->setEnabled(false);
  306. toggleHideAction = new QAction(platformStyle->TextColorIcon(":/icons/about"), tr("&Show / Hide"), this);
  307. toggleHideAction->setStatusTip(tr("Show or hide the main Window"));
  308. encryptWalletAction = new QAction(platformStyle->TextColorIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
  309. encryptWalletAction->setStatusTip(tr("Encrypt the private keys that belong to your wallet"));
  310. encryptWalletAction->setCheckable(true);
  311. backupWalletAction = new QAction(platformStyle->TextColorIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
  312. backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
  313. changePassphraseAction = new QAction(platformStyle->TextColorIcon(":/icons/key"), tr("&Change Passphrase..."), this);
  314. changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
  315. signMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/edit"), tr("Sign &message..."), this);
  316. signMessageAction->setStatusTip(tr("Sign messages with your Bitcoin addresses to prove you own them"));
  317. verifyMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/verify"), tr("&Verify message..."), this);
  318. verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Bitcoin addresses"));
  319. openRPCConsoleAction = new QAction(platformStyle->TextColorIcon(":/icons/debugwindow"), tr("&Debug window"), this);
  320. openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
  321. // initially disable the debug window menu item
  322. openRPCConsoleAction->setEnabled(false);
  323. usedSendingAddressesAction = new QAction(platformStyle->TextColorIcon(":/icons/address-book"), tr("&Sending addresses..."), this);
  324. usedSendingAddressesAction->setStatusTip(tr("Show the list of used sending addresses and labels"));
  325. usedReceivingAddressesAction = new QAction(platformStyle->TextColorIcon(":/icons/address-book"), tr("&Receiving addresses..."), this);
  326. usedReceivingAddressesAction->setStatusTip(tr("Show the list of used receiving addresses and labels"));
  327. openAction = new QAction(platformStyle->TextColorIcon(":/icons/open"), tr("Open &URI..."), this);
  328. openAction->setStatusTip(tr("Open a bitcoin: URI or payment request"));
  329. showHelpMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/info"), tr("&Command-line options"), this);
  330. showHelpMessageAction->setMenuRole(QAction::NoRole);
  331. showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Bitcoin command-line options").arg(tr(PACKAGE_NAME)));
  332. connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
  333. connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
  334. connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
  335. connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
  336. connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
  337. connect(showHelpMessageAction, SIGNAL(triggered()), this, SLOT(showHelpMessageClicked()));
  338. connect(openRPCConsoleAction, SIGNAL(triggered()), this, SLOT(showDebugWindow()));
  339. // prevents an open debug window from becoming stuck/unusable on client shutdown
  340. connect(quitAction, SIGNAL(triggered()), rpcConsole, SLOT(hide()));
  341. #ifdef ENABLE_WALLET
  342. if(walletFrame)
  343. {
  344. connect(encryptWalletAction, SIGNAL(triggered(bool)), walletFrame, SLOT(encryptWallet(bool)));
  345. connect(backupWalletAction, SIGNAL(triggered()), walletFrame, SLOT(backupWallet()));
  346. connect(changePassphraseAction, SIGNAL(triggered()), walletFrame, SLOT(changePassphrase()));
  347. connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
  348. connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
  349. connect(usedSendingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedSendingAddresses()));
  350. connect(usedReceivingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedReceivingAddresses()));
  351. connect(openAction, SIGNAL(triggered()), this, SLOT(openClicked()));
  352. }
  353. #endif // ENABLE_WALLET
  354. new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C), this, SLOT(showDebugWindowActivateConsole()));
  355. new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D), this, SLOT(showDebugWindow()));
  356. }
  357. void BitcoinGUI::createMenuBar()
  358. {
  359. #ifdef Q_OS_MAC
  360. // Create a decoupled menu bar on Mac which stays even if the window is closed
  361. appMenuBar = new QMenuBar();
  362. #else
  363. // Get the main window's menu bar on other platforms
  364. appMenuBar = menuBar();
  365. #endif
  366. // Configure the menus
  367. QMenu *file = appMenuBar->addMenu(tr("&File"));
  368. if(walletFrame)
  369. {
  370. file->addAction(openAction);
  371. file->addAction(backupWalletAction);
  372. file->addAction(signMessageAction);
  373. file->addAction(verifyMessageAction);
  374. file->addSeparator();
  375. file->addAction(usedSendingAddressesAction);
  376. file->addAction(usedReceivingAddressesAction);
  377. file->addSeparator();
  378. }
  379. file->addAction(quitAction);
  380. QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
  381. if(walletFrame)
  382. {
  383. settings->addAction(encryptWalletAction);
  384. settings->addAction(changePassphraseAction);
  385. settings->addSeparator();
  386. }
  387. settings->addAction(optionsAction);
  388. QMenu *help = appMenuBar->addMenu(tr("&Help"));
  389. if(walletFrame)
  390. {
  391. help->addAction(openRPCConsoleAction);
  392. }
  393. help->addAction(showHelpMessageAction);
  394. help->addSeparator();
  395. help->addAction(aboutAction);
  396. help->addAction(aboutQtAction);
  397. }
  398. void BitcoinGUI::createToolBars()
  399. {
  400. if(walletFrame)
  401. {
  402. QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
  403. toolbar->setContextMenuPolicy(Qt::PreventContextMenu);
  404. toolbar->setMovable(false);
  405. toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
  406. toolbar->addAction(overviewAction);
  407. toolbar->addAction(sendCoinsAction);
  408. toolbar->addAction(receiveCoinsAction);
  409. toolbar->addAction(historyAction);
  410. overviewAction->setChecked(true);
  411. }
  412. }
  413. void BitcoinGUI::setClientModel(ClientModel *_clientModel)
  414. {
  415. this->clientModel = _clientModel;
  416. if(_clientModel)
  417. {
  418. // Create system tray menu (or setup the dock menu) that late to prevent users from calling actions,
  419. // while the client has not yet fully loaded
  420. createTrayIconMenu();
  421. // Keep up to date with client
  422. updateNetworkState();
  423. connect(_clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
  424. connect(_clientModel, SIGNAL(networkActiveChanged(bool)), this, SLOT(setNetworkActive(bool)));
  425. modalOverlay->setKnownBestHeight(_clientModel->getHeaderTipHeight(), QDateTime::fromTime_t(_clientModel->getHeaderTipTime()));
  426. setNumBlocks(_clientModel->getNumBlocks(), _clientModel->getLastBlockDate(), _clientModel->getVerificationProgress(nullptr), false);
  427. connect(_clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool)));
  428. // Receive and report messages from client model
  429. connect(_clientModel, SIGNAL(message(QString,QString,unsigned int)), this, SLOT(message(QString,QString,unsigned int)));
  430. // Show progress dialog
  431. connect(_clientModel, SIGNAL(showProgress(QString,int)), this, SLOT(showProgress(QString,int)));
  432. rpcConsole->setClientModel(_clientModel);
  433. #ifdef ENABLE_WALLET
  434. if(walletFrame)
  435. {
  436. walletFrame->setClientModel(_clientModel);
  437. }
  438. #endif // ENABLE_WALLET
  439. unitDisplayControl->setOptionsModel(_clientModel->getOptionsModel());
  440. OptionsModel* optionsModel = _clientModel->getOptionsModel();
  441. if(optionsModel)
  442. {
  443. // be aware of the tray icon disable state change reported by the OptionsModel object.
  444. connect(optionsModel,SIGNAL(hideTrayIconChanged(bool)),this,SLOT(setTrayIconVisible(bool)));
  445. // initialize the disable state of the tray icon with the current value in the model.
  446. setTrayIconVisible(optionsModel->getHideTrayIcon());
  447. }
  448. } else {
  449. // Disable possibility to show main window via action
  450. toggleHideAction->setEnabled(false);
  451. if(trayIconMenu)
  452. {
  453. // Disable context menu on tray icon
  454. trayIconMenu->clear();
  455. }
  456. // Propagate cleared model to child objects
  457. rpcConsole->setClientModel(nullptr);
  458. #ifdef ENABLE_WALLET
  459. if (walletFrame)
  460. {
  461. walletFrame->setClientModel(nullptr);
  462. }
  463. #endif // ENABLE_WALLET
  464. unitDisplayControl->setOptionsModel(nullptr);
  465. }
  466. }
  467. #ifdef ENABLE_WALLET
  468. bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel)
  469. {
  470. if(!walletFrame)
  471. return false;
  472. setWalletActionsEnabled(true);
  473. return walletFrame->addWallet(name, walletModel);
  474. }
  475. bool BitcoinGUI::setCurrentWallet(const QString& name)
  476. {
  477. if(!walletFrame)
  478. return false;
  479. return walletFrame->setCurrentWallet(name);
  480. }
  481. void BitcoinGUI::removeAllWallets()
  482. {
  483. if(!walletFrame)
  484. return;
  485. setWalletActionsEnabled(false);
  486. walletFrame->removeAllWallets();
  487. }
  488. #endif // ENABLE_WALLET
  489. void BitcoinGUI::setWalletActionsEnabled(bool enabled)
  490. {
  491. overviewAction->setEnabled(enabled);
  492. sendCoinsAction->setEnabled(enabled);
  493. sendCoinsMenuAction->setEnabled(enabled);
  494. receiveCoinsAction->setEnabled(enabled);
  495. receiveCoinsMenuAction->setEnabled(enabled);
  496. historyAction->setEnabled(enabled);
  497. encryptWalletAction->setEnabled(enabled);
  498. backupWalletAction->setEnabled(enabled);
  499. changePassphraseAction->setEnabled(enabled);
  500. signMessageAction->setEnabled(enabled);
  501. verifyMessageAction->setEnabled(enabled);
  502. usedSendingAddressesAction->setEnabled(enabled);
  503. usedReceivingAddressesAction->setEnabled(enabled);
  504. openAction->setEnabled(enabled);
  505. }
  506. void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle)
  507. {
  508. #ifndef Q_OS_MAC
  509. trayIcon = new QSystemTrayIcon(this);
  510. QString toolTip = tr("%1 client").arg(tr(PACKAGE_NAME)) + " " + networkStyle->getTitleAddText();
  511. trayIcon->setToolTip(toolTip);
  512. trayIcon->setIcon(networkStyle->getTrayAndWindowIcon());
  513. trayIcon->hide();
  514. #endif
  515. notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
  516. }
  517. void BitcoinGUI::createTrayIconMenu()
  518. {
  519. #ifndef Q_OS_MAC
  520. // return if trayIcon is unset (only on non-Mac OSes)
  521. if (!trayIcon)
  522. return;
  523. trayIconMenu = new QMenu(this);
  524. trayIcon->setContextMenu(trayIconMenu);
  525. connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
  526. this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
  527. #else
  528. // Note: On Mac, the dock icon is used to provide the tray's functionality.
  529. MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
  530. dockIconHandler->setMainWindow((QMainWindow *)this);
  531. trayIconMenu = dockIconHandler->dockMenu();
  532. #endif
  533. // Configuration of the tray icon (or dock icon) icon menu
  534. trayIconMenu->addAction(toggleHideAction);
  535. trayIconMenu->addSeparator();
  536. trayIconMenu->addAction(sendCoinsMenuAction);
  537. trayIconMenu->addAction(receiveCoinsMenuAction);
  538. trayIconMenu->addSeparator();
  539. trayIconMenu->addAction(signMessageAction);
  540. trayIconMenu->addAction(verifyMessageAction);
  541. trayIconMenu->addSeparator();
  542. trayIconMenu->addAction(optionsAction);
  543. trayIconMenu->addAction(openRPCConsoleAction);
  544. #ifndef Q_OS_MAC // This is built-in on Mac
  545. trayIconMenu->addSeparator();
  546. trayIconMenu->addAction(quitAction);
  547. #endif
  548. }
  549. #ifndef Q_OS_MAC
  550. void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
  551. {
  552. if(reason == QSystemTrayIcon::Trigger)
  553. {
  554. // Click on system tray icon triggers show/hide of the main window
  555. toggleHidden();
  556. }
  557. }
  558. #endif
  559. void BitcoinGUI::optionsClicked()
  560. {
  561. if(!clientModel || !clientModel->getOptionsModel())
  562. return;
  563. OptionsDialog dlg(this, enableWallet);
  564. dlg.setModel(clientModel->getOptionsModel());
  565. dlg.exec();
  566. }
  567. void BitcoinGUI::aboutClicked()
  568. {
  569. if(!clientModel)
  570. return;
  571. HelpMessageDialog dlg(this, true);
  572. dlg.exec();
  573. }
  574. void BitcoinGUI::showDebugWindow()
  575. {
  576. rpcConsole->showNormal();
  577. rpcConsole->show();
  578. rpcConsole->raise();
  579. rpcConsole->activateWindow();
  580. }
  581. void BitcoinGUI::showDebugWindowActivateConsole()
  582. {
  583. rpcConsole->setTabFocus(RPCConsole::TAB_CONSOLE);
  584. showDebugWindow();
  585. }
  586. void BitcoinGUI::showHelpMessageClicked()
  587. {
  588. helpMessageDialog->show();
  589. }
  590. #ifdef ENABLE_WALLET
  591. void BitcoinGUI::openClicked()
  592. {
  593. OpenURIDialog dlg(this);
  594. if(dlg.exec())
  595. {
  596. Q_EMIT receivedURI(dlg.getURI());
  597. }
  598. }
  599. void BitcoinGUI::gotoOverviewPage()
  600. {
  601. overviewAction->setChecked(true);
  602. if (walletFrame) walletFrame->gotoOverviewPage();
  603. }
  604. void BitcoinGUI::gotoHistoryPage()
  605. {
  606. historyAction->setChecked(true);
  607. if (walletFrame) walletFrame->gotoHistoryPage();
  608. }
  609. void BitcoinGUI::gotoReceiveCoinsPage()
  610. {
  611. receiveCoinsAction->setChecked(true);
  612. if (walletFrame) walletFrame->gotoReceiveCoinsPage();
  613. }
  614. void BitcoinGUI::gotoSendCoinsPage(QString addr)
  615. {
  616. sendCoinsAction->setChecked(true);
  617. if (walletFrame) walletFrame->gotoSendCoinsPage(addr);
  618. }
  619. void BitcoinGUI::gotoSignMessageTab(QString addr)
  620. {
  621. if (walletFrame) walletFrame->gotoSignMessageTab(addr);
  622. }
  623. void BitcoinGUI::gotoVerifyMessageTab(QString addr)
  624. {
  625. if (walletFrame) walletFrame->gotoVerifyMessageTab(addr);
  626. }
  627. #endif // ENABLE_WALLET
  628. void BitcoinGUI::updateNetworkState()
  629. {
  630. int count = clientModel->getNumConnections();
  631. QString icon;
  632. switch(count)
  633. {
  634. case 0: icon = ":/icons/connect_0"; break;
  635. case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
  636. case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
  637. case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
  638. default: icon = ":/icons/connect_4"; break;
  639. }
  640. QString tooltip;
  641. if (clientModel->getNetworkActive()) {
  642. tooltip = tr("%n active connection(s) to Bitcoin network", "", count) + QString(".<br>") + tr("Click to disable network activity.");
  643. } else {
  644. tooltip = tr("Network activity disabled.") + QString("<br>") + tr("Click to enable network activity again.");
  645. icon = ":/icons/network_disabled";
  646. }
  647. // Don't word-wrap this (fixed-width) tooltip
  648. tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
  649. connectionsControl->setToolTip(tooltip);
  650. connectionsControl->setPixmap(platformStyle->SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
  651. }
  652. void BitcoinGUI::setNumConnections(int count)
  653. {
  654. updateNetworkState();
  655. }
  656. void BitcoinGUI::setNetworkActive(bool networkActive)
  657. {
  658. updateNetworkState();
  659. }
  660. void BitcoinGUI::updateHeadersSyncProgressLabel()
  661. {
  662. int64_t headersTipTime = clientModel->getHeaderTipTime();
  663. int headersTipHeight = clientModel->getHeaderTipHeight();
  664. int estHeadersLeft = (GetTime() - headersTipTime) / Params().GetConsensus().nPowTargetSpacing;
  665. if (estHeadersLeft > HEADER_HEIGHT_DELTA_SYNC)
  666. progressBarLabel->setText(tr("Syncing Headers (%1%)...").arg(QString::number(100.0 / (headersTipHeight+estHeadersLeft)*headersTipHeight, 'f', 1)));
  667. }
  668. void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool header)
  669. {
  670. if (modalOverlay)
  671. {
  672. if (header)
  673. modalOverlay->setKnownBestHeight(count, blockDate);
  674. else
  675. modalOverlay->tipUpdate(count, blockDate, nVerificationProgress);
  676. }
  677. if (!clientModel)
  678. return;
  679. // Prevent orphan statusbar messages (e.g. hover Quit in main menu, wait until chain-sync starts -> garbled text)
  680. statusBar()->clearMessage();
  681. // Acquire current block source
  682. enum BlockSource blockSource = clientModel->getBlockSource();
  683. switch (blockSource) {
  684. case BLOCK_SOURCE_NETWORK:
  685. if (header) {
  686. updateHeadersSyncProgressLabel();
  687. return;
  688. }
  689. progressBarLabel->setText(tr("Synchronizing with network..."));
  690. updateHeadersSyncProgressLabel();
  691. break;
  692. case BLOCK_SOURCE_DISK:
  693. if (header) {
  694. progressBarLabel->setText(tr("Indexing blocks on disk..."));
  695. } else {
  696. progressBarLabel->setText(tr("Processing blocks on disk..."));
  697. }
  698. break;
  699. case BLOCK_SOURCE_REINDEX:
  700. progressBarLabel->setText(tr("Reindexing blocks on disk..."));
  701. break;
  702. case BLOCK_SOURCE_NONE:
  703. if (header) {
  704. return;
  705. }
  706. progressBarLabel->setText(tr("Connecting to peers..."));
  707. break;
  708. }
  709. QString tooltip;
  710. QDateTime currentDate = QDateTime::currentDateTime();
  711. qint64 secs = blockDate.secsTo(currentDate);
  712. tooltip = tr("Processed %n block(s) of transaction history.", "", count);
  713. // Set icon state: spinning if catching up, tick otherwise
  714. if(secs < 90*60)
  715. {
  716. tooltip = tr("Up to date") + QString(".<br>") + tooltip;
  717. labelBlocksIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
  718. #ifdef ENABLE_WALLET
  719. if(walletFrame)
  720. {
  721. walletFrame->showOutOfSyncWarning(false);
  722. modalOverlay->showHide(true, true);
  723. }
  724. #endif // ENABLE_WALLET
  725. progressBarLabel->setVisible(false);
  726. progressBar->setVisible(false);
  727. }
  728. else
  729. {
  730. QString timeBehindText = GUIUtil::formatNiceTimeOffset(secs);
  731. progressBarLabel->setVisible(true);
  732. progressBar->setFormat(tr("%1 behind").arg(timeBehindText));
  733. progressBar->setMaximum(1000000000);
  734. progressBar->setValue(nVerificationProgress * 1000000000.0 + 0.5);
  735. progressBar->setVisible(true);
  736. tooltip = tr("Catching up...") + QString("<br>") + tooltip;
  737. if(count != prevBlocks)
  738. {
  739. labelBlocksIcon->setPixmap(platformStyle->SingleColorIcon(QString(
  740. ":/movies/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0')))
  741. .pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
  742. spinnerFrame = (spinnerFrame + 1) % SPINNER_FRAMES;
  743. }
  744. prevBlocks = count;
  745. #ifdef ENABLE_WALLET
  746. if(walletFrame)
  747. {
  748. walletFrame->showOutOfSyncWarning(true);
  749. modalOverlay->showHide();
  750. }
  751. #endif // ENABLE_WALLET
  752. tooltip += QString("<br>");
  753. tooltip += tr("Last received block was generated %1 ago.").arg(timeBehindText);
  754. tooltip += QString("<br>");
  755. tooltip += tr("Transactions after this will not yet be visible.");
  756. }
  757. // Don't word-wrap this (fixed-width) tooltip
  758. tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
  759. labelBlocksIcon->setToolTip(tooltip);
  760. progressBarLabel->setToolTip(tooltip);
  761. progressBar->setToolTip(tooltip);
  762. }
  763. void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, bool *ret)
  764. {
  765. QString strTitle = tr("Bitcoin"); // default title
  766. // Default to information icon
  767. int nMBoxIcon = QMessageBox::Information;
  768. int nNotifyIcon = Notificator::Information;
  769. QString msgType;
  770. // Prefer supplied title over style based title
  771. if (!title.isEmpty()) {
  772. msgType = title;
  773. }
  774. else {
  775. switch (style) {
  776. case CClientUIInterface::MSG_ERROR:
  777. msgType = tr("Error");
  778. break;
  779. case CClientUIInterface::MSG_WARNING:
  780. msgType = tr("Warning");
  781. break;
  782. case CClientUIInterface::MSG_INFORMATION:
  783. msgType = tr("Information");
  784. break;
  785. default:
  786. break;
  787. }
  788. }
  789. // Append title to "Bitcoin - "
  790. if (!msgType.isEmpty())
  791. strTitle += " - " + msgType;
  792. // Check for error/warning icon
  793. if (style & CClientUIInterface::ICON_ERROR) {
  794. nMBoxIcon = QMessageBox::Critical;
  795. nNotifyIcon = Notificator::Critical;
  796. }
  797. else if (style & CClientUIInterface::ICON_WARNING) {
  798. nMBoxIcon = QMessageBox::Warning;
  799. nNotifyIcon = Notificator::Warning;
  800. }
  801. // Display message
  802. if (style & CClientUIInterface::MODAL) {
  803. // Check for buttons, use OK as default, if none was supplied
  804. QMessageBox::StandardButton buttons;
  805. if (!(buttons = (QMessageBox::StandardButton)(style & CClientUIInterface::BTN_MASK)))
  806. buttons = QMessageBox::Ok;
  807. showNormalIfMinimized();
  808. QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons, this);
  809. int r = mBox.exec();
  810. if (ret != nullptr)
  811. *ret = r == QMessageBox::Ok;
  812. }
  813. else
  814. notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message);
  815. }
  816. void BitcoinGUI::changeEvent(QEvent *e)
  817. {
  818. QMainWindow::changeEvent(e);
  819. #ifndef Q_OS_MAC // Ignored on Mac
  820. if(e->type() == QEvent::WindowStateChange)
  821. {
  822. if(clientModel && clientModel->getOptionsModel() && clientModel->getOptionsModel()->getMinimizeToTray())
  823. {
  824. QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
  825. if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
  826. {
  827. QTimer::singleShot(0, this, SLOT(hide()));
  828. e->ignore();
  829. }
  830. else if((wsevt->oldState() & Qt::WindowMinimized) && !isMinimized())
  831. {
  832. QTimer::singleShot(0, this, SLOT(show()));
  833. e->ignore();
  834. }
  835. }
  836. }
  837. #endif
  838. }
  839. void BitcoinGUI::closeEvent(QCloseEvent *event)
  840. {
  841. #ifndef Q_OS_MAC // Ignored on Mac
  842. if(clientModel && clientModel->getOptionsModel())
  843. {
  844. if(!clientModel->getOptionsModel()->getMinimizeOnClose())
  845. {
  846. // close rpcConsole in case it was open to make some space for the shutdown window
  847. rpcConsole->close();
  848. QApplication::quit();
  849. }
  850. else
  851. {
  852. QMainWindow::showMinimized();
  853. event->ignore();
  854. }
  855. }
  856. #else
  857. QMainWindow::closeEvent(event);
  858. #endif
  859. }
  860. void BitcoinGUI::showEvent(QShowEvent *event)
  861. {
  862. // enable the debug window when the main window shows up
  863. openRPCConsoleAction->setEnabled(true);
  864. aboutAction->setEnabled(true);
  865. optionsAction->setEnabled(true);
  866. }
  867. #ifdef ENABLE_WALLET
  868. void BitcoinGUI::incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label)
  869. {
  870. // On new transaction, make an info balloon
  871. QString msg = tr("Date: %1\n").arg(date) +
  872. tr("Amount: %1\n").arg(BitcoinUnits::formatWithUnit(unit, amount, true)) +
  873. tr("Type: %1\n").arg(type);
  874. if (!label.isEmpty())
  875. msg += tr("Label: %1\n").arg(label);
  876. else if (!address.isEmpty())
  877. msg += tr("Address: %1\n").arg(address);
  878. message((amount)<0 ? tr("Sent transaction") : tr("Incoming transaction"),
  879. msg, CClientUIInterface::MSG_INFORMATION);
  880. }
  881. #endif // ENABLE_WALLET
  882. void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
  883. {
  884. // Accept only URIs
  885. if(event->mimeData()->hasUrls())
  886. event->acceptProposedAction();
  887. }
  888. void BitcoinGUI::dropEvent(QDropEvent *event)
  889. {
  890. if(event->mimeData()->hasUrls())
  891. {
  892. for (const QUrl &uri : event->mimeData()->urls())
  893. {
  894. Q_EMIT receivedURI(uri.toString());
  895. }
  896. }
  897. event->acceptProposedAction();
  898. }
  899. bool BitcoinGUI::eventFilter(QObject *object, QEvent *event)
  900. {
  901. // Catch status tip events
  902. if (event->type() == QEvent::StatusTip)
  903. {
  904. // Prevent adding text from setStatusTip(), if we currently use the status bar for displaying other stuff
  905. if (progressBarLabel->isVisible() || progressBar->isVisible())
  906. return true;
  907. }
  908. return QMainWindow::eventFilter(object, event);
  909. }
  910. #ifdef ENABLE_WALLET
  911. bool BitcoinGUI::handlePaymentRequest(const SendCoinsRecipient& recipient)
  912. {
  913. // URI has to be valid
  914. if (walletFrame && walletFrame->handlePaymentRequest(recipient))
  915. {
  916. showNormalIfMinimized();
  917. gotoSendCoinsPage();
  918. return true;
  919. }
  920. return false;
  921. }
  922. void BitcoinGUI::setHDStatus(int hdEnabled)
  923. {
  924. labelWalletHDStatusIcon->setPixmap(platformStyle->SingleColorIcon(hdEnabled ? ":/icons/hd_enabled" : ":/icons/hd_disabled").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
  925. labelWalletHDStatusIcon->setToolTip(hdEnabled ? tr("HD key generation is <b>enabled</b>") : tr("HD key generation is <b>disabled</b>"));
  926. // eventually disable the QLabel to set its opacity to 50%
  927. labelWalletHDStatusIcon->setEnabled(hdEnabled);
  928. }
  929. void BitcoinGUI::setEncryptionStatus(int status)
  930. {
  931. switch(status)
  932. {
  933. case WalletModel::Unencrypted:
  934. labelWalletEncryptionIcon->hide();
  935. encryptWalletAction->setChecked(false);
  936. changePassphraseAction->setEnabled(false);
  937. encryptWalletAction->setEnabled(true);
  938. break;
  939. case WalletModel::Unlocked:
  940. labelWalletEncryptionIcon->show();
  941. labelWalletEncryptionIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
  942. labelWalletEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
  943. encryptWalletAction->setChecked(true);
  944. changePassphraseAction->setEnabled(true);
  945. encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
  946. break;
  947. case WalletModel::Locked:
  948. labelWalletEncryptionIcon->show();
  949. labelWalletEncryptionIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
  950. labelWalletEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
  951. encryptWalletAction->setChecked(true);
  952. changePassphraseAction->setEnabled(true);
  953. encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
  954. break;
  955. }
  956. }
  957. #endif // ENABLE_WALLET
  958. void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
  959. {
  960. if(!clientModel)
  961. return;
  962. // activateWindow() (sometimes) helps with keyboard focus on Windows
  963. if (isHidden())
  964. {
  965. show();
  966. activateWindow();
  967. }
  968. else if (isMinimized())
  969. {
  970. showNormal();
  971. activateWindow();
  972. }
  973. else if (GUIUtil::isObscured(this))
  974. {
  975. raise();
  976. activateWindow();
  977. }
  978. else if(fToggleHidden)
  979. hide();
  980. }
  981. void BitcoinGUI::toggleHidden()
  982. {
  983. showNormalIfMinimized(true);
  984. }
  985. void BitcoinGUI::detectShutdown()
  986. {
  987. if (ShutdownRequested())
  988. {
  989. if(rpcConsole)
  990. rpcConsole->hide();
  991. qApp->quit();
  992. }
  993. }
  994. void BitcoinGUI::showProgress(const QString &title, int nProgress)
  995. {
  996. if (nProgress == 0)
  997. {
  998. progressDialog = new QProgressDialog(title, "", 0, 100);
  999. progressDialog->setWindowModality(Qt::ApplicationModal);
  1000. progressDialog->setMinimumDuration(0);
  1001. progressDialog->setCancelButton(0);
  1002. progressDialog->setAutoClose(false);
  1003. progressDialog->setValue(0);
  1004. }
  1005. else if (nProgress == 100)
  1006. {
  1007. if (progressDialog)
  1008. {
  1009. progressDialog->close();
  1010. progressDialog->deleteLater();
  1011. }
  1012. }
  1013. else if (progressDialog)
  1014. progressDialog->setValue(nProgress);
  1015. }
  1016. void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)
  1017. {
  1018. if (trayIcon)
  1019. {
  1020. trayIcon->setVisible(!fHideTrayIcon);
  1021. }
  1022. }
  1023. void BitcoinGUI::showModalOverlay()
  1024. {
  1025. if (modalOverlay && (progressBar->isVisible() || modalOverlay->isLayerVisible()))
  1026. modalOverlay->toggleVisibility();
  1027. }
  1028. static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style)
  1029. {
  1030. bool modal = (style & CClientUIInterface::MODAL);
  1031. // The SECURE flag has no effect in the Qt GUI.
  1032. // bool secure = (style & CClientUIInterface::SECURE);
  1033. style &= ~CClientUIInterface::SECURE;
  1034. bool ret = false;
  1035. // In case of modal message, use blocking connection to wait for user to click a button
  1036. QMetaObject::invokeMethod(gui, "message",
  1037. modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection,
  1038. Q_ARG(QString, QString::fromStdString(caption)),
  1039. Q_ARG(QString, QString::fromStdString(message)),
  1040. Q_ARG(unsigned int, style),
  1041. Q_ARG(bool*, &ret));
  1042. return ret;
  1043. }
  1044. void BitcoinGUI::subscribeToCoreSignals()
  1045. {
  1046. // Connect signals to client
  1047. uiInterface.ThreadSafeMessageBox.connect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
  1048. uiInterface.ThreadSafeQuestion.connect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4));
  1049. }
  1050. void BitcoinGUI::unsubscribeFromCoreSignals()
  1051. {
  1052. // Disconnect signals from client
  1053. uiInterface.ThreadSafeMessageBox.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
  1054. uiInterface.ThreadSafeQuestion.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4));
  1055. }
  1056. void BitcoinGUI::toggleNetworkActive()
  1057. {
  1058. if (clientModel) {
  1059. clientModel->setNetworkActive(!clientModel->getNetworkActive());
  1060. }
  1061. }
  1062. UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle) :
  1063. optionsModel(0),
  1064. menu(0)
  1065. {
  1066. createContextMenu();
  1067. setToolTip(tr("Unit to show amounts in. Click to select another unit."));
  1068. QList<BitcoinUnits::Unit> units = BitcoinUnits::availableUnits();
  1069. int max_width = 0;
  1070. const QFontMetrics fm(font());
  1071. for (const BitcoinUnits::Unit unit : units)
  1072. {
  1073. max_width = qMax(max_width, fm.width(BitcoinUnits::longName(unit)));
  1074. }
  1075. setMinimumSize(max_width, 0);
  1076. setAlignment(Qt::AlignRight | Qt::AlignVCenter);
  1077. setStyleSheet(QString("QLabel { color : %1 }").arg(platformStyle->SingleColor().name()));
  1078. }
  1079. /** So that it responds to button clicks */
  1080. void UnitDisplayStatusBarControl::mousePressEvent(QMouseEvent *event)
  1081. {
  1082. onDisplayUnitsClicked(event->pos());
  1083. }
  1084. /** Creates context menu, its actions, and wires up all the relevant signals for mouse events. */
  1085. void UnitDisplayStatusBarControl::createContextMenu()
  1086. {
  1087. menu = new QMenu(this);
  1088. for (BitcoinUnits::Unit u : BitcoinUnits::availableUnits())
  1089. {
  1090. QAction *menuAction = new QAction(QString(BitcoinUnits::longName(u)), this);
  1091. menuAction->setData(QVariant(u));
  1092. menu->addAction(menuAction);
  1093. }
  1094. connect(menu,SIGNAL(triggered(QAction*)),this,SLOT(onMenuSelection(QAction*)));
  1095. }
  1096. /** Lets the control know about the Options Model (and its signals) */
  1097. void UnitDisplayStatusBarControl::setOptionsModel(OptionsModel *_optionsModel)
  1098. {
  1099. if (_optionsModel)
  1100. {
  1101. this->optionsModel = _optionsModel;
  1102. // be aware of a display unit change reported by the OptionsModel object.
  1103. connect(_optionsModel,SIGNAL(displayUnitChanged(int)),this,SLOT(updateDisplayUnit(int)));
  1104. // initialize the display units label with the current value in the model.
  1105. updateDisplayUnit(_optionsModel->getDisplayUnit());
  1106. }
  1107. }
  1108. /** When Display Units are changed on OptionsModel it will refresh the display text of the control on the status bar */
  1109. void UnitDisplayStatusBarControl::updateDisplayUnit(int newUnits)
  1110. {
  1111. setText(BitcoinUnits::longName(newUnits));
  1112. }
  1113. /** Shows context menu with Display Unit options by the mouse coordinates */
  1114. void UnitDisplayStatusBarControl::onDisplayUnitsClicked(const QPoint& point)
  1115. {
  1116. QPoint globalPos = mapToGlobal(point);
  1117. menu->exec(globalPos);
  1118. }
  1119. /** Tells underlying optionsModel to update its current display unit. */
  1120. void UnitDisplayStatusBarControl::onMenuSelection(QAction* action)
  1121. {
  1122. if (action)
  1123. {
  1124. optionsModel->setDisplayUnit(action->data());
  1125. }
  1126. }