Add context menu on transaction list: copy label, copy address, edit label, show...
[novacoin.git] / src / qt / bitcoingui.cpp
index 99dbbc1..5291951 100644 (file)
@@ -35,6 +35,7 @@
 #include <QMessageBox>
 #include <QProgressBar>
 #include <QStackedWidget>
+#include <QDateTime>
 
 #include <QDebug>
 
@@ -83,7 +84,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
     QVBoxLayout *vbox = new QVBoxLayout();
 
     transactionView = new TransactionView(this);
-    connect(transactionView, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(transactionDetails(const QModelIndex&)));
+    connect(transactionView, SIGNAL(doubleClicked(const QModelIndex&)), transactionView, SLOT(transactionDetails()));
     vbox->addWidget(transactionView);
 
     transactionsPage = new QWidget(this);
@@ -109,11 +110,13 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
     labelConnections = new QLabel();
     labelConnections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
     labelConnections->setMinimumWidth(150);
+    labelConnections->setMaximumWidth(150);
     labelConnections->setToolTip(tr("Number of connections to other clients"));
 
     labelBlocks = new QLabel();
     labelBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
-    labelBlocks->setMinimumWidth(130);
+    labelBlocks->setMinimumWidth(150);
+    labelBlocks->setMaximumWidth(150);
     labelBlocks->setToolTip(tr("Number of blocks in the block chain"));
 
     // Progress bar for blocks download
@@ -190,7 +193,7 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
 
     if(clientModel->isTestNet())
     {
-        QString title_testnet = tr("Bitcoin Wallet [testnet]");
+        QString title_testnet = windowTitle() + QString(" ") + tr("[testnet]");
         setWindowTitle(title_testnet);
         setWindowIcon(QIcon(":icons/bitcoin_testnet"));
         if(trayIcon)
@@ -226,7 +229,7 @@ void BitcoinGUI::setWalletModel(WalletModel *walletModel)
     connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
 
     // Put transaction list in tabs
-    transactionView->setModel(walletModel->getTransactionTableModel());
+    transactionView->setModel(walletModel);
 
     addressBookPage->setModel(walletModel->getAddressTableModel());
     receiveCoinsPage->setModel(walletModel->getAddressTableModel());
@@ -314,7 +317,34 @@ void BitcoinGUI::setNumBlocks(int count)
         progressBar->setVisible(false);
     }
 
-    labelBlocks->setText(tr("%n block(s)", "", count));
+    QDateTime now = QDateTime::currentDateTime();
+    QDateTime lastBlockDate = clientModel->getLastBlockDate();
+    int secs = lastBlockDate.secsTo(now);
+    QString text;
+    QString icon = ":/icons/notsynced";
+
+    // "Up to date" icon, and outdated icon
+    if(secs < 30*60)
+    {
+        text = "Up to date";
+        icon = ":/icons/synced";
+    }
+    else if(secs < 60*60)
+    {
+        text = tr("%n minute(s) ago","",secs/60);
+    }
+    else if(secs < 24*60*60)
+    {
+        text = tr("%n hour(s) ago","",secs/(60*60));
+    }
+    else
+    {
+        text = tr("%n day(s) ago","",secs/(60*60*24));
+    }
+
+    labelBlocks->setText("<img src=\""+icon+"\"> " + text);
+    labelBlocks->setToolTip(tr("%n block(s) in total, last block was generated %1", "", count)
+                            .arg(QLocale::system().toString(lastBlockDate)));
 }
 
 void BitcoinGUI::setNumTransactions(int count)
@@ -381,13 +411,6 @@ void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
     *payFee = (retval == QMessageBox::Yes);
 }
 
-void BitcoinGUI::transactionDetails(const QModelIndex& idx)
-{
-    // A transaction is doubleclicked
-    TransactionDescDialog dlg(idx);
-    dlg.exec();
-}
-
 void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
 {
     TransactionTableModel *ttm = walletModel->getTransactionTableModel();
@@ -444,6 +467,7 @@ void BitcoinGUI::gotoReceiveCoinsPage()
 void BitcoinGUI::gotoSendCoinsPage()
 {
     sendCoinsAction->setChecked(true);
+    sendCoinsPage->clear();
     centralWidget->setCurrentWidget(sendCoinsPage);
     exportAction->setEnabled(false);
 }