1 // Copyright (c) 2011-2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 #ifndef BITCOIN_QT_OPTIONSMODEL_H
6 #define BITCOIN_QT_OPTIONSMODEL_H
7
8 #include <amount.h>
9 #include <qt/guiconstants.h>
10
11 #include <QAbstractListModel>
12
13 namespace interfaces {
14 class Node;
15 }
16
17 extern const char *DEFAULT_GUI_PROXY_HOST;
18 static constexpr unsigned short DEFAULT_GUI_PROXY_PORT = 9050;
19 static const bool DEFAULT_CHECK_FOR_UPDATES = true;
20
21 /**
22 * Convert configured prune target MiB to displayed GB. Round up to avoid underestimating max disk usage.
23 */
PruneMiBtoGB(int64_t mib)24 static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES; }
25
26 /**
27 * Convert displayed prune target GB to configured MiB. Round down so roundtrip GB -> MiB -> GB conversion is stable.
28 */
PruneGBtoMiB(int gb)29 static inline int64_t PruneGBtoMiB(int gb) { return gb * GB_BYTES / 1024 / 1024; }
30
31 /** Interface from Qt to configuration data structure for Bitcoin client.
32 To Qt, the options are presented as a list with the different options
33 laid out vertically.
34 This can be changed to a tree once the settings become sufficiently
35 complex.
36 */
37 class OptionsModel : public QAbstractListModel
38 {
39 Q_OBJECT
40
41 public:
42 explicit OptionsModel(interfaces::Node& node, QObject *parent = nullptr, bool resetSettings = false);
43
44 enum OptionID {
45 StartAtStartup, // bool
46 HideTrayIcon, // bool
47 MinimizeToTray, // bool
48 MapPortUPnP, // bool
49 MinimizeOnClose, // bool
50 ProxyUse, // bool
51 ProxyIP, // QString
52 ProxyPort, // int
53 ProxyUseTor, // bool
54 ProxyIPTor, // QString
55 ProxyPortTor, // int
56 DisplayUnit, // BitcoinUnits::Unit
57 ThirdPartyTxUrls, // QString
58 Language, // QString
59 CoinControlFeatures, // bool
60 ThreadsScriptVerif, // int
61 Prune, // bool
62 PruneSize, // int
63 DatabaseCache, // int
64 LogEvents, // bool
65 SuperStaking, // bool
66 SpendZeroConfChange, // bool
67 ZeroBalanceAddressToken,// bool
68 Listen, // bool
69 UseChangeAddress, // bool
70 CheckForUpdates, // bool
71 ReserveBalance, // CAmount
72 Theme, // QString
73 OptionIDRowCount,
74 };
75
76 void Init(bool resetSettings = false);
77 void Reset();
78
79 int rowCount(const QModelIndex & parent = QModelIndex()) const;
80 QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
81 bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
82 /** Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal */
83 void setDisplayUnit(const QVariant &value);
84
85 /* Explicit getters */
getHideTrayIcon()86 bool getHideTrayIcon() const { return fHideTrayIcon; }
getMinimizeToTray()87 bool getMinimizeToTray() const { return fMinimizeToTray; }
getMinimizeOnClose()88 bool getMinimizeOnClose() const { return fMinimizeOnClose; }
getDisplayUnit()89 int getDisplayUnit() const { return nDisplayUnit; }
getThirdPartyTxUrls()90 QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
getCoinControlFeatures()91 bool getCoinControlFeatures() const { return fCoinControlFeatures; }
getOverriddenByCommandLine()92 const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
getCheckForUpdates()93 bool getCheckForUpdates() const { return fCheckForUpdates; }
94
95 /* Explicit setters */
96 void SetPruneEnabled(bool prune, bool force = false);
97 void SetPruneTargetGB(int prune_target_gb, bool force = false);
getZeroBalanceAddressToken()98 bool getZeroBalanceAddressToken() const { return bZeroBalanceAddressToken; }
99
100 /* Restart flag helper */
101 void setRestartRequired(bool fRequired);
102 bool isRestartRequired() const;
103
node()104 interfaces::Node& node() const { return m_node; }
105
106 bool getRestartApp() const;
107 void setRestartApp(bool value);
108
109 private:
110 interfaces::Node& m_node;
111 /* Qt-only settings */
112 bool fHideTrayIcon;
113 bool fMinimizeToTray;
114 bool fMinimizeOnClose;
115 QString language;
116 int nDisplayUnit;
117 QString strThirdPartyTxUrls;
118 bool fCoinControlFeatures;
119 /* settings that were overridden by command-line */
120 QString strOverriddenByCommandLine;
121 bool fCheckForUpdates;
122 bool bZeroBalanceAddressToken;
123 QString theme;
124 bool restartApp;
125
126 // Add option to list of GUI options overridden through command line/config file
127 void addOverriddenOption(const std::string &option);
128
129 // Check settings version and upgrade default values if required
130 void checkAndMigrate();
131 Q_SIGNALS:
132 void displayUnitChanged(int unit);
133 void coinControlFeaturesChanged(bool);
134 void hideTrayIconChanged(bool);
135 void zeroBalanceAddressTokenChanged(bool);
136 };
137
138 #endif // BITCOIN_QT_OPTIONSMODEL_H
139