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