Skip to content

Commit

Permalink
Bitcoin-Qt: add "send coins" to context menu in addressbook
Browse files Browse the repository at this point in the history
- allows to directly select an address from the addressbook, chose "send
  coins" from the context menu, which sends you to sendcoins tab and fills
  in the selected address
  • Loading branch information
Philip Kaufmann committed Mar 18, 2013
1 parent 74e4d80 commit 311993a
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/qt/addressbookpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
QAction *copyAddressAction = new QAction(ui->copyToClipboard->text(), this);
QAction *copyLabelAction = new QAction(tr("Copy &Label"), 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);
Expand All @@ -78,6 +79,8 @@ 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
Expand All @@ -91,6 +94,7 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(onCopyLabelAction()));
connect(editAction, SIGNAL(triggered()), this, SLOT(onEditAction()));
connect(deleteAction, SIGNAL(triggered()), this, SLOT(on_deleteButton_clicked()));
connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(onSendCoins_clicked()));
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()));
Expand Down Expand Up @@ -206,6 +210,18 @@ void AddressBookPage::on_verifyMessage_clicked()
}
}

void AddressBookPage::onSendCoins_clicked()
{
QTableView *table = ui->tableView;
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);

foreach (QModelIndex index, indexes)
{
QString address = index.data().toString();
emit sendCoins(address);
}
}

void AddressBookPage::on_newAddressButton_clicked()
{
if(!model)
Expand Down
3 changes: 3 additions & 0 deletions src/qt/addressbookpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ private slots:
void on_signMessage_clicked();
/** Open the verify message tab in the Sign/Verify Message dialog with currently selected address */
void on_verifyMessage_clicked();
/** Open send coins dialog for currently selected address (no button) */
void onSendCoins_clicked();
/** Generate a QR Code from the currently selected address */
void on_showQRCode_clicked();
/** Copy label of currently selected address entry to clipboard (no button) */
Expand All @@ -85,6 +87,7 @@ private slots:
signals:
void signMessage(QString addr);
void verifyMessage(QString addr);
void sendCoins(QString addr);
};

#endif // ADDRESSBOOKPAGE_H
11 changes: 8 additions & 3 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
rpcConsole = new RPCConsole(this);
connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(show()));

// Clicking on "Verify Message" in the address book sends you to the verify message tab
// Clicking on "Send Coins" in the address book sends you to the send coins tab
connect(addressBookPage, SIGNAL(sendCoins(QString)), this, SLOT(gotoSendCoinsPage(QString)));
// Clicking on "Verify Message" in the address book opens the verify message tab in the Sign/Verify Message dialog
connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
// Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
// Clicking on "Sign Message" in the receive coins page opens the sign message tab in the Sign/Verify Message dialog
connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));

// Install event filter to be able to catch status tip events (QEvent::StatusTip)
Expand Down Expand Up @@ -758,13 +760,16 @@ void BitcoinGUI::gotoReceiveCoinsPage()
connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked()));
}

void BitcoinGUI::gotoSendCoinsPage()
void BitcoinGUI::gotoSendCoinsPage(QString addr)
{
sendCoinsAction->setChecked(true);
centralWidget->setCurrentWidget(sendCoinsPage);

exportAction->setEnabled(false);
disconnect(exportAction, SIGNAL(triggered()), 0, 0);

if(!addr.isEmpty())
sendCoinsPage->setAddress(addr);
}

void BitcoinGUI::gotoSignMessageTab(QString addr)
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private slots:
/** Switch to receive coins page */
void gotoReceiveCoinsPage();
/** Switch to send coins page */
void gotoSendCoinsPage();
void gotoSendCoinsPage(QString addr = "");

/** Show Sign/Verify Message dialog and switch to sign message tab */
void gotoSignMessageTab(QString addr = "");
Expand Down
20 changes: 20 additions & 0 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,26 @@ QWidget *SendCoinsDialog::setupTabChain(QWidget *prev)
return ui->sendButton;
}

void SendCoinsDialog::setAddress(const QString &address)
{
SendCoinsEntry *entry = 0;
// Replace the first entry if it is still unused
if(ui->entries->count() == 1)
{
SendCoinsEntry *first = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(0)->widget());
if(first->isClear())
{
entry = first;
}
}
if(!entry)
{
entry = addEntry();
}

entry->setAddress(address);
}

void SendCoinsDialog::pasteEntry(const SendCoinsRecipient &rv)
{
if(!fNewRecipientAllowed)
Expand Down
1 change: 1 addition & 0 deletions src/qt/sendcoinsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SendCoinsDialog : public QDialog
*/
QWidget *setupTabChain(QWidget *prev);

void setAddress(const QString &address);
void pasteEntry(const SendCoinsRecipient &rv);
bool handleURI(const QString &uri);

Expand Down
6 changes: 6 additions & 0 deletions src/qt/sendcoinsentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
ui->payAmount->setValue(value.amount);
}

void SendCoinsEntry::setAddress(const QString &address)
{
ui->payTo->setText(address);
ui->payAmount->setFocus();
}

bool SendCoinsEntry::isClear()
{
return ui->payTo->text().isEmpty();
Expand Down
1 change: 1 addition & 0 deletions src/qt/sendcoinsentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SendCoinsEntry : public QFrame
bool isClear();

void setValue(const SendCoinsRecipient &value);
void setAddress(const QString &address);

/** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://bugreports.qt-project.org/browse/QTBUG-10907).
*/
Expand Down

0 comments on commit 311993a

Please sign in to comment.