Make "Quit" menu saner
[novacoin.git] / src / qt / bitcoingui.cpp
index 0c2eaab..25261c7 100644 (file)
@@ -20,6 +20,7 @@
 #include "bitcoinunits.h"
 #include "guiconstants.h"
 #include "askpassphrasedialog.h"
+#include "notificator.h"
 
 #include <QApplication>
 #include <QMainWindow>
@@ -51,7 +52,8 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
     walletModel(0),
     encryptWalletAction(0),
     changePassphraseAction(0),
-    trayIcon(0)
+    trayIcon(0),
+    notificator(0)
 {
     resize(850, 550);
     setWindowTitle(tr("Bitcoin Wallet"));
@@ -63,9 +65,6 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
 
     // Menus
     QMenu *file = menuBar()->addMenu(tr("&File"));
-    file->addAction(sendCoinsAction);
-    file->addAction(receiveCoinsAction);
-    file->addSeparator();
     file->addAction(quitAction);
     
     QMenu *settings = menuBar()->addMenu(tr("&Settings"));
@@ -195,8 +194,9 @@ void BitcoinGUI::createActions()
     connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
     connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
 
-    quitAction = new QAction(QIcon(":/icons/quit"), tr("&Exit"), this);
+    quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
     quitAction->setToolTip(tr("Quit application"));
+    quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
     aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About"), this);
     aboutAction->setToolTip(tr("Show information about Bitcoin"));
     optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
@@ -214,7 +214,7 @@ void BitcoinGUI::createActions()
     connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
     connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
     connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
-    connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(show()));
+    connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormal()));
     connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
     connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
 }
@@ -287,15 +287,18 @@ void BitcoinGUI::createTrayIcon()
     connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
             this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
     trayIcon->show();
+
+    notificator = new Notificator(tr("bitcoin-qt"), trayIcon);
 }
 
 void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
 {
     if(reason == QSystemTrayIcon::Trigger)
     {
-        // Doubleclick on system tray icon triggers "open bitcoin"
+        // Click on system tray icon triggers "open bitcoin"
         openBitcoinAction->trigger();
     }
+
 }
 
 void BitcoinGUI::optionsClicked()
@@ -329,15 +332,16 @@ void BitcoinGUI::setNumConnections(int count)
 
 void BitcoinGUI::setNumBlocks(int count)
 {
-    int total = clientModel->getTotalBlocksEstimate();
+    int initTotal = clientModel->getNumBlocksAtStartup();
+    int total = clientModel->getNumBlocksOfPeers();
     QString tooltip;
 
     if(count < total)
     {
         progressBarLabel->setVisible(true);
         progressBar->setVisible(true);
-        progressBar->setMaximum(total);
-        progressBar->setValue(count);
+        progressBar->setMaximum(total - initTotal);
+        progressBar->setValue(count - initTotal);
         tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total);
     }
     else
@@ -394,18 +398,7 @@ void BitcoinGUI::setNumBlocks(int count)
 void BitcoinGUI::error(const QString &title, const QString &message)
 {
     // Report errors from network/worker thread
-    if(trayIcon->supportsMessages())
-    {
-        // Show as "balloon" message if possible
-        trayIcon->showMessage(title, message, QSystemTrayIcon::Critical);
-    }
-    else
-    {
-        // Fall back to old fashioned popup dialog if not
-        QMessageBox::critical(this, title,
-            message,
-            QMessageBox::Ok, QMessageBox::Ok);
-    }
+    notificator->notify(Notificator::Critical, title, message);
 }
 
 void BitcoinGUI::changeEvent(QEvent *e)
@@ -421,6 +414,7 @@ void BitcoinGUI::changeEvent(QEvent *e)
             }
             else
             {
+                show();
                 e->accept();
             }
         }
@@ -453,8 +447,6 @@ void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
 
 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
 {
-    if(start == end)
-        return;
     TransactionTableModel *ttm = walletModel->getTransactionTableModel();
     qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
                     .data(Qt::EditRole).toULongLong();
@@ -468,14 +460,21 @@ void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int
                         .data().toString();
         QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
                         .data().toString();
-
-        trayIcon->showMessage((amount)<0 ? tr("Sent transaction") :
-                                           tr("Incoming transaction"),
-                              tr("Date: ") + date + "\n" +
-                              tr("Amount: ") + BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true) + "\n" +
-                              tr("Type: ") + type + "\n" +
-                              tr("Address: ") + address + "\n",
-                              QSystemTrayIcon::Information);
+        QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
+                            TransactionTableModel::ToAddress, parent)
+                        .data(Qt::DecorationRole));
+
+        notificator->notify(Notificator::Information,
+                            (amount)<0 ? tr("Sent transaction") :
+                                         tr("Incoming transaction"),
+                              tr("Date: %1\n"
+                                 "Amount: %2\n"
+                                 "Type: %3\n"
+                                 "Address: %4\n")
+                              .arg(date)
+                              .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
+                              .arg(type)
+                              .arg(address), icon);
     }
 }
 
@@ -521,11 +520,6 @@ void BitcoinGUI::gotoReceiveCoinsPage()
 void BitcoinGUI::gotoSendCoinsPage()
 {
     sendCoinsAction->setChecked(true);
-    if(centralWidget->currentWidget() != sendCoinsPage)
-    {
-        // Clear the current contents if we arrived from another tab
-        sendCoinsPage->clear();
-    }
     centralWidget->setCurrentWidget(sendCoinsPage);
 
     exportAction->setEnabled(false);
@@ -602,7 +596,7 @@ void BitcoinGUI::changePassphrase()
 
 void BitcoinGUI::unlockWallet()
 {
-    // Unlock wallet if needed
+    // Unlock wallet when requested by wallet model
     if(walletModel->getEncryptionStatus() == WalletModel::Locked)
     {
         AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);