Commit 3758e9d5 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵 Committed by Nate Graham
Browse files

use generic code and configuration to display most top level views

list views are still not without regressions

remove no longer needed code
parent 68e626a3
......@@ -93,7 +93,7 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.openParentView(ViewManager::AllAlbums, {}, {});
viewManager.openView(3);
QCOMPARE(openGridViewSpy.count(), 1);
QCOMPARE(openListViewSpy.count(), 0);
......@@ -129,7 +129,7 @@ private Q_SLOTS:
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openParentView(ViewManager::AllAlbums, {}, {});
viewManager.openView(3);
QCOMPARE(openGridViewSpy.count(), 2);
QCOMPARE(openListViewSpy.count(), 1);
......@@ -175,7 +175,7 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.openParentView(ViewManager::AllAlbums, {}, {});
viewManager.openView(3);
QCOMPARE(openGridViewSpy.count(), 1);
QCOMPARE(openListViewSpy.count(), 0);
......@@ -291,7 +291,7 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.openParentView(ViewManager::AllArtists, {}, {});
viewManager.openView(4);
QCOMPARE(openGridViewSpy.count(), 1);
QCOMPARE(openListViewSpy.count(), 0);
......@@ -325,7 +325,7 @@ private Q_SLOTS:
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openParentView(ViewManager::AllArtists, {}, {});
viewManager.openView(4);
QCOMPARE(openGridViewSpy.count(), 3);
QCOMPARE(openListViewSpy.count(), 0);
......@@ -369,7 +369,7 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.openParentView(ViewManager::AllArtists, {}, {});
viewManager.openView(4);
QCOMPARE(openGridViewSpy.count(), 1);
QCOMPARE(openListViewSpy.count(), 0);
......@@ -481,7 +481,7 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.openParentView(ViewManager::AllGenres, {}, {});
viewManager.openView(6);
QCOMPARE(openGridViewSpy.count(), 1);
QCOMPARE(openListViewSpy.count(), 0);
......@@ -515,7 +515,7 @@ private Q_SLOTS:
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openParentView(ViewManager::AllGenres, {}, {});
viewManager.openView(6);
QCOMPARE(openGridViewSpy.count(), 3);
QCOMPARE(openListViewSpy.count(), 0);
......@@ -559,7 +559,7 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.openParentView(ViewManager::AllGenres, {}, {});
viewManager.openView(6);
QCOMPARE(openGridViewSpy.count(), 1);
QCOMPARE(openListViewSpy.count(), 0);
......@@ -634,7 +634,7 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.openParentView(ViewManager::AllGenres, {}, {});
viewManager.openView(6);
QCOMPARE(openGridViewSpy.count(), 1);
QCOMPARE(openListViewSpy.count(), 0);
......
......@@ -178,6 +178,7 @@ int ViewsModel::indexFromViewType(ViewManager::ViewsType type)
case ViewManager::OneArtistFromGenre:
case ViewManager::OneAlbumFromArtistAndGenre:
case ViewManager::AllArtistsFromGenre:
case ViewManager::UnknownView:
break;
}
......
......@@ -24,12 +24,70 @@
class ViewParameters
{
public:
ViewParameters(ViewManager::ViewsType viewType,
QString mainTitle,
QUrl mainImage,
ViewManager::ViewPresentationType viewPresentationType)
: mViewType(viewType)
, mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
{
}
ViewManager::ViewsType mViewType;
ViewParameters(ViewManager::ViewsType viewType,
QString mainTitle,
QUrl mainImage,
ViewManager::ViewPresentationType viewPresentationType,
ElisaUtils::FilterType filterType,
ElisaUtils::PlayListEntryType dataType,
QUrl fallbackItemIcon,
ViewManager::DelegateUseSecondaryText showSecondaryTextOnDelegates,
ViewManager::ViewCanBeRated viewCanBeRated)
: mViewType(viewType)
, mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
, mFilterType(filterType)
, mDataType(dataType)
, mFallbackItemIcon(fallbackItemIcon)
, mShowSecondaryTextOnDelegates(showSecondaryTextOnDelegates)
, mViewCanBeRated(viewCanBeRated)
{
}
ViewParameters(ViewManager::ViewsType viewType,
QString mainTitle,
QUrl mainImage,
ViewManager::ViewPresentationType viewPresentationType,
ElisaUtils::FilterType filterType,
ElisaUtils::PlayListEntryType dataType)
: mViewType(viewType)
, mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
, mFilterType(filterType)
, mDataType(dataType)
{
}
ViewManager::ViewsType mViewType = ViewManager::UnknownView;
QString mMainTitle;
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;
};
class ViewManagerPrivate
......@@ -37,31 +95,63 @@ class ViewManagerPrivate
public:
QList<ViewParameters> mViewsData = {{ViewManager::Context,
{i18nc("Title of the view of the playlist", "Now Playing")},
QUrl{QStringLiteral("image://icon/view-media-lyrics")}},
QUrl{QStringLiteral("image://icon/view-media-lyrics")},
ViewManager::ContextView},
{ViewManager::RecentlyPlayedTracks,
{i18nc("Title of the view of recently played tracks", "Recently Played")},
QUrl{QStringLiteral("image://icon/media-playlist-play")}},
QUrl{QStringLiteral("image://icon/media-playlist-play")},
ViewManager::ListView,
ElisaUtils::FilterByRecentlyPlayed,
ElisaUtils::Track},
{ViewManager::FrequentlyPlayedTracks,
{i18nc("Title of the view of frequently played tracks", "Frequently Played")},
QUrl{QStringLiteral("image://icon/view-media-playcount")}},
QUrl{QStringLiteral("image://icon/view-media-playcount")},
ViewManager::ListView,
ElisaUtils::FilterByFrequentlyPlayed,
ElisaUtils::Track},
{ViewManager::AllAlbums,
{i18nc("Title of the view of all albums", "Albums")},
QUrl{QStringLiteral("image://icon/view-media-album-cover")}},
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},
{ViewManager::AllArtists,
{i18nc("Title of the view of all artists", "Artists")},
QUrl{QStringLiteral("image://icon/view-media-artist")}},
QUrl{QStringLiteral("image://icon/view-media-artist")},
ViewManager::GridView,
ElisaUtils::NoFilter,
ElisaUtils::Artist,
QUrl{QStringLiteral("image://icon/view-media-artist")},
ViewManager::DelegateWithoutSecondaryText,
ViewManager::ViewHideRating},
{ViewManager::AllTracks,
{i18nc("Title of the view of all tracks", "Tracks")},
QUrl{QStringLiteral("image://icon/view-media-track")}},
QUrl{QStringLiteral("image://icon/view-media-track")},
ViewManager::ListView,
ElisaUtils::NoFilter,
ElisaUtils::Track},
{ViewManager::AllGenres,
{i18nc("Title of the view of all genres", "Genres")},
QUrl{QStringLiteral("image://icon/view-media-genre")}},
QUrl{QStringLiteral("image://icon/view-media-genre")},
ViewManager::GridView,
ElisaUtils::NoFilter,
ElisaUtils::Genre,
QUrl{QStringLiteral("image://icon/view-media-genre")},
ViewManager::DelegateWithoutSecondaryText,
ViewManager::ViewHideRating},
{ViewManager::FilesBrowser,
{i18nc("Title of the file browser view", "Files")},
QUrl{QStringLiteral("image://icon/document-open-folder")}},
QUrl{QStringLiteral("image://icon/document-open-folder")},
ViewManager::FileBrowserView},
{ViewManager::RadiosBrowser,
{i18nc("Title of the file radios browser view", "Radios")},
QUrl{QStringLiteral("image://icon/radio")}}};
QUrl{QStringLiteral("image://icon/radio")},
ViewManager::ListView,
ElisaUtils::NoFilter,
ElisaUtils::Radio}};
QString mCurrentAlbumTitle;
QString mCurrentAlbumAuthor;
......@@ -91,47 +181,30 @@ ViewManager::~ViewManager() = default;
void ViewManager::openView(int viewIndex)
{
const auto &viewData = d->mViewsData[viewIndex];
openParentView(viewData.mViewType, viewData.mMainTitle, viewData.mMainImage);
}
void ViewManager::openParentView(ViewManager::ViewsType viewType, const QString &mainTitle, const QUrl &mainImage)
{
switch(viewType)
{
case RecentlyPlayedTracks:
openRecentlyPlayedTracks(mainTitle, mainImage);
break;
case FrequentlyPlayedTracks:
openFrequentlyPlayedTracks(mainTitle, mainImage);
break;
case AllAlbums:
openAllAlbums(mainTitle, mainImage);
break;
case AllArtists:
openAllArtists(mainTitle, mainImage);
break;
case AllTracks:
openAllTracks(mainTitle, mainImage);
break;
case AllGenres:
openAllGenres(mainTitle, mainImage);
break;
case FilesBrowser:
openFilesBrowser(mainTitle, mainImage);
break;
case Context:
openContextView(mainTitle, mainImage);
break;
case RadiosBrowser:
openRadiosBrowser(mainTitle, mainImage);
break;
case OneAlbum:
case OneArtist:
case OneAlbumFromArtist:
case OneArtistFromGenre:
case OneAlbumFromArtistAndGenre:
case AllArtistsFromGenre:
break;
d->mTargetView = viewData.mViewType;
if (d->mCurrentView != d->mTargetView) {
switch (viewData.mViewPresentationType)
{
case ViewPresentationType::GridView:
Q_EMIT openGridView(d->mTargetView, viewData.mFilterType, 1, viewData.mMainTitle, {}, viewData.mMainImage, viewData.mDataType,
viewData.mFallbackItemIcon, {}, {}, viewData.mViewCanBeRated, viewData.mShowSecondaryTextOnDelegates);
break;
case ViewPresentationType::ListView:
Q_EMIT openListView(d->mTargetView, viewData.mFilterType, 1, viewData.mMainTitle, {},
0, viewData.mMainImage, viewData.mDataType, DataTypes::LastPlayDate,
SortOrder::SortDescending, MultipleAlbum, NoDiscHeaders, IsTrack);
break;
case ViewPresentationType::FileBrowserView:
Q_EMIT switchFilesBrowserView(d->mTargetView, 1, viewData.mMainTitle, viewData.mMainImage);
break;
case ContextView:
Q_EMIT switchContextView(d->mTargetView, 1, viewData.mMainTitle, viewData.mMainImage);
break;
case UnknownViewPresentation:
break;
}
}
}
......@@ -209,6 +282,8 @@ void ViewManager::viewIsLoaded(ViewManager::ViewsType viewType)
case ViewsType::RadiosBrowser:
radiosBrowserViewIsLoaded();
break;
case UnknownView:
break;
}
}
......@@ -234,16 +309,6 @@ void ViewManager::openFrequentlyPlayedTracks(const QString &mainTitle, const QUr
}
}
void ViewManager::openAllAlbums(const QString &mainTitle, const QUrl &imageUrl)
{
d->mTargetView = ViewsType::AllAlbums;
if (d->mCurrentView != d->mTargetView) {
Q_EMIT openGridView(d->mTargetView, ElisaUtils::NoFilter, 1, mainTitle, {}, imageUrl, ElisaUtils::Album,
QUrl(QStringLiteral("image://icon/media-optical-audio")), {}, {}, ViewShowRating, DelegateWithSecondaryText);
}
}
void ViewManager::openOneAlbum(const QString &albumTitle, const QString &albumAuthor,
const QUrl &albumCover, qulonglong albumDatabaseId,
AlbumViewStyle albumDiscHeader)
......@@ -279,16 +344,6 @@ void ViewManager::openOneAlbum(const QString &albumTitle, const QString &albumAu
}
}
void ViewManager::openAllArtists(const QString &mainTitle, const QUrl &imageUrl)
{
d->mTargetView = ViewsType::AllArtists;
if (d->mCurrentView != d->mTargetView) {
Q_EMIT openGridView(ViewsType::AllArtists, ElisaUtils::NoFilter, 1, mainTitle, {}, imageUrl, ElisaUtils::Artist,
QUrl(QStringLiteral("image://icon/view-media-artist")), {}, {}, ViewHideRating, DelegateWithoutSecondaryText);
}
}
void ViewManager::openOneArtist(const QString &artistName, const QUrl &artistImageUrl, qulonglong artistDatabaseId)
{
d->mTargetArtistName = artistName;
......@@ -331,16 +386,6 @@ void ViewManager::openAllTracks(const QString &mainTitle, const QUrl &imageUrl)
}
}
void ViewManager::openAllGenres(const QString &mainTitle, const QUrl &imageUrl)
{
d->mTargetView = ViewsType::AllGenres;
if (d->mCurrentView != d->mTargetView) {
Q_EMIT openGridView(d->mTargetView, ElisaUtils::NoFilter, 1, mainTitle, {}, imageUrl, ElisaUtils::Genre,
QUrl(QStringLiteral("image://icon/view-media-genre")), {}, {}, ViewHideRating, DelegateWithoutSecondaryText);
}
}
void ViewManager::openAllArtistsFromGenre(const QString &genreName)
{
d->mTargetView = ViewsType::AllArtistsFromGenre;
......
......@@ -49,7 +49,8 @@ public:
RecentlyPlayedTracks,
FilesBrowser,
Context,
RadiosBrowser
RadiosBrowser,
UnknownView,
};
Q_ENUM(ViewsType)
......@@ -97,6 +98,16 @@ public:
Q_ENUM(ViewCanBeRated)
enum ViewPresentationType {
ContextView,
GridView,
ListView,
FileBrowserView,
UnknownViewPresentation,
};
Q_ENUM(ViewPresentationType)
explicit ViewManager(QObject *parent = nullptr);
~ViewManager() override;
......@@ -130,8 +141,6 @@ public Q_SLOTS:
void openView(int viewIndex);
void openParentView(ViewManager::ViewsType viewType, const QString &mainTitle, const QUrl &mainImage);
void openChildView(const QString &innerMainTitle, const QString & innerSecondaryTitle,
const QUrl &innerImage, qulonglong databaseId,
ElisaUtils::PlayListEntryType dataType, ViewManager::AlbumViewStyle albumDiscHeader);
......@@ -146,14 +155,8 @@ private:
void openFrequentlyPlayedTracks(const QString &mainTitle, const QUrl &imageUrl);
void openAllAlbums(const QString &mainTitle, const QUrl &imageUrl);
void openAllArtists(const QString &mainTitle, const QUrl &imageUrl);
void openAllTracks(const QString &mainTitle, const QUrl &imageUrl);
void openAllGenres(const QString &mainTitle, const QUrl &imageUrl);
void openFilesBrowser(const QString &mainTitle, const QUrl &imageUrl);
void openContextView(const QString &mainTitle, const QUrl &imageUrl);
......
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