diff options
Diffstat (limited to 'src/qt/bitcoingui.cpp')
-rw-r--r-- | src/qt/bitcoingui.cpp | 224 |
1 files changed, 174 insertions, 50 deletions
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 2d0f51a3fb..f548c65161 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -4,7 +4,6 @@ #include "bitcoingui.h" -#include "aboutdialog.h" #include "bitcoinunits.h" #include "clientmodel.h" #include "guiconstants.h" @@ -14,8 +13,11 @@ #include "optionsdialog.h" #include "optionsmodel.h" #include "rpcconsole.h" +#include "utilitydialog.h" +#ifdef ENABLE_WALLET #include "walletframe.h" #include "walletmodel.h" +#endif #ifdef Q_OS_MAC #include "macdockiconhandler.h" @@ -37,7 +39,6 @@ #include <QMenuBar> #include <QMessageBox> #include <QMimeData> -#include <QMovie> #include <QProgressBar> #include <QSettings> #include <QStackedWidget> @@ -59,19 +60,34 @@ const QString BitcoinGUI::DEFAULT_WALLET = "~Default"; BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) : QMainWindow(parent), clientModel(0), + walletFrame(0), encryptWalletAction(0), changePassphraseAction(0), aboutQtAction(0), trayIcon(0), notificator(0), rpcConsole(0), - prevBlocks(0) + prevBlocks(0), + spinnerFrame(0) { GUIUtil::restoreWindowGeometry("nWindow", QSize(850, 550), this); + QString windowTitle = tr("Bitcoin Core") + " - "; +#ifdef ENABLE_WALLET + /* if compiled with wallet support, -disablewallet can still disable the wallet */ + bool enableWallet = !GetBoolArg("-disablewallet", false); +#else + bool enableWallet = false; +#endif + if(enableWallet) + { + windowTitle += tr("Wallet"); + } else { + windowTitle += tr("Node"); + } + if (!fIsTestnet) { - setWindowTitle(tr("Bitcoin Core") + " - " + tr("Wallet")); #ifndef Q_OS_MAC QApplication::setWindowIcon(QIcon(":icons/bitcoin")); setWindowIcon(QIcon(":icons/bitcoin")); @@ -81,7 +97,7 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) : } else { - setWindowTitle(tr("Bitcoin Core") + " - " + tr("Wallet") + " " + tr("[testnet]")); + windowTitle += " " + tr("[testnet]"); #ifndef Q_OS_MAC QApplication::setWindowIcon(QIcon(":icons/bitcoin_testnet")); setWindowIcon(QIcon(":icons/bitcoin_testnet")); @@ -89,6 +105,7 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) : MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet")); #endif } + setWindowTitle(windowTitle); #if defined(Q_OS_MAC) && QT_VERSION < 0x050000 // This property is not implemented in Qt 5. Setting it has no effect. @@ -96,9 +113,21 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) : setUnifiedTitleAndToolBarOnMac(true); #endif - // Create wallet frame and make it the central widget - walletFrame = new WalletFrame(this); - setCentralWidget(walletFrame); + rpcConsole = new RPCConsole(enableWallet ? this : 0); +#ifdef ENABLE_WALLET + if(enableWallet) + { + /** Create wallet frame and make it the central widget */ + walletFrame = new WalletFrame(this); + setCentralWidget(walletFrame); + } else +#endif + { + /* When compiled without wallet or -disablewallet is provided, + * the central widget is the rpc console. + */ + setCentralWidget(rpcConsole); + } // Accept D&D of URIs setAcceptDrops(true); @@ -158,10 +187,8 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) : statusBar()->addWidget(progressBar); statusBar()->addPermanentWidget(frameBlocks); - syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this); - - rpcConsole = new RPCConsole(this); connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show())); + // prevents an oben debug window from becoming stuck/unusable on client shutdown connect(quitAction, SIGNAL(triggered()), rpcConsole, SLOT(hide())); @@ -170,10 +197,16 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) : // Initially wallet actions should be disabled setWalletActionsEnabled(false); + + // Subscribe to notifications from core + subscribeToCoreSignals(); } BitcoinGUI::~BitcoinGUI() { + // Unsubscribe from notifications from core + unsubscribeFromCoreSignals(); + GUIUtil::saveWindowGeometry("nWindow", this); if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu) trayIcon->hide(); @@ -267,27 +300,36 @@ void BitcoinGUI::createActions(bool fIsTestnet) openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this); openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console")); - usedSendingAddressesAction = new QAction(QIcon(":/icons/address-book"), tr("&Used sending addresses..."), this); + usedSendingAddressesAction = new QAction(QIcon(":/icons/address-book"), tr("&Sending addresses..."), this); usedSendingAddressesAction->setStatusTip(tr("Show the list of used sending addresses and labels")); - usedReceivingAddressesAction = new QAction(QIcon(":/icons/address-book"), tr("Used &receiving addresses..."), this); + usedReceivingAddressesAction = new QAction(QIcon(":/icons/address-book"), tr("&Receiving addresses..."), this); usedReceivingAddressesAction->setStatusTip(tr("Show the list of used receiving addresses and labels")); - openAction = new QAction(QApplication::style()->standardIcon(QStyle::SP_FileIcon), tr("Open URI..."), this); + openAction = new QAction(QApplication::style()->standardIcon(QStyle::SP_FileIcon), tr("Open &URI..."), this); openAction->setStatusTip(tr("Open a bitcoin: URI or payment request")); + showHelpMessageAction = new QAction(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation), tr("&Command-line options"), this); + showHelpMessageAction->setStatusTip(tr("Show the Bitcoin Core help message to get a list with possible Bitcoin command-line options")); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked())); connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden())); - connect(encryptWalletAction, SIGNAL(triggered(bool)), walletFrame, SLOT(encryptWallet(bool))); - connect(backupWalletAction, SIGNAL(triggered()), walletFrame, SLOT(backupWallet())); - connect(changePassphraseAction, SIGNAL(triggered()), walletFrame, SLOT(changePassphrase())); - connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab())); - connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab())); - connect(usedSendingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedSendingAddresses())); - connect(usedReceivingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedReceivingAddresses())); - connect(openAction, SIGNAL(triggered()), this, SLOT(openClicked())); + connect(showHelpMessageAction, SIGNAL(triggered()), this, SLOT(showHelpMessageClicked())); +#ifdef ENABLE_WALLET + if(walletFrame) + { + connect(encryptWalletAction, SIGNAL(triggered(bool)), walletFrame, SLOT(encryptWallet(bool))); + connect(backupWalletAction, SIGNAL(triggered()), walletFrame, SLOT(backupWallet())); + connect(changePassphraseAction, SIGNAL(triggered()), walletFrame, SLOT(changePassphrase())); + connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab())); + connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab())); + connect(usedSendingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedSendingAddresses())); + connect(usedReceivingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedReceivingAddresses())); + connect(openAction, SIGNAL(triggered()), this, SLOT(openClicked())); + } +#endif } void BitcoinGUI::createMenuBar() @@ -302,24 +344,34 @@ void BitcoinGUI::createMenuBar() // Configure the menus QMenu *file = appMenuBar->addMenu(tr("&File")); - file->addAction(openAction); - file->addAction(backupWalletAction); - file->addAction(signMessageAction); - file->addAction(verifyMessageAction); - file->addSeparator(); - file->addAction(usedSendingAddressesAction); - file->addAction(usedReceivingAddressesAction); - file->addSeparator(); + if(walletFrame) + { + file->addAction(openAction); + file->addAction(backupWalletAction); + file->addAction(signMessageAction); + file->addAction(verifyMessageAction); + file->addSeparator(); + file->addAction(usedSendingAddressesAction); + file->addAction(usedReceivingAddressesAction); + file->addSeparator(); + } file->addAction(quitAction); QMenu *settings = appMenuBar->addMenu(tr("&Settings")); - settings->addAction(encryptWalletAction); - settings->addAction(changePassphraseAction); - settings->addSeparator(); + if(walletFrame) + { + settings->addAction(encryptWalletAction); + settings->addAction(changePassphraseAction); + settings->addSeparator(); + } settings->addAction(optionsAction); QMenu *help = appMenuBar->addMenu(tr("&Help")); - help->addAction(openRPCConsoleAction); + if(walletFrame) + { + help->addAction(openRPCConsoleAction); + } + help->addAction(showHelpMessageAction); help->addSeparator(); help->addAction(aboutAction); help->addAction(aboutQtAction); @@ -327,13 +379,16 @@ void BitcoinGUI::createMenuBar() void BitcoinGUI::createToolBars() { - QToolBar *toolbar = addToolBar(tr("Tabs toolbar")); - toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - toolbar->addAction(overviewAction); - toolbar->addAction(sendCoinsAction); - toolbar->addAction(receiveCoinsAction); - toolbar->addAction(historyAction); - overviewAction->setChecked(true); + if(walletFrame) + { + QToolBar *toolbar = addToolBar(tr("Tabs toolbar")); + toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + toolbar->addAction(overviewAction); + toolbar->addAction(sendCoinsAction); + toolbar->addAction(receiveCoinsAction); + toolbar->addAction(historyAction); + overviewAction->setChecked(true); + } } void BitcoinGUI::setClientModel(ClientModel *clientModel) @@ -356,26 +411,39 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel) connect(clientModel, SIGNAL(message(QString,QString,unsigned int)), this, SLOT(message(QString,QString,unsigned int))); rpcConsole->setClientModel(clientModel); - walletFrame->setClientModel(clientModel); +#ifdef ENABLE_WALLET + if(walletFrame) + { + walletFrame->setClientModel(clientModel); + } +#endif } } +#ifdef ENABLE_WALLET bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel) { + if(!walletFrame) + return false; setWalletActionsEnabled(true); return walletFrame->addWallet(name, walletModel); } bool BitcoinGUI::setCurrentWallet(const QString& name) { + if(!walletFrame) + return false; return walletFrame->setCurrentWallet(name); } void BitcoinGUI::removeAllWallets() { + if(!walletFrame) + return; setWalletActionsEnabled(false); walletFrame->removeAllWallets(); } +#endif void BitcoinGUI::setWalletActionsEnabled(bool enabled) { @@ -483,6 +551,14 @@ void BitcoinGUI::aboutClicked() dlg.exec(); } +void BitcoinGUI::showHelpMessageClicked() +{ + HelpMessageDialog *help = new HelpMessageDialog(this); + help->setAttribute(Qt::WA_DeleteOnClose); + help->show(); +} + +#ifdef ENABLE_WALLET void BitcoinGUI::openClicked() { OpenURIDialog dlg(this); @@ -525,6 +601,7 @@ void BitcoinGUI::gotoVerifyMessageTab(QString addr) { if (walletFrame) walletFrame->gotoVerifyMessageTab(addr); } +#endif void BitcoinGUI::setNumConnections(int count) { @@ -585,7 +662,10 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks) tooltip = tr("Up to date") + QString(".<br>") + tooltip; labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE)); - walletFrame->showOutOfSyncWarning(false); +#ifdef ENABLE_WALLET + if(walletFrame) + walletFrame->showOutOfSyncWarning(false); +#endif progressBarLabel->setVisible(false); progressBar->setVisible(false); @@ -614,12 +694,19 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks) progressBar->setVisible(true); tooltip = tr("Catching up...") + QString("<br>") + tooltip; - labelBlocksIcon->setMovie(syncIconMovie); if(count != prevBlocks) - syncIconMovie->jumpToNextFrame(); + { + labelBlocksIcon->setPixmap(QIcon(QString( + ":/movies/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0'))) + .pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE)); + spinnerFrame = (spinnerFrame + 1) % SPINNER_FRAMES; + } prevBlocks = count; - walletFrame->showOutOfSyncWarning(true); +#ifdef ENABLE_WALLET + if(walletFrame) + walletFrame->showOutOfSyncWarning(true); +#endif tooltip += QString("<br>"); tooltip += tr("Last received block was generated %1 ago.").arg(timeBehindText); @@ -684,8 +771,11 @@ void BitcoinGUI::message(const QString &title, const QString &message, unsigned if (!(buttons = (QMessageBox::StandardButton)(style & CClientUIInterface::BTN_MASK))) buttons = QMessageBox::Ok; - // Ensure we get users attention - showNormalIfMinimized(); + // Ensure we get users attention, but only if main window is visible + // as we don't want to pop up the main window for messages that happen before + // initialization is finished. + if(!(style & CClientUIInterface::NOSHOWGUI)) + showNormalIfMinimized(); QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons, this); int r = mBox.exec(); if (ret != NULL) @@ -729,6 +819,7 @@ void BitcoinGUI::closeEvent(QCloseEvent *event) QMainWindow::closeEvent(event); } +#ifdef ENABLE_WALLET void BitcoinGUI::incomingTransaction(const QString& date, int unit, qint64 amount, const QString& type, const QString& address) { // On new transaction, make an info balloon @@ -742,6 +833,7 @@ void BitcoinGUI::incomingTransaction(const QString& date, int unit, qint64 amoun .arg(type) .arg(address), CClientUIInterface::MSG_INFORMATION); } +#endif void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event) { @@ -774,10 +866,11 @@ bool BitcoinGUI::eventFilter(QObject *object, QEvent *event) return QMainWindow::eventFilter(object, event); } +#ifdef ENABLE_WALLET bool BitcoinGUI::handlePaymentRequest(const SendCoinsRecipient& recipient) { // URI has to be valid - if (walletFrame->handlePaymentRequest(recipient)) + if (walletFrame && walletFrame->handlePaymentRequest(recipient)) { showNormalIfMinimized(); gotoSendCoinsPage(); @@ -815,6 +908,7 @@ void BitcoinGUI::setEncryptionStatus(int status) break; } } +#endif void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden) { @@ -846,5 +940,35 @@ void BitcoinGUI::toggleHidden() void BitcoinGUI::detectShutdown() { if (ShutdownRequested()) - QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection); + { + if(rpcConsole) + rpcConsole->hide(); + qApp->quit(); + } +} + +static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style) +{ + bool modal = (style & CClientUIInterface::MODAL); + bool ret = false; + // In case of modal message, use blocking connection to wait for user to click a button + QMetaObject::invokeMethod(gui, "message", + modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection, + Q_ARG(QString, QString::fromStdString(caption)), + Q_ARG(QString, QString::fromStdString(message)), + Q_ARG(unsigned int, style), + Q_ARG(bool*, &ret)); + return ret; +} + +void BitcoinGUI::subscribeToCoreSignals() +{ + // Connect signals to client + uiInterface.ThreadSafeMessageBox.connect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3)); +} + +void BitcoinGUI::unsubscribeFromCoreSignals() +{ + // Disconnect signals from client + uiInterface.ThreadSafeMessageBox.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3)); } |