add "BTC" to balance for clarity
[novacoin.git] / src / qt / bitcoingui.cpp
index 3a24c76..5bf79ee 100644 (file)
@@ -14,8 +14,9 @@
 #include "editaddressdialog.h"
 #include "optionsmodel.h"
 #include "transactiondescdialog.h"
+#include "addresstablemodel.h"
 
-#include "main.h"
+#include "headers.h"
 
 #include <QApplication>
 #include <QMainWindow>
@@ -36,6 +37,7 @@
 #include <QSortFilterProxyModel>
 #include <QClipboard>
 #include <QMessageBox>
+#include <QProgressBar>
 
 #include <QDebug>
 
@@ -71,7 +73,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
 
     // Address: <address>: New... : Paste to clipboard
     QHBoxLayout *hbox_address = new QHBoxLayout();
-    hbox_address->addWidget(new QLabel(tr("Your Bitcoin Address:")));
+    hbox_address->addWidget(new QLabel(tr("Your Bitcoin address:")));
     address = new QLineEdit();
     address->setReadOnly(true);
     address->setFont(GUIUtil::bitcoinAddressFont());
@@ -80,8 +82,10 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
     
     QPushButton *button_new = new QPushButton(tr("&New..."));
     button_new->setToolTip(tr("Create new receiving address"));
+    button_new->setIcon(QIcon(":/icons/add"));
     QPushButton *button_clipboard = new QPushButton(tr("&Copy to clipboard"));
     button_clipboard->setToolTip(tr("Copy current receiving address to the system clipboard"));
+    button_clipboard->setIcon(QIcon(":/icons/editcopy"));
     hbox_address->addWidget(button_new);
     hbox_address->addWidget(button_clipboard);
     
@@ -91,7 +95,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
     hbox_balance->addSpacing(5);/* Add some spacing between the label and the text */
 
     labelBalance = new QLabel();
-    labelBalance->setFont(QFont("Monospace"));
+    labelBalance->setFont(QFont("Monospace", -1, QFont::Bold));
     labelBalance->setToolTip(tr("Your current balance"));
     hbox_balance->addWidget(labelBalance);
     hbox_balance->addStretch(1);
@@ -108,12 +112,12 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
     
     // Create status bar
     statusBar();
-    
+
     labelConnections = new QLabel();
     labelConnections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
-    labelConnections->setMinimumWidth(130);
+    labelConnections->setMinimumWidth(150);
     labelConnections->setToolTip(tr("Number of connections to other clients"));
-    
+
     labelBlocks = new QLabel();
     labelBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
     labelBlocks->setMinimumWidth(130);
@@ -124,10 +128,19 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
     labelTransactions->setMinimumWidth(130);
     labelTransactions->setToolTip(tr("Number of transactions in your wallet"));
 
+    // Progress bar for blocks download
+    progressBarLabel = new QLabel(tr("Synchronizing with network..."));
+    progressBarLabel->setVisible(false);
+    progressBar = new QProgressBar();
+    progressBar->setToolTip(tr("Block chain synchronization in progress"));
+    progressBar->setVisible(false);
+
+    statusBar()->addWidget(progressBarLabel);
+    statusBar()->addWidget(progressBar);
     statusBar()->addPermanentWidget(labelConnections);
     statusBar()->addPermanentWidget(labelBlocks);
     statusBar()->addPermanentWidget(labelTransactions);
-     
+
     // Action bindings
     connect(button_new, SIGNAL(clicked()), this, SLOT(newAddressClicked()));
     connect(button_clipboard, SIGNAL(clicked()), this, SLOT(copyClipboardClicked()));
@@ -145,7 +158,7 @@ void BitcoinGUI::createActions()
     addressbook->setToolTip(tr("Edit the list of stored addresses and labels"));
     about = new QAction(QIcon(":/icons/bitcoin"), tr("&About"), this);
     about->setToolTip(tr("Show information about Bitcoin"));
-    receivingAddresses = new QAction(QIcon(":/icons/receiving-addresses"), tr("Your &Receiving Addresses..."), this);
+    receivingAddresses = new QAction(QIcon(":/icons/receiving_addresses"), tr("Your &Receiving Addresses..."), this);
     receivingAddresses->setToolTip(tr("Show the list of receiving addresses and edit their labels"));
     options = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
     options->setToolTip(tr("Modify configuration options for bitcoin"));
@@ -178,8 +191,8 @@ void BitcoinGUI::setModel(ClientModel *model)
     setNumBlocks(model->getNumBlocks());
     connect(model, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
 
-    setAddress(model->getAddress());
-    connect(model, SIGNAL(addressChanged(QString)), this, SLOT(setAddress(QString)));
+    setAddress(model->getAddressTableModel()->getDefaultAddress());
+    connect(model->getAddressTableModel(), SIGNAL(defaultAddressChanged(QString)), this, SLOT(setAddress(QString)));
 
     // Report errors from network/worker thread
     connect(model, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));    
@@ -254,6 +267,7 @@ void BitcoinGUI::setTabsModel(QAbstractItemModel *transaction_model)
 
         QTableView *transaction_table = transactionViews.at(i);
         transaction_table->setModel(proxy_model);
+        transaction_table->setAlternatingRowColors(true);
         transaction_table->setSelectionBehavior(QAbstractItemView::SelectRows);
         transaction_table->setSelectionMode(QAbstractItemView::ExtendedSelection);
         transaction_table->setSortingEnabled(true);
@@ -261,15 +275,15 @@ void BitcoinGUI::setTabsModel(QAbstractItemModel *transaction_model)
         transaction_table->verticalHeader()->hide();
 
         transaction_table->horizontalHeader()->resizeSection(
-                TransactionTableModel::Status, 145);
+                TransactionTableModel::Status, 23);
         transaction_table->horizontalHeader()->resizeSection(
                 TransactionTableModel::Date, 120);
-        transaction_table->horizontalHeader()->setResizeMode(
-                TransactionTableModel::Description, QHeaderView::Stretch);
         transaction_table->horizontalHeader()->resizeSection(
-                TransactionTableModel::Debit, 79);
+                TransactionTableModel::Type, 120);
+        transaction_table->horizontalHeader()->setResizeMode(
+                TransactionTableModel::ToAddress, QHeaderView::Stretch);
         transaction_table->horizontalHeader()->resizeSection(
-                TransactionTableModel::Credit, 79);
+                TransactionTableModel::Amount, 79);
     }
 
     connect(transaction_model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
@@ -285,7 +299,7 @@ void BitcoinGUI::sendcoinsClicked()
 
 void BitcoinGUI::addressbookClicked()
 {
-    AddressBookDialog dlg;
+    AddressBookDialog dlg(AddressBookDialog::ForEditing);
     dlg.setModel(model->getAddressTableModel());
     dlg.setTab(AddressBookDialog::SendingTab);
     dlg.exec();
@@ -293,7 +307,7 @@ void BitcoinGUI::addressbookClicked()
 
 void BitcoinGUI::receivingAddressesClicked()
 {
-    AddressBookDialog dlg;
+    AddressBookDialog dlg(AddressBookDialog::ForEditing);
     dlg.setModel(model->getAddressTableModel());
     dlg.setTab(AddressBookDialog::ReceivingTab);
     dlg.exec();
@@ -319,11 +333,6 @@ void BitcoinGUI::newAddressClicked()
     if(dlg.exec())
     {
         QString newAddress = dlg.saveCurrentRow();
-        // Set returned address as new default addres
-        if(!newAddress.isEmpty())
-        {
-            model->setAddress(newAddress);
-        }
     }
 }
 
@@ -335,7 +344,7 @@ void BitcoinGUI::copyClipboardClicked()
 
 void BitcoinGUI::setBalance(qint64 balance)
 {
-    labelBalance->setText(QString::fromStdString(FormatMoney(balance)));
+    labelBalance->setText(QString::fromStdString(FormatMoney(balance)) + QString(" BTC"));
 }
 
 void BitcoinGUI::setAddress(const QString &addr)
@@ -345,17 +354,41 @@ void BitcoinGUI::setAddress(const QString &addr)
 
 void BitcoinGUI::setNumConnections(int count)
 {
-    labelConnections->setText(QLocale::system().toString(count)+" "+tr("connections(s)", "", count));
+    QString icon;
+    switch(count)
+    {
+    case 0: icon = ":/icons/connect_0"; break;
+    case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
+    case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
+    case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
+    default: icon = ":/icons/connect_4"; break;
+    }
+    labelConnections->setTextFormat(Qt::RichText);
+    labelConnections->setText("<img src=\""+icon+"\"> " + tr("%n connection(s)", "", count));
 }
 
 void BitcoinGUI::setNumBlocks(int count)
 {
-    labelBlocks->setText(QLocale::system().toString(count)+" "+tr("block(s)", "", count));
+    int total = model->getTotalBlocksEstimate();
+    if(count < total)
+    {
+        progressBarLabel->setVisible(true);
+        progressBar->setVisible(true);
+        progressBar->setMaximum(total);
+        progressBar->setValue(count);
+    }
+    else
+    {
+        progressBarLabel->setVisible(false);
+        progressBar->setVisible(false);
+    }
+
+    labelBlocks->setText(tr("%n block(s)", "", count));
 }
 
 void BitcoinGUI::setNumTransactions(int count)
 {
-    labelTransactions->setText(QLocale::system().toString(count)+" "+tr("transaction(s)", "", count));
+    labelTransactions->setText(tr("%n transaction(s)", "", count));
 }
 
 void BitcoinGUI::error(const QString &title, const QString &message)
@@ -419,7 +452,7 @@ void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
 
 void BitcoinGUI::transactionDetails(const QModelIndex& idx)
 {
-    /* A transaction is doubleclicked */
+    // A transaction is doubleclicked
     TransactionDescDialog dlg(idx);
     dlg.exec();
 }
@@ -427,22 +460,24 @@ void BitcoinGUI::transactionDetails(const QModelIndex& idx)
 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
 {
     TransactionTableModel *ttm = model->getTransactionTableModel();
-    qint64 credit = ttm->index(start, TransactionTableModel::Credit, parent)
+    qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
                     .data(Qt::EditRole).toULongLong();
-    qint64 debit = ttm->index(start, TransactionTableModel::Debit, parent)
-                    .data(Qt::EditRole).toULongLong();
-    if((credit+debit)>0)
+    if(amount>0 && !model->inInitialBlockDownload())
     {
-        /* On incoming transaction, make an info balloon */
+        // On incoming transaction, make an info balloon
+        // Unless the initial block download is in progress, to prevent balloon-spam
         QString date = ttm->index(start, TransactionTableModel::Date, parent)
                         .data().toString();
-        QString description = ttm->index(start, TransactionTableModel::Description, parent)
+        QString type = ttm->index(start, TransactionTableModel::Type, parent)
+                        .data().toString();
+        QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
                         .data().toString();
 
         trayIcon->showMessage(tr("Incoming transaction"),
-                              "Date: " + date + "\n" +
-                              "Amount: " + QString::fromStdString(FormatMoney(credit+debit, true)) + "\n" +
-                              description,
+                              tr("Date: ") + date + "\n" +
+                              tr("Amount: ") + QString::fromStdString(FormatMoney(amount, true)) + "\n" +
+                              tr("Type: ") + type + "\n" +
+                              tr("Address: ") + address + "\n",
                               QSystemTrayIcon::Information);
     }
 }