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"
25 #include "infoparserbase.h"
27 #include "meta/CustomActionsCapability.h"
28 #include "ServiceCustomActionsCapability.h"
31 #include <QStringList>
34 class AMAROK_EXPORT ServiceMetaFactory
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
);
61 QString m_dbTablePrefix
;
66 class AMAROK_EXPORT ServiceDisplayInfoProvider
70 ServiceDisplayInfoProvider() {}
71 virtual ~ServiceDisplayInfoProvider() {}
73 virtual void processInfoOf( InfoParserBase
* infoParser
) = 0;
78 class AMAROK_EXPORT CustomActionsProvider
82 CustomActionsProvider() {}
83 virtual ~CustomActionsProvider() {}
85 virtual QList
< QAction
*> customActions() { DEBUG_BLOCK
return QList
< QAction
*>(); }
98 class ServiceComposer
;
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
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
)
191 if( type
== Meta::Capability::CustomActions
)
192 return new ServiceCustomActionsCapability( this );
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
);
209 void setAlbumId( int albumId
);
211 void setArtistId( int id
);
212 int artistId() const;
213 void setUrl( const QString
&url
);
219 ComposerPtr m_composer
;
226 QString m_displayUrl
;
227 QString m_playableUrl
;
231 QString m_artistName
;
236 class AMAROK_EXPORT ServiceArtist
: public Meta::Artist
, public ServiceDisplayInfoProvider
, public CustomActionsProvider
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
)
262 if( type
== Meta::Capability::CustomActions
)
263 return new ServiceCustomActionsCapability( this );
268 //ServiceArtist specific methods
270 void addTrack( TrackPtr track
);
272 void setDescription( const QString
&description
);
273 QString
description( ) const;
274 void setId( int id
);
276 void setTitle( const QString
&title
);
281 QString m_description
;
286 class AMAROK_EXPORT ServiceAlbum
: public Meta::Album
, public ServiceDisplayInfoProvider
, public CustomActionsProvider
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
)
312 if( type
== Meta::Capability::CustomActions
)
313 return new ServiceCustomActionsCapability( this );
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
);
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
);
341 bool m_isCompilation
;
342 ArtistPtr m_albumArtist
;
343 QString m_description
;
345 QString m_artistName
;
348 class AMAROK_EXPORT ServiceGenre
: public Meta::Genre
, public ServiceDisplayInfoProvider
, public CustomActionsProvider
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
)
370 if( type
== Meta::Capability::CustomActions
)
371 return new ServiceCustomActionsCapability( this );
376 //ServiceGenre specific methods
377 void setId( int id
);
380 void addTrack( TrackPtr track
);
381 void setName( const QString
&name
);
383 void setAlbumId( int albumId
);
392 class AMAROK_EXPORT ServiceComposer
: public Meta::Composer
, public ServiceDisplayInfoProvider
, public CustomActionsProvider
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
)
413 if( type
== Meta::Capability::CustomActions
)
414 return new ServiceCustomActionsCapability( this );
419 //ServiceComposer specific methods
420 void addTrack( ServiceTrackPtr track
);
427 class AMAROK_EXPORT ServiceYear
: public Meta::Year
, public ServiceDisplayInfoProvider
, public CustomActionsProvider
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
)
448 if( type
== Meta::Capability::CustomActions
)
449 return new ServiceCustomActionsCapability( this );
454 //ServiceYear specific methods
455 void addTrack( ServiceTrackPtr track
);