|
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: Image Viewer AppUi class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "glxivwrappui.h" |
|
22 #include "glxivwrdocument.h" |
|
23 |
|
24 #include <apgcli.h> |
|
25 #include <hal.h> |
|
26 #include <oommonitorsession.h> |
|
27 #include <mpxviewutility.h> |
|
28 #include <mpxcollectionpath.h> |
|
29 |
|
30 #include <glxmedialist.h> |
|
31 #include <glxcollectionpluginimageviewer.hrh> |
|
32 #include <glxviewpluginuids.hrh> |
|
33 #include <glxuiutility.h> |
|
34 #include <glxzoomstatepublisher.h> |
|
35 #include <glxnavigationalstate.h> |
|
36 #include <glxnavigationalstatedefs.h> |
|
37 #include <glxtracer.h> |
|
38 #include <glxlog.h> |
|
39 #include <glxivwr.rsg> |
|
40 |
|
41 |
|
42 |
|
43 //constants |
|
44 const TInt KGlxFullThumbnailCount = 1 ; // 1 visible thumnail |
|
45 #ifdef __MARM |
|
46 const TInt KGlxMaxMegaPixelsSupportedByCamera = 5242880 ; // 5 MB |
|
47 #else |
|
48 const TInt KGlxMaxMegaPixelsSupportedByCamera = 2097152 ; // 2 MB |
|
49 #endif |
|
50 const TInt KGlxMaxMemoryToDecodeCapturedPicture = 2 * KGlxMaxMegaPixelsSupportedByCamera ; |
|
51 const TInt KGlxMemoryForOOMFwk = 1048576 ; // 1 MB |
|
52 const TInt KGlxThumbNailRepresentation = 4; // Thumbnail Representation; Could be 3 also |
|
53 |
|
54 // UID for the application, |
|
55 // this should correspond to the uid defined in the mmp file |
|
56 static const TUid KUidGlxIvwrApp = {0x200104E7}; |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // Constructor |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CGlxIVwrAppUi::CGlxIVwrAppUi() |
|
63 { |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // ConstructL is called by the application framework |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CGlxIVwrAppUi::ConstructL() |
|
71 { |
|
72 TRACER("void CGlxIVwrAppUi::ConstructL()"); |
|
73 |
|
74 // Enable Avkon skins. |
|
75 BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible ); |
|
76 |
|
77 // Create navigational state |
|
78 iNavigationalState = CGlxNavigationalState::InstanceL(); |
|
79 iNavigationalState->AddObserverL( *this ); |
|
80 iNavigationalState->SetBackExitStatus(EFalse); |
|
81 |
|
82 // Get an instance of view utility |
|
83 iViewUtility = MMPXViewUtility::UtilityL(); |
|
84 |
|
85 iUiUtility = CGlxUiUtility::UtilityL(); |
|
86 // Always start in default orientation |
|
87 iUiUtility->SetAppOrientationL(EGlxOrientationDefault); |
|
88 |
|
89 ReserveMemoryL(EEntryTypeStartUp); |
|
90 |
|
91 // publish zoom context, no zoom keys for now |
|
92 NGlxZoomStatePublisher::PublishStateL( EFalse ); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // Destructor |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 CGlxIVwrAppUi::~CGlxIVwrAppUi() |
|
100 { |
|
101 TRACER("CGlxIVwrAppUi::~CGlxIVwrAppUi()"); |
|
102 if ( iNavigationalState ) |
|
103 { |
|
104 iNavigationalState->RemoveObserver(*this); |
|
105 iNavigationalState->Close(); |
|
106 } |
|
107 |
|
108 if ( iViewUtility ) |
|
109 { |
|
110 iViewUtility->Close(); |
|
111 } |
|
112 |
|
113 if ( iUiUtility ) |
|
114 { |
|
115 iUiUtility->Close(); |
|
116 } |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // HandleCommandL |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 void CGlxIVwrAppUi::HandleCommandL(TInt aCommand) |
|
124 { |
|
125 TRACER("void CGlxIVwrAppUi::HandleCommandL(TInt aCommand)"); |
|
126 GLX_LOG_INFO1("void CGlxIVwrAppUi::HandleCommandL(aCommand=%d)", aCommand ); |
|
127 switch (aCommand) |
|
128 { |
|
129 case EEikCmdExit: |
|
130 { |
|
131 Exit(); |
|
132 } |
|
133 break; |
|
134 case EAknSoftkeyExit: |
|
135 { |
|
136 CloseImgVwr(); |
|
137 GLX_LOG_INFO("CGlxIVwrAppUi::HandleCommandL: Exit() being Called"); |
|
138 Exit(); |
|
139 } |
|
140 break; |
|
141 |
|
142 case EAknSoftkeyBack: |
|
143 { |
|
144 iNavigationalState->ActivatePreviousViewL(); |
|
145 } |
|
146 break; |
|
147 |
|
148 default: |
|
149 break; |
|
150 } |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // ProcessCommandParametersL |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 TBool CGlxIVwrAppUi::ProcessCommandParametersL(TApaCommand /*aCommand*/, |
|
158 TFileName& /*aDocumentName*/, const TDesC8& /*aTail*/) |
|
159 { |
|
160 TRACER("TBool CGlxIVwrAppUi::ProcessCommandParametersL()"); |
|
161 |
|
162 // Bring the application to foreground, if not already |
|
163 if (0 != iEikonEnv->RootWin().OrdinalPosition()) |
|
164 { |
|
165 iEikonEnv->RootWin().SetOrdinalPosition(0); |
|
166 } |
|
167 |
|
168 //To call OpenFileL in document class it must retun ETrue |
|
169 return ETrue; |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // Handle navigational state change |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 void CGlxIVwrAppUi::HandleNavigationalStateChangedL() |
|
177 { |
|
178 TRACER("void CGlxIVwrAppUi::HandleNavigationalStateChangedL()"); |
|
179 // get current navigational state |
|
180 CMPXCollectionPath* naviState = iNavigationalState->StateLC(); |
|
181 |
|
182 // Case: Open photos in grid, go to filemanager via menu and open any image |
|
183 if (naviState->Id() != TMPXItemId( |
|
184 KGlxCollectionPluginImageViewerImplementationUid)) |
|
185 { |
|
186 /* |
|
187 * This thread chk is added for EDDG-7UUC53. In this scenario we get EPathChanged from MPX. |
|
188 * That initiates a viewnavigational change from CGlxNavigationalStateImp HandleCollectionMessageL() |
|
189 * In these types of scenarios we don't want a view switch. So ignoring the event. |
|
190 */ |
|
191 TApaTaskList taskList(iCoeEnv->WsSession()); |
|
192 TApaTask task = taskList.FindApp(KUidGlxIvwrApp); |
|
193 TApaTask taskForeGround = taskList.FindByPos(0); // get fopreground app |
|
194 if (task.Exists() && task.ThreadId() != taskForeGround.ThreadId()) |
|
195 { |
|
196 GLX_LOG_INFO("CGlxIVwrAppUi ::HandleNavigationalStateChanged: Return "); |
|
197 return; |
|
198 } |
|
199 } |
|
200 |
|
201 CleanupStack::PopAndDestroy(naviState); |
|
202 |
|
203 if (TUid::Null() != iStartupViewUid) |
|
204 { |
|
205 GLX_LOG_INFO("CGlxIVwrAppUi::HandleNavigationalStateChanged:Activating startup view"); |
|
206 // Activate startup view |
|
207 iViewUtility->ActivateViewL(iStartupViewUid, NULL); |
|
208 iStartupViewUid = TUid::Null(); |
|
209 } |
|
210 else |
|
211 { |
|
212 GLX_LOG_INFO("CGlxIVwrAppUi::HandleNavigationalStateChanged:Activating view"); |
|
213 |
|
214 // get ids for scoring a view |
|
215 RArray<TUid> scoringIds; |
|
216 CleanupClosePushL(scoringIds); |
|
217 GetViewScoringIdsL(scoringIds); |
|
218 |
|
219 GLX_LOG_INFO1("CGlxIVwrAppUi::HandleNavigationalStateChanged:Uid count %d", scoringIds.Count()); |
|
220 // let view utility to select the best view based on scoring ids |
|
221 iViewUtility->ActivateViewL(scoringIds, NULL); |
|
222 |
|
223 CleanupStack::PopAndDestroy(&scoringIds); |
|
224 } |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // Populate array with view scoring ids |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 void CGlxIVwrAppUi::GetViewScoringIdsL( RArray<TUid>& aIds ) const |
|
232 { |
|
233 TRACER("void CGlxIVwrAppUi::GetViewScoringIdsL()"); |
|
234 CleanupClosePushL(aIds); |
|
235 aIds.Reset(); // For maintenance safety |
|
236 |
|
237 // get current navigational state |
|
238 CMPXCollectionPath* naviState = iNavigationalState->StateLC(); |
|
239 |
|
240 // no if check in needed here ,it makes the aapui aware of the list view depth |
|
241 // to be removed.added by gopa |
|
242 if (naviState->Levels() >= 1) |
|
243 { |
|
244 if (iNavigationalState->ViewingMode() |
|
245 == NGlxNavigationalState::EBrowse) |
|
246 { |
|
247 // For image viewer collection, goto view mode |
|
248 if (naviState->Id() == TMPXItemId( |
|
249 KGlxCollectionPluginImageViewerImplementationUid)) |
|
250 { |
|
251 aIds.AppendL(TUid::Uid(KGlxViewingModeView)); |
|
252 } |
|
253 else |
|
254 { |
|
255 aIds.AppendL(TUid::Uid(KGlxViewingModeBrowse)); |
|
256 } |
|
257 } |
|
258 else |
|
259 { |
|
260 aIds.AppendL(TUid::Uid(KGlxViewingModeView)); |
|
261 } |
|
262 } |
|
263 |
|
264 if (TUid::Null() != GetViewScoringIdForCollectionPlugin(*naviState)) |
|
265 { |
|
266 // add scoring id for collection plugin |
|
267 aIds.AppendL(GetViewScoringIdForCollectionPlugin(*naviState)); |
|
268 } |
|
269 |
|
270 if (TUid::Null() != ViewScoringIdForNaviStateDepth(*naviState)) |
|
271 { |
|
272 // add scoring id for depth in the ui hierarchy |
|
273 aIds.AppendL(ViewScoringIdForNaviStateDepth(*naviState)); |
|
274 } |
|
275 |
|
276 CleanupStack::PopAndDestroy(naviState); |
|
277 CleanupStack::Pop(&aIds); |
|
278 } |
|
279 |
|
280 // --------------------------------------------------------------------------- |
|
281 // Return scoring id for collection plugin |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 TUid CGlxIVwrAppUi::GetViewScoringIdForCollectionPlugin( |
|
285 const CMPXCollectionPath& aNaviState) const |
|
286 { |
|
287 TRACER("TUid CGlxIVwrAppUi::GetViewScoringIdForCollectionPluginL()"); |
|
288 |
|
289 GLX_LOG_INFO1( "CGlxIVwrAppUi::GetViewScoringIdForCollectionPluginL:Depth %d", aNaviState.Levels() ); |
|
290 // score view based on collection plugin if not on root level |
|
291 if (aNaviState.Levels()) |
|
292 { |
|
293 return TUid::Uid(aNaviState.Id(0)); |
|
294 } |
|
295 // return null as id to be ignored in scoring |
|
296 return TUid::Null(); |
|
297 } |
|
298 |
|
299 // --------------------------------------------------------------------------- |
|
300 // Return scoring id for depth |
|
301 // --------------------------------------------------------------------------- |
|
302 // |
|
303 TUid CGlxIVwrAppUi::ViewScoringIdForNaviStateDepth( |
|
304 const CMPXCollectionPath& aNaviState) const |
|
305 { |
|
306 TRACER("TUid CGlxIVwrAppUi::ViewScoringIdForNaviStateDepthL()"); |
|
307 GLX_LOG_INFO1( "CGlxIVwrAppUi::ViewScoringIdForNaviStateDepthL: Level %d",aNaviState.Levels() ); |
|
308 |
|
309 switch (aNaviState.Levels()) |
|
310 { |
|
311 case 0: |
|
312 |
|
313 GLX_LOG_INFO1( "CGlxIVwrAppUi::ViewScoringIdForNaviStateDepthL:Depth case 0 %x", TUid::Uid( KGlxDepthOne ) ); |
|
314 return TUid::Uid(KGlxDepthOne); |
|
315 |
|
316 case 1: |
|
317 |
|
318 GLX_LOG_INFO1( "CGlxIVwrAppUi::ViewScoringIdForNaviStateDepthL:Depth case 1 %x", TUid::Uid( KGlxDepthTwo ) ); |
|
319 return TUid::Uid(KGlxDepthTwo); |
|
320 |
|
321 case 2: |
|
322 |
|
323 GLX_LOG_INFO1( "CGlxIVwrAppUi::GetViewScoringIdForUiHieararchyDepthL:Depth case 2 %x", TUid::Uid( KGlxDepthThree ) ); |
|
324 return TUid::Uid(KGlxDepthThree); |
|
325 |
|
326 default: |
|
327 GLX_LOG_WARNING( "CGlxIVwrAppUi::GetViewScoringIdsL:Navigational state deeper than supported" ); |
|
328 // return null as an id to be ignored in scoring |
|
329 return TUid::Null(); |
|
330 } |
|
331 } |
|
332 |
|
333 // --------------------------------------------------------------------------- |
|
334 // HandleOpenFileL |
|
335 // --------------------------------------------------------------------------- |
|
336 // |
|
337 void CGlxIVwrAppUi::HandleOpenFileL() |
|
338 { |
|
339 TRACER("void CGlxIVwrAppUi::HandleOpenFileL()"); |
|
340 CMPXCollectionPath* path = CMPXCollectionPath::NewL(); |
|
341 CleanupStack::PushL(path); |
|
342 path->AppendL( KGlxCollectionPluginImageViewerImplementationUid ); |
|
343 iNavigationalState->NavigateToL( *path ); |
|
344 CleanupStack::PopAndDestroy( path ); |
|
345 } |
|
346 |
|
347 // --------------------------------------------------------------------------- |
|
348 // OOMRequestFreeMemoryL |
|
349 // --------------------------------------------------------------------------- |
|
350 // |
|
351 TInt CGlxIVwrAppUi::OOMRequestFreeMemoryL(TInt aBytesRequested) |
|
352 { |
|
353 TRACER("TInt CGlxIVwrAppUi::OOMRequestFreeMemoryL(TInt aBytesRequested)"); |
|
354 GLX_LOG_INFO1("CGlxIVwrAppUi::OOMRequestFreeMemoryL() aBytesRequested=%d",aBytesRequested); |
|
355 |
|
356 ROomMonitorSession oomMonitor; |
|
357 User::LeaveIfError( oomMonitor.Connect() ); |
|
358 // No leaving code after this point, so no need to use cleanup stack |
|
359 // for oomMonitor |
|
360 TInt errorCode = oomMonitor.RequestFreeMemory( aBytesRequested ); |
|
361 GLX_LOG_INFO1("CGlxIVwrAppUi::OOMRequestFreeMemoryL(1) errorCode=%d",errorCode); |
|
362 if ( errorCode != KErrNone ) |
|
363 { |
|
364 // try one more time |
|
365 errorCode = oomMonitor.RequestFreeMemory( aBytesRequested ); |
|
366 GLX_LOG_INFO1("CGlxIVwrAppUi::OOMRequestFreeMemoryL(2) errorCode=%d",errorCode); |
|
367 } |
|
368 oomMonitor.Close(); |
|
369 return errorCode; |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------------------------- |
|
373 // ReserveMemoryL |
|
374 // --------------------------------------------------------------------------- |
|
375 // |
|
376 TInt CGlxIVwrAppUi::ReserveMemoryL(TInt aCriticalMemoryRequired) |
|
377 { |
|
378 TRACER("void CGlxIVwrAppUi::ReserveMemoryL(TInt aCriticalMemoryRequired)"); |
|
379 |
|
380 TInt memoryLeft = 0; |
|
381 TInt error = KErrNone ; |
|
382 HAL::Get( HALData::EMemoryRAMFree, memoryLeft ); |
|
383 GLX_LOG_INFO2("CGlxIVwrAppUi::ReserveMemoryL() - aCriticalMemoryRequired=%d, memoryLeft=%d", aCriticalMemoryRequired, memoryLeft); |
|
384 if ( aCriticalMemoryRequired > memoryLeft ) |
|
385 { |
|
386 // Request for critical memory required |
|
387 error = OOMRequestFreeMemoryL( aCriticalMemoryRequired); |
|
388 GLX_LOG_INFO1("CGlxIVwrAppUi::ReserveMemoryL() - OOMRequestFreeMemoryL() error=%d", error); |
|
389 } |
|
390 return error; |
|
391 } |
|
392 |
|
393 // --------------------------------------------------------------------------- |
|
394 // RamRequiredInBytesL |
|
395 // --------------------------------------------------------------------------- |
|
396 // |
|
397 TInt CGlxIVwrAppUi::RamRequiredInBytesL(TEntryType aType) |
|
398 { |
|
399 TRACER("TInt CGlxIVwrAppUi::RamRequiredInBytesL(TEntryType aType)"); |
|
400 TInt criticalRamMemory = 0 ; |
|
401 TSize displaySize = iUiUtility->DisplaySize(); |
|
402 if(EEntryTypeStartUp == aType) |
|
403 { |
|
404 // This is Bare Minimum Required Memory for Photos to start |
|
405 // For Framework to work and to do the on-the-fly decoding |
|
406 // for the just captured picture = KGlxMemoryForOOMFwk + KGlxMaxMemoryToDecodeCapturedPicture |
|
407 // For FullScreen to Work Number of Thumbnail(s) * Width * Height * Representation |
|
408 criticalRamMemory = KGlxMemoryForOOMFwk |
|
409 + KGlxMaxMemoryToDecodeCapturedPicture |
|
410 + (KGlxFullThumbnailCount * displaySize.iWidth |
|
411 * displaySize.iHeight * KGlxThumbNailRepresentation); |
|
412 |
|
413 GLX_LOG_INFO1("CGlxIVwrAppUi::RamRequiredInBytesL(EEntryTypeStartUp):criticalRamMemory=%d", criticalRamMemory); |
|
414 } |
|
415 else |
|
416 { |
|
417 GLX_LOG_INFO("CGlxIVwrAppUi::RamRequiredInBytesL():Viewer Already Running"); |
|
418 } |
|
419 |
|
420 return criticalRamMemory; |
|
421 } |
|
422 |
|
423 // --------------------------------------------------------------------------- |
|
424 // ReserveMemoryL |
|
425 // --------------------------------------------------------------------------- |
|
426 // |
|
427 void CGlxIVwrAppUi::ReserveMemoryL(TEntryType aType) |
|
428 { |
|
429 TRACER("TInt CGlxIVwrAppUi::ReserveMemoryL(TEntryType aType)"); |
|
430 |
|
431 TInt error = ReserveMemoryL(RamRequiredInBytesL(aType)); |
|
432 GLX_LOG_INFO1("CGlxIVwrAppUi::ReserveMemoryL() error=%d", error); |
|
433 |
|
434 if (KErrNoMemory == error) |
|
435 { |
|
436 GLX_LOG_INFO("CGlxIVwrAppUi::ReserveMemoryL():LEAVE with KErrNoMemory"); |
|
437 User::Leave(KErrNoMemory); |
|
438 } |
|
439 } |
|
440 |
|
441 // --------------------------------------------------------------------------- |
|
442 // HandleApplicationSpecificEventL |
|
443 // |
|
444 // --------------------------------------------------------------------------- |
|
445 // |
|
446 void CGlxIVwrAppUi::HandleApplicationSpecificEventL(TInt aEventType, |
|
447 const TWsEvent& aWsEvent) |
|
448 { |
|
449 TRACER("CGlxIVwrAppUi::HandleApplicationSpecificEventL"); |
|
450 CAknViewAppUi::HandleApplicationSpecificEventL(aEventType,aWsEvent); |
|
451 if(aWsEvent.Type() == KAknUidValueEndKeyCloseEvent) |
|
452 { |
|
453 CloseImgVwr(); |
|
454 } |
|
455 } |
|
456 |
|
457 // ----------------------------------------------------------------------------- |
|
458 // CloseImgVwr |
|
459 // ----------------------------------------------------------------------------- |
|
460 // |
|
461 void CGlxIVwrAppUi::CloseImgVwr() |
|
462 { |
|
463 TRACER("CGlxIVwrAppUi::CloseImgVwr()"); |
|
464 iUiUtility->SetViewNavigationDirection(EGlxNavigationBackwards); |
|
465 iUiUtility->SetExitingState(ETrue); |
|
466 } |
|
467 |
|
468 // ---------------------------------------------------------------------------- |
|
469 // CGlxIVwrAppUi::OpenFileL |
|
470 // This is called by framework when application is already open in background |
|
471 // and user open other file in eg. File Browse. |
|
472 // New file to been shown is passed via aFileName. |
|
473 // ---------------------------------------------------------------------------- |
|
474 // |
|
475 void CGlxIVwrAppUi::OpenFileL(const TDesC& aFileName) |
|
476 { |
|
477 TRACER("CGlxIVwrAppUi::OpenFileL()"); |
|
478 GLX_LOG_URI("CGlxIVwrAppUi::OpenFileL(%S)", &aFileName); |
|
479 |
|
480 // File changed. Open new file with documents OpenFileL method. |
|
481 Document()->OpenFileL(EFalse, aFileName, iEikonEnv->FsSession()); |
|
482 |
|
483 GLX_DEBUG1("CGlxIVwrAppUi::OpenFileL() *** File Changed *** "); |
|
484 MGlxCache* cacheManager = MGlxCache::InstanceL(); |
|
485 CleanupClosePushL(*cacheManager); |
|
486 |
|
487 CMPXCollectionPath* path = CMPXCollectionPath::NewL(); |
|
488 CleanupStack::PushL(path); |
|
489 path->AppendL(KGlxCollectionPluginImageViewerImplementationUid); |
|
490 |
|
491 MGlxMediaList* mediaList = MGlxMediaList::InstanceL(*path); |
|
492 CleanupClosePushL(*mediaList); |
|
493 |
|
494 if (mediaList->Count() > 0) |
|
495 { |
|
496 GLX_DEBUG1("CGlxIVwrAppUi::OpenFileL() - Cleanup & Refresh Media!"); |
|
497 cacheManager->ForceCleanupMedia(mediaList->IdSpaceId(0), |
|
498 mediaList->Item(0).Id()); |
|
499 cacheManager->RefreshL(); |
|
500 } |
|
501 |
|
502 CleanupStack::PopAndDestroy(mediaList); |
|
503 CleanupStack::PopAndDestroy(path); |
|
504 CleanupStack::PopAndDestroy(cacheManager); |
|
505 } |