Bitcoin ABC  0.26.3
P2P Digital Currency
optionsmodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 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 #include <cassert>
14 #include <cstdint>
15 
16 namespace interfaces {
17 class Node;
18 }
19 
20 QT_BEGIN_NAMESPACE
21 class QNetworkProxy;
22 QT_END_NAMESPACE
23 
24 extern const char *DEFAULT_GUI_PROXY_HOST;
25 static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050;
26 
31 static inline int PruneMiBtoGB(int64_t mib) {
32  return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES;
33 }
34 
39 static inline int64_t PruneGBtoMiB(int gb) {
40  return gb * GB_BYTES / 1024 / 1024;
41 }
42 
49 class OptionsModel : public QAbstractListModel {
50  Q_OBJECT
51 
52 public:
53  explicit OptionsModel(QObject *parent = nullptr,
54  bool resetSettings = false);
55 
56  enum OptionID {
57  StartAtStartup, // bool
58  HideTrayIcon, // bool
59  MinimizeToTray, // bool
60  MapPortUPnP, // bool
61  MapPortNatpmp, // bool
62  MinimizeOnClose, // bool
63  ProxyUse, // bool
64  ProxyIP, // QString
65  ProxyPort, // int
66  ProxyUseTor, // bool
67  ProxyIPTor, // QString
68  ProxyPortTor, // int
69  DisplayUnit, // BitcoinUnits::Unit
70  ThirdPartyTxUrls, // QString
71  Language, // QString
74  Prune, // bool
75  PruneSize, // int
76  DatabaseCache, // int
78  Listen, // bool
80  };
81 
82  void Init(bool resetSettings = false);
83  void Reset();
84 
85  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
86  QVariant data(const QModelIndex &index,
87  int role = Qt::DisplayRole) const override;
88  bool setData(const QModelIndex &index, const QVariant &value,
89  int role = Qt::EditRole) override;
92  void setDisplayUnit(const QVariant &value);
93 
94  /* Explicit getters */
95  bool getHideTrayIcon() const { return fHideTrayIcon; }
96  bool getMinimizeToTray() const { return fMinimizeToTray; }
97  bool getMinimizeOnClose() const { return fMinimizeOnClose; }
98  int getDisplayUnit() const { return nDisplayUnit; }
99  QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
100  bool getProxySettings(QNetworkProxy &proxy) const;
102  const QString &getOverriddenByCommandLine() {
104  }
105 
106  /* Explicit setters */
107  void SetPruneEnabled(bool prune, bool force = false);
108  void SetPruneTargetGB(int prune_target_gb, bool force = false);
109 
110  /* Restart flag helper */
111  void setRestartRequired(bool fRequired);
112  bool isRestartRequired() const;
113 
115  assert(m_node);
116  return *m_node;
117  }
119  assert(!m_node);
120  m_node = &node;
121  }
122 
123 private:
125  /* Qt-only settings */
129  QString language;
133  /* settings that were overridden by command-line */
135 
136  // Add option to list of GUI options overridden through command line/config
137  // file
138  void addOverriddenOption(const std::string &option);
139 
140  // Check settings version and upgrade default values if required
141  void checkAndMigrate();
142 Q_SIGNALS:
143  void displayUnitChanged(int unit);
146 };
147 
148 #endif // BITCOIN_QT_OPTIONSMODEL_H
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:49
int getDisplayUnit() const
Definition: optionsmodel.h:98
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QString strOverriddenByCommandLine
Definition: optionsmodel.h:134
bool getProxySettings(QNetworkProxy &proxy) const
bool isRestartRequired() const
void Init(bool resetSettings=false)
bool getCoinControlFeatures() const
Definition: optionsmodel.h:101
bool fCoinControlFeatures
Definition: optionsmodel.h:132
interfaces::Node * m_node
Definition: optionsmodel.h:124
void setDisplayUnit(const QVariant &value)
Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal.
void coinControlFeaturesChanged(bool)
QString strThirdPartyTxUrls
Definition: optionsmodel.h:131
OptionsModel(QObject *parent=nullptr, bool resetSettings=false)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void SetPruneTargetGB(int prune_target_gb, bool force=false)
void SetPruneEnabled(bool prune, bool force=false)
void displayUnitChanged(int unit)
bool fHideTrayIcon
Definition: optionsmodel.h:126
bool getMinimizeToTray() const
Definition: optionsmodel.h:96
bool fMinimizeToTray
Definition: optionsmodel.h:127
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
bool getMinimizeOnClose() const
Definition: optionsmodel.h:97
void setNode(interfaces::Node &node)
Definition: optionsmodel.h:118
const QString & getOverriddenByCommandLine()
Definition: optionsmodel.h:102
QString getThirdPartyTxUrls() const
Definition: optionsmodel.h:99
interfaces::Node & node() const
Definition: optionsmodel.h:114
void checkAndMigrate()
bool getHideTrayIcon() const
Definition: optionsmodel.h:95
QString language
Definition: optionsmodel.h:129
void addOverriddenOption(const std::string &option)
bool fMinimizeOnClose
Definition: optionsmodel.h:128
void setRestartRequired(bool fRequired)
void hideTrayIconChanged(bool)
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:55
static constexpr uint64_t GB_BYTES
Definition: guiconstants.h:52
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
Definition: optionsmodel.h:31
static int64_t PruneGBtoMiB(int gb)
Convert displayed prune target GB to configured MiB.
Definition: optionsmodel.h:39
QT_END_NAMESPACE const char * DEFAULT_GUI_PROXY_HOST
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
Definition: optionsmodel.h:25
assert(!tx.IsCoinBase())