Commit 94d1ed04 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵 Committed by Nate Graham
Browse files

introduce ViewsListData to handle data of the list of views

to be used by both the model and the ViewManager class handling the
switch between views
parent a7b318dd
......@@ -30,6 +30,7 @@ set(elisaLib_SOURCES
models/editabletrackmetadatamodel.cpp
models/trackcontextmetadatamodel.cpp
models/viewsmodel.cpp
viewslistdata.cpp
localFileConfiguration/elisaconfigurationdialog.cpp
)
......
......@@ -333,6 +333,11 @@ public:
using DataType::DataType;
QString name() const
{
return operator[](key_type::TitleRole).toString();
}
qulonglong databaseId() const
{
return operator[](key_type::DatabaseIdRole).toULongLong();
......
......@@ -27,6 +27,7 @@
#include "managemediaplayercontrol.h"
#include "manageheaderbar.h"
#include "databaseinterface.h"
#include "viewslistdata.h"
#include "elisa_settings.h"
#include <KConfigCore/KAuthorized>
......@@ -101,6 +102,8 @@ public:
std::unique_ptr<ManageHeaderBar> mManageHeaderBar;
std::unique_ptr<ViewsListData> mViewsListData;
QQmlApplicationEngine *mEngine = nullptr;
QFileSystemWatcher mConfigFileWatcher;
......@@ -356,6 +359,9 @@ void ElisaApplication::setQmlEngine(QQmlApplicationEngine *engine)
void ElisaApplication::initializeModels()
{
d->mViewsListData = std::make_unique<ViewsListData>();
Q_EMIT viewsListDataChanged();
d->mMusicManager = std::make_unique<MusicListenersManager>();
Q_EMIT musicManagerChanged();
......@@ -540,6 +546,11 @@ ManageHeaderBar *ElisaApplication::manageHeaderBar() const
return d->mManageHeaderBar.get();
}
ViewsListData *ElisaApplication::viewsListData() const
{
return d->mViewsListData.get();
}
bool ElisaApplication::showProgressOnTaskBar() const
{
auto currentConfiguration = Elisa::ElisaConfiguration::self();
......
......@@ -38,6 +38,7 @@ class AudioWrapper;
class ManageAudioPlayer;
class ManageMediaPlayerControl;
class ManageHeaderBar;
class ViewsListData;
class QQmlApplicationEngine;
class ElisaApplicationPrivate;
......@@ -81,6 +82,8 @@ class ELISALIB_EXPORT ElisaApplication : public QObject
READ manageHeaderBar
NOTIFY manageHeaderBarChanged)
Q_PROPERTY(ViewsListData* viewsListData READ viewsListData NOTIFY viewsListDataChanged)
Q_PROPERTY(bool showProgressOnTaskBar
READ showProgressOnTaskBar
NOTIFY showProgressOnTaskBarChanged)
......@@ -118,6 +121,8 @@ public:
ManageHeaderBar *manageHeaderBar() const;
ViewsListData* viewsListData() const;
bool showProgressOnTaskBar() const;
bool showSystemTrayIcon() const;
......@@ -151,6 +156,8 @@ Q_SIGNALS:
void showSystemTrayIconChanged();
void viewsListDataChanged();
public Q_SLOTS:
void appHelpActivated();
......
......@@ -44,6 +44,7 @@
#include "musiclistenersmanager.h"
#include "trackslistener.h"
#include "viewmanager.h"
#include "viewslistdata.h"
#include "databaseinterface.h"
#include "datatypes.h"
#include "models/datamodel.h"
......@@ -123,6 +124,7 @@ void ElisaQmlTestPlugin::registerTypes(const char *uri)
qmlRegisterType<ProgressIndicator>(uri, 1, 0, "ProgressIndicator");
qmlRegisterType<MusicListenersManager>(uri, 1, 0, "MusicListenersManager");
qmlRegisterType<ViewManager>(uri, 1, 0, "ViewManager");
qmlRegisterType<ViewsListData>(uri, 1, 0, "ViewsListData");
qmlRegisterType<DataModel>(uri, 1, 0, "DataModel");
qmlRegisterType<TrackMetadataModel>(uri, 1, 0, "TrackMetadataModel");
qmlRegisterType<TrackContextMetaDataModel>(uri, 1, 0, "TrackContextMetaDataModel");
......
......@@ -17,51 +17,14 @@
#include "viewsmodel.h"
#include "viewmanager.h"
#include <KI18n/KLocalizedString>
#include <QUrl>
#include "viewslistdata.h"
class ViewsModelPrivate
{
public:
QList<ViewManager::ViewsType> mTypes;
QHash<ViewManager::ViewsType, QString> mNames;
QHash<ViewManager::ViewsType, QUrl> mIcons;
ViewsModelPrivate()
{
mTypes = {ViewManager::Context, ViewManager::RecentlyPlayedTracks,
ViewManager::FrequentlyPlayedTracks, ViewManager::AllAlbums,
ViewManager::AllArtists, ViewManager::AllTracks,
ViewManager::AllGenres, ViewManager::FilesBrowser,
ViewManager::RadiosBrowser};
mNames = {{ViewManager::Context, {i18nc("Title of the view of the playlist", "Now Playing")}},
{ViewManager::RecentlyPlayedTracks, {i18nc("Title of the view of recently played tracks", "Recently Played")}},
{ViewManager::FrequentlyPlayedTracks, {i18nc("Title of the view of frequently played tracks", "Frequently Played")}},
{ViewManager::AllAlbums, {i18nc("Title of the view of all albums", "Albums")}},
{ViewManager::AllArtists, {i18nc("Title of the view of all artists", "Artists")}},
{ViewManager::AllTracks, {i18nc("Title of the view of all tracks", "Tracks")}},
{ViewManager::AllGenres, {i18nc("Title of the view of all genres", "Genres")}},
{ViewManager::FilesBrowser, {i18nc("Title of the file browser view", "Files")}},
{ViewManager::RadiosBrowser, {i18nc("Title of the file radios browser view", "Radios")}}};
mIcons = {{ViewManager::Context, QUrl{QStringLiteral("image://icon/view-media-lyrics")}},
{ViewManager::RecentlyPlayedTracks, QUrl{QStringLiteral("image://icon/media-playlist-play")}},
{ViewManager::FrequentlyPlayedTracks, QUrl{QStringLiteral("image://icon/view-media-playcount")}},
{ViewManager::AllAlbums, QUrl{QStringLiteral("image://icon/view-media-album-cover")}},
{ViewManager::AllArtists, QUrl{QStringLiteral("image://icon/view-media-artist")}},
{ViewManager::AllTracks, QUrl{QStringLiteral("image://icon/view-media-track")}},
{ViewManager::AllGenres, QUrl{QStringLiteral("image://icon/view-media-genre")}},
{ViewManager::FilesBrowser, QUrl{QStringLiteral("image://icon/document-open-folder")}},
{ViewManager::RadiosBrowser, QUrl{QStringLiteral("image://icon/radio")}}};
}
ViewsListData *mViewsData = nullptr;
};
......@@ -76,8 +39,7 @@ QHash<int, QByteArray> ViewsModel::roleNames() const
{
auto result = QAbstractListModel::roleNames();
result[ItemType] = "type";
result[ImageName] = "image";
result[ImageNameRole] = "image";
return result;
}
......@@ -97,13 +59,21 @@ int ViewsModel::rowCount(const QModelIndex &parent) const
return 0;
}
return d->mTypes.count();
if (!d->mViewsData) {
return 0;
}
return d->mViewsData->count();
}
QVariant ViewsModel::data(const QModelIndex &index, int role) const
{
auto result = QVariant{};
if (!d->mViewsData) {
return result;
}
if (!index.isValid()) {
return result;
}
......@@ -111,13 +81,10 @@ QVariant ViewsModel::data(const QModelIndex &index, int role) const
switch(role)
{
case Qt::DisplayRole:
result = d->mNames[d->mTypes[index.row()]];
break;
case ColumnRoles::ImageName:
result = d->mIcons[d->mTypes[index.row()]];
result = d->mViewsData->title(index.row());
break;
case ColumnRoles::ItemType:
result = d->mTypes[index.row()];
case ColumnRoles::ImageNameRole:
result = d->mViewsData->iconUrl(index.row());
break;
}
......@@ -150,5 +117,22 @@ QModelIndex ViewsModel::parent(const QModelIndex &child) const
return result;
}
ViewsListData *ViewsModel::viewsData() const
{
return d->mViewsData;
}
void ViewsModel::setViewsData(ViewsListData *viewsData)
{
if (d->mViewsData == viewsData) {
return;
}
beginResetModel();
d->mViewsData = viewsData;
Q_EMIT viewsDataChanged();
endResetModel();
}
#include "moc_viewsmodel.cpp"
......@@ -27,16 +27,18 @@
#include <memory>
class ViewsModelPrivate;
class ViewsListData;
class ELISALIB_EXPORT ViewsModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(ViewsListData* viewsData READ viewsData WRITE setViewsData NOTIFY viewsDataChanged)
public:
enum ColumnRoles {
ItemType = Qt::UserRole + 1,
ImageName,
ImageNameRole = Qt::UserRole + 1,
};
explicit ViewsModel(QObject *parent = nullptr);
......@@ -55,10 +57,19 @@ public:
QModelIndex parent(const QModelIndex &child) const override;
ViewsListData* viewsData() const;
Q_SIGNALS:
void viewsDataChanged();
public Q_SLOTS:
void setViewsData(ViewsListData* viewsData);
private:
std::unique_ptr<ViewsModelPrivate> d;
};
#endif // VIEWSMODEL_H
......@@ -143,6 +143,8 @@ RowLayout {
ViewsModel {
id: pageModel
viewsData: elisa.viewsListData
}
ViewSelector {
......
......@@ -23,7 +23,6 @@ import org.kde.kirigami 2.5 as Kirigami
FocusScope {
id: rootItem
property var viewType: model.type
property bool isSelected
signal clicked()
......
/*
* Copyright 2020 Matthieu Gallien <matthieu_gallien@yahoo.fr>
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "viewslistdata.h"
#include <KI18n/KLocalizedString>
#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;
};
ViewsListData::ViewsListData(QObject *parent) : QObject(parent), d(std::make_unique<ViewsListDataPrivate>())
{
}
ViewsListData::~ViewsListData() = default;
int ViewsListData::count() const
{
return d->mData.count();
}
const QString &ViewsListData::title(int index) const
{
return d->mData[index].mTitle;
}
const QUrl &ViewsListData::iconUrl(int index) const
{
return d->mData[index].mIconUrl;
}
#include "moc_viewslistdata.cpp"
/*
* Copyright 2020 Matthieu Gallien <matthieu_gallien@yahoo.fr>
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef VIEWSLISTDATA_H
#define VIEWSLISTDATA_H
#include "elisaLib_export.h"
#include <QObject>
#include "viewmanager.h"
#include "datatypes.h"
#include <memory>
class QUrl;
class QString;
class ViewsListDataPrivate;
class ELISALIB_EXPORT ViewsListData : public QObject
{
Q_OBJECT
public:
explicit ViewsListData(QObject *parent = nullptr);
~ViewsListData();
int count() const;
const QString& title(int index) const;
const QUrl& iconUrl(int index) const;
Q_SIGNALS:
public Q_SLOTS:
private:
std::unique_ptr<ViewsListDataPrivate> d;
};
#endif // VIEWSLISTDATA_H
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