aboutsummaryrefslogtreecommitdiff
path: root/src/qt/guiutil.cpp
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-04-17 22:20:59 +0200
committerTheCharlatan <seb.kung@gmail.com>2023-05-09 15:49:14 +0200
commitba8fc7d788932b25864fb260ca14983aa2398c23 (patch)
tree3049d9b5282c243faf7e0ab1e7d2a7ee17937a36 /src/qt/guiutil.cpp
parent401453df419af35957ec711423ac3d93ad512fe8 (diff)
refactor: Replace string chain name constants with ChainTypes
This commit effectively moves the definition of these constants out of the chainparamsbase to their own file. Using the ChainType enums provides better type safety compared to passing around strings. The commit is part of an ongoing effort to decouple the libbitcoinkernel library from the ArgsManager and other functionality that should not be part of the kernel library.
Diffstat (limited to 'src/qt/guiutil.cpp')
-rw-r--r--src/qt/guiutil.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index dc7daed4bc..8d8328aad8 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -21,6 +21,7 @@
#include <protocol.h>
#include <script/script.h>
#include <script/standard.h>
+#include <util/chaintype.h>
#include <util/exception.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
@@ -503,12 +504,12 @@ bool LabelOutOfFocusEventFilter::eventFilter(QObject* watched, QEvent* event)
#ifdef WIN32
fs::path static StartupShortcutPath()
{
- std::string chain = gArgs.GetChainName();
- if (chain == CBaseChainParams::MAIN)
+ ChainType chain = gArgs.GetChainType();
+ if (chain == ChainType::MAIN)
return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin.lnk";
- if (chain == CBaseChainParams::TESTNET) // Remove this special case when CBaseChainParams::TESTNET = "testnet4"
+ if (chain == ChainType::TESTNET) // Remove this special case when testnet CBaseChainParams::DataDir() is incremented to "testnet4"
return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin (testnet).lnk";
- return GetSpecialFolderPath(CSIDL_STARTUP) / fs::u8path(strprintf("Bitcoin (%s).lnk", chain));
+ return GetSpecialFolderPath(CSIDL_STARTUP) / fs::u8path(strprintf("Bitcoin (%s).lnk", ChainTypeToString(chain)));
}
bool GetStartOnSystemStartup()
@@ -541,7 +542,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
// Start client minimized
QString strArgs = "-min";
// Set -testnet /-regtest options
- strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainName()));
+ strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainTypeString()));
// Set the path to the shortcut target
psl->SetPath(pszExePath);
@@ -586,10 +587,10 @@ fs::path static GetAutostartDir()
fs::path static GetAutostartFilePath()
{
- std::string chain = gArgs.GetChainName();
- if (chain == CBaseChainParams::MAIN)
+ ChainType chain = gArgs.GetChainType();
+ if (chain == ChainType::MAIN)
return GetAutostartDir() / "bitcoin.desktop";
- return GetAutostartDir() / fs::u8path(strprintf("bitcoin-%s.desktop", chain));
+ return GetAutostartDir() / fs::u8path(strprintf("bitcoin-%s.desktop", ChainTypeToString(chain)));
}
bool GetStartOnSystemStartup()
@@ -629,15 +630,15 @@ bool SetStartOnSystemStartup(bool fAutoStart)
std::ofstream optionFile{GetAutostartFilePath(), std::ios_base::out | std::ios_base::trunc};
if (!optionFile.good())
return false;
- std::string chain = gArgs.GetChainName();
+ ChainType chain = gArgs.GetChainType();
// Write a bitcoin.desktop file to the autostart directory:
optionFile << "[Desktop Entry]\n";
optionFile << "Type=Application\n";
- if (chain == CBaseChainParams::MAIN)
+ if (chain == ChainType::MAIN)
optionFile << "Name=Bitcoin\n";
else
- optionFile << strprintf("Name=Bitcoin (%s)\n", chain);
- optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", chain);
+ optionFile << strprintf("Name=Bitcoin (%s)\n", ChainTypeToString(chain));
+ optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", ChainTypeToString(chain));
optionFile << "Terminal=false\n";
optionFile << "Hidden=false\n";
optionFile.close();