ui/viewmanagement/statehandler/src/glxstatemanager.cpp
changeset 49 f291796e213d
parent 48 d0b4e67b3a60
child 50 a0f57508af73
child 55 fb37077c270f
equal deleted inserted replaced
48:d0b4e67b3a60 49:f291796e213d
    20 #include <QDebug>
    20 #include <QDebug>
    21 #include <QItemSelectionModel>
    21 #include <QItemSelectionModel>
    22 #include <hbnotificationdialog.h>
    22 #include <hbnotificationdialog.h>
    23 #include <QProcess>
    23 #include <QProcess>
    24 #include <hbinstance.h>
    24 #include <hbinstance.h>
       
    25 #include <HbActivityManager.h>
       
    26 #include <hbapplication.h>
    25 
    27 
    26 //user includes
    28 //user includes
    27 #include "glxstatemanager.h"
    29 #include "glxstatemanager.h"
    28 #include "glxviewmanager.h"
    30 #include "glxviewmanager.h"
    29 #include "glxviewids.h"
    31 #include "glxviewids.h"
    65     qDebug("GlxStateManager::GlxStateManager");
    67     qDebug("GlxStateManager::GlxStateManager");
    66     PERFORMANCE_ADV ( d1, "view manager creation time") {
    68     PERFORMANCE_ADV ( d1, "view manager creation time") {
    67         mViewManager = new GlxViewManager();
    69         mViewManager = new GlxViewManager();
    68     }
    70     }
    69     mTNObserver = new GlxTNObserver();
    71     mTNObserver = new GlxTNObserver();
       
    72     mSaveActivity.clear();
    70     
    73     
    71     connect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ), Qt::QueuedConnection );
    74     connect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ), Qt::QueuedConnection );
    72     connect ( mViewManager, SIGNAL(actionTriggered( qint32 )), this, SLOT(actionTriggered( qint32 )), Qt::QueuedConnection );
    75     connect ( mViewManager, SIGNAL(actionTriggered( qint32 )), this, SLOT(actionTriggered( qint32 )), Qt::QueuedConnection );
    73     connect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) );
    76     connect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) );
       
    77     connect ( qobject_cast<HbApplication*>(qApp), SIGNAL (aboutToQuit()), this, SLOT(saveData()));
    74 	//TO:DO TBD through exception when it is null
    78 	//TO:DO TBD through exception when it is null
    75 }
    79 }
    76 
    80 
    77 void GlxStateManager::enterMarkingMode()
    81 void GlxStateManager::enterMarkingMode()
    78 {
    82 {
   119 }
   123 }
   120 
   124 
   121 void GlxStateManager::launchApplication()
   125 void GlxStateManager::launchApplication()
   122 {
   126 {
   123     qDebug("GlxStateManager::launchApplication");   
   127     qDebug("GlxStateManager::launchApplication");   
   124        
   128      bool activitySuccess = false;  
   125     //To:Do use it in future once performance code is removed nextState(GLX_GRIDVIEW_ID, ALL_ITEM_S)
   129     //To:Do use it in future once performance code is removed nextState(GLX_GRIDVIEW_ID, ALL_ITEM_S)
       
   130      HbApplication* app = qobject_cast<HbApplication*>(qApp);
       
   131      if(app->activateReason() == Hb::ActivationReasonActivity) {
       
   132           activitySuccess = launchActivity();
       
   133      }
       
   134      if( !activitySuccess ) { 
   126     mCurrentState = createState( GLX_GRIDVIEW_ID );
   135     mCurrentState = createState( GLX_GRIDVIEW_ID );
   127     mCurrentState->setState( ALL_ITEM_S );
   136     mCurrentState->setState( ALL_ITEM_S );
   128        
   137     
   129     if ( mTNObserver->getTNLeftCount() > 0 ) {
   138     int leftCount = mTNObserver->getTNLeftCount() ;
       
   139     if (  leftCount > 0  ) {
   130         mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel);
   140         mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel);
   131         launchProgressDialog();
   141         launchProgressDialog();
   132     }
   142     }
   133     else {
   143     else {
   134         createModel( GLX_GRIDVIEW_ID );
   144         createModel( GLX_GRIDVIEW_ID );
   135         mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel);
   145         mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel);
   136     }
   146     }
   137     
   147     
   138     mTNObserver->startTNObserving() ; 
   148     mTNObserver->startTNObserving() ; 
       
   149      }
       
   150      //Remove the previous activity
       
   151      HbActivityManager* activityManager = app->activityManager();
       
   152      bool ok = activityManager->removeActivity("PhotosMainView");
       
   153      if ( !ok )
       
   154      {
       
   155          qDebug("launchapplication::Remove activity failed" );
       
   156      } 
       
   157 }
       
   158 bool GlxStateManager::launchActivity()
       
   159 {
       
   160     HbApplication* app = qobject_cast<HbApplication*>(qApp);
       
   161     bool ok = app->activityManager()->waitActivity();
       
   162     if ( !ok )
       
   163     {
       
   164         qDebug("subscribing to activity manager failed" );
       
   165         //return false;  TBD: waitActivity is always returning false. Could be some issue with AM.
       
   166     }
       
   167     QVariant data = app->activityManager()->activityData( "PhotosMainView" );
       
   168     QByteArray serializedModel = data.toByteArray();
       
   169     QDataStream stream(&serializedModel, QIODevice::ReadOnly);
       
   170     //Fetch the data from the activity Manager
       
   171     QMap<QString, qint32> fetchActivity;
       
   172     stream >> fetchActivity;  
       
   173     qint32 stateId = fetchActivity.value("ID");
       
   174     mCurrentState = createState(stateId);
       
   175     mCurrentState->setState( fetchActivity.value("InternalState") );
       
   176     createModel( stateId);
       
   177 	/*Model might not be populated yet to set the visibleWindowIndex right away.
       
   178 	*So, let us store the visible index as a temporary Variable, so that  visible Window Index 
       
   179 	*is set once the model is populated.
       
   180     */
       
   181     mCurrentModel->setData(QModelIndex(), fetchActivity.value("VisibleIndex") , GlxTempVisualWindowIndex );
       
   182     mViewManager->launchApplication(stateId, mCurrentModel); 
       
   183     return true;
   139 }
   184 }
   140 
   185 
   141 void GlxStateManager::launchFromExternal()
   186 void GlxStateManager::launchFromExternal()
   142 {
   187 {
   143     qDebug("GlxStateManager::launchApplication");
   188     qDebug("GlxStateManager::launchApplication");
   169 }
   214 }
   170 
   215 
   171 void GlxStateManager::updateTNProgress( int count)
   216 void GlxStateManager::updateTNProgress( int count)
   172 {    
   217 {    
   173     TRACER("GlxStateManager::updateTNProgress() ");
   218     TRACER("GlxStateManager::updateTNProgress() ");
   174     // this is case when progress bar is not showing
   219 // mCurrentModel ------------this is case when progress bar is not showing
   175     // in the case of rename of an image or capture the single item
   220 // count > 5 ----------------in the case of rename of an image or capture the single item
   176     // it is also launching the progress bar, to avoid this scenario add the check of count more than 5
   221 //                           it is also launching the progress bar, to avoid this scenario add the check of count more than 5
   177     if ( mCurrentModel && count > 5 ) { 
   222 // count == KErrNotReady ----A case when memory card is inserted but it is not harvest so it is given an error
       
   223 //                           In that case also user should be block to browse the images
       
   224     if ( mCurrentModel && ( count > 5  ) ) { 
   178          goBack( GLX_GRIDVIEW_ID, ALL_ITEM_S ) ;
   225          goBack( GLX_GRIDVIEW_ID, ALL_ITEM_S ) ;
   179          cleanAllModel();
   226          cleanAllModel();
   180          launchProgressDialog();
   227          launchProgressDialog();
   181     }
   228     }
   182     
   229     
   187             vanishProgressDialog();
   234             vanishProgressDialog();
   188         }
   235         }
   189         else {
   236         else {
   190             mViewManager->updateProgressDialog( count );
   237             mViewManager->updateProgressDialog( count );
   191         }
   238         }
   192     }
   239     }   
   193 }
   240 }
       
   241 
       
   242 void GlxStateManager::saveData()
       
   243 {
       
   244     if( (mCurrentState->id() == GLX_GRIDVIEW_ID && mCurrentState->state() == ALL_ITEM_S) || mCurrentState->id() == GLX_LISTVIEW_ID ) {
       
   245     mSaveActivity.insert("ID",mCurrentState->id()); 
       
   246     mSaveActivity.insert("InternalState",mCurrentState->state());
       
   247     
       
   248     //Store the visual Index
       
   249     if(mCurrentModel)
       
   250     {
       
   251     	QVariant variant = mCurrentModel->data( mCurrentModel->index(0,0), GlxVisualWindowIndex );
       
   252     	if ( variant.isValid() &&  variant.canConvert<int> () ) {
       
   253          mSaveActivity.insert("VisibleIndex",variant.value<int>());
       
   254     	}
       
   255  		}
       
   256  		else
       
   257  			   mSaveActivity.insert("VisibleIndex",0);
       
   258  			   
       
   259     HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
       
   260     
       
   261     //Take a screenshot
       
   262     QVariantHash metadata;
       
   263     HbMainWindow *window = hbInstance->allMainWindows().first();
       
   264     metadata.insert("screenshot", QPixmap::grabWidget(window, window->rect()));
       
   265 
       
   266      QByteArray serializedModel;
       
   267      QDataStream stream(&serializedModel, QIODevice::WriteOnly | QIODevice::Append);
       
   268      stream << mSaveActivity;
       
   269      //Add the activity
       
   270     bool ok = activityManager->addActivity("PhotosMainView", serializedModel, metadata);
       
   271      if ( !ok )
       
   272      {
       
   273         qDebug("SaveData::Add activity failed" );
       
   274     }
       
   275    }
       
   276 }
       
   277 
   194 
   278 
   195 void GlxStateManager::nextState(qint32 state, int internalState)
   279 void GlxStateManager::nextState(qint32 state, int internalState)
   196 {
   280 {
   197     qDebug("GlxStateManager::nextState next state = %u", state);
   281     qDebug("GlxStateManager::nextState next state = %u", state);
   198     GlxEffect effect = NO_EFFECT ;
   282     GlxEffect effect = NO_EFFECT ;
   224 
   308 
   225     GlxState *state = mCurrentState; // To delete the current state later  
   309     GlxState *state = mCurrentState; // To delete the current state later  
   226 
   310 
   227     if ( mCurrentState->previousState() == NULL ) { //In the case only one state in stack then exit from the application
   311     if ( mCurrentState->previousState() == NULL ) { //In the case only one state in stack then exit from the application
   228         exitApplication() ;
   312         exitApplication() ;
   229         mCurrentState = NULL;
   313         return ;
   230     }
   314     }
   231     else {
   315     else {
   232         //effect parameter should be set here other wise there is no way to know from where it come from
   316         //effect parameter should be set here other wise there is no way to know from where it come from
   233         mCurrentState->setTranstionParameter( BACKWARD_DIR, effect, viewEffect);
   317         mCurrentState->setTranstionParameter( BACKWARD_DIR, effect, viewEffect);
   234         mCurrentState = mCurrentState->previousState(); //get the pervious state
   318         mCurrentState = mCurrentState->previousState(); //get the pervious state
   616     }	
   700     }	
   617 }
   701 }
   618 
   702 
   619 void GlxStateManager::exitApplication()
   703 void GlxStateManager::exitApplication()
   620 {
   704 {
   621     if ( mCurrentState->id( ) == GLX_FULLSCREENVIEW_ID && mCurrentState->state() == EXTERNAL_S ) {
   705     
   622         emit externalCommand(EGlxPluginCmdBack);
   706     
   623     }
       
   624     else {
       
   625     //To:Do memory cleanup
   707     //To:Do memory cleanup
   626         QApplication::quit();
   708         QApplication::quit();
   627     }    
   709      
   628 }
   710 }
   629 
   711 
   630 GlxStateManager::~GlxStateManager()
   712 GlxStateManager::~GlxStateManager()
   631 {
   713 {
   632     qDebug("GlxStateManager::~GlxStateManager");
   714     qDebug("GlxStateManager::~GlxStateManager");
   636     
   718     
   637     disconnect ( mViewManager, SIGNAL(actionTriggered(qint32 )), this, SLOT(actionTriggered(qint32 )) );
   719     disconnect ( mViewManager, SIGNAL(actionTriggered(qint32 )), this, SLOT(actionTriggered(qint32 )) );
   638     disconnect ( mViewManager, SIGNAL(externalCommand(int )), this, SIGNAL(externalCommand(int )) );
   720     disconnect ( mViewManager, SIGNAL(externalCommand(int )), this, SIGNAL(externalCommand(int )) );
   639     disconnect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) );
   721     disconnect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) );
   640     disconnect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ) );
   722     disconnect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ) );
       
   723     disconnect ( qobject_cast<HbApplication*>(qApp), SIGNAL (aboutToQuit()), this, SLOT(saveData()));
   641     
   724     
   642     delete mTNObserver;
   725     delete mTNObserver;
   643     delete mViewManager; 
   726     delete mViewManager; 
   644     qDebug("GlxStateManager::~GlxStateManager delete view manager");
   727     qDebug("GlxStateManager::~GlxStateManager delete view manager");
   645     
   728