photosgallery/gallery/src/glxappui.cpp
branchRCL_3
changeset 26 5b3385a43d68
child 27 34937ec34dac
equal deleted inserted replaced
25:8e5f6eea9c9f 26:5b3385a43d68
       
     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:    AppUi class 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19  
       
    20 
       
    21 #include "glxappui.h"
       
    22 #include "glxcachemanager.h"
       
    23 #include "glxiadupdate.h"
       
    24 
       
    25 #include <avkon.hrh>
       
    26 #include <StringLoader.h>    
       
    27 #include <aknnotewrappers.h>
       
    28 #include <AknUtils.h>
       
    29 #include <mpxviewutility.h>
       
    30 #include <mpxcollectionutility.h>
       
    31 #include <mpxcollectionmessage.h>
       
    32 #include <mpxmessagegeneraldefs.h>
       
    33 #include <mpxcollectionpath.h>
       
    34 #include <centralrepository.h>
       
    35 #include <alf/alfenv.h>
       
    36 #include <akntoolbar.h>
       
    37 #include <glxgallery.hrh>
       
    38 #include <glxcollectionplugincamera.hrh>
       
    39 #include <glxcollectionpluginall.hrh>
       
    40 #include <glxcollectionpluginalbums.hrh>
       
    41 #include <glxcollectionplugintags.hrh>
       
    42 #include <glxcollectionpluginimageviewer.hrh>
       
    43 #include <glxcollectionplugintype.hrh>
       
    44 #include <glxfiltergeneraldefs.h>
       
    45 #include <glxpanic.h>
       
    46 #include <glxuistd.h>
       
    47 #include <glxviewpluginuids.hrh>
       
    48 #include <glxlog.h>
       
    49 #include <glxuiutility.h>
       
    50 #include <glxsettingsmodel.h>
       
    51 #include <glxupnprenderer.h>
       
    52 #include <glxcommandhandlers.hrh>
       
    53 #include <glxzoomstatepublisher.h>
       
    54 #include <glxnavigationalstate.h>
       
    55 #include <glxnavigationalstatedefs.h>
       
    56 #include <glxfullscreenviewplugin.hrh>
       
    57 #include <glx.rsg>
       
    58 #include <AknGlobalNote.h>
       
    59 #include <hal.h>
       
    60 #include <hal_data.h>
       
    61 #include <oommonitorsession.h>
       
    62 #include <glxtracer.h>
       
    63 
       
    64 //OOM
       
    65 #include <oommonitorplugin.h>
       
    66 #include <oommonitorsession.h>
       
    67 #include <glxuistd.h>
       
    68 #include <apgcli.h>
       
    69 
       
    70 //constants
       
    71 const TInt KGlxGridThumbnailPages          = 9 ;       // 4 page Down + 4 page Up + 1 Visible page = 9 page 
       
    72 const TInt KGlxFullThumbnailCount         = 11 ;       // 5 Thumnail Front + 5 Thumbnail Rear + 1 Visible = 11 page
       
    73 #ifdef __MARM
       
    74 const TInt KGlxMaxMegaPixelsSupportedByCamera = 5242880 ; // 5 MB
       
    75 #else
       
    76 const TInt KGlxMaxMegaPixelsSupportedByCamera = 2097152 ; // 2 MB
       
    77 #endif
       
    78 const TInt KGlxMaxMemoryToDecodeCapturedPicture = 2 * KGlxMaxMegaPixelsSupportedByCamera ;
       
    79 const TInt KGlxMemoryForOOMFwk          = 1048576 ; // 1 MB
       
    80 const TInt KGlxThumbNailRepresentation    = 2;         // Thumbnail Representation; Could be 3 also 
       
    81 
       
    82 /**
       
    83  * Start Delay for the periodic timer, in microseconds
       
    84  */
       
    85 const TInt KPeriodicStartDelay = 60000000; // 60 secs
       
    86 // -----------------------------------------------------------------------------
       
    87 // Constructor
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 CGlxAppUi::CGlxAppUi()
       
    91     {
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // ConstructL is called by the application framework
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CGlxAppUi::ConstructL()
       
    99     {
       
   100     TRACER("void CGlxAppUi::ConstructL()");
       
   101 
       
   102     // Enable Avkon skins.
       
   103     BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible );
       
   104     // Create navigational state 
       
   105     iNavigationalState = CGlxNavigationalState::InstanceL();
       
   106     
       
   107     iNavigationalState->AddObserverL( *this );
       
   108 
       
   109 	iNavigationalState->SetBackExitStatus(EFalse);
       
   110     
       
   111     iFocusLostLowMemory = EFalse;
       
   112     
       
   113     // Get an instance of view utility
       
   114     iViewUtility = MMPXViewUtility::UtilityL();
       
   115     
       
   116     iUiUtility = CGlxUiUtility::UtilityL();
       
   117     // Always start in default orientation
       
   118     iUiUtility->SetAppOrientationL(EGlxOrientationDefault);
       
   119     ReserveMemoryL(EEntryTypeStartUp);
       
   120     // publish zoom context, no zoom keys for now
       
   121     NGlxZoomStatePublisher::PublishStateL( EFalse );
       
   122     iEndKeyPressed = EFalse;
       
   123     iStateChangeRequested = EFalse;
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // Destructor
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 CGlxAppUi::~CGlxAppUi()
       
   131     {
       
   132     TRACER("CGlxAppUi::~CGlxAppUi()");
       
   133 	iEndKeyPressed = EFalse;
       
   134     if ( iNavigationalState )
       
   135         {
       
   136         iNavigationalState->RemoveObserver(*this);
       
   137         iNavigationalState->Close();
       
   138         }
       
   139 
       
   140     if ( iViewUtility )
       
   141         {
       
   142         iViewUtility->Close();
       
   143         }
       
   144 
       
   145     delete iActivationParam;
       
   146 
       
   147     if ( iUiUtility )
       
   148         {
       
   149         iUiUtility->Close();
       
   150         }
       
   151 
       
   152     if (iPeriodic)
       
   153         {
       
   154         iPeriodic->Cancel();
       
   155         delete iPeriodic;
       
   156         }
       
   157     
       
   158     if( iIadUpdate )
       
   159         {	
       
   160     	delete iIadUpdate;
       
   161     	}
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // HandleCommandL
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CGlxAppUi::HandleCommandL(TInt aCommand)
       
   169     {
       
   170     TRACER("void CGlxAppUi::HandleCommandL(TInt aCommand)");
       
   171     GLX_LOG_INFO1("PHOTOS LOGS: void CGlxAppUi::HandleCommandL(TInt aCommand = %d)",aCommand );
       
   172     switch(aCommand)
       
   173         {
       
   174         case EEikCmdExit:
       
   175             {
       
   176             iUiUtility->SetExitingState(ETrue);
       
   177             Exit();
       
   178             }
       
   179             break;
       
   180         case EAknSoftkeyExit:
       
   181             {
       
   182 			ClosePhotosL();
       
   183             GLX_LOG_INFO("CGlxAppUi::HandleCommandL: Exit() being Called");
       
   184             Exit();
       
   185             }
       
   186             break;
       
   187 
       
   188         case EAknSoftkeyBack:
       
   189             iNavigationalState->ActivatePreviousViewL();
       
   190             break;
       
   191 
       
   192         default:
       
   193             break;
       
   194         }
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // HandleMessageL
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 MCoeMessageObserver::TMessageResponse CGlxAppUi::HandleMessageL(
       
   202                             TUint32 /*aClientHandleOfTargetWindowGroup*/,
       
   203                             TUid aMessageUid, const TDesC8& aMessageParameters)
       
   204     {
       
   205     TRACER("MCoeMessageObserver::TMessageResponse CGlxAppUi::HandleMessageL(TUint32 aClientHandleOfTargetWindowGroup,TUid aMessageUid, const TDesC8& aMessageParameters)");
       
   206 
       
   207     // TO DO: Check if gallery is in background
       
   208     MCoeMessageObserver::TMessageResponse
       
   209                             response = MCoeMessageObserver::EMessageHandled;
       
   210 
       
   211 
       
   212     switch ( aMessageUid.iUid )
       
   213 		{
       
   214         case KGlxActivationCmdShowLastModified:
       
   215         case KGlxActivationCameraAlbum:
       
   216         case KGlxActivationCmdShowAll:
       
   217             HandleActivationMessageL(aMessageParameters);
       
   218             break;
       
   219          
       
   220         default:
       
   221             //To prevent Continues Activation of the Same View; Same is Triggered in ProcessCommandParametersL
       
   222             HandleActivationMessageL(aMessageParameters);           
       
   223             break;
       
   224         }
       
   225     
       
   226     //Safely we can call Destroy screen here, as there can be already 
       
   227     //photos in background and bringing it to foreground does not 
       
   228     //give the ViewActivate( ) callback to view.
       
   229     iUiUtility->DestroyScreenClearer();
       
   230     
       
   231     return response;
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // ProcessCommandParametersL
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 TBool CGlxAppUi::ProcessCommandParametersL(TApaCommand aCommand,
       
   239                             TFileName& aDocumentName, const TDesC8& aTail)
       
   240     {
       
   241     TRACER("TBool CGlxAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& aDocumentName, const TDesC8& aTail)");
       
   242     
       
   243     TRAPD(err, HandleActivationMessageL(aCommand, aDocumentName, aTail));
       
   244     if ( KErrNone != err )
       
   245         {
       
   246         // Open navigational state at root level
       
   247         CMPXCollectionPath* newState = CMPXCollectionPath::NewL();
       
   248         CleanupStack::PushL( newState );
       
   249         iNavigationalState->NavigateToL( *newState );
       
   250         iStateChangeRequested = ETrue;
       
   251         CleanupStack::PopAndDestroy( newState );
       
   252         }
       
   253 
       
   254     //Start a timer to check for thr IAD update after 60 Secs.
       
   255     //Only when any view is launched in photos.
       
   256     if(!iPeriodic)
       
   257         {
       
   258         iPeriodic = CPeriodic::NewL(CActive::EPriorityLow);
       
   259         }    
       
   260     if ( !iPeriodic->IsActive() )
       
   261         {
       
   262         iPeriodic->Start( KPeriodicStartDelay, KMaxTInt, 
       
   263                 TCallBack( &PeriodicCallback, static_cast<TAny*>(this) ) );
       
   264         }
       
   265     
       
   266     if(0 == aTail.CompareC(KNullDesC8))
       
   267         {
       
   268       	return ETrue;
       
   269         }
       
   270     else
       
   271         {
       
   272         //other case
       
   273         return EFalse;
       
   274         }
       
   275 
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // Handle navigational state change
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 void CGlxAppUi::HandleNavigationalStateChangedL()
       
   283     {
       
   284     TRACER("void CGlxAppUi::HandleNavigationalStateChangedL()");
       
   285 
       
   286     /*
       
   287      * This thread chk is added for EDDG-7UUC53. In this scenario we get EPathChanged from MPX.
       
   288      * That initiates a viewnavigational change from CGlxNavigationalStateImp  HandleCollectionMessageL()
       
   289      * In these types of scenarios we don't want a view switch. So ignoring the event. 
       
   290      */
       
   291     TApaTaskList taskList( iCoeEnv->WsSession() );
       
   292 	TApaTask task = taskList.FindApp( TUid::Uid( KGlxGalleryApplicationUid ) );
       
   293 	TApaTask taskForeGround = taskList.FindByPos(0); // get fopreground app
       
   294 	if (!iStateChangeRequested && task.Exists() && task.ThreadId()
       
   295             != taskForeGround.ThreadId())
       
   296         {
       
   297         GLX_LOG_INFO("* CGlxAppUi::HandleNavigationalStateChanged:Return *");
       
   298         return;
       
   299         }
       
   300     HBufC* activationParam = iActivationParam;
       
   301     iActivationParam = NULL; // release ownership
       
   302     CleanupStack::PushL( activationParam );
       
   303 
       
   304     if ( TUid::Null() != iStartupViewUid )
       
   305         {
       
   306         GLX_LOG_INFO("CGlxAppUi::HandleNavigationalStateChanged: Activating startup view");
       
   307         // Activate startup view
       
   308         iViewUtility->ActivateViewL( iStartupViewUid, activationParam );
       
   309         iStartupViewUid = TUid::Null();
       
   310         }
       
   311     else
       
   312         {
       
   313         GLX_LOG_INFO("CGlxAppUi::HandleNavigationalStateChanged: Activating view");
       
   314         
       
   315         // get ids for scoring a view
       
   316         RArray< TUid > scoringIds;
       
   317         CleanupClosePushL( scoringIds );
       
   318         GetViewScoringIdsL( scoringIds );
       
   319         
       
   320         GLX_LOG_INFO1( "CGlxAppUi::HandleNavigationalStateChanged: Uid count %d", scoringIds.Count());
       
   321         // let view utility to select the best view based on scoring ids
       
   322         iViewUtility->ActivateViewL( scoringIds, activationParam );
       
   323     
       
   324         CleanupStack::PopAndDestroy( &scoringIds );
       
   325         }
       
   326 
       
   327     CleanupStack::PopAndDestroy( activationParam );
       
   328     iStateChangeRequested = EFalse;
       
   329     }
       
   330 
       
   331 // ---------------------------------------------------------------------------
       
   332 // Populate array with view scoring ids
       
   333 // ---------------------------------------------------------------------------
       
   334 //
       
   335 void CGlxAppUi::GetViewScoringIdsL( RArray<TUid>& aIds ) const
       
   336     {
       
   337     TRACER("void CGlxAppUi::GetViewScoringIdsL( RArray<TUid>& aIds ) const");
       
   338     CleanupClosePushL(aIds);
       
   339     aIds.Reset(); // For maintenance safety
       
   340 
       
   341     // get current navigational state
       
   342     CMPXCollectionPath* naviState = iNavigationalState->StateLC();
       
   343     if (naviState->Levels() >= 1)
       
   344         {
       
   345         if (iNavigationalState->ViewingMode()
       
   346                 == NGlxNavigationalState::EBrowse)
       
   347             {
       
   348             aIds.AppendL(TUid::Uid(KGlxViewingModeBrowse));
       
   349             }
       
   350         else
       
   351             {
       
   352             aIds.AppendL(TUid::Uid(KGlxViewingModeView));
       
   353             }
       
   354         }
       
   355 
       
   356     if (TUid::Null() != GetViewScoringIdForCollectionPlugin(*naviState))
       
   357         {
       
   358         // add scoring id for collection plugin
       
   359         aIds.AppendL(GetViewScoringIdForCollectionPlugin(*naviState));
       
   360         }
       
   361 
       
   362     if (TUid::Null() != ViewScoringIdForNaviStateDepth(*naviState))
       
   363         {
       
   364         // add scoring id for depth in the ui hierarchy
       
   365         aIds.AppendL(ViewScoringIdForNaviStateDepth(*naviState));
       
   366         }
       
   367 
       
   368     CleanupStack::PopAndDestroy(naviState);
       
   369     CleanupStack::Pop(&aIds);
       
   370     }
       
   371 
       
   372 // ---------------------------------------------------------------------------
       
   373 // Handles the foreground events
       
   374 // ---------------------------------------------------------------------------
       
   375 //
       
   376  void CGlxAppUi::HandleForegroundEventL( TBool aForeground )
       
   377     {
       
   378     TRACER("void CGlxAppUi::HandleForegroundEventL( TBool aForeground )");
       
   379 
       
   380     // first let base class handle it so that we dont break anything
       
   381     CAknViewAppUi::HandleForegroundEventL( aForeground );
       
   382 
       
   383     }
       
   384 // ---------------------------------------------------------------------------
       
   385 // Return scoring id for collection plugin
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 TUid CGlxAppUi::GetViewScoringIdForCollectionPlugin( const CMPXCollectionPath& aNaviState ) const
       
   389     {
       
   390     TRACER("TUid CGlxAppUi::GetViewScoringIdForCollectionPluginL( const CMPXCollectionPath& aNaviState ) const");
       
   391 
       
   392     GLX_LOG_INFO1( "CGlxAppUi::GetViewScoringIdForCollectionPluginL: Depth %d", aNaviState.Levels() );
       
   393     // score view based on collection plugin if not on root level
       
   394     if ( aNaviState.Levels() )
       
   395         {
       
   396         return TUid::Uid( aNaviState.Id( 0 ) );
       
   397         }
       
   398     // return null as id to be ignored in scoring
       
   399     return TUid::Null(); 
       
   400     }
       
   401 
       
   402 
       
   403 // ---------------------------------------------------------------------------
       
   404 // Return scoring id for depth
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 TUid CGlxAppUi::ViewScoringIdForNaviStateDepth( const CMPXCollectionPath& aNaviState ) const
       
   408     {
       
   409     TRACER("TUid CGlxAppUi::ViewScoringIdForNaviStateDepthL( const CMPXCollectionPath& aNaviState ) const");
       
   410     GLX_LOG_INFO1( "CGlxAppUi::ViewScoringIdForNaviStateDepthL: Level %d", aNaviState.Levels() );
       
   411 
       
   412     switch ( aNaviState.Levels() )
       
   413         {
       
   414         case 0:
       
   415       
       
   416             GLX_LOG_INFO1( "CGlxAppUi::ViewScoringIdForNaviStateDepthL: \
       
   417                             Depth  case 0 %x", TUid::Uid( KGlxDepthOne ) );
       
   418             return TUid::Uid( KGlxDepthOne );
       
   419         
       
   420         case 1:
       
   421        
       
   422             GLX_LOG_INFO1( "CGlxAppUi::ViewScoringIdForNaviStateDepthL: \
       
   423                             Depth case 1 %x", TUid::Uid( KGlxDepthTwo ) );
       
   424             return TUid::Uid( KGlxDepthTwo );
       
   425             
       
   426 
       
   427         case 2:
       
   428 
       
   429             GLX_LOG_INFO1( "CGlxAppUi::GetViewScoringIdForUiHieararchyDepthL: \
       
   430                             Depth case 2 %x", TUid::Uid( KGlxDepthThree ) );
       
   431             return TUid::Uid( KGlxDepthThree );
       
   432 
       
   433         default:
       
   434             GLX_LOG_WARNING( "CGlxAppUi::GetViewScoringIdsL: Navigational state deeper than supported" );
       
   435             // return null as an id to be ignored in scoring
       
   436             return TUid::Null(); 
       
   437         }
       
   438     }
       
   439 
       
   440 // ---------------------------------------------------------------------------
       
   441 // HandleActivationMessageL
       
   442 // ---------------------------------------------------------------------------
       
   443 //
       
   444 void CGlxAppUi::HandleActivationMessageL(const TApaCommand& /*aCommand*/, 
       
   445         const TFileName& /*aDocumentName*/, const TDesC8& aData)
       
   446     {
       
   447     TRACER("void CGlxAppUi::HandleActivationMessageL(const TApaCommand& aCommand, const TFileName& aDocumentName,const TDesC8& aData)");
       
   448     GLX_LOG_INFO1("Glx-HandleActivationMessageL() aData length=%d",
       
   449             aData.Length());
       
   450 
       
   451     delete iActivationParam;
       
   452     iActivationParam = NULL;
       
   453 
       
   454     if (aData.Length() == 0 )
       
   455         {
       
   456         // Open navigational state at root level
       
   457         CMPXCollectionPath* newState = CMPXCollectionPath::NewL();
       
   458         CleanupStack::PushL(newState);
       
   459         iNavigationalState->NavigateToL(*newState);
       
   460         iStateChangeRequested = ETrue;
       
   461         CleanupStack::PopAndDestroy(newState);
       
   462         }
       
   463     else
       
   464         {
       
   465         GLX_LOG_INFO("CGlxAppUi::HandleActivationMessageL(aData)");        
       
   466         HandleActivationMessageL( aData );
       
   467         }
       
   468     }
       
   469 
       
   470 // ---------------------------------------------------------------------------
       
   471 // HandleActivationMessageL
       
   472 // ---------------------------------------------------------------------------
       
   473 //
       
   474 void CGlxAppUi::HandleActivationMessageL(const TDesC8& aData)
       
   475     {
       
   476     TRACER("void CGlxAppUi::HandleActivationMessageL(const TDesC8& aData)");
       
   477 
       
   478     CMPXCollectionPath* path = CMPXCollectionPath::NewL();
       
   479     CleanupStack::PushL(path);
       
   480 
       
   481     delete iActivationParam;
       
   482     iActivationParam = NULL;
       
   483 
       
   484     TUid msgUid;
       
   485     RDesReadStream stream(aData);
       
   486     CleanupClosePushL(stream);
       
   487     stream >> msgUid;
       
   488     
       
   489     switch ( msgUid.iUid )
       
   490         {
       
   491         case KGlxActivationCmdShowLastModified:
       
   492         case KGlxActivationCameraAlbum:
       
   493         case KGlxActivationCmdShowAll:
       
   494             {
       
   495             GLX_LOG_INFO("CGlxAppUi::HandleActivationMessageL: Creating Screen Clearer");
       
   496             iUiUtility->DisplayScreenClearerL();
       
   497             HBufC8* activationParam = HBufC8::NewLC(KMaxUidName);
       
   498             activationParam->Des().AppendNum(KGlxActivationCmdShowAll);
       
   499             SetActivationParamL(*activationParam);
       
   500             CleanupStack::PopAndDestroy(activationParam);
       
   501             
       
   502             // Go to All grid view
       
   503             GLX_LOG_INFO("CGlxAppUi::HandleActivationMessageL: All Grid View");
       
   504             // Send the command to reset the view
       
   505             ProcessCommandL(EGlxCmdResetView);
       
   506             iNavigationalState->SetBackExitStatus(ETrue);
       
   507             path->AppendL(KGlxCollectionPluginAllImplementationUid);
       
   508             }
       
   509             break;
       
   510 
       
   511         default:
       
   512             GLX_LOG_INFO("CGlxAppUi::HandleActivationMessageL: unknown command");
       
   513             User::Leave(KErrNotSupported);
       
   514         }
       
   515     CleanupStack::PopAndDestroy(&stream);
       
   516     iNavigationalState->SetStartingLevel(path->Levels());
       
   517     iNavigationalState->NavigateToL( *path );
       
   518     iStateChangeRequested = ETrue;
       
   519     CleanupStack::PopAndDestroy(path);
       
   520     
       
   521     // Introduced to fix bug EMJN-78GH6N. 
       
   522     if (0 != iEikonEnv->RootWin().OrdinalPosition())
       
   523         {
       
   524         iEikonEnv->RootWin().SetOrdinalPosition(0);
       
   525         }
       
   526     }
       
   527 
       
   528 // ---------------------------------------------------------------------------
       
   529 // SetActivationParamL
       
   530 // ---------------------------------------------------------------------------
       
   531 //
       
   532 void CGlxAppUi::SetActivationParamL(const TDesC8& aParam)
       
   533     {
       
   534     TRACER("void CGlxAppUi::SetActivationParamL(const TDesC8& aParam)");
       
   535     iActivationParam = HBufC::NewL(aParam.Length());
       
   536     iActivationParam->Des().Copy(aParam);
       
   537     }
       
   538 
       
   539 // ---------------------------------------------------------------------------
       
   540 // RequestFreeMemory
       
   541 // ---------------------------------------------------------------------------
       
   542 //
       
   543 TInt CGlxAppUi::OOMRequestFreeMemoryL( TInt aBytesRequested)
       
   544     {
       
   545     TRACER("TInt CGlxAppUi::OOMRequestFreeMemoryL( TInt aBytesRequested)");
       
   546     GLX_LOG_INFO1("CGlxAppUi::OOMRequestFreeMemoryL() aBytesRequested=%d",
       
   547                                                         aBytesRequested);
       
   548 
       
   549     ROomMonitorSession oomMonitor;
       
   550     User::LeaveIfError( oomMonitor.Connect() );
       
   551     // No leaving code after this point, so no need to use cleanup stack
       
   552     // for oomMonitor
       
   553     TInt errorCode = oomMonitor.RequestFreeMemory( aBytesRequested );
       
   554     GLX_LOG_INFO1("CGlxAppUi::OOMRequestFreeMemoryL(1) errorCode=%d",errorCode);
       
   555     if ( errorCode != KErrNone )
       
   556         {
       
   557         // try one more time 
       
   558         errorCode = oomMonitor.RequestFreeMemory( aBytesRequested );
       
   559         GLX_LOG_INFO1("CGlxAppUi::OOMRequestFreeMemoryL(2) errorCode=%d",errorCode);
       
   560         }
       
   561     oomMonitor.Close();
       
   562     return errorCode;
       
   563     }
       
   564 
       
   565 
       
   566 // ---------------------------------------------------------------------------
       
   567 // ReserveMemory
       
   568 // ---------------------------------------------------------------------------
       
   569 //
       
   570 TInt CGlxAppUi::ReserveMemoryL(TInt aCriticalMemoryRequired)
       
   571     {
       
   572     TRACER("void CGlxAppUi::ReserveMemory(TInt aCriticalMemoryRequired)");
       
   573 
       
   574     TInt memoryLeft = 0;
       
   575     TInt error = KErrNone ; 
       
   576     HAL::Get( HALData::EMemoryRAMFree, memoryLeft );
       
   577     GLX_LOG_INFO2("CGlxAppUi::ReserveMemoryL() - aCriticalMemoryRequired=%d, memoryLeft=%d",
       
   578                                        aCriticalMemoryRequired, memoryLeft);
       
   579     if ( aCriticalMemoryRequired > memoryLeft )
       
   580         {
       
   581         // Request for critical memory required 
       
   582         error = OOMRequestFreeMemoryL( aCriticalMemoryRequired);
       
   583         GLX_LOG_INFO1("CGlxAppUi::ReserveMemoryL() - OOMRequestFreeMemoryL() error=%d", error);
       
   584         }
       
   585     return error;
       
   586     }
       
   587 
       
   588 // ---------------------------------------------------------------------------
       
   589 // CriticalRamMemory
       
   590 // ---------------------------------------------------------------------------
       
   591 //
       
   592 TInt CGlxAppUi::RamRequiredInBytesL(TEntryType aType)
       
   593     {
       
   594     TRACER("TInt CGlxAppUi::RamRequiredInBytesL(TEntryType aType)");
       
   595 	TSize gridIconSize = iUiUtility->GetGridIconSize();
       
   596     TInt criticalRamMemory = 0 ;
       
   597     TSize displaySize = iUiUtility->DisplaySize();
       
   598     TInt itemsInPage =  iUiUtility->VisibleItemsInPageGranularityL();
       
   599     if(EEntryTypeStartUp == aType)
       
   600         {
       
   601         // This is Bare Minimum Required Memory for Photos to start 
       
   602         // For Framework to work and to do the on-the-fly decoding 
       
   603         // for the just captured picture = KGlxMemoryForOOMFwk + KGlxMaxMemoryToDecodeCapturedPicture
       
   604         // For Grid Number of pages * Thumbnail width * Thumbnail Height * KGlxThumbNailRepresentation *
       
   605         // Number of images in a page +
       
   606         // For FullScreen to Work Number of Thumbnails * Width * Height * Representation
       
   607         criticalRamMemory =  KGlxMemoryForOOMFwk + KGlxMaxMemoryToDecodeCapturedPicture + 
       
   608                                              (KGlxFullThumbnailCount *
       
   609                                               displaySize.iWidth * displaySize.iHeight * 
       
   610                                               KGlxThumbNailRepresentation ) +
       
   611                                              (KGlxGridThumbnailPages *  
       
   612                                               itemsInPage * gridIconSize.iWidth *
       
   613                                               gridIconSize.iHeight * 
       
   614                                               KGlxThumbNailRepresentation);
       
   615         
       
   616         GLX_LOG_INFO1("CGlxAppUi::RamRequiredInBytesL(EEntryTypeStartUp): criticalRamMemory=%d",
       
   617                                                                             criticalRamMemory);
       
   618         }
       
   619     else
       
   620         {
       
   621         GLX_LOG_INFO("CGlxAppUi::RamRequiredInBytesL(): Photos Already Running");
       
   622         }
       
   623  
       
   624     return criticalRamMemory;
       
   625     }
       
   626 
       
   627 // ---------------------------------------------------------------------------
       
   628 // ReserveMemoryL
       
   629 // ---------------------------------------------------------------------------
       
   630 //
       
   631 void CGlxAppUi::ReserveMemoryL(TEntryType aType)
       
   632     {
       
   633     TRACER("TInt CGlxAppUi::ReserveMemoryL(TEntryType aType)");
       
   634     
       
   635     TInt error = ReserveMemoryL(RamRequiredInBytesL(aType));
       
   636     GLX_LOG_INFO1("CGlxAppUi::ReserveMemoryL() error=%d", error);
       
   637     
       
   638     if (KErrNoMemory == error)
       
   639         {
       
   640         GLX_LOG_INFO("CGlxAppUi::ReserveMemoryL(): LEAVE with KErrNoMemory ");
       
   641         User::Leave(KErrNoMemory);
       
   642         }
       
   643     }
       
   644 
       
   645 //OOM
       
   646 
       
   647 // ---------------------------------------------------------------------------
       
   648 // HandleApplicationSpecificEventL
       
   649 // Handle OOM events.
       
   650 // ---------------------------------------------------------------------------
       
   651 //
       
   652 
       
   653 void CGlxAppUi::HandleApplicationSpecificEventL(TInt aEventType, const TWsEvent& aWsEvent)
       
   654 {
       
   655 TRACER("CGlxAppUi::HandleApplicationSpecificEventL");
       
   656 CAknViewAppUi::HandleApplicationSpecificEventL(aEventType,aWsEvent);
       
   657 	if(aWsEvent.Type() == KAknUidValueEndKeyCloseEvent)
       
   658 		{
       
   659 		/**
       
   660 		* Making the flag etrue ensures that it will not call LaunchMmViewL in handlecommandl while 
       
   661 		* red key is pressed. Otherwise it will launch matrix menu, not idle screen. 
       
   662 		*/
       
   663 		iEndKeyPressed = ETrue;
       
   664 		ClosePhotosL();
       
   665 		}
       
   666 switch(aEventType)	
       
   667 	{
       
   668 	case KAppOomMonitor_FreeRam:
       
   669 		{
       
   670 		StartCleanupL();				
       
   671 		}
       
   672 		break;
       
   673 	case KAppOomMonitor_MemoryGood:
       
   674 		{
       
   675 		StopCleanupL();
       
   676 		}
       
   677 		break;
       
   678 	default:
       
   679 		break;
       
   680 	}
       
   681 }
       
   682 
       
   683 // ---------------------------------------------------------------------------
       
   684 // StartCleanup
       
   685 // Initiate cleanup from cache manager on low memory event
       
   686 // ---------------------------------------------------------------------------
       
   687 //
       
   688 void CGlxAppUi::StartCleanupL()
       
   689     {
       
   690     MGlxCache* cacheManager = MGlxCache::InstanceL();
       
   691     cacheManager->ReleaseRAML();
       
   692     cacheManager->Close();
       
   693     }
       
   694 
       
   695 // ---------------------------------------------------------------------------
       
   696 // StopCleanup
       
   697 // Cancel cache cleanup on memory good event
       
   698 // ---------------------------------------------------------------------------
       
   699 //
       
   700 void CGlxAppUi::StopCleanupL()
       
   701     {
       
   702     MGlxCache* cacheManager = MGlxCache::InstanceL();
       
   703     cacheManager->StopRAMReleaseL();
       
   704     cacheManager->Close();
       
   705     }
       
   706 
       
   707 // -----------------------------------------------------------------------------
       
   708 // Callback from periodic timer
       
   709 // -----------------------------------------------------------------------------
       
   710 //
       
   711 TInt CGlxAppUi::PeriodicCallback(TAny* aPtr)
       
   712     {
       
   713     TRACER("CGlxAppUi::PeriodicCallback(TAny* aPtr)");
       
   714     // get "this" pointer    
       
   715     static_cast<CGlxAppUi*>(aPtr)->PeriodicCallback();
       
   716     return KErrNone;
       
   717     }
       
   718 
       
   719 // -----------------------------------------------------------------------------
       
   720 // Callback from periodic timer, non-static
       
   721 // -----------------------------------------------------------------------------
       
   722 //
       
   723 void CGlxAppUi::PeriodicCallback()
       
   724     {
       
   725     TRACER("CGlxAppUi::PeriodicCallback()");
       
   726     TRAP_IGNORE(DoCheckForIADUpdatesL());
       
   727     iPeriodic->Cancel();
       
   728     }    
       
   729 
       
   730 // ---------------------------------------------------------------------------
       
   731 // CCGlxNsAppUi::DoCheckForIADUpdatesL()
       
   732 // Check for updates via IAD
       
   733 // ---------------------------------------------------------------------------
       
   734 // 
       
   735 void CGlxAppUi::DoCheckForIADUpdatesL()
       
   736     {
       
   737     TRACER("CGlxAppUi::DoCheckForIADUpdatesL()");
       
   738 #ifdef _DEBUG
       
   739     TTime startTime;
       
   740     GLX_LOG_INFO("CGlxAppUi::DoCheckForIADUpdatesL(+)");  
       
   741     startTime.HomeTime();
       
   742 #endif
       
   743     if ( !iIadUpdate )
       
   744         {
       
   745         iIadUpdate = CGlxIadUpdate::NewL();
       
   746         }
       
   747     iIadUpdate->StartL();
       
   748 #ifdef _DEBUG
       
   749     TTime stopTime;
       
   750     stopTime.HomeTime();
       
   751     GLX_DEBUG2("CGlxAppUi::DoCheckForIADUpdatesL(-) took <%d> us", 
       
   752                     (TInt)stopTime.MicroSecondsFrom(startTime).Int64());
       
   753 #endif    
       
   754     }
       
   755 
       
   756 // -----------------------------------------------------------------------------
       
   757 // ClosePhotosL
       
   758 // -----------------------------------------------------------------------------
       
   759 //
       
   760 void CGlxAppUi::ClosePhotosL()
       
   761     {
       
   762 	TRACER("CGlxNsAppUi::ClosePhotosL()");
       
   763 	iUiUtility->SetViewNavigationDirection(EGlxNavigationBackwards);
       
   764 	//Temparory fix provided for Kern Exec 3 bug
       
   765 	//UPnP Stop Showin is explicitly called when exiting the gallery
       
   766 	GlxUpnpRenderer:: StopShowingL();
       
   767 	iUiUtility->SetExitingState(ETrue);
       
   768     }
       
   769 //OOM