Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ BITCOIN_QT_H = \
qt/macdockiconhandler.h \
qt/macnotificationhandler.h \
qt/monitoreddatamapper.h \
qt/networkstyle.h \
qt/notificator.h \
qt/openuridialog.h \
qt/optionsdialog.h \
Expand Down Expand Up @@ -269,6 +270,7 @@ BITCOIN_QT_CPP = \
qt/guiutil.cpp \
qt/intro.cpp \
qt/monitoreddatamapper.cpp \
qt/networkstyle.cpp \
qt/notificator.cpp \
qt/optionsdialog.cpp \
qt/optionsmodel.cpp \
Expand Down
25 changes: 12 additions & 13 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "guiconstants.h"
#include "guiutil.h"
#include "intro.h"
#include "networkstyle.h"
#include "optionsmodel.h"
#include "splashscreen.h"
#include "utilitydialog.h"
Expand Down Expand Up @@ -190,9 +191,9 @@ class BitcoinApplication: public QApplication
/// Create options model
void createOptionsModel();
/// Create main window
void createWindow(bool isaTestNet);
void createWindow(const NetworkStyle *networkStyle);
/// Create splash screen
void createSplashScreen(bool isaTestNet);
void createSplashScreen(const NetworkStyle *networkStyle);

/// Request core initialization
void requestInitialize();
Expand Down Expand Up @@ -331,18 +332,18 @@ void BitcoinApplication::createOptionsModel()
optionsModel = new OptionsModel();
}

void BitcoinApplication::createWindow(bool isaTestNet)
void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
{
window = new BitcoinGUI(isaTestNet, 0);
window = new BitcoinGUI(networkStyle, 0);

pollShutdownTimer = new QTimer(window);
connect(pollShutdownTimer, SIGNAL(timeout()), window, SLOT(detectShutdown()));
pollShutdownTimer->start(200);
}

void BitcoinApplication::createSplashScreen(bool isaTestNet)
void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
{
SplashScreen *splash = new SplashScreen(0, isaTestNet);
SplashScreen *splash = new SplashScreen(0, networkStyle);
// We don't hold a direct pointer to the splash screen after creation, so use
// Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually.
splash->setAttribute(Qt::WA_DeleteOnClose);
Expand Down Expand Up @@ -572,12 +573,10 @@ int main(int argc, char *argv[])
if (!PaymentServer::ipcParseCommandLine(argc, argv))
exit(0);
#endif
bool isaTestNet = Params().NetworkID() != CBaseChainParams::MAIN;
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString())));
assert(!networkStyle.isNull());
// Allow for separate UI settings for testnets
if (isaTestNet)
QApplication::setApplicationName(QAPP_APP_NAME_TESTNET);
else
QApplication::setApplicationName(QAPP_APP_NAME_DEFAULT);
QApplication::setApplicationName(networkStyle->getAppName());
// Re-initialize translations after changing application name (language in network-specific settings can be different)
initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);

Expand Down Expand Up @@ -617,11 +616,11 @@ int main(int argc, char *argv[])
uiInterface.InitMessage.connect(InitMessage);

if (GetBoolArg("-splash", true) && !GetBoolArg("-min", false))
app.createSplashScreen(isaTestNet);
app.createSplashScreen(networkStyle.data());

try
{
app.createWindow(isaTestNet);
app.createWindow(networkStyle.data());
app.requestInitialize();
#if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("Bitcoin Core didn't yet exit safely..."), (HWND)app.getMainWinId());
Expand Down
57 changes: 15 additions & 42 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "clientmodel.h"
#include "guiconstants.h"
#include "guiutil.h"
#include "networkstyle.h"
#include "notificator.h"
#include "openuridialog.h"
#include "optionsdialog.h"
Expand Down Expand Up @@ -59,7 +60,7 @@

const QString BitcoinGUI::DEFAULT_WALLET = "~Default";

BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) :
BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) :
QMainWindow(parent),
clientModel(0),
walletFrame(0),
Expand Down Expand Up @@ -112,26 +113,13 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) :
} else {
windowTitle += tr("Node");
}

if (!fIsTestnet)
{
windowTitle += " " + networkStyle->getTitleAddText();
#ifndef Q_OS_MAC
QApplication::setWindowIcon(QIcon(":icons/bitcoin"));
setWindowIcon(QIcon(":icons/bitcoin"));
QApplication::setWindowIcon(networkStyle->getAppIcon());
setWindowIcon(networkStyle->getAppIcon());
#else
MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin"));
MacDockIconHandler::instance()->setIcon(networkStyle->getAppIcon());
#endif
}
else
{
windowTitle += " " + 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
}
setWindowTitle(windowTitle);

#if defined(Q_OS_MAC) && QT_VERSION < 0x050000
Expand Down Expand Up @@ -161,7 +149,7 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) :

// Create actions for the toolbar, menu bar and tray/dock icon
// Needs walletFrame to be initialized
createActions(fIsTestnet);
createActions(networkStyle);

// Create application menu bar
createMenuBar();
Expand All @@ -170,7 +158,7 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) :
createToolBars();

// Create system tray icon and notification
createTrayIcon(fIsTestnet);
createTrayIcon(networkStyle);

// Create status bar
statusBar();
Expand Down Expand Up @@ -248,7 +236,7 @@ BitcoinGUI::~BitcoinGUI()
#endif
}

void BitcoinGUI::createActions(bool fIsTestnet)
void BitcoinGUI::createActions(const NetworkStyle *networkStyle)
{
QActionGroup *tabGroup = new QActionGroup(this);

Expand Down Expand Up @@ -295,10 +283,7 @@ void BitcoinGUI::createActions(bool fIsTestnet)
quitAction->setStatusTip(tr("Quit application"));
quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
quitAction->setMenuRole(QAction::QuitRole);
if (!fIsTestnet)
aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About Bitcoin Core"), this);
else
aboutAction = new QAction(QIcon(":/icons/bitcoin_testnet"), tr("&About Bitcoin Core"), this);
aboutAction = new QAction(networkStyle->getAppIcon(), tr("&About Bitcoin Core"), this);
aboutAction->setStatusTip(tr("Show information about Bitcoin Core"));
aboutAction->setMenuRole(QAction::AboutRole);
#if QT_VERSION < 0x050000
Expand All @@ -311,10 +296,7 @@ void BitcoinGUI::createActions(bool fIsTestnet)
optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
optionsAction->setStatusTip(tr("Modify configuration options for Bitcoin"));
optionsAction->setMenuRole(QAction::PreferencesRole);
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 = new QAction(networkStyle->getAppIcon(), tr("&Show / Hide"), this);
toggleHideAction->setStatusTip(tr("Show or hide the main Window"));

encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
Expand Down Expand Up @@ -505,22 +487,13 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled)
openAction->setEnabled(enabled);
}

void BitcoinGUI::createTrayIcon(bool fIsTestnet)
void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle)
{
#ifndef Q_OS_MAC
trayIcon = new QSystemTrayIcon(this);

if (!fIsTestnet)
{
trayIcon->setToolTip(tr("Bitcoin Core client"));
trayIcon->setIcon(QIcon(":/icons/bitcoin"));
}
else
{
trayIcon->setToolTip(tr("Bitcoin Core client") + " " + tr("[testnet]"));
trayIcon->setIcon(QIcon(":/icons/bitcoin_testnet"));
}

QString toolTip = tr("Bitcoin Core client") + " " + networkStyle->getTitleAddText();
trayIcon->setToolTip(toolTip);
trayIcon->setIcon(networkStyle->getAppIcon());
trayIcon->show();
#endif

Expand Down
7 changes: 4 additions & 3 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <QSystemTrayIcon>

class ClientModel;
class NetworkStyle;
class Notificator;
class OptionsModel;
class RPCConsole;
Expand Down Expand Up @@ -46,7 +47,7 @@ class BitcoinGUI : public QMainWindow
public:
static const QString DEFAULT_WALLET;

explicit BitcoinGUI(bool fIsTestnet = false, QWidget *parent = 0);
explicit BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent = 0);
~BitcoinGUI();

/** Set the client model.
Expand Down Expand Up @@ -114,13 +115,13 @@ class BitcoinGUI : public QMainWindow
int spinnerFrame;

/** Create the main UI actions. */
void createActions(bool fIsTestnet);
void createActions(const NetworkStyle *networkStyle);
/** Create the menu bar and sub-menus. */
void createMenuBar();
/** Create the toolbars */
void createToolBars();
/** Create system tray icon and notification */
void createTrayIcon(bool fIsTestnet);
void createTrayIcon(const NetworkStyle *networkStyle);
/** Create system tray menu (or setup the dock menu) */
void createTrayIconMenu();

Expand Down
47 changes: 47 additions & 0 deletions src/qt/networkstyle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2014 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "networkstyle.h"

#include "guiconstants.h"

#include <QApplication>

static const struct {
const char *networkId;
const char *appName;
const char *appIcon;
const char *titleAddText;
const char *splashImage;
} network_styles[] = {
{"main", QAPP_APP_NAME_DEFAULT, ":/icons/bitcoin", "", ":/images/splash"},
{"test", QAPP_APP_NAME_TESTNET, ":/icons/bitcoin_testnet", QT_TRANSLATE_NOOP("SplashScreen", "[testnet]"), ":/images/splash_testnet"},
{"regtest", QAPP_APP_NAME_TESTNET, ":/icons/bitcoin_testnet", "[regtest]", ":/images/splash_testnet"}
};
static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);

// titleAddText needs to be const char* for tr()
NetworkStyle::NetworkStyle(const QString &appName, const QString &appIcon, const char *titleAddText, const QString &splashImage):
appName(appName),
appIcon(appIcon),
titleAddText(qApp->translate("SplashScreen", titleAddText)),
splashImage(splashImage)
{
}

const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
{
for (unsigned x=0; x<network_styles_count; ++x)
{
if (networkId == network_styles[x].networkId)
{
return new NetworkStyle(
network_styles[x].appName,
network_styles[x].appIcon,
network_styles[x].titleAddText,
network_styles[x].splashImage);
}
}
return 0;
}
33 changes: 33 additions & 0 deletions src/qt/networkstyle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2014 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef H_NETWORKSTYLE
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing license

#define H_NETWORKSTYLE

#include <QIcon>
#include <QPixmap>
#include <QString>

/* Coin network-specific GUI style information */
class NetworkStyle
{
public:
/** Get style associated with provided BIP70 network id, or 0 if not known */
static const NetworkStyle *instantiate(const QString &networkId);

const QString &getAppName() const { return appName; }
const QIcon &getAppIcon() const { return appIcon; }
const QString &getTitleAddText() const { return titleAddText; }
const QPixmap &getSplashImage() const { return splashImage; }

private:
NetworkStyle(const QString &appName, const QString &appIcon, const char *titleAddText, const QString &splashImage);

QString appName;
QIcon appIcon;
QString titleAddText;
QPixmap splashImage;
};

#endif // H_NETWORKSTYLE
25 changes: 9 additions & 16 deletions src/qt/splashscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "clientversion.h"
#include "init.h"
#include "networkstyle.h"
#include "ui_interface.h"
#include "util.h"
#include "version.h"
Expand All @@ -19,7 +20,7 @@
#include <QDesktopWidget>
#include <QPainter>

SplashScreen::SplashScreen(Qt::WindowFlags f, bool isTestNet) :
SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle) :
QWidget(0, f), curAlignment(0)
{
// set reference point, paddings
Expand All @@ -34,17 +35,12 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, bool isTestNet) :
QString titleText = tr("Bitcoin Core");
QString versionText = QString("Version %1").arg(QString::fromStdString(FormatFullVersion()));
QString copyrightText = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Core developers"));
QString testnetAddText = QString(tr("[testnet]")); // define text to place as single text object
QString titleAddText = networkStyle->getTitleAddText();

QString font = "Arial";

// load the bitmap for writing some text over it
if(isTestNet) {
pixmap = QPixmap(":/images/splash_testnet");
}
else {
pixmap = QPixmap(":/images/splash");
}
pixmap = networkStyle->getSplashImage();

QPainter pixPaint(&pixmap);
pixPaint.setPen(QColor(100,100,100));
Expand Down Expand Up @@ -78,23 +74,20 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, bool isTestNet) :
pixPaint.setFont(QFont(font, 10*fontFactor));
pixPaint.drawText(pixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText);

// draw testnet string if testnet is on
if(isTestNet) {
// draw additional text if special network
if(!titleAddText.isEmpty()) {
QFont boldFont = QFont(font, 10*fontFactor);
boldFont.setWeight(QFont::Bold);
pixPaint.setFont(boldFont);
fm = pixPaint.fontMetrics();
int testnetAddTextWidth = fm.width(testnetAddText);
pixPaint.drawText(pixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
int titleAddTextWidth = fm.width(titleAddText);
pixPaint.drawText(pixmap.width()-titleAddTextWidth-10,15,titleAddText);
}

pixPaint.end();

// Set window title
if(isTestNet)
setWindowTitle(titleText + " " + testnetAddText);
else
setWindowTitle(titleText);
setWindowTitle(titleText + " " + titleAddText);

// Resize window and move to center of desktop, disallow resizing
QRect r(QPoint(), pixmap.size());
Expand Down
Loading