PRCYCoin  2.0.0.7rc1
P2P Digital Currency
historypage.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include "historypage.h"
6 #include "ui_historypage.h"
7 
8 #include "addressbookpage.h"
9 #include "addresstablemodel.h"
10 #include "bitcoingui.h"
11 #include "bitcoinunits.h"
12 #include "guiconstants.h"
13 #include "guiutil.h"
14 #include "optionsmodel.h"
15 #include "transactionrecord.h"
16 #include "walletmodel.h"
17 #include "revealtxdialog.h"
18 
19 #include <algorithm>
20 
21 #include <QAction>
22 #include <QBrush>
23 #include <QCalendarWidget>
24 #include <QCursor>
25 #include <QItemSelection>
26 #include <QScrollBar>
27 #include <QSortFilterProxyModel>
28 #include <QTextDocument>
29 #include <QTime>
30 #include <QDate>
31 #include <QTextStream>
32 #include <QProcess>
33 
34 HistoryPage::HistoryPage(QWidget* parent) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
35  ui(new Ui::HistoryPage),
36  // m_SizeGrip(this),
37  model(0)
38 
39 {
40  ui->setupUi(this);
41 
42  initWidgets();
46 }
47 
48 
50 {
51  delete ui;
52 }
54 {
55  //set String for all addresses
56  allAddressString = "All addresses...";
57  //adjust qt paint flags
58  ui->tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
59  ui->tableView->setAttribute(Qt::WA_TranslucentBackground, true);
60  connect(ui->tableView, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(on_cellClicked(int, int)));
61 
62  //set date formats and init date from current timestamp
63  ui->dateTimeEditTo->setDisplayFormat("M/d/yy");
64  ui->dateTimeEditFrom->setDisplayFormat("M/d/yy");
65  ui->dateTimeEditTo->setDateTime(QDateTime::currentDateTime().addDays(1));
66  ui->dateTimeEditFrom->setDateTime(QDateTime::currentDateTime().addDays(-7));
67  //add QTimeEdit's to QCalendar popups
68  timeEditTo = new QTimeEdit(ui->dateTimeEditTo);
69  timeEditFrom = new QTimeEdit(ui->dateTimeEditFrom);
70  ui->dateTimeEditTo->calendarWidget()->parentWidget()->layout()->addWidget(timeEditTo);
71  ui->dateTimeEditFrom->calendarWidget()->parentWidget()->layout()->addWidget(timeEditFrom);
72  //color calendarwidgets
73  GUIUtil::colorCalendarWidgetWeekends(ui->dateTimeEditTo->calendarWidget(), QColor("gray"));
74  GUIUtil::colorCalendarWidgetWeekends(ui->dateTimeEditFrom->calendarWidget(), QColor("gray"));
75  ui->horizontalLayout_2->setAlignment(Qt::AlignTop);
76 }
77 
78 void HistoryPage::connectWidgets() //add functions to widget signals
79 {
80  connect(ui->dateTimeEditTo, SIGNAL(dateChanged(const QDate&)), this, SLOT(updateFilter()));
81  connect(ui->dateTimeEditFrom, SIGNAL(dateChanged(const QDate&)), this, SLOT(updateFilter()));
82  connect(ui->comboBoxType, SIGNAL(currentIndexChanged(const int&)), this, SLOT(updateFilter()));
83  //
84  connect(ui->lineEditDesc, SIGNAL(currentIndexChanged(const int&)), this, SLOT(updateFilter()));
85  connect(ui->lineEditDesc->lineEdit(), SIGNAL(textChanged(const QString&)), this, SLOT(updateFilter()));
86 
87  //
88  connect(ui->lineEditAmount, SIGNAL(textChanged(const QString&)), this, SLOT(updateFilter()));
89  //
90  connect(timeEditFrom, SIGNAL(timeChanged(const QTime&)), this, SLOT(updateFilter()));
91  connect(timeEditTo, SIGNAL(timeChanged(const QTime&)), this, SLOT(updateFilter()));
92 }
93 
94 void HistoryPage::on_cellClicked(int row, int column)
95 {
96  if (pwalletMain->IsLocked()) return;
97  //1 is column index for type
98  QTableWidgetItem* cell = ui->tableView->item(row, 1);
99  QString type = cell->data(0).toString();
100  std::string stdType = type.trimmed().toStdString();
101  //2 is column index for address
102  cell = ui->tableView->item(row, 2);
103  QString address = cell->data(0).toString();
104  //3 is column index for amount
105  cell = ui->tableView->item(row, 3);
106  QString amount = cell->data(0).toString();
107  std::string stdAddress = address.trimmed().toStdString();
108  if (pwalletMain->addrToTxHashMap.count(stdAddress) == 1) {
109  RevealTxDialog txdlg;
110  txdlg.setStyleSheet(GUIUtil::loadStyleSheet());
111 
112  txdlg.setTxID(pwalletMain->addrToTxHashMap[stdAddress].c_str());
113 
114  txdlg.setTxAddress(stdAddress.c_str());
115  bool privkeyFound = false;
116  std::string txHash = pwalletMain->addrToTxHashMap[stdAddress];
117  if (IsHex(txHash)) {
118  uint256 hash;
119  hash.SetHex(txHash);
120 
121  if (pwalletMain && pwalletMain->mapWallet.count(hash) == 1) {
122  CWalletTx tx = pwalletMain->mapWallet[hash];
123  for (size_t i = 0; i < tx.vout.size(); i++) {
124  txnouttype type;
125  std::vector<CTxDestination> addresses;
126  int nRequired;
127 
128  if (ExtractDestinations(tx.vout[i].scriptPubKey, type, addresses, nRequired)) {
129  std::string parseddAddress = CBitcoinAddress(addresses[0]).ToString();
130  if (stdAddress == parseddAddress) {
131  if (tx.IsCoinStake() && !tx.vout[i].txPriv.empty()) {
132  CKey txPriv;
133  txPriv.Set(tx.vout[i].txPriv.begin(), tx.vout[i].txPriv.end(), true);
134  txdlg.setTxPrivKey(CBitcoinSecret(txPriv).ToString().c_str());
135  privkeyFound = true;
136  } else {
137  std::string key = txHash + std::to_string(i);
138  std::string secret;
140  txdlg.setTxPrivKey(secret.c_str());
141  privkeyFound = true;
142  }
143  }
144  }
145  }
146  }
147  txdlg.setTxAmount(amount);
148  txdlg.setTxFee(tx.nTxFee);
149  if (tx.hasPaymentID) {
150  txdlg.setTxPaymentID(tx.paymentID);
151  } else {
152  txdlg.setTxPaymentID(0);
153  }
154  txdlg.setTxRingSize(tx.vin[0].decoys.size() + 1);
155  }
156  }
157  std::string txdlgMsg = "Request from Sender (if applicable)";
158  if (stdType == "Minted") {
159  privkeyFound = false;
160  txdlgMsg = "Minted transactions do not have a PrivKey";
161  }
162  if (pwalletMain->IsLocked()) {
163  privkeyFound = false;
164  txdlgMsg = "Wallet must be unlocked to view PrivKey";
165  }
166  if (!privkeyFound) txdlg.setTxPrivKey(std::string(txdlgMsg).c_str());
167 
168  txdlg.exec();
169  }
170 }
171 
172 void HistoryPage::resizeEvent(QResizeEvent* event)
173 {
174  QWidget::resizeEvent(event);
175  ui->tableView->setColumnWidth(2, this->width() * .65);
176  ui->tableView->resizeColumnToContents(QHeaderView::ResizeToContents);
177  ui->tableView->resizeColumnsToContents();
178 }
179 
180 void HistoryPage::keyPressEvent(QKeyEvent* event)
181 {
182  this->QDialog::keyPressEvent(event);
183 }
184 
186 {
187  if (pwalletMain) {
189  }
190 }
191 
193 {
194  if (!wallet || wallet->IsLocked()) return;
195  TRY_LOCK(cs_main, lockMain);
196  if (!lockMain)
197  return;
198  TRY_LOCK(pwalletMain->cs_wallet, lockWallet);
199  if (!lockWallet)
200  return;
201  {
202  ui->tableView->setSortingEnabled(false);
203  while (ui->tableView->rowCount() > 0)
204  {
205  ui->tableView->removeRow(0);
206  }
207  ui->tableView->setRowCount(0);
208  std::vector<std::map<QString, QString> > txs;
209  txs = WalletUtil::getTXs(wallet);
210  for (int row = 0; row < (short)txs.size(); row++) {
211  ui->tableView->insertRow(row);
212  int col = 0;
213  for (QString dataName : {"date", "type", "address", "amount", "confirmations"}) {
214  QString data = txs[row].at(dataName);
215  QDateTime date;
216  QTableWidgetItem* cell = new QTableWidgetItem();
217  switch (col) {
218  case 0: /*date*/
219  date = QDateTime::fromString(data, "MM/dd/yy hh:mm:ss").addYears(100);
220  cell->setData(0, date);
221  break;
222  case 3: /*amount*/
223  if (settings.value("fHideBalance", false).toBool()) {
224  cell->setData(0, QString("Hidden"));
225  } else {
226  cell->setData(0, data);
227  }
228  break;
229  case 4: /*confirmations*/
230  cell->setData(0, data.toInt());
231  break;
232  default:
233  cell->setData(0, data);
234  break;
235  }
236  ui->tableView->setItem(row, col, cell);
237  cell->setTextAlignment(Qt::AlignCenter);
238  col++;
239  }
240  }
241  ui->tableView->setVisible(ui->tableView->rowCount());
242  ui->tableView->sortByColumn(4, Qt::AscendingOrder);
243  ui->tableView->setSortingEnabled(true);
244  }
245 }
246 
248 {
249  ui->lineEditDesc->clear();
250  ui->lineEditDesc->addItem(allAddressString);
251  QList<QString> addresses = WalletUtil::getAddressBookData(wallet);
252  for (QString address : addresses)
253  ui->lineEditDesc->addItem(address);
254  ui->lineEditDesc->lineEdit()->setText(QString(""));
255 }
256 
258 {
259  syncTime(ui->dateTimeEditFrom, timeEditFrom);
260  syncTime(ui->dateTimeEditTo, timeEditTo);
261  auto selectedAmount = ui->lineEditAmount->text().toFloat();
262  QString selectedType = ui->comboBoxType->currentText();
263  QList<QString> selectedAddresses = ui->lineEditDesc->lineEdit()->text().split(" | ");
264 
265  for (int row = 0; row < ui->tableView->rowCount(); row++) {
266  bool hide = false;
267  QDateTime date = QDateTime::fromString(ui->tableView->item(row, 0)->text(), "yyyy-MM-ddThh:mm:ss");
268  QString type = ui->tableView->item(row, 1)->text();
269  QString address = ui->tableView->item(row, 2)->text();
270  auto amount = ui->tableView->item(row, 3)->text().toFloat();
271 
272  if (
273  (ui->dateTimeEditFrom->dateTime() > date) || (ui->dateTimeEditTo->dateTime() < date) || //record is not between selected dates
274 
275  (amount < selectedAmount) //record smaller than selected min amount
276  )
277  hide = true;
278  if (selectedType != tr("All Types")) {
279  if (selectedType == tr("Received")) {
280  hide = hide || !(type == tr("Received"));
281  } else if (selectedType == tr("Sent")) {
282  hide = hide || !(type == tr("Sent"));
283  } else if (selectedType == tr("Mined")) {
284  hide = hide || !(type == tr("Mined"));
285  } else if (selectedType == tr("Minted")) {
286  hide = hide || !(type == tr("Minted"));
287  } else if (selectedType == tr("Masternode")) {
288  hide = hide || !(type == tr("Masternode"));
289  } else if (selectedType == tr("Payment to yourself")) {
290  hide = hide || !(type == tr("Payment to yourself"));
291  } else if (selectedType == tr("Rewards")) {
292  hide = hide || !(type == tr("Mined")) && !(type == tr("Minted")) && !(type == tr("Masternode"));
293  }
294  } else {
295  hide = hide || !(type == tr("Received")) && !(type == tr("Sent")) && !(type == tr("Mined")) && !(type == tr("Minted")) && !(type == tr("Masternode")) && !(type == tr("Payment to yourself"));
296  }
297 
298  if (ui->lineEditDesc->currentText() != allAddressString) {
299  bool found = false;
300  for (QString selectedAddress : selectedAddresses)
301  if (address.contains(selectedAddress))
302  found = true;
303  hide = !found || hide;
304  }
305 
306  ui->tableView->setRowHidden(row, hide);
307  }
308 }
309 
310 void HistoryPage::syncTime(QDateTimeEdit* calendar, QTimeEdit* clock)
311 {
312  calendar->setTime(clock->time());
313 }
314 
316 {
317  this->model = model;
318  connect(model, SIGNAL(WalletUnlocked()), this,
319  SLOT(updateTableData()));
320 }
HistoryPage::HistoryPage
HistoryPage(QWidget *parent=0)
Definition: historypage.cpp:34
HistoryPage::timeEditTo
QTimeEdit * timeEditTo
Definition: historypage.h:59
WalletUtil::getTXs
std::vector< std::map< QString, QString > > getTXs(CWallet *wallet)
Definition: walletmodel.cpp:757
HistoryPage::resizeEvent
virtual void resizeEvent(QResizeEvent *event)
Definition: historypage.cpp:172
HistoryPage::ui
Ui::HistoryPage * ui
Definition: historypage.h:54
CWallet::mapWallet
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:344
CWallet::addrToTxHashMap
std::map< std::string, std::string > addrToTxHashMap
Definition: wallet.h:355
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:102
historypage.h
GUIUtil::colorCalendarWidgetWeekends
void colorCalendarWidgetWeekends(QCalendarWidget *widget, QColor color)
Change the color of weekends on calendar widget *Defaults to Red.
Definition: guiutil.cpp:770
addressbookpage.h
RevealTxDialog::setTxFee
void setTxFee(CAmount fee)
Definition: revealtxdialog.cpp:82
walletmodel.h
CBitcoinAddress
base58-encoded PRCY addresses.
Definition: base58.h:109
CKey::Set
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
Definition: key.h:83
HistoryPage::connectWidgets
void connectWidgets()
Definition: historypage.cpp:78
RevealTxDialog::setTxPrivKey
void setTxPrivKey(QString strPrivKey)
Definition: revealtxdialog.cpp:71
TRY_LOCK
#define TRY_LOCK(cs, name)
Definition: sync.h:186
HistoryPage::model
WalletModel * model
Definition: historypage.h:56
HistoryPage::settings
QSettings settings
Definition: historypage.h:63
HistoryPage::~HistoryPage
~HistoryPage()
Definition: historypage.cpp:49
CBase58Data::ToString
std::string ToString() const
Definition: base58.cpp:200
CBitcoinSecret
A base58-encoded secret key.
Definition: base58.h:131
RevealTxDialog::setTxRingSize
void setTxRingSize(int64_t ringSize)
Definition: revealtxdialog.cpp:98
cs_main
RecursiveMutex cs_main
Global state.
Definition: main.cpp:65
RevealTxDialog::setTxAmount
void setTxAmount(QString amount)
Definition: revealtxdialog.cpp:76
RevealTxDialog
Definition: revealtxdialog.h:14
IsHex
bool IsHex(const std::string &str)
Definition: utilstrencodings.cpp:68
HistoryPage::updateAddressBookData
void updateAddressBookData(CWallet *wallet)
Definition: historypage.cpp:247
HistoryPage::updateTableData
void updateTableData()
Definition: historypage.cpp:185
CTransaction::vout
std::vector< CTxOut > vout
Definition: transaction.h:286
WalletUtil::getAddressBookData
QList< QString > getAddressBookData(CWallet *wallet)
Definition: walletmodel.cpp:881
CWalletDB
Access to the wallet database (wallet.dat)
Definition: walletdb.h:80
CTransaction::nTxFee
CAmount nTxFee
Definition: transaction.h:298
RevealTxDialog::setTxAddress
void setTxAddress(QString strAddr)
Definition: revealtxdialog.cpp:66
HistoryPage::updateFilter
void updateFilter()
Definition: historypage.cpp:257
guiutil.h
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
base_uint::SetHex
void SetHex(const char *psz)
Definition: arith_uint256.cpp:164
RevealTxDialog::setTxID
void setTxID(QString strId)
Definition: revealtxdialog.cpp:61
HistoryPage
Dialog for options page.
Definition: historypage.h:37
HistoryPage::timeEditFrom
QTimeEdit * timeEditFrom
Definition: historypage.h:60
transactionrecord.h
HistoryPage::allAddressString
QString allAddressString
Definition: historypage.h:62
Ui
Definition: 2faconfirmdialog.h:7
guiconstants.h
CKey
An encapsulated private key.
Definition: key.h:39
CTransaction::vin
std::vector< CTxIn > vin
Definition: transaction.h:285
key
CKey key
Definition: bip38tooldialog.cpp:173
CWallet
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:243
CWalletTx
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:792
CTransaction::paymentID
uint64_t paymentID
Definition: transaction.h:292
HistoryPage::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
Definition: historypage.cpp:180
bitcoinunits.h
CWalletDB::ReadTxPrivateKey
bool ReadTxPrivateKey(const std::string &outpointKey, std::string &k)
Definition: walletdb.cpp:1276
bitcoingui.h
CWallet::cs_wallet
RecursiveMutex cs_wallet
Definition: wallet.h:301
HistoryPage::initWidgets
void initWidgets()
Definition: historypage.cpp:53
txnouttype
txnouttype
Definition: standard.h:57
optionsmodel.h
CTransaction::hasPaymentID
char hasPaymentID
Definition: transaction.h:291
GUIUtil::loadStyleSheet
QString loadStyleSheet()
Load global CSS theme.
Definition: guiutil.cpp:721
ExtractDestinations
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
Definition: standard.cpp:223
CWallet::strWalletFile
std::string strWalletFile
Definition: wallet.h:305
pwalletMain
CWallet * pwalletMain
Definition: wallet.cpp:49
addresstablemodel.h
RevealTxDialog::setTxPaymentID
void setTxPaymentID(uint64_t paymentID)
Definition: revealtxdialog.cpp:88
CCryptoKeyStore::IsLocked
bool IsLocked() const
Definition: crypter.h:159
HistoryPage::syncTime
void syncTime(QDateTimeEdit *calendar, QTimeEdit *clock)
Definition: historypage.cpp:310
HistoryPage::on_cellClicked
void on_cellClicked(int row, int column)
Definition: historypage.cpp:94
HistoryPage::setModel
void setModel(WalletModel *model)
Definition: historypage.cpp:315
revealtxdialog.h
CTransaction::IsCoinStake
bool IsCoinStake() const
Definition: transaction.cpp:143