utilities/mpnowplayingbanner/src/mpnowplayingwidget_p.cpp
changeset 36 a0afa279b8fe
parent 35 fdb31ab341af
child 51 560ce2306a17
--- a/utilities/mpnowplayingbanner/src/mpnowplayingwidget_p.cpp	Fri May 14 18:54:37 2010 -0500
+++ b/utilities/mpnowplayingbanner/src/mpnowplayingwidget_p.cpp	Fri May 28 19:46:01 2010 -0500
@@ -23,12 +23,11 @@
 #include <hbiconitem.h>
 #include <hbdocumentloader.h>
 #include <hbinstance.h>
-#include <hbcolorscheme.h>
 #include <hbstyleloader.h>
 
+#include "mpenginefactory.h"
 #include "mpnowplayingwidget_p.h"
 #include "mpnowplayingwidget.h"
-#include "mpnowplayingbackend.h"
 #include "mptrace.h"
 
 const char *NOW_PLAYING_XML = ":/xml/nowplaying.docml";
@@ -48,16 +47,18 @@
  \internal
  Constructs the now playing widget private.
  */
-MpNowPlayingWidgetPrivate::MpNowPlayingWidgetPrivate( long int playerId, MpNowPlayingWidget *qq )
+MpNowPlayingWidgetPrivate::MpNowPlayingWidgetPrivate( MpNowPlayingWidget *qq )
     : q_ptr( qq ),
       mPrimaryText(0),
       mSecondaryText(0),
-      mState( NotPlaying ),
+      mState( MpPlaybackData::NotPlaying ),
+      mPlaybackData(0),
+      mMpEngine(0),
       mIcon(0),
       mDocumentLoader(0),
       mCurrentPressedState( BannerNone )
 {
-    TX_ENTRY_ARGS( "Player ID =" << playerId << " Q pointer=" << ( void * )qq )
+    TX_ENTRY_ARGS( " Q pointer=" << ( void * )qq )
     QGraphicsWidget *widget;
     bool widgetsOk = false;
     
@@ -106,7 +107,8 @@
         Q_ASSERT_X(widgetsOk, "MpNowPlayingWidgetPrivate", "invalid xml file");
     }
 
-    mBackEnd = new MpNowPlayingBackEnd( playerId );
+    mMpEngine = MpEngineFactory::sharedEngine();
+    mPlaybackData = mMpEngine->playbackData();
     setEnabled(true);
     TX_EXIT
 }
@@ -119,7 +121,6 @@
 MpNowPlayingWidgetPrivate::~MpNowPlayingWidgetPrivate()
 {
     TX_ENTRY
-    delete mBackEnd;
     delete mPlayIcon;
     delete mPauseIcon;
     delete mDocumentLoader;
@@ -133,26 +134,30 @@
 void MpNowPlayingWidgetPrivate::setEnabled( bool enabled )
 {
     if ( enabled ) {
-        connect( mBackEnd, SIGNAL(stateUpdate(SimplifiedPlayerState)),
-                 this, SLOT(setState(SimplifiedPlayerState)) );
+        connect( mPlaybackData, SIGNAL( playbackStateChanged() ),
+                 this, SLOT( setState() ) );
 
-        connect( mBackEnd, SIGNAL(titleChanged(QString)),
-                 this, SLOT(setTitle(QString)) );
+        connect( mPlaybackData, SIGNAL( playbackInfoChanged() ),
+                 this, SLOT( updateBannerInfo() ) );
 
-        connect( mBackEnd, SIGNAL(artistChanged(QString)),
-                 this, SLOT(setArtist(QString)) );
-        mBackEnd->update();
+    setState();
+    updateBannerInfo();
     }
     else {
-        disconnect( mBackEnd, SIGNAL(stateUpdate(SimplifiedPlayerState)),
-                    this, SLOT(setState(SimplifiedPlayerState)) );
+        disconnect( mPlaybackData, SIGNAL( playbackStateChanged() ),
+                 this, SLOT( setState() ) );
+    
+        disconnect( mPlaybackData, SIGNAL( playbackInfoChanged() ),
+                 this, SLOT( updateBannerInfo() ) );
+    }
+}
 
-        disconnect( mBackEnd, SIGNAL(titleChanged(QString)),
-                    mPrimaryText, SLOT(setPlainText(QString)) );
-
-        disconnect( mBackEnd, SIGNAL(artistChanged(QString)),
-                    mSecondaryText, SLOT(setPlainText(QString)) );
-    }
+/*!
+ Return if banner is attached based on current playback state
+ */
+bool MpNowPlayingWidgetPrivate::isBannerAttached()
+{
+    return mState == MpPlaybackData::NotPlaying ? false : true;
 }
 
 /*!
@@ -172,7 +177,7 @@
         if ( iconTouchRect.contains( event->pos() ) ) {
             if ( mCurrentPressedState == BannerIcon ) {
                     // click on play/pause
-                    mBackEnd->playPause();
+                mMpEngine->playPause();
             }
         }
         else if ( mCurrentPressedState == BannerLabels && geometry.contains( event->pos() )){
@@ -257,24 +262,27 @@
  \internal
  Sets the simplified playback \a state.
  */
-void MpNowPlayingWidgetPrivate::setState( SimplifiedPlayerState state )
+void MpNowPlayingWidgetPrivate::setState( )
 {
+    MpPlaybackData::SimplifiedState state = mPlaybackData->playbackState();
     TX_ENTRY_ARGS( "State = " << state )
+            
     switch ( state ) {
-        case NotPlaying:
-            if ( mState != NotPlaying )
+        case MpPlaybackData::NotPlaying:
+            if ( mState != MpPlaybackData::NotPlaying )
                 emit q_ptr->playbackAttachmentChanged( false );
             break;
-        case Playing:
+        case MpPlaybackData::Playing:
             mIcon->setIcon( *mPauseIcon );
             mIcon->setProperty( "state", mIcon->property("state").toString() );
-            if ( mState == NotPlaying )
+            if ( mState == MpPlaybackData::NotPlaying )
                 emit q_ptr->playbackAttachmentChanged( true );
             break;
-        case Paused:
+        case MpPlaybackData::Paused:
+        case MpPlaybackData::Stopped:    
             mIcon->setIcon( *mPlayIcon );
             mIcon->setProperty( "state", mIcon->property("state").toString() );
-            if ( mState == NotPlaying )
+            if ( mState == MpPlaybackData::NotPlaying )
                 emit q_ptr->playbackAttachmentChanged( true );
             break;
         default:
@@ -288,20 +296,12 @@
  \internal
  Sets the \a title 
  */
-void MpNowPlayingWidgetPrivate::setTitle( const QString &title )
+void MpNowPlayingWidgetPrivate::updateBannerInfo()
 {
-    mPrimaryText->setPlainText( title );
+    mPrimaryText->setPlainText( mPlaybackData->title() );
     mPrimaryText->setProperty( "state", mPrimaryText->property("state").toString() );
-}
-
-/*!
- \internal
- Sets the \a artist
- */
-void MpNowPlayingWidgetPrivate::setArtist( const QString &artist )
-{
-    mSecondaryText->setPlainText( artist );
+    
+    mSecondaryText->setPlainText( mPlaybackData->artist() );
     mSecondaryText->setProperty( "state", mSecondaryText->property("state").toString() );
 }
 
-