Browse Source

allow adding address to address book in send dialog

0.8
Wladimir J. van der Laan 14 years ago
parent
commit
38deedc1b5
  1. 7
      src/qt/clientmodel.cpp
  2. 2
      src/qt/clientmodel.h
  3. 30
      src/qt/forms/sendcoinsdialog.ui
  4. 14
      src/qt/sendcoinsdialog.cpp
  5. 1
      src/qt/sendcoinsdialog.h

7
src/qt/clientmodel.cpp

@ -60,7 +60,7 @@ void ClientModel::update()
addressTableModel->update(); addressTableModel->update();
} }
ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payAmount) ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payAmount, const QString &addToAddressBookAs)
{ {
uint160 hash160 = 0; uint160 hash160 = 0;
bool valid = false; bool valid = false;
@ -95,7 +95,7 @@ ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payA
std::string strError = SendMoney(scriptPubKey, payAmount, wtx, true); std::string strError = SendMoney(scriptPubKey, payAmount, wtx, true);
if (strError == "") if (strError == "")
{ {
return OK; // OK
} }
else if (strError == "ABORTED") else if (strError == "ABORTED")
{ {
@ -107,11 +107,12 @@ ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payA
return MiscError; return MiscError;
} }
} }
// Add addresses that we've sent to to the address book // Add addresses that we've sent to to the address book
std::string strAddress = payTo.toStdString(); std::string strAddress = payTo.toStdString();
CRITICAL_BLOCK(cs_mapAddressBook) CRITICAL_BLOCK(cs_mapAddressBook)
if (!mapAddressBook.count(strAddress)) if (!mapAddressBook.count(strAddress))
SetAddressBookName(strAddress, ""); SetAddressBookName(strAddress, addToAddressBookAs.toStdString());
return OK; return OK;
} }

2
src/qt/clientmodel.h

@ -39,7 +39,7 @@ public:
int getTotalBlocksEstimate() const; int getTotalBlocksEstimate() const;
/* Send coins */ /* Send coins */
StatusCode sendCoins(const QString &payTo, qint64 payAmount); StatusCode sendCoins(const QString &payTo, qint64 payAmount, const QString &addToAddressBookAs=QString());
private: private:
OptionsModel *optionsModel; OptionsModel *optionsModel;
AddressTableModel *addressTableModel; AddressTableModel *addressTableModel;

30
src/qt/forms/sendcoinsdialog.ui

@ -16,7 +16,7 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="4" column="0"> <item row="5" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>&amp;Amount:</string> <string>&amp;Amount:</string>
@ -90,9 +90,33 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="5" column="1">
<widget class="BitcoinAmountField" name="payAmount" native="true"/> <widget class="BitcoinAmountField" name="payAmount" native="true"/>
</item> </item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="addToAddressBook">
<property name="toolTip">
<string>Add specified destination address to address book</string>
</property>
<property name="text">
<string>Add to address book as</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="addAsLabel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Label to add address as</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -170,6 +194,8 @@
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>payTo</tabstop> <tabstop>payTo</tabstop>
<tabstop>addToAddressBook</tabstop>
<tabstop>addAsLabel</tabstop>
<tabstop>payAmount</tabstop> <tabstop>payAmount</tabstop>
<tabstop>pasteButton</tabstop> <tabstop>pasteButton</tabstop>
<tabstop>addressBookButton</tabstop> <tabstop>addressBookButton</tabstop>

14
src/qt/sendcoinsdialog.cpp

@ -46,6 +46,7 @@ void SendCoinsDialog::on_sendButton_clicked()
{ {
bool valid; bool valid;
QString payAmount = ui->payAmount->text(); QString payAmount = ui->payAmount->text();
QString label;
qint64 payAmountParsed; qint64 payAmountParsed;
valid = ParseMoney(payAmount.toStdString(), payAmountParsed); valid = ParseMoney(payAmount.toStdString(), payAmountParsed);
@ -58,7 +59,13 @@ void SendCoinsDialog::on_sendButton_clicked()
return; return;
} }
switch(model->sendCoins(ui->payTo->text(), payAmountParsed)) if(ui->addToAddressBook->isChecked())
{
// Add address to address book under label, if specified
label = ui->addAsLabel->text();
}
switch(model->sendCoins(ui->payTo->text(), payAmountParsed, label))
{ {
case ClientModel::InvalidAddress: case ClientModel::InvalidAddress:
QMessageBox::warning(this, tr("Send Coins"), QMessageBox::warning(this, tr("Send Coins"),
@ -110,3 +117,8 @@ void SendCoinsDialog::on_buttonBox_rejected()
{ {
reject(); reject();
} }
void SendCoinsDialog::on_addToAddressBook_toggled(bool checked)
{
ui->addAsLabel->setEnabled(checked);
}

1
src/qt/sendcoinsdialog.h

@ -23,6 +23,7 @@ private:
ClientModel *model; ClientModel *model;
private slots: private slots:
void on_addToAddressBook_toggled(bool checked);
void on_buttonBox_rejected(); void on_buttonBox_rejected();
void on_addressBookButton_clicked(); void on_addressBookButton_clicked();
void on_pasteButton_clicked(); void on_pasteButton_clicked();

Loading…
Cancel
Save