Skip to content

Commit

Permalink
Merge #397: UI Only Custom Datadir Display
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hebasto committed Jun 8, 2024
2 parents a7ccfc3 + 7a8fb19 commit 364e41d
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 9 deletions.
27 changes: 23 additions & 4 deletions src/qml/components/StorageLocations.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,52 @@ ColumnLayout {
}
spacing: 15
OptionButton {
id: defaultDirOption
Layout.fillWidth: true
ButtonGroup.group: group
text: qsTr("Default")
description: qsTr("Your application directory.")
recommended: true
checked: true
customDir: optionsModel.getDefaultDataDirString
checked: optionsModel.dataDir === optionsModel.getDefaultDataDirString
onClicked: {
defaultDirOption.checked = true
optionsModel.dataDir = optionsModel.getDefaultDataDirString
}
}
OptionButton {
id: customDirOption
Layout.fillWidth: true
ButtonGroup.group: group
text: qsTr("Custom")
description: qsTr("Choose the directory and storage device.")
customDir: customDirOption.checked ? fileDialog.folder : ""
checked: optionsModel.dataDir !== optionsModel.getDefaultDataDirString
onClicked: fileDialog.open()
}
FileDialog {
id: fileDialog
selectFolder: true
folder: optionsModel.getDefaultDataDirectory
folder: shortcuts.home
onAccepted: {
optionsModel.setCustomDataDirString(fileDialog.fileUrls[0].toString())
var customDataDir = fileDialog.fileUrl.toString();
if (customDataDir !== "") {
optionsModel.setCustomDataDirArgs(customDataDir);
optionsModel.setCustomDataDirArgs(customDataDir)
customDirOption.customDir = optionsModel.getCustomDataDirString()
if (optionsModel.dataDir !== optionsModel.getDefaultDataDirString) {
customDirOption.checked = true
defaultDirOption.checked = false
}
}
}
onRejected: {
console.log("Custom datadir selection canceled")
if (optionsModel.dataDir !== optionsModel.getDefaultDataDirString) {
customDirOption.checked = true
defaultDirOption.checked = false
} else {
defaultDirOption.checked = true
}
}
}
}
13 changes: 13 additions & 0 deletions src/qml/components/StorageSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,17 @@ ColumnLayout {
loadedItem.forceActiveFocus()
}
}
Separator { Layout.fillWidth: true }
Setting {
id: customDataDirSetting
Layout.fillWidth: true
header: qsTr("Data Directory")
}
CoreText {
Layout.fillWidth: true
text: optionsModel.dataDir
color: Theme.color.neutral7
font.pixelSize: 15
horizontalAlignment: Text.AlignLeft
}
}
29 changes: 29 additions & 0 deletions src/qml/controls/OptionButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Button {
property string description
property bool recommended: false
property string image: ""
property string customDir: ""
padding: 15
checkable: true
implicitWidth: 450
Expand All @@ -24,6 +25,12 @@ Button {
borderRadius: 14
}
}

MouseArea {
anchors.fill: parent
onClicked: button.clicked()
}

contentItem: RowLayout {
spacing: 3
Loader {
Expand Down Expand Up @@ -80,6 +87,28 @@ Button {
}
}
}
Loader {
Layout.topMargin: 12
Layout.fillWidth: true
active: button.customDir.length > 0
visible: active
sourceComponent: Button {
id: container
background: Rectangle {
color: Theme.color.neutral2
radius: 5
}
font.family: "Inter"
font.styleName: "Semi Bold"
font.pixelSize: 13
contentItem: Text {
font: container.font
color: Theme.color.neutral9
text: button.customDir
wrapMode: Text.WordWrap
}
}
}
}
Item {
height: parent.height
Expand Down
41 changes: 39 additions & 2 deletions src/qml/models/options_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/qml/models/options_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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();

Expand All @@ -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;
Expand All @@ -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;
};
Expand Down

0 comments on commit 364e41d

Please sign in to comment.