31 #include <QApplication>
33 #include <QDesktopWidget>
34 #include <QDragEnterEvent>
37 #include <QListWidget>
40 #include <QMessageBox>
42 #include <QProgressBar>
44 #include <QStackedWidget>
49 #include <QVBoxLayout>
51 #if QT_VERSION < 0x050000
53 #include <QTextDocument>
64 encryptWalletAction(0),
65 changePassphraseAction(0),
75 QString windowTitle = tr(
"Master Core") +
" - ";
78 bool enableWallet = !
GetBoolArg(
"-disablewallet",
false);
80 bool enableWallet =
false;
84 windowTitle += tr(
"Wallet");
86 windowTitle += tr(
"Node");
92 QApplication::setWindowIcon(QIcon(
":icons/bitcoin"));
93 setWindowIcon(QIcon(
":icons/bitcoin"));
100 windowTitle +=
" " + tr(
"[testnet]");
102 QApplication::setWindowIcon(QIcon(
":icons/bitcoin_testnet"));
103 setWindowIcon(QIcon(
":icons/bitcoin_testnet"));
108 setWindowTitle(windowTitle);
110 #if defined(Q_OS_MAC) && QT_VERSION < 0x050000
113 setUnifiedTitleAndToolBarOnMac(
true);
133 setAcceptDrops(
true);
153 frameBlocks->setContentsMargins(0,0,0,0);
154 frameBlocks->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
155 QHBoxLayout *frameBlocksLayout =
new QHBoxLayout(frameBlocks);
156 frameBlocksLayout->setContentsMargins(3,0,3,0);
157 frameBlocksLayout->setSpacing(3);
161 frameBlocksLayout->addStretch();
163 frameBlocksLayout->addStretch();
165 frameBlocksLayout->addStretch();
167 frameBlocksLayout->addStretch();
179 QString curStyle = QApplication::style()->metaObject()->className();
180 if(curStyle ==
"QWindowsStyle" || curStyle ==
"QWindowsXPStyle")
182 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; }");
187 statusBar()->addPermanentWidget(frameBlocks);
195 this->installEventFilter(
this);
220 QActionGroup *tabGroup =
new QActionGroup(
this);
222 overviewAction =
new QAction(QIcon(
":/icons/overview"), tr(
"&Overview"),
this);
223 overviewAction->setStatusTip(tr(
"Show general overview of wallet"));
229 balancesAction =
new QAction(QIcon(
":/icons/balances"), tr(
"&Balances"),
this);
230 balancesAction->setStatusTip(tr(
"Show Master Protocol balances"));
236 sendCoinsAction =
new QAction(QIcon(
":/icons/send"), tr(
"&Send"),
this);
243 receiveCoinsAction =
new QAction(QIcon(
":/icons/receiving_addresses"), tr(
"&Receive"),
this);
244 receiveCoinsAction->setStatusTip(tr(
"Request payments (generates QR codes and bitcoin: URIs)"));
250 historyAction =
new QAction(QIcon(
":/icons/history"), tr(
"&Transactions"),
this);
251 historyAction->setStatusTip(tr(
"Browse transaction history"));
254 historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
260 connect(
overviewAction, SIGNAL(triggered()),
this, SLOT(gotoOverviewPage()));
262 connect(
balancesAction, SIGNAL(triggered()),
this, SLOT(gotoBalancesPage()));
264 connect(
sendCoinsAction, SIGNAL(triggered()),
this, SLOT(gotoSendCoinsPage()));
268 connect(
historyAction, SIGNAL(triggered()),
this, SLOT(gotoHistoryPage()));
270 quitAction =
new QAction(QIcon(
":/icons/quit"), tr(
"E&xit"),
this);
271 quitAction->setStatusTip(tr(
"Quit application"));
272 quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
275 aboutAction =
new QAction(QIcon(
":/icons/bitcoin"), tr(
"&About Master Core"),
this);
277 aboutAction =
new QAction(QIcon(
":/icons/bitcoin_testnet"), tr(
"&About Master Core"),
this);
278 aboutAction->setStatusTip(tr(
"Show information about Master Core"));
280 #if QT_VERSION < 0x050000
281 aboutQtAction =
new QAction(QIcon(
":/trolltech/qmessagebox/images/qtlogo-64.png"), tr(
"About &Qt"),
this);
283 aboutQtAction =
new QAction(QIcon(
":/qt-project.org/qmessagebox/images/qtlogo-64.png"), tr(
"About &Qt"),
this);
285 aboutQtAction->setStatusTip(tr(
"Show information about Qt"));
287 optionsAction =
new QAction(QIcon(
":/icons/options"), tr(
"&Options..."),
this);
288 optionsAction->setStatusTip(tr(
"Modify configuration options for Bitcoin"));
291 toggleHideAction =
new QAction(QIcon(
":/icons/bitcoin"), tr(
"&Show / Hide"),
this);
293 toggleHideAction =
new QAction(QIcon(
":/icons/bitcoin_testnet"), tr(
"&Show / Hide"),
this);
296 encryptWalletAction =
new QAction(QIcon(
":/icons/lock_closed"), tr(
"&Encrypt Wallet..."),
this);
297 encryptWalletAction->setStatusTip(tr(
"Encrypt the private keys that belong to your wallet"));
299 backupWalletAction =
new QAction(QIcon(
":/icons/filesave"), tr(
"&Backup Wallet..."),
this);
303 signMessageAction =
new QAction(QIcon(
":/icons/edit"), tr(
"Sign &message..."),
this);
304 signMessageAction->setStatusTip(tr(
"Sign messages with your Bitcoin addresses to prove you own them"));
305 verifyMessageAction =
new QAction(QIcon(
":/icons/transaction_0"), tr(
"&Verify message..."),
this);
306 verifyMessageAction->setStatusTip(tr(
"Verify messages to ensure they were signed with specified Bitcoin addresses"));
316 openAction =
new QAction(QApplication::style()->standardIcon(QStyle::SP_FileIcon), tr(
"Open &URI..."),
this);
317 openAction->setStatusTip(tr(
"Open a bitcoin: URI or payment request"));
319 showHelpMessageAction =
new QAction(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation), tr(
"&Command-line options"),
this);
320 showHelpMessageAction->setStatusTip(tr(
"Show the Bitcoin Core help message to get a list with possible Bitcoin command-line options"));
322 connect(
quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
324 connect(
aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
334 connect(
signMessageAction, SIGNAL(triggered()),
this, SLOT(gotoSignMessageTab()));
338 connect(
openAction, SIGNAL(triggered()),
this, SLOT(openClicked()));
354 QMenu *file =
appMenuBar->addMenu(tr(
"&File"));
361 file->addSeparator();
364 file->addSeparator();
368 QMenu *settings =
appMenuBar->addMenu(tr(
"&Settings"));
373 settings->addSeparator();
383 help->addSeparator();
392 QToolBar *toolbar = addToolBar(tr(
"Tabs toolbar"));
393 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
414 connect(clientModel, SIGNAL(numConnectionsChanged(
int)),
this, SLOT(
setNumConnections(
int)));
417 connect(clientModel, SIGNAL(numBlocksChanged(
int)),
this, SLOT(
setNumBlocks(
int)));
420 connect(clientModel, SIGNAL(
message(QString,QString,
unsigned int)),
this, SLOT(
message(QString,QString,
unsigned int)));
433 bool BitcoinGUI::addWallet(
const QString& name,
WalletModel *walletModel)
441 bool BitcoinGUI::setCurrentWallet(
const QString& name)
448 void BitcoinGUI::removeAllWallets()
477 trayIcon =
new QSystemTrayIcon(
this);
481 trayIcon->setToolTip(tr(
"Bitcoin client"));
482 trayIcon->setIcon(QIcon(
":/icons/toolbar"));
486 trayIcon->setToolTip(tr(
"Bitcoin client") +
" " + tr(
"[testnet]"));
487 trayIcon->setIcon(QIcon(
":/icons/toolbar_testnet"));
504 trayIconMenu =
new QMenu(
this);
505 trayIcon->setContextMenu(trayIconMenu);
507 connect(
trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
513 trayIconMenu = dockIconHandler->
dockMenu();
518 trayIconMenu->addSeparator();
521 trayIconMenu->addSeparator();
524 trayIconMenu->addSeparator();
527 #ifndef Q_OS_MAC // This is built-in on Mac
528 trayIconMenu->addSeparator();
536 if(reason == QSystemTrayIcon::Trigger)
567 help->setAttribute(Qt::WA_DeleteOnClose);
572 void BitcoinGUI::openClicked()
581 void BitcoinGUI::gotoOverviewPage()
587 void BitcoinGUI::gotoBalancesPage()
593 void BitcoinGUI::gotoHistoryPage()
599 void BitcoinGUI::gotoReceiveCoinsPage()
605 void BitcoinGUI::gotoSendCoinsPage(QString addr)
611 void BitcoinGUI::gotoSignMessageTab(QString addr)
616 void BitcoinGUI::gotoVerifyMessageTab(QString addr)
627 case 0: icon =
":/icons/connect_0";
break;
628 case 1:
case 2:
case 3: icon =
":/icons/connect_1";
break;
629 case 4:
case 5:
case 6: icon =
":/icons/connect_2";
break;
630 case 7:
case 8:
case 9: icon =
":/icons/connect_3";
break;
631 default: icon =
":/icons/connect_4";
break;
640 statusBar()->clearMessage();
644 switch (blockSource) {
663 QDateTime currentDate = QDateTime::currentDateTime();
664 int secs = lastBlockDate.secsTo(currentDate);
666 tooltip = tr(
"Processed %1 blocks of transaction history.").arg(count);
671 tooltip = tr(
"Up to date") + QString(
".<br>") + tooltip;
685 QString timeBehindText;
686 const int HOUR_IN_SECONDS = 60*60;
687 const int DAY_IN_SECONDS = 24*60*60;
688 const int WEEK_IN_SECONDS = 7*24*60*60;
689 const int YEAR_IN_SECONDS = 31556952;
690 if(secs < 2*DAY_IN_SECONDS)
692 timeBehindText = tr(
"%n hour(s)",
"",secs/HOUR_IN_SECONDS);
694 else if(secs < 2*WEEK_IN_SECONDS)
696 timeBehindText = tr(
"%n day(s)",
"",secs/DAY_IN_SECONDS);
698 else if(secs < YEAR_IN_SECONDS)
700 timeBehindText = tr(
"%n week(s)",
"",secs/WEEK_IN_SECONDS);
704 int years = secs / YEAR_IN_SECONDS;
705 int remainder = secs % YEAR_IN_SECONDS;
706 timeBehindText = tr(
"%1 and %2").arg(tr(
"%n year(s)",
"", years)).arg(tr(
"%n week(s)",
"", remainder/WEEK_IN_SECONDS));
710 progressBar->setFormat(tr(
"%1 behind").arg(timeBehindText));
715 tooltip = tr(
"Catching up...") + QString(
"<br>") + tooltip;
719 ":/movies/spinner-%1").arg(
spinnerFrame, 3, 10, QChar(
'0')))
730 tooltip += QString(
"<br>");
731 tooltip += tr(
"Last received block was generated %1 ago.").arg(timeBehindText);
732 tooltip += QString(
"<br>");
733 tooltip += tr(
"Transactions after this will not yet be visible.");
737 tooltip = QString(
"<nobr>") + tooltip + QString(
"</nobr>");
746 QString strTitle = tr(
"Bitcoin");
748 int nMBoxIcon = QMessageBox::Information;
754 if (!title.isEmpty()) {
760 msgType = tr(
"Error");
763 msgType = tr(
"Warning");
766 msgType = tr(
"Information");
773 if (!msgType.isEmpty())
774 strTitle +=
" - " + msgType;
778 nMBoxIcon = QMessageBox::Critical;
782 nMBoxIcon = QMessageBox::Warning;
789 QMessageBox::StandardButton buttons;
791 buttons = QMessageBox::Ok;
798 QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons,
this);
801 *ret = r == QMessageBox::Ok;
809 QMainWindow::changeEvent(e);
810 #ifndef Q_OS_MAC // Ignored on Mac
811 if(e->type() == QEvent::WindowStateChange)
815 QWindowStateChangeEvent *wsevt =
static_cast<QWindowStateChangeEvent*
>(e);
816 if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
818 QTimer::singleShot(0,
this, SLOT(hide()));
830 #ifndef Q_OS_MAC // Ignored on Mac
834 QApplication::quit();
838 QMainWindow::closeEvent(event);
842 void BitcoinGUI::incomingTransaction(
const QString& date,
int unit, qint64 amount,
const QString& type,
const QString& address)
845 message((amount)<0 ? tr(
"Sent transaction") : tr(
"Incoming transaction"),
860 if(event->mimeData()->hasUrls())
861 event->acceptProposedAction();
866 if(event->mimeData()->hasUrls())
868 foreach(
const QUrl &uri, event->mimeData()->urls())
873 event->acceptProposedAction();
879 if (event->type() == QEvent::StatusTip)
885 return QMainWindow::eventFilter(
object, event);
902 void BitcoinGUI::setEncryptionStatus(
int status)
915 labelEncryptionIcon->setToolTip(tr(
"Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
923 labelEncryptionIcon->setToolTip(tr(
"Wallet is <b>encrypted</b> and currently <b>locked</b>"));
940 else if (isMinimized())
950 else if(fToggleHidden)
974 QMetaObject::invokeMethod(gui,
"message",
976 Q_ARG(QString, QString::fromStdString(caption)),
977 Q_ARG(QString, QString::fromStdString(message)),
978 Q_ARG(
unsigned int, style),
void subscribeToCoreSignals()
Connect core signals to GUI client.
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
CClientUIInterface uiInterface
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
bool setCurrentWallet(const QString &name)
bool getMinimizeOnClose()
QAction * receiveCoinsAction
Local Bitcoin RPC console.
static const QString DEFAULT_WALLET
QAction * signMessageAction
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
Value help(const Array ¶ms, bool fHelp)
void showNormalIfMinimized(bool fToggleHidden=false)
Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHid...
static QString formatWithUnit(int unit, qint64 amount, bool plussign=false)
Format as string (with unit)
void createTrayIcon(bool fIsTestnet)
Create system tray icon and notification.
ClientModel * clientModel
void createToolBars()
Create the toolbars.
void createTrayIconMenu()
Create system tray menu (or setup the dock menu)
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string &message, const std::string &caption, unsigned int style)
QAction * verifyMessageAction
void dropEvent(QDropEvent *event)
int getNumConnections(unsigned int flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
BitcoinGUI(bool fIsTestnet=false, QWidget *parent=0)
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
void setWalletActionsEnabled(bool enabled)
Enable or disable all wallet-related actions.
OptionsModel * getOptionsModel()
Macintosh-specific dock icon handler.
Mask of all available buttons in CClientUIInterface::MessageBoxFlags This needs to be updated...
Don't bring GUI to foreground.
QLabel * progressBarLabel
QSystemTrayIcon * trayIcon
QAction * showHelpMessageAction
Notify user of potential problem.
QAction * backupWalletAction
QLabel * labelConnectionsIcon
void createActions(bool fIsTestnet)
Create the main UI actions.
void saveWindowGeometry(const QString &strSetting, QWidget *parent)
Save window size and position.
Force blocking, modal message box dialog (not just OS notification)
void showOutOfSyncWarning(bool fShow)
void setIcon(const QIcon &icon)
void setClientModel(ClientModel *model)
void gotoHistoryPage()
Switch to history (transactions) page.
QAction * usedReceivingAddressesAction
void setClientModel(ClientModel *clientModel)
Set the client model.
void gotoOverviewPage()
Switch to overview (home) page.
QAction * toggleHideAction
double getVerificationProgress() const
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
static MacDockIconHandler * instance()
void setClientModel(ClientModel *clientModel)
void setMainWindow(QMainWindow *window)
bool isObscured(QWidget *w)
void optionsClicked()
Show configuration dialog.
void gotoVerifyMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to verify message tab.
void notify(Class cls, const QString &title, const QString &text, const QIcon &icon=QIcon(), int millisTimeout=10000)
Show notification message.
bool eventFilter(QObject *object, QEvent *event)
bool addWallet(const QString &name, WalletModel *walletModel)
QDateTime getLastBlockDate() const
WalletFrame * walletFrame
QAction * usedSendingAddressesAction
void setModel(OptionsModel *model)
QAction * openRPCConsoleAction
void detectShutdown()
called by a timer to check if fRequestShutdown has been set
Cross-platform desktop notification client.
void showHelpMessageClicked()
Show help message dialog.
void dragEnterEvent(QDragEnterEvent *event)
void restoreWindowGeometry(const QString &strSetting, const QSize &defaultSize, QWidget *parent)
Restore window size and position.
Notificator * notificator
Model for Bitcoin network client.
void gotoSignMessageTab(QString addr="")
Show Sign/Verify Message dialog and switch to sign message tab.
QAction * sendCoinsAction
static const int STATUSBAR_ICONSIZE
void trayIconActivated(QSystemTrayIcon::ActivationReason reason)
Handle tray icon clicked.
QAction * changePassphraseAction
void gotoSendCoinsPage(QString addr="")
Switch to send coins page.
void gotoReceiveCoinsPage()
Switch to receive coins page.
void closeEvent(QCloseEvent *event)
Interface to Bitcoin wallet from Qt view code.
void changeEvent(QEvent *e)
int prevBlocks
Keep track of previous number of blocks, to detect progress.
void toggleHidden()
Simply calls showNormalIfMinimized(true) for use in SLOT() macro.
QProgressBar * progressBar
boost::signals2::signal< bool(const std::string &message, const std::string &caption, unsigned int style), boost::signals2::last_value< bool > > ThreadSafeMessageBox
Show message box.
void setNumConnections(int count)
Set number of connections shown in the UI.
"Help message" dialog box
void gotoBalancesPage()
Switch to balances page.
QAction * encryptWalletAction
void aboutClicked()
Show about dialog.
void message(const QString &title, const QString &message, unsigned int style, bool *ret=NULL)
Notify the user of an event from the core network or transaction handling code.
QLabel * labelEncryptionIcon
enum BlockSource getBlockSource() const
Return true if core is importing blocks.
void createMenuBar()
Create the menu bar and sub-menus.
Predefined combinations for certain default usage cases.
void setNumBlocks(int count)
Set number of blocks shown in the UI.
void setModel(ClientModel *model)