Commit 645550df authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

allow to load/save sort preferences for order and roles in all views

parent 1b5e83e1
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "viewslistdata.h" #include "viewslistdata.h"
#include "viewconfigurationdata.h" #include "viewconfigurationdata.h"
#include "elisa_settings.h"
#include <QtTest> #include <QtTest>
class ViewManagerTests: public QObject class ViewManagerTests: public QObject
...@@ -37,10 +39,13 @@ private Q_SLOTS: ...@@ -37,10 +39,13 @@ private Q_SLOTS:
qRegisterMetaType<QAbstractItemModel*>("QAbstractItemModel*"); qRegisterMetaType<QAbstractItemModel*>("QAbstractItemModel*");
qRegisterMetaType<QAbstractProxyModel*>("QAbstractProxyModel*"); qRegisterMetaType<QAbstractProxyModel*>("QAbstractProxyModel*");
qRegisterMetaType<DataTypes::DataType>("DataTypes::DataType"); qRegisterMetaType<DataTypes::DataType>("DataTypes::DataType");
QStandardPaths::setTestModeEnabled(true);
Elisa::ElisaConfiguration::instance(QStringLiteral("testfoo"));
} }
void openAlbumViewTest() void openAlbumViewTest()
{ {
Elisa::ElisaConfiguration::self()->setDefaults();
ViewManager viewManager; ViewManager viewManager;
ViewsListData viewsData; ViewsListData viewsData;
viewManager.setViewsData(&viewsData); viewManager.setViewsData(&viewsData);
...@@ -85,6 +90,7 @@ private Q_SLOTS: ...@@ -85,6 +90,7 @@ private Q_SLOTS:
void openAlbumView2Test() void openAlbumView2Test()
{ {
Elisa::ElisaConfiguration::self()->setDefaults();
ViewManager viewManager; ViewManager viewManager;
ViewsListData viewsData; ViewsListData viewsData;
viewManager.setViewsData(&viewsData); viewManager.setViewsData(&viewsData);
...@@ -175,6 +181,7 @@ private Q_SLOTS: ...@@ -175,6 +181,7 @@ private Q_SLOTS:
void openAlbumView3Test() void openAlbumView3Test()
{ {
Elisa::ElisaConfiguration::self()->setDefaults();
ViewManager viewManager; ViewManager viewManager;
ViewsListData viewsData; ViewsListData viewsData;
viewManager.setViewsData(&viewsData); viewManager.setViewsData(&viewsData);
...@@ -261,6 +268,7 @@ private Q_SLOTS: ...@@ -261,6 +268,7 @@ private Q_SLOTS:
void openArtistViewTest() void openArtistViewTest()
{ {
Elisa::ElisaConfiguration::self()->setDefaults();
ViewManager viewManager; ViewManager viewManager;
ViewsListData viewsData; ViewsListData viewsData;
viewManager.setViewsData(&viewsData); viewManager.setViewsData(&viewsData);
...@@ -305,6 +313,7 @@ private Q_SLOTS: ...@@ -305,6 +313,7 @@ private Q_SLOTS:
void openArtistView2Test() void openArtistView2Test()
{ {
Elisa::ElisaConfiguration::self()->setDefaults();
ViewManager viewManager; ViewManager viewManager;
ViewsListData viewsData; ViewsListData viewsData;
viewManager.setViewsData(&viewsData); viewManager.setViewsData(&viewsData);
...@@ -395,6 +404,7 @@ private Q_SLOTS: ...@@ -395,6 +404,7 @@ private Q_SLOTS:
void openArtistView3Test() void openArtistView3Test()
{ {
Elisa::ElisaConfiguration::self()->setDefaults();
ViewManager viewManager; ViewManager viewManager;
ViewsListData viewsData; ViewsListData viewsData;
viewManager.setViewsData(&viewsData); viewManager.setViewsData(&viewsData);
...@@ -481,6 +491,7 @@ private Q_SLOTS: ...@@ -481,6 +491,7 @@ private Q_SLOTS:
void openGenreViewTest() void openGenreViewTest()
{ {
Elisa::ElisaConfiguration::self()->setDefaults();
ViewManager viewManager; ViewManager viewManager;
ViewsListData viewsData; ViewsListData viewsData;
viewManager.setViewsData(&viewsData); viewManager.setViewsData(&viewsData);
...@@ -525,6 +536,7 @@ private Q_SLOTS: ...@@ -525,6 +536,7 @@ private Q_SLOTS:
void openGenreView2Test() void openGenreView2Test()
{ {
Elisa::ElisaConfiguration::self()->setDefaults();
ViewManager viewManager; ViewManager viewManager;
ViewsListData viewsData; ViewsListData viewsData;
viewManager.setViewsData(&viewsData); viewManager.setViewsData(&viewsData);
...@@ -615,6 +627,7 @@ private Q_SLOTS: ...@@ -615,6 +627,7 @@ private Q_SLOTS:
void openGenreView3Test() void openGenreView3Test()
{ {
Elisa::ElisaConfiguration::self()->setDefaults();
ViewManager viewManager; ViewManager viewManager;
ViewsListData viewsData; ViewsListData viewsData;
viewManager.setViewsData(&viewsData); viewManager.setViewsData(&viewsData);
...@@ -701,6 +714,7 @@ private Q_SLOTS: ...@@ -701,6 +714,7 @@ private Q_SLOTS:
void openArtistFromGenreViewTest() void openArtistFromGenreViewTest()
{ {
Elisa::ElisaConfiguration::self()->setDefaults();
ViewManager viewManager; ViewManager viewManager;
ViewsListData viewsData; ViewsListData viewsData;
viewManager.setViewsData(&viewsData); viewManager.setViewsData(&viewsData);
...@@ -769,6 +783,7 @@ private Q_SLOTS: ...@@ -769,6 +783,7 @@ private Q_SLOTS:
void openArtistViewAndAlbumFromAnotherArtistTest() void openArtistViewAndAlbumFromAnotherArtistTest()
{ {
Elisa::ElisaConfiguration::self()->setDefaults();
ViewManager viewManager; ViewManager viewManager;
ViewsListData viewsData; ViewsListData viewsData;
viewManager.setViewsData(&viewsData); viewManager.setViewsData(&viewsData);
...@@ -848,6 +863,7 @@ private Q_SLOTS: ...@@ -848,6 +863,7 @@ private Q_SLOTS:
void openNowPlayingViewTest() void openNowPlayingViewTest()
{ {
Elisa::ElisaConfiguration::self()->setDefaults();
ViewManager viewManager; ViewManager viewManager;
ViewsListData viewsData; ViewsListData viewsData;
viewManager.setViewsData(&viewsData); viewManager.setViewsData(&viewsData);
......
...@@ -36,5 +36,9 @@ ...@@ -36,5 +36,9 @@
<choice name="AllGenres" /> <choice name="AllGenres" />
</choices> </choices>
</entry> </entry>
<entry key="SortRolePreferences" type="StringList">
</entry>
<entry key="SortOrderPreferences" type="StringList">
</entry>
</group> </group>
</kcfg> </kcfg>
...@@ -71,6 +71,7 @@ RowLayout { ...@@ -71,6 +71,7 @@ RowLayout {
sortRoleNames: configurationData.sortRoleNames, sortRoleNames: configurationData.sortRoleNames,
sortOrder: configurationData.sortOrder, sortOrder: configurationData.sortOrder,
sortOrderNames: configurationData.sortOrderNames, sortOrderNames: configurationData.sortOrderNames,
viewManager: viewManager,
opacity: 1, opacity: 1,
}, StackView.Immediate) }, StackView.Immediate)
} }
...@@ -106,6 +107,7 @@ RowLayout { ...@@ -106,6 +107,7 @@ RowLayout {
sortRoleNames: configurationData.sortRoleNames, sortRoleNames: configurationData.sortRoleNames,
sortOrder: configurationData.sortOrder, sortOrder: configurationData.sortOrder,
sortOrderNames: configurationData.sortOrderNames, sortOrderNames: configurationData.sortOrderNames,
viewManager: viewManager,
opacity: 1, opacity: 1,
}, StackView.Immediate) }, StackView.Immediate)
} }
......
...@@ -32,6 +32,7 @@ FocusScope { ...@@ -32,6 +32,7 @@ FocusScope {
property alias sortOrderNames: gridView.sortOrderNames property alias sortOrderNames: gridView.sortOrderNames
property alias sortOrder: gridView.sortOrder property alias sortOrder: gridView.sortOrder
property bool modelIsInitialized: false property bool modelIsInitialized: false
property alias viewManager: gridView.viewManager
focus: true focus: true
......
...@@ -32,6 +32,7 @@ FocusScope { ...@@ -32,6 +32,7 @@ FocusScope {
property bool displaySingleAlbum: false property bool displaySingleAlbum: false
property alias radioCase: listView.showCreateRadioButton property alias radioCase: listView.showCreateRadioButton
property bool modelIsInitialized: false property bool modelIsInitialized: false
property alias viewManager: listView.viewManager
function openMetaDataView(databaseId, url, entryType) { function openMetaDataView(databaseId, url, entryType) {
metadataLoader.setSource("MediaTrackMetadataView.qml", metadataLoader.setSource("MediaTrackMetadataView.qml",
......
...@@ -33,6 +33,7 @@ FocusScope { ...@@ -33,6 +33,7 @@ FocusScope {
property var stackView property var stackView
property url defaultIcon property url defaultIcon
property int depth: 1 property int depth: 1
property alias viewManager: navigationBar.viewManager
signal enqueue(var fullData, string name) signal enqueue(var fullData, string name)
signal replaceAndPlay(var fullData, string name) signal replaceAndPlay(var fullData, string name)
......
...@@ -41,6 +41,7 @@ FocusScope { ...@@ -41,6 +41,7 @@ FocusScope {
property alias showCreateRadioButton: navigationBar.showCreateRadioButton property alias showCreateRadioButton: navigationBar.showCreateRadioButton
property alias navigationBar: navigationBar property alias navigationBar: navigationBar
property int depth: 1 property int depth: 1
property alias viewManager: navigationBar.viewManager
signal goBackRequested() signal goBackRequested()
signal showArtist(var name) signal showArtist(var name)
......
...@@ -9,6 +9,7 @@ import QtQuick 2.7 ...@@ -9,6 +9,7 @@ import QtQuick 2.7
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import org.kde.kirigami 2.8 as Kirigami import org.kde.kirigami 2.8 as Kirigami
import org.kde.elisa 1.0
ColumnLayout { ColumnLayout {
id: navigationBar id: navigationBar
...@@ -35,6 +36,8 @@ ColumnLayout { ...@@ -35,6 +36,8 @@ ColumnLayout {
property alias sortOrder: sortMenu.sortOrder property alias sortOrder: sortMenu.sortOrder
property alias sortOrderNames: sortMenu.sortOrderNames property alias sortOrderNames: sortMenu.sortOrderNames
property ViewManager viewManager
signal enqueue(); signal enqueue();
signal replaceAndPlay(); signal replaceAndPlay();
signal createRadio(); signal createRadio();
...@@ -145,6 +148,10 @@ ColumnLayout { ...@@ -145,6 +148,10 @@ ColumnLayout {
SortMenu { SortMenu {
id: sortMenu id: sortMenu
onSortOrderChanged: if (viewManager) viewManager.sortOrderChanged(sortOrder)
onSortRoleChanged: if (viewManager) viewManager.sortRoleChanged(sortRole)
} }
}, },
FlatButtonWithToolTip { FlatButtonWithToolTip {
......
...@@ -14,10 +14,12 @@ ...@@ -14,10 +14,12 @@
#include "models/gridviewproxymodel.h" #include "models/gridviewproxymodel.h"
#include "models/filebrowsermodel.h" #include "models/filebrowsermodel.h"
#include "models/filebrowserproxymodel.h" #include "models/filebrowserproxymodel.h"
#include "elisa_settings.h"
#include <KI18n/KLocalizedString> #include <KI18n/KLocalizedString>
#include <QQmlEngine> #include <QQmlEngine>
#include <QMetaEnum>
class ViewManagerPrivate class ViewManagerPrivate
{ {
...@@ -317,8 +319,10 @@ void ViewManager::openViewFromData(const ViewParameters &viewParamaters) ...@@ -317,8 +319,10 @@ void ViewManager::openViewFromData(const ViewParameters &viewParamaters)
viewParamaters.mMainImage, viewParamaters.mDataType, viewParamaters.mMainImage, viewParamaters.mDataType,
newModel, proxyModel, viewParamaters.mFallbackItemIcon, newModel, proxyModel, viewParamaters.mFallbackItemIcon,
viewParamaters.mDataFilter, viewParamaters.mDataFilter,
viewParamaters.mSortRole, viewParamaters.mSortRoles, viewParamaters.mSortRoleNames, computePreferredSortRole(viewParamaters.mSortRole),
viewParamaters.mSortOrder, viewParamaters.mSortOrderNames, viewParamaters.mSortRoles, viewParamaters.mSortRoleNames,
computePreferredSortOrder(viewParamaters.mSortOrder),
viewParamaters.mSortOrderNames,
viewParamaters.mViewCanBeRated, viewParamaters.mShowSecondaryTextOnDelegates, viewParamaters.mViewCanBeRated, viewParamaters.mShowSecondaryTextOnDelegates,
viewParamaters.mIsTreeModel); viewParamaters.mIsTreeModel);
...@@ -342,8 +346,10 @@ void ViewManager::openViewFromData(const ViewParameters &viewParamaters) ...@@ -342,8 +346,10 @@ void ViewManager::openViewFromData(const ViewParameters &viewParamaters)
viewParamaters.mMainTitle, viewParamaters.mSecondaryTitle, viewParamaters.mMainTitle, viewParamaters.mSecondaryTitle,
viewParamaters.mMainImage, viewParamaters.mDataType, viewParamaters.mMainImage, viewParamaters.mDataType,
newModel, proxyModel, viewParamaters.mDataFilter, newModel, proxyModel, viewParamaters.mDataFilter,
viewParamaters.mSortRole, viewParamaters.mSortRoles, viewParamaters.mSortRoleNames, computePreferredSortRole(viewParamaters.mSortRole),
viewParamaters.mSortOrder, viewParamaters.mSortOrderNames, viewParamaters.mSortRoles, viewParamaters.mSortRoleNames,
computePreferredSortOrder(viewParamaters.mSortOrder),
viewParamaters.mSortOrderNames,
viewParamaters.mAlbumCardinality, viewParamaters.mAlbumViewStyle, viewParamaters.mAlbumCardinality, viewParamaters.mAlbumViewStyle,
viewParamaters.mRadioSpecificStyle, viewParamaters.mIsTreeModel); viewParamaters.mRadioSpecificStyle, viewParamaters.mIsTreeModel);
...@@ -389,6 +395,76 @@ void ViewManager::applyFilter(ViewParameters &nextViewParameters, ...@@ -389,6 +395,76 @@ void ViewManager::applyFilter(ViewParameters &nextViewParameters,
} }
} }
QString ViewManager::buildViewId() const
{
const auto &entryTypeMetaEnum = QMetaEnum::fromType<ElisaUtils::PlayListEntryType>();
QString viewId;
for (const auto &oneView : d->mViewParametersStack) {
viewId += QString::fromLatin1(entryTypeMetaEnum.valueToKey(oneView.mDataType)) + QStringLiteral("::");
}
return viewId;
}
QStringList::iterator ViewManager::findViewPreference(QStringList &list, const QString &viewId) const
{
auto itViewPreference = list.end();
for(itViewPreference = list.begin(); itViewPreference != list.end(); ++itViewPreference) {
auto parts = itViewPreference->splitRef(QStringLiteral("=="));
if (parts.size() != 2) {
continue;
}
if (parts[0] == viewId) {
break;
}
}
return itViewPreference;
}
Qt::SortOrder ViewManager::computePreferredSortOrder(Qt::SortOrder initialValue) const
{
auto currentSortOrderPreferences = Elisa::ElisaConfiguration::sortOrderPreferences();
auto viewId = buildViewId();
auto itViewPreference = findViewPreference(currentSortOrderPreferences, viewId);
if (itViewPreference != currentSortOrderPreferences.end()) {
auto result = itViewPreference->splitRef(QStringLiteral("=="));
if (result.size() == 2) {
const auto &sortOrderMetaEnum = QMetaEnum::fromType<Qt::SortOrder>();
bool conversionOk;
auto newValue = static_cast<Qt::SortOrder>(sortOrderMetaEnum.keyToValue(result[1].toLatin1().data(), &conversionOk));
if (conversionOk) {
initialValue = newValue;
}
}
}
return initialValue;
}
int ViewManager::computePreferredSortRole(int initialValue) const
{
auto currentSortRolePreferences = Elisa::ElisaConfiguration::sortRolePreferences();
auto viewId = buildViewId();
auto itViewPreference = findViewPreference(currentSortRolePreferences, viewId);
if (itViewPreference != currentSortRolePreferences.end()) {
auto result = itViewPreference->splitRef(QStringLiteral("=="));
if (result.size() == 2) {
const auto &sortRoleMetaEnum = QMetaEnum::fromType<DataTypes::ColumnsRoles>();
bool conversionOk;
auto newValue = static_cast<DataTypes::ColumnsRoles>(sortRoleMetaEnum.keyToValue(result[1].toLatin1().data(), &conversionOk));
if (conversionOk) {
initialValue = newValue;
}
}
}
return initialValue;
}
void ViewManager::goBack() void ViewManager::goBack()
{ {
qCDebug(orgKdeElisaViews()) << "ViewManager::goBack" << d->mViewParametersStack.size() qCDebug(orgKdeElisaViews()) << "ViewManager::goBack" << d->mViewParametersStack.size()
...@@ -424,5 +500,53 @@ void ViewManager::setViewsData(ViewsListData *viewsData) ...@@ -424,5 +500,53 @@ void ViewManager::setViewsData(ViewsListData *viewsData)
} }
} }
void ViewManager::sortOrderChanged(Qt::SortOrder sortOrder)
{
auto currentSortOrderPreferences = Elisa::ElisaConfiguration::sortOrderPreferences();
auto viewId = buildViewId();
auto itViewPreference = findViewPreference(currentSortOrderPreferences, viewId);
const auto &sortOrderMetaEnum = QMetaEnum::fromType<Qt::SortOrder>();
auto enumStringValue = sortOrderMetaEnum.valueToKey(sortOrder);
if (!enumStringValue) {
return;
}
QString newSortOrderPreference = viewId + QStringLiteral("==") + QString::fromLatin1(enumStringValue);
if (itViewPreference != currentSortOrderPreferences.end()) {
(*itViewPreference) = newSortOrderPreference;
} else {
currentSortOrderPreferences.push_back(newSortOrderPreference);
}
Elisa::ElisaConfiguration::setSortOrderPreferences(currentSortOrderPreferences);
Elisa::ElisaConfiguration::self()->save();
}
void ViewManager::sortRoleChanged(int sortRole)
{
auto currentSortRolePreferences = Elisa::ElisaConfiguration::sortRolePreferences();
auto viewId = buildViewId();
auto itViewPreference = findViewPreference(currentSortRolePreferences, viewId);
const auto &sortRoleMetaEnum = QMetaEnum::fromType<DataTypes::ColumnsRoles>();
auto enumStringValue = sortRoleMetaEnum.valueToKey(static_cast<DataTypes::ColumnsRoles>(sortRole));
if (!enumStringValue) {
return;
}
QString newSortRolePreference = viewId + QStringLiteral("==") + QString::fromLatin1(enumStringValue);
if (itViewPreference != currentSortRolePreferences.end()) {
(*itViewPreference) = newSortRolePreference;
} else {
currentSortRolePreferences.push_back(newSortRolePreference);
}
Elisa::ElisaConfiguration::setSortRolePreferences(currentSortRolePreferences);
Elisa::ElisaConfiguration::self()->save();
}
#include "moc_viewmanager.cpp" #include "moc_viewmanager.cpp"
...@@ -136,6 +136,10 @@ public Q_SLOTS: ...@@ -136,6 +136,10 @@ public Q_SLOTS:
void setViewsData(ViewsListData* viewsData); void setViewsData(ViewsListData* viewsData);
void sortOrderChanged(Qt::SortOrder sortOrder);
void sortRoleChanged(int sortRole);
private: private:
void openViewFromData(const ViewParameters &viewParamaters); void openViewFromData(const ViewParameters &viewParamaters);
...@@ -143,6 +147,14 @@ private: ...@@ -143,6 +147,14 @@ private:
void applyFilter(ViewParameters &nextViewParameters, void applyFilter(ViewParameters &nextViewParameters,
QString title, const ViewParameters &lastView) const; QString title, const ViewParameters &lastView) const;
QString buildViewId() const;
QStringList::iterator findViewPreference(QStringList &list, const QString &viewId) const;
Qt::SortOrder computePreferredSortOrder(Qt::SortOrder initialValue) const;
int computePreferredSortRole(int initialValue) const;
private: private:
std::unique_ptr<ViewManagerPrivate> d; std::unique_ptr<ViewManagerPrivate> d;
......
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