Create better Settings

Use the settings components from Kirigami
This commit is contained in:
Tobias Fella 2021-07-26 21:20:16 +02:00 committed by Bart De Vries
parent 0d37ee9f82
commit 6ad1818734
9 changed files with 176 additions and 114 deletions

View File

@ -12,7 +12,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
set(KF5_MIN_VERSION "5.75.0") set(KF5_MIN_VERSION "5.86.0")
set(QT_MIN_VERSION "5.15.0") set(QT_MIN_VERSION "5.15.0")
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)

View File

@ -180,6 +180,8 @@ if(ANDROID)
error error
search search
kt-add-feeds kt-add-feeds
network-connect
drive-harddisk-symbolic
) )
else() else()
target_link_libraries(kasts PRIVATE Qt::Widgets Qt::DBus) target_link_libraries(kasts PRIVATE Qt::Widgets Qt::DBus)

View File

@ -8,14 +8,13 @@
import QtQuick 2.15 import QtQuick 2.15
import QtQuick.Controls 2.15 as Controls import QtQuick.Controls 2.15 as Controls
import QtQuick.Layouts 1.14 import QtQuick.Layouts 1.14
import QtQuick.Dialogs 1.3
import org.kde.kirigami 2.12 as Kirigami import org.kde.kirigami 2.12 as Kirigami
import org.kde.kasts 1.0 import org.kde.kasts 1.0
Kirigami.ScrollablePage { Kirigami.ScrollablePage {
title: i18n("Settings") title: i18n("General Settings")
Kirigami.FormLayout { Kirigami.FormLayout {
@ -99,33 +98,6 @@ Kirigami.ScrollablePage {
onToggled: SettingsManager.resetPositionOnPlayed = checked onToggled: SettingsManager.resetPositionOnPlayed = checked
} }
Kirigami.Heading {
Kirigami.FormData.isSection: true
text: i18n("Network")
}
Controls.CheckBox {
id: allowMeteredFeedUpdates
checked: SettingsManager.allowMeteredFeedUpdates
Kirigami.FormData.label: i18n("On metered connections:")
text: i18n("Allow podcast updates")
onToggled: SettingsManager.allowMeteredFeedUpdates = checked
}
Controls.CheckBox {
id: allowMeteredEpisodeDownloads
checked: SettingsManager.allowMeteredEpisodeDownloads
text: i18n("Allow episode downloads")
onToggled: SettingsManager.allowMeteredEpisodeDownloads = checked
}
Controls.CheckBox {
id: allowMeteredImageDownloads
checked: SettingsManager.allowMeteredImageDownloads
text: i18n("Allow image downloads")
onToggled: SettingsManager.allowMeteredImageDownloads = checked
}
Kirigami.Heading { Kirigami.Heading {
Kirigami.FormData.isSection: true Kirigami.FormData.isSection: true
text: i18n("Article") text: i18n("Article")
@ -151,68 +123,6 @@ Kirigami.ScrollablePage {
onToggled: SettingsManager.articleFontUseSystem = checked onToggled: SettingsManager.articleFontUseSystem = checked
} }
Kirigami.Heading {
Kirigami.FormData.isSection: true
text: i18n("Storage")
}
RowLayout {
visible: Qt.platform.os !== "android" // not functional on android
Kirigami.FormData.label: i18n("Storage path:")
Layout.fillWidth: true
Controls.TextField {
Layout.fillWidth: true
readOnly: true
text: StorageManager.storagePath
enabled: !defaultStoragePath.checked
}
Controls.Button {
icon.name: "document-open-folder"
text: i18n("Select folder...")
enabled: !defaultStoragePath.checked
onClicked: storagePathDialog.open()
}
FileDialog {
id: storagePathDialog
title: i18n("Select Storage Path")
selectFolder: true
folder: "file://" + StorageManager.storagePath
onAccepted: {
StorageManager.setStoragePath(fileUrl);
}
}
}
Controls.CheckBox {
id: defaultStoragePath
visible: Qt.platform.os !== "android" // not functional on android
checked: SettingsManager.storagePath == ""
text: i18n("Use default path")
onToggled: {
if (checked) {
StorageManager.setStoragePath("");
}
}
}
Controls.Label {
Kirigami.FormData.label: i18n("Podcast Downloads:")
text: i18nc("Using <amount of bytes> of disk space", "Using %1 of disk space", StorageManager.formattedEnclosureDirSize)
}
RowLayout {
Kirigami.FormData.label: i18n("Image Cache:")
Controls.Label {
text: i18nc("Using <amount of bytes> of disk space", "Using %1 of disk space", StorageManager.formattedImageDirSize)
}
Controls.Button {
icon.name: "edit-clear-all"
text: i18n("Clear Cache")
onClicked: StorageManager.clearImageCache();
}
}
Kirigami.Heading { Kirigami.Heading {
Kirigami.FormData.isSection: true Kirigami.FormData.isSection: true
text: i18n("Errors") text: i18n("Errors")
@ -221,7 +131,11 @@ Kirigami.ScrollablePage {
Controls.Button { Controls.Button {
icon.name: "error" icon.name: "error"
text: i18n("Show Error Log") text: i18n("Show Error Log")
onClicked: errorOverlay.open() onClicked: settingsErrorOverlay.open()
}
ErrorListOverlay {
id: settingsErrorOverlay
} }
} }
} }

View File

@ -0,0 +1,42 @@
/**
* SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>
* SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import QtQuick 2.14
import QtQuick.Controls 2.14 as Controls
import QtQuick.Layouts 1.14
import org.kde.kirigami 2.12 as Kirigami
import org.kde.kasts 1.0
Kirigami.ScrollablePage {
title: i18n("Network Settings")
Kirigami.FormLayout {
Controls.CheckBox {
id: allowMeteredFeedUpdates
checked: SettingsManager.allowMeteredFeedUpdates
Kirigami.FormData.label: i18n("On metered connections:")
text: i18n("Allow podcast updates")
onToggled: SettingsManager.allowMeteredFeedUpdates = checked
}
Controls.CheckBox {
id: allowMeteredEpisodeDownloads
checked: SettingsManager.allowMeteredEpisodeDownloads
text: i18n("Allow episode downloads")
onToggled: SettingsManager.allowMeteredEpisodeDownloads = checked
}
Controls.CheckBox {
id: allowMeteredImageDownloads
checked: SettingsManager.allowMeteredImageDownloads
text: i18n("Allow image downloads")
onToggled: SettingsManager.allowMeteredImageDownloads = checked
}
}
}

View File

@ -0,0 +1,36 @@
/**
* SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import QtQuick 2.15
import QtQuick.Controls 2.15 as QQC2
import QtQuick.Layouts 1.15
import org.kde.kirigami 2.18 as Kirigami
Kirigami.CategorizedSettings {
actions: [
Kirigami.SettingAction {
text: i18n("General")
icon.name: "kasts"
page: "qrc:/GeneralSettingsPage.qml"
},
Kirigami.SettingAction {
text: i18n("Storage")
icon.name: "drive-harddisk-symbolic"
page: "qrc:/StorageSettingsPage.qml"
},
Kirigami.SettingAction {
text: i18n("Network")
icon.name: "network-connect"
page: "qrc:/NetworkSettingsPage.qml"
},
Kirigami.SettingAction {
text: i18n("About")
icon.name: "help-about-symbolic"
page: "qrc:/AboutPage.qml"
}
]
}

View File

@ -0,0 +1,78 @@
/**
* SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>
* SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import QtQuick 2.14
import QtQuick.Controls 2.14 as Controls
import QtQuick.Layouts 1.14
import QtQuick.Dialogs 1.3
import org.kde.kirigami 2.12 as Kirigami
import org.kde.kasts 1.0
Kirigami.ScrollablePage {
title: i18n("Storage Settings")
Kirigami.FormLayout {
RowLayout {
visible: Qt.platform.os !== "android" // not functional on android
Kirigami.FormData.label: i18n("Storage path:")
Layout.fillWidth: true
Controls.TextField {
Layout.fillWidth: true
readOnly: true
text: StorageManager.storagePath
enabled: !defaultStoragePath.checked
}
Controls.Button {
icon.name: "document-open-folder"
text: i18n("Select folder...")
enabled: !defaultStoragePath.checked
onClicked: storagePathDialog.open()
}
FileDialog {
id: storagePathDialog
title: i18n("Select Storage Path")
selectFolder: true
folder: "file://" + StorageManager.storagePath
onAccepted: {
StorageManager.setStoragePath(fileUrl);
}
}
}
Controls.CheckBox {
id: defaultStoragePath
visible: Qt.platform.os !== "android" // not functional on android
checked: SettingsManager.storagePath == ""
text: i18n("Use default path")
onToggled: {
if (checked) {
StorageManager.setStoragePath("");
}
}
}
Controls.Label {
Kirigami.FormData.label: i18n("Podcast Downloads:")
text: i18nc("Using <amount of bytes> of disk space", "Using %1 of disk space", StorageManager.formattedEnclosureDirSize)
}
RowLayout {
Kirigami.FormData.label: i18n("Image Cache:")
Controls.Label {
text: i18nc("Using <amount of bytes> of disk space", "Using %1 of disk space", StorageManager.formattedImageDirSize)
}
Controls.Button {
icon.name: "edit-clear-all"
text: i18n("Clear Cache")
onClicked: StorageManager.clearImageCache();
}
}
}
}

View File

@ -40,13 +40,13 @@ Kirigami.ApplicationWindow {
case "DiscoverPage": return "qrc:/DiscoverPage.qml"; case "DiscoverPage": return "qrc:/DiscoverPage.qml";
case "FeedListPage": return "qrc:/FeedListPage.qml"; case "FeedListPage": return "qrc:/FeedListPage.qml";
case "DownloadListPage": return "qrc:/DownloadListPage.qml"; case "DownloadListPage": return "qrc:/DownloadListPage.qml";
case "SettingsPage": return "qrc:/SettingsPage.qml"; case "SettingsPage": return "qrc:/Settings/SettingsPage.qml";
case "AboutPage": return "qrc:/AboutPage.qml";
default: return "qrc:/FeedListPage.qml"; default: return "qrc:/FeedListPage.qml";
} }
} }
function pushPage(page) { function pushPage(page) {
pageStack.clear() pageStack.clear()
pageStack.layers.clear()
pageStack.push(getPage(page)) pageStack.push(getPage(page))
currentPage = page currentPage = page
} }
@ -141,15 +141,10 @@ Kirigami.ApplicationWindow {
iconName: "settings-configure" iconName: "settings-configure"
checked: currentPage == "SettingsPage" checked: currentPage == "SettingsPage"
onTriggered: { onTriggered: {
pushPage("SettingsPage") root.pageStack.layers.clear()
} root.pageStack.pushDialogLayer("qrc:/SettingsPage.qml", {}, {
}, title: i18n("Settings")
Kirigami.Action { })
text: i18n("About")
iconName: "help-about-symbolic"
checked: currentPage == "AboutPage"
onTriggered: {
pushPage("AboutPage")
} }
} }
] ]
@ -166,14 +161,6 @@ Kirigami.ApplicationWindow {
} }
} }
Component {
id: aboutPage
Kirigami.AboutPage {
aboutData: _aboutData
}
}
contextDrawer: Kirigami.ContextDrawer { contextDrawer: Kirigami.ContextDrawer {
id: contextDrawer id: contextDrawer
// make room at the bottom for miniplayer // make room at the bottom for miniplayer

View File

@ -6,8 +6,7 @@
<file alias="EntryListPage.qml">qml/EntryListPage.qml</file> <file alias="EntryListPage.qml">qml/EntryListPage.qml</file>
<file alias="FeedListPage.qml">qml/FeedListPage.qml</file> <file alias="FeedListPage.qml">qml/FeedListPage.qml</file>
<file alias="EntryPage.qml">qml/EntryPage.qml</file> <file alias="EntryPage.qml">qml/EntryPage.qml</file>
<file alias="SettingsPage.qml">qml/SettingsPage.qml</file> <file alias="AboutPage.qml">qml/Settings/AboutPage.qml</file>
<file alias="AboutPage.qml">qml/AboutPage.qml</file>
<file alias="FeedDetailsPage.qml">qml/FeedDetailsPage.qml</file> <file alias="FeedDetailsPage.qml">qml/FeedDetailsPage.qml</file>
<file alias="AddFeedSheet.qml">qml/AddFeedSheet.qml</file> <file alias="AddFeedSheet.qml">qml/AddFeedSheet.qml</file>
<file alias="FeedListDelegate.qml">qml/FeedListDelegate.qml</file> <file alias="FeedListDelegate.qml">qml/FeedListDelegate.qml</file>
@ -29,6 +28,10 @@
<file alias="ErrorNotification.qml">qml/ErrorNotification.qml</file> <file alias="ErrorNotification.qml">qml/ErrorNotification.qml</file>
<file alias="ConnectionCheckAction.qml">qml/ConnectionCheckAction.qml</file> <file alias="ConnectionCheckAction.qml">qml/ConnectionCheckAction.qml</file>
<file alias="ChapterListDelegate.qml">qml/ChapterListDelegate.qml</file> <file alias="ChapterListDelegate.qml">qml/ChapterListDelegate.qml</file>
<file alias="SettingsPage.qml">qml/Settings/SettingsPage.qml</file>
<file alias="GeneralSettingsPage.qml">qml/Settings/GeneralSettingsPage.qml</file>
<file alias="NetworkSettingsPage.qml">qml/Settings/NetworkSettingsPage.qml</file>
<file alias="StorageSettingsPage.qml">qml/Settings/StorageSettingsPage.qml</file>
<file>qtquickcontrols2.conf</file> <file>qtquickcontrols2.conf</file>
<file alias="logo.svg">../kasts.svg</file> <file alias="logo.svg">../kasts.svg</file>
</qresource> </qresource>