photosgallery/common/src/glxcommandparser.cpp
changeset 0 4e91876724a2
child 18 bcb43dc84c44
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:    Command request
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "glxcommandparser.h"
       
    23 
       
    24 #include <glxcommandgeneraldefs.h>
       
    25 #include <glxmediageneraldefs.h>
       
    26 #include <mpxcollectionpath.h>
       
    27 #include <mpxcommand.h>
       
    28 #include <mpxcommandgeneraldefs.h>
       
    29 #include <mpxmediageneraldefs.h>
       
    30 
       
    31 /// @todo minor: Rowland Cook 12/06/2007 Add method decription.
       
    32 // -----------------------------------------------------------------------------
       
    33 // TGlxCommandParser::ParseL
       
    34 // -----------------------------------------------------------------------------
       
    35 //	
       
    36 EXPORT_C void TGlxCommandParser::ParseL(MGlxCommandParserCallback& aCommandHandler, const CMPXCommand& aCommand)
       
    37     {
       
    38     TUint32 commandId = ValueL<TUint32>(KMPXCommandGeneralId, aCommand);
       
    39 
       
    40     RArray<TGlxMediaId> sourceIdArray;
       
    41     CleanupClosePushL(sourceIdArray);
       
    42   
       
    43     RArray<TGlxMediaId> targetIdArray;
       
    44     CleanupClosePushL(targetIdArray);
       
    45   
       
    46     switch (commandId)
       
    47         {
       
    48         case KGlxCommandIdAdd:
       
    49             { 
       
    50             TBool hasTitle = aCommand.IsSupported(KMPXMediaGeneralTitle);
       
    51             TBool hasSourceIds = aCommand.IsSupported(KMPXCommandGeneralSourceIds);
       
    52             TBool hasUri = aCommand.IsSupported(KMPXCommandGeneralSourceUri);
       
    53             TBool hasTargetIds = aCommand.IsSupported(KMPXMediaGeneralContainerId);
       
    54             TBool hasDrive = aCommand.IsSupported(KMPXMediaGeneralDrive);
       
    55         
       
    56             if (hasSourceIds)
       
    57                 {            
       
    58                 ArrayValueL(KMPXCommandGeneralSourceIds, sourceIdArray, aCommand);
       
    59                 }
       
    60             if (hasTargetIds)
       
    61                 {
       
    62                 ArrayValueL(KMPXMediaGeneralContainerId, targetIdArray, aCommand);  
       
    63                 }
       
    64 
       
    65 /// @todo minor: Rowland Cook 12/06/2007 Could this be restrctured to be more efficient?
       
    66 //                                       IE - Test for invalid combiations before retrieving the data. 
       
    67             
       
    68             if(hasTitle)
       
    69                 {
       
    70                 if(hasUri || hasSourceIds || hasDrive || hasTargetIds)
       
    71                     {
       
    72                     User::Leave(KErrArgument);
       
    73                     }
       
    74                 aCommandHandler.AddContainerL(DescriptorValueL(KMPXMediaGeneralTitle, aCommand));
       
    75                 }
       
    76             else if (hasUri)
       
    77                 {
       
    78                 if (hasSourceIds || hasDrive || !hasTargetIds)
       
    79                     // Illegal parameter combination
       
    80                     {
       
    81                     User::Leave(KErrArgument);
       
    82                     }
       
    83                 aCommandHandler.AddToContainerL(DescriptorValueL(KMPXCommandGeneralSourceUri, aCommand), targetIdArray);   
       
    84                 }
       
    85             else if (hasSourceIds)
       
    86                 {
       
    87                 if (hasTargetIds)
       
    88                     {
       
    89                     if (hasDrive)
       
    90                     	// Illegal parameter combination
       
    91                     	{
       
    92                     	User::Leave(KErrArgument);
       
    93                     	}
       
    94                     aCommandHandler.AddToContainerL(sourceIdArray, targetIdArray);
       
    95                     }
       
    96                 else if (hasDrive)
       
    97                     {
       
    98                     aCommandHandler.CopyL(sourceIdArray, DescriptorValueL(KMPXMediaGeneralDrive, aCommand));
       
    99                     }
       
   100                 else
       
   101                     // There isn't a target
       
   102                     {
       
   103                     User::Leave(KErrArgument);
       
   104                     }
       
   105                 }
       
   106             else // There isn't a source
       
   107                 {
       
   108                 User::Leave(KErrArgument);
       
   109                 }
       
   110             break;
       
   111             }
       
   112         case KGlxCommandIdRemove:
       
   113             {
       
   114             ArrayValueL(KMPXCommandGeneralSourceIds, sourceIdArray, aCommand);  
       
   115             TGlxMediaId containerId (ValueL<TMPXItemId>(KMPXMediaGeneralContainerId, aCommand));
       
   116             if (containerId == KGlxContainerDevice)
       
   117             	{
       
   118             	aCommandHandler.DeleteL(sourceIdArray);
       
   119             	}
       
   120             else
       
   121             	{
       
   122             	aCommandHandler.RemoveFromContainerL(sourceIdArray, containerId);
       
   123             	}
       
   124             break;
       
   125             }
       
   126         case KGlxCommandIdSet:
       
   127             {    
       
   128             TBool hasTitle = aCommand.IsSupported(KMPXMediaGeneralTitle);
       
   129             TBool hasDrive = aCommand.IsSupported(KMPXMediaGeneralDrive);
       
   130             TBool hasComment = aCommand.IsSupported(KMPXMediaGeneralComment);
       
   131             TBool hasLocation = aCommand.IsSupported(KGlxMediaGeneralLocation);
       
   132             
       
   133             ArrayValueL(KMPXCommandGeneralSourceIds, sourceIdArray, aCommand);
       
   134             
       
   135             if (hasTitle)
       
   136                 // Rename operation
       
   137                 {
       
   138                 if (hasDrive || hasComment || hasLocation || sourceIdArray.Count() < 1)
       
   139                     // Unsupported attribute combination
       
   140                     {
       
   141                     User::Leave(KErrArgument);
       
   142                     }
       
   143                  const TDesC& title = DescriptorValueL(KMPXMediaGeneralTitle, aCommand);
       
   144                  aCommandHandler.RenameL(sourceIdArray[0], title);
       
   145                 }
       
   146             else if (hasDrive)
       
   147                 {
       
   148                 if(hasComment  || hasLocation)
       
   149                     // Unsupported attribute combination
       
   150                     {
       
   151                     User::Leave(KErrArgument);
       
   152                     }
       
   153                 const TDesC& drive = DescriptorValueL(KMPXMediaGeneralDrive, aCommand);
       
   154                 aCommandHandler.MoveL(sourceIdArray, drive);
       
   155                 }
       
   156             else if (hasComment)
       
   157                 {
       
   158                 if ( hasLocation )
       
   159                     // Unsupported attribute combination
       
   160                     {
       
   161                     User::Leave(KErrArgument);
       
   162                     }
       
   163                 const TDesC& comment = DescriptorValueL(KMPXMediaGeneralComment, aCommand);
       
   164                 aCommandHandler.SetDescriptionL(sourceIdArray, comment);
       
   165                 }
       
   166             else if (hasLocation)
       
   167             	{
       
   168             	TCoordinate coordinate = aCommand.ValueTObjectL<TCoordinate>(KGlxMediaGeneralLocation);
       
   169             	aCommandHandler.SetCaptureLocationL(sourceIdArray, coordinate);
       
   170             	}
       
   171             else
       
   172             	{
       
   173                 
       
   174                 User::Leave(KErrArgument);
       
   175             	}
       
   176             break;
       
   177             }
       
   178         case KGlxCommandThumbnailCleanup:
       
   179         	{
       
   180         	aCommandHandler.ThumbnailCleanupL();
       
   181         	break;
       
   182         	}
       
   183         }
       
   184         CleanupStack::PopAndDestroy(&targetIdArray); 
       
   185         CleanupStack::PopAndDestroy(&sourceIdArray);
       
   186  
       
   187     }
       
   188 
       
   189 /// @todo minor: Rowland Cook 12/06/2007 Add method decription.
       
   190 // -----------------------------------------------------------------------------
       
   191 // TGlxCommandParser::IdsL
       
   192 // -----------------------------------------------------------------------------
       
   193 //	
       
   194 EXPORT_C TBool TGlxCommandParser::IdsL(TUid& aCollectionUid, TUint32& aSessionId, const CMPXCommand& aCommand)
       
   195     {	
       
   196 	aCollectionUid = ValueL<TUid>(KMPXCommandGeneralCollectionId, aCommand);    
       
   197     if ( aCommand.IsSupported(KMPXCommandGeneralSessionId) )
       
   198     	{
       
   199     	aSessionId = aCommand.ValueTObjectL<TUint32>(KMPXCommandGeneralSessionId);
       
   200     	return ETrue;
       
   201     	}
       
   202     else
       
   203     	{
       
   204     	return EFalse;
       
   205     	}
       
   206     }
       
   207 
       
   208 /// @todo minor: Rowland Cook 12/06/2007 Add method decription.
       
   209 // -----------------------------------------------------------------------------
       
   210 // TTGlxCommandParser::ArrayValueL
       
   211 // -----------------------------------------------------------------------------
       
   212 //	
       
   213 void TGlxCommandParser::ArrayValueL(const TMPXAttribute & aAttribute, RArray<TGlxMediaId>& aArray, const CMPXCommand& aCommand)
       
   214     {
       
   215     if (!aCommand.IsSupported(aAttribute) || aCommand.Type(aAttribute) != EMPXTypeCObject)
       
   216         {
       
   217         User::Leave(KErrArgument);
       
   218         }
       
   219   
       
   220     const CMPXCollectionPath* path = aCommand.ValueCObjectL<CMPXCollectionPath>(aAttribute);
       
   221 	RArray<TMPXItemId> list;
       
   222     path->SelectionL(list);
       
   223   
       
   224     if (list.Count() == 0) // append the current item
       
   225         {
       
   226         aArray.AppendL(TGlxMediaId(path->Id())); 
       
   227         } 
       
   228     else
       
   229     	{
       
   230     	for( TInt i = 0 ; i < list.Count() ; i++ )
       
   231     		{
       
   232     		aArray.AppendL(TGlxMediaId(list[i]));
       
   233     		}
       
   234     	}
       
   235     }
       
   236 
       
   237 /// @todo minor: Rowland Cook 12/06/2007 Add method decription.
       
   238 // -----------------------------------------------------------------------------
       
   239 // TGlxCommandParser::ValueL
       
   240 // -----------------------------------------------------------------------------
       
   241 //	
       
   242 template<typename T> T TGlxCommandParser::ValueL(const TMPXAttribute & aAttribute, const CMPXCommand& aCommand)
       
   243     {
       
   244     if ( !aCommand.IsSupported(aAttribute) )
       
   245     	{
       
   246         User::Leave(KErrArgument); 	
       
   247     	}
       
   248     return aCommand.ValueTObjectL<T>(aAttribute);
       
   249     }
       
   250 
       
   251 /// @todo minor: Rowland Cook 12/06/2007 Add method decription.
       
   252 // -----------------------------------------------------------------------------
       
   253 // TGlxCommandParser::DescriptorValueL
       
   254 // -----------------------------------------------------------------------------
       
   255 //	
       
   256 const TDesC& TGlxCommandParser::DescriptorValueL(const TMPXAttribute& aAttribute, const CMPXCommand& aCommand)
       
   257     {
       
   258     if (!aCommand.IsSupported(aAttribute) || aCommand.Type(aAttribute) != EMPXTypeText)
       
   259         {
       
   260         User::Leave(KErrArgument);
       
   261         }
       
   262     return aCommand.ValueText(aAttribute);
       
   263     }