qt: clean up signal handling in walletframe/walletview

Use proper signals everywhere.
Removes the need to store a pointer to the BitcoinGUI object in
the walletview.
Also removes the interdependence between setWalletModel / setBitcoinGUI.
This commit is contained in:
Wladimir J. van der Laan 2013-10-25 16:10:43 +02:00
parent 0d09b3e8b0
commit 7d16bb3874
4 changed files with 37 additions and 43 deletions

View file

@ -62,7 +62,7 @@ bool WalletFrame::setCurrentWallet(const QString& name)
WalletView *walletView = mapWalletViews.value(name); WalletView *walletView = mapWalletViews.value(name);
walletStack->setCurrentWidget(walletView); walletStack->setCurrentWidget(walletView);
walletView->setEncryptionStatus(); walletView->updateEncryptionStatus();
return true; return true;
} }
@ -171,13 +171,6 @@ void WalletFrame::unlockWallet()
walletView->unlockWallet(); walletView->unlockWallet();
} }
void WalletFrame::setEncryptionStatus()
{
WalletView *walletView = (WalletView*)walletStack->currentWidget();
if (walletView)
walletView->setEncryptionStatus();
}
void WalletFrame::usedSendingAddresses() void WalletFrame::usedSendingAddresses()
{ {
WalletView *walletView = (WalletView*)walletStack->currentWidget(); WalletView *walletView = (WalletView*)walletStack->currentWidget();

View file

@ -75,12 +75,6 @@ public slots:
void usedSendingAddresses(); void usedSendingAddresses();
/** Show used receiving addresses */ /** Show used receiving addresses */
void usedReceivingAddresses(); void usedReceivingAddresses();
/** Set the encryption status as shown in the UI.
@param[in] status current encryption status
@see WalletModel::EncryptionStatus
*/
void setEncryptionStatus();
}; };
#endif // WALLETFRAME_H #endif // WALLETFRAME_H

View file

@ -32,7 +32,6 @@
WalletView::WalletView(QWidget *parent): WalletView::WalletView(QWidget *parent):
QStackedWidget(parent), QStackedWidget(parent),
gui(0),
clientModel(0), clientModel(0),
walletModel(0) walletModel(0)
{ {
@ -70,6 +69,9 @@ WalletView::WalletView(QWidget *parent):
// Clicking on "Export" allows to export the transaction list // Clicking on "Export" allows to export the transaction list
connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked())); connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
// Pass through messages from sendCoinsPage
connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
} }
WalletView::~WalletView() WalletView::~WalletView()
@ -78,8 +80,6 @@ WalletView::~WalletView()
void WalletView::setBitcoinGUI(BitcoinGUI *gui) void WalletView::setBitcoinGUI(BitcoinGUI *gui)
{ {
this->gui = gui;
if (gui) if (gui)
{ {
// Clicking on a transaction on the overview page sends you to the transactions tab // Clicking on a transaction on the overview page sends you to the transactions tab
@ -87,26 +87,25 @@ void WalletView::setBitcoinGUI(BitcoinGUI *gui)
// Receive and report messages // Receive and report messages
connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int))); connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
// Pass through encryption status changed signals
connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
// Pass through transaction notifications
connect(this, SIGNAL(incomingTransaction(QString,int,qint64,QString,QString)), gui, SLOT(incomingTransaction(QString,int,qint64,QString,QString)));
} }
} }
void WalletView::setClientModel(ClientModel *clientModel) void WalletView::setClientModel(ClientModel *clientModel)
{ {
this->clientModel = clientModel; this->clientModel = clientModel;
if (clientModel)
{
overviewPage->setClientModel(clientModel); overviewPage->setClientModel(clientModel);
}
} }
void WalletView::setWalletModel(WalletModel *walletModel) void WalletView::setWalletModel(WalletModel *walletModel)
{ {
this->walletModel = walletModel; this->walletModel = walletModel;
if (walletModel && gui)
{
// Receive and report messages from wallet thread
connect(walletModel, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
// Put transaction list in tabs // Put transaction list in tabs
transactionView->setModel(walletModel); transactionView->setModel(walletModel);
@ -114,19 +113,25 @@ void WalletView::setWalletModel(WalletModel *walletModel)
receiveCoinsPage->setModel(walletModel); receiveCoinsPage->setModel(walletModel);
sendCoinsPage->setModel(walletModel); sendCoinsPage->setModel(walletModel);
setEncryptionStatus(); if (walletModel)
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int))); {
// Receive and report messages from wallet thread
connect(walletModel, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int)));
// Handle changes in encryption status
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int)));
updateEncryptionStatus();
// Balloon pop-up for new transaction // Balloon pop-up for new transaction
connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)), connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(incomingTransaction(QModelIndex,int,int))); this, SLOT(processNewTransaction(QModelIndex,int,int)));
// Ask for passphrase if needed // Ask for passphrase if needed
connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet())); connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
} }
} }
void WalletView::incomingTransaction(const QModelIndex& parent, int start, int /*end*/) void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
{ {
// Prevent balloon-spam when initial block download is in progress // Prevent balloon-spam when initial block download is in progress
if (!walletModel || !clientModel || clientModel->inInitialBlockDownload()) if (!walletModel || !clientModel || clientModel->inInitialBlockDownload())
@ -139,7 +144,7 @@ void WalletView::incomingTransaction(const QModelIndex& parent, int start, int /
QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString(); QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
QString address = ttm->index(start, TransactionTableModel::ToAddress, parent).data().toString(); QString address = ttm->index(start, TransactionTableModel::ToAddress, parent).data().toString();
gui->incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address); emit incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address);
} }
void WalletView::gotoOverviewPage() void WalletView::gotoOverviewPage()
@ -199,9 +204,9 @@ void WalletView::showOutOfSyncWarning(bool fShow)
overviewPage->showOutOfSyncWarning(fShow); overviewPage->showOutOfSyncWarning(fShow);
} }
void WalletView::setEncryptionStatus() void WalletView::updateEncryptionStatus()
{ {
gui->setEncryptionStatus(walletModel->getEncryptionStatus()); emit encryptionStatusChanged(walletModel->getEncryptionStatus());
} }
void WalletView::encryptWallet(bool status) void WalletView::encryptWallet(bool status)
@ -212,7 +217,7 @@ void WalletView::encryptWallet(bool status)
dlg.setModel(walletModel); dlg.setModel(walletModel);
dlg.exec(); dlg.exec();
setEncryptionStatus(); updateEncryptionStatus();
} }
void WalletView::backupWallet() void WalletView::backupWallet()

View file

@ -55,7 +55,6 @@ public:
void showOutOfSyncWarning(bool fShow); void showOutOfSyncWarning(bool fShow);
private: private:
BitcoinGUI *gui;
ClientModel *clientModel; ClientModel *clientModel;
WalletModel *walletModel; WalletModel *walletModel;
@ -85,7 +84,7 @@ public slots:
The new items are those between start and end inclusive, under the given parent item. The new items are those between start and end inclusive, under the given parent item.
*/ */
void incomingTransaction(const QModelIndex& parent, int start, int /*end*/); void processNewTransaction(const QModelIndex& parent, int start, int /*end*/);
/** Encrypt the wallet */ /** Encrypt the wallet */
void encryptWallet(bool status); void encryptWallet(bool status);
/** Backup the wallet */ /** Backup the wallet */
@ -100,14 +99,17 @@ public slots:
/** Show used receiving addresses */ /** Show used receiving addresses */
void usedReceivingAddresses(); void usedReceivingAddresses();
void setEncryptionStatus(); /** Re-emit encryption status signal */
void updateEncryptionStatus();
signals: signals:
/** Signal that we want to show the main window */ /** Signal that we want to show the main window */
void showNormalIfMinimized(); void showNormalIfMinimized();
/** Fired when a message should be reported to the user */ /** Fired when a message should be reported to the user */
void message(const QString &title, const QString &message, unsigned int style); void message(const QString &title, const QString &message, unsigned int style);
/** Encryption status of wallet changed */
void encryptionStatusChanged(int status);
/** Notify that a new transaction appeared */
void incomingTransaction(const QString& date, int unit, qint64 amount, const QString& type, const QString& address);
}; };
#endif // WALLETVIEW_H #endif // WALLETVIEW_H