|
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 <e32base.h> |
|
24 #include <fbs.h> |
|
25 #include <glxbackgroundtnmessagedefs.h> |
|
26 #include <glxcollectionmessagedefs.h> |
|
27 #include <glxcommandrequest.h> |
|
28 #include <glxgetrequest.h> |
|
29 #include <glxidlistrequest.h> |
|
30 #include <glxrequest.h> |
|
31 #include <glxthumbnailrequest.h> |
|
32 |
|
33 #ifndef USE_S60_TNM |
|
34 #include <glxtndatabase.h> |
|
35 #include <glxtnthumbnailcreator.h> |
|
36 #endif |
|
37 |
|
38 #include <glxtracer.h> |
|
39 #include <glxlog.h> |
|
40 #include <mdeobjectcondition.h> |
|
41 #include <mderelationcondition.h> |
|
42 #include <mderelationdef.h> |
|
43 #include <mpxmediageneraldefs.h> |
|
44 #include <mpxmessagegeneraldefs.h> |
|
45 |
|
46 #include "glxdatasourcetaskmds.h" |
|
47 #include "glxdatasourcetaskmdsattribute.h" |
|
48 #include "glxdatasourcetaskmdscommand.h" |
|
49 #include "glxdatasourcetaskmdsidlist.h" |
|
50 #include "glxdatasourcetaskmdsthumbnail.h" |
|
51 |
|
52 #ifdef USE_S60_TNM |
|
53 const TInt KMaxGridThumbnailWidth = 200; |
|
54 #else |
|
55 const TInt KGlxThumbnailCleanupAfterDeletions = 200; |
|
56 |
|
57 _LIT(KGlxMdeDataSourceThumbnailDatabase, "glxmdstn"); |
|
58 #endif |
|
59 |
|
60 _LIT(KObjectDefLocation, "Location"); |
|
61 _LIT(KObjectDefNameAlbum, "Album"); |
|
62 _LIT(KObjectDefNameImage, "Image"); |
|
63 _LIT(KObjectDefNameMedia, "MediaObject"); |
|
64 _LIT(KObjectDefNameObject, "Object"); |
|
65 _LIT(KObjectDefNameTag, "Tag"); |
|
66 _LIT(KObjectDefNameVideo, "Video"); |
|
67 _LIT(KPropertyDefNameCreationDate, "CreationDate"); |
|
68 _LIT(KPropertyDefNameLastModifiedDate, "LastModifiedDate"); |
|
69 _LIT(KPropertyDefNameSize, "Size"); |
|
70 _LIT(KPropertyDefNameTitle, "Title"); |
|
71 _LIT(KRelationDefNameContains, "Contains"); |
|
72 _LIT(KRelationDefNameContainsLocation, "ContainsLocation"); |
|
73 |
|
74 _LIT(KObjectDefNameMonth, "MediaObject");/// @todo nasty hack remove and use base object |
|
75 |
|
76 _LIT(KGlxMdeCameraAlbumUri, "defaultalbum_captured"); |
|
77 _LIT(KGlxMdeFavoritesUri, "defaultalbum_favourites"); |
|
78 |
|
79 #undef __USING_INTELLIGENT_UPDATE_FILTERING |
|
80 |
|
81 const TInt KHarvestUpdateChunkSize = 1000; |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // MPXChangeEventType |
|
85 // Helper method |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 TMPXChangeEventType MPXChangeEventType(const TObserverNotificationType& aType) |
|
89 { |
|
90 TMPXChangeEventType type = EMPXItemInserted; |
|
91 |
|
92 switch (aType) |
|
93 { |
|
94 case ENotifyAdd: |
|
95 type = EMPXItemInserted; |
|
96 break; |
|
97 case ENotifyModify: |
|
98 type = EMPXItemModified; |
|
99 break; |
|
100 case ENotifyRemove: |
|
101 type = EMPXItemDeleted; |
|
102 break; |
|
103 } |
|
104 return type; |
|
105 } |
|
106 |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // CGlxMDSShutdownObserver::NewL() |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 CGlxMDSShutdownObserver* CGlxMDSShutdownObserver::NewL( MGlxMDSShutdownObserver& aObserver, |
|
113 const TUid& aKeyCategory, |
|
114 const TInt aPropertyKey, |
|
115 TBool aDefineKey) |
|
116 { |
|
117 TRACER("CGlxMDSShutdownObserver* CGlxMDSShutdownObserver::NewL"); |
|
118 CGlxMDSShutdownObserver* self = new( ELeave )CGlxMDSShutdownObserver( aObserver, |
|
119 aKeyCategory, |
|
120 aPropertyKey, |
|
121 aDefineKey); |
|
122 CleanupStack::PushL( self ); |
|
123 self->ConstructL(); |
|
124 CleanupStack::Pop( self ); |
|
125 return self; |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // CGlxMDSShutdownObserver::CGlxMDSShutdownObserver() |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 CGlxMDSShutdownObserver::CGlxMDSShutdownObserver( MGlxMDSShutdownObserver& aObserver, |
|
133 const TUid& aKeyCategory, |
|
134 const TInt aPropertyKey, |
|
135 TBool aDefineKey) |
|
136 : CActive( CActive::EPriorityStandard ), iObserver( aObserver ), |
|
137 iKeyCategory( aKeyCategory ), iPropertyKey(aPropertyKey), iDefineKey( aDefineKey ) |
|
138 { |
|
139 TRACER("CGlxMDSShutdownObserver::CGlxMDSShutdownObserver()"); |
|
140 CActiveScheduler::Add( this ); |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // CGlxMDSShutdownObserver::ConstructL() |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CGlxMDSShutdownObserver::ConstructL() |
|
148 { |
|
149 TRACER("void CGlxMDSShutdownObserver::ConstructL()"); |
|
150 // define P&S property types |
|
151 if (iDefineKey) |
|
152 { |
|
153 RProperty::Define(iKeyCategory,iPropertyKey, |
|
154 RProperty::EInt,KAllowAllPolicy,KPowerMgmtPolicy); |
|
155 } |
|
156 |
|
157 // attach to the property |
|
158 TInt err = iProperty.Attach(iKeyCategory,iPropertyKey,EOwnerThread); |
|
159 User::LeaveIfError(err); |
|
160 |
|
161 // wait for the previously attached property to be updated |
|
162 iProperty.Subscribe(iStatus); |
|
163 SetActive(); |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CGlxMDSShutdownObserver::~CGlxMDSShutdownObserver() |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 CGlxMDSShutdownObserver::~CGlxMDSShutdownObserver() |
|
171 { |
|
172 TRACER("CGlxMDSShutdownObserver::~CGlxMDSShutdownObserver()"); |
|
173 Cancel(); |
|
174 iProperty.Close(); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CGlxMDSShutdownObserver::RunL() |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CGlxMDSShutdownObserver::RunL() |
|
182 { |
|
183 TRACER("void CGlxMDSShutdownObserver::RunL()"); |
|
184 |
|
185 // resubscribe before processing new value to prevent missing updates |
|
186 iProperty.Subscribe(iStatus); |
|
187 SetActive(); |
|
188 |
|
189 // retrieve the value |
|
190 TInt value = 0; |
|
191 TInt err = iProperty.Get(value); |
|
192 GLX_DEBUG2("CGlxMDSShutdownObserver::RunL(): iProperty.Get(value); returns %d", err); |
|
193 |
|
194 User::LeaveIfError(err); |
|
195 |
|
196 iObserver.ShutdownNotification(value); |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // CGlxMDSShutdownObserver::DoCancel() |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 void CGlxMDSShutdownObserver::DoCancel() |
|
204 { |
|
205 TRACER("void CGlxMDSShutdownObserver::DoCancel()"); |
|
206 iProperty.Cancel(); |
|
207 } |
|
208 |
|
209 |
|
210 |
|
211 // ============================ MEMBER FUNCTIONS ============================== |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // NewL() |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 CGlxDataSourceMde* CGlxDataSourceMde::NewL() |
|
218 { |
|
219 TRACER("CGlxDataSourceMde* CGlxDataSourceMde::NewL()"); |
|
220 CGlxDataSourceMde* ds = new (ELeave) CGlxDataSourceMde(); |
|
221 CleanupStack::PushL(ds); |
|
222 ds->ConstructL(); |
|
223 CleanupStack::Pop(ds); |
|
224 return ds; |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // ~CGlxDataSourceMde() |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 |
|
232 CGlxDataSourceMde::~CGlxDataSourceMde() |
|
233 { |
|
234 TRACER("CGlxDataSourceMde::~CGlxDataSourceMde()"); |
|
235 delete iSession; |
|
236 |
|
237 #ifdef USE_S60_TNM |
|
238 delete iTnThumbnail; |
|
239 iTnThumbnail = NULL; |
|
240 |
|
241 delete iThumbnail; |
|
242 iThumbnail = NULL; |
|
243 |
|
244 delete iTnEngine; |
|
245 iTnEngine = NULL; |
|
246 #else |
|
247 if (iThumbnailCreator) |
|
248 { |
|
249 iThumbnailCreator->Close(iThumbnailDatabase); |
|
250 } |
|
251 delete iThumbnailDatabase; |
|
252 #endif |
|
253 iFs.Close(); |
|
254 iHC.Close(); |
|
255 RFbsSession::Disconnect(); |
|
256 iMonthArray.Close(); |
|
257 iMonthList.Close(); |
|
258 iUpdateData.Close(); |
|
259 iAddedItems.Reset(); |
|
260 iAddedItems.Close(); |
|
261 delete iUpdateCallback; |
|
262 delete iCreateSessionCallback; |
|
263 delete iMDSShutdownObserver ; |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // CGlxDataSourceMde() |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 CGlxDataSourceMde::CGlxDataSourceMde() |
|
271 { |
|
272 TRACER("CGlxDataSourceMde::CGlxDataSourceMde()"); |
|
273 //No Implementation |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 // ConstructL() |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 void CGlxDataSourceMde::ConstructL() |
|
281 { |
|
282 TRACER("CGlxDataSourceMde::ConstructL()"); |
|
283 |
|
284 iDataSourceReady = EFalse; |
|
285 User::LeaveIfError(iFs.Connect()); |
|
286 iSession = CMdESession::NewL( *this ); |
|
287 |
|
288 User::LeaveIfError(RFbsSession::Connect()); |
|
289 |
|
290 #ifdef USE_S60_TNM |
|
291 iTnEngine = CThumbnailManager::NewL( *this); |
|
292 iTnEngine->SetDisplayModeL( EColor16M ); |
|
293 iTnRequestInProgress = EFalse; |
|
294 #else |
|
295 iThumbnailCreator = CGlxtnThumbnailCreator::InstanceL(); |
|
296 iThumbnailDatabase = CGlxtnThumbnailDatabase::NewL( |
|
297 KGlxMdeDataSourceThumbnailDatabase, this); |
|
298 #endif |
|
299 |
|
300 iCreateSessionCallback = new ( ELeave ) |
|
301 CAsyncCallBack( TCallBack( CreateSession, this ), CActive::EPriorityHigh ); |
|
302 |
|
303 iMDSShutdownObserver = CGlxMDSShutdownObserver::NewL( *this, KHarvesterPSShutdown, KMdSShutdown, EFalse ); |
|
304 |
|
305 iUpdateCallback = new ( ELeave ) |
|
306 CAsyncCallBack( TCallBack( ProcessItemUpdate, this ), CActive::EPriorityLow ); |
|
307 iUpdateData.Reserve(100); // ignore if it fails |
|
308 |
|
309 User::LeaveIfError(iHC.Connect()); |
|
310 iHC.AddHarvesterEventObserver(*this, EHEObserverTypePlaceholder, KHarvestUpdateChunkSize); |
|
311 |
|
312 iHarvestingOngoing = EFalse; |
|
313 } |
|
314 |
|
315 // ---------------------------------------------------------------------------- |
|
316 // from MMdESessionObserver |
|
317 // CMPXCollectionMdEPlugin::HandleSessionOpened |
|
318 // ---------------------------------------------------------------------------- |
|
319 // |
|
320 void CGlxDataSourceMde::HandleSessionOpened( CMdESession& aSession, TInt aError ) |
|
321 { |
|
322 TRACER("CGlxDataSourceMde::HandleSessionOpened(CMdESession& aSession, TInt aError)"); |
|
323 if( KErrNone != aError ) |
|
324 { |
|
325 HandleSessionError(aSession, aError); |
|
326 } |
|
327 TRAPD(err, DoSessionInitL()); |
|
328 if (KErrNone == err) |
|
329 { |
|
330 iSessionOpen = ETrue; |
|
331 iDataSourceReady = ETrue; |
|
332 TryStartTask(ETrue); |
|
333 } |
|
334 else |
|
335 { |
|
336 HandleSessionError(aSession, err); |
|
337 } |
|
338 } |
|
339 |
|
340 // ---------------------------------------------------------------------------- |
|
341 // from MMdESessionObserver |
|
342 // CMPXCollectionMdEPlugin::HandleSessionError |
|
343 // ---------------------------------------------------------------------------- |
|
344 // |
|
345 void CGlxDataSourceMde::HandleSessionError(CMdESession& /*aSession*/, TInt aError ) |
|
346 { |
|
347 TRACER("CGlxDataSourceMde::HandleSessionError(CMdESession& /*aSession*/, TInt aError)") |
|
348 GLX_DEBUG2("void CGlxDataSourceMde::HandleSessionError() aError(%d)", aError); |
|
349 |
|
350 iDataSourceReady = EFalse; |
|
351 iSessionOpen = EFalse; |
|
352 |
|
353 // We wait till MDS restarts before starting the session if the current session is locked. |
|
354 // that is handled separately by the MDS Shutdown PUB SUB Framework. |
|
355 // for everything else we use the generic method and continue. |
|
356 if ( (KErrLocked != aError) && ( KErrServerTerminated != aError) ) |
|
357 { |
|
358 iCreateSessionCallback->CallBack(); |
|
359 } |
|
360 } |
|
361 |
|
362 // --------------------------------------------------------------------------- |
|
363 // CreateTaskL |
|
364 // --------------------------------------------------------------------------- |
|
365 // |
|
366 CGlxDataSourceTask* CGlxDataSourceMde::CreateTaskL(CGlxRequest* aRequest, |
|
367 MGlxDataSourceRequestObserver& aObserver) |
|
368 { |
|
369 TRACER("CGlxDataSourceTask* CGlxDataSourceMde::CreateTaskL(CGlxRequest* aRequest,MGlxDataSourceRequestObserver& aObserver)") ; |
|
370 if(dynamic_cast<CGlxCommandRequest*>(aRequest)) |
|
371 { |
|
372 CleanupStack::PushL(aRequest); |
|
373 CGlxDataSourceTaskMdeCommand* task = new (ELeave) |
|
374 CGlxDataSourceTaskMdeCommand(static_cast<CGlxCommandRequest*>(aRequest), |
|
375 aObserver, this); |
|
376 CleanupStack::Pop(aRequest); // now owned by task |
|
377 CleanupStack::PushL(task); |
|
378 task->ConstructL(); |
|
379 CleanupStack::Pop(task); |
|
380 return task; |
|
381 } |
|
382 else if (dynamic_cast< CGlxGetRequest *>(aRequest)) |
|
383 { |
|
384 CleanupStack::PushL(aRequest); |
|
385 CGlxDataSourceTaskMdeAttributeMde* task = new (ELeave) |
|
386 CGlxDataSourceTaskMdeAttributeMde(static_cast<CGlxGetRequest*>(aRequest), |
|
387 aObserver, this); |
|
388 CleanupStack::Pop(aRequest); // now owned by task |
|
389 CleanupStack::PushL(task); |
|
390 task->ConstructL(); |
|
391 CleanupStack::Pop(task); |
|
392 return task; |
|
393 } |
|
394 else if (dynamic_cast< CGlxIdListRequest *>(aRequest)) |
|
395 { |
|
396 CleanupStack::PushL(aRequest); |
|
397 CGlxDataSourceTaskMdeIdList* task = new (ELeave) |
|
398 CGlxDataSourceTaskMdeIdList(static_cast<CGlxIdListRequest*>(aRequest), |
|
399 aObserver, this); |
|
400 CleanupStack::Pop(aRequest); // now owned by task |
|
401 CleanupStack::PushL(task); |
|
402 task->ConstructL(); |
|
403 CleanupStack::Pop(task); |
|
404 return task; |
|
405 } |
|
406 else if (dynamic_cast< CGlxThumbnailRequest *>(aRequest)) |
|
407 { |
|
408 CleanupStack::PushL(aRequest); |
|
409 CGlxDataSourceTaskMdeThumbnail* task = new (ELeave) |
|
410 CGlxDataSourceTaskMdeThumbnail(static_cast<CGlxThumbnailRequest*>(aRequest), |
|
411 aObserver, this); |
|
412 CleanupStack::Pop(aRequest); // now owned by task |
|
413 CleanupStack::PushL(task); |
|
414 task->ConstructL(); |
|
415 CleanupStack::Pop(task); |
|
416 return task; |
|
417 } |
|
418 else |
|
419 { |
|
420 User::Leave(KErrNotSupported); |
|
421 return NULL; // stops compiler warning |
|
422 } |
|
423 } |
|
424 |
|
425 #ifndef USE_S60_TNM |
|
426 // --------------------------------------------------------------------------- |
|
427 // ThumbnailAvailable |
|
428 // --------------------------------------------------------------------------- |
|
429 // |
|
430 void CGlxDataSourceMde::ThumbnailAvailable(const TGlxMediaId& |
|
431 /*aId*/, const TSize& /*aSize*/) |
|
432 { |
|
433 TRACER("CGlxDataSourceMde::ThumbnailAvailable(const TGlxMediaId& /*aId*/, const TSize& /*aSize*/)"); |
|
434 //No implementation |
|
435 } |
|
436 |
|
437 // --------------------------------------------------------------------------- |
|
438 // BackgroundThumbnailError |
|
439 // --------------------------------------------------------------------------- |
|
440 // |
|
441 void CGlxDataSourceMde::BackgroundThumbnailError(const TGlxMediaId& aId, TInt aError) |
|
442 { |
|
443 TRACER("CGlxDataSourceMde::BackgroundThumbnailError(const TGlxMediaId& aId, TInt aError)"); |
|
444 TSize size(0, 0); |
|
445 TRAP_IGNORE(BackgroundThumbnailMessageL(aId, size, aError)); |
|
446 } |
|
447 #endif |
|
448 |
|
449 // --------------------------------------------------------------------------- |
|
450 // BackgroundThumbnailMessageL |
|
451 // --------------------------------------------------------------------------- |
|
452 // |
|
453 void CGlxDataSourceMde::BackgroundThumbnailMessageL(const TGlxMediaId& aId, |
|
454 const TSize& aSize, TInt aError) |
|
455 { |
|
456 TRACER("CGlxDataSourceMde::BackgroundThumbnailMessageL(const TGlxMediaId& aId, const TSize& aSize, TInt aError)"); |
|
457 CMPXMessage* message = CMPXMessage::NewL(); |
|
458 CleanupStack::PushL(message); |
|
459 message->SetTObjectValueL(KMPXMessageGeneralId, KGlxMessageIdBackgroundThumbnail); |
|
460 message->SetTObjectValueL<TMPXItemId>(KGlxBackgroundThumbnailMediaId, aId.Value()); |
|
461 message->SetTObjectValueL(KGlxBackgroundThumbnailSize, aSize); |
|
462 message->SetTObjectValueL(KGlxBackgroundThumbnailError, aError); |
|
463 BroadcastMessage(*message); |
|
464 CleanupStack::PopAndDestroy(message); |
|
465 } |
|
466 |
|
467 // --------------------------------------------------------------------------- |
|
468 // DoSessionInitL |
|
469 // --------------------------------------------------------------------------- |
|
470 // |
|
471 void CGlxDataSourceMde::DoSessionInitL() |
|
472 { |
|
473 TRACER("CGlxDataSourceMde::DoSessionInitL()"); |
|
474 /// @todo check schema version number |
|
475 iNameSpaceDef = &iSession->GetDefaultNamespaceDefL(); |
|
476 |
|
477 CMdEObject* cameraAlbum = iSession->GetObjectL(KGlxMdeCameraAlbumUri); |
|
478 if ( !cameraAlbum ) |
|
479 { |
|
480 User::Leave(KErrCorrupt); |
|
481 } |
|
482 iCameraAlbumId = (TGlxMediaId)cameraAlbum->Id(); |
|
483 delete cameraAlbum; |
|
484 |
|
485 CMdEObject* favorites = iSession->GetObjectL(KGlxMdeFavoritesUri); |
|
486 if ( !favorites ) |
|
487 { |
|
488 User::Leave(KErrCorrupt); |
|
489 } |
|
490 iFavoritesId = (TGlxMediaId)favorites->Id(); |
|
491 delete favorites; |
|
492 |
|
493 |
|
494 iContainsDef = &iNameSpaceDef->GetRelationDefL(KRelationDefNameContains); |
|
495 iContainsLocationDef = &iNameSpaceDef->GetRelationDefL(KRelationDefNameContainsLocation); |
|
496 |
|
497 iObjectDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameObject); |
|
498 iImageDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameImage); |
|
499 iVideoDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameVideo); |
|
500 iMediaDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameMedia); |
|
501 iAlbumDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameAlbum); |
|
502 iTagDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameTag); |
|
503 iMonthDef = &iNameSpaceDef->GetObjectDefL(KObjectDefNameMonth); |
|
504 iLocationDef = &iNameSpaceDef->GetObjectDefL(KObjectDefLocation); |
|
505 |
|
506 AddMdEObserversL(); |
|
507 |
|
508 PrepareMonthsL(); |
|
509 } |
|
510 |
|
511 // --------------------------------------------------------------------------- |
|
512 // AddMdEObserversL |
|
513 // --------------------------------------------------------------------------- |
|
514 // |
|
515 void CGlxDataSourceMde::AddMdEObserversL() |
|
516 { |
|
517 TRACER("CGlxDataSourceMde::AddMdEObserversL()"); |
|
518 iSession->AddRelationObserverL(*this); |
|
519 iSession->AddRelationPresentObserverL(*this); |
|
520 |
|
521 //when setting observing conditions, |
|
522 //add filters for all images, videos, Albums & Tags |
|
523 CMdELogicCondition* addCondition = CMdELogicCondition::NewLC( ELogicConditionOperatorOr ); |
|
524 addCondition->AddObjectConditionL( *iImageDef ); |
|
525 addCondition->AddObjectConditionL( *iAlbumDef ); |
|
526 addCondition->AddObjectConditionL( *iTagDef ); |
|
527 |
|
528 iSession->AddObjectObserverL(*this, addCondition ); |
|
529 iSession->AddObjectPresentObserverL(*this ); |
|
530 |
|
531 // This addCondition should only be popped. |
|
532 // As the ownership is transferred, the same will be destroyed by MdS. |
|
533 CleanupStack::Pop( addCondition ); |
|
534 } |
|
535 |
|
536 // --------------------------------------------------------------------------- |
|
537 // CGlxDataSourceMde::HandleObjectNotification |
|
538 // --------------------------------------------------------------------------- |
|
539 // |
|
540 ///@todo AB test this |
|
541 void CGlxDataSourceMde::HandleObjectNotification(CMdESession& /*aSession*/, |
|
542 TObserverNotificationType aType, |
|
543 const RArray<TItemId>& aObjectIdArray) |
|
544 { |
|
545 TRACER("CGlxDataSourceMde::HandleObjectNotification()"); |
|
546 GLX_LOG_INFO3("CGlxDataSourceMde::HandleObjectNotification() aType=%d, aObjectIdArray.Count()=%d, iHarvestingOngoing=%d", |
|
547 aType, aObjectIdArray.Count(), |
|
548 iHarvestingOngoing); |
|
549 if (ENotifyAdd == aType) |
|
550 { |
|
551 for ( TInt i = 0; i < aObjectIdArray.Count(); i++ ) |
|
552 { |
|
553 TInt ret = iAddedItems.Append(aObjectIdArray[i]); |
|
554 if (ret != KErrNone) |
|
555 { |
|
556 GLX_DEBUG2("ENotifyAdd-iAddedItems.Append() failed i(%d)", i); |
|
557 } |
|
558 } |
|
559 GLX_DEBUG2("ENotifyAdd - iAddedItems.Count()=%d", iAddedItems.Count()); |
|
560 } |
|
561 |
|
562 if (ENotifyModify == aType) |
|
563 { |
|
564 for ( TInt i = 0; i < aObjectIdArray.Count(); i++ ) |
|
565 { |
|
566 if (iAddedItems.Find(aObjectIdArray[i]) != KErrNotFound) |
|
567 { |
|
568 if (!iHarvestingOngoing) |
|
569 { |
|
570 GLX_DEBUG1("ENotifyModify - Harvesting Completed - " |
|
571 "Reset iAddedItems array"); |
|
572 iAddedItems.Reset(); |
|
573 break; |
|
574 } |
|
575 GLX_DEBUG1("ENotifyModify - Id found in iAddedItems array, DO NOT PROCESS"); |
|
576 return; |
|
577 } |
|
578 } |
|
579 } |
|
580 |
|
581 GLX_DEBUG1("HandleObjectNotification - ProcessUpdateArray"); |
|
582 ProcessUpdateArray(aObjectIdArray, MPXChangeEventType(aType), ETrue); |
|
583 #ifndef USE_S60_TNM |
|
584 if(MPXChangeEventType(aType) == EMPXItemDeleted ) |
|
585 { |
|
586 TInt count = aObjectIdArray.Count(); |
|
587 iDeletedCount += count; |
|
588 GLX_DEBUG3("EMPXItemDeleted - aObjectIdArray.Count()=%d, iDeletedCount=%d", |
|
589 count, iDeletedCount); |
|
590 if(iDeletedCount > KGlxThumbnailCleanupAfterDeletions) |
|
591 { |
|
592 TRAPD(err, ThumbnailCreator().CleanupThumbnailsL(iThumbnailDatabase)); |
|
593 if(!err) |
|
594 { |
|
595 iDeletedCount = 0; |
|
596 } |
|
597 } |
|
598 } |
|
599 |
|
600 if(MPXChangeEventType(aType) == EMPXItemModified ) |
|
601 { |
|
602 GLX_DEBUG1("HandleObjectNotification - EMPXItemModified"); |
|
603 TRAP_IGNORE(ThumbnailCreator().CleanupThumbnailsL(iThumbnailDatabase)); |
|
604 } |
|
605 #endif |
|
606 } |
|
607 |
|
608 // --------------------------------------------------------------------------- |
|
609 // CGlxDataSourceMde::HandleObjectPresentNotification |
|
610 // --------------------------------------------------------------------------- |
|
611 // |
|
612 ///@todo AB test this |
|
613 void CGlxDataSourceMde::HandleObjectPresentNotification(CMdESession& /*aSession*/, |
|
614 TBool aPresent, const RArray<TItemId>& aObjectIdArray) |
|
615 { |
|
616 TRACER("CGlxDataSourceMde::HandleObjectPresentNotification()"); |
|
617 if (aPresent) |
|
618 { |
|
619 ProcessUpdateArray(aObjectIdArray, EMPXItemInserted, ETrue); |
|
620 } |
|
621 else |
|
622 { |
|
623 ProcessUpdateArray(aObjectIdArray, EMPXItemDeleted, ETrue); |
|
624 } |
|
625 } |
|
626 |
|
627 // --------------------------------------------------------------------------- |
|
628 // CGlxDataSourceMde::HandleRelationNotification |
|
629 // --------------------------------------------------------------------------- |
|
630 // |
|
631 ///@todo AB test this |
|
632 void CGlxDataSourceMde::HandleRelationNotification(CMdESession& /*aSession*/, |
|
633 TObserverNotificationType aType, |
|
634 const RArray<TItemId>& aRelationIdArray) |
|
635 { |
|
636 TRACER("CGlxDataSourceMde::HandleRelationNotification()"); |
|
637 ProcessUpdateArray(aRelationIdArray, MPXChangeEventType(aType), EFalse); |
|
638 } |
|
639 |
|
640 // --------------------------------------------------------------------------- |
|
641 // CGlxDataSourceMde::HandleRelationPresentNotification |
|
642 // --------------------------------------------------------------------------- |
|
643 // |
|
644 ///@todo AB test this |
|
645 void CGlxDataSourceMde::HandleRelationPresentNotification(CMdESession& /*aSession*/, |
|
646 TBool aPresent, const RArray<TItemId>& aRelationIdArray) |
|
647 { |
|
648 TRACER("CGlxDataSourceMde::HandleRelationPresentNotification()"); |
|
649 if (aPresent) |
|
650 { |
|
651 ProcessUpdateArray(aRelationIdArray, EMPXItemInserted, EFalse); |
|
652 } |
|
653 else |
|
654 { |
|
655 ProcessUpdateArray(aRelationIdArray, EMPXItemDeleted, EFalse); |
|
656 } |
|
657 } |
|
658 |
|
659 // --------------------------------------------------------------------------- |
|
660 // ProcessUpdateArray |
|
661 // --------------------------------------------------------------------------- |
|
662 // |
|
663 void CGlxDataSourceMde::ProcessUpdateArray(const RArray<TItemId>& aArray, |
|
664 TMPXChangeEventType aType, TBool aIsObject) |
|
665 { |
|
666 TRACER("CGlxDataSourceMde::ProcessUpdateArray(const RArray<TItemId>& aArray,TMPXChangeEventType aType, TBool aIsObject)"); |
|
667 // only need one message so process first item |
|
668 TUpdateData update; |
|
669 update.iId = aArray[0]; |
|
670 update.iType = aType; |
|
671 update.iIsObject = aIsObject; |
|
672 if( iUpdateData.Count() ) |
|
673 { |
|
674 if( ( iUpdateData[0].iType == aType ) && ( iUpdateData[0].iIsObject ) ) |
|
675 { |
|
676 return; |
|
677 } |
|
678 } |
|
679 if( iUpdateData.Append(update) == KErrNone ) // if we can't allocate space for the update, ignore it |
|
680 { |
|
681 iUpdateCallback->CallBack(); |
|
682 } |
|
683 } |
|
684 |
|
685 // --------------------------------------------------------------------------- |
|
686 // CreateSession |
|
687 // --------------------------------------------------------------------------- |
|
688 // |
|
689 void CGlxDataSourceMde::CreateSession() |
|
690 { |
|
691 TRACER("CGlxDataSourceMde::CreateSession()") |
|
692 TRAP_IGNORE(CreateSessionL()); |
|
693 } |
|
694 |
|
695 // --------------------------------------------------------------------------- |
|
696 // CreateSession |
|
697 // --------------------------------------------------------------------------- |
|
698 // |
|
699 TInt CGlxDataSourceMde::CreateSession(TAny* aPtr) |
|
700 { |
|
701 TRACER("CGlxDataSourceMde::CreateSession(TAny* aPtr)"); |
|
702 CGlxDataSourceMde* self |
|
703 = reinterpret_cast<CGlxDataSourceMde*>( aPtr ); |
|
704 TRAP_IGNORE(self->CreateSessionL()); |
|
705 return 0; |
|
706 } |
|
707 |
|
708 // --------------------------------------------------------------------------- |
|
709 // CreateSessionL |
|
710 // --------------------------------------------------------------------------- |
|
711 // |
|
712 void CGlxDataSourceMde::CreateSessionL() |
|
713 { |
|
714 TRACER("CGlxDataSourceMde::CreateSessionL()"); |
|
715 delete iSession; |
|
716 iSession = NULL; |
|
717 iSession = CMdESession::NewL( *this ); |
|
718 } |
|
719 |
|
720 |
|
721 // --------------------------------------------------------------------------- |
|
722 // ProcessItemUpdate |
|
723 // --------------------------------------------------------------------------- |
|
724 // |
|
725 TInt CGlxDataSourceMde::ProcessItemUpdate(TAny* aPtr) |
|
726 { |
|
727 TRACER("CGlxDataSourceMde::ProcessItemUpdate(TAny* aPtr)"); |
|
728 CGlxDataSourceMde* self |
|
729 = reinterpret_cast<CGlxDataSourceMde*>( aPtr ); |
|
730 TRAP_IGNORE(self->ProcessItemUpdateL()); |
|
731 return 0; |
|
732 } |
|
733 |
|
734 // --------------------------------------------------------------------------- |
|
735 // ProcessItemUpdateL |
|
736 // --------------------------------------------------------------------------- |
|
737 // |
|
738 void CGlxDataSourceMde::ProcessItemUpdateL() |
|
739 { |
|
740 TRACER("CGlxDataSourceMde::ProcessItemUpdateL()"); |
|
741 if ( !iUpdateData.Count() || iPauseUpdate ) |
|
742 { |
|
743 return; |
|
744 } |
|
745 CMPXMessage* message = CMPXMessage::NewL(); |
|
746 CleanupStack::PushL(message); |
|
747 message->SetTObjectValueL<TInt>(KMPXMessageGeneralId, KMPXMessageIdItemChanged); |
|
748 message->SetTObjectValueL<TMPXChangeEventType>(KMPXMessageChangeEventType, |
|
749 iUpdateData[0].iType); |
|
750 TMPXGeneralCategory category = EMPXNoCategory; |
|
751 TMPXItemId id = iUpdateData[0].iId; |
|
752 |
|
753 #ifdef __USING_INTELLIGENT_UPDATE_FILTERING |
|
754 if ( !iUpdateData[0].iIsObject ) |
|
755 { |
|
756 TMPXGeneralCategory containerCategory = EMPXNoCategory; |
|
757 TMPXItemId containerId; |
|
758 |
|
759 CMdERelation* relation = iSession->GetRelationL(id); |
|
760 if( relation ) |
|
761 { |
|
762 TItemId rightId = relation->RightObjectId(); |
|
763 TItemId leftId = relation->LeftObjectId(); |
|
764 delete relation; |
|
765 |
|
766 CMdEObject* contObject = iSession->GetObjectL(leftId); |
|
767 __ASSERT_DEBUG(contObject, Panic(EGlxPanicIllegalState)); |
|
768 TContainerType container = ContainerType(contObject); |
|
769 delete contObject; |
|
770 __ASSERT_DEBUG(( EContainerTypeTag != container), Panic(EGlxPanicIllegalState)); |
|
771 if( EContainerTypeNotAContainer == container ) |
|
772 { |
|
773 CMdEObject* rightObject = iSession->GetObjectL(rightId); |
|
774 __ASSERT_DEBUG(rightObject, Panic(EGlxPanicIllegalState)); |
|
775 TContainerType rightContainer = ContainerType(rightObject); |
|
776 delete rightObject; |
|
777 __ASSERT_DEBUG(( EContainerTypeAlbum != rightContainer), |
|
778 Panic(EGlxPanicIllegalState)); |
|
779 if( EContainerTypeTag == rightContainer ) |
|
780 { |
|
781 id = leftId; |
|
782 containerId = rightId; |
|
783 containerCategory = EMPXTag; |
|
784 } |
|
785 else if( EContainerTypeNotAContainer == rightContainer ) |
|
786 { |
|
787 User::Leave(KErrNotSupported); // Not a gallery relation. |
|
788 } |
|
789 } |
|
790 else if( EContainerTypeAlbum == container) |
|
791 { |
|
792 id = rightId; |
|
793 containerId = leftId; |
|
794 containerCategory = EMPXAlbum; |
|
795 } |
|
796 message->SetTObjectValueL<TMPXGeneralCategory>(KGlxCollectionMessageContainerCategory, |
|
797 containerCategory); |
|
798 message->SetTObjectValueL<TMPXItemId>(KGlxCollectionMessageContainerId, |
|
799 containerId); |
|
800 } |
|
801 else |
|
802 { |
|
803 // use id 0 to identify to ML that we don't know what was deleted |
|
804 id = 0; |
|
805 } |
|
806 } |
|
807 |
|
808 if ( id != 0 ) |
|
809 { |
|
810 CMdEObject* object = iSession->GetObjectL(id); |
|
811 if( object ) |
|
812 { |
|
813 TContainerType container = ContainerType(object); |
|
814 if( EContainerTypeAlbum == container) |
|
815 { |
|
816 category = EMPXAlbum; |
|
817 } |
|
818 else if( EContainerTypeTag == container) |
|
819 { |
|
820 category = EMPXTag; |
|
821 } |
|
822 else |
|
823 { |
|
824 TItemType item = ItemType(object); |
|
825 if( EItemTypeImage == item) |
|
826 { |
|
827 category = EMPXImage; |
|
828 } |
|
829 else if( EItemTypeVideo == item) |
|
830 { |
|
831 category = EMPXVideo; |
|
832 } |
|
833 } |
|
834 delete object; |
|
835 } |
|
836 } |
|
837 #endif // __USING_INTELLIGENT_UPDATE_FILTERING |
|
838 message->SetTObjectValueL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory, |
|
839 category); |
|
840 message->SetTObjectValueL<TMPXItemId>(KMPXMessageMediaGeneralId, id); |
|
841 BroadcastMessage(*message); |
|
842 CleanupStack::PopAndDestroy(message); |
|
843 iUpdateData.Remove(0); |
|
844 } |
|
845 |
|
846 // --------------------------------------------------------------------------- |
|
847 // ContainerType |
|
848 // --------------------------------------------------------------------------- |
|
849 // |
|
850 CGlxDataSource::TContainerType CGlxDataSourceMde::ContainerType(CMdEObject* aObject) |
|
851 { |
|
852 TRACER("CGlxDataSourceMde::ContainerType(CMdEObject* aObject)"); |
|
853 TContainerType containerType = EContainerTypeNotAContainer; |
|
854 |
|
855 if( 0 == aObject->Def().Compare(*iAlbumDef) ) |
|
856 { |
|
857 containerType = EContainerTypeAlbum; |
|
858 } |
|
859 else if( 0 == aObject->Def().Compare(*iTagDef) ) |
|
860 { |
|
861 containerType = EContainerTypeTag; |
|
862 } |
|
863 else if( 0 == aObject->Def().Compare(*iMonthDef) ) |
|
864 { |
|
865 containerType = EContainerTypeMonth; |
|
866 } |
|
867 |
|
868 return containerType; |
|
869 } |
|
870 |
|
871 |
|
872 // --------------------------------------------------------------------------- |
|
873 // ContainerType |
|
874 // --------------------------------------------------------------------------- |
|
875 // |
|
876 CGlxDataSource::TContainerType CGlxDataSourceMde::ContainerType(CMdEObjectDef* |
|
877 aObjectDef) |
|
878 { |
|
879 TRACER("CGlxDataSourceMde::ContainerType()"); |
|
880 TContainerType containerType = EContainerTypeNotAContainer; |
|
881 |
|
882 if( 0 == aObjectDef->Compare(*iAlbumDef) ) |
|
883 { |
|
884 containerType = EContainerTypeAlbum; |
|
885 } |
|
886 else if( 0 == aObjectDef->Compare(*iTagDef) ) |
|
887 { |
|
888 containerType = EContainerTypeTag; |
|
889 } |
|
890 else if( 0 == aObjectDef->Compare(*iMonthDef) ) |
|
891 { |
|
892 containerType = EContainerTypeMonth; |
|
893 } |
|
894 |
|
895 return containerType; |
|
896 } |
|
897 |
|
898 // --------------------------------------------------------------------------- |
|
899 // ItemType() |
|
900 // --------------------------------------------------------------------------- |
|
901 // |
|
902 CGlxDataSource::TItemType CGlxDataSourceMde::ItemType(CMdEObject* aObject) |
|
903 { |
|
904 TRACER("CGlxDataSourceMde::ItemType(CMdEObject* aObject)"); |
|
905 TItemType itemType = EItemTypeNotAnItem; |
|
906 |
|
907 if( 0 == aObject->Def().Compare(*iImageDef) ) |
|
908 { |
|
909 itemType = EItemTypeImage; |
|
910 } |
|
911 else if(0 == aObject->Def().Compare(*iVideoDef) ) |
|
912 { |
|
913 itemType = EItemTypeVideo; |
|
914 } |
|
915 |
|
916 return itemType; |
|
917 } |
|
918 |
|
919 // --------------------------------------------------------------------------- |
|
920 // PrepareMonthsL() |
|
921 // --------------------------------------------------------------------------- |
|
922 // |
|
923 void CGlxDataSourceMde::PrepareMonthsL() |
|
924 { |
|
925 TRACER("CGlxDataSourceMde::PrepareMonthsL()"); |
|
926 TTime month(0); |
|
927 iFirstMonth = month; |
|
928 } |
|
929 |
|
930 // --------------------------------------------------------------------------- |
|
931 // GetMonthIdL() |
|
932 // --------------------------------------------------------------------------- |
|
933 // |
|
934 const TGlxMediaId CGlxDataSourceMde::GetMonthIdL(const TTime& aMonth) |
|
935 { |
|
936 TRACER("CGlxDataSourceMde::GetMonthIdL()"); |
|
937 TTime monthStart = iFirstMonth + aMonth.MonthsFrom(iFirstMonth); |
|
938 const TTimeIntervalMonths KGlxOneMonth = 1; |
|
939 const TTimeIntervalMicroSeconds KGlxOneMicrosecond = 1; |
|
940 |
|
941 TGlxMediaId monthId; |
|
942 TInt monthIndex = iMonthArray.Find(monthStart); |
|
943 if( monthIndex != KErrNotFound ) |
|
944 { |
|
945 monthId = iMonthList[monthIndex]; |
|
946 } |
|
947 else |
|
948 { |
|
949 _LIT(KGlxMonthTitleFormat, "%F%Y%M%D:"); |
|
950 const TInt KGlxMonthTitleLength = 12; |
|
951 TBuf<KGlxMonthTitleLength> title; |
|
952 monthStart.FormatL(title, KGlxMonthTitleFormat); |
|
953 |
|
954 CMdEObject* month = iSession->GetObjectL(title); |
|
955 if( month ) |
|
956 { |
|
957 monthId = (TGlxMediaId)month->Id(); |
|
958 iMonthArray.AppendL(monthStart); |
|
959 iMonthList.AppendL(monthId); |
|
960 delete month; |
|
961 } |
|
962 else |
|
963 { |
|
964 TTime monthEnd = monthStart + KGlxOneMonth - KGlxOneMicrosecond; |
|
965 month = iSession->NewObjectLC(*iMonthDef, title); |
|
966 |
|
967 // A title property def of type text is required. |
|
968 CMdEPropertyDef& titlePropertyDef = iObjectDef->GetPropertyDefL( |
|
969 KPropertyDefNameTitle); |
|
970 if (titlePropertyDef.PropertyType() != EPropertyText) |
|
971 { |
|
972 User::Leave(KErrCorrupt); |
|
973 } |
|
974 // Set the object title. |
|
975 month->AddTextPropertyL (titlePropertyDef, title); |
|
976 |
|
977 // A size property is required. |
|
978 CMdEPropertyDef& sizePropertyDef = iObjectDef->GetPropertyDefL( |
|
979 KPropertyDefNameSize); |
|
980 if (sizePropertyDef.PropertyType() != EPropertyUint32) |
|
981 { |
|
982 User::Leave(KErrCorrupt); |
|
983 } |
|
984 month->AddUint32PropertyL(sizePropertyDef,0); |
|
985 |
|
986 |
|
987 // A creation date property is required. |
|
988 CMdEPropertyDef& creationDateDef = iObjectDef->GetPropertyDefL( |
|
989 KPropertyDefNameCreationDate); |
|
990 if (creationDateDef.PropertyType() != EPropertyTime) |
|
991 { |
|
992 User::Leave(KErrCorrupt); |
|
993 } |
|
994 month->AddTimePropertyL(creationDateDef, monthStart); |
|
995 |
|
996 // A last modified date property is required. |
|
997 CMdEPropertyDef& lmDateDef = iObjectDef->GetPropertyDefL( |
|
998 KPropertyDefNameLastModifiedDate); |
|
999 if (lmDateDef.PropertyType() != EPropertyTime) |
|
1000 { |
|
1001 User::Leave(KErrCorrupt); |
|
1002 } |
|
1003 |
|
1004 month->AddTimePropertyL(lmDateDef, monthEnd); |
|
1005 |
|
1006 monthId = (TGlxMediaId)iSession->AddObjectL(*month); |
|
1007 CleanupStack::PopAndDestroy(month); |
|
1008 iMonthArray.AppendL(monthStart); |
|
1009 iMonthList.AppendL(monthId); |
|
1010 } |
|
1011 } |
|
1012 return monthId; |
|
1013 } |
|
1014 |
|
1015 // --------------------------------------------------------------------------- |
|
1016 // SameMonth |
|
1017 // --------------------------------------------------------------------------- |
|
1018 // |
|
1019 TBool CGlxDataSourceMde::SameMonth(const TTime& aOldDate, const TTime& aNewDate) |
|
1020 { |
|
1021 TRACER("CGlxDataSourceMde::SameMonth(const TTime& aOldDate, const TTime& aNewDate)") |
|
1022 return ( aOldDate.MonthsFrom(iFirstMonth) == aNewDate.MonthsFrom(iFirstMonth) ); |
|
1023 } |
|
1024 |
|
1025 // --------------------------------------------------------------------------- |
|
1026 // ContainerIsLeft |
|
1027 // --------------------------------------------------------------------------- |
|
1028 // |
|
1029 TBool CGlxDataSourceMde::ContainerIsLeft(CMdEObjectDef& aObjectDef) |
|
1030 { |
|
1031 TRACER("CGlxDataSourceMde::ContainerIsLeft(CMdEObjectDef& aObjectDef)") |
|
1032 TBool containerLeft = EFalse; |
|
1033 if ( 0 == aObjectDef.Compare(AlbumDef()) ) |
|
1034 { |
|
1035 containerLeft = ETrue; |
|
1036 } |
|
1037 return containerLeft; |
|
1038 } |
|
1039 |
|
1040 // --------------------------------------------------------------------------- |
|
1041 // CGlxDataSource |
|
1042 // TaskCompletedL |
|
1043 // --------------------------------------------------------------------------- |
|
1044 // |
|
1045 void CGlxDataSourceMde::TaskCompletedL() |
|
1046 { |
|
1047 iPauseUpdate = EFalse; |
|
1048 iUpdateCallback->CallBack(); |
|
1049 } |
|
1050 |
|
1051 // --------------------------------------------------------------------------- |
|
1052 // CGlxDataSource |
|
1053 // TaskStartedL |
|
1054 // --------------------------------------------------------------------------- |
|
1055 // |
|
1056 void CGlxDataSourceMde::TaskStartedL() |
|
1057 { |
|
1058 iPauseUpdate = ETrue; |
|
1059 } |
|
1060 |
|
1061 #ifdef USE_S60_TNM |
|
1062 void CGlxDataSourceMde::FetchThumbnailL(CGlxRequest* aRequest, |
|
1063 MThumbnailFetchRequestObserver& aObserver) |
|
1064 { |
|
1065 TRACER("CGlxDataSourceMde::FetchThumbnailL()"); |
|
1066 #ifdef _DEBUG |
|
1067 iStartTime.HomeTime(); // Get home time |
|
1068 #endif |
|
1069 |
|
1070 iTnFetchObserver = &aObserver; |
|
1071 |
|
1072 CGlxThumbnailRequest* request = static_cast<CGlxThumbnailRequest*>(aRequest); |
|
1073 |
|
1074 TGlxThumbnailRequest tnReq; |
|
1075 request->ThumbnailRequest(tnReq); |
|
1076 User::LeaveIfNull(request->ThumbnailInfo()); |
|
1077 |
|
1078 iTnHandle = tnReq.iBitmapHandle; |
|
1079 iMediaId = tnReq.iId; |
|
1080 if (tnReq.iSizeClass.iWidth < KMaxGridThumbnailWidth) |
|
1081 { |
|
1082 iTnEngine->SetFlagsL(CThumbnailManager::ECropToAspectRatio); |
|
1083 iTnEngine->SetThumbnailSizeL(EGridThumbnailSize); |
|
1084 GLX_LOG_INFO("CGlxDataSourceMde::FetchThumbnailL() - Fetch TN attrib -" |
|
1085 " EGridThumbnailSize"); |
|
1086 } |
|
1087 else |
|
1088 { |
|
1089 iTnEngine->SetFlagsL(CThumbnailManager::EDefaultFlags); |
|
1090 iTnEngine->SetThumbnailSizeL(EFullScreenThumbnailSize); |
|
1091 GLX_LOG_INFO("CGlxDataSourceMde::FetchThumbnailL() - Fetch TN attrib - " |
|
1092 "EFullScreenThumbnailSize"); |
|
1093 } |
|
1094 |
|
1095 if (tnReq.iPriorityMode == TGlxThumbnailRequest::EPrioritizeQuality) |
|
1096 { |
|
1097 iTnEngine->SetQualityPreferenceL(CThumbnailManager::EOptimizeForQuality); |
|
1098 GLX_LOG_INFO("CGlxDataSourceMde::FetchThumbnailL() - Fetch TN attrib -" |
|
1099 " EOptimizeForQuality"); |
|
1100 } |
|
1101 else |
|
1102 { |
|
1103 iTnEngine->SetQualityPreferenceL(CThumbnailManager::EOptimizeForQualityWithPreview); |
|
1104 GLX_LOG_INFO("CGlxDataSourceMde::FetchThumbnailL() - Fetch TN attrib -" |
|
1105 " EOptimizeForQualityWithPreview"); |
|
1106 } |
|
1107 |
|
1108 CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC( |
|
1109 request->ThumbnailInfo()->FilePath(), 0); |
|
1110 iTnThumbnailCbId = iTnEngine->GetThumbnailL(*source); |
|
1111 CleanupStack::PopAndDestroy(source); |
|
1112 |
|
1113 iTnRequestInProgress = ETrue; |
|
1114 } |
|
1115 |
|
1116 TInt CGlxDataSourceMde::CancelFetchThumbnail() |
|
1117 { |
|
1118 TRACER("CGlxDataSourceMde::CancelFetchThumbnail"); |
|
1119 TInt ret = KErrNone; |
|
1120 if (iTnRequestInProgress) |
|
1121 { |
|
1122 ret = iTnEngine->CancelRequest(iTnThumbnailCbId); |
|
1123 iTnRequestInProgress = EFalse; |
|
1124 iTnFetchObserver->ThumbnailFetchComplete(KErrCancel,EFalse); |
|
1125 } |
|
1126 return ret; |
|
1127 } |
|
1128 |
|
1129 // Called when preview thumbnail is created |
|
1130 void CGlxDataSourceMde::ThumbnailPreviewReady(MThumbnailData& aThumbnail, |
|
1131 TThumbnailRequestId aId) |
|
1132 { |
|
1133 TRACER("CGlxDataSourceMde::ThumbnailPreviewReady()"); |
|
1134 |
|
1135 TInt error = KErrNotSupported; |
|
1136 if ( aThumbnail.Bitmap() ) |
|
1137 { |
|
1138 GLX_DEBUG1("CGlxDataSourceMde::ThumbnailPreviewReady preview aval"); |
|
1139 error = KErrNone; |
|
1140 } |
|
1141 //This function is called number of times as a callback , |
|
1142 //hence not trapping the leaving function which costs time and memory. |
|
1143 //Ignoring this for code scanner warnings - Leaving functions called in non-leaving functions. |
|
1144 ThumbnailReadyL(error, aThumbnail, aId, EFalse); |
|
1145 } |
|
1146 |
|
1147 // Called when real thumbnail is created |
|
1148 void CGlxDataSourceMde::ThumbnailReady(TInt aError, |
|
1149 MThumbnailData& aThumbnail, TThumbnailRequestId aId) |
|
1150 { |
|
1151 TRACER("CGlxDataSourceMde::ThumbnailReady"); |
|
1152 GLX_DEBUG2("GlxDataSourceMde::ThumbnailReady aError=%d", aError); |
|
1153 //This function is called number of times as a callback , |
|
1154 //hence not trapping the leaving function which costs time and memory. |
|
1155 //Ignoring this for code scanner warnings - Leaving functions called in non-leaving functions. |
|
1156 ThumbnailReadyL(aError,aThumbnail, aId, ETrue); |
|
1157 } |
|
1158 |
|
1159 // --------------------------------------------------------------------------- |
|
1160 // ThumbnailReadyL |
|
1161 // --------------------------------------------------------------------------- |
|
1162 // |
|
1163 void CGlxDataSourceMde::ThumbnailReadyL(TInt aError, |
|
1164 MThumbnailData& aThumbnail, TThumbnailRequestId aId, TBool aQuality) |
|
1165 { |
|
1166 TRACER("CGlxDataSourceMde::ThumbnailReadyL()"); |
|
1167 GLX_DEBUG3("CGlxDataSourceMde::ThumbnailReadyL aError=%d, aQuality=%d", |
|
1168 aError, aQuality); |
|
1169 #ifdef _DEBUG |
|
1170 iStopTime.HomeTime(); // Get home time |
|
1171 GLX_DEBUG2("=>CGlxDataSourceMde::ThumbnailReadyL - TN Fetch took <%d> us", |
|
1172 (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64()); |
|
1173 #endif |
|
1174 |
|
1175 if (iTnThumbnailCbId == aId) |
|
1176 { |
|
1177 if (aError == KErrNone && iTnHandle) |
|
1178 { |
|
1179 if (iTnHandle == KGlxMessageIdBackgroundThumbnail) |
|
1180 { |
|
1181 BackgroundThumbnailMessageL(iMediaId, TSize(), aError); |
|
1182 } |
|
1183 else |
|
1184 { |
|
1185 delete iTnThumbnail; |
|
1186 iTnThumbnail = NULL; |
|
1187 iTnThumbnail = aThumbnail.DetachBitmap(); |
|
1188 |
|
1189 delete iThumbnail; |
|
1190 iThumbnail = NULL; |
|
1191 iThumbnail = new (ELeave) CFbsBitmap(); |
|
1192 User::LeaveIfError( iThumbnail->Duplicate(iTnHandle)); |
|
1193 User::LeaveIfError(iThumbnail->Resize(iTnThumbnail->SizeInPixels())); |
|
1194 CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(iThumbnail); |
|
1195 CleanupStack::PushL(device ); |
|
1196 CFbsBitGc* context = NULL; |
|
1197 User::LeaveIfError(device->CreateContext(context)); |
|
1198 CleanupStack::PushL(context); |
|
1199 context->BitBlt( TPoint(), iTnThumbnail); |
|
1200 CleanupStack::PopAndDestroy(context); |
|
1201 CleanupStack::PopAndDestroy(device); |
|
1202 } |
|
1203 } |
|
1204 } |
|
1205 |
|
1206 if (iTnFetchObserver && iTnRequestInProgress) |
|
1207 { |
|
1208 iTnFetchObserver->ThumbnailFetchComplete(aError, aQuality); |
|
1209 iTnHandle = KErrNone; |
|
1210 iTnRequestInProgress = EFalse; |
|
1211 } |
|
1212 } |
|
1213 #endif |
|
1214 |
|
1215 // --------------------------------------------------------------------------- |
|
1216 // CGlxDataSourceMde |
|
1217 // HarvestingUpdated |
|
1218 // --------------------------------------------------------------------------- |
|
1219 // |
|
1220 void CGlxDataSourceMde::HarvestingUpdated( |
|
1221 HarvesterEventObserverType /*aHEObserverType*/, |
|
1222 HarvesterEventState aHarvesterEventState, |
|
1223 TInt /*aItemsLeft*/) |
|
1224 { |
|
1225 TRACER("void CGlxDataSourceMde::HarvestingUpdated()"); |
|
1226 GLX_LOG_INFO1("CGlxDataSourceMde::HarvestingUpdated() aHarvesterEventState=%d", |
|
1227 aHarvesterEventState); |
|
1228 |
|
1229 switch(aHarvesterEventState) |
|
1230 { |
|
1231 case EHEStateStarted: |
|
1232 GLX_LOG_INFO("CGlxDataSourceMde::HarvestingUpdated() - EHEStateStarted"); |
|
1233 case EHEStateResumed: |
|
1234 case EHEStateHarvesting: |
|
1235 { |
|
1236 iHarvestingOngoing = ETrue; |
|
1237 } |
|
1238 break; |
|
1239 case EHEStatePaused: |
|
1240 case EHEStateFinished: |
|
1241 { |
|
1242 iHarvestingOngoing = EFalse; |
|
1243 GLX_LOG_INFO("CGlxDataSourceMde::HarvestingUpdated() - EHEStateFinished"); |
|
1244 } |
|
1245 break; |
|
1246 default: |
|
1247 break; |
|
1248 } |
|
1249 } |
|
1250 |
|
1251 // --------------------------------------------------------------------------- |
|
1252 // ShutdownNotification |
|
1253 // --------------------------------------------------------------------------- |
|
1254 // |
|
1255 void CGlxDataSourceMde::ShutdownNotification(TInt aShutdownState) |
|
1256 { |
|
1257 TRACER("void CGlxDataSourceMde::ShutdownNotification(TInt aShutdownState)") |
|
1258 GLX_DEBUG2("CGlxDataSourceMde::ShutdownNotification(aShutdownState=%d)", |
|
1259 aShutdownState); |
|
1260 |
|
1261 if (!iDataSourceReady && 0 == aShutdownState) |
|
1262 { |
|
1263 GLX_DEBUG1("Photos MdS ShutdownNotification - MdS Server restarted!"); |
|
1264 CreateSession(); |
|
1265 } |
|
1266 |
|
1267 if (iDataSourceReady && 1 == aShutdownState) |
|
1268 { |
|
1269 GLX_DEBUG1("Photos MdS ShutdownNotification - MdS Server Shutdown!"); |
|
1270 HandleSessionError(*iSession, KErrServerTerminated); |
|
1271 } |
|
1272 } |