photosgallery/collectionframework/datasource/plugins/glxdatasourcemde2.5/src/glxdatasourcetaskmdscommand.cpp
changeset 0 4e91876724a2
child 9 6b87b143d312
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     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:    Data Source Task MDS Command Class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  * @internal reviewed 11/07/2007 by M Byrne
       
    23  */
       
    24 
       
    25 
       
    26 #include "glxdatasourcetaskmdscommand.h"
       
    27 
       
    28 #include <bautils.h>
       
    29 #include <e32math.h>
       
    30 #include <glxcommandrequest.h>
       
    31 #include <glxpanic.h>
       
    32 #include <glxtndatabase.h>
       
    33 #include <glxtnthumbnailcreator.h>
       
    34 #include <glxtracer.h>
       
    35 #include <caf/manager.h>
       
    36 #include <mdeconstants.h>
       
    37 #include <mdeeventdef.h>
       
    38 #include <mdelogiccondition.h>
       
    39 #include <mdeobject.h>
       
    40 #include <mdeobjectdef.h>
       
    41 #include <mdeobjectquery.h>
       
    42 #include <mdepropertydef.h>
       
    43 #include <mderelationcondition.h>
       
    44 #include <mderelationdef.h>
       
    45 #include <mderelationquery.h>
       
    46 #include <mdesession.h>
       
    47 #include <mdetextproperty.h>
       
    48 #include <mpxcollectionmessagedefs.h>
       
    49 #include <mpxcommandgeneraldefs.h>
       
    50 #include <mpxmedia.h>
       
    51 #include <mpxmediaarray.h>
       
    52 #include <mpxmediacollectiondetaildefs.h>
       
    53 #include <mpxmediacontainerdefs.h>
       
    54 #include <mpxmediageneraldefs.h>
       
    55 #include <mpxmessagegeneraldefs.h>
       
    56 #include <mpxmessageprogressdefs.h>
       
    57 #include <pathinfo.h>
       
    58 
       
    59 #include <glxstringcache.h>
       
    60 
       
    61 #include <glxcollectionplugincamera.hrh>
       
    62 #include <glxcollectionplugintags.hrh>
       
    63 #include <glxcollectionpluginalbums.hrh>
       
    64 #include <glxcollectionpluginall.hrh>
       
    65 
       
    66 #include "glxdatasourcemds.h"
       
    67 #include "glxdatasourcemdsutility.h"
       
    68 #include "glxdatasourcemds.hrh"
       
    69 
       
    70 #include <glxpluginalbums.rsg>
       
    71 
       
    72 #include <data_caging_path_literals.hrh>
       
    73 #include <f32file.h>
       
    74 #include <barsc.h>
       
    75 #include <bautils.h>
       
    76 
       
    77 // CONSTANTS
       
    78 _LIT(KPropertyDefNameDescription, "Comment");
       
    79 _LIT(KPropertyDefNameTitle, "Title" );
       
    80 _LIT(KPropertyDefNameSize, "Size");
       
    81 _LIT(KPropertyDefNameCreationDate, "CreationDate");
       
    82 _LIT(KPropertyDefNameLastModifiedDate, "LastModifiedDate");
       
    83 _LIT(KPropertyDefNameAlbumType, "Type");
       
    84 _LIT(KPropertyDefItemType, "ItemType");
       
    85 // Item type for Album
       
    86 _LIT( KAlbumItemType, "application/vnd.nokia.mde.album" );
       
    87 // Item type for Tag
       
    88 _LIT( KTagItemType, "application/vnd.nokia.mde.tag" );
       
    89 
       
    90 const TInt KDriveLetterLength = 1;
       
    91 _LIT(KColonBackslash, ":\\");
       
    92 _LIT(KFileNameFormatString, "(%+02u)");
       
    93 
       
    94 // ----------------------------------------------------------------------------
       
    95 // Destructor
       
    96 // ----------------------------------------------------------------------------
       
    97 //
       
    98 CGlxDataSourceTaskMdeCommand::~CGlxDataSourceTaskMdeCommand()
       
    99 	{
       
   100     TRACER("CGlxDataSourceTaskMdeCommand::~CGlxDataSourceTaskMdeCommand()");
       
   101 	iLeftIds.Close();
       
   102     iRightIds.Close();
       
   103     delete iTitle;
       
   104     delete iObjectToRename;
       
   105     delete iStringCache;
       
   106     }
       
   107 
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // Constructor
       
   111 // ----------------------------------------------------------------------------
       
   112 //
       
   113 CGlxDataSourceTaskMdeCommand::CGlxDataSourceTaskMdeCommand(
       
   114        CGlxCommandRequest* aRequest, MGlxDataSourceRequestObserver& aObserver, 
       
   115        CGlxDataSource* aDataSource)
       
   116     : CGlxDataSourceTaskMde(aRequest, aObserver, aDataSource) 
       
   117 	{
       
   118     TRACER("CGlxDataSourceTaskMdeCommand::CGlxDataSourceTaskMdeCommand()");
       
   119 	// No implementation required
       
   120 	}
       
   121 
       
   122 // ----------------------------------------------------------------------------
       
   123 // Second phase constructor
       
   124 // ----------------------------------------------------------------------------
       
   125 //
       
   126 void CGlxDataSourceTaskMdeCommand::ConstructL()
       
   127 	{
       
   128     TRACER("CGlxDataSourceTaskMdeCommand::ConstructL()");
       
   129 	iResponse = CMPXCommand::NewL(static_cast<CGlxCommandRequest*>(iRequest)->Command());
       
   130 #ifdef USE_S60_TNM
       
   131     DataSource()->CancelFetchThumbnail();
       
   132 #else    
       
   133     DataSource()->ThumbnailCreator().CancelRequest( TGlxMediaId(0) );
       
   134 #endif
       
   135 	}
       
   136 
       
   137 /// @todo minor: Rowland Cook 12/06/2007 Add method decription.
       
   138 // ----------------------------------------------------------------------------
       
   139 // CGlxDataSourceTaskMdeCommand::ExecuteRequestL
       
   140 // ----------------------------------------------------------------------------
       
   141 //
       
   142 void CGlxDataSourceTaskMdeCommand::ExecuteRequestL()
       
   143 	{
       
   144     TRACER("CGlxDataSourceTaskMdeCommand::ExecuteRequestL()");
       
   145     __ASSERT_DEBUG(DataSource()->NamespaceDef(), Panic(EGlxPanicIllegalState));
       
   146     
       
   147 	const CMPXCommand& command = static_cast<CGlxCommandRequest*>(iRequest)->Command();
       
   148 	
       
   149 	if ( command.IsSupported(KMPXCommandGeneralCollectionId) )
       
   150 		{
       
   151 		iCollectionUid = command.ValueTObjectL<TUid>(KMPXCommandGeneralCollectionId);
       
   152 		}
       
   153 	else
       
   154 		{
       
   155 		// if the collection Uid has not been set on the command, use the Ud of the plugin in use.
       
   156 		iCollectionUid = iRequest->CollectionPluginUid();
       
   157 		}
       
   158 	
       
   159 	TGlxCommandParser::ParseL(*this, command);
       
   160 	}
       
   161 
       
   162 // ----------------------------------------------------------------------------
       
   163 // Add container
       
   164 // ----------------------------------------------------------------------------
       
   165 //
       
   166 void CGlxDataSourceTaskMdeCommand::AddContainerL(const TDesC& aContainerName)
       
   167 	{
       
   168     TRACER("CGlxDataSourceTaskMdeCommand::AddContainerL()");
       
   169 	iTitle = aContainerName.AllocL();
       
   170 	AppendContainerTitleCountQueryL(ECommandAddContainer, aContainerName);
       
   171     ExecuteQueryL();
       
   172     }
       
   173 
       
   174 // ----------------------------------------------------------------------------
       
   175 // Add items to container by id
       
   176 // ----------------------------------------------------------------------------
       
   177 //
       
   178 void CGlxDataSourceTaskMdeCommand::AddToContainerL(const RArray<TGlxMediaId>& aSourceIds,
       
   179         const RArray<TGlxMediaId>& aTargetContainers)
       
   180 	{
       
   181     TRACER("CGlxDataSourceTaskMdeCommand::AddToContainerL(const RArray<TGlxMediaId>& aSourceIds,const RArray<TGlxMediaId>& aTargetContainers)");	
       
   182 	__ASSERT_DEBUG(aSourceIds.Count() && aTargetContainers.Count(), 
       
   183 	        Panic(EGlxPanicEmptyArray));
       
   184 	
       
   185     iLeftIds.Reset();
       
   186     iRightIds.Reset();
       
   187 
       
   188 	CMdEQuery* query = DataSource()->Session().NewRelationQueryL(
       
   189 	        *DataSource()->NamespaceDef(), this); 
       
   190 	AppendQueryL(query, ECommandAddToContainer);
       
   191     
       
   192     CMdELogicCondition& rootCondition = query->Conditions();
       
   193     CMdERelationCondition& containerRelationCondition = 
       
   194     rootCondition.AddRelationConditionL(DataSource()->ContainsDef(),
       
   195             ERelationConditionSideLeft);
       
   196     CMdELogicCondition& leftLogicCondition = containerRelationCondition.LeftL();
       
   197     CMdELogicCondition& rightLogicCondition = containerRelationCondition.RightL();
       
   198     leftLogicCondition.SetOperator(ELogicConditionOperatorOr);
       
   199     rightLogicCondition.SetOperator(ELogicConditionOperatorOr);
       
   200 
       
   201     TItemId containerId = ContainerItemId(aTargetContainers[0]);
       
   202     // It is currenly a safe assumption that all containers are of the same type (either albums or tags)
       
   203     // and thus they will either all be on the left or all be on the right of the logic condition. Therefore, 
       
   204     // we only need to test the first container to see if it is on the left or on the right. 
       
   205     CMdEObject* container = DataSource()->Session().GetObjectL(containerId);
       
   206     if (!container)
       
   207         {
       
   208         User::Leave(KErrNotFound);
       
   209         }
       
   210     TBool containerIsLeft = DataSource()->ContainerIsLeft(container->Def());
       
   211     
       
   212     delete container;
       
   213     container = NULL;
       
   214     
       
   215 
       
   216     if (containerIsLeft)
       
   217         {
       
   218         // the container is on the left
       
   219         NGlxDataSourceMdsUtility::CopyMediaIdArrayL(iLeftIds, aTargetContainers);
       
   220         NGlxDataSourceMdsUtility::CopyMediaIdArrayL(iRightIds, aSourceIds);
       
   221         }
       
   222     else
       
   223         {
       
   224         // the container is on the right
       
   225         NGlxDataSourceMdsUtility::CopyMediaIdArrayL(iRightIds, aTargetContainers);
       
   226         NGlxDataSourceMdsUtility::CopyMediaIdArrayL(iLeftIds, aSourceIds);
       
   227         }
       
   228     
       
   229     leftLogicCondition.AddObjectConditionL(iLeftIds);
       
   230     rightLogicCondition.AddObjectConditionL(iRightIds);
       
   231 
       
   232     query->SetResultMode(EQueryResultModeItem);	 
       
   233 
       
   234     ExecuteQueryL();
       
   235     
       
   236     }
       
   237 
       
   238 // ----------------------------------------------------------------------------
       
   239 // Add item to containers by URI.
       
   240 // ----------------------------------------------------------------------------
       
   241 //
       
   242 void CGlxDataSourceTaskMdeCommand::AddToContainerL(const TDesC& aSourceUri, 
       
   243 		                        const RArray< TGlxMediaId >& aTargetContainers)
       
   244     {
       
   245     TRACER("CGlxDataSourceTaskMdeCommand::AddToContainerL()");
       
   246     CMdEObject* sourceObject = DataSource()->Session().GetObjectL(aSourceUri);
       
   247     if (!sourceObject)
       
   248         {
       
   249         User::Leave(KErrNotFound);
       
   250         }
       
   251     RArray<TGlxMediaId> sourceIds;
       
   252     CleanupClosePushL(sourceIds);
       
   253     sourceIds.AppendL(TGlxMediaId(sourceObject->Id()));
       
   254     
       
   255     AddToContainerL(sourceIds, aTargetContainers);
       
   256     CleanupStack::PopAndDestroy(&sourceIds);
       
   257     }
       
   258 
       
   259 // ----------------------------------------------------------------------------
       
   260 // Copy files to another drive.
       
   261 // ----------------------------------------------------------------------------
       
   262 //
       
   263 /// @todo minor: Rowland Cook 12/06/2007 Has this method been tested? If so remove comments
       
   264 void CGlxDataSourceTaskMdeCommand::CopyL(const RArray<TGlxMediaId>& aSourceIds, 
       
   265         const TDesC& aDrive)
       
   266     {
       
   267     TRACER("CGlxDataSourceTaskMdeCommand::CopyL()");
       
   268     FileOperationL(aSourceIds.Array(), aDrive, ECopy);
       
   269     }
       
   270 
       
   271 // ----------------------------------------------------------------------------
       
   272 // Move files to another drive.
       
   273 // ----------------------------------------------------------------------------
       
   274 //
       
   275 /// @todo minor: Rowland Cook 12/06/2007 Has this method been tested? If so remove comments
       
   276 void CGlxDataSourceTaskMdeCommand::MoveL(const RArray<TGlxMediaId>& aSourceIds, 
       
   277         const TDesC& aDrive)
       
   278     {
       
   279     TRACER("CGlxDataSourceTaskMdeCommand::MoveL()");
       
   280     FileOperationL(aSourceIds.Array(), aDrive, EMove);
       
   281     }
       
   282 
       
   283 // ----------------------------------------------------------------------------
       
   284 // Remove items from a container.
       
   285 // ----------------------------------------------------------------------------
       
   286 //
       
   287 void CGlxDataSourceTaskMdeCommand::RemoveFromContainerL(
       
   288         const RArray<TGlxMediaId>& aItemIds, const TGlxMediaId& aContainerId)
       
   289     {
       
   290     TRACER("CGlxDataSourceTaskMdeCommand::RemoveFromContainerL()");
       
   291     // Answer to question in @bug above: No
       
   292     
       
   293 	CMdEObject* object = NULL;
       
   294 	object = DataSource()->Session().GetObjectL(aContainerId.Value());
       
   295     CleanupStack::PushL(object);
       
   296 	if (!object)
       
   297     	{
       
   298     	User::Leave(KErrNotFound);
       
   299     	}
       
   300 	
       
   301 	CMdEQuery* query = DataSource()->Session().NewRelationQueryL(
       
   302 	        *DataSource()->NamespaceDef(), this); 
       
   303 	AppendQueryL(query, ECommandRemoveFromContainer); // query is now owned by the query array.
       
   304     
       
   305     CMdELogicCondition& rootCondition = query->Conditions();
       
   306 
       
   307     CMdERelationCondition& containerRelationCondition = 
       
   308     rootCondition.AddRelationConditionL(
       
   309             DataSource()->ContainsDef(), ERelationConditionSideLeft);
       
   310     CMdELogicCondition* containerLogicCondition = NULL;
       
   311     CMdELogicCondition* itemLogicCondition = NULL;
       
   312     // Containers are on the left for albums, right for tags
       
   313     if ( DataSource()->ContainerIsLeft(object->Def()) )
       
   314     	{
       
   315     	containerLogicCondition = &containerRelationCondition.LeftL();
       
   316     	itemLogicCondition = &containerRelationCondition.RightL();
       
   317     	}
       
   318     else
       
   319     	{
       
   320     	containerLogicCondition = &containerRelationCondition.RightL();
       
   321     	itemLogicCondition = &containerRelationCondition.LeftL();
       
   322     	}
       
   323    
       
   324     containerLogicCondition->AddObjectConditionL(aContainerId.Value());
       
   325     
       
   326     itemLogicCondition->SetOperator(ELogicConditionOperatorOr);
       
   327 
       
   328     NGlxDataSourceMdsUtility::AddObjectConditionL(*itemLogicCondition,aItemIds);
       
   329     
       
   330     query->SetResultMode(EQueryResultModeId);	 
       
   331     CleanupStack::PopAndDestroy(object);
       
   332     ExecuteQueryL();
       
   333     }
       
   334 
       
   335 // ----------------------------------------------------------------------------
       
   336 // Delete files, Remove container.
       
   337 // ----------------------------------------------------------------------------
       
   338 //
       
   339 void CGlxDataSourceTaskMdeCommand::DeleteL(const RArray<TGlxMediaId>& aItemIds)
       
   340     {
       
   341     TRACER("CGlxDataSourceTaskMdeCommand::DeleteL()");
       
   342     CMdEObjectDef* containerObjectDef = NULL;
       
   343     TInt err = ContainerObjectDef(containerObjectDef);
       
   344     if (err == KErrNone)
       
   345     	{
       
   346 	    QueueObjectQueryL(*containerObjectDef, 
       
   347 	            aItemIds, ECommandDeleteContainers);
       
   348     	}
       
   349     // Assume that only items are left
       
   350     QueueObjectQueryL(DataSource()->ObjectDef(), 
       
   351                 aItemIds, ECommandDeleteItems);
       
   352     
       
   353     ExecuteQueryL();
       
   354     }
       
   355 
       
   356 // ----------------------------------------------------------------------------
       
   357 // Rename files, Rename container.
       
   358 //
       
   359 /// @todo test this method.
       
   360 //
       
   361 // ----------------------------------------------------------------------------
       
   362 //
       
   363 /// @todo minor: Rowland Cook 12/06/2007 Has this method been tested? If so remove comments
       
   364 void CGlxDataSourceTaskMdeCommand::RenameL(const TGlxMediaId& aSourceItemId, 
       
   365         const TDesC& aTitle)
       
   366     {
       
   367     TRACER("CGlxDataSourceTaskMdeCommand::RenameL()");
       
   368     delete iTitle;
       
   369     iTitle = NULL;
       
   370 	iTitle = aTitle.AllocL();
       
   371 	
       
   372 	RArray<TGlxMediaId> sourceIdArray;
       
   373 	CleanupClosePushL(sourceIdArray);
       
   374 	sourceIdArray.AppendL(aSourceItemId);
       
   375 	
       
   376 	QueueObjectQueryL(DataSource()->ObjectDef(), sourceIdArray , ECommandRename);
       
   377 	CleanupStack::PopAndDestroy(&sourceIdArray);
       
   378 	
       
   379 	ExecuteQueryL();
       
   380     }
       
   381 
       
   382 // ----------------------------------------------------------------------------
       
   383 // Set description.
       
   384 // ----------------------------------------------------------------------------
       
   385 //
       
   386 void CGlxDataSourceTaskMdeCommand::SetDescriptionL(const RArray<TGlxMediaId>& aItemIds, 
       
   387         const TDesC& aDescription)
       
   388     {
       
   389     TRACER("CGlxDataSourceTaskMdeCommand::SetDescriptionL()");
       
   390     CMdEPropertyDef& descriptionPropertyDef = DataSource()->MediaDef().GetPropertyDefL(
       
   391             KPropertyDefNameDescription);
       
   392     if (descriptionPropertyDef.PropertyType() != EPropertyText)
       
   393     	{
       
   394     	User::Leave(KErrCorrupt);
       
   395     	}
       
   396     
       
   397     TInt count = aItemIds.Count();
       
   398     for (TInt i = 0; i < count; i++)
       
   399     	{
       
   400     	TItemId itemId = aItemIds[i].Value();
       
   401     	CMdEObject* object = DataSource()->Session().OpenFullObjectL(itemId);
       
   402     	if (!object)
       
   403     		{
       
   404     		User::Leave(KErrNotFound);
       
   405     		}
       
   406     	CleanupStack::PushL(object);
       
   407     	CMdEProperty* descriptionProperty = NULL;
       
   408     
       
   409     			
       
   410     	TInt index = object->Property(descriptionPropertyDef, descriptionProperty);
       
   411 	    if (index < KErrNotFound)
       
   412 	    	{
       
   413 	    	User::Leave(index);
       
   414 	    	}
       
   415 	    if (index != KErrNotFound)
       
   416 	    	{
       
   417 	    	// Check whether the description string is empty
       
   418 	    	if( aDescription.Length()  )
       
   419 	    	    {	    	   
       
   420 	    	    static_cast<CMdETextProperty*>(descriptionProperty)->SetValueL(aDescription);
       
   421 	    	    }
       
   422 	    	    
       
   423 	        //if entered description string is blank then remove the old property
       
   424 	    	else
       
   425                 {
       
   426                 object->RemoveProperty(index);
       
   427                 }
       
   428 	    	}
       
   429     	else
       
   430     	    {
       
   431     	    if( aDescription.Length()  )
       
   432 	    	    {
       
   433     	    object->AddTextPropertyL(descriptionPropertyDef, aDescription);
       
   434 	    	    }
       
   435     	    }
       
   436 	    DataSource()->Session().CommitObjectL(*object); 
       
   437 	    CleanupStack::PopAndDestroy(object);
       
   438     	}
       
   439     
       
   440     HandleRequestComplete(KErrNone);
       
   441     }
       
   442 
       
   443 
       
   444 // ----------------------------------------------------------------------------
       
   445 // Set capture location.
       
   446 // ----------------------------------------------------------------------------
       
   447 //
       
   448 void CGlxDataSourceTaskMdeCommand::SetCaptureLocationL(const RArray<TGlxMediaId>& aItemIds, 
       
   449         const TCoordinate& aCoordinate)
       
   450     {
       
   451     TRACER("CGlxDataSourceTaskMdeCommand::SetCaptureLocationL()") ;   
       
   452     if (!Math::IsNaN(aCoordinate.Latitude()) || !Math::IsNaN(aCoordinate.Longitude()))
       
   453     	{
       
   454     	User::Leave(KErrArgument);
       
   455     	}
       
   456     	
       
   457 	CMdEQuery* query = DataSource()->Session().NewRelationQueryL(*DataSource()->NamespaceDef(), this); 
       
   458 	AppendQueryL(query, ECommandRemoveLocation); // query is now owned by the query array.
       
   459     
       
   460     CMdELogicCondition& rootCondition = query->Conditions();
       
   461 
       
   462     CMdERelationCondition& containerRelationCondition = rootCondition.AddRelationConditionL(
       
   463             ERelationConditionSideLeft);
       
   464     CMdELogicCondition& locationLogicCondition = containerRelationCondition.RightL();
       
   465     CMdELogicCondition& itemLogicCondition = containerRelationCondition.LeftL();
       
   466     locationLogicCondition.AddObjectConditionL(DataSource()->LocationDef());
       
   467     
       
   468     itemLogicCondition.SetOperator(ELogicConditionOperatorOr);
       
   469 
       
   470 
       
   471     itemLogicCondition.AddObjectConditionL(reinterpret_cast<const RArray<TItemId>&>(aItemIds));
       
   472     
       
   473     query->SetResultMode(EQueryResultModeId);	 
       
   474     ExecuteQueryL();
       
   475     }
       
   476 
       
   477 // ----------------------------------------------------------------------------
       
   478 // CGlxDataSourceTaskMdeCommand::ThumbnailCleanupL
       
   479 // ----------------------------------------------------------------------------
       
   480 //
       
   481 void CGlxDataSourceTaskMdeCommand::ThumbnailCleanupL()
       
   482 	{
       
   483     TRACER("CGlxDataSourceTaskMdeCommand::ThumbnailCleanupL()");
       
   484 #ifndef USE_S60_TNM
       
   485     CGlxDataSourceMde* ds = DataSource();
       
   486     ds->ThumbnailCreator().CleanupThumbnailsL(&ds->ThumbnailDatabase());
       
   487 #endif
       
   488 	HandleRequestComplete(KErrNone);	
       
   489 	}
       
   490 
       
   491 // ----------------------------------------------------------------------------
       
   492 // CGlxDataSourceTaskMdeCommand::HandleQueryCompletedL
       
   493 // ----------------------------------------------------------------------------
       
   494 //
       
   495 void CGlxDataSourceTaskMdeCommand::DoHandleQueryCompletedL(CMdEQuery& aQuery)
       
   496 	{
       
   497     TRACER("CGlxDataSourceTaskMdeCommand::DoHandleQueryCompletedL()");
       
   498     TGlxQueryType queryType = iQueryTypes[0];
       
   499 	
       
   500     switch (queryType)
       
   501     	{
       
   502 
       
   503 	    case ECommandRemoveFromContainer: // don't break
       
   504 	    case ECommandRemoveLocation:
       
   505 			{
       
   506 			TInt queryCount = aQuery.Count();
       
   507 			RArray<TItemId> relationsToRemove;
       
   508 			CleanupClosePushL(relationsToRemove);
       
   509 			User::LeaveIfError(relationsToRemove.Reserve(queryCount));
       
   510 			
       
   511 			RArray<TItemId> successfullyRemovedReleations;
       
   512 			CleanupClosePushL(successfullyRemovedReleations);
       
   513 			User::LeaveIfError(successfullyRemovedReleations.Reserve(queryCount));
       
   514 			
       
   515 			for(TInt i = queryCount - 1; i >= 0; i--)
       
   516 				{		
       
   517 				relationsToRemove.AppendL(aQuery.ResultId(i));
       
   518 				}
       
   519 			
       
   520 			if (queryCount)
       
   521 				{
       
   522 				User::LeaveIfError(DataSource()->Session().RemoveRelationsL(
       
   523 				        relationsToRemove, successfullyRemovedReleations));
       
   524 				}
       
   525 			
       
   526 			CleanupStack::PopAndDestroy(&successfullyRemovedReleations);
       
   527 			CleanupStack::PopAndDestroy(&relationsToRemove);
       
   528 			}
       
   529 	    break;
       
   530 	    case ECommandAddToContainer:
       
   531 			{
       
   532 			DoHandleAddToContainerQueryCompletedL(aQuery);
       
   533 	        }
       
   534 	    break;
       
   535 	    case ECommandAddContainer:
       
   536 	        { 
       
   537 	        DoHandleAddContainerQueryCompletedL(aQuery);   
       
   538 	        }
       
   539 	        break;
       
   540 	    case ECommandDeleteContainers:
       
   541 	        {
       
   542 	        DoHandleDeleteContainersQueryCompletedL(aQuery);
       
   543 	        }
       
   544 	    break;
       
   545 	    case ECommandDeleteItems:
       
   546 	        {
       
   547 	        DoHandleDeleteItemsQueryCompletedL(aQuery);
       
   548 	        }
       
   549 	    break;
       
   550     	case ECommandRename:
       
   551     		{
       
   552     		DoHandleRenameQueryCompletedL(aQuery);
       
   553     		}
       
   554     	break;
       
   555     	case ECommandRenameContainer:
       
   556     		{
       
   557     		DoHandleRenameConainerQueryCompletedL(aQuery);
       
   558     		}
       
   559     	break;
       
   560     	}
       
   561     }
       
   562 // ----------------------------------------------------------------------------
       
   563 // CGlxDataSourceTaskMdeCommand::DoNextQueryL
       
   564 // ----------------------------------------------------------------------------
       
   565 //
       
   566 void CGlxDataSourceTaskMdeCommand::DoNextQueryL()
       
   567     {
       
   568     TRACER("CGlxDataSourceTaskMdeCommand::DoNextQueryL()");
       
   569     if (iQueries.Count())
       
   570         {
       
   571         ExecuteQueryL();
       
   572         }
       
   573     else
       
   574         {
       
   575         HandleRequestComplete(KErrNone);
       
   576         }
       
   577     }
       
   578 
       
   579 // ----------------------------------------------------------------------------
       
   580 // CGlxDataSourceTaskMdeCommand::FileOperationL
       
   581 // ----------------------------------------------------------------------------
       
   582 //
       
   583 void CGlxDataSourceTaskMdeCommand::FileOperationL(const TArray<TGlxMediaId>& aSourceIds, 
       
   584         const TDesC& aDrive, TFileOperation aFileOperation)
       
   585 	{
       
   586     TRACER("CGlxDataSourceTaskMdeCommand::FileOperationL()");
       
   587 	ContentAccess::CManager *manager = ContentAccess::CManager::NewL();
       
   588 	CleanupStack::PushL(manager);
       
   589 	// The following line causes a code scanner warning advising use of EikonEnv RFs instance.
       
   590 	// We don't have an EikonEnv as we are running in a server process.
       
   591 	RFs rfs; // used for BaflUtils::FileExists
       
   592 	
       
   593 	CleanupClosePushL(rfs);
       
   594 	User::LeaveIfError(rfs.Connect());
       
   595 	for (TInt i = 0; i < aSourceIds.Count(); i++)
       
   596     	{
       
   597     	CMdEObject* sourceObject = DataSource()->Session().GetObjectL(aSourceIds[i].Value());
       
   598     	if (!sourceObject)
       
   599     		{
       
   600     		User::Leave(KErrNotFound);
       
   601     		}
       
   602 
       
   603     	CleanupStack::PushL(sourceObject);
       
   604     	
       
   605     	const TDesC& sourceFileName = sourceObject->Uri();
       
   606     	TFileName sourceRootPath;
       
   607     	
       
   608     	RootPath(sourceFileName, sourceRootPath);
       
   609     	TPtrC fileNameWithoutRoot(NULL,0);
       
   610     	if (sourceFileName.Left(sourceRootPath.Length()).CompareF(sourceRootPath) == 0)
       
   611     		// This is the expected case. The file to be copied is under the 'root' of 
       
   612     		// the drive that it is located on. (For the C:, the root is C:\data, 
       
   613     		// for the D: the root is D:\)
       
   614     		{
       
   615     		fileNameWithoutRoot.Set(sourceFileName.Right(sourceFileName.Length() - 
       
   616     		        sourceRootPath.Length()));
       
   617     		}
       
   618     	else
       
   619     		{
       
   620     		fileNameWithoutRoot.Set(sourceFileName);
       
   621     		}
       
   622     		
       
   623     	TFileName destinationFileName;
       
   624     	// Set destination file name to destination 'root' path
       
   625     	RootPath(aDrive, destinationFileName);
       
   626     	// Append the file name
       
   627     	destinationFileName.Append(fileNameWithoutRoot);
       
   628     	
       
   629 /// @todo minor: Rowland Cook 12/06/2007 majic number.
       
   630     	if (destinationFileName.CompareF(sourceFileName) != 0)
       
   631     		{
       
   632     		// If source and destination are not identical, perform the copy.	
       
   633 			if (BaflUtils::FileExists(rfs, destinationFileName))
       
   634 				{
       
   635 				// If the destination file name already exists find an available file name.
       
   636 				TParse destinationFileNameParse;
       
   637 				destinationFileNameParse.Set(destinationFileName,NULL,NULL); // this is a copy of the data
       
   638 				TInt destinationFileNameWithoutExtensionLength = destinationFileName.Length()
       
   639 				- destinationFileNameParse.Ext().Length();
       
   640 				TInt i = 1;
       
   641 				do
       
   642 					{
       
   643 			    	destinationFileName.SetLength(destinationFileNameWithoutExtensionLength);
       
   644 			    	destinationFileName.AppendFormat(KFileNameFormatString,i++);
       
   645 			    	destinationFileName.Append(destinationFileNameParse.Ext());		    	
       
   646 					}
       
   647 				while (BaflUtils::FileExists(rfs, destinationFileName));
       
   648 				}
       
   649 			
       
   650             // Ensure the path that we are copying to exists.
       
   651             // Fixed error ID:  ELLZ-798BP3 Lumiere 07.46.08_MC Photo: 
       
   652             // "System: System error." is displayed when copying/moving image which is saved in a user created folder.
       
   653             BaflUtils::EnsurePathExistsL(rfs,destinationFileName);
       
   654             
       
   655 	    	if (aFileOperation == ECopy)
       
   656 	    		{
       
   657 	    		User::LeaveIfError(manager->CopyFile(sourceFileName, destinationFileName));		
       
   658 	    		}
       
   659 	    	else
       
   660 	    		{
       
   661 	    		User::LeaveIfError(manager->RenameFile(sourceFileName, destinationFileName));
       
   662 	    		}
       
   663 
       
   664     		}
       
   665     	
       
   666     	CleanupStack::PopAndDestroy(sourceObject);
       
   667     	}
       
   668     
       
   669 	CleanupStack::PopAndDestroy(&rfs);
       
   670 	CleanupStack::PopAndDestroy(manager);
       
   671 	
       
   672     HandleRequestComplete(KErrNone);
       
   673 	}
       
   674 
       
   675 // ----------------------------------------------------------------------------
       
   676 // CGlxDataSourceTaskMdeCommand::ContainerItemId
       
   677 // ----------------------------------------------------------------------------
       
   678 //
       
   679 TItemId CGlxDataSourceTaskMdeCommand::ContainerItemId(const TGlxMediaId& aMediaId)
       
   680     {
       
   681     TRACER("TMdEItemId CGlxDataSourceTaskMdeCommand::ContainerItemId()");    
       
   682     TItemId containerId = aMediaId.Value();
       
   683     if (aMediaId == KGlxCollectionRootId)
       
   684         {
       
   685         // Check the collection plugin uid
       
   686         if (iCollectionUid == TUid::Uid(KGlxCollectionPluginCameraImplementationUid))
       
   687             {
       
   688           //  containerId = DataSource()->CameraAlbumId().Value();
       
   689             }  
       
   690         }
       
   691     return containerId;
       
   692     }
       
   693 
       
   694 // ----------------------------------------------------------------------------
       
   695 // CGlxDataSourceTaskMdeCommand::ContainerItemId
       
   696 // ----------------------------------------------------------------------------
       
   697 //
       
   698 void CGlxDataSourceTaskMdeCommand::RootPath(const TDesC& aDrive, TDes& aRootPath)
       
   699 	{
       
   700     TRACER("CGlxDataSourceTaskMdeCommand::RootPath()");
       
   701 	if (aDrive.Left(KDriveLetterLength).CompareF(PathInfo::PhoneMemoryRootPath().Left(
       
   702 	        KDriveLetterLength)) == 0)
       
   703 		{
       
   704 		aRootPath = PathInfo::PhoneMemoryRootPath();
       
   705 		}
       
   706 	else if (aDrive.Left(KDriveLetterLength).CompareF(PathInfo::MemoryCardRootPath().Left(
       
   707 	        KDriveLetterLength)) == 0)
       
   708 		{
       
   709 		aRootPath = PathInfo::MemoryCardRootPath();
       
   710 		}
       
   711 	else if (aDrive.Left(KDriveLetterLength).CompareF(PathInfo::RomRootPath().Left(
       
   712 	        KDriveLetterLength)) == 0)
       
   713 		{
       
   714 		aRootPath = PathInfo::RomRootPath();
       
   715 		}
       
   716 	else
       
   717 		{
       
   718 		aRootPath = aDrive.Left(KDriveLetterLength);
       
   719 		aRootPath.Append(KColonBackslash);
       
   720 		}
       
   721 	}
       
   722 
       
   723 // ----------------------------------------------------------------------------
       
   724 // CGlxDataSourceTaskMdeCommand::SendProgressMessageL
       
   725 // ----------------------------------------------------------------------------
       
   726 //
       
   727 void CGlxDataSourceTaskMdeCommand::SendProgressMessageL(TInt aCurrentStep, TInt aStepCount)
       
   728 	{
       
   729     TRACER("CGlxDataSourceTaskMdeCommand::SendProgressMessageL()");
       
   730 	MGlxDataSourceUpdateObserver& observer = 
       
   731 	static_cast<CGlxCommandRequest*>(iRequest)->DataSourceUpdateObserver();
       
   732 	
       
   733 	const CMPXCommand& command = static_cast<CGlxCommandRequest*>(iRequest)->Command();
       
   734 	__ASSERT_DEBUG(command.IsSupported(KMPXCommandGeneralSessionId), Panic(
       
   735 	        EGlxPanicCommandHasNoGeneralSessionId));
       
   736 	
       
   737 	TAny* sessionId = command.ValueTObjectL<TAny*>(KMPXCommandGeneralSessionId);
       
   738 	
       
   739 	CMPXMessage* progressMessage = CMPXMessage::NewL();
       
   740 	CleanupStack::PushL(progressMessage);
       
   741 	progressMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralId, KMPXMessageContentIdProgress);	
       
   742 	progressMessage->SetTObjectValueL<TInt>(TMPXAttribute(KMPXMessageContentIdProgress, 
       
   743 	        EMPXMessageProgressCurrentCount), aCurrentStep);
       
   744 	progressMessage->SetTObjectValueL<TInt>(TMPXAttribute(KMPXMessageContentIdProgress,
       
   745 	        EMPXMessageProgressTotalCount), aStepCount);
       
   746 	progressMessage->SetTObjectValueL<TAny*>(KMPXCommandGeneralSessionId, sessionId);
       
   747 	
       
   748 	observer.HandleMessage(*progressMessage);
       
   749 	
       
   750 	CleanupStack::PopAndDestroy(progressMessage);
       
   751 	}
       
   752 
       
   753 // ----------------------------------------------------------------------------
       
   754 // CGlxDataSourceTaskMdeCommand::ContainerObjectDef
       
   755 // ----------------------------------------------------------------------------
       
   756 //
       
   757 TInt CGlxDataSourceTaskMdeCommand::ContainerObjectDef(CMdEObjectDef*& aContainerObjectDef)
       
   758 {
       
   759     TRACER("CGlxDataSourceTaskMdeCommand::ContainerObjectDef()");
       
   760     //__ASSERT_DEBUG( (iCollectionUid == TUid::Uid(KGlxTagCollectionPluginImplementationUid) 
       
   761     //|| iCollectionUid == TUid::Uid(KGlxCollectionPluginAlbumsImplementationUid)), Panic(EGlxPanicInvalidCollectionUid));
       
   762     TInt err = KErrNone;
       
   763 	if (iCollectionUid == TUid::Uid(KGlxTagCollectionPluginImplementationUid))
       
   764         {
       
   765         aContainerObjectDef  = &DataSource()->TagDef();      
       
   766         }
       
   767     else if (iCollectionUid  == TUid::Uid(KGlxCollectionPluginAlbumsImplementationUid))
       
   768         {
       
   769         aContainerObjectDef  = &DataSource()->AlbumDef();
       
   770         }
       
   771     else if(iCollectionUid  == TUid::Uid(KGlxCollectionPluginAllImplementationUid))
       
   772         {
       
   773         aContainerObjectDef  = &DataSource()->MediaDef();
       
   774         }
       
   775     else
       
   776     	{
       
   777     	err = KErrNotFound;
       
   778     	}
       
   779 	return err;
       
   780 }
       
   781 
       
   782 // ----------------------------------------------------------------------------
       
   783 // CGlxDataSourceTaskMdeCommand::DoHandleAddToContainerQueryCompletedL
       
   784 // ----------------------------------------------------------------------------
       
   785 //
       
   786 void CGlxDataSourceTaskMdeCommand::DoHandleAddToContainerQueryCompletedL
       
   787 															(CMdEQuery& aQuery)
       
   788 	{
       
   789     TRACER("CGlxDataSourceTaskMdeCommand::DoHandleAddToContainerQueryCompletedL()");
       
   790 	RPointerArray<CMdEInstanceItem> relations;
       
   791 	CleanupClosePushL(relations);
       
   792 	 
       
   793 	TInt leftCount = iLeftIds.Count();
       
   794 	User::LeaveIfError(relations.Reserve(leftCount)); // this is a bigest reservation that could be required.
       
   795     for (TInt leftPos = 0; leftPos < leftCount; leftPos++)
       
   796         {
       
   797         TInt rightCount = iRightIds.Count();
       
   798         for (TInt rightPos = 0; rightPos < rightCount; rightPos++)
       
   799             {
       
   800             // Check to see if id already exists
       
   801             TBool alreadyExists = EFalse;
       
   802             for(TInt queryPos = aQuery.Count() - 1; queryPos >= 0; queryPos--)
       
   803                 {
       
   804                 CMdERelation& relation = static_cast<CMdERelation&>(aQuery.ResultItem(queryPos));
       
   805                 if (relation.LeftObjectId() == iLeftIds[leftPos]
       
   806                     && relation.RightObjectId() == iRightIds[rightPos])
       
   807                     {
       
   808                     alreadyExists = ETrue;
       
   809                     break;
       
   810                     }
       
   811                 }
       
   812             
       
   813             if (!alreadyExists)
       
   814                 {
       
   815                 CMdERelation* relation = DataSource()->Session().NewRelationL(
       
   816                         DataSource()->ContainsDef(), iLeftIds[leftPos], iRightIds[rightPos]);
       
   817                 CleanupStack::PushL(relation);
       
   818                 relations.AppendL(relation);
       
   819                 CleanupStack::Pop(relation);
       
   820                 }
       
   821             }
       
   822         
       
   823         }
       
   824 
       
   825     if (relations.Count())
       
   826     	{
       
   827     	User::LeaveIfError(DataSource()->Session().AddItemsL(relations));
       
   828     	}
       
   829     
       
   830     CleanupStack::PopAndDestroy(&relations);
       
   831 
       
   832     iLeftIds.Reset();
       
   833     iRightIds.Reset();
       
   834 	}
       
   835 
       
   836 // ----------------------------------------------------------------------------
       
   837 // CGlxDataSourceTaskMdeCommand::DoHandleAddContainerQueryCompletedL
       
   838 // ----------------------------------------------------------------------------
       
   839 //
       
   840 void CGlxDataSourceTaskMdeCommand::DoHandleAddContainerQueryCompletedL
       
   841 															(CMdEQuery& aQuery)
       
   842 
       
   843 	{
       
   844     TRACER("CGlxDataSourceTaskMdeCommand::DoHandleAddContainerQueryCompletedL()");
       
   845    	
       
   846    	//Duplicate albums check for the default albums i.e. Favourites 
       
   847    	//as title property is left blank in MDS 2.5
       
   848    	if(iCollectionUid == TUid::Uid(KGlxCollectionPluginAlbumsImplementationUid))
       
   849    		{
       
   850    		if(SearchStringL(R_ALBUM_FAVORITES_TITLE) == 0 || 
       
   851    				SearchStringL(R_ALBUM_CAMERA_TITLE) == 0 )
       
   852     		{
       
   853     		User::Leave(KErrAlreadyExists);	
       
   854     		}        	
       
   855    		}
       
   856    	   	
       
   857     if (aQuery.Count())
       
   858         {
       
   859         // An object (or more strickly objects) with the given container name already exist
       
   860         User::Leave(KErrAlreadyExists);
       
   861         }
       
   862      
       
   863     CMdEObject* object = NULL;
       
   864     CMdEObjectDef* containerObjectDef = NULL;
       
   865     TInt err = ContainerObjectDef(containerObjectDef );
       
   866     __ASSERT_ALWAYS(err == KErrNone, Panic(EGlxPanicInvalidCollectionUid));
       
   867     
       
   868     object = DataSource()->Session().NewObjectLC(*containerObjectDef, KNullDesC);
       
   869     
       
   870     // A title property def of type text is required.
       
   871     CMdEPropertyDef& titlePropertyDef = containerObjectDef->GetPropertyDefL(
       
   872             KPropertyDefNameTitle);
       
   873     if (titlePropertyDef.PropertyType() != EPropertyText)
       
   874         {
       
   875         User::Leave(KErrCorrupt);
       
   876         }
       
   877     // Set the object title.
       
   878     object->AddTextPropertyL(titlePropertyDef, *iTitle);
       
   879     
       
   880       //ItemType property def of type text is required.
       
   881     CMdEPropertyDef& itemTypePropertyDef = containerObjectDef->GetPropertyDefL(
       
   882             KPropertyDefItemType);
       
   883     if (itemTypePropertyDef.PropertyType() != EPropertyText)
       
   884     	{
       
   885     	User::Leave(KErrCorrupt);
       
   886     	}
       
   887   
       
   888     // Checks the Container type whether it is Tag or Album	
       
   889     if (iCollectionUid == TUid::Uid(KGlxTagCollectionPluginImplementationUid))
       
   890       {
       
   891       object->AddTextPropertyL (itemTypePropertyDef, KTagItemType);
       
   892       }
       
   893     else
       
   894       {
       
   895       object->AddTextPropertyL (itemTypePropertyDef, KAlbumItemType);
       
   896       }
       
   897    
       
   898    
       
   899     // A size property is required.
       
   900   
       
   901     CMdEPropertyDef& sizePropertyDef = containerObjectDef->GetPropertyDefL(
       
   902             KPropertyDefNameSize);
       
   903     if (sizePropertyDef.PropertyType() != EPropertyUint32)
       
   904         {
       
   905         User::Leave(KErrCorrupt);
       
   906         }
       
   907     object->AddUint32PropertyL(sizePropertyDef,0);
       
   908 
       
   909     
       
   910     // A creation date property is required.
       
   911     CMdEPropertyDef& creationDateDef = containerObjectDef->GetPropertyDefL(
       
   912             KPropertyDefNameCreationDate);
       
   913     if (creationDateDef.PropertyType() != EPropertyTime)
       
   914         {
       
   915         User::Leave(KErrCorrupt);
       
   916         }
       
   917 
       
   918     // A last modified date property is required.
       
   919     CMdEPropertyDef& lmDateDef = containerObjectDef->GetPropertyDefL(
       
   920             KPropertyDefNameLastModifiedDate);
       
   921     if (lmDateDef.PropertyType() != EPropertyTime)
       
   922         {
       
   923         User::Leave(KErrCorrupt);
       
   924         }
       
   925     
       
   926     TTime uTime;
       
   927     uTime.UniversalTime();
       
   928     object->AddTimePropertyL(creationDateDef, uTime);
       
   929     object->AddTimePropertyL(lmDateDef, uTime);
       
   930     
       
   931     TItemId id = DataSource()->Session().AddObjectL(*object);
       
   932     CleanupStack::PopAndDestroy(object);
       
   933     
       
   934     iResponse->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, id);
       
   935     iResponse->SetTObjectValueL<TMPXItemId>(KMPXMessageMediaGeneralId, id);  
       
   936     iResponse->SetTObjectValueL<TMPXChangeEventType>(KMPXMessageChangeEventType,
       
   937             EMPXItemInserted); 
       
   938 	}
       
   939 // ----------------------------------------------------------------------------
       
   940 // CGlxDataSourceTaskMdeCommand::DoHandleDeleteContainersQueryCompletedL
       
   941 // ----------------------------------------------------------------------------
       
   942 //
       
   943 void CGlxDataSourceTaskMdeCommand::DoHandleDeleteContainersQueryCompletedL
       
   944 															(CMdEQuery& aQuery)
       
   945 	{
       
   946     TRACER("CGlxDataSourceTaskMdeCommand::DoHandleDeleteContainersQueryCompletedL()");
       
   947     CMdEPropertyDef& albumTypeProperty = DataSource()->AlbumDef().GetPropertyDefL(
       
   948             KPropertyDefNameAlbumType);
       
   949     TInt queryCount = aQuery.Count();
       
   950     
       
   951     RArray<TItemId> objectsForRemoval;
       
   952     CleanupClosePushL(objectsForRemoval);
       
   953     User::LeaveIfError(objectsForRemoval.Reserve(queryCount));
       
   954 
       
   955     RArray<TItemId> sucessfullyRemovedObjects;
       
   956     CleanupClosePushL(sucessfullyRemovedObjects);
       
   957     User::LeaveIfError(sucessfullyRemovedObjects.Reserve(queryCount));
       
   958     
       
   959     // Ensure that deletion is legal and that deletion
       
   960     for(TInt queryPos = 0; queryPos < queryCount; queryPos++)
       
   961         {
       
   962         CMdEObject& object = static_cast<CMdEObject&>(aQuery.ResultItem(queryPos));
       
   963   
       
   964         CMdEProperty* albumType;
       
   965         TInt albumTypeIndex = object.Property(albumTypeProperty, albumType);
       
   966         if (KErrNotFound != albumTypeIndex)
       
   967             {
       
   968             TInt albumTypeValue = static_cast<CMdEUint16Property*>(albumType)->Value();
       
   969             if ((albumTypeValue == MdeConstants::Album::EAlbumSystemFavourite) || 
       
   970             		(albumTypeValue == MdeConstants::Album::EAlbumSystemCamera))
       
   971                {
       
   972                User::Leave(KErrAccessDenied); 
       
   973                }
       
   974             }
       
   975         objectsForRemoval.AppendL(object.Id());
       
   976         }
       
   977     
       
   978     if (queryCount)
       
   979     	{
       
   980     	User::LeaveIfError(DataSource()->Session().RemoveObjectsL(objectsForRemoval, 
       
   981     	        sucessfullyRemovedObjects));
       
   982     	}
       
   983     
       
   984     CleanupStack::PopAndDestroy(&sucessfullyRemovedObjects);
       
   985     CleanupStack::PopAndDestroy(&objectsForRemoval);
       
   986 	}
       
   987 // ----------------------------------------------------------------------------
       
   988 // CGlxDataSourceTaskMdeCommand::DoHandleDeleteItemsContainersQueryCompletedL
       
   989 // ----------------------------------------------------------------------------
       
   990 //
       
   991 void CGlxDataSourceTaskMdeCommand::DoHandleDeleteItemsQueryCompletedL
       
   992 															(CMdEQuery& aQuery)
       
   993 	{
       
   994     TRACER("CGlxDataSourceTaskMdeCommand::DoHandleDeleteItemsQueryCompletedL()");
       
   995     ContentAccess::CManager *manager = ContentAccess::CManager::NewL();
       
   996     CleanupStack::PushL(manager);
       
   997     TInt queryCount = aQuery.Count();
       
   998     RArray<TItemId> objectsForRemoval;
       
   999     CleanupClosePushL(objectsForRemoval);
       
  1000     User::LeaveIfError(objectsForRemoval.Reserve(queryCount));
       
  1001 
       
  1002     RArray<TItemId> sucessfullyRemovedObjects;
       
  1003     CleanupClosePushL(sucessfullyRemovedObjects);
       
  1004     User::LeaveIfError(sucessfullyRemovedObjects.Reserve(queryCount));
       
  1005     //Handle to a file server session
       
  1006     RFs fs; 
       
  1007     // Pushing the handle in Clean-up Stack to call Close() on file server session 
       
  1008     CleanupClosePushL( fs );
       
  1009     //Connects a client to the file server
       
  1010     User::LeaveIfError( fs.Connect() );
       
  1011     
       
  1012     TInt lastErr = KErrNone;
       
  1013     for(TInt queryPos = queryCount - 1; queryPos >= 0; queryPos--)
       
  1014         {
       
  1015         CMdEObject& object = static_cast<CMdEObject&>(aQuery.ResultItem(queryPos));
       
  1016         //Removes the Read Only attributes of the file 
       
  1017         fs.SetAtt(object.Uri(), 0, KEntryAttReadOnly);
       
  1018         TInt err = manager->DeleteFile(object.Uri());
       
  1019         if (err != KErrNone)
       
  1020         	{
       
  1021         	lastErr = err;
       
  1022         	}    
       
  1023         objectsForRemoval.AppendL(object.Id());
       
  1024         }
       
  1025     // Calling Close() on file server session 
       
  1026     CleanupStack::PopAndDestroy( &fs );
       
  1027     
       
  1028     User::LeaveIfError(lastErr);
       
  1029     
       
  1030     if (queryCount)
       
  1031     	{
       
  1032     	// Some objects may have already been removed by the harvester
       
  1033     	DataSource()->Session().RemoveObjectsL(objectsForRemoval, sucessfullyRemovedObjects);
       
  1034     	}
       
  1035     
       
  1036     CleanupStack::PopAndDestroy(&sucessfullyRemovedObjects);
       
  1037     CleanupStack::PopAndDestroy(&objectsForRemoval);
       
  1038     
       
  1039     CleanupStack::PopAndDestroy(manager);
       
  1040 	}
       
  1041 
       
  1042 // ----------------------------------------------------------------------------
       
  1043 //  CGlxDataSourceTaskMdeCommand::DoHandleRenameConainerQueryCompletedL
       
  1044 // ----------------------------------------------------------------------------
       
  1045 //
       
  1046 void CGlxDataSourceTaskMdeCommand::DoHandleRenameConainerQueryCompletedL
       
  1047                                                             (CMdEQuery& aQuery)
       
  1048 	{
       
  1049     TRACER("CGlxDataSourceTaskMdeCommand::DoHandleRenameConainerQueryCompletedL()");
       
  1050 	__ASSERT_DEBUG(iObjectToRename, Panic(EGlxPanicLogicError));
       
  1051 	if (aQuery.Count())
       
  1052 		{
       
  1053 		User::Leave(KErrAlreadyExists);
       
  1054 		}
       
  1055 		
       
  1056 	CMdEObject* object = DataSource()->Session().OpenObjectL(iObjectToRename->Id(), iObjectToRename->Def());
       
  1057 	CleanupStack::PushL(object);
       
  1058     CMdEProperty* albumType;
       
  1059     // @todo AB test this
       
  1060     CMdEPropertyDef* albumTypeProperty = NULL;
       
  1061     TRAP_IGNORE(albumTypeProperty = &object->Def().GetPropertyDefL(KPropertyDefNameAlbumType));       
       
  1062     TInt albumTypeIndex = KErrNotFound;
       
  1063     // Must guard against non-existance of albumTypeProperty (e.g. when renaming a tag)
       
  1064     if (albumTypeProperty)
       
  1065         {
       
  1066         albumTypeIndex = object->Property(*albumTypeProperty, albumType);
       
  1067         }
       
  1068     if( KErrNotFound != albumTypeIndex )
       
  1069         {
       
  1070         TInt albumTypeValue = static_cast<CMdEUint16Property*>(albumType)->Value();
       
  1071         if ( albumTypeValue == MdeConstants::Album::EAlbumUserPredefined ) 
       
  1072             {
       
  1073             // Want to rename a predefined, localised album name so reclassify
       
  1074             // the type to be a non-localised user defined album
       
  1075             static_cast<CMdEUint16Property*>(albumType)->SetValueL(MdeConstants::Album::EAlbumUser);
       
  1076             }
       
  1077 		else if ((albumTypeValue == MdeConstants::Album::EAlbumSystemFavourite) || 
       
  1078 				(albumTypeValue == MdeConstants::Album::EAlbumSystemCamera))
       
  1079 		    {
       
  1080             // Cannot rename system albums
       
  1081 		    User::Leave(KErrAccessDenied); 
       
  1082 		    }
       
  1083         }
       
  1084 
       
  1085     
       
  1086     CMdEPropertyDef& titlePropertyDef = object->Def().GetPropertyDefL(KPropertyDefNameTitle);
       
  1087     if (titlePropertyDef.PropertyType() != EPropertyText)
       
  1088     	{
       
  1089     	User::Leave(KErrCorrupt);
       
  1090     	}
       
  1091     
       
  1092     CMdEProperty* titleProperty = NULL;
       
  1093     TInt index = object->Property(titlePropertyDef, titleProperty);
       
  1094     if (index < KErrNotFound)
       
  1095     	{
       
  1096     	User::Leave(index);
       
  1097     	}
       
  1098     if (index != KErrNotFound)
       
  1099     	{
       
  1100     	// Remove the old property
       
  1101     	object->RemoveProperty(index);
       
  1102     	}
       
  1103     // Set the object title
       
  1104     object->AddTextPropertyL(titlePropertyDef, *iTitle);
       
  1105     
       
  1106     // Get time propertydef of current session object
       
  1107     CMdEPropertyDef& timePropertyDef = object->Def().GetPropertyDefL(
       
  1108         KPropertyDefNameLastModifiedDate);
       
  1109         
       
  1110     // Check the validty of the time def
       
  1111     if (timePropertyDef.PropertyType() != EPropertyTime)
       
  1112     	{
       
  1113     	User::Leave(KErrCorrupt);
       
  1114     	}
       
  1115     	
       
  1116     // Get index and check the validity 
       
  1117     CMdEProperty* timeProperty = NULL;
       
  1118     index = object->Property(timePropertyDef, timeProperty);
       
  1119     
       
  1120     if (index < KErrNotFound)
       
  1121     	{
       
  1122     	User::Leave(index);
       
  1123     	}
       
  1124     	
       
  1125     if (index != KErrNotFound)
       
  1126     	{
       
  1127     	// Remove the old property
       
  1128     	object->RemoveProperty(index);
       
  1129     	}
       
  1130     	
       
  1131     // Take current universal time
       
  1132     TTime currentTime;
       
  1133     currentTime.UniversalTime();
       
  1134 
       
  1135     // Set the object current time
       
  1136     object->AddTimePropertyL(timePropertyDef, currentTime);
       
  1137     
       
  1138     DataSource()->Session().CommitObjectL(*object);
       
  1139     CleanupStack::PopAndDestroy(object);
       
  1140 	}
       
  1141 
       
  1142 // ----------------------------------------------------------------------------
       
  1143 //  CGlxDataSourceTaskMdeCommand::DoHandleRenameConainerQueryCompletedL
       
  1144 // ----------------------------------------------------------------------------
       
  1145 //
       
  1146 void CGlxDataSourceTaskMdeCommand::DoHandleRenameQueryCompletedL
       
  1147                                                            (CMdEQuery& aQuery)
       
  1148 	{
       
  1149     TRACER("CGlxDataSourceTaskMdeCommand::DoHandleRenameQueryCompletedL()");
       
  1150 	__ASSERT_DEBUG(aQuery.Count() == 1, Panic(EGlxPanicUnexpectedQueryResultCount ));
       
  1151 	delete iObjectToRename;
       
  1152 	iObjectToRename = static_cast<CMdEObject*>(aQuery.TakeOwnershipOfResult(0));
       
  1153 	
       
  1154     CMdEObjectDef* containerObjectDef = NULL;
       
  1155     TInt err = ContainerObjectDef(containerObjectDef);
       
  1156 	if (err == KErrNone)
       
  1157 		{
       
  1158 		AppendContainerTitleCountQueryL(ECommandRenameContainer, *iTitle);
       
  1159 		}
       
  1160 	}
       
  1161 
       
  1162 // ----------------------------------------------------------------------------
       
  1163 //  CGlxDataSourceTaskMdeCommand::AppendContainerTitleCountQueryL
       
  1164 // ----------------------------------------------------------------------------
       
  1165 //
       
  1166 void  CGlxDataSourceTaskMdeCommand::AppendContainerTitleCountQueryL
       
  1167                         (const TGlxQueryType& aQueryType, const TDesC& aTitle)
       
  1168 	{
       
  1169     TRACER("CGlxDataSourceTaskMdeCommand::AppendContainerTitleCountQueryL()");
       
  1170 	// Test to see if a container alerady exists in the database with aContainerName
       
  1171     CMdEObjectDef* containerObjectDef = NULL;
       
  1172     TInt err = ContainerObjectDef(containerObjectDef);
       
  1173     __ASSERT_ALWAYS(err == KErrNone, Panic(EGlxPanicInvalidCollectionUid));
       
  1174     
       
  1175     CMdEQuery* query = DataSource()->Session().NewObjectQueryL(*DataSource()->NamespaceDef(),
       
  1176             *containerObjectDef, this);
       
  1177     CleanupStack::PushL(query);
       
  1178     
       
  1179     CMdEPropertyDef& titlePropertyDef = DataSource()->ObjectDef().GetPropertyDefL(
       
  1180             KPropertyDefNameTitle);
       
  1181     
       
  1182     query->SetResultMode(EQueryResultModeCount);
       
  1183     
       
  1184     query->Conditions().AddPropertyConditionL(titlePropertyDef, 
       
  1185             ETextPropertyConditionCompareEquals, aTitle);
       
  1186     
       
  1187     CleanupStack::Pop(query);
       
  1188     
       
  1189     AppendQueryL(query, aQueryType); 
       
  1190 	}
       
  1191 
       
  1192 // ----------------------------------------------------------------------------
       
  1193 //  CGlxDataSourceTaskMdeCommand::SearchString
       
  1194 // ----------------------------------------------------------------------------
       
  1195 //	
       
  1196 TInt CGlxDataSourceTaskMdeCommand::SearchStringL(TInt aResourceId)
       
  1197 	{
       
  1198 	TRACER("CGlxDataSourceTaskMdeCommand::SearchStringL()");
       
  1199 	_LIT(KResourceFile, "z:glxpluginalbums.rsc");	
       
  1200    	
       
  1201    	if (!iStringCache)
       
  1202         {
       
  1203         iStringCache = CGlxStringCache::NewL();
       
  1204         }        
       
  1205     //Get the localized string from the cache    
       
  1206 	HBufC* string = iStringCache->LoadLocalizedStringLC(KResourceFile,aResourceId);		
       
  1207 	
       
  1208 	TInt result = string->CompareF(iTitle->Des());
       
  1209 	
       
  1210 	CleanupStack::PopAndDestroy(string);
       
  1211     
       
  1212     return result;    
       
  1213         	
       
  1214 	}