Merge pull request #3240 from laanwj/2013_11_rebase_no_wallet

Introduce disable-wallet / no-wallet mode (rebased)
This commit is contained in:
Wladimir J. van der Laan 2013-11-13 04:35:12 -08:00
commit 2830a9051d
6 changed files with 192 additions and 138 deletions

View File

@ -499,6 +499,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
fPrintToConsole = GetBoolArg("-printtoconsole", false); fPrintToConsole = GetBoolArg("-printtoconsole", false);
fPrintToDebugger = GetBoolArg("-printtodebugger", false); fPrintToDebugger = GetBoolArg("-printtodebugger", false);
fLogTimestamps = GetBoolArg("-logtimestamps", true); fLogTimestamps = GetBoolArg("-logtimestamps", true);
bool fDisableWallet = GetBoolArg("-disablewallet", false);
if (mapArgs.count("-timeout")) if (mapArgs.count("-timeout"))
{ {
@ -587,6 +588,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
// ********************************************************* Step 5: verify wallet database integrity // ********************************************************* Step 5: verify wallet database integrity
if (!fDisableWallet) {
uiInterface.InitMessage(_("Verifying wallet...")); uiInterface.InitMessage(_("Verifying wallet..."));
if (!bitdb.Open(GetDataDir())) if (!bitdb.Open(GetDataDir()))
@ -630,6 +632,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
if (r == CDBEnv::RECOVER_FAIL) if (r == CDBEnv::RECOVER_FAIL)
return InitError(_("wallet.dat corrupt, salvage failed")); return InitError(_("wallet.dat corrupt, salvage failed"));
} }
} // (!fDisableWallet)
// ********************************************************* Step 6: network initialization // ********************************************************* Step 6: network initialization
@ -898,6 +901,10 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
// ********************************************************* Step 8: load wallet // ********************************************************* Step 8: load wallet
if (fDisableWallet) {
pwalletMain = NULL;
LogPrintf("Wallet disabled!\n");
} else {
uiInterface.InitMessage(_("Loading wallet...")); uiInterface.InitMessage(_("Loading wallet..."));
nStart = GetTimeMillis(); nStart = GetTimeMillis();
@ -984,6 +991,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
pwalletMain->SetBestChain(chainActive.GetLocator()); pwalletMain->SetBestChain(chainActive.GetLocator());
nWalletDBUpdated++; nWalletDBUpdated++;
} }
} // (!fDisableWallet)
// ********************************************************* Step 9: import blocks // ********************************************************* Step 9: import blocks

View File

@ -313,11 +313,16 @@ int main(int argc, char *argv[])
splash.finish(&window); splash.finish(&window);
ClientModel clientModel(&optionsModel); ClientModel clientModel(&optionsModel);
WalletModel walletModel(pwalletMain, &optionsModel); WalletModel *walletModel = 0;
if(pwalletMain)
walletModel = new WalletModel(pwalletMain, &optionsModel);
window.setClientModel(&clientModel); window.setClientModel(&clientModel);
window.addWallet("~Default", &walletModel); if(walletModel)
{
window.addWallet("~Default", walletModel);
window.setCurrentWallet("~Default"); window.setCurrentWallet("~Default");
}
// If -min option passed, start window minimized. // If -min option passed, start window minimized.
if(GetBoolArg("-min", false)) if(GetBoolArg("-min", false))
@ -335,8 +340,11 @@ int main(int argc, char *argv[])
&window, SLOT(handlePaymentRequest(SendCoinsRecipient))); &window, SLOT(handlePaymentRequest(SendCoinsRecipient)));
QObject::connect(&window, SIGNAL(receivedURI(QString)), QObject::connect(&window, SIGNAL(receivedURI(QString)),
paymentServer, SLOT(handleURIOrFile(QString))); paymentServer, SLOT(handleURIOrFile(QString)));
QObject::connect(&walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)), if(walletModel)
{
QObject::connect(walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)),
paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray))); paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray)));
}
QObject::connect(paymentServer, SIGNAL(message(QString,QString,unsigned int)), QObject::connect(paymentServer, SIGNAL(message(QString,QString,unsigned int)),
guiref, SLOT(message(QString,QString,unsigned int))); guiref, SLOT(message(QString,QString,unsigned int)));
QTimer::singleShot(100, paymentServer, SLOT(uiReady())); QTimer::singleShot(100, paymentServer, SLOT(uiReady()));
@ -347,6 +355,7 @@ int main(int argc, char *argv[])
window.setClientModel(0); window.setClientModel(0);
window.removeAllWallets(); window.removeAllWallets();
guiref = 0; guiref = 0;
delete walletModel;
} }
// Shutdown the core and its threads, but don't exit Bitcoin-Qt here // Shutdown the core and its threads, but don't exit Bitcoin-Qt here
threadGroup.interrupt_all(); threadGroup.interrupt_all();

View File

@ -163,6 +163,9 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) :
// Install event filter to be able to catch status tip events (QEvent::StatusTip) // Install event filter to be able to catch status tip events (QEvent::StatusTip)
this->installEventFilter(this); this->installEventFilter(this);
// Initially wallet actions should be disabled
setWalletActionsEnabled(false);
} }
BitcoinGUI::~BitcoinGUI() BitcoinGUI::~BitcoinGUI()
@ -352,6 +355,7 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel) bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel)
{ {
setWalletActionsEnabled(true);
return walletFrame->addWallet(name, walletModel); return walletFrame->addWallet(name, walletModel);
} }
@ -362,9 +366,26 @@ bool BitcoinGUI::setCurrentWallet(const QString& name)
void BitcoinGUI::removeAllWallets() void BitcoinGUI::removeAllWallets()
{ {
setWalletActionsEnabled(false);
walletFrame->removeAllWallets(); 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);
usedSendingAddressesAction->setEnabled(enabled);
usedReceivingAddressesAction->setEnabled(enabled);
openAction->setEnabled(enabled);
}
void BitcoinGUI::createTrayIcon(bool fIsTestnet) void BitcoinGUI::createTrayIcon(bool fIsTestnet)
{ {
#ifndef Q_OS_MAC #ifndef Q_OS_MAC

View File

@ -108,6 +108,9 @@ private:
/** Create system tray menu (or setup the dock menu) */ /** Create system tray menu (or setup the dock menu) */
void createTrayIconMenu(); void createTrayIconMenu();
/** Enable or disable all wallet-related actions */
void setWalletActionsEnabled(bool enabled);
signals: signals:
/** Signal raised when a URI was entered or dragged to the GUI */ /** Signal raised when a URI was entered or dragged to the GUI */
void receivedURI(const QString &uri); void receivedURI(const QString &uri);

View File

@ -10,6 +10,7 @@
#include <cstdio> #include <cstdio>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel>
WalletFrame::WalletFrame(BitcoinGUI *_gui) : WalletFrame::WalletFrame(BitcoinGUI *_gui) :
QFrame(_gui), QFrame(_gui),
@ -21,6 +22,10 @@ WalletFrame::WalletFrame(BitcoinGUI *_gui) :
walletStack = new QStackedWidget(this); walletStack = new QStackedWidget(this);
walletFrameLayout->setContentsMargins(0,0,0,0); walletFrameLayout->setContentsMargins(0,0,0,0);
walletFrameLayout->addWidget(walletStack); walletFrameLayout->addWidget(walletStack);
QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
noWallet->setAlignment(Qt::AlignCenter);
walletStack->addWidget(noWallet);
} }
WalletFrame::~WalletFrame() WalletFrame::~WalletFrame()
@ -85,7 +90,7 @@ void WalletFrame::removeAllWallets()
bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient) bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
{ {
WalletView *walletView = (WalletView*)walletStack->currentWidget(); WalletView *walletView = currentWalletView();
if (!walletView) if (!walletView)
return false; return false;
@ -130,56 +135,62 @@ void WalletFrame::gotoSendCoinsPage(QString addr)
void WalletFrame::gotoSignMessageTab(QString addr) void WalletFrame::gotoSignMessageTab(QString addr)
{ {
WalletView *walletView = (WalletView*)walletStack->currentWidget(); WalletView *walletView = currentWalletView();
if (walletView) if (walletView)
walletView->gotoSignMessageTab(addr); walletView->gotoSignMessageTab(addr);
} }
void WalletFrame::gotoVerifyMessageTab(QString addr) void WalletFrame::gotoVerifyMessageTab(QString addr)
{ {
WalletView *walletView = (WalletView*)walletStack->currentWidget(); WalletView *walletView = currentWalletView();
if (walletView) if (walletView)
walletView->gotoVerifyMessageTab(addr); walletView->gotoVerifyMessageTab(addr);
} }
void WalletFrame::encryptWallet(bool status) void WalletFrame::encryptWallet(bool status)
{ {
WalletView *walletView = (WalletView*)walletStack->currentWidget(); WalletView *walletView = currentWalletView();
if (walletView) if (walletView)
walletView->encryptWallet(status); walletView->encryptWallet(status);
} }
void WalletFrame::backupWallet() void WalletFrame::backupWallet()
{ {
WalletView *walletView = (WalletView*)walletStack->currentWidget(); WalletView *walletView = currentWalletView();
if (walletView) if (walletView)
walletView->backupWallet(); walletView->backupWallet();
} }
void WalletFrame::changePassphrase() void WalletFrame::changePassphrase()
{ {
WalletView *walletView = (WalletView*)walletStack->currentWidget(); WalletView *walletView = currentWalletView();
if (walletView) if (walletView)
walletView->changePassphrase(); walletView->changePassphrase();
} }
void WalletFrame::unlockWallet() void WalletFrame::unlockWallet()
{ {
WalletView *walletView = (WalletView*)walletStack->currentWidget(); WalletView *walletView = currentWalletView();
if (walletView) if (walletView)
walletView->unlockWallet(); walletView->unlockWallet();
} }
void WalletFrame::usedSendingAddresses() void WalletFrame::usedSendingAddresses()
{ {
WalletView *walletView = (WalletView*)walletStack->currentWidget(); WalletView *walletView = currentWalletView();
if (walletView) if (walletView)
walletView->usedSendingAddresses(); walletView->usedSendingAddresses();
} }
void WalletFrame::usedReceivingAddresses() void WalletFrame::usedReceivingAddresses()
{ {
WalletView *walletView = (WalletView*)walletStack->currentWidget(); WalletView *walletView = currentWalletView();
if (walletView) if (walletView)
walletView->usedReceivingAddresses(); walletView->usedReceivingAddresses();
} }
WalletView *WalletFrame::currentWalletView()
{
return qobject_cast<WalletView*>(walletStack->currentWidget());
}

View File

@ -45,6 +45,8 @@ private:
bool bOutOfSync; bool bOutOfSync;
WalletView *currentWalletView();
public slots: public slots:
/** Switch to overview (home) page */ /** Switch to overview (home) page */
void gotoOverviewPage(); void gotoOverviewPage();