File indexing completed on 2024-04-21 04:49:01
0001 /* 0002 SPDX-FileCopyrightText: 2016 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr> 0003 0004 SPDX-License-Identifier: LGPL-3.0-or-later 0005 */ 0006 0007 #ifndef MUSICLISTENERSMANAGER_H 0008 #define MUSICLISTENERSMANAGER_H 0009 0010 #include "elisaLib_export.h" 0011 0012 #include "datatypes.h" 0013 #include "elisautils.h" 0014 0015 #include <QObject> 0016 #include <QMediaPlayer> 0017 0018 #include <memory> 0019 0020 class DatabaseInterface; 0021 class MusicListenersManagerPrivate; 0022 class MediaPlayList; 0023 class ElisaApplication; 0024 class ModelDataLoader; 0025 class TracksListener; 0026 0027 class ELISALIB_EXPORT MusicListenersManager : public QObject 0028 { 0029 0030 Q_OBJECT 0031 0032 Q_PROPERTY(DatabaseInterface* viewDatabase 0033 READ viewDatabase 0034 NOTIFY viewDatabaseChanged) 0035 0036 Q_PROPERTY(int importedTracksCount 0037 READ importedTracksCount 0038 NOTIFY importedTracksCountChanged) 0039 0040 Q_PROPERTY(ElisaApplication* elisaApplication 0041 READ elisaApplication 0042 WRITE setElisaApplication 0043 NOTIFY elisaApplicationChanged) 0044 0045 Q_PROPERTY(TracksListener* tracksListener 0046 READ tracksListener 0047 NOTIFY tracksListenerChanged) 0048 0049 Q_PROPERTY(bool indexerBusy 0050 READ indexerBusy 0051 NOTIFY indexerBusyChanged) 0052 0053 Q_PROPERTY(bool fileSystemIndexerActive 0054 READ fileSystemIndexerActive 0055 NOTIFY fileSystemIndexerActiveChanged) 0056 0057 Q_PROPERTY(bool androidIndexerActive 0058 READ androidIndexerActive 0059 NOTIFY androidIndexerActiveChanged) 0060 0061 Q_PROPERTY(bool androidIndexerAvailable 0062 READ androidIndexerAvailable 0063 NOTIFY androidIndexerAvailableChanged) 0064 0065 public: 0066 0067 enum class CollectionScan { 0068 Soft, 0069 Hard, 0070 }; 0071 Q_ENUM(CollectionScan) 0072 0073 explicit MusicListenersManager(QObject *parent = nullptr); 0074 0075 ~MusicListenersManager() override; 0076 0077 [[nodiscard]] DatabaseInterface* viewDatabase() const; 0078 0079 void subscribeForTracks(MediaPlayList *client); 0080 0081 [[nodiscard]] int importedTracksCount() const; 0082 0083 [[nodiscard]] ElisaApplication* elisaApplication() const; 0084 0085 [[nodiscard]] TracksListener* tracksListener() const; 0086 0087 [[nodiscard]] bool indexerBusy() const; 0088 0089 [[nodiscard]] bool fileSystemIndexerActive() const; 0090 0091 [[nodiscard]] bool androidIndexerActive() const; 0092 0093 [[nodiscard]] bool androidIndexerAvailable() const; 0094 0095 Q_SIGNALS: 0096 0097 void viewDatabaseChanged(); 0098 0099 void applicationIsTerminating(); 0100 0101 void tracksListenerChanged(); 0102 0103 void importedTracksCountChanged(); 0104 0105 void elisaApplicationChanged(); 0106 0107 void removeTracksInError(const QList<QUrl> &tracks); 0108 0109 void displayTrackError(const QString &fileName); 0110 0111 void indexerBusyChanged(); 0112 0113 void clearDatabase(); 0114 0115 void clearedDatabase(); 0116 0117 void fileSystemIndexerActiveChanged(); 0118 0119 void androidIndexerActiveChanged(); 0120 0121 void androidIndexerAvailableChanged(); 0122 0123 void refreshDatabase(); 0124 0125 public Q_SLOTS: 0126 0127 void databaseReady(); 0128 0129 void applicationAboutToQuit(); 0130 0131 void setElisaApplication(ElisaApplication* elisaApplication); 0132 0133 void playBackError(const QUrl &sourceInError, QMediaPlayer::Error playerError); 0134 0135 void deleteElementById(ElisaUtils::PlayListEntryType entryType, qulonglong databaseId); 0136 0137 void connectModel(ModelDataLoader *dataLoader); 0138 0139 void scanCollection(CollectionScan scantype); 0140 0141 void updateSingleFileMetaData(const QUrl &url, DataTypes::ColumnsRoles role, const QVariant &data); 0142 0143 private Q_SLOTS: 0144 0145 void configChanged(); 0146 0147 void increaseImportedTracksCount(const DataTypes::ListTrackDataType &allTracks); 0148 0149 void decreaseImportedTracksCount(); 0150 0151 void monitorStartingListeners(); 0152 0153 void monitorEndingListeners(); 0154 0155 void cleanedDatabase(); 0156 0157 private: 0158 0159 void startLocalFileSystemIndexing(); 0160 0161 void startAndroidIndexing(); 0162 0163 auto initializeRootPath(); 0164 0165 std::unique_ptr<MusicListenersManagerPrivate> d; 0166 0167 void createTracksListener(); 0168 0169 }; 0170 0171 #endif // MUSICLISTENERSMANAGER_H