Skip to content

Commit

Permalink
qml: added getting custom datadir for display
Browse files Browse the repository at this point in the history
  • Loading branch information
D33r-Gee committed May 1, 2024
1 parent 085805f commit 61c180e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
38 changes: 35 additions & 3 deletions src/qml/models/options_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ OptionsQmlModel::OptionsQmlModel(interfaces::Node& node)
m_prune_size_gb = m_prune ? PruneMiBtoGB(prune_value) : DEFAULT_PRUNE_TARGET_GB;

m_script_threads = SettingToInt(m_node.getPersistentSetting("par"), DEFAULT_SCRIPTCHECK_THREADS);

m_custom_datadir = false;
}

void OptionsQmlModel::setDbcacheSizeMiB(int new_dbcache_size_mib)
Expand Down Expand Up @@ -130,10 +132,40 @@ QUrl OptionsQmlModel::getDefaultDataDirectory()
return QUrl::fromLocalFile(path);
}

void OptionsQmlModel::setCustomDataDirArgs(QString path)
bool OptionsQmlModel::setCustomDataDirArgs(QString path)
{
if (!path.isEmpty()) {
// TODO: add actual custom data wiring
// TODO: add actual custom data wiring
#ifdef __ANDROID__
QString uri = path;
QString originalPrefix = "content://com.android.externalstorage.documents/tree/primary%3A";
QString newPrefix = "/storage/self/primary/";
QString path = uri.replace(originalPrefix, newPrefix);
#else
path = QUrl(path).toLocalFile();
#endif // __ANDROID__
qDebug() << "PlaceHolder: Created data directory: " << path;

m_custom_datadir_string = path;
Q_EMIT customDataDirStringChanged(path);
m_custom_datadir = true;
return true;
}
return false;
}

QString OptionsQmlModel::getCustomDataDirString()
{
#ifdef __ANDROID__
m_custom_datadir_string = m_custom_datadir_string.replace("content://com.android.externalstorage.documents/tree/primary%3A", "/storage/self/primary/");
#endif // __ANDROID__
return m_custom_datadir_string;
}

void OptionsQmlModel::setCustomDataDir(bool new_custom_datadir)
{
if (new_custom_datadir != m_custom_datadir) {
m_custom_datadir = new_custom_datadir;
Q_EMIT customDataDirChanged(new_custom_datadir);
}
}
}
8 changes: 7 additions & 1 deletion src/qml/models/options_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class OptionsQmlModel : public QObject
Q_PROPERTY(bool upnp READ upnp WRITE setUpnp NOTIFY upnpChanged)
Q_PROPERTY(QString getDefaultDataDirString READ getDefaultDataDirString CONSTANT)
Q_PROPERTY(QUrl getDefaultDataDirectory READ getDefaultDataDirectory CONSTANT)
Q_PROPERTY(bool customDataDir READ customDataDir WRITE setCustomDataDir NOTIFY customDataDirChanged)

public:
explicit OptionsQmlModel(interfaces::Node& node);
Expand All @@ -62,7 +63,10 @@ class OptionsQmlModel : public QObject
void setUpnp(bool new_upnp);
QString getDefaultDataDirString();
QUrl getDefaultDataDirectory();
Q_INVOKABLE void setCustomDataDirArgs(QString path);
Q_INVOKABLE bool setCustomDataDirArgs(QString path);
Q_INVOKABLE QString getCustomDataDirString();
bool customDataDir() const { return m_custom_datadir; }
void setCustomDataDir(bool new_custom_datadir);

public Q_SLOTS:
void setCustomDataDirString(const QString &new_custom_datadir_string) {
Expand All @@ -80,6 +84,7 @@ public Q_SLOTS:
void serverChanged(bool new_server);
void upnpChanged(bool new_upnp);
void customDataDirStringChanged(QString new_custom_datadir_string);
void customDataDirChanged(bool new_custom_datadir);

private:
interfaces::Node& m_node;
Expand All @@ -99,6 +104,7 @@ public Q_SLOTS:
bool m_upnp;
QString m_custom_datadir_string;
bool m_signalReceived = false;
bool m_custom_datadir;

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

0 comments on commit 61c180e

Please sign in to comment.