Skip to content

Commit 364e41d

Browse files
committed
Merge #397: UI Only Custom Datadir Display
7a8fb19 qml: UI only display datadir functionality (D33r-Gee) b648cbb qml: added getting custom datadir for display (D33r-Gee) Pull request description: This pull request builds upon #392 and introduces enhancements to display the data directory information within the UI. This functionality encompasses both default and custom data directory paths, fulfilling the UI requirements for user-defined data directory selection initiated in #273. Also the custom datadir is not persistent at the moment it will be once the back end wiring is added. <details> <summary>Ubuntu 22.04 Screenshots</summary> ![datadir_desktop](https://github.com/bitcoin-core/gui-qml/assets/111142327/639873a5-fd5d-44ac-b0be-66e0762a08db) </details> <details> <summary>Android Screenshots</summary> ![datadir_mobile_720](https://github.com/bitcoin-core/gui-qml/assets/111142327/e6fcd12b-f6e6-4efc-adba-071d2caaddef) </details> As a potential follow-up enhancement, consider incorporating mechanisms for saving the data directory path. This could be achieved through: - Double-click functionality: Allow users to save the displayed path by simply double-clicking on it. This provides a convenient and intuitive method for desktop environments. - Dedicated button: For mobile use cases or scenarios where double-clicking might not be feasible, introduce a dedicated "Save Path" button. This ensures a clear and accessible action for users on various devices. ACKs for top commit: GBKS: ACK 7a8fb19. Looks and feels great, just tested again on MacOS. MarnixCroes: tACK 7a8fb19 on Ubuntu desktop pablomartin4btc: reACK 7a8fb19 Tree-SHA512: 4be20832b72fee99046e78ce45e766ff3f00fc556d57c47311828daa3270d1980fdb2b16b95715024a5835f5730f4a3a347337e9dcc22f57fbaf2ac6711a9f6d
2 parents a7ccfc3 + 7a8fb19 commit 364e41d

File tree

5 files changed

+111
-9
lines changed

5 files changed

+111
-9
lines changed

src/qml/components/StorageLocations.qml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,52 @@ ColumnLayout {
1717
}
1818
spacing: 15
1919
OptionButton {
20+
id: defaultDirOption
2021
Layout.fillWidth: true
2122
ButtonGroup.group: group
2223
text: qsTr("Default")
2324
description: qsTr("Your application directory.")
24-
recommended: true
25-
checked: true
25+
customDir: optionsModel.getDefaultDataDirString
26+
checked: optionsModel.dataDir === optionsModel.getDefaultDataDirString
27+
onClicked: {
28+
defaultDirOption.checked = true
29+
optionsModel.dataDir = optionsModel.getDefaultDataDirString
30+
}
2631
}
2732
OptionButton {
33+
id: customDirOption
2834
Layout.fillWidth: true
2935
ButtonGroup.group: group
3036
text: qsTr("Custom")
3137
description: qsTr("Choose the directory and storage device.")
38+
customDir: customDirOption.checked ? fileDialog.folder : ""
39+
checked: optionsModel.dataDir !== optionsModel.getDefaultDataDirString
3240
onClicked: fileDialog.open()
3341
}
3442
FileDialog {
3543
id: fileDialog
3644
selectFolder: true
37-
folder: optionsModel.getDefaultDataDirectory
45+
folder: shortcuts.home
3846
onAccepted: {
3947
optionsModel.setCustomDataDirString(fileDialog.fileUrls[0].toString())
4048
var customDataDir = fileDialog.fileUrl.toString();
4149
if (customDataDir !== "") {
42-
optionsModel.setCustomDataDirArgs(customDataDir);
50+
optionsModel.setCustomDataDirArgs(customDataDir)
51+
customDirOption.customDir = optionsModel.getCustomDataDirString()
52+
if (optionsModel.dataDir !== optionsModel.getDefaultDataDirString) {
53+
customDirOption.checked = true
54+
defaultDirOption.checked = false
55+
}
4356
}
4457
}
4558
onRejected: {
4659
console.log("Custom datadir selection canceled")
60+
if (optionsModel.dataDir !== optionsModel.getDefaultDataDirString) {
61+
customDirOption.checked = true
62+
defaultDirOption.checked = false
63+
} else {
64+
defaultDirOption.checked = true
65+
}
4766
}
4867
}
4968
}

src/qml/components/StorageSettings.qml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,17 @@ ColumnLayout {
5858
loadedItem.forceActiveFocus()
5959
}
6060
}
61+
Separator { Layout.fillWidth: true }
62+
Setting {
63+
id: customDataDirSetting
64+
Layout.fillWidth: true
65+
header: qsTr("Data Directory")
66+
}
67+
CoreText {
68+
Layout.fillWidth: true
69+
text: optionsModel.dataDir
70+
color: Theme.color.neutral7
71+
font.pixelSize: 15
72+
horizontalAlignment: Text.AlignLeft
73+
}
6174
}

src/qml/controls/OptionButton.qml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Button {
1111
property string description
1212
property bool recommended: false
1313
property string image: ""
14+
property string customDir: ""
1415
padding: 15
1516
checkable: true
1617
implicitWidth: 450
@@ -24,6 +25,12 @@ Button {
2425
borderRadius: 14
2526
}
2627
}
28+
29+
MouseArea {
30+
anchors.fill: parent
31+
onClicked: button.clicked()
32+
}
33+
2734
contentItem: RowLayout {
2835
spacing: 3
2936
Loader {
@@ -80,6 +87,28 @@ Button {
8087
}
8188
}
8289
}
90+
Loader {
91+
Layout.topMargin: 12
92+
Layout.fillWidth: true
93+
active: button.customDir.length > 0
94+
visible: active
95+
sourceComponent: Button {
96+
id: container
97+
background: Rectangle {
98+
color: Theme.color.neutral2
99+
radius: 5
100+
}
101+
font.family: "Inter"
102+
font.styleName: "Semi Bold"
103+
font.pixelSize: 13
104+
contentItem: Text {
105+
font: container.font
106+
color: Theme.color.neutral9
107+
text: button.customDir
108+
wrapMode: Text.WordWrap
109+
}
110+
}
111+
}
83112
}
84113
Item {
85114
height: parent.height

src/qml/models/options_model.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ OptionsQmlModel::OptionsQmlModel(interfaces::Node& node, bool is_onboarded)
4343
m_server = SettingToBool(m_node.getPersistentSetting("server"), false);
4444

4545
m_upnp = SettingToBool(m_node.getPersistentSetting("upnp"), DEFAULT_UPNP);
46+
47+
m_dataDir = getDefaultDataDirString();
4648
}
4749

4850
void OptionsQmlModel::setDbcacheSizeMiB(int new_dbcache_size_mib)
@@ -156,11 +158,46 @@ QUrl OptionsQmlModel::getDefaultDataDirectory()
156158
return QUrl::fromLocalFile(path);
157159
}
158160

159-
void OptionsQmlModel::setCustomDataDirArgs(QString path)
161+
bool OptionsQmlModel::setCustomDataDirArgs(QString path)
160162
{
161163
if (!path.isEmpty()) {
162-
// TODO: add actual custom data wiring
164+
// TODO: add actual custom data wiring
165+
#ifdef __ANDROID__
166+
QString uri = path;
167+
QString originalPrefix = "content://com.android.externalstorage.documents/tree/primary%3A";
168+
QString newPrefix = "/storage/self/primary/";
169+
QString path = uri.replace(originalPrefix, newPrefix);
170+
#else
171+
path = QUrl(path).toLocalFile();
172+
#endif // __ANDROID__
163173
qDebug() << "PlaceHolder: Created data directory: " << path;
174+
175+
m_custom_datadir_string = path;
176+
Q_EMIT customDataDirStringChanged(path);
177+
setDataDir(path);
178+
return true;
179+
}
180+
return false;
181+
}
182+
183+
QString OptionsQmlModel::getCustomDataDirString()
184+
{
185+
#ifdef __ANDROID__
186+
m_custom_datadir_string = m_custom_datadir_string.replace("content://com.android.externalstorage.documents/tree/primary%3A", "/storage/self/primary/");
187+
#endif // __ANDROID__
188+
return m_custom_datadir_string;
189+
}
190+
191+
void OptionsQmlModel::setDataDir(QString new_data_dir)
192+
{
193+
if (new_data_dir != m_dataDir) {
194+
m_dataDir = new_data_dir;
195+
if (!getCustomDataDirString().isEmpty() && (new_data_dir != getDefaultDataDirString())) {
196+
m_dataDir = getCustomDataDirString();
197+
} else {
198+
m_dataDir = getDefaultDataDirString();
199+
}
200+
Q_EMIT dataDirChanged(new_data_dir);
164201
}
165202
}
166203

src/qml/models/options_model.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class OptionsQmlModel : public QObject
3434
Q_PROPERTY(int scriptThreads READ scriptThreads WRITE setScriptThreads NOTIFY scriptThreadsChanged)
3535
Q_PROPERTY(bool server READ server WRITE setServer NOTIFY serverChanged)
3636
Q_PROPERTY(bool upnp READ upnp WRITE setUpnp NOTIFY upnpChanged)
37+
Q_PROPERTY(QString dataDir READ dataDir WRITE setDataDir NOTIFY dataDirChanged)
3738
Q_PROPERTY(QString getDefaultDataDirString READ getDefaultDataDirString CONSTANT)
3839
Q_PROPERTY(QUrl getDefaultDataDirectory READ getDefaultDataDirectory CONSTANT)
3940

@@ -60,14 +61,16 @@ class OptionsQmlModel : public QObject
6061
void setServer(bool new_server);
6162
bool upnp() const { return m_upnp; }
6263
void setUpnp(bool new_upnp);
64+
QString dataDir() const { return m_dataDir; }
65+
void setDataDir(QString new_data_dir);
6366
QString getDefaultDataDirString();
6467
QUrl getDefaultDataDirectory();
65-
Q_INVOKABLE void setCustomDataDirArgs(QString path);
68+
Q_INVOKABLE bool setCustomDataDirArgs(QString path);
69+
Q_INVOKABLE QString getCustomDataDirString();
6670

6771
public Q_SLOTS:
6872
void setCustomDataDirString(const QString &new_custom_datadir_string) {
6973
m_custom_datadir_string = new_custom_datadir_string;
70-
m_signalReceived = true;
7174
}
7275
Q_INVOKABLE void onboard();
7376

@@ -81,6 +84,7 @@ public Q_SLOTS:
8184
void serverChanged(bool new_server);
8285
void upnpChanged(bool new_upnp);
8386
void customDataDirStringChanged(QString new_custom_datadir_string);
87+
void dataDirChanged(QString new_data_dir);
8488

8589
private:
8690
interfaces::Node& m_node;
@@ -100,7 +104,7 @@ public Q_SLOTS:
100104
bool m_server;
101105
bool m_upnp;
102106
QString m_custom_datadir_string;
103-
bool m_signalReceived = false;
107+
QString m_dataDir;
104108

105109
common::SettingsValue pruneSetting() const;
106110
};

0 commit comments

Comments
 (0)