photosgallery/viewframework/commandhandlers/commoncommandhandlers/src/glxcommandhandleraddtocontainer.cpp
changeset 0 4e91876724a2
child 2 7d9067c6fcb1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/photosgallery/viewframework/commandhandlers/commoncommandhandlers/src/glxcommandhandleraddtocontainer.cpp	Thu Dec 17 08:45:44 2009 +0200
@@ -0,0 +1,301 @@
+/*
+* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:    Add to container command handler
+*
+*/
+
+
+
+
+/**
+ * @internal reviewed 05/06/2007 by Dave Schofield
+ */
+
+#include "glxcommandhandleraddtocontainer.h"
+
+#include <AknUtils.h>
+#include <bautils.h>
+#include <data_caging_path_literals.hrh>
+#include <eikmenup.h> 
+#include <glxcollectionpluginalbums.hrh>
+#include <glxcollectionplugintags.hrh>
+#include <glxcommandfactory.h>
+#include <glxcommandhandlers.hrh>
+#include <glxfilterfactory.h>
+#include <glxuiutility.h>
+#include <glxuistd.h>
+#include <glxresourceutilities.h>                // for CGlxResourceUtilities
+#include <glxuiutilities.rsg>
+#include <mglxmedialist.h>
+
+#include <mpxcollectioncommanddefs.h>
+#include <mpxcollectionpath.h>
+#include <mpxcommandgeneraldefs.h>
+#include <mpxmediaarray.h>
+#include <mpxmediacontainerdefs.h>
+#include <StringLoader.h>
+
+#include "glxmediaselectionpopup.h"
+#include <glxicons.mbg>
+
+TInt CGlxCommandHandlerAddToContainer::iSelectionCount = 0;
+
+// ---------------------------------------------------------------------------
+// Return add to album command handler
+// ---------------------------------------------------------------------------
+//
+EXPORT_C CGlxCommandHandlerAddToContainer* 
+    CGlxCommandHandlerAddToContainer::NewAddToAlbumCommandHandlerL(
+        MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem) 
+    {
+    return CGlxCommandHandlerAddToContainer::NewL (aMediaListProvider, 
+                                                EGlxCmdAddToAlbum, aHasToolbarItem);
+    }
+
+// ---------------------------------------------------------------------------
+// Return add (to) tags command handler
+// ---------------------------------------------------------------------------
+//
+EXPORT_C CGlxCommandHandlerAddToContainer* 
+    CGlxCommandHandlerAddToContainer::NewAddToTagCommandHandlerL(
+        MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem) 
+    {
+    return CGlxCommandHandlerAddToContainer::NewL(aMediaListProvider, 
+                                                EGlxCmdAddTag, aHasToolbarItem);
+    }
+
+// ---------------------------------------------------------------------------
+// Return add (to) Favourites command handler
+// ---------------------------------------------------------------------------
+//
+EXPORT_C CGlxCommandHandlerAddToContainer* 
+    CGlxCommandHandlerAddToContainer::NewAddToFavCommandHandlerL(
+        MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem) 
+    {
+    return CGlxCommandHandlerAddToContainer::NewL(aMediaListProvider, 
+                                    EGlxCmdAddToFavourites, aHasToolbarItem);
+    }
+
+// ---------------------------------------------------------------------------
+// Two-phased constructor.
+// ---------------------------------------------------------------------------
+//
+EXPORT_C CGlxCommandHandlerAddToContainer* CGlxCommandHandlerAddToContainer::NewL(
+        MGlxMediaListProvider* aMediaListProvider, TInt aCommandId, TBool aHasToolbarItem)
+    {
+    CGlxCommandHandlerAddToContainer* self = 
+        new ( ELeave ) CGlxCommandHandlerAddToContainer( aMediaListProvider, aHasToolbarItem );
+    CleanupStack::PushL( self );
+    self->ConstructL( aCommandId );
+    CleanupStack::Pop( self );
+    return self;
+    }
+    
+// ---------------------------------------------------------------------------
+// Constructor
+// ---------------------------------------------------------------------------
+//
+CGlxCommandHandlerAddToContainer::CGlxCommandHandlerAddToContainer(
+    MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem)
+        : CGlxMpxCommandCommandHandler( aMediaListProvider, aHasToolbarItem )
+    {
+    // Do nothing
+    }
+
+// ---------------------------------------------------------------------------
+// Symbian 2nd phase constructor can leave.
+// ---------------------------------------------------------------------------
+//
+void CGlxCommandHandlerAddToContainer::ConstructL(TInt aCommandId)
+    {
+    // Load resource
+	TParse parse;
+    parse.Set(KGlxUiUtilitiesResource, &KDC_APP_RESOURCE_DIR, NULL);
+    TFileName resourceFile;
+    resourceFile.Append(parse.FullName());
+    CGlxResourceUtilities::GetResourceFilenameL(resourceFile);  
+   	iResourceOffset = CCoeEnv::Static()->AddResourceFileL(resourceFile);
+	// Reset the Flag inorder to allow for a new selection pop-up to be created.
+   	iIsProcessOngoing = EFalse;
+   	// Add supported command
+   	TCommandInfo info(aCommandId);
+   	
+    // Filter out static items - user must have selected at least one item to
+    // enable the command handler    
+    const TInt KGlxCommandHandlerMinSelectionAllowSingle = 1;
+    info.iMinSelectionLength = KGlxCommandHandlerMinSelectionAllowSingle;
+    
+   	AddCommandL(info);
+   	iCommandId = aCommandId;
+	}
+
+// ---------------------------------------------------------------------------
+// Destructor
+// ---------------------------------------------------------------------------
+//
+EXPORT_C CGlxCommandHandlerAddToContainer::~CGlxCommandHandlerAddToContainer()
+    {
+    if ( iResourceOffset )
+        {
+        CCoeEnv::Static()->DeleteResourceFile(iResourceOffset);
+        }
+	// Reset the Flag inorder to allow for a new selection pop-up to be created.
+    iIsProcessOngoing = EFalse;
+    }
+
+// ---------------------------------------------------------------------------
+// Create an add to container command
+// ---------------------------------------------------------------------------
+//
+CMPXCommand* CGlxCommandHandlerAddToContainer::CreateCommandL(TInt aCommandId, 
+        MGlxMediaList& aMediaList, TBool& /*aConsume*/) const
+    {
+	// Ignore the current command in case the previous command has still not been completed
+	if(iIsProcessOngoing)
+	    {
+	    return NULL;
+	    }
+    iSelectionCount = 0;
+	// Set the Flag inorder to block any new subsequent selection pop-ups from getting created.
+	iIsProcessOngoing = ETrue;
+    CMPXCollectionPath* targetCollection = CMPXCollectionPath::NewL();
+    CleanupStack::PushL(targetCollection);
+    TBool enableMultipleSelection = EFalse;
+    TBool enablePopup = EFalse;
+    CMPXFilter* filter = NULL;
+    switch(aCommandId)
+        {
+        case EGlxCmdAddToFavourites:
+            {
+            targetCollection->AppendL(KGlxCollectionPluginAlbumsImplementationUid);
+            // The target collection has also to be appeneded with the the relation id.
+            // appending another level into the albums to get favourites and 1 is the relation id of albums
+            targetCollection->AppendL( TMPXItemId(1) );
+            targetCollection->Set( 0 );
+            break;
+            }
+        case EGlxCmdAddToAlbum:
+            {
+            enablePopup = ETrue;
+            targetCollection->AppendL(KGlxCollectionPluginAlbumsImplementationUid);
+	        filter = TGlxFilterFactory::CreateCameraAlbumExclusionFilterL();
+	        CleanupStack::PushL(filter);
+            break;
+            }
+        case EGlxCmdAddTag:
+            {
+            enableMultipleSelection = ETrue;
+            enablePopup = ETrue;
+            targetCollection->AppendL(KGlxTagCollectionPluginImplementationUid);
+            filter = TGlxFilterFactory::CreateIncludeEmptyContainersFilterL();
+            CleanupStack::PushL(filter);
+            break;
+            }
+        }
+               
+    CMPXCollectionPath* sourceItems = aMediaList.PathLC( NGlxListDefs::EPathFocusOrSelection );
+    CMPXCommand* command = NULL;
+    if (enablePopup )
+        {
+        CGlxMediaSelectionPopup* popup = new (ELeave) CGlxMediaSelectionPopup;
+        
+        TBool accepted = EFalse;
+        CMPXCollectionPath* targetContainers = 
+            popup->ExecuteLD(*targetCollection, accepted, enableMultipleSelection, ETrue, filter);
+
+        if (accepted)
+            {        
+            // Set the container selection count to give correct completion text
+            TArray<TInt> selection = targetContainers->Selection();
+            iSelectionCount = selection.Count();
+            
+            CleanupStack::PushL(targetContainers);
+            command = TGlxCommandFactory::AddToContainerCommandLC(
+                *sourceItems, *targetContainers);
+            CleanupStack::Pop(command); 
+            CleanupStack::PopAndDestroy(targetContainers);
+            }
+        else
+	    	{
+    		// Reset the Flag inorder to allow any new selection pop-up to be created.
+	    	iIsProcessOngoing = EFalse;
+	    	}
+        }
+    else
+        {
+        command = TGlxCommandFactory::AddToContainerCommandLC(
+            *sourceItems, *targetCollection);
+        CleanupStack::Pop(command); 
+        }
+    CleanupStack::PopAndDestroy(sourceItems);
+    if (filter)
+        {
+        CleanupStack::PopAndDestroy(filter);
+        }
+    CleanupStack::PopAndDestroy(targetCollection);
+	return command;
+    } 
+
+// -----------------------------------------------------------------------------
+// CGlxCommandHandlerAddToContainer::CompletionTextL
+// -----------------------------------------------------------------------------
+//	
+HBufC* CGlxCommandHandlerAddToContainer::CompletionTextL() const
+    {
+    if (iCommandId == EGlxCmdAddToAlbum)
+    	{
+   		if (iSelectionCount > 1)
+   			{
+	   		return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_CONTAINER_MULTI_ITEM_ALBUM);
+   			}
+   		return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_CONTAINER_ONE_ITEM_ALBUM);
+    	}
+   	else if (iCommandId == EGlxCmdAddTag)
+   		{
+   		if (iSelectionCount > 1)
+   			{
+	   		return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_CONTAINER_MULTI_ITEM_TAG);
+   			}
+		return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_CONTAINER_ONE_ITEM_TAG);	
+   		}
+    else // considered as favourites 
+        {
+        return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_FAVOURITES);
+        }
+    }
+
+// -----------------------------------------------------------------------------
+// CGlxCommandHandlerAddToContainer::DoHandleCommandCompleteL
+// -----------------------------------------------------------------------------
+//
+void CGlxCommandHandlerAddToContainer::DoHandleCommandCompleteL(TAny* /*aSessionId*/,
+        CMPXCommand* /*aCommandResult*/, TInt /*aError*/, MGlxMediaList* /*aList*/)
+      {
+	  // Reset the Flag inorder to allow any new selection pop-up to be created.
+      iIsProcessOngoing = EFalse;
+      }
+    
+// ---------------------------------------------------------------------------
+// CGlxCommandHandlerAddToContainer::DoActivateL
+// ---------------------------------------------------------------------------
+//
+void CGlxCommandHandlerAddToContainer::DoActivateL(TInt /*aViewId*/)
+	{
+
+ 	}
+
+void CGlxCommandHandlerAddToContainer::PopulateToolbarL()
+	{
+
+	}