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