Add context menu on transaction list: copy label, copy address, edit label, show...
[novacoin.git] / src / qt / transactiontablemodel.cpp
index 65e1632..17622e0 100644 (file)
@@ -4,6 +4,7 @@
 #include "guiconstants.h"
 #include "transactiondesc.h"
 #include "walletmodel.h"
+#include "addresstablemodel.h"
 
 #include "headers.h"
 
@@ -208,7 +209,7 @@ TransactionTableModel::TransactionTableModel(CWallet* wallet, WalletModel *paren
         walletModel(parent),
         priv(new TransactionTablePriv(wallet, this))
 {
-    columns << tr("Status") << tr("Date") << tr("Type") << tr("Address") << tr("Amount");
+    columns << QString() << tr("Date") << tr("Type") << tr("Address") << tr("Amount");
 
     priv->refreshWallet();
 
@@ -278,7 +279,7 @@ QVariant TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) con
         status = tr("Offline (%1 confirmations)").arg(wtx->status.depth);
         break;
     case TransactionStatus::Unconfirmed:
-        status = tr("Unconfirmed (%1/%2 confirmations)").arg(wtx->status.depth).arg(TransactionRecord::NumConfirmations);
+        status = tr("Unconfirmed (%1 of %2 confirmations required)").arg(wtx->status.depth).arg(TransactionRecord::NumConfirmations);
         break;
     case TransactionStatus::HaveConfirmations:
         status = tr("Confirmed (%1 confirmations)").arg(wtx->status.depth);
@@ -286,11 +287,11 @@ QVariant TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) con
     }
     if(wtx->type == TransactionRecord::Generated)
     {
-        status += "\n";
+        status += "\n\n";
         switch(wtx->status.maturity)
         {
         case TransactionStatus::Immature:
-            status += tr("Generation matures in %n more blocks", "",
+            status += tr("Mined balance will be available in %n more blocks", "",
                            wtx->status.matures_in);
             break;
         case TransactionStatus::Mature:
@@ -320,12 +321,12 @@ QVariant TransactionTableModel::formatTxDate(const TransactionRecord *wtx) const
 }
 
 /* Look up address in address book, if found return
-     address[0:12]... (label)
+     address (label)
    otherwise just return address
  */
 QString TransactionTableModel::lookupAddress(const std::string &address) const
 {
-    QString label = walletModel->labelForAddress(QString::fromStdString(address));
+    QString label = walletModel->getAddressTableModel()->labelForAddress(QString::fromStdString(address));
     QString description;
     if(label.isEmpty())
     {
@@ -333,7 +334,7 @@ QString TransactionTableModel::lookupAddress(const std::string &address) const
     }
     else
     {
-        description = label + QString(" (") + QString::fromStdString(address.substr(0,12)) + QString("...)");
+        description = label + QString(" (") + QString::fromStdString(address) + QString(")");
     }
     return description;
 }
@@ -360,7 +361,7 @@ QVariant TransactionTableModel::formatTxType(const TransactionRecord *wtx) const
         description = tr("Payment to yourself");
         break;
     case TransactionRecord::Generated:
-        description = tr("Generated");
+        description = tr("Mined");
         break;
     }
     return QVariant(description);
@@ -394,12 +395,15 @@ QVariant TransactionTableModel::formatTxToAddress(const TransactionRecord *wtx)
     return QVariant(description);
 }
 
-QVariant TransactionTableModel::formatTxAmount(const TransactionRecord *wtx) const
+QVariant TransactionTableModel::formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed) const
 {
     QString str = QString::fromStdString(FormatMoney(wtx->credit + wtx->debit));
-    if(!wtx->status.confirmed || wtx->status.maturity != TransactionStatus::Mature)
+    if(showUnconfirmed)
     {
-        str = QString("[") + str + QString("]");
+        if(!wtx->status.confirmed || wtx->status.maturity != TransactionStatus::Mature)
+        {
+            str = QString("[") + str + QString("]");
+        }
     }
     return QVariant(str);
 }
@@ -535,12 +539,24 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
     }
     else if (role == LabelRole)
     {
-        return walletModel->labelForAddress(QString::fromStdString(rec->address));
+        return walletModel->getAddressTableModel()->labelForAddress(QString::fromStdString(rec->address));
     }
     else if (role == AbsoluteAmountRole)
     {
         return llabs(rec->credit + rec->debit);
     }
+    else if (role == TxIDRole)
+    {
+        return QString::fromStdString(rec->getTxID());
+    }
+    else if (role == ConfirmedRole)
+    {
+        return rec->status.status == TransactionStatus::HaveConfirmations;
+    }
+    else if (role == FormattedAmountRole)
+    {
+        return formatTxAmount(rec, false);
+    }
     return QVariant();
 }