photosgallery/viewframework/commandhandlers/commandhandlerbase/src/glxmpxcommandcommandhandler.cpp
branchRCL_3
changeset 24 ea65f74e6de4
parent 23 b023a8d2866a
--- a/photosgallery/viewframework/commandhandlers/commandhandlerbase/src/glxmpxcommandcommandhandler.cpp	Thu Jul 15 18:39:01 2010 +0300
+++ b/photosgallery/viewframework/commandhandlers/commandhandlerbase/src/glxmpxcommandcommandhandler.cpp	Thu Aug 19 09:55:03 2010 +0300
@@ -43,9 +43,12 @@
 #include <glxcommandhandlers.hrh>
 #include <glxtracer.h>
 #include <glxresourceutilities.h>                // for CGlxResourceUtilities
+#include <glxnavigationalstate.h>
+#include <mpxcollectionpath.h>
+#include <glxcollectionpluginimageviewer.hrh>
+#include <glximageviewermanager.h>
+#include <caf/manager.h>
 
-/// @todo Move elsewhere
-const TInt KGlxMaxNoteLength = 256;
 
 // -----------------------------------------------------------------------------
 // ConstructL
@@ -120,40 +123,85 @@
 
     if ( consume )
         {
-        // get a command object from the deriving class.
-        // Allow deriving class modify the consume value, even without 
-        // creating a commmand (in case it wants to filter out a command)
-        CMPXCommand* command = CreateCommandL(aCommandId, aList, consume);
-        
-        if (command)
+        CGlxNavigationalState* navState = CGlxNavigationalState::InstanceL();
+		CleanupClosePushL(*navState);
+        CMPXCollectionPath* path = navState->StateLC();
+        CreateImageViewerInstanceL();
+        TBool privatePath = iImageViewerInstance->IsPrivate();
+        TBool viewerPathId = (path->Id() == TMPXItemId(KGlxCollectionPluginImageViewerImplementationUid)) ? ETrue : EFalse;
+        iImageViewerInstance->CloseImageDecoder();
+        DeleteImageViewerInstance();
+        CleanupStack::PopAndDestroy(path);
+        CleanupStack::PopAndDestroy(navState);
+	 		
+        if (viewerPathId && !privatePath)
             {
-            CleanupStack::PushL(command);
-            
-            if ( CommandInfo(aCommandId).iStopAnimationForExecution )
+            RFs fs;
+			CleanupClosePushL(fs);
+            User::LeaveIfError(fs.Connect());
+			ContentAccess::CManager *manager = ContentAccess::CManager::NewL();
+			CleanupStack::PushL(manager);
+			fs.SetAtt(focusedMedia.Uri(), 0, KEntryAttReadOnly);		
+            TInt ret = manager->DeleteFile(focusedMedia.Uri());
+            if(ret != KErrNone)
                 {
-                // Stop GIF animation
-                iAppUi->ProcessCommandL(EGlxCmdDisableAnimations);
-                iAnimationStopped = ETrue;
+				CreateImageViewerInstanceL();
+				iImageViewerInstance->CreateImageDecoderL();
+				DeleteImageViewerInstance();
+                HBufC* noteText = StringLoader::LoadL(R_GLX_DELETION_FAILURE_NOTE);
+                CleanupStack::PushL(noteText);
+                const TDesC& itemName = focusedMedia.Uri();
+                TParsePtrC parse(focusedMedia.Uri());
+                TBuf<KMaxFileName> text;
+                StringLoader::Format(text, *noteText, -1, parse.Name());
+                GlxGeneralUiUtilities::ShowErrorNoteL(text, ETrue);
+                CleanupStack::PopAndDestroy(noteText);
+                }
+            CleanupStack::PopAndDestroy(manager);
+            CleanupStack::PopAndDestroy(&fs);
+            if(ret == KErrNone)
+                {
+                iAppUi->ProcessCommandL(EAknSoftkeyExit);
                 }
-            
-            // Add the pointer of this command handler as session id into the message
-            // This can be used to ensure that this object is the intended recipient
-            // of a message
-            command->SetTObjectValueL<TAny*>(KMPXCommandGeneralSessionId,
-            		static_cast<TAny*>(this));
+            }
+        else
+            {
+            // get a command object from the deriving class.
+            // Allow deriving class modify the consume value, even without 
+            // creating a commmand (in case it wants to filter out a command)
+            CMPXCommand* command = CreateCommandL(aCommandId, aList, consume);
+
+            if (command)
+                {
+                CleanupStack::PushL(command);
+
+                if (CommandInfo(aCommandId).iStopAnimationForExecution)
+                    {
+                    // Stop GIF animation
+                    iAppUi->ProcessCommandL(EGlxCmdDisableAnimations);
+                    iAnimationStopped = ETrue;
+                    }
 
-       		aList.AddMediaListObserverL(this);
-			
-            aList.CommandL(*command);
-            
-            // raise progress note. Note will be closed when complete message received
-			// For EGlxCmdAddMedia we dont need to show dialog as EGlxCmdAddToAlbum or
-			// EGlxCmdAddTag will show processing dialog.
-            if (aCommandId != EGlxCmdAddMedia)
-                {
-                ProgressNoteL(aCommandId);
+                // Add the pointer of this command handler as session id into the message
+                // This can be used to ensure that this object is the intended recipient
+                // of a message
+                command->SetTObjectValueL<TAny*> (
+                        KMPXCommandGeneralSessionId,
+                        static_cast<TAny*> (this));
+
+                aList.AddMediaListObserverL(this);
+
+                aList.CommandL(*command);
+
+                // raise progress note. Note will be closed when complete message received
+                // For EGlxCmdAddMedia we dont need to show dialog as EGlxCmdAddToAlbum or
+                // EGlxCmdAddTag will show processing dialog.
+                if (aCommandId != EGlxCmdAddMedia)
+                    {
+                    ProgressNoteL(aCommandId);
+                    }
+                CleanupStack::PopAndDestroy(command);
                 }
-            CleanupStack::PopAndDestroy(command);
             }
         }
     
@@ -381,7 +429,7 @@
             // noteText has a place for a title string in it
             const TDesC& itemName = media->ValueText(KMPXMediaGeneralTitle);
     
-            TBuf<KGlxMaxNoteLength> text;
+            TBuf<KMaxFileName> text;
             StringLoader::Format(text, *noteText, -1, itemName);
     
             // show popup
@@ -416,7 +464,7 @@
         // item count
 		TInt count = aMediaList.SelectionCount();
 
-        TBuf<KGlxMaxNoteLength> text;
+        TBuf<KMaxFileName> text;
 		GlxGeneralUiUtilities::FormatString(text, *noteText, -1, count, ETrue);
 		
         // show popup
@@ -699,3 +747,27 @@
         TRAP_IGNORE(DismissProgressNoteL());
         }
     }
+
+// -----------------------------------------------------------------------------
+// CreateImageViewerInstanceL
+// -----------------------------------------------------------------------------
+//
+void CGlxMpxCommandCommandHandler::CreateImageViewerInstanceL()
+    {
+    TRACER("CGlxMpxCommandCommandHandler::CreateImageViewerInstanceL");
+    iImageViewerInstance = CGlxImageViewerManager::InstanceL();    
+    __ASSERT_ALWAYS(iImageViewerInstance, Panic(EGlxPanicNullPointer));
+    }
+
+// -----------------------------------------------------------------------------
+// DeleteImageViewerInstance
+// -----------------------------------------------------------------------------
+//
+void CGlxMpxCommandCommandHandler::DeleteImageViewerInstance()
+    {
+    TRACER("CGlxMpxCommandCommandHandler::DeleteImageViewerInstance");
+    if ( iImageViewerInstance )
+        {
+        iImageViewerInstance->DeleteInstance();
+        }
+    }