/*
* Qt4 bitcoin GUI.
*
- * W.J. van der Laan 2011
- * The Bitcoin Developers 2011
+ * W.J. van der Laan 20011-2012
+ * The Bitcoin Developers 20011-2012
*/
#include "bitcoingui.h"
#include "transactiontablemodel.h"
#include "addressbookpage.h"
#include "sendcoinsdialog.h"
+#include "messagepage.h"
#include "optionsdialog.h"
#include "aboutdialog.h"
#include "clientmodel.h"
#include <QStackedWidget>
#include <QDateTime>
#include <QMovie>
+#include <QFileDialog>
+#include <QDesktopServices>
+#include <QTimer>
#include <QDragEnterEvent>
#include <QUrl>
sendCoinsPage = new SendCoinsDialog(this);
+ messagePage = new MessagePage(this);
+
centralWidget = new QStackedWidget(this);
centralWidget->addWidget(overviewPage);
centralWidget->addWidget(transactionsPage);
centralWidget->addWidget(addressBookPage);
centralWidget->addWidget(receiveCoinsPage);
centralWidget->addWidget(sendCoinsPage);
+#ifdef FIRST_CLASS_MESSAGING
+ centralWidget->addWidget(messagePage);
+#endif
setCentralWidget(centralWidget);
// Create status bar
// Status bar notification icons
QFrame *frameBlocks = new QFrame();
- //frameBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
frameBlocks->setContentsMargins(0,0,0,0);
frameBlocks->setMinimumWidth(56);
frameBlocks->setMaximumWidth(56);
BitcoinGUI::~BitcoinGUI()
{
+ if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
+ trayIcon->hide();
#ifdef Q_WS_MAC
delete appMenuBar;
#endif
sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
tabGroup->addAction(sendCoinsAction);
- connect(overviewAction, SIGNAL(triggered()), this, SLOT(show()));
+ messageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message"), this);
+ messageAction->setToolTip(tr("Prove you control an address"));
+#ifdef FIRST_CLASS_MESSAGING
+ messageAction->setCheckable(true);
+#endif
+ tabGroup->addAction(messageAction);
+
+ connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
- connect(historyAction, SIGNAL(triggered()), this, SLOT(show()));
+ connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
- connect(addressBookAction, SIGNAL(triggered()), this, SLOT(show()));
+ connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage()));
- connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(show()));
+ connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
- connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(show()));
+ connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
+ connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
+ connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage()));
quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
quitAction->setToolTip(tr("Quit application"));
openBitcoinAction = new QAction(QIcon(":/icons/bitcoin"), tr("Open &Bitcoin"), this);
openBitcoinAction->setToolTip(tr("Show the Bitcoin window"));
exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
- exportAction->setToolTip(tr("Export the current view to a file"));
+ exportAction->setToolTip(tr("Export the data in the current tab to a file"));
encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this);
encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
encryptWalletAction->setCheckable(true);
+ backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet"), this);
+ backupWalletAction->setToolTip(tr("Backup wallet to another location"));
changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase"), this);
changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
- connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormal()));
+ connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
+ connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
}
// Configure the menus
QMenu *file = appMenuBar->addMenu(tr("&File"));
+ file->addAction(backupWalletAction);
+ file->addAction(exportAction);
+#ifndef FIRST_CLASS_MESSAGING
+ file->addAction(messageAction);
+#endif
+ file->addSeparator();
file->addAction(quitAction);
QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
toolbar->addAction(receiveCoinsAction);
toolbar->addAction(historyAction);
toolbar->addAction(addressBookAction);
+#ifdef FIRST_CLASS_MESSAGING
+ toolbar->addAction(messageAction);
+#endif
QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
addressBookPage->setModel(walletModel->getAddressTableModel());
receiveCoinsPage->setModel(walletModel->getAddressTableModel());
sendCoinsPage->setModel(walletModel);
+ messagePage->setModel(walletModel);
setEncryptionStatus(walletModel->getEncryptionStatus());
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
// Configuration of the tray icon (or dock icon) icon menu
trayIconMenu->addAction(openBitcoinAction);
trayIconMenu->addSeparator();
+ trayIconMenu->addAction(messageAction);
+#ifndef FIRST_CLASS_MESSAGING
+ trayIconMenu->addSeparator();
+#endif
trayIconMenu->addAction(receiveCoinsAction);
trayIconMenu->addAction(sendCoinsAction);
trayIconMenu->addSeparator();
// Click on system tray icon triggers "open bitcoin"
openBitcoinAction->trigger();
}
-
}
#endif
{
if(!clientModel)
return;
- int initTotal = clientModel->getNumBlocksAtStartup();
int total = clientModel->getNumBlocksOfPeers();
QString tooltip;
progressBarLabel->setVisible(true);
progressBarLabel->setText(tr("Synchronizing with network..."));
progressBar->setVisible(true);
- progressBar->setMaximum(total - initTotal);
- progressBar->setValue(count - initTotal);
+ progressBar->setMaximum(total);
+ progressBar->setValue(count);
}
else
{
QString text;
// Represent time from last generated block in human readable text
- if(secs < 60)
+ if(secs <= 0)
+ {
+ // Fully up to date. Leave text empty.
+ }
+ else if(secs < 60)
{
text = tr("%n second(s) ago","",secs);
}
// Set icon state: spinning if catching up, tick otherwise
if(secs < 30*60)
{
- tooltip = tr("Up to date") + QString("\n") + tooltip;
+ tooltip = tr("Up to date") + QString(".\n") + tooltip;
labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
}
else
syncIconMovie->start();
}
- tooltip += QString("\n");
- tooltip += tr("Last received block was generated %1.").arg(text);
+ if(!text.isEmpty())
+ {
+ tooltip += QString("\n");
+ tooltip += tr("Last received block was generated %1.").arg(text);
+ }
labelBlocksIcon->setToolTip(tooltip);
progressBarLabel->setToolTip(tooltip);
void BitcoinGUI::changeEvent(QEvent *e)
{
+ QMainWindow::changeEvent(e);
#ifndef Q_WS_MAC // Ignored on Mac
if(e->type() == QEvent::WindowStateChange)
{
if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray())
{
- if(isMinimized())
+ QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e);
+ if(!(wsevt->oldState() & Qt::WindowMinimized) && isMinimized())
{
- hide();
+ QTimer::singleShot(0, this, SLOT(hide()));
e->ignore();
}
- else
- {
- show();
- e->accept();
- }
}
}
#endif
- QMainWindow::changeEvent(e);
}
void BitcoinGUI::closeEvent(QCloseEvent *event)
disconnect(exportAction, SIGNAL(triggered()), 0, 0);
}
+void BitcoinGUI::gotoMessagePage()
+{
+#ifdef FIRST_CLASS_MESSAGING
+ messageAction->setChecked(true);
+ centralWidget->setCurrentWidget(messagePage);
+
+ exportAction->setEnabled(false);
+ disconnect(exportAction, SIGNAL(triggered()), 0, 0);
+#else
+ messagePage->show();
+ messagePage->setFocus();
+#endif
+}
+
+void BitcoinGUI::gotoMessagePage(QString addr)
+{
+ gotoMessagePage();
+ messagePage->setAddress(addr);
+}
+
void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
{
// Accept only URLs
QList<QUrl> urls = event->mimeData()->urls();
foreach(const QUrl &url, urls)
{
- sendCoinsPage->handleURL(&url);
+ sendCoinsPage->handleURL(url.toString());
}
}
event->acceptProposedAction();
}
+void BitcoinGUI::handleURL(QString strURL)
+{
+ gotoSendCoinsPage();
+ sendCoinsPage->handleURL(strURL);
+
+ if(!isActiveWindow())
+ activateWindow();
+
+ showNormalIfMinimized();
+}
+
void BitcoinGUI::setEncryptionStatus(int status)
{
switch(status)
setEncryptionStatus(walletModel->getEncryptionStatus());
}
+void BitcoinGUI::backupWallet()
+{
+ QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
+ QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
+ if(!filename.isEmpty()) {
+ if(!walletModel->backupWallet(filename)) {
+ QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location."));
+ }
+ }
+}
+
void BitcoinGUI::changePassphrase()
{
AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
dlg.exec();
}
}
+
+void BitcoinGUI::showNormalIfMinimized()
+{
+ if(!isVisible()) // Show, if hidden
+ show();
+ if(isMinimized()) // Unminimize, if minimized
+ showNormal();
+}