Accept "bitcoin:" URL drops from browsers
[novacoin.git] / src / qt / bitcoingui.cpp
index 6e76065..b20f633 100644 (file)
@@ -38,6 +38,9 @@
 #include <QDateTime>
 #include <QMovie>
 
+#include <QDragEnterEvent>
+#include <QUrl>
+
 #include <QDebug>
 
 #include <iostream>
@@ -108,34 +111,21 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
     // Create status bar
     statusBar();
 
-    // Status bar "Connections" notification
-    QFrame *frameConnections = new QFrame();
-    frameConnections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
-    frameConnections->setMinimumWidth(150);
-    frameConnections->setMaximumWidth(150);
-    QHBoxLayout *frameConnectionsLayout = new QHBoxLayout(frameConnections);
-    frameConnectionsLayout->setContentsMargins(3,0,3,0);
-    frameConnectionsLayout->setSpacing(3);
-    labelConnectionsIcon = new QLabel();
-    labelConnectionsIcon->setToolTip(tr("Number of connections to other clients"));
-    frameConnectionsLayout->addWidget(labelConnectionsIcon);
-    labelConnections = new QLabel();
-    labelConnections->setToolTip(tr("Number of connections to other clients"));
-    frameConnectionsLayout->addWidget(labelConnections);
-    frameConnectionsLayout->addStretch();
-
     // Status bar "Blocks" notification
     QFrame *frameBlocks = new QFrame();
-    frameBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
-    frameBlocks->setMinimumWidth(150);
-    frameBlocks->setMaximumWidth(150);
+    //frameBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
+    frameBlocks->setContentsMargins(0,0,0,0);
+    frameBlocks->setMinimumWidth(56);
+    frameBlocks->setMaximumWidth(56);
     QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
     frameBlocksLayout->setContentsMargins(3,0,3,0);
     frameBlocksLayout->setSpacing(3);
+    labelConnectionsIcon = new QLabel();
     labelBlocksIcon = new QLabel();
+    frameBlocksLayout->addStretch();
+    frameBlocksLayout->addWidget(labelConnectionsIcon);
+    frameBlocksLayout->addStretch();
     frameBlocksLayout->addWidget(labelBlocksIcon);
-    labelBlocks = new QLabel();
-    frameBlocksLayout->addWidget(labelBlocks);
     frameBlocksLayout->addStretch();
 
     // Progress bar for blocks download
@@ -147,7 +137,6 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
 
     statusBar()->addWidget(progressBarLabel);
     statusBar()->addWidget(progressBar);
-    statusBar()->addPermanentWidget(frameConnections);
     statusBar()->addPermanentWidget(frameBlocks);
 
     createTrayIcon();
@@ -157,7 +146,9 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
     // Clicking on a transaction simply sends you to transaction history page
     connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
 
-    gotoOverviewPage();    
+    setAcceptDrops(true);
+
+    gotoOverviewPage();
 }
 
 void BitcoinGUI::createActions()
@@ -312,7 +303,7 @@ void BitcoinGUI::setNumConnections(int count)
     default: icon = ":/icons/connect_4"; break;
     }
     labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(16,16));
-    labelConnections->setText(tr("%n connection(s)", "", count));
+    labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
 }
 
 void BitcoinGUI::setNumBlocks(int count)
@@ -359,13 +350,16 @@ void BitcoinGUI::setNumBlocks(int count)
     }
 
     // In the label we want to be less specific
-    QString labelText = text;
     bool spinning = true;
     if(secs < 30*60)
     {
-        labelText = "Up to date";
+        tooltip = tr("Up to date") + QString("\n") + tooltip;
         spinning = false;
     }
+    else
+    {
+        tooltip = tr("Catching up...") + QString("\n") + tooltip;
+    }
 
     tooltip += QString("\n");
     tooltip += tr("Last received block was generated %1.").arg(text);
@@ -379,10 +373,8 @@ void BitcoinGUI::setNumBlocks(int count)
     {
         labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(16,16));
     }
-    labelBlocks->setText(labelText);
 
     labelBlocksIcon->setToolTip(tooltip);
-    labelBlocks->setToolTip(tooltip);
     progressBarLabel->setToolTip(tooltip);
     progressBar->setToolTip(tooltip);
 }
@@ -515,10 +507,36 @@ void BitcoinGUI::gotoReceiveCoinsPage()
 void BitcoinGUI::gotoSendCoinsPage()
 {
     sendCoinsAction->setChecked(true);
-    sendCoinsPage->clear();
+    if(centralWidget->currentWidget() != sendCoinsPage)
+    {
+        // Clear the current contents if we arrived from another tab
+        sendCoinsPage->clear();
+    }
     centralWidget->setCurrentWidget(sendCoinsPage);
 
     exportAction->setEnabled(false);
     disconnect(exportAction, SIGNAL(triggered()), 0, 0);
 }
 
+void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
+{
+    // Accept only URLs
+    if(event->mimeData()->hasUrls())
+        event->acceptProposedAction();
+}
+
+void BitcoinGUI::dropEvent(QDropEvent *event)
+{
+    if(event->mimeData()->hasUrls())
+    {
+        gotoSendCoinsPage();
+        QList<QUrl> urls = event->mimeData()->urls();
+        foreach(const QUrl &url, urls)
+        {
+            sendCoinsPage->handleURL(&url);
+        }
+    }
+
+    event->acceptProposedAction();
+}
+