musicwidgetplugin/src/musicwidget.cpp
changeset 61 3cd404d31176
parent 58 ed94e1e8390e
equal deleted inserted replaced
58:ed94e1e8390e 61:3cd404d31176
    13 *
    13 *
    14 * Description:  Music player home screen widget
    14 * Description:  Music player home screen widget
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "musicwidget.h"
    18 // System includes
    19 
    19 #include <qgraphicslinearlayout.h>
    20 #include <QtGui>
       
    21 #include <hbpushbutton.h>
    20 #include <hbpushbutton.h>
    22 #include <hblabel.h>
    21 #include <hblabel.h>
    23 #include <hbicon.h>
    22 #include <hbicon.h>
    24 #include <hbmarqueeitem.h>
    23 #include <hbmarqueeitem.h>
    25 #include <hbanchorlayout.h>
    24 #include <hbanchorlayout.h>
    26 #include <hbwidget.h>
    25 #include <hbwidget.h>
    27 #include <hbframeitem.h>
    26 #include <hbframeitem.h>
    28 #include <hbframedrawer.h>
    27 #include <hbframedrawer.h>
    29 #include <hbcolorscheme.h>
    28 #include <hbtranslator.h>
    30 
    29 
       
    30 // User includes
       
    31 #include "musicwidget.h"
    31 #include "musicwidgetdocumentloader.h"
    32 #include "musicwidgetdocumentloader.h"
    32 #include "mptrace.h"
    33 #include "mptrace.h"
    33 #include "mpenginefactory.h"
    34 #include "mpenginefactory.h"
    34 #include "mpalbumcoverwidget.h"
    35 #include "mpalbumcoverwidget.h"
       
    36 #include "mpplaybackdata.h"
       
    37 #include "mpapplicationmonitor.h"
    35 
    38 
    36 // Constants
    39 // Constants
    37 /** Docml */
    40 /** Docml */
    38 const QString MUSIC_WIDGET_DOCML = ":/gfx/music_widget.docml";
    41 const QString MUSIC_WIDGET_DOCML = ":/docml/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 
    42 
    55 /**  Play and Pause icons */
    43 /**  Play and Pause icons */
    56 const QLatin1String ICON_PLAY ("qtg_mono_play");
    44 const QLatin1String ICON_PLAY ( "qtg_mono_play" );
    57 const QLatin1String ICON_PAUSE ("qtg_mono_pause");
    45 const QLatin1String ICON_PAUSE ( "qtg_mono_pause" );
    58 /**  Music Player shortcut icon */
    46 
    59 const QLatin1String ICON_LARGE_MUSIC_PLAYER ("qtg_large_music");
    47 /** Album art icon */
    60 /**  Music Player shortcut icon */
    48 const QLatin1String ICON_DEFAULT_ART ( "qtg_large_music_empty" );
    61 const QLatin1String ICON_FIRST_TIME_USE ("qtg_large_music_empty");
       
    62 const QLatin1String ICON_DEFAULT_ART ("qtg_large_album_art");
       
    63 
    49 
    64 /**  HsWidget normal background */
    50 /**  HsWidget normal background */
    65 const QLatin1String WIDGET_BG_NORMAL ("qtg_fr_hswidget_normal");
    51 const QLatin1String WIDGET_BG_NORMAL ( "qtg_fr_hswidget_normal" );
    66 /**  Text background */
    52 /**  Text background */
    67 const QLatin1String TEXT_BG_NORMAL ("qtg_fr_multimedia_trans");
    53 const QLatin1String TEXT_BG_NORMAL ( "qtg_fr_multimedia_trans" );
    68 /**  Separator : character and space between artist and song name */
    54 /**  Separator : character and space between artist and song name */
    69 const QLatin1String SEPARATOR_TEXT (": ");
    55 const QLatin1String SEPARATOR_TEXT ( ": " );
    70 /**  Temporary unknown artist */
    56 
    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 */
    57 /**  Infinite loop value for marquee */
    78 const int MARQUEE_LOOP_FOREVER = -1;
    58 const int MARQUEE_LOOP_FOREVER = -1;
    79 
    59 
    80 /**  Now playing view with random play */
    60 /**  Now playing view with random play */
    81 const QLatin1String SERVICEREQ_FIRST_TIME_USE ("appto://10207C62?activityname=MusicNowPlayingView&launchtype=standalone&shuffle=yes");
    61 const QLatin1String SERVICEREQ_NOW_PLAYING_VIEW_SHUFFLE ( "appto://10207C62?activityname=MusicNowPlayingView&launchtype=standalone&shuffle=yes" );
    82 /**  Main view */
    62 /**  Main view */
    83 const QLatin1String SERVICEREQ_MAIN_VIEW ("appto://10207C62?activityname=MusicMainView&launchtype=standalone");
    63 const QLatin1String SERVICEREQ_MAIN_VIEW ( "appto://10207C62?activityname=MusicMainView&launchtype=standalone" );
    84 /**  Now playing view */
    64 /**  Now playing view */
    85 const QLatin1String SERVICEREQ_NOW_PLAYING_VIEW ("appto://10207C62?activityname=MusicNowPlayingView&launchtype=standalone");
    65 const QLatin1String SERVICEREQ_NOW_PLAYING_VIEW ( "appto://10207C62?activityname=MusicNowPlayingView&launchtype=standalone" );
    86 
    66 
    87 /**  DOCML object name for main widget */
    67 /**  DOCML object names */
    88 const QLatin1String DOCML_CONTAINER_WIDGET ("containerWidget");
    68 const QLatin1String DOCML_CONTAINER_WIDGET ( "containerWidget" );
    89 /**  DOCML object name for widget background */
    69 const QLatin1String DOCML_BG_ICON ( "widget_background_icon" );
    90 const QLatin1String DOCML_BG_ICON ("widget_background_icon");
    70 const QLatin1String DOCML_ALBUM_ART ( "album_art_image" );
    91 /**  DOCML object name for album art image */
    71 const QLatin1String DOCML_TEXT_BG ( "text_bg" );
    92 const QLatin1String DOCML_ALBUM_ART ("album_art_image");
    72 const QLatin1String DOCML_SCROLLING_TEXT ( "scrolling_text" );
    93 /**  DOCML object name for shortcut icon background */
    73 const QLatin1String DOCML_BUTTON_GROUP_CONTAINER ( "button_group_container" );
    94 const QLatin1String DOCML_SHORTCUT_ICON_BG ("shortcut_icon_background");
    74 const QLatin1String DOCML_PREV_BUTTON ( "btn_previous" );
    95 /**  DOCML object name for shortcut icon */
    75 const QLatin1String DOCML_PLAY_BUTTON ( "btn_play" );
    96 const QLatin1String DOCML_SHORTCUT_ICON ("shortcut_icon");
    76 const QLatin1String DOCML_NEXT_BUTTON ( "btn_next" );
    97 /**  DOCML object name for scrolling text background */
    77 
    98 const QLatin1String DOCML_TEXT_BG ("text_bg");
    78 /*!
    99 /**  DOCML object name for scrolling text */
    79     \class MusicWidget
   100 const QLatin1String DOCML_SCROLLING_TEXT ("scrolling_text");
    80     \brief Provides simple Music Player playback controls from the Home Screen.
   101 /**  DOCML object name for button group container */
    81  */
   102 const QLatin1String DOCML_BUTTON_GROUP_CONTAINER ("button_group_container");
    82 
   103 /**  DOCML object name for prev button */
    83 /*!
   104 const QLatin1String DOCML_PREV_BUTTON ("btn_previous");
    84  Constructs the Music Player home screen widget.
   105 /**  DOCML object name for play button */
    85  */
   106 const QLatin1String DOCML_PLAY_BUTTON ("btn_play");
    86 MusicWidget::MusicWidget( QGraphicsItem* parent, Qt::WindowFlags flags ):
   107 /**  DOCML object name for next button */
    87     HbWidget( parent, flags ),
   108 const QLatin1String DOCML_NEXT_BUTTON ("btn_next");
    88     mSongDataBackground( 0 ),
   109 
    89     mMarqueeText( 0 ),    
   110 
    90     mPreviousPushButton( 0 ),
   111 MusicWidget::MusicWidget(QGraphicsItem* parent, Qt::WindowFlags flags):
    91     mPlayPushButton( 0 ),    
   112     HbWidget(parent, flags),
    92     mNextPushButton( 0 ),
   113     mShortcutArea(0),
    93     mMusicPlayerUpdating( false ),
   114     mSongDataBG(0),
    94     mMusicPlayerBlocked( false ),
   115     mInformationSongName(0),
    95     mMusicPlayerRunning( false ),
   116     mMarqueeText(0),    
    96     mAlbumArt( 0 ),
   117     mPreviousPushButton(0),
    97     mMpEngine( 0 ),
   118     mPlayPushButton(0),    
    98     mMpPlaybackData( 0 ),
   119     mNextPushButton(0),
    99     mMpApplicationMonitor( 0 )
   120     mMusicPlayerNoSongData(1),
   100 {
   121     mMusicPlayerUpdating(0),
   101     TX_LOG
   122     mMusicPlayerBlocked(0),
   102     HbTranslator translator( QString( "musicwidgetplugin" ) );
   123     mAlbumArt(0),
   103 }
   124     mArtist(0),
   104 
   125     mTitle(0),    
   105 /*!
   126     mMpEngine(0),
   106  Destructor
   127     mMpPlaybackData(0)
   107  */
   128 {
       
   129     TX_ENTRY
       
   130     
       
   131     // Setup UI
       
   132     setupUi();
       
   133     
       
   134     // Connect to MP engine and playback data
       
   135     mMpEngine = MpEngineFactory::createSharedEngine(MpCommon::KMusicPlayerUid, MpEngine::HomeScreen );
       
   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(libraryUpdateStarted()), this, SLOT(libraryUpdateStarted()));
       
   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()
   108 MusicWidget::~MusicWidget()
   196 {
   109 {
       
   110     TX_ENTRY
       
   111     if ( mMpEngine ) {
       
   112         MpEngineFactory::close();
       
   113     }
       
   114 
       
   115     delete mMpApplicationMonitor;
       
   116     TX_EXIT
   197 }
   117 }
   198 
   118 
   199 /*!
   119 /*!
   200  Creates UI.
   120  Creates UI.
   201  */
   121  */
   204     TX_ENTRY
   124     TX_ENTRY
   205     
   125     
   206     // Use document loader to load the contents
   126     // Use document loader to load the contents
   207     MusicWidgetDocumentLoader loader;
   127     MusicWidgetDocumentLoader loader;
   208     bool ok = false;
   128     bool ok = false;
   209     loader.load( MUSIC_WIDGET_DOCML, &ok);
   129     loader.load( MUSIC_WIDGET_DOCML, &ok );
   210     Q_ASSERT_X(ok, "music_widget", "invalid title docml file");
   130     Q_ASSERT_X( ok, "music_widget", "invalid title docml file" );
   211 
   131 
   212     TX_LOG_ARGS("loaded docml")
   132     TX_LOG_ARGS( "loaded docml" )
   213     
   133     
   214     QGraphicsLinearLayout* mainLayout = new QGraphicsLinearLayout(Qt::Vertical, this);
   134     QGraphicsLinearLayout* mainLayout = new QGraphicsLinearLayout( Qt::Vertical, this );
   215     QGraphicsWidget* container = loader.findWidget(DOCML_CONTAINER_WIDGET);
   135     QGraphicsWidget* container = loader.findWidget( DOCML_CONTAINER_WIDGET );
   216     mainLayout->addItem(container);
   136     mainLayout->addItem( container );
       
   137     
   217     //Sets parent
   138     //Sets parent
   218     setLayout( mainLayout );
   139     setLayout( mainLayout );
   219 
   140 
   220     // Load and set widget background
   141     // Load and set widget background
   221     HbWidget *bgWidget = qobject_cast<HbWidget*> (loader.findWidget(DOCML_BG_ICON));
   142     HbLabel *bgWidget = qobject_cast<HbLabel*> ( loader.findWidget( DOCML_BG_ICON ) );
   222     HbFrameItem *frameItem;
   143     HbFrameItem *frameItemWidgetBg = new HbFrameItem();
   223     if (bgWidget)
   144     frameItemWidgetBg->frameDrawer().setFrameGraphicsName( WIDGET_BG_NORMAL );
   224         {
   145     frameItemWidgetBg->frameDrawer().setFrameType( HbFrameDrawer::NinePieces );
   225         HbFrameDrawer *drawer = new HbFrameDrawer(WIDGET_BG_NORMAL,
   146     frameItemWidgetBg->frameDrawer().setFillWholeRect( true );
   226             HbFrameDrawer::NinePieces);
   147     bgWidget->setBackgroundItem( frameItemWidgetBg );
   227         frameItem = new HbFrameItem(drawer, bgWidget);
       
   228         frameItem->setPreferredSize(bgWidget->preferredSize());
       
   229         bgWidget->setZValue(1);
       
   230         }
       
   231 
   148 
   232     // Setup album art area
   149     // Setup album art area
   233     QGraphicsWidget *tmpWidgetPtr;
   150     QGraphicsWidget *tmpWidgetPtr;
   234     tmpWidgetPtr = loader.findWidget(DOCML_ALBUM_ART);
   151     tmpWidgetPtr = loader.findWidget( DOCML_ALBUM_ART );
   235     mAlbumArt = qobject_cast<MpAlbumCoverWidget*>(tmpWidgetPtr);
   152     mAlbumArt = qobject_cast<MpAlbumCoverWidget*>( tmpWidgetPtr );
   236     mAlbumArt->setEnabled( false );
   153     mAlbumArt->setEnabled( false );
   237     mAlbumArt->setDefaultIcon( HbIcon( ICON_DEFAULT_ART ) );
   154     mAlbumArt->setDefaultIcon( HbIcon( ICON_DEFAULT_ART ) );
   238         
   155         
   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
   156     // Set song data background
   260     mSongDataBG = qobject_cast<HbWidget*> (loader.findWidget(DOCML_TEXT_BG));
   157     mSongDataBackground = qobject_cast<HbLabel*> ( loader.findWidget( DOCML_TEXT_BG ) );
   261     HbFrameItem *scrollTextItem;
   158     HbFrameItem *frameItemSongBg = new HbFrameItem();
   262     if (mSongDataBG) 
   159     frameItemSongBg->frameDrawer().setFrameGraphicsName( TEXT_BG_NORMAL );
   263         {
   160     frameItemSongBg->frameDrawer().setFrameType( HbFrameDrawer::NinePieces );
   264         HbFrameDrawer *drawer = new HbFrameDrawer(TEXT_BG_NORMAL, 
   161     frameItemSongBg->frameDrawer().setFillWholeRect( true );
   265             HbFrameDrawer::NinePieces);
   162     mSongDataBackground->setBackgroundItem( frameItemSongBg );
   266         scrollTextItem = new HbFrameItem(drawer, mSongDataBG);
   163     mSongDataBackground->hide();
   267         scrollTextItem->setPreferredSize(mSongDataBG->preferredSize());
       
   268         mSongDataBG->setZValue(4);
       
   269         mSongDataBG->hide(); // Hide initially...
       
   270         }
       
   271 
   164 
   272     // Set scrolling song data
   165     // Set scrolling song data
   273     mInformationSongName = qobject_cast<HbLabel*> (loader.findWidget(DOCML_SCROLLING_TEXT));
   166     mMarqueeText = qobject_cast<HbMarqueeItem*> ( loader.findWidget( DOCML_SCROLLING_TEXT ) );
   274     if ( mInformationSongName )
   167     mMarqueeText->setLoopCount( MARQUEE_LOOP_FOREVER );
   275         {
   168 
   276         // Setting primitive marquee item values from .css doesn't work well, set in code...
   169     // Get buttons
   277         mMarqueeText = new HbMarqueeItem(mInformationSongName);
   170     HbWidget *buttonGroupContainer = qobject_cast<HbWidget*> ( loader.findWidget(
   278         HbFontSpec fs(HbFontSpec::Secondary);
   171             DOCML_BUTTON_GROUP_CONTAINER ) );
   279         mMarqueeText->setFontSpec(fs);        
   172     if ( buttonGroupContainer ) {
   280         mMarqueeText->setTextColor(mInformationSongName->textColor());
   173         // Define push buttons
   281         mMarqueeText->setMinimumWidth(MARQUEE_WIDTH);
   174         mPreviousPushButton = qobject_cast<HbPushButton*> ( loader.findWidget( DOCML_PREV_BUTTON ) );
   282         mMarqueeText->setLoopCount(MARQUEE_LOOP_FOREVER);
   175         mPlayPushButton = qobject_cast<HbPushButton*> ( loader.findWidget( DOCML_PLAY_BUTTON ) );
   283         }
   176         mNextPushButton = qobject_cast<HbPushButton*> ( loader.findWidget( DOCML_NEXT_BUTTON ) );
   284     
   177     }
   285     HbWidget *buttonGroupContainer = qobject_cast<HbWidget*> (loader.findWidget(
   178 
   286             DOCML_BUTTON_GROUP_CONTAINER));
   179     TX_EXIT
   287     if (buttonGroupContainer)
   180 }
   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 
   181 
   432 /*!
   182 /*!
   433  Manually update music widget state.
   183  Manually update music widget state.
   434  */
   184  */
   435 void MusicWidget::refreshData()
   185 void MusicWidget::refreshData()
   436 { 
   186 { 
   437     TX_ENTRY
   187     TX_ENTRY
       
   188     
   438     // Get current player state
   189     // Get current player state
   439     playbackStateChanged();
   190     playbackStateChanged();
   440     
   191     
   441     // Get current song data, updates button states
   192     // Get current song data, updates button states
   442     playbackInfoChanged();
   193     playbackInfoChanged();
   443 
   194 
   444     // Get current album art
   195     // Get current album art
   445     albumArtReady();
   196     albumArtReady();
   446     TX_EXIT
   197     
   447 }
   198     TX_EXIT
   448 
   199 }
   449 /*!
   200 
   450  Launch music player...
   201 /*!
   451  */
   202  Launch music player.
   452 void MusicWidget::launchMusicPlayer(int launchMode)
   203  */
       
   204 void MusicWidget::launchMusicPlayer( int launchMode )
   453 {  
   205 {  
   454     TX_ENTRY
   206     TX_ENTRY
   455     //TODO: Detect if MusicPlayer is running or not properly, handle case where player not available?!
   207     
   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;
   208     QUrl url;
       
   209     
       
   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     }
       
   231     
   461     XQAiwRequest* req;
   232     XQAiwRequest* req;
   462     
   233     req = mApplicationManager.create( url );    
   463     if ( launchMode == ELaunchFromPlay )
   234     if ( req ) {
   464         {
   235         req->setBackground( false );
   465         TX_LOG_ARGS("launch from play")
   236         req->setSynchronous( false );
   466         // Launch to now playing view, random play to be started!
   237     
   467         url.setUrl(SERVICEREQ_FIRST_TIME_USE);        
   238         // Set function parameters
   468         }
   239         QList<QVariant> args;
   469     else if (mMusicPlayerNoSongData)
   240         args << url.toString();
   470         {
   241         req->setArguments( args );
   471         TX_LOG_ARGS("to main view")
   242 
   472         // Launch to main view
   243         // Send the request
   473         url.setUrl(SERVICEREQ_MAIN_VIEW);    
   244         bool res = req->send();
   474         }
   245         if ( !res ) {
   475     else
   246             // Request failed. 
   476         {
   247             int error = req->lastError();
   477         TX_LOG_ARGS("to now playing view")
   248             // Handle error
   478         // Launch to now playing view
   249             TX_LOG_ARGS( "req send error: " << error )
   479         url.setUrl(SERVICEREQ_NOW_PLAYING_VIEW);
   250         }
   480         }   
   251         delete req;
   481     
   252     }
   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    
   253    
   510    TX_EXIT
   254     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 }
   255 }
   530 
   256 
   531 /*!
   257 /*!
   532  Initializes the widget.
   258  Initializes the widget.
   533  */
   259  */
   534 void MusicWidget::onInitialize()
   260 void MusicWidget::onInitialize()
   535 {
   261 {
       
   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
       
   289 }
       
   290 
       
   291 /*!
       
   292  Shows the widget.
       
   293  */
       
   294 void MusicWidget::onShow()
       
   295 {
       
   296     TX_ENTRY
       
   297     refreshData();
       
   298     TX_EXIT
       
   299 }
       
   300 
       
   301 /*!
       
   302  Hides the widget.
       
   303  */
       
   304 void MusicWidget::onHide()
       
   305 {
   536     TX_LOG
   306     TX_LOG
   537 }
   307     if ( mMarqueeText->isAnimating() ) {
   538 
   308         mMarqueeText->stopAnimation();
   539 /*!
   309     }
   540  Shows the widget.
   310 }
   541  */
   311 
   542 void MusicWidget::onShow()
   312 /*!
       
   313  Uninitializes the widget.
       
   314  */
       
   315 void MusicWidget::onUninitialize()
   543 {
   316 {
   544     TX_LOG
   317     TX_LOG
   545     refreshData();
   318 }
   546 }
   319 
   547 
   320 /*!
   548 /*!
   321  Slot to handle when the album art area is clicked.
   549  Hides the widget.
   322  */
   550  */
   323 void MusicWidget::handleAlbumArtClicked()
   551 void MusicWidget::onHide()
   324 {
   552 {
   325     TX_ENTRY
   553     TX_LOG
   326     if ( getPlaybackState() == MpPlaybackData::NotPlaying ) {
   554 }
   327         launchMusicPlayer( ELaunchToMainView );
   555 
   328     }
   556 /*!
   329     else {
   557  Uninitializes the widget.
   330         launchMusicPlayer( ELaunchToNowPlayingView );
   558  */
   331     }
   559 void MusicWidget::onUninitialize()
   332     TX_EXIT
   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 }
   333 }
   572 
   334 
   573 /*!
   335 /*!
   574  Slot for previous button clicked.
   336  Slot for previous button clicked.
   575  */
   337  */
   576 void MusicWidget::prevSong()
   338 void MusicWidget::handlePrevButtonClicked()
   577 { 
   339 { 
   578     TX_LOG
   340     TX_ENTRY
   579     mMpEngine->skipBackward();
   341     if ( mMpEngine ) {
       
   342         mMpEngine->skipBackward();
       
   343     }
       
   344     TX_EXIT
   580 }
   345 }
   581 
   346 
   582 /*!
   347 /*!
   583  Slot for play button clicked. Handles both Play and Pause!
   348  Slot for play button clicked. Handles both Play and Pause!
   584  */
   349  */
   585 void MusicWidget::playSong()
   350 void MusicWidget::handlePlayButtonClicked()
   586 {
   351 {
   587     TX_ENTRY
   352     TX_ENTRY
   588     if (mMusicPlayerNoSongData && mMpPlaybackData->playbackState() != MpPlaybackData::Playing )
   353     // If nothing to play, start music player in playback view.
   589         {
   354     if ( getPlaybackState() == MpPlaybackData::NotPlaying ) {
   590         //Signal music player to start playing all songs with random
   355         //Signal music player to start playing all songs with random
   591         launchMusicPlayer(ELaunchFromPlay);
   356         launchMusicPlayer( ELaunchToNowPlayingViewWithShuffle );
   592         }
   357     }
   593 
   358     else {
   594     mMpEngine->playPause();
   359         // send play/pause command.
   595     TX_EXIT
   360         if ( mMpEngine ) {
   596 }
   361             mMpEngine->playPause();
       
   362         }
       
   363     }
       
   364     TX_EXIT
       
   365 }
       
   366 
   597 /*!
   367 /*!
   598  Slot for next button clicked.
   368  Slot for next button clicked.
   599  */
   369  */
   600 void MusicWidget::nextSong()
   370 void MusicWidget::handleNextButtonClicked()
   601 {
   371 {
   602     TX_LOG
   372     TX_ENTRY
   603     mMpEngine->skipForward();
   373     if ( mMpEngine ) {
   604 }
   374         mMpEngine->skipForward();
   605 
   375     }
   606 /*!
   376     TX_EXIT
   607 
   377 }
   608  */
   378 
   609 bool MusicWidget::eventFilter(QObject *target, QEvent *event)
   379 /*!
   610  {
   380  Slot to handle when the music player running status changed.
   611     // pass the event on to the parent class
   381  */
   612     return HbWidget::eventFilter(target, event);    
   382 void MusicWidget::applicationStatusChanged( bool isRunning )
   613 }
   383 {
   614 
   384     TX_ENTRY_ARGS( "running " << isRunning );
   615 /*!
   385 
   616  MpEngine related
   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
       
   401 }
       
   402 
       
   403 /*!
       
   404  Library started refreshing.
   617  */
   405  */
   618 void MusicWidget::libraryUpdateStarted()
   406 void MusicWidget::libraryUpdateStarted()
   619 {
   407 {
   620     TX_LOG
   408     TX_ENTRY
   621     //Refresh Library start
   409     //Refresh Library start
   622     mMusicPlayerUpdating = true;
   410     mMusicPlayerUpdating = true;
   623     
   411     
   624     // Update button enabled/disabled state
   412     // Update button enabled/disabled state
   625     toggleButtons();
   413     updateButtons();
   626 }
   414     TX_EXIT
   627 
   415 }
   628 /*!
   416 
   629  MpEngine related
   417 /*!
       
   418  Library is finished refreshing.
   630  */
   419  */
   631 void MusicWidget::libraryUpdated()
   420 void MusicWidget::libraryUpdated()
   632 {
   421 {
   633     TX_LOG
   422     TX_ENTRY
   634     //Refresh Library done
   423     //Refresh Library done
   635     mMusicPlayerUpdating = false;
   424     mMusicPlayerUpdating = false;
   636     
   425     
   637     // Update button enabled/disabled state
   426     // Update button enabled/disabled state
   638     toggleButtons();
   427     updateButtons();
   639 }
   428     TX_EXIT
   640 
   429 }
   641 /*!
   430 
   642  MpEngine related
   431 /*!
       
   432  USB blocking state has changed.
   643  */
   433  */
   644 void MusicWidget::usbBlocked( bool blocked )
   434 void MusicWidget::usbBlocked( bool blocked )
   645 {
   435 {
   646     TX_LOG_ARGS("blocked: " << blocked)
   436     TX_ENTRY_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;
   437     mMusicPlayerBlocked = blocked;
   654     
   438     
   655     // Update button enabled/disabled state
   439     // Update button enabled/disabled state
   656     toggleButtons();
   440     updateButtons();
   657 }
   441     TX_EXIT
   658 
   442 }
   659 /*!
   443 
   660  MpPlaybackData related
   444 /*!
       
   445  The album art has changed.
   661  */
   446  */
   662 void MusicWidget::albumArtReady()
   447 void MusicWidget::albumArtReady()
   663 {   
   448 {   
   664     TX_ENTRY
   449     TX_ENTRY
   665     HbIcon icon;
   450     HbIcon icon;
   666     
   451     
   667     if ( mMpPlaybackData->playbackState() == MpPlaybackData::NotPlaying )
   452     if ( getPlaybackState() == MpPlaybackData::NotPlaying ) {
   668         {
   453         TX_LOG_ARGS( "default album art" )
   669         TX_LOG_ARGS("1st time album art")
   454         icon = HbIcon( ICON_DEFAULT_ART );    
   670         icon = HbIcon(ICON_FIRST_TIME_USE);    
   455     }
   671         }
   456     else {
   672     else
   457         TX_LOG_ARGS( "playback data album art" )
   673         {
   458         if ( mMpPlaybackData ) {
   674         TX_LOG_ARGS("playback data album art")
   459             mMpPlaybackData->albumArt( icon );
   675         mMpPlaybackData->albumArt( icon );
   460         }
   676         }
   461     }
   677     
   462     
   678     mAlbumArt->setIcon( icon );
   463     mAlbumArt->setIcon( icon );
   679     mAlbumArt->setEnabled( true );
   464     mAlbumArt->setEnabled( true );
   680     
   465     TX_EXIT
   681     TX_EXIT
   466 }
   682 }
   467 
   683 
   468 /*!
       
   469  Playback state has changed.
       
   470  */
   684 void MusicWidget::playbackStateChanged()
   471 void MusicWidget::playbackStateChanged()
   685 {
   472 {
   686     TX_ENTRY
   473     TX_ENTRY
   687     // Set play/pause icon and start/stop marquee.   
   474     
   688     QString iconName;
   475     if ( getPlaybackState() == MpPlaybackData::Playing ) {
   689     
   476         TX_LOG_ARGS( "pause icon" )
   690     int state = mMpPlaybackData->playbackState();
   477         mPlayPushButton->setIcon( HbIcon( ICON_PAUSE ) );
   691     
   478     }
   692     TX_LOG_ARGS("state: " << state)
   479     else {
   693     
   480         TX_LOG_ARGS( "play icon" )
   694     switch (state)
   481         mPlayPushButton->setIcon( HbIcon( ICON_PLAY ) );
   695         {
   482     }
   696         case MpPlaybackData::Playing:
   483 
   697             {
   484     // Update button enabled/disabled state
   698             TX_LOG_ARGS("pause icon, start marquee")
   485     updateButtons();
   699             iconName.append(ICON_PAUSE);
   486     
   700             mMarqueeText->startAnimation();
   487     TX_EXIT
   701             break;
   488 }
   702             }
   489 
   703         case MpPlaybackData::Paused:
   490 /*!
   704         case MpPlaybackData::Stopped:
   491  Song data has changed.
   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  */
   492  */
   723 void MusicWidget::playbackInfoChanged()
   493 void MusicWidget::playbackInfoChanged()
   724 { 
   494 { 
   725     TX_ENTRY
   495     TX_ENTRY
   726     // Initialize maqruee with something (space), to ensure
   496     
   727     // text updates to display as well.
       
   728     QString songData;
   497     QString songData;
   729     
   498     QString artist;
   730     mArtist = mMpPlaybackData->artist();
   499     QString title;
   731     mTitle = mMpPlaybackData->title();
   500     
   732     
   501     if ( mMpPlaybackData ) {
   733     if ( !mTitle.length() )
   502         artist = mMpPlaybackData->artist();
   734         {
   503         title = mMpPlaybackData->title();
   735         mArtist.clear();
   504     }
   736         mTitle.clear();
   505     
       
   506     if ( !title.length() ) {
       
   507         artist.clear();
       
   508         title.clear();
       
   509         // Initialize marquee with something (space), to ensure text updates to display as well.
   737         songData = " ";
   510         songData = " ";
   738 
   511         TX_LOG_ARGS( "no song data" )
   739         //1st time launch
   512     }
   740         mMusicPlayerNoSongData = true;
   513     else {
   741         
   514         if ( !artist.length() ) {
   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
   515             //Show localized "Unknown" if there is no artist name
   749             
   516             songData.append( hbTrId( "txt_muwidget_other_unknown_1" ).arg( title ) );
   750             //TODO: Widget needs own localization?!?!
   517         }
   751             //mArtist.append( hbTrId(UNKWNOWN_TEXT) );
   518         else {
   752 
   519             songData.append( artist );
   753             //TODO: Remove temporary unknown string when localization resolved.
   520             songData.append( SEPARATOR_TEXT );
   754             mArtist.append( TEMPORARY_UNKWNOWN_TEXT );
   521             songData.append( title );
   755             }
   522         }
   756         
   523         TX_LOG_ARGS( "song data received" )
   757         songData.append(mArtist);
   524     }    
   758         songData.append(SEPARATOR_TEXT);
   525     
   759         songData.append(mTitle);
   526     mMarqueeText->setText( songData );
   760         
   527     TX_LOG_ARGS( "marquee text: " << songData )
   761         mMusicPlayerNoSongData = false;
   528 
   762         
   529     // Display song data if it exist.
   763         TX_LOG_ARGS("song data received")
   530     if ( title.length() ) {
   764         }    
   531         if ( !mSongDataBackground->isVisible() ) {
   765     
   532             mSongDataBackground->show();
   766     mMarqueeText->setText(songData);
   533         }
   767     TX_LOG_ARGS("marquee text: " << songData)
   534         if ( !mMarqueeText->isAnimating() ) {
   768 
   535             mMarqueeText->startAnimation();
   769     // Show dark BG to songdata only if there is songdata...
   536         }
   770     if ( mMusicPlayerNoSongData && mSongDataBG->isVisible() )
   537     }
   771         {
   538     else {
   772         TX_LOG_ARGS("hide marquee bg")
   539         if ( mSongDataBackground->isVisible() ) {
   773         mSongDataBG->hide();
   540             mSongDataBackground->hide();
   774         }
   541         }
   775     else if ( !mMusicPlayerNoSongData && !mSongDataBG->isVisible() )
   542         if ( mMarqueeText->isAnimating() ) {
   776         {
   543             mMarqueeText->stopAnimation();
   777         TX_LOG_ARGS("show marquee bg")
   544         }
   778         mSongDataBG->show();  
   545     }
   779         }
   546     
   780     
   547     TX_EXIT
   781     // Update button enabled/disabled state
   548 }
   782     toggleButtons();
   549 
   783     
   550 /*!
   784     TX_EXIT
   551  Update buttons to disabled/enabled as required.
   785 }
   552  */
   786 
   553 void MusicWidget::updateButtons()
   787 /*!
       
   788  Toggle buttons to disabled/enabled as required.
       
   789  */
       
   790 void MusicWidget::toggleButtons()
       
   791 { 
   554 { 
   792     TX_ENTRY
   555     TX_ENTRY
   793     // All buttons disabled if updating
   556     
   794     if ( mMusicPlayerUpdating )
   557     // All buttons disabled if updating or usb blocked
   795         {
   558     if ( mMusicPlayerUpdating || mMusicPlayerBlocked ) {
   796         TX_LOG_ARGS("updating")
   559         TX_LOG_ARGS( "refreshing" )
   797         mediaButtonDisabled( EPlayPause );
   560         mPreviousPushButton->setEnabled( false );
   798         mediaButtonDisabled( EPrevious );
   561         mPlayPushButton->setEnabled( false );
   799         mediaButtonDisabled( ENext );
   562         mNextPushButton->setEnabled( false );
   800         }
   563     }
   801     
   564     // Only play button enabled if there is no song data
   802     // All buttons disabled if blocked
   565     else if ( getPlaybackState() == MpPlaybackData::NotPlaying ) {
   803     else if ( mMusicPlayerBlocked )
   566         TX_LOG_ARGS( "no song data" )
   804         {
   567         mPreviousPushButton->setEnabled( false );
   805         TX_LOG_ARGS("blocked")
   568         mPlayPushButton->setEnabled( true );
   806         mediaButtonDisabled( EPlayPause );
   569         mNextPushButton->setEnabled( false );
   807         mediaButtonDisabled( EPrevious );
   570     }
   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
   571     // Enable all buttons if there is song data
   821     else
   572     else {
   822         {
   573         TX_LOG_ARGS( "enable all buttons" )
   823         TX_LOG_ARGS("enable all buttons")
   574         mPreviousPushButton->setEnabled( true );
   824         mediaButtonEnabled( EPlayPause );      
   575         mPlayPushButton->setEnabled( true );
   825         mediaButtonEnabled( EPrevious );
   576         mNextPushButton->setEnabled( true );
   826         mediaButtonEnabled( ENext );      
   577     }
   827         }
   578     
   828     TX_EXIT
   579     TX_EXIT
   829 }
   580 }
       
   581 
       
   582 /*!
       
   583  Connect/disconnect Music Player engine and playback data
       
   584  */
       
   585 void MusicWidget::connectMusicPlayerEngine( bool connect )
       
   586 {
       
   587     TX_ENTRY
       
   588 
       
   589     if ( mMpEngine ) {
       
   590         MpEngineFactory::close();
       
   591         mMpEngine = 0;
       
   592         mMpPlaybackData = 0;
       
   593         mMusicPlayerUpdating = false;
       
   594         mMusicPlayerBlocked = false;
       
   595     }
       
   596     
       
   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" )
       
   606     
       
   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     }
       
   617     
       
   618     TX_EXIT
       
   619 }
       
   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 }