|
1 /* |
|
2 * Copyright (c) 2010 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: Music player home screen widget |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "musicwidget.h" |
|
19 |
|
20 #include <QtGui> |
|
21 #include <hbpushbutton.h> |
|
22 #include <hblabel.h> |
|
23 #include <hbicon.h> |
|
24 #include <hbmarqueeitem.h> |
|
25 #include <hbanchorlayout.h> |
|
26 #include <hbwidget.h> |
|
27 #include <hbframeitem.h> |
|
28 #include <hbframedrawer.h> |
|
29 #include <hbcolorscheme.h> |
|
30 |
|
31 #include "musicwidgetdocumentloader.h" |
|
32 #include "mptrace.h" |
|
33 #include "mpenginefactory.h" |
|
34 #include "mpalbumcoverwidget.h" |
|
35 |
|
36 // Constants |
|
37 /** Docml */ |
|
38 const QString MUSIC_WIDGET_DOCML = ":/gfx/music_widget.docml"; |
|
39 |
|
40 /** File name suffix lists for push buttons */ |
|
41 const QStringList PREV_BUTTON_SUFFIXES = (QStringList() << "_l" << "_c" << "_cr"); |
|
42 const QStringList PLAY_BUTTON_SUFFIXES = (QStringList() << "_cl" << "_c" << "_cr"); |
|
43 const QStringList NEXT_BUTTON_SUFFIXES = (QStringList() << "_cl" << "_c" << "_r"); |
|
44 |
|
45 /** Prefixes for 3 piece button background graphics */ |
|
46 const QLatin1String PUSH_BUTTON_NORMAL("qtg_fr_hsbutton_normal"); |
|
47 const QLatin1String PUSH_BUTTON_PRESSED ("qtg_fr_hsbutton_pressed"); |
|
48 const QLatin1String PUSH_BUTTON_DISABLED ("qtg_fr_hsbutton_disabled"); |
|
49 |
|
50 /** Push button icon colors for each of the states (Normal, Pressed and Disabled) */ |
|
51 const QLatin1String ICON_COLOR_NORMAL ("qtc_button_normal"); |
|
52 const QLatin1String ICON_COLOR_PRESSED ("qtc_button_pressed"); |
|
53 const QLatin1String ICON_COLOR_DISABLED ("qtc_button_disabled"); |
|
54 |
|
55 /** Play and Pause icons */ |
|
56 const QLatin1String ICON_PLAY ("qtg_mono_play"); |
|
57 const QLatin1String ICON_PAUSE ("qtg_mono_pause"); |
|
58 /** Music Player shortcut icon */ |
|
59 const QLatin1String ICON_LARGE_MUSIC_PLAYER ("qtg_large_music"); |
|
60 /** Music Player shortcut icon */ |
|
61 const QLatin1String ICON_FIRST_TIME_USE ("qtg_large_music_empty"); |
|
62 const QLatin1String ICON_DEFAULT_ART ("qtg_large_album_art"); |
|
63 |
|
64 /** HsWidget normal background */ |
|
65 const QLatin1String WIDGET_BG_NORMAL ("qtg_fr_hswidget_normal"); |
|
66 /** Text background */ |
|
67 const QLatin1String TEXT_BG_NORMAL ("qtg_fr_multimedia_trans"); |
|
68 /** Separator : character and space between artist and song name */ |
|
69 const QLatin1String SEPARATOR_TEXT (": "); |
|
70 /** Temporary unknown artist */ |
|
71 const QLatin1String TEMPORARY_UNKWNOWN_TEXT ("Unknown"); |
|
72 /** Localized unknown artist */ |
|
73 const QLatin1String UNKWNOWN_TEXT ("txt_mus_other_unknown_1"); |
|
74 |
|
75 /** Marquee width */ |
|
76 const int MARQUEE_WIDTH = 170; |
|
77 /** Infinite loop value for marquee */ |
|
78 const int MARQUEE_LOOP_FOREVER = -1; |
|
79 |
|
80 /** Now playing view with random play */ |
|
81 const QLatin1String SERVICEREQ_FIRST_TIME_USE ("appto://10207C62?activityname=MusicNowPlayingView&launchtype=standalone&shuffle=yes"); |
|
82 /** Main view */ |
|
83 const QLatin1String SERVICEREQ_MAIN_VIEW ("appto://10207C62?activityname=MusicMainView&launchtype=standalone"); |
|
84 /** Now playing view */ |
|
85 const QLatin1String SERVICEREQ_NOW_PLAYING_VIEW ("appto://10207C62?activityname=MusicNowPlayingView&launchtype=standalone"); |
|
86 |
|
87 /** DOCML object name for main widget */ |
|
88 const QLatin1String DOCML_CONTAINER_WIDGET ("containerWidget"); |
|
89 /** DOCML object name for widget background */ |
|
90 const QLatin1String DOCML_BG_ICON ("widget_background_icon"); |
|
91 /** DOCML object name for album art image */ |
|
92 const QLatin1String DOCML_ALBUM_ART ("album_art_image"); |
|
93 /** DOCML object name for shortcut icon background */ |
|
94 const QLatin1String DOCML_SHORTCUT_ICON_BG ("shortcut_icon_background"); |
|
95 /** DOCML object name for shortcut icon */ |
|
96 const QLatin1String DOCML_SHORTCUT_ICON ("shortcut_icon"); |
|
97 /** DOCML object name for scrolling text background */ |
|
98 const QLatin1String DOCML_TEXT_BG ("text_bg"); |
|
99 /** DOCML object name for scrolling text */ |
|
100 const QLatin1String DOCML_SCROLLING_TEXT ("scrolling_text"); |
|
101 /** DOCML object name for button group container */ |
|
102 const QLatin1String DOCML_BUTTON_GROUP_CONTAINER ("button_group_container"); |
|
103 /** DOCML object name for prev button */ |
|
104 const QLatin1String DOCML_PREV_BUTTON ("btn_previous"); |
|
105 /** DOCML object name for play button */ |
|
106 const QLatin1String DOCML_PLAY_BUTTON ("btn_play"); |
|
107 /** DOCML object name for next button */ |
|
108 const QLatin1String DOCML_NEXT_BUTTON ("btn_next"); |
|
109 |
|
110 |
|
111 MusicWidget::MusicWidget(QGraphicsItem* parent, Qt::WindowFlags flags): |
|
112 HbWidget(parent, flags), |
|
113 mShortcutArea(0), |
|
114 mSongDataBG(0), |
|
115 mInformationSongName(0), |
|
116 mMarqueeText(0), |
|
117 mPreviousPushButton(0), |
|
118 mPlayPushButton(0), |
|
119 mNextPushButton(0), |
|
120 mMusicPlayerNoSongData(1), |
|
121 mMusicPlayerUpdating(0), |
|
122 mMusicPlayerBlocked(0), |
|
123 mAlbumArt(0), |
|
124 mArtist(0), |
|
125 mTitle(0), |
|
126 mMpEngine(0), |
|
127 mMpPlaybackData(0) |
|
128 { |
|
129 TX_ENTRY |
|
130 |
|
131 // Setup UI |
|
132 setupUi(); |
|
133 |
|
134 // Connect to MP engine and playback data |
|
135 mMpEngine = MpEngineFactory::createSharedEngine(); |
|
136 Q_ASSERT_X(mMpEngine, "music_widget", "no music player engine"); |
|
137 TX_LOG_ARGS("got mp engine") |
|
138 |
|
139 mMpPlaybackData = mMpEngine->playbackData(); |
|
140 Q_ASSERT_X(mMpPlaybackData, "music_widget", "no playback data"); |
|
141 TX_LOG_ARGS("got playback data") |
|
142 |
|
143 // Connect outgoing signals and slots |
|
144 QObject::connect(mShortcutArea, SIGNAL(clicked()), this, SLOT(shortcutButton())); |
|
145 |
|
146 // use signal mapper to indicate button identifiers to button event slots |
|
147 QSignalMapper* signalMapperPressed = new QSignalMapper( this ); |
|
148 signalMapperPressed->setMapping( mPreviousPushButton, EPrevious ); |
|
149 signalMapperPressed->setMapping( mPlayPushButton, EPlayPause); |
|
150 signalMapperPressed->setMapping( mNextPushButton, ENext); |
|
151 |
|
152 // need to use different signal mapper for pressed and released events, |
|
153 // both have same mappings but they are mapped to different slots |
|
154 QSignalMapper* signalMapperReleased = new QSignalMapper( this ); |
|
155 signalMapperReleased->setMapping( mPreviousPushButton, EPrevious ); |
|
156 signalMapperReleased->setMapping( mPlayPushButton, EPlayPause); |
|
157 signalMapperReleased->setMapping( mNextPushButton, ENext); |
|
158 |
|
159 // Connect button events to signal maps |
|
160 QObject::connect(mPreviousPushButton, SIGNAL(pressed()), signalMapperPressed, SLOT (map())); |
|
161 QObject::connect(mPreviousPushButton, SIGNAL(released()), signalMapperReleased, SLOT (map())); |
|
162 |
|
163 QObject::connect(mPlayPushButton, SIGNAL(pressed()), signalMapperPressed, SLOT (map())); |
|
164 QObject::connect(mPlayPushButton, SIGNAL(released()), signalMapperReleased, SLOT (map())); |
|
165 |
|
166 QObject::connect(mNextPushButton, SIGNAL(pressed()), signalMapperPressed, SLOT (map())); |
|
167 QObject::connect(mNextPushButton, SIGNAL(released()), signalMapperReleased, SLOT (map())); |
|
168 |
|
169 // Connect mapper signals to self implemented slots |
|
170 QObject::connect( signalMapperPressed, SIGNAL(mapped(int)), this, SLOT(mediaButtonPressed(int))); |
|
171 QObject::connect( signalMapperReleased, SIGNAL(mapped(int)), this, SLOT(mediaButtonReleased(int))); |
|
172 |
|
173 // Connect clicked events |
|
174 QObject::connect(mPreviousPushButton, SIGNAL(clicked()), this, SLOT(prevSong())); |
|
175 QObject::connect(mPlayPushButton, SIGNAL(clicked()), this, SLOT(playSong())); |
|
176 QObject::connect(mNextPushButton, SIGNAL(clicked()), this, SLOT(nextSong())); |
|
177 |
|
178 // MpEngine |
|
179 QObject::connect(mMpEngine, SIGNAL(libraryAboutToUpdate()), this, SLOT(libraryAboutToUpdate())); |
|
180 QObject::connect(mMpEngine, SIGNAL(libraryUpdated()), this, SLOT(libraryUpdated())); |
|
181 QObject::connect(mMpEngine, SIGNAL(usbBlocked(bool)), this, SLOT(usbBlocked(bool))); |
|
182 |
|
183 //MpPlaybackData |
|
184 QObject::connect(mMpPlaybackData, SIGNAL(albumArtReady()), this, SLOT(albumArtReady())); |
|
185 QObject::connect(mMpPlaybackData, SIGNAL(playbackStateChanged()), this, SLOT(playbackStateChanged())); |
|
186 QObject::connect(mMpPlaybackData, SIGNAL(playbackInfoChanged()), this, SLOT(playbackInfoChanged())); |
|
187 |
|
188 // Initial data from Music Player get by onShow method call |
|
189 TX_EXIT |
|
190 } |
|
191 |
|
192 /*! |
|
193 Destructor |
|
194 */ |
|
195 MusicWidget::~MusicWidget() |
|
196 { |
|
197 } |
|
198 |
|
199 /*! |
|
200 Creates UI. |
|
201 */ |
|
202 void MusicWidget::setupUi() |
|
203 { |
|
204 TX_ENTRY |
|
205 |
|
206 // Use document loader to load the contents |
|
207 MusicWidgetDocumentLoader loader; |
|
208 bool ok = false; |
|
209 loader.load( MUSIC_WIDGET_DOCML, &ok); |
|
210 Q_ASSERT_X(ok, "music_widget", "invalid title docml file"); |
|
211 |
|
212 TX_LOG_ARGS("loaded docml") |
|
213 |
|
214 QGraphicsLinearLayout* mainLayout = new QGraphicsLinearLayout(Qt::Vertical, this); |
|
215 QGraphicsWidget* container = loader.findWidget(DOCML_CONTAINER_WIDGET); |
|
216 mainLayout->addItem(container); |
|
217 //Sets parent |
|
218 setLayout( mainLayout ); |
|
219 |
|
220 // Load and set widget background |
|
221 HbWidget *bgWidget = qobject_cast<HbWidget*> (loader.findWidget(DOCML_BG_ICON)); |
|
222 HbFrameItem *frameItem; |
|
223 if (bgWidget) |
|
224 { |
|
225 HbFrameDrawer *drawer = new HbFrameDrawer(WIDGET_BG_NORMAL, |
|
226 HbFrameDrawer::NinePieces); |
|
227 frameItem = new HbFrameItem(drawer, bgWidget); |
|
228 frameItem->setPreferredSize(bgWidget->preferredSize()); |
|
229 bgWidget->setZValue(1); |
|
230 } |
|
231 |
|
232 // Setup album art area |
|
233 QGraphicsWidget *tmpWidgetPtr; |
|
234 tmpWidgetPtr = loader.findWidget(DOCML_ALBUM_ART); |
|
235 mAlbumArt = qobject_cast<MpAlbumCoverWidget*>(tmpWidgetPtr); |
|
236 mAlbumArt->setEnabled( false ); |
|
237 mAlbumArt->setDefaultIcon( HbIcon( ICON_DEFAULT_ART ) ); |
|
238 |
|
239 // Load shortcut background |
|
240 HbWidget *shortcutAreaLayout = qobject_cast<HbWidget*> (loader.findWidget(DOCML_SHORTCUT_ICON_BG)); |
|
241 HbFrameItem *shortcutFrameItem; |
|
242 if (shortcutAreaLayout) { |
|
243 HbFrameDrawer *drawer = new HbFrameDrawer(WIDGET_BG_NORMAL, |
|
244 HbFrameDrawer::NinePieces); |
|
245 shortcutFrameItem = new HbFrameItem(drawer, shortcutAreaLayout); |
|
246 shortcutFrameItem->setPreferredSize(shortcutAreaLayout->preferredSize()); |
|
247 shortcutAreaLayout->setZValue(3); |
|
248 } |
|
249 |
|
250 // Load shortcut widget and set background |
|
251 mShortcutArea = qobject_cast<HbPushButton*> (loader.findWidget(DOCML_SHORTCUT_ICON)); |
|
252 if ( mShortcutArea ) |
|
253 { |
|
254 // icon needs to be put as a background so that it fills the whole button area |
|
255 HbFrameDrawer* drawer = new HbFrameDrawer(ICON_LARGE_MUSIC_PLAYER, HbFrameDrawer::OnePiece); |
|
256 mShortcutArea->setFrameBackground( drawer ); |
|
257 } |
|
258 |
|
259 // Set song data background |
|
260 mSongDataBG = qobject_cast<HbWidget*> (loader.findWidget(DOCML_TEXT_BG)); |
|
261 HbFrameItem *scrollTextItem; |
|
262 if (mSongDataBG) |
|
263 { |
|
264 HbFrameDrawer *drawer = new HbFrameDrawer(TEXT_BG_NORMAL, |
|
265 HbFrameDrawer::NinePieces); |
|
266 scrollTextItem = new HbFrameItem(drawer, mSongDataBG); |
|
267 scrollTextItem->setPreferredSize(mSongDataBG->preferredSize()); |
|
268 mSongDataBG->setZValue(4); |
|
269 mSongDataBG->hide(); // Hide initially... |
|
270 } |
|
271 |
|
272 // Set scrolling song data |
|
273 mInformationSongName = qobject_cast<HbLabel*> (loader.findWidget(DOCML_SCROLLING_TEXT)); |
|
274 if ( mInformationSongName ) |
|
275 { |
|
276 // Setting primitive marquee item values from .css doesn't work well, set in code... |
|
277 mMarqueeText = new HbMarqueeItem(mInformationSongName); |
|
278 HbFontSpec fs(HbFontSpec::Secondary); |
|
279 mMarqueeText->setFontSpec(fs); |
|
280 mMarqueeText->setTextColor(mInformationSongName->textColor()); |
|
281 mMarqueeText->setMinimumWidth(MARQUEE_WIDTH); |
|
282 mMarqueeText->setLoopCount(MARQUEE_LOOP_FOREVER); |
|
283 } |
|
284 |
|
285 HbWidget *buttonGroupContainer = qobject_cast<HbWidget*> (loader.findWidget( |
|
286 DOCML_BUTTON_GROUP_CONTAINER)); |
|
287 if (buttonGroupContainer) |
|
288 { |
|
289 // Define push buttons in state at this point, check the player status later and update buttons if needed |
|
290 mPreviousPushButton = qobject_cast<HbPushButton*> (loader.findWidget(DOCML_PREV_BUTTON)); |
|
291 defineMediaButton( *mPreviousPushButton, PUSH_BUTTON_NORMAL, PREV_BUTTON_SUFFIXES, ICON_COLOR_NORMAL ); |
|
292 |
|
293 mPlayPushButton = qobject_cast<HbPushButton*> (loader.findWidget(DOCML_PLAY_BUTTON)); |
|
294 defineMediaButton( *mPlayPushButton, PUSH_BUTTON_NORMAL, PLAY_BUTTON_SUFFIXES, ICON_COLOR_NORMAL ); |
|
295 |
|
296 mNextPushButton = qobject_cast<HbPushButton*> (loader.findWidget(DOCML_NEXT_BUTTON)); |
|
297 defineMediaButton( *mNextPushButton, PUSH_BUTTON_NORMAL, NEXT_BUTTON_SUFFIXES, ICON_COLOR_NORMAL ); |
|
298 } |
|
299 |
|
300 TX_EXIT |
|
301 } |
|
302 |
|
303 /*! |
|
304 Makes the push button based on information aGraphicsId and aSuffix |
|
305 */ |
|
306 void MusicWidget::defineMediaButton( HbPushButton& aTarget, QString aGraphicsId, QStringList aSuffix, QString aIconColor ) |
|
307 { |
|
308 TX_ENTRY |
|
309 |
|
310 TX_LOG_ARGS("graphics id: " << aGraphicsId) |
|
311 TX_LOG_ARGS("icon color: " << aIconColor) |
|
312 |
|
313 HbFrameDrawer* drawer; |
|
314 |
|
315 // First check if the drawer is already created for this push button |
|
316 if ( !aTarget.frameBackground()){ |
|
317 // Nope, create one now |
|
318 drawer = new HbFrameDrawer(aGraphicsId, HbFrameDrawer::ThreePiecesHorizontal); |
|
319 aTarget.setFrameBackground( drawer ); |
|
320 TX_LOG_ARGS("created drawer for button bg") |
|
321 } |
|
322 else { |
|
323 // Frame drawer already created, only need to update frame graphics |
|
324 drawer = aTarget.frameBackground(); |
|
325 drawer->setFrameGraphicsName( aGraphicsId ); |
|
326 TX_LOG_ARGS("using existing drawer for button bg") |
|
327 } |
|
328 |
|
329 // Set file name suffix list, so that drawer can load correct 3-piece graphic files |
|
330 drawer->setFileNameSuffixList( aSuffix ); |
|
331 |
|
332 // Update also the icon color |
|
333 QColor color = HbColorScheme::color(aIconColor); |
|
334 aTarget.icon().setColor( color ); |
|
335 |
|
336 // Lastly, check if the buttton is disabled |
|
337 if ( aIconColor == ICON_COLOR_DISABLED ) |
|
338 { |
|
339 aTarget.setEnabled(false); |
|
340 TX_LOG_ARGS("button disabled") |
|
341 } |
|
342 else |
|
343 { |
|
344 aTarget.setEnabled(true); |
|
345 TX_LOG_ARGS("button enabled") |
|
346 } |
|
347 |
|
348 TX_EXIT |
|
349 } |
|
350 |
|
351 /*! |
|
352 |
|
353 */ |
|
354 void MusicWidget::mediaButtonEvent( MediaKeyIdentifier aMediaKeyId, QString aGraphicsId, QString aIconColor ) |
|
355 { |
|
356 TX_ENTRY |
|
357 |
|
358 HbPushButton* target = NULL; |
|
359 QStringList suffix; |
|
360 |
|
361 switch ( aMediaKeyId ) |
|
362 { |
|
363 case EPrevious: { |
|
364 TX_LOG_ARGS("previous") |
|
365 target = mPreviousPushButton; |
|
366 suffix = PREV_BUTTON_SUFFIXES; |
|
367 break; |
|
368 } |
|
369 case EPlayPause: { |
|
370 TX_LOG_ARGS("play/pause") |
|
371 target = mPlayPushButton; |
|
372 suffix = PLAY_BUTTON_SUFFIXES; |
|
373 break; |
|
374 } |
|
375 case ENext: { |
|
376 TX_LOG_ARGS("next") |
|
377 target = mNextPushButton; |
|
378 suffix = NEXT_BUTTON_SUFFIXES; |
|
379 break; |
|
380 } |
|
381 default: { |
|
382 // Do proper error handling.. should not be possible to get here ever tough |
|
383 TX_LOG_ARGS("unknown button") |
|
384 return; |
|
385 } |
|
386 } |
|
387 |
|
388 if ( target ) |
|
389 { |
|
390 MusicWidget::defineMediaButton( *target, aGraphicsId, suffix, aIconColor ); |
|
391 } |
|
392 |
|
393 TX_EXIT |
|
394 } |
|
395 |
|
396 /*! |
|
397 Emited from HbPushButton:pressed() signal, changes the button layout to 'Pressed' |
|
398 */ |
|
399 void MusicWidget::mediaButtonPressed( int aMediaKeyId ) |
|
400 { |
|
401 TX_LOG_ARGS("media key: " << aMediaKeyId ) |
|
402 mediaButtonEvent( (MediaKeyIdentifier)aMediaKeyId, PUSH_BUTTON_PRESSED, ICON_COLOR_PRESSED ); |
|
403 } |
|
404 |
|
405 /*! |
|
406 Emited from HbPushButton:released() signal, changes the button layout to 'Normal' |
|
407 */ |
|
408 void MusicWidget::mediaButtonReleased( int aMediaKeyId ) |
|
409 { |
|
410 TX_LOG_ARGS("media key: " << aMediaKeyId ) |
|
411 mediaButtonEvent( (MediaKeyIdentifier)aMediaKeyId, PUSH_BUTTON_NORMAL, ICON_COLOR_NORMAL ); |
|
412 } |
|
413 |
|
414 /*! |
|
415 Disables specified push button |
|
416 */ |
|
417 void MusicWidget::mediaButtonDisabled( int aMediaKeyId ) |
|
418 { |
|
419 TX_LOG_ARGS("media key: " << aMediaKeyId ) |
|
420 mediaButtonEvent( (MediaKeyIdentifier)aMediaKeyId, PUSH_BUTTON_DISABLED, ICON_COLOR_DISABLED ); |
|
421 } |
|
422 |
|
423 /*! |
|
424 Disables specified push button |
|
425 */ |
|
426 void MusicWidget::mediaButtonEnabled( int aMediaKeyId ) |
|
427 { |
|
428 TX_LOG_ARGS("media key: " << aMediaKeyId ) |
|
429 mediaButtonEvent( (MediaKeyIdentifier)aMediaKeyId, PUSH_BUTTON_NORMAL, ICON_COLOR_NORMAL ); |
|
430 } |
|
431 |
|
432 /*! |
|
433 Manually update music widget state. |
|
434 */ |
|
435 void MusicWidget::refreshData() |
|
436 { |
|
437 TX_ENTRY |
|
438 // Get current player state |
|
439 playbackStateChanged(); |
|
440 |
|
441 // Get current song data, updates button states |
|
442 playbackInfoChanged(); |
|
443 |
|
444 // Get current album art |
|
445 albumArtReady(); |
|
446 TX_EXIT |
|
447 } |
|
448 |
|
449 /*! |
|
450 Launch music player... |
|
451 */ |
|
452 void MusicWidget::launchMusicPlayer(int launchMode) |
|
453 { |
|
454 TX_ENTRY |
|
455 //TODO: Detect if MusicPlayer is running or not properly, handle case where player not available?! |
|
456 //TODO: Get service status from XQSettingManager |
|
457 //TODO: Service status from signal: |
|
458 //TODO: void statusChanged(const XQAiwInterfaceDescriptor& implementation, ServiceStatus currentStatus); |
|
459 |
|
460 QUrl url; |
|
461 XQAiwRequest* req; |
|
462 |
|
463 if ( launchMode == ELaunchFromPlay ) |
|
464 { |
|
465 TX_LOG_ARGS("launch from play") |
|
466 // Launch to now playing view, random play to be started! |
|
467 url.setUrl(SERVICEREQ_FIRST_TIME_USE); |
|
468 } |
|
469 else if (mMusicPlayerNoSongData) |
|
470 { |
|
471 TX_LOG_ARGS("to main view") |
|
472 // Launch to main view |
|
473 url.setUrl(SERVICEREQ_MAIN_VIEW); |
|
474 } |
|
475 else |
|
476 { |
|
477 TX_LOG_ARGS("to now playing view") |
|
478 // Launch to now playing view |
|
479 url.setUrl(SERVICEREQ_NOW_PLAYING_VIEW); |
|
480 } |
|
481 |
|
482 req = mApplicationManager.create(url); |
|
483 if (req == NULL) |
|
484 { |
|
485 // No handlers for the URI |
|
486 TX_LOG_ARGS("no req created") |
|
487 return; |
|
488 } |
|
489 |
|
490 req->setBackground(false); |
|
491 req->setSynchronous(false); |
|
492 |
|
493 // Set function parameters |
|
494 QList<QVariant> args; |
|
495 args << url.toString(); |
|
496 req->setArguments(args); |
|
497 |
|
498 // Send the request |
|
499 bool res = req->send(); |
|
500 if (!res) |
|
501 { |
|
502 // Request failed. |
|
503 int error = req->lastError(); |
|
504 // Handle error |
|
505 TX_LOG_ARGS("req send error: " << error) |
|
506 } |
|
507 |
|
508 delete req; |
|
509 |
|
510 TX_EXIT |
|
511 } |
|
512 |
|
513 /*! |
|
514 Return bounding rect |
|
515 */ |
|
516 QRectF MusicWidget::boundingRect() const |
|
517 { |
|
518 return childrenBoundingRect(); |
|
519 } |
|
520 |
|
521 /*! |
|
522 Return shape |
|
523 */ |
|
524 QPainterPath MusicWidget::shape() const |
|
525 { |
|
526 QPainterPath path; |
|
527 path.addRect(boundingRect()); |
|
528 return path; |
|
529 } |
|
530 |
|
531 /*! |
|
532 Initializes the widget. |
|
533 */ |
|
534 void MusicWidget::onInitialize() |
|
535 { |
|
536 TX_LOG |
|
537 } |
|
538 |
|
539 /*! |
|
540 Shows the widget. |
|
541 */ |
|
542 void MusicWidget::onShow() |
|
543 { |
|
544 TX_LOG |
|
545 refreshData(); |
|
546 } |
|
547 |
|
548 /*! |
|
549 Hides the widget. |
|
550 */ |
|
551 void MusicWidget::onHide() |
|
552 { |
|
553 TX_LOG |
|
554 } |
|
555 |
|
556 /*! |
|
557 Uninitializes the widget. |
|
558 */ |
|
559 void MusicWidget::onUninitialize() |
|
560 { |
|
561 TX_LOG |
|
562 } |
|
563 |
|
564 /*! |
|
565 Slot for shortcut button clicked. |
|
566 */ |
|
567 void MusicWidget::shortcutButton() |
|
568 { |
|
569 TX_LOG |
|
570 launchMusicPlayer(ELaunchFromShortcut); |
|
571 } |
|
572 |
|
573 /*! |
|
574 Slot for previous button clicked. |
|
575 */ |
|
576 void MusicWidget::prevSong() |
|
577 { |
|
578 TX_LOG |
|
579 mMpEngine->skipBackward(); |
|
580 } |
|
581 |
|
582 /*! |
|
583 Slot for play button clicked. Handles both Play and Pause! |
|
584 */ |
|
585 void MusicWidget::playSong() |
|
586 { |
|
587 TX_ENTRY |
|
588 if (mMusicPlayerNoSongData && mMpPlaybackData->playbackState() != MpPlaybackData::Playing ) |
|
589 { |
|
590 //Signal music player to start playing all songs with random |
|
591 launchMusicPlayer(ELaunchFromPlay); |
|
592 } |
|
593 |
|
594 mMpEngine->playPause(); |
|
595 TX_EXIT |
|
596 } |
|
597 /*! |
|
598 Slot for next button clicked. |
|
599 */ |
|
600 void MusicWidget::nextSong() |
|
601 { |
|
602 TX_LOG |
|
603 mMpEngine->skipForward(); |
|
604 } |
|
605 |
|
606 /*! |
|
607 |
|
608 */ |
|
609 bool MusicWidget::eventFilter(QObject *target, QEvent *event) |
|
610 { |
|
611 // pass the event on to the parent class |
|
612 return HbWidget::eventFilter(target, event); |
|
613 } |
|
614 |
|
615 /*! |
|
616 MpEngine related |
|
617 */ |
|
618 void MusicWidget::libraryAboutToUpdate() |
|
619 { |
|
620 TX_LOG |
|
621 //Refresh Library start |
|
622 mMusicPlayerUpdating = true; |
|
623 |
|
624 // Update button enabled/disabled state |
|
625 toggleButtons(); |
|
626 } |
|
627 |
|
628 /*! |
|
629 MpEngine related |
|
630 */ |
|
631 void MusicWidget::libraryUpdated() |
|
632 { |
|
633 TX_LOG |
|
634 //Refresh Library done |
|
635 mMusicPlayerUpdating = false; |
|
636 |
|
637 // Update button enabled/disabled state |
|
638 toggleButtons(); |
|
639 } |
|
640 |
|
641 /*! |
|
642 MpEngine related |
|
643 */ |
|
644 void MusicWidget::usbBlocked( bool blocked ) |
|
645 { |
|
646 TX_LOG_ARGS("blocked: " << blocked) |
|
647 //Blocked state |
|
648 //Mass storage mode |
|
649 //Media transfer mode |
|
650 //Ovi Suite mode |
|
651 //Insert memory card |
|
652 |
|
653 mMusicPlayerBlocked = blocked; |
|
654 |
|
655 // Update button enabled/disabled state |
|
656 toggleButtons(); |
|
657 } |
|
658 |
|
659 /*! |
|
660 MpPlaybackData related |
|
661 */ |
|
662 void MusicWidget::albumArtReady() |
|
663 { |
|
664 TX_ENTRY |
|
665 HbIcon icon; |
|
666 |
|
667 if ( mMpPlaybackData->playbackState() == MpPlaybackData::NotPlaying ) |
|
668 { |
|
669 TX_LOG_ARGS("1st time album art") |
|
670 icon = HbIcon(ICON_FIRST_TIME_USE); |
|
671 } |
|
672 else |
|
673 { |
|
674 TX_LOG_ARGS("playback data album art") |
|
675 mMpPlaybackData->albumArt( icon ); |
|
676 } |
|
677 |
|
678 mAlbumArt->setIcon( icon ); |
|
679 mAlbumArt->setEnabled( true ); |
|
680 |
|
681 TX_EXIT |
|
682 } |
|
683 |
|
684 void MusicWidget::playbackStateChanged() |
|
685 { |
|
686 TX_ENTRY |
|
687 // Set play/pause icon and start/stop marquee. |
|
688 QString iconName; |
|
689 |
|
690 int state = mMpPlaybackData->playbackState(); |
|
691 |
|
692 TX_LOG_ARGS("state: " << state) |
|
693 |
|
694 switch (state) |
|
695 { |
|
696 case MpPlaybackData::Playing: |
|
697 { |
|
698 TX_LOG_ARGS("pause icon, start marquee") |
|
699 iconName.append(ICON_PAUSE); |
|
700 mMarqueeText->startAnimation(); |
|
701 break; |
|
702 } |
|
703 case MpPlaybackData::Paused: |
|
704 case MpPlaybackData::Stopped: |
|
705 case MpPlaybackData::NotPlaying: |
|
706 { |
|
707 TX_LOG_ARGS("play icon, stop marquee") |
|
708 iconName.append(ICON_PLAY); |
|
709 mMarqueeText->stopAnimation(); |
|
710 break; |
|
711 } |
|
712 } |
|
713 |
|
714 HbIcon iconPlayPause(iconName); |
|
715 mPlayPushButton->setIcon(iconPlayPause); |
|
716 |
|
717 TX_EXIT |
|
718 } |
|
719 |
|
720 /*! |
|
721 MpPlaybackData related |
|
722 */ |
|
723 void MusicWidget::playbackInfoChanged() |
|
724 { |
|
725 TX_ENTRY |
|
726 // Initialize maqruee with something (space), to ensure |
|
727 // text updates to display as well. |
|
728 QString songData; |
|
729 |
|
730 mArtist = mMpPlaybackData->artist(); |
|
731 mTitle = mMpPlaybackData->title(); |
|
732 |
|
733 if ( !mTitle.length() ) |
|
734 { |
|
735 mArtist.clear(); |
|
736 mTitle.clear(); |
|
737 songData = " "; |
|
738 |
|
739 //1st time launch |
|
740 mMusicPlayerNoSongData = true; |
|
741 |
|
742 TX_LOG_ARGS("no song data") |
|
743 } |
|
744 else |
|
745 { |
|
746 if ( !mArtist.length() ) |
|
747 { |
|
748 //Show localized "Unknown" if there is no artist name |
|
749 |
|
750 //TODO: Widget needs own localization?!?! |
|
751 //mArtist.append( hbTrId(UNKWNOWN_TEXT) ); |
|
752 |
|
753 //TODO: Remove temporary unknown string when localization resolved. |
|
754 mArtist.append( TEMPORARY_UNKWNOWN_TEXT ); |
|
755 } |
|
756 |
|
757 songData.append(mArtist); |
|
758 songData.append(SEPARATOR_TEXT); |
|
759 songData.append(mTitle); |
|
760 |
|
761 mMusicPlayerNoSongData = false; |
|
762 |
|
763 TX_LOG_ARGS("song data received") |
|
764 } |
|
765 |
|
766 mMarqueeText->setText(songData); |
|
767 TX_LOG_ARGS("marquee text: " << songData) |
|
768 |
|
769 // Show dark BG to songdata only if there is songdata... |
|
770 if ( mMusicPlayerNoSongData && mSongDataBG->isVisible() ) |
|
771 { |
|
772 TX_LOG_ARGS("hide marquee bg") |
|
773 mSongDataBG->hide(); |
|
774 } |
|
775 else if ( !mMusicPlayerNoSongData && !mSongDataBG->isVisible() ) |
|
776 { |
|
777 TX_LOG_ARGS("show marquee bg") |
|
778 mSongDataBG->show(); |
|
779 } |
|
780 |
|
781 // Update button enabled/disabled state |
|
782 toggleButtons(); |
|
783 |
|
784 TX_EXIT |
|
785 } |
|
786 |
|
787 /*! |
|
788 Toggle buttons to disabled/enabled as required. |
|
789 */ |
|
790 void MusicWidget::toggleButtons() |
|
791 { |
|
792 TX_ENTRY |
|
793 // All buttons disabled if updating |
|
794 if ( mMusicPlayerUpdating ) |
|
795 { |
|
796 TX_LOG_ARGS("updating") |
|
797 mediaButtonDisabled( EPlayPause ); |
|
798 mediaButtonDisabled( EPrevious ); |
|
799 mediaButtonDisabled( ENext ); |
|
800 } |
|
801 |
|
802 // All buttons disabled if blocked |
|
803 else if ( mMusicPlayerBlocked ) |
|
804 { |
|
805 TX_LOG_ARGS("blocked") |
|
806 mediaButtonDisabled( EPlayPause ); |
|
807 mediaButtonDisabled( EPrevious ); |
|
808 mediaButtonDisabled( ENext ); |
|
809 } |
|
810 |
|
811 // Only play button enabled if there is no song data, 1st time use |
|
812 else if ( mMusicPlayerNoSongData ) |
|
813 { |
|
814 TX_LOG_ARGS("no song data") |
|
815 mediaButtonEnabled( EPlayPause ); |
|
816 mediaButtonDisabled( EPrevious ); |
|
817 mediaButtonDisabled( ENext ); |
|
818 } |
|
819 |
|
820 // Enable all buttons if there is song data |
|
821 else |
|
822 { |
|
823 TX_LOG_ARGS("enable all buttons") |
|
824 mediaButtonEnabled( EPlayPause ); |
|
825 mediaButtonEnabled( EPrevious ); |
|
826 mediaButtonEnabled( ENext ); |
|
827 } |
|
828 TX_EXIT |
|
829 } |