|
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 if(hasTitle) |
|
65 { |
|
66 if(hasUri || hasSourceIds || hasDrive || hasTargetIds) |
|
67 { |
|
68 User::Leave(KErrArgument); |
|
69 } |
|
70 aCommandHandler.AddContainerL(DescriptorValueL(KMPXMediaGeneralTitle, aCommand)); |
|
71 } |
|
72 else if (hasUri) |
|
73 { |
|
74 if (hasSourceIds || hasDrive || !hasTargetIds) |
|
75 // Illegal parameter combination |
|
76 { |
|
77 User::Leave(KErrArgument); |
|
78 } |
|
79 aCommandHandler.AddToContainerL(DescriptorValueL(KMPXCommandGeneralSourceUri, aCommand), targetIdArray); |
|
80 } |
|
81 else if (hasSourceIds) |
|
82 { |
|
83 if (hasTargetIds) |
|
84 { |
|
85 if (hasDrive) |
|
86 // Illegal parameter combination |
|
87 { |
|
88 User::Leave(KErrArgument); |
|
89 } |
|
90 aCommandHandler.AddToContainerL(sourceIdArray, targetIdArray); |
|
91 } |
|
92 else if (hasDrive) |
|
93 { |
|
94 aCommandHandler.CopyL(sourceIdArray, DescriptorValueL(KMPXMediaGeneralDrive, aCommand)); |
|
95 } |
|
96 else |
|
97 // There isn't a target |
|
98 { |
|
99 User::Leave(KErrArgument); |
|
100 } |
|
101 } |
|
102 else // There isn't a source |
|
103 { |
|
104 User::Leave(KErrArgument); |
|
105 } |
|
106 break; |
|
107 } |
|
108 case KGlxCommandIdRemove: |
|
109 { |
|
110 ArrayValueL(KMPXCommandGeneralSourceIds, sourceIdArray, aCommand); |
|
111 TGlxMediaId containerId (ValueL<TMPXItemId>(KMPXMediaGeneralContainerId, aCommand)); |
|
112 if (containerId == KGlxContainerDevice) |
|
113 { |
|
114 aCommandHandler.DeleteL(sourceIdArray); |
|
115 } |
|
116 else |
|
117 { |
|
118 aCommandHandler.RemoveFromContainerL(sourceIdArray, containerId); |
|
119 } |
|
120 break; |
|
121 } |
|
122 case KGlxCommandIdSet: |
|
123 { |
|
124 TBool hasTitle = aCommand.IsSupported(KMPXMediaGeneralTitle); |
|
125 TBool hasDrive = aCommand.IsSupported(KMPXMediaGeneralDrive); |
|
126 TBool hasComment = aCommand.IsSupported(KMPXMediaGeneralComment); |
|
127 TBool hasLocation = aCommand.IsSupported(KGlxMediaGeneralLocation); |
|
128 |
|
129 ArrayValueL(KMPXCommandGeneralSourceIds, sourceIdArray, aCommand); |
|
130 |
|
131 if (hasTitle) |
|
132 // Rename operation |
|
133 { |
|
134 if (hasDrive || hasComment || hasLocation || sourceIdArray.Count() < 1) |
|
135 // Unsupported attribute combination |
|
136 { |
|
137 User::Leave(KErrArgument); |
|
138 } |
|
139 const TDesC& title = DescriptorValueL(KMPXMediaGeneralTitle, aCommand); |
|
140 aCommandHandler.RenameL(sourceIdArray[0], title); |
|
141 } |
|
142 else if (hasDrive) |
|
143 { |
|
144 if(hasComment || hasLocation) |
|
145 // Unsupported attribute combination |
|
146 { |
|
147 User::Leave(KErrArgument); |
|
148 } |
|
149 const TDesC& drive = DescriptorValueL(KMPXMediaGeneralDrive, aCommand); |
|
150 aCommandHandler.MoveL(sourceIdArray, drive); |
|
151 } |
|
152 else if (hasComment) |
|
153 { |
|
154 if ( hasLocation ) |
|
155 // Unsupported attribute combination |
|
156 { |
|
157 User::Leave(KErrArgument); |
|
158 } |
|
159 const TDesC& comment = DescriptorValueL(KMPXMediaGeneralComment, aCommand); |
|
160 aCommandHandler.SetDescriptionL(sourceIdArray, comment); |
|
161 } |
|
162 else if (hasLocation) |
|
163 { |
|
164 TCoordinate coordinate = aCommand.ValueTObjectL<TCoordinate>(KGlxMediaGeneralLocation); |
|
165 aCommandHandler.SetCaptureLocationL(sourceIdArray, coordinate); |
|
166 } |
|
167 else |
|
168 { |
|
169 |
|
170 User::Leave(KErrArgument); |
|
171 } |
|
172 break; |
|
173 } |
|
174 case KGlxCommandThumbnailCleanup: |
|
175 { |
|
176 aCommandHandler.ThumbnailCleanupL(); |
|
177 break; |
|
178 } |
|
179 } |
|
180 CleanupStack::PopAndDestroy(&targetIdArray); |
|
181 CleanupStack::PopAndDestroy(&sourceIdArray); |
|
182 |
|
183 } |
|
184 |
|
185 /// @todo minor: Rowland Cook 12/06/2007 Add method decription. |
|
186 // ----------------------------------------------------------------------------- |
|
187 // TGlxCommandParser::IdsL |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 EXPORT_C TBool TGlxCommandParser::IdsL(TUid& aCollectionUid, TUint32& aSessionId, const CMPXCommand& aCommand) |
|
191 { |
|
192 aCollectionUid = ValueL<TUid>(KMPXCommandGeneralCollectionId, aCommand); |
|
193 if ( aCommand.IsSupported(KMPXCommandGeneralSessionId) ) |
|
194 { |
|
195 aSessionId = aCommand.ValueTObjectL<TUint32>(KMPXCommandGeneralSessionId); |
|
196 return ETrue; |
|
197 } |
|
198 else |
|
199 { |
|
200 return EFalse; |
|
201 } |
|
202 } |
|
203 |
|
204 /// @todo minor: Rowland Cook 12/06/2007 Add method decription. |
|
205 // ----------------------------------------------------------------------------- |
|
206 // TTGlxCommandParser::ArrayValueL |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void TGlxCommandParser::ArrayValueL(const TMPXAttribute & aAttribute, |
|
210 RArray<TGlxMediaId>& aArray, const CMPXCommand& aCommand) |
|
211 { |
|
212 CleanupClosePushL(aArray); |
|
213 if (!aCommand.IsSupported(aAttribute) || aCommand.Type(aAttribute) != EMPXTypeCObject) |
|
214 { |
|
215 User::Leave(KErrArgument); |
|
216 } |
|
217 |
|
218 CMPXCollectionPath* path = aCommand.ValueCObjectL<CMPXCollectionPath>(aAttribute); |
|
219 // ValueCObjectL returns the ownership of path, hence we need to delete |
|
220 CleanupStack::PushL(path); |
|
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 CleanupStack::PopAndDestroy(path); |
|
236 CleanupStack::Pop(&aArray); |
|
237 } |
|
238 |
|
239 /// @todo minor: Rowland Cook 12/06/2007 Add method decription. |
|
240 // ----------------------------------------------------------------------------- |
|
241 // TGlxCommandParser::ValueL |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 template<typename T> T TGlxCommandParser::ValueL(const TMPXAttribute & aAttribute, const CMPXCommand& aCommand) |
|
245 { |
|
246 if ( !aCommand.IsSupported(aAttribute) ) |
|
247 { |
|
248 User::Leave(KErrArgument); |
|
249 } |
|
250 return aCommand.ValueTObjectL<T>(aAttribute); |
|
251 } |
|
252 |
|
253 /// @todo minor: Rowland Cook 12/06/2007 Add method decription. |
|
254 // ----------------------------------------------------------------------------- |
|
255 // TGlxCommandParser::DescriptorValueL |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 const TDesC& TGlxCommandParser::DescriptorValueL(const TMPXAttribute& aAttribute, const CMPXCommand& aCommand) |
|
259 { |
|
260 if (!aCommand.IsSupported(aAttribute) || aCommand.Type(aAttribute) != EMPXTypeText) |
|
261 { |
|
262 User::Leave(KErrArgument); |
|
263 } |
|
264 return aCommand.ValueText(aAttribute); |
|
265 } |