Commit 627e41be authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

let views be configured to use their specific model/proxy model

all views except FileBrowserView are working fine

automatic tests are broken
parent 975c1ec8
......@@ -64,6 +64,8 @@
#include <QAction>
#include <QStandardPaths>
#include <QAbstractProxyModel>
#include <QAbstractItemModel>
#include <QQmlExtensionPlugin>
#include <QQmlEngine>
......@@ -129,6 +131,8 @@ void ElisaQmlTestPlugin::registerTypes(const char *uri)
qmlRegisterType<AudioWrapper>(uri, 1, 0, "AudioWrapper");
qmlRegisterUncreatableType<DatabaseInterface>(uri, 1, 0, "DatabaseInterface", QStringLiteral("Only created in c++"));
qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", QStringLiteral("Abstract Qt type"));
qmlRegisterUncreatableType<QAbstractProxyModel>(uri, 1, 0, "AbstractProxyModel", QStringLiteral("Abstract Qt type"));
#if defined Qt5DBus_FOUND && Qt5DBus_FOUND
qmlRegisterType<Mpris2>(uri, 1, 0, "Mpris2");
......
......@@ -50,6 +50,11 @@ void FileBrowserModel::setUrl(const QString &url)
emit urlChanged();
}
bool FileBrowserModel::isBusy() const
{
return false;
}
QHash<int, QByteArray> FileBrowserModel::roleNames() const
{
auto roles = KDirModel::roleNames();
......@@ -112,4 +117,11 @@ QVariant FileBrowserModel::data(const QModelIndex &index, int role) const
return result;
}
void FileBrowserModel::initialize(MusicListenersManager *manager, DatabaseInterface *database,
ElisaUtils::PlayListEntryType modelType, ElisaUtils::FilterType filter,
const QString &genre, const QString &artist, qulonglong databaseId)
{
}
#include "moc_filebrowsermodel.cpp"
......@@ -9,13 +9,19 @@
#include "elisaLib_export.h"
#include "elisautils.h"
#include <KIOWidgets/KDirModel>
class MusicListenersManager;
class DatabaseInterface;
class ELISALIB_EXPORT FileBrowserModel : public KDirModel
{
Q_OBJECT
Q_PROPERTY(bool isBusy READ isBusy NOTIFY isBusyChanged)
public:
enum ColumnsRoles {
......@@ -40,10 +46,21 @@ public:
void setUrl(const QString &url);
bool isBusy() const;
Q_SIGNALS:
void urlChanged();
void isBusyChanged();
public Q_SLOTS:
void initialize(MusicListenersManager *manager, DatabaseInterface *database,
ElisaUtils::PlayListEntryType modelType, ElisaUtils::FilterType filter,
const QString &genre, const QString &artist, qulonglong databaseId);
};
#endif //FILEBROWSERMODEL_H
......@@ -56,6 +56,8 @@ RowLayout {
secondaryTitle: secondaryTitle,
image: imageUrl,
modelType: dataType,
realModel: model,
proxyModel: associatedProxyModel,
defaultIcon: viewDefaultIcon,
showRating: viewShowRating,
delegateDisplaySecondaryText: viewDelegateDisplaySecondaryText,
......@@ -84,6 +86,8 @@ RowLayout {
databaseId: databaseId,
image: imageUrl,
modelType: dataType,
realModel: model,
proxyModel: associatedProxyModel,
sortRole: sortRole,
sortAscending: sortOrder,
stackView: browseStackView,
......
......@@ -17,6 +17,8 @@ FocusScope {
property alias secondaryTitle: gridView.secondaryTitle
property alias image: gridView.image
property var modelType
property AbstractItemModel realModel
property AbstractProxyModel proxyModel
property alias defaultIcon: gridView.defaultIcon
property alias showRating: gridView.showRating
property alias delegateDisplaySecondaryText: gridView.delegateDisplaySecondaryText
......@@ -24,6 +26,7 @@ FocusScope {
property alias expandedFilterView: gridView.expandedFilterView
property string genreFilterText
property string artistFilter
property bool modelIsInitialized: false
focus: true
......@@ -32,19 +35,31 @@ FocusScope {
function initializeModel()
{
realModel.initialize(elisa.musicManager, elisa.musicManager.viewDatabase,
modelType, filterType, genreFilterText, artistFilter, 0)
}
if (!proxyModel) {
return
}
DataModel {
id: realModel
}
if (!realModel) {
return
}
GridViewProxyModel {
id: proxyModel
if (!elisa.musicManager) {
return
}
sourceModel: realModel
playList: elisa.mediaPlayListProxyModel
if (modelIsInitialized) {
return
}
proxyModel.sourceModel = realModel
proxyModel.dataType = modelType
proxyModel.playList = elisa.mediaPlayListProxyModel
gridView.contentModel = proxyModel
realModel.initialize(elisa.musicManager, elisa.musicManager.viewDatabase,
modelType, filterType, genreFilterText, artistFilter, 0)
modelIsInitialized = true
}
GridBrowserView {
......@@ -54,8 +69,6 @@ FocusScope {
anchors.fill: parent
contentModel: proxyModel
onEnqueue: elisa.mediaPlayListProxyModel.enqueue(fullData, name,
ElisaUtils.AppendPlayList,
ElisaUtils.DoNotTriggerPlay)
......@@ -69,6 +82,7 @@ FocusScope {
onGoBack: viewManager.goBack()
Loader {
id: busyIndicatorLoader
anchors.centerIn: parent
height: Kirigami.Units.gridUnit * 5
width: height
......@@ -89,8 +103,6 @@ FocusScope {
}
Component.onCompleted: {
if (elisa.musicManager) {
initializeModel()
}
initializeModel()
}
}
......@@ -21,10 +21,13 @@ FocusScope {
property alias expandedFilterView: listView.expandedFilterView
property alias image: listView.image
property var modelType
property alias sortRole: proxyModel.sortRole
property AbstractItemModel realModel
property AbstractProxyModel proxyModel
property int sortRole
property var sortAscending
property bool displaySingleAlbum: false
property alias radioCase: listView.showCreateRadioButton
property bool modelIsInitialized: false
function openMetaDataView(databaseId, url, entryType) {
metadataLoader.setSource("MediaTrackMetadataView.qml",
......@@ -56,15 +59,35 @@ FocusScope {
metadataLoader.active = true
}
DataModel {
id: realModel
}
function initializeModel()
{
if (!proxyModel) {
return
}
if (!realModel) {
return
}
if (!elisa.musicManager) {
return
}
if (modelIsInitialized) {
return
}
AllTracksProxyModel {
id: proxyModel
proxyModel.sourceModel = realModel
proxyModel.dataType = modelType
proxyModel.playList = elisa.mediaPlayListProxyModel
listView.contentModel = proxyModel
sourceModel: realModel
playList: elisa.mediaPlayListProxyModel
if (!displaySingleAlbum) {
proxyModel.sortModel(sortAscending)
}
realModel.initialize(elisa.musicManager, elisa.musicManager.viewDatabase,
modelType, filterType, mainTitle, secondaryTitle, databaseId)
}
Loader {
......@@ -206,9 +229,7 @@ FocusScope {
Connections {
target: elisa
onMusicManagerChanged: realModel.initialize(elisa.musicManager,
elisa.musicManager.viewDatabase,
modelType)
onMusicManagerChanged: initializeModel()
}
Connections {
......@@ -220,12 +241,6 @@ FocusScope {
}
Component.onCompleted: {
if (elisa.musicManager) {
realModel.initialize(elisa.musicManager, elisa.musicManager.viewDatabase, modelType, filterType, mainTitle, secondaryTitle, databaseId)
}
if (!displaySingleAlbum) {
proxyModel.sortModel(sortAscending)
}
initializeModel()
}
}
......@@ -58,11 +58,12 @@ FocusScope {
}
Loader {
active: contentModel
active: contentModel !== undefined
sourceComponent: Binding {
target: contentModel
property: 'filterRating'
when: contentModel !== undefined
value: navigationBar.filterRating
}
}
......
......@@ -9,6 +9,10 @@
#include "viewslistdata.h"
#include "datatypes.h"
#include "viewsLogging.h"
#include "models/datamodel.h"
#include "models/gridviewproxymodel.h"
#include "models/filebrowsermodel.h"
#include "models/filebrowserproxymodel.h"
#include <KI18n/KLocalizedString>
......@@ -21,6 +25,7 @@ public:
{ElisaUtils::Album, {{},
QUrl{QStringLiteral("image://icon/view-media-track")},
ViewManager::ListView,
ViewManager::GenericDataModel,
ElisaUtils::FilterById,
ElisaUtils::Track,
Qt::DisplayRole,
......@@ -31,6 +36,7 @@ public:
{ElisaUtils::Genre, {{},
QUrl{QStringLiteral("image://icon/view-media-artist")},
ViewManager::GridView,
ViewManager::GenericDataModel,
ElisaUtils::FilterByGenre,
ElisaUtils::Artist,
QUrl{QStringLiteral("image://icon/view-media-artist")},
......@@ -39,6 +45,7 @@ public:
{ElisaUtils::Artist, {{},
QUrl{QStringLiteral("image://icon/view-media-album-cover")},
ViewManager::GridView,
ViewManager::GenericDataModel,
ElisaUtils::FilterByArtist,
ElisaUtils::Album,
QUrl{QStringLiteral("image://icon/media-optical-audio")},
......@@ -185,6 +192,23 @@ void ViewManager::openViewFromData(const ViewParameters &viewParamaters)
d->mViewParametersStack.pop_back();
}
QAbstractItemModel *newModel = nullptr;
QAbstractProxyModel *proxyModel = nullptr;
switch (viewParamaters.mModelType)
{
case FileBrowserModel:
newModel = new ::FileBrowserModel;
proxyModel = new FileBrowserProxyModel;
break;
case GenericDataModel:
newModel = new DataModel;
proxyModel = new GridViewProxyModel;
break;
case UnknownModelType:
break;
}
d->mViewParametersStack.push_back(viewParamaters);
switch (viewParamaters.mViewPresentationType)
{
......@@ -192,24 +216,27 @@ void ViewManager::openViewFromData(const ViewParameters &viewParamaters)
qCDebug(orgKdeElisaViews()) << "ViewManager::openViewFromData" << viewParamaters.mViewPresentationType
<< viewParamaters.mFilterType
<< viewParamaters.mDepth << viewParamaters.mMainTitle << viewParamaters.mSecondaryTitle
<< viewParamaters.mMainImage << viewParamaters.mDataType << viewParamaters.mFallbackItemIcon
<< viewParamaters.mMainImage << viewParamaters.mDataType
<< viewParamaters.mModelType << viewParamaters.mFallbackItemIcon
<< viewParamaters.mGenreNameFilter << viewParamaters.mArtistNameFilter
<< viewParamaters.mViewCanBeRated << viewParamaters.mShowSecondaryTextOnDelegates;
Q_EMIT openGridView(viewParamaters.mFilterType, viewParamaters.mDepth,
viewParamaters.mMainTitle, viewParamaters.mSecondaryTitle, viewParamaters.mMainImage,
viewParamaters.mDataType, viewParamaters.mFallbackItemIcon,
viewParamaters.mDataType, newModel, proxyModel, viewParamaters.mFallbackItemIcon,
viewParamaters.mGenreNameFilter, viewParamaters.mArtistNameFilter,
viewParamaters.mViewCanBeRated, viewParamaters.mShowSecondaryTextOnDelegates);
break;
case ViewPresentationType::ListView:
qCDebug(orgKdeElisaViews()) << "ViewManager::openViewFromData" << viewParamaters.mFilterType
<< viewParamaters.mDepth << viewParamaters.mMainTitle << viewParamaters.mSecondaryTitle
<< viewParamaters.mDatabaseIdFilter << viewParamaters.mMainImage << viewParamaters.mDataType
<< viewParamaters.mDatabaseIdFilter << viewParamaters.mMainImage
<< viewParamaters.mModelType << viewParamaters.mDataType
<< viewParamaters.mSortRole << viewParamaters.mSortOrder << viewParamaters.mAlbumCardinality
<< viewParamaters.mAlbumViewStyle << viewParamaters.mRadioSpecificStyle;
Q_EMIT openListView(viewParamaters.mFilterType, viewParamaters.mDepth, viewParamaters.mMainTitle, viewParamaters.mSecondaryTitle,
viewParamaters.mDatabaseIdFilter, viewParamaters.mMainImage, viewParamaters.mDataType, viewParamaters.mSortRole,
viewParamaters.mSortOrder, viewParamaters.mAlbumCardinality, viewParamaters.mAlbumViewStyle, viewParamaters.mRadioSpecificStyle);
viewParamaters.mDatabaseIdFilter, viewParamaters.mMainImage, viewParamaters.mDataType,
newModel, proxyModel, viewParamaters.mSortRole, viewParamaters.mSortOrder,
viewParamaters.mAlbumCardinality, viewParamaters.mAlbumViewStyle, viewParamaters.mRadioSpecificStyle);
break;
case ViewPresentationType::FileBrowserView:
qCDebug(orgKdeElisaViews()) << "ViewManager::openViewFromData" << viewParamaters.mViewPresentationType
......
......@@ -20,6 +20,8 @@
class ViewManagerPrivate;
class ViewParameters;
class ViewsListData;
class QAbstractItemModel;
class QAbstractProxyModel;
class ELISALIB_EXPORT ViewManager : public QObject
{
......@@ -78,6 +80,14 @@ public:
Q_ENUM(ViewPresentationType)
enum ModelType {
GenericDataModel,
FileBrowserModel,
UnknownModelType,
};
Q_ENUM(ModelType)
explicit ViewManager(QObject *parent = nullptr);
~ViewManager() override;
......@@ -90,14 +100,15 @@ Q_SIGNALS:
void openGridView(ElisaUtils::FilterType filterType, int expectedDepth,
const QString &mainTitle, const QString &secondaryTitle, const QUrl &imageUrl,
ElisaUtils::PlayListEntryType dataType, const QUrl &viewDefaultIcon,
const QString &genreNameFilter, const QString &artistNameFilter,
ViewManager::ViewCanBeRated viewShowRating,
ElisaUtils::PlayListEntryType dataType, QAbstractItemModel *model,
QAbstractProxyModel *associatedProxyModel, const QUrl &viewDefaultIcon, const QString &genreNameFilter,
const QString &artistNameFilter, ViewManager::ViewCanBeRated viewShowRating,
ViewManager::DelegateUseSecondaryText viewDelegateDisplaySecondaryText);
void openListView(ElisaUtils::FilterType filterType, int expectedDepth,
const QString &mainTitle, const QString &secondaryTitle, qulonglong databaseId,
const QUrl &imageUrl, ElisaUtils::PlayListEntryType dataType, const QVariant &sortRole,
const QUrl &imageUrl, ElisaUtils::PlayListEntryType dataType, QAbstractItemModel *model,
QAbstractProxyModel *associatedProxyModel, const QVariant &sortRole,
Qt::SortOrder sortOrder, ViewManager::AlbumCardinality displaySingleAlbum,
ViewManager::AlbumViewStyle showDiscHeaders, ViewManager::RadioSpecificStyle radioCase);
......
......@@ -19,6 +19,7 @@ public:
{{i18nc("Title of the view of recently played tracks", "Recently Played")},
QUrl{QStringLiteral("image://icon/media-playlist-play")},
ViewManager::ListView,
ViewManager::GenericDataModel,
ElisaUtils::FilterByRecentlyPlayed,
ElisaUtils::Track,
DataTypes::LastPlayDate,
......@@ -29,6 +30,7 @@ public:
{{i18nc("Title of the view of frequently played tracks", "Frequently Played")},
QUrl{QStringLiteral("image://icon/view-media-playcount")},
ViewManager::ListView,
ViewManager::GenericDataModel,
ElisaUtils::FilterByFrequentlyPlayed,
ElisaUtils::Track,
DataTypes::PlayFrequency,
......@@ -39,6 +41,7 @@ public:
{{i18nc("Title of the view of all albums", "Albums")},
QUrl{QStringLiteral("image://icon/view-media-album-cover")},
ViewManager::GridView,
ViewManager::GenericDataModel,
ElisaUtils::NoFilter,
ElisaUtils::Album,
QUrl{QStringLiteral("image://icon/media-optical-audio")},
......@@ -47,6 +50,7 @@ public:
{{i18nc("Title of the view of all artists", "Artists")},
QUrl{QStringLiteral("image://icon/view-media-artist")},
ViewManager::GridView,
ViewManager::GenericDataModel,
ElisaUtils::NoFilter,
ElisaUtils::Artist,
QUrl{QStringLiteral("image://icon/view-media-artist")},
......@@ -55,6 +59,7 @@ public:
{{i18nc("Title of the view of all tracks", "Tracks")},
QUrl{QStringLiteral("image://icon/view-media-track")},
ViewManager::ListView,
ViewManager::GenericDataModel,
ElisaUtils::NoFilter,
ElisaUtils::Track,
Qt::DisplayRole,
......@@ -65,6 +70,7 @@ public:
{{i18nc("Title of the view of all genres", "Genres")},
QUrl{QStringLiteral("image://icon/view-media-genre")},
ViewManager::GridView,
ViewManager::GenericDataModel,
ElisaUtils::NoFilter,
ElisaUtils::Genre,
QUrl{QStringLiteral("image://icon/view-media-genre")},
......@@ -72,10 +78,13 @@ public:
ViewManager::ViewHideRating},
{{i18nc("Title of the file browser view", "Files")},
QUrl{QStringLiteral("image://icon/document-open-folder")},
ViewManager::FileBrowserView},
ViewManager::GridView,
ViewManager::FileBrowserModel,
},
{{i18nc("Title of the file radios browser view", "Radios")},
QUrl{QStringLiteral("image://icon/radio")},
ViewManager::ListView,
ViewManager::GenericDataModel,
ElisaUtils::NoFilter,
ElisaUtils::Radio,
Qt::DisplayRole,
......
......@@ -39,6 +39,19 @@ public:
ViewParameters(QString mainTitle,
QUrl mainImage,
ViewManager::ViewPresentationType viewPresentationType,
ViewManager::ModelType modelType)
: mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
, mModelType(modelType)
, mIsValid(true)
{
}
ViewParameters(QString mainTitle,
QUrl mainImage,
ViewManager::ViewPresentationType viewPresentationType,
ViewManager::ModelType modelType,
ElisaUtils::FilterType filterType,
ElisaUtils::PlayListEntryType dataType,
QUrl fallbackItemIcon,
......@@ -47,6 +60,7 @@ public:
: mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
, mModelType(modelType)
, mFilterType(filterType)
, mDataType(dataType)
, mFallbackItemIcon(std::move(fallbackItemIcon))
......@@ -59,6 +73,7 @@ public:
ViewParameters(QString mainTitle,
QUrl mainImage,
ViewManager::ViewPresentationType viewPresentationType,
ViewManager::ModelType modelType,
ElisaUtils::FilterType filterType,
ElisaUtils::PlayListEntryType dataType,
int sortRole,
......@@ -69,6 +84,7 @@ public:
: mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
, mModelType(modelType)
, mFilterType(filterType)
, mDataType(dataType)
, mSortRole(sortRole)
......@@ -83,7 +99,8 @@ public:
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 &&
mModelType == other.mModelType && 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 &&
......@@ -95,7 +112,8 @@ public:
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 ||
mModelType != other.mModelType || 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 ||
......@@ -112,6 +130,8 @@ public:
ViewManager::ViewPresentationType mViewPresentationType = ViewManager::UnknownViewPresentation;
ViewManager::ModelType mModelType = ViewManager::UnknownModelType;
ElisaUtils::FilterType mFilterType = ElisaUtils::UnknownFilter;
ElisaUtils::PlayListEntryType mDataType = ElisaUtils::Unknown;
......
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