Bitcoin Core  21.99.0
P2P Digital Currency
optionsmodel.h
Go to the documentation of this file.
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 <cstdint>
10 #include <qt/guiconstants.h>
11 
12 #include <QAbstractListModel>
13 
14 #include <assert.h>
15 
16 namespace interfaces {
17 class Node;
18 }
19 
20 extern const char *DEFAULT_GUI_PROXY_HOST;
21 static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050;
22 
26 static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES; }
27 
31 static inline int64_t PruneGBtoMiB(int gb) { return gb * GB_BYTES / 1024 / 1024; }
32 
39 class OptionsModel : public QAbstractListModel
40 {
41  Q_OBJECT
42 
43 public:
44  explicit OptionsModel(QObject *parent = nullptr, bool resetSettings = false);
45 
46  enum OptionID {
47  StartAtStartup, // bool
48  ShowTrayIcon, // bool
49  MinimizeToTray, // bool
50  MapPortUPnP, // bool
51  MapPortNatpmp, // bool
52  MinimizeOnClose, // bool
53  ProxyUse, // bool
54  ProxyIP, // QString
55  ProxyPort, // int
56  ProxyUseTor, // bool
57  ProxyIPTor, // QString
58  ProxyPortTor, // int
59  DisplayUnit, // BitcoinUnits::Unit
60  ThirdPartyTxUrls, // QString
61  Language, // QString
64  Prune, // bool
65  PruneSize, // int
66  DatabaseCache, // int
68  Listen, // bool
70  };
71 
72  void Init(bool resetSettings = false);
73  void Reset();
74 
75  int rowCount(const QModelIndex & parent = QModelIndex()) const override;
76  QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
77  bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
79  void setDisplayUnit(const QVariant &value);
80 
81  /* Explicit getters */
82  bool getShowTrayIcon() const { return m_show_tray_icon; }
83  bool getMinimizeToTray() const { return fMinimizeToTray; }
84  bool getMinimizeOnClose() const { return fMinimizeOnClose; }
85  int getDisplayUnit() const { return nDisplayUnit; }
86  QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
87  bool getCoinControlFeatures() const { return fCoinControlFeatures; }
88  const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
89 
90  /* Explicit setters */
91  void SetPruneEnabled(bool prune, bool force = false);
92  void SetPruneTargetGB(int prune_target_gb, bool force = false);
93 
94  /* Restart flag helper */
95  void setRestartRequired(bool fRequired);
96  bool isRestartRequired() const;
97 
98  interfaces::Node& node() const { assert(m_node); return *m_node; }
100 
101 private:
103  /* Qt-only settings */
107  QString language;
111  /* settings that were overridden by command-line */
113 
114  // Add option to list of GUI options overridden through command line/config file
115  void addOverriddenOption(const std::string &option);
116 
117  // Check settings version and upgrade default values if required
118  void checkAndMigrate();
119 Q_SIGNALS:
120  void displayUnitChanged(int unit);
121  void coinControlFeaturesChanged(bool);
122  void showTrayIconChanged(bool);
123 };
124 
125 #endif // BITCOIN_QT_OPTIONSMODEL_H
assert(!tx.IsCoinBase())
NodeContext & m_node
Definition: interfaces.cpp:660
const QString & getOverriddenByCommandLine()
Definition: optionsmodel.h:88
QString language
Definition: optionsmodel.h:107
bool getShowTrayIcon() const
Definition: optionsmodel.h:82
static constexpr uint64_t GB_BYTES
Definition: guiconstants.h:53
const char * DEFAULT_GUI_PROXY_HOST
static int64_t PruneGBtoMiB(int gb)
Convert displayed prune target GB to configured MiB.
Definition: optionsmodel.h:31
bool fMinimizeOnClose
Definition: optionsmodel.h:106
int getDisplayUnit() const
Definition: optionsmodel.h:85
interfaces::Node & node() const
Definition: optionsmodel.h:98
bool fMinimizeToTray
Definition: optionsmodel.h:105
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
Definition: optionsmodel.h:26
bool m_show_tray_icon
Definition: optionsmodel.h:104
void setNode(interfaces::Node &node)
Definition: optionsmodel.h:99
QString getThirdPartyTxUrls() const
Definition: optionsmodel.h:86
bool fCoinControlFeatures
Definition: optionsmodel.h:110
bool getCoinControlFeatures() const
Definition: optionsmodel.h:87
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
Definition: optionsmodel.h:21
bool getMinimizeOnClose() const
Definition: optionsmodel.h:84
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:39
QString strThirdPartyTxUrls
Definition: optionsmodel.h:109
bool getMinimizeToTray() const
Definition: optionsmodel.h:83
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:52
QString strOverriddenByCommandLine
Definition: optionsmodel.h:112