photosgallery/viewframework/commandhandlers/commoncommandhandlers/src/glxcommandhandleraddtocontainer.cpp
branchRCL_3
changeset 60 5b3385a43d68
equal deleted inserted replaced
59:8e5f6eea9c9f 60:5b3385a43d68
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    Add to container command handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  * @internal reviewed 05/06/2007 by Dave Schofield
       
    23  */
       
    24 
       
    25 #include "glxcommandhandleraddtocontainer.h"
       
    26 
       
    27 #include <AknUtils.h>
       
    28 #include <bautils.h>
       
    29 #include <data_caging_path_literals.hrh>
       
    30 #include <eikmenup.h> 
       
    31 #include <glxcollectionpluginalbums.hrh>
       
    32 #include <glxcollectionplugintags.hrh>
       
    33 #include <glxcommandfactory.h>
       
    34 #include <glxcommandhandlers.hrh>
       
    35 #include <glxfilterfactory.h>
       
    36 #include <glxuiutility.h>
       
    37 #include <glxuistd.h>
       
    38 #include <glxresourceutilities.h>                // for CGlxResourceUtilities
       
    39 #include <glxuiutilities.rsg>
       
    40 #include <mglxmedialist.h>
       
    41 
       
    42 #include <mpxcollectioncommanddefs.h>
       
    43 #include <mpxcollectionpath.h>
       
    44 #include <mpxcommandgeneraldefs.h>
       
    45 #include <mpxmediaarray.h>
       
    46 #include <mpxmediacontainerdefs.h>
       
    47 #include <StringLoader.h>
       
    48 
       
    49 #include "glxmediaselectionpopup.h"
       
    50 #include <glxicons.mbg>
       
    51 #include <glxtracer.h>
       
    52 
       
    53 TInt CGlxCommandHandlerAddToContainer::iSelectionCount = 0;
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // Return add to album command handler
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 EXPORT_C CGlxCommandHandlerAddToContainer*
       
    60 CGlxCommandHandlerAddToContainer::NewAddToAlbumCommandHandlerL(
       
    61 		MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem,
       
    62 		const TDesC& aFileName)
       
    63 	{
       
    64 	TRACER("CGlxCommandHandlerAddToContainer::NewAddToAlbumCommandHandlerL");
       
    65 	return CGlxCommandHandlerAddToContainer::NewL(aMediaListProvider,
       
    66 			EGlxCmdAddToAlbum, aHasToolbarItem, aFileName);
       
    67 	}
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // Return add (to) tags command handler
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 EXPORT_C CGlxCommandHandlerAddToContainer*
       
    74 CGlxCommandHandlerAddToContainer::NewAddToTagCommandHandlerL(
       
    75 		MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem,
       
    76 		const TDesC& aFileName)
       
    77 	{
       
    78 	TRACER("CGlxCommandHandlerAddToContainer::NewAddToTagCommandHandlerL");
       
    79 	return CGlxCommandHandlerAddToContainer::NewL(aMediaListProvider,
       
    80 			EGlxCmdAddTag, aHasToolbarItem, aFileName);
       
    81 	}
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // Return add (to) Favourites command handler
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 EXPORT_C CGlxCommandHandlerAddToContainer*
       
    88 CGlxCommandHandlerAddToContainer::NewAddToFavCommandHandlerL(
       
    89 		MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem,
       
    90 		const TDesC& aFileName)
       
    91 	{
       
    92 	TRACER("CGlxCommandHandlerAddToContainer::NewAddToFavCommandHandlerL");
       
    93 	return CGlxCommandHandlerAddToContainer::NewL(aMediaListProvider,
       
    94 			EGlxCmdAddToFavourites, aHasToolbarItem, aFileName);
       
    95 	}
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // Two-phased constructor.
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C CGlxCommandHandlerAddToContainer* CGlxCommandHandlerAddToContainer::NewL(
       
   102 		MGlxMediaListProvider* aMediaListProvider, TInt aCommandId,
       
   103 		TBool aHasToolbarItem, const TDesC& aFileName)
       
   104 	{
       
   105 	TRACER("CGlxCommandHandlerAddToContainer::NewL");
       
   106 	CGlxCommandHandlerAddToContainer* self =
       
   107 			new (ELeave) CGlxCommandHandlerAddToContainer(aMediaListProvider,
       
   108 					aHasToolbarItem);
       
   109 	CleanupStack::PushL(self);
       
   110 	self->ConstructL(aCommandId, aFileName);
       
   111 	CleanupStack::Pop(self);
       
   112 	return self;
       
   113 	}
       
   114     
       
   115 // ---------------------------------------------------------------------------
       
   116 // Constructor
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 CGlxCommandHandlerAddToContainer::CGlxCommandHandlerAddToContainer(
       
   120     MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem)
       
   121         : CGlxMpxCommandCommandHandler( aMediaListProvider, aHasToolbarItem )
       
   122     {
       
   123     // Do nothing
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // Symbian 2nd phase constructor can leave.
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CGlxCommandHandlerAddToContainer::ConstructL(TInt aCommandId,
       
   131 		const TDesC& aFileName)
       
   132 	{
       
   133 	TRACER("CGlxCommandHandlerAddToContainer::ConstructL");
       
   134 	// Load resource
       
   135 	iResourceOffset = CCoeEnv::Static()->AddResourceFileL(aFileName);
       
   136 	// Reset the Flag inorder to allow for a new selection pop-up to be created.
       
   137 	iIsProcessOngoing = EFalse;
       
   138 	// Add supported command
       
   139 	TCommandInfo info(aCommandId);
       
   140 
       
   141 	// Filter out static items - user must have selected at least one item to
       
   142 	// enable the command handler    
       
   143 	const TInt KGlxCommandHandlerMinSelectionAllowSingle = 1;
       
   144 	info.iMinSelectionLength = KGlxCommandHandlerMinSelectionAllowSingle;
       
   145 
       
   146 	AddCommandL(info);
       
   147 	iCommandId = aCommandId;
       
   148 	}
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // Destructor
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 EXPORT_C CGlxCommandHandlerAddToContainer::~CGlxCommandHandlerAddToContainer()
       
   155     {
       
   156     TRACER("CGlxCommandHandlerAddToContainer::~CGlxCommandHandlerAddToContainer");
       
   157     if ( iResourceOffset )
       
   158         {
       
   159         CCoeEnv::Static()->DeleteResourceFile(iResourceOffset);
       
   160         }
       
   161 	// Reset the Flag inorder to allow for a new selection pop-up to be created.
       
   162     iIsProcessOngoing = EFalse;
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // Create an add to container command
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 CMPXCommand* CGlxCommandHandlerAddToContainer::CreateCommandL(TInt aCommandId, 
       
   170         MGlxMediaList& aMediaList, TBool& /*aConsume*/) const
       
   171     {
       
   172     TRACER("CGlxCommandHandlerAddToContainer::CreateCommandL");
       
   173 	// Ignore the current command in case the previous command has still not been completed
       
   174 	if(iIsProcessOngoing)
       
   175 	    {
       
   176 	    return NULL;
       
   177 	    }
       
   178     iSelectionCount = 0;
       
   179     iItemsSelectionCount = 0;
       
   180 	// Set the Flag inorder to block any new subsequent selection pop-ups from getting created.
       
   181 	iIsProcessOngoing = ETrue;
       
   182     CMPXCollectionPath* targetCollection = CMPXCollectionPath::NewL();
       
   183     CleanupStack::PushL(targetCollection);
       
   184     TBool enableMultipleSelection = EFalse;
       
   185     TBool enablePopup = EFalse;
       
   186     CMPXFilter* filter = NULL;
       
   187     switch(aCommandId)
       
   188         {
       
   189         case EGlxCmdAddToFavourites:
       
   190             {
       
   191             targetCollection->AppendL(KGlxCollectionPluginAlbumsImplementationUid);
       
   192             // The target collection has also to be appeneded with the the relation id.
       
   193             // appending another level into the albums to get favourites and 1 is the relation id of albums
       
   194             targetCollection->AppendL( TMPXItemId(1) );
       
   195             targetCollection->Set( 0 );
       
   196             break;
       
   197             }
       
   198         case EGlxCmdAddToAlbum:
       
   199             {
       
   200             enablePopup = ETrue;
       
   201             targetCollection->AppendL(KGlxCollectionPluginAlbumsImplementationUid);
       
   202 	        filter = TGlxFilterFactory::CreateCameraAlbumExclusionFilterL();
       
   203 	        CleanupStack::PushL(filter);
       
   204             break;
       
   205             }
       
   206         case EGlxCmdAddTag:
       
   207             {
       
   208             enableMultipleSelection = ETrue;
       
   209             enablePopup = ETrue;
       
   210             targetCollection->AppendL(KGlxTagCollectionPluginImplementationUid);
       
   211             break;
       
   212             }
       
   213         }
       
   214                
       
   215     CMPXCollectionPath* sourceItems = aMediaList.PathLC( NGlxListDefs::EPathFocusOrSelection );
       
   216     CMPXCommand* command = NULL;
       
   217     if (enablePopup )
       
   218         {
       
   219         CGlxMediaSelectionPopup* popup = new (ELeave) CGlxMediaSelectionPopup;
       
   220         
       
   221         TBool accepted = EFalse;
       
   222         CMPXCollectionPath* targetContainers = 
       
   223             popup->ExecuteLD(*targetCollection, accepted, enableMultipleSelection, ETrue, filter);
       
   224 
       
   225         if (accepted)
       
   226             {        
       
   227             // Set the container selection count to give correct completion text
       
   228             TArray<TInt> selection = targetContainers->Selection();
       
   229             iSelectionCount = selection.Count();
       
   230             iItemsSelectionCount = sourceItems->Count();
       
   231             
       
   232             CleanupStack::PushL(targetContainers);
       
   233             command = TGlxCommandFactory::AddToContainerCommandLC(
       
   234                 *sourceItems, *targetContainers);
       
   235             CleanupStack::Pop(command); 
       
   236             CleanupStack::PopAndDestroy(targetContainers);
       
   237             }
       
   238         else
       
   239 	    	{
       
   240     		// Reset the Flag inorder to allow any new selection pop-up to be created.
       
   241 	    	iIsProcessOngoing = EFalse;
       
   242 	    	}
       
   243         }
       
   244     else
       
   245         {
       
   246         command = TGlxCommandFactory::AddToContainerCommandLC(
       
   247             *sourceItems, *targetCollection);
       
   248         CleanupStack::Pop(command); 
       
   249         }
       
   250     CleanupStack::PopAndDestroy(sourceItems);
       
   251     if (filter)
       
   252         {
       
   253         CleanupStack::PopAndDestroy(filter);
       
   254         }
       
   255     CleanupStack::PopAndDestroy(targetCollection);
       
   256 	return command;
       
   257     } 
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CGlxCommandHandlerAddToContainer::CompletionTextL
       
   261 // -----------------------------------------------------------------------------
       
   262 //	
       
   263 HBufC* CGlxCommandHandlerAddToContainer::CompletionTextL() const
       
   264     {
       
   265     TRACER("CGlxCommandHandlerAddToContainer::CompletionTextL()");
       
   266     if (iCommandId == EGlxCmdAddToAlbum)
       
   267     	{
       
   268    		if (iItemsSelectionCount > 1)
       
   269    			{
       
   270 	   		return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_CONTAINER_MULTI_ITEM_ALBUM);
       
   271    			}
       
   272    		return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_CONTAINER_ONE_ITEM_ALBUM);
       
   273     	}
       
   274    	else if (iCommandId == EGlxCmdAddTag)
       
   275    		{
       
   276    		if (iSelectionCount > 1)
       
   277    			{
       
   278 	   		return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_CONTAINER_MULTI_ITEM_TAG);
       
   279    			}
       
   280 		return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_CONTAINER_ONE_ITEM_TAG);	
       
   281    		}
       
   282     else // considered as favourites 
       
   283         {
       
   284         return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_FAVOURITES);
       
   285         }
       
   286     }
       
   287 
       
   288 
       
   289 TBool CGlxCommandHandlerAddToContainer::OkToExit() const
       
   290         {
       
   291         return ETrue;
       
   292         }
       
   293 // -----------------------------------------------------------------------------
       
   294 // CGlxCommandHandlerAddToContainer::DoHandleCommandCompleteL
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 void CGlxCommandHandlerAddToContainer::DoHandleCommandCompleteL(TAny* /*aSessionId*/,
       
   298         CMPXCommand* /*aCommandResult*/, TInt /*aError*/, MGlxMediaList* /*aList*/)
       
   299       {
       
   300       TRACER("CGlxCommandHandlerAddToContainer::DoHandleCommandCompleteL()");
       
   301 	  // Reset the Flag inorder to allow any new selection pop-up to be created.
       
   302       iIsProcessOngoing = EFalse;
       
   303       }
       
   304 
       
   305 
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // DialogDismissedL
       
   309 // -----------------------------------------------------------------------------
       
   310 //  
       
   311 void CGlxCommandHandlerAddToContainer::DialogDismissedL(TInt aButtonId)
       
   312     {
       
   313     TRACER("CGlxCommandHandlerAddToContainer::DialogDismissedL");
       
   314     iIsProcessOngoing = EFalse;
       
   315     CGlxMpxCommandCommandHandler::DialogDismissedL(aButtonId);
       
   316     }
       
   317 
       
   318 
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // CGlxCommandHandlerAddToContainer::DoActivateL
       
   322 // ---------------------------------------------------------------------------
       
   323 //
       
   324 void CGlxCommandHandlerAddToContainer::DoActivateL(TInt /*aViewId*/)
       
   325 	{
       
   326 
       
   327  	}
       
   328 
       
   329 void CGlxCommandHandlerAddToContainer::PopulateToolbarL()
       
   330 	{
       
   331 
       
   332 	}
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // CGlxCommandHandlerAddToContainer::DoIsDisabled
       
   336 // ---------------------------------------------------------------------------
       
   337 //
       
   338 TBool CGlxCommandHandlerAddToContainer::DoIsDisabled(TInt aCommandId, 
       
   339                                                  MGlxMediaList& /*aList*/) const
       
   340     {
       
   341 	TRACER("CGlxCommandHandlerAddToContainer::DoIsDisabled");
       
   342 	if (EGlxCmdAddToAlbum==aCommandId || EGlxCmdAddTag == aCommandId)
       
   343         {
       
   344         return EFalse;
       
   345         }
       
   346     return ETrue;
       
   347     }
       
   348 // End of File