Fix status bar not displaying Alerts.
[novacoin.git] / src / qt / addressbookpage.cpp
index 063e510..0a147c9 100644 (file)
@@ -9,7 +9,6 @@
 #include <QClipboard>
 #include <QFileDialog>
 #include <QMessageBox>
-#include <QDebug>
 
 AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
     QDialog(parent),
@@ -19,6 +18,13 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
     tab(tab)
 {
     ui->setupUi(this);
+
+#ifdef Q_WS_MAC // Icons on push buttons are very uncommon on Mac
+    ui->newAddressButton->setIcon(QIcon());
+    ui->copyToClipboard->setIcon(QIcon());
+    ui->deleteButton->setIcon(QIcon());
+#endif
+
     switch(mode)
     {
     case ForSending:
@@ -51,6 +57,8 @@ AddressBookPage::~AddressBookPage()
 void AddressBookPage::setModel(AddressTableModel *model)
 {
     this->model = model;
+    if(!model)
+        return;
     // Refresh list from core
     model->updateList();
 
@@ -90,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)
@@ -111,17 +116,33 @@ void AddressBookPage::on_copyToClipboard_clicked()
 
 void AddressBookPage::on_newAddressButton_clicked()
 {
+    if(!model)
+        return;
     EditAddressDialog dlg(
             tab == SendingTab ?
             EditAddressDialog::NewSendingAddress :
             EditAddressDialog::NewReceivingAddress);
     dlg.setModel(model);
-    dlg.exec();
+    if(dlg.exec())
+    {
+        // Select row for newly created address
+        QString address = dlg.getAddress();
+        QModelIndexList lst = proxyModel->match(proxyModel->index(0,
+                          AddressTableModel::Address, QModelIndex()),
+                          Qt::EditRole, address, 1, Qt::MatchExactly);
+        if(!lst.isEmpty())
+        {
+            ui->tableView->setFocus();
+            ui->tableView->selectRow(lst.at(0).row());
+        }
+    }
 }
 
 void AddressBookPage::on_deleteButton_clicked()
 {
-    QTableView *table = getCurrentTable();
+    QTableView *table = ui->tableView;
+    if(!table->selectionModel())
+        return;
     QModelIndexList indexes = table->selectionModel()->selectedRows();
     if(!indexes.isEmpty())
     {
@@ -132,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())
     {
@@ -156,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)