diff options
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/forms/receivecoinsdialog.ui | 6 | ||||
-rw-r--r-- | src/qt/optionsdialog.cpp | 3 | ||||
-rw-r--r-- | src/qt/optionsmodel.cpp | 24 | ||||
-rw-r--r-- | src/qt/optionsmodel.h | 6 | ||||
-rw-r--r-- | src/qt/paymentserver.cpp | 25 | ||||
-rw-r--r-- | src/qt/receivecoinsdialog.cpp | 2 | ||||
-rw-r--r-- | src/qt/recentrequeststablemodel.cpp | 78 | ||||
-rw-r--r-- | src/qt/recentrequeststablemodel.h | 45 | ||||
-rw-r--r-- | src/qt/walletmodel.cpp | 24 | ||||
-rw-r--r-- | src/qt/walletmodel.h | 42 |
10 files changed, 230 insertions, 25 deletions
diff --git a/src/qt/forms/receivecoinsdialog.ui b/src/qt/forms/receivecoinsdialog.ui index 8242763e77..7bf01224ee 100644 --- a/src/qt/forms/receivecoinsdialog.ui +++ b/src/qt/forms/receivecoinsdialog.ui @@ -207,7 +207,11 @@ </widget> </item> <item> - <widget class="QTableView" name="recentRequestsView"/> + <widget class="QTableView" name="recentRequestsView"> + <property name="sortingEnabled"> + <bool>true</bool> + </property> + </widget> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout_2"> diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index d024e3b7aa..f61bb3ed2c 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -53,7 +53,6 @@ OptionsDialog::OptionsDialog(QWidget *parent) : connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool))); connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool))); connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->socksVersion, SLOT(setEnabled(bool))); - connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning_Proxy())); ui->proxyIp->installEventFilter(this); @@ -204,7 +203,7 @@ void OptionsDialog::on_resetButton_clicked() if(btnRetVal == QMessageBox::Cancel) return; - /* reset all options and close Bitcoin-Qt */ + /* reset all options and close GUI */ model->Reset(); QApplication::quit(); } diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 1133c457b3..a18fd1d514 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -19,6 +19,7 @@ #include "walletdb.h" #endif +#include <QNetworkProxy> #include <QSettings> #include <QStringList> @@ -375,14 +376,25 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in return successful; } -bool OptionsModel::getProxySettings(QString& proxyIP, quint16 &proxyPort) const +bool OptionsModel::getProxySettings(QNetworkProxy& proxy) const { - std::string proxy = GetArg("-proxy", ""); - if (proxy.empty()) return false; + // Directly query current base proxy, because + // GUI settings can be overridden with -proxy. + proxyType curProxy; + if (GetProxy(NET_IPV4, curProxy)) { + if (curProxy.second == 5) { + proxy.setType(QNetworkProxy::Socks5Proxy); + proxy.setHostName(QString::fromStdString(curProxy.first.ToStringIP())); + proxy.setPort(curProxy.first.GetPort()); + + return true; + } + else + return false; + } + else + proxy.setType(QNetworkProxy::NoProxy); - CService addrProxy(proxy); - proxyIP = QString(addrProxy.ToStringIP().c_str()); - proxyPort = addrProxy.GetPort(); return true; } diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index d05cb46746..7a71b772b2 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -7,6 +7,10 @@ #include <QAbstractListModel> +QT_BEGIN_NAMESPACE +class QNetworkProxy; +QT_END_NAMESPACE + /** Interface from Qt to configuration data structure for Bitcoin client. To Qt, the options are presented as a list with the different options laid out vertically. @@ -54,7 +58,7 @@ public: bool getMinimizeOnClose() { return fMinimizeOnClose; } int getDisplayUnit() { return nDisplayUnit; } bool getDisplayAddresses() { return bDisplayAddresses; } - bool getProxySettings(QString& proxyIP, quint16 &proxyPort) const; + bool getProxySettings(QNetworkProxy& proxy) const; bool getCoinControlFeatures() { return fCoinControlFeatures; } const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; } diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index 7642cd117a..ca6ae17990 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -335,17 +335,22 @@ void PaymentServer::initNetManager() // netManager is used to fetch paymentrequests given in bitcoin: URIs netManager = new QNetworkAccessManager(this); - // Use proxy settings from optionsModel - QString proxyIP; - quint16 proxyPort; - if (optionsModel->getProxySettings(proxyIP, proxyPort)) - { - QNetworkProxy proxy; - proxy.setType(QNetworkProxy::Socks5Proxy); - proxy.setHostName(proxyIP); - proxy.setPort(proxyPort); - netManager->setProxy(proxy); + QNetworkProxy proxy; + + // Query active proxy (fails if no SOCKS5 proxy) + if (optionsModel->getProxySettings(proxy)) { + if (proxy.type() == QNetworkProxy::Socks5Proxy) { + netManager->setProxy(proxy); + + qDebug() << "PaymentServer::initNetManager : Using SOCKS5 proxy" << proxy.hostName() << ":" << proxy.port(); + } + else + qDebug() << "PaymentServer::initNetManager : No active proxy server found."; } + else + emit message(tr("Net manager warning"), + tr("Your active proxy doesn't support SOCKS5, which is required for payment requests via proxy."), + CClientUIInterface::MSG_WARNING); connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(netRequestFinished(QNetworkReply*))); diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index 075a16dabf..38dc88f63b 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -55,6 +55,8 @@ void ReceiveCoinsDialog::setModel(WalletModel *model) ui->recentRequestsView->horizontalHeader()->setSectionResizeMode(RecentRequestsTableModel::Message, QHeaderView::Stretch); #endif ui->recentRequestsView->horizontalHeader()->resizeSection(RecentRequestsTableModel::Amount, 100); + + model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder); } } diff --git a/src/qt/recentrequeststablemodel.cpp b/src/qt/recentrequeststablemodel.cpp index 86c29dd02b..74b43f1d24 100644 --- a/src/qt/recentrequeststablemodel.cpp +++ b/src/qt/recentrequeststablemodel.cpp @@ -12,6 +12,13 @@ RecentRequestsTableModel::RecentRequestsTableModel(CWallet *wallet, WalletModel walletModel(parent) { 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 */ 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()) { + 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); list.erase(list.begin() + row, list.begin() + row + count); endRemoveRows(); @@ -118,12 +133,73 @@ Qt::ItemFlags RecentRequestsTableModel::flags(const QModelIndex &index) const return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } +// called when adding a request from the GUI void RecentRequestsTableModel::addNewRequest(const SendCoinsRecipient &recipient) { RecentRequestEntry newEntry; + newEntry.id = ++nReceiveRequestsMaxId; newEntry.date = QDateTime::currentDateTime(); 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); - list.prepend(newEntry); + list.prepend(recipient); endInsertRows(); } + +void RecentRequestsTableModel::sort(int column, Qt::SortOrder order) +{ + qSort(list.begin(), list.end(), RecentRequestEntryLessThan(column, order)); + emit dataChanged(index(0, 0, QModelIndex()), index(list.size() - 1, NUMBER_OF_COLUMNS - 1, QModelIndex())); +} + +bool RecentRequestEntryLessThan::operator()(RecentRequestEntry &left, RecentRequestEntry &right) const +{ + RecentRequestEntry *pLeft = &left; + RecentRequestEntry *pRight = &right; + if (order == Qt::DescendingOrder) + std::swap(pLeft, pRight); + + switch(column) + { + case RecentRequestsTableModel::Date: + return pLeft->date.toTime_t() < pRight->date.toTime_t(); + case RecentRequestsTableModel::Label: + return pLeft->recipient.label < pRight->recipient.label; + case RecentRequestsTableModel::Message: + return pLeft->recipient.message < pRight->recipient.message; + case RecentRequestsTableModel::Amount: + return pLeft->recipient.amount < pRight->recipient.amount; + default: + return pLeft->id < pRight->id; + } +} diff --git a/src/qt/recentrequeststablemodel.h b/src/qt/recentrequeststablemodel.h index 3aab7b0a48..6b20402f78 100644 --- a/src/qt/recentrequeststablemodel.h +++ b/src/qt/recentrequeststablemodel.h @@ -13,10 +13,44 @@ class CWallet; -struct RecentRequestEntry +class RecentRequestEntry { +public: + RecentRequestEntry() : nVersion(RecentRequestEntry::CURRENT_VERSION), id(0) { } + + static const int CURRENT_VERSION=1; + int nVersion; + int64_t id; QDateTime date; SendCoinsRecipient recipient; + + IMPLEMENT_SERIALIZE + ( + RecentRequestEntry* pthis = const_cast<RecentRequestEntry*>(this); + + unsigned int nDate = date.toTime_t(); + + READWRITE(pthis->nVersion); + nVersion = pthis->nVersion; + READWRITE(id); + READWRITE(nDate); + READWRITE(recipient); + + if (fRead) + pthis->date = QDateTime::fromTime_t(nDate); + ) +}; + +class RecentRequestEntryLessThan +{ +public: + RecentRequestEntryLessThan(int nColumn, Qt::SortOrder fOrder): + column(nColumn), order(fOrder) {} + bool operator()(RecentRequestEntry &left, RecentRequestEntry &right ) const; + +private: + int column; + Qt::SortOrder order; }; /** Model for list of recently generated payment requests / bitcoin URIs. @@ -34,7 +68,8 @@ public: Date = 0, Label = 1, Message = 2, - Amount = 3 + Amount = 3, + NUMBER_OF_COLUMNS }; /** @name Methods overridden from QAbstractTableModel @@ -51,11 +86,17 @@ public: const RecentRequestEntry &entry(int row) const { return list[row]; } void addNewRequest(const SendCoinsRecipient &recipient); + void addNewRequest(const std::string &recipient); + void addNewRequest(RecentRequestEntry &recipient); + +public slots: + void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); private: WalletModel *walletModel; QStringList columns; QList<RecentRequestEntry> list; + int64_t nReceiveRequestsMaxId; }; #endif diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 33db145db0..ddc8c6ea79 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -556,3 +556,27 @@ void WalletModel::listLockedCoins(std::vector<COutPoint>& vOutpts) LOCK(wallet->cs_wallet); wallet->ListLockedCoins(vOutpts); } + +void WalletModel::loadReceiveRequests(std::vector<std::string>& vReceiveRequests) +{ + LOCK(wallet->cs_wallet); + BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& item, wallet->mapAddressBook) + BOOST_FOREACH(const PAIRTYPE(std::string, std::string)& item2, item.second.destdata) + if (item2.first.size() > 2 && item2.first.substr(0,2) == "rr") // receive request + vReceiveRequests.push_back(item2.second); +} + +bool WalletModel::saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest) +{ + CTxDestination dest = CBitcoinAddress(sAddress).Get(); + + std::stringstream ss; + ss << nId; + std::string key = "rr" + ss.str(); // "rr" prefix = "receive request" in destdata + + LOCK(wallet->cs_wallet); + if (sRequest.empty()) + return wallet->EraseDestData(dest, key); + else + return wallet->AddDestData(dest, key, sRequest); +} diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 1a4d25615a..600bef346b 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -36,9 +36,9 @@ QT_END_NAMESPACE class SendCoinsRecipient { public: - explicit SendCoinsRecipient() : amount(0) { } + explicit SendCoinsRecipient() : amount(0), nVersion(SendCoinsRecipient::CURRENT_VERSION) { } explicit SendCoinsRecipient(const QString &addr, const QString &label, quint64 amount, const QString &message): - address(addr), label(label), amount(amount), message(message) {} + address(addr), label(label), amount(amount), message(message), nVersion(SendCoinsRecipient::CURRENT_VERSION) {} // If from an insecure payment request, this is used for storing // the addresses, e.g. address-A<br />address-B<br />address-C. @@ -55,6 +55,41 @@ public: PaymentRequestPlus paymentRequest; // Empty if no authentication or invalid signature/cert/etc. QString authenticatedMerchant; + + static const int CURRENT_VERSION=1; + int nVersion; + + IMPLEMENT_SERIALIZE + ( + SendCoinsRecipient* pthis = const_cast<SendCoinsRecipient*>(this); + + std::string sAddress = pthis->address.toStdString(); + std::string sLabel = pthis->label.toStdString(); + std::string sMessage = pthis->message.toStdString(); + std::string sPaymentRequest; + if (!fRead && pthis->paymentRequest.IsInitialized()) + pthis->paymentRequest.SerializeToString(&sPaymentRequest); + std::string sAuthenticatedMerchant = pthis->authenticatedMerchant.toStdString(); + + READWRITE(pthis->nVersion); + nVersion = pthis->nVersion; + READWRITE(sAddress); + READWRITE(sLabel); + READWRITE(amount); + READWRITE(sMessage); + READWRITE(sPaymentRequest); + READWRITE(sAuthenticatedMerchant); + + if (fRead) + { + pthis->address = QString::fromStdString(sAddress); + pthis->label = QString::fromStdString(sLabel); + pthis->message = QString::fromStdString(sMessage); + if (!sPaymentRequest.empty()) + pthis->paymentRequest.parse(QByteArray::fromRawData(sPaymentRequest.data(), sPaymentRequest.size())); + pthis->authenticatedMerchant = QString::fromStdString(sAuthenticatedMerchant); + } + ) }; /** Interface to Bitcoin wallet from Qt view code. */ @@ -152,6 +187,9 @@ public: void unlockCoin(COutPoint& output); void listLockedCoins(std::vector<COutPoint>& vOutpts); + void loadReceiveRequests(std::vector<std::string>& vReceiveRequests); + bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest); + private: CWallet *wallet; |