Bitcoin Core  27.99.0
P2P Digital Currency
optionsmodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2022 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 <cstdint>
9 #include <qt/bitcoinunits.h>
10 #include <qt/guiconstants.h>
11 
12 #include <QAbstractListModel>
13 #include <QFont>
14 
15 #include <assert.h>
16 #include <variant>
17 
18 struct bilingual_str;
19 namespace interfaces {
20 class Node;
21 }
22 
23 extern const char *DEFAULT_GUI_PROXY_HOST;
24 static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050;
25 
29 static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES; }
30 
34 static inline int64_t PruneGBtoMiB(int gb) { return gb * GB_BYTES / 1024 / 1024; }
35 
42 class OptionsModel : public QAbstractListModel
43 {
44  Q_OBJECT
45 
46 public:
47  explicit OptionsModel(interfaces::Node& node, QObject *parent = nullptr);
48 
49  enum OptionID {
50  StartAtStartup, // bool
51  ShowTrayIcon, // bool
52  MinimizeToTray, // bool
53  MapPortUPnP, // bool
54  MapPortNatpmp, // bool
55  MinimizeOnClose, // bool
56  ProxyUse, // bool
57  ProxyIP, // QString
58  ProxyPort, // int
59  ProxyUseTor, // bool
60  ProxyIPTor, // QString
61  ProxyPortTor, // int
62  DisplayUnit, // BitcoinUnit
63  ThirdPartyTxUrls, // QString
64  Language, // QString
65  FontForMoney, // FontChoice
69  Prune, // bool
70  PruneSize, // int
71  DatabaseCache, // int
72  ExternalSignerPath, // QString
74  Listen, // bool
75  Server, // bool
77  MaskValues, // bool
79  };
80 
81  enum class FontChoiceAbstract {
84  };
85  typedef std::variant<FontChoiceAbstract, QFont> FontChoice;
87  static QFont getFontForChoice(const FontChoice& fc);
88 
89  bool Init(bilingual_str& error);
90  void Reset();
91 
92  int rowCount(const QModelIndex & parent = QModelIndex()) const override;
93  QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
94  bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
95  QVariant getOption(OptionID option, const std::string& suffix="") const;
96  bool setOption(OptionID option, const QVariant& value, const std::string& suffix="");
98  void setDisplayUnit(const QVariant& new_unit);
99 
100  /* Explicit getters */
101  bool getShowTrayIcon() const { return m_show_tray_icon; }
102  bool getMinimizeToTray() const { return fMinimizeToTray; }
103  bool getMinimizeOnClose() const { return fMinimizeOnClose; }
105  QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
106  QFont getFontForMoney() const;
111 
113  bool hasSigner();
114 
115  /* Explicit setters */
116  void SetPruneTargetGB(int prune_target_gb);
117 
118  /* Restart flag helper */
119  void setRestartRequired(bool fRequired);
120  bool isRestartRequired() const;
121 
122  interfaces::Node& node() const { return m_node; }
123 
124 private:
126  /* Qt-only settings */
130  QString language;
138 
139  /* settings that were overridden by command-line */
141 
142  static QString FontChoiceToString(const OptionsModel::FontChoice&);
143  static FontChoice FontChoiceFromString(const QString&);
144 
145  // Add option to list of GUI options overridden through command line/config file
146  void addOverriddenOption(const std::string &option);
147 
148  // Check settings version and upgrade default values if required
149  void checkAndMigrate();
150 
151 Q_SIGNALS:
155  void fontForMoneyChanged(const QFont&);
156 };
157 
158 Q_DECLARE_METATYPE(OptionsModel::FontChoice)
159 
160 #endif // BITCOIN_QT_OPTIONSMODEL_H
Unit
Bitcoin units.
Definition: bitcoinunits.h:42
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:43
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
BitcoinUnit m_display_bitcoin_unit
Definition: optionsmodel.h:131
QString strOverriddenByCommandLine
Definition: optionsmodel.h:140
std::variant< FontChoiceAbstract, QFont > FontChoice
Definition: optionsmodel.h:85
bool isRestartRequired() const
QFont getFontForMoney() const
bool getCoinControlFeatures() const
Definition: optionsmodel.h:107
bool fCoinControlFeatures
Definition: optionsmodel.h:134
bool getEnablePSBTControls() const
Definition: optionsmodel.h:109
void coinControlFeaturesChanged(bool)
QString strThirdPartyTxUrls
Definition: optionsmodel.h:132
bool getSubFeeFromAmount() const
Definition: optionsmodel.h:108
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool m_sub_fee_from_amount
Definition: optionsmodel.h:135
bool setOption(OptionID option, const QVariant &value, const std::string &suffix="")
interfaces::Node & m_node
Definition: optionsmodel.h:125
void displayUnitChanged(BitcoinUnit unit)
void SetPruneTargetGB(int prune_target_gb)
bool Init(bilingual_str &error)
void showTrayIconChanged(bool)
OptionsModel(interfaces::Node &node, QObject *parent=nullptr)
bool getMinimizeToTray() const
Definition: optionsmodel.h:102
bool fMinimizeToTray
Definition: optionsmodel.h:128
BitcoinUnit getDisplayUnit() const
Definition: optionsmodel.h:104
bool getShowTrayIcon() const
Definition: optionsmodel.h:101
bool hasSigner()
Whether -signer was set or not.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
bool m_mask_values
Definition: optionsmodel.h:137
bool m_enable_psbt_controls
Definition: optionsmodel.h:136
QVariant getOption(OptionID option, const std::string &suffix="") const
bool getMinimizeOnClose() const
Definition: optionsmodel.h:103
void setDisplayUnit(const QVariant &new_unit)
Updates current unit in memory, settings and emits displayUnitChanged(new_unit) signal.
FontChoice m_font_money
Definition: optionsmodel.h:133
static FontChoice FontChoiceFromString(const QString &)
static QFont getFontForChoice(const FontChoice &fc)
const QString & getOverriddenByCommandLine()
Definition: optionsmodel.h:110
QString getThirdPartyTxUrls() const
Definition: optionsmodel.h:105
interfaces::Node & node() const
Definition: optionsmodel.h:122
void checkAndMigrate()
void fontForMoneyChanged(const QFont &)
QString language
Definition: optionsmodel.h:130
static QString FontChoiceToString(const OptionsModel::FontChoice &)
void addOverriddenOption(const std::string &option)
static const FontChoice UseBestSystemFont
Definition: optionsmodel.h:86
bool fMinimizeOnClose
Definition: optionsmodel.h:129
void setRestartRequired(bool fRequired)
bool m_show_tray_icon
Definition: optionsmodel.h:127
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:70
static constexpr uint64_t GB_BYTES
Definition: guiconstants.h:57
Definition: init.h:25
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
Definition: optionsmodel.h:29
static int64_t PruneGBtoMiB(int gb)
Convert displayed prune target GB to configured MiB.
Definition: optionsmodel.h:34
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
Definition: optionsmodel.h:24
const char * DEFAULT_GUI_PROXY_HOST
Bilingual messages:
Definition: translation.h:18