Skip to content

Commit

Permalink
qml: UI only. added setcustomdatadir() method into the options_model …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
D33r-Gee committed Mar 29, 2024
1 parent 0b59fee commit ffd5201
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/qml/models/options_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@
#include <common/system.h>
#include <interfaces/node.h>
#include <qt/guiconstants.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
#include <txdb.h>
#include <univalue.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <validation.h>

#include <cassert>

#include <QDebug>
#include <QDir>
#include <QSettings>

OptionsQmlModel::OptionsQmlModel(interfaces::Node& node)
: m_node{node}
{
Expand Down Expand Up @@ -105,3 +112,28 @@ common::SettingsValue OptionsQmlModel::pruneSetting() const
assert(!m_prune || m_prune_size_gb >= 1);
return m_prune ? PruneGBtoMiB(m_prune_size_gb) : 0;
}

QString PathToQString(const fs::path &path)
{
return QString::fromStdString(path.u8string());
}

QString OptionsQmlModel::getDefaultDataDirString()
{
return PathToQString(GetDefaultDataDir());
}


QUrl OptionsQmlModel::getDefaultDataDirectory()
{
QString path = getDefaultDataDirString();
return QUrl::fromLocalFile(path);
}

void OptionsQmlModel::setCustomDataDirArgs(QString path)
{
if (!path.isEmpty()) {
// TODO: add actual custom data wiring
qDebug() << "PlaceHolder: Created data directory: " << path;
}
}
16 changes: 16 additions & 0 deletions src/qml/models/options_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <validation.h>

#include <QObject>
#include <QString>
#include <QUrl>

namespace interfaces {
class Node;
Expand All @@ -32,6 +34,8 @@ class OptionsQmlModel : public QObject
Q_PROPERTY(int scriptThreads READ scriptThreads WRITE setScriptThreads NOTIFY scriptThreadsChanged)
Q_PROPERTY(bool server READ server WRITE setServer NOTIFY serverChanged)
Q_PROPERTY(bool upnp READ upnp WRITE setUpnp NOTIFY upnpChanged)
Q_PROPERTY(QString getDefaultDataDirString READ getDefaultDataDirString CONSTANT)
Q_PROPERTY(QUrl getDefaultDataDirectory READ getDefaultDataDirectory CONSTANT)

public:
explicit OptionsQmlModel(interfaces::Node& node);
Expand All @@ -56,6 +60,15 @@ class OptionsQmlModel : public QObject
void setServer(bool new_server);
bool upnp() const { return m_upnp; }
void setUpnp(bool new_upnp);
QString getDefaultDataDirString();
QUrl getDefaultDataDirectory();
Q_INVOKABLE void setCustomDataDirArgs(QString path);

public Q_SLOTS:
void setCustomDataDirString(const QString &new_custom_datadir_string) {
m_custom_datadir_string = new_custom_datadir_string;
m_signalReceived = true;
}

Q_SIGNALS:
void dbcacheSizeMiBChanged(int new_dbcache_size_mib);
Expand All @@ -66,6 +79,7 @@ class OptionsQmlModel : public QObject
void scriptThreadsChanged(int new_script_threads);
void serverChanged(bool new_server);
void upnpChanged(bool new_upnp);
void customDataDirStringChanged(QString new_custom_datadir_string);

private:
interfaces::Node& m_node;
Expand All @@ -83,6 +97,8 @@ class OptionsQmlModel : public QObject
int m_script_threads;
bool m_server;
bool m_upnp;
QString m_custom_datadir_string;
bool m_signalReceived = false;

common::SettingsValue pruneSetting() const;
};
Expand Down

0 comments on commit ffd5201

Please sign in to comment.