From d29ec6c2301e593d577126d1ca85b93307b32bf1 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 14 Jul 2015 13:59:05 +0200 Subject: qt: define QT_NO_KEYWORDS QT_NO_KEYWORDS prevents Qt from defining the `foreach`, `signals`, `slots` and `emit` macros. Avoid overlap between Qt macros and boost - for example #undef hackiness in #6421. --- src/qt/utilitydialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 386cf31d7..5e26f3e01 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -84,7 +84,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : QTextCharFormat bold; bold.setFontWeight(QFont::Bold); - foreach (const QString &line, coreOptions.split("\n")) { + Q_FOREACH (const QString &line, coreOptions.split("\n")) { if (line.startsWith(" -")) { cursor.currentTable()->appendRows(1); -- cgit v1.2.3 From fa41d4c8c6e3f84a9117c0addf51a87f14321e2a Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 9 Nov 2015 19:23:46 +0100 Subject: [qt] Move GUI related HelpMessage() part downstream --- src/qt/utilitydialog.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 5e26f3e01..da85ab2b3 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -8,6 +8,9 @@ #include "bitcoingui.h" #include "clientmodel.h" +#include "guiconstants.h" +#include "intro.h" +#include "paymentrequestplus.h" #include "guiutil.h" #include "clientversion.h" @@ -70,7 +73,22 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : cursor.insertText(header); cursor.insertBlock(); - QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT)); + std::string strUsage = HelpMessage(HMM_BITCOIN_QT); + const bool showDebug = GetBoolArg("-help-debug", false); + strUsage += HelpMessageGroup(_("UI Options:")); + if (showDebug) { + strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS)); + } + strUsage += HelpMessageOpt("-choosedatadir", strprintf(_("Choose data directory on startup (default: %u)"), DEFAULT_CHOOSE_DATADIR)); + strUsage += HelpMessageOpt("-lang=", _("Set language, for example \"de_DE\" (default: system locale)")); + strUsage += HelpMessageOpt("-min", _("Start minimized")); + strUsage += HelpMessageOpt("-rootcertificates=", _("Set SSL root certificates for payment request (default: -system-)")); + strUsage += HelpMessageOpt("-splash", strprintf(_("Show splash screen on startup (default: %u)"), DEFAULT_SPLASHSCREEN)); + strUsage += HelpMessageOpt("-resetguisettings", _("Reset all settings changes made over the GUI")); + if (showDebug) { + strUsage += HelpMessageOpt("-uiplatform", "Select platform to customize UI for (one of windows, macosx, other; default: platform compiled on)"); + } + QString coreOptions = QString::fromStdString(strUsage); text = version + "\n" + header + "\n" + coreOptions; QTextTableFormat tf; -- cgit v1.2.3 From a6cbc02b6b279dc0ed11e007ba84a6b09bdcd740 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 28 Nov 2015 21:44:55 +0000 Subject: Bugfix: Default -uiplatform is not actually the platform this build was compiled on --- src/qt/utilitydialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index da85ab2b3..f60928974 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -86,7 +86,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : strUsage += HelpMessageOpt("-splash", strprintf(_("Show splash screen on startup (default: %u)"), DEFAULT_SPLASHSCREEN)); strUsage += HelpMessageOpt("-resetguisettings", _("Reset all settings changes made over the GUI")); if (showDebug) { - strUsage += HelpMessageOpt("-uiplatform", "Select platform to customize UI for (one of windows, macosx, other; default: platform compiled on)"); + strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM)); } QString coreOptions = QString::fromStdString(strUsage); text = version + "\n" + header + "\n" + coreOptions; -- cgit v1.2.3 From fab83476acf4a1eaeb5d6c3fe6195b9ff80b193c Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 2 Dec 2015 16:37:43 +0100 Subject: [qt] Use tr() instead of _() Also, `make translate` --- src/qt/utilitydialog.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index f60928974..81b597e2e 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -75,16 +75,16 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : std::string strUsage = HelpMessage(HMM_BITCOIN_QT); const bool showDebug = GetBoolArg("-help-debug", false); - strUsage += HelpMessageGroup(_("UI Options:")); + strUsage += HelpMessageGroup(tr("UI Options:").toStdString()); if (showDebug) { strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS)); } - strUsage += HelpMessageOpt("-choosedatadir", strprintf(_("Choose data directory on startup (default: %u)"), DEFAULT_CHOOSE_DATADIR)); - strUsage += HelpMessageOpt("-lang=", _("Set language, for example \"de_DE\" (default: system locale)")); - strUsage += HelpMessageOpt("-min", _("Start minimized")); - strUsage += HelpMessageOpt("-rootcertificates=", _("Set SSL root certificates for payment request (default: -system-)")); - strUsage += HelpMessageOpt("-splash", strprintf(_("Show splash screen on startup (default: %u)"), DEFAULT_SPLASHSCREEN)); - strUsage += HelpMessageOpt("-resetguisettings", _("Reset all settings changes made over the GUI")); + strUsage += HelpMessageOpt("-choosedatadir", strprintf(tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR)); + strUsage += HelpMessageOpt("-lang=", tr("Set language, for example \"de_DE\" (default: system locale)").toStdString()); + strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString()); + strUsage += HelpMessageOpt("-rootcertificates=", tr("Set SSL root certificates for payment request (default: -system-)").toStdString()); + strUsage += HelpMessageOpt("-splash", strprintf(tr("Show splash screen on startup (default: %u)").toStdString(), DEFAULT_SPLASHSCREEN)); + strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changes made over the GUI").toStdString()); if (showDebug) { strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM)); } -- cgit v1.2.3 From fa24439ff3d8ab5b9efaf66ef4dae6713b88cb35 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sun, 13 Dec 2015 17:58:29 +0100 Subject: Bump copyright headers to 2015 --- src/qt/utilitydialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 81b597e2e..5e7345144 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2014 The Bitcoin Core developers +// Copyright (c) 2011-2015 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -- cgit v1.2.3 From d5f46832de900cee0801ca40bba743c9564cccb8 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Wed, 9 Dec 2015 10:53:12 +0000 Subject: Unify package name to as few places as possible without major changes --- src/qt/utilitydialog.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 5e26f3e01..3e96f26b3 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -2,6 +2,10 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#if defined(HAVE_CONFIG_H) +#include "config/bitcoin-config.h" +#endif + #include "utilitydialog.h" #include "ui_helpmessagedialog.h" @@ -30,7 +34,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : { ui->setupUi(this); - QString version = tr("Bitcoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion()); + QString version = tr(PACKAGE_NAME) + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion()); /* On x86 add a bit specifier to the version so that users can distinguish between * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious. */ @@ -42,7 +46,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : if (about) { - setWindowTitle(tr("About Bitcoin Core")); + setWindowTitle(tr("About %1").arg(tr(PACKAGE_NAME))); /// HTML-format the license message from the core QString licenseInfo = QString::fromStdString(LicenseInfo()); @@ -144,7 +148,7 @@ ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f): { QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(new QLabel( - tr("Bitcoin Core is shutting down...") + "

" + + tr("%1 is shutting down...").arg(tr(PACKAGE_NAME)) + "

" + tr("Do not shut down the computer until this window disappears."))); setLayout(layout); } -- cgit v1.2.3 From fa5769e95a44427e1ed7d63795d4ff60985f0059 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 16 Dec 2015 13:06:51 +0100 Subject: [qt] Fix misleading translation --- src/qt/utilitydialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 81b597e2e..088578b7a 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -84,7 +84,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString()); strUsage += HelpMessageOpt("-rootcertificates=", tr("Set SSL root certificates for payment request (default: -system-)").toStdString()); strUsage += HelpMessageOpt("-splash", strprintf(tr("Show splash screen on startup (default: %u)").toStdString(), DEFAULT_SPLASHSCREEN)); - strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changes made over the GUI").toStdString()); + strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changed in the GUI").toStdString()); if (showDebug) { strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM)); } -- cgit v1.2.3 From 027fdb83b41ae9e9125cf61f6460c03ab34e5961 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Wed, 3 Feb 2016 05:38:27 +0000 Subject: When/if the copyright line does not mention Bitcoin Core developers, add a second line to copyrights in -version, About dialog, and splash screen --- src/qt/utilitydialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 3e96f26b3..5fafa5759 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -56,7 +56,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : uri.setMinimal(true); // use non-greedy matching licenseInfoHTML.replace(uri, "\\1"); // Replace newlines with HTML breaks - licenseInfoHTML.replace("\n\n", "

"); + licenseInfoHTML.replace("\n", "
"); ui->aboutMessage->setTextFormat(Qt::RichText); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); -- cgit v1.2.3 From 5204598f8d07d7432d91e9b8781806d2f3d16415 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sat, 19 Nov 2016 14:28:55 +0100 Subject: qt: Avoid shutdownwindow-related memory leak Store a reference to the shutdown window on BitcoinApplication, so that it will be deleted when exiting the main loop. --- src/qt/utilitydialog.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 947bcdb15..4ec022881 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -171,22 +171,20 @@ ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f): setLayout(layout); } -void ShutdownWindow::showShutdownWindow(BitcoinGUI *window) +QWidget *ShutdownWindow::showShutdownWindow(BitcoinGUI *window) { if (!window) - return; + return nullptr; // Show a simple window indicating shutdown status QWidget *shutdownWindow = new ShutdownWindow(); - // We don't hold a direct pointer to the shutdown window after creation, so use - // Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually. - shutdownWindow->setAttribute(Qt::WA_DeleteOnClose); shutdownWindow->setWindowTitle(window->windowTitle()); // Center shutdown window at where main window was const QPoint global = window->mapToGlobal(window->rect().center()); shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2); shutdownWindow->show(); + return shutdownWindow; } void ShutdownWindow::closeEvent(QCloseEvent *event) -- cgit v1.2.3 From 27765b6403cece54320374b37afb01a0cfe571c3 Mon Sep 17 00:00:00 2001 From: isle2983 Date: Sat, 31 Dec 2016 11:01:21 -0700 Subject: Increment MIT Licence copyright header year on files modified in 2016 Edited via: $ contrib/devtools/copyright_header.py update . --- src/qt/utilitydialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 4ec022881..70efe2799 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers +// Copyright (c) 2011-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -- cgit v1.2.3 From cc16d99f1dc8305b1b255f1cc0f2b1516aa77ed0 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Wed, 18 Jan 2017 16:15:37 +0100 Subject: [trivial] Fix typos in comments --- src/qt/utilitydialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 70efe2799..7ab412528 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -39,7 +39,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : QString version = tr(PACKAGE_NAME) + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion()); /* On x86 add a bit specifier to the version so that users can distinguish between - * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious. + * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambiguous. */ #if defined(__x86_64__) version += " " + tr("(%1-bit)").arg(64); -- cgit v1.2.3 From 4dd8838b3a34bcaf6fc9230744c73d5e3ab530f7 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sun, 2 Aug 2015 10:56:20 +0100 Subject: Rename binaries to match Dogecoin --- src/qt/utilitydialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 7ab412528..5f3756750 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -70,7 +70,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : } else { setWindowTitle(tr("Command-line options")); QString header = tr("Usage:") + "\n" + - " bitcoin-qt [" + tr("command-line options") + "] " + "\n"; + " dogecoin-qt [" + tr("command-line options") + "] " + "\n"; QTextCursor cursor(ui->helpMessage->document()); cursor.insertText(version); cursor.insertBlock(); -- cgit v1.2.3 From 2a0c66035d0fb53b3d12b299707244a13d19cb37 Mon Sep 17 00:00:00 2001 From: Max K Date: Sun, 28 Jan 2018 18:44:52 +0100 Subject: Re-add paperwallet printer (#1467) * Add paper wallet generator to QT wallet * Replace print icon with Typeicons equivalent * Re-add printer support to Qt * depends: fix fontconfig with newer glibc See comment for more detail * Set fixed size for paper wallet dialog --- src/qt/utilitydialog.cpp | 329 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 329 insertions(+) (limited to 'src/qt/utilitydialog.cpp') diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 5f3756750..e25e8cf7b 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -9,7 +9,17 @@ #include "utilitydialog.h" #include "ui_helpmessagedialog.h" +#include "ui_paperwalletdialog.h" +#include "bitcoinunits.h" + +#ifdef ENABLE_WALLET +#include "sendcoinsdialog.h" +#include "sendcoinsentry.h" +#include "coincontroldialog.h" +#endif + +#include "optionsmodel.h" #include "bitcoingui.h" #include "clientmodel.h" #include "guiconstants.h" @@ -20,15 +30,36 @@ #include "clientversion.h" #include "init.h" #include "util.h" +#include "net.h" +#include "utilstrencodings.h" #include #include +#include #include #include #include #include #include +#include + +#ifdef USE_QRCODE +#include +#endif + +#if QT_VERSION < 0x050000 +#include +#include +#include +#else +// Use QT5's new modular classes +#include +#include +#include +#endif +#include +#include "walletmodel.h" /** "Help message" or "About" dialog box */ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : @@ -159,6 +190,304 @@ void HelpMessageDialog::on_okButton_accepted() close(); } +/** "PaperWallet" dialog box */ +PaperWalletDialog::PaperWalletDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::PaperWalletDialog) +{ + ui->setupUi(this); + + ui->buttonBox->addButton(tr("Close"), QDialogButtonBox::RejectRole); + + // Begin with a small bold monospace font for the textual version of the key and address. + QFont font("Monospace"); + font.setBold(true); + font.setStyleHint(QFont::TypeWriter); + font.setPixelSize(1); + ui->addressText->setFont(font); + ui->privateKeyText->setFont(font); + ui->addressText->setAlignment(Qt::AlignJustify); + ui->privateKeyText->setAlignment(Qt::AlignJustify); + setFixedSize(size()); +} + +void PaperWalletDialog::setClientModel(ClientModel *_clientModel) +{ + this->clientModel = _clientModel; + + // FIXME: This cannot be the right way of doing something on open + if (_clientModel && _clientModel->getNetworkActive()) { + QMessageBox::critical(this, "Warning: Network Activity Detected", tr("It is recommended to disconnect from the internet before printing paper wallets. Even though paper wallets are generated on your local computer, it is still possible to unknowingly have malware that transmits your screen to a remote location. It is also recommended to print to a local printer vs a network printer since that network traffic can be monitored. Some advanced printers also store copies of each printed document. Proceed with caution relative to the amount of value you plan to store on each address."), QMessageBox::Ok, QMessageBox::Ok); + } +} + +void PaperWalletDialog::setModel(WalletModel *model) +{ + RandAddSeed(); + this->model = model; + this->on_getNewAddress_clicked(); +} + +PaperWalletDialog::~PaperWalletDialog() +{ + delete ui; +} + +void PaperWalletDialog::on_getNewAddress_clicked() +{ + // Create a new private key + CKey privKey; + privKey.MakeNewKey(true); + + // Derive the public key + CPubKey pubkey = privKey.GetPubKey(); + + // Derive the public key hash + CBitcoinAddress pubkeyhash; + pubkeyhash.Set(pubkey.GetID()); + + // Create String versions of each + std::string myPrivKey = CBitcoinSecret(privKey).ToString(); + std::string myPubKey = HexStr(pubkey.begin(), pubkey.end()); + std::string myAddress = pubkeyhash.ToString(); + + +#ifdef USE_QRCODE + // Generate the address QR code + QRcode *code = QRcode_encodeString(myAddress.c_str(), 0, QR_ECLEVEL_M, QR_MODE_8, 1); + if (!code) { + ui->addressQRCode->setText(tr("Error encoding Address into QR Code.")); + return; + } + QImage myImage = QImage(code->width, code->width, QImage::Format_ARGB32); + myImage.fill(QColor(0, 0, 0, 0)); + unsigned char* p = code->data; + for (int y = 0; y < code->width; y++) { + for (int x = 0; x < code->width; x++) { + myImage.setPixel(x, y, ((*p & 1) ? 0xff000000 : 0x0)); + p++; + } + } + QRcode_free(code); + + + // Generate the private key QR code + code = QRcode_encodeString(myPrivKey.c_str(), 0, QR_ECLEVEL_M, QR_MODE_8, 1); + if (!code) { + ui->privateKeyQRCode->setText(tr("Error encoding private key into QR Code.")); + return; + } + QImage myImagePriv = QImage(code->width, code->width, QImage::Format_ARGB32); + myImagePriv.fill(QColor(0, 0, 0, 0)); + p = code->data; + for (int y = 0; y < code->width; y++) { + for (int x = 0; x < code->width; x++) { + myImagePriv.setPixel(x, y, ((*p & 1) ? 0xff000000 : 0x0)); + p++; + } + } + QRcode_free(code); + + // Populate the QR Codes + ui->addressQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(ui->addressQRCode->width(), ui->addressQRCode->height())); + ui->privateKeyQRCode->setPixmap(QPixmap::fromImage(myImagePriv).scaled(ui->privateKeyQRCode->width(), ui->privateKeyQRCode->height())); +#endif + + // Populate the Texts + ui->addressText->setText(myAddress.c_str()); + ui->privateKeyText->setText(tr(myPrivKey.c_str())); + + ui->publicKey->setHtml(myPubKey.c_str()); + + // Update the fonts to fit the height of the wallet. + // This should only really trigger the first time since the font size persists. + double paperHeight = (double)ui->paperTemplate->height(); + double maxTextWidth = paperHeight * 0.99; + double minTextWidth = paperHeight * 0.95; + int pixelSizeStep = 1; + + int addressTextLength = ui->addressText->fontMetrics().boundingRect(ui->addressText->text()).width(); + QFont font = ui->addressText->font(); + for (int i = 0; i < PAPER_WALLET_READJUST_LIMIT; i++) { + if (addressTextLength < minTextWidth) { + font.setPixelSize(font.pixelSize() + pixelSizeStep); + ui->addressText->setFont(font); + addressTextLength = ui->addressText->fontMetrics().boundingRect(ui->addressText->text()).width(); + } else { + break; + } + } + if (addressTextLength > maxTextWidth) { + font.setPixelSize(font.pixelSize() - pixelSizeStep); + ui->addressText->setFont(font); + addressTextLength = ui->addressText->fontMetrics().boundingRect(ui->addressText->text()).width(); + } + + int privateKeyTextLength = ui->privateKeyText->fontMetrics().boundingRect(ui->privateKeyText->text()).width(); + font = ui->privateKeyText->font(); + for (int i = 0; i < PAPER_WALLET_READJUST_LIMIT; i++) { + if (privateKeyTextLength < minTextWidth) { + font.setPixelSize(font.pixelSize() + pixelSizeStep); + ui->privateKeyText->setFont(font); + privateKeyTextLength = ui->privateKeyText->fontMetrics().boundingRect(ui->privateKeyText->text()).width(); + } else { + break; + } + } + if (privateKeyTextLength > maxTextWidth) { + font.setPixelSize(font.pixelSize() - pixelSizeStep); + ui->privateKeyText->setFont(font); + privateKeyTextLength = ui->privateKeyText->fontMetrics().boundingRect(ui->privateKeyText->text()).width(); + } +} + +void PaperWalletDialog::on_printButton_clicked() +{ + QPrinter printer(QPrinter::HighResolution); + QPrintDialog* qpd = new QPrintDialog(&printer, this); + + qpd->setPrintRange(QAbstractPrintDialog::AllPages); + + QList recipientPubKeyHashes; + + if (qpd->exec() != QDialog::Accepted) { + return; + } + + // Hardcode these values + printer.setOrientation(QPrinter::Portrait); + printer.setPaperSize(QPrinter::A4); + printer.setFullPage(true); + + QPainter painter; + if (!painter.begin(&printer)) { // failed to open file + QMessageBox::critical(this, "Printing Error", tr("failed to open file, is it writable?"), QMessageBox::Ok, QMessageBox::Ok); + return; + } + + int walletCount = ui->walletCount->currentIndex() + 1; + int walletsPerPage = 4; + + int pageHeight = printer.pageRect().height() - PAPER_WALLET_PAGE_MARGIN; + int walletHeight = ui->paperTemplate->height(); + double computedWalletHeight = 0.9 * pageHeight / walletsPerPage; + double scale = computedWalletHeight / walletHeight; + double walletPadding = pageHeight * 0.05 / (walletsPerPage - 1) / scale; + + QRegion walletRegion = QRegion(ui->paperTemplate->x(), ui->paperTemplate->y(), ui->paperTemplate->width(), ui->paperTemplate->height()); + painter.scale(scale, scale); + + for (int i = 0; i < walletCount; i++) { + QPoint point = QPoint(PAPER_WALLET_PAGE_MARGIN, (PAPER_WALLET_PAGE_MARGIN / 2) + (i % walletsPerPage) * (walletHeight + walletPadding)); + this->render(&painter, point, walletRegion); + recipientPubKeyHashes.append(ui->addressText->text()); + + if (i % walletsPerPage == (walletsPerPage - 1)) { + printer.newPage(); + } + + this->on_getNewAddress_clicked(); + } + + painter.end(); + +#ifdef ENABLE_WALLET + QStringList formatted; + + WalletModelTransaction* tx; + while (true) { + bool ok; + + // Ask for an amount to send to each paper wallet. It might be better to try to use the BitcoinAmountField, but this works fine. + double amountInput = QInputDialog::getDouble(this, tr("Load Paper Wallets"), tr("The paper wallet printing process has begun.
Please wait for the wallets to print completely and verify that everything printed correctly.
Check for misalignments, ink bleeding, smears, or anything else that could make the private keys unreadable.
Now, enter the number of DOGE you wish to send to each wallet:"), 0, 0, 2147483647, 8, &ok); + + if (!ok) { + return; + } + + + WalletModel::UnlockContext ctx(this->model->requestUnlock()); + if (!ctx.isValid()) { + return; + } + + QList recipients; + quint64 amount = (quint64)(amountInput * COIN); + Q_FOREACH (const QString& dest, recipientPubKeyHashes) { + recipients.append(SendCoinsRecipient(dest, tr("Paper wallet %1").arg(dest), amount, "")); + formatted.append(tr("%1 to Paper Wallet %2").arg(QString::number(amountInput, 'f', 8), GUIUtil::HtmlEscape(dest))); + } + + tx = new WalletModelTransaction(recipients); + + WalletModel::SendCoinsReturn prepareStatus; + if (this->model->getOptionsModel()->getCoinControlFeatures()) // coin control enabled + prepareStatus = this->model->prepareTransaction(*tx, CoinControlDialog::coinControl); + else + prepareStatus = this->model->prepareTransaction(*tx); + + if (prepareStatus.status == WalletModel::InvalidAddress) { + QMessageBox::critical(this, tr("Send Coins"), tr("The recipient address is not valid, please recheck."), QMessageBox::Ok, QMessageBox::Ok); + } else if (prepareStatus.status == WalletModel::InvalidAmount) { + QMessageBox::critical(this, tr("Send Coins"), tr("The amount to pay must be larger than 0"), QMessageBox::Ok, QMessageBox::Ok); + } else if (prepareStatus.status == WalletModel::AmountExceedsBalance) { + QMessageBox::critical(this, tr("Send Coins"), tr("The amount exceeds your balance."), QMessageBox::Ok, QMessageBox::Ok); + } else if (prepareStatus.status == WalletModel::AmountWithFeeExceedsBalance) { + QMessageBox::critical(this, tr("Send Coins"), tr("The total exceeds your balance when the transaction fee is included"), QMessageBox::Ok, QMessageBox::Ok); + } else if (prepareStatus.status == WalletModel::DuplicateAddress) { + QMessageBox::critical(this, tr("Send Coins"), tr("Duplicate address found, can only send to each address once per send operation."), QMessageBox::Ok, QMessageBox::Ok); + } else if (prepareStatus.status == WalletModel::TransactionCreationFailed) { + QMessageBox::critical(this, tr("Send Coins"), tr("Transaction creation failed!"), QMessageBox::Ok, QMessageBox::Ok); + } else if (prepareStatus.status == WalletModel::OK) { + break; + } else { + delete tx; + return; + } + } + + // Stolen from sendcoinsdialog.cpp + qint64 txFee = tx->getTransactionFee(); + QString questionString = tr("Are you sure you want to send?"); + questionString.append("

%1"); + + if (txFee > 0) { + // append fee string if a fee is required + questionString.append("
"); + questionString.append(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee)); + questionString.append(" "); + questionString.append(tr("added as transaction fee")); + } + + // add total amount in all subdivision units + questionString.append("
"); + qint64 totalAmount = tx->getTotalTransactionAmount() + txFee; + QStringList alternativeUnits; + Q_FOREACH (BitcoinUnits::Unit u, BitcoinUnits::availableUnits()) { + if (u != model->getOptionsModel()->getDisplayUnit()) + alternativeUnits.append(BitcoinUnits::formatWithUnit(u, totalAmount)); + } + + questionString.append(tr("Total Amount %1 (= %2)") + .arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), totalAmount)) + .arg(alternativeUnits.join(" " + tr("or") + " "))); + + QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"), questionString.arg(formatted.join("
")), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); + + if (retval != QMessageBox::Yes) { + delete tx; + return; + } + + WalletModel::SendCoinsReturn sendStatus = this->model->sendCoins(*tx); + + if (sendStatus.status == WalletModel::TransactionCommitFailed) { + QMessageBox::critical(this, tr("Send Coins"), tr("The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."), QMessageBox::Ok, QMessageBox::Ok); + } + delete tx; +#endif + return; +} /** "Shutdown" window */ ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f): -- cgit v1.2.3