Bitcoin ABC 0.30.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 <qt/guiconstants.h>
9
10#include <QAbstractListModel>
11
12#include <cassert>
13#include <cstdint>
14
15namespace interfaces {
16class Node;
17}
18
19QT_BEGIN_NAMESPACE
20class QNetworkProxy;
21QT_END_NAMESPACE
22
23extern const char *DEFAULT_GUI_PROXY_HOST;
24static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050;
25
30static inline int PruneMiBtoGB(int64_t mib) {
31 return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES;
32}
33
38static inline int64_t PruneGBtoMiB(int gb) {
39 return gb * GB_BYTES / 1024 / 1024;
40}
41
48class OptionsModel : public QAbstractListModel {
49 Q_OBJECT
50
51public:
52 explicit OptionsModel(QObject *parent = nullptr,
53 bool resetSettings = false);
54
55 enum OptionID {
57 HideTrayIcon, // bool
59 MapPortUPnP, // bool
62 ProxyUse, // bool
63 ProxyIP, // QString
64 ProxyPort, // int
65 ProxyUseTor, // bool
66 ProxyIPTor, // QString
68 DisplayUnit, // BitcoinUnits::Unit
69 ThirdPartyTxUrls, // QString
70 Language, // QString
73 Prune, // bool
74 PruneSize, // 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
122private:
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();
141Q_SIGNALS:
142 void displayUnitChanged(int unit);
145};
146
147#endif // BITCOIN_QT_OPTIONSMODEL_H
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:48
int getDisplayUnit() const
Definition: optionsmodel.h:97
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QString strOverriddenByCommandLine
Definition: optionsmodel.h:133
bool getProxySettings(QNetworkProxy &proxy) const
bool isRestartRequired() const
void Init(bool resetSettings=false)
bool getCoinControlFeatures() const
Definition: optionsmodel.h:100
bool fCoinControlFeatures
Definition: optionsmodel.h:131
interfaces::Node * m_node
Definition: optionsmodel.h:123
interfaces::Node & node() const
Definition: optionsmodel.h:113
void setDisplayUnit(const QVariant &value)
Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal.
void coinControlFeaturesChanged(bool)
QString strThirdPartyTxUrls
Definition: optionsmodel.h:130
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:125
bool getMinimizeToTray() const
Definition: optionsmodel.h:95
bool fMinimizeToTray
Definition: optionsmodel.h:126
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
const QString & getOverriddenByCommandLine()
Definition: optionsmodel.h:101
bool getMinimizeOnClose() const
Definition: optionsmodel.h:96
void setNode(interfaces::Node &node)
Definition: optionsmodel.h:117
QString getThirdPartyTxUrls() const
Definition: optionsmodel.h:98
void checkAndMigrate()
bool getHideTrayIcon() const
Definition: optionsmodel.h:94
QString language
Definition: optionsmodel.h:128
void addOverriddenOption(const std::string &option)
bool fMinimizeOnClose
Definition: optionsmodel.h:127
void setRestartRequired(bool fRequired)
void hideTrayIconChanged(bool)
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:59
static constexpr uint64_t GB_BYTES
Definition: guiconstants.h:50
Definition: init.h:28
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
Definition: optionsmodel.h:30
static int64_t PruneGBtoMiB(int gb)
Convert displayed prune target GB to configured MiB.
Definition: optionsmodel.h:38
QT_END_NAMESPACE const char * DEFAULT_GUI_PROXY_HOST
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
Definition: optionsmodel.h:24
assert(!tx.IsCoinBase())