|
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 #include <qicon> |
|
19 #include <qstring> |
|
20 #include <qpixmap> |
|
21 #include <qpainter> |
|
22 #include <hbicon.h> |
|
23 #include <thumbnailmanager_qt.h> |
|
24 |
|
25 #include "mpplaybackdata.h" |
|
26 #include "mptrace.h" |
|
27 |
|
28 const int KUndefined = -1; |
|
29 |
|
30 /*! |
|
31 \class MpPlaybackData |
|
32 \brief Music Player playback data. |
|
33 |
|
34 Playback data provides access to current playing song data, and playback |
|
35 properties, it is designed as an interface between the playback wrapper |
|
36 and the UI, it also provides album art extraction. |
|
37 */ |
|
38 |
|
39 /*! |
|
40 \fn void durationChanged() |
|
41 |
|
42 This signal is emitted when duration changes. |
|
43 */ |
|
44 |
|
45 /*! |
|
46 \fn void positionChanged() |
|
47 |
|
48 This signal is emitted when position changes. |
|
49 */ |
|
50 |
|
51 /*! |
|
52 \fn void albumArtReady() |
|
53 |
|
54 This signal is emitted when album art is ready. |
|
55 */ |
|
56 |
|
57 /*! |
|
58 \fn void playbackStateChanged() |
|
59 |
|
60 This signal is emitted when there is a *transition* on the playback state, |
|
61 this is based on a simple state. |
|
62 */ |
|
63 |
|
64 /*! |
|
65 \fn void playbackInfoChanged() |
|
66 |
|
67 This signal is emitted when playback info changes. This includes: |
|
68 title, artist and album name. |
|
69 */ |
|
70 |
|
71 |
|
72 |
|
73 /*! |
|
74 Constructs a new MpPlaybackData. |
|
75 */ |
|
76 MpPlaybackData::MpPlaybackData( QObject *parent ) |
|
77 : QObject(parent), |
|
78 mThumbnailManager(0), |
|
79 mReqId(KUndefined), |
|
80 mDuration(0), |
|
81 mPosition(0), |
|
82 mAlbumArt(), |
|
83 mPlaybackState(Stopped) |
|
84 { |
|
85 TX_ENTRY |
|
86 mThumbnailManager = new ThumbnailManager(this); |
|
87 mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality); |
|
88 mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge); |
|
89 connect( mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void *, int, int)), |
|
90 this, SLOT(thumbnailReady(QPixmap, void *, int, int)) ); |
|
91 |
|
92 //TODO: Change to final resource when available |
|
93 mDefaultAlbumArt = new HbIcon("qtg_large_music"); |
|
94 TX_EXIT |
|
95 } |
|
96 |
|
97 /*! |
|
98 Constructs a new MpPlaybackData. |
|
99 */ |
|
100 MpPlaybackData::~MpPlaybackData() |
|
101 { |
|
102 TX_ENTRY |
|
103 delete mThumbnailManager; |
|
104 TX_EXIT |
|
105 } |
|
106 |
|
107 /*! |
|
108 Sets the song \a duration. |
|
109 */ |
|
110 void MpPlaybackData::setDuration( int duration ) |
|
111 { |
|
112 TX_ENTRY_ARGS( "duration = " << duration ) |
|
113 mDuration = duration; |
|
114 emit durationChanged(); |
|
115 TX_EXIT |
|
116 } |
|
117 |
|
118 /*! |
|
119 Returns the song duration. |
|
120 */ |
|
121 int MpPlaybackData::duration() const |
|
122 { |
|
123 TX_LOG_ARGS( "mDuration = " << mDuration ) |
|
124 return mDuration; |
|
125 } |
|
126 |
|
127 /*! |
|
128 Sets the song \a position. |
|
129 */ |
|
130 void MpPlaybackData::setPosition( int position ) |
|
131 { |
|
132 TX_ENTRY_ARGS( "position = " << position ) |
|
133 mPosition = position; |
|
134 emit positionChanged(); |
|
135 TX_EXIT |
|
136 } |
|
137 |
|
138 /*! |
|
139 Returns the song position. |
|
140 */ |
|
141 int MpPlaybackData::position() const |
|
142 { |
|
143 TX_ENTRY_ARGS( "mPosition = " << mPosition ) |
|
144 return mPosition; |
|
145 } |
|
146 |
|
147 /*! |
|
148 Sets the song \a title, returns true if the value is new. |
|
149 */ |
|
150 bool MpPlaybackData::setTitle( const QString& title ) |
|
151 { |
|
152 TX_ENTRY_ARGS( "title = " << title ) |
|
153 bool change = false; |
|
154 if ( title != mTitle ) { |
|
155 change = true; |
|
156 mTitle = title; |
|
157 } |
|
158 TX_EXIT |
|
159 return change; |
|
160 } |
|
161 |
|
162 /*! |
|
163 Returns the song title. |
|
164 */ |
|
165 const QString& MpPlaybackData::title() const |
|
166 { |
|
167 TX_ENTRY_ARGS( "mTitle = " << mTitle ) |
|
168 return mTitle; |
|
169 } |
|
170 |
|
171 /*! |
|
172 Sets the song \a artist, returns true if the value is new. |
|
173 */ |
|
174 bool MpPlaybackData::setArtist( const QString& artist ) |
|
175 { |
|
176 TX_ENTRY_ARGS( "artist = " << artist ) |
|
177 bool change = false; |
|
178 if ( artist != mArtist ) { |
|
179 change = true; |
|
180 mArtist = artist; |
|
181 } |
|
182 TX_EXIT |
|
183 return change; |
|
184 } |
|
185 |
|
186 /*! |
|
187 Returns the song artist. |
|
188 */ |
|
189 const QString& MpPlaybackData::artist() const |
|
190 { |
|
191 TX_ENTRY_ARGS( "mArtist = " << mArtist ) |
|
192 return mArtist; |
|
193 } |
|
194 |
|
195 /*! |
|
196 Sets the song \a album, returns true if the value is new. |
|
197 */ |
|
198 bool MpPlaybackData::setAlbum( const QString& album ) |
|
199 { |
|
200 TX_ENTRY_ARGS( "album = " << album ) |
|
201 bool change = false; |
|
202 if ( album != mAlbum ) { |
|
203 change = true; |
|
204 mAlbum = album; |
|
205 } |
|
206 TX_EXIT |
|
207 return change; |
|
208 } |
|
209 |
|
210 /*! |
|
211 Returns the song album. |
|
212 */ |
|
213 const QString& MpPlaybackData::album() const |
|
214 { |
|
215 TX_ENTRY_ARGS( "mAlbum = " << mAlbum ) |
|
216 return mAlbum; |
|
217 } |
|
218 |
|
219 /*! |
|
220 Sets the song \a uri, returns true if the value is new. |
|
221 */ |
|
222 bool MpPlaybackData::setUri( const QString& uri ) |
|
223 { |
|
224 TX_ENTRY_ARGS( "uri = " << uri ) |
|
225 bool change = false; |
|
226 if ( uri != mUri ) { |
|
227 change = true; |
|
228 mUri = uri; |
|
229 } |
|
230 TX_EXIT |
|
231 return change; |
|
232 } |
|
233 |
|
234 /*! |
|
235 Returns the song uri. |
|
236 */ |
|
237 const QString& MpPlaybackData::uri() const |
|
238 { |
|
239 TX_ENTRY_ARGS( "mUri = " << mUri ) |
|
240 return mUri; |
|
241 } |
|
242 |
|
243 /*! |
|
244 Sets the song \a albumArtUri. |
|
245 */ |
|
246 void MpPlaybackData::setAlbumArtUri( const QString& albumArtUri ) |
|
247 { |
|
248 TX_ENTRY_ARGS( "albumArtUri = " << albumArtUri ) |
|
249 if ( !albumArtUri.isEmpty() ) { |
|
250 bool ok = true; |
|
251 if ( mReqId != KUndefined ) { |
|
252 // There is already an outstanding request. Cancel it first. |
|
253 bool ok = mThumbnailManager->cancelRequest(mReqId); |
|
254 } |
|
255 if ( ok ) { |
|
256 mReqId = mThumbnailManager->getThumbnail( albumArtUri ); |
|
257 if ( mReqId == KUndefined ) { |
|
258 // Request failed. Set default album art. |
|
259 mAlbumArt = mDefaultAlbumArt; |
|
260 emit albumArtReady(); |
|
261 } |
|
262 } |
|
263 } |
|
264 else { |
|
265 // No album art uri. Set default album art. |
|
266 mAlbumArt = mDefaultAlbumArt; |
|
267 emit albumArtReady(); |
|
268 } |
|
269 TX_EXIT |
|
270 } |
|
271 |
|
272 /*! |
|
273 Returns the song album art on \a icon. |
|
274 */ |
|
275 void MpPlaybackData::albumArt( HbIcon& icon ) const |
|
276 { |
|
277 TX_ENTRY |
|
278 if ( mAlbumArt->isNull() ) { |
|
279 icon = HbIcon(); |
|
280 } |
|
281 else { |
|
282 icon = *mAlbumArt ; |
|
283 } |
|
284 TX_EXIT |
|
285 } |
|
286 |
|
287 /*! |
|
288 Sets the playback \a state. |
|
289 */ |
|
290 void MpPlaybackData::setPlaybackState( const SimplifiedState state ) |
|
291 { |
|
292 TX_ENTRY_ARGS( "state = " << state ) |
|
293 if ( state != mPlaybackState ) { |
|
294 mPlaybackState = state; |
|
295 emit playbackStateChanged(); |
|
296 } |
|
297 TX_EXIT |
|
298 } |
|
299 |
|
300 /*! |
|
301 Returns the playback state. |
|
302 */ |
|
303 MpPlaybackData::SimplifiedState MpPlaybackData::playbackState() const |
|
304 { |
|
305 TX_LOG_ARGS( "mPlaybackState = " << mPlaybackState ) |
|
306 return mPlaybackState; |
|
307 } |
|
308 |
|
309 /*! |
|
310 |
|
311 */ |
|
312 void MpPlaybackData::commitPlaybackInfo() |
|
313 { |
|
314 TX_ENTRY |
|
315 emit playbackInfoChanged(); |
|
316 TX_EXIT |
|
317 } |
|
318 |
|
319 /*! |
|
320 Slot to handle the album art thumb. |
|
321 */ |
|
322 void MpPlaybackData::thumbnailReady( |
|
323 const QPixmap& pixmap, void *data, int id, int error ) |
|
324 { |
|
325 TX_LOG_ARGS( "error = " << error << ", id = " << id ) |
|
326 Q_UNUSED(data); |
|
327 if ( error == 0 && mReqId == id ) { |
|
328 QIcon qicon; |
|
329 QPixmap mCompositePixmap; |
|
330 mReqId = KUndefined; |
|
331 |
|
332 mCompositePixmap = QPixmap( 360, 360 ); |
|
333 mCompositePixmap.fill( Qt::transparent ); |
|
334 QPainter painter(&mCompositePixmap); |
|
335 painter.setCompositionMode(QPainter::CompositionMode_Clear); |
|
336 painter.setCompositionMode(QPainter::CompositionMode_SourceOver); |
|
337 painter.fillRect(mCompositePixmap.rect(), Qt::transparent); |
|
338 painter.drawPixmap(QRect(0, 0,360,360), pixmap); |
|
339 |
|
340 if ( !mCompositePixmap.isNull() ) { |
|
341 qicon = QIcon( mCompositePixmap ); |
|
342 } |
|
343 else { |
|
344 qicon = QIcon( pixmap ); |
|
345 } |
|
346 |
|
347 |
|
348 mAlbumArt = new HbIcon(qicon); |
|
349 |
|
350 emit albumArtReady(); |
|
351 } |
|
352 else { |
|
353 mReqId = KUndefined; |
|
354 mAlbumArt = mDefaultAlbumArt; |
|
355 emit albumArtReady(); |
|
356 } |
|
357 TX_EXIT |
|
358 } |
|
359 |