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 mAlbumArt(), |
|
65 mReqId( KUndefined ) |
|
66 { |
|
67 TX_ENTRY |
|
68 mThumbnailManager = new ThumbnailManager( this ); |
|
69 mThumbnailManager->setQualityPreference( ThumbnailManager::OptimizeForQuality ); |
|
70 mThumbnailManager->setThumbnailSize( ThumbnailManager::ThumbnailMedium ); |
|
71 QObject::connect( mThumbnailManager, SIGNAL( thumbnailReady( QPixmap , void * , int , int ) ), |
|
72 this, SLOT( thumbnailReady( QPixmap , void * , int , int ) ) ); |
|
73 |
|
74 mDefaultAlbumArt = QPixmap( ":/detailsviewicons/defaultalbumart.png" ); |
|
75 TX_EXIT |
|
76 } |
|
77 |
|
78 /*! |
|
79 Constructs a new MpSongData. |
|
80 */ |
|
81 MpSongData::~MpSongData() |
|
82 { |
|
83 TX_ENTRY |
|
84 if( mThumbnailManager ) { |
|
85 delete mThumbnailManager; |
|
86 } |
|
87 TX_EXIT |
|
88 } |
|
89 |
|
90 /*! |
|
91 Returns the song album art on \a pixmap. |
|
92 */ |
|
93 void MpSongData::albumArt( QPixmap& pixmap ) |
|
94 { |
|
95 TX_ENTRY |
|
96 if ( !mAlbumArt.isNull() ) { |
|
97 pixmap = mAlbumArt; |
|
98 } |
|
99 else { |
|
100 pixmap = QPixmap(); |
|
101 } |
|
102 TX_EXIT |
|
103 } |
|
104 |
|
105 |
|
106 /*! |
|
107 Returns the song title. |
|
108 */ |
|
109 QString MpSongData::title() const |
|
110 { |
|
111 TX_LOG |
|
112 return mTitle; |
|
113 } |
|
114 |
|
115 /*! |
|
116 Returns the song album. |
|
117 */ |
|
118 QString MpSongData::album() const |
|
119 { |
|
120 TX_LOG |
|
121 return mAlbum; |
|
122 } |
|
123 |
|
124 /*! |
|
125 Returns the song artist. |
|
126 */ |
|
127 QString MpSongData::artist() const |
|
128 { |
|
129 TX_LOG |
|
130 return mArtist; |
|
131 } |
|
132 |
|
133 /*! |
|
134 Returns comment |
|
135 */ |
|
136 QString MpSongData::comment() const |
|
137 { |
|
138 TX_LOG |
|
139 return mComment; |
|
140 } |
|
141 |
|
142 /*! |
|
143 Returns the song composer. |
|
144 */ |
|
145 QString MpSongData::composer() const |
|
146 { |
|
147 TX_LOG |
|
148 return mComposer; |
|
149 } |
|
150 |
|
151 |
|
152 /*! |
|
153 Returns the song genre. |
|
154 */ |
|
155 QString MpSongData::genre() const |
|
156 { |
|
157 TX_LOG |
|
158 return mGenre; |
|
159 } |
|
160 |
|
161 |
|
162 /*! |
|
163 Returns the album track. |
|
164 */ |
|
165 QString MpSongData::albumTrack() const |
|
166 { |
|
167 TX_LOG |
|
168 return mAlbumTrack; |
|
169 } |
|
170 |
|
171 /*! |
|
172 Returns link |
|
173 */ |
|
174 QString MpSongData::link() const |
|
175 { |
|
176 TX_LOG |
|
177 return mLink; |
|
178 } |
|
179 |
|
180 /*! |
|
181 Returns the release date. |
|
182 */ |
|
183 QString MpSongData::year() const |
|
184 { |
|
185 TX_LOG |
|
186 return mYear; |
|
187 } |
|
188 |
|
189 |
|
190 /*! |
|
191 Sets the song \a title, returns true if the value is new. |
|
192 */ |
|
193 bool MpSongData::setTitle( const QString &title ) |
|
194 { |
|
195 TX_ENTRY_ARGS( "title =" << title ) |
|
196 bool change = false; |
|
197 if ( title != mTitle ) { |
|
198 change = true; |
|
199 mTitle = title; |
|
200 } |
|
201 TX_EXIT |
|
202 return change; |
|
203 } |
|
204 |
|
205 /*! |
|
206 Sets the song \a album, returns true if the value is new. |
|
207 */ |
|
208 bool MpSongData::setAlbum( const QString &album ) |
|
209 { |
|
210 TX_ENTRY_ARGS( "album =" << album ) |
|
211 bool change = false; |
|
212 if ( album != mAlbum ) { |
|
213 change = true; |
|
214 mAlbum = album; |
|
215 } |
|
216 TX_EXIT |
|
217 return change; |
|
218 } |
|
219 |
|
220 /*! |
|
221 Sets the song \a artist, returns true if the value is new. |
|
222 */ |
|
223 bool MpSongData::setArtist( const QString &artist ) |
|
224 { |
|
225 TX_ENTRY_ARGS( "artist =" << artist ) |
|
226 bool change = false; |
|
227 if ( artist != mArtist ) { |
|
228 change = true; |
|
229 mArtist = artist; |
|
230 } |
|
231 TX_EXIT |
|
232 return change; |
|
233 } |
|
234 |
|
235 /*! |
|
236 Sets the song \a comment, returns true if the value is new. |
|
237 */ |
|
238 bool MpSongData::setComment( const QString &comment) |
|
239 { |
|
240 TX_ENTRY_ARGS( "comment =" << comment ) |
|
241 bool change = false; |
|
242 if ( comment != mComment ) { |
|
243 change = true; |
|
244 mComment = comment; |
|
245 } |
|
246 TX_EXIT |
|
247 return change; |
|
248 } |
|
249 |
|
250 |
|
251 /*! |
|
252 Sets the song \a composer, returns true if the value is new. |
|
253 */ |
|
254 bool MpSongData::setComposer( const QString &composer ) |
|
255 { |
|
256 TX_ENTRY_ARGS( "composer =" << composer ) |
|
257 bool change = false; |
|
258 if ( composer != mComposer ) { |
|
259 change = true; |
|
260 mComposer = composer; |
|
261 } |
|
262 TX_EXIT |
|
263 return change; |
|
264 } |
|
265 |
|
266 /*! |
|
267 Sets the song \a genre, returns true if the value is new. |
|
268 */ |
|
269 bool MpSongData::setGenre( const QString &genre ) |
|
270 { |
|
271 TX_ENTRY_ARGS( "genre =" << genre ) |
|
272 bool change = false; |
|
273 if ( genre != mGenre ) { |
|
274 change = true; |
|
275 mGenre = genre; |
|
276 } |
|
277 TX_EXIT |
|
278 return change; |
|
279 } |
|
280 |
|
281 |
|
282 /*! |
|
283 Sets the song \a date, returns true if the value is new. |
|
284 */ |
|
285 bool MpSongData::setYear( int year ) |
|
286 { |
|
287 TX_ENTRY_ARGS( "year =" << year ) |
|
288 bool change = false; |
|
289 if ( QString::number(year) != mYear ) { |
|
290 change = true; |
|
291 if ( year >= 0 && year < 9999 ) { |
|
292 mYear = QString::number(year); |
|
293 } else { |
|
294 mYear = QString(); |
|
295 } |
|
296 } |
|
297 TX_EXIT |
|
298 return change; |
|
299 } |
|
300 |
|
301 /*! |
|
302 Sets the \a album track, returns true if the value is new. |
|
303 */ |
|
304 bool MpSongData::setAlbumTrack( const QString &track ) |
|
305 { |
|
306 TX_ENTRY_ARGS( "track =" << track ) |
|
307 bool change = false; |
|
308 if ( track != mAlbumTrack ) { |
|
309 change = true; |
|
310 mAlbumTrack = track; |
|
311 } |
|
312 TX_EXIT |
|
313 return change; |
|
314 } |
|
315 |
|
316 /*! |
|
317 Sets the \a link |
|
318 */ |
|
319 void MpSongData::setLink( const QString &link ) |
|
320 { |
|
321 TX_ENTRY_ARGS( "Link =" << link ) |
|
322 mLink = link; |
|
323 TX_EXIT |
|
324 } |
|
325 |
|
326 /*! |
|
327 Sets the song \a albumArtUri. |
|
328 */ |
|
329 void MpSongData::setAlbumArtUri( const QString &albumArtUri) |
|
330 { |
|
331 TX_ENTRY_ARGS( "albumArtUri = " << albumArtUri ) |
|
332 if ( !albumArtUri.isEmpty() ) { |
|
333 bool ok = true; |
|
334 if ( mReqId != KUndefined ) { |
|
335 // There is already an outstanding request. Cancel it first. |
|
336 bool ok = mThumbnailManager->cancelRequest( mReqId ); |
|
337 } |
|
338 if ( ok ) { |
|
339 mReqId = mThumbnailManager->getThumbnail( albumArtUri ); |
|
340 if ( mReqId == KUndefined ) { |
|
341 // Request failed. Set default album art. |
|
342 mAlbumArt = mDefaultAlbumArt; |
|
343 emit albumArtReady(); |
|
344 } |
|
345 } |
|
346 } |
|
347 else { |
|
348 // No album art uri. Set default album art. |
|
349 mAlbumArt = mDefaultAlbumArt; |
|
350 emit albumArtReady(); |
|
351 } |
|
352 TX_EXIT |
|
353 } |
|
354 |
|
355 |
|
356 /*! |
|
357 Slot to handle the album art thumb. |
|
358 */ |
|
359 void MpSongData::thumbnailReady( |
|
360 const QPixmap& pixmap, |
|
361 void *data, |
|
362 int id, |
|
363 int error ) |
|
364 { |
|
365 TX_ENTRY |
|
366 Q_UNUSED( data ); |
|
367 if ( error == 0 && mReqId == id ) { |
|
368 mReqId = 0; |
|
369 mAlbumArt = pixmap; |
|
370 emit albumArtReady(); |
|
371 } |
|
372 else { |
|
373 mReqId = 0; |
|
374 mAlbumArt = mDefaultAlbumArt; |
|
375 emit albumArtReady(); |
|
376 } |
|
377 |
|
378 TX_EXIT |
|
379 } |
|
380 |
|
381 /*! |
|
382 Emit signal when playback information changed, such as artist, track name |
|
383 */ |
|
384 void MpSongData::commitPlaybackInfo() |
|
385 { |
|
386 TX_ENTRY |
|
387 emit playbackInfoChanged(); |
|
388 TX_EXIT |
|
389 } |
|
390 |
|
391 /*! |
|
392 Emit signal when song detail information changed |
|
393 */ |
|
394 void MpSongData::commitSongDetailInfo() |
|
395 { |
|
396 TX_ENTRY |
|
397 emit songDetailInfoChanged(); |
|
398 TX_EXIT |
|
399 } |
|
400 |
|