From 99f3d18b62159bf2ecd7eb52ada2ba0a19e5e599 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 12 Nov 2013 14:54:43 +0100 Subject: [PATCH] qt: GUI support for -disablewallet mode Rebased-from: 8121047b20f6486bf049e642c3e6ca61682ffdd9 --- src/qt/bitcoin.cpp | 12 ++++++++--- src/qt/bitcoingui.cpp | 19 +++++++++++++++++ src/qt/bitcoingui.h | 2 ++ src/qt/walletframe.cpp | 48 +++++++++++++++++++++++++++++++++++------- src/qt/walletframe.h | 5 ++++- 5 files changed, 74 insertions(+), 12 deletions(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index a6b8a3373..9e6644efd 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -254,11 +254,16 @@ int main(int argc, char *argv[]) splash.finish(&window); ClientModel clientModel(&optionsModel); - WalletModel walletModel(pwalletMain, &optionsModel); + WalletModel *walletModel = 0; + if(pwalletMain) + walletModel = new WalletModel(pwalletMain, &optionsModel); window.setClientModel(&clientModel); - window.addWallet("~Default", &walletModel); - window.setCurrentWallet("~Default"); + if(walletModel) + { + window.addWallet("~Default", walletModel); + window.setCurrentWallet("~Default"); + } // If -min option passed, start window minimized. if(GetBoolArg("-min")) @@ -281,6 +286,7 @@ int main(int argc, char *argv[]) window.setClientModel(0); window.removeAllWallets(); guiref = 0; + delete walletModel; } // Shutdown the core and its threads, but don't exit Bitcoin-Qt here threadGroup.interrupt_all(); diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index c460cd3c4..4b4aaa089 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -146,6 +146,9 @@ BitcoinGUI::BitcoinGUI(QWidget *parent) : // Install event filter to be able to catch status tip events (QEvent::StatusTip) this->installEventFilter(this); + + // Initially wallet actions should be disabled + setWalletActionsEnabled(false); } BitcoinGUI::~BitcoinGUI() @@ -341,6 +344,7 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel) bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel) { + setWalletActionsEnabled(true); return walletFrame->addWallet(name, walletModel); } @@ -351,9 +355,24 @@ bool BitcoinGUI::setCurrentWallet(const QString& name) void BitcoinGUI::removeAllWallets() { + setWalletActionsEnabled(false); walletFrame->removeAllWallets(); } +void BitcoinGUI::setWalletActionsEnabled(bool enabled) +{ + overviewAction->setEnabled(enabled); + sendCoinsAction->setEnabled(enabled); + receiveCoinsAction->setEnabled(enabled); + historyAction->setEnabled(enabled); + encryptWalletAction->setEnabled(enabled); + backupWalletAction->setEnabled(enabled); + changePassphraseAction->setEnabled(enabled); + signMessageAction->setEnabled(enabled); + verifyMessageAction->setEnabled(enabled); + addressBookAction->setEnabled(enabled); +} + void BitcoinGUI::createTrayIcon() { #ifndef Q_OS_MAC diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index f361a62a4..5656af4ce 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -126,6 +126,8 @@ private: void saveWindowGeometry(); /** Restore window size and position */ void restoreWindowGeometry(); + /** Enable or disable all wallet-related actions */ + void setWalletActionsEnabled(bool enabled); public slots: /** Set number of connections shown in the UI */ diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 50c03ac62..dc074e888 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -7,9 +7,11 @@ #include "walletframe.h" #include "bitcoingui.h" #include "walletstack.h" +#include "walletview.h" #include #include +#include WalletFrame::WalletFrame(BitcoinGUI *_gui) : QFrame(_gui), @@ -23,6 +25,10 @@ WalletFrame::WalletFrame(BitcoinGUI *_gui) : walletStack->setBitcoinGUI(gui); walletFrameLayout->setContentsMargins(0,0,0,0); walletFrameLayout->addWidget(walletStack); + + QLabel *noWallet = new QLabel(tr("No wallet has been loaded.")); + noWallet->setAlignment(Qt::AlignCenter); + walletStack->addWidget(noWallet); } WalletFrame::~WalletFrame() @@ -54,6 +60,10 @@ void WalletFrame::removeAllWallets() bool WalletFrame::handleURI(const QString &uri) { + WalletView *walletView = currentWalletView(); + if (!walletView) + return false; + return walletStack->handleURI(uri); } @@ -80,7 +90,9 @@ void WalletFrame::gotoHistoryPage() void WalletFrame::gotoAddressBookPage() { - walletStack->gotoAddressBookPage(); + WalletView *walletView = currentWalletView(); + if (walletView) + walletStack->gotoAddressBookPage(); } void WalletFrame::gotoReceiveCoinsPage() @@ -95,35 +107,55 @@ void WalletFrame::gotoSendCoinsPage(QString addr) void WalletFrame::gotoSignMessageTab(QString addr) { - walletStack->gotoSignMessageTab(addr); + WalletView *walletView = currentWalletView(); + if (walletView) + walletView->gotoSignMessageTab(addr); } void WalletFrame::gotoVerifyMessageTab(QString addr) { - walletStack->gotoSignMessageTab(addr); + WalletView *walletView = currentWalletView(); + if (walletView) + walletView->gotoVerifyMessageTab(addr); } void WalletFrame::encryptWallet(bool status) { - walletStack->encryptWallet(status); + WalletView *walletView = currentWalletView(); + if (walletView) + walletView->encryptWallet(status); } void WalletFrame::backupWallet() { - walletStack->backupWallet(); + WalletView *walletView = currentWalletView(); + if (walletView) + walletView->backupWallet(); } void WalletFrame::changePassphrase() { - walletStack->changePassphrase(); + WalletView *walletView = currentWalletView(); + if (walletView) + walletView->changePassphrase(); } void WalletFrame::unlockWallet() { - walletStack->unlockWallet(); + WalletView *walletView = currentWalletView(); + if (walletView) + walletView->unlockWallet(); } void WalletFrame::setEncryptionStatus() { - walletStack->setEncryptionStatus(); + WalletView *walletView = currentWalletView(); + if (walletView) + walletStack->setEncryptionStatus(); +} + +WalletView *WalletFrame::currentWalletView() +{ + return qobject_cast(walletStack->currentWidget()); } + diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index d7092f987..74454b1a9 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -13,6 +13,7 @@ class BitcoinGUI; class ClientModel; class WalletModel; class WalletStack; +class WalletView; class WalletFrame : public QFrame { @@ -38,6 +39,8 @@ private: ClientModel *clientModel; WalletStack *walletStack; + WalletView *currentWalletView(); + public slots: /** Switch to overview (home) page */ void gotoOverviewPage(); @@ -71,4 +74,4 @@ public slots: void setEncryptionStatus(); }; -#endif // WALLETFRAME_H \ No newline at end of file +#endif // WALLETFRAME_H