aboutsummaryrefslogtreecommitdiff
path: root/src/qt/networkstyle.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-10-09 11:04:49 +0200
committerjtimon <jtimon@blockstream.io>2014-10-10 11:00:59 +0200
commit6de50c3c9a89e72f3152a1df7775572d5c8ad0e7 (patch)
treecf708c7b5b7800b295aeb5bcdb3d742f79b6a31b /src/qt/networkstyle.cpp
parentdec58922d07241f0b502c96f8e5131abccbd5dc1 (diff)
qt: add network-specific style object
Mainly cleanups: Gets rid of isTestNet everywhere, by keeping track of network-specific theming in a central place. Also makes GUI no longer dependent on the network ID enumeration, which alleviates concerns about #4802.
Diffstat (limited to 'src/qt/networkstyle.cpp')
-rw-r--r--src/qt/networkstyle.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/qt/networkstyle.cpp b/src/qt/networkstyle.cpp
new file mode 100644
index 0000000000..62c44703f4
--- /dev/null
+++ b/src/qt/networkstyle.cpp
@@ -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;
+}