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