From 0e2932640cf6fe7ca27b8f7bddd51dacdff42fc3 Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Wed, 7 Feb 2024 20:32:12 +0100 Subject: [PATCH] Use Sailfish.Pickers.FolderPickerPage to configure music directories (#33) * Use Sailfish.Pickers.FolderPickerPage to configure music directories * Detect if Pickers are available. Fallback to old code if the Sailfish.Pickers module is not available in the import path. --------- Co-authored-by: Damien Caliste --- FlowPlayer.pro | 1 + qml/pages/ManageFolders.qml | 2 +- qml/pages/PickFolder.qml | 12 ++++++++++++ src/FlowPlayer.cpp | 5 +++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 qml/pages/PickFolder.qml diff --git a/FlowPlayer.pro b/FlowPlayer.pro index 8f20ce8..5cb219d 100644 --- a/FlowPlayer.pro +++ b/FlowPlayer.pro @@ -78,6 +78,7 @@ OTHER_FILES += \ qml/pages/SongsPage.qml \ qml/pages/ManageFolders.qml \ qml/pages/AddFolder.qml \ + qml/pages/PickFolder.qml \ qml/pages/AboutPage.qml \ qml/pages/SelectPreset.qml \ qml/pages/LastFM.qml \ diff --git a/qml/pages/ManageFolders.qml b/qml/pages/ManageFolders.qml index 2667646..3e752dc 100644 --- a/qml/pages/ManageFolders.qml +++ b/qml/pages/ManageFolders.qml @@ -42,7 +42,7 @@ Page { PullDownMenu { MenuItem { text: qsTr("Add folder") - onClicked: pageStack.push("AddFolder.qml") + onClicked: pageStack.push(hasPickers ? "PickFolder.qml" : "AddFolder.qml") } } diff --git a/qml/pages/PickFolder.qml b/qml/pages/PickFolder.qml new file mode 100644 index 0000000..c636087 --- /dev/null +++ b/qml/pages/PickFolder.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import Sailfish.Pickers 1.0 +import FlowPlayer 1.0 + +FolderPickerPage { + dialogTitle: qsTr("Select folder") + showSystemFiles: false + onSelectedPathChanged: { + utils.addFolderToList(selectedPath) + } +} diff --git a/src/FlowPlayer.cpp b/src/FlowPlayer.cpp index 55a5e0f..1ee8fce 100644 --- a/src/FlowPlayer.cpp +++ b/src/FlowPlayer.cpp @@ -60,6 +60,11 @@ int main(int argc, char *argv[]) window->engine()->addImportPath("/usr/share/flowplayer/qml"); window->rootContext()->setContextProperty("appVersion", VERSION); + bool hasPickers = false; + for (const QString &path : window->engine()->importPathList()) { + hasPickers = hasPickers || QFile::exists(path + "/Sailfish/Pickers"); + } + window->rootContext()->setContextProperty("hasPickers", hasPickers); qmlRegisterType("FlowPlayer", 1, 0, "Utils"); qmlRegisterType("FlowPlayer", 1, 0, "CoverSearch");