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