Commit 4b9bdde4 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Save last used sort order

Separately for installed page and the rest

BUG: 401856
parent f8d991fa
...@@ -6,6 +6,7 @@ endif() ...@@ -6,6 +6,7 @@ endif()
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/..) include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/..)
ecm_qt_declare_logging_category(plasma_discover_SRCS HEADER discover_debug.h IDENTIFIER DISCOVER_LOG CATEGORY_NAME org.kde.plasma.discover) ecm_qt_declare_logging_category(plasma_discover_SRCS HEADER discover_debug.h IDENTIFIER DISCOVER_LOG CATEGORY_NAME org.kde.plasma.discover)
kconfig_add_kcfg_files(plasma_discover_SRCS discoversettings.kcfgc GENERATE_MOC)
add_executable(plasma-discover ${plasma_discover_SRCS} add_executable(plasma-discover ${plasma_discover_SRCS}
main.cpp main.cpp
......
...@@ -69,6 +69,8 @@ ...@@ -69,6 +69,8 @@
#include <utils.h> #include <utils.h>
#include <QMimeDatabase> #include <QMimeDatabase>
#include "discoversettings.h"
class OurSortFilterProxyModel : public QSortFilterProxyModel, public QQmlParserStatus class OurSortFilterProxyModel : public QSortFilterProxyModel, public QQmlParserStatus
{ {
Q_OBJECT Q_OBJECT
...@@ -100,6 +102,12 @@ DiscoverObject::DiscoverObject(CompactMode mode) ...@@ -100,6 +102,12 @@ DiscoverObject::DiscoverObject(CompactMode mode)
qmlRegisterType<FeaturedModel>("org.kde.discover.app", 1, 0, "FeaturedModel"); qmlRegisterType<FeaturedModel>("org.kde.discover.app", 1, 0, "FeaturedModel");
qmlRegisterType<OurSortFilterProxyModel>("org.kde.discover.app", 1, 0, "QSortFilterProxyModel"); qmlRegisterType<OurSortFilterProxyModel>("org.kde.discover.app", 1, 0, "QSortFilterProxyModel");
qmlRegisterSingletonType<DiscoverSettings>("org.kde.discover.app", 1, 0, "DiscoverSettings", [](QQmlEngine*, QJSEngine*) -> QObject* {
auto r = new DiscoverSettings;
connect(r, &DiscoverSettings::installedPageSortingChanged, r, &DiscoverSettings::save);
connect(r, &DiscoverSettings::appsListPageSortingChanged, r, &DiscoverSettings::save);
return r;
});
qmlRegisterType<QQuickView>(); qmlRegisterType<QQuickView>();
qmlRegisterType<QActionGroup>(); qmlRegisterType<QActionGroup>();
qmlRegisterType<QAction>(); qmlRegisterType<QAction>();
......
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
<kcfgfile arg="true"/>
<group name="DiscoverUI">
<entry name="appsListPageSorting" type="Int"><default>ResourcesProxyModel::SortableRatingRole</default></entry>
<entry name="installedPageSorting" type="Int"><default>ResourcesProxyModel::NameRole</default></entry>
</group>
</kcfg>
File=discoversettings.kcfg
ClassName=DiscoverSettings
GenerateProperties=true
Mutators=true
IncludeFiles=resources/ResourcesProxyModel.h
...@@ -43,6 +43,7 @@ DiscoverPage { ...@@ -43,6 +43,7 @@ DiscoverPage {
property alias count: apps.count property alias count: apps.count
property alias listHeader: apps.header property alias listHeader: apps.header
property alias listHeaderPositioning: apps.headerPositioning property alias listHeaderPositioning: apps.headerPositioning
property alias sortProperty: saveChanges.property
property bool compact: page.width < 550 || !applicationWindow().wideScreen property bool compact: page.width < 550 || !applicationWindow().wideScreen
property bool showRating: true property bool showRating: true
...@@ -74,6 +75,13 @@ DiscoverPage { ...@@ -74,6 +75,13 @@ DiscoverPage {
exclusive: true exclusive: true
} }
Binding {
id: saveChanges
target: DiscoverSettings
property: "appsListPageSorting"
value: appsModel.sortRole
}
contextualActions: [ contextualActions: [
Kirigami.Action { Kirigami.Action {
visible: !appsModel.sortByRelevancy visible: !appsModel.sortByRelevancy
...@@ -83,7 +91,6 @@ DiscoverPage { ...@@ -83,7 +91,6 @@ DiscoverPage {
text: i18n("Name") text: i18n("Name")
onTriggered: { onTriggered: {
appsModel.sortRole = ResourcesProxyModel.NameRole appsModel.sortRole = ResourcesProxyModel.NameRole
appsModel.sortOrder = Qt.AscendingOrder
} }
checkable: true checkable: true
checked: appsModel.sortRole == ResourcesProxyModel.NameRole checked: appsModel.sortRole == ResourcesProxyModel.NameRole
...@@ -93,7 +100,6 @@ DiscoverPage { ...@@ -93,7 +100,6 @@ DiscoverPage {
text: i18n("Rating") text: i18n("Rating")
onTriggered: { onTriggered: {
appsModel.sortRole = ResourcesProxyModel.SortableRatingRole appsModel.sortRole = ResourcesProxyModel.SortableRatingRole
appsModel.sortOrder = Qt.DescendingOrder
} }
checkable: true checkable: true
checked: appsModel.sortRole == ResourcesProxyModel.SortableRatingRole checked: appsModel.sortRole == ResourcesProxyModel.SortableRatingRole
...@@ -103,7 +109,6 @@ DiscoverPage { ...@@ -103,7 +109,6 @@ DiscoverPage {
text: i18n("Size") text: i18n("Size")
onTriggered: { onTriggered: {
appsModel.sortRole = ResourcesProxyModel.SizeRole appsModel.sortRole = ResourcesProxyModel.SizeRole
appsModel.sortOrder = Qt.AscendingOrder
} }
checkable: true checkable: true
checked: appsModel.sortRole == ResourcesProxyModel.SizeRole checked: appsModel.sortRole == ResourcesProxyModel.SizeRole
...@@ -113,7 +118,6 @@ DiscoverPage { ...@@ -113,7 +118,6 @@ DiscoverPage {
text: i18n("Release Date") text: i18n("Release Date")
onTriggered: { onTriggered: {
appsModel.sortRole = ResourcesProxyModel.ReleaseDateRole appsModel.sortRole = ResourcesProxyModel.ReleaseDateRole
appsModel.sortOrder = Qt.DescendingOrder
} }
checkable: true checkable: true
checked: appsModel.sortRole == ResourcesProxyModel.ReleaseDateRole checked: appsModel.sortRole == ResourcesProxyModel.ReleaseDateRole
...@@ -133,8 +137,9 @@ DiscoverPage { ...@@ -133,8 +137,9 @@ DiscoverPage {
model: ResourcesProxyModel { model: ResourcesProxyModel {
id: appsModel id: appsModel
sortRole: ResourcesProxyModel.SortableRatingRole sortRole: DiscoverSettings.appsListPageSorting
sortOrder: Qt.DescendingOrder sortOrder: sortRole === ResourcesProxyModel.SortableRatingRole || sortRole === ResourcesProxyModel.ReleaseDateRole ? Qt.DescendingOrder : Qt.AscendingOrder
onBusyChanged: if (isBusy) { onBusyChanged: if (isBusy) {
apps.currentIndex = -1 apps.currentIndex = -1
} }
......
...@@ -8,9 +8,9 @@ import org.kde.kirigami 2.1 as Kirigami ...@@ -8,9 +8,9 @@ import org.kde.kirigami 2.1 as Kirigami
ApplicationsListPage { ApplicationsListPage {
id: page id: page
stateFilter: AbstractResource.Installed stateFilter: AbstractResource.Installed
sortRole: ResourcesProxyModel.NameRole
sortOrder: Qt.AscendingOrder sortOrder: Qt.AscendingOrder
allBackends: true allBackends: true
sortProperty: "installedPageSorting"
title: i18n("Installed") title: i18n("Installed")
compact: true compact: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment