Bitcoin ABC  0.24.7
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  MinimizeOnClose, // bool
62  ProxyUse, // bool
63  ProxyIP, // QString
64  ProxyPort, // int
65  ProxyUseTor, // bool
66  ProxyIPTor, // QString
67  ProxyPortTor, // int
68  DisplayUnit, // BitcoinUnits::Unit
69  ThirdPartyTxUrls, // QString
70  Language, // QString
73  Prune, // bool
74  PruneSize, // int
75  DatabaseCache, // int
77  Listen, // bool
79  };
80 
81  void Init(bool resetSettings = false);
82  void Reset();
83 
84  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
85  QVariant data(const QModelIndex &index,
86  int role = Qt::DisplayRole) const override;
87  bool setData(const QModelIndex &index, const QVariant &value,
88  int role = Qt::EditRole) override;
91  void setDisplayUnit(const QVariant &value);
92 
93  /* Explicit getters */
94  bool getHideTrayIcon() const { return fHideTrayIcon; }
95  bool getMinimizeToTray() const { return fMinimizeToTray; }
96  bool getMinimizeOnClose() const { return fMinimizeOnClose; }
97  int getDisplayUnit() const { return nDisplayUnit; }
98  QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
99  bool getProxySettings(QNetworkProxy &proxy) const;
101  const QString &getOverriddenByCommandLine() {
103  }
104 
105  /* Explicit setters */
106  void SetPruneEnabled(bool prune, bool force = false);
107  void SetPruneTargetGB(int prune_target_gb, bool force = false);
108 
109  /* Restart flag helper */
110  void setRestartRequired(bool fRequired);
111  bool isRestartRequired() const;
112 
114  assert(m_node);
115  return *m_node;
116  }
118  assert(!m_node);
119  m_node = &node;
120  }
121 
122 private:
124  /* Qt-only settings */
128  QString language;
132  /* settings that were overridden by command-line */
134 
135  // Add option to list of GUI options overridden through command line/config
136  // file
137  void addOverriddenOption(const std::string &option);
138 
139  // Check settings version and upgrade default values if required
140  void checkAndMigrate();
141 Q_SIGNALS:
142  void displayUnitChanged(int unit);
143  void coinControlFeaturesChanged(bool);
144  void hideTrayIconChanged(bool);
145 };
146 
147 #endif // BITCOIN_QT_OPTIONSMODEL_H
PruneMiBtoGB
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
Definition: optionsmodel.h:31
interfaces
Definition: dummywallet.cpp:12
OptionsModel::getMinimizeOnClose
bool getMinimizeOnClose() const
Definition: optionsmodel.h:96
OptionsModel::MinimizeOnClose
@ MinimizeOnClose
Definition: optionsmodel.h:61
OptionsModel::ThreadsScriptVerif
@ ThreadsScriptVerif
Definition: optionsmodel.h:72
OptionsModel::PruneSize
@ PruneSize
Definition: optionsmodel.h:74
OptionsModel::DisplayUnit
@ DisplayUnit
Definition: optionsmodel.h:68
OptionsModel::getOverriddenByCommandLine
const QString & getOverriddenByCommandLine()
Definition: optionsmodel.h:101
OptionsModel::Listen
@ Listen
Definition: optionsmodel.h:77
OptionsModel::fMinimizeOnClose
bool fMinimizeOnClose
Definition: optionsmodel.h:127
DEFAULT_GUI_PROXY_PORT
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
Definition: optionsmodel.h:25
OptionsModel::OptionID
OptionID
Definition: optionsmodel.h:56
OptionsModel::SetPruneEnabled
void SetPruneEnabled(bool prune, bool force=false)
Definition: optionsmodel.cpp:285
OptionsModel::displayUnitChanged
void displayUnitChanged(int unit)
OptionsModel::ProxyPort
@ ProxyPort
Definition: optionsmodel.h:64
OptionsModel::getHideTrayIcon
bool getHideTrayIcon() const
Definition: optionsmodel.h:94
OptionsModel::DatabaseCache
@ DatabaseCache
Definition: optionsmodel.h:75
OptionsModel::SpendZeroConfChange
@ SpendZeroConfChange
Definition: optionsmodel.h:76
OptionsModel::setDisplayUnit
void setDisplayUnit(const QVariant &value)
Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal.
Definition: optionsmodel.cpp:524
OptionsModel::nDisplayUnit
int nDisplayUnit
Definition: optionsmodel.h:129
OptionsModel::m_node
interfaces::Node * m_node
Definition: optionsmodel.h:123
OptionsModel::OptionIDRowCount
@ OptionIDRowCount
Definition: optionsmodel.h:78
OptionsModel::MinimizeToTray
@ MinimizeToTray
Definition: optionsmodel.h:59
OptionsModel::Reset
void Reset()
Definition: optionsmodel.cpp:221
OptionsModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: optionsmodel.cpp:375
OptionsModel::ProxyUse
@ ProxyUse
Definition: optionsmodel.h:62
OptionsModel::node
interfaces::Node & node() const
Definition: optionsmodel.h:113
OptionsModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: optionsmodel.cpp:246
OptionsModel::addOverriddenOption
void addOverriddenOption(const std::string &option)
Definition: optionsmodel.cpp:34
OptionsModel
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:49
OptionsModel::getProxySettings
bool getProxySettings(QNetworkProxy &proxy) const
Definition: optionsmodel.cpp:533
DEFAULT_GUI_PROXY_HOST
const QT_END_NAMESPACE char * DEFAULT_GUI_PROXY_HOST
Definition: optionsmodel.cpp:25
OptionsModel::OptionsModel
OptionsModel(QObject *parent=nullptr, bool resetSettings=false)
Definition: optionsmodel.cpp:29
OptionsModel::isRestartRequired
bool isRestartRequired() const
Definition: optionsmodel.cpp:555
OptionsModel::SetPruneTargetGB
void SetPruneTargetGB(int prune_target_gb, bool force=false)
Definition: optionsmodel.cpp:300
OptionsModel::strThirdPartyTxUrls
QString strThirdPartyTxUrls
Definition: optionsmodel.h:130
OptionsModel::getCoinControlFeatures
bool getCoinControlFeatures() const
Definition: optionsmodel.h:100
OptionsModel::StartAtStartup
@ StartAtStartup
Definition: optionsmodel.h:57
OptionsModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: optionsmodel.cpp:310
OptionsModel::checkAndMigrate
void checkAndMigrate()
Definition: optionsmodel.cpp:560
OptionsModel::strOverriddenByCommandLine
QString strOverriddenByCommandLine
Definition: optionsmodel.h:133
OptionsModel::HideTrayIcon
@ HideTrayIcon
Definition: optionsmodel.h:58
OptionsModel::fMinimizeToTray
bool fMinimizeToTray
Definition: optionsmodel.h:126
OptionsModel::ProxyIPTor
@ ProxyIPTor
Definition: optionsmodel.h:66
OptionsModel::ProxyUseTor
@ ProxyUseTor
Definition: optionsmodel.h:65
OptionsModel::language
QString language
Definition: optionsmodel.h:128
OptionsModel::ProxyPortTor
@ ProxyPortTor
Definition: optionsmodel.h:67
OptionsModel::CoinControlFeatures
@ CoinControlFeatures
Definition: optionsmodel.h:71
OptionsModel::fCoinControlFeatures
bool fCoinControlFeatures
Definition: optionsmodel.h:131
OptionsModel::fHideTrayIcon
bool fHideTrayIcon
Definition: optionsmodel.h:125
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:55
GB_BYTES
static constexpr uint64_t GB_BYTES
Definition: guiconstants.h:52
OptionsModel::Init
void Init(bool resetSettings=false)
Definition: optionsmodel.cpp:41
OptionsModel::setNode
void setNode(interfaces::Node &node)
Definition: optionsmodel.h:117
OptionsModel::ProxyIP
@ ProxyIP
Definition: optionsmodel.h:63
OptionsModel::Prune
@ Prune
Definition: optionsmodel.h:73
OptionsModel::ThirdPartyTxUrls
@ ThirdPartyTxUrls
Definition: optionsmodel.h:69
OptionsModel::MapPortUPnP
@ MapPortUPnP
Definition: optionsmodel.h:60
guiconstants.h
OptionsModel::getDisplayUnit
int getDisplayUnit() const
Definition: optionsmodel.h:97
OptionsModel::Language
@ Language
Definition: optionsmodel.h:70
PruneGBtoMiB
static int64_t PruneGBtoMiB(int gb)
Convert displayed prune target GB to configured MiB.
Definition: optionsmodel.h:39
OptionsModel::getThirdPartyTxUrls
QString getThirdPartyTxUrls() const
Definition: optionsmodel.h:98
OptionsModel::hideTrayIconChanged
void hideTrayIconChanged(bool)
OptionsModel::getMinimizeToTray
bool getMinimizeToTray() const
Definition: optionsmodel.h:95
amount.h
OptionsModel::coinControlFeaturesChanged
void coinControlFeaturesChanged(bool)
OptionsModel::setRestartRequired
void setRestartRequired(bool fRequired)
Definition: optionsmodel.cpp:550