Commit 8de0a185 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵 Committed by Nate Graham
Browse files

use ViewsListData in ViewManager

parent 0891f3a6
......@@ -65,7 +65,7 @@ Q_SIGNALS:
public Q_SLOTS:
void setViewsData(ViewsListData* viewsData);
void setViewsData(ViewsListData* viewsData);
private:
......
......@@ -17,207 +17,16 @@
#include "viewmanager.h"
#include "viewslistdata.h"
#include "datatypes.h"
#include "viewsLogging.h"
#include <KI18n/KLocalizedString>
class ViewParameters
{
public:
ViewParameters() = default;
ViewParameters(QString mainTitle,
QUrl mainImage,
ViewManager::ViewPresentationType viewPresentationType)
: mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
, mIsValid(true)
{
}
ViewParameters(QString mainTitle,
QUrl mainImage,
ViewManager::ViewPresentationType viewPresentationType,
ElisaUtils::FilterType filterType,
ElisaUtils::PlayListEntryType dataType,
QUrl fallbackItemIcon,
ViewManager::DelegateUseSecondaryText showSecondaryTextOnDelegates,
ViewManager::ViewCanBeRated viewCanBeRated)
: mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
, mFilterType(filterType)
, mDataType(dataType)
, mFallbackItemIcon(fallbackItemIcon)
, mShowSecondaryTextOnDelegates(showSecondaryTextOnDelegates)
, mViewCanBeRated(viewCanBeRated)
, mIsValid(true)
{
}
ViewParameters(QString mainTitle,
QUrl mainImage,
ViewManager::ViewPresentationType viewPresentationType,
ElisaUtils::FilterType filterType,
ElisaUtils::PlayListEntryType dataType,
int sortRole,
ViewManager::SortOrder sortOrder,
ViewManager::AlbumCardinality albumCardinality,
ViewManager::AlbumViewStyle albumViewStyle,
ViewManager::RadioSpecificStyle radioSpecificStyle)
: mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
, mFilterType(filterType)
, mDataType(dataType)
, mSortRole(sortRole)
, mSortOrder(sortOrder)
, mAlbumCardinality(albumCardinality)
, mAlbumViewStyle(albumViewStyle)
, mRadioSpecificStyle(radioSpecificStyle)
, mIsValid(true)
{
}
bool operator==(const ViewParameters &other) const {
return mMainTitle == other.mMainTitle && mMainImage == other.mMainImage &&
mSecondaryTitle == other.mSecondaryTitle && mViewPresentationType == other.mViewPresentationType &&
mFilterType == other.mFilterType && mDataType == other.mDataType && mFallbackItemIcon == other.mFallbackItemIcon &&
mShowSecondaryTextOnDelegates == other.mShowSecondaryTextOnDelegates && mViewCanBeRated == other.mViewCanBeRated &&
mSortRole == other.mSortRole && mSortOrder == other.mSortOrder &&
mAlbumCardinality == other.mAlbumCardinality && mAlbumViewStyle == other.mAlbumViewStyle &&
mRadioSpecificStyle == other.mRadioSpecificStyle && mDepth == other.mDepth &&
mDatabaseIdFilter == other.mDatabaseIdFilter && mGenreNameFilter == other.mGenreNameFilter &&
mArtistNameFilter == other.mArtistNameFilter;
}
bool operator!=(const ViewParameters &other) const {
return mMainTitle != other.mMainTitle || mMainImage != other.mMainImage ||
mSecondaryTitle != other.mSecondaryTitle || mViewPresentationType != other.mViewPresentationType ||
mFilterType != other.mFilterType || mDataType != other.mDataType || mFallbackItemIcon != other.mFallbackItemIcon ||
mShowSecondaryTextOnDelegates != other.mShowSecondaryTextOnDelegates || mViewCanBeRated != other.mViewCanBeRated ||
mSortRole != other.mSortRole || mSortOrder != other.mSortOrder ||
mAlbumCardinality != other.mAlbumCardinality || mAlbumViewStyle != other.mAlbumViewStyle ||
mRadioSpecificStyle != other.mRadioSpecificStyle || mDepth != other.mDepth ||
mDatabaseIdFilter != other.mDatabaseIdFilter || mGenreNameFilter != other.mGenreNameFilter ||
mArtistNameFilter != other.mArtistNameFilter;
}
QString mMainTitle;
QString mSecondaryTitle;
QUrl mMainImage;
ViewManager::ViewPresentationType mViewPresentationType = ViewManager::UnknownViewPresentation;
ElisaUtils::FilterType mFilterType = ElisaUtils::UnknownFilter;
ElisaUtils::PlayListEntryType mDataType = ElisaUtils::Unknown;
QUrl mFallbackItemIcon;
ViewManager::DelegateUseSecondaryText mShowSecondaryTextOnDelegates = ViewManager::DelegateWithSecondaryText;
ViewManager::ViewCanBeRated mViewCanBeRated = ViewManager::ViewHideRating;
int mSortRole = Qt::DisplayRole;
ViewManager::SortOrder mSortOrder = ViewManager::SortAscending;
ViewManager::AlbumCardinality mAlbumCardinality = ViewManager::MultipleAlbum;
ViewManager::AlbumViewStyle mAlbumViewStyle = ViewManager::NoDiscHeaders;
ViewManager::RadioSpecificStyle mRadioSpecificStyle = ViewManager::IsTrack;
int mDepth = 1;
qulonglong mDatabaseIdFilter = 0;
QString mGenreNameFilter;
QString mArtistNameFilter;
bool mIsValid = false;
};
class ViewManagerPrivate
{
public:
QList<ViewParameters> mViewsParameters = {{{i18nc("Title of the view of the playlist", "Now Playing")},
QUrl{QStringLiteral("image://icon/view-media-lyrics")},
ViewManager::ContextView},
{{i18nc("Title of the view of recently played tracks", "Recently Played")},
QUrl{QStringLiteral("image://icon/media-playlist-play")},
ViewManager::ListView,
ElisaUtils::FilterByRecentlyPlayed,
ElisaUtils::Track,
DataTypes::LastPlayDate,
ViewManager::SortDescending,
ViewManager::MultipleAlbum,
ViewManager::NoDiscHeaders,
ViewManager::IsTrack},
{{i18nc("Title of the view of frequently played tracks", "Frequently Played")},
QUrl{QStringLiteral("image://icon/view-media-playcount")},
ViewManager::ListView,
ElisaUtils::FilterByFrequentlyPlayed,
ElisaUtils::Track,
DataTypes::PlayFrequency,
ViewManager::SortDescending,
ViewManager::MultipleAlbum,
ViewManager::NoDiscHeaders,
ViewManager::IsTrack},
{{i18nc("Title of the view of all albums", "Albums")},
QUrl{QStringLiteral("image://icon/view-media-album-cover")},
ViewManager::GridView,
ElisaUtils::NoFilter,
ElisaUtils::Album,
QUrl{QStringLiteral("image://icon/media-optical-audio")},
ViewManager::DelegateWithSecondaryText,
ViewManager::ViewShowRating},
{{i18nc("Title of the view of all artists", "Artists")},
QUrl{QStringLiteral("image://icon/view-media-artist")},
ViewManager::GridView,
ElisaUtils::NoFilter,
ElisaUtils::Artist,
QUrl{QStringLiteral("image://icon/view-media-artist")},
ViewManager::DelegateWithoutSecondaryText,
ViewManager::ViewHideRating},
{{i18nc("Title of the view of all tracks", "Tracks")},
QUrl{QStringLiteral("image://icon/view-media-track")},
ViewManager::ListView,
ElisaUtils::NoFilter,
ElisaUtils::Track,
Qt::DisplayRole,
ViewManager::SortAscending,
ViewManager::MultipleAlbum,
ViewManager::NoDiscHeaders,
ViewManager::IsTrack},
{{i18nc("Title of the view of all genres", "Genres")},
QUrl{QStringLiteral("image://icon/view-media-genre")},
ViewManager::GridView,
ElisaUtils::NoFilter,
ElisaUtils::Genre,
QUrl{QStringLiteral("image://icon/view-media-genre")},
ViewManager::DelegateWithoutSecondaryText,
ViewManager::ViewHideRating},
{{i18nc("Title of the file browser view", "Files")},
QUrl{QStringLiteral("image://icon/document-open-folder")},
ViewManager::FileBrowserView},
{{i18nc("Title of the file radios browser view", "Radios")},
QUrl{QStringLiteral("image://icon/radio")},
ViewManager::ListView,
ElisaUtils::NoFilter,
ElisaUtils::Radio,
Qt::DisplayRole,
ViewManager::SortAscending,
ViewManager::MultipleAlbum,
ViewManager::NoDiscHeaders,
ViewManager::IsRadio}};
ViewsListData mViewsListData;
QMap<ElisaUtils::PlayListEntryType, ViewParameters> mChildViews = {
{ElisaUtils::Album, {{},
......@@ -250,7 +59,7 @@ public:
int mViewIndex = 0;
QList<ViewParameters> mViewParametersStack = {mViewsParameters[mViewIndex]};
QList<ViewParameters> mViewParametersStack = {mViewsListData.viewParameters(0)};
ViewParameters mNextViewParameters;
};
......@@ -266,13 +75,18 @@ int ViewManager::viewIndex() const
return d->mViewIndex;
}
ViewsListData *ViewManager::viewsData() const
{
return &d->mViewsListData;
}
ViewManager::~ViewManager() = default;
void ViewManager::openView(int viewIndex)
{
qCDebug(orgKdeElisaViews()) << "ViewManager::openView" << viewIndex << d->mViewParametersStack.size();
const auto &viewParameters = d->mViewsParameters[viewIndex];
const auto &viewParameters = d->mViewsListData.viewParameters(viewIndex);
if (viewParameters != d->mViewParametersStack.back()) {
d->mViewIndex = viewIndex;
......@@ -328,12 +142,12 @@ void ViewManager::openChildView(const QString &innerMainTitle, const QString & i
d->mNextViewParameters = nextViewParameters;
if (lastView.mDataType != dataType) {
for(int i = 0; i < d->mViewsParameters.size(); ++i) {
if (d->mViewsParameters.at(i).mDataType == dataType) {
for(int i = 0; i < d->mViewsListData.count(); ++i) {
if (d->mViewsListData.viewParameters(i).mDataType == dataType) {
d->mViewIndex = i;
Q_EMIT viewIndexChanged();
nextViewParameters = d->mViewsParameters.at(i);
nextViewParameters = d->mViewsListData.viewParameters(i);
break;
}
}
......@@ -418,5 +232,10 @@ void ViewManager::goBack()
d->mNextViewParameters = {};
}
void ViewManager::setViewsData(ViewsListData *viewsData)
{
Q_UNUSED(viewsData)
}
#include "moc_viewmanager.cpp"
......@@ -29,6 +29,7 @@
class ViewManagerPrivate;
class ViewParameters;
class ViewsListData;
class ELISALIB_EXPORT ViewManager : public QObject
{
......@@ -38,6 +39,8 @@ class ELISALIB_EXPORT ViewManager : public QObject
READ viewIndex
NOTIFY viewIndexChanged)
Q_PROPERTY(ViewsListData* viewsData READ viewsData WRITE setViewsData NOTIFY viewsDataChanged)
public:
enum ViewsType {
......@@ -120,6 +123,8 @@ public:
int viewIndex() const;
ViewsListData* viewsData() const;
Q_SIGNALS:
void openGridView(ElisaUtils::FilterType filterType, int expectedDepth,
......@@ -143,6 +148,8 @@ Q_SIGNALS:
void viewIndexChanged();
void viewsDataChanged();
public Q_SLOTS:
void openView(int viewIndex);
......@@ -155,6 +162,8 @@ public Q_SLOTS:
void goBack();
void setViewsData(ViewsListData* viewsData);
private:
void openViewFromData(const ViewParameters &viewParamaters);
......
......@@ -21,46 +21,79 @@
#include <QUrl>
struct ViewItem
{
QString mTitle;
QUrl mIconUrl;
};
class ViewsListDataPrivate
{
public:
ViewsListDataPrivate()
{
mData = {{i18nc("Title of the view of the playlist", "Now Playing"),
QUrl{QStringLiteral("image://icon/view-media-lyrics")}},
{i18nc("Title of the view of recently played tracks", "Recently Played"),
QUrl{QStringLiteral("image://icon/media-playlist-play")}},
{i18nc("Title of the view of frequently played tracks", "Frequently Played"),
QUrl{QStringLiteral("image://icon/view-media-playcount")}},
{i18nc("Title of the view of all albums", "Albums"),
QUrl{QStringLiteral("image://icon/view-media-album-cover")}},
{i18nc("Title of the view of all artists", "Artists"),
QUrl{QStringLiteral("image://icon/view-media-artist")}},
{i18nc("Title of the view of all tracks", "Tracks"),
QUrl{QStringLiteral("image://icon/view-media-track")}},
{i18nc("Title of the view of all genres", "Genres"),
QUrl{QStringLiteral("image://icon/view-media-genre")}},
{i18nc("Title of the file browser view", "Files"),
QUrl{QStringLiteral("image://icon/document-open-folder")}},
{i18nc("Title of the file radios browser view", "Radios"),
QUrl{QStringLiteral("image://icon/radio")}}};
mDefaultIcons = {{ViewManager::AllAlbums, QUrl{QStringLiteral("image://icon/view-media-album-cover")}},
{ViewManager::AllArtists, QUrl{QStringLiteral("image://icon/view-media-artist")}},
{ViewManager::AllGenres, QUrl{QStringLiteral("image://icon/view-media-genre")}},};
}
QList<ViewItem> mData;
QMap<ViewManager::ViewsType, QUrl> mDefaultIcons;
QList<ViewParameters> mViewsParameters = {{{i18nc("Title of the view of the playlist", "Now Playing")},
QUrl{QStringLiteral("image://icon/view-media-lyrics")},
ViewManager::ContextView},
{{i18nc("Title of the view of recently played tracks", "Recently Played")},
QUrl{QStringLiteral("image://icon/media-playlist-play")},
ViewManager::ListView,
ElisaUtils::FilterByRecentlyPlayed,
ElisaUtils::Track,
DataTypes::LastPlayDate,
ViewManager::SortDescending,
ViewManager::MultipleAlbum,
ViewManager::NoDiscHeaders,
ViewManager::IsTrack},
{{i18nc("Title of the view of frequently played tracks", "Frequently Played")},
QUrl{QStringLiteral("image://icon/view-media-playcount")},
ViewManager::ListView,
ElisaUtils::FilterByFrequentlyPlayed,
ElisaUtils::Track,
DataTypes::PlayFrequency,
ViewManager::SortDescending,
ViewManager::MultipleAlbum,
ViewManager::NoDiscHeaders,
ViewManager::IsTrack},
{{i18nc("Title of the view of all albums", "Albums")},
QUrl{QStringLiteral("image://icon/view-media-album-cover")},
ViewManager::GridView,
ElisaUtils::NoFilter,
ElisaUtils::Album,
QUrl{QStringLiteral("image://icon/media-optical-audio")},
ViewManager::DelegateWithSecondaryText,
ViewManager::ViewShowRating},
{{i18nc("Title of the view of all artists", "Artists")},
QUrl{QStringLiteral("image://icon/view-media-artist")},
ViewManager::GridView,
ElisaUtils::NoFilter,
ElisaUtils::Artist,
QUrl{QStringLiteral("image://icon/view-media-artist")},
ViewManager::DelegateWithoutSecondaryText,
ViewManager::ViewHideRating},
{{i18nc("Title of the view of all tracks", "Tracks")},
QUrl{QStringLiteral("image://icon/view-media-track")},
ViewManager::ListView,
ElisaUtils::NoFilter,
ElisaUtils::Track,
Qt::DisplayRole,
ViewManager::SortAscending,
ViewManager::MultipleAlbum,
ViewManager::NoDiscHeaders,
ViewManager::IsTrack},
{{i18nc("Title of the view of all genres", "Genres")},
QUrl{QStringLiteral("image://icon/view-media-genre")},
ViewManager::GridView,
ElisaUtils::NoFilter,
ElisaUtils::Genre,
QUrl{QStringLiteral("image://icon/view-media-genre")},
ViewManager::DelegateWithoutSecondaryText,
ViewManager::ViewHideRating},
{{i18nc("Title of the file browser view", "Files")},
QUrl{QStringLiteral("image://icon/document-open-folder")},
ViewManager::FileBrowserView},
{{i18nc("Title of the file radios browser view", "Radios")},
QUrl{QStringLiteral("image://icon/radio")},
ViewManager::ListView,
ElisaUtils::NoFilter,
ElisaUtils::Radio,
Qt::DisplayRole,
ViewManager::SortAscending,
ViewManager::MultipleAlbum,
ViewManager::NoDiscHeaders,
ViewManager::IsRadio}};
};
......@@ -72,17 +105,22 @@ ViewsListData::~ViewsListData() = default;
int ViewsListData::count() const
{
return d->mData.count();
return d->mViewsParameters.count();
}
const ViewParameters &ViewsListData::viewParameters(int index) const
{
return d->mViewsParameters[index];
}
const QString &ViewsListData::title(int index) const
{
return d->mData[index].mTitle;
return d->mViewsParameters[index].mMainTitle;
}
const QUrl &ViewsListData::iconUrl(int index) const
{
return d->mData[index].mIconUrl;
return d->mViewsParameters[index].mMainImage;
}
......
......@@ -24,6 +24,7 @@
#include "viewmanager.h"
#include "datatypes.h"
#include "elisautils.h"
#include <memory>
......@@ -31,6 +32,128 @@ class QUrl;
class QString;
class ViewsListDataPrivate;
class ViewParameters
{
public:
ViewParameters() = default;
ViewParameters(QString mainTitle,
QUrl mainImage,
ViewManager::ViewPresentationType viewPresentationType)
: mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
, mIsValid(true)
{
}
ViewParameters(QString mainTitle,
QUrl mainImage,
ViewManager::ViewPresentationType viewPresentationType,
ElisaUtils::FilterType filterType,
ElisaUtils::PlayListEntryType dataType,
QUrl fallbackItemIcon,
ViewManager::DelegateUseSecondaryText showSecondaryTextOnDelegates,
ViewManager::ViewCanBeRated viewCanBeRated)
: mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
, mFilterType(filterType)
, mDataType(dataType)
, mFallbackItemIcon(fallbackItemIcon)
, mShowSecondaryTextOnDelegates(showSecondaryTextOnDelegates)
, mViewCanBeRated(viewCanBeRated)
, mIsValid(true)
{
}
ViewParameters(QString mainTitle,
QUrl mainImage,
ViewManager::ViewPresentationType viewPresentationType,
ElisaUtils::FilterType filterType,
ElisaUtils::PlayListEntryType dataType,
int sortRole,
ViewManager::SortOrder sortOrder,
ViewManager::AlbumCardinality albumCardinality,
ViewManager::AlbumViewStyle albumViewStyle,
ViewManager::RadioSpecificStyle radioSpecificStyle)
: mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
, mFilterType(filterType)
, mDataType(dataType)
, mSortRole(sortRole)
, mSortOrder(sortOrder)
, mAlbumCardinality(albumCardinality)
, mAlbumViewStyle(albumViewStyle)
, mRadioSpecificStyle(radioSpecificStyle)
, mIsValid(true)
{
}
bool operator==(const ViewParameters &other) const {
return mMainTitle == other.mMainTitle && mMainImage == other.mMainImage &&
mSecondaryTitle == other.mSecondaryTitle && mViewPresentationType == other.mViewPresentationType &&
mFilterType == other.mFilterType && mDataType == other.mDataType && mFallbackItemIcon == other.mFallbackItemIcon &&
mShowSecondaryTextOnDelegates == other.mShowSecondaryTextOnDelegates && mViewCanBeRated == other.mViewCanBeRated &&
mSortRole == other.mSortRole && mSortOrder == other.mSortOrder &&
mAlbumCardinality == other.mAlbumCardinality && mAlbumViewStyle == other.mAlbumViewStyle &&
mRadioSpecificStyle == other.mRadioSpecificStyle && mDepth == other.mDepth &&
mDatabaseIdFilter == other.mDatabaseIdFilter && mGenreNameFilter == other.mGenreNameFilter &&
mArtistNameFilter == other.mArtistNameFilter;
}
bool operator!=(const ViewParameters &other) const {
return mMainTitle != other.mMainTitle || mMainImage != other.mMainImage ||
mSecondaryTitle != other.mSecondaryTitle || mViewPresentationType != other.mViewPresentationType ||
mFilterType != other.mFilterType || mDataType != other.mDataType || mFallbackItemIcon != other.mFallbackItemIcon ||
mShowSecondaryTextOnDelegates != other.mShowSecondaryTextOnDelegates || mViewCanBeRated != other.mViewCanBeRated ||
mSortRole != other.mSortRole || mSortOrder != other.mSortOrder ||
mAlbumCardinality != other.mAlbumCardinality || mAlbumViewStyle != other.mAlbumViewStyle ||
mRadioSpecificStyle != other.mRadioSpecificStyle || mDepth != other.mDepth ||
mDatabaseIdFilter != other.mDatabaseIdFilter || mGenreNameFilter != other.mGenreNameFilter ||
mArtistNameFilter != other.mArtistNameFilter;
}
QString mMainTitle;
QString mSecondaryTitle;
QUrl mMainImage;
ViewManager::ViewPresentationType mViewPresentationType = ViewManager::UnknownViewPresentation;
ElisaUtils::FilterType mFilterType = ElisaUtils::UnknownFilter;
ElisaUtils::PlayListEntryType mDataType = ElisaUtils::Unknown;
QUrl mFallbackItemIcon;
ViewManager::DelegateUseSecondaryText mShowSecondaryTextOnDelegates = ViewManager::DelegateWithSecondaryText;
ViewManager::ViewCanBeRated mViewCanBeRated = ViewManager::ViewHideRating;
int mSortRole = Qt::DisplayRole;
ViewManager::SortOrder mSortOrder = ViewManager::SortAscending;
ViewManager::AlbumCardinality mAlbumCardinality = ViewManager::MultipleAlbum;
ViewManager::AlbumViewStyle mAlbumViewStyle = ViewManager::NoDiscHeaders;
ViewManager::RadioSpecificStyle mRadioSpecificStyle = ViewManager::IsTrack;
int mDepth = 1;
qulonglong mDatabaseIdFilter = 0;
QString mGenreNameFilter;
QString mArtistNameFilter;
bool mIsValid = false;
};
class ELISALIB_EXPORT ViewsListData : public QObject
{
Q_OBJECT
......@@ -43,6 +166,8 @@ public:
int count() const;
const ViewParameters& viewParameters(int index) const;
const QString& title(int index) const;
const QUrl& iconUrl(int index) const;
......
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