ui/viewmanagement/statehandler/src/glxstatemanager.cpp
changeset 45 863223ea6961
parent 44 aa2fa096cbfb
child 50 a0f57508af73
child 55 fb37077c270f
--- a/ui/viewmanagement/statehandler/src/glxstatemanager.cpp	Fri Jun 11 17:53:15 2010 +0530
+++ b/ui/viewmanagement/statehandler/src/glxstatemanager.cpp	Fri Jun 25 15:41:33 2010 +0530
@@ -22,6 +22,8 @@
 #include <hbnotificationdialog.h>
 #include <QProcess>
 #include <hbinstance.h>
+#include <HbActivityManager.h>
+#include <hbapplication.h>
 
 //user includes
 #include "glxstatemanager.h"
@@ -67,10 +69,12 @@
         mViewManager = new GlxViewManager();
     }
     mTNObserver = new GlxTNObserver();
+    mSaveActivity.clear();
     
     connect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ), Qt::QueuedConnection );
     connect ( mViewManager, SIGNAL(actionTriggered( qint32 )), this, SLOT(actionTriggered( qint32 )), Qt::QueuedConnection );
     connect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) );
+    connect ( qobject_cast<HbApplication*>(qApp), SIGNAL (aboutToQuit()), this, SLOT(saveData()));
 	//TO:DO TBD through exception when it is null
 }
 
@@ -121,12 +125,18 @@
 void GlxStateManager::launchApplication()
 {
     qDebug("GlxStateManager::launchApplication");   
-       
+     bool activitySuccess = false;  
     //To:Do use it in future once performance code is removed nextState(GLX_GRIDVIEW_ID, ALL_ITEM_S)
+     HbApplication* app = qobject_cast<HbApplication*>(qApp);
+     if(app->activateReason() == Hb::ActivationReasonActivity) {
+          activitySuccess = launchActivity();
+     }
+     if( !activitySuccess ) { 
     mCurrentState = createState( GLX_GRIDVIEW_ID );
     mCurrentState->setState( ALL_ITEM_S );
-       
-    if ( mTNObserver->getTNLeftCount() > 0 ) {
+    
+    int leftCount = mTNObserver->getTNLeftCount() ;
+    if (  leftCount > 0  ) {
         mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel);
         launchProgressDialog();
     }
@@ -136,6 +146,41 @@
     }
     
     mTNObserver->startTNObserving() ; 
+     }
+     //Remove the previous activity
+     HbActivityManager* activityManager = app->activityManager();
+     bool ok = activityManager->removeActivity("PhotosMainView");
+     if ( !ok )
+     {
+         qDebug("launchapplication::Remove activity failed" );
+     } 
+}
+bool GlxStateManager::launchActivity()
+{
+    HbApplication* app = qobject_cast<HbApplication*>(qApp);
+    bool ok = app->activityManager()->waitActivity();
+    if ( !ok )
+    {
+        qDebug("subscribing to activity manager failed" );
+        //return false;  TBD: waitActivity is always returning false. Could be some issue with AM.
+    }
+    QVariant data = app->activityManager()->activityData( "PhotosMainView" );
+    QByteArray serializedModel = data.toByteArray();
+    QDataStream stream(&serializedModel, QIODevice::ReadOnly);
+    //Fetch the data from the activity Manager
+    QMap<QString, qint32> fetchActivity;
+    stream >> fetchActivity;  
+    qint32 stateId = fetchActivity.value("ID");
+    mCurrentState = createState(stateId);
+    mCurrentState->setState( fetchActivity.value("InternalState") );
+    createModel( stateId);
+	/*Model might not be populated yet to set the visibleWindowIndex right away.
+	*So, let us store the visible index as a temporary Variable, so that  visible Window Index 
+	*is set once the model is populated.
+    */
+    mCurrentModel->setData(QModelIndex(), fetchActivity.value("VisibleIndex") , GlxTempVisualWindowIndex );
+    mViewManager->launchApplication(stateId, mCurrentModel); 
+    return true;
 }
 
 void GlxStateManager::launchFromExternal()
@@ -171,10 +216,12 @@
 void GlxStateManager::updateTNProgress( int count)
 {    
     TRACER("GlxStateManager::updateTNProgress() ");
-    // this is case when progress bar is not showing
-    // in the case of rename of an image or capture the single item
-    // it is also launching the progress bar, to avoid this scenario add the check of count more than 5
-    if ( mCurrentModel && count > 5 ) { 
+// mCurrentModel ------------this is case when progress bar is not showing
+// count > 5 ----------------in the case of rename of an image or capture the single item
+//                           it is also launching the progress bar, to avoid this scenario add the check of count more than 5
+// count == KErrNotReady ----A case when memory card is inserted but it is not harvest so it is given an error
+//                           In that case also user should be block to browse the images
+    if ( mCurrentModel && ( count > 5  ) ) { 
          goBack( GLX_GRIDVIEW_ID, ALL_ITEM_S ) ;
          cleanAllModel();
          launchProgressDialog();
@@ -189,9 +236,46 @@
         else {
             mViewManager->updateProgressDialog( count );
         }
+    }   
+}
+
+void GlxStateManager::saveData()
+{
+    if( (mCurrentState->id() == GLX_GRIDVIEW_ID && mCurrentState->state() == ALL_ITEM_S) || mCurrentState->id() == GLX_LISTVIEW_ID ) {
+    mSaveActivity.insert("ID",mCurrentState->id()); 
+    mSaveActivity.insert("InternalState",mCurrentState->state());
+    
+    //Store the visual Index
+    if(mCurrentModel)
+    {
+    	QVariant variant = mCurrentModel->data( mCurrentModel->index(0,0), GlxVisualWindowIndex );
+    	if ( variant.isValid() &&  variant.canConvert<int> () ) {
+         mSaveActivity.insert("VisibleIndex",variant.value<int>());
+    	}
+ 		}
+ 		else
+ 			   mSaveActivity.insert("VisibleIndex",0);
+ 			   
+    HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
+    
+    //Take a screenshot
+    QVariantHash metadata;
+    HbMainWindow *window = hbInstance->allMainWindows().first();
+    metadata.insert("screenshot", QPixmap::grabWidget(window, window->rect()));
+
+     QByteArray serializedModel;
+     QDataStream stream(&serializedModel, QIODevice::WriteOnly | QIODevice::Append);
+     stream << mSaveActivity;
+     //Add the activity
+    bool ok = activityManager->addActivity("PhotosMainView", serializedModel, metadata);
+     if ( !ok )
+     {
+        qDebug("SaveData::Add activity failed" );
     }
+   }
 }
 
+
 void GlxStateManager::nextState(qint32 state, int internalState)
 {
     qDebug("GlxStateManager::nextState next state = %u", state);
@@ -226,7 +310,7 @@
 
     if ( mCurrentState->previousState() == NULL ) { //In the case only one state in stack then exit from the application
         exitApplication() ;
-        mCurrentState = NULL;
+        return ;
     }
     else {
         //effect parameter should be set here other wise there is no way to know from where it come from
@@ -618,13 +702,11 @@
 
 void GlxStateManager::exitApplication()
 {
-    if ( mCurrentState->id( ) == GLX_FULLSCREENVIEW_ID && mCurrentState->state() == EXTERNAL_S ) {
-        emit externalCommand(EGlxPluginCmdBack);
-    }
-    else {
+    
+    
     //To:Do memory cleanup
         QApplication::quit();
-    }    
+     
 }
 
 GlxStateManager::~GlxStateManager()
@@ -638,6 +720,7 @@
     disconnect ( mViewManager, SIGNAL(externalCommand(int )), this, SIGNAL(externalCommand(int )) );
     disconnect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) );
     disconnect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ) );
+    disconnect ( qobject_cast<HbApplication*>(qApp), SIGNAL (aboutToQuit()), this, SLOT(saveData()));
     
     delete mTNObserver;
     delete mViewManager;