optionsmodel.h raw
1 // Copyright (c) 2011-2022 The Limenka 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 LIMENKA_QT_OPTIONSMODEL_H
6 #define LIMENKA_QT_OPTIONSMODEL_H
7
8 #include <cstdint>
9 #include <qt/limenkaunits.h>
10 #include <qt/guiconstants.h>
11
12 #include <QAbstractListModel>
13 #include <QFont>
14 #include <QString>
15
16 #include <assert.h>
17 #include <map>
18 #include <utility>
19 #include <variant>
20
21 struct bilingual_str;
22 enum class OutputType;
23
24 namespace interfaces {
25 class Node;
26 }
27
28 extern const char *DEFAULT_GUI_PROXY_HOST;
29 static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050;
30
31 std::pair<QString, QString> GetOutputTypeDescription(const OutputType type);
32
33 /** Interface from Qt to configuration data structure for Limenka client.
34 To Qt, the options are presented as a list with the different options
35 laid out vertically.
36 This can be changed to a tree once the settings become sufficiently
37 complex.
38 */
39 class OptionsModel : public QAbstractListModel
40 {
41 Q_OBJECT
42
43 public:
44 explicit OptionsModel(interfaces::Node& node, QObject *parent = nullptr);
45
46 enum OptionID {
47 StartAtStartup, // bool
48 ShowTrayIcon, // bool
49 MinimizeToTray, // bool
50 NetworkPort, // int
51 MapPortUPnP, // bool
52 MapPortNatpmp, // bool
53 MinimizeOnClose, // bool
54 ProxyUse, // bool
55 ProxyIP, // QString
56 ProxyPort, // int
57 ProxyUseTor, // bool
58 ProxyIPTor, // QString
59 ProxyPortTor, // int
60 DisplayUnit, // LimenkaUnit
61 DisplayAddresses, // bool
62 ThirdPartyTxUrls, // QString
63 Language, // QString
64 FontForMoney, // FontChoice
65 FontForQRCodes, // FontChoice
66 PeersTabAlternatingRowColors, // bool
67 walletrbf, // bool
68 CoinControlFeatures, // bool
69 SubFeeFromAmount, // bool
70 ThreadsScriptVerif, // int
71 PruneTristate, // Qt::CheckState
72 PruneSizeMiB, // int
73 DatabaseCache, // int
74 ExternalSignerPath, // QString
75 SpendZeroConfChange, // bool
76 addresstype, // QString
77 Listen, // bool
78 Server, // bool
79 EnablePSBTControls, // bool
80 MaskValues, // bool
81 maxuploadtarget,
82 peerbloomfilters, // bool
83 peerblockfilters, // bool
84 mempoolreplacement,
85 mempooltruc,
86 maxorphantx,
87 maxmempool,
88 incrementalrelayfee,
89 mempoolexpiry,
90 rejectunknownscripts, // bool
91 rejectunknownwitness, // bool
92 rejectparasites, // bool
93 rejecttokens, // bool
94 subdustfeepenalty, // bool
95 rejectspkreuse, // bool
96 minrelaytxfee,
97 minrelaycoinblocks,
98 minrelaymaturity,
99 bytespersigop,
100 bytespersigopstrict,
101 limitancestorcount,
102 limitancestorsize,
103 limitdescendantcount,
104 limitdescendantsize,
105 rejectbarepubkey, // bool
106 rejectbaremultisig, // bool
107 permitephemeral,
108 rejectbareanchor, // bool
109 rejectbaredatacarrier, // bool
110 maxscriptsize,
111 maxtxlegacysigops,
112 datacarriercost, // double
113 datacarriersize,
114 rejectnonstddatacarrier, // bool
115 dustrelayfee,
116 dustdynamic, // QString
117 blockmintxfee,
118 blockmaxsize,
119 blockprioritysize,
120 blockmaxweight,
121 blockreconstructionextratxn,
122 blockreconstructionextratxnsize,
123 corepolicy,
124 OptionIDRowCount,
125 };
126
127 enum class FontChoiceAbstract {
128 EmbeddedFont,
129 BestSystemFont,
130 };
131 typedef std::variant<FontChoiceAbstract, QFont> FontChoice;
132 static inline const FontChoice UseBestSystemFont{FontChoiceAbstract::BestSystemFont};
133 static QFont getFontForChoice(const FontChoice& fc);
134
135 bool Init(bilingual_str& error);
136 void Reset();
137
138 int rowCount(const QModelIndex & parent = QModelIndex()) const override;
139 QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
140 bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
141 QVariant getOption(OptionID option, const std::string& suffix="") const;
142 bool setOption(OptionID option, const QVariant& value, const std::string& suffix="");
143 /** Updates current unit in memory, settings and emits displayUnitChanged(new_unit) signal */
144 void setDisplayUnit(const QVariant& new_unit);
145
146 /* Explicit getters */
147 bool getShowTrayIcon() const { return m_show_tray_icon; }
148 bool getMinimizeToTray() const { return fMinimizeToTray; }
149 bool getMinimizeOnClose() const { return fMinimizeOnClose; }
150 LimenkaUnit getDisplayUnit() const { return m_display_limenka_unit; }
151 bool getDisplayAddresses() const { return bDisplayAddresses; }
152 QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
153 QFont getFontForMoney(LimenkaUnit) const;
154 FontChoice getFontChoiceForQRCodes() const { return m_font_qrcodes; }
155 bool getPeersTabAlternatingRowColors() const { return m_peers_tab_alternating_row_colors; }
156 bool getCoinControlFeatures() const { return fCoinControlFeatures; }
157 bool getSubFeeFromAmount() const { return m_sub_fee_from_amount; }
158 bool getEnablePSBTControls() const { return m_enable_psbt_controls; }
159 const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
160
161 /** Whether -signer was set or not */
162 bool hasSigner();
163
164 /* Explicit setters */
165 void SetPruneTargetMiB(int prune_target_mib);
166
167 /* Restart flag helper */
168 void setRestartRequired(bool fRequired);
169 bool isRestartRequired() const;
170
171 interfaces::Node& node() const { return m_node; }
172
173 private:
174 interfaces::Node& m_node;
175 /* Qt-only settings */
176 bool m_show_tray_icon;
177 bool fMinimizeToTray;
178 bool fMinimizeOnClose;
179 QString language;
180 LimenkaUnit m_display_limenka_unit;
181 bool bDisplayAddresses;
182 QString strThirdPartyTxUrls;
183 FontChoice m_font_money{FontChoiceAbstract::EmbeddedFont};
184 bool m_font_money_supports_tonal;
185 FontChoice m_font_qrcodes{FontChoiceAbstract::EmbeddedFont};
186 bool m_peers_tab_alternating_row_colors;
187 bool fCoinControlFeatures;
188 bool m_sub_fee_from_amount;
189 bool m_enable_psbt_controls;
190 bool m_mask_values;
191
192 /* settings that were overridden by command-line */
193 QString strOverriddenByCommandLine;
194 bool m_prune_forced_by_gui{false};
195
196 static QString FontChoiceToString(const OptionsModel::FontChoice&);
197 static FontChoice FontChoiceFromString(const QString&);
198
199 /* rwconf settings that require a restart */
200 bool f_peerbloomfilters;
201 bool f_rejectspkreuse;
202
203 // Add option to list of GUI options overridden through command line/config file
204 void addOverriddenOption(const std::string &option);
205
206 // Check settings version and upgrade default values if required
207 void checkAndMigrate();
208
209 Q_SIGNALS:
210 void displayUnitChanged(LimenkaUnit unit);
211 void coinControlFeaturesChanged(bool);
212 void addresstypeChanged(OutputType);
213 void showTrayIconChanged(bool);
214 void fontForMoneyChanged(const QFont&);
215 void fontForQRCodesChanged(const FontChoice&);
216 void peersTabAlternatingRowColorsChanged(bool);
217 };
218
219 Q_DECLARE_METATYPE(OptionsModel::FontChoice)
220
221 #endif // LIMENKA_QT_OPTIONSMODEL_H
222