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