appinstaller/AppMngr2/src/appmngr2listview.cpp
changeset 80 9dcba1ee99f7
parent 77 d1838696558c
equal deleted inserted replaced
77:d1838696558c 80:9dcba1ee99f7
     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:   Base class for different AppMngr2 list views
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "appmngr2listview.h"           // CAppMngr2ListView
       
    20 #include "appmngr2listcontainer.h"      // CAppMngr2ListContainer
       
    21 #include "appmngr2appui.h"              // CAppMngr2AppUi
       
    22 #include "appmngr2model.h"              // CAppMngr2Model
       
    23 #include "appmngr2log.h"                // CAppMngr2Log
       
    24 #include "appmngr2.hrh"                 // Command IDs
       
    25 #include <appmngr2runtime.h>            // CAppMngr2Runtime
       
    26 #include <appmngr2infobase.h>           // CAppMngr2InfoBase
       
    27 #include <appmngr2cleanuputils.h>       // CleanupResetAndDestroyPushL
       
    28 #include <appmngr2debugutils.h>         // FLOG macros
       
    29 #include <appmngr2common.hrh>           // generic command ids
       
    30 #include <data_caging_path_literals.hrh> // KDC_RESOURCE_FILES_DIR
       
    31 #include <featmgr.h>                    // FeatureManager
       
    32 #include <bautils.h>                    // BaflUtils
       
    33 #include <eikenv.h>                     // CEikonEnv
       
    34 #include <aknViewAppUi.h>               // CAknViewAppUi
       
    35 #include <eikmenub.h>                   // CEikMenuBar, CEikMenuPane
       
    36 #include <eikmenup.h>                   // CEikMenuPaneItem
       
    37 #include <akntitle.h>                   // CAknTitlePane
       
    38 #include <StringLoader.h>               // StringLoader
       
    39 #include <AknInfoPopupNoteController.h> // CAknInfoPopupNoteController
       
    40 #include <appmngr2.rsg>                 // Resource IDs
       
    41 
       
    42 const TUid KStatusPaneUid = { EEikStatusPaneUidTitle };
       
    43 
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CAppMngr2ListView::ConstructL() 
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 void CAppMngr2ListView::ConstructL( TInt aResourceId )
       
    52     {
       
    53     FLOG( "CAppMngr2ListView::ConstructL( 0x%08x )", aResourceId );
       
    54     
       
    55     BaseConstructL( aResourceId );
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CAppMngr2ListView::~CAppMngr2ListView() 
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CAppMngr2ListView::~CAppMngr2ListView()
       
    63     {
       
    64     FLOG( "CAppMngr2ListView::~CAppMngr2ListView" );
       
    65     
       
    66     if( iContainer )
       
    67         {
       
    68         AppUi()->RemoveFromViewStack( *this, iContainer );
       
    69         delete iContainer;
       
    70         }
       
    71     delete iInfoPopup;
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CAppMngr2ListView::RefreshL()
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CAppMngr2ListView::RefreshL( TInt aMoreRefreshesExpected )
       
    79     {
       
    80     if( iContainer )
       
    81         {
       
    82         TBool selectedItemChanged = EFalse;
       
    83         iContainer->RefreshL( iMaintainFocus, selectedItemChanged, aMoreRefreshesExpected );
       
    84         if( selectedItemChanged )
       
    85             {
       
    86             UpdateMiddleSoftkeyCommandL();
       
    87             StopDisplayingMenuBar();
       
    88             iMaintainFocus = EFalse;
       
    89             }
       
    90 
       
    91         // Close progress note used in application startup
       
    92         if( iInfoPopup && !aMoreRefreshesExpected )
       
    93             {
       
    94             iInfoPopup->HideInfoPopupNote();
       
    95             delete iInfoPopup;
       
    96             iInfoPopup = NULL;
       
    97             }
       
    98         }
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CAppMngr2ListView::UpdateMiddleSoftkeyCommandL()
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CAppMngr2ListView::UpdateMiddleSoftkeyCommandL()
       
   106     {
       
   107     FLOG_PERF_STATIC_BEGIN( UpdateMiddleSoftkeyCommandL );
       
   108     
       
   109     if( iContainer && !iContainer->IsListEmpty() )
       
   110         {
       
   111         // add item-specific MSK if the current item has one
       
   112         CAppMngr2InfoBase& currentItem = iContainer->CurrentItem();
       
   113         TInt resourceId = 0;
       
   114         TInt commandId = 0;
       
   115         currentItem.GetMiddleSoftkeyCommandL( resourceId, commandId );
       
   116         if( resourceId && commandId )
       
   117             {
       
   118             SetMiddleSoftkeyCommandL( resourceId, commandId );
       
   119             }
       
   120         else
       
   121             {
       
   122             SetDefaultMiddleSoftkeyCommandL();
       
   123             }
       
   124         }
       
   125     else
       
   126         {
       
   127         // list is empty, remove old MSK if it has been added and set the default
       
   128         CEikButtonGroupContainer* cba = Cba();
       
   129         if( iMiddleSoftkeyCommandId && cba )
       
   130             {
       
   131             cba->RemoveCommandFromStack( CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   132                     iMiddleSoftkeyCommandId );
       
   133             }
       
   134         SetDefaultMiddleSoftkeyCommandL();
       
   135         }
       
   136     
       
   137     FLOG_PERF_STATIC_END( UpdateMiddleSoftkeyCommandL )
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // CAppMngr2ListView::CurrentItemSelectedByUser()
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CAppMngr2ListView::CurrentItemSelectedByUser( TBool aMaintainFocus )
       
   145     {
       
   146     iMaintainFocus = aMaintainFocus;
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CAppMngr2ListView::HandleViewRectChange()
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CAppMngr2ListView::HandleViewRectChange()
       
   154     {
       
   155     if( iContainer )
       
   156         {
       
   157         iContainer->SetRect( ClientRect() );
       
   158         }
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CAppMngr2ListView::HandleCommandL()
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 void CAppMngr2ListView::HandleCommandL( TInt aCommand )
       
   166     {
       
   167     FLOG( "CAppMngr2ListView::HandleCommandL( %d )", aCommand );
       
   168     
       
   169     switch( aCommand )
       
   170         {
       
   171         case EAknSoftkeyBack:
       
   172             AppUi()->HandleCommandL( EAknSoftkeyExit );
       
   173             break;
       
   174 
       
   175         case EAppMngr2CmdLog:
       
   176             {
       
   177             CAppMngr2Log* log = CAppMngr2Log::NewLC();
       
   178             log->ShowInstallationLogL();
       
   179             CleanupStack::PopAndDestroy( log );
       
   180             }
       
   181             break;
       
   182 
       
   183         case EAknCmdHelp:
       
   184         case EAknCmdExit:
       
   185             AppUi()->HandleCommandL( aCommand );
       
   186             break;
       
   187 
       
   188         default:
       
   189             Model().HandleCommandL( iContainer->CurrentItem(), aCommand );
       
   190             break;
       
   191         }
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CAppMngr2ListView::DynInitMenuPaneL()
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CAppMngr2ListView::DynInitMenuPaneL( TInt aResourceId,
       
   199         CEikMenuPane* aMenuPane )
       
   200     {
       
   201     if( aResourceId == R_APPMNGR2_INSTALLED_MENU
       
   202             || aResourceId == R_APPMNGR2_PACKAGES_MENU )
       
   203         {
       
   204         if( !FeatureManager::FeatureSupported( KFeatureIdHelp ) ) 
       
   205             {
       
   206             aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   207             }
       
   208 
       
   209         // Keep the currently selected item focused in forthcoming list refreshes. 
       
   210         iMaintainFocus = ETrue;
       
   211         }
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // CAppMngr2ListView::DoActivateL()
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CAppMngr2ListView::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
       
   219         TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/ )
       
   220     {
       
   221     FLOG( "CAppMngr2ListView::DoActivateL, id 0x%08x", Id().iUid );
       
   222     
       
   223     CAknTitlePane* titlePane = NULL;
       
   224     titlePane = static_cast<CAknTitlePane*>( StatusPane()->ControlL( KStatusPaneUid ) );
       
   225     SetTitleL( *titlePane );
       
   226     
       
   227     if( iContainer == NULL )
       
   228         {
       
   229         iContainer = CreateContainerL();
       
   230         iContainer->SetMopParent( this );
       
   231         AppUi()->AddToViewStackL( *this, iContainer );
       
   232         iContainer->ActivateL();
       
   233         }
       
   234     UpdateMiddleSoftkeyCommandL();
       
   235 
       
   236     if( iInfoPopup == NULL )
       
   237         {
       
   238         iInfoPopup = CAknInfoPopupNoteController::NewL();
       
   239         iInfoPopup->SetTimePopupInView( 0 );
       
   240         iInfoPopup->HideWhenAppFaded( EFalse );
       
   241         HBufC* noteText = StringLoader::LoadLC( R_QTN_AM_SCANNING_MEMORY );
       
   242         iInfoPopup->SetTextL( *noteText );
       
   243         CleanupStack::PopAndDestroy( noteText );
       
   244         iInfoPopup->ShowInfoPopupNote();
       
   245         }
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CAppMngr2ListView::DoDeactivate()
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 void CAppMngr2ListView::DoDeactivate()
       
   253     {
       
   254     FLOG( "CAppMngr2ListView::DoDeactivate, id 0x%08x", Id().iUid );
       
   255     
       
   256     if( iContainer )
       
   257         {
       
   258         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   259         delete iContainer;
       
   260         iContainer = NULL;
       
   261         }
       
   262     if( iInfoPopup )
       
   263         {
       
   264         delete iInfoPopup;
       
   265         iInfoPopup = NULL;
       
   266         }
       
   267     }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // CAppMngr2ListView::Model()
       
   271 // ---------------------------------------------------------------------------
       
   272 //
       
   273 CAppMngr2Model& CAppMngr2ListView::Model() const
       
   274     {
       
   275     return reinterpret_cast<CAppMngr2AppUi*>( iEikonEnv->EikAppUi() )->Model();
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CAppMngr2ListView::AddDynamicMenuItemsL()
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 void CAppMngr2ListView::AddDynamicMenuItemsL( CAppMngr2InfoBase& aCurrentItem,
       
   283         CEikMenuPane* aMenuPane )
       
   284     {
       
   285     if( aMenuPane )
       
   286         {
       
   287         FLOG_PERF_STATIC_BEGIN( AddDynamicMenuItemsL );
       
   288         
       
   289         TInt position = 0;
       
   290         if( aMenuPane->MenuItemExists( EAppMngr2PlaceForPluginSpecificCmds, position ) )
       
   291             {
       
   292             aMenuPane->DeleteMenuItem( EAppMngr2PlaceForPluginSpecificCmds );
       
   293     
       
   294             RPointerArray<CEikMenuPaneItem::SData> menuItems;
       
   295             CleanupResetAndDestroyPushL( menuItems );
       
   296 
       
   297             TRAPD( err, aCurrentItem.GetMenuItemsL( menuItems ) );
       
   298             if( !err )
       
   299                 {
       
   300                 TInt count = menuItems.Count();
       
   301                 for( TInt index = 0; index < count; index++ )
       
   302                     {
       
   303                     aMenuPane->InsertMenuItemL( *( menuItems[ index ] ), position++ );
       
   304                     aMenuPane->SetItemSpecific( menuItems[ index ]->iCommandId, ETrue );
       
   305                     }
       
   306                 }
       
   307 
       
   308             CleanupStack::PopAndDestroy( &menuItems );
       
   309             }
       
   310         
       
   311         FLOG_PERF_STATIC_END( AddDynamicMenuItemsL )
       
   312         }
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // CAppMngr2ListView::SetMiddleSoftkeyCommandL()
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 void CAppMngr2ListView::SetMiddleSoftkeyCommandL( TInt aResourceId, TInt aCommandId )
       
   320     {
       
   321     CEikButtonGroupContainer* cba = Cba();
       
   322     if( cba )
       
   323         {
       
   324         // remove old command from the stack if it is already added
       
   325         if( iMiddleSoftkeyCommandId )
       
   326             {
       
   327             cba->RemoveCommandFromStack( CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   328                     iMiddleSoftkeyCommandId );
       
   329             }
       
   330         HBufC* middleSoftkeyLabel = StringLoader::LoadLC( aResourceId );
       
   331         cba->AddCommandToStackL( CEikButtonGroupContainer::EMiddleSoftkeyPosition, 
       
   332                 aCommandId, *middleSoftkeyLabel );
       
   333         CleanupStack::PopAndDestroy( middleSoftkeyLabel );
       
   334         iMiddleSoftkeyCommandId = aCommandId;
       
   335         }
       
   336     }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // CAppMngr2ListView::CAppMngr2ListView()
       
   340 // ---------------------------------------------------------------------------
       
   341 //
       
   342 CAppMngr2ListView::CAppMngr2ListView()
       
   343     {
       
   344     }
       
   345