qtinternetradio/irhswidgetplugin/src/irhswidget.cpp
changeset 15 065198191975
parent 14 896e9dbc5f19
equal deleted inserted replaced
14:896e9dbc5f19 15:065198191975
    44       mMetaDataRow(NULL),
    44       mMetaDataRow(NULL),
    45       mServiceClient(NULL),
    45       mServiceClient(NULL),
    46       mIrState(IrAppState::Unknown),
    46       mIrState(IrAppState::Unknown),
    47       mIrHsWidgetState(EUnknown)
    47       mIrHsWidgetState(EUnknown)
    48 {
    48 {
       
    49     LOG_METHOD;
    49     setupUi();
    50     setupUi();
    50     initHomeSreenWidget();
    51     initHomeSreenWidget();
    51     
    52     
    52     mServiceClient = IrServiceClient::openInstance();
    53     mServiceClient = IrServiceClient::openInstance();
    53     setupConnection();
    54     setupConnection();
    54 }
    55 }
    55 
    56 
    56 // Destructor
    57 // Destructor
    57 IrHsWidget::~IrHsWidget()
    58 IrHsWidget::~IrHsWidget()
    58 {
    59 {
       
    60     LOG_METHOD;
    59     if (mServiceClient)
    61     if (mServiceClient)
    60     {
    62     {
    61         mServiceClient->closeInstance();
    63         mServiceClient->closeInstance();
    62     } 
    64     } 
    63     
    65     
    70 
    72 
    71 // Initializes the widget.
    73 // Initializes the widget.
    72 // called by kqti fw when widget is added to home screen
    74 // called by kqti fw when widget is added to home screen
    73 void IrHsWidget::onInitialize()
    75 void IrHsWidget::onInitialize()
    74 {    
    76 {    
       
    77     LOG_METHOD;
    75     mServiceClient->startMonitoringIrState();    
    78     mServiceClient->startMonitoringIrState();    
    76 }
    79 }
    77 
    80 
    78 // Uninitializes the widget.
    81 // Uninitializes the widget.
    79 // called by kqti fw when widget is removed from home screen
    82 // called by kqti fw when widget is removed from home screen
    80 void IrHsWidget::onUninitialize()
    83 void IrHsWidget::onUninitialize()
    81 {
    84 {
       
    85     LOG_METHOD;
    82 }
    86 }
    83 
    87 
    84 // Called when widget is shown in the home screen
    88 // Called when widget is shown in the home screen
    85 void IrHsWidget::onShow()
    89 void IrHsWidget::onShow()
    86 { 
    90 { 
       
    91     LOG_METHOD;
    87     if (mRowLayout->count() == 2)
    92     if (mRowLayout->count() == 2)
    88     {
    93     {
    89         mMetaDataRow->startMetaDataMarquee();
    94         mMetaDataRow->startMetaDataMarquee();
    90     }   
    95     }   
    91 }
    96 }
    92 
    97 
    93 // Called when widget is hidden from the home screen
    98 // Called when widget is hidden from the home screen
    94 void IrHsWidget::onHide()
    99 void IrHsWidget::onHide()
    95 {
   100 {
       
   101     LOG_METHOD;
    96     if (mRowLayout->count() == 2)
   102     if (mRowLayout->count() == 2)
    97     {
   103     {
    98         mMetaDataRow->stopMetaDataMarquee();
   104         mMetaDataRow->stopMetaDataMarquee();
    99     }  
   105     }  
   100 }
   106 }
   101 
   107 
   102 
   108 
   103 void IrHsWidget::setupUi()
   109 void IrHsWidget::setupUi()
   104 {
   110 {
       
   111     LOG_METHOD;
   105     setContentsMargins( KIrHsWidgetContentsMargin, KIrHsWidgetContentsMargin,
   112     setContentsMargins( KIrHsWidgetContentsMargin, KIrHsWidgetContentsMargin,
   106             KIrHsWidgetContentsMargin, KIrHsWidgetContentsMargin);
   113             KIrHsWidgetContentsMargin, KIrHsWidgetContentsMargin);
   107     
   114     
   108     //Setup layout
   115     //Setup layout
   109     mRowLayout = new QGraphicsLinearLayout(Qt::Vertical);
   116     mRowLayout = new QGraphicsLinearLayout(Qt::Vertical);
   119    setBackgroundItem( backgroundLayoutItem );
   126    setBackgroundItem( backgroundLayoutItem );
   120 }
   127 }
   121 
   128 
   122 void IrHsWidget::initHomeSreenWidget()
   129 void IrHsWidget::initHomeSreenWidget()
   123 {
   130 {
       
   131     LOG_METHOD;
   124     mTitleRow = new IrHsWidgetTitleRow(); 
   132     mTitleRow = new IrHsWidgetTitleRow(); 
   125     mMetaDataRow = new IrHsWidgetMetaDataRow();
   133     mMetaDataRow = new IrHsWidgetMetaDataRow();
   126     
   134     
   127     mRowLayout->addItem(mTitleRow);
   135     mRowLayout->addItem(mTitleRow);
   128     resizeHomeScreenWidget();
   136     resizeHomeScreenWidget();
   147     }
   155     }
   148 }
   156 }
   149 
   157 
   150 void IrHsWidget::resizeHomeScreenWidget()
   158 void IrHsWidget::resizeHomeScreenWidget()
   151 {
   159 {
       
   160     LOG_METHOD;
   152     //resize here so homescreen will place widget correctly on screen
   161     //resize here so homescreen will place widget correctly on screen
   153     setPreferredSize( mRowLayout->preferredSize() );
   162     setPreferredSize( mRowLayout->preferredSize() );
   154     if (parentWidget())
   163     if (parentWidget())
   155     {
   164     {
   156         //to place widget properly after adding to homescreen
   165         //to place widget properly after adding to homescreen
   158 	}
   167 	}
   159 }
   168 }
   160     
   169     
   161 void IrHsWidget::setupConnection()
   170 void IrHsWidget::setupConnection()
   162 {
   171 {
       
   172     LOG_METHOD;
   163     // signal - slot for service event
   173     // signal - slot for service event
   164     QObject::connect(mServiceClient, SIGNAL(stationNameUpdated(QString)),
   174     QObject::connect(mServiceClient, SIGNAL(stationNameUpdated(QString)),
   165         this, SLOT(handleStationNameUpdated(QString)));
   175         this, SLOT(handleStationNameUpdated(QString)));
   166     QObject::connect(mServiceClient, SIGNAL(stationLogoUpdated(bool)),
   176     QObject::connect(mServiceClient, SIGNAL(stationLogoUpdated(bool)),
   167         this, SLOT(handleStationLogoUpdated(bool)));
   177         this, SLOT(handleStationLogoUpdated(bool)));
   175     enableUserAction();          
   185     enableUserAction();          
   176 }
   186 }
   177 
   187 
   178 void IrHsWidget::launchNowplayingView()
   188 void IrHsWidget::launchNowplayingView()
   179 {
   189 {
       
   190     LOG_METHOD;
   180     mServiceClient->launchIrNowPlaying();  
   191     mServiceClient->launchIrNowPlaying();  
   181 }
   192 }
   182 
   193 
   183 // ================ handle user press event ===============
   194 // ================ handle user press event ===============
   184 void IrHsWidget::handleCommonAreaAction()
   195 void IrHsWidget::handleCommonAreaAction()
   185 {
   196 {
       
   197     LOG_METHOD;
       
   198     LOG_FORMAT("mIrState = %d", mIrState);
   186     switch (mIrState)
   199     switch (mIrState)
   187     {
   200     {
   188         case IrAppState::NoRunInit:
   201         case IrAppState::NoRunInit:
   189         case IrAppState::NoRunStopped:
   202         case IrAppState::NoRunStopped:
   190             disableUserAction();
   203             disableUserAction();
   203     }
   216     }
   204 }
   217 }
   205 
   218 
   206 void IrHsWidget::handleControlAreaAction()
   219 void IrHsWidget::handleControlAreaAction()
   207 {
   220 {
   208     LOG("IrHsWidget::handleControlAreaAction()");
   221     LOG_METHOD;
       
   222     LOG_FORMAT("mIrState = %d", mIrState);
   209     //here, for we will control the application by homescreen, 
   223     //here, for we will control the application by homescreen, 
   210     //to avoid repeat actions, we disable all control event here
   224     //to avoid repeat actions, we disable all control event here
   211     //and enable them when state changed or failed.      
   225     //and enable them when state changed or failed.      
   212     disableUserAction();
   226     disableUserAction();
   213     
   227     
   236 }
   250 }
   237 
   251 
   238 
   252 
   239 void IrHsWidget::handleControlFailed()
   253 void IrHsWidget::handleControlFailed()
   240 { 
   254 { 
   241     LOG("handleControlFailed()");
   255     LOG_METHOD;
       
   256     LOG_FORMAT("mIrHsWidgetState = %d", mIrHsWidgetState);
   242     enableUserAction();
   257     enableUserAction();
   243     switch (mIrHsWidgetState)
   258     switch (mIrHsWidgetState)
   244     {
   259     {
   245         case EInit:     // LAF == [logo][go to interneat radio]
   260         case EInit:     // LAF == [logo][go to interneat radio]
   246             loadInitLayout();
   261             loadInitLayout();
   265 
   280 
   266 
   281 
   267 // ======== for service notification ========
   282 // ======== for service notification ========
   268 void IrHsWidget::handleStationNameUpdated(const QString &aStationName)
   283 void IrHsWidget::handleStationNameUpdated(const QString &aStationName)
   269 {
   284 {
       
   285     LOG_METHOD;
       
   286     LOG_FORMAT("aStationName = %s", STRING2CHAR(aStationName));
   270     mTitleRow->setStationName(aStationName);
   287     mTitleRow->setStationName(aStationName);
   271 }
   288 }
   272 
   289 
   273 void IrHsWidget::handleStationLogoUpdated(bool aLogoAvailable)
   290 void IrHsWidget::handleStationLogoUpdated(bool aLogoAvailable)
   274 {    
   291 {    
       
   292     LOG_METHOD;
   275     if (aLogoAvailable)
   293     if (aLogoAvailable)
   276     {
   294     {
       
   295         LOG( "aLogoAvailable = true" );
   277         mTitleRow->loadStationLogo();
   296         mTitleRow->loadStationLogo();
   278     }
   297     }
   279     else
   298     else
   280     {
   299     {
       
   300         LOG( "aLogoAvailable = false" );
   281         mTitleRow->setDefaultLogo();
   301         mTitleRow->setDefaultLogo();
   282     }
   302     }
   283 }
   303 }
   284 
   304 
   285 void IrHsWidget::handleMetaDataUpdated(const QString &aMetaData)
   305 void IrHsWidget::handleMetaDataUpdated(const QString &aMetaData)
   286 {
   306 {
       
   307     LOG_METHOD;
       
   308     LOG_FORMAT("aMetaData = %s", STRING2CHAR(aMetaData));
   287     mMetaDataRow->setMetaData(aMetaData); 
   309     mMetaDataRow->setMetaData(aMetaData); 
   288 }
   310 }
   289 
   311 
   290 
   312 
   291 void IrHsWidget::handleIrStateUpdated(IrAppState::Type aNewState)
   313 void IrHsWidget::handleIrStateUpdated(IrAppState::Type aNewState)
   292 {
   314 {
   293     LOG("IrHsWidget::handleIrStateUpdated()");
   315     LOG_METHOD;
       
   316     LOG_FORMAT("mIrState = %d", mIrState);
       
   317     LOG_FORMAT("aNewState = %d", aNewState);
   294     enableUserAction();
   318     enableUserAction();
   295     if (aNewState == mIrState)
   319     if (aNewState == mIrState)
   296     {
   320     {
   297         return;
   321         return;
   298     }
   322     }
   323     }
   347     }
   324 }
   348 }
   325 
   349 
   326 void IrHsWidget::handleHsWidgetStateChange(IrHsWidgetState aNewState)
   350 void IrHsWidget::handleHsWidgetStateChange(IrHsWidgetState aNewState)
   327 {
   351 {
       
   352     LOG_METHOD;
       
   353     LOG_FORMAT("mIrHsWidgetState = %d", mIrHsWidgetState);
       
   354     LOG_FORMAT("aNewIrHsWidgetState = %d", aNewState);    
   328     if (aNewState == mIrHsWidgetState)
   355     if (aNewState == mIrHsWidgetState)
   329     {
   356     {
   330         return;
   357         return;
   331     }
   358     }
   332     
   359     
   354     }
   381     }
   355 }
   382 }
   356 // LAF == [logo][go to interneat radio]
   383 // LAF == [logo][go to interneat radio]
   357 void IrHsWidget::loadInitLayout()
   384 void IrHsWidget::loadInitLayout()
   358 {
   385 {
       
   386     LOG_METHOD;
   359     if (mRowLayout->count() == 2)
   387     if (mRowLayout->count() == 2)
   360     {
   388     {
   361         mRowLayout->removeItem(mMetaDataRow);
   389         mRowLayout->removeItem(mMetaDataRow);
   362         resizeHomeScreenWidget();      
   390         resizeHomeScreenWidget();      
   363     }
   391     }
   366 }
   394 }
   367 
   395 
   368 // LAF == [logo][StationInfo][Play]
   396 // LAF == [logo][StationInfo][Play]
   369 void IrHsWidget::loadStoppedLayout()
   397 void IrHsWidget::loadStoppedLayout()
   370 {
   398 {
       
   399     LOG_METHOD;
   371     if (mRowLayout->count() == 1)
   400     if (mRowLayout->count() == 1)
   372     {
   401     {
   373         mRowLayout->addItem(mMetaDataRow);
   402         mRowLayout->addItem(mMetaDataRow);
   374         resizeHomeScreenWidget();      
   403         resizeHomeScreenWidget();      
   375     }
   404     }
   378 }
   407 }
   379 
   408 
   380 // LAF == [logo][StationInfo][Stop]
   409 // LAF == [logo][StationInfo][Stop]
   381 void IrHsWidget::loadPlayingLayout()
   410 void IrHsWidget::loadPlayingLayout()
   382 {
   411 {
       
   412     LOG_METHOD;
   383     if (mRowLayout->count() == 1)
   413     if (mRowLayout->count() == 1)
   384     {
   414     {
   385         mRowLayout->addItem(mMetaDataRow);
   415         mRowLayout->addItem(mMetaDataRow);
   386         resizeHomeScreenWidget();      
   416         resizeHomeScreenWidget();      
   387     }
   417     }
   390 }
   420 }
   391 
   421 
   392 // LAF == [logo][StationInfo][Loading]
   422 // LAF == [logo][StationInfo][Loading]
   393 void IrHsWidget::loadLoadingLayout()
   423 void IrHsWidget::loadLoadingLayout()
   394 {
   424 {
       
   425     LOG_METHOD;
   395     if (mRowLayout->count() == 1)
   426     if (mRowLayout->count() == 1)
   396     {
   427     {
   397         mRowLayout->addItem(mMetaDataRow);
   428         mRowLayout->addItem(mMetaDataRow);
   398         resizeHomeScreenWidget();      
   429         resizeHomeScreenWidget();      
   399     }
   430     }
   403 
   434 
   404 
   435 
   405 
   436 
   406 void IrHsWidget::enableUserAction()
   437 void IrHsWidget::enableUserAction()
   407 {
   438 {
       
   439     LOG_METHOD;
   408     if (!mUserActionEnabled)
   440     if (!mUserActionEnabled)
   409     {
   441     {
   410         mUserActionEnabled = true;
   442         mUserActionEnabled = true;
   411         // signal - slot for user click action
   443         // signal - slot for user click action
   412         QObject::connect(mTitleRow, SIGNAL(titleRowClicked()),
   444         QObject::connect(mTitleRow, SIGNAL(titleRowClicked()),
   418     }
   450     }
   419 }
   451 }
   420 
   452 
   421 void IrHsWidget::disableUserAction()
   453 void IrHsWidget::disableUserAction()
   422 {
   454 {
       
   455     LOG_METHOD;
   423     if (mUserActionEnabled)
   456     if (mUserActionEnabled)
   424     {    
   457     {    
   425         mUserActionEnabled = false;
   458         mUserActionEnabled = false;
   426         // signal - slot for user click action
   459         // signal - slot for user click action
   427         QObject::disconnect(mTitleRow, SIGNAL(titleRowClicked()),
   460         QObject::disconnect(mTitleRow, SIGNAL(titleRowClicked()),