Revert previous commit, was incorrect
[amarok.git] / src / servicebrowser / servicemetabase.h
blobe536ce15c70c275b20a2b3b45814336dfeb86cec
1 /* This file is part of the KDE project
2 Copyright (C) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com>
3 Copyright (C) 2007 Nikolaj Hald Nielsen <nhnFreespirit@gmail.com>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #ifndef SERVICEMETABASE_H
21 #define SERVICEMETABASE_H
23 #include "amarok_export.h"
24 #include "debug.h"
25 #include "infoparserbase.h"
26 #include "Meta.h"
27 #include "meta/CustomActionsCapability.h"
28 #include "ServiceCustomActionsCapability.h"
30 #include <QAction>
31 #include <QStringList>
34 class AMAROK_EXPORT ServiceMetaFactory
37 public:
38 ServiceMetaFactory( const QString &dbPrefix );
39 virtual ~ServiceMetaFactory() {}
41 QString tablePrefix();
43 virtual int getTrackSqlRowCount();
44 virtual QString getTrackSqlRows();
45 virtual Meta::TrackPtr createTrack( const QStringList &rows );
47 virtual int getAlbumSqlRowCount();
48 virtual QString getAlbumSqlRows();
49 virtual Meta::AlbumPtr createAlbum( const QStringList &rows );
51 virtual int getArtistSqlRowCount();
52 virtual QString getArtistSqlRows();
53 virtual Meta::ArtistPtr createArtist( const QStringList &rows );
55 virtual int getGenreSqlRowCount();
56 virtual QString getGenreSqlRows();
57 virtual Meta::GenrePtr createGenre( const QStringList &rows );
59 private:
61 QString m_dbTablePrefix;
66 class AMAROK_EXPORT ServiceDisplayInfoProvider
69 public:
70 ServiceDisplayInfoProvider() {}
71 virtual ~ServiceDisplayInfoProvider() {}
73 virtual void processInfoOf( InfoParserBase * infoParser ) = 0;
78 class AMAROK_EXPORT CustomActionsProvider
81 public:
82 CustomActionsProvider() {}
83 virtual ~CustomActionsProvider() {}
85 virtual QList< QAction *> customActions() { DEBUG_BLOCK return QList< QAction *>(); }
91 namespace Meta
94 class ServiceTrack;
95 class ServiceAlbum;
96 class ServiceArtist;
97 class ServiceGenre;
98 class ServiceComposer;
99 class ServiceYear;
101 typedef KSharedPtr<ServiceTrack> ServiceTrackPtr;
102 typedef KSharedPtr<ServiceArtist> ServiceArtistPtr;
103 typedef KSharedPtr<ServiceAlbum> ServiceAlbumPtr;
104 typedef KSharedPtr<ServiceGenre> ServiceGenrePtr;
105 typedef KSharedPtr<ServiceComposer> ServiceComposerPtr;
106 typedef KSharedPtr<ServiceYear> ServiceYearPtr;
109 typedef QList<ServiceTrackPtr > ServiceTrackList;
110 typedef QList<ServiceArtistPtr > ServiceArtistList;
111 typedef QList<ServiceAlbumPtr > ServiceAlbumList;
112 typedef QList<ServiceComposerPtr> ServiceComposerList;
113 typedef QList<ServiceGenrePtr > ServiceGenreList;
114 typedef QList<ServiceYearPtr > ServiceYearList;
116 class AMAROK_EXPORT ServiceTrack : public Meta::Track, public ServiceDisplayInfoProvider, public CustomActionsProvider
118 public:
119 //Give this a displayable name as some services has terrible names for their streams
120 ServiceTrack( const QString & name );
122 //create track based on an sql query result
123 ServiceTrack( const QStringList & resultRow );
124 virtual ~ServiceTrack();
126 virtual QString name() const;
127 virtual QString prettyName() const;
129 virtual KUrl playableUrl() const;
130 virtual QString url() const;
131 virtual QString prettyUrl() const;
133 virtual bool isPlayable() const;
134 virtual bool isEditable() const;
136 virtual AlbumPtr album() const;
137 virtual ArtistPtr artist() const;
138 virtual GenrePtr genre() const;
139 virtual ComposerPtr composer() const;
140 virtual YearPtr year() const;
142 virtual void setAlbum ( const QString &newAlbum );
143 virtual void setArtist ( const QString &newArtist );
144 virtual void setGenre ( const QString &newGenre );
145 virtual void setComposer ( const QString &newComposer );
146 virtual void setYear ( const QString &newYear );
148 virtual void setTitle( const QString &newTitle );
150 virtual QString comment() const;
151 virtual void setComment ( const QString &newComment );
153 virtual double score() const;
154 virtual void setScore ( double newScore );
156 virtual int rating() const;
157 virtual void setRating ( int newRating );
159 virtual int length() const;
161 virtual int filesize() const;
162 virtual int sampleRate() const;
163 virtual int bitrate() const;
165 virtual int trackNumber() const;
166 virtual void setTrackNumber ( int newTrackNumber );
168 virtual int discNumber() const;
169 virtual void setDiscNumber ( int newDiscNumber );
171 virtual uint lastPlayed() const;
172 virtual int playCount() const;
174 virtual QString type() const;
176 virtual void beginMetaDataUpdate() {} //read only
177 virtual void endMetaDataUpdate() {} //read only
178 virtual void abortMetaDataUpdate() {} //read only
180 virtual void processInfoOf( InfoParserBase * infoParser );
183 virtual bool hasCapabilityInterface( Meta::Capability::Type type ) const
185 return type == Meta::Capability::CustomActions;
188 virtual Meta::Capability* asCapabilityInterface( Meta::Capability::Type type )
190 DEBUG_BLOCK
191 if( type == Meta::Capability::CustomActions )
192 return new ServiceCustomActionsCapability( this );
193 else
194 return 0;
197 //ServiceTrack specific methods
199 void setAlbum( Meta::AlbumPtr album );
200 void setArtist( Meta::ArtistPtr artist );
201 void setComposer( Meta::ComposerPtr composer );
202 void setGenre( Meta::GenrePtr genre );
203 void setYear( Meta::YearPtr year );
205 void setLength( int length );
207 void setId( int id );
208 int id( ) const;
209 void setAlbumId( int albumId );
210 int albumId() const;
211 void setArtistId( int id );
212 int artistId() const;
213 void setUrl( const QString &url );
215 private:
216 ArtistPtr m_artist;
217 AlbumPtr m_album;
218 GenrePtr m_genre;
219 ComposerPtr m_composer;
220 YearPtr m_year;
222 int m_id;
223 QString m_name;
224 int m_trackNumber;
225 int m_length;
226 QString m_displayUrl;
227 QString m_playableUrl;
228 int m_albumId;
229 QString m_albumName;
230 int m_artistId;
231 QString m_artistName;
233 QString m_type;
236 class AMAROK_EXPORT ServiceArtist : public Meta::Artist, public ServiceDisplayInfoProvider, public CustomActionsProvider
238 public:
240 ServiceArtist( const QStringList & resultRow );
241 ServiceArtist( const QString & name );
242 virtual ~ServiceArtist();
244 virtual QString name() const;
245 virtual QString prettyName() const;
247 virtual TrackList tracks();
249 virtual AlbumList albums();
251 virtual void processInfoOf( InfoParserBase * infoParser );
254 virtual bool hasCapabilityInterface( Meta::Capability::Type type ) const
256 return type == Meta::Capability::CustomActions;
259 virtual Meta::Capability* asCapabilityInterface( Meta::Capability::Type type )
261 DEBUG_BLOCK
262 if( type == Meta::Capability::CustomActions )
263 return new ServiceCustomActionsCapability( this );
264 else
265 return 0;
268 //ServiceArtist specific methods
270 void addTrack( TrackPtr track );
272 void setDescription( const QString &description );
273 QString description( ) const;
274 void setId( int id );
275 int id( ) const;
276 void setTitle( const QString &title );
278 private:
279 int m_id;
280 QString m_name;
281 QString m_description;
282 TrackList m_tracks;
286 class AMAROK_EXPORT ServiceAlbum : public Meta::Album, public ServiceDisplayInfoProvider, public CustomActionsProvider
288 public:
289 ServiceAlbum( const QStringList & resultRow );
290 ServiceAlbum( const QString & name );
291 virtual ~ServiceAlbum();
293 virtual QString name() const;
294 virtual QString prettyName() const;
296 virtual bool isCompilation() const;
297 virtual bool hasAlbumArtist() const;
298 virtual ArtistPtr albumArtist() const;
299 virtual TrackList tracks();
301 virtual void processInfoOf( InfoParserBase * infoParser );
304 virtual bool hasCapabilityInterface( Meta::Capability::Type type ) const
306 return type == Meta::Capability::CustomActions;
309 virtual Meta::Capability* asCapabilityInterface( Meta::Capability::Type type )
311 DEBUG_BLOCK
312 if( type == Meta::Capability::CustomActions )
313 return new ServiceCustomActionsCapability( this );
314 else
315 return 0;
321 //ServiceAlbum specific methods
323 void addTrack( TrackPtr track );
324 void setAlbumArtist( ArtistPtr artist );
325 void setIsCompilation( bool compilation );
327 void setDescription( const QString &description );
328 QString description( ) const;
329 void setId( int id );
330 int id( ) const;
331 void setArtistId( int artistId );
332 int artistId( ) const;
333 void setArtistName( const QString &name );
334 QString artistName() const;
335 void setTitle( const QString &title );
337 private:
338 int m_id;
339 QString m_name;
340 TrackList m_tracks;
341 bool m_isCompilation;
342 ArtistPtr m_albumArtist;
343 QString m_description;
344 int m_artistId;
345 QString m_artistName;
348 class AMAROK_EXPORT ServiceGenre : public Meta::Genre, public ServiceDisplayInfoProvider, public CustomActionsProvider
350 public:
351 ServiceGenre( const QString &name );
352 ServiceGenre( const QStringList &row );
353 virtual ~ServiceGenre();
355 virtual QString name() const;
356 virtual QString prettyName() const;
358 virtual TrackList tracks();
360 virtual void processInfoOf( InfoParserBase * infoParser );
362 virtual bool hasCapabilityInterface( Meta::Capability::Type type ) const
364 return type == Meta::Capability::CustomActions;
367 virtual Meta::Capability* asCapabilityInterface( Meta::Capability::Type type )
369 DEBUG_BLOCK
370 if( type == Meta::Capability::CustomActions )
371 return new ServiceCustomActionsCapability( this );
372 else
373 return 0;
376 //ServiceGenre specific methods
377 void setId( int id );
378 int id( ) const;
380 void addTrack( TrackPtr track );
381 void setName( const QString &name );
382 int albumId();
383 void setAlbumId( int albumId );
385 private:
386 int m_id;
387 int m_albumId;
388 QString m_name;
389 TrackList m_tracks;
392 class AMAROK_EXPORT ServiceComposer : public Meta::Composer, public ServiceDisplayInfoProvider, public CustomActionsProvider
394 public:
395 ServiceComposer( const QString &name );
396 virtual ~ServiceComposer();
398 virtual QString name() const;
399 virtual QString prettyName() const;
401 virtual TrackList tracks();
403 virtual void processInfoOf( InfoParserBase * infoParser );
405 virtual bool hasCapabilityInterface( Meta::Capability::Type type ) const
407 return type == Meta::Capability::CustomActions;
410 virtual Meta::Capability* asCapabilityInterface( Meta::Capability::Type type )
412 DEBUG_BLOCK
413 if( type == Meta::Capability::CustomActions )
414 return new ServiceCustomActionsCapability( this );
415 else
416 return 0;
419 //ServiceComposer specific methods
420 void addTrack( ServiceTrackPtr track );
422 private:
423 QString m_name;
424 TrackList m_tracks;
427 class AMAROK_EXPORT ServiceYear : public Meta::Year, public ServiceDisplayInfoProvider, public CustomActionsProvider
429 public:
430 ServiceYear( const QString &name );
431 virtual ~ServiceYear();
433 virtual QString name() const;
434 virtual QString prettyName() const;
436 virtual TrackList tracks();
438 virtual void processInfoOf( InfoParserBase * infoParser );
440 virtual bool hasCapabilityInterface( Meta::Capability::Type type ) const
442 return type == Meta::Capability::CustomActions;
445 virtual Meta::Capability* asCapabilityInterface( Meta::Capability::Type type )
447 DEBUG_BLOCK
448 if( type == Meta::Capability::CustomActions )
449 return new ServiceCustomActionsCapability( this );
450 else
451 return 0;
454 //ServiceYear specific methods
455 void addTrack( ServiceTrackPtr track );
457 private:
458 QString m_name;
459 TrackList m_tracks;
464 #endif