omadm/omadmappui/src/NSmlDMFotaView.cpp
changeset 0 3ce708148e4d
child 8 0a8136f75056
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Methods for the firmware update view 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <AknIconArray.h>
       
    22 #include <AknQueryDialog.h>
       
    23 #include <AknsUtils.h>
       
    24 #include <featmgr.h>
       
    25 #include <StringLoader.h>
       
    26 #include <data_caging_path_literals.hrh>
       
    27 #include <centralrepository.h>
       
    28 #include <SyncMLNotifierDomainCRKeys.h>
       
    29 
       
    30 #include <e32property.h> 
       
    31 #include "NSmlDMSyncApp.h"
       
    32 #include "nsmldmsyncinternalpskeys.h"
       
    33 
       
    34 #include "NSmlDMSyncPrivateCRKeys.h"
       
    35 
       
    36 #include "NSmlDMSyncDocument.h"
       
    37 #include "NSmlDMSyncAppUi.h"
       
    38 #include "NSmlDMFotaModel.h"
       
    39 #include "NSmlDMFotaView.h"
       
    40 #include "NSmlDMFotaContainer.h"
       
    41 #include "NSmlDMFotaSettingsDialog.h"
       
    42 #include "NSmlDMdef.h"
       
    43 
       
    44 #include "NSmlDMSyncUi.hrh"
       
    45 #include <NSmlDMSync.rsg>
       
    46 #include <nsmldmsync.mbg>
       
    47 #include "NSmlDMSyncDebug.h"
       
    48 
       
    49 // ============================ MEMBER FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CNSmlDMFotaView::ConstructL
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CNSmlDMFotaView::ConstructL()
       
    57     {
       
    58     FLOG( "[OMADM]\t CNSmlDMFotaView::ConstructL()" );
       
    59     CNSmlDMSyncDocument* doc = ( CNSmlDMSyncDocument* ) AppUi()->Document();
       
    60     if( doc->IsServerAlertSync() ) //For embedded application opening
       
    61        {       	      
       
    62        BaseConstructL( R_CP_SMLSYNC_FOTA_VIEW );
       
    63        }
       
    64     else     //Independent application opening
       
    65        {
       
    66        BaseConstructL( R_SMLSYNC_FOTA_VIEW );	
       
    67        }       
       
    68     iExitPress = -1;
       
    69     FeatureManager::InitializeLibL();
       
    70     iFotaDLObserver = new (ELeave) CDLObserver;
       
    71     iFotaDLObserver->ConstructL(this);
       
    72     iFotaDLObserver->StartL(EFalse);
       
    73     FLOG( "[OMADM]\t CNSmlDMFotaView::ConstructL() completed" );
       
    74     }
       
    75 
       
    76 // Destructor
       
    77 CNSmlDMFotaView::~CNSmlDMFotaView()
       
    78     {
       
    79     FLOG( "[OMADM]\t CNSmlDMFotaView::~CNSmlDMFotaView()" );
       
    80    
       
    81     if(iFotaDLObserver)
       
    82     	{
       
    83     	iFotaDLObserver->Cancel();
       
    84     	delete iFotaDLObserver;
       
    85     	iFotaDLObserver = NULL;
       
    86     	}    
       
    87     
       
    88     if ( iContainer )
       
    89         {
       
    90         AppUi()->RemoveFromStack( iContainer );
       
    91         }
       
    92     delete iContainer;
       
    93      FeatureManager::UnInitializeLib();
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CNSmlDMFotaView::Id
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 TUid CNSmlDMFotaView::Id() const
       
   101     {
       
   102     FLOG( "[OMADM]\t CNSmlDMFotaView::Id()" );
       
   103     return KNSmlDMFotaViewId;
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CNSmlDMFotaView::HandleCommandL
       
   108 // Redirects commands to the appui class.
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void CNSmlDMFotaView::HandleCommandL( TInt aCommand )
       
   112     {
       
   113     FTRACE( FPrint( _L("[OMADM]\t CNSmlDMFotaView::HandleCommandL(), aCommand = 0x%x"),
       
   114         aCommand ) );
       
   115 
       
   116     switch ( aCommand )
       
   117         {
       
   118         case EAknSoftkeyBack:
       
   119             {
       
   120             UpdateExitL();
       
   121             TInt value=-1;
       
   122             TInt r1=RProperty::Set(KPSUidNSmlDMSyncApp,KNSmlDMSyncUiLaunchKey,value);
       
   123             AppUi()->HandleCommandL( EEikCmdExit );
       
   124             break;
       
   125             }
       
   126         /*case EAknCmdExit: 
       
   127         case EEikCmdExit:
       
   128             {
       
   129             STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi() )->CloseGs(); //control panel            
       
   130             break;
       
   131             }*/
       
   132 
       
   133         case ENSmlMenuCmdFotaCheck:
       
   134             {
       
   135             InitiateFotaCheckL();
       
   136             break;
       
   137             }
       
   138         case ENSmlMenuCmdFotaInstall:
       
   139             {
       
   140             InitiateFwUpdInstallL();
       
   141             break;
       
   142             }
       
   143         case ENSmlMenuCmdFotaContinue:
       
   144             {
       
   145             RefreshL(EFalse);
       
   146             InitiateFwUpdContinueL();
       
   147             break;
       
   148             }
       
   149         case ENSmlMenuCmdFotaSettings:
       
   150             {
       
   151             TInt value = ETrue;                 //IAD: Making DM busy
       
   152             TInt r1=RProperty::Set(KPSUidNSmlDMSyncApp,KDMIdle,value);	
       
   153             CNSmlDMFotaSettingsDialog* settingDialog = CNSmlDMFotaSettingsDialog::NewL();
       
   154             settingDialog->ExecuteLD( R_NSML_FOTA_SETTINGS_DIALOG );
       
   155             break;
       
   156             }
       
   157  
       
   158         case ENSmlMenuCmdFotaServers:
       
   159             {
       
   160             TInt value = ETrue;    //IAD: Making DM busy
       
   161             TInt r1=RProperty::Set(KPSUidNSmlDMSyncApp,KDMIdle,value);	
       
   162              AppUi()->ActivateLocalViewL( KNSmlDMProfilesViewId );
       
   163              break;
       
   164             }    
       
   165  
       
   166         case EEikCmdExit:
       
   167         case EAknCmdExit:
       
   168             {
       
   169             UpdateExitL();	
       
   170             STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi() )->CloseGs(); //control panel            
       
   171             break;
       
   172             }
       
   173         default:
       
   174             {
       
   175             UpdateExitL();	
       
   176             AppUi()->HandleCommandL( aCommand );
       
   177             break;
       
   178             }
       
   179         }
       
   180         
       
   181     FLOG( "[OMADM]\t CNSmlDMFotaView::HandleCommandL() completed" );
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CNSmlDMFotaView::StepL
       
   186 // Does nothing.
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void CNSmlDMFotaView::StepL()
       
   190     {
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CNSmlDMFotaView::IsProcessDone
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 TBool CNSmlDMFotaView::IsProcessDone() const
       
   198     {
       
   199     return ETrue;
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CNSmlDMFotaView::InitiateFotaCheckL
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CNSmlDMFotaView::InitiateFotaCheckL()
       
   207     {
       
   208     FLOG( "[OMADM]\t CNSmlDMFotaView::InitiateFotaCheck()" );
       
   209     TInt profileId( KErrNotFound );
       
   210     TBool isValidId( EFalse );
       
   211     HBufC* stringHolder = NULL;
       
   212 
       
   213     profileId = iFotaModel->DefaultFotaProfileIdL();
       
   214 
       
   215     if ( profileId >= KErrNone )
       
   216         {
       
   217          isValidId = iFotaModel->VerifyProfileL( profileId );
       
   218         }
       
   219 
       
   220     if( ( profileId == KErrNotFound ) || ( !isValidId ) )
       
   221         {
       
   222     	profileId = ShowFotaProfileQueryL();
       
   223     	if( profileId == KErrNotFound )    
       
   224     	  return;
       
   225         }
       
   226     TInt query(EFalse);
       
   227     CRepository* cRepository=NULL;
       
   228 	TRAPD ( error, cRepository = CRepository::NewL ( KCRUidNSmlNotifierDomainKeys ) );
       
   229 	if ( error == KErrNone )
       
   230 	{
       
   231 		CleanupStack::PushL( cRepository );
       
   232 		TInt dmChargingNote(1);
       
   233 		cRepository->Get ( KNSmlDMChargingNote, dmChargingNote );
       
   234 		if(dmChargingNote==1)
       
   235 		{      
       
   236     	CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   237     	CleanupStack::PushL( dlg );
       
   238     	stringHolder = StringLoader::LoadLC( R_QTN_FOTA_CONNECTION_NEEDED );
       
   239     	dlg->SetPromptL( stringHolder->Des() );
       
   240     
       
   241     CleanupStack::PopAndDestroy( stringHolder );
       
   242     stringHolder = NULL;
       
   243     
       
   244     	CleanupStack::Pop( dlg );
       
   245     
       
   246     	query = dlg->ExecuteLD( R_SML_CONFIRMATION_QUERY );
       
   247   		}
       
   248   		else
       
   249   			query = ETrue;
       
   250   		CleanupStack::PopAndDestroy( cRepository );//cRepository
       
   251   	}
       
   252     if(query)
       
   253     {
       
   254         __ASSERT_ALWAYS( iFotaModel, TUtil::Panic( KErrGeneral ) );
       
   255         
       
   256         iFotaModel->EnableFwUpdRequestL( profileId );
       
   257         ( ( CNSmlDMSyncAppUi* ) AppUi() )->StartSyncL( profileId, ETrue );
       
   258     	iFotaDLObserver->StartL(ETrue);
       
   259         }
       
   260     
       
   261     FLOG( "[OMADM]\t CNSmlDMFotaView::InitiateFotaCheck() completed" );
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CNSmlDMFotaView::ShowFotaProfileQueryL
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 TInt CNSmlDMFotaView::ShowFotaProfileQueryL()
       
   269     {
       
   270     FLOG( "[OMADM] CNSmlDMFotaView::ShowFotaProfileQueryL()" );
       
   271 
       
   272     TInt retval( KErrNotFound );
       
   273 
       
   274     CDesCArray* items = new (ELeave) CDesCArrayFlat( KNSmlDefaultGranularity );
       
   275     CleanupStack::PushL( items );
       
   276     items->Reset();
       
   277 
       
   278     // Profile list owned by the dialog
       
   279     CArrayFixFlat<TInt>* profileIdList =
       
   280         new ( ELeave ) CArrayFixFlat<TInt>( KNSmlDefaultGranularity );
       
   281     CleanupStack::PushL( profileIdList );
       
   282 
       
   283     FormatProfileQueryListItemsL( items, profileIdList );
       
   284 
       
   285     if ( items->Count() > 1 )
       
   286         {
       
   287     	CEikFormattedCellListBox* listBox = new ( ELeave )
       
   288     	    CAknDoubleLargeGraphicPopupMenuStyleListBox;
       
   289     	CleanupStack::PushL( listBox );
       
   290 
       
   291     	CAknPopupList* popupList = CAknPopupList::NewL( listBox, 
       
   292     							   R_AVKON_SOFTKEYS_OK_CANCEL__OK,
       
   293             				 AknPopupLayouts::EMenuDoubleLargeGraphicWindow );
       
   294     	CleanupStack::PushL( popupList );
       
   295 
       
   296     	listBox->ConstructL( popupList, ( EAknListBoxSelectionList | EAknListBoxLoopScrolling ) );
       
   297     	listBox->Model()->SetItemTextArray( items );
       
   298     	listBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   299         listBox->HandleItemAdditionL();
       
   300     	
       
   301         listBox->CreateScrollBarFrameL( ETrue );
       
   302         listBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   303             CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   304 
       
   305     	CAknIconArray* icons = new (ELeave) CAknIconArray( 10 );
       
   306     	CleanupStack::PushL( icons );
       
   307         CreateIconArrayL( icons );
       
   308     	listBox->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
       
   309     	CleanupStack::Pop( icons );
       
   310 
       
   311         HBufC* popupTitle = iCoeEnv->AllocReadResourceLC(
       
   312             R_QTN_FOTA_LIST_QUERY_SELECT_SERVER_PROFILE );
       
   313         popupList->SetTitleL( popupTitle->Des() );
       
   314         CleanupStack::PopAndDestroy( popupTitle );
       
   315         popupTitle = NULL;
       
   316 
       
   317         CleanupStack::Pop( popupList );
       
   318         TBool queryResult = popupList->ExecuteLD();
       
   319         popupList = NULL;
       
   320 
       
   321         if ( queryResult )
       
   322             {
       
   323             retval = profileIdList->At( listBox->CurrentItemIndex() );
       
   324             }
       
   325         CleanupStack::PopAndDestroy( listBox );  // Destroys also the icon array
       
   326         }
       
   327     else if ( items->Count() == 1 )
       
   328         {
       
   329         retval = profileIdList->At(0);
       
   330         }
       
   331     else
       
   332         {
       
   333         
       
   334         TInt ServersViewVariable( 0 );
       
   335         CRepository* centrep = NULL;
       
   336         TRAPD( err, centrep = CRepository::NewL( KCRUidNSmlDMSyncApp ) );
       
   337         if ( centrep )
       
   338             {
       
   339             centrep->Get( KNSmlDMServersMenuKey, ServersViewVariable );         
       
   340             delete centrep;
       
   341             }
       
   342         if ( err != KErrNone ) 
       
   343             {
       
   344             User::Leave( err );
       
   345             }    
       
   346         if( ServersViewVariable == 0)   
       
   347             {
       
   348             CleanupStack::PopAndDestroy( profileIdList );
       
   349             CleanupStack::PopAndDestroy( items );
       
   350          	return KErrNotFound;
       
   351             }
       
   352         
       
   353         
       
   354 		HBufC* newProfileString = 
       
   355 		            iEikonEnv->AllocReadResourceLC( R_SML_APPUI_NOTE_TEXT_NEW );
       
   356 
       
   357 		CAknQueryDialog* newProfileDialog = new ( ELeave ) CAknQueryDialog;
       
   358 
       
   359 		if ( newProfileDialog->ExecuteLD( R_SML_CONFIRMATION_QUERY,
       
   360 		                                  newProfileString->Des() ) )
       
   361 			{	
       
   362 			
       
   363 			TInt viewtitle = 1;
       
   364 			( (CNSmlDMSyncAppUi*) AppUi() )->
       
   365 			                         SetTitleCall( viewtitle );	
       
   366 			                       
       
   367 			( (CNSmlDMSyncAppUi*) AppUi() )->
       
   368 			    ShowEditProfileDialogL( ESmlNewProfile );
       
   369 			}
       
   370 		newProfileDialog = NULL;
       
   371 		CleanupStack::PopAndDestroy( newProfileString );
       
   372 		
       
   373         }
       
   374 
       
   375     CleanupStack::PopAndDestroy( profileIdList );
       
   376     CleanupStack::PopAndDestroy( items );
       
   377 
       
   378     FTRACE( FPrint(
       
   379         _L("[OMADM]\t CNSmlDMFotaView::ShowFotaProfileQueryL() completed, retval = %d"),
       
   380         retval ) );
       
   381     return retval;
       
   382     }
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // CNSmlDMFotaView::FormatProfileQueryListItemsL
       
   386 // -----------------------------------------------------------------------------
       
   387 //
       
   388 void CNSmlDMFotaView::FormatProfileQueryListItemsL( CDesCArray*          aItems,
       
   389                                                     CArrayFixFlat<TInt>* aProfileIdList )
       
   390     {
       
   391     FLOG( "[OMADM] CNSmlDMFotaView::FormatProfileQueryListItemsL()" );
       
   392     TInt index( 0 );
       
   393     
       
   394     CNSmlDMSyncDocument* doc = ( CNSmlDMSyncDocument* ) AppUi()->Document();
       
   395     
       
   396     doc->RefreshProfileListL( ETrue ); // Include hidden profile
       
   397     CArrayFixFlat<TNSmlDMProfileItem>* profileList = doc->ProfileList( index );
       
   398 
       
   399     TBuf<KNSmlMaxTextLength256> text;
       
   400 
       
   401     for ( index = 0; index < profileList->Count(); index++ )
       
   402         {
       
   403         text.Zero();
       
   404         TInt iconIndex( EProfileInternet ); //internet
       
   405 
       
   406         if ( ( *profileList )[index].iBearer != EProfileInternet )
       
   407             {
       
   408             iconIndex = EProfileObexBlueTooth;	
       
   409             }
       
   410         text.Num( iconIndex );
       
   411         text.Append( KNSmlTab );
       
   412         text.Append( ( *profileList )[index].iProfileName );
       
   413         text.Append( KNSmlTab );
       
   414         
       
   415         aItems->AppendL( text );
       
   416         aProfileIdList->AppendL( ( *profileList )[index].iProfileId );
       
   417         }
       
   418     FLOG( "[OMADM] CNSmlDMFotaView::FormatProfileQueryListItemsL() completed" );
       
   419     }
       
   420 
       
   421 // -----------------------------------------------------------------------------
       
   422 // CNSmlDMFotaView::CreateIconArrayL
       
   423 // -----------------------------------------------------------------------------
       
   424 //
       
   425 void CNSmlDMFotaView::CreateIconArrayL( CAknIconArray* aIconArray )
       
   426     {
       
   427     FLOG( "[OMADM] CNSmlDMFotaView::CreateIconArrayL()" );
       
   428 
       
   429     HBufC* appIconFilePath = HBufC::NewLC( 5 + KDC_APP_BITMAP_DIR().Length() 
       
   430                                              + KDMAppIconFileName().Length() );
       
   431     TPtr ptr = appIconFilePath->Des();
       
   432     ptr.Append( KZDrive );
       
   433     ptr.Append( KDC_APP_BITMAP_DIR );
       
   434     ptr.Append( KDMAppIconFileName );
       
   435 
       
   436 	aIconArray->AppendL( AknsUtils::CreateGulIconL( 
       
   437 	                             AknsUtils::SkinInstance(),
       
   438 	                             KAknsIIDQgnPropSmlHttp,
       
   439 	                             *appIconFilePath,
       
   440 	                             EMbmNsmldmsyncQgn_prop_sml_http,
       
   441 	                             EMbmNsmldmsyncQgn_prop_sml_http_mask ) );
       
   442 	                             
       
   443 	aIconArray->AppendL( AknsUtils::CreateGulIconL( 
       
   444 	                          AknsUtils::SkinInstance(),
       
   445 	                          KAknsIIDQgnPropSmlHttpOff,
       
   446 	                          *appIconFilePath,
       
   447 	                          EMbmNsmldmsyncQgn_prop_sml_http_off,
       
   448 	                          EMbmNsmldmsyncQgn_prop_sml_http_off_mask ) );
       
   449 
       
   450 	if ( FeatureManager::FeatureSupported( KFeatureIdSyncMlDmObex ) )
       
   451 		{
       
   452 		aIconArray->AppendL( AknsUtils::CreateGulIconL( 
       
   453 		                            AknsUtils::SkinInstance(),
       
   454 		                            KAknsIIDQgnPropSmlBt,
       
   455 		                            *appIconFilePath,
       
   456 		                            EMbmNsmldmsyncQgn_prop_sml_bt,
       
   457 		                            EMbmNsmldmsyncQgn_prop_sml_bt_mask ) );
       
   458 		                            
       
   459 		aIconArray->AppendL( AknsUtils::CreateGulIconL(
       
   460 		                        AknsUtils::SkinInstance(),
       
   461 		                        KAknsIIDQgnPropSmlBtOff,
       
   462 		                        *appIconFilePath,
       
   463 		                        EMbmNsmldmsyncQgn_prop_sml_bt_off,
       
   464 		                        EMbmNsmldmsyncQgn_prop_sml_bt_off_mask ) );
       
   465 		}
       
   466 	
       
   467     CleanupStack::PopAndDestroy( appIconFilePath );
       
   468 
       
   469     FLOG( "[OMADM] CNSmlDMFotaView::CreateIconArrayL() completed" );
       
   470     }
       
   471     
       
   472 // -----------------------------------------------------------------------------
       
   473 // CNSmlDMFotaView::InitiateFwUpdInstallL
       
   474 // -----------------------------------------------------------------------------
       
   475 //
       
   476 void CNSmlDMFotaView::InitiateFwUpdInstallL()
       
   477     {
       
   478     FLOG( "[OMADM]\t CNSmlDMFotaView::InitiateFwUpdInstallL()" );
       
   479     
       
   480     TInt pkgId = iFotaModel->RetrieveFwUpdPkgIdListL(
       
   481         EStartingUpdate );
       
   482     
       
   483     if ( pkgId != KErrNotFound )
       
   484         {
       
   485         TInt retval = iFotaModel->InitiateFwUpdInstall( pkgId, KErrNotFound );
       
   486 
       
   487         // No profile id was stored in the fota engine. Trying to select a suitable
       
   488         // profile, or asking user.
       
   489         if ( retval == KErrNotFound )
       
   490             {
       
   491             TBool isValidId( EFalse );
       
   492             TInt profileId = iFotaModel->DefaultFotaProfileIdL();
       
   493 
       
   494             if ( profileId >= KErrNone )
       
   495                 {
       
   496                  isValidId = iFotaModel->VerifyProfileL( profileId );
       
   497                 }
       
   498 
       
   499             if( ( profileId == KErrNotFound ) || ( !isValidId ) )
       
   500                 {
       
   501             	profileId = ShowFotaProfileQueryL();
       
   502                 }
       
   503             
       
   504             // Retrying the update with the chosen profile id.
       
   505             iFotaModel->InitiateFwUpdInstall( pkgId, profileId );
       
   506             }
       
   507         
       
   508         }
       
   509 
       
   510     FLOG( "[OMADM]\t CNSmlDMFotaView::InitiateFwUpdInstallL() completed" );
       
   511     }
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // CNSmlDMFotaView::InitiateFwUpdContinueL
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 void CNSmlDMFotaView::InitiateFwUpdContinueL()
       
   518     {
       
   519     FLOG( "[OMADM]\t CNSmlDMFotaView::InitiateFwUpdContinueL()" );    
       
   520     iFotaDLObserver->StartL(ETrue);
       
   521     iFotaModel->ContinueFwUpdInstall();
       
   522     FLOG( "[OMADM]\t CNSmlDMFotaView::InitiateFwUpdContinueL() completed" );
       
   523     }
       
   524         
       
   525 // -----------------------------------------------------------------------------
       
   526 // CNSmlDMFotaView::DoActivateL
       
   527 // -----------------------------------------------------------------------------
       
   528 //
       
   529 void CNSmlDMFotaView::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
       
   530                                          TUid /*aCustomMessageId*/,
       
   531                                    const TDesC8& /*aCustomMessage*/ )
       
   532     {
       
   533     FLOG( "[OMADM]\t CNSmlDMFotaView::DoActivateL()" );
       
   534 
       
   535     CNSmlDMSyncDocument* doc = ( CNSmlDMSyncDocument* ) AppUi()->Document();
       
   536     __ASSERT_ALWAYS( doc, TUtil::Panic( KErrGeneral ) );
       
   537     
       
   538     	MenuBar()->SetContextMenuTitleResourceId( 
       
   539     	                              R_SMLSYNC_CONTXT_MENUBAR_FOTA_VIEW );
       
   540     
       
   541     //MANUAL CHECK
       
   542     if( !ManualCheckAllowedL() )
       
   543        {    	    
       
   544     Cba()->MakeCommandVisible(EAknSoftkeyContextOptions,EFalse);
       
   545     Cba()->DrawDeferred();    
       
   546        }
       
   547     iFotaModel = doc->FotaModel();
       
   548     iContainer = CNSmlDMFotaContainer::NewL( this, ClientRect(), iFotaModel );
       
   549     AppUi()->AddToStackL( *this, iContainer );
       
   550 
       
   551 
       
   552 	CAknTitlePane* titlePane = 
       
   553 	    (CAknTitlePane*)(AppUi()->StatusPane())->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) );
       
   554     HBufC* titleText = iEikonEnv->AllocReadResourceLC( R_CP_APP_TITLE );	
       
   555 	titlePane->SetTextL( titleText->Des() );
       
   556 	CleanupStack::PopAndDestroy(titleText);	
       
   557     
       
   558     FLOG( "[OMADM]\t CNSmlDMFotaView::DoActivateL() completed" );
       
   559     }
       
   560 
       
   561 // -----------------------------------------------------------------------------
       
   562 // CNSmlDMFotaView::DoDeactivate
       
   563 // -----------------------------------------------------------------------------
       
   564 //
       
   565 void CNSmlDMFotaView::DoDeactivate()
       
   566     {
       
   567     FLOG( "[OMADM]\t CNSmlDMFotaView::DoDeactivate()" );
       
   568 
       
   569     if ( iContainer )
       
   570         {
       
   571         AppUi()->RemoveFromStack( iContainer );
       
   572         }
       
   573 
       
   574     delete iContainer;
       
   575     iContainer = NULL;
       
   576 
       
   577     FLOG( "[OMADM]\t CNSmlDMFotaView::DoDeactivate() completed" );
       
   578     }
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 // CNSmlDMFotaView::DynInitMenuPaneL
       
   582 // -----------------------------------------------------------------------------
       
   583 //
       
   584 void CNSmlDMFotaView::DynInitMenuPaneL( TInt aResourceId,
       
   585                                         CEikMenuPane* aMenuPane )
       
   586 	{
       
   587 	FLOG( "[OMADM] CNSmlDMFotaView::DynInitMenuPaneL()" );
       
   588      
       
   589     if ( aResourceId == R_SMLSYNC_MENU_COMMON && 
       
   590                     ! FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   591       {   
       
   592           aMenuPane->SetItemDimmed( EAknCmdHelp , ETrue );
       
   593           
       
   594       }        
       
   595     if ( aResourceId == R_SMLSYNC_MENU_FOTA_VIEW 
       
   596         || aResourceId == R_SMLSYNC_CONTXT_MENU_FOTA_VIEW )
       
   597         {
       
   598         __ASSERT_ALWAYS( iFotaModel, TUtil::Panic( KErrGeneral ) );
       
   599           
       
   600         // Set all variated items first dimmed and show them according to the
       
   601         // configuration flags.
       
   602   
       
   603         aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaCheck, ETrue );
       
   604         aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaInstall, ETrue );
       
   605         aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaContinue, ETrue );
       
   606         TInt configFlags( 0 );
       
   607         
       
   608         TInt ServersViewVariable( 0 ),SettingsVariable(0);
       
   609         
       
   610         CRepository* centrep = NULL;
       
   611         TRAPD( err, centrep = CRepository::NewL( KCRUidNSmlDMSyncApp ) );
       
   612         FTRACE( FPrint(
       
   613             _L("[OMADM]\t CNSmlDMFotaView::DynInitMenuPaneL() centrep open returned %d"),
       
   614             err ) );
       
   615 
       
   616         if ( centrep )
       
   617             {
       
   618             centrep->Get( KNSmlDMFotaConfigurationKey, configFlags );
       
   619             centrep->Get( KNSmlDMServersMenuKey, ServersViewVariable );
       
   620             centrep->Get( KNSmlDMSettingsMenuKey, SettingsVariable );
       
   621             delete centrep;
       
   622             }
       
   623 
       
   624         // If there was problems with the centrep key, the context menu will
       
   625         // be empty. However, the framework does not handle the situation correctly
       
   626         // and we'll have to leave here in order not to break things.
       
   627         // The Options menu shows at least the Exit item and can be shown.
       
   628         if ( err != KErrNone && aResourceId == R_SMLSYNC_CONTXT_MENU_FOTA_VIEW ) 
       
   629             {
       
   630             User::Leave( err );
       
   631             }
       
   632       
       
   633       if( aResourceId == R_SMLSYNC_MENU_FOTA_VIEW )
       
   634       {      	
       
   635       if(SettingsVariable )
       
   636         {
       
   637         aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaSettings, EFalse );
       
   638         }
       
   639       else
       
   640         {
       
   641         aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaSettings, ETrue );	
       
   642         }      
       
   643       }
       
   644            
       
   645         // if ( configFlags & KNSmlDMFotaEnableManualCheckFlag )
       
   646       if ( ManualCheckAllowedL() )
       
   647             {
       
   648             aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaCheck, EFalse );
       
   649             }
       
   650       if( FeatureManager::FeatureSupported( KFeatureIdSyncMlDmFota ) ) //NFUI
       
   651       {
       
   652         if ( iFotaModel->FindFwUpdPkgWithStateL(
       
   653             EDownloadProgressingWithResume ) != KErrNotFound )
       
   654             {
       
   655             aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaInstall, ETrue );          
       
   656             aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaCheck, ETrue );
       
   657             aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaContinue, EFalse );          
       
   658             }
       
   659         else if ( iFotaModel->FindFwUpdPkgWithStateL(
       
   660             EStartingUpdate ) != KErrNotFound )
       
   661             {
       
   662             aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaInstall, EFalse );          
       
   663             aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaCheck, ETrue );          
       
   664             aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaContinue, ETrue );          
       
   665             }
       
   666         }
       
   667    
       
   668       if( aResourceId == R_SMLSYNC_MENU_FOTA_VIEW )
       
   669         {
       
   670         if( ServersViewVariable )
       
   671            {
       
   672            aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaServers, EFalse );	
       
   673            }
       
   674         else
       
   675            {
       
   676            aMenuPane->SetItemDimmed( ENSmlMenuCmdFotaServers, ETrue );	
       
   677            }
       
   678         
       
   679         }
       
   680       
       
   681 	    }
       
   682 	   FLOG( "[OMADM] CNSmlDMFotaView::DynInitMenuPaneL() completed" );
       
   683 	}
       
   684 
       
   685 
       
   686 // -----------------------------------------------------------------------------
       
   687 // CNSmlDMFotaView::RefreshL
       
   688 // -----------------------------------------------------------------------------
       
   689 //
       
   690 void CNSmlDMFotaView::RefreshL(TBool aPostponeDisplay)
       
   691     {
       
   692     FLOG( "[OMADM]\t CNSmlDMFotaView::RefreshListBox()" );
       
   693 
       
   694     if ( iContainer )
       
   695         {
       
   696         iContainer->RefreshL(aPostponeDisplay);
       
   697         }
       
   698     FLOG( "[OMADM]\t CNSmlDMFotaView::RefreshListBox() completed" );
       
   699     }	
       
   700 
       
   701 
       
   702 // -----------------------------------------------------------------------------
       
   703 // CNSmlDMFotaView::ManualCheckAllowed
       
   704 // -----------------------------------------------------------------------------
       
   705 //
       
   706 TBool CNSmlDMFotaView::ManualCheckAllowedL()
       
   707 	{
       
   708 	CRepository* cenrep = NULL;
       
   709     TRAPD( error, cenrep = CRepository::NewL( KCRUidNSmlDMSyncApp ) );        
       
   710     if ( cenrep )
       
   711         {
       
   712         cenrep->Get( KNsmlDmManualCheckAllowed, iManCheckAllowed );
       
   713         delete cenrep;
       
   714         }
       
   715     if ( error != KErrNone ) 
       
   716         {
       
   717         User::Leave( error );
       
   718         }
       
   719 	if ( iManCheckAllowed == 1)
       
   720 	    {
       
   721 		return ETrue;		
       
   722 	    }
       
   723  
       
   724 	return EFalse;
       
   725 	}
       
   726 
       
   727 // -----------------------------------------------------------------------------
       
   728 // CNSmlDMFotaView::HandleForegroundEventL
       
   729 // -----------------------------------------------------------------------------
       
   730 //
       
   731 void CNSmlDMFotaView::HandleForegroundEventL(TBool aForeground)
       
   732 	{
       
   733 	
       
   734 	// For Application Management purpose whenever there is switch between app.
       
   735 	
       
   736 	
       
   737 	
       
   738 	FLOG( "[OMADM]\t CNSmlDMFotaView::HandleForegroundEventL():Begin" );
       
   739 	if( !aForeground )
       
   740 		{
       
   741 		FLOG( "[OMADM]\t CNSmlDMFotaView::HandleForegroundEventL() not in FG :end" );
       
   742 	    return;	
       
   743 		}	
       
   744 	
       
   745 	
       
   746 	if( iExitPress != -2 ) // == 1 some what fast as no call to refreshL based on iexitPress
       
   747 		{
       
   748 		iExitPress = -1;	
       
   749 		STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi())->CheckFotaDlL();
       
   750 		FLOG( "[OMADM]\t CNSmlDMFotaView::HandleForegroundEventL(): CheckAMDlL Begin" );
       
   751 		STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi())->CheckAMDlL();
       
   752 		FLOG( "[OMADM]\t CNSmlDMFotaView::HandleForegroundEventL(): CheckAMDlL END" );
       
   753 		}
       
   754 	iFotaDLObserver->StartL(EFalse);
       
   755 	
       
   756 	if ( !ManualCheckAllowedL() && iExitPress != -2 )	//for MSK display
       
   757 	    {
       
   758 	    if( FeatureManager::FeatureSupported( KFeatureIdSyncMlDmFota ) )
       
   759 	       {
       
   760 	       if ( iFotaModel->FindFwUpdPkgWithStateL(
       
   761             EStartingUpdate ) != KErrNotFound )
       
   762 	    	{
       
   763 	        EnableMskL( ETrue );	
       
   764 	    	}	
       
   765 	       }	    
       
   766 	    iExitPress = -1;	
       
   767 	    }
       
   768 	CAknView::HandleForegroundEventL(aForeground);
       
   769 	FLOG( "[OMADM]\t CNSmlDMFotaView::HandleForegroundEventL():completed" );
       
   770 	}    
       
   771 	
       
   772 // -----------------------------------------------------------------------------
       
   773 // CNSmlDMFotaView::EnableMskL
       
   774 // -----------------------------------------------------------------------------
       
   775 //
       
   776 void CNSmlDMFotaView::EnableMskL ( TBool aEnable )	
       
   777 	{
       
   778 	CEikButtonGroupContainer* cbaGrp= Cba();
       
   779 	if (cbaGrp)
       
   780 		{
       
   781 		if (aEnable)
       
   782 			{						
       
   783 			cbaGrp->MakeCommandVisible(EAknSoftkeyContextOptions,ETrue);	    	
       
   784 			}
       
   785 		else
       
   786 			{
       
   787 			cbaGrp->MakeCommandVisible(EAknSoftkeyContextOptions,EFalse);
       
   788 			}		
       
   789 		}
       
   790 	}
       
   791 
       
   792 // ----------------------------------------------------
       
   793 // CNSmlDMFotaView::UpdateExitL
       
   794 // ----------------------------------------------------
       
   795 //	
       
   796 void CNSmlDMFotaView::UpdateExitL()
       
   797 	{
       
   798 	iExitPress = -2;	
       
   799 	}	
       
   800 
       
   801 
       
   802 // -----------------------------------------------------------------------------
       
   803 // CDLObserver::CDLObserver()
       
   804 // -----------------------------------------------------------------------------
       
   805 
       
   806 inline CDLObserver::CDLObserver()
       
   807 	:CActive(EPriorityStandard)
       
   808 	{
       
   809 	
       
   810 	}
       
   811 	
       
   812 	
       
   813 // -----------------------------------------------------------------------------
       
   814 // CDLObserver::ConstructL()
       
   815 // -----------------------------------------------------------------------------
       
   816 
       
   817 void CDLObserver::ConstructL(CNSmlDMFotaView* iFotaView)
       
   818 	{
       
   819 	CActiveScheduler::Add(this);	
       
   820     iView = iFotaView;
       
   821 	}
       
   822 
       
   823 // -----------------------------------------------------------------------------
       
   824 // CDLObserver::Start()
       
   825 // -----------------------------------------------------------------------------
       
   826 void CDLObserver::StartL(TBool aResetKey)
       
   827 	{	
       
   828 	FLOG("CDLObserver::Start- begin");
       
   829 	if(!IsActive())
       
   830 		{
       
   831 		//set key value to -1			
       
   832 		FLOG("logging new request");
       
   833 		TInt err = iProperty.Attach(KPSUidNSmlDMSyncApp,KFotaDLRefresh);
       
   834 		FTRACE( FPrint(_L("CDLObserver::StartL attached to P&S key with error as %d"),err ) );		
       
   835 		CNSmlDMSyncDocument* doc = 
       
   836 		    ( CNSmlDMSyncDocument* ) iView->AppUi()->Document();
       
   837 		if( aResetKey && doc->DMDefinesFotaDLKey())		
       
   838 		 {		 
       
   839 		 TInt value = -1;
       
   840 		 err = iProperty.Set(KPSUidNSmlDMSyncApp,KFotaDLRefresh,value);
       
   841 		 FTRACE( FPrint(_L("CDLObserver::StartL updated the value of p&S key with error %d"),err ) );
       
   842 		 }
       
   843 		iStatus=KRequestPending;
       
   844 		iProperty.Subscribe(iStatus);
       
   845 		FLOG("CDLObserver::StartL subscribed to p&S ");
       
   846 		SetActive();	
       
   847 		}		   
       
   848 	}
       
   849 
       
   850 // -----------------------------------------------------------------------------
       
   851 // CDLObserver::RunL()
       
   852 // -----------------------------------------------------------------------------
       
   853 void CDLObserver::RunL()
       
   854 	{
       
   855 	FLOG("CDLObserver::RunL()- begin");
       
   856 	TInt value;	
       
   857 	iProperty.Attach(KPSUidNSmlDMSyncApp,KFotaDLRefresh);
       
   858 	iProperty.Get(KPSUidNSmlDMSyncApp,KFotaDLRefresh,value);
       
   859 	TInt state (EIdle);
       
   860 	state = iView->iFotaModel->GetCurrentFwUpdState();
       
   861 	FTRACE( FPrint(_L("current state of fota is %d"),state ) );
       
   862 	//EFALSE for suspended,failed & completed
       
   863 	//Download Ended either successfully or unsuccessfully
       
   864 	if( value == EFalse ) 
       
   865 		{			
       
   866 		FLOG("CDLObserver::RunL()--status value = 0");			
       
   867 		if (state == EDownloadProgressingWithResume || 
       
   868 				state == EDownloadComplete ||
       
   869 				state == EStartingUpdate ||
       
   870 				state == EDownloadFailed)
       
   871 			{
       
   872 			TInt IsDMBusy = EFalse;    //IAD: Making DM Idle 
       
   873 			TInt r2=RProperty::Set(KUidSmlSyncApp,KDMIdle,IsDMBusy);	
       
   874 			iView->RefreshL(ETrue);				
       
   875 			iProperty.Subscribe(iStatus);
       
   876 			FLOG("CDLObserver::RunL()--issued request in the loop EFalse");
       
   877 			SetActive();
       
   878 			}
       
   879 		}
       
   880 	else if( value == 1 ) //resume case and update the UI
       
   881 		{		
       
   882 		FLOG("CDLObserver::RunL()--status value = 1");
       
   883 		if (state == EDownloadProgressingWithResume || 
       
   884 				state == EDownloadProgressing || 
       
   885 				state == EStartingDownload )
       
   886 			{
       
   887 			TInt IsDMBusy = ETrue;    //IAD: Making DM Busy
       
   888 			TInt r2=RProperty::Set(KUidSmlSyncApp,KDMIdle,IsDMBusy);		
       
   889 			FLOG("CDLObserver::RunL():call to view refresh");
       
   890 			iView->RefreshL(EFalse);
       
   891 			}
       
   892 		iProperty.Subscribe(iStatus);
       
   893 		FLOG("CDLObserver::RunL()--issued request in the loop ETRUe");
       
   894 		SetActive();
       
   895 
       
   896 		}
       
   897 	else 
       
   898 		{			
       
   899 		FTRACE( FPrint(_L("CDLObserver::RunL()-- else loop & value is %d"),value ) );
       
   900 		if(!IsActive())
       
   901 			{
       
   902 			iStatus=KRequestPending;
       
   903 			value = -1;
       
   904 			iProperty.Set(KPSUidNSmlDMSyncApp,KFotaDLRefresh,value);
       
   905 			iProperty.Subscribe(iStatus);
       
   906 			FLOG("CDLObserver::RunL()--issued request again");
       
   907 			SetActive();
       
   908 			}				
       
   909 		}
       
   910 
       
   911 	}
       
   912 
       
   913 // ----------------------------------------------------------------------------------------
       
   914 // CDLObserver::DoCancel() 
       
   915 // ----------------------------------------------------------------------------------------
       
   916 void CDLObserver::DoCancel()
       
   917 	{
       
   918 	FLOG("CDLObserver::::DoCancel()");
       
   919     if( iStatus == KRequestPending )
       
   920     	{	
       
   921     	iProperty.Cancel();// new fix to be tested thoroughly
       
   922     	TRequestStatus* status = &iStatus;
       
   923     	User::RequestComplete( status, KErrCancel );
       
   924     	}
       
   925 	}
       
   926 
       
   927 // ----------------------------------------------------------------------------------------
       
   928 // CDLObserver::~CDLObserver() 
       
   929 // ----------------------------------------------------------------------------------------
       
   930 CDLObserver::~CDLObserver()
       
   931 	{ 
       
   932 	FLOG("CDLObserver::~CDLObserver()");  
       
   933     Cancel();
       
   934     if (iProperty.Handle()) iProperty.Close();
       
   935 	}
       
   936 
       
   937 
       
   938 // ---------------------------------------------------------------------------
       
   939 // CDLObserver::RunError
       
   940 // ---------------------------------------------------------------------------
       
   941 //
       
   942 TInt CDLObserver::RunError( TInt aError )
       
   943     {
       
   944     return aError;
       
   945     }
       
   946 
       
   947 //  End of File