LCOV - code coverage report
Current view: top level - src/qt - optionsmodel.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 0 11 0.0 %
Date: 2020-09-26 01:30:44 Functions: 0 13 0.0 %

          Line data    Source code
       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 <cstdint>
      10             : #include <qt/guiconstants.h>
      11             : 
      12             : #include <QAbstractListModel>
      13             : 
      14             : #include <assert.h>
      15             : 
      16             : namespace interfaces {
      17             : class Node;
      18             : }
      19             : 
      20             : extern const char *DEFAULT_GUI_PROXY_HOST;
      21             : static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050;
      22             : 
      23             : /**
      24             :  * Convert configured prune target MiB to displayed GB. Round up to avoid underestimating max disk usage.
      25             :  */
      26           0 : static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES; }
      27             : 
      28             : /**
      29             :  * Convert displayed prune target GB to configured MiB. Round down so roundtrip GB -> MiB -> GB conversion is stable.
      30             :  */
      31           0 : static inline int64_t PruneGBtoMiB(int gb) { return gb * GB_BYTES / 1024 / 1024; }
      32             : 
      33             : /** Interface from Qt to configuration data structure for Bitcoin client.
      34             :    To Qt, the options are presented as a list with the different options
      35             :    laid out vertically.
      36             :    This can be changed to a tree once the settings become sufficiently
      37             :    complex.
      38             :  */
      39           0 : class OptionsModel : public QAbstractListModel
      40             : {
      41             :     Q_OBJECT
      42             : 
      43             : public:
      44             :     explicit OptionsModel(QObject *parent = nullptr, bool resetSettings = false);
      45             : 
      46             :     enum OptionID {
      47             :         StartAtStartup,         // bool
      48             :         HideTrayIcon,           // bool
      49             :         MinimizeToTray,         // bool
      50             :         MapPortUPnP,            // bool
      51             :         MinimizeOnClose,        // bool
      52             :         ProxyUse,               // bool
      53             :         ProxyIP,                // QString
      54             :         ProxyPort,              // int
      55             :         ProxyUseTor,            // bool
      56             :         ProxyIPTor,             // QString
      57             :         ProxyPortTor,           // int
      58             :         DisplayUnit,            // BitcoinUnits::Unit
      59             :         ThirdPartyTxUrls,       // QString
      60             :         Language,               // QString
      61             :         CoinControlFeatures,    // bool
      62             :         ThreadsScriptVerif,     // int
      63             :         Prune,                  // bool
      64             :         PruneSize,              // int
      65             :         DatabaseCache,          // int
      66             :         SpendZeroConfChange,    // bool
      67             :         Listen,                 // bool
      68             :         OptionIDRowCount,
      69             :     };
      70             : 
      71             :     void Init(bool resetSettings = false);
      72             :     void Reset();
      73             : 
      74             :     int rowCount(const QModelIndex & parent = QModelIndex()) const override;
      75             :     QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
      76             :     bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
      77             :     /** Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal */
      78             :     void setDisplayUnit(const QVariant &value);
      79             : 
      80             :     /* Explicit getters */
      81           0 :     bool getHideTrayIcon() const { return fHideTrayIcon; }
      82           0 :     bool getMinimizeToTray() const { return fMinimizeToTray; }
      83             :     bool getMinimizeOnClose() const { return fMinimizeOnClose; }
      84           0 :     int getDisplayUnit() const { return nDisplayUnit; }
      85           0 :     QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
      86           0 :     bool getCoinControlFeatures() const { return fCoinControlFeatures; }
      87           0 :     const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
      88             : 
      89             :     /* Explicit setters */
      90             :     void SetPruneEnabled(bool prune, bool force = false);
      91             :     void SetPruneTargetGB(int prune_target_gb, bool force = false);
      92             : 
      93             :     /* Restart flag helper */
      94             :     void setRestartRequired(bool fRequired);
      95             :     bool isRestartRequired() const;
      96             : 
      97           0 :     interfaces::Node& node() const { assert(m_node); return *m_node; }
      98           0 :     void setNode(interfaces::Node& node) { assert(!m_node); m_node = &node; }
      99             : 
     100             : private:
     101             :     interfaces::Node* m_node = nullptr;
     102             :     /* Qt-only settings */
     103             :     bool fHideTrayIcon;
     104             :     bool fMinimizeToTray;
     105             :     bool fMinimizeOnClose;
     106             :     QString language;
     107             :     int nDisplayUnit;
     108             :     QString strThirdPartyTxUrls;
     109             :     bool fCoinControlFeatures;
     110             :     /* settings that were overridden by command-line */
     111             :     QString strOverriddenByCommandLine;
     112             : 
     113             :     // Add option to list of GUI options overridden through command line/config file
     114             :     void addOverriddenOption(const std::string &option);
     115             : 
     116             :     // Check settings version and upgrade default values if required
     117             :     void checkAndMigrate();
     118             : Q_SIGNALS:
     119             :     void displayUnitChanged(int unit);
     120             :     void coinControlFeaturesChanged(bool);
     121             :     void hideTrayIconChanged(bool);
     122             : };
     123             : 
     124             : #endif // BITCOIN_QT_OPTIONSMODEL_H

Generated by: LCOV version 1.15