File indexing completed on 2024-04-28 04:49:01
0001 /* 0002 SPDX-FileCopyrightText: 2015 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr> 0003 0004 SPDX-License-Identifier: LGPL-3.0-or-later 0005 */ 0006 0007 #ifndef DATAMODEL_H 0008 #define DATAMODEL_H 0009 0010 #include "elisaLib_export.h" 0011 0012 #include "elisautils.h" 0013 #include "datatypes.h" 0014 0015 #include <QAbstractListModel> 0016 #include <QHash> 0017 #include <QString> 0018 0019 #include <memory> 0020 0021 class DataModelPrivate; 0022 class MusicListenersManager; 0023 class DatabaseInterface; 0024 0025 class ELISALIB_EXPORT DataModel : public QAbstractListModel 0026 { 0027 Q_OBJECT 0028 0029 Q_PROPERTY(QString title 0030 READ title 0031 NOTIFY titleChanged) 0032 0033 Q_PROPERTY(QString author 0034 READ author 0035 NOTIFY authorChanged) 0036 0037 Q_PROPERTY(bool isBusy READ isBusy NOTIFY isBusyChanged) 0038 0039 public: 0040 0041 using ListRadioDataType = DataTypes::ListRadioDataType; 0042 0043 using ListTrackDataType = DataTypes::ListTrackDataType; 0044 0045 using TrackDataType = DataTypes::TrackDataType; 0046 0047 using ListAlbumDataType = DataTypes::ListAlbumDataType; 0048 0049 using AlbumDataType = DataTypes::AlbumDataType; 0050 0051 using ListArtistDataType = DataTypes::ListArtistDataType; 0052 0053 using ArtistDataType = DataTypes::ArtistDataType; 0054 0055 using ListGenreDataType = DataTypes::ListGenreDataType; 0056 0057 using GenreDataType = DataTypes::GenreDataType; 0058 0059 using FilterType = ElisaUtils::FilterType; 0060 0061 explicit DataModel(QObject *parent = nullptr); 0062 0063 ~DataModel() override; 0064 0065 [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0066 0067 [[nodiscard]] QHash<int, QByteArray> roleNames() const override; 0068 0069 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override; 0070 0071 [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0072 0073 [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0074 0075 [[nodiscard]] QModelIndex parent(const QModelIndex &child) const override; 0076 0077 [[nodiscard]] QString title() const; 0078 0079 [[nodiscard]] QString author() const; 0080 0081 [[nodiscard]] bool isBusy() const; 0082 0083 Q_SIGNALS: 0084 0085 void titleChanged(); 0086 0087 void authorChanged(); 0088 0089 void needData(ElisaUtils::PlayListEntryType dataType); 0090 0091 void needDataById(ElisaUtils::PlayListEntryType dataType, qulonglong databaseId); 0092 0093 void needDataByGenre(ElisaUtils::PlayListEntryType dataType, const QString &genre); 0094 0095 void needDataByArtist(ElisaUtils::PlayListEntryType dataType, const QString &artist); 0096 0097 void needDataByGenreAndArtist(ElisaUtils::PlayListEntryType dataType, 0098 const QString &genre, const QString &artist); 0099 0100 void needRecentlyPlayedData(ElisaUtils::PlayListEntryType dataType); 0101 0102 void needFrequentlyPlayedData(ElisaUtils::PlayListEntryType dataType); 0103 0104 void isBusyChanged(); 0105 0106 public Q_SLOTS: 0107 0108 void tracksAdded(DataModel::ListTrackDataType newData); 0109 0110 void radiosAdded(DataModel::ListRadioDataType newData); 0111 0112 void trackModified(const DataModel::TrackDataType &modifiedTrack); 0113 0114 void trackRemoved(qulonglong removedTrackId); 0115 0116 void radioRemoved(qulonglong removedRadioId); 0117 0118 void genresAdded(DataModel::ListGenreDataType newData); 0119 0120 void artistsAdded(DataModel::ListArtistDataType newData); 0121 0122 void artistRemoved(qulonglong removedDatabaseId); 0123 0124 void albumsAdded(DataModel::ListAlbumDataType newData); 0125 0126 void albumRemoved(qulonglong removedDatabaseId); 0127 0128 void albumModified(const DataModel::AlbumDataType &modifiedAlbum); 0129 0130 void initialize(MusicListenersManager *manager, DatabaseInterface *database, 0131 ElisaUtils::PlayListEntryType modelType, ElisaUtils::FilterType filter, 0132 const QString &genre, const QString &artist, qulonglong databaseId, 0133 const QUrl &pathFilter); 0134 0135 void initializeByData(MusicListenersManager *manager, DatabaseInterface *database, 0136 ElisaUtils::PlayListEntryType modelType, ElisaUtils::FilterType filter, 0137 const DataTypes::DataType &dataFilter); 0138 0139 private Q_SLOTS: 0140 0141 void cleanedDatabase(); 0142 0143 private: 0144 0145 void radioAdded(const TrackDataType &radiosData); 0146 0147 void radioModified(const DataModel::TrackDataType &modifiedRadio); 0148 0149 [[nodiscard]] int indexFromId(qulonglong id) const; 0150 0151 void connectModel(DatabaseInterface *database); 0152 0153 void setBusy(bool value); 0154 0155 void initializeModel(MusicListenersManager *manager, DatabaseInterface *database, 0156 ElisaUtils::PlayListEntryType modelType, ElisaUtils::FilterType type); 0157 0158 void askModelData(); 0159 0160 void removeRadios(); 0161 0162 std::unique_ptr<DataModelPrivate> d; 0163 0164 }; 0165 0166 #endif // DATAMODEL_H