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