|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "glxdatasourcemds.h" |
|
22 |
|
23 #include <fbs.h> |
|
24 #include <glxbackgroundtnmessagedefs.h> |
|
25 #include <glxcollectionmessagedefs.h> |
|
26 #include <glxcommandrequest.h> |
|
27 #include <glxgetrequest.h> |
|
28 #include <glxidlistrequest.h> |
|
29 #include <glxrequest.h> |
|
30 #include <glxthumbnailrequest.h> |
|
31 |
|
32 #ifndef USE_S60_TNM |
|
33 #include <glxtndatabase.h> |
|
34 #include <glxtnthumbnailcreator.h> |
|
35 #endif |
|
36 |
|
37 #include <glxtracer.h> |
|
38 #include <glxlog.h> |
|
39 #include <mdeobjectcondition.h> |
|
40 #include <mderelationcondition.h> |
|
41 #include <mderelationdef.h> |
|
42 #include <mpxmediageneraldefs.h> |
|
43 #include <mpxmessagegeneraldefs.h> |
|
44 |
|
45 #include "glxdatasourcetaskmds.h" |
|
46 #include "glxdatasourcetaskmdsattribute.h" |
|
47 #include "glxdatasourcetaskmdscommand.h" |
|
48 #include "glxdatasourcetaskmdsidlist.h" |
|
49 #include "glxdatasourcetaskmdsthumbnail.h" |
|
50 |
|
51 #ifndef USE_S60_TNM |
|
52 const TInt KGlxThumbnailCleanupAfterDeletions = 200; |
|
53 |
|
54 _LIT(KGlxMdeDataSourceThumbnailDatabase, "glxmdstn"); |
|
55 #endif |
|
56 |
|
57 const TInt KMaxGridThumbnailWidth = 200; |
|
58 |
|
59 _LIT(KObjectDefLocation, "Location"); |
|
60 _LIT(KObjectDefNameAlbum, "Album"); |
|
61 _LIT(KObjectDefNameImage, "Image"); |
|
62 _LIT(KObjectDefNameMedia, "MediaObject"); |
|
63 _LIT(KObjectDefNameObject, "Object"); |
|
64 _LIT(KObjectDefNameTag, "Tag"); |
|
65 _LIT(KObjectDefNameVideo, "Video"); |
|
66 _LIT(KPropertyDefNameCreationDate, "CreationDate"); |
|
67 _LIT(KPropertyDefNameLastModifiedDate, "LastModifiedDate"); |
|
68 _LIT(KPropertyDefNameSize, "Size"); |
|
69 _LIT(KPropertyDefNameTitle, "Title"); |
|
70 _LIT(KRelationDefNameContains, "Contains"); |
|
71 _LIT(KRelationDefNameContainsLocation, "ContainsLocation"); |
|
72 |
|
73 _LIT(KObjectDefNameMonth, "MediaObject");/// @todo nasty hack remove and use base object |
|
74 |
|
75 _LIT(KGlxMdeCameraAlbumUri, "defaultalbum_captured"); |
|
76 _LIT(KGlxMdeFavoritesUri, "defaultalbum_favourites"); |
|
77 |
|
78 #undef __USING_INTELLIGENT_UPDATE_FILTERING |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // MPXChangeEventType |
|
82 // Helper method |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 TMPXChangeEventType MPXChangeEventType(const TObserverNotificationType& aType) |
|
86 { |
|
87 TMPXChangeEventType type = EMPXItemInserted; |
|
88 |
|
89 switch (aType) |
|
90 { |
|
91 case ENotifyAdd: |
|
92 type = EMPXItemInserted; |
|
93 break; |
|
94 case ENotifyModify: |
|
95 type = EMPXItemModified; |
|
96 break; |
|
97 case ENotifyRemove: |
|
98 type = EMPXItemDeleted; |
|
99 break; |
|
100 } |
|
101 return type; |
|
102 } |
|
103 |
|
104 // ============================ MEMBER FUNCTIONS ============================== |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // NewL() |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 CGlxDataSourceMde* CGlxDataSourceMde::NewL() |
|
111 { |
|
112 TRACER("CGlxDataSourceMde* CGlxDataSourceMde::NewL()"); |
|
113 CGlxDataSourceMde* ds = new (ELeave) CGlxDataSourceMde(); |
|
114 CleanupStack::PushL(ds); |
|
115 ds->ConstructL(); |
|
116 CleanupStack::Pop(ds); |
|
117 return ds; |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // ~CGlxDataSourceMde() |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 |
|
125 CGlxDataSourceMde::~CGlxDataSourceMde() |
|
126 { |
|
127 TRACER("CGlxDataSourceMde::~CGlxDataSourceMde()"); |
|
128 delete iSession; |
|
129 |
|
130 #ifdef USE_S60_TNM |
|
131 delete iTnThumbnail; |
|
132 iTnThumbnail = NULL; |
|
133 |
|
134 delete iThumbnail; |
|
135 iThumbnail = NULL; |
|
136 |
|
137 delete iTnEngine; |
|
138 iTnEngine = NULL; |
|
139 #else |
|
140 if (iThumbnailCreator) |
|
141 { |
|
142 iThumbnailCreator->Close(iThumbnailDatabase); |
|
143 } |
|
144 delete iThumbnailDatabase; |
|
145 #endif |
|
146 |
|
147 iFs.Close(); |
|
148 RFbsSession::Disconnect(); |
|
149 iMonthArray.Close(); |
|
150 iMonthList.Close(); |
|
151 iUpdateData.Close(); |
|
152 delete iUpdateCallback; |
|
153 delete iCreateSessionCallback; |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // CGlxDataSourceMde() |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 CGlxDataSourceMde::CGlxDataSourceMde() |
|
161 { |
|
162 TRACER("CGlxDataSourceMde::CGlxDataSourceMde()") |
|
163 //No Implementation |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // ConstructL() |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 void CGlxDataSourceMde::ConstructL() |
|
171 { |
|
172 TRACER("CGlxDataSourceMde::ConstructL()") |
|
173 |
|
174 iDataSourceReady = EFalse; |
|
175 User::LeaveIfError(iFs.Connect()); |
|
176 iSession = CMdESession::NewL( *this ); |
|
177 |
|
178 User::LeaveIfError(RFbsSession::Connect()); |
|
179 |
|
180 #ifdef USE_S60_TNM |
|
181 iTnEngine = CThumbnailManager::NewL( *this); |
|
182 iTnEngine->SetFlagsL(CThumbnailManager::EAllowAnySize); |
|
183 iTnEngine->SetDisplayModeL( EColor64K ); |
|
184 iTnRequestInProgress = EFalse; |
|
185 #else |
|
186 iThumbnailCreator = CGlxtnThumbnailCreator::InstanceL(); |
|
187 iThumbnailDatabase = CGlxtnThumbnailDatabase::NewL( |
|
188 KGlxMdeDataSourceThumbnailDatabase, this); |
|
189 #endif |
|
190 |
|
191 iCreateSessionCallback = new ( ELeave ) |
|
192 CAsyncCallBack( TCallBack( CreateSession, this ), CActive::EPriorityHigh ); |
|
193 iUpdateCallback = new ( ELeave ) |
|
194 CAsyncCallBack( TCallBack( ProcessItemUpdate, this ), CActive::EPriorityLow ); |
|
195 iUpdateData.Reserve(100); // ignore if it fails |
|
196 } |
|
197 |
|
198 // ---------------------------------------------------------------------------- |
|
199 // from MMdESessionObserver |
|
200 // CMPXCollectionMdEPlugin::HandleSessionOpened |
|
201 // ---------------------------------------------------------------------------- |
|
202 // |
|
203 void CGlxDataSourceMde::HandleSessionOpened( CMdESession& aSession, TInt aError ) |
|
204 { |
|
205 TRACER("CGlxDataSourceMde::HandleSessionOpened(CMdESession& aSession, TInt aError)") |
|
206 if( KErrNone != aError ) |
|
207 { |
|
208 HandleSessionError(aSession, aError); |
|
209 } |
|
210 TRAPD(err, DoSessionInitL()); |
|
211 if( KErrNone != err ) |
|
212 { |
|
213 HandleSessionError(aSession, err); |
|
214 } |
|
215 |
|
216 iSessionOpen = ETrue; |
|
217 iDataSourceReady = ETrue; |
|
218 TryStartTask(ETrue); |
|
219 } |
|
220 |
|
221 // ---------------------------------------------------------------------------- |
|
222 // from MMdESessionObserver |
|
223 // CMPXCollectionMdEPlugin::HandleSessionError |
|
224 // ---------------------------------------------------------------------------- |
|
225 // |
|
226 void CGlxDataSourceMde::HandleSessionError(CMdESession& /*aSession*/, TInt /*aError*/ ) |
|
227 { |
|
228 TRACER("CGlxDataSourceMde::HandleSessionError(CMdESession& /*aSession*/, TInt /*aError*/)") |
|
229 iSession = NULL; |
|
230 iDataSourceReady = EFalse; |
|
231 iSessionOpen = EFalse; |
|
232 iCreateSessionCallback->CallBack(); |
|
233 } |
|
234 |
|
235 |
|
236 // --------------------------------------------------------------------------- |
|
237 // CreateTaskL |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 CGlxDataSourceTask* CGlxDataSourceMde::CreateTaskL(CGlxRequest* aRequest, MGlxDataSourceRequestObserver& aObserver) |
|
241 { |
|
242 TRACER("CGlxDataSourceTask* CGlxDataSourceMde::CreateTaskL(CGlxRequest* aRequest, MGlxDataSourceRequestObserver& aObserver)") |
|
243 if(dynamic_cast<CGlxCommandRequest*>(aRequest)) |
|
244 { |
|
245 CleanupStack::PushL(aRequest); |
|
246 CGlxDataSourceTaskMdeCommand* task = new (ELeave) CGlxDataSourceTaskMdeCommand(static_cast<CGlxCommandRequest*>(aRequest), aObserver, this); |
|
247 CleanupStack::Pop(aRequest); // now owned by task |
|
248 CleanupStack::PushL(task); |
|
249 task->ConstructL(); |
|
250 CleanupStack::Pop(task); |
|
251 return task; |
|
252 } |
|
253 else if (dynamic_cast< CGlxGetRequest *>(aRequest)) |
|
254 { |
|
255 _LIT( KFormatTimeStamp, "[%H:%T:%S.%*C5]"); |
|
256 RDebug::Print(_L("==> CGlxDataSourceMde::CreateTaskL - CGlxDataSourceTaskMdeAttributeMde+")); |
|
257 TTime time; |
|
258 time.HomeTime(); // Get home time |
|
259 TBuf<32> timeStampBuf; |
|
260 time.FormatL(timeStampBuf, KFormatTimeStamp); |
|
261 RDebug::Print(_L("%S"), &timeStampBuf); |
|
262 |
|
263 CleanupStack::PushL(aRequest); |
|
264 CGlxDataSourceTaskMdeAttributeMde* task = new (ELeave) CGlxDataSourceTaskMdeAttributeMde(static_cast<CGlxGetRequest*>(aRequest), aObserver, this); |
|
265 CleanupStack::Pop(aRequest); // now owned by task |
|
266 CleanupStack::PushL(task); |
|
267 task->ConstructL(); |
|
268 CleanupStack::Pop(task); |
|
269 return task; |
|
270 } |
|
271 else if (dynamic_cast< CGlxIdListRequest *>(aRequest)) |
|
272 { |
|
273 CleanupStack::PushL(aRequest); |
|
274 CGlxDataSourceTaskMdeIdList* task = new (ELeave) CGlxDataSourceTaskMdeIdList(static_cast<CGlxIdListRequest*>(aRequest), aObserver, this); |
|
275 CleanupStack::Pop(aRequest); // now owned by task |
|
276 CleanupStack::PushL(task); |
|
277 task->ConstructL(); |
|
278 CleanupStack::Pop(task); |
|
279 return task; |
|
280 } |
|
281 else if (dynamic_cast< CGlxThumbnailRequest *>(aRequest)) |
|
282 { |
|
283 _LIT( KFormatTimeStamp, "[%H:%T:%S.%*C5]"); |
|
284 RDebug::Print(_L("==> CGlxDataSourceMde::CreateTaskL - CGlxDataSourceTaskMdeThumbnail+")); |
|
285 TTime time; |
|
286 time.HomeTime(); // Get home time |
|
287 TBuf<32> timeStampBuf; |
|
288 time.FormatL(timeStampBuf, KFormatTimeStamp); |
|
289 RDebug::Print(_L("%S"), &timeStampBuf); |
|
290 |
|
291 CleanupStack::PushL(aRequest); |
|
292 CGlxDataSourceTaskMdeThumbnail* task = new (ELeave) CGlxDataSourceTaskMdeThumbnail(static_cast<CGlxThumbnailRequest*>(aRequest), aObserver, this); |
|
293 CleanupStack::Pop(aRequest); // now owned by task |
|
294 CleanupStack::PushL(task); |
|
295 task->ConstructL(); |
|
296 CleanupStack::Pop(task); |
|
297 return task; |
|
298 } |
|
299 else |
|
300 { |
|
301 User::Leave(KErrNotSupported); |
|
302 return NULL; // stops compiler warning |
|
303 } |
|
304 } |
|
305 |
|
306 #ifndef USE_S60_TNM |
|
307 // --------------------------------------------------------------------------- |
|
308 // ThumbnailAvailable |
|
309 // --------------------------------------------------------------------------- |
|
310 // |
|
311 void CGlxDataSourceMde::ThumbnailAvailable(const TGlxMediaId& /*aId*/, const TSize& /*aSize*/) |
|
312 { |
|
313 TRACER("CGlxDataSourceMde::ThumbnailAvailable(const TGlxMediaId& /*aId*/, const TSize& /*aSize*/)") |
|
314 //No implementation |
|
315 } |
|
316 |
|
317 // --------------------------------------------------------------------------- |
|
318 // BackgroundThumbnailError |
|
319 // --------------------------------------------------------------------------- |
|
320 // |
|
321 void CGlxDataSourceMde::BackgroundThumbnailError(const TGlxMediaId& aId, TInt aError) |
|
322 { |
|
323 TRACER("CGlxDataSourceMde::BackgroundThumbnailError(const TGlxMediaId& aId, TInt aError)") |
|
324 TSize size(0, 0); |
|
325 TRAP_IGNORE(BackgroundThumbnailMessageL(aId, size, aError)); |
|
326 } |
|
327 #endif |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // BackgroundThumbnailMessageL |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 void CGlxDataSourceMde::BackgroundThumbnailMessageL(const TGlxMediaId& aId, const TSize& aSize, TInt aError) |
|
334 { |
|
335 TRACER("CGlxDataSourceMde::BackgroundThumbnailMessageL(const TGlxMediaId& aId, const TSize& aSize, TInt aError)") |
|
336 CMPXMessage* message = CMPXMessage::NewL(); |
|
337 CleanupStack::PushL(message); |
|
338 message->SetTObjectValueL(KMPXMessageGeneralId, KGlxMessageIdBackgroundThumbnail); |
|
339 message->SetTObjectValueL<TMPXItemId>(KGlxBackgroundThumbnailMediaId, aId.Value()); |
|
340 message->SetTObjectValueL(KGlxBackgroundThumbnailSize, aSize); |
|
341 message->SetTObjectValueL(KGlxBackgroundThumbnailError, aError); |
|
342 BroadcastMessage(*message); |
|
343 CleanupStack::PopAndDestroy(message); |
|
344 } |
|
345 |
|
346 // --------------------------------------------------------------------------- |
|
347 // DoSessionInitL |
|
348 // --------------------------------------------------------------------------- |
|
349 // |
|
350 void CGlxDataSourceMde::DoSessionInitL() |
|
351 { |
|
352 TRACER("CGlxDataSourceMde::DoSessionInitL()") |
|
353 /// @todo check schema version number |
|
354 iNameSpaceDef = &iSession->GetDefaultNamespaceDefL(); |
|
355 |
|
356 CMdEObject* cameraAlbum = iSession->GetObjectL(KGlxMdeCameraAlbumUri); |
|
357 if ( !cameraAlbum ) |
|
358 { |
|
359 User::Leave(KErrCorrupt); |
|
360 } |
|
361 iCameraAlbumId = (TGlxMediaId)cameraAlbum->Id(); |
|
362 delete cameraAlbum; |
|
363 |
|
364 CMdEObject* favorites = iSession->GetObjectL(KGlxMdeFavoritesUri); |
|
365 if ( !favorites ) |
|
366 { |
|
367 User::Leave(KErrCorrupt); |
|
368 } |
|
369 iFavoritesId = (TGlxMediaId)favorites->Id(); |
|
370 delete favorites; |
|
371 |
|
372 |
|
373 iContainsDef = &iNameSpaceDef->GetRelationDefL(KRelationDefNameContains); |
|
374 iContainsLocationDef = &iNameSpaceDef->GetRelationDefL(KRelationDefNameContainsLocation); |
|
375 |
|
376 iObjectDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameObject); |
|
377 iImageDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameImage); |
|
378 iVideoDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameVideo); |
|
379 iMediaDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameMedia); |
|
380 iAlbumDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameAlbum); |
|
381 iTagDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameTag); |
|
382 iMonthDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameMonth); |
|
383 iLocationDef = &iNameSpaceDef->GetObjectDefL(KObjectDefLocation); |
|
384 |
|
385 AddMdEObserversL(); |
|
386 |
|
387 PrepareMonthsL(); |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // AddMdEObserversL |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 void CGlxDataSourceMde::AddMdEObserversL() |
|
395 { |
|
396 TRACER("CGlxDataSourceMde::AddMdEObserversL()") |
|
397 iSession->AddRelationObserverL(*this); |
|
398 iSession->AddRelationPresentObserverL(*this); |
|
399 |
|
400 iSession->AddObjectObserverL(*this); |
|
401 iSession->AddObjectPresentObserverL(*this); |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------------------------- |
|
405 // CGlxDataSourceMde::HandleObjectNotification |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 ///@todo AB test this |
|
409 void CGlxDataSourceMde::HandleObjectNotification(CMdESession& /*aSession*/, |
|
410 TObserverNotificationType aType, |
|
411 const RArray<TItemId>& aObjectIdArray) |
|
412 { |
|
413 TRACER("CGlxDataSourceMde::HandleObjectNotification()") |
|
414 ProcessUpdateArray(aObjectIdArray, MPXChangeEventType(aType), ETrue); |
|
415 #ifndef USE_S60_TNM |
|
416 if(MPXChangeEventType(aType) == EMPXItemDeleted ) |
|
417 { |
|
418 TInt count = aObjectIdArray.Count(); |
|
419 iDeletedCount += count; |
|
420 if(iDeletedCount > KGlxThumbnailCleanupAfterDeletions) |
|
421 { |
|
422 TRAPD(err, ThumbnailCreator().CleanupThumbnailsL(iThumbnailDatabase)); |
|
423 if(!err) |
|
424 { |
|
425 iDeletedCount = 0; |
|
426 } |
|
427 } |
|
428 } |
|
429 #endif |
|
430 } |
|
431 |
|
432 |
|
433 // --------------------------------------------------------------------------- |
|
434 // CGlxDataSourceMde::HandleObjectPresentNotification |
|
435 // --------------------------------------------------------------------------- |
|
436 // |
|
437 ///@todo AB test this |
|
438 void CGlxDataSourceMde::HandleObjectPresentNotification(CMdESession& /*aSession*/, |
|
439 TBool aPresent, const RArray<TItemId>& aObjectIdArray) |
|
440 { |
|
441 TRACER("CGlxDataSourceMde::HandleObjectPresentNotification()") |
|
442 if (aPresent) |
|
443 { |
|
444 ProcessUpdateArray(aObjectIdArray, EMPXItemInserted, ETrue); |
|
445 } |
|
446 else |
|
447 { |
|
448 ProcessUpdateArray(aObjectIdArray, EMPXItemDeleted, ETrue); |
|
449 } |
|
450 } |
|
451 |
|
452 // --------------------------------------------------------------------------- |
|
453 // CGlxDataSourceMde::HandleRelationNotification |
|
454 // --------------------------------------------------------------------------- |
|
455 // |
|
456 ///@todo AB test this |
|
457 void CGlxDataSourceMde::HandleRelationNotification(CMdESession& /*aSession*/, |
|
458 TObserverNotificationType aType, |
|
459 const RArray<TItemId>& aRelationIdArray) |
|
460 { |
|
461 TRACER("CGlxDataSourceMde::HandleRelationNotification()") |
|
462 ProcessUpdateArray(aRelationIdArray, MPXChangeEventType(aType), EFalse); |
|
463 } |
|
464 |
|
465 // --------------------------------------------------------------------------- |
|
466 // CGlxDataSourceMde::HandleRelationPresentNotification |
|
467 // --------------------------------------------------------------------------- |
|
468 // |
|
469 ///@todo AB test this |
|
470 void CGlxDataSourceMde::HandleRelationPresentNotification(CMdESession& /*aSession*/, |
|
471 TBool aPresent, const RArray<TItemId>& aRelationIdArray) |
|
472 { |
|
473 TRACER("CGlxDataSourceMde::HandleRelationPresentNotification()") |
|
474 if (aPresent) |
|
475 { |
|
476 ProcessUpdateArray(aRelationIdArray, EMPXItemInserted, EFalse); |
|
477 } |
|
478 else |
|
479 { |
|
480 ProcessUpdateArray(aRelationIdArray, EMPXItemDeleted, EFalse); |
|
481 } |
|
482 } |
|
483 |
|
484 // --------------------------------------------------------------------------- |
|
485 // ProcessUpdateArray |
|
486 // --------------------------------------------------------------------------- |
|
487 // |
|
488 void CGlxDataSourceMde::ProcessUpdateArray(const RArray<TItemId>& aArray, TMPXChangeEventType aType, TBool aIsObject) |
|
489 { |
|
490 TRACER("CGlxDataSourceMde::ProcessUpdateArray(const RArray<TItemId>& aArray, TMPXChangeEventType aType, TBool aIsObject)") |
|
491 // only need one message so process first item |
|
492 TUpdateData update; |
|
493 update.iId = aArray[0]; |
|
494 update.iType = aType; |
|
495 update.iIsObject = aIsObject; |
|
496 if( iUpdateData.Count() ) |
|
497 { |
|
498 if( ( iUpdateData[0].iType == aType ) && ( iUpdateData[0].iIsObject ) ) |
|
499 { |
|
500 return; |
|
501 } |
|
502 } |
|
503 if( iUpdateData.Append(update) == KErrNone ) // if we can't allocate space for the update, ignore it |
|
504 { |
|
505 iUpdateCallback->CallBack(); |
|
506 } |
|
507 } |
|
508 |
|
509 // --------------------------------------------------------------------------- |
|
510 // MPXChangeEventType |
|
511 // --------------------------------------------------------------------------- |
|
512 // |
|
513 TInt CGlxDataSourceMde::CreateSession(TAny* aPtr) |
|
514 { |
|
515 TRACER("CGlxDataSourceMde::CreateSession(TAny* aPtr)") |
|
516 CGlxDataSourceMde* self |
|
517 = reinterpret_cast<CGlxDataSourceMde*>( aPtr ); |
|
518 TRAP_IGNORE(self->CreateSessionL()); |
|
519 return 0; |
|
520 } |
|
521 |
|
522 // --------------------------------------------------------------------------- |
|
523 // CreateSessionL |
|
524 // --------------------------------------------------------------------------- |
|
525 // |
|
526 void CGlxDataSourceMde::CreateSessionL() |
|
527 { |
|
528 TRACER("CGlxDataSourceMde::CreateSessionL()") |
|
529 iSession = CMdESession::NewL( *this ); |
|
530 } |
|
531 |
|
532 |
|
533 // --------------------------------------------------------------------------- |
|
534 // ProcessItemUpdate |
|
535 // --------------------------------------------------------------------------- |
|
536 // |
|
537 TInt CGlxDataSourceMde::ProcessItemUpdate(TAny* aPtr) |
|
538 { |
|
539 TRACER("CGlxDataSourceMde::ProcessItemUpdate(TAny* aPtr)") |
|
540 CGlxDataSourceMde* self |
|
541 = reinterpret_cast<CGlxDataSourceMde*>( aPtr ); |
|
542 TRAP_IGNORE(self->ProcessItemUpdateL()); |
|
543 return 0; |
|
544 } |
|
545 |
|
546 // --------------------------------------------------------------------------- |
|
547 // ProcessItemUpdateL |
|
548 // --------------------------------------------------------------------------- |
|
549 // |
|
550 void CGlxDataSourceMde::ProcessItemUpdateL() |
|
551 { |
|
552 TRACER("CGlxDataSourceMde::ProcessItemUpdateL()") |
|
553 //__ASSERT_DEBUG(iUpdateData.Count(), Panic(EGlxPanicIllegalState)); |
|
554 if ( !iUpdateData.Count() || iPauseUpdate ) |
|
555 { |
|
556 return; |
|
557 } |
|
558 CMPXMessage* message = CMPXMessage::NewL(); |
|
559 CleanupStack::PushL(message); |
|
560 message->SetTObjectValueL<TInt>(KMPXMessageGeneralId, KMPXMessageIdItemChanged); |
|
561 message->SetTObjectValueL<TMPXChangeEventType>(KMPXMessageChangeEventType, iUpdateData[0].iType); |
|
562 TMPXGeneralCategory category = EMPXNoCategory; |
|
563 TMPXItemId id = iUpdateData[0].iId; |
|
564 |
|
565 #ifdef __USING_INTELLIGENT_UPDATE_FILTERING |
|
566 if ( !iUpdateData[0].iIsObject ) |
|
567 { |
|
568 TMPXGeneralCategory containerCategory = EMPXNoCategory; |
|
569 TMPXItemId containerId; |
|
570 |
|
571 CMdERelation* relation = iSession->GetRelationL(id); |
|
572 if( relation ) |
|
573 { |
|
574 TItemId rightId = relation->RightObjectId(); |
|
575 TItemId leftId = relation->LeftObjectId(); |
|
576 delete relation; |
|
577 |
|
578 CMdEObject* contObject = iSession->GetObjectL(leftId); |
|
579 __ASSERT_DEBUG(contObject, Panic(EGlxPanicIllegalState)); |
|
580 TContainerType container = ContainerType(contObject); |
|
581 delete contObject; |
|
582 __ASSERT_DEBUG(( EContainerTypeTag != container), Panic(EGlxPanicIllegalState)); |
|
583 if( EContainerTypeNotAContainer == container ) |
|
584 { |
|
585 CMdEObject* rightObject = iSession->GetObjectL(rightId); |
|
586 __ASSERT_DEBUG(rightObject, Panic(EGlxPanicIllegalState)); |
|
587 TContainerType rightContainer = ContainerType(rightObject); |
|
588 delete rightObject; |
|
589 __ASSERT_DEBUG(( EContainerTypeAlbum != rightContainer), Panic(EGlxPanicIllegalState)); |
|
590 if( EContainerTypeTag == rightContainer ) |
|
591 { |
|
592 id = leftId; |
|
593 containerId = rightId; |
|
594 containerCategory = EMPXTag; |
|
595 } |
|
596 else if( EContainerTypeNotAContainer == rightContainer ) |
|
597 { |
|
598 User::Leave(KErrNotSupported); // Not a gallery relation. |
|
599 } |
|
600 } |
|
601 else if( EContainerTypeAlbum == container) |
|
602 { |
|
603 id = rightId; |
|
604 containerId = leftId; |
|
605 containerCategory = EMPXAlbum; |
|
606 } |
|
607 message->SetTObjectValueL<TMPXGeneralCategory>(KGlxCollectionMessageContainerCategory, containerCategory); |
|
608 message->SetTObjectValueL<TMPXItemId>(KGlxCollectionMessageContainerId, containerId); |
|
609 } |
|
610 else |
|
611 { |
|
612 // use id 0 to identify to ML that we don't know what was deleted |
|
613 id = 0; |
|
614 } |
|
615 } |
|
616 |
|
617 if ( id != 0 ) |
|
618 { |
|
619 CMdEObject* object = iSession->GetObjectL(id); |
|
620 if( object ) |
|
621 { |
|
622 TContainerType container = ContainerType(object); |
|
623 if( EContainerTypeAlbum == container) |
|
624 { |
|
625 category = EMPXAlbum; |
|
626 } |
|
627 else if( EContainerTypeTag == container) |
|
628 { |
|
629 category = EMPXTag; |
|
630 } |
|
631 else |
|
632 { |
|
633 TItemType item = ItemType(object); |
|
634 if( EItemTypeImage == item) |
|
635 { |
|
636 category = EMPXImage; |
|
637 } |
|
638 else if( EItemTypeVideo == item) |
|
639 { |
|
640 category = EMPXVideo; |
|
641 } |
|
642 } |
|
643 delete object; |
|
644 } |
|
645 } |
|
646 #endif // __USING_INTELLIGENT_UPDATE_FILTERING |
|
647 message->SetTObjectValueL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory, category); |
|
648 message->SetTObjectValueL<TMPXItemId>(KMPXMessageMediaGeneralId, id); |
|
649 BroadcastMessage(*message); |
|
650 CleanupStack::PopAndDestroy(message); |
|
651 iUpdateData.Remove(0); |
|
652 } |
|
653 |
|
654 // --------------------------------------------------------------------------- |
|
655 // ContainerType |
|
656 // --------------------------------------------------------------------------- |
|
657 // |
|
658 CGlxDataSource::TContainerType CGlxDataSourceMde::ContainerType(CMdEObject* aObject) |
|
659 { |
|
660 TRACER("CGlxDataSourceMde::ContainerType(CMdEObject* aObject)") |
|
661 TContainerType containerType = EContainerTypeNotAContainer; |
|
662 |
|
663 if( 0 == aObject->Def().Compare(*iAlbumDef) ) |
|
664 { |
|
665 containerType = EContainerTypeAlbum; |
|
666 } |
|
667 else if( 0 == aObject->Def().Compare(*iTagDef) ) |
|
668 { |
|
669 containerType = EContainerTypeTag; |
|
670 } |
|
671 else if( 0 == aObject->Def().Compare(*iMonthDef) ) |
|
672 { |
|
673 containerType = EContainerTypeMonth; |
|
674 } |
|
675 |
|
676 return containerType; |
|
677 } |
|
678 |
|
679 |
|
680 // --------------------------------------------------------------------------- |
|
681 // ContainerType |
|
682 // --------------------------------------------------------------------------- |
|
683 // |
|
684 CGlxDataSource::TContainerType CGlxDataSourceMde::ContainerType(CMdEObjectDef* aObjectDef) |
|
685 { |
|
686 TRACER("CGlxDataSourceMde::ContainerType(CMdEObjectDef* aObjectDef)") |
|
687 TContainerType containerType = EContainerTypeNotAContainer; |
|
688 |
|
689 if( 0 == aObjectDef->Compare(*iAlbumDef) ) |
|
690 { |
|
691 containerType = EContainerTypeAlbum; |
|
692 } |
|
693 else if( 0 == aObjectDef->Compare(*iTagDef) ) |
|
694 { |
|
695 containerType = EContainerTypeTag; |
|
696 } |
|
697 else if( 0 == aObjectDef->Compare(*iMonthDef) ) |
|
698 { |
|
699 containerType = EContainerTypeMonth; |
|
700 } |
|
701 |
|
702 return containerType; |
|
703 } |
|
704 |
|
705 // --------------------------------------------------------------------------- |
|
706 // ItemType() |
|
707 // --------------------------------------------------------------------------- |
|
708 // |
|
709 CGlxDataSource::TItemType CGlxDataSourceMde::ItemType(CMdEObject* aObject) |
|
710 { |
|
711 TRACER("CGlxDataSourceMde::ItemType(CMdEObject* aObject)") |
|
712 TItemType itemType = EItemTypeNotAnItem; |
|
713 |
|
714 if( 0 == aObject->Def().Compare(*iImageDef) ) |
|
715 { |
|
716 itemType = EItemTypeImage; |
|
717 } |
|
718 else if(0 == aObject->Def().Compare(*iVideoDef) ) |
|
719 { |
|
720 itemType = EItemTypeVideo; |
|
721 } |
|
722 |
|
723 return itemType; |
|
724 } |
|
725 |
|
726 // --------------------------------------------------------------------------- |
|
727 // PrepareMonthsL() |
|
728 // --------------------------------------------------------------------------- |
|
729 // |
|
730 void CGlxDataSourceMde::PrepareMonthsL() |
|
731 { |
|
732 TRACER("CGlxDataSourceMde::PrepareMonthsL()") |
|
733 TTime month(0); |
|
734 iFirstMonth = month; |
|
735 } |
|
736 |
|
737 // --------------------------------------------------------------------------- |
|
738 // GetMonthIdL() |
|
739 // --------------------------------------------------------------------------- |
|
740 // |
|
741 const TGlxMediaId CGlxDataSourceMde::GetMonthIdL(const TTime& aMonth) |
|
742 { |
|
743 TRACER("CGlxDataSourceMde::GetMonthIdL(const TTime& aMonth)") |
|
744 TTime monthStart = iFirstMonth + aMonth.MonthsFrom(iFirstMonth); |
|
745 const TTimeIntervalMonths KGlxOneMonth = 1; |
|
746 const TTimeIntervalMicroSeconds KGlxOneMicrosecond = 1; |
|
747 |
|
748 TGlxMediaId monthId; |
|
749 TInt monthIndex = iMonthArray.Find(monthStart); |
|
750 if( monthIndex != KErrNotFound ) |
|
751 { |
|
752 monthId = iMonthList[monthIndex]; |
|
753 } |
|
754 else |
|
755 { |
|
756 _LIT(KGlxMonthTitleFormat, "%F%Y%M%D:"); |
|
757 const TInt KGlxMonthTitleLength = 12; |
|
758 TBuf<KGlxMonthTitleLength> title; |
|
759 monthStart.FormatL(title, KGlxMonthTitleFormat); |
|
760 |
|
761 CMdEObject* month = iSession->GetObjectL(title); |
|
762 if( month ) |
|
763 { |
|
764 monthId = (TGlxMediaId)month->Id(); |
|
765 iMonthArray.AppendL(monthStart); |
|
766 iMonthList.AppendL(monthId); |
|
767 delete month; |
|
768 } |
|
769 else |
|
770 { |
|
771 TTime monthEnd = monthStart + KGlxOneMonth - KGlxOneMicrosecond; |
|
772 month = iSession->NewObjectLC(*iMonthDef, title); |
|
773 |
|
774 // A title property def of type text is required. |
|
775 CMdEPropertyDef& titlePropertyDef = iObjectDef->GetPropertyDefL(KPropertyDefNameTitle); |
|
776 if (titlePropertyDef.PropertyType() != EPropertyText) |
|
777 { |
|
778 User::Leave(KErrCorrupt); |
|
779 } |
|
780 // Set the object title. |
|
781 month->AddTextPropertyL (titlePropertyDef, title); |
|
782 |
|
783 // A size property is required. |
|
784 CMdEPropertyDef& sizePropertyDef = iObjectDef->GetPropertyDefL(KPropertyDefNameSize); |
|
785 if (sizePropertyDef.PropertyType() != EPropertyUint32) |
|
786 { |
|
787 User::Leave(KErrCorrupt); |
|
788 } |
|
789 month->AddUint32PropertyL(sizePropertyDef,0); |
|
790 |
|
791 |
|
792 // A creation date property is required. |
|
793 CMdEPropertyDef& creationDateDef = iObjectDef->GetPropertyDefL(KPropertyDefNameCreationDate); |
|
794 if (creationDateDef.PropertyType() != EPropertyTime) |
|
795 { |
|
796 User::Leave(KErrCorrupt); |
|
797 } |
|
798 month->AddTimePropertyL(creationDateDef, monthStart); |
|
799 |
|
800 // A last modified date property is required. |
|
801 CMdEPropertyDef& lmDateDef = iObjectDef->GetPropertyDefL(KPropertyDefNameLastModifiedDate); |
|
802 if (lmDateDef.PropertyType() != EPropertyTime) |
|
803 { |
|
804 User::Leave(KErrCorrupt); |
|
805 } |
|
806 |
|
807 month->AddTimePropertyL(lmDateDef, monthEnd); |
|
808 |
|
809 monthId = (TGlxMediaId)iSession->AddObjectL(*month); |
|
810 CleanupStack::PopAndDestroy(month); |
|
811 iMonthArray.AppendL(monthStart); |
|
812 iMonthList.AppendL(monthId); |
|
813 } |
|
814 } |
|
815 return monthId; |
|
816 } |
|
817 |
|
818 // --------------------------------------------------------------------------- |
|
819 // SameMonth |
|
820 // --------------------------------------------------------------------------- |
|
821 // |
|
822 TBool CGlxDataSourceMde::SameMonth(const TTime& aOldDate, const TTime& aNewDate) |
|
823 { |
|
824 TRACER("CGlxDataSourceMde::SameMonth(const TTime& aOldDate, const TTime& aNewDate)") |
|
825 return ( aOldDate.MonthsFrom(iFirstMonth) == aNewDate.MonthsFrom(iFirstMonth) ); |
|
826 } |
|
827 |
|
828 // --------------------------------------------------------------------------- |
|
829 // ContainerIsLeft |
|
830 // --------------------------------------------------------------------------- |
|
831 // |
|
832 TBool CGlxDataSourceMde::ContainerIsLeft(CMdEObjectDef& aObjectDef) |
|
833 { |
|
834 TRACER("CGlxDataSourceMde::ContainerIsLeft(CMdEObjectDef& aObjectDef)") |
|
835 TBool containerLeft = EFalse; |
|
836 if ( 0 == aObjectDef.Compare(AlbumDef()) ) |
|
837 { |
|
838 containerLeft = ETrue; |
|
839 } |
|
840 return containerLeft; |
|
841 } |
|
842 |
|
843 // --------------------------------------------------------------------------- |
|
844 // CGlxDataSource |
|
845 // TaskCompletedL |
|
846 // --------------------------------------------------------------------------- |
|
847 // |
|
848 void CGlxDataSourceMde::TaskCompletedL() |
|
849 { |
|
850 iPauseUpdate = EFalse; |
|
851 iUpdateCallback->CallBack(); |
|
852 } |
|
853 |
|
854 // --------------------------------------------------------------------------- |
|
855 // CGlxDataSource |
|
856 // TaskStartedL |
|
857 // --------------------------------------------------------------------------- |
|
858 // |
|
859 void CGlxDataSourceMde::TaskStartedL() |
|
860 { |
|
861 iPauseUpdate = ETrue; |
|
862 } |
|
863 |
|
864 #ifdef USE_S60_TNM |
|
865 void CGlxDataSourceMde::FetchThumbnailL(CGlxRequest* aRequest, MThumbnailFetchRequestObserver& aObserver) |
|
866 { |
|
867 iTnFetchObserver = &aObserver; |
|
868 |
|
869 CGlxThumbnailRequest* request = static_cast<CGlxThumbnailRequest*>(aRequest); |
|
870 |
|
871 TGlxThumbnailRequest tnReq; |
|
872 request->ThumbnailRequest(tnReq); |
|
873 User::LeaveIfNull(request->ThumbnailInfo()); |
|
874 |
|
875 iTnHandle = tnReq.iBitmapHandle; |
|
876 iMediaId = tnReq.iId; |
|
877 if (tnReq.iSizeClass.iWidth < KMaxGridThumbnailWidth) |
|
878 { |
|
879 iTnEngine->SetFlagsL(CThumbnailManager::ECropToAspectRatio); |
|
880 iTnEngine->SetThumbnailSizeL(EGridThumbnailSize); |
|
881 GLX_LOG_INFO("CGlxDataSourceMde::FetchThumbnailL() - Fetch TN attrib - EGridThumbnailSize"); |
|
882 } |
|
883 else |
|
884 { |
|
885 iTnEngine->SetFlagsL(CThumbnailManager::EDefaultFlags); |
|
886 iTnEngine->SetThumbnailSizeL(EFullScreenThumbnailSize); |
|
887 GLX_LOG_INFO("CGlxDataSourceMde::FetchThumbnailL() - Fetch TN attrib - EFullScreenThumbnailSize"); |
|
888 } |
|
889 CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(request->ThumbnailInfo()->FilePath(), 0); |
|
890 iStartTime.UniversalTime(); |
|
891 iTnThumbnailCbId = iTnEngine->GetThumbnailL(*source); |
|
892 iTnRequestInProgress = ETrue; |
|
893 CleanupStack::PopAndDestroy(); |
|
894 } |
|
895 |
|
896 TInt CGlxDataSourceMde::CancelFetchThumbnail() |
|
897 { |
|
898 TInt ret = KErrNone; |
|
899 if (iTnRequestInProgress) |
|
900 { |
|
901 ret = iTnEngine->CancelRequest(iTnThumbnailCbId); |
|
902 } |
|
903 return ret; |
|
904 } |
|
905 |
|
906 void CGlxDataSourceMde::ThumbnailPreviewReady(MThumbnailData& /*aThumbnail*/, |
|
907 TThumbnailRequestId /*aId*/) |
|
908 { |
|
909 } |
|
910 |
|
911 // Called when real thumbnail is created |
|
912 void CGlxDataSourceMde::ThumbnailReady(TInt aError, |
|
913 MThumbnailData& aThumbnail, TThumbnailRequestId aId) |
|
914 { |
|
915 if (iTnThumbnailCbId == aId) |
|
916 { |
|
917 iTnRequestInProgress = EFalse; |
|
918 iStopTime.UniversalTime(); |
|
919 RDebug::Print(_L("==> S60 TNMan fetch took <%d> us"), (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64()); |
|
920 |
|
921 if (aError == KErrNone && iTnHandle) |
|
922 { |
|
923 if (iTnHandle == KGlxMessageIdBackgroundThumbnail) |
|
924 { |
|
925 BackgroundThumbnailMessageL(iMediaId, TSize(), aError); |
|
926 } |
|
927 else |
|
928 { |
|
929 delete iTnThumbnail; |
|
930 iTnThumbnail = NULL; |
|
931 iTnThumbnail = aThumbnail.DetachBitmap(); |
|
932 |
|
933 delete iThumbnail; |
|
934 iThumbnail = NULL; |
|
935 iThumbnail = new (ELeave) CFbsBitmap(); |
|
936 User::LeaveIfError( iThumbnail->Duplicate(iTnHandle)); |
|
937 User::LeaveIfError(iThumbnail->Resize(iTnThumbnail->SizeInPixels())); |
|
938 CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(iThumbnail); |
|
939 CleanupStack::PushL(device ); |
|
940 CFbsBitGc* context = NULL; |
|
941 User::LeaveIfError(device->CreateContext(context)); |
|
942 CleanupStack::PushL(context); |
|
943 context->BitBlt( TPoint(), iTnThumbnail); |
|
944 CleanupStack::PopAndDestroy(context); |
|
945 CleanupStack::PopAndDestroy(device); |
|
946 } |
|
947 } |
|
948 |
|
949 if (iTnFetchObserver) |
|
950 { |
|
951 iTnFetchObserver->ThumbnailFetchComplete(aError); |
|
952 iTnHandle = KErrNone; |
|
953 } |
|
954 } |
|
955 } |
|
956 #endif |