#include "overviewpage.h"
#include "bitcoinunits.h"
#include "guiconstants.h"
+#include "askpassphrasedialog.h"
+#include "notificator.h"
+#include "qtwin.h"
#include <QApplication>
#include <QMainWindow>
QMainWindow(parent),
clientModel(0),
walletModel(0),
- trayIcon(0)
+ encryptWalletAction(0),
+ changePassphraseAction(0),
+ trayIcon(0),
+ notificator(0)
{
resize(850, 550);
setWindowTitle(tr("Bitcoin Wallet"));
file->addAction(quitAction);
QMenu *settings = menuBar()->addMenu(tr("&Settings"));
+ settings->addAction(encryptWalletAction);
+ settings->addAction(changePassphraseAction);
+ settings->addSeparator();
settings->addAction(optionsAction);
QMenu *help = menuBar()->addMenu(tr("&Help"));
// Doubleclicking on a transaction on the transaction history page shows details
connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
+#ifdef Q_OS_WIN
+ // Windows-specific customization
+ if (QtWin::isCompositionEnabled())
+ {
+ QtWin::extendFrameIntoClientArea(&window);
+ window.setContentsMargins(0, 0, 0, 0);
+ }
+#endif
+ setWindowComposition();
+
gotoOverviewPage();
}
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"));
+ encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this);
+ encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
+ encryptWalletAction->setCheckable(true);
+ changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase"), this);
+ changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption"));
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
- connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(show()));
+ connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormal()));
+ connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
+ connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
}
void BitcoinGUI::setClientModel(ClientModel *clientModel)
// Balloon popup for new transaction
connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(incomingTransaction(QModelIndex,int,int)));
+
+ // Ask for passphrase if needed
+ connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
}
void BitcoinGUI::createTrayIcon()
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
trayIcon->show();
+
+ notificator = new Notificator(tr("bitcoin-qt"), trayIcon);
}
void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
{
if(reason == QSystemTrayIcon::Trigger)
{
- // Doubleclick on system tray icon triggers "open bitcoin"
+ // Click on system tray icon triggers "open bitcoin"
openBitcoinAction->trigger();
}
+
}
void BitcoinGUI::optionsClicked()
void BitcoinGUI::error(const QString &title, const QString &message)
{
// Report errors from network/worker thread
- if(trayIcon->supportsMessages())
- {
- // Show as "balloon" message if possible
- trayIcon->showMessage(title, message, QSystemTrayIcon::Critical);
- }
- else
- {
- // Fall back to old fashioned popup dialog if not
- QMessageBox::critical(this, title,
- message,
- QMessageBox::Ok, QMessageBox::Ok);
- }
+ notificator->notify(Notificator::Critical, title, message);
}
void BitcoinGUI::changeEvent(QEvent *e)
}
else
{
+ show();
e->accept();
}
}
}
+ setWindowComposition();
QMainWindow::changeEvent(e);
}
QMainWindow::closeEvent(event);
}
+void BitcoinGUI::setWindowComposition()
+{
+#ifdef Q_OS_WIN
+ // Make the background transparent on Windows Vista or 7, except when maximized
+ // Otherwise text becomes hard to read
+ if (QtWin::isCompositionEnabled())
+ {
+ QPalette pal = palette();
+ QColor bg = pal.window().color();
+ if(isMaximized())
+ {
+ setAttribute(Qt::WA_TranslucentBackground, false);
+ setAttribute(Qt::WA_StyledBackground, true);
+ QBrush wb = pal.window();
+ bg = wb.color();
+ bg.setAlpha(255);
+ pal.setColor(QPalette::Window, bg);
+ setPalette(pal);
+
+ }
+ else
+ {
+ setAttribute(Qt::WA_TranslucentBackground);
+ setAttribute(Qt::WA_StyledBackground, false);
+ bg.setAlpha(0);
+ pal.setColor(QPalette::Window, bg);
+ setPalette(pal);
+ setAttribute(Qt::WA_NoSystemBackground, false);
+ ensurePolished();
+ setAttribute(Qt::WA_StyledBackground, false);
+ }
+ }
+#endif
+}
+
void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
{
QString strMessage =
void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
{
- if(start == end)
- return;
TransactionTableModel *ttm = walletModel->getTransactionTableModel();
qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
.data(Qt::EditRole).toULongLong();
.data().toString();
QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
.data().toString();
-
- trayIcon->showMessage((amount)<0 ? tr("Sent transaction") :
- tr("Incoming transaction"),
- tr("Date: ") + date + "\n" +
- tr("Amount: ") + BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true) + "\n" +
- tr("Type: ") + type + "\n" +
- tr("Address: ") + address + "\n",
- QSystemTrayIcon::Information);
+ QIcon icon = qvariant_cast<QIcon>(ttm->index(start,
+ TransactionTableModel::ToAddress, parent)
+ .data(Qt::DecorationRole));
+
+ notificator->notify(Notificator::Information,
+ (amount)<0 ? tr("Sent transaction") :
+ tr("Incoming transaction"),
+ tr("Date: %1\n"
+ "Amount: %2\n"
+ "Type: %3\n"
+ "Address: %4\n")
+ .arg(date)
+ .arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true))
+ .arg(type)
+ .arg(address), icon);
}
}
{
case WalletModel::Unencrypted:
labelEncryptionIcon->hide();
+ encryptWalletAction->setChecked(false);
+ changePassphraseAction->setEnabled(false);
+ encryptWalletAction->setEnabled(true);
break;
case WalletModel::Unlocked:
labelEncryptionIcon->show();
labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
+ encryptWalletAction->setChecked(true);
+ changePassphraseAction->setEnabled(true);
+ encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
break;
case WalletModel::Locked:
labelEncryptionIcon->show();
labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
+ encryptWalletAction->setChecked(true);
+ changePassphraseAction->setEnabled(true);
+ encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
break;
}
}
+
+void BitcoinGUI::encryptWallet(bool status)
+{
+ AskPassphraseDialog dlg(status ? AskPassphraseDialog::Encrypt:
+ AskPassphraseDialog::Decrypt, this);
+ dlg.setModel(walletModel);
+ dlg.exec();
+
+ setEncryptionStatus(walletModel->getEncryptionStatus());
+}
+
+void BitcoinGUI::changePassphrase()
+{
+ AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
+ dlg.setModel(walletModel);
+ dlg.exec();
+}
+
+void BitcoinGUI::unlockWallet()
+{
+ // Unlock wallet when requested by wallet model
+ if(walletModel->getEncryptionStatus() == WalletModel::Locked)
+ {
+ AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);
+ dlg.setModel(walletModel);
+ dlg.exec();
+ }
+}