changed progressbar text to "~n blocks remaining"
[novacoin.git] / src / qt / bitcoingui.cpp
index abf2c38..319a2f9 100644 (file)
@@ -48,6 +48,7 @@
 #include <QMovie>
 #include <QFileDialog>
 #include <QDesktopServices>
+#include <QTimer>
 
 #include <QDragEnterEvent>
 #include <QUrl>
@@ -375,7 +376,7 @@ void BitcoinGUI::createTrayIcon()
     trayIcon = new QSystemTrayIcon(this);
     trayIconMenu = new QMenu(this);
     trayIcon->setContextMenu(trayIconMenu);
-    trayIcon->setToolTip("Bitcoin client");
+    trayIcon->setToolTip(tr("Bitcoin client"));
     trayIcon->setIcon(QIcon(":/icons/toolbar"));
     connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
             this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
@@ -450,20 +451,33 @@ void BitcoinGUI::setNumConnections(int count)
 
 void BitcoinGUI::setNumBlocks(int count)
 {
-    if(!clientModel)
+    // don't show / hide progressBar and it's label if we have no connection(s) to the network
+    if (!clientModel || clientModel->getNumConnections() == 0)
+    {
+        progressBarLabel->setVisible(false);
+        progressBar->setVisible(false);
+
         return;
-    int total = clientModel->getNumBlocksOfPeers();
+    }
+
+    int nTotal = clientModel->getNumBlocksOfPeers();
     QString tooltip;
 
-    if(count < total)
+    if(count < nTotal)
     {
+        int nCurMax = nTotal - count;
+        int nOnePercentCurMax = nCurMax / 100;
+        int nPercentageDone = (count / (nTotal / 100));
+
         if (clientModel->getStatusBarWarnings() == "")
         {
             progressBarLabel->setVisible(true);
             progressBarLabel->setText(tr("Synchronizing with network..."));
             progressBar->setVisible(true);
-            progressBar->setMaximum(total);
-            progressBar->setValue(count);
+            progressBar->setFormat(tr("~%m blocks remaining"));
+            progressBar->setAlignment(Qt::AlignCenter);
+            progressBar->setMaximum(nCurMax);
+            progressBar->setValue(nOnePercentCurMax * nPercentageDone);
         }
         else
         {
@@ -471,7 +485,7 @@ void BitcoinGUI::setNumBlocks(int count)
             progressBarLabel->setVisible(true);
             progressBar->setVisible(false);
         }
-        tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total);
+        tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotal).arg(nPercentageDone);
     }
     else
     {
@@ -558,29 +572,21 @@ void BitcoinGUI::error(const QString &title, const QString &message)
 
 void BitcoinGUI::changeEvent(QEvent *e)
 {
+    QMainWindow::changeEvent(e);
 #ifndef Q_WS_MAC // Ignored on Mac
     if(e->type() == QEvent::WindowStateChange)
     {
         if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
         {
             QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
-            bool wasMinimized = wsevt->oldState() & Qt::WindowMinimized;
-            bool isMinimized = windowState() & Qt::WindowMinimized;
-            if(!wasMinimized && isMinimized)
-            {
-                // Minimized, hide the window from taskbar
-                setWindowFlags(windowFlags() | Qt::Tool);
-                return;
-            }
-            else if(wasMinimized && !isMinimized)
+            if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
             {
-                // Unminimized, show the window in taskbar
-                setWindowFlags(windowFlags() &~ Qt::Tool);
+                QTimer::singleShot(0, this, SLOT(hide()));
+                e->ignore();
             }
         }
     }
 #endif
-    QMainWindow::changeEvent(e);
 }
 
 void BitcoinGUI::closeEvent(QCloseEvent *event)
@@ -740,6 +746,11 @@ void BitcoinGUI::handleURL(QString strURL)
 {
     gotoSendCoinsPage();
     sendCoinsPage->handleURL(strURL);
+
+    if(!isActiveWindow())
+        activateWindow();
+
+    showNormalIfMinimized();
 }
 
 void BitcoinGUI::setEncryptionStatus(int status)