|
|
@ -12,6 +12,13 @@ RecentRequestsTableModel::RecentRequestsTableModel(CWallet *wallet, WalletModel |
|
|
|
walletModel(parent) |
|
|
|
walletModel(parent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Q_UNUSED(wallet); |
|
|
|
Q_UNUSED(wallet); |
|
|
|
|
|
|
|
nReceiveRequestsMaxId = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load entries from wallet
|
|
|
|
|
|
|
|
std::vector<std::string> vReceiveRequests; |
|
|
|
|
|
|
|
parent->loadReceiveRequests(vReceiveRequests); |
|
|
|
|
|
|
|
BOOST_FOREACH(const std::string& request, vReceiveRequests) |
|
|
|
|
|
|
|
addNewRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
/* These columns must match the indices in the ColumnIndex enumeration */ |
|
|
|
/* These columns must match the indices in the ColumnIndex enumeration */ |
|
|
|
columns << tr("Date") << tr("Label") << tr("Message") << tr("Amount"); |
|
|
|
columns << tr("Date") << tr("Label") << tr("Message") << tr("Amount"); |
|
|
@ -104,6 +111,14 @@ bool RecentRequestsTableModel::removeRows(int row, int count, const QModelIndex |
|
|
|
|
|
|
|
|
|
|
|
if(count > 0 && row >= 0 && (row+count) <= list.size()) |
|
|
|
if(count > 0 && row >= 0 && (row+count) <= list.size()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
const RecentRequestEntry *rec; |
|
|
|
|
|
|
|
for (int i = 0; i < count; ++i) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
rec = &list[row+i]; |
|
|
|
|
|
|
|
if (!walletModel->saveReceiveRequest(rec->recipient.address.toStdString(), rec->id, "")) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
beginRemoveRows(parent, row, row + count - 1); |
|
|
|
beginRemoveRows(parent, row, row + count - 1); |
|
|
|
list.erase(list.begin() + row, list.begin() + row + count); |
|
|
|
list.erase(list.begin() + row, list.begin() + row + count); |
|
|
|
endRemoveRows(); |
|
|
|
endRemoveRows(); |
|
|
@ -118,12 +133,45 @@ Qt::ItemFlags RecentRequestsTableModel::flags(const QModelIndex &index) const |
|
|
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled; |
|
|
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// called when adding a request from the GUI
|
|
|
|
void RecentRequestsTableModel::addNewRequest(const SendCoinsRecipient &recipient) |
|
|
|
void RecentRequestsTableModel::addNewRequest(const SendCoinsRecipient &recipient) |
|
|
|
{ |
|
|
|
{ |
|
|
|
RecentRequestEntry newEntry; |
|
|
|
RecentRequestEntry newEntry; |
|
|
|
|
|
|
|
newEntry.id = ++nReceiveRequestsMaxId; |
|
|
|
newEntry.date = QDateTime::currentDateTime(); |
|
|
|
newEntry.date = QDateTime::currentDateTime(); |
|
|
|
newEntry.recipient = recipient; |
|
|
|
newEntry.recipient = recipient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CDataStream ss(SER_DISK, CLIENT_VERSION); |
|
|
|
|
|
|
|
ss << newEntry; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!walletModel->saveReceiveRequest(recipient.address.toStdString(), newEntry.id, ss.str())) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addNewRequest(newEntry); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// called from ctor when loading from wallet
|
|
|
|
|
|
|
|
void RecentRequestsTableModel::addNewRequest(const std::string &recipient) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::vector<char> data(recipient.begin(), recipient.end()); |
|
|
|
|
|
|
|
CDataStream ss(data, SER_DISK, CLIENT_VERSION); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RecentRequestEntry entry; |
|
|
|
|
|
|
|
ss >> entry; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (entry.id == 0) // should not happen
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (entry.id > nReceiveRequestsMaxId) |
|
|
|
|
|
|
|
nReceiveRequestsMaxId = entry.id; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addNewRequest(entry); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// actually add to table in GUI
|
|
|
|
|
|
|
|
void RecentRequestsTableModel::addNewRequest(RecentRequestEntry &recipient) |
|
|
|
|
|
|
|
{ |
|
|
|
beginInsertRows(QModelIndex(), 0, 0); |
|
|
|
beginInsertRows(QModelIndex(), 0, 0); |
|
|
|
list.prepend(newEntry); |
|
|
|
list.prepend(recipient); |
|
|
|
endInsertRows(); |
|
|
|
endInsertRows(); |
|
|
|
} |
|
|
|
} |
|
|
|