diff options
-rw-r--r-- | bitcoin-qt.pro | 10 | ||||
-rw-r--r-- | src/keystore.cpp | 2 | ||||
-rw-r--r-- | src/net.cpp | 22 | ||||
-rw-r--r-- | src/qt/bitcoin.cpp | 2 | ||||
-rw-r--r-- | src/qt/bitcoinaddressvalidator.h | 2 | ||||
-rw-r--r-- | src/qt/bitcoingui.cpp | 37 | ||||
-rw-r--r-- | src/qt/bitcoingui.h | 4 | ||||
-rw-r--r-- | src/qt/guiutil.cpp | 37 | ||||
-rw-r--r-- | src/qt/test/test_main.cpp | 11 | ||||
-rw-r--r-- | src/qt/test/urltests.cpp | 68 | ||||
-rw-r--r-- | src/qt/test/urltests.h | 15 |
11 files changed, 185 insertions, 25 deletions
diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index 678bec0134..e2097fd4b0 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -226,6 +226,16 @@ SOURCES += src/qt/qrcodedialog.cpp FORMS += src/qt/forms/qrcodedialog.ui } +contains(BITCOIN_QT_TEST, 1) { +SOURCES += src/qt/test/test_main.cpp \ + src/qt/test/urltests.cpp +HEADERS += src/qt/test/urltests.h +DEPENDPATH += src/qt/test +QT += testlib +TARGET = bitcoin-qt_test +DEFINES += BITCOIN_QT_TEST +} + CODECFORTR = UTF-8 # for lrelease/lupdate diff --git a/src/keystore.cpp b/src/keystore.cpp index 4a59010fdb..18e5c377dc 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -192,7 +192,7 @@ bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn) BOOST_FOREACH(KeyMap::value_type& mKey, mapKeys) { CKey key; - if (!key.SetSecret(mKey.second.first, false)) + if (!key.SetSecret(mKey.second.first, mKey.second.second)) return false; const std::vector<unsigned char> vchPubKey = key.GetPubKey(); std::vector<unsigned char> vchCryptedSecret; diff --git a/src/net.cpp b/src/net.cpp index f0ea5506e2..63829d0e0a 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -530,7 +530,7 @@ void CNode::PushVersion() /// when NTP implemented, change to just nTime = GetAdjustedTime() int64 nTime = (fInbound ? GetAdjustedTime() : GetTime()); CAddress addrYou = (fUseProxy ? CAddress(CService("0.0.0.0",0)) : addr); - CAddress addrMe = (fUseProxy ? CAddress(CService("0.0.0.0",0)) : addrLocalHost); + CAddress addrMe = (fUseProxy || !addrLocalHost.IsRoutable() ? CAddress(CService("0.0.0.0",0)) : addrLocalHost); RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce)); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>()), nBestHeight); @@ -965,6 +965,26 @@ void ThreadMapPort2(void* parg) r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr)); if (r == 1) { + if (!addrLocalHost.IsRoutable()) + { + char externalIPAddress[40]; + r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress); + if(r != UPNPCOMMAND_SUCCESS) + printf("UPnP: GetExternalIPAddress() returned %d\n", r); + else + { + if(externalIPAddress[0]) + { + printf("UPnP: ExternalIPAddress = %s\n", externalIPAddress); + CAddress addrExternalFromUPnP(CService(externalIPAddress, 0), nLocalServices); + if (addrExternalFromUPnP.IsRoutable()) + addrLocalHost = addrExternalFromUPnP; + } + else + printf("UPnP: GetExternalIPAddress failed.\n"); + } + } + string strDesc = "Bitcoin " + FormatFullVersion(); #ifndef UPNPDISCOVER_SUCCESS /* miniupnpc 1.5 */ diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index b25216fe98..8c4b0e6c10 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -131,6 +131,7 @@ std::string _(const char* psz) return QCoreApplication::translate("bitcoin-core", psz).toStdString(); } +#ifndef BITCOIN_QT_TEST int main(int argc, char *argv[]) { // Do this early as we don't want to bother initializing if we are just calling IPC @@ -257,3 +258,4 @@ int main(int argc, char *argv[]) } return 0; } +#endif // BITCOIN_QT_TEST diff --git a/src/qt/bitcoinaddressvalidator.h b/src/qt/bitcoinaddressvalidator.h index 6ca3bd6a05..9710d122b6 100644 --- a/src/qt/bitcoinaddressvalidator.h +++ b/src/qt/bitcoinaddressvalidator.h @@ -14,7 +14,7 @@ public: State validate(QString &input, int &pos) const; - static const int MaxAddressLength = 34; + static const int MaxAddressLength = 35; signals: public slots: diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index f67a5d6b56..b72f128291 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -56,6 +56,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): QMainWindow(parent), clientModel(0), walletModel(0), + dummyWidget(0), encryptWalletAction(0), changePassphraseAction(0), aboutQtAction(0), @@ -85,6 +86,9 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): // Create the tray icon (or setup the dock icon) createTrayIcon(); + // Dummy widget used when restoring window state after minimization + dummyWidget = new QWidget(); + // Create tabs overviewPage = new OverviewPage(); @@ -162,6 +166,7 @@ BitcoinGUI::~BitcoinGUI() #ifdef Q_WS_MAC delete appMenuBar; #endif + delete dummyWidget; } void BitcoinGUI::createActions() @@ -205,17 +210,17 @@ void BitcoinGUI::createActions() #endif tabGroup->addAction(messageAction); - connect(overviewAction, SIGNAL(triggered()), this, SLOT(show())); + connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormal())); connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage())); - connect(historyAction, SIGNAL(triggered()), this, SLOT(show())); + connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormal())); connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage())); - connect(addressBookAction, SIGNAL(triggered()), this, SLOT(show())); + connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormal())); connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage())); - connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(show())); + connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormal())); connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage())); - connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(show())); + connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormal())); connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage())); - connect(messageAction, SIGNAL(triggered()), this, SLOT(show())); + connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormal())); connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage())); quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this); @@ -234,7 +239,7 @@ void BitcoinGUI::createActions() openBitcoinAction = new QAction(QIcon(":/icons/bitcoin"), tr("Open &Bitcoin"), this); openBitcoinAction->setToolTip(tr("Show the Bitcoin window")); exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this); - exportAction->setToolTip(tr("Export the current view to a file")); + exportAction->setToolTip(tr("Export the data in the current tab to a file")); encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this); encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet")); encryptWalletAction->setCheckable(true); @@ -262,6 +267,7 @@ void BitcoinGUI::createMenuBar() // Configure the menus QMenu *file = appMenuBar->addMenu(tr("&File")); + file->addAction(exportAction); #ifndef FIRST_CLASS_MESSAGING file->addAction(messageAction); file->addSeparator(); @@ -405,10 +411,17 @@ void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason) // Click on system tray icon triggers "open bitcoin" openBitcoinAction->trigger(); } - } #endif +void BitcoinGUI::showNormal() +{ + // Reparent window to the desktop (in case it was hidden on minimize) + if(parent() != NULL) + setParent(NULL, Qt::Window); + QMainWindow::showNormal(); +} + void BitcoinGUI::optionsClicked() { if(!clientModel || !clientModel->getOptionsModel()) @@ -550,13 +563,13 @@ void BitcoinGUI::changeEvent(QEvent *e) { if(isMinimized()) { - hide(); - e->ignore(); + // Hiding the window from taskbar + setParent(dummyWidget, Qt::SubWindow); + return; } else { - show(); - e->accept(); + showNormal(); } } } diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 09ad89a894..37ab12577c 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -58,6 +58,8 @@ private: QStackedWidget *centralWidget; + QWidget *dummyWidget; + OverviewPage *overviewPage; QWidget *transactionsPage; AddressBookPage *addressBookPage; @@ -131,6 +133,8 @@ public slots: void gotoMessagePage(); void gotoMessagePage(QString); + void showNormal(); + private slots: /** Switch to overview (home) page */ void gotoOverviewPage(); diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 22d9cc7384..29ef554ac3 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -56,19 +56,36 @@ bool GUIUtil::parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out) SendCoinsRecipient rv; rv.address = url->path(); - rv.label = url->queryItemValue("label"); - - QString amount = url->queryItemValue("amount"); - if(amount.isEmpty()) - { - rv.amount = 0; - } - else // Amount is non-empty + rv.amount = 0; + QList<QPair<QString, QString> > items = url->queryItems(); + for (QList<QPair<QString, QString> >::iterator i = items.begin(); i != items.end(); i++) { - if(!BitcoinUnits::parse(BitcoinUnits::BTC, amount, &rv.amount)) + bool fShouldReturnFalse = false; + if (i->first.startsWith("req-")) { - return false; + i->first.remove(0, 4); + fShouldReturnFalse = true; } + + if (i->first == "label") + { + rv.label = i->second; + fShouldReturnFalse = false; + } + else if (i->first == "amount") + { + if(!i->second.isEmpty()) + { + if(!BitcoinUnits::parse(BitcoinUnits::BTC, i->second, &rv.amount)) + { + return false; + } + } + fShouldReturnFalse = false; + } + + if (fShouldReturnFalse) + return false; } if(out) { diff --git a/src/qt/test/test_main.cpp b/src/qt/test/test_main.cpp new file mode 100644 index 0000000000..0a08eafa1e --- /dev/null +++ b/src/qt/test/test_main.cpp @@ -0,0 +1,11 @@ +#include <QTest>
+#include <QObject>
+
+#include "urltests.h"
+
+// This is all you need to run all the tests
+int main(int argc, char *argv[])
+{
+ URLTests test1;
+ QTest::qExec(&test1);
+}
diff --git a/src/qt/test/urltests.cpp b/src/qt/test/urltests.cpp new file mode 100644 index 0000000000..5ecc846203 --- /dev/null +++ b/src/qt/test/urltests.cpp @@ -0,0 +1,68 @@ +#include "urltests.h" +#include "../guiutil.h" +#include "../walletmodel.h" + +#include <QUrl> + +/* +struct SendCoinsRecipient +{ + QString address; + QString label; + qint64 amount; +}; +*/ + +void URLTests::urlTests() +{ + SendCoinsRecipient rv; + QUrl url; + url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-dontexist=")); + QVERIFY(!GUIUtil::parseBitcoinURL(&url, &rv)); + + url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?dontexist=")); + QVERIFY(GUIUtil::parseBitcoinURL(&url, &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.label == QString()); + QVERIFY(rv.amount == 0); + + url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Wikipedia Example Address")); + QVERIFY(GUIUtil::parseBitcoinURL(&url, &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.label == QString("Wikipedia Example Address")); + QVERIFY(rv.amount == 0); + + url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=0.001")); + QVERIFY(GUIUtil::parseBitcoinURL(&url, &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.label == QString()); + QVERIFY(rv.amount == 100000); + + url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1.001")); + QVERIFY(GUIUtil::parseBitcoinURL(&url, &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.label == QString()); + QVERIFY(rv.amount == 100100000); + + url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=Wikipedia Example")); + QVERIFY(GUIUtil::parseBitcoinURL(&url, &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.amount == 10000000000); + QVERIFY(rv.label == QString("Wikipedia Example")); + + url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address")); + QVERIFY(GUIUtil::parseBitcoinURL(&url, &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.label == QString()); + QVERIFY(rv.label == QString()); + + // We currently dont implement the message paramenter (ok, yea, we break spec...) + url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-message=Wikipedia Example Address")); + QVERIFY(!GUIUtil::parseBitcoinURL(&url, &rv)); + + url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000&label=Wikipedia Example")); + QVERIFY(!GUIUtil::parseBitcoinURL(&url, &rv)); + + url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000.0&label=Wikipedia Example")); + QVERIFY(!GUIUtil::parseBitcoinURL(&url, &rv)); +} diff --git a/src/qt/test/urltests.h b/src/qt/test/urltests.h new file mode 100644 index 0000000000..393c511390 --- /dev/null +++ b/src/qt/test/urltests.h @@ -0,0 +1,15 @@ +#ifndef URLTESTS_H +#define URLTESTS_H + +#include <QTest> +#include <QObject> + +class URLTests : public QObject +{ + Q_OBJECT + +private slots: + void urlTests(); +}; + +#endif // URLTESTS_H |