Skip to content

Commit a31878b

Browse files
committed
qml: added getting custom datadir for display
1 parent b80e167 commit a31878b

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/qml/models/options_model.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ OptionsQmlModel::OptionsQmlModel(interfaces::Node& node)
3333
m_prune_size_gb = m_prune ? PruneMiBtoGB(prune_value) : DEFAULT_PRUNE_TARGET_GB;
3434

3535
m_script_threads = SettingToInt(m_node.getPersistentSetting("par"), DEFAULT_SCRIPTCHECK_THREADS);
36+
37+
m_custom_datadir = false;
3638
}
3739

3840
void OptionsQmlModel::setDbcacheSizeMiB(int new_dbcache_size_mib)
@@ -130,10 +132,40 @@ QUrl OptionsQmlModel::getDefaultDataDirectory()
130132
return QUrl::fromLocalFile(path);
131133
}
132134

133-
void OptionsQmlModel::setCustomDataDirArgs(QString path)
135+
bool OptionsQmlModel::setCustomDataDirArgs(QString path)
134136
{
135137
if (!path.isEmpty()) {
136-
// TODO: add actual custom data wiring
138+
// TODO: add actual custom data wiring
139+
#ifdef __ANDROID__
140+
QString uri = path;
141+
QString originalPrefix = "content://com.android.externalstorage.documents/tree/primary%3A";
142+
QString newPrefix = "/storage/self/primary/";
143+
QString path = uri.replace(originalPrefix, newPrefix);
144+
#else
145+
path = QUrl(path).toLocalFile();
146+
#endif // __ANDROID__
137147
qDebug() << "PlaceHolder: Created data directory: " << path;
148+
149+
m_custom_datadir_string = path;
150+
Q_EMIT customDataDirStringChanged(path);
151+
m_custom_datadir = true;
152+
return true;
153+
}
154+
return false;
155+
}
156+
157+
QString OptionsQmlModel::getCustomDataDirString()
158+
{
159+
#ifdef __ANDROID__
160+
m_custom_datadir_string = m_custom_datadir_string.replace("content://com.android.externalstorage.documents/tree/primary%3A", "/storage/self/primary/");
161+
#endif // __ANDROID__
162+
return m_custom_datadir_string;
163+
}
164+
165+
void OptionsQmlModel::setCustomDataDir(bool new_custom_datadir)
166+
{
167+
if (new_custom_datadir != m_custom_datadir) {
168+
m_custom_datadir = new_custom_datadir;
169+
Q_EMIT customDataDirChanged(new_custom_datadir);
138170
}
139-
}
171+
}

src/qml/models/options_model.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class OptionsQmlModel : public QObject
3636
Q_PROPERTY(bool upnp READ upnp WRITE setUpnp NOTIFY upnpChanged)
3737
Q_PROPERTY(QString getDefaultDataDirString READ getDefaultDataDirString CONSTANT)
3838
Q_PROPERTY(QUrl getDefaultDataDirectory READ getDefaultDataDirectory CONSTANT)
39+
Q_PROPERTY(bool customDataDir READ customDataDir WRITE setCustomDataDir NOTIFY customDataDirChanged)
3940

4041
public:
4142
explicit OptionsQmlModel(interfaces::Node& node);
@@ -62,7 +63,10 @@ class OptionsQmlModel : public QObject
6263
void setUpnp(bool new_upnp);
6364
QString getDefaultDataDirString();
6465
QUrl getDefaultDataDirectory();
65-
Q_INVOKABLE void setCustomDataDirArgs(QString path);
66+
Q_INVOKABLE bool setCustomDataDirArgs(QString path);
67+
Q_INVOKABLE QString getCustomDataDirString();
68+
bool customDataDir() const { return m_custom_datadir; }
69+
void setCustomDataDir(bool new_custom_datadir);
6670

6771
public Q_SLOTS:
6872
void setCustomDataDirString(const QString &new_custom_datadir_string) {
@@ -80,6 +84,7 @@ public Q_SLOTS:
8084
void serverChanged(bool new_server);
8185
void upnpChanged(bool new_upnp);
8286
void customDataDirStringChanged(QString new_custom_datadir_string);
87+
void customDataDirChanged(bool new_custom_datadir);
8388

8489
private:
8590
interfaces::Node& m_node;
@@ -99,6 +104,7 @@ public Q_SLOTS:
99104
bool m_upnp;
100105
QString m_custom_datadir_string;
101106
bool m_signalReceived = false;
107+
bool m_custom_datadir;
102108

103109
common::SettingsValue pruneSetting() const;
104110
};

0 commit comments

Comments
 (0)