homescreenapp/hsapplication/src/hsstatemachine.cpp
changeset 71 1db7cc813a4e
parent 69 87476091b3f5
child 81 7dd137878ff8
equal deleted inserted replaced
69:87476091b3f5 71:1db7cc813a4e
    47 #include "hswidgetpositioningonwidgetmove.h"
    47 #include "hswidgetpositioningonwidgetmove.h"
    48 
    48 
    49 QTM_USE_NAMESPACE
    49 QTM_USE_NAMESPACE
    50 #define hbApp qobject_cast<HbApplication*>(qApp)
    50 #define hbApp qobject_cast<HbApplication*>(qApp)
    51 
    51 
    52 #ifdef Q_OS_SYMBIAN
       
    53 const static Qt::Key applicationKey = Qt::Key_Menu;
       
    54 #else
       
    55 const static Qt::Key applicationKey = Qt::Key_Home;
       
    56 #endif
       
    57 
       
    58 namespace
    52 namespace
    59 {
    53 {
    60     const char KHsRootStateInterface[] = "com.nokia.homescreen.state.HsRootState";
    54     const char KHsRootStateInterface[] = "com.nokia.homescreen.state.HsRootState";
    61     const char KHsLoadSceneStateInterface[] = "com.nokia.homescreen.state.HsLoadSceneState";
    55     const char KHsLoadSceneStateInterface[] = "com.nokia.homescreen.state.HsLoadSceneState";
    62     const char KHsIdleStateInterface[] = "com.nokia.homescreen.state.HsIdleState";
    56     const char KHsIdleStateInterface[] = "com.nokia.homescreen.state.HsIdleState";
    83 HsStateMachine::HsStateMachine(QObject *parent)
    77 HsStateMachine::HsStateMachine(QObject *parent)
    84     : QStateMachine(parent),
    78     : QStateMachine(parent),
    85       mContentService(0),	  
    79       mContentService(0),	  
    86       mHomeScreenActive(false),
    80       mHomeScreenActive(false),
    87       mIdleStateActive(false),
    81       mIdleStateActive(false),
       
    82       mEndKeyCaptured(false),
    88       mPublisher(NULL)
    83       mPublisher(NULL)
    89 #ifdef Q_OS_SYMBIAN
    84 #ifdef Q_OS_SYMBIAN
    90 	  ,keyCapture()
    85 	  ,keyCapture()
    91 #endif
    86 #endif
    92 {
    87 {
   160     Q_UNUSED(watched);
   155     Q_UNUSED(watched);
   161 
   156 
   162     switch (event->type()) {
   157     switch (event->type()) {
   163         case QEvent::ApplicationActivate:
   158         case QEvent::ApplicationActivate:
   164             qDebug() << "HsStateMachine::eventFilter: QEvent::ApplicationActivate";
   159             qDebug() << "HsStateMachine::eventFilter: QEvent::ApplicationActivate";
   165 #ifdef Q_OS_SYMBIAN
       
   166             keyCapture.captureKey(applicationKey);
       
   167 #endif
       
   168             mHomeScreenActive = true;
   160             mHomeScreenActive = true;
   169             updatePSKeys();
   161             updatePSKeys();
   170             break;
   162             break;
   171         case QEvent::ApplicationDeactivate:
   163         case QEvent::ApplicationDeactivate:
   172             qDebug() << "HsStateMachine::eventFilter: QEvent::ApplicationDeactivate";
   164             qDebug() << "HsStateMachine::eventFilter: QEvent::ApplicationDeactivate";
   173 #ifdef Q_OS_SYMBIAN
       
   174             keyCapture.cancelCaptureKey(applicationKey);
       
   175 #endif
       
   176             mHomeScreenActive = false;
   165             mHomeScreenActive = false;
   177             updatePSKeys();
   166             updatePSKeys();
   178             break;
   167             break;
   179         default:
   168         default:
   180             break;
   169             break;
   181     }
   170     }
   182    
   171         
   183     bool result =  QStateMachine::eventFilter(watched, event);
   172     bool result =  QStateMachine::eventFilter(watched, event);    
   184     // temporary hack as we should not register twice for events
       
   185     if (event->type() == QEvent::KeyPress ) {
   173     if (event->type() == QEvent::KeyPress ) {
   186         QKeyEvent* ke = static_cast<QKeyEvent *>(event);         
   174         QKeyEvent* ke = static_cast<QKeyEvent *>(event);                 
   187         // Key_Launch0 should be removed when QT starts to send Key_Menu
   175         result = (ke->key() == Qt::Key_Home);
   188         result = (ke->key() == applicationKey) || ke->key() == Qt::Key_Launch0;        
       
   189     }
   176     }
   190     return result;
   177     return result;
   191 }
   178 }
   192 
   179 
   193 
   180 
   312             HsMenuEvent::OpenHomeScreen, appLibraryState, idleState);
   299             HsMenuEvent::OpenHomeScreen, appLibraryState, idleState);
   313     appLibraryState->addTransition(appLibToIdleTransition);
   300     appLibraryState->addTransition(appLibToIdleTransition);
   314 
   301 
   315     HbMainWindow *window = hbInstance->allMainWindows().first();
   302     HbMainWindow *window = hbInstance->allMainWindows().first();
   316 
   303 
       
   304 #ifndef  Q_OS_SYMBIAN   
   317     // key driven transition from idle to menu
   305     // key driven transition from idle to menu
   318     QKeyEventTransition *idleToMenuRootTransition =
   306     QKeyEventTransition *idleToMenuRootTransition =
   319         new QKeyEventTransition(
   307         new QKeyEventTransition(
   320                 window, QEvent::KeyPress, applicationKey);
   308                 window, QEvent::KeyPress, Qt::Key_Home);
   321     idleToMenuRootTransition->setTargetState(menuRootState);
   309     idleToMenuRootTransition->setTargetState(menuRootState);
   322     idleState->addTransition(idleToMenuRootTransition);
   310     idleState->addTransition(idleToMenuRootTransition);
   323     // key driven transition from menu to idle
   311     // key driven transition from menu to idle
   324     QKeyEventTransition *menuToIdleTransition =
   312     QKeyEventTransition *menuToIdleTransition =
   325         new QKeyEventTransition(
   313         new QKeyEventTransition(
   326                 window, QEvent::KeyPress, applicationKey);
   314                 window, QEvent::KeyPress, Qt::Key_Home);
   327     menuToIdleTransition->setTargetState(idleState);
   315     menuToIdleTransition->setTargetState(idleState);
   328     menuRootState->addTransition(menuToIdleTransition);
   316     menuRootState->addTransition(menuToIdleTransition);
   329     
   317 #endif 
   330     // transition for Key_Launch0 should be removed 
   318     // key driven transition from menu to idle
   331     // when OT starts to send Key_Menu (maybe wk14)
   319     QKeyEventTransition *menuToIdleTransitionNoKey =
   332     QKeyEventTransition *idleToMenuRootTransition2 =
       
   333         new QKeyEventTransition(
   320         new QKeyEventTransition(
   334                 window, QEvent::KeyPress, Qt::Key_Launch0);
   321                 window, QEvent::KeyPress, Qt::Key_No);
   335     idleToMenuRootTransition2->setTargetState(menuRootState);
   322     menuToIdleTransitionNoKey->setTargetState(idleState);
   336     idleState->addTransition(idleToMenuRootTransition2);
   323     menuRootState->addTransition(menuToIdleTransitionNoKey);
   337     // key driven transition from menu to idle
   324     
   338     QKeyEventTransition *menuToIdleTransition2 =
       
   339         new QKeyEventTransition(
       
   340                 window, QEvent::KeyPress, Qt::Key_Launch0);
       
   341     menuToIdleTransition2->setTargetState(idleState);
       
   342     menuRootState->addTransition(menuToIdleTransition2);
       
   343     // add transition to switch to idle
   325     // add transition to switch to idle
   344     menuRootState->addTransition( this, SIGNAL(event_toIdle()), idleState);    
   326     menuRootState->addTransition( this, SIGNAL(event_toIdle()), idleState);    
       
   327     // add transition to switch to applib 
       
   328     idleState->addTransition( this, SIGNAL(event_toAppLib()), menuRootState);
   345     
   329     
   346     // transitions to child states
   330     // transitions to child states
   347     // opening shortcut to a colleciton
   331     // opening shortcut to a colleciton
   348     QList<QState *> collectionStates =
   332     QList<QState *> collectionStates =
   349         appLibraryState->
   333         appLibraryState->
   381     }
   365     }
   382     else{
   366     else{
   383     	qDebug() << "HsStateMachine::updatePSKeys: EHomeScreenInactive";
   367     	qDebug() << "HsStateMachine::updatePSKeys: EHomeScreenInactive";
   384     	mPublisher->setValue(HsStatePSKeySubPath, EHomeScreenInactive);
   368     	mPublisher->setValue(HsStatePSKeySubPath, EHomeScreenInactive);
   385     }	
   369     }	
       
   370     
       
   371     if (mHomeScreenActive && !mIdleStateActive) {
       
   372         captureEndKey(true);
       
   373     } else {
       
   374         captureEndKey(false);
       
   375     }
       
   376 }
       
   377 
       
   378 /*!
       
   379     capture End key 
       
   380 */
       
   381 void HsStateMachine::captureEndKey(bool enable) 
       
   382 {
       
   383 #ifdef Q_OS_SYMBIAN
       
   384     if (enable && !mEndKeyCaptured) {
       
   385         mEndKeyCaptured = true;
       
   386         keyCapture.captureKey(Qt::Key_No);        
       
   387     } else if (mEndKeyCaptured) {
       
   388         mEndKeyCaptured = false;
       
   389         keyCapture.cancelCaptureKey(Qt::Key_No);
       
   390     }
       
   391 #endif
   386 }
   392 }
   387 
   393 
   388 /*!
   394 /*!
   389     Called when state machine is in Idle state.
   395     Called when state machine is in Idle state.
   390 */
   396 */
   412         this->postEvent(
   418         this->postEvent(
   413             HsMenuEventFactory::createOpenCollectionEvent(0,
   419             HsMenuEventFactory::createOpenCollectionEvent(0,
   414             collectionDownloadedTypeName()));
   420             collectionDownloadedTypeName()));
   415     } else if (name == activityHsIdleView()) {
   421     } else if (name == activityHsIdleView()) {
   416         emit event_toIdle();
   422         emit event_toIdle();
   417     }
   423     } else if (name == activityAppLibMainView()) {
   418 }
   424         emit event_toAppLib();
       
   425     }
       
   426 }