|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Playback Data provider for playback view. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <qstring> |
|
20 #include <qpixmap> |
|
21 |
|
22 #include <thumbnailmanager_qt.h> |
|
23 #include <thumbnaildata.h> |
|
24 #include <thumbnailobjectsource.h> |
|
25 |
|
26 #include "mpsongdata.h" |
|
27 #include "mptrace.h" |
|
28 |
|
29 |
|
30 const int KUndefined = -1; |
|
31 |
|
32 /*! |
|
33 \class MpSongData |
|
34 \brief Music Player song metadata. |
|
35 |
|
36 Song data provide acces to current playing song metadata |
|
37 */ |
|
38 |
|
39 /*! |
|
40 \fn void albumArtReady() |
|
41 |
|
42 This signal is albuma alrt is ready. |
|
43 */ |
|
44 |
|
45 /*! |
|
46 \fn void playbackInfoChanged() |
|
47 |
|
48 This signal is emitted when basic information is available |
|
49 */ |
|
50 |
|
51 /*! |
|
52 \fn void songDetailInfoChanged() |
|
53 |
|
54 This signal is emitted when detail information is available |
|
55 */ |
|
56 |
|
57 |
|
58 |
|
59 /*! |
|
60 Constructs a new MpSongData. |
|
61 */ |
|
62 MpSongData::MpSongData( QObject *parent ) |
|
63 : QObject( parent ), |
|
64 mTitle( NULL ), |
|
65 mAlbum( NULL ), |
|
66 mArtist( NULL ), |
|
67 mComposer( NULL), |
|
68 mGenre( NULL ), |
|
69 mYear( NULL ), |
|
70 mAlbumTrack( NULL ), |
|
71 mAlbumArt(), |
|
72 mReqId( KUndefined ) |
|
73 { |
|
74 TX_ENTRY |
|
75 mThumbnailManager = new ThumbnailManager( this ); |
|
76 mThumbnailManager->setQualityPreference( ThumbnailManager::OptimizeForQuality ); |
|
77 mThumbnailManager->setThumbnailSize( ThumbnailManager::ThumbnailMedium ); |
|
78 QObject::connect( mThumbnailManager, SIGNAL( thumbnailReady( QPixmap , void * , int , int ) ), |
|
79 this, SLOT( thumbnailReady( QPixmap , void * , int , int ) ) ); |
|
80 |
|
81 mDefaultAlbumArt = QPixmap( ":/detailsviewicons/defaultalbumart.png" ); |
|
82 TX_EXIT |
|
83 } |
|
84 |
|
85 /*! |
|
86 Constructs a new MpSongData. |
|
87 */ |
|
88 MpSongData::~MpSongData() |
|
89 { |
|
90 TX_ENTRY |
|
91 if( mThumbnailManager ) { |
|
92 delete mThumbnailManager; |
|
93 } |
|
94 TX_EXIT |
|
95 } |
|
96 |
|
97 /*! |
|
98 Returns the song album art on \a pixmap. |
|
99 */ |
|
100 void MpSongData::albumArt( QPixmap& pixmap ) |
|
101 { |
|
102 TX_ENTRY |
|
103 if ( !mAlbumArt.isNull() ) { |
|
104 pixmap = mAlbumArt; |
|
105 } |
|
106 else { |
|
107 pixmap = QPixmap(); |
|
108 } |
|
109 TX_EXIT |
|
110 } |
|
111 |
|
112 |
|
113 /*! |
|
114 Returns the song title. |
|
115 */ |
|
116 QString MpSongData::title() const |
|
117 { |
|
118 TX_LOG |
|
119 return mTitle; |
|
120 } |
|
121 |
|
122 /*! |
|
123 Returns the song album. |
|
124 */ |
|
125 QString MpSongData::album() const |
|
126 { |
|
127 TX_LOG |
|
128 return mAlbum; |
|
129 } |
|
130 |
|
131 /*! |
|
132 Returns the song artist. |
|
133 */ |
|
134 QString MpSongData::artist() const |
|
135 { |
|
136 TX_LOG |
|
137 return mArtist; |
|
138 } |
|
139 |
|
140 /*! |
|
141 Returns comment |
|
142 */ |
|
143 QString MpSongData::comment() const |
|
144 { |
|
145 TX_LOG |
|
146 return mComment; |
|
147 } |
|
148 |
|
149 /*! |
|
150 Returns the song composer. |
|
151 */ |
|
152 QString MpSongData::composer() const |
|
153 { |
|
154 TX_LOG |
|
155 return mComposer; |
|
156 } |
|
157 |
|
158 |
|
159 /*! |
|
160 Returns the song genre. |
|
161 */ |
|
162 QString MpSongData::genre() const |
|
163 { |
|
164 TX_LOG |
|
165 return mGenre; |
|
166 } |
|
167 |
|
168 |
|
169 /*! |
|
170 Returns the album track. |
|
171 */ |
|
172 QString MpSongData::albumTrack() const |
|
173 { |
|
174 TX_LOG |
|
175 return mAlbumTrack; |
|
176 } |
|
177 |
|
178 /*! |
|
179 Returns link |
|
180 */ |
|
181 QString MpSongData::link() const |
|
182 { |
|
183 TX_LOG |
|
184 return mLink; |
|
185 } |
|
186 |
|
187 /*! |
|
188 Returns the release date. |
|
189 */ |
|
190 QString MpSongData::year() const |
|
191 { |
|
192 TX_LOG |
|
193 return mYear; |
|
194 } |
|
195 |
|
196 |
|
197 /*! |
|
198 Sets the song \a title, returns true if the value is new. |
|
199 */ |
|
200 bool MpSongData::setTitle( const QString &title ) |
|
201 { |
|
202 TX_ENTRY_ARGS( "title =" << title ) |
|
203 bool change = false; |
|
204 if ( title != mTitle ) { |
|
205 change = true; |
|
206 mTitle = title; |
|
207 } |
|
208 TX_EXIT |
|
209 return change; |
|
210 } |
|
211 |
|
212 /*! |
|
213 Sets the song \a album, returns true if the value is new. |
|
214 */ |
|
215 bool MpSongData::setAlbum( const QString &album ) |
|
216 { |
|
217 TX_ENTRY_ARGS( "album =" << album ) |
|
218 bool change = false; |
|
219 if ( album != mAlbum ) { |
|
220 change = true; |
|
221 mAlbum = album; |
|
222 } |
|
223 TX_EXIT |
|
224 return change; |
|
225 } |
|
226 |
|
227 /*! |
|
228 Sets the song \a artist, returns true if the value is new. |
|
229 */ |
|
230 bool MpSongData::setArtist( const QString &artist ) |
|
231 { |
|
232 TX_ENTRY_ARGS( "artist =" << artist ) |
|
233 bool change = false; |
|
234 if ( artist != mArtist ) { |
|
235 change = true; |
|
236 mArtist = artist; |
|
237 } |
|
238 TX_EXIT |
|
239 return change; |
|
240 } |
|
241 |
|
242 /*! |
|
243 Sets the song \a comment, returns true if the value is new. |
|
244 */ |
|
245 bool MpSongData::setComment( const QString &comment) |
|
246 { |
|
247 TX_ENTRY_ARGS( "comment =" << comment ) |
|
248 bool change = false; |
|
249 if ( comment != mComment ) { |
|
250 change = true; |
|
251 mComment = comment; |
|
252 } |
|
253 TX_EXIT |
|
254 return change; |
|
255 } |
|
256 |
|
257 |
|
258 /*! |
|
259 Sets the song \a composer, returns true if the value is new. |
|
260 */ |
|
261 bool MpSongData::setComposer( const QString &composer ) |
|
262 { |
|
263 TX_ENTRY_ARGS( "composer =" << composer ) |
|
264 bool change = false; |
|
265 if ( composer != mComposer ) { |
|
266 change = true; |
|
267 mComposer = composer; |
|
268 } |
|
269 TX_EXIT |
|
270 return change; |
|
271 } |
|
272 |
|
273 /*! |
|
274 Sets the song \a genre, returns true if the value is new. |
|
275 */ |
|
276 bool MpSongData::setGenre( const QString &genre ) |
|
277 { |
|
278 TX_ENTRY_ARGS( "genre =" << genre ) |
|
279 bool change = false; |
|
280 if ( genre != mGenre ) { |
|
281 change = true; |
|
282 mGenre = genre; |
|
283 } |
|
284 TX_EXIT |
|
285 return change; |
|
286 } |
|
287 |
|
288 |
|
289 /*! |
|
290 Sets the song \a date, returns true if the value is new. |
|
291 */ |
|
292 bool MpSongData::setYear( int year ) |
|
293 { |
|
294 TX_ENTRY_ARGS( "year =" << year ) |
|
295 bool change = false; |
|
296 if ( QString::number(year) != mYear ) { |
|
297 change = true; |
|
298 if ( year >= 0 && year < 9999 ) { |
|
299 mYear = QString::number(year); |
|
300 } else { |
|
301 mYear = QString(); |
|
302 } |
|
303 } |
|
304 TX_EXIT |
|
305 return change; |
|
306 } |
|
307 |
|
308 /*! |
|
309 Sets the \a album track, returns true if the value is new. |
|
310 */ |
|
311 bool MpSongData::setAlbumTrack( const QString &track ) |
|
312 { |
|
313 TX_ENTRY_ARGS( "track =" << track ) |
|
314 bool change = false; |
|
315 if ( track != mAlbumTrack ) { |
|
316 change = true; |
|
317 mAlbumTrack = track; |
|
318 } |
|
319 TX_EXIT |
|
320 return change; |
|
321 } |
|
322 |
|
323 /*! |
|
324 Sets the \a link |
|
325 */ |
|
326 void MpSongData::setLink( const QString &link ) |
|
327 { |
|
328 TX_ENTRY_ARGS( "Link =" << link ) |
|
329 mLink = link; |
|
330 TX_EXIT |
|
331 } |
|
332 |
|
333 /*! |
|
334 Sets the song \a albumArtUri. |
|
335 */ |
|
336 void MpSongData::setAlbumArtUri( const QString &albumArtUri) |
|
337 { |
|
338 TX_ENTRY_ARGS( "albumArtUri = " << albumArtUri ) |
|
339 if ( !albumArtUri.isEmpty() ) { |
|
340 bool ok = true; |
|
341 if ( mReqId != KUndefined ) { |
|
342 // There is already an outstanding request. Cancel it first. |
|
343 bool ok = mThumbnailManager->cancelRequest( mReqId ); |
|
344 } |
|
345 if ( ok ) { |
|
346 mReqId = mThumbnailManager->getThumbnail( albumArtUri ); |
|
347 if ( mReqId == KUndefined ) { |
|
348 // Request failed. Set default album art. |
|
349 mAlbumArt = mDefaultAlbumArt; |
|
350 emit albumArtReady(); |
|
351 } |
|
352 } |
|
353 } |
|
354 else { |
|
355 // No album art uri. Set default album art. |
|
356 mAlbumArt = mDefaultAlbumArt; |
|
357 emit albumArtReady(); |
|
358 } |
|
359 TX_EXIT |
|
360 } |
|
361 |
|
362 |
|
363 /*! |
|
364 Slot to handle the album art thumb. |
|
365 */ |
|
366 void MpSongData::thumbnailReady( |
|
367 const QPixmap& pixmap, |
|
368 void *data, |
|
369 int id, |
|
370 int error ) |
|
371 { |
|
372 TX_ENTRY |
|
373 Q_UNUSED( data ); |
|
374 if ( error == 0 && mReqId == id ) { |
|
375 mReqId = 0; |
|
376 mAlbumArt = pixmap; |
|
377 emit albumArtReady(); |
|
378 } |
|
379 else { |
|
380 mReqId = 0; |
|
381 mAlbumArt = mDefaultAlbumArt; |
|
382 emit albumArtReady(); |
|
383 } |
|
384 |
|
385 TX_EXIT |
|
386 } |
|
387 |
|
388 /*! |
|
389 Emit signal when playback information changed, such as artist, track name |
|
390 */ |
|
391 void MpSongData::commitPlaybackInfo() |
|
392 { |
|
393 TX_ENTRY |
|
394 emit playbackInfoChanged(); |
|
395 TX_EXIT |
|
396 } |
|
397 |
|
398 /*! |
|
399 Emit signal when song detail information changed |
|
400 */ |
|
401 void MpSongData::commitSongDetailInfo() |
|
402 { |
|
403 TX_ENTRY |
|
404 emit songDetailInfoChanged(); |
|
405 TX_EXIT |
|
406 } |
|
407 |