1 /**************************************************************************************** 2 * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com> * 3 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org> * 4 * Copyright (c) 2008 Casey Link <unnamedrambler@gmail.com> * 5 * * 6 * This program is free software; you can redistribute it and/or modify it under * 7 * the terms of the GNU General Public License as published by the Free Software * 8 * Foundation; either version 2 of the License, or (at your option) any later * 9 * version. * 10 * * 11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 13 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License along with * 16 * this program. If not, see <http://www.gnu.org/licenses/>. * 17 ****************************************************************************************/ 18 19 #ifndef SERVICECOLLECTION_H 20 #define SERVICECOLLECTION_H 21 22 #include "amarok_export.h" 23 #include "core/collections/Collection.h" 24 #include "core-impl/collections/support/MemoryCollection.h" 25 #include "ServiceBase.h" 26 27 #include <QIcon> 28 29 #include <QtGlobal> 30 #include <QSharedPointer> 31 32 typedef QMap<int, Meta::TrackPtr> TrackIdMap; 33 typedef QMap<int, Meta::ArtistPtr> ArtistIdMap; 34 typedef QMap<int, Meta::AlbumPtr> AlbumIdMap; 35 typedef QMap<int, Meta::GenrePtr> GenreIdMap; 36 37 namespace Collections { 38 39 /** 40 * This is a specialized collection that can be used by services who dynamically 41 * fetch their data from somewhere ( a web service, an external program, etc....) 42 */ 43 44 class AMAROK_EXPORT ServiceCollection : public Collections::Collection 45 { 46 Q_OBJECT 47 public: 48 explicit ServiceCollection( ServiceBase * service = 0 ); 49 ServiceCollection( ServiceBase * service, const QString &id, const QString &prettyName ); 50 ~ServiceCollection() override; 51 52 Collections::QueryMaker* queryMaker() override; 53 54 QString collectionId() const override; 55 QString prettyName() const override; icon()56 QIcon icon() const override { return QIcon::fromTheme(QStringLiteral("action-view-services-scripted-amarok")); } 57 58 CollectionLocation* location() override; 59 60 void emitUpdated(); 61 query(const QString & query)62 virtual QStringList query( const QString &query ) { Q_UNUSED( query ); return QStringList(); } insert(const QString & statement,const QString & table)63 virtual int insert( const QString &statement, const QString &table ) { Q_UNUSED( statement ); Q_UNUSED( table ); return 0; } 64 escape(const QString & text)65 virtual QString escape( const QString &text ) const { Q_UNUSED( text ); return QString(); } 66 67 68 Meta::TrackPtr trackById( int id ); 69 Meta::AlbumPtr albumById( int id ); 70 Meta::ArtistPtr artistById( int id ); 71 Meta::GenrePtr genreById( int id ); 72 73 //Override some stuff to be able to handle id mappings 74 75 void addTrack( const Meta::TrackPtr &trackPtr ); 76 void addArtist( const Meta::ArtistPtr &artistPtr ); 77 void addAlbum( const Meta::AlbumPtr &albumPtr ); 78 void addGenre( const Meta::GenrePtr &genrePtr ); 79 80 //TODO: 81 //void setTrackMap( TrackMap map ) { m_trackMap = map; } 82 //void setArtistMap( ArtistMap map ) { m_artistMap = map; } 83 //void setAlbumMap( AlbumMap map ) { m_albumMap = map; } 84 //void setGenreMap( GenreMap map ) { m_genreMap = map; } 85 86 ServiceBase * service(); 87 88 //convenience functions for subclasses acquireWriteLock()89 void acquireWriteLock() { m_mc->acquireWriteLock(); } acquireReadLock()90 void acquireReadLock() { m_mc->acquireReadLock(); } releaseLock()91 void releaseLock() { m_mc->releaseLock(); } genreMap()92 GenreMap genreMap() const { return m_mc->genreMap(); } setGenreMap(const GenreMap & map)93 void setGenreMap( const GenreMap &map ) { m_mc->setGenreMap( map ); } artistMap()94 ArtistMap artistMap() const { return m_mc->artistMap(); } setArtistMap(const ArtistMap & map)95 void setArtistMap( const ArtistMap &map ) { m_mc->setArtistMap( map ); } trackMap()96 TrackMap trackMap() const { return m_mc->trackMap(); } setTrackMap(const TrackMap & map)97 void setTrackMap( const TrackMap &map ) { m_mc->setTrackMap( map ); } albumMap()98 AlbumMap albumMap() const { return m_mc->albumMap(); } setAlbumMap(const AlbumMap & map)99 void setAlbumMap( const AlbumMap &map ) { m_mc->setAlbumMap( map ); } 100 101 private: 102 ServiceBase * m_service; 103 QSharedPointer<MemoryCollection> m_mc; 104 105 QString m_collectionId; 106 QString m_prettyName; 107 108 TrackIdMap m_trackIdMap; 109 ArtistIdMap m_artistIdMap; 110 AlbumIdMap m_albumIdMap; 111 GenreIdMap m_genreIdMap; 112 }; 113 114 } //namespace Collections 115 116 #endif 117