2018-01-02 18:12:05 +01:00
|
|
|
// Copyright (c) 2011-2017 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 16:20:43 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2013-01-23 21:51:02 +01:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/bitcoingui.h>
|
|
|
|
|
|
|
|
#include <qt/bitcoinunits.h>
|
|
|
|
#include <qt/clientmodel.h>
|
|
|
|
#include <qt/guiconstants.h>
|
|
|
|
#include <qt/guiutil.h>
|
|
|
|
#include <qt/modaloverlay.h>
|
|
|
|
#include <qt/networkstyle.h>
|
|
|
|
#include <qt/notificator.h>
|
|
|
|
#include <qt/openuridialog.h>
|
|
|
|
#include <qt/optionsdialog.h>
|
|
|
|
#include <qt/optionsmodel.h>
|
|
|
|
#include <qt/platformstyle.h>
|
|
|
|
#include <qt/rpcconsole.h>
|
|
|
|
#include <qt/utilitydialog.h>
|
2014-09-05 13:18:35 +02:00
|
|
|
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/walletframe.h>
|
|
|
|
#include <qt/walletmodel.h>
|
2016-10-24 09:21:51 +02:00
|
|
|
#include <qt/walletview.h>
|
2014-10-30 07:31:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2011-05-07 22:13:39 +02:00
|
|
|
|
2012-09-21 19:06:53 +02:00
|
|
|
#ifdef Q_OS_MAC
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/macdockiconhandler.h>
|
2011-10-07 13:21:45 +02:00
|
|
|
#endif
|
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <chainparams.h>
|
|
|
|
#include <init.h>
|
|
|
|
#include <ui_interface.h>
|
|
|
|
#include <util.h>
|
2013-04-13 07:13:08 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2014-06-07 08:20:22 +02:00
|
|
|
#include <QAction>
|
2013-07-23 08:52:24 +02:00
|
|
|
#include <QApplication>
|
2016-09-09 12:43:54 +02:00
|
|
|
#include <QComboBox>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QDateTime>
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QDragEnterEvent>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QMenuBar>
|
2011-05-30 20:20:12 +02:00
|
|
|
#include <QMessageBox>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QMimeData>
|
2014-05-23 18:04:09 +02:00
|
|
|
#include <QProgressDialog>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QSettings>
|
2015-11-12 12:59:26 +01:00
|
|
|
#include <QShortcut>
|
2011-07-05 22:09:39 +02:00
|
|
|
#include <QStackedWidget>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QStatusBar>
|
|
|
|
#include <QStyle>
|
2012-03-15 22:30:08 +01:00
|
|
|
#include <QTimer>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QToolBar>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2013-05-31 14:02:24 +02:00
|
|
|
#if QT_VERSION < 0x050000
|
2013-07-22 08:50:39 +02:00
|
|
|
#include <QTextDocument>
|
2014-09-05 13:18:35 +02:00
|
|
|
#include <QUrl>
|
2013-04-13 07:13:08 +02:00
|
|
|
#else
|
|
|
|
#include <QUrlQuery>
|
2013-05-31 14:02:24 +02:00
|
|
|
#endif
|
2011-05-07 22:13:39 +02:00
|
|
|
|
2015-11-28 22:44:55 +01:00
|
|
|
const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
|
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
"macosx"
|
|
|
|
#elif defined(Q_OS_WIN)
|
|
|
|
"windows"
|
|
|
|
#else
|
|
|
|
"other"
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
|
2011-06-30 18:05:29 +02:00
|
|
|
QMainWindow(parent),
|
2016-09-21 12:37:00 +02:00
|
|
|
enableWallet(false),
|
2011-06-30 18:05:29 +02:00
|
|
|
clientModel(0),
|
2013-12-11 15:00:56 +01:00
|
|
|
walletFrame(0),
|
2014-08-07 09:34:31 +02:00
|
|
|
unitDisplayControl(0),
|
2016-08-17 14:09:47 +02:00
|
|
|
labelWalletEncryptionIcon(0),
|
|
|
|
labelWalletHDStatusIcon(0),
|
2014-11-19 13:33:34 +01:00
|
|
|
connectionsControl(0),
|
2014-08-07 09:34:31 +02:00
|
|
|
labelBlocksIcon(0),
|
|
|
|
progressBarLabel(0),
|
|
|
|
progressBar(0),
|
|
|
|
progressDialog(0),
|
|
|
|
appMenuBar(0),
|
|
|
|
overviewAction(0),
|
|
|
|
historyAction(0),
|
|
|
|
quitAction(0),
|
|
|
|
sendCoinsAction(0),
|
2015-01-12 21:59:58 +01:00
|
|
|
sendCoinsMenuAction(0),
|
2014-08-07 09:34:31 +02:00
|
|
|
usedSendingAddressesAction(0),
|
|
|
|
usedReceivingAddressesAction(0),
|
|
|
|
signMessageAction(0),
|
|
|
|
verifyMessageAction(0),
|
|
|
|
aboutAction(0),
|
|
|
|
receiveCoinsAction(0),
|
2015-01-12 21:59:58 +01:00
|
|
|
receiveCoinsMenuAction(0),
|
2014-08-07 09:34:31 +02:00
|
|
|
optionsAction(0),
|
|
|
|
toggleHideAction(0),
|
2011-08-24 22:07:26 +02:00
|
|
|
encryptWalletAction(0),
|
2014-08-07 09:34:31 +02:00
|
|
|
backupWalletAction(0),
|
2011-08-24 22:07:26 +02:00
|
|
|
changePassphraseAction(0),
|
2011-12-13 17:30:13 +01:00
|
|
|
aboutQtAction(0),
|
2014-08-07 09:34:31 +02:00
|
|
|
openRPCConsoleAction(0),
|
|
|
|
openAction(0),
|
|
|
|
showHelpMessageAction(0),
|
2011-09-03 20:52:54 +02:00
|
|
|
trayIcon(0),
|
2014-08-07 09:37:21 +02:00
|
|
|
trayIconMenu(0),
|
2012-04-09 21:07:25 +02:00
|
|
|
notificator(0),
|
2013-02-10 19:01:30 +01:00
|
|
|
rpcConsole(0),
|
2015-08-27 21:53:16 +02:00
|
|
|
helpMessageDialog(0),
|
2016-07-19 15:51:24 +02:00
|
|
|
modalOverlay(0),
|
2014-01-13 14:16:48 +01:00
|
|
|
prevBlocks(0),
|
2015-07-28 15:20:14 +02:00
|
|
|
spinnerFrame(0),
|
2016-09-09 13:43:29 +02:00
|
|
|
platformStyle(_platformStyle)
|
2011-05-07 22:13:39 +02:00
|
|
|
{
|
2017-09-15 06:38:42 +02:00
|
|
|
QSettings settings;
|
|
|
|
if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
|
|
|
|
// Restore failed (perhaps missing setting), center the window
|
|
|
|
move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
|
|
|
|
}
|
2013-05-19 20:20:06 +02:00
|
|
|
|
2015-12-09 11:53:12 +01:00
|
|
|
QString windowTitle = tr(PACKAGE_NAME) + " - ";
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2016-09-21 12:37:00 +02:00
|
|
|
enableWallet = WalletModel::isWalletEnabled();
|
2014-10-30 07:31:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2013-12-11 15:00:56 +01:00
|
|
|
if(enableWallet)
|
|
|
|
{
|
|
|
|
windowTitle += tr("Wallet");
|
|
|
|
} else {
|
|
|
|
windowTitle += tr("Node");
|
|
|
|
}
|
2014-10-09 11:04:49 +02:00
|
|
|
windowTitle += " " + networkStyle->getTitleAddText();
|
2013-11-21 17:59:31 +01:00
|
|
|
#ifndef Q_OS_MAC
|
2014-11-14 17:16:31 +01:00
|
|
|
QApplication::setWindowIcon(networkStyle->getTrayAndWindowIcon());
|
|
|
|
setWindowIcon(networkStyle->getTrayAndWindowIcon());
|
2011-10-07 13:21:45 +02:00
|
|
|
#else
|
2014-10-09 11:04:49 +02:00
|
|
|
MacDockIconHandler::instance()->setIcon(networkStyle->getAppIcon());
|
2011-10-07 13:21:45 +02:00
|
|
|
#endif
|
2013-12-11 15:00:56 +01:00
|
|
|
setWindowTitle(windowTitle);
|
2013-11-21 17:59:31 +01:00
|
|
|
|
|
|
|
#if defined(Q_OS_MAC) && QT_VERSION < 0x050000
|
|
|
|
// This property is not implemented in Qt 5. Setting it has no effect.
|
|
|
|
// A replacement API (QtMacUnifiedToolBar) is available in QtMacExtras.
|
|
|
|
setUnifiedTitleAndToolBarOnMac(true);
|
|
|
|
#endif
|
2013-05-19 20:20:06 +02:00
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
rpcConsole = new RPCConsole(_platformStyle, 0);
|
2015-08-27 21:53:16 +02:00
|
|
|
helpMessageDialog = new HelpMessageDialog(this, false);
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
if(enableWallet)
|
|
|
|
{
|
|
|
|
/** Create wallet frame and make it the central widget */
|
2016-09-09 13:43:29 +02:00
|
|
|
walletFrame = new WalletFrame(_platformStyle, this);
|
2013-12-11 15:00:56 +01:00
|
|
|
setCentralWidget(walletFrame);
|
|
|
|
} else
|
2014-10-30 07:31:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2013-12-11 15:00:56 +01:00
|
|
|
{
|
|
|
|
/* When compiled without wallet or -disablewallet is provided,
|
|
|
|
* the central widget is the rpc console.
|
|
|
|
*/
|
|
|
|
setCentralWidget(rpcConsole);
|
|
|
|
}
|
2013-04-06 18:11:15 +02:00
|
|
|
|
2011-08-08 17:38:17 +02:00
|
|
|
// Accept D&D of URIs
|
|
|
|
setAcceptDrops(true);
|
2011-05-12 20:16:42 +02:00
|
|
|
|
2011-10-07 13:21:45 +02:00
|
|
|
// Create actions for the toolbar, menu bar and tray/dock icon
|
2013-04-06 18:11:15 +02:00
|
|
|
// Needs walletFrame to be initialized
|
2015-03-03 08:42:52 +01:00
|
|
|
createActions();
|
2011-05-10 19:03:10 +02:00
|
|
|
|
2011-10-07 13:21:45 +02:00
|
|
|
// Create application menu bar
|
|
|
|
createMenuBar();
|
2011-07-16 19:28:15 +02:00
|
|
|
|
2011-10-07 13:21:45 +02:00
|
|
|
// Create the toolbars
|
|
|
|
createToolBars();
|
2011-05-07 22:13:39 +02:00
|
|
|
|
2012-11-27 22:20:43 +01:00
|
|
|
// Create system tray icon and notification
|
2014-10-09 11:04:49 +02:00
|
|
|
createTrayIcon(networkStyle);
|
2011-07-05 22:09:39 +02:00
|
|
|
|
2011-06-05 14:19:57 +02:00
|
|
|
// Create status bar
|
2011-05-12 20:16:42 +02:00
|
|
|
statusBar();
|
2015-03-18 11:26:09 +01:00
|
|
|
|
2015-01-13 08:38:57 +01:00
|
|
|
// Disable size grip because it looks ugly and nobody needs it
|
|
|
|
statusBar()->setSizeGripEnabled(false);
|
2011-06-14 21:34:51 +02:00
|
|
|
|
2011-08-08 17:38:17 +02:00
|
|
|
// Status bar notification icons
|
2011-07-17 17:30:58 +02:00
|
|
|
QFrame *frameBlocks = new QFrame();
|
2011-08-04 19:04:42 +02:00
|
|
|
frameBlocks->setContentsMargins(0,0,0,0);
|
2014-03-06 14:47:07 +01:00
|
|
|
frameBlocks->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
2011-07-17 17:30:58 +02:00
|
|
|
QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
|
|
|
|
frameBlocksLayout->setContentsMargins(3,0,3,0);
|
|
|
|
frameBlocksLayout->setSpacing(3);
|
2015-07-28 15:20:14 +02:00
|
|
|
unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle);
|
2016-08-17 14:09:47 +02:00
|
|
|
labelWalletEncryptionIcon = new QLabel();
|
|
|
|
labelWalletHDStatusIcon = new QLabel();
|
2016-11-24 14:26:20 +01:00
|
|
|
connectionsControl = new GUIUtil::ClickableLabel();
|
2016-11-24 14:37:36 +01:00
|
|
|
labelBlocksIcon = new GUIUtil::ClickableLabel();
|
2014-07-13 06:27:29 +02:00
|
|
|
if(enableWallet)
|
|
|
|
{
|
|
|
|
frameBlocksLayout->addStretch();
|
|
|
|
frameBlocksLayout->addWidget(unitDisplayControl);
|
|
|
|
frameBlocksLayout->addStretch();
|
2016-08-17 14:09:47 +02:00
|
|
|
frameBlocksLayout->addWidget(labelWalletEncryptionIcon);
|
|
|
|
frameBlocksLayout->addWidget(labelWalletHDStatusIcon);
|
2014-07-13 06:27:29 +02:00
|
|
|
}
|
2011-08-23 20:08:42 +02:00
|
|
|
frameBlocksLayout->addStretch();
|
2014-11-19 13:33:34 +01:00
|
|
|
frameBlocksLayout->addWidget(connectionsControl);
|
2011-08-04 19:04:42 +02:00
|
|
|
frameBlocksLayout->addStretch();
|
2011-07-17 17:30:58 +02:00
|
|
|
frameBlocksLayout->addWidget(labelBlocksIcon);
|
|
|
|
frameBlocksLayout->addStretch();
|
2011-06-11 12:46:09 +02:00
|
|
|
|
2012-04-02 19:07:03 +02:00
|
|
|
// Progress bar and label for blocks download
|
|
|
|
progressBarLabel = new QLabel();
|
2011-06-18 21:25:38 +02:00
|
|
|
progressBarLabel->setVisible(false);
|
2014-11-18 09:55:39 +01:00
|
|
|
progressBar = new GUIUtil::ProgressBar();
|
2012-04-13 18:25:56 +02:00
|
|
|
progressBar->setAlignment(Qt::AlignCenter);
|
2011-06-18 21:25:38 +02:00
|
|
|
progressBar->setVisible(false);
|
|
|
|
|
2012-08-24 14:47:54 +02:00
|
|
|
// Override style sheet for progress bar for styles that have a segmented progress bar,
|
|
|
|
// as they make the text unreadable (workaround for issue #1071)
|
|
|
|
// See https://qt-project.org/doc/qt-4.8/gallery.html
|
2013-04-02 17:30:14 +02:00
|
|
|
QString curStyle = QApplication::style()->metaObject()->className();
|
2012-08-24 14:47:54 +02:00
|
|
|
if(curStyle == "QWindowsStyle" || curStyle == "QWindowsXPStyle")
|
|
|
|
{
|
|
|
|
progressBar->setStyleSheet("QProgressBar { background-color: #e8e8e8; border: 1px solid grey; border-radius: 7px; padding: 1px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF8000, stop: 1 orange); border-radius: 7px; margin: 0px; }");
|
|
|
|
}
|
|
|
|
|
2011-06-18 21:25:38 +02:00
|
|
|
statusBar()->addWidget(progressBarLabel);
|
|
|
|
statusBar()->addWidget(progressBar);
|
2011-07-17 17:30:58 +02:00
|
|
|
statusBar()->addPermanentWidget(frameBlocks);
|
2011-06-18 21:25:38 +02:00
|
|
|
|
2012-10-12 16:08:47 +02:00
|
|
|
// Install event filter to be able to catch status tip events (QEvent::StatusTip)
|
|
|
|
this->installEventFilter(this);
|
2013-11-12 14:54:43 +01:00
|
|
|
|
|
|
|
// Initially wallet actions should be disabled
|
|
|
|
setWalletActionsEnabled(false);
|
2014-01-08 08:59:24 +01:00
|
|
|
|
|
|
|
// Subscribe to notifications from core
|
|
|
|
subscribeToCoreSignals();
|
2016-07-19 15:51:24 +02:00
|
|
|
|
2016-11-24 14:26:20 +01:00
|
|
|
connect(connectionsControl, SIGNAL(clicked(QPoint)), this, SLOT(toggleNetworkActive()));
|
|
|
|
|
2016-07-19 15:51:24 +02:00
|
|
|
modalOverlay = new ModalOverlay(this->centralWidget());
|
|
|
|
#ifdef ENABLE_WALLET
|
2016-11-24 14:37:36 +01:00
|
|
|
if(enableWallet) {
|
2016-09-21 10:29:57 +02:00
|
|
|
connect(walletFrame, SIGNAL(requestedSyncWarningInfo()), this, SLOT(showModalOverlay()));
|
2016-11-24 14:37:36 +01:00
|
|
|
connect(labelBlocksIcon, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
|
2016-12-05 09:26:43 +01:00
|
|
|
connect(progressBar, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
|
2016-11-24 14:37:36 +01:00
|
|
|
}
|
2016-07-19 15:51:24 +02:00
|
|
|
#endif
|
2011-05-12 20:16:42 +02:00
|
|
|
}
|
|
|
|
|
2011-10-07 13:21:45 +02:00
|
|
|
BitcoinGUI::~BitcoinGUI()
|
|
|
|
{
|
2014-01-08 08:59:24 +01:00
|
|
|
// Unsubscribe from notifications from core
|
|
|
|
unsubscribeFromCoreSignals();
|
|
|
|
|
2017-09-15 06:38:42 +02:00
|
|
|
QSettings settings;
|
|
|
|
settings.setValue("MainWindowGeometry", saveGeometry());
|
2012-02-19 12:07:07 +01:00
|
|
|
if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
|
|
|
|
trayIcon->hide();
|
2012-09-21 19:06:53 +02:00
|
|
|
#ifdef Q_OS_MAC
|
2011-10-07 13:21:45 +02:00
|
|
|
delete appMenuBar;
|
2015-03-13 15:40:53 +01:00
|
|
|
MacDockIconHandler::cleanup();
|
2011-10-07 13:21:45 +02:00
|
|
|
#endif
|
2014-11-10 16:41:57 +01:00
|
|
|
|
|
|
|
delete rpcConsole;
|
2011-10-07 13:21:45 +02:00
|
|
|
}
|
|
|
|
|
2015-03-03 08:42:52 +01:00
|
|
|
void BitcoinGUI::createActions()
|
2011-05-12 20:16:42 +02:00
|
|
|
{
|
2011-07-05 22:09:39 +02:00
|
|
|
QActionGroup *tabGroup = new QActionGroup(this);
|
2011-07-07 17:33:15 +02:00
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
overviewAction = new QAction(platformStyle->SingleColorIcon(":/icons/overview"), tr("&Overview"), this);
|
2012-10-12 16:08:47 +02:00
|
|
|
overviewAction->setStatusTip(tr("Show general overview of wallet"));
|
|
|
|
overviewAction->setToolTip(overviewAction->statusTip());
|
2011-07-05 22:09:39 +02:00
|
|
|
overviewAction->setCheckable(true);
|
2011-10-09 21:40:03 +02:00
|
|
|
overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1));
|
2011-07-05 22:09:39 +02:00
|
|
|
tabGroup->addAction(overviewAction);
|
2011-07-07 17:33:15 +02:00
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
sendCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/send"), tr("&Send"), this);
|
2012-10-12 16:08:47 +02:00
|
|
|
sendCoinsAction->setStatusTip(tr("Send coins to a Bitcoin address"));
|
|
|
|
sendCoinsAction->setToolTip(sendCoinsAction->statusTip());
|
2012-08-29 10:12:34 +02:00
|
|
|
sendCoinsAction->setCheckable(true);
|
|
|
|
sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
|
|
|
|
tabGroup->addAction(sendCoinsAction);
|
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
sendCoinsMenuAction = new QAction(platformStyle->TextColorIcon(":/icons/send"), sendCoinsAction->text(), this);
|
2015-01-12 21:59:58 +01:00
|
|
|
sendCoinsMenuAction->setStatusTip(sendCoinsAction->statusTip());
|
|
|
|
sendCoinsMenuAction->setToolTip(sendCoinsMenuAction->statusTip());
|
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
receiveCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/receiving_addresses"), tr("&Receive"), this);
|
2013-10-25 14:19:44 +02:00
|
|
|
receiveCoinsAction->setStatusTip(tr("Request payments (generates QR codes and bitcoin: URIs)"));
|
2012-10-12 16:08:47 +02:00
|
|
|
receiveCoinsAction->setToolTip(receiveCoinsAction->statusTip());
|
2012-08-29 10:12:34 +02:00
|
|
|
receiveCoinsAction->setCheckable(true);
|
|
|
|
receiveCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_3));
|
|
|
|
tabGroup->addAction(receiveCoinsAction);
|
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
receiveCoinsMenuAction = new QAction(platformStyle->TextColorIcon(":/icons/receiving_addresses"), receiveCoinsAction->text(), this);
|
2015-01-12 21:59:58 +01:00
|
|
|
receiveCoinsMenuAction->setStatusTip(receiveCoinsAction->statusTip());
|
|
|
|
receiveCoinsMenuAction->setToolTip(receiveCoinsMenuAction->statusTip());
|
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
historyAction = new QAction(platformStyle->SingleColorIcon(":/icons/history"), tr("&Transactions"), this);
|
2012-10-12 16:08:47 +02:00
|
|
|
historyAction->setStatusTip(tr("Browse transaction history"));
|
|
|
|
historyAction->setToolTip(historyAction->statusTip());
|
2011-07-05 22:09:39 +02:00
|
|
|
historyAction->setCheckable(true);
|
2011-10-09 21:40:03 +02:00
|
|
|
historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
|
2011-07-05 22:09:39 +02:00
|
|
|
tabGroup->addAction(historyAction);
|
|
|
|
|
2014-10-30 07:31:34 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2013-12-20 09:33:44 +01:00
|
|
|
// These showNormalIfMinimized are needed because Send Coins and Receive Coins
|
|
|
|
// can be triggered from the tray menu, and need to show the GUI to be useful.
|
2012-02-17 23:19:52 +01:00
|
|
|
connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
|
2011-07-07 17:33:15 +02:00
|
|
|
connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
|
2012-08-29 10:12:34 +02:00
|
|
|
connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
|
|
|
|
connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
|
2015-01-12 21:59:58 +01:00
|
|
|
connect(sendCoinsMenuAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
|
|
|
|
connect(sendCoinsMenuAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
|
2012-08-29 10:12:34 +02:00
|
|
|
connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
|
|
|
|
connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
|
2015-01-12 21:59:58 +01:00
|
|
|
connect(receiveCoinsMenuAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
|
|
|
|
connect(receiveCoinsMenuAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
|
2012-02-17 23:19:52 +01:00
|
|
|
connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
|
2011-07-07 17:33:15 +02:00
|
|
|
connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
|
2014-10-30 07:31:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2013-04-01 14:43:50 +02:00
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
quitAction = new QAction(platformStyle->TextColorIcon(":/icons/quit"), tr("E&xit"), this);
|
2012-10-12 16:08:47 +02:00
|
|
|
quitAction->setStatusTip(tr("Quit application"));
|
2011-10-09 21:06:28 +02:00
|
|
|
quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
|
2011-10-07 13:21:45 +02:00
|
|
|
quitAction->setMenuRole(QAction::QuitRole);
|
2015-12-09 11:53:12 +01:00
|
|
|
aboutAction = new QAction(platformStyle->TextColorIcon(":/icons/about"), tr("&About %1").arg(tr(PACKAGE_NAME)), this);
|
|
|
|
aboutAction->setStatusTip(tr("Show information about %1").arg(tr(PACKAGE_NAME)));
|
2011-12-13 17:30:13 +01:00
|
|
|
aboutAction->setMenuRole(QAction::AboutRole);
|
2016-05-11 21:08:36 +02:00
|
|
|
aboutAction->setEnabled(false);
|
2015-07-28 15:20:14 +02:00
|
|
|
aboutQtAction = new QAction(platformStyle->TextColorIcon(":/icons/about_qt"), tr("About &Qt"), this);
|
2012-10-12 16:08:47 +02:00
|
|
|
aboutQtAction->setStatusTip(tr("Show information about Qt"));
|
2011-12-13 17:30:13 +01:00
|
|
|
aboutQtAction->setMenuRole(QAction::AboutQtRole);
|
2015-07-28 15:20:14 +02:00
|
|
|
optionsAction = new QAction(platformStyle->TextColorIcon(":/icons/options"), tr("&Options..."), this);
|
2015-12-09 11:53:12 +01:00
|
|
|
optionsAction->setStatusTip(tr("Modify configuration options for %1").arg(tr(PACKAGE_NAME)));
|
2011-10-07 13:21:45 +02:00
|
|
|
optionsAction->setMenuRole(QAction::PreferencesRole);
|
2016-05-11 21:08:36 +02:00
|
|
|
optionsAction->setEnabled(false);
|
2015-07-28 15:20:14 +02:00
|
|
|
toggleHideAction = new QAction(platformStyle->TextColorIcon(":/icons/about"), tr("&Show / Hide"), this);
|
2012-10-12 16:08:47 +02:00
|
|
|
toggleHideAction->setStatusTip(tr("Show or hide the main Window"));
|
2013-04-03 17:29:02 +02:00
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
encryptWalletAction = new QAction(platformStyle->TextColorIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
|
2012-10-12 16:08:47 +02:00
|
|
|
encryptWalletAction->setStatusTip(tr("Encrypt the private keys that belong to your wallet"));
|
2011-08-24 22:07:26 +02:00
|
|
|
encryptWalletAction->setCheckable(true);
|
2015-07-28 15:20:14 +02:00
|
|
|
backupWalletAction = new QAction(platformStyle->TextColorIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
|
2012-10-12 16:08:47 +02:00
|
|
|
backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
|
2015-07-28 15:20:14 +02:00
|
|
|
changePassphraseAction = new QAction(platformStyle->TextColorIcon(":/icons/key"), tr("&Change Passphrase..."), this);
|
2012-10-12 16:08:47 +02:00
|
|
|
changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
|
2015-07-28 15:20:14 +02:00
|
|
|
signMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/edit"), tr("Sign &message..."), this);
|
2012-10-12 16:08:47 +02:00
|
|
|
signMessageAction->setStatusTip(tr("Sign messages with your Bitcoin addresses to prove you own them"));
|
2015-07-28 15:20:14 +02:00
|
|
|
verifyMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/verify"), tr("&Verify message..."), this);
|
2012-10-12 16:08:47 +02:00
|
|
|
verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Bitcoin addresses"));
|
2012-08-29 10:12:34 +02:00
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
openRPCConsoleAction = new QAction(platformStyle->TextColorIcon(":/icons/debugwindow"), tr("&Debug window"), this);
|
2012-10-12 16:08:47 +02:00
|
|
|
openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
|
2016-05-11 21:08:36 +02:00
|
|
|
// initially disable the debug window menu item
|
|
|
|
openRPCConsoleAction->setEnabled(false);
|
2011-05-12 20:16:42 +02:00
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
usedSendingAddressesAction = new QAction(platformStyle->TextColorIcon(":/icons/address-book"), tr("&Sending addresses..."), this);
|
2013-10-25 14:19:44 +02:00
|
|
|
usedSendingAddressesAction->setStatusTip(tr("Show the list of used sending addresses and labels"));
|
2015-07-28 15:20:14 +02:00
|
|
|
usedReceivingAddressesAction = new QAction(platformStyle->TextColorIcon(":/icons/address-book"), tr("&Receiving addresses..."), this);
|
2013-10-25 14:19:44 +02:00
|
|
|
usedReceivingAddressesAction->setStatusTip(tr("Show the list of used receiving addresses and labels"));
|
2013-10-16 15:14:26 +02:00
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
openAction = new QAction(platformStyle->TextColorIcon(":/icons/open"), tr("Open &URI..."), this);
|
2013-11-06 15:08:56 +01:00
|
|
|
openAction->setStatusTip(tr("Open a bitcoin: URI or payment request"));
|
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
showHelpMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/info"), tr("&Command-line options"), this);
|
2015-03-06 09:33:23 +01:00
|
|
|
showHelpMessageAction->setMenuRole(QAction::NoRole);
|
2015-12-09 11:53:12 +01:00
|
|
|
showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Bitcoin command-line options").arg(tr(PACKAGE_NAME)));
|
2014-01-22 14:47:33 +01:00
|
|
|
|
2011-07-07 17:33:15 +02:00
|
|
|
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
|
|
|
|
connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
|
2011-12-13 17:30:13 +01:00
|
|
|
connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
2012-08-29 10:12:34 +02:00
|
|
|
connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
|
2012-02-17 15:34:53 +01:00
|
|
|
connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
|
2014-01-22 14:47:33 +01:00
|
|
|
connect(showHelpMessageAction, SIGNAL(triggered()), this, SLOT(showHelpMessageClicked()));
|
2015-09-07 11:00:59 +02:00
|
|
|
connect(openRPCConsoleAction, SIGNAL(triggered()), this, SLOT(showDebugWindow()));
|
|
|
|
// prevents an open debug window from becoming stuck/unusable on client shutdown
|
|
|
|
connect(quitAction, SIGNAL(triggered()), rpcConsole, SLOT(hide()));
|
|
|
|
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
if(walletFrame)
|
|
|
|
{
|
|
|
|
connect(encryptWalletAction, SIGNAL(triggered(bool)), walletFrame, SLOT(encryptWallet(bool)));
|
|
|
|
connect(backupWalletAction, SIGNAL(triggered()), walletFrame, SLOT(backupWallet()));
|
|
|
|
connect(changePassphraseAction, SIGNAL(triggered()), walletFrame, SLOT(changePassphrase()));
|
|
|
|
connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
|
|
|
|
connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
|
|
|
|
connect(usedSendingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedSendingAddresses()));
|
|
|
|
connect(usedReceivingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedReceivingAddresses()));
|
|
|
|
connect(openAction, SIGNAL(triggered()), this, SLOT(openClicked()));
|
|
|
|
}
|
2014-10-30 07:31:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2015-11-12 12:59:26 +01:00
|
|
|
|
|
|
|
new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C), this, SLOT(showDebugWindowActivateConsole()));
|
|
|
|
new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D), this, SLOT(showDebugWindow()));
|
2011-05-12 20:16:42 +02:00
|
|
|
}
|
|
|
|
|
2011-10-07 13:21:45 +02:00
|
|
|
void BitcoinGUI::createMenuBar()
|
|
|
|
{
|
2012-09-21 19:06:53 +02:00
|
|
|
#ifdef Q_OS_MAC
|
2011-10-07 13:21:45 +02:00
|
|
|
// Create a decoupled menu bar on Mac which stays even if the window is closed
|
|
|
|
appMenuBar = new QMenuBar();
|
|
|
|
#else
|
|
|
|
// Get the main window's menu bar on other platforms
|
|
|
|
appMenuBar = menuBar();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Configure the menus
|
|
|
|
QMenu *file = appMenuBar->addMenu(tr("&File"));
|
2013-12-11 15:00:56 +01:00
|
|
|
if(walletFrame)
|
|
|
|
{
|
|
|
|
file->addAction(openAction);
|
|
|
|
file->addAction(backupWalletAction);
|
|
|
|
file->addAction(signMessageAction);
|
|
|
|
file->addAction(verifyMessageAction);
|
|
|
|
file->addSeparator();
|
|
|
|
file->addAction(usedSendingAddressesAction);
|
|
|
|
file->addAction(usedReceivingAddressesAction);
|
|
|
|
file->addSeparator();
|
|
|
|
}
|
2011-10-07 13:21:45 +02:00
|
|
|
file->addAction(quitAction);
|
|
|
|
|
|
|
|
QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
|
2013-12-11 15:00:56 +01:00
|
|
|
if(walletFrame)
|
|
|
|
{
|
|
|
|
settings->addAction(encryptWalletAction);
|
|
|
|
settings->addAction(changePassphraseAction);
|
|
|
|
settings->addSeparator();
|
|
|
|
}
|
2011-10-07 13:21:45 +02:00
|
|
|
settings->addAction(optionsAction);
|
|
|
|
|
|
|
|
QMenu *help = appMenuBar->addMenu(tr("&Help"));
|
2013-12-11 15:00:56 +01:00
|
|
|
if(walletFrame)
|
|
|
|
{
|
|
|
|
help->addAction(openRPCConsoleAction);
|
|
|
|
}
|
2014-01-22 14:47:33 +01:00
|
|
|
help->addAction(showHelpMessageAction);
|
|
|
|
help->addSeparator();
|
2011-10-07 13:21:45 +02:00
|
|
|
help->addAction(aboutAction);
|
2011-12-13 17:30:13 +01:00
|
|
|
help->addAction(aboutQtAction);
|
2011-10-07 13:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::createToolBars()
|
|
|
|
{
|
2013-12-11 15:00:56 +01:00
|
|
|
if(walletFrame)
|
|
|
|
{
|
|
|
|
QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
|
2017-08-27 07:08:19 +02:00
|
|
|
toolbar->setContextMenuPolicy(Qt::PreventContextMenu);
|
2015-05-19 17:23:32 +02:00
|
|
|
toolbar->setMovable(false);
|
2013-12-11 15:00:56 +01:00
|
|
|
toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
|
|
|
toolbar->addAction(overviewAction);
|
|
|
|
toolbar->addAction(sendCoinsAction);
|
|
|
|
toolbar->addAction(receiveCoinsAction);
|
|
|
|
toolbar->addAction(historyAction);
|
|
|
|
overviewAction->setChecked(true);
|
2016-09-09 12:43:54 +02:00
|
|
|
|
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
QWidget *spacer = new QWidget();
|
|
|
|
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
toolbar->addWidget(spacer);
|
|
|
|
|
|
|
|
m_wallet_selector_label = new QLabel();
|
|
|
|
m_wallet_selector_label->setText(tr("Wallet:") + " ");
|
|
|
|
toolbar->addWidget(m_wallet_selector_label);
|
|
|
|
m_wallet_selector_label->setVisible(false);
|
|
|
|
m_wallet_selector = new QComboBox();
|
|
|
|
toolbar->addWidget(m_wallet_selector);
|
|
|
|
m_wallet_selector->setVisible(false);
|
|
|
|
m_wallet_selector_label->setBuddy(m_wallet_selector);
|
|
|
|
|
|
|
|
connect(m_wallet_selector, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(setCurrentWallet(const QString&)));
|
|
|
|
#endif
|
2013-12-11 15:00:56 +01:00
|
|
|
}
|
2011-10-07 13:21:45 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
void BitcoinGUI::setClientModel(ClientModel *_clientModel)
|
2011-05-22 17:19:43 +02:00
|
|
|
{
|
2016-09-09 13:43:29 +02:00
|
|
|
this->clientModel = _clientModel;
|
|
|
|
if(_clientModel)
|
2011-06-30 19:14:42 +02:00
|
|
|
{
|
2012-11-27 22:20:43 +01:00
|
|
|
// Create system tray menu (or setup the dock menu) that late to prevent users from calling actions,
|
|
|
|
// while the client has not yet fully loaded
|
2013-03-19 23:33:36 +01:00
|
|
|
createTrayIconMenu();
|
2012-11-27 22:20:43 +01:00
|
|
|
|
2011-11-08 21:18:36 +01:00
|
|
|
// Keep up to date with client
|
2013-03-26 03:07:06 +01:00
|
|
|
updateNetworkState();
|
2016-09-09 13:43:29 +02:00
|
|
|
connect(_clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
|
2013-03-26 03:07:06 +01:00
|
|
|
connect(_clientModel, SIGNAL(networkActiveChanged(bool)), this, SLOT(setNetworkActive(bool)));
|
2011-05-22 17:19:43 +02:00
|
|
|
|
2017-04-19 20:54:30 +02:00
|
|
|
modalOverlay->setKnownBestHeight(_clientModel->getHeaderTipHeight(), QDateTime::fromTime_t(_clientModel->getHeaderTipTime()));
|
2017-08-07 07:36:37 +02:00
|
|
|
setNumBlocks(_clientModel->getNumBlocks(), _clientModel->getLastBlockDate(), _clientModel->getVerificationProgress(nullptr), false);
|
2016-09-09 13:43:29 +02:00
|
|
|
connect(_clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool)));
|
2011-05-22 17:19:43 +02:00
|
|
|
|
2013-11-14 19:47:45 +01:00
|
|
|
// Receive and report messages from client model
|
2016-09-09 13:43:29 +02:00
|
|
|
connect(_clientModel, SIGNAL(message(QString,QString,unsigned int)), this, SLOT(message(QString,QString,unsigned int)));
|
2012-04-09 21:07:25 +02:00
|
|
|
|
2014-05-23 18:04:09 +02:00
|
|
|
// Show progress dialog
|
2016-09-09 13:43:29 +02:00
|
|
|
connect(_clientModel, SIGNAL(showProgress(QString,int)), this, SLOT(showProgress(QString,int)));
|
2014-05-23 18:04:09 +02:00
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
rpcConsole->setClientModel(_clientModel);
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
if(walletFrame)
|
|
|
|
{
|
2016-09-09 13:43:29 +02:00
|
|
|
walletFrame->setClientModel(_clientModel);
|
2013-12-11 15:00:56 +01:00
|
|
|
}
|
2014-10-30 07:31:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2016-09-09 13:43:29 +02:00
|
|
|
unitDisplayControl->setOptionsModel(_clientModel->getOptionsModel());
|
2016-05-12 04:28:02 +02:00
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
OptionsModel* optionsModel = _clientModel->getOptionsModel();
|
2016-05-12 04:28:02 +02:00
|
|
|
if(optionsModel)
|
|
|
|
{
|
|
|
|
// be aware of the tray icon disable state change reported by the OptionsModel object.
|
|
|
|
connect(optionsModel,SIGNAL(hideTrayIconChanged(bool)),this,SLOT(setTrayIconVisible(bool)));
|
|
|
|
|
|
|
|
// initialize the disable state of the tray icon with the current value in the model.
|
|
|
|
setTrayIconVisible(optionsModel->getHideTrayIcon());
|
|
|
|
}
|
2014-08-07 09:37:21 +02:00
|
|
|
} else {
|
|
|
|
// Disable possibility to show main window via action
|
|
|
|
toggleHideAction->setEnabled(false);
|
2014-08-26 17:44:57 +02:00
|
|
|
if(trayIconMenu)
|
|
|
|
{
|
|
|
|
// Disable context menu on tray icon
|
|
|
|
trayIconMenu->clear();
|
|
|
|
}
|
2016-11-18 16:35:14 +01:00
|
|
|
// Propagate cleared model to child objects
|
|
|
|
rpcConsole->setClientModel(nullptr);
|
|
|
|
#ifdef ENABLE_WALLET
|
2017-02-21 14:36:36 +01:00
|
|
|
if (walletFrame)
|
|
|
|
{
|
|
|
|
walletFrame->setClientModel(nullptr);
|
|
|
|
}
|
2016-11-18 16:35:14 +01:00
|
|
|
#endif // ENABLE_WALLET
|
|
|
|
unitDisplayControl->setOptionsModel(nullptr);
|
2011-11-08 21:18:36 +01:00
|
|
|
}
|
2011-06-30 18:05:29 +02:00
|
|
|
}
|
|
|
|
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2013-03-22 18:32:49 +01:00
|
|
|
bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel)
|
2011-06-30 18:05:29 +02:00
|
|
|
{
|
2013-12-11 15:00:56 +01:00
|
|
|
if(!walletFrame)
|
|
|
|
return false;
|
2013-11-12 14:54:43 +01:00
|
|
|
setWalletActionsEnabled(true);
|
2016-09-09 12:43:54 +02:00
|
|
|
m_wallet_selector->addItem(name);
|
|
|
|
if (m_wallet_selector->count() == 2) {
|
|
|
|
m_wallet_selector->setVisible(true);
|
|
|
|
m_wallet_selector->setVisible(true);
|
|
|
|
}
|
2016-09-09 22:55:59 +02:00
|
|
|
rpcConsole->addWallet(name, walletModel);
|
2013-03-22 18:32:49 +01:00
|
|
|
return walletFrame->addWallet(name, walletModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BitcoinGUI::setCurrentWallet(const QString& name)
|
|
|
|
{
|
2013-12-11 15:00:56 +01:00
|
|
|
if(!walletFrame)
|
|
|
|
return false;
|
2013-03-22 18:32:49 +01:00
|
|
|
return walletFrame->setCurrentWallet(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::removeAllWallets()
|
|
|
|
{
|
2013-12-11 15:00:56 +01:00
|
|
|
if(!walletFrame)
|
|
|
|
return;
|
2013-11-12 14:54:43 +01:00
|
|
|
setWalletActionsEnabled(false);
|
2013-03-22 18:32:49 +01:00
|
|
|
walletFrame->removeAllWallets();
|
2011-05-22 17:19:43 +02:00
|
|
|
}
|
2014-10-30 07:31:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2011-05-22 17:19:43 +02:00
|
|
|
|
2013-11-12 14:54:43 +01:00
|
|
|
void BitcoinGUI::setWalletActionsEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
overviewAction->setEnabled(enabled);
|
|
|
|
sendCoinsAction->setEnabled(enabled);
|
2015-01-12 21:59:58 +01:00
|
|
|
sendCoinsMenuAction->setEnabled(enabled);
|
2013-11-12 14:54:43 +01:00
|
|
|
receiveCoinsAction->setEnabled(enabled);
|
2015-01-12 21:59:58 +01:00
|
|
|
receiveCoinsMenuAction->setEnabled(enabled);
|
2013-11-12 14:54:43 +01:00
|
|
|
historyAction->setEnabled(enabled);
|
|
|
|
encryptWalletAction->setEnabled(enabled);
|
|
|
|
backupWalletAction->setEnabled(enabled);
|
|
|
|
changePassphraseAction->setEnabled(enabled);
|
|
|
|
signMessageAction->setEnabled(enabled);
|
|
|
|
verifyMessageAction->setEnabled(enabled);
|
|
|
|
usedSendingAddressesAction->setEnabled(enabled);
|
|
|
|
usedReceivingAddressesAction->setEnabled(enabled);
|
|
|
|
openAction->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2014-10-09 11:04:49 +02:00
|
|
|
void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle)
|
2011-05-12 20:16:42 +02:00
|
|
|
{
|
2012-09-21 19:06:53 +02:00
|
|
|
#ifndef Q_OS_MAC
|
2011-05-12 20:16:42 +02:00
|
|
|
trayIcon = new QSystemTrayIcon(this);
|
2015-12-09 11:53:12 +01:00
|
|
|
QString toolTip = tr("%1 client").arg(tr(PACKAGE_NAME)) + " " + networkStyle->getTitleAddText();
|
2014-10-09 11:04:49 +02:00
|
|
|
trayIcon->setToolTip(toolTip);
|
2014-11-14 17:16:31 +01:00
|
|
|
trayIcon->setIcon(networkStyle->getTrayAndWindowIcon());
|
2016-05-12 04:28:02 +02:00
|
|
|
trayIcon->hide();
|
2012-11-27 22:20:43 +01:00
|
|
|
#endif
|
|
|
|
|
2013-12-03 09:25:24 +01:00
|
|
|
notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
|
2012-11-27 22:20:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::createTrayIconMenu()
|
|
|
|
{
|
|
|
|
#ifndef Q_OS_MAC
|
2013-03-19 23:33:36 +01:00
|
|
|
// return if trayIcon is unset (only on non-Mac OSes)
|
|
|
|
if (!trayIcon)
|
|
|
|
return;
|
|
|
|
|
2012-11-27 22:20:43 +01:00
|
|
|
trayIconMenu = new QMenu(this);
|
|
|
|
trayIcon->setContextMenu(trayIconMenu);
|
|
|
|
|
2011-06-05 14:19:57 +02:00
|
|
|
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
|
|
|
this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
|
2011-10-07 13:21:45 +02:00
|
|
|
#else
|
|
|
|
// Note: On Mac, the dock icon is used to provide the tray's functionality.
|
|
|
|
MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
|
2017-06-01 16:13:35 +02:00
|
|
|
dockIconHandler->setMainWindow(static_cast<QMainWindow*>(this));
|
2011-10-07 13:21:45 +02:00
|
|
|
trayIconMenu = dockIconHandler->dockMenu();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Configuration of the tray icon (or dock icon) icon menu
|
2012-02-17 15:34:53 +01:00
|
|
|
trayIconMenu->addAction(toggleHideAction);
|
2011-10-07 13:21:45 +02:00
|
|
|
trayIconMenu->addSeparator();
|
2015-01-12 21:59:58 +01:00
|
|
|
trayIconMenu->addAction(sendCoinsMenuAction);
|
|
|
|
trayIconMenu->addAction(receiveCoinsMenuAction);
|
2011-12-23 16:14:57 +01:00
|
|
|
trayIconMenu->addSeparator();
|
2012-06-15 09:48:26 +02:00
|
|
|
trayIconMenu->addAction(signMessageAction);
|
2012-06-14 07:57:10 +02:00
|
|
|
trayIconMenu->addAction(verifyMessageAction);
|
2011-10-07 13:21:45 +02:00
|
|
|
trayIconMenu->addSeparator();
|
|
|
|
trayIconMenu->addAction(optionsAction);
|
2012-06-14 07:57:10 +02:00
|
|
|
trayIconMenu->addAction(openRPCConsoleAction);
|
2012-09-21 19:06:53 +02:00
|
|
|
#ifndef Q_OS_MAC // This is built-in on Mac
|
2011-10-07 13:21:45 +02:00
|
|
|
trayIconMenu->addSeparator();
|
|
|
|
trayIconMenu->addAction(quitAction);
|
|
|
|
#endif
|
2011-05-12 20:16:42 +02:00
|
|
|
}
|
|
|
|
|
2012-09-21 19:06:53 +02:00
|
|
|
#ifndef Q_OS_MAC
|
2011-06-05 14:19:57 +02:00
|
|
|
void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
|
|
|
|
{
|
2011-08-08 17:38:17 +02:00
|
|
|
if(reason == QSystemTrayIcon::Trigger)
|
2011-06-05 14:19:57 +02:00
|
|
|
{
|
2012-07-21 13:01:02 +02:00
|
|
|
// Click on system tray icon triggers show/hide of the main window
|
2014-08-07 09:37:21 +02:00
|
|
|
toggleHidden();
|
2011-06-05 14:19:57 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-07 13:21:45 +02:00
|
|
|
#endif
|
2011-06-05 14:19:57 +02:00
|
|
|
|
2011-05-10 19:03:10 +02:00
|
|
|
void BitcoinGUI::optionsClicked()
|
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!clientModel || !clientModel->getOptionsModel())
|
|
|
|
return;
|
2013-11-14 19:47:45 +01:00
|
|
|
|
2014-11-08 19:48:35 +01:00
|
|
|
OptionsDialog dlg(this, enableWallet);
|
2011-06-30 18:05:29 +02:00
|
|
|
dlg.setModel(clientModel->getOptionsModel());
|
2011-05-12 09:40:40 +02:00
|
|
|
dlg.exec();
|
2011-05-10 19:03:10 +02:00
|
|
|
}
|
|
|
|
|
2011-05-12 09:40:40 +02:00
|
|
|
void BitcoinGUI::aboutClicked()
|
2011-05-10 19:03:10 +02:00
|
|
|
{
|
2013-11-14 19:47:45 +01:00
|
|
|
if(!clientModel)
|
|
|
|
return;
|
|
|
|
|
2014-06-11 21:44:47 +02:00
|
|
|
HelpMessageDialog dlg(this, true);
|
2011-05-12 09:40:40 +02:00
|
|
|
dlg.exec();
|
2011-05-10 19:03:10 +02:00
|
|
|
}
|
|
|
|
|
2015-09-07 11:00:59 +02:00
|
|
|
void BitcoinGUI::showDebugWindow()
|
|
|
|
{
|
|
|
|
rpcConsole->showNormal();
|
|
|
|
rpcConsole->show();
|
|
|
|
rpcConsole->raise();
|
|
|
|
rpcConsole->activateWindow();
|
|
|
|
}
|
|
|
|
|
2015-11-12 12:59:26 +01:00
|
|
|
void BitcoinGUI::showDebugWindowActivateConsole()
|
|
|
|
{
|
|
|
|
rpcConsole->setTabFocus(RPCConsole::TAB_CONSOLE);
|
|
|
|
showDebugWindow();
|
|
|
|
}
|
|
|
|
|
2014-01-22 14:47:33 +01:00
|
|
|
void BitcoinGUI::showHelpMessageClicked()
|
|
|
|
{
|
2015-08-27 21:53:16 +02:00
|
|
|
helpMessageDialog->show();
|
2014-01-22 14:47:33 +01:00
|
|
|
}
|
|
|
|
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2013-11-06 15:08:56 +01:00
|
|
|
void BitcoinGUI::openClicked()
|
|
|
|
{
|
2013-11-14 19:47:45 +01:00
|
|
|
OpenURIDialog dlg(this);
|
2013-11-06 15:08:56 +01:00
|
|
|
if(dlg.exec())
|
|
|
|
{
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT receivedURI(dlg.getURI());
|
2013-11-06 15:08:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 18:32:49 +01:00
|
|
|
void BitcoinGUI::gotoOverviewPage()
|
|
|
|
{
|
2013-10-18 18:43:07 +02:00
|
|
|
overviewAction->setChecked(true);
|
2013-03-22 18:32:49 +01:00
|
|
|
if (walletFrame) walletFrame->gotoOverviewPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::gotoHistoryPage()
|
|
|
|
{
|
2013-10-18 18:43:07 +02:00
|
|
|
historyAction->setChecked(true);
|
2013-03-22 18:32:49 +01:00
|
|
|
if (walletFrame) walletFrame->gotoHistoryPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::gotoReceiveCoinsPage()
|
|
|
|
{
|
2013-10-18 18:43:07 +02:00
|
|
|
receiveCoinsAction->setChecked(true);
|
2013-03-22 18:32:49 +01:00
|
|
|
if (walletFrame) walletFrame->gotoReceiveCoinsPage();
|
|
|
|
}
|
|
|
|
|
2013-04-01 14:43:50 +02:00
|
|
|
void BitcoinGUI::gotoSendCoinsPage(QString addr)
|
2013-03-22 18:32:49 +01:00
|
|
|
{
|
2013-10-18 18:43:07 +02:00
|
|
|
sendCoinsAction->setChecked(true);
|
2013-04-01 14:43:50 +02:00
|
|
|
if (walletFrame) walletFrame->gotoSendCoinsPage(addr);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::gotoSignMessageTab(QString addr)
|
|
|
|
{
|
|
|
|
if (walletFrame) walletFrame->gotoSignMessageTab(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::gotoVerifyMessageTab(QString addr)
|
|
|
|
{
|
2013-04-03 15:28:16 +02:00
|
|
|
if (walletFrame) walletFrame->gotoVerifyMessageTab(addr);
|
2013-03-22 18:32:49 +01:00
|
|
|
}
|
2014-10-30 07:31:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2013-03-22 18:32:49 +01:00
|
|
|
|
2013-03-26 03:07:06 +01:00
|
|
|
void BitcoinGUI::updateNetworkState()
|
2011-05-12 20:28:07 +02:00
|
|
|
{
|
2013-03-26 03:07:06 +01:00
|
|
|
int count = clientModel->getNumConnections();
|
2011-06-14 21:34:51 +02:00
|
|
|
QString icon;
|
|
|
|
switch(count)
|
|
|
|
{
|
2011-06-17 17:47:40 +02:00
|
|
|
case 0: icon = ":/icons/connect_0"; break;
|
|
|
|
case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
|
|
|
|
case 4: case 5: case 6: icon = ":/icons/connect_2"; break;
|
|
|
|
case 7: case 8: case 9: icon = ":/icons/connect_3"; break;
|
|
|
|
default: icon = ":/icons/connect_4"; break;
|
2011-06-14 21:34:51 +02:00
|
|
|
}
|
2013-03-26 03:07:06 +01:00
|
|
|
|
2016-11-11 11:59:33 +01:00
|
|
|
QString tooltip;
|
|
|
|
|
2013-03-26 03:07:06 +01:00
|
|
|
if (clientModel->getNetworkActive()) {
|
2016-11-11 11:59:33 +01:00
|
|
|
tooltip = tr("%n active connection(s) to Bitcoin network", "", count) + QString(".<br>") + tr("Click to disable network activity.");
|
2013-03-26 03:07:06 +01:00
|
|
|
} else {
|
2016-11-11 11:59:33 +01:00
|
|
|
tooltip = tr("Network activity disabled.") + QString("<br>") + tr("Click to enable network activity again.");
|
2014-11-19 13:33:34 +01:00
|
|
|
icon = ":/icons/network_disabled";
|
2013-03-26 03:07:06 +01:00
|
|
|
}
|
2014-11-19 13:33:34 +01:00
|
|
|
|
2016-11-11 11:59:33 +01:00
|
|
|
// Don't word-wrap this (fixed-width) tooltip
|
|
|
|
tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
|
|
|
|
connectionsControl->setToolTip(tooltip);
|
|
|
|
|
2014-11-19 13:33:34 +01:00
|
|
|
connectionsControl->setPixmap(platformStyle->SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
|
2013-03-26 03:07:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::setNumConnections(int count)
|
|
|
|
{
|
|
|
|
updateNetworkState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::setNetworkActive(bool networkActive)
|
|
|
|
{
|
|
|
|
updateNetworkState();
|
2011-05-12 20:28:07 +02:00
|
|
|
}
|
|
|
|
|
2017-01-03 15:09:57 +01:00
|
|
|
void BitcoinGUI::updateHeadersSyncProgressLabel()
|
|
|
|
{
|
|
|
|
int64_t headersTipTime = clientModel->getHeaderTipTime();
|
|
|
|
int headersTipHeight = clientModel->getHeaderTipHeight();
|
2017-01-19 20:51:59 +01:00
|
|
|
int estHeadersLeft = (GetTime() - headersTipTime) / Params().GetConsensus().nPowTargetSpacing;
|
|
|
|
if (estHeadersLeft > HEADER_HEIGHT_DELTA_SYNC)
|
2017-01-03 15:09:57 +01:00
|
|
|
progressBarLabel->setText(tr("Syncing Headers (%1%)...").arg(QString::number(100.0 / (headersTipHeight+estHeadersLeft)*headersTipHeight, 'f', 1)));
|
|
|
|
}
|
|
|
|
|
2016-04-28 16:18:45 +02:00
|
|
|
void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool header)
|
2011-05-12 20:28:07 +02:00
|
|
|
{
|
2016-07-19 15:51:24 +02:00
|
|
|
if (modalOverlay)
|
|
|
|
{
|
2016-10-20 18:56:03 +02:00
|
|
|
if (header)
|
|
|
|
modalOverlay->setKnownBestHeight(count, blockDate);
|
|
|
|
else
|
2016-07-19 15:51:24 +02:00
|
|
|
modalOverlay->tipUpdate(count, blockDate, nVerificationProgress);
|
|
|
|
}
|
|
|
|
if (!clientModel)
|
2014-09-22 14:41:54 +02:00
|
|
|
return;
|
|
|
|
|
2017-01-29 18:19:55 +01:00
|
|
|
// Prevent orphan statusbar messages (e.g. hover Quit in main menu, wait until chain-sync starts -> garbled text)
|
2012-10-12 16:08:47 +02:00
|
|
|
statusBar()->clearMessage();
|
|
|
|
|
2013-04-10 15:45:49 +02:00
|
|
|
// Acquire current block source
|
|
|
|
enum BlockSource blockSource = clientModel->getBlockSource();
|
|
|
|
switch (blockSource) {
|
|
|
|
case BLOCK_SOURCE_NETWORK:
|
2016-04-28 16:18:45 +02:00
|
|
|
if (header) {
|
2017-01-03 15:09:57 +01:00
|
|
|
updateHeadersSyncProgressLabel();
|
2016-04-28 16:18:45 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-04-10 15:45:49 +02:00
|
|
|
progressBarLabel->setText(tr("Synchronizing with network..."));
|
2017-01-03 15:09:57 +01:00
|
|
|
updateHeadersSyncProgressLabel();
|
2013-04-10 15:45:49 +02:00
|
|
|
break;
|
|
|
|
case BLOCK_SOURCE_DISK:
|
2016-04-28 16:18:45 +02:00
|
|
|
if (header) {
|
|
|
|
progressBarLabel->setText(tr("Indexing blocks on disk..."));
|
|
|
|
} else {
|
|
|
|
progressBarLabel->setText(tr("Processing blocks on disk..."));
|
|
|
|
}
|
2013-04-10 15:45:49 +02:00
|
|
|
break;
|
|
|
|
case BLOCK_SOURCE_REINDEX:
|
|
|
|
progressBarLabel->setText(tr("Reindexing blocks on disk..."));
|
|
|
|
break;
|
|
|
|
case BLOCK_SOURCE_NONE:
|
2016-04-28 16:18:45 +02:00
|
|
|
if (header) {
|
|
|
|
return;
|
|
|
|
}
|
2017-01-03 15:09:57 +01:00
|
|
|
progressBarLabel->setText(tr("Connecting to peers..."));
|
2013-04-10 15:45:49 +02:00
|
|
|
break;
|
2012-04-02 10:18:51 +02:00
|
|
|
}
|
|
|
|
|
2011-07-17 14:06:43 +02:00
|
|
|
QString tooltip;
|
|
|
|
|
2013-02-10 19:01:30 +01:00
|
|
|
QDateTime currentDate = QDateTime::currentDateTime();
|
2015-02-09 11:19:01 +01:00
|
|
|
qint64 secs = blockDate.secsTo(currentDate);
|
2011-07-08 18:05:10 +02:00
|
|
|
|
2015-05-04 12:25:22 +02:00
|
|
|
tooltip = tr("Processed %n block(s) of transaction history.", "", count);
|
2011-07-18 06:55:05 +02:00
|
|
|
|
2011-08-08 17:38:17 +02:00
|
|
|
// Set icon state: spinning if catching up, tick otherwise
|
2014-05-05 19:43:14 +02:00
|
|
|
if(secs < 90*60)
|
2011-07-18 06:55:05 +02:00
|
|
|
{
|
2012-04-13 17:10:50 +02:00
|
|
|
tooltip = tr("Up to date") + QString(".<br>") + tooltip;
|
2015-07-28 15:20:14 +02:00
|
|
|
labelBlocksIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
|
2012-05-15 16:57:59 +02:00
|
|
|
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
if(walletFrame)
|
2016-07-19 15:51:24 +02:00
|
|
|
{
|
2013-12-11 15:00:56 +01:00
|
|
|
walletFrame->showOutOfSyncWarning(false);
|
2016-07-19 15:51:24 +02:00
|
|
|
modalOverlay->showHide(true, true);
|
|
|
|
}
|
2014-10-30 07:31:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2013-02-10 19:01:30 +01:00
|
|
|
|
|
|
|
progressBarLabel->setVisible(false);
|
|
|
|
progressBar->setVisible(false);
|
2011-07-18 06:55:05 +02:00
|
|
|
}
|
2011-08-04 19:04:42 +02:00
|
|
|
else
|
|
|
|
{
|
2017-01-12 16:47:51 +01:00
|
|
|
QString timeBehindText = GUIUtil::formatNiceTimeOffset(secs);
|
2013-02-10 19:01:30 +01:00
|
|
|
|
|
|
|
progressBarLabel->setVisible(true);
|
|
|
|
progressBar->setFormat(tr("%1 behind").arg(timeBehindText));
|
2013-02-10 19:46:42 +01:00
|
|
|
progressBar->setMaximum(1000000000);
|
2015-11-27 18:22:18 +01:00
|
|
|
progressBar->setValue(nVerificationProgress * 1000000000.0 + 0.5);
|
2013-02-10 19:01:30 +01:00
|
|
|
progressBar->setVisible(true);
|
|
|
|
|
2012-04-13 17:10:50 +02:00
|
|
|
tooltip = tr("Catching up...") + QString("<br>") + tooltip;
|
2013-02-10 19:01:30 +01:00
|
|
|
if(count != prevBlocks)
|
2014-01-13 14:16:48 +01:00
|
|
|
{
|
2015-07-28 15:20:14 +02:00
|
|
|
labelBlocksIcon->setPixmap(platformStyle->SingleColorIcon(QString(
|
2014-01-13 14:16:48 +01:00
|
|
|
":/movies/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0')))
|
|
|
|
.pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
|
|
|
|
spinnerFrame = (spinnerFrame + 1) % SPINNER_FRAMES;
|
|
|
|
}
|
2013-02-10 19:01:30 +01:00
|
|
|
prevBlocks = count;
|
2012-05-15 16:57:59 +02:00
|
|
|
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
if(walletFrame)
|
2016-07-19 15:51:24 +02:00
|
|
|
{
|
2013-12-11 15:00:56 +01:00
|
|
|
walletFrame->showOutOfSyncWarning(true);
|
2016-07-19 15:51:24 +02:00
|
|
|
modalOverlay->showHide();
|
|
|
|
}
|
2014-10-30 07:31:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2011-07-18 06:55:05 +02:00
|
|
|
|
2012-04-13 17:10:50 +02:00
|
|
|
tooltip += QString("<br>");
|
2013-02-10 19:01:30 +01:00
|
|
|
tooltip += tr("Last received block was generated %1 ago.").arg(timeBehindText);
|
|
|
|
tooltip += QString("<br>");
|
|
|
|
tooltip += tr("Transactions after this will not yet be visible.");
|
2012-02-25 19:07:53 +01:00
|
|
|
}
|
2011-07-17 17:30:58 +02:00
|
|
|
|
2012-04-13 17:10:50 +02:00
|
|
|
// Don't word-wrap this (fixed-width) tooltip
|
|
|
|
tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
|
|
|
|
|
2011-07-17 17:30:58 +02:00
|
|
|
labelBlocksIcon->setToolTip(tooltip);
|
2011-07-17 14:06:43 +02:00
|
|
|
progressBarLabel->setToolTip(tooltip);
|
|
|
|
progressBar->setToolTip(tooltip);
|
2011-05-12 20:28:07 +02:00
|
|
|
}
|
|
|
|
|
2013-02-16 17:58:45 +01:00
|
|
|
void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, bool *ret)
|
2011-05-30 20:20:12 +02:00
|
|
|
{
|
2013-04-09 09:54:19 +02:00
|
|
|
QString strTitle = tr("Bitcoin"); // default title
|
2012-11-05 08:04:21 +01:00
|
|
|
// Default to information icon
|
|
|
|
int nMBoxIcon = QMessageBox::Information;
|
|
|
|
int nNotifyIcon = Notificator::Information;
|
|
|
|
|
2013-04-09 09:54:19 +02:00
|
|
|
QString msgType;
|
2013-09-14 11:44:12 +02:00
|
|
|
|
|
|
|
// Prefer supplied title over style based title
|
|
|
|
if (!title.isEmpty()) {
|
|
|
|
msgType = title;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (style) {
|
|
|
|
case CClientUIInterface::MSG_ERROR:
|
|
|
|
msgType = tr("Error");
|
|
|
|
break;
|
|
|
|
case CClientUIInterface::MSG_WARNING:
|
|
|
|
msgType = tr("Warning");
|
|
|
|
break;
|
|
|
|
case CClientUIInterface::MSG_INFORMATION:
|
|
|
|
msgType = tr("Information");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-11-05 08:04:21 +01:00
|
|
|
}
|
2013-09-14 11:44:12 +02:00
|
|
|
// Append title to "Bitcoin - "
|
2013-04-09 09:54:19 +02:00
|
|
|
if (!msgType.isEmpty())
|
|
|
|
strTitle += " - " + msgType;
|
2012-11-05 08:04:21 +01:00
|
|
|
|
|
|
|
// Check for error/warning icon
|
|
|
|
if (style & CClientUIInterface::ICON_ERROR) {
|
|
|
|
nMBoxIcon = QMessageBox::Critical;
|
|
|
|
nNotifyIcon = Notificator::Critical;
|
2012-03-25 20:47:33 +02:00
|
|
|
}
|
2012-11-05 08:04:21 +01:00
|
|
|
else if (style & CClientUIInterface::ICON_WARNING) {
|
|
|
|
nMBoxIcon = QMessageBox::Warning;
|
|
|
|
nNotifyIcon = Notificator::Warning;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display message
|
2012-12-03 13:24:42 +01:00
|
|
|
if (style & CClientUIInterface::MODAL) {
|
2012-11-05 08:04:21 +01:00
|
|
|
// Check for buttons, use OK as default, if none was supplied
|
|
|
|
QMessageBox::StandardButton buttons;
|
|
|
|
if (!(buttons = (QMessageBox::StandardButton)(style & CClientUIInterface::BTN_MASK)))
|
|
|
|
buttons = QMessageBox::Ok;
|
|
|
|
|
2014-07-14 10:46:06 +02:00
|
|
|
showNormalIfMinimized();
|
2017-06-01 16:13:35 +02:00
|
|
|
QMessageBox mBox(static_cast<QMessageBox::Icon>(nMBoxIcon), strTitle, message, buttons, this);
|
2013-02-16 17:58:45 +01:00
|
|
|
int r = mBox.exec();
|
2017-08-07 07:36:37 +02:00
|
|
|
if (ret != nullptr)
|
2013-02-16 17:58:45 +01:00
|
|
|
*ret = r == QMessageBox::Ok;
|
2012-11-05 08:04:21 +01:00
|
|
|
}
|
|
|
|
else
|
2017-06-01 16:13:35 +02:00
|
|
|
notificator->notify(static_cast<Notificator::Class>(nNotifyIcon), strTitle, message);
|
2011-05-30 20:20:12 +02:00
|
|
|
}
|
2011-06-05 14:19:57 +02:00
|
|
|
|
|
|
|
void BitcoinGUI::changeEvent(QEvent *e)
|
|
|
|
{
|
2012-03-15 22:30:08 +01:00
|
|
|
QMainWindow::changeEvent(e);
|
2012-09-21 19:06:53 +02:00
|
|
|
#ifndef Q_OS_MAC // Ignored on Mac
|
2011-11-13 08:45:29 +01:00
|
|
|
if(e->type() == QEvent::WindowStateChange)
|
2011-06-05 14:19:57 +02:00
|
|
|
{
|
2014-09-22 14:41:54 +02:00
|
|
|
if(clientModel && clientModel->getOptionsModel() && clientModel->getOptionsModel()->getMinimizeToTray())
|
2011-06-05 14:19:57 +02:00
|
|
|
{
|
2012-02-17 13:50:32 +01:00
|
|
|
QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
|
2012-03-15 22:30:08 +01:00
|
|
|
if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
|
2011-06-07 18:59:01 +02:00
|
|
|
{
|
2012-03-15 22:30:08 +01:00
|
|
|
QTimer::singleShot(0, this, SLOT(hide()));
|
|
|
|
e->ignore();
|
2011-06-05 14:19:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-07 13:21:45 +02:00
|
|
|
#endif
|
2011-06-05 14:19:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2012-09-21 19:06:53 +02:00
|
|
|
#ifndef Q_OS_MAC // Ignored on Mac
|
2014-09-22 14:41:54 +02:00
|
|
|
if(clientModel && clientModel->getOptionsModel())
|
|
|
|
{
|
2016-08-07 08:58:30 +02:00
|
|
|
if(!clientModel->getOptionsModel()->getMinimizeOnClose())
|
2011-11-08 21:18:36 +01:00
|
|
|
{
|
2014-11-10 16:41:57 +01:00
|
|
|
// close rpcConsole in case it was open to make some space for the shutdown window
|
|
|
|
rpcConsole->close();
|
|
|
|
|
2013-04-02 17:30:14 +02:00
|
|
|
QApplication::quit();
|
2011-11-08 21:18:36 +01:00
|
|
|
}
|
2016-08-07 08:58:30 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
QMainWindow::showMinimized();
|
|
|
|
event->ignore();
|
|
|
|
}
|
2011-11-08 21:18:36 +01:00
|
|
|
}
|
2016-08-07 08:58:30 +02:00
|
|
|
#else
|
2011-06-05 14:19:57 +02:00
|
|
|
QMainWindow::closeEvent(event);
|
2016-08-07 08:58:30 +02:00
|
|
|
#endif
|
2011-06-05 14:19:57 +02:00
|
|
|
}
|
2011-06-05 17:36:52 +02:00
|
|
|
|
2016-05-11 21:08:36 +02:00
|
|
|
void BitcoinGUI::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
// enable the debug window when the main window shows up
|
|
|
|
openRPCConsoleAction->setEnabled(true);
|
|
|
|
aboutAction->setEnabled(true);
|
|
|
|
optionsAction->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2015-02-26 21:57:08 +01:00
|
|
|
void BitcoinGUI::incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label)
|
2011-06-10 21:59:29 +02:00
|
|
|
{
|
2013-04-01 14:43:50 +02:00
|
|
|
// On new transaction, make an info balloon
|
2015-02-26 21:57:08 +01:00
|
|
|
QString msg = tr("Date: %1\n").arg(date) +
|
|
|
|
tr("Amount: %1\n").arg(BitcoinUnits::formatWithUnit(unit, amount, true)) +
|
|
|
|
tr("Type: %1\n").arg(type);
|
|
|
|
if (!label.isEmpty())
|
|
|
|
msg += tr("Label: %1\n").arg(label);
|
|
|
|
else if (!address.isEmpty())
|
|
|
|
msg += tr("Address: %1\n").arg(address);
|
2012-11-27 22:02:50 +01:00
|
|
|
message((amount)<0 ? tr("Sent transaction") : tr("Incoming transaction"),
|
2015-02-26 21:57:08 +01:00
|
|
|
msg, CClientUIInterface::MSG_INFORMATION);
|
2011-06-10 21:59:29 +02:00
|
|
|
}
|
2014-10-30 07:31:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2011-07-05 22:09:39 +02:00
|
|
|
|
2011-08-07 16:04:48 +02:00
|
|
|
void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
|
|
|
|
{
|
2012-03-25 23:25:10 +02:00
|
|
|
// Accept only URIs
|
2011-08-07 16:04:48 +02:00
|
|
|
if(event->mimeData()->hasUrls())
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::dropEvent(QDropEvent *event)
|
|
|
|
{
|
|
|
|
if(event->mimeData()->hasUrls())
|
|
|
|
{
|
2017-06-02 03:25:02 +02:00
|
|
|
for (const QUrl &uri : event->mimeData()->urls())
|
2011-08-07 16:04:48 +02:00
|
|
|
{
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT receivedURI(uri.toString());
|
2011-08-07 16:04:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
2012-10-12 16:08:47 +02:00
|
|
|
bool BitcoinGUI::eventFilter(QObject *object, QEvent *event)
|
|
|
|
{
|
|
|
|
// Catch status tip events
|
|
|
|
if (event->type() == QEvent::StatusTip)
|
|
|
|
{
|
|
|
|
// Prevent adding text from setStatusTip(), if we currently use the status bar for displaying other stuff
|
2013-04-06 12:20:02 +02:00
|
|
|
if (progressBarLabel->isVisible() || progressBar->isVisible())
|
2012-10-12 16:08:47 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return QMainWindow::eventFilter(object, event);
|
|
|
|
}
|
|
|
|
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2013-10-24 15:49:13 +02:00
|
|
|
bool BitcoinGUI::handlePaymentRequest(const SendCoinsRecipient& recipient)
|
2011-12-24 05:27:12 +01:00
|
|
|
{
|
2013-10-24 15:49:13 +02:00
|
|
|
// URI has to be valid
|
2013-12-11 15:00:56 +01:00
|
|
|
if (walletFrame && walletFrame->handlePaymentRequest(recipient))
|
2013-10-24 15:49:13 +02:00
|
|
|
{
|
|
|
|
showNormalIfMinimized();
|
|
|
|
gotoSendCoinsPage();
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-22 14:41:54 +02:00
|
|
|
return false;
|
2013-07-22 08:50:39 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 14:09:47 +02:00
|
|
|
void BitcoinGUI::setHDStatus(int hdEnabled)
|
|
|
|
{
|
|
|
|
labelWalletHDStatusIcon->setPixmap(platformStyle->SingleColorIcon(hdEnabled ? ":/icons/hd_enabled" : ":/icons/hd_disabled").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
|
|
|
|
labelWalletHDStatusIcon->setToolTip(hdEnabled ? tr("HD key generation is <b>enabled</b>") : tr("HD key generation is <b>disabled</b>"));
|
|
|
|
|
|
|
|
// eventually disable the QLabel to set its opacity to 50%
|
|
|
|
labelWalletHDStatusIcon->setEnabled(hdEnabled);
|
|
|
|
}
|
|
|
|
|
2011-08-23 20:08:42 +02:00
|
|
|
void BitcoinGUI::setEncryptionStatus(int status)
|
|
|
|
{
|
|
|
|
switch(status)
|
|
|
|
{
|
|
|
|
case WalletModel::Unencrypted:
|
2016-08-17 14:09:47 +02:00
|
|
|
labelWalletEncryptionIcon->hide();
|
2011-08-24 22:07:26 +02:00
|
|
|
encryptWalletAction->setChecked(false);
|
|
|
|
changePassphraseAction->setEnabled(false);
|
|
|
|
encryptWalletAction->setEnabled(true);
|
2011-08-23 20:08:42 +02:00
|
|
|
break;
|
|
|
|
case WalletModel::Unlocked:
|
2016-08-17 14:09:47 +02:00
|
|
|
labelWalletEncryptionIcon->show();
|
|
|
|
labelWalletEncryptionIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
|
|
|
|
labelWalletEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
|
2011-08-24 22:07:26 +02:00
|
|
|
encryptWalletAction->setChecked(true);
|
|
|
|
changePassphraseAction->setEnabled(true);
|
|
|
|
encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
|
2011-08-23 20:08:42 +02:00
|
|
|
break;
|
|
|
|
case WalletModel::Locked:
|
2016-08-17 14:09:47 +02:00
|
|
|
labelWalletEncryptionIcon->show();
|
|
|
|
labelWalletEncryptionIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
|
|
|
|
labelWalletEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
|
2011-08-24 22:07:26 +02:00
|
|
|
encryptWalletAction->setChecked(true);
|
|
|
|
changePassphraseAction->setEnabled(true);
|
|
|
|
encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
|
2011-08-23 20:08:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-10-24 09:21:51 +02:00
|
|
|
|
|
|
|
void BitcoinGUI::updateWalletStatus()
|
|
|
|
{
|
|
|
|
if (!walletFrame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WalletView * const walletView = walletFrame->currentWalletView();
|
|
|
|
if (!walletView) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WalletModel * const walletModel = walletView->getWalletModel();
|
|
|
|
setEncryptionStatus(walletModel->getEncryptionStatus());
|
|
|
|
setHDStatus(walletModel->hdEnabled());
|
|
|
|
}
|
2014-10-30 07:31:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2011-08-24 22:07:26 +02:00
|
|
|
|
2012-06-05 07:23:26 +02:00
|
|
|
void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
|
2012-02-17 23:19:52 +01:00
|
|
|
{
|
2014-07-14 10:46:06 +02:00
|
|
|
if(!clientModel)
|
|
|
|
return;
|
2014-08-07 09:37:21 +02:00
|
|
|
|
2012-06-05 07:23:26 +02:00
|
|
|
// activateWindow() (sometimes) helps with keyboard focus on Windows
|
|
|
|
if (isHidden())
|
|
|
|
{
|
2012-02-17 23:19:52 +01:00
|
|
|
show();
|
2012-06-05 07:23:26 +02:00
|
|
|
activateWindow();
|
|
|
|
}
|
|
|
|
else if (isMinimized())
|
|
|
|
{
|
2012-02-17 23:19:52 +01:00
|
|
|
showNormal();
|
2012-06-05 07:23:26 +02:00
|
|
|
activateWindow();
|
|
|
|
}
|
|
|
|
else if (GUIUtil::isObscured(this))
|
|
|
|
{
|
|
|
|
raise();
|
|
|
|
activateWindow();
|
|
|
|
}
|
|
|
|
else if(fToggleHidden)
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::toggleHidden()
|
|
|
|
{
|
|
|
|
showNormalIfMinimized(true);
|
2012-02-17 23:19:52 +01:00
|
|
|
}
|
2013-03-23 23:14:12 +01:00
|
|
|
|
|
|
|
void BitcoinGUI::detectShutdown()
|
|
|
|
{
|
|
|
|
if (ShutdownRequested())
|
2014-01-08 10:45:00 +01:00
|
|
|
{
|
|
|
|
if(rpcConsole)
|
|
|
|
rpcConsole->hide();
|
|
|
|
qApp->quit();
|
|
|
|
}
|
2013-03-23 23:14:12 +01:00
|
|
|
}
|
2014-01-08 08:59:24 +01:00
|
|
|
|
2014-05-23 18:04:09 +02:00
|
|
|
void BitcoinGUI::showProgress(const QString &title, int nProgress)
|
|
|
|
{
|
|
|
|
if (nProgress == 0)
|
|
|
|
{
|
|
|
|
progressDialog = new QProgressDialog(title, "", 0, 100);
|
|
|
|
progressDialog->setWindowModality(Qt::ApplicationModal);
|
|
|
|
progressDialog->setMinimumDuration(0);
|
|
|
|
progressDialog->setCancelButton(0);
|
|
|
|
progressDialog->setAutoClose(false);
|
|
|
|
progressDialog->setValue(0);
|
|
|
|
}
|
|
|
|
else if (nProgress == 100)
|
|
|
|
{
|
|
|
|
if (progressDialog)
|
|
|
|
{
|
|
|
|
progressDialog->close();
|
|
|
|
progressDialog->deleteLater();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (progressDialog)
|
|
|
|
progressDialog->setValue(nProgress);
|
|
|
|
}
|
|
|
|
|
2016-05-12 04:28:02 +02:00
|
|
|
void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)
|
|
|
|
{
|
|
|
|
if (trayIcon)
|
|
|
|
{
|
|
|
|
trayIcon->setVisible(!fHideTrayIcon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 15:51:24 +02:00
|
|
|
void BitcoinGUI::showModalOverlay()
|
|
|
|
{
|
2016-12-05 09:26:43 +01:00
|
|
|
if (modalOverlay && (progressBar->isVisible() || modalOverlay->isLayerVisible()))
|
|
|
|
modalOverlay->toggleVisibility();
|
2016-07-19 15:51:24 +02:00
|
|
|
}
|
|
|
|
|
2014-01-08 08:59:24 +01:00
|
|
|
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style)
|
|
|
|
{
|
|
|
|
bool modal = (style & CClientUIInterface::MODAL);
|
2014-10-17 01:16:29 +02:00
|
|
|
// The SECURE flag has no effect in the Qt GUI.
|
|
|
|
// bool secure = (style & CClientUIInterface::SECURE);
|
|
|
|
style &= ~CClientUIInterface::SECURE;
|
2014-01-08 08:59:24 +01:00
|
|
|
bool ret = false;
|
|
|
|
// In case of modal message, use blocking connection to wait for user to click a button
|
|
|
|
QMetaObject::invokeMethod(gui, "message",
|
|
|
|
modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection,
|
|
|
|
Q_ARG(QString, QString::fromStdString(caption)),
|
|
|
|
Q_ARG(QString, QString::fromStdString(message)),
|
|
|
|
Q_ARG(unsigned int, style),
|
|
|
|
Q_ARG(bool*, &ret));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::subscribeToCoreSignals()
|
|
|
|
{
|
|
|
|
// Connect signals to client
|
|
|
|
uiInterface.ThreadSafeMessageBox.connect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
|
2016-06-24 16:35:21 +02:00
|
|
|
uiInterface.ThreadSafeQuestion.connect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4));
|
2014-01-08 08:59:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BitcoinGUI::unsubscribeFromCoreSignals()
|
|
|
|
{
|
|
|
|
// Disconnect signals from client
|
|
|
|
uiInterface.ThreadSafeMessageBox.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
|
2016-06-24 16:35:21 +02:00
|
|
|
uiInterface.ThreadSafeQuestion.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4));
|
2014-01-08 08:59:24 +01:00
|
|
|
}
|
2014-06-07 08:20:22 +02:00
|
|
|
|
2016-11-24 14:26:20 +01:00
|
|
|
void BitcoinGUI::toggleNetworkActive()
|
|
|
|
{
|
|
|
|
if (clientModel) {
|
|
|
|
clientModel->setNetworkActive(!clientModel->getNetworkActive());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle) :
|
2014-08-07 09:34:31 +02:00
|
|
|
optionsModel(0),
|
|
|
|
menu(0)
|
2014-06-07 08:20:22 +02:00
|
|
|
{
|
|
|
|
createContextMenu();
|
|
|
|
setToolTip(tr("Unit to show amounts in. Click to select another unit."));
|
2014-12-27 20:19:51 +01:00
|
|
|
QList<BitcoinUnits::Unit> units = BitcoinUnits::availableUnits();
|
|
|
|
int max_width = 0;
|
|
|
|
const QFontMetrics fm(font());
|
2017-06-02 03:25:02 +02:00
|
|
|
for (const BitcoinUnits::Unit unit : units)
|
2014-12-27 20:19:51 +01:00
|
|
|
{
|
2017-12-27 17:01:45 +01:00
|
|
|
max_width = qMax(max_width, fm.width(BitcoinUnits::longName(unit)));
|
2014-12-27 20:19:51 +01:00
|
|
|
}
|
|
|
|
setMinimumSize(max_width, 0);
|
|
|
|
setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
2015-07-28 15:20:14 +02:00
|
|
|
setStyleSheet(QString("QLabel { color : %1 }").arg(platformStyle->SingleColor().name()));
|
2014-06-07 08:20:22 +02:00
|
|
|
}
|
|
|
|
|
2014-07-13 08:14:29 +02:00
|
|
|
/** So that it responds to button clicks */
|
2014-06-07 08:20:22 +02:00
|
|
|
void UnitDisplayStatusBarControl::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
onDisplayUnitsClicked(event->pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Creates context menu, its actions, and wires up all the relevant signals for mouse events. */
|
|
|
|
void UnitDisplayStatusBarControl::createContextMenu()
|
|
|
|
{
|
2016-11-18 15:47:20 +01:00
|
|
|
menu = new QMenu(this);
|
2017-06-02 03:25:02 +02:00
|
|
|
for (BitcoinUnits::Unit u : BitcoinUnits::availableUnits())
|
2014-06-07 08:20:22 +02:00
|
|
|
{
|
2017-12-27 17:01:45 +01:00
|
|
|
QAction *menuAction = new QAction(QString(BitcoinUnits::longName(u)), this);
|
2014-06-07 08:20:22 +02:00
|
|
|
menuAction->setData(QVariant(u));
|
|
|
|
menu->addAction(menuAction);
|
|
|
|
}
|
|
|
|
connect(menu,SIGNAL(triggered(QAction*)),this,SLOT(onMenuSelection(QAction*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Lets the control know about the Options Model (and its signals) */
|
2016-09-09 13:43:29 +02:00
|
|
|
void UnitDisplayStatusBarControl::setOptionsModel(OptionsModel *_optionsModel)
|
2014-06-07 08:20:22 +02:00
|
|
|
{
|
2016-09-09 13:43:29 +02:00
|
|
|
if (_optionsModel)
|
2014-06-07 08:20:22 +02:00
|
|
|
{
|
2016-09-09 13:43:29 +02:00
|
|
|
this->optionsModel = _optionsModel;
|
2014-06-07 08:20:22 +02:00
|
|
|
|
|
|
|
// be aware of a display unit change reported by the OptionsModel object.
|
2016-09-09 13:43:29 +02:00
|
|
|
connect(_optionsModel,SIGNAL(displayUnitChanged(int)),this,SLOT(updateDisplayUnit(int)));
|
2014-06-07 08:20:22 +02:00
|
|
|
|
|
|
|
// initialize the display units label with the current value in the model.
|
2016-09-09 13:43:29 +02:00
|
|
|
updateDisplayUnit(_optionsModel->getDisplayUnit());
|
2014-06-07 08:20:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** When Display Units are changed on OptionsModel it will refresh the display text of the control on the status bar */
|
|
|
|
void UnitDisplayStatusBarControl::updateDisplayUnit(int newUnits)
|
|
|
|
{
|
2017-12-27 17:01:45 +01:00
|
|
|
setText(BitcoinUnits::longName(newUnits));
|
2014-06-07 08:20:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Shows context menu with Display Unit options by the mouse coordinates */
|
|
|
|
void UnitDisplayStatusBarControl::onDisplayUnitsClicked(const QPoint& point)
|
|
|
|
{
|
|
|
|
QPoint globalPos = mapToGlobal(point);
|
|
|
|
menu->exec(globalPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Tells underlying optionsModel to update its current display unit. */
|
|
|
|
void UnitDisplayStatusBarControl::onMenuSelection(QAction* action)
|
|
|
|
{
|
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
optionsModel->setDisplayUnit(action->data());
|
|
|
|
}
|
|
|
|
}
|