ui/viewmanagement/statehandler/src/glxstatemanager.cpp
changeset 55 fb37077c270f
parent 49 f291796e213d
child 70 a91aa46552be
--- a/ui/viewmanagement/statehandler/src/glxstatemanager.cpp	Tue Jul 06 14:16:16 2010 +0300
+++ b/ui/viewmanagement/statehandler/src/glxstatemanager.cpp	Wed Aug 18 09:48:53 2010 +0300
@@ -51,7 +51,7 @@
 #include "glxplugincommandid.hrh"
 #include "glxlog.h"
 #include "glxtracer.h"
-
+#include <glximageviewermanager.h>
 
 GlxStateManager::GlxStateManager() 
     : mAllMediaModel( NULL ), 
@@ -69,7 +69,6 @@
         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 );
@@ -122,39 +121,50 @@
     return QObject::eventFilter(obj, event);
 }
 
+void GlxStateManager::launchFetcher()
+{
+    qDebug("GlxStateManager::launchFetcher");
+    mCurrentState = createState(GLX_GRIDVIEW_ID);
+    mCurrentState->setState(FETCHER_ITEM_S);
+    
+    createModel(GLX_GRIDVIEW_ID);
+    mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel);
+}
+
 void GlxStateManager::launchApplication()
 {
     qDebug("GlxStateManager::launchApplication");   
-     bool activitySuccess = false;  
+    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 );
-    
-    int leftCount = mTNObserver->getTNLeftCount() ;
-    if (  leftCount > 0  ) {
-        mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel);
-        launchProgressDialog();
-    }
-    else {
-        createModel( GLX_GRIDVIEW_ID );
-        mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel);
+    HbApplication* app = qobject_cast<HbApplication*>(qApp);
+    if(app->activateReason() == Hb::ActivationReasonActivity) {
+        activitySuccess = launchActivity();
     }
     
-    mTNObserver->startTNObserving() ; 
-     }
-     //Remove the previous activity
-     HbActivityManager* activityManager = app->activityManager();
-     bool ok = activityManager->removeActivity("PhotosMainView");
-     if ( !ok )
-     {
+    if( !activitySuccess ) { 
+        mCurrentState = createState( GLX_GRIDVIEW_ID );
+        mCurrentState->setState( ALL_ITEM_S );
+       
+        int leftCount = mTNObserver->getTNLeftCount() ;
+        if (  leftCount > 0  ) {
+            mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel );
+            launchProgressDialog();
+        }
+        else {
+            createModel( GLX_GRIDVIEW_ID );
+            mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel );
+        }    
+        mTNObserver->startTNObserving() ; 
+    }
+    
+    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);
@@ -162,30 +172,29 @@
     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");
+    stream >> mSaveActivity;  
+    qint32 stateId = mSaveActivity.value("ID");
     mCurrentState = createState(stateId);
-    mCurrentState->setState( fetchActivity.value("InternalState") );
+    mCurrentState->setState( mSaveActivity.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 );
+    mCurrentModel->setData(QModelIndex(), mSaveActivity.value("VisibleIndex") , GlxTempVisualWindowIndex );
     mViewManager->launchApplication(stateId, mCurrentModel); 
     return true;
 }
 
 void GlxStateManager::launchFromExternal()
 {
-    qDebug("GlxStateManager::launchApplication");
+    qDebug("GlxStateManager::launchFromExternal");
     mCurrentState = createState(GLX_FULLSCREENVIEW_ID);
     mCurrentState->setState(IMAGEVIEWER_S);
     
@@ -210,17 +219,23 @@
     mActionHandler = new GlxActionHandler();
     connect ( mViewManager, SIGNAL(externalCommand(int )), this, SIGNAL(externalCommand(int )) );
     mViewManager->setupItems();
-    mViewManager->updateToolBarIcon(GLX_ALL_ACTION_ID);
+    switch( mSaveActivity.value( "ID" ) ){
+        case GLX_LISTVIEW_ID:
+            mViewManager->updateToolBarIcon(GLX_ALBUM_ACTION_ID);
+            break;
+            
+        case GLX_GRIDVIEW_ID:
+        default:
+            mViewManager->updateToolBarIcon(GLX_ALL_ACTION_ID);
+    }
 }
 
 void GlxStateManager::updateTNProgress( int count)
 {    
     TRACER("GlxStateManager::updateTNProgress() ");
-// 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
+    // 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  ) ) { 
          goBack( GLX_GRIDVIEW_ID, ALL_ITEM_S ) ;
          cleanAllModel();
@@ -229,8 +244,6 @@
     
     if ( isProgressbarRunning ){
         if ( count == 0 ) {
-            createModel( mCurrentState->id() );
-            mViewManager->setModel( mCurrentModel );
             vanishProgressDialog();
         }
         else {
@@ -239,43 +252,46 @@
     }   
 }
 
+void GlxStateManager::thumbnailPopulated()
+{
+    mViewManager->setModel( mCurrentModel );
+    isProgressbarRunning = false;
+    mViewManager->updateProgressDialog( 0 );  
+    disconnect ( mCurrentModel, SIGNAL( thumbnailPopulated() ), this, SLOT( thumbnailPopulated() ) );
+}
+
 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>());
-    	}
+        mSaveActivity.insert("ID",mCurrentState->id()); 
+        mSaveActivity.insert("InternalState",mCurrentState->state());
+        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();
+ 		else {
+ 			mSaveActivity.insert("VisibleIndex",0);
+ 		}
     
-    //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" );
+        HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
+        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;
+        
+        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);
@@ -309,6 +325,7 @@
     GlxState *state = mCurrentState; // To delete the current state later  
 
     if ( mCurrentState->previousState() == NULL ) { //In the case only one state in stack then exit from the application
+        saveImage(); // save image if it is in private folder
         exitApplication() ;
         return ;
     }
@@ -327,7 +344,34 @@
     }
     delete state;
 }
-   
+
+void GlxStateManager::saveImage()
+    {
+    CGlxImageViewerManager *imageViewerInstance = CGlxImageViewerManager::InstanceL();
+    if(imageViewerInstance->IsPrivate())
+        {
+        HBufC* imagePath = imageViewerInstance->ImageUri();
+		QString srcPath = QString::fromUtf16(imagePath->Des().Ptr(),imagePath->Length());
+		QString imageName = srcPath.section('\\', -1);
+		QString imagesFolderPath("c:/data/images/");
+		QString destPath;
+		destPath.append(imagesFolderPath);
+		destPath.append(imageName);
+		int cnt = 1;
+		qDebug() << "GlxStateManager::saveImage path before while = "<< destPath;
+		while(!QFile::copy(srcPath,destPath))
+			{
+			QString filename = imageName.section('.', 0,0);
+			QString ext = imageName.section('.', -1);
+			destPath.clear();
+			destPath = imagesFolderPath + filename + QString::number(cnt) + "." + ext;
+			qDebug() << "GlxStateManager::saveImage path = "<< destPath;
+			cnt++;
+			}
+        }
+    imageViewerInstance->Close();
+    }
+	
 void GlxStateManager::goBack(qint32 stateId, int internalState)
 {
     qDebug("GlxStateManager::goBack()");
@@ -428,23 +472,23 @@
 void GlxStateManager::launchProgressDialog()
 {
     TRACER("GlxStateManager::launchProgressDialog() ");
-    //HbMainWindow *window = hbInstance->allMainWindows().first();
-    //window->setAutomaticOrientationEffectEnabled( true );
     
     QCoreApplication::instance()->installEventFilter( this );
-    mViewManager->launchProgressDialog( mTNObserver->getTNLeftCount() );
+    if ( isProgressbarRunning ) {
+        mViewManager->updateProgressDialog( mTNObserver->getTNLeftCount() );
+    }
+    else {
+        mViewManager->launchProgressDialog( mTNObserver->getTNLeftCount() );
+    }
     isProgressbarRunning = true ;
 }
 
 void GlxStateManager::vanishProgressDialog()
 {
     TRACER("GlxStateManager::vanishProgressDialog() ");
-    //HbMainWindow *window = hbInstance->allMainWindows().first();
-    //window->setAutomaticOrientationEffectEnabled( false );
-    
     QCoreApplication::instance()->removeEventFilter( this );
-    isProgressbarRunning = false;
-    mViewManager->updateProgressDialog( 0 );    
+    createModel( mCurrentState->id() );
+    connect ( mCurrentModel, SIGNAL( thumbnailPopulated() ), this, SLOT( thumbnailPopulated() ) );
 }
 
 GlxState * GlxStateManager::createState(qint32 stateId)
@@ -459,7 +503,7 @@
         return new GlxListState( mCurrentState );    	
     	
     case GLX_FULLSCREENVIEW_ID :
-        return new GlxFullScreenState( mCurrentState );
+        return new GlxFullScreenState( this, mCurrentState );
         
     case GLX_DETAILSVIEW_ID:
         return new GlxDetailState( mCurrentState );
@@ -544,6 +588,7 @@
     
     switch( internalState) {
     case ALL_ITEM_S :
+	case FETCHER_ITEM_S:
         if ( mAllMediaModel == NULL ) {
             modelParm.setCollection( KGlxCollectionPluginAllImplementationUid );
             modelParm.setDepth(0);
@@ -556,6 +601,7 @@
         break;
         
     case ALBUM_ITEM_S :
+    case FETCHER_ALBUM_ITEM_S :    
         if ( dir != BACKWARD_DIR ) { 
             modelParm.setCollection( KGlxAlbumsMediaId );
             modelParm.setDepth(0);
@@ -592,17 +638,30 @@
         changeState( GLX_GRIDVIEW_ID, ALL_ITEM_S );
         id = EGlxCmdHandled;
         break;
+
+    case EGlxCmdFetcherAllGridOpen :
+        changeState( GLX_GRIDVIEW_ID, FETCHER_ITEM_S );
+        id = EGlxCmdHandled;
+        break;
     	
     case EGlxCmdAlbumListOpen:
         changeState( GLX_LISTVIEW_ID, -1 );
         id = EGlxCmdHandled;
         break;
-    	
+    case EGlxCmdFetcherAlbumListOpen:
+        changeState( GLX_LISTVIEW_ID, FETCHER_ALBUM_S );
+        id = EGlxCmdHandled;
+        break;
+        
     case EGlxCmdAlbumGridOpen:
         nextState( GLX_GRIDVIEW_ID, ALBUM_ITEM_S );
         id = EGlxCmdHandled;
         break;
-      
+    case EGlxCmdFetcherAlbumGridOpen:
+        nextState( GLX_GRIDVIEW_ID, FETCHER_ALBUM_ITEM_S );
+        id = EGlxCmdHandled;
+        break;
+        
     case EGlxCmdFirstSlideshow :
         //play the slide show with first item
         mCurrentModel->setData( mCurrentModel->index(0, 0), 0, GlxFocusIndexRole );
@@ -645,6 +704,7 @@
     }
     	
     case EGlxCmdBack :
+    case EGlxCmdSlideShowBack :
     	previousState();
     	id = EGlxCmdHandled;
     	break;
@@ -684,17 +744,28 @@
 		}
         break;
         
-   case EGlxCmdMarkAll:
-   case EGlxCmdUnMarkAll:
-       mViewManager->handleUserAction(mCurrentState->id(), id);
+   case EGlxCmdMarkAll :
+   case EGlxCmdUnMarkAll :
+   case EGlxCmd3DEffectOn :
+   case EGlxCmd3DEffectOff :
+   case EGlxCmdPlayBackAnim :
+       mViewManager->handleUserAction( mCurrentState->id(), id );
        id = EGlxCmdHandled;
        break;
        
    case EGlxCmdSetupItem :
        emit setupItemsSignal();
        break;
+   
+   case EGlxCmdFetcherSelect: 
+       {
+       QModelIndex selectedIndex = mCurrentModel->index(mCurrentModel->data(mCurrentModel->index(0,0),GlxFocusIndexRole).value<int>(),0);
+       emit gridItemSelected(selectedIndex,*mCurrentModel);
+       id = EGlxCmdHandled;
+       }
+       break;
        
-    default :
+   default :
         mActionHandler->handleAction(id,mCollectionId);
     	break;
     }	
@@ -713,6 +784,7 @@
 {
     qDebug("GlxStateManager::~GlxStateManager");
     cleanAllModel();
+    mSaveActivity.clear();
     delete mActionHandler;
     qDebug("GlxStateManager::~GlxStateManager delete Model");