Skip to content

Commit

Permalink
Merge branch 'nullmodels' of https://github.com/laanwj/bitcoin
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinandresen committed Nov 10, 2011
2 parents 5efee7d + dead0ff commit ba1fce9
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 98 deletions.
5 changes: 4 additions & 1 deletion src/qt/aboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ AboutDialog::AboutDialog(QWidget *parent) :

void AboutDialog::setModel(ClientModel *model)
{
ui->versionLabel->setText(model->formatFullVersion());
if(model)
{
ui->versionLabel->setText(model->formatFullVersion());
}
}

AboutDialog::~AboutDialog()
Expand Down
25 changes: 16 additions & 9 deletions src/qt/addressbookpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ AddressBookPage::~AddressBookPage()
void AddressBookPage::setModel(AddressTableModel *model)
{
this->model = model;
if(!model)
return;
// Refresh list from core
model->updateList();

Expand Down Expand Up @@ -96,16 +98,13 @@ void AddressBookPage::setModel(AddressTableModel *model)
selectionChanged();
}

QTableView *AddressBookPage::getCurrentTable()
{
return ui->tableView;
}

void AddressBookPage::on_copyToClipboard_clicked()
{
// Copy currently selected address to clipboard
// (or nothing, if nothing selected)
QTableView *table = getCurrentTable();
QTableView *table = ui->tableView;
if(!table->selectionModel())
return;
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);

foreach (QModelIndex index, indexes)
Expand All @@ -117,6 +116,8 @@ void AddressBookPage::on_copyToClipboard_clicked()

void AddressBookPage::on_newAddressButton_clicked()
{
if(!model)
return;
EditAddressDialog dlg(
tab == SendingTab ?
EditAddressDialog::NewSendingAddress :
Expand All @@ -139,7 +140,9 @@ void AddressBookPage::on_newAddressButton_clicked()

void AddressBookPage::on_deleteButton_clicked()
{
QTableView *table = getCurrentTable();
QTableView *table = ui->tableView;
if(!table->selectionModel())
return;
QModelIndexList indexes = table->selectionModel()->selectedRows();
if(!indexes.isEmpty())
{
Expand All @@ -150,7 +153,9 @@ void AddressBookPage::on_deleteButton_clicked()
void AddressBookPage::selectionChanged()
{
// Set button states based on selected tab and selection
QTableView *table = getCurrentTable();
QTableView *table = ui->tableView;
if(!table->selectionModel())
return;

if(table->selectionModel()->hasSelection())
{
Expand All @@ -174,12 +179,14 @@ void AddressBookPage::selectionChanged()

void AddressBookPage::done(int retval)
{
QTableView *table = ui->tableView;
if(!table->selectionModel() || !table->model())
return;
// When this is a tab/widget and not a model dialog, ignore "done"
if(mode == ForEditing)
return;

// Figure out which address was selected, and return it
QTableView *table = getCurrentTable();
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);

foreach (QModelIndex index, indexes)
Expand Down
2 changes: 0 additions & 2 deletions src/qt/addressbookpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public slots:
QString returnValue;
QSortFilterProxyModel *proxyModel;

QTableView *getCurrentTable();

private slots:
void on_deleteButton_clicked();
void on_newAddressButton_clicked();
Expand Down
2 changes: 2 additions & 0 deletions src/qt/askpassphrasedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ void AskPassphraseDialog::setModel(WalletModel *model)
void AskPassphraseDialog::accept()
{
std::string oldpass, newpass1, newpass2;
if(!model)
return;
// TODO: mlock memory / munlock on return so they will not be swapped out, really need "mlockedstring" wrapper class to do this safely
oldpass.reserve(MAX_PASSPHRASE_SIZE);
newpass1.reserve(MAX_PASSPHRASE_SIZE);
Expand Down
95 changes: 56 additions & 39 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,58 +267,62 @@ void BitcoinGUI::createToolBars()
void BitcoinGUI::setClientModel(ClientModel *clientModel)
{
this->clientModel = clientModel;

if(clientModel->isTestNet())
if(clientModel)
{
QString title_testnet = windowTitle() + QString(" ") + tr("[testnet]");
setWindowTitle(title_testnet);
if(clientModel->isTestNet())
{
QString title_testnet = windowTitle() + QString(" ") + tr("[testnet]");
setWindowTitle(title_testnet);
#ifndef Q_WS_MAC
setWindowIcon(QIcon(":icons/bitcoin_testnet"));
setWindowIcon(QIcon(":icons/bitcoin_testnet"));
#else
MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
#endif
if(trayIcon)
{
trayIcon->setToolTip(title_testnet);
trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
if(trayIcon)
{
trayIcon->setToolTip(title_testnet);
trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
}
}
}

// Keep up to date with client
setNumConnections(clientModel->getNumConnections());
connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
// Keep up to date with client
setNumConnections(clientModel->getNumConnections());
connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));

setNumBlocks(clientModel->getNumBlocks());
connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
setNumBlocks(clientModel->getNumBlocks());
connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));

// Report errors from network/worker thread
connect(clientModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
// Report errors from network/worker thread
connect(clientModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
}
}

void BitcoinGUI::setWalletModel(WalletModel *walletModel)
{
this->walletModel = walletModel;
if(walletModel)
{
// Report errors from wallet thread
connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));

// Report errors from wallet thread
connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));

// Put transaction list in tabs
transactionView->setModel(walletModel);
// Put transaction list in tabs
transactionView->setModel(walletModel);

overviewPage->setModel(walletModel);
addressBookPage->setModel(walletModel->getAddressTableModel());
receiveCoinsPage->setModel(walletModel->getAddressTableModel());
sendCoinsPage->setModel(walletModel);
overviewPage->setModel(walletModel);
addressBookPage->setModel(walletModel->getAddressTableModel());
receiveCoinsPage->setModel(walletModel->getAddressTableModel());
sendCoinsPage->setModel(walletModel);

setEncryptionStatus(walletModel->getEncryptionStatus());
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
setEncryptionStatus(walletModel->getEncryptionStatus());
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));

// Balloon popup for new transaction
connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(incomingTransaction(QModelIndex,int,int)));
// Balloon popup for new transaction
connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(incomingTransaction(QModelIndex,int,int)));

// Ask for passphrase if needed
connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
// Ask for passphrase if needed
connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
}
}

void BitcoinGUI::createTrayIcon()
Expand Down Expand Up @@ -369,6 +373,8 @@ void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)

void BitcoinGUI::optionsClicked()
{
if(!clientModel || !clientModel->getOptionsModel())
return;
OptionsDialog dlg;
dlg.setModel(clientModel->getOptionsModel());
dlg.exec();
Expand Down Expand Up @@ -398,6 +404,8 @@ void BitcoinGUI::setNumConnections(int count)

void BitcoinGUI::setNumBlocks(int count)
{
if(!clientModel)
return;
int initTotal = clientModel->getNumBlocksAtStartup();
int total = clientModel->getNumBlocksOfPeers();
QString tooltip;
Expand Down Expand Up @@ -492,13 +500,16 @@ void BitcoinGUI::changeEvent(QEvent *e)

void BitcoinGUI::closeEvent(QCloseEvent *event)
{
#ifndef Q_WS_MAC // Ignored on Mac
if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
!clientModel->getOptionsModel()->getMinimizeOnClose())
if(clientModel)
{
qApp->quit();
}
#ifndef Q_WS_MAC // Ignored on Mac
if(!clientModel->getOptionsModel()->getMinimizeToTray() &&
!clientModel->getOptionsModel()->getMinimizeOnClose())
{
qApp->quit();
}
#endif
}
QMainWindow::closeEvent(event);
}

Expand All @@ -517,6 +528,8 @@ void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)

void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
{
if(!walletModel || !clientModel)
return;
TransactionTableModel *ttm = walletModel->getTransactionTableModel();
qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
.data(Qt::EditRole).toULongLong();
Expand Down Expand Up @@ -654,6 +667,8 @@ void BitcoinGUI::setEncryptionStatus(int status)

void BitcoinGUI::encryptWallet(bool status)
{
if(!walletModel)
return;
AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
AskPassphraseDialog::Decrypt, this);
dlg.setModel(walletModel);
Expand All @@ -671,6 +686,8 @@ void BitcoinGUI::changePassphrase()

void BitcoinGUI::unlockWallet()
{
if(!walletModel)
return;
// Unlock wallet when requested by wallet model
if(walletModel->getEncryptionStatus() == WalletModel::Locked)
{
Expand Down
6 changes: 5 additions & 1 deletion src/qt/csvmodelwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ bool CSVModelWriter::write()
return false;
QTextStream out(&file);

int numRows = model->rowCount();
int numRows = 0;
if(model)
{
numRows = model->rowCount();
}

// Header row
for(int i=0; i<columns.size(); ++i)
Expand Down
4 changes: 4 additions & 0 deletions src/qt/editaddressdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void EditAddressDialog::loadRow(int row)

bool EditAddressDialog::saveCurrentRow()
{
if(!model)
return false;
switch(mode)
{
case NewReceivingAddress:
Expand All @@ -78,6 +80,8 @@ bool EditAddressDialog::saveCurrentRow()

void EditAddressDialog::accept()
{
if(!model)
return;
if(!saveCurrentRow())
{
switch(model->getEditStatus())
Expand Down
36 changes: 20 additions & 16 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,34 @@ void OverviewPage::setNumTransactions(int count)
void OverviewPage::setModel(WalletModel *model)
{
this->model = model;
if(model)
{
// Set up transaction list
TransactionFilterProxy *filter = new TransactionFilterProxy();
filter->setSourceModel(model->getTransactionTableModel());
filter->setLimit(NUM_ITEMS);
filter->setDynamicSortFilter(true);
filter->setSortRole(Qt::EditRole);
filter->sort(TransactionTableModel::Status, Qt::DescendingOrder);

// Set up transaction list
TransactionFilterProxy *filter = new TransactionFilterProxy();
filter->setSourceModel(model->getTransactionTableModel());
filter->setLimit(NUM_ITEMS);
filter->setDynamicSortFilter(true);
filter->setSortRole(Qt::EditRole);
filter->sort(TransactionTableModel::Status, Qt::DescendingOrder);

ui->listTransactions->setModel(filter);
ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress);
ui->listTransactions->setModel(filter);
ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress);

// Keep up to date with wallet
setBalance(model->getBalance(), model->getUnconfirmedBalance());
connect(model, SIGNAL(balanceChanged(qint64, qint64)), this, SLOT(setBalance(qint64, qint64)));
// Keep up to date with wallet
setBalance(model->getBalance(), model->getUnconfirmedBalance());
connect(model, SIGNAL(balanceChanged(qint64, qint64)), this, SLOT(setBalance(qint64, qint64)));

setNumTransactions(model->getNumTransactions());
connect(model, SIGNAL(numTransactionsChanged(int)), this, SLOT(setNumTransactions(int)));
setNumTransactions(model->getNumTransactions());
connect(model, SIGNAL(numTransactionsChanged(int)), this, SLOT(setNumTransactions(int)));

connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(displayUnitChanged()));
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(displayUnitChanged()));
}
}

void OverviewPage::displayUnitChanged()
{
if(!model || !model->getOptionsModel())
return;
if(currentBalance != -1)
setBalance(currentBalance, currentUnconfirmedBalance);

Expand Down
15 changes: 12 additions & 3 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ void SendCoinsDialog::setModel(WalletModel *model)
entry->setModel(model);
}
}

setBalance(model->getBalance(), model->getUnconfirmedBalance());
connect(model, SIGNAL(balanceChanged(qint64, qint64)), this, SLOT(setBalance(qint64, qint64)));
if(model)
{
setBalance(model->getBalance(), model->getUnconfirmedBalance());
connect(model, SIGNAL(balanceChanged(qint64, qint64)), this, SLOT(setBalance(qint64, qint64)));
}
}

SendCoinsDialog::~SendCoinsDialog()
Expand All @@ -57,6 +59,10 @@ void SendCoinsDialog::on_sendButton_clicked()
{
QList<SendCoinsRecipient> recipients;
bool valid = true;

if(!model)
return;

for(int i = 0; i < ui->entries->count(); ++i)
{
SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
Expand Down Expand Up @@ -255,6 +261,9 @@ void SendCoinsDialog::handleURL(const QUrl *url)
void SendCoinsDialog::setBalance(qint64 balance, qint64 unconfirmedBalance)
{
Q_UNUSED(unconfirmedBalance);
if(!model || !model->getOptionsModel())
return;

int unit = model->getOptionsModel()->getDisplayUnit();
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balance));
}
Loading

0 comments on commit ba1fce9

Please sign in to comment.