Warning, file /multimedia/amarok/src/core-impl/collections/support/CollectionManager.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /**************************************************************************************** 0002 * Copyright (c) 2007-2008 Maximilian Kossick <maximilian.kossick@googlemail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef AMAROK_COLLECTIONMANAGER_H 0018 #define AMAROK_COLLECTIONMANAGER_H 0019 0020 #include "amarok_export.h" 0021 #include "core/meta/forward_declarations.h" 0022 0023 #include <QUrl> 0024 0025 #include <QList> 0026 #include <QObject> 0027 0028 0029 namespace Plugins { 0030 class PluginFactory; 0031 } 0032 0033 namespace Collections { 0034 class Collection; 0035 class CollectionFactory; 0036 class TrackProvider; 0037 class QueryMaker; 0038 } 0039 0040 /** Class managing the different collections. 0041 * 0042 * This singleton class is the main repository for all current collections. 0043 * The most useful functions are probably queryMaker and 0044 * viewableCollections 0045 */ 0046 class AMAROK_EXPORT CollectionManager : public QObject 0047 { 0048 Q_OBJECT 0049 0050 public: 0051 0052 /** 0053 * defines the status of a collection in respect to global queries (i.e. queries that query all known collections) 0054 * or the collection browser. 0055 */ 0056 enum CollectionStatus { CollectionDisabled = 1, ///< Collection neither viewable nor queryable (but might produce tracks that can be played) 0057 CollectionViewable = 2, ///< Collection will not be queried by CollectionManager::queryMaker 0058 CollectionQueryable= 4, ///< Collection wil not show up in the browser, but is queryable by global queries 0059 CollectionEnabled = CollectionViewable | CollectionQueryable ///< Collection viewable in the browser and queryable 0060 }; 0061 Q_ENUM( CollectionStatus ) 0062 0063 static CollectionManager *instance(); 0064 0065 /** Destroys the instance of the CollectionManager. 0066 */ 0067 static void destroy(); 0068 0069 /** 0070 * Returns a query maker that queries all queryable the collections 0071 */ 0072 Collections::QueryMaker *queryMaker() const; 0073 0074 /** 0075 * returns all viewable collections. 0076 */ 0077 QList<Collections::Collection*> viewableCollections() const; 0078 0079 //TODO: Remove 0080 /** 0081 * Allows access to one of Amarok's collection. 0082 * 0083 * @deprecated DO NOT USE this method. This is legacy code from the early days of Amarok 0084 * when SqlCollection was the only working collection. If you are writing new code, make 0085 * sure that it is able to handle multiple collections, 0086 * e.g. multiple connected media devices. Using this method means you are lazy. An easy way 0087 * is to use CollectionManager::queryMaker(). Alternatively, access the available collections 0088 * using CollectionManager::queryableCollections() or CollectionManager::viewableCollections() 0089 * and do whatever you want to. 0090 * 0091 */ 0092 Collections::Collection* primaryCollection() const; 0093 0094 /** 0095 This method will try to get a Track object for the given url. This method will return 0 if no Track object 0096 could be created for the url. 0097 */ 0098 Meta::TrackPtr trackForUrl( const QUrl &url ); 0099 0100 CollectionStatus collectionStatus( const QString &collectionId ) const; 0101 0102 QHash<Collections::Collection*, CollectionStatus> collections() const; 0103 0104 /** 0105 * adds a TrackProvider to the list of TrackProviders, 0106 * which allows CollectionManager to create tracks in trackForUrl. 0107 * CollectionManager does not take ownership of the TrackProvider pointer 0108 * 0109 * Note: collections that CollectionManager knows about are automatically 0110 * added to the list of TrackProviders. 0111 * 0112 * @param provider the new TrackProvider 0113 */ 0114 void addTrackProvider( Collections::TrackProvider *provider ); 0115 0116 /** 0117 * removes a TrackProvider. Does not do anything if 0118 * CollectionManager does not know the given TrackProvider. 0119 * 0120 * Note: collections will be automatically removed from 0121 * the list of available TrackProviders. 0122 * 0123 * @param provider the provider to be removed 0124 */ 0125 void removeTrackProvider( Collections::TrackProvider *provider ); 0126 0127 /** 0128 * Set the list of current factories 0129 * 0130 * For every factory that is a CollectionFactory uses it to create new 0131 * collections and register with this manager. 0132 */ 0133 void setFactories( const QList<QSharedPointer<Plugins::PluginFactory> > &factories ); 0134 0135 public Q_SLOTS: 0136 /** Starts the full scan for each collection with CollectionScanCapability */ 0137 void startFullScan(); 0138 /** Starts the incremental scan for each collection with CollectionScanCapability */ 0139 void startIncrementalScan( const QString &directory = QString() ); 0140 void stopScan(); 0141 void checkCollectionChanges(); 0142 0143 Q_SIGNALS: 0144 //deprecated, use collectionAdded( Collections::Collection*, CollectionStatus ) instead 0145 // void collectionAdded( Collections::Collection *newCollection ); 0146 0147 void collectionAdded( Collections::Collection *newCollection, CollectionManager::CollectionStatus status ); 0148 void collectionRemoved( const QString &collectionId ); 0149 void trackProviderAdded( Collections::TrackProvider *provider ); 0150 //this signal will be emitted after major changes to the collection 0151 //e.g. new songs where added, or an album changed 0152 //from compilation to non-compilation (and vice versa) 0153 //it will not be emitted on minor changes (e.g. the tags of a song were changed) 0154 void collectionDataChanged( Collections::Collection *changedCollection ); 0155 0156 private Q_SLOTS: 0157 /** Will be called whenever a registered collection factory creates a new collection */ 0158 void slotNewCollection( Collections::Collection *newCollection ); 0159 /** Will remove the collection that emitted the signal */ 0160 void slotRemoveCollection(); 0161 void slotCollectionChanged(); 0162 0163 private: 0164 static CollectionManager* s_instance; 0165 CollectionManager(); 0166 ~CollectionManager() override; 0167 0168 void init(); 0169 0170 0171 Q_DISABLE_COPY( CollectionManager ) 0172 0173 struct Private; 0174 Private * const d; 0175 }; 0176 0177 #endif /* AMAROK_COLLECTIONMANAGER_H */