Merge pull request #2672 from Diapolo/Qt_testnet

Bitcoin-Qt: setup testnet GUI directly
This commit is contained in:
Wladimir J. van der Laan 2013-06-02 09:23:37 -07:00
commit fa9e5adddd
3 changed files with 47 additions and 48 deletions

View file

@ -15,9 +15,6 @@
#include "ui_interface.h" #include "ui_interface.h"
#include "paymentserver.h" #include "paymentserver.h"
#include "splashscreen.h" #include "splashscreen.h"
#ifdef Q_OS_MAC
#include "macdockiconhandler.h"
#endif
#include <QMessageBox> #include <QMessageBox>
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
@ -205,14 +202,6 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
#ifdef Q_OS_MAC
// on mac, also change the icon now because it would look strange to have a testnet splash (green) and a std app icon (orange)
if(GetBoolArg("-testnet", false))
{
MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
}
#endif
SplashScreen splash(QPixmap(), 0); SplashScreen splash(QPixmap(), 0);
if (GetBoolArg("-splash", true) && !GetBoolArg("-min", false)) if (GetBoolArg("-splash", true) && !GetBoolArg("-min", false))
{ {
@ -232,7 +221,7 @@ int main(int argc, char *argv[])
boost::thread_group threadGroup; boost::thread_group threadGroup;
BitcoinGUI window; BitcoinGUI window(GetBoolArg("-testnet", false), 0);
guiref = &window; guiref = &window;
QTimer* pollShutdownTimer = new QTimer(guiref); QTimer* pollShutdownTimer = new QTimer(guiref);

View file

@ -57,7 +57,7 @@
const QString BitcoinGUI::DEFAULT_WALLET = "~Default"; const QString BitcoinGUI::DEFAULT_WALLET = "~Default";
BitcoinGUI::BitcoinGUI(QWidget *parent) : BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
clientModel(0), clientModel(0),
encryptWalletAction(0), encryptWalletAction(0),
@ -69,14 +69,30 @@ BitcoinGUI::BitcoinGUI(QWidget *parent) :
prevBlocks(0) prevBlocks(0)
{ {
restoreWindowGeometry(); restoreWindowGeometry();
setWindowTitle(tr("Bitcoin") + " - " + tr("Wallet"));
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
QApplication::setWindowIcon(QIcon(":icons/bitcoin")); if (!fIsTestnet)
setWindowIcon(QIcon(":icons/bitcoin")); {
setWindowTitle(tr("Bitcoin") + " - " + tr("Wallet"));
QApplication::setWindowIcon(QIcon(":icons/bitcoin"));
setWindowIcon(QIcon(":icons/bitcoin"));
}
else
{
setWindowTitle(tr("Bitcoin") + " - " + tr("Wallet") + " " + tr("[testnet]"));
QApplication::setWindowIcon(QIcon(":icons/bitcoin_testnet"));
setWindowIcon(QIcon(":icons/bitcoin_testnet"));
}
#else #else
setUnifiedTitleAndToolBarOnMac(true); setUnifiedTitleAndToolBarOnMac(true);
QApplication::setAttribute(Qt::AA_DontShowIconsInMenus); QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
if (!fIsTestnet)
MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin"));
else
MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
#endif #endif
// Create wallet frame and make it the central widget // Create wallet frame and make it the central widget
walletFrame = new WalletFrame(this); walletFrame = new WalletFrame(this);
setCentralWidget(walletFrame); setCentralWidget(walletFrame);
@ -86,7 +102,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent) :
// Create actions for the toolbar, menu bar and tray/dock icon // Create actions for the toolbar, menu bar and tray/dock icon
// Needs walletFrame to be initialized // Needs walletFrame to be initialized
createActions(); createActions(fIsTestnet);
// Create application menu bar // Create application menu bar
createMenuBar(); createMenuBar();
@ -95,7 +111,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent) :
createToolBars(); createToolBars();
// Create system tray icon and notification // Create system tray icon and notification
createTrayIcon(); createTrayIcon(fIsTestnet);
// Create status bar // Create status bar
statusBar(); statusBar();
@ -159,7 +175,7 @@ BitcoinGUI::~BitcoinGUI()
#endif #endif
} }
void BitcoinGUI::createActions() void BitcoinGUI::createActions(bool fIsTestnet)
{ {
QActionGroup *tabGroup = new QActionGroup(this); QActionGroup *tabGroup = new QActionGroup(this);
@ -213,7 +229,10 @@ void BitcoinGUI::createActions()
quitAction->setStatusTip(tr("Quit application")); quitAction->setStatusTip(tr("Quit application"));
quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q)); quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
quitAction->setMenuRole(QAction::QuitRole); quitAction->setMenuRole(QAction::QuitRole);
aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About Bitcoin"), this); if (!fIsTestnet)
aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About Bitcoin"), this);
else
aboutAction = new QAction(QIcon(":/icons/bitcoin_testnet"), tr("&About Bitcoin"), this);
aboutAction->setStatusTip(tr("Show information about Bitcoin")); aboutAction->setStatusTip(tr("Show information about Bitcoin"));
aboutAction->setMenuRole(QAction::AboutRole); aboutAction->setMenuRole(QAction::AboutRole);
aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this); aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
@ -222,7 +241,10 @@ void BitcoinGUI::createActions()
optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this); optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
optionsAction->setStatusTip(tr("Modify configuration options for Bitcoin")); optionsAction->setStatusTip(tr("Modify configuration options for Bitcoin"));
optionsAction->setMenuRole(QAction::PreferencesRole); optionsAction->setMenuRole(QAction::PreferencesRole);
toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this); if (!fIsTestnet)
toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this);
else
toggleHideAction = new QAction(QIcon(":/icons/bitcoin_testnet"), tr("&Show / Hide"), this);
toggleHideAction->setStatusTip(tr("Show or hide the main Window")); toggleHideAction->setStatusTip(tr("Show or hide the main Window"));
encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this); encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
@ -299,27 +321,6 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
this->clientModel = clientModel; this->clientModel = clientModel;
if(clientModel) if(clientModel)
{ {
// Replace some strings and icons, when using the testnet
if(clientModel->isTestNet())
{
setWindowTitle(windowTitle() + QString(" ") + tr("[testnet]"));
#ifndef Q_OS_MAC
QApplication::setWindowIcon(QIcon(":icons/bitcoin_testnet"));
setWindowIcon(QIcon(":icons/bitcoin_testnet"));
#else
MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
#endif
if(trayIcon)
{
// Just attach " [testnet]" to the existing tooltip
trayIcon->setToolTip(trayIcon->toolTip() + QString(" ") + tr("[testnet]"));
trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
}
toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet"));
aboutAction->setIcon(QIcon(":/icons/toolbar_testnet"));
}
// Create system tray menu (or setup the dock menu) that late to prevent users from calling actions, // 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 // while the client has not yet fully loaded
createTrayIconMenu(); createTrayIconMenu();
@ -354,13 +355,22 @@ void BitcoinGUI::removeAllWallets()
walletFrame->removeAllWallets(); walletFrame->removeAllWallets();
} }
void BitcoinGUI::createTrayIcon() void BitcoinGUI::createTrayIcon(bool fIsTestnet)
{ {
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
trayIcon = new QSystemTrayIcon(this); trayIcon = new QSystemTrayIcon(this);
trayIcon->setToolTip(tr("Bitcoin client")); if (!fIsTestnet)
trayIcon->setIcon(QIcon(":/icons/toolbar")); {
trayIcon->setToolTip(tr("Bitcoin client"));
trayIcon->setIcon(QIcon(":/icons/toolbar"));
}
else
{
trayIcon->setToolTip(tr("Bitcoin client") + " " + tr("[testnet]"));
trayIcon->setIcon(QIcon(":/icons/toolbar_testnet"));
}
trayIcon->show(); trayIcon->show();
#endif #endif

View file

@ -43,7 +43,7 @@ class BitcoinGUI : public QMainWindow
public: public:
static const QString DEFAULT_WALLET; static const QString DEFAULT_WALLET;
explicit BitcoinGUI(QWidget *parent = 0); explicit BitcoinGUI(bool fIsTestnet = false, QWidget *parent = 0);
~BitcoinGUI(); ~BitcoinGUI();
/** Set the client model. /** Set the client model.
@ -113,13 +113,13 @@ private:
int prevBlocks; int prevBlocks;
/** Create the main UI actions. */ /** Create the main UI actions. */
void createActions(); void createActions(bool fIsTestnet);
/** Create the menu bar and sub-menus. */ /** Create the menu bar and sub-menus. */
void createMenuBar(); void createMenuBar();
/** Create the toolbars */ /** Create the toolbars */
void createToolBars(); void createToolBars();
/** Create system tray icon and notification */ /** Create system tray icon and notification */
void createTrayIcon(); void createTrayIcon(bool fIsTestnet);
/** Create system tray menu (or setup the dock menu) */ /** Create system tray menu (or setup the dock menu) */
void createTrayIconMenu(); void createTrayIconMenu();
/** Save window size and position */ /** Save window size and position */