1 /****************************************************************************************
2 * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free Software *
6 * Foundation; either version 2 of the License, or (at your option) any later *
7 * version. *
8 * *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
11 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
12 * *
13 * You should have received a copy of the GNU General Public License along with *
14 * this program. If not, see <http://www.gnu.org/licenses/>. *
15 ****************************************************************************************/
16
17 #include "DaapMeta.h"
18
19 #include "DaapCollection.h"
20
21 using namespace Meta;
22
DaapTrack(Collections::DaapCollection * collection,const QString & host,quint16 port,const QString & dbId,const QString & itemId,const QString & format)23 DaapTrack::DaapTrack( Collections::DaapCollection *collection, const QString &host, quint16 port, const QString &dbId, const QString &itemId, const QString &format)
24 : Meta::Track()
25 , m_collection( collection )
26 , m_artist( 0 )
27 , m_album( 0 )
28 , m_genre( 0 )
29 , m_composer( 0 )
30 , m_year( 0 )
31 , m_name()
32 , m_type( format )
33 , m_length( 0 )
34 , m_trackNumber( 0 )
35 , m_displayUrl()
36 , m_playableUrl()
37 {
38 QString url = QStringLiteral( "daap://%1:%2/databases/%3/items/%4.%5" )
39 .arg( host, QString::number( port ), dbId, itemId, format );
40 m_displayUrl = url;
41 m_playableUrl = url;
42 }
43
~DaapTrack()44 DaapTrack::~DaapTrack()
45 {
46 //nothing to do
47 }
48
49 QString
name() const50 DaapTrack::name() const
51 {
52 return m_name;
53 }
54
55 QUrl
playableUrl() const56 DaapTrack::playableUrl() const
57 {
58 QUrl url( m_playableUrl );
59 url.setScheme( "http" );
60 return url;
61 }
62
63 QString
uidUrl() const64 DaapTrack::uidUrl() const
65 {
66 return m_playableUrl;
67 }
68
69 QString
prettyUrl() const70 DaapTrack::prettyUrl() const
71 {
72 return m_displayUrl;
73 }
74
75 QString
notPlayableReason() const76 DaapTrack::notPlayableReason() const
77 {
78 return networkNotPlayableReason();
79 }
80
81 AlbumPtr
album() const82 DaapTrack::album() const
83 {
84 return AlbumPtr::staticCast( m_album );
85 }
86
87 ArtistPtr
artist() const88 DaapTrack::artist() const
89 {
90 return ArtistPtr::staticCast( m_artist );
91 }
92
93 GenrePtr
genre() const94 DaapTrack::genre() const
95 {
96 return GenrePtr::staticCast( m_genre );
97 }
98
99 ComposerPtr
composer() const100 DaapTrack::composer() const
101 {
102 return ComposerPtr::staticCast( m_composer );
103 }
104
105 YearPtr
year() const106 DaapTrack::year() const
107 {
108 return YearPtr::staticCast( m_year );
109 }
110
111 void
setAlbum(const QString & newAlbum)112 DaapTrack::setAlbum( const QString &newAlbum )
113 {
114 Q_UNUSED( newAlbum )
115 }
116
117 void
setArtist(const QString & newArtist)118 DaapTrack::setArtist( const QString &newArtist )
119 {
120 Q_UNUSED( newArtist )
121 }
122
123 void
setComposer(const QString & newComposer)124 DaapTrack::setComposer( const QString &newComposer )
125 {
126 Q_UNUSED( newComposer )
127 }
128
129 void
setGenre(const QString & newGenre)130 DaapTrack::setGenre( const QString &newGenre )
131 {
132 Q_UNUSED( newGenre )
133 }
134
135 void
setYear(int newYear)136 DaapTrack::setYear( int newYear )
137 {
138 Q_UNUSED( newYear )
139 }
140
141 /*
142 TODO: This isn't good enough, but for now as daapreader/Reader.cpp indicates
143 we can query for the BPM from daap server, but desire is to get BPM of files working
144 first!
145 */
146 qreal
bpm() const147 DaapTrack::bpm() const
148 {
149 return -1.0;
150 }
151
152 QString
comment() const153 DaapTrack::comment() const
154 {
155 return QString();
156 }
157
158 void
setComment(const QString & newComment)159 DaapTrack::setComment( const QString &newComment )
160 {
161 Q_UNUSED( newComment )
162 }
163
164 qint64
length() const165 DaapTrack::length() const
166 {
167 return m_length;
168 }
169
170 int
filesize() const171 DaapTrack::filesize() const
172 {
173 return 0;
174 }
175
176 int
sampleRate() const177 DaapTrack::sampleRate() const
178 {
179 return 0;
180 }
181
182 int
bitrate() const183 DaapTrack::bitrate() const
184 {
185 return 0;
186 }
187
188 int
trackNumber() const189 DaapTrack::trackNumber() const
190 {
191 return m_trackNumber;
192 }
193
194 void
setTrackNumber(int newTrackNumber)195 DaapTrack::setTrackNumber( int newTrackNumber )
196 {
197 m_trackNumber = newTrackNumber;
198 }
199
200 int
discNumber() const201 DaapTrack::discNumber() const
202 {
203 return 0;
204 }
205
206 void
setDiscNumber(int newDiscNumber)207 DaapTrack::setDiscNumber( int newDiscNumber )
208 {
209 Q_UNUSED( newDiscNumber )
210 }
211
212 QString
type() const213 DaapTrack::type() const
214 {
215 return m_type;
216 }
217
218 bool
inCollection() const219 DaapTrack::inCollection() const
220 {
221 return true;
222 }
223
224 Collections::Collection*
collection() const225 DaapTrack::collection() const
226 {
227 return m_collection;
228 }
229
230 void
setAlbum(const DaapAlbumPtr & album)231 DaapTrack::setAlbum( const DaapAlbumPtr &album )
232 {
233 m_album = album;
234 }
235
236 void
setArtist(const DaapArtistPtr & artist)237 DaapTrack::setArtist( const DaapArtistPtr &artist )
238 {
239 m_artist = artist;
240 }
241
242 void
setGenre(const DaapGenrePtr & genre)243 DaapTrack::setGenre( const DaapGenrePtr &genre )
244 {
245 m_genre = genre;
246 }
247
248 void
setComposer(const DaapComposerPtr & composer)249 DaapTrack::setComposer( const DaapComposerPtr &composer )
250 {
251 m_composer = composer;
252 }
253
254 void
setYear(const DaapYearPtr & year)255 DaapTrack::setYear( const DaapYearPtr &year )
256 {
257 m_year = year;
258 }
259
260 void
setTitle(const QString & title)261 DaapTrack::setTitle( const QString &title )
262 {
263 m_name = title;
264 }
265
266 void
setLength(qint64 length)267 DaapTrack::setLength( qint64 length )
268 {
269 m_length = length;
270 }
271
272 //DaapArtist
273
DaapArtist(const QString & name)274 DaapArtist::DaapArtist( const QString &name )
275 : Meta::Artist()
276 , m_name( name )
277 , m_tracks()
278 {
279 //nothing to do
280 }
281
~DaapArtist()282 DaapArtist::~DaapArtist()
283 {
284 //nothing to do
285 }
286
287 QString
name() const288 DaapArtist::name() const
289 {
290 return m_name;
291 }
292
293 TrackList
tracks()294 DaapArtist::tracks()
295 {
296 return m_tracks;
297 }
298
299 AlbumList
albums()300 DaapArtist::albums()
301 {
302 //TODO
303 return AlbumList();
304 }
305
306 void
addTrack(const DaapTrackPtr & track)307 DaapArtist::addTrack( const DaapTrackPtr &track )
308 {
309 m_tracks.append( TrackPtr::staticCast( track ) );
310 }
311
DaapAlbum(const QString & name)312 DaapAlbum::DaapAlbum( const QString &name )
313 : Meta::Album()
314 , m_name( name )
315 , m_tracks()
316 , m_isCompilation( false )
317 , m_albumArtist( 0 )
318 {
319 //nothing to do
320 }
321
~DaapAlbum()322 DaapAlbum::~DaapAlbum()
323 {
324 //nothing to do
325 }
326
327 QString
name() const328 DaapAlbum::name() const
329 {
330 return m_name;
331 }
332
333 bool
isCompilation() const334 DaapAlbum::isCompilation() const
335 {
336 return m_isCompilation;
337 }
338
339 bool
hasAlbumArtist() const340 DaapAlbum::hasAlbumArtist() const
341 {
342 return !m_albumArtist.isNull();
343 }
344
345 ArtistPtr
albumArtist() const346 DaapAlbum::albumArtist() const
347 {
348 return ArtistPtr::staticCast( m_albumArtist );
349 }
350
351 TrackList
tracks()352 DaapAlbum::tracks()
353 {
354 return m_tracks;
355 }
356
357 void
addTrack(const DaapTrackPtr & track)358 DaapAlbum::addTrack( const DaapTrackPtr &track )
359 {
360 m_tracks.append( TrackPtr::staticCast( track ) );
361 }
362
363 void
setAlbumArtist(const DaapArtistPtr & artist)364 DaapAlbum::setAlbumArtist( const DaapArtistPtr &artist )
365 {
366 m_albumArtist = artist;
367 }
368
369 //DaapGenre
370
DaapGenre(const QString & name)371 DaapGenre::DaapGenre( const QString &name )
372 : Meta::Genre()
373 , m_name( name )
374 , m_tracks()
375 {
376 //nothing to do
377 }
378
~DaapGenre()379 DaapGenre::~DaapGenre()
380 {
381 //nothing to do
382 }
383
384 QString
name() const385 DaapGenre::name() const
386 {
387 return m_name;
388 }
389
390 TrackList
tracks()391 DaapGenre::tracks()
392 {
393 return m_tracks;
394 }
395
396 void
addTrack(const DaapTrackPtr & track)397 DaapGenre::addTrack( const DaapTrackPtr &track )
398 {
399 m_tracks.append( TrackPtr::staticCast( track ) );
400 }
401
402 //DaapComposer
403
DaapComposer(const QString & name)404 DaapComposer::DaapComposer( const QString &name )
405 : Meta::Composer()
406 , m_name( name )
407 , m_tracks()
408 {
409 //nothing to do
410 }
411
~DaapComposer()412 DaapComposer::~DaapComposer()
413 {
414 //nothing to do
415 }
416
417 QString
name() const418 DaapComposer::name() const
419 {
420 return m_name;
421 }
422
423 TrackList
tracks()424 DaapComposer::tracks()
425 {
426 return m_tracks;
427 }
428
429 void
addTrack(const DaapTrackPtr & track)430 DaapComposer::addTrack( const DaapTrackPtr &track )
431 {
432 m_tracks.append( TrackPtr::staticCast( track ) );
433 }
434
435 //DaapYear
436
DaapYear(const QString & name)437 DaapYear::DaapYear( const QString &name )
438 : Meta::Year()
439 , m_name( name )
440 , m_tracks()
441 {
442 //nothing to do
443 }
444
~DaapYear()445 DaapYear::~DaapYear()
446 {
447 //nothing to do
448 }
449
450 QString
name() const451 DaapYear::name() const
452 {
453 return m_name;
454 }
455
456 TrackList
tracks()457 DaapYear::tracks()
458 {
459 return m_tracks;
460 }
461
462 void
addTrack(const DaapTrackPtr & track)463 DaapYear::addTrack( const DaapTrackPtr &track )
464 {
465 m_tracks.append( TrackPtr::staticCast( track ) );
466 }
467