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