aboutsummaryrefslogtreecommitdiff
path: root/src/qt
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt')
-rw-r--r--src/qt/addressbookpage.cpp26
-rw-r--r--src/qt/addressbookpage.h19
-rw-r--r--src/qt/addresstablemodel.cpp36
-rw-r--r--src/qt/addresstablemodel.h23
-rw-r--r--src/qt/bitcoin.cpp1
-rw-r--r--src/qt/editaddressdialog.cpp30
-rw-r--r--src/qt/editaddressdialog.h8
-rw-r--r--src/qt/guiutil.cpp3
8 files changed, 91 insertions, 55 deletions
diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp
index 263fd52790..f4696d5a3b 100644
--- a/src/qt/addressbookpage.cpp
+++ b/src/qt/addressbookpage.cpp
@@ -62,8 +62,8 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
}
// Context menu actions
- QAction *copyLabelAction = new QAction(tr("Copy &Label"), this);
QAction *copyAddressAction = new QAction(ui->copyToClipboard->text(), this);
+ QAction *copyLabelAction = new QAction(tr("Copy &Label"), this);
QAction *editAction = new QAction(tr("&Edit"), this);
QAction *showQRCodeAction = new QAction(ui->showQRCode->text(), this);
QAction *signMessageAction = new QAction(ui->signMessage->text(), this);
@@ -78,7 +78,9 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
if(tab == SendingTab)
contextMenu->addAction(deleteAction);
contextMenu->addSeparator();
+#ifdef USE_QRCODE
contextMenu->addAction(showQRCodeAction);
+#endif
if(tab == ReceivingTab)
contextMenu->addAction(signMessageAction);
else if(tab == SendingTab)
@@ -184,36 +186,31 @@ 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);
}
-
- emit verifyMessage(addr);
}
void AddressBookPage::on_newAddressButton_clicked()
{
if(!model)
return;
+
EditAddressDialog dlg(
tab == SendingTab ?
EditAddressDialog::NewSendingAddress :
@@ -230,6 +227,7 @@ void AddressBookPage::on_deleteButton_clicked()
QTableView *table = ui->tableView;
if(!table->selectionModel())
return;
+
QModelIndexList indexes = table->selectionModel()->selectedRows();
if(!indexes.isEmpty())
{
@@ -341,11 +339,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();
}
diff --git a/src/qt/addressbookpage.h b/src/qt/addressbookpage.h
index 6d3a734a16..c676d1e941 100644
--- a/src/qt/addressbookpage.h
+++ b/src/qt/addressbookpage.h
@@ -54,26 +54,31 @@ private:
QString returnValue;
QSortFilterProxyModel *proxyModel;
QMenu *contextMenu;
- QAction *deleteAction;
+ QAction *deleteAction; // to be able to explicitly disable it
QString newAddressToSelect;
private slots:
+ /** Delete currently selected address entry */
void on_deleteButton_clicked();
+ /** Create a new address for receiving coins and / or add a new address book entry */
void on_newAddressButton_clicked();
/** Copy address of currently selected address entry to clipboard */
void on_copyToClipboard_clicked();
+ /** Open the sign message tab in the Sign/Verify Message dialog with currently selected address */
void on_signMessage_clicked();
+ /** Open the verify message tab in the Sign/Verify Message dialog with currently selected address */
void on_verifyMessage_clicked();
- void selectionChanged();
+ /** Generate a QR Code from the currently selected address */
void on_showQRCode_clicked();
- /** Spawn contextual menu (right mouse menu) for address book entry */
- void contextualMenu(const QPoint &point);
-
- /** Copy label of currently selected address entry to clipboard */
+ /** Copy label of currently selected address entry to clipboard (no button) */
void onCopyLabelAction();
- /** Edit currently selected address entry */
+ /** Edit currently selected address entry (no button) */
void onEditAction();
+ /** Set button states based on selected tab and selection */
+ void selectionChanged();
+ /** Spawn contextual menu (right mouse menu) for address book entry */
+ void contextualMenu(const QPoint &point);
/** New entry/entries were added to address table */
void selectNewAddress(const QModelIndex &parent, int begin, int /*end*/);
diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp
index e65d3915ec..03b09cdceb 100644
--- a/src/qt/addresstablemodel.cpp
+++ b/src/qt/addresstablemodel.cpp
@@ -69,6 +69,8 @@ public:
QString::fromStdString(address.ToString())));
}
}
+ // qLowerBound() and qUpperBound() require our cachedAddressTable list to be sorted in asc order
+ qSort(cachedAddressTable.begin(), cachedAddressTable.end(), AddressTableEntryLessThan());
}
void updateEntry(const QString &address, const QString &label, bool isMine, int status)
@@ -208,7 +210,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
return QVariant();
}
-bool AddressTableModel::setData(const QModelIndex & index, const QVariant & value, int role)
+bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if(!index.isValid())
return false;
@@ -221,18 +223,36 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
switch(index.column())
{
case Label:
+ // Do nothing, if old label == new label
+ if(rec->label == value.toString())
+ {
+ editStatus = NO_CHANGES;
+ return false;
+ }
wallet->SetAddressBookName(CBitcoinAddress(rec->address.toStdString()).Get(), value.toString().toStdString());
- rec->label = value.toString();
break;
case Address:
+ // Do nothing, if old address == new address
+ if(CBitcoinAddress(rec->address.toStdString()) == CBitcoinAddress(value.toString().toStdString()))
+ {
+ editStatus = NO_CHANGES;
+ return false;
+ }
// Refuse to set invalid address, set error status and return false
- if(!walletModel->validateAddress(value.toString()))
+ else if(!walletModel->validateAddress(value.toString()))
{
editStatus = INVALID_ADDRESS;
return false;
}
+ // Check for duplicate addresses to prevent accidental deletion of addresses, if you try
+ // to paste an existing address over another address (with a different label)
+ else if(wallet->mapAddressBook.count(CBitcoinAddress(value.toString().toStdString()).Get()))
+ {
+ editStatus = DUPLICATE_ADDRESS;
+ return false;
+ }
// Double-check that we're not overwriting a receiving address
- if(rec->type == AddressTableEntry::Sending)
+ else if(rec->type == AddressTableEntry::Sending)
{
{
LOCK(wallet->cs_wallet);
@@ -244,7 +264,6 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
}
break;
}
-
return true;
}
return false;
@@ -262,7 +281,7 @@ QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation,
return QVariant();
}
-Qt::ItemFlags AddressTableModel::flags(const QModelIndex & index) const
+Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
return 0;
@@ -279,7 +298,7 @@ Qt::ItemFlags AddressTableModel::flags(const QModelIndex & index) const
return retval;
}
-QModelIndex AddressTableModel::index(int row, int column, const QModelIndex & parent) const
+QModelIndex AddressTableModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);
AddressTableEntry *data = priv->index(row);
@@ -345,6 +364,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
{
return QString();
}
+
// Add entry
{
LOCK(wallet->cs_wallet);
@@ -353,7 +373,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
return QString::fromStdString(strAddress);
}
-bool AddressTableModel::removeRows(int row, int count, const QModelIndex & parent)
+bool AddressTableModel::removeRows(int row, int count, const QModelIndex &parent)
{
Q_UNUSED(parent);
AddressTableEntry *rec = priv->index(row);
diff --git a/src/qt/addresstablemodel.h b/src/qt/addresstablemodel.h
index 42974e3e1f..ae3e3b2f04 100644
--- a/src/qt/addresstablemodel.h
+++ b/src/qt/addresstablemodel.h
@@ -29,26 +29,27 @@ public:
/** Return status of edit/insert operation */
enum EditStatus {
- OK,
- INVALID_ADDRESS, /**< Unparseable address */
- DUPLICATE_ADDRESS, /**< Address already in address book */
- WALLET_UNLOCK_FAILURE, /**< Wallet could not be unlocked to create new receiving address */
- KEY_GENERATION_FAILURE /**< Generating a new public key for a receiving address failed */
+ OK, /**< Everything ok */
+ NO_CHANGES, /**< No changes were made during edit operation */
+ INVALID_ADDRESS, /**< Unparseable address */
+ DUPLICATE_ADDRESS, /**< Address already in address book */
+ WALLET_UNLOCK_FAILURE, /**< Wallet could not be unlocked to create new receiving address */
+ KEY_GENERATION_FAILURE /**< Generating a new public key for a receiving address failed */
};
- static const QString Send; /**< Specifies send address */
- static const QString Receive; /**< Specifies receive address */
+ static const QString Send; /**< Specifies send address */
+ static const QString Receive; /**< Specifies receive address */
/** @name Methods overridden from QAbstractTableModel
@{*/
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
- bool setData(const QModelIndex & index, const QVariant & value, int role);
+ bool setData(const QModelIndex &index, const QVariant &value, int role);
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
- QModelIndex index(int row, int column, const QModelIndex & parent) const;
- bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
- Qt::ItemFlags flags(const QModelIndex & index) const;
+ QModelIndex index(int row, int column, const QModelIndex &parent) const;
+ bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
+ Qt::ItemFlags flags(const QModelIndex &index) const;
/*@}*/
/* Add an address to the model.
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index c3701ced7f..e5526a6c09 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -86,6 +86,7 @@ static void InitMessage(const std::string &message)
splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(255,255,200));
QApplication::instance()->processEvents();
}
+ printf("init message: %s\n", message.c_str());
}
static void QueueShutdown()
diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp
index 0d88aa47cb..5cfcb34b95 100644
--- a/src/qt/editaddressdialog.cpp
+++ b/src/qt/editaddressdialog.cpp
@@ -25,7 +25,7 @@ EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) :
break;
case EditReceivingAddress:
setWindowTitle(tr("Edit receiving address"));
- ui->addressEdit->setDisabled(true);
+ ui->addressEdit->setEnabled(false);
break;
case EditSendingAddress:
setWindowTitle(tr("Edit sending address"));
@@ -44,6 +44,9 @@ EditAddressDialog::~EditAddressDialog()
void EditAddressDialog::setModel(AddressTableModel *model)
{
this->model = model;
+ if(!model)
+ return;
+
mapper->setModel(model);
mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
@@ -58,6 +61,7 @@ bool EditAddressDialog::saveCurrentRow()
{
if(!model)
return false;
+
switch(mode)
{
case NewReceivingAddress:
@@ -82,35 +86,39 @@ void EditAddressDialog::accept()
{
if(!model)
return;
+
if(!saveCurrentRow())
{
switch(model->getEditStatus())
{
- case AddressTableModel::DUPLICATE_ADDRESS:
- QMessageBox::warning(this, windowTitle(),
- tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
- QMessageBox::Ok, QMessageBox::Ok);
+ case AddressTableModel::OK:
+ // Failed with unknown reason. Just reject.
+ break;
+ case AddressTableModel::NO_CHANGES:
+ // No changes were made during edit operation. Just reject.
break;
case AddressTableModel::INVALID_ADDRESS:
QMessageBox::warning(this, windowTitle(),
tr("The entered address \"%1\" is not a valid Bitcoin address.").arg(ui->addressEdit->text()),
QMessageBox::Ok, QMessageBox::Ok);
- return;
+ break;
+ case AddressTableModel::DUPLICATE_ADDRESS:
+ QMessageBox::warning(this, windowTitle(),
+ tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
+ QMessageBox::Ok, QMessageBox::Ok);
+ break;
case AddressTableModel::WALLET_UNLOCK_FAILURE:
QMessageBox::critical(this, windowTitle(),
tr("Could not unlock wallet."),
QMessageBox::Ok, QMessageBox::Ok);
- return;
+ break;
case AddressTableModel::KEY_GENERATION_FAILURE:
QMessageBox::critical(this, windowTitle(),
tr("New key generation failed."),
QMessageBox::Ok, QMessageBox::Ok);
- return;
- case AddressTableModel::OK:
- // Failed with unknown reason. Just reject.
break;
- }
+ }
return;
}
QDialog::accept();
diff --git a/src/qt/editaddressdialog.h b/src/qt/editaddressdialog.h
index 7ec053f135..0e4183bd52 100644
--- a/src/qt/editaddressdialog.h
+++ b/src/qt/editaddressdialog.h
@@ -27,15 +27,17 @@ public:
};
explicit EditAddressDialog(Mode mode, QWidget *parent = 0);
- ~EditAddressDialog();
+ ~EditAddressDialog();
void setModel(AddressTableModel *model);
void loadRow(int row);
- void accept();
-
QString getAddress() const;
void setAddress(const QString &address);
+
+public slots:
+ void accept();
+
private:
bool saveCurrentRow();
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index ff70ca24af..d4e73adf96 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -77,7 +77,8 @@ void setupAmountWidget(QLineEdit *widget, QWidget *parent)
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
{
- if(uri.scheme() != QString("bitcoin"))
+ // return if URI is not valid or is no bitcoin URI
+ if(!uri.isValid() || uri.scheme() != QString("bitcoin"))
return false;
SendCoinsRecipient rv;