Accept "bitcoin:" URL drops from browsers
[novacoin.git] / src / qt / bitcoingui.cpp
index c9feca5..b20f633 100644 (file)
@@ -38,6 +38,9 @@
 #include <QDateTime>
 #include <QMovie>
 
+#include <QDragEnterEvent>
+#include <QUrl>
+
 #include <QDebug>
 
 #include <iostream>
@@ -143,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()
@@ -298,7 +303,7 @@ void BitcoinGUI::setNumConnections(int count)
     default: icon = ":/icons/connect_4"; break;
     }
     labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(16,16));
-    labelConnectionsIcon->setToolTip(tr("%n active connections to Bitcoin network", "", count));
+    labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
 }
 
 void BitcoinGUI::setNumBlocks(int count)
@@ -502,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();
+}
+