diff options
Diffstat (limited to 'src/qt/addressbookpage.cpp')
-rw-r--r-- | src/qt/addressbookpage.cpp | 104 |
1 files changed, 60 insertions, 44 deletions
diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index e20358c70e..8529c88b39 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -8,15 +8,15 @@ #include "csvmodelwriter.h" #include "guiutil.h" +#ifdef USE_QRCODE +#include "qrcodedialog.h" +#endif + #include <QSortFilterProxyModel> #include <QClipboard> #include <QMessageBox> #include <QMenu> -#ifdef USE_QRCODE -#include "qrcodedialog.h" -#endif - AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : QDialog(parent), ui(new Ui::AddressBookPage), @@ -28,9 +28,12 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : ui->setupUi(this); #ifdef Q_OS_MAC // Icons on push buttons are very uncommon on Mac - ui->newAddressButton->setIcon(QIcon()); - ui->copyToClipboard->setIcon(QIcon()); - ui->deleteButton->setIcon(QIcon()); + ui->newAddress->setIcon(QIcon()); + ui->copyAddress->setIcon(QIcon()); + ui->deleteAddress->setIcon(QIcon()); + ui->verifyMessage->setIcon(QIcon()); + ui->signMessage->setIcon(QIcon()); + ui->exportButton->setIcon(QIcon()); #endif #ifndef USE_QRCODE @@ -43,6 +46,7 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : connect(ui->tableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(accept())); ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); ui->tableView->setFocus(); + ui->exportButton->hide(); break; case ForEditing: ui->buttonBox->setVisible(false); @@ -51,24 +55,26 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : switch(tab) { case SendingTab: - ui->labelExplanation->setVisible(false); - ui->deleteButton->setVisible(true); + ui->labelExplanation->setText(tr("These are your Bitcoin addresses for sending payments. Always check the amount and the receiving address before sending coins.")); + ui->deleteAddress->setVisible(true); ui->signMessage->setVisible(false); break; case ReceivingTab: - ui->deleteButton->setVisible(false); + ui->labelExplanation->setText(tr("These are your Bitcoin addresses for receiving payments. You may want to give a different one to each sender so you can keep track of who is paying you.")); + ui->deleteAddress->setVisible(false); ui->signMessage->setVisible(true); break; } // Context menu actions + QAction *copyAddressAction = new QAction(ui->copyAddress->text(), this); QAction *copyLabelAction = new QAction(tr("Copy &Label"), this); - QAction *copyAddressAction = new QAction(ui->copyToClipboard->text(), this); QAction *editAction = new QAction(tr("&Edit"), this); + QAction *sendCoinsAction = new QAction(tr("Send &Coins"), this); QAction *showQRCodeAction = new QAction(ui->showQRCode->text(), this); QAction *signMessageAction = new QAction(ui->signMessage->text(), this); QAction *verifyMessageAction = new QAction(ui->verifyMessage->text(), this); - deleteAction = new QAction(ui->deleteButton->text(), this); + deleteAction = new QAction(ui->deleteAddress->text(), this); // Build context menu contextMenu = new QMenu(); @@ -78,17 +84,22 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : if(tab == SendingTab) contextMenu->addAction(deleteAction); contextMenu->addSeparator(); + if(tab == SendingTab) + contextMenu->addAction(sendCoinsAction); +#ifdef USE_QRCODE contextMenu->addAction(showQRCodeAction); +#endif if(tab == ReceivingTab) contextMenu->addAction(signMessageAction); else if(tab == SendingTab) contextMenu->addAction(verifyMessageAction); // Connect signals for context menu actions - connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(on_copyToClipboard_clicked())); + connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(on_copyAddress_clicked())); connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(onCopyLabelAction())); connect(editAction, SIGNAL(triggered()), this, SLOT(onEditAction())); - connect(deleteAction, SIGNAL(triggered()), this, SLOT(on_deleteButton_clicked())); + connect(deleteAction, SIGNAL(triggered()), this, SLOT(on_deleteAddress_clicked())); + connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(onSendCoinsAction())); connect(showQRCodeAction, SIGNAL(triggered()), this, SLOT(on_showQRCode_clicked())); connect(signMessageAction, SIGNAL(triggered()), this, SLOT(on_signMessage_clicked())); connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(on_verifyMessage_clicked())); @@ -132,17 +143,14 @@ void AddressBookPage::setModel(AddressTableModel *model) ui->tableView->sortByColumn(0, Qt::AscendingOrder); // Set column widths - ui->tableView->horizontalHeader()->resizeSection( - AddressTableModel::Address, 320); - ui->tableView->horizontalHeader()->setResizeMode( - AddressTableModel::Label, QHeaderView::Stretch); + ui->tableView->horizontalHeader()->setResizeMode(AddressTableModel::Label, QHeaderView::Stretch); + ui->tableView->horizontalHeader()->setResizeMode(AddressTableModel::Address, QHeaderView::ResizeToContents); connect(ui->tableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged())); // Select row for newly created address - connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), - this, SLOT(selectNewAddress(QModelIndex,int,int))); + connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(selectNewAddress(QModelIndex,int,int))); selectionChanged(); } @@ -152,7 +160,7 @@ void AddressBookPage::setOptionsModel(OptionsModel *optionsModel) this->optionsModel = optionsModel; } -void AddressBookPage::on_copyToClipboard_clicked() +void AddressBookPage::on_copyAddress_clicked() { GUIUtil::copyEntryData(ui->tableView, AddressTableModel::Address); } @@ -184,36 +192,43 @@ void AddressBookPage::on_signMessage_clicked() { QTableView *table = ui->tableView; QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address); - QString addr; foreach (QModelIndex index, indexes) { - QVariant address = index.data(); - addr = address.toString(); + QString address = index.data().toString(); + emit signMessage(address); } - - emit signMessage(addr); } void AddressBookPage::on_verifyMessage_clicked() { QTableView *table = ui->tableView; QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address); - QString addr; foreach (QModelIndex index, indexes) { - QVariant address = index.data(); - addr = address.toString(); + QString address = index.data().toString(); + emit verifyMessage(address); } +} + +void AddressBookPage::onSendCoinsAction() +{ + QTableView *table = ui->tableView; + QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address); - emit verifyMessage(addr); + foreach (QModelIndex index, indexes) + { + QString address = index.data().toString(); + emit sendCoins(address); + } } -void AddressBookPage::on_newAddressButton_clicked() +void AddressBookPage::on_newAddress_clicked() { if(!model) return; + EditAddressDialog dlg( tab == SendingTab ? EditAddressDialog::NewSendingAddress : @@ -225,11 +240,12 @@ void AddressBookPage::on_newAddressButton_clicked() } } -void AddressBookPage::on_deleteButton_clicked() +void AddressBookPage::on_deleteAddress_clicked() { QTableView *table = ui->tableView; if(!table->selectionModel()) return; + QModelIndexList indexes = table->selectionModel()->selectedRows(); if(!indexes.isEmpty()) { @@ -250,8 +266,8 @@ void AddressBookPage::selectionChanged() { case SendingTab: // In sending tab, allow deletion of selection - ui->deleteButton->setEnabled(true); - ui->deleteButton->setVisible(true); + ui->deleteAddress->setEnabled(true); + ui->deleteAddress->setVisible(true); deleteAction->setEnabled(true); ui->signMessage->setEnabled(false); ui->signMessage->setVisible(false); @@ -260,8 +276,8 @@ void AddressBookPage::selectionChanged() break; case ReceivingTab: // Deleting receiving addresses, however, is not allowed - ui->deleteButton->setEnabled(false); - ui->deleteButton->setVisible(false); + ui->deleteAddress->setEnabled(false); + ui->deleteAddress->setVisible(false); deleteAction->setEnabled(false); ui->signMessage->setEnabled(true); ui->signMessage->setVisible(true); @@ -269,14 +285,14 @@ void AddressBookPage::selectionChanged() ui->verifyMessage->setVisible(false); break; } - ui->copyToClipboard->setEnabled(true); + ui->copyAddress->setEnabled(true); ui->showQRCode->setEnabled(true); } else { - ui->deleteButton->setEnabled(false); + ui->deleteAddress->setEnabled(false); ui->showQRCode->setEnabled(false); - ui->copyToClipboard->setEnabled(false); + ui->copyAddress->setEnabled(false); ui->signMessage->setEnabled(false); ui->verifyMessage->setEnabled(false); } @@ -309,7 +325,7 @@ void AddressBookPage::done(int retval) QDialog::done(retval); } -void AddressBookPage::exportClicked() +void AddressBookPage::on_exportButton_clicked() { // CSV is currently the only supported format QString filename = GUIUtil::getSaveFileName( @@ -341,11 +357,11 @@ void AddressBookPage::on_showQRCode_clicked() foreach (QModelIndex index, indexes) { - QString address = index.data().toString(), label = index.sibling(index.row(), 0).data(Qt::EditRole).toString(); + QString address = index.data().toString(); + QString label = index.sibling(index.row(), 0).data(Qt::EditRole).toString(); QRCodeDialog *dialog = new QRCodeDialog(address, label, tab == ReceivingTab, this); - if(optionsModel) - dialog->setModel(optionsModel); + dialog->setModel(optionsModel); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); } @@ -361,7 +377,7 @@ void AddressBookPage::contextualMenu(const QPoint &point) } } -void AddressBookPage::selectNewAddress(const QModelIndex &parent, int begin, int end) +void AddressBookPage::selectNewAddress(const QModelIndex &parent, int begin, int /*end*/) { QModelIndex idx = proxyModel->mapFromSource(model->index(begin, AddressTableModel::Address, parent)); if(idx.isValid() && (idx.data(Qt::EditRole).toString() == newAddressToSelect)) |