ui/viewmanagement/statehandler/src/glxstatemanager.cpp
changeset 42 5e1df1b52eb3
parent 40 112f0ac2d1f0
child 36 6481344a6d67
equal deleted inserted replaced
41:ae07d189b490 42:5e1df1b52eb3
    23 #include <glxliststate.h>
    23 #include <glxliststate.h>
    24 #include <glxfullscreenstate.h>
    24 #include <glxfullscreenstate.h>
    25 #include <glxdetailstate.h>
    25 #include <glxdetailstate.h>
    26 #include <glxslideshowsettingsstate.h>
    26 #include <glxslideshowsettingsstate.h>
    27 #include <glxslideshowstate.h>
    27 #include <glxslideshowstate.h>
       
    28 #include <glxtnobserver.h>
    28 #include <glxmodelparm.h>
    29 #include <glxmodelparm.h>
    29 #include <glxcollectionpluginall.hrh>
    30 #include <glxcollectionpluginall.hrh>
    30 #include <glxcollectionplugincamera.hrh>
    31 #include <glxcollectionplugincamera.hrh>
    31 #include <glxcollectionpluginalbums.hrh>
    32 #include <glxcollectionpluginalbums.hrh>
    32 #include <glxcollectionpluginimageviewer.hrh>
    33 #include <glxcollectionpluginimageviewer.hrh>
    41 #include <QDebug>
    42 #include <QDebug>
    42 #include <QItemSelectionModel>
    43 #include <QItemSelectionModel>
    43 #include <hbnotificationdialog.h>
    44 #include <hbnotificationdialog.h>
    44 #include <QProcess>
    45 #include <QProcess>
    45 
    46 
    46 GlxStateManager::GlxStateManager() : mAllMediaModel(NULL), mAlbumGridMediaModel(NULL),
    47 
    47             mAlbumMediaModel(NULL),mImageviewerMediaModel(NULL), mCurrentModel (NULL), mCurrentState (NULL), mActionHandler (NULL)
    48 GlxStateManager::GlxStateManager() 
       
    49     : mAllMediaModel( NULL ), 
       
    50       mAlbumGridMediaModel( NULL ),
       
    51       mAlbumMediaModel( NULL ),
       
    52       mImageviewerMediaModel( NULL ), 
       
    53       mCurrentModel( NULL ), 
       
    54       mCurrentState( NULL ), 
       
    55       mActionHandler( NULL ),
       
    56       mTNObserver ( NULL )
    48 {
    57 {
    49     qDebug("GlxStateManager::GlxStateManager");
    58     qDebug("GlxStateManager::GlxStateManager");
    50     PERFORMANCE_ADV ( d1, "view manager creation time") {
    59     PERFORMANCE_ADV ( d1, "view manager creation time") {
    51         mViewManager = new GlxViewManager();
    60         mViewManager = new GlxViewManager();
    52     }
    61     }
       
    62     mTNObserver = new GlxTNObserver();
       
    63     
    53     connect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ), Qt::QueuedConnection );
    64     connect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ), Qt::QueuedConnection );
    54     connect ( mViewManager, SIGNAL(actionTriggered(qint32 )), this, SLOT(actionTriggered(qint32 )), Qt::QueuedConnection );
    65     connect ( mViewManager, SIGNAL(actionTriggered( qint32 )), this, SLOT(actionTriggered( qint32 )), Qt::QueuedConnection );
       
    66     connect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) );
    55 	//TO:DO TBD through exception when it is null
    67 	//TO:DO TBD through exception when it is null
    56 }
    68 }
    57 
    69 
    58 void GlxStateManager::enterMarkingMode()
    70 void GlxStateManager::enterMarkingMode()
    59 {
    71 {
    85     return TRUE;
    97     return TRUE;
    86 }
    98 }
    87 
    99 
    88 void GlxStateManager::launchApplication()
   100 void GlxStateManager::launchApplication()
    89 {
   101 {
    90    qDebug("GlxStateManager::launchApplication");   
   102     qDebug("GlxStateManager::launchApplication");   
    91    //To:Do use it in future once performance code is removed nextState(GLX_GRIDVIEW_ID, ALL_ITEM_S)
   103        
    92    
   104     //To:Do use it in future once performance code is removed nextState(GLX_GRIDVIEW_ID, ALL_ITEM_S)
    93    mCurrentState = createState(GLX_GRIDVIEW_ID);
   105     mCurrentState = createState( GLX_GRIDVIEW_ID );
    94    mCurrentState->setState(ALL_ITEM_S);
   106     mCurrentState->setState( ALL_ITEM_S );
    95    
   107        
    96    PERFORMANCE_ADV ( d1, "Media model creation time" ) {
   108     if ( mTNObserver->getTNLeftCount() > 0 ) {
    97        createModel(GLX_GRIDVIEW_ID);
   109         mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel);
    98    }
   110         mViewManager->launchProgressDialog( mTNObserver->getTNLeftCount() );
    99    
   111     }
   100    PERFORMANCE_ADV ( d2, "Grid View Launch time" ) {
   112     else {
   101        mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel);
   113         createModel( GLX_GRIDVIEW_ID );
   102    }   
   114         mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel);
       
   115     }
       
   116     
       
   117     mTNObserver->startTNObserving() ; 
   103 }
   118 }
   104 
   119 
   105 void GlxStateManager::launchFromExternal()
   120 void GlxStateManager::launchFromExternal()
   106 {
   121 {
   107     qDebug("GlxStateManager::launchApplication");
   122     qDebug("GlxStateManager::launchApplication");
   130     connect ( mViewManager, SIGNAL(externalCommand(int )), this, SIGNAL(externalCommand(int )) );
   145     connect ( mViewManager, SIGNAL(externalCommand(int )), this, SIGNAL(externalCommand(int )) );
   131     mViewManager->setupItems();
   146     mViewManager->setupItems();
   132     mViewManager->updateToolBarIcon(GLX_ALL_ACTION_ID);
   147     mViewManager->updateToolBarIcon(GLX_ALL_ACTION_ID);
   133 }
   148 }
   134 
   149 
       
   150 void GlxStateManager::updateTNProgress( int count)
       
   151 {
       
   152     if (  mCurrentState->id() != GLX_GRIDVIEW_ID  && count > 0) {
       
   153          goBack( GLX_GRIDVIEW_ID, ALL_ITEM_S ) ;
       
   154     }
       
   155     if ( mCurrentModel && count > 0) {
       
   156          cleanAllModel();   
       
   157          mViewManager->launchProgressDialog ( count ) ;
       
   158     }
       
   159     if ( count == 0 ) {
       
   160         createModel( mCurrentState->id() );
       
   161         mViewManager->setModel( mCurrentModel );
       
   162     }
       
   163     mViewManager->updateProgressDialog( count );
       
   164 }
       
   165 
   135 void GlxStateManager::nextState(qint32 state, int internalState)
   166 void GlxStateManager::nextState(qint32 state, int internalState)
   136 {
   167 {
   137     qDebug("GlxStateManager::nextState next state = %u", state);
   168     qDebug("GlxStateManager::nextState next state = %u", state);
   138     GlxEffect effect = NO_EFFECT ;
   169     GlxEffect effect = NO_EFFECT ;
   139     GlxViewEffect viewEffect = NO_VIEW ;
   170     GlxViewEffect viewEffect = NO_VIEW ;
   187 void GlxStateManager::goBack(qint32 stateId, int internalState)
   218 void GlxStateManager::goBack(qint32 stateId, int internalState)
   188 {
   219 {
   189     qDebug("GlxStateManager::goBack()");
   220     qDebug("GlxStateManager::goBack()");
   190     GlxState *state = mCurrentState;
   221     GlxState *state = mCurrentState;
   191     
   222     
   192     do {
   223     while ( mCurrentState ) {
       
   224         if ( mCurrentState->id() == stateId  && mCurrentState->state() == internalState ) {
       
   225             break ;           
       
   226         }
       
   227         
   193         mCurrentState = mCurrentState->previousState(); // set pervious state to the current state
   228         mCurrentState = mCurrentState->previousState(); // set pervious state to the current state
   194         delete state; //delete the current state
   229         delete state; //delete the current state
   195         state = mCurrentState;
   230         state = mCurrentState;    
   196     }
   231     }
   197     while ( mCurrentState && mCurrentState->id() != stateId ); //check, cuurent state is a new state
       
   198     
   232     
   199     //case when new state is not hierarchy then create a new state
   233     //case when new state is not hierarchy then create a new state
   200     if ( mCurrentState == NULL ) {
   234     if ( mCurrentState == NULL ) {
   201         mCurrentState = createState(stateId);
   235         mCurrentState = createState(stateId);
   202         mCurrentState->setState( internalState );
   236         mCurrentState->setState( internalState );
   253     }
   287     }
   254     else {
   288     else {
   255     	qDebug("GlxStateManager::removeCurrentModel() do nothing");
   289     	qDebug("GlxStateManager::removeCurrentModel() do nothing");
   256     	//do nothing
   290     	//do nothing
   257     }
   291     }
       
   292 }
       
   293 
       
   294 void GlxStateManager::cleanAllModel()
       
   295 {
       
   296     delete mAllMediaModel ;
       
   297     mAllMediaModel = NULL ;
       
   298     delete mAlbumMediaModel ; 
       
   299     mAlbumMediaModel = NULL ;
       
   300     delete mAlbumGridMediaModel ;
       
   301     mAlbumGridMediaModel = NULL ;
       
   302     delete mImageviewerMediaModel ;
       
   303     mImageviewerMediaModel = NULL ;
       
   304     mCurrentModel = NULL ;
   258 }
   305 }
   259 
   306 
   260 GlxState * GlxStateManager::createState(qint32 stateId)
   307 GlxState * GlxStateManager::createState(qint32 stateId)
   261 {
   308 {
   262     qDebug("GlxStateManager::createState state id = %d", stateId);
   309     qDebug("GlxStateManager::createState state id = %d", stateId);
   434         
   481         
   435     case EGlxCmdSlideshowSettings:
   482     case EGlxCmdSlideshowSettings:
   436         nextState(GLX_SLIDESHOWSETTINGSVIEW_ID,-1 );
   483         nextState(GLX_SLIDESHOWSETTINGSVIEW_ID,-1 );
   437         id = EGlxCmdHandled;
   484         id = EGlxCmdHandled;
   438         break;
   485         break;
       
   486         
   439     case EGlxCmdDetailsOpen:
   487     case EGlxCmdDetailsOpen:
   440         qDebug("GlxStateManager::eventHandler EGlxCmdDetailsOpen");
   488         qDebug("GlxStateManager::eventHandler EGlxCmdDetailsOpen");
   441         nextState( GLX_DETAILSVIEW_ID, -1 );
   489         nextState( GLX_DETAILSVIEW_ID, -1 );
   442         id = EGlxCmdHandled;
   490         id = EGlxCmdHandled;
   443         break;
   491         break;
   444         
   492         
   445     case EGlxCmdEmptyData :
   493     case EGlxCmdEmptyData : {
   446         goBack(GLX_GRIDVIEW_ID, NO_GRID_S);
   494         GlxState *tmpState = mCurrentState ;
   447         id = EGlxCmdHandled;
   495         while ( tmpState->id() != GLX_GRIDVIEW_ID ) {
   448         break;
   496             tmpState = tmpState->previousState() ;
       
   497         }
       
   498         
       
   499         goBack( GLX_GRIDVIEW_ID, tmpState->state() );
       
   500         id = EGlxCmdHandled;
       
   501         break;
       
   502     }
   449     	
   503     	
   450     case EGlxCmdBack :
   504     case EGlxCmdBack :
   451     	previousState();
   505     	previousState();
   452     	id = EGlxCmdHandled;
   506     	id = EGlxCmdHandled;
   453     	break;
   507     	break;
   515 }
   569 }
   516 
   570 
   517 GlxStateManager::~GlxStateManager()
   571 GlxStateManager::~GlxStateManager()
   518 {
   572 {
   519     qDebug("GlxStateManager::~GlxStateManager");
   573     qDebug("GlxStateManager::~GlxStateManager");
   520     delete mAllMediaModel;
   574     cleanAllModel();
   521     delete mAlbumMediaModel;
       
   522     delete mAlbumGridMediaModel;
       
   523 	
       
   524     delete mActionHandler;
   575     delete mActionHandler;
   525     qDebug("GlxStateManager::~GlxStateManager delete Model");
   576     qDebug("GlxStateManager::~GlxStateManager delete Model");
   526     
   577     
   527     disconnect ( mViewManager, SIGNAL(actionTriggered(qint32 )), this, SLOT(actionTriggered(qint32 )) );
   578     disconnect ( mViewManager, SIGNAL(actionTriggered(qint32 )), this, SLOT(actionTriggered(qint32 )) );
   528     disconnect ( mViewManager, SIGNAL(externalCommand(int )), this, SIGNAL(externalCommand(int )) );
   579     disconnect ( mViewManager, SIGNAL(externalCommand(int )), this, SIGNAL(externalCommand(int )) );
       
   580     disconnect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) );
       
   581     disconnect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ) );
       
   582     
       
   583     delete mTNObserver;
   529     delete mViewManager; 
   584     delete mViewManager; 
   530     qDebug("GlxStateManager::~GlxStateManager delete view manager");
   585     qDebug("GlxStateManager::~GlxStateManager delete view manager");
   531     delete mImageviewerMediaModel;
   586     
   532     GlxState *tmp;   
   587     GlxState *tmp;   
   533     while (mCurrentState) {
   588     while (mCurrentState) {
   534         tmp = mCurrentState;
   589         tmp = mCurrentState;
   535         mCurrentState = mCurrentState->previousState();
   590         mCurrentState = mCurrentState->previousState();
   536         delete tmp;        
   591         delete tmp;        
   537     }
   592     }
   538     disconnect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ) );
   593     
   539     qDebug("GlxStateManager::~GlxStateManager Exit");
   594     qDebug("GlxStateManager::~GlxStateManager Exit");
   540 }
   595 }
   541 
   596 
   542 void GlxStateManager::cleanupExternal()
   597 void GlxStateManager::cleanupExternal()
   543 {
   598 {