36
|
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 |
|
59
|
18 |
// System includes
|
|
19 |
#include <qgraphicslinearlayout.h>
|
36
|
20 |
#include <hbpushbutton.h>
|
|
21 |
#include <hblabel.h>
|
|
22 |
#include <hbicon.h>
|
|
23 |
#include <hbmarqueeitem.h>
|
|
24 |
#include <hbanchorlayout.h>
|
|
25 |
#include <hbwidget.h>
|
|
26 |
#include <hbframeitem.h>
|
|
27 |
#include <hbframedrawer.h>
|
59
|
28 |
#include <hbtranslator.h>
|
36
|
29 |
|
59
|
30 |
// User includes
|
|
31 |
#include "musicwidget.h"
|
43
|
32 |
#include "musicwidgetdocumentloader.h"
|
36
|
33 |
#include "mptrace.h"
|
|
34 |
#include "mpenginefactory.h"
|
43
|
35 |
#include "mpalbumcoverwidget.h"
|
59
|
36 |
#include "mpplaybackdata.h"
|
|
37 |
#include "mpapplicationmonitor.h"
|
36
|
38 |
|
|
39 |
// Constants
|
|
40 |
/** Docml */
|
59
|
41 |
const QString MUSIC_WIDGET_DOCML = ":/docml/music_widget.docml";
|
36
|
42 |
|
|
43 |
/** Play and Pause icons */
|
59
|
44 |
const QLatin1String ICON_PLAY ( "qtg_mono_play" );
|
|
45 |
const QLatin1String ICON_PAUSE ( "qtg_mono_pause" );
|
|
46 |
|
|
47 |
/** Album art icon */
|
|
48 |
const QLatin1String ICON_DEFAULT_ART ( "qtg_large_music_empty" );
|
36
|
49 |
|
|
50 |
/** HsWidget normal background */
|
59
|
51 |
const QLatin1String WIDGET_BG_NORMAL ( "qtg_fr_hswidget_normal" );
|
36
|
52 |
/** Text background */
|
59
|
53 |
const QLatin1String TEXT_BG_NORMAL ( "qtg_fr_multimedia_trans" );
|
36
|
54 |
/** Separator : character and space between artist and song name */
|
59
|
55 |
const QLatin1String SEPARATOR_TEXT ( ": " );
|
36
|
56 |
|
|
57 |
/** Infinite loop value for marquee */
|
|
58 |
const int MARQUEE_LOOP_FOREVER = -1;
|
|
59 |
|
|
60 |
/** Now playing view with random play */
|
59
|
61 |
const QLatin1String SERVICEREQ_NOW_PLAYING_VIEW_SHUFFLE ( "appto://10207C62?activityname=MusicNowPlayingView&launchtype=standalone&shuffle=yes" );
|
36
|
62 |
/** Main view */
|
59
|
63 |
const QLatin1String SERVICEREQ_MAIN_VIEW ( "appto://10207C62?activityname=MusicMainView&launchtype=standalone" );
|
36
|
64 |
/** Now playing view */
|
59
|
65 |
const QLatin1String SERVICEREQ_NOW_PLAYING_VIEW ( "appto://10207C62?activityname=MusicNowPlayingView&launchtype=standalone" );
|
|
66 |
|
|
67 |
/** DOCML object names */
|
|
68 |
const QLatin1String DOCML_CONTAINER_WIDGET ( "containerWidget" );
|
|
69 |
const QLatin1String DOCML_BG_ICON ( "widget_background_icon" );
|
|
70 |
const QLatin1String DOCML_ALBUM_ART ( "album_art_image" );
|
|
71 |
const QLatin1String DOCML_TEXT_BG ( "text_bg" );
|
|
72 |
const QLatin1String DOCML_SCROLLING_TEXT ( "scrolling_text" );
|
|
73 |
const QLatin1String DOCML_BUTTON_GROUP_CONTAINER ( "button_group_container" );
|
|
74 |
const QLatin1String DOCML_PREV_BUTTON ( "btn_previous" );
|
|
75 |
const QLatin1String DOCML_PLAY_BUTTON ( "btn_play" );
|
|
76 |
const QLatin1String DOCML_NEXT_BUTTON ( "btn_next" );
|
36
|
77 |
|
59
|
78 |
/*!
|
|
79 |
\class MusicWidget
|
|
80 |
\brief Provides simple Music Player playback controls from the Home Screen.
|
|
81 |
*/
|
36
|
82 |
|
59
|
83 |
/*!
|
|
84 |
Constructs the Music Player home screen widget.
|
|
85 |
*/
|
|
86 |
MusicWidget::MusicWidget( QGraphicsItem* parent, Qt::WindowFlags flags ):
|
|
87 |
HbWidget( parent, flags ),
|
|
88 |
mSongDataBackground( 0 ),
|
|
89 |
mMarqueeText( 0 ),
|
|
90 |
mPreviousPushButton( 0 ),
|
|
91 |
mPlayPushButton( 0 ),
|
|
92 |
mNextPushButton( 0 ),
|
|
93 |
mMusicPlayerUpdating( false ),
|
|
94 |
mMusicPlayerBlocked( false ),
|
|
95 |
mMusicPlayerRunning( false ),
|
|
96 |
mAlbumArt( 0 ),
|
|
97 |
mMpEngine( 0 ),
|
|
98 |
mMpPlaybackData( 0 ),
|
|
99 |
mMpApplicationMonitor( 0 )
|
36
|
100 |
{
|
59
|
101 |
TX_LOG
|
|
102 |
HbTranslator translator( QString( "musicwidgetplugin" ) );
|
36
|
103 |
}
|
|
104 |
|
|
105 |
/*!
|
59
|
106 |
Destructor
|
|
107 |
*/
|
36
|
108 |
MusicWidget::~MusicWidget()
|
|
109 |
{
|
59
|
110 |
TX_ENTRY
|
|
111 |
if ( mMpEngine ) {
|
|
112 |
MpEngineFactory::close();
|
|
113 |
}
|
|
114 |
|
|
115 |
delete mMpApplicationMonitor;
|
|
116 |
TX_EXIT
|
36
|
117 |
}
|
|
118 |
|
|
119 |
/*!
|
|
120 |
Creates UI.
|
|
121 |
*/
|
|
122 |
void MusicWidget::setupUi()
|
|
123 |
{
|
|
124 |
TX_ENTRY
|
|
125 |
|
|
126 |
// Use document loader to load the contents
|
43
|
127 |
MusicWidgetDocumentLoader loader;
|
36
|
128 |
bool ok = false;
|
59
|
129 |
loader.load( MUSIC_WIDGET_DOCML, &ok );
|
|
130 |
Q_ASSERT_X( ok, "music_widget", "invalid title docml file" );
|
36
|
131 |
|
59
|
132 |
TX_LOG_ARGS( "loaded docml" )
|
36
|
133 |
|
59
|
134 |
QGraphicsLinearLayout* mainLayout = new QGraphicsLinearLayout( Qt::Vertical, this );
|
|
135 |
QGraphicsWidget* container = loader.findWidget( DOCML_CONTAINER_WIDGET );
|
|
136 |
mainLayout->addItem( container );
|
|
137 |
|
36
|
138 |
//Sets parent
|
|
139 |
setLayout( mainLayout );
|
|
140 |
|
|
141 |
// Load and set widget background
|
59
|
142 |
HbLabel *bgWidget = qobject_cast<HbLabel*> ( loader.findWidget( DOCML_BG_ICON ) );
|
|
143 |
HbFrameItem *frameItemWidgetBg = new HbFrameItem();
|
|
144 |
frameItemWidgetBg->frameDrawer().setFrameGraphicsName( WIDGET_BG_NORMAL );
|
|
145 |
frameItemWidgetBg->frameDrawer().setFrameType( HbFrameDrawer::NinePieces );
|
|
146 |
frameItemWidgetBg->frameDrawer().setFillWholeRect( true );
|
|
147 |
bgWidget->setBackgroundItem( frameItemWidgetBg );
|
36
|
148 |
|
|
149 |
// Setup album art area
|
|
150 |
QGraphicsWidget *tmpWidgetPtr;
|
59
|
151 |
tmpWidgetPtr = loader.findWidget( DOCML_ALBUM_ART );
|
|
152 |
mAlbumArt = qobject_cast<MpAlbumCoverWidget*>( tmpWidgetPtr );
|
43
|
153 |
mAlbumArt->setEnabled( false );
|
|
154 |
mAlbumArt->setDefaultIcon( HbIcon( ICON_DEFAULT_ART ) );
|
36
|
155 |
|
|
156 |
// Set song data background
|
59
|
157 |
mSongDataBackground = qobject_cast<HbLabel*> ( loader.findWidget( DOCML_TEXT_BG ) );
|
|
158 |
HbFrameItem *frameItemSongBg = new HbFrameItem();
|
|
159 |
frameItemSongBg->frameDrawer().setFrameGraphicsName( TEXT_BG_NORMAL );
|
|
160 |
frameItemSongBg->frameDrawer().setFrameType( HbFrameDrawer::NinePieces );
|
|
161 |
frameItemSongBg->frameDrawer().setFillWholeRect( true );
|
|
162 |
mSongDataBackground->setBackgroundItem( frameItemSongBg );
|
|
163 |
mSongDataBackground->hide();
|
36
|
164 |
|
|
165 |
// Set scrolling song data
|
59
|
166 |
mMarqueeText = qobject_cast<HbMarqueeItem*> ( loader.findWidget( DOCML_SCROLLING_TEXT ) );
|
|
167 |
mMarqueeText->setLoopCount( MARQUEE_LOOP_FOREVER );
|
|
168 |
|
|
169 |
// Get buttons
|
|
170 |
HbWidget *buttonGroupContainer = qobject_cast<HbWidget*> ( loader.findWidget(
|
|
171 |
DOCML_BUTTON_GROUP_CONTAINER ) );
|
|
172 |
if ( buttonGroupContainer ) {
|
|
173 |
// Define push buttons
|
|
174 |
mPreviousPushButton = qobject_cast<HbPushButton*> ( loader.findWidget( DOCML_PREV_BUTTON ) );
|
|
175 |
mPlayPushButton = qobject_cast<HbPushButton*> ( loader.findWidget( DOCML_PLAY_BUTTON ) );
|
|
176 |
mNextPushButton = qobject_cast<HbPushButton*> ( loader.findWidget( DOCML_NEXT_BUTTON ) );
|
|
177 |
}
|
|
178 |
|
36
|
179 |
TX_EXIT
|
|
180 |
}
|
|
181 |
|
|
182 |
/*!
|
|
183 |
Manually update music widget state.
|
|
184 |
*/
|
|
185 |
void MusicWidget::refreshData()
|
|
186 |
{
|
|
187 |
TX_ENTRY
|
59
|
188 |
|
36
|
189 |
// Get current player state
|
|
190 |
playbackStateChanged();
|
|
191 |
|
|
192 |
// Get current song data, updates button states
|
|
193 |
playbackInfoChanged();
|
|
194 |
|
|
195 |
// Get current album art
|
|
196 |
albumArtReady();
|
59
|
197 |
|
36
|
198 |
TX_EXIT
|
|
199 |
}
|
|
200 |
|
|
201 |
/*!
|
59
|
202 |
Launch music player.
|
36
|
203 |
*/
|
59
|
204 |
void MusicWidget::launchMusicPlayer( int launchMode )
|
36
|
205 |
{
|
|
206 |
TX_ENTRY
|
59
|
207 |
|
36
|
208 |
QUrl url;
|
|
209 |
|
59
|
210 |
switch ( launchMode ) {
|
|
211 |
case ELaunchToMainView:
|
|
212 |
TX_LOG_ARGS( "to main view" )
|
|
213 |
// Launch to main view
|
|
214 |
url.setUrl( SERVICEREQ_MAIN_VIEW );
|
|
215 |
break;
|
|
216 |
case ELaunchToNowPlayingView:
|
|
217 |
TX_LOG_ARGS( "to now playing view" )
|
|
218 |
// Launch to now playing view
|
|
219 |
url.setUrl( SERVICEREQ_NOW_PLAYING_VIEW );
|
|
220 |
break;
|
|
221 |
case ELaunchToNowPlayingViewWithShuffle:
|
|
222 |
TX_LOG_ARGS( "to now playing view with shuffle" )
|
|
223 |
// Launch to now playing view with shuffle
|
|
224 |
url.setUrl( SERVICEREQ_NOW_PLAYING_VIEW_SHUFFLE );
|
|
225 |
break;
|
|
226 |
default:
|
|
227 |
//should never get here
|
|
228 |
TX_LOG_ARGS( "Error: invalid launchMode." )
|
|
229 |
return;
|
|
230 |
}
|
36
|
231 |
|
59
|
232 |
XQAiwRequest* req;
|
|
233 |
req = mApplicationManager.create( url );
|
|
234 |
if ( req ) {
|
|
235 |
req->setBackground( false );
|
|
236 |
req->setSynchronous( false );
|
|
237 |
|
|
238 |
// Set function parameters
|
|
239 |
QList<QVariant> args;
|
|
240 |
args << url.toString();
|
|
241 |
req->setArguments( args );
|
36
|
242 |
|
59
|
243 |
// Send the request
|
|
244 |
bool res = req->send();
|
|
245 |
if ( !res ) {
|
|
246 |
// Request failed.
|
|
247 |
int error = req->lastError();
|
|
248 |
// Handle error
|
|
249 |
TX_LOG_ARGS( "req send error: " << error )
|
|
250 |
}
|
|
251 |
delete req;
|
|
252 |
}
|
36
|
253 |
|
59
|
254 |
TX_EXIT
|
36
|
255 |
}
|
|
256 |
|
|
257 |
/*!
|
|
258 |
Initializes the widget.
|
|
259 |
*/
|
|
260 |
void MusicWidget::onInitialize()
|
|
261 |
{
|
59
|
262 |
TX_ENTRY
|
|
263 |
|
|
264 |
// Setup UI
|
|
265 |
setupUi();
|
|
266 |
|
|
267 |
// Start Monitoring Music Player running status.
|
|
268 |
mMpApplicationMonitor = new MpApplicationMonitor();
|
|
269 |
|
|
270 |
// Check if Music Player UI is up and running
|
|
271 |
mMusicPlayerRunning = mMpApplicationMonitor->isApplicationRunning();
|
|
272 |
|
|
273 |
// Connect to MP engine and playback data
|
|
274 |
connectMusicPlayerEngine( mMusicPlayerRunning );
|
|
275 |
|
|
276 |
// Connect albumart click signal
|
|
277 |
QObject::connect( mAlbumArt, SIGNAL( clicked() ), this, SLOT( handleAlbumArtClicked() ) );
|
|
278 |
|
|
279 |
// Connect button clicked signals
|
|
280 |
QObject::connect( mPreviousPushButton, SIGNAL( clicked() ), this, SLOT( handlePrevButtonClicked() ) );
|
|
281 |
QObject::connect( mPlayPushButton, SIGNAL( clicked() ), this, SLOT( handlePlayButtonClicked() ) );
|
|
282 |
QObject::connect( mNextPushButton, SIGNAL( clicked() ), this, SLOT( handleNextButtonClicked() ) );
|
|
283 |
|
|
284 |
// Connect Music Player observer signal
|
|
285 |
QObject::connect( mMpApplicationMonitor, SIGNAL( applicationStatusChanged( bool ) ),
|
|
286 |
this, SLOT ( applicationStatusChanged( bool ) ) );
|
|
287 |
|
|
288 |
TX_EXIT
|
36
|
289 |
}
|
|
290 |
|
|
291 |
/*!
|
|
292 |
Shows the widget.
|
|
293 |
*/
|
|
294 |
void MusicWidget::onShow()
|
|
295 |
{
|
59
|
296 |
TX_ENTRY
|
36
|
297 |
refreshData();
|
59
|
298 |
TX_EXIT
|
36
|
299 |
}
|
|
300 |
|
|
301 |
/*!
|
|
302 |
Hides the widget.
|
|
303 |
*/
|
|
304 |
void MusicWidget::onHide()
|
|
305 |
{
|
|
306 |
TX_LOG
|
59
|
307 |
if ( mMarqueeText->isAnimating() ) {
|
|
308 |
mMarqueeText->stopAnimation();
|
|
309 |
}
|
36
|
310 |
}
|
|
311 |
|
|
312 |
/*!
|
|
313 |
Uninitializes the widget.
|
|
314 |
*/
|
|
315 |
void MusicWidget::onUninitialize()
|
|
316 |
{
|
|
317 |
TX_LOG
|
|
318 |
}
|
|
319 |
|
|
320 |
/*!
|
59
|
321 |
Slot to handle when the album art area is clicked.
|
36
|
322 |
*/
|
59
|
323 |
void MusicWidget::handleAlbumArtClicked()
|
36
|
324 |
{
|
59
|
325 |
TX_ENTRY
|
|
326 |
if ( getPlaybackState() == MpPlaybackData::NotPlaying ) {
|
|
327 |
launchMusicPlayer( ELaunchToMainView );
|
|
328 |
}
|
|
329 |
else {
|
|
330 |
launchMusicPlayer( ELaunchToNowPlayingView );
|
|
331 |
}
|
|
332 |
TX_EXIT
|
36
|
333 |
}
|
|
334 |
|
|
335 |
/*!
|
|
336 |
Slot for previous button clicked.
|
|
337 |
*/
|
59
|
338 |
void MusicWidget::handlePrevButtonClicked()
|
36
|
339 |
{
|
59
|
340 |
TX_ENTRY
|
|
341 |
if ( mMpEngine ) {
|
|
342 |
mMpEngine->skipBackward();
|
|
343 |
}
|
|
344 |
TX_EXIT
|
36
|
345 |
}
|
|
346 |
|
|
347 |
/*!
|
|
348 |
Slot for play button clicked. Handles both Play and Pause!
|
|
349 |
*/
|
59
|
350 |
void MusicWidget::handlePlayButtonClicked()
|
36
|
351 |
{
|
|
352 |
TX_ENTRY
|
59
|
353 |
// If nothing to play, start music player in playback view.
|
|
354 |
if ( getPlaybackState() == MpPlaybackData::NotPlaying ) {
|
36
|
355 |
//Signal music player to start playing all songs with random
|
59
|
356 |
launchMusicPlayer( ELaunchToNowPlayingViewWithShuffle );
|
|
357 |
}
|
|
358 |
else {
|
|
359 |
// send play/pause command.
|
|
360 |
if ( mMpEngine ) {
|
|
361 |
mMpEngine->playPause();
|
36
|
362 |
}
|
59
|
363 |
}
|
36
|
364 |
TX_EXIT
|
|
365 |
}
|
59
|
366 |
|
36
|
367 |
/*!
|
|
368 |
Slot for next button clicked.
|
|
369 |
*/
|
59
|
370 |
void MusicWidget::handleNextButtonClicked()
|
36
|
371 |
{
|
59
|
372 |
TX_ENTRY
|
|
373 |
if ( mMpEngine ) {
|
|
374 |
mMpEngine->skipForward();
|
|
375 |
}
|
|
376 |
TX_EXIT
|
36
|
377 |
}
|
|
378 |
|
|
379 |
/*!
|
59
|
380 |
Slot to handle when the music player running status changed.
|
36
|
381 |
*/
|
59
|
382 |
void MusicWidget::applicationStatusChanged( bool isRunning )
|
|
383 |
{
|
|
384 |
TX_ENTRY_ARGS( "running " << isRunning );
|
|
385 |
|
|
386 |
// Connect/disconnect engine base on music player running state.
|
|
387 |
if ( mMusicPlayerRunning != isRunning ) {
|
|
388 |
TX_LOG_ARGS("running state changed");
|
|
389 |
mMusicPlayerRunning = isRunning;
|
|
390 |
connectMusicPlayerEngine( isRunning );
|
|
391 |
// refresh data if musicplayer is on, otherwise clear data
|
|
392 |
if ( isRunning ) {
|
|
393 |
refreshData();
|
|
394 |
}
|
|
395 |
else {
|
|
396 |
clearData();
|
|
397 |
}
|
|
398 |
}
|
|
399 |
|
|
400 |
TX_EXIT
|
36
|
401 |
}
|
|
402 |
|
|
403 |
/*!
|
59
|
404 |
Library started refreshing.
|
36
|
405 |
*/
|
55
|
406 |
void MusicWidget::libraryUpdateStarted()
|
36
|
407 |
{
|
59
|
408 |
TX_ENTRY
|
36
|
409 |
//Refresh Library start
|
|
410 |
mMusicPlayerUpdating = true;
|
|
411 |
|
|
412 |
// Update button enabled/disabled state
|
59
|
413 |
updateButtons();
|
|
414 |
TX_EXIT
|
36
|
415 |
}
|
|
416 |
|
|
417 |
/*!
|
59
|
418 |
Library is finished refreshing.
|
36
|
419 |
*/
|
|
420 |
void MusicWidget::libraryUpdated()
|
|
421 |
{
|
59
|
422 |
TX_ENTRY
|
36
|
423 |
//Refresh Library done
|
|
424 |
mMusicPlayerUpdating = false;
|
|
425 |
|
|
426 |
// Update button enabled/disabled state
|
59
|
427 |
updateButtons();
|
|
428 |
TX_EXIT
|
36
|
429 |
}
|
|
430 |
|
|
431 |
/*!
|
59
|
432 |
USB blocking state has changed.
|
36
|
433 |
*/
|
|
434 |
void MusicWidget::usbBlocked( bool blocked )
|
|
435 |
{
|
59
|
436 |
TX_ENTRY_ARGS( "blocked: " << blocked )
|
36
|
437 |
mMusicPlayerBlocked = blocked;
|
|
438 |
|
|
439 |
// Update button enabled/disabled state
|
59
|
440 |
updateButtons();
|
|
441 |
TX_EXIT
|
36
|
442 |
}
|
|
443 |
|
|
444 |
/*!
|
59
|
445 |
The album art has changed.
|
36
|
446 |
*/
|
|
447 |
void MusicWidget::albumArtReady()
|
|
448 |
{
|
|
449 |
TX_ENTRY
|
|
450 |
HbIcon icon;
|
|
451 |
|
59
|
452 |
if ( getPlaybackState() == MpPlaybackData::NotPlaying ) {
|
|
453 |
TX_LOG_ARGS( "default album art" )
|
|
454 |
icon = HbIcon( ICON_DEFAULT_ART );
|
|
455 |
}
|
|
456 |
else {
|
|
457 |
TX_LOG_ARGS( "playback data album art" )
|
|
458 |
if ( mMpPlaybackData ) {
|
|
459 |
mMpPlaybackData->albumArt( icon );
|
36
|
460 |
}
|
59
|
461 |
}
|
36
|
462 |
|
43
|
463 |
mAlbumArt->setIcon( icon );
|
|
464 |
mAlbumArt->setEnabled( true );
|
59
|
465 |
TX_EXIT
|
|
466 |
}
|
|
467 |
|
|
468 |
/*!
|
|
469 |
Playback state has changed.
|
|
470 |
*/
|
|
471 |
void MusicWidget::playbackStateChanged()
|
|
472 |
{
|
|
473 |
TX_ENTRY
|
|
474 |
|
|
475 |
if ( getPlaybackState() == MpPlaybackData::Playing ) {
|
|
476 |
TX_LOG_ARGS( "pause icon" )
|
|
477 |
mPlayPushButton->setIcon( HbIcon( ICON_PAUSE ) );
|
|
478 |
}
|
|
479 |
else {
|
|
480 |
TX_LOG_ARGS( "play icon" )
|
|
481 |
mPlayPushButton->setIcon( HbIcon( ICON_PLAY ) );
|
|
482 |
}
|
|
483 |
|
|
484 |
// Update button enabled/disabled state
|
|
485 |
updateButtons();
|
36
|
486 |
|
|
487 |
TX_EXIT
|
|
488 |
}
|
|
489 |
|
59
|
490 |
/*!
|
|
491 |
Song data has changed.
|
|
492 |
*/
|
|
493 |
void MusicWidget::playbackInfoChanged()
|
|
494 |
{
|
36
|
495 |
TX_ENTRY
|
59
|
496 |
|
|
497 |
QString songData;
|
|
498 |
QString artist;
|
|
499 |
QString title;
|
36
|
500 |
|
59
|
501 |
if ( mMpPlaybackData ) {
|
|
502 |
artist = mMpPlaybackData->artist();
|
|
503 |
title = mMpPlaybackData->title();
|
|
504 |
}
|
36
|
505 |
|
59
|
506 |
if ( !title.length() ) {
|
|
507 |
artist.clear();
|
|
508 |
title.clear();
|
|
509 |
// Initialize marquee with something (space), to ensure text updates to display as well.
|
|
510 |
songData = " ";
|
|
511 |
TX_LOG_ARGS( "no song data" )
|
|
512 |
}
|
|
513 |
else {
|
|
514 |
if ( !artist.length() ) {
|
|
515 |
//Show localized "Unknown" if there is no artist name
|
|
516 |
songData.append( hbTrId( "txt_muwidget_other_unknown_1" ).arg( title ) );
|
|
517 |
}
|
|
518 |
else {
|
|
519 |
songData.append( artist );
|
|
520 |
songData.append( SEPARATOR_TEXT );
|
|
521 |
songData.append( title );
|
|
522 |
}
|
|
523 |
TX_LOG_ARGS( "song data received" )
|
|
524 |
}
|
|
525 |
|
|
526 |
mMarqueeText->setText( songData );
|
|
527 |
TX_LOG_ARGS( "marquee text: " << songData )
|
|
528 |
|
|
529 |
// Display song data if it exist.
|
|
530 |
if ( title.length() ) {
|
|
531 |
if ( !mSongDataBackground->isVisible() ) {
|
|
532 |
mSongDataBackground->show();
|
|
533 |
}
|
|
534 |
if ( !mMarqueeText->isAnimating() ) {
|
36
|
535 |
mMarqueeText->startAnimation();
|
59
|
536 |
}
|
|
537 |
}
|
|
538 |
else {
|
|
539 |
if ( mSongDataBackground->isVisible() ) {
|
|
540 |
mSongDataBackground->hide();
|
|
541 |
}
|
|
542 |
if ( mMarqueeText->isAnimating() ) {
|
36
|
543 |
mMarqueeText->stopAnimation();
|
|
544 |
}
|
59
|
545 |
}
|
36
|
546 |
|
|
547 |
TX_EXIT
|
|
548 |
}
|
|
549 |
|
|
550 |
/*!
|
59
|
551 |
Update buttons to disabled/enabled as required.
|
36
|
552 |
*/
|
59
|
553 |
void MusicWidget::updateButtons()
|
36
|
554 |
{
|
|
555 |
TX_ENTRY
|
|
556 |
|
59
|
557 |
// All buttons disabled if updating or usb blocked
|
|
558 |
if ( mMusicPlayerUpdating || mMusicPlayerBlocked ) {
|
|
559 |
TX_LOG_ARGS( "refreshing" )
|
|
560 |
mPreviousPushButton->setEnabled( false );
|
|
561 |
mPlayPushButton->setEnabled( false );
|
|
562 |
mNextPushButton->setEnabled( false );
|
|
563 |
}
|
|
564 |
// Only play button enabled if there is no song data
|
|
565 |
else if ( getPlaybackState() == MpPlaybackData::NotPlaying ) {
|
|
566 |
TX_LOG_ARGS( "no song data" )
|
|
567 |
mPreviousPushButton->setEnabled( false );
|
|
568 |
mPlayPushButton->setEnabled( true );
|
|
569 |
mNextPushButton->setEnabled( false );
|
|
570 |
}
|
|
571 |
// Enable all buttons if there is song data
|
|
572 |
else {
|
|
573 |
TX_LOG_ARGS( "enable all buttons" )
|
|
574 |
mPreviousPushButton->setEnabled( true );
|
|
575 |
mPlayPushButton->setEnabled( true );
|
|
576 |
mNextPushButton->setEnabled( true );
|
|
577 |
}
|
36
|
578 |
|
|
579 |
TX_EXIT
|
|
580 |
}
|
|
581 |
|
|
582 |
/*!
|
59
|
583 |
Connect/disconnect Music Player engine and playback data
|
36
|
584 |
*/
|
59
|
585 |
void MusicWidget::connectMusicPlayerEngine( bool connect )
|
|
586 |
{
|
36
|
587 |
TX_ENTRY
|
59
|
588 |
|
|
589 |
if ( mMpEngine ) {
|
|
590 |
MpEngineFactory::close();
|
|
591 |
mMpEngine = 0;
|
|
592 |
mMpPlaybackData = 0;
|
|
593 |
mMusicPlayerUpdating = false;
|
|
594 |
mMusicPlayerBlocked = false;
|
|
595 |
}
|
36
|
596 |
|
59
|
597 |
if ( connect ) {
|
|
598 |
// Connect to MP engine and playback data
|
|
599 |
mMpEngine = MpEngineFactory::createSharedEngine( MpCommon::KMusicPlayerUid, MpEngine::HomeScreen );
|
|
600 |
Q_ASSERT_X( mMpEngine, "music_widget", "no music player engine" );
|
|
601 |
TX_LOG_ARGS( "got mp engine" )
|
|
602 |
|
|
603 |
mMpPlaybackData = mMpEngine->playbackData();
|
|
604 |
Q_ASSERT_X( mMpPlaybackData, "music_widget", "no playback data" );
|
|
605 |
TX_LOG_ARGS( "got playback data" )
|
36
|
606 |
|
59
|
607 |
// MpEngine
|
|
608 |
QObject::connect( mMpEngine, SIGNAL( libraryUpdateStarted() ), this, SLOT( libraryUpdateStarted() ) );
|
|
609 |
QObject::connect( mMpEngine, SIGNAL( libraryUpdated() ), this, SLOT( libraryUpdated() ) );
|
|
610 |
QObject::connect( mMpEngine, SIGNAL( usbBlocked( bool ) ), this, SLOT( usbBlocked( bool ) ) );
|
|
611 |
|
|
612 |
//MpPlaybackData
|
|
613 |
QObject::connect( mMpPlaybackData, SIGNAL( albumArtReady() ), this, SLOT( albumArtReady() ) );
|
|
614 |
QObject::connect( mMpPlaybackData, SIGNAL( playbackStateChanged() ), this, SLOT( playbackStateChanged() ) );
|
|
615 |
QObject::connect( mMpPlaybackData, SIGNAL( playbackInfoChanged() ), this, SLOT( playbackInfoChanged() ) );
|
|
616 |
}
|
36
|
617 |
|
|
618 |
TX_EXIT
|
|
619 |
}
|
59
|
620 |
|
|
621 |
/*!
|
|
622 |
Get the playback state
|
|
623 |
*/
|
|
624 |
int MusicWidget::getPlaybackState()
|
|
625 |
{
|
|
626 |
TX_ENTRY
|
|
627 |
int state;
|
|
628 |
if ( mMpPlaybackData ) {
|
|
629 |
state = mMpPlaybackData->playbackState();
|
|
630 |
}
|
|
631 |
else {
|
|
632 |
state = MpPlaybackData::NotPlaying;
|
|
633 |
}
|
|
634 |
TX_EXIT_ARGS( "playback state = " << state );
|
|
635 |
return state;
|
|
636 |
}
|
|
637 |
|
|
638 |
/*!
|
|
639 |
Clear the song data
|
|
640 |
*/
|
|
641 |
void MusicWidget::clearData()
|
|
642 |
{
|
|
643 |
TX_ENTRY
|
|
644 |
// set play button to PLAY icon.
|
|
645 |
mPlayPushButton->setIcon( HbIcon( ICON_PLAY ) );
|
|
646 |
updateButtons();
|
|
647 |
|
|
648 |
// remove song data.
|
|
649 |
mMarqueeText->setText( QString( " " ) );
|
|
650 |
mMarqueeText->stopAnimation();
|
|
651 |
mSongDataBackground->hide();
|
|
652 |
|
|
653 |
// set default album art
|
|
654 |
mAlbumArt->setIcon( HbIcon( ICON_DEFAULT_ART ) );
|
|
655 |
mAlbumArt->setEnabled( true );
|
|
656 |
TX_EXIT
|
|
657 |
}
|