omadm/omadmappui/src/NSmlDMFotaSettingsDialog.cpp
changeset 0 3ce708148e4d
child 23 c4687ff85147
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 FOTA Setting Dialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <StringLoader.h>
       
    22 #include <aknradiobuttonsettingpage.h>
       
    23 #include <aknlists.h>
       
    24 
       
    25 #include "NSmlDMSyncApp.h"
       
    26 #include "NSmlDMSyncDocument.h"
       
    27 #include "NSmlDMSyncAppUi.h"
       
    28 #include "NSmlDMFotaSettingsDialog.h"
       
    29 #include "NSmlDMFotaModel.h"
       
    30 #include "NSmlDMSyncUi.hrh"
       
    31 #include <NSmlDMSync.rsg>
       
    32 #include <featmgr.h>
       
    33 #include "nsmldmsyncinternalpskeys.h" 
       
    34 
       
    35 #include <hlplch.h>
       
    36 #include <csxhelp/dm.hlp.hrh>
       
    37 
       
    38 
       
    39 #include "NSmlDMSyncDebug.h"
       
    40 
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43     
       
    44 // -----------------------------------------------------------------------------
       
    45 // CNSmlDMFotaSettingsDialog::NewL
       
    46 // Two-phased constructor.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CNSmlDMFotaSettingsDialog* CNSmlDMFotaSettingsDialog::NewL()
       
    50     {
       
    51     CNSmlDMFotaSettingsDialog* self = new ( ELeave ) CNSmlDMFotaSettingsDialog;
       
    52     
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop();
       
    56 
       
    57     return self;
       
    58     }
       
    59 
       
    60 // Destructor
       
    61 CNSmlDMFotaSettingsDialog::~CNSmlDMFotaSettingsDialog()
       
    62     {
       
    63     if ( iNaviPane )
       
    64         {
       
    65         iNaviPane->Pop();
       
    66         }
       
    67     
       
    68     if ( iTitlePane->Text() && iOriginalTitle ) 
       
    69         {
       
    70         TRAP_IGNORE( iTitlePane->SetTextL( *iOriginalTitle ) );
       
    71         }
       
    72     delete iOriginalTitle;
       
    73     iAvkonAppUi->RemoveFromStack( this );
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CNSmlDMFotaSettingsDialog::UpdateFotaSettListboxL
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CNSmlDMFotaSettingsDialog::UpdateFotaSettListboxL()
       
    81     {
       
    82     FLOG( "[OMADM] CNSmlDMFotaSettingsDialog::UpdateFotaSettListboxL()" );
       
    83 
       
    84     iFotaSettListBox->ItemDrawer()->ClearAllPropertiesL();
       
    85     
       
    86     CDesCArray* itemsArray = (CDesCArray*) iFotaSettListBox->Model()->ItemTextArray();
       
    87     itemsArray->Reset();
       
    88     
       
    89     TInt profileId = iDocument->FotaModel()->DefaultFotaProfileIdL();
       
    90     HBufC* profileName = HBufC::NewLC( KNSmlMaxProfileNameLength );
       
    91     iDocument->FotaModel()->GetProfileNameL( profileId, profileName );
       
    92     
       
    93     // No default profile found, "Always ask" is shown instead.
       
    94     if ( profileName->Des() == KNullDesC )
       
    95         {
       
    96         // Existing buffer is deleted, since the AllocReadResourceLC reserves
       
    97         // memory for the resource.
       
    98         CleanupStack::PopAndDestroy( profileName );
       
    99         profileName  = iCoeEnv->AllocReadResourceLC( R_QTN_FOTA_PROFILE_ALWAYS_ASK );
       
   100         }
       
   101     
       
   102     
       
   103     HBufC* itemText = StringLoader::LoadLC( R_ITEM_FOTA_DEFAULT_SERVER, *profileName );
       
   104 
       
   105     itemsArray->AppendL( itemText->Des() );
       
   106     
       
   107     CleanupStack::PopAndDestroy( 2 ); // itemText, profileName
       
   108     iFotaSettListBox->HandleItemAdditionL();
       
   109 
       
   110     FLOG( "[OMADM] CNSmlDMFotaSettingsDialog::UpdateFotaSettListboxL() completed" );
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CNSmlDMFotaSettingsDialog::HandleOKL
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CNSmlDMFotaSettingsDialog::HandleOKL()
       
   118     {
       
   119     FLOG( "[OMADM] CNSmlDMFotaSettingsDialog::HandleOKL()" );
       
   120 	
       
   121     // Profile list owned by the dialog
       
   122     CArrayFixFlat<TInt>* profileIdList = new ( ELeave ) CArrayFixFlat<TInt>( 1 );
       
   123     CleanupStack::PushL( profileIdList );
       
   124 
       
   125     CDesCArray* items = new ( ELeave ) CDesCArrayFlat( 1 );
       
   126     CleanupStack::PushL( items );
       
   127     items->Reset();
       
   128 
       
   129     HBufC* string = StringLoader::LoadLC( R_QTN_FOTA_PROFILE_ALWAYS_ASK );
       
   130     items->AppendL( string->Des() );
       
   131     CleanupStack::PopAndDestroy( string );
       
   132     string = NULL;
       
   133 
       
   134     iDocument->FotaModel()->ReadProfileListL( items, profileIdList );
       
   135     TInt value = iDocument->FotaModel()->SelectDefaultProfileFromList( profileIdList ) + 1;
       
   136     
       
   137     CAknRadioButtonSettingPage* dlg = 
       
   138         new (ELeave) CAknRadioButtonSettingPage( R_SETTINGS_RADIO,
       
   139                                                  value, items );
       
   140  
       
   141     HBufC* hdr = StringLoader::LoadLC( R_HDR_FOTA_DEFAULT_SERVER );
       
   142 	CleanupStack::PushL( dlg );
       
   143 	dlg->SetSettingTextL( hdr->Des() );
       
   144     CleanupStack::Pop( dlg );
       
   145 
       
   146     TBool ret = dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged );
       
   147 
       
   148 	CleanupStack::PopAndDestroy( hdr );
       
   149 	hdr = NULL;
       
   150     CleanupStack::PopAndDestroy( items ); 
       
   151 
       
   152     if ( ret )  // User has accepted a choice
       
   153         {
       
   154         // Checks that the value conversion is done propery and the result
       
   155         // is in range.
       
   156         __ASSERT_ALWAYS( ( value >= 0 ) && ( value - 1 < profileIdList->Count() ),
       
   157                          TUtil::Panic( KErrArgument ) );
       
   158         
       
   159         if ( value == 0 )
       
   160             {
       
   161             iDocument->FotaModel()->SetDefaultFotaProfileIdL( KErrNotFound );
       
   162             }
       
   163         else
       
   164             {
       
   165             TInt profileId( ( *profileIdList )[value - 1] );
       
   166             iDocument->FotaModel()->SetDefaultFotaProfileIdL( profileId );
       
   167             }
       
   168         }
       
   169     else //For End key press
       
   170         {
       
   171         STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi() )->ExitCallL();	
       
   172         }    
       
   173     CleanupStack::PopAndDestroy( profileIdList );
       
   174         
       
   175     UpdateFotaSettListboxL();
       
   176 
       
   177     FLOG( "[OMADM] CNSmlDMFotaSettingsDialog::HandleOKL() completed" );
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CNSmlDMFotaSettingsDialog::OkToExitL
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 TBool CNSmlDMFotaSettingsDialog::OkToExitL( TInt aButtonId )
       
   185     {
       
   186     FLOG( "[OMADM] CNSmlDMFotaSettingsDialog::OkToExitL()" );
       
   187     
       
   188     if ( aButtonId == EAknSoftkeyChange )
       
   189         {
       
   190     	HandleOKL();
       
   191     	return EFalse;
       
   192         }
       
   193        
       
   194     if ( aButtonId == EEikBidCancel || aButtonId == EAknSoftkeyBack )
       
   195         {
       
   196         TInt value = EFalse;  //IAD: Making DM Idle
       
   197         TInt r1 = RProperty::Set(KPSUidNSmlDMSyncApp,KDMIdle,value); 
       
   198         FLOG( "[OMADM] CNSmlDMFotaSettingsDialog::OkToExitL() completed" );
       
   199         return ETrue;
       
   200         }
       
   201 
       
   202     FLOG( "[OMADM] CNSmlDMFotaSettingsDialog::OkToExitL() completed" );
       
   203     return CAknDialog::OkToExitL( aButtonId );
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CNSmlDMFotaSettingsDialog::PreLayoutDynInitL
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void CNSmlDMFotaSettingsDialog::PreLayoutDynInitL()
       
   211     {
       
   212     iAvkonAppUi->AddToStackL( this );
       
   213     
       
   214     iFotaSettListBox = (CAknSettingStyleListBox*) ControlOrNull ( ENSmlFotaSettList );
       
   215 
       
   216     if ( !iFotaSettListBox )
       
   217         {
       
   218         User::Leave( KErrGeneral );
       
   219         }
       
   220     // Set up/down arrows at bottom of the screen (scrollbar)
       
   221     iFotaSettListBox->CreateScrollBarFrameL( ETrue );
       
   222     iFotaSettListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOn,
       
   223                                                                  CEikScrollBarFrame::EAuto );
       
   224 
       
   225     iFotaSettListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );   // Deletes items array
       
   226     UpdateFotaSettListboxL();
       
   227 
       
   228     // Set up the observer (events listener)
       
   229     iFotaSettListBox->SetListBoxObserver( this );
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CNSmlDMFotaSettingsDialog::DynInitMenuPaneL
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 void CNSmlDMFotaSettingsDialog::DynInitMenuPaneL( TInt aResourceID,CEikMenuPane* aMenuPane )
       
   237 	{
       
   238      	FLOG( "[OMADM] CNSmlDMDlgProfileView::DynInitMenuPaneL:" );
       
   239      
       
   240      	if (aResourceID == R_SETTINGS_MENU &&
       
   241      	         !FeatureManager::FeatureSupported( KFeatureIdHelp ))    
       
   242           {   
       
   243               aMenuPane->SetItemDimmed( EAknCmdHelp , ETrue );
       
   244           
       
   245           }
       
   246 	}
       
   247 
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CNSmlDMFotaSettingsDialog::OfferKeyEventL
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 TKeyResponse CNSmlDMFotaSettingsDialog::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   254                                                               TEventCode aType )
       
   255 	{
       
   256     FLOG( "[OMADM] CNSmlDMFotaSettingsDialog::OfferKeyEventL()" );
       
   257 
       
   258     if ( aType == EEventKey )
       
   259         {
       
   260         switch ( aKeyEvent.iCode )
       
   261             {
       
   262             case EKeyEscape:
       
   263                 {
       
   264                 iAvkonAppUi->ProcessCommandL( EAknCmdExit );
       
   265                 break;
       
   266                 }
       
   267             case EKeyEnter: // Enter button
       
   268             case EKeyOK: // OK button
       
   269                 {
       
   270                 HandleOKL();
       
   271                 return EKeyWasConsumed;
       
   272                 }
       
   273             case EKeyPhoneEnd:
       
   274                 {
       
   275                 STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi() )->ExitCallL();
       
   276                 return EKeyWasConsumed;	
       
   277                 }
       
   278             default:
       
   279                 {
       
   280                 break;
       
   281                 }
       
   282             }
       
   283         }
       
   284     return CAknDialog::OfferKeyEventL( aKeyEvent, aType);
       
   285     }
       
   286     
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CNSmlDMFotaSettingsDialog::ProcessCommandL
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 void CNSmlDMFotaSettingsDialog::ProcessCommandL( TInt aCommandId )
       
   293     {
       
   294     FLOG( "[OMADM] CNSmlDMFotaSettingsDialog::ProcessCommandL()" );
       
   295 
       
   296     HideMenu();
       
   297     switch ( aCommandId )
       
   298         {
       
   299         case EAknCmdHelp:    
       
   300             { if (FeatureManager::FeatureSupported( KFeatureIdHelp ))
       
   301                {               
       
   302                	HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi())->AppHelpContextL());
       
   303                }
       
   304             
       
   305             break;
       
   306             }
       
   307         case ENSmlSettChange:
       
   308         case ENSmlMenuCmdFotaSettChange:
       
   309             {				
       
   310             HandleOKL();
       
   311             break;
       
   312             }			
       
   313 
       
   314         case ENSmlSettExit:
       
   315         case EAknCmdExit:
       
   316         case EEikCmdExit:
       
   317             {
       
   318             STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi() )->ExitCallL();
       
   319 	        STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi() )->CloseGs();
       
   320             break;
       
   321             }
       
   322 
       
   323         default:
       
   324             {
       
   325             break;
       
   326             }
       
   327         }
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CNSmlDMFotaSettingsDialog::HandleListBoxEventL
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 void CNSmlDMFotaSettingsDialog::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   335                                                  TListBoxEvent aEventType )
       
   336 	{
       
   337 	FLOG( "[OMADM] CNSmlDMDlgProfileView::HandleListBoxEventL()" );
       
   338 	
       
   339 	if ( aEventType == EEventEnterKeyPressed ||
       
   340 	     aEventType == EEventItemSingleClicked )
       
   341 		{
       
   342 		HandleOKL();
       
   343 		}
       
   344 	}
       
   345 
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CNSmlDMFotaSettingsDialog::GetHelpContext
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 void CNSmlDMFotaSettingsDialog::GetHelpContext( TCoeHelpContext& aContext ) const
       
   352     {
       
   353 	FLOG( "[OMADM] CNSmlDMFotaSettingsDialog::GetHelpContext" );
       
   354 	
       
   355 	aContext.iMajor = KUidSmlSyncApp;
       
   356     aContext.iContext = KFOTA_HLP_SETTINGS;
       
   357     }
       
   358 
       
   359 
       
   360 
       
   361 // -----------------------------------------------------------------------------
       
   362 // CNSmlDMFotaSettingsDialog::CNSmlDMFotaSettingsDialog
       
   363 // C++ default constructor can NOT contain any code, that
       
   364 // might leave.
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 CNSmlDMFotaSettingsDialog::CNSmlDMFotaSettingsDialog()
       
   368     {
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CNSmlDMFotaSettingsDialog::ConstructL
       
   373 // Symbian 2nd phase constructor can leave.
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CNSmlDMFotaSettingsDialog::ConstructL()
       
   377     {
       
   378     CAknDialog::ConstructL( R_SETTINGS_PROFILEMENU );
       
   379 
       
   380     iDocument = (CNSmlDMSyncDocument*) iAvkonAppUi->Document();
       
   381     
       
   382     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   383     if ( statusPane && statusPane->PaneCapabilities( TUid::Uid(EEikStatusPaneUidTitle) ).IsPresent() )
       
   384         {
       
   385         iNaviPane = ( CAknNavigationControlContainer* )
       
   386             statusPane->ControlL( TUid::Uid(EEikStatusPaneUidNavi) );
       
   387         iNaviPane->PushDefaultL();
       
   388         iTitlePane = static_cast<CAknTitlePane*>
       
   389             ( statusPane->ControlL( TUid::Uid(EEikStatusPaneUidTitle) ) );
       
   390         if ( iTitlePane->Text() ) 
       
   391 			{
       
   392 			iOriginalTitle = HBufC::NewL( 50 ); //KNsmlMaxTitleSize );
       
   393 			iOriginalTitle->Des().Copy( *iTitlePane->Text() );
       
   394             HBufC* titleText = StringLoader::LoadLC( R_QTN_FOTA_TITLE_SETTINGS_DIALOG );
       
   395 	   		iTitlePane->SetTextL( *titleText );
       
   396             CleanupStack::PopAndDestroy( titleText );
       
   397             titleText = NULL;
       
   398 			}
       
   399 		}
       
   400     }
       
   401 
       
   402 
       
   403 //  End of File