diff --git a/src/qml/models/options_model.cpp b/src/qml/models/options_model.cpp index 0125e56354..9e95152311 100644 --- a/src/qml/models/options_model.cpp +++ b/src/qml/models/options_model.cpp @@ -43,6 +43,8 @@ OptionsQmlModel::OptionsQmlModel(interfaces::Node& node, bool is_onboarded) m_server = SettingToBool(m_node.getPersistentSetting("server"), false); m_upnp = SettingToBool(m_node.getPersistentSetting("upnp"), DEFAULT_UPNP); + + m_dataDir = getDefaultDataDirString(); } void OptionsQmlModel::setDbcacheSizeMiB(int new_dbcache_size_mib) @@ -156,11 +158,46 @@ 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); + setDataDir(path); + 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::setDataDir(QString new_data_dir) +{ + if (new_data_dir != m_dataDir) { + m_dataDir = new_data_dir; + if (!getCustomDataDirString().isEmpty() && (new_data_dir != getDefaultDataDirString())) { + m_dataDir = getCustomDataDirString(); + } else { + m_dataDir = getDefaultDataDirString(); + } + Q_EMIT dataDirChanged(new_data_dir); } } diff --git a/src/qml/models/options_model.h b/src/qml/models/options_model.h index d5f3b0b957..459d40b574 100644 --- a/src/qml/models/options_model.h +++ b/src/qml/models/options_model.h @@ -34,6 +34,7 @@ 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 dataDir READ dataDir WRITE setDataDir NOTIFY dataDirChanged) Q_PROPERTY(QString getDefaultDataDirString READ getDefaultDataDirString CONSTANT) Q_PROPERTY(QUrl getDefaultDataDirectory READ getDefaultDataDirectory CONSTANT) @@ -60,14 +61,16 @@ class OptionsQmlModel : public QObject void setServer(bool new_server); bool upnp() const { return m_upnp; } void setUpnp(bool new_upnp); + QString dataDir() const { return m_dataDir; } + void setDataDir(QString new_data_dir); QString getDefaultDataDirString(); QUrl getDefaultDataDirectory(); - Q_INVOKABLE void setCustomDataDirArgs(QString path); + Q_INVOKABLE bool setCustomDataDirArgs(QString path); + Q_INVOKABLE QString getCustomDataDirString(); public Q_SLOTS: void setCustomDataDirString(const QString &new_custom_datadir_string) { m_custom_datadir_string = new_custom_datadir_string; - m_signalReceived = true; } Q_INVOKABLE void onboard(); @@ -81,6 +84,7 @@ public Q_SLOTS: void serverChanged(bool new_server); void upnpChanged(bool new_upnp); void customDataDirStringChanged(QString new_custom_datadir_string); + void dataDirChanged(QString new_data_dir); private: interfaces::Node& m_node; @@ -100,7 +104,7 @@ public Q_SLOTS: bool m_server; bool m_upnp; QString m_custom_datadir_string; - bool m_signalReceived = false; + QString m_dataDir; common::SettingsValue pruneSetting() const; };