X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Ftransactionview.cpp;h=88b119a9e65601dab388fdd1a73320792d7fb607;hb=63e4509c569f16145ab861717baf865fc6d05af1;hp=64891359d05b9c9a41a748ccdbc9fce64cd8d127;hpb=2c8f88fc67af7916670ce0086e6a9078df8182f0;p=novacoin.git diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 6489135..88b119a 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -11,6 +11,7 @@ #include "editaddressdialog.h" #include "optionsmodel.h" #include "guiutil.h" +#include "wallet.h" #include #include @@ -28,6 +29,10 @@ #include #include #include +#include +#include +#include +#include TransactionView::TransactionView(QWidget *parent) : QWidget(parent), model(0), transactionProxyModel(0), @@ -129,6 +134,7 @@ TransactionView::TransactionView(QWidget *parent) : QAction *copyTxIDAction = new QAction(tr("Copy transaction ID"), this); QAction *editLabelAction = new QAction(tr("Edit label"), this); QAction *showDetailsAction = new QAction(tr("Show transaction details"), this); + QAction *clearOrphansAction = new QAction(tr("Clear orphans"), this); contextMenu = new QMenu(); contextMenu->addAction(copyAddressAction); @@ -137,8 +143,14 @@ TransactionView::TransactionView(QWidget *parent) : contextMenu->addAction(copyTxIDAction); contextMenu->addAction(editLabelAction); contextMenu->addAction(showDetailsAction); + contextMenu->addSeparator(); + contextMenu->addAction(clearOrphansAction); + + mapperThirdPartyTxUrls = new QSignalMapper(this); // Connect actions + connect(mapperThirdPartyTxUrls, SIGNAL(mapped(QString)), this, SLOT(openThirdPartyTxUrl(QString))); + connect(dateWidget, SIGNAL(activated(int)), this, SLOT(chooseDate(int))); connect(typeWidget, SIGNAL(activated(int)), this, SLOT(chooseType(int))); connect(addressWidget, SIGNAL(textChanged(QString)), this, SLOT(changedPrefix(QString))); @@ -153,9 +165,10 @@ TransactionView::TransactionView(QWidget *parent) : connect(copyTxIDAction, SIGNAL(triggered()), this, SLOT(copyTxID())); connect(editLabelAction, SIGNAL(triggered()), this, SLOT(editLabel())); connect(showDetailsAction, SIGNAL(triggered()), this, SLOT(showDetails())); + connect(clearOrphansAction, SIGNAL(triggered()), this, SLOT(clearOrphans())); } -void TransactionView::setModel(WalletModel *model) +void TransactionView::setModel(WalletModel *model, bool fShoudAddThirdPartyURL) { this->model = model; if(model) @@ -167,6 +180,7 @@ void TransactionView::setModel(WalletModel *model) transactionProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); transactionProxyModel->setSortRole(Qt::EditRole); +// transactionProxyModel->setSortRole(TransactionTableModel::DateRole); transactionView->setModel(transactionProxyModel); transactionView->setAlternatingRowColors(true); @@ -182,10 +196,33 @@ void TransactionView::setModel(WalletModel *model) TransactionTableModel::Date, 120); transactionView->horizontalHeader()->resizeSection( TransactionTableModel::Type, 120); +#if QT_VERSION < 0x050000 transactionView->horizontalHeader()->setResizeMode( TransactionTableModel::ToAddress, QHeaderView::Stretch); +#else + transactionView->horizontalHeader()->setSectionResizeMode(TransactionTableModel::ToAddress, QHeaderView::Stretch); +#endif transactionView->horizontalHeader()->resizeSection( - TransactionTableModel::Amount, 100); + TransactionTableModel::Amount, 130); + + if (model->getOptionsModel() && fShoudAddThirdPartyURL) + { + // Add third party transaction URLs to context menu + QStringList listUrls = model->getOptionsModel()->getThirdPartyTxUrls().split("|", QString::SkipEmptyParts); + for (int i = 0; i < listUrls.size(); ++i) + { + QString host = QUrl(listUrls[i].trimmed(), QUrl::StrictMode).host(); + if (!host.isEmpty()) + { + QAction *thirdPartyTxUrlAction = new QAction(host, this); // use host as menu item label + if (i == 0) + contextMenu->addSeparator(); + contextMenu->addAction(thirdPartyTxUrlAction); + connect(thirdPartyTxUrlAction, SIGNAL(triggered()), mapperThirdPartyTxUrls, SLOT(map())); + mapperThirdPartyTxUrls->setMapping(thirdPartyTxUrlAction, listUrls[i].trimmed()); + } + } + } } } @@ -222,7 +259,7 @@ void TransactionView::chooseDate(int idx) break; case LastMonth: transactionProxyModel->setDateRange( - QDateTime(QDate(current.year(), current.month()-1, 1)), + QDateTime(QDate(current.year(), current.month(), 1).addMonths(-1)), QDateTime(QDate(current.year(), current.month(), 1))); break; case ThisYear: @@ -379,10 +416,38 @@ void TransactionView::showDetails() if(!selection.isEmpty()) { TransactionDescDialog dlg(selection.at(0)); - dlg.exec(); + dlg.setWindowModality(Qt::ApplicationModal); + dlg.show(); + + // This loop will wait for the window is closed + QEventLoop loop; + connect(&dlg, SIGNAL(stopExec()), &loop, SLOT(quit())); + loop.exec(); } } +void TransactionView::clearOrphans() +{ + if(!model) + return; + + model->clearOrphans(); + model->getTransactionTableModel()->refresh(); + delete transactionProxyModel; + setModel(model, false); + transactionView->sortByColumn(TransactionTableModel::Status, Qt::DescendingOrder); + transactionView->sortByColumn(TransactionTableModel::Date, Qt::DescendingOrder); +} + +void TransactionView::openThirdPartyTxUrl(QString url) +{ + if(!transactionView->selectionModel()) + return; + QModelIndexList selection = transactionView->selectionModel()->selectedRows(0); + if(!selection.isEmpty()) + QDesktopServices::openUrl(QUrl::fromUserInput(url.replace("%s", selection.at(0).data(TransactionTableModel::TxHashRole).toString()))); +} + QWidget *TransactionView::createDateRangeWidget() { dateRangeWidget = new QFrame();