Testchains: Qt: Simplify network/chain styles

This commit is contained in:
Jorge Timón 2016-10-13 23:24:21 +02:00
parent 052c54ecb0
commit 3bf9d8cac0
No known key found for this signature in database
GPG key ID: 8866C18EA1C944A2
4 changed files with 12 additions and 10 deletions

View file

@ -524,7 +524,7 @@ int GuiMain(int argc, char* argv[])
PaymentServer::ipcParseCommandLine(*node, argc, argv); PaymentServer::ipcParseCommandLine(*node, argc, argv);
#endif #endif
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString()))); QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(Params().NetworkIDString()));
assert(!networkStyle.isNull()); assert(!networkStyle.isNull());
// Allow for separate UI settings for testnets // Allow for separate UI settings for testnets
QApplication::setApplicationName(networkStyle->getAppName()); QApplication::setApplicationName(networkStyle->getAppName());

View file

@ -6,6 +6,9 @@
#include <qt/guiconstants.h> #include <qt/guiconstants.h>
#include <chainparamsbase.h>
#include <tinyformat.h>
#include <QApplication> #include <QApplication>
static const struct { static const struct {
@ -13,11 +16,10 @@ static const struct {
const char *appName; const char *appName;
const int iconColorHueShift; const int iconColorHueShift;
const int iconColorSaturationReduction; const int iconColorSaturationReduction;
const char *titleAddText;
} network_styles[] = { } network_styles[] = {
{"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""}, {"main", QAPP_APP_NAME_DEFAULT, 0, 0},
{"test", QAPP_APP_NAME_TESTNET, 70, 30, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")}, {"test", QAPP_APP_NAME_TESTNET, 70, 30},
{"regtest", QAPP_APP_NAME_REGTEST, 160, 30, "[regtest]"} {"regtest", QAPP_APP_NAME_REGTEST, 160, 30}
}; };
static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles); static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
@ -75,8 +77,9 @@ NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift,
trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256))); trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256)));
} }
const NetworkStyle *NetworkStyle::instantiate(const QString &networkId) const NetworkStyle* NetworkStyle::instantiate(const std::string& networkId)
{ {
std::string titleAddText = networkId == CBaseChainParams::MAIN ? "" : strprintf("[%s]", networkId);
for (unsigned x=0; x<network_styles_count; ++x) for (unsigned x=0; x<network_styles_count; ++x)
{ {
if (networkId == network_styles[x].networkId) if (networkId == network_styles[x].networkId)
@ -85,7 +88,7 @@ const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
network_styles[x].appName, network_styles[x].appName,
network_styles[x].iconColorHueShift, network_styles[x].iconColorHueShift,
network_styles[x].iconColorSaturationReduction, network_styles[x].iconColorSaturationReduction,
network_styles[x].titleAddText); titleAddText.c_str());
} }
} }
return nullptr; return nullptr;

View file

@ -14,7 +14,7 @@ class NetworkStyle
{ {
public: public:
/** Get style associated with provided BIP70 network id, or 0 if not known */ /** Get style associated with provided BIP70 network id, or 0 if not known */
static const NetworkStyle *instantiate(const QString &networkId); static const NetworkStyle* instantiate(const std::string& networkId);
const QString &getAppName() const { return appName; } const QString &getAppName() const { return appName; }
const QIcon &getAppIcon() const { return appIcon; } const QIcon &getAppIcon() const { return appIcon; }

View file

@ -68,8 +68,7 @@ void AppTests::appTests()
m_app.parameterSetup(); m_app.parameterSetup();
m_app.createOptionsModel(true /* reset settings */); m_app.createOptionsModel(true /* reset settings */);
QScopedPointer<const NetworkStyle> style( QScopedPointer<const NetworkStyle> style(NetworkStyle::instantiate(Params().NetworkIDString()));
NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString())));
m_app.setupPlatformStyle(); m_app.setupPlatformStyle();
m_app.createWindow(style.data()); m_app.createWindow(style.data());
connect(&m_app, &BitcoinApplication::windowShown, this, &AppTests::guiTests); connect(&m_app, &BitcoinApplication::windowShown, this, &AppTests::guiTests);