Browse Source
Keep a list of requested payments in the Receive tab so that a user can recall previously created requests after closing their windows. Currently this list is not stored between bitcoin-qt sessions. This can be implemented later, but it is not clear where it should be stored as I don't think it belongs in the wallet (maybe in QSettings?)0.10
Wladimir J. van der Laan
11 years ago
11 changed files with 409 additions and 73 deletions
@ -0,0 +1,121 @@
@@ -0,0 +1,121 @@
|
||||
// Copyright (c) 2011-2013 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "recentrequeststablemodel.h" |
||||
#include "guiutil.h" |
||||
#include "bitcoinunits.h" |
||||
#include "optionsmodel.h" |
||||
|
||||
RecentRequestsTableModel::RecentRequestsTableModel(CWallet *wallet, WalletModel *parent): |
||||
walletModel(parent) |
||||
{ |
||||
/* These columns must match the indices in the ColumnIndex enumeration */ |
||||
columns << tr("Date") << tr("Label") << tr("Message") << tr("Amount"); |
||||
} |
||||
|
||||
RecentRequestsTableModel::~RecentRequestsTableModel() |
||||
{ |
||||
/* Intentionally left empty */ |
||||
} |
||||
|
||||
int RecentRequestsTableModel::rowCount(const QModelIndex &parent) const |
||||
{ |
||||
Q_UNUSED(parent); |
||||
return list.length(); |
||||
} |
||||
|
||||
int RecentRequestsTableModel::columnCount(const QModelIndex &parent) const |
||||
{ |
||||
Q_UNUSED(parent); |
||||
return columns.length(); |
||||
} |
||||
|
||||
QVariant RecentRequestsTableModel::data(const QModelIndex &index, int role) const |
||||
{ |
||||
if(!index.isValid() || index.row() >= list.length()) |
||||
return QVariant(); |
||||
|
||||
const RecentRequestEntry *rec = &list[index.row()]; |
||||
|
||||
if(role == Qt::DisplayRole || role == Qt::EditRole) |
||||
{ |
||||
switch(index.column()) |
||||
{ |
||||
case Date: |
||||
return GUIUtil::dateTimeStr(rec->date); |
||||
case Label: |
||||
if(rec->recipient.label.isEmpty() && role == Qt::DisplayRole) |
||||
{ |
||||
return tr("(no label)"); |
||||
} |
||||
else |
||||
{ |
||||
return rec->recipient.label; |
||||
} |
||||
case Message: |
||||
if(rec->recipient.message.isEmpty() && role == Qt::DisplayRole) |
||||
{ |
||||
return tr("(no message)"); |
||||
} |
||||
else |
||||
{ |
||||
return rec->recipient.message; |
||||
} |
||||
case Amount: |
||||
return BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), rec->recipient.amount); |
||||
} |
||||
} |
||||
return QVariant(); |
||||
} |
||||
|
||||
bool RecentRequestsTableModel::setData(const QModelIndex &index, const QVariant &value, int role) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
QVariant RecentRequestsTableModel::headerData(int section, Qt::Orientation orientation, int role) const |
||||
{ |
||||
if(orientation == Qt::Horizontal) |
||||
{ |
||||
if(role == Qt::DisplayRole && section < columns.size()) |
||||
{ |
||||
return columns[section]; |
||||
} |
||||
} |
||||
return QVariant(); |
||||
} |
||||
|
||||
QModelIndex RecentRequestsTableModel::index(int row, int column, const QModelIndex &parent) const |
||||
{ |
||||
return createIndex(row, column, 0); |
||||
} |
||||
|
||||
bool RecentRequestsTableModel::removeRows(int row, int count, const QModelIndex &parent) |
||||
{ |
||||
Q_UNUSED(parent); |
||||
if(count > 0 && row >= 0 && (row+count) <= list.size()) |
||||
{ |
||||
beginRemoveRows(parent, row, row + count - 1); |
||||
list.erase(list.begin() + row, list.begin() + row + count); |
||||
endRemoveRows(); |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
Qt::ItemFlags RecentRequestsTableModel::flags(const QModelIndex &index) const |
||||
{ |
||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled; |
||||
} |
||||
|
||||
void RecentRequestsTableModel::addNewRequest(const SendCoinsRecipient &recipient) |
||||
{ |
||||
RecentRequestEntry newEntry; |
||||
newEntry.date = QDateTime::currentDateTime(); |
||||
newEntry.recipient = recipient; |
||||
beginInsertRows(QModelIndex(), 0, 0); |
||||
list.prepend(newEntry); |
||||
endInsertRows(); |
||||
} |
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
// Copyright (c) 2011-2013 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef RECENTREQUESTSTABLEMODEL_H |
||||
#define RECENTREQUESTSTABLEMODEL_H |
||||
|
||||
#include <QAbstractTableModel> |
||||
#include <QStringList> |
||||
#include <QDateTime> |
||||
|
||||
#include "walletmodel.h" |
||||
|
||||
class CWallet; |
||||
|
||||
struct RecentRequestEntry |
||||
{ |
||||
QDateTime date; |
||||
SendCoinsRecipient recipient; |
||||
}; |
||||
|
||||
/** Model for list of recently generated payment requests / bitcoin URIs.
|
||||
* Part of wallet model. |
||||
*/ |
||||
class RecentRequestsTableModel: public QAbstractTableModel |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit RecentRequestsTableModel(CWallet *wallet, WalletModel *parent = 0); |
||||
~RecentRequestsTableModel(); |
||||
|
||||
enum ColumnIndex { |
||||
Date = 0, |
||||
Label = 1, |
||||
Message = 2, |
||||
Amount = 3 |
||||
}; |
||||
|
||||
/** @name Methods overridden from QAbstractTableModel
|
||||
@{*/ |
||||
int rowCount(const QModelIndex &parent) const; |
||||
int columnCount(const QModelIndex &parent) const; |
||||
QVariant data(const QModelIndex &index, int role) const; |
||||
bool setData(const QModelIndex &index, const QVariant &value, int role); |
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
||||
QModelIndex index(int row, int column, const QModelIndex &parent) const; |
||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
||||
Qt::ItemFlags flags(const QModelIndex &index) const; |
||||
/*@}*/ |
||||
|
||||
const RecentRequestEntry &entry(int row) const { return list[row]; } |
||||
void addNewRequest(const SendCoinsRecipient &recipient); |
||||
|
||||
private: |
||||
WalletModel *walletModel; |
||||
QStringList columns; |
||||
QList<RecentRequestEntry> list; |
||||
}; |
||||
|
||||
#endif |
Loading…
Reference in new issue