Bitcoin Core  0.20.99
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  HideTrayIcon, // bool
49  MinimizeToTray, // bool
50  MapPortUPnP, // bool
51  MinimizeOnClose, // bool
52  ProxyUse, // bool
53  ProxyIP, // QString
54  ProxyPort, // int
55  ProxyUseTor, // bool
56  ProxyIPTor, // QString
57  ProxyPortTor, // int
58  DisplayUnit, // BitcoinUnits::Unit
59  ThirdPartyTxUrls, // QString
60  Language, // QString
63  Prune, // bool
64  PruneSize, // int
65  DatabaseCache, // int
67  Listen, // bool
69  };
70 
71  void Init(bool resetSettings = false);
72  void Reset();
73 
74  int rowCount(const QModelIndex & parent = QModelIndex()) const override;
75  QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
76  bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
78  void setDisplayUnit(const QVariant &value);
79 
80  /* Explicit getters */
81  bool getHideTrayIcon() const { return fHideTrayIcon; }
82  bool getMinimizeToTray() const { return fMinimizeToTray; }
83  bool getMinimizeOnClose() const { return fMinimizeOnClose; }
84  int getDisplayUnit() const { return nDisplayUnit; }
85  QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
86  bool getCoinControlFeatures() const { return fCoinControlFeatures; }
87  const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
88 
89  /* Explicit setters */
90  void SetPruneEnabled(bool prune, bool force = false);
91  void SetPruneTargetGB(int prune_target_gb, bool force = false);
92 
93  /* Restart flag helper */
94  void setRestartRequired(bool fRequired);
95  bool isRestartRequired() const;
96 
97  interfaces::Node& node() const { assert(m_node); return *m_node; }
98  void setNode(interfaces::Node& node) { assert(!m_node); m_node = &node; }
99 
100 private:
102  /* Qt-only settings */
106  QString language;
110  /* settings that were overridden by command-line */
112 
113  // Add option to list of GUI options overridden through command line/config file
114  void addOverriddenOption(const std::string &option);
115 
116  // Check settings version and upgrade default values if required
117  void checkAndMigrate();
118 Q_SIGNALS:
119  void displayUnitChanged(int unit);
120  void coinControlFeaturesChanged(bool);
121  void hideTrayIconChanged(bool);
122 };
123 
124 #endif // BITCOIN_QT_OPTIONSMODEL_H
NodeContext & m_node
Definition: chain.cpp:411
const QString & getOverriddenByCommandLine()
Definition: optionsmodel.h:87
QString language
Definition: optionsmodel.h:106
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:105
int getDisplayUnit() const
Definition: optionsmodel.h:84
interfaces::Node & node() const
Definition: optionsmodel.h:97
bool fHideTrayIcon
Definition: optionsmodel.h:103
bool fMinimizeToTray
Definition: optionsmodel.h:104
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
Definition: optionsmodel.h:26
void setNode(interfaces::Node &node)
Definition: optionsmodel.h:98
QString getThirdPartyTxUrls() const
Definition: optionsmodel.h:85
bool fCoinControlFeatures
Definition: optionsmodel.h:109
bool getCoinControlFeatures() const
Definition: optionsmodel.h:86
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
Definition: optionsmodel.h:21
bool getMinimizeOnClose() const
Definition: optionsmodel.h:83
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:39
QString strThirdPartyTxUrls
Definition: optionsmodel.h:108
bool getMinimizeToTray() const
Definition: optionsmodel.h:82
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:52
bool getHideTrayIcon() const
Definition: optionsmodel.h:81
QString strOverriddenByCommandLine
Definition: optionsmodel.h:111