utilities/mpnowplayingbanner/src/mpnowplayingwidget_p.cpp
changeset 32 c163ef0b758d
parent 29 8192e5b5c935
child 51 560ce2306a17
equal deleted inserted replaced
29:8192e5b5c935 32:c163ef0b758d
    21 #include <hblabel.h>
    21 #include <hblabel.h>
    22 #include <hbicon.h>
    22 #include <hbicon.h>
    23 #include <hbiconitem.h>
    23 #include <hbiconitem.h>
    24 #include <hbdocumentloader.h>
    24 #include <hbdocumentloader.h>
    25 #include <hbinstance.h>
    25 #include <hbinstance.h>
    26 #include <hbcolorscheme.h>
       
    27 #include <hbstyleloader.h>
    26 #include <hbstyleloader.h>
    28 
    27 
       
    28 #include "mpenginefactory.h"
    29 #include "mpnowplayingwidget_p.h"
    29 #include "mpnowplayingwidget_p.h"
    30 #include "mpnowplayingwidget.h"
    30 #include "mpnowplayingwidget.h"
    31 #include "mpnowplayingbackend.h"
       
    32 #include "mptrace.h"
    31 #include "mptrace.h"
    33 
    32 
    34 const char *NOW_PLAYING_XML = ":/xml/nowplaying.docml";
    33 const char *NOW_PLAYING_XML = ":/xml/nowplaying.docml";
    35 const char *NOW_PLAYING_CSS = ":/css/banner_color.css";
    34 const char *NOW_PLAYING_CSS = ":/css/banner_color.css";
    36 
    35 
    46 
    45 
    47 /*!
    46 /*!
    48  \internal
    47  \internal
    49  Constructs the now playing widget private.
    48  Constructs the now playing widget private.
    50  */
    49  */
    51 MpNowPlayingWidgetPrivate::MpNowPlayingWidgetPrivate( long int playerId, MpNowPlayingWidget *qq )
    50 MpNowPlayingWidgetPrivate::MpNowPlayingWidgetPrivate( MpNowPlayingWidget *qq )
    52     : q_ptr( qq ),
    51     : q_ptr( qq ),
    53       mPrimaryText(0),
    52       mPrimaryText(0),
    54       mSecondaryText(0),
    53       mSecondaryText(0),
    55       mState( NotPlaying ),
    54       mState( MpPlaybackData::NotPlaying ),
       
    55       mPlaybackData(0),
       
    56       mMpEngine(0),
    56       mIcon(0),
    57       mIcon(0),
    57       mDocumentLoader(0),
    58       mDocumentLoader(0),
    58       mCurrentPressedState( BannerNone )
    59       mCurrentPressedState( BannerNone )
    59 {
    60 {
    60     TX_ENTRY_ARGS( "Player ID =" << playerId << " Q pointer=" << ( void * )qq )
    61     TX_ENTRY_ARGS( " Q pointer=" << ( void * )qq )
    61     QGraphicsWidget *widget;
    62     QGraphicsWidget *widget;
    62     bool widgetsOk = false;
    63     bool widgetsOk = false;
    63     
    64     
    64     HbStyleLoader::registerFilePath(NOW_PLAYING_CSS);  
    65     HbStyleLoader::registerFilePath(NOW_PLAYING_CSS);  
    65     
    66     
   104     else {
   105     else {
   105         TX_LOG_ARGS("Error: invalid xml file.");
   106         TX_LOG_ARGS("Error: invalid xml file.");
   106         Q_ASSERT_X(widgetsOk, "MpNowPlayingWidgetPrivate", "invalid xml file");
   107         Q_ASSERT_X(widgetsOk, "MpNowPlayingWidgetPrivate", "invalid xml file");
   107     }
   108     }
   108 
   109 
   109     mBackEnd = new MpNowPlayingBackEnd( playerId );
   110     mMpEngine = MpEngineFactory::sharedEngine();
       
   111     mPlaybackData = mMpEngine->playbackData();
   110     setEnabled(true);
   112     setEnabled(true);
   111     TX_EXIT
   113     TX_EXIT
   112 }
   114 }
   113 
   115 
   114 
   116 
   117  Destructs the now playing widget private.
   119  Destructs the now playing widget private.
   118  */
   120  */
   119 MpNowPlayingWidgetPrivate::~MpNowPlayingWidgetPrivate()
   121 MpNowPlayingWidgetPrivate::~MpNowPlayingWidgetPrivate()
   120 {
   122 {
   121     TX_ENTRY
   123     TX_ENTRY
   122     delete mBackEnd;
       
   123     delete mPlayIcon;
   124     delete mPlayIcon;
   124     delete mPauseIcon;
   125     delete mPauseIcon;
   125     delete mDocumentLoader;
   126     delete mDocumentLoader;
   126     TX_EXIT
   127     TX_EXIT
   127 }
   128 }
   131  Item is enabled by default.
   132  Item is enabled by default.
   132  */
   133  */
   133 void MpNowPlayingWidgetPrivate::setEnabled( bool enabled )
   134 void MpNowPlayingWidgetPrivate::setEnabled( bool enabled )
   134 {
   135 {
   135     if ( enabled ) {
   136     if ( enabled ) {
   136         connect( mBackEnd, SIGNAL(stateUpdate(SimplifiedPlayerState)),
   137         connect( mPlaybackData, SIGNAL( playbackStateChanged() ),
   137                  this, SLOT(setState(SimplifiedPlayerState)) );
   138                  this, SLOT( setState() ) );
   138 
   139 
   139         connect( mBackEnd, SIGNAL(titleChanged(QString)),
   140         connect( mPlaybackData, SIGNAL( playbackInfoChanged() ),
   140                  this, SLOT(setTitle(QString)) );
   141                  this, SLOT( updateBannerInfo() ) );
   141 
   142 
   142         connect( mBackEnd, SIGNAL(artistChanged(QString)),
   143     setState();
   143                  this, SLOT(setArtist(QString)) );
   144     updateBannerInfo();
   144         mBackEnd->update();
       
   145     }
   145     }
   146     else {
   146     else {
   147         disconnect( mBackEnd, SIGNAL(stateUpdate(SimplifiedPlayerState)),
   147         disconnect( mPlaybackData, SIGNAL( playbackStateChanged() ),
   148                     this, SLOT(setState(SimplifiedPlayerState)) );
   148                  this, SLOT( setState() ) );
   149 
   149     
   150         disconnect( mBackEnd, SIGNAL(titleChanged(QString)),
   150         disconnect( mPlaybackData, SIGNAL( playbackInfoChanged() ),
   151                     mPrimaryText, SLOT(setPlainText(QString)) );
   151                  this, SLOT( updateBannerInfo() ) );
   152 
   152     }
   153         disconnect( mBackEnd, SIGNAL(artistChanged(QString)),
   153 }
   154                     mSecondaryText, SLOT(setPlainText(QString)) );
   154 
   155     }
   155 /*!
       
   156  Return if banner is attached based on current playback state
       
   157  */
       
   158 bool MpNowPlayingWidgetPrivate::isBannerAttached()
       
   159 {
       
   160     return mState == MpPlaybackData::NotPlaying ? false : true;
   156 }
   161 }
   157 
   162 
   158 /*!
   163 /*!
   159  \internal
   164  \internal
   160  Offers click \a event to the widget privated side, if event is consumed it returns true.
   165  Offers click \a event to the widget privated side, if event is consumed it returns true.
   170         QRectF iconTouchRect( mIcon->windowFrameGeometry() );
   175         QRectF iconTouchRect( mIcon->windowFrameGeometry() );
   171         iconTouchRect.adjust( -delta, -delta, delta, delta );
   176         iconTouchRect.adjust( -delta, -delta, delta, delta );
   172         if ( iconTouchRect.contains( event->pos() ) ) {
   177         if ( iconTouchRect.contains( event->pos() ) ) {
   173             if ( mCurrentPressedState == BannerIcon ) {
   178             if ( mCurrentPressedState == BannerIcon ) {
   174                     // click on play/pause
   179                     // click on play/pause
   175                     mBackEnd->playPause();
   180                 mMpEngine->playPause();
   176             }
   181             }
   177         }
   182         }
   178         else if ( mCurrentPressedState == BannerLabels && geometry.contains( event->pos() )){
   183         else if ( mCurrentPressedState == BannerLabels && geometry.contains( event->pos() )){
   179             // click somewhere else on the widget.
   184             // click somewhere else on the widget.
   180             ret = false;
   185             ret = false;
   255 
   260 
   256 /*!
   261 /*!
   257  \internal
   262  \internal
   258  Sets the simplified playback \a state.
   263  Sets the simplified playback \a state.
   259  */
   264  */
   260 void MpNowPlayingWidgetPrivate::setState( SimplifiedPlayerState state )
   265 void MpNowPlayingWidgetPrivate::setState( )
   261 {
   266 {
       
   267     MpPlaybackData::SimplifiedState state = mPlaybackData->playbackState();
   262     TX_ENTRY_ARGS( "State = " << state )
   268     TX_ENTRY_ARGS( "State = " << state )
       
   269             
   263     switch ( state ) {
   270     switch ( state ) {
   264         case NotPlaying:
   271         case MpPlaybackData::NotPlaying:
   265             if ( mState != NotPlaying )
   272             if ( mState != MpPlaybackData::NotPlaying )
   266                 emit q_ptr->playbackAttachmentChanged( false );
   273                 emit q_ptr->playbackAttachmentChanged( false );
   267             break;
   274             break;
   268         case Playing:
   275         case MpPlaybackData::Playing:
   269             mIcon->setIcon( *mPauseIcon );
   276             mIcon->setIcon( *mPauseIcon );
   270             mIcon->setProperty( "state", mIcon->property("state").toString() );
   277             mIcon->setProperty( "state", mIcon->property("state").toString() );
   271             if ( mState == NotPlaying )
   278             if ( mState == MpPlaybackData::NotPlaying )
   272                 emit q_ptr->playbackAttachmentChanged( true );
   279                 emit q_ptr->playbackAttachmentChanged( true );
   273             break;
   280             break;
   274         case Paused:
   281         case MpPlaybackData::Paused:
       
   282         case MpPlaybackData::Stopped:    
   275             mIcon->setIcon( *mPlayIcon );
   283             mIcon->setIcon( *mPlayIcon );
   276             mIcon->setProperty( "state", mIcon->property("state").toString() );
   284             mIcon->setProperty( "state", mIcon->property("state").toString() );
   277             if ( mState == NotPlaying )
   285             if ( mState == MpPlaybackData::NotPlaying )
   278                 emit q_ptr->playbackAttachmentChanged( true );
   286                 emit q_ptr->playbackAttachmentChanged( true );
   279             break;
   287             break;
   280         default:
   288         default:
   281             break;
   289             break;
   282     }
   290     }
   286 
   294 
   287 /*!
   295 /*!
   288  \internal
   296  \internal
   289  Sets the \a title 
   297  Sets the \a title 
   290  */
   298  */
   291 void MpNowPlayingWidgetPrivate::setTitle( const QString &title )
   299 void MpNowPlayingWidgetPrivate::updateBannerInfo()
   292 {
   300 {
   293     mPrimaryText->setPlainText( title );
   301     mPrimaryText->setPlainText( mPlaybackData->title() );
   294     mPrimaryText->setProperty( "state", mPrimaryText->property("state").toString() );
   302     mPrimaryText->setProperty( "state", mPrimaryText->property("state").toString() );
   295 }
   303     
   296 
   304     mSecondaryText->setPlainText( mPlaybackData->artist() );
   297 /*!
       
   298  \internal
       
   299  Sets the \a artist
       
   300  */
       
   301 void MpNowPlayingWidgetPrivate::setArtist( const QString &artist )
       
   302 {
       
   303     mSecondaryText->setPlainText( artist );
       
   304     mSecondaryText->setProperty( "state", mSecondaryText->property("state").toString() );
   305     mSecondaryText->setProperty( "state", mSecondaryText->property("state").toString() );
   305 }
   306 }
   306 
   307 
   307