iaupdate/IAD/ui/src/iaupdatesettingdialog.cpp
branchRCL_3
changeset 65 7333d7932ef7
parent 15 51c0f5edf5ef
child 66 8b7f4e561641
equal deleted inserted replaced
62:5cc91383ab1e 65:7333d7932ef7
     1 /*
     1 /*
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:    
    14 * Description:   This module contains the implementation of IAUpdateSettingDialog 
       
    15 *                class member functions.
    15 *
    16 *
    16 */
    17 */
    17 
    18 
    18 
    19 #include <hbdataform.h>
    19 
    20 #include <hbdataformmodel.h>
    20 
    21 #include <centralrepository.h>
    21 // INCLUDE FILES
    22 #include <cmconnectionmethoddef.h>
       
    23 #include <cmdestination.h>
       
    24 #include <xqconversions.h>
       
    25 #include <hbaction.h> 
    22 
    26 
    23 #include "iaupdatesettingdialog.h"
    27 #include "iaupdatesettingdialog.h"
    24 #include "iaupdateaccesspointhandler.h"  
    28 #include "iaupdateprivatecrkeys.h"
    25 #include "iaupdatestatuspanehandler.h"
       
    26 #include "iaupdateapplication.h"
       
    27 #include "iaupdate.hrh"
    29 #include "iaupdate.hrh"
    28 #include "iaupdateprivatecrkeys.h"
    30 
    29 #include "iaupdatedebug.h"
    31 
    30 #include <iaupdate.rsg>
    32 const TInt KAutoUpdateOn( 0 );
    31 
    33 const TInt KAutoUpdateOff( 1 );
    32 #include <centralrepository.h>
    34 const TInt KAutoUpdateOnInHomeNetwork( 2 );
    33 #include <featmgr.h> 
    35 
    34 #include <hlplch.h>
    36 /*
    35 
    37 Constructor. It creates a formwidget on the view. 
    36 
    38 */
    37 _LIT( KSWUPDATE_HLP_SETTINGS, "SWUPDATE_HLP_SETTINGS" ); 
    39 CIAUpdateSettingDialog::CIAUpdateSettingDialog(QGraphicsItem* parent):HbView(parent)
    38 
    40     {
    39 
    41     
    40 
    42     //setTitle("Software update");
    41 
    43     
    42 // cenrep in emulator:
    44     mSettingsForm = new HbDataForm(this);
    43 // copy 2000F85A.txt to '\epoc32\release\winscw\udeb\Z\private\10202be9\'
    45             
    44 // delete 2000F85A.txt from 'epoc32\winscw\c\private\10202be9\persists'
    46 
    45 //
    47     // open connection manager 
    46 // cenrep in hardware:
    48     TRAPD(err,  mCmManager.OpenL()); 
    47 // copy 2000F85A.txt to '\epoc32\data\Z\private\10202be9'
    49     qt_symbian_throwIfError(err);
    48 //
    50     
    49 
    51     // destination field flag inititializations 
    50 
    52     mSetByNwQuery = false; // dest set by user/by destination query
    51 
    53     mConnected = false;    // already connected to query
    52 /******************************************************************************
    54     mInitialized = false;  // field initialized ?
    53  * class CIAUpdateSettingDialog
    55     
    54  ******************************************************************************/
    56     // Initialize view
    55 
    57     initializeView();
    56 
    58     
    57 // -----------------------------------------------------------------------------
    59     //setWidget(mSettingsForm);
    58 // CIAUpdateSettingDialog::ShowDialogL
    60     setWidget(mSettingsForm);
       
    61     
       
    62     // Create application settings ui
       
    63     mApplSett = new CmApplSettingsUi(this);
       
    64 
       
    65     // Create a back key action and set it as the default navigation
       
    66     // action once the back key is pressed
       
    67     mBackKey = new HbAction(Hb::BackNaviAction, this);
       
    68     this->setNavigationAction(mBackKey);
       
    69 
       
    70     connect(mBackKey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
       
    71 
       
    72     }
       
    73 
       
    74 /*
       
    75 Destructor
       
    76 */
       
    77 CIAUpdateSettingDialog::~CIAUpdateSettingDialog()
       
    78     {
       
    79     // close connection manager 
       
    80     mCmManager.Close();
       
    81     }
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CIAUpdateSettingDialog::toggleChange
    59 // 
    85 // 
    60 // -----------------------------------------------------------------------------
    86 // ----------------------------------------------------------------------------
    61 TBool CIAUpdateSettingDialog::ShowDialogL()
    87 //
    62 	{
    88 void CIAUpdateSettingDialog::toggleChange(QModelIndex startIn, QModelIndex /*endIn*/)
    63 	//__UHEAP_MARK;
    89 {
    64 	
    90     // HLa: this should work
    65 	CIAUpdateSettingDialog* dialog = CIAUpdateSettingDialog::NewL();
    91     HbDataFormModelItem *itm = mModel->itemFromIndex(startIn);
    66 
    92 
    67 	TBool ret = dialog->ExecuteLD( R_IAUPDATE_SETTING_DIALOG );
    93     // Destination ?
    68 
    94     if ( startIn.row() == 0 )
    69    	//__UHEAP_MARKEND;
    95         {
    70    	
    96         // no query when initializing fields
    71     return ret;
    97         if ( mInitialized )
    72 	}
    98             {
    73 
    99             // no query if field value set by destination query
    74 
   100             if (!mSetByNwQuery )
    75 // -----------------------------------------------------------------------------
   101                 {
    76 // CIAUpdateSettingDialog::NewL
   102                 queryDestination();
    77 //
   103                 mSetByNwQuery = true;
    78 // -----------------------------------------------------------------------------
   104                 }
    79 CIAUpdateSettingDialog* CIAUpdateSettingDialog::NewL()
   105                 else
    80     {
   106                 {
    81     CIAUpdateSettingDialog* self = new ( ELeave ) CIAUpdateSettingDialog();
   107                 mSetByNwQuery = false;
    82     CleanupStack::PushL( self );
   108                 }
    83     self->ConstructL();
   109             }
    84     CleanupStack::Pop( self );
   110         else
    85 
   111             {
    86     return self;
   112             mInitialized = true;
    87     }
   113             }
    88 
   114            
    89 
   115         }
    90 // -----------------------------------------------------------------------------
   116     // Auto update ?
    91 // CIAUpdateSettingDialog::CIAUpdateSettingDialog
   117     if ( startIn.row() == 1 )
       
   118         {
       
   119          int currentIndex = mAutoUpdateItem->contentWidgetData(QString("currentIndex")).toInt();
       
   120         }
       
   121 }
       
   122 // ----------------------------------------------------------------------------
       
   123 // CIAUpdateSettingDialog::queryDestination
    92 // 
   124 // 
    93 // -----------------------------------------------------------------------------
   125 // ----------------------------------------------------------------------------
    94 //
   126 //
    95 CIAUpdateSettingDialog::CIAUpdateSettingDialog()
   127 void CIAUpdateSettingDialog::queryDestination()
    96 	{
   128   {
    97     }
   129         QFlags<CmApplSettingsUi::SelectionDialogItems> listItems;
    98 
   130         QSet<CmApplSettingsUi::BearerTypeFilter> filter;
    99 
   131         
   100 // -----------------------------------------------------------------------------
   132         // Show only destinations
   101 // CIAUpdateSettingDialog::ConstructL
   133        listItems |= CmApplSettingsUi::ShowDestinations;
   102 //
   134        // listItems |= CmApplSettingsUi::ShowConnectionMethods;
   103 // -----------------------------------------------------------------------------
   135 
   104 //
   136         mApplSett->setOptions(listItems, filter);
   105 void CIAUpdateSettingDialog::ConstructL()
   137         mApplSett->setSelection(mSelection);
   106     {
   138         
   107  	CAknDialog::ConstructL( R_IAUPDATE_SETTING_DIALOG_MENU );
   139         // Connect finished(uint) signal and handle result via it
   108     
   140         if (!mConnected)
   109     // get previous title so it can be restored
       
   110 	iStatusPaneHandler = CIAUpdateStatusPaneHandler::NewL( iAvkonAppUi );
       
   111 	iStatusPaneHandler->StoreOriginalTitleL();
       
   112     } 
       
   113 
       
   114 
       
   115 // ----------------------------------------------------------------------------
       
   116 // Destructor
       
   117 //
       
   118 // ----------------------------------------------------------------------------
       
   119 //
       
   120 CIAUpdateSettingDialog::~CIAUpdateSettingDialog()
       
   121     {
       
   122 	delete iStatusPaneHandler;
       
   123 	
       
   124     if (iAvkonAppUi)
       
   125     	{
       
   126     	iAvkonAppUi->RemoveFromStack( this );
       
   127     	}
       
   128     }
       
   129 
       
   130 
       
   131 // ---------------------------------------------------------
       
   132 // CIAUpdateSettingDialog::CreateCustomControlL
       
   133 // ---------------------------------------------------------
       
   134 //
       
   135 SEikControlInfo CIAUpdateSettingDialog::CreateCustomControlL( TInt aControlType )
       
   136     {
       
   137     SEikControlInfo controlInfo;
       
   138     controlInfo.iControl = NULL;
       
   139     controlInfo.iTrailerTextId = 0;
       
   140     controlInfo.iFlags = 0;
       
   141     
       
   142     switch ( aControlType )
       
   143         {
       
   144         case EAknCtLastControlId:
       
   145             {
   141             {
   146             controlInfo.iControl = new (ELeave) CIAUpdateSettingItemList();
   142             connect(mApplSett, SIGNAL(finished(uint)), this, SLOT(showResults(uint)));
   147             break;
   143             mConnected = true;
   148             }
   144             }
   149 
   145         
   150         default:
   146         // Start CmApplSettingsUi
       
   147         mApplSett->open();
       
   148 
       
   149   }
       
   150 // ----------------------------------------------------------------------------
       
   151 // CIAUpdateSettingDialog::showResults
       
   152 // 
       
   153 // ----------------------------------------------------------------------------
       
   154 //
       
   155 void CIAUpdateSettingDialog::showResults(uint retval)
       
   156 {
       
   157     if (retval == CmApplSettingsUi::ApplSettingsErrorNone) {
       
   158         mSelection = mApplSett->selection();
       
   159         
       
   160         uint destinationId = mSelection.id;
       
   161         
       
   162         QString idString;
       
   163         
       
   164         TRAPD( err, getDestinationNameL( destinationId, idString ) );
       
   165         qt_symbian_throwIfError(err);
       
   166 
       
   167         // Destination changed ?
       
   168         if ( idString != mCurrentDest )
   151             {
   169             {
   152             break;
   170             mCurrentDest = idString;
   153             }
   171             }
   154         }
   172     }
   155     return controlInfo;
   173    // inform toggleChange that change is not made by user
   156     }
   174     mSetByNwQuery = true;
   157 
   175     mDestinationItem->setContentWidgetData(QString("text"), mCurrentDest);
   158 
   176 }
   159 //------------------------------------------------------------------------------
       
   160 // CIAUpdateSettingDialog::ActivateL
       
   161 //
       
   162 // Called by system when dialog is activated.
       
   163 //------------------------------------------------------------------------------
       
   164 //
       
   165 void CIAUpdateSettingDialog::ActivateL()
       
   166 	{
       
   167     CAknDialog::ActivateL();
       
   168 
       
   169 	// this cannot be in ConstructL which is executed before dialog is launched
       
   170 	iAvkonAppUi->AddToStackL(this);
       
   171     }
       
   172 
       
   173 
       
   174 //------------------------------------------------------------------------------
       
   175 // CIAUpdateSettingDialog::GetHelpContext
       
   176 //
       
   177 //------------------------------------------------------------------------------
       
   178 //
       
   179 void CIAUpdateSettingDialog::GetHelpContext( TCoeHelpContext& aContext ) const
       
   180 	{
       
   181 	aContext.iMajor = KUidIAUpdateApp;
       
   182     aContext.iContext = KSWUPDATE_HLP_SETTINGS;        
       
   183 	}
       
   184 
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CIAUpdateSettingDialog::HandleListBoxEventL
       
   188 // 
       
   189 // -----------------------------------------------------------------------------
       
   190 void CIAUpdateSettingDialog::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   191                                                   TListBoxEvent /*aEventType*/ )
       
   192     {
       
   193     }
       
   194 
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CIAUpdateSettingDialog::PreLayoutDynInitL
       
   198 // 
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void CIAUpdateSettingDialog::PreLayoutDynInitL()
       
   202     {
       
   203     iList = (CIAUpdateSettingItemList*) ControlOrNull ( EIAUpdateSettingDialogList );
       
   204     
       
   205     iList->LoadSettingsL(); // from CAknSettingItemList
       
   206     
       
   207 	iStatusPaneHandler->SetTitleL( R_IAUPDATE_SETTING_DIALOG_TITLE );
       
   208 	iStatusPaneHandler->SetNaviPaneTitleL(KNullDesC);
       
   209     }
       
   210 
       
   211 
       
   212 //------------------------------------------------------------------------------
       
   213 // CIAUpdateSettingDialog::DynInitMenuPaneL
       
   214 //
       
   215 // Called by system before menu is shown.
       
   216 //------------------------------------------------------------------------------
       
   217 //
       
   218 void CIAUpdateSettingDialog::DynInitMenuPaneL(TInt aResourceID, CEikMenuPane* aMenuPane )
       
   219 	{
       
   220     if( aResourceID == R_IAUPDATE_SETTING_DIALOG_MENU_PANE ) 
       
   221         {
       
   222         if ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   223             {
       
   224             aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   225             }
       
   226         }
       
   227     }
       
   228 
       
   229 
       
   230 //------------------------------------------------------------------------------
       
   231 // CIAUpdateSettingDialog::ProcessCommandL
       
   232 //
       
   233 // Handle commands from menu.
       
   234 //------------------------------------------------------------------------------
       
   235 //
       
   236 void CIAUpdateSettingDialog::ProcessCommandL(TInt aCommandId)
       
   237 	{
       
   238     if ( MenuShowing() ) 
       
   239         {
       
   240         HideMenu();
       
   241         }
       
   242 
       
   243 
       
   244 	switch ( aCommandId )
       
   245 		{
       
   246 		case EAknCmdHelp:
       
   247 			{
       
   248 			HlpLauncher::LaunchHelpApplicationL( 
       
   249 			                     iEikonEnv->WsSession(), 
       
   250 			                     iEikonEnv->EikAppUi()->AppHelpContextL() );
       
   251 		    break;
       
   252 			}
       
   253  
       
   254 		case EAknCmdOpen:
       
   255 			{
       
   256 			EditItemL();
       
   257 			break;
       
   258 			}
       
   259 		    
       
   260         case EAknCmdExit:
       
   261         case EEikCmdExit:
       
   262 			{
       
   263 			// close dialog and exit calling application
       
   264 			iAvkonAppUi->ProcessCommandL( EAknCmdExit );
       
   265 			break;
       
   266 			}
       
   267 
       
   268 		default:			
       
   269 		    break;
       
   270 		}
       
   271 	}
       
   272 
       
   273 
       
   274 //------------------------------------------------------------------------------
       
   275 // CIAUpdateSettingDialog::OkToExitL
       
   276 //
       
   277 //------------------------------------------------------------------------------
       
   278 //
       
   279 TBool CIAUpdateSettingDialog::OkToExitL(TInt aButtonId)
       
   280 	{
       
   281 	if ( aButtonId == EEikBidCancel )
       
   282 		{
       
   283 		TRAP_IGNORE( SaveSettingsL() );  //potential leave trapped 
       
   284 		                                 //because IAD is not closed if SaveSettingsL() leaves 
       
   285 		return ETrue; // close dialog
       
   286 		}
       
   287 
       
   288 	if ( aButtonId == EAknSoftkeyOpen )
       
   289 		{
       
   290 		EditItemL();
       
   291 
       
   292 		return EFalse; // leave dialog open
       
   293 		}
       
   294 
       
   295 	if ( aButtonId == EAknSoftkeyBack )
       
   296         {
       
   297 		SaveSettingsL();
       
   298 		
       
   299 		return ETrue; // close dialog
       
   300 		}
       
   301 
       
   302 	return CAknDialog::OkToExitL(aButtonId);
       
   303 	}
       
   304 
       
   305 
       
   306 
       
   307 // ----------------------------------------------------------------------------
       
   308 // CIAUpdateSettingDialog::OfferKeyEventL
       
   309 // 
       
   310 // ----------------------------------------------------------------------------
       
   311 //
       
   312 TKeyResponse CIAUpdateSettingDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   313 	{
       
   314 	if (aType == EEventKey)
       
   315 		{
       
   316 		switch (aKeyEvent.iCode)
       
   317 			{
       
   318 			case EKeyEscape:  // framework calls this when dialog must shut down
       
   319 				{
       
   320 				return CAknDialog::OfferKeyEventL(aKeyEvent, aType);
       
   321         		}
       
   322 			case EKeyUpArrow:
       
   323 			case EKeyDownArrow:
       
   324 			    {
       
   325     		    break;
       
   326 			    }
       
   327             default:
       
   328 				{
       
   329 			    break;
       
   330 				}
       
   331 			}
       
   332 		}
       
   333 
       
   334 	return CAknDialog::OfferKeyEventL( aKeyEvent, aType);
       
   335 	}
       
   336 
       
   337 
       
   338 // ----------------------------------------------------------------------------
       
   339 // CIAUpdateSettingDialog::HandleResourceChange
       
   340 // 
       
   341 // ----------------------------------------------------------------------------
       
   342 //
       
   343 void CIAUpdateSettingDialog::HandleResourceChange(TInt aType)
       
   344     {   
       
   345     if (aType == KEikDynamicLayoutVariantSwitch) //Handle change in layout orientation
       
   346         {
       
   347         TRect mainPaneRect;
       
   348         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect );
       
   349         SetRect( mainPaneRect );
       
   350     
       
   351         iList->HandleResourceChange( aType );
       
   352     
       
   353         CCoeControl::HandleResourceChange( aType );
       
   354 		DrawDeferred();
       
   355 	    return;
       
   356 		}
       
   357 		
       
   358     if ( aType == KAknsMessageSkinChange )
       
   359         {
       
   360         }
       
   361 		
       
   362     CCoeControl::HandleResourceChange( aType );
       
   363     }
       
   364 
       
   365 
       
   366 // ----------------------------------------------------------------------------
       
   367 // CIAUpdateSettingDialog::EditItemL
       
   368 // 
       
   369 // ----------------------------------------------------------------------------
       
   370 //
       
   371 void CIAUpdateSettingDialog::EditItemL()
       
   372 	{
       
   373 	TInt currentIndex = iList->ListBox()->CurrentItemIndex();
       
   374 	TBool calledFromMenu = ETrue;
       
   375 	
       
   376 	iList->EditItemL( currentIndex, calledFromMenu );
       
   377 	}
       
   378 
       
   379 
       
   380 // -----------------------------------------------------------------------------
       
   381 // CIAUpdateSettingDialog::SetVisibility
       
   382 // 
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 void CIAUpdateSettingDialog::SetVisibility()
       
   386 	{
       
   387 	}
       
   388 
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // CAspContentDialog::SetAllReadOnly
       
   392 // 
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 void CIAUpdateSettingDialog::SetAllReadOnly()
       
   396 	{
       
   397 	}
       
   398 
       
   399 
   177 
   400 // ----------------------------------------------------------------------------
   178 // ----------------------------------------------------------------------------
   401 // CIAUpdateSettingDialog::SaveSettingsL
   179 // CIAUpdateSettingDialog::SaveSettingsL
   402 // 
   180 // 
   403 // ----------------------------------------------------------------------------
   181 // ----------------------------------------------------------------------------
   404 //
   182 //
   405 void CIAUpdateSettingDialog::SaveSettingsL()
   183 void CIAUpdateSettingDialog::saveSettingsL()
   406 	{
   184     {
   407     iList->StoreSettingsL();  // from CAknSettingItemList
       
   408     
       
   409     CRepository* cenrep = CRepository::NewLC( KCRUidIAUpdateSettings );
   185     CRepository* cenrep = CRepository::NewLC( KCRUidIAUpdateSettings );
   410     TInt err = cenrep->StartTransaction( CRepository::EReadWriteTransaction );
   186     TInt err = cenrep->StartTransaction( CRepository::EReadWriteTransaction );
   411     User::LeaveIfError( err );
   187     User::LeaveIfError( err );
       
   188     
   412     cenrep->CleanupCancelTransactionPushL();
   189     cenrep->CleanupCancelTransactionPushL();
   413 
   190     
   414     
   191     // Set destination
   415     TInt num = iList->Attribute( EAccessPoint );
   192     TInt value = mSelection.id;
   416     if ( num == 0 )
   193     err = cenrep->Set( KIAUpdateAccessPoint, value ) ;
   417         {
       
   418         // O means default destination. Let's save it as -1 so that we know later on 
       
   419         // whether cenrep really contained the default or just nothing.
       
   420         num = -1;
       
   421         }
       
   422     err = cenrep->Set( KIAUpdateAccessPoint, num );
       
   423     User::LeaveIfError( err );
   194     User::LeaveIfError( err );
   424 
   195     
   425     num = iList->Attribute( EAutoUpdateCheck );
   196     // Set auto update check
   426     err = cenrep->Set( KIAUpdateAutoUpdateCheck, num );
   197     value = mAutoUpdateItem->contentWidgetData(QString("currentIndex")).toInt();
       
   198     
       
   199     // Convert ist index index to setting value
       
   200     switch ( value )
       
   201          {
       
   202          case KAutoUpdateOn:
       
   203              value = EIAUpdateSettingValueDisableWhenRoaming;
       
   204              break;
       
   205          case KAutoUpdateOff:
       
   206              value = EIAUpdateSettingValueDisable;
       
   207              break;
       
   208          case KAutoUpdateOnInHomeNetwork:
       
   209              value = EIAUpdateSettingValueEnable;
       
   210              break;
       
   211          default: 
       
   212              break;
       
   213          }
       
   214     err = cenrep->Set( KIAUpdateAutoUpdateCheck, value ); 
       
   215     
   427     User::LeaveIfError( err );
   216     User::LeaveIfError( err );
   428            
   217     
   429     TUint32 ignore = KErrNone;
   218     TUint32 ignore = KErrNone;
   430     User::LeaveIfError( cenrep->CommitTransaction( ignore ) );
   219     User::LeaveIfError( cenrep->CommitTransaction( ignore ) );
   431     CleanupStack::PopAndDestroy(); // CleanupCancelTransactionPushL()
   220     CleanupStack::PopAndDestroy(); // CleanupCancelTransactionPushL()
   432     CleanupStack::PopAndDestroy( cenrep );
   221     CleanupStack::PopAndDestroy( cenrep );
   433 	}
   222     }
   434 	
   223 
   435 	
   224 
   436 
   225 // -----------------------------------------------------------------------------
   437 
   226 // CIAUpdateSettingDialog::initializeFieldsL
   438 
   227 // -----------------------------------------------------------------------------
   439 /******************************************************************************
   228 //
   440  * class CIAUpdateSettingItemList
   229 void CIAUpdateSettingDialog::initializeFieldsL()
   441  ******************************************************************************/
   230     {
   442 
       
   443 
       
   444 // -----------------------------------------------------------------------------
       
   445 // CIAUpdateSettingItemList::CreateSettingItemL
       
   446 // 
       
   447 // -----------------------------------------------------------------------------
       
   448 //
       
   449 CAknSettingItem* CIAUpdateSettingItemList::CreateSettingItemL( TInt aSettingId )
       
   450     {
       
   451     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSettingItemList::CreateSettingItemL begin");
       
   452     CRepository* cenrep = CRepository::NewLC( KCRUidIAUpdateSettings );
   231     CRepository* cenrep = CRepository::NewLC( KCRUidIAUpdateSettings );
   453     CAknSettingItem* item = NULL;
   232     int destId = 0;
   454     
   233     
   455     switch ( aSettingId )
   234     // get access point id
   456         {
   235     User::LeaveIfError( cenrep->Get( KIAUpdateAccessPoint, destId ) );
   457         case EIAUpdateSettingAccessPoint:
   236     
       
   237     // save id
       
   238     mSelection.id = destId;
       
   239     
       
   240     // On first time: show internet access point
       
   241     if ( mSelection.id == 0 )
       
   242         {
       
   243         User::LeaveIfError(mSelection.id = getInternetSnapIdL());
       
   244         }
       
   245 
       
   246     // set destination name
       
   247     TRAPD( err, getDestinationNameL( mSelection.id, mCurrentDest ) );
       
   248    
       
   249     if ( err == KErrNotFound )
       
   250         { 
       
   251         mSelection.id = 0;
       
   252         }
       
   253     else
       
   254         {
       
   255          // nothing to do ?
       
   256          User::LeaveIfError( err );
       
   257         }
       
   258     mDestinationItem->setContentWidgetData(QString("text"), mCurrentDest);
       
   259     
       
   260     // set auto update value
       
   261     int value = 0;
       
   262     User::LeaveIfError( cenrep->Get( KIAUpdateAutoUpdateCheck, value ) );
       
   263     
       
   264     // map cenrep value to index
       
   265     switch ( value )
       
   266          {
       
   267          case EIAUpdateSettingValueEnable:
       
   268              value = KAutoUpdateOn; // On 
       
   269              break;
       
   270          case EIAUpdateSettingValueDisable:
       
   271              value = KAutoUpdateOff; // Off
       
   272              break;
       
   273          case EIAUpdateSettingValueDisableWhenRoaming:
       
   274              value = KAutoUpdateOnInHomeNetwork; // On in home network
       
   275              break;
       
   276          default: 
       
   277              break;
       
   278          }
       
   279     
       
   280     mAutoUpdateItem->setContentWidgetData("currentIndex", value);
       
   281     
       
   282    
       
   283     CleanupStack::PopAndDestroy( cenrep ); 
       
   284 
       
   285     } 
       
   286 
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CIAUpdateSettingDialog::getDestinationNameL
       
   290 //
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void CIAUpdateSettingDialog::getDestinationNameL( uint aItemUid, QString& aItemName )
       
   294     {
       
   295     
       
   296     if ( aItemUid == 0 )
       
   297         {
       
   298         aItemUid = getInternetSnapIdL();
       
   299         }
       
   300 
       
   301     RCmDestination dest = mCmManager.DestinationL( aItemUid );
       
   302     CleanupClosePushL( dest );
       
   303     HBufC* temp = dest.NameLC();    
       
   304     CleanupStack::Pop( temp );
       
   305     CleanupStack::PopAndDestroy( &dest ); 
       
   306     
       
   307     aItemName = XQConversions::s60DescToQString( temp->Des() );
       
   308 
       
   309     if ( aItemName.size() == 0 ) 
       
   310         {
       
   311         User::Leave(KErrNotFound);
       
   312         }
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // ActionView::initializeView
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 void CIAUpdateSettingDialog::initializeView()
       
   320     {
       
   321     
       
   322     setTitle("Software update"); // txt_software_title_software_update
       
   323     mSettingsForm->setHeading("Settings"); // txt_software_subhead_settings
       
   324 
       
   325      //create a model class
       
   326      HbDataFormModel *mModel = new HbDataFormModel();
       
   327 
       
   328      // add Destination item
       
   329      mDestinationItem = mModel->appendDataFormItem(
       
   330          HbDataFormModelItem::ToggleValueItem, QString("Network connection")); // txt_software_formlabel_access_point
       
   331 
       
   332      // add auto update item
       
   333      mAutoUpdateItem = mModel->appendDataFormItem(
       
   334         HbDataFormModelItem::ComboBoxItem, QString("Auto-check for updates")); // txt_software_setlabel_autocheck_for_updates
       
   335      
       
   336      // auto update selection values
       
   337      QStringList list;
       
   338      list.insert(0, QString("On")); // txt_software_setlabel_val_on
       
   339      list.append(QString("Off")); // txt_software_setlabel_val_off
       
   340      list.append(QString("On in home network")); // txt_software_setlabel_val_on_in_home_network
       
   341      mAutoUpdateItem->setContentWidgetData("items", list);
       
   342 
       
   343      // connect data changes for launching the access point selection dialog
       
   344      connect(mModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), 
       
   345                  this, SLOT(toggleChange(QModelIndex, QModelIndex)));
       
   346 
       
   347      // connect to function called when data items are displayed
       
   348      connect(mSettingsForm, SIGNAL(activated(QModelIndex)), 
       
   349                       this, SLOT(activated(QModelIndex)));
       
   350      
       
   351      mSettingsForm->setModel(mModel);
       
   352          
       
   353      // set values for items
       
   354      TRAPD(err, initializeFieldsL());
       
   355      qt_symbian_throwIfError(err);
       
   356 }
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // ActionView::getInternetSnapIdL
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 uint CIAUpdateSettingDialog::getInternetSnapIdL()
       
   363     {
       
   364     TUint internetSnapId( 0 );
       
   365     
       
   366     RArray<TUint32> destinationIdArray;
       
   367     mCmManager.AllDestinationsL( destinationIdArray );
       
   368     
       
   369     for ( TInt i = 0; i < destinationIdArray.Count(); i++ )
       
   370         {
       
   371         RCmDestination destination = mCmManager.DestinationL( destinationIdArray[i] );
       
   372         CleanupClosePushL( destination );
       
   373         
       
   374         TUint32 metadata = destination.MetadataL( CMManager::ESnapMetadataPurpose );
       
   375         if ( metadata == CMManager::ESnapPurposeInternet )
   458             {
   376             {
   459             User::LeaveIfError( cenrep->Get( KIAUpdateAccessPoint, iAccessPoint ) );
   377             internetSnapId = destinationIdArray[i];
   460             IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateSettingItemList::CreateSettingItemL iAccessPoint: %d", iAccessPoint);
   378             // Get the destination name with destination.NameLC() if need.
   461             if ( iAccessPoint == -1 )
   379             CleanupStack::PopAndDestroy( &destination );
   462                 {
       
   463                 // -1 was just our private representation in cenrep of the default destination  
       
   464                 // Let's handle it as it was 0
       
   465                 iAccessPoint = 0;
       
   466                 }
       
   467             item = CIAUpdateAccessPointSettingItem::NewL( aSettingId, iAccessPoint );
       
   468             break;
   380             break;
   469             }
   381             }
   470 
   382         CleanupStack::PopAndDestroy( &destination );
   471         case EIAUpdateSettingAutoUpdateCheck:
   383         }
   472             {
   384     destinationIdArray.Close();
   473             User::LeaveIfError( cenrep->Get( KIAUpdateAutoUpdateCheck, iAutoUpdateCheck ) );
   385     
   474             item = new (ELeave) CAknEnumeratedTextPopupSettingItem
   386     return internetSnapId;
   475                                ( aSettingId, iAutoUpdateCheck );
   387     
   476             break;
   388     }
   477             }
   389 
   478 
   390 void CIAUpdateSettingDialog::showPreviousView()
   479         default:
   391 {
   480             {
   392     // Save settings    
   481             item = new (ELeave) CAknSettingItem( aSettingId );
   393     TRAPD(err,  saveSettingsL()); 
   482             break;
   394     qt_symbian_throwIfError(err);
   483             }
   395     
   484         }
   396     // Switch view
   485     CleanupStack::PopAndDestroy( cenrep ); 
   397     emit toMainView();
   486     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSettingItemList::CreateSettingItemL end");
   398 }
   487     return item;
   399 
   488     }
   400 void CIAUpdateSettingDialog::activated(const QModelIndex& index)
   489 
   401 {
   490 
   402     if ( this->isActiveWindow() && index.row() == 0 )
   491 // -----------------------------------------------------------------------------
   403         {
   492 // CIAUpdateSettingItemList::LoadSettingsL
   404         }
   493 // 
   405 
   494 // -----------------------------------------------------------------------------
   406 }
   495 //
       
   496 void CIAUpdateSettingItemList::LoadSettingsL()
       
   497     {
       
   498     CAknSettingItemList::LoadSettingsL();
       
   499     }
       
   500 
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // CIAUpdateSettingItemList::EditItemL
       
   504 // 
       
   505 // -----------------------------------------------------------------------------
       
   506 //
       
   507 void CIAUpdateSettingItemList::EditItemL( TInt aIndex, TBool aCalledFromMenu )
       
   508     {
       
   509     CAknSettingItemList::EditItemL( aIndex, aCalledFromMenu );
       
   510     }
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // CIAUpdateSettingItemList::SetAttribute
       
   514 // 
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 
       
   518 // -----------------------------------------------------------------------------
       
   519 // CIAUpdateSettingItemList::Attribute
       
   520 // 
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 TInt CIAUpdateSettingItemList::Attribute( TInt aKey )
       
   524     {
       
   525     TInt ret = KErrNotFound;
       
   526     
       
   527     switch ( aKey )
       
   528         {
       
   529         case CIAUpdateSettingDialog::EAccessPoint:
       
   530             {
       
   531             ret = iAccessPoint;
       
   532             break;
       
   533             }
       
   534         case CIAUpdateSettingDialog::EAutoUpdateCheck:
       
   535             {
       
   536             ret = iAutoUpdateCheck;
       
   537             break;
       
   538             }
       
   539         default:
       
   540             {
       
   541             IAUpdateDialogUtil::Panic( KErrNotSupported );
       
   542             break;
       
   543             }
       
   544         }
       
   545         
       
   546     return ret;
       
   547     }
       
   548 
       
   549 
       
   550 // -----------------------------------------------------------------------------
       
   551 // CIAUpdateSettingItemList::CheckSettings
       
   552 // 
       
   553 // -----------------------------------------------------------------------------
       
   554 //
       
   555 void CIAUpdateSettingItemList::CheckSettings()
       
   556     {
       
   557     if ( iAutoUpdateCheck != EIAUpdateSettingValueDisable &&
       
   558          iAutoUpdateCheck != EIAUpdateSettingValueDisableWhenRoaming &&
       
   559          iAutoUpdateCheck != EIAUpdateSettingValueEnable )
       
   560         {
       
   561         iAutoUpdateCheck = EIAUpdateSettingValueEnable;
       
   562         }
       
   563     }
       
   564 
       
   565 
       
   566 
       
   567 /******************************************************************************
       
   568  * class CIAUpdateAccessPointSettingItem
       
   569  ******************************************************************************/
       
   570 
       
   571 // -----------------------------------------------------------------------------
       
   572 // CIAUpdateAccessPointSettingItem::NewL
       
   573 //
       
   574 // -----------------------------------------------------------------------------
       
   575 //
       
   576 CIAUpdateAccessPointSettingItem* CIAUpdateAccessPointSettingItem::NewL(
       
   577                    TInt aSettingId, TInt& aAccessPointId )
       
   578     {
       
   579     CIAUpdateAccessPointSettingItem* item = 
       
   580     new (ELeave) CIAUpdateAccessPointSettingItem( aSettingId, aAccessPointId );
       
   581     CleanupStack::PushL(item);
       
   582     item->ConstructL();
       
   583     CleanupStack::Pop(item);
       
   584     return item;
       
   585 	}
       
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 // CIAUpdateAccessPointSettingItem::CIAUpdateAccessPointSettingItem
       
   589 //
       
   590 // -----------------------------------------------------------------------------
       
   591 //
       
   592 CIAUpdateAccessPointSettingItem::CIAUpdateAccessPointSettingItem( 
       
   593                                  TInt aSettingId, TInt& aAccessPointId )
       
   594 :   CAknSettingItem( aSettingId ), 
       
   595     iAccessPointId ( aAccessPointId )
       
   596     {
       
   597     }
       
   598 
       
   599 
       
   600 // -----------------------------------------------------------------------------
       
   601 // CIAUpdateAccessPointSettingItem::~CIAUpdateAccessPointSettingItem
       
   602 // 
       
   603 // -----------------------------------------------------------------------------
       
   604 //
       
   605 CIAUpdateAccessPointSettingItem::~CIAUpdateAccessPointSettingItem()
       
   606     {
       
   607     delete iSettingText;
       
   608     delete iApHandler;
       
   609     }
       
   610 
       
   611 
       
   612 // -----------------------------------------------------------------------------
       
   613 // CIAUpdateAccessPointSettingItem::ConstructL
       
   614 //
       
   615 // -----------------------------------------------------------------------------
       
   616 //
       
   617 void CIAUpdateAccessPointSettingItem::ConstructL()
       
   618     {
       
   619     iApHandler = CIAUpdateAccessPointHandler::NewL();
       
   620      
       
   621     if ( iAccessPointId == 0 )
       
   622         {
       
   623     	iApHandler->GetDefaultConnectionLabelL( iSettingText );
       
   624         }
       
   625     else
       
   626         {
       
   627         TRAPD( err, iApHandler->GetApNameL( iAccessPointId, iSettingText ) );
       
   628         if ( err == KErrNotFound )
       
   629             { // destination stored by IAD may be removed
       
   630             iAccessPointId = 0;
       
   631             iApHandler->GetDefaultConnectionLabelL( iSettingText );
       
   632             }
       
   633         else
       
   634             {
       
   635             User::LeaveIfError( err );
       
   636             }
       
   637         }
       
   638     } 
       
   639 
       
   640 
       
   641 // -----------------------------------------------------------------------------
       
   642 // CIAUpdateAccessPointSettingItem::EditItemL
       
   643 // 
       
   644 // -----------------------------------------------------------------------------
       
   645 //
       
   646 void CIAUpdateAccessPointSettingItem::EditItemL( TBool /*aCalledFromMenu*/ )
       
   647     {
       
   648     EditAccessPointItemL();
       
   649     }
       
   650 
       
   651 
       
   652 // -----------------------------------------------------------------------------
       
   653 // CIAUpdateAccessPointSettingItem::SettingTextL
       
   654 // 
       
   655 // -----------------------------------------------------------------------------
       
   656 //
       
   657 const TDesC& CIAUpdateAccessPointSettingItem::SettingTextL()
       
   658     {
       
   659     if ( !iSettingText )
       
   660         {
       
   661     	return CAknSettingItem::SettingTextL();
       
   662         }
       
   663     else if ( iSettingText->Length() == 0 )
       
   664         {
       
   665         return CAknSettingItem::SettingTextL();
       
   666         }
       
   667         
       
   668     return *iSettingText;
       
   669     }
       
   670 
       
   671 
       
   672 //------------------------------------------------------------------------------
       
   673 // CIAUpdateAccessPointSettingItem::EditAccessPointItemL
       
   674 //
       
   675 //------------------------------------------------------------------------------
       
   676 //	
       
   677 TBool CIAUpdateAccessPointSettingItem::EditAccessPointItemL()
       
   678     {
       
   679 	TInt itemUid = iAccessPointId;
       
   680 	
       
   681 	TInt ret = KErrNone;
       
   682 	
       
   683 	delete iSettingText;
       
   684 	iSettingText = NULL;
       
   685 	TRAPD( err, ret = iApHandler->ShowApSelectDialogL( itemUid, iSettingText ) );
       
   686 	
       
   687 	if ( err != KErrNone )
       
   688 	    {
       
   689 	    iAccessPointId = KErrNotFound;
       
   690 	    UpdateListBoxTextL(); // from CAknSettingItem
       
   691 	    return EFalse;
       
   692 	    }
       
   693 	
       
   694 	if ( ret == CIAUpdateAccessPointHandler::EDialogSelect )
       
   695 		{
       
   696 		iAccessPointId = itemUid;
       
   697  	    UpdateListBoxTextL(); // from CAknSettingItem
       
   698 	    return ETrue;
       
   699 		}
       
   700 		
       
   701 	return EFalse;
       
   702     }
       
   703 
       
   704 	
       
   705 //  End of File