File indexing completed on 2024-05-19 04:49:27
0001 /**************************************************************************************** 0002 * Copyright (c) 2007-2008 Maximilian Kossick <maximilian.kossick@googlemail.com> * 0003 * Copyright (c) 2012 Matěj Laitl <matej@laitl.cz> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #ifndef AMAROK_COLLECTION_H 0019 #define AMAROK_COLLECTION_H 0020 0021 #include "core/amarokcore_export.h" 0022 #include "core/interfaces/MetaCapability.h" 0023 #include "core/support/PluginFactory.h" 0024 #include "AmarokSharedPointer.h" 0025 0026 #include <QObject> 0027 0028 namespace Meta { 0029 class Track; 0030 typedef AmarokSharedPointer<Track> TrackPtr; 0031 } 0032 namespace Playlists { 0033 } 0034 0035 class QIcon; 0036 0037 namespace Collections 0038 { 0039 class Collection; 0040 class CollectionLocation; 0041 class QueryMaker; 0042 typedef QList<Collection*> CollectionList; 0043 0044 /** A plugin that creates new collections. 0045 */ 0046 class AMAROKCORE_EXPORT CollectionFactory : public Plugins::PluginFactory 0047 { 0048 Q_OBJECT 0049 0050 public: 0051 CollectionFactory(); 0052 ~CollectionFactory() override; 0053 0054 Q_SIGNALS: 0055 void newCollection( Collections::Collection *newCollection ); 0056 }; 0057 0058 /** A TrackProvider is a class that can lookup urls and return Track objects. 0059 * 0060 * A track provider is implemented by every collection, but there 0061 * are also a couple of other track providers. 0062 * All TrackProvider are managed by the CollectionManager. 0063 */ 0064 class AMAROKCORE_EXPORT TrackProvider 0065 { 0066 public: 0067 TrackProvider(); 0068 virtual ~TrackProvider(); 0069 0070 /** 0071 * Returns true if this track provider has a chance of providing the 0072 * track specified by @p url. 0073 * This should do a minimal amount of checking, and return quickly. 0074 */ 0075 virtual bool possiblyContainsTrack( const QUrl &url ) const; 0076 0077 /** 0078 * Creates a TrackPtr object for url @p url. Returns a null track Ptr if 0079 * it cannot be done. 0080 * If asynchronysity is desired it is suggested to return a MetaProxy track here 0081 * and have the proxy watch for the real track. 0082 */ 0083 virtual Meta::TrackPtr trackForUrl( const QUrl &url ); 0084 }; 0085 0086 class AMAROKCORE_EXPORT Collection : public QObject, public TrackProvider, public MetaCapability 0087 { 0088 Q_OBJECT 0089 0090 public: 0091 ~Collection() override; 0092 0093 /** 0094 * The collection's querymaker 0095 * @return A querymaker that belongs to this collection. 0096 */ 0097 virtual QueryMaker *queryMaker() = 0; 0098 0099 /** 0100 * The protocol of uids coming from this collection. 0101 * @return A string of the protocol, without the :// 0102 */ 0103 virtual QString uidUrlProtocol() const; 0104 0105 /** 0106 * @return A unique identifier for this collection 0107 */ 0108 virtual QString collectionId() const = 0; 0109 0110 /** 0111 * @return a user visible name for this collection, to be displayed in the collectionbrowser and elsewhere 0112 */ 0113 virtual QString prettyName() const = 0; 0114 0115 /** 0116 * @return an icon representing this collection 0117 */ 0118 virtual QIcon icon() const = 0; 0119 0120 virtual bool hasCapacity() const { return false; } 0121 virtual float usedCapacity() const { return 0.0; } 0122 virtual float totalCapacity() const { return 0.0; } 0123 0124 /** 0125 * Create collection location that can be used to copy track to this 0126 * collection or to delete collection tracks. If you don't call 0127 * prepare{Move,Copy,Remove} on it, you must delete it after use. 0128 */ 0129 virtual Collections::CollectionLocation *location(); 0130 0131 /** 0132 * Return true if this collection can be written to (tracks added, removed). 0133 * Convenience short-cut for calling CollectionLocation's isWritable. 0134 */ 0135 virtual bool isWritable() const; 0136 0137 /** 0138 * Return true if user can choose track file path within this collection. 0139 * Convenience short-cut for calling CollectionLocation's isOrganizable. 0140 */ 0141 virtual bool isOrganizable() const; 0142 0143 Q_SIGNALS: 0144 /** 0145 * Once you register a collection with CollectionManager, this signal is the 0146 * only way to safely destroy it. CollectionManger will remove this collection 0147 * from the list of active ones and will destroy this collection after some 0148 * time. 0149 */ 0150 void remove(); 0151 0152 /** 0153 * This signal must be emitted when the collection contents has changed 0154 * significantly. 0155 * 0156 * More specifically, you must Q_EMIT this signal (only) in such situations: 0157 * a) the set of entities (tracks, albums, years, ...) in this collection has 0158 * changed: a track was added, album is renamed, year was removed... 0159 * b) the relationship between the entities has changed: the track changed 0160 * album, album is no longer associated to an album artist and became a 0161 * compilation, an alum changed its year... 0162 * 0163 * You should not Q_EMIT this signal when some minor data of an entity change, 0164 * for example when a track comment changes, etc. 0165 * 0166 * Also note there are \::notifyObservers() methods of various entities. 0167 * \::notifyObservers() and Collection::updated() are perpendicular and 0168 * responsibility to call one of these may and may not mean need to call the 0169 * other. 0170 * 0171 * This signal specifically this means that previous done searches can no 0172 * longer be considered valid. 0173 */ 0174 void updated(); 0175 }; 0176 } 0177 0178 Q_DECLARE_METATYPE( Collections::Collection* ) 0179 Q_DECLARE_METATYPE( Collections::CollectionList ) 0180 0181 #endif /* AMAROK_COLLECTION_H */