Accept "bitcoin:" URL drops from browsers
[novacoin.git] / src / qt / bitcoingui.cpp
index bd80e42..b20f633 100644 (file)
@@ -38,6 +38,9 @@
 #include <QDateTime>
 #include <QMovie>
 
+#include <QDragEnterEvent>
+#include <QUrl>
+
 #include <QDebug>
 
 #include <iostream>
@@ -85,7 +88,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
     QVBoxLayout *vbox = new QVBoxLayout();
 
     transactionView = new TransactionView(this);
-    connect(transactionView, SIGNAL(doubleClicked(const QModelIndex&)), transactionView, SLOT(showDetails()));
+    connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
     vbox->addWidget(transactionView);
 
     transactionsPage = new QWidget(this);
@@ -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,13 +137,17 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
 
     statusBar()->addWidget(progressBarLabel);
     statusBar()->addWidget(progressBar);
-    statusBar()->addPermanentWidget(frameConnections);
     statusBar()->addPermanentWidget(frameBlocks);
 
     createTrayIcon();
 
     syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this);
 
+    // Clicking on a transaction simply sends you to transaction history page
+    connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
+
+    setAcceptDrops(true);
+
     gotoOverviewPage();
 }
 
@@ -252,8 +246,8 @@ void BitcoinGUI::setWalletModel(WalletModel *walletModel)
     sendCoinsPage->setModel(walletModel);
 
     // Balloon popup for new transaction
-    connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
-            this, SLOT(incomingTransaction(const QModelIndex &, int, int)));
+    connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
+            this, SLOT(incomingTransaction(QModelIndex,int,int)));
 }
 
 void BitcoinGUI::createTrayIcon()
@@ -309,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)
@@ -356,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);
@@ -376,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);
 }
@@ -463,7 +458,7 @@ void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int
         trayIcon->showMessage((amount)<0 ? tr("Sent transaction") :
                                            tr("Incoming transaction"),
                               tr("Date: ") + date + "\n" +
-                              tr("Amount: ") + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, amount, true) + "\n" +
+                              tr("Amount: ") + BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true) + "\n" +
                               tr("Type: ") + type + "\n" +
                               tr("Address: ") + address + "\n",
                               QSystemTrayIcon::Information);
@@ -512,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();
+}
+