Bitcoin Core  24.99.0
P2P Digital Currency
optionsmodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2021 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 
14 #include <assert.h>
15 
16 struct bilingual_str;
17 namespace interfaces {
18 class Node;
19 }
20 
21 extern const char *DEFAULT_GUI_PROXY_HOST;
22 static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050;
23 
27 static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES; }
28 
32 static inline int64_t PruneGBtoMiB(int gb) { return gb * GB_BYTES / 1024 / 1024; }
33 
40 class OptionsModel : public QAbstractListModel
41 {
42  Q_OBJECT
43 
44 public:
45  explicit OptionsModel(interfaces::Node& node, QObject *parent = nullptr);
46 
47  enum OptionID {
48  StartAtStartup, // bool
49  ShowTrayIcon, // bool
50  MinimizeToTray, // bool
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, // BitcoinUnit
61  ThirdPartyTxUrls, // QString
62  Language, // QString
67  Prune, // bool
68  PruneSize, // int
69  DatabaseCache, // int
70  ExternalSignerPath, // QString
72  Listen, // bool
73  Server, // bool
76  };
77 
78  bool Init(bilingual_str& error);
79  void Reset();
80 
81  int rowCount(const QModelIndex & parent = QModelIndex()) const override;
82  QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
83  bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
84  QVariant getOption(OptionID option) const;
85  bool setOption(OptionID option, const QVariant& value);
87  void setDisplayUnit(const QVariant& new_unit);
88 
89  /* Explicit getters */
90  bool getShowTrayIcon() const { return m_show_tray_icon; }
91  bool getMinimizeToTray() const { return fMinimizeToTray; }
92  bool getMinimizeOnClose() const { return fMinimizeOnClose; }
94  QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
97  bool getSubFeeFromAmount() const { return m_sub_fee_from_amount; }
100 
101  /* Explicit setters */
102  void SetPruneTargetGB(int prune_target_gb);
103 
104  /* Restart flag helper */
105  void setRestartRequired(bool fRequired);
106  bool isRestartRequired() const;
107 
108  interfaces::Node& node() const { return m_node; }
109 
110 private:
112  /* Qt-only settings */
116  QString language;
123 
128  QString m_proxy_ip;
129  QString m_proxy_port;
130  QString m_onion_ip;
131  QString m_onion_port;
132 
133  /* settings that were overridden by command-line */
135 
136  // Add option to list of GUI options overridden through command line/config file
137  void addOverriddenOption(const std::string &option);
138 
139  // Check settings version and upgrade default values if required
140  void checkAndMigrate();
141 
142 Q_SIGNALS:
147 };
148 
149 #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:41
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QString m_onion_ip
Definition: optionsmodel.h:130
BitcoinUnit m_display_bitcoin_unit
Definition: optionsmodel.h:117
QString strOverriddenByCommandLine
Definition: optionsmodel.h:134
bool m_use_embedded_monospaced_font
Definition: optionsmodel.h:119
bool isRestartRequired() const
bool getUseEmbeddedMonospacedFont() const
Definition: optionsmodel.h:95
bool getCoinControlFeatures() const
Definition: optionsmodel.h:96
QString m_proxy_port
Definition: optionsmodel.h:129
bool fCoinControlFeatures
Definition: optionsmodel.h:120
bool getEnablePSBTControls() const
Definition: optionsmodel.h:98
int m_prune_size_gb
In-memory settings for display.
Definition: optionsmodel.h:127
QString m_proxy_ip
Definition: optionsmodel.h:128
void coinControlFeaturesChanged(bool)
QString strThirdPartyTxUrls
Definition: optionsmodel.h:118
bool getSubFeeFromAmount() const
Definition: optionsmodel.h:97
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool m_sub_fee_from_amount
Definition: optionsmodel.h:121
@ UseEmbeddedMonospacedFont
Definition: optionsmodel.h:63
interfaces::Node & m_node
Definition: optionsmodel.h:111
void displayUnitChanged(BitcoinUnit unit)
void SetPruneTargetGB(int prune_target_gb)
bool Init(bilingual_str &error)
QVariant getOption(OptionID option) const
void showTrayIconChanged(bool)
OptionsModel(interfaces::Node &node, QObject *parent=nullptr)
bool getMinimizeToTray() const
Definition: optionsmodel.h:91
bool fMinimizeToTray
Definition: optionsmodel.h:114
BitcoinUnit getDisplayUnit() const
Definition: optionsmodel.h:93
bool getShowTrayIcon() const
Definition: optionsmodel.h:90
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
bool setOption(OptionID option, const QVariant &value)
QString m_onion_port
Definition: optionsmodel.h:131
bool m_enable_psbt_controls
Definition: optionsmodel.h:122
bool getMinimizeOnClose() const
Definition: optionsmodel.h:92
void setDisplayUnit(const QVariant &new_unit)
Updates current unit in memory, settings and emits displayUnitChanged(new_unit) signal.
const QString & getOverriddenByCommandLine()
Definition: optionsmodel.h:99
QString getThirdPartyTxUrls() const
Definition: optionsmodel.h:94
interfaces::Node & node() const
Definition: optionsmodel.h:108
void checkAndMigrate()
QString language
Definition: optionsmodel.h:116
void addOverriddenOption(const std::string &option)
void useEmbeddedMonospacedFontChanged(bool)
bool fMinimizeOnClose
Definition: optionsmodel.h:115
void setRestartRequired(bool fRequired)
bool m_show_tray_icon
Definition: optionsmodel.h:113
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:27
static int64_t PruneGBtoMiB(int gb)
Convert displayed prune target GB to configured MiB.
Definition: optionsmodel.h:32
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
Definition: optionsmodel.h:22
const char * DEFAULT_GUI_PROXY_HOST
Bilingual messages:
Definition: translation.h:18
bool error(const char *fmt, const Args &... args)
Definition: system.h:48