supl/locationomasuplprotocolhandler/protocolhandlerver1/src/epos_comasuplsettingslauncher.cpp
changeset 51 111f80460dbe
parent 46 df1a0df61209
equal deleted inserted replaced
46:df1a0df61209 51:111f80460dbe
     1 /*
       
     2 * Copyright (c) 2002-2004 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:   Active object wrapper for launching Settings UI
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <e32std.h>
       
    24 #include <e32svr.h>
       
    25 #include <e32base.h>
       
    26 #include <AknNotifierWrapper.h>
       
    27 #include <commdb.h>                 // CommsDatabase                                    
       
    28 #include <cmapplicationsettingsui.h>// Access Point Configurator
       
    29 #include <cmplugincsddef.h>			// For UID of CSD BearerType
       
    30 #include <cmpluginpacketdatadef.h>	// For UID of Packet data BearerType
       
    31 #include <cmmanager.h>				// For Conversion from UID to Name and Name to UID 
       
    32 #include <cmconnectionmethod.h> 	// For Conversion from UID to Name and Name to UID
       
    33 
       
    34 #include <locsettingsuiclient.h>
       
    35 
       
    36 #include "epos_comasupltrace.h"
       
    37 #include "epos_comasuplsettingslauncher.h"
       
    38 
       
    39 _LIT(KTraceFileName,"SUPL_OMA_SESSION::EPos_COMASuplSettingsLauncher.cpp");
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // COMASuplSettingsLauncher::COMASuplSettingsLauncher
       
    45 // C++ constructor can NOT contain any code, that
       
    46 // might leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 COMASuplSettingsLauncher::COMASuplSettingsLauncher(MOMASuplUISettingsObserver& aCallback)
       
    50     : CActive(EPriorityStandard),
       
    51     iCallback(aCallback)
       
    52     {
       
    53     CActiveScheduler::Add(this);
       
    54     }
       
    55 // -----------------------------------------------------------------------------
       
    56 // COMASuplSettingsLauncher::NewL
       
    57 // Two-phased constructor for single key listening.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 COMASuplSettingsLauncher* COMASuplSettingsLauncher::NewL(MOMASuplUISettingsObserver& aCallback)
       
    61     {
       
    62     COMASuplSettingsLauncher* newInstance = NewLC(aCallback);
       
    63     CleanupStack::Pop();
       
    64     return newInstance;
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // COMASuplSettingsLauncher::NewLC
       
    69 // Two-phased constructor for single key listening. Leaves instance to cleanup stack
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 COMASuplSettingsLauncher* COMASuplSettingsLauncher::NewLC(MOMASuplUISettingsObserver& aCallback)
       
    73     {
       
    74     // check for NULL references.
       
    75 
       
    76     if ( !&aCallback)    
       
    77     {
       
    78         User::Leave(KErrArgument);
       
    79     }
       
    80 
       
    81 	COMASuplSettingsLauncher* newInstance = new (ELeave) COMASuplSettingsLauncher( aCallback);
       
    82 	CleanupStack::PushL( newInstance );
       
    83 	newInstance->ConstructL();
       
    84 
       
    85 	return newInstance;
       
    86     }
       
    87 
       
    88 // Destructor
       
    89 COMASuplSettingsLauncher::~COMASuplSettingsLauncher()
       
    90     {
       
    91     Cancel();
       
    92     delete iSettingsLauncher;	
       
    93     iNotifier.Close();
       
    94     delete iTrace;
       
    95     iIapSelector.Close();
       
    96     }
       
    97 
       
    98 
       
    99 void COMASuplSettingsLauncher::ConstructL()
       
   100     {
       
   101     iTrace = COMASuplTrace::NewL();	
       
   102     iTrace->Trace(_L("COMASuplSettingsLauncher::ConstructL"), KTraceFileName, __LINE__);             
       
   103     iSettingsLauncher = CLocSettingsUiClient::NewL();
       
   104 	User::LeaveIfError(iNotifier.Connect());
       
   105 	    // Establish a connection to the RGenConAgentDialogServer
       
   106     User::LeaveIfError( iIapSelector.Connect());
       
   107     
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // COMASuplSettingsLauncher::LaunchSettings
       
   112 // If already active, just return. Order notification otherwise and set active.
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 TInt COMASuplSettingsLauncher::LaunchSettings()
       
   116     {
       
   117     if(IsActive() && iDialogType == ESUPLTimeoutDialog)
       
   118         {
       
   119         Cancel();
       
   120         }
       
   121    else if( IsActive() && iDialogType != ESUPLTimeoutDialog)
       
   122         {
       
   123         return KErrInUse;
       
   124         }
       
   125    
       
   126 	TRAPD(error,iSettingsLauncher->LaunchSettingsUiL( TUid::Uid( KLocSUPLSettingsUID ),
       
   127 													  ELocSUPLIAPSelection,
       
   128 													  iStatus ));
       
   129 
       
   130 	iDialogType = ESUPLYesNoDialog;
       
   131 	SetActive();
       
   132 	
       
   133     return error;
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // COMASuplSettingsLauncher::CancelLaunch
       
   138 // If active, cancel.
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void COMASuplSettingsLauncher::CancelLaunch()
       
   142     {
       
   143     if(IsActive())
       
   144         {
       
   145         Cancel();
       
   146         }
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // COMASuplSettingsLauncher::RunL
       
   151 // Handle notification from CenRep session.
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void COMASuplSettingsLauncher::RunL()
       
   155     {
       
   156     // Handle notification  
       
   157     
       
   158     if(iDialogType == ESUPLYesNoDialog )
       
   159     	{
       
   160     		if(iStatus.Int() == KErrNone)
       
   161     			{
       
   162 				LaunchIAPDialog();//Launch IAP Dialog
       
   163     			}
       
   164     		else
       
   165     			{
       
   166     				iCallback.SettingsUICompletedL(iStatus.Int()); // Handle notification	
       
   167     			}	
       
   168     	}
       
   169     else if(iDialogType == ESUPLIAPDialog)
       
   170     	{
       
   171     		iCallback.SettingsUICompletedL(iStatus.Int()); // Handle notification	
       
   172     	}
       
   173     	  
       
   174     else
       
   175     if(iDialogType == ESUPLUsageDialog)		  	
       
   176     	iCallback.SettingsUsageUICompletedL(iStatus.Int()); // Handle notification	
       
   177     else
       
   178     if(iDialogType == ESUPLTimeoutDialog)		  	
       
   179     	iCallback.SettingsTimeOutUICompletedL(iStatus.Int()); // Handle notification	
       
   180     }
       
   181     
       
   182 // -----------------------------------------------------------------------------
       
   183 // COMASuplSettingsLauncher::RunError
       
   184 // Handle error from CenRep session.
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 TInt COMASuplSettingsLauncher::RunError(TInt aError)
       
   188     {
       
   189     if(iDialogType == ESUPLIAPDialog)
       
   190         {
       
   191         TRAP_IGNORE(iCallback.SettingsUICompletedL(aError));    
       
   192         }
       
   193     else
       
   194      if(iDialogType == ESUPLUsageDialog)	
       
   195         {
       
   196         TRAP_IGNORE(iCallback.SettingsUsageUICompletedL(aError));	
       
   197         }
       
   198      if(iDialogType == ESUPLTimeoutDialog)	
       
   199         {
       
   200         TRAP_IGNORE(iCallback.SettingsTimeOutUICompletedL(aError));	
       
   201         }
       
   202      return KErrNone;
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // COMASuplSettingsLauncher::DoCancel
       
   207 // Handle cancel order on this active object.
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void COMASuplSettingsLauncher::DoCancel()
       
   211     {
       
   212     if(IsActive())
       
   213     	{
       
   214         if(iDialogType == ESUPLIAPDialog)
       
   215             {
       
   216             iSettingsLauncher->CancelLaunchedSettingsUi();		
       
   217             }
       
   218             else
       
   219             if(iDialogType == ESUPLTimeoutDialog)
       
   220             {
       
   221             iNotifier.CancelNotifier(KNotifier3Uid);	
       
   222             }
       
   223             else
       
   224             {
       
   225             if (iRoaming)                     
       
   226                 iNotifier.CancelNotifier(KNotifier2Uid);		
       
   227             else
       
   228                 iNotifier.CancelNotifier(KNotifier1Uid);		
       
   229             }                
       
   230     	}    
       
   231     }
       
   232 
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // COMASuplSettingsLauncher::LaunchSettings
       
   236 // If already active, just return. Order notification otherwise and set active.
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 TInt COMASuplSettingsLauncher::LaunchSuplUsageSettingsUI(TBool aRoaming)
       
   240     {
       
   241     if(IsActive())
       
   242         {
       
   243         return KErrInUse;
       
   244         } 
       
   245 
       
   246 	iDialogType = ESUPLUsageDialog;   
       
   247 
       
   248     if (aRoaming)    
       
   249         {            
       
   250         iTrace->Trace(_L("COMASuplSettingsLauncher::LaunchSuplUsage, user is roaming"),KTraceFileName, __LINE__);
       
   251         //SMP Changes
       
   252 		iRoaming = ETrue;
       
   253 	    iNotifier.StartNotifierAndGetResponse( iStatus, KNotifier2Uid, buffer1, buffer2 );        
       
   254         }
       
   255     else
       
   256         {            
       
   257         iTrace->Trace(_L("COMASuplSettingsLauncher::LaunchSuplUsage, user is not roaming"),KTraceFileName, __LINE__);
       
   258 		//SMP Changes
       
   259 	    iNotifier.StartNotifierAndGetResponse( iStatus, KNotifier1Uid, buffer1, buffer2 );
       
   260         iRoaming = EFalse;
       
   261         }
       
   262 	SetActive();        
       
   263 
       
   264     return KErrNone;
       
   265     }
       
   266 
       
   267 TInt COMASuplSettingsLauncher::LaunchSessionTimeOutDialog()
       
   268     {
       
   269     if(IsActive())
       
   270         {
       
   271         Cancel();
       
   272         }
       
   273     iDialogType = ESUPLTimeoutDialog;  	
       
   274     iTrace->Trace(_L("COMASuplSettingsLauncher::LaunchSessionTimeOutDialog"),KTraceFileName, __LINE__);
       
   275     iNotifier.StartNotifierAndGetResponse( iStatus, KNotifier3Uid, buffer1, buffer2 );
       
   276     SetActive();
       
   277     return KErrNone;
       
   278     }
       
   279     
       
   280 // -----------------------------------------------------------------------------
       
   281 // COMASuplSettingsLauncher::LaunchIAPDialog
       
   282 // If already active, just return. Order notification otherwise and set active.
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 
       
   286 TInt COMASuplSettingsLauncher::LaunchIAPDialog()
       
   287 	{
       
   288 	    if(IsActive())
       
   289         {
       
   290         return KErrInUse;
       
   291         } 
       
   292         
       
   293 	iDialogType = ESUPLIAPDialog;   
       
   294 
       
   295     TConnectionPrefs    prefs; // filtering conditions for the access points list
       
   296     prefs.iRank         = 1;
       
   297     prefs.iDirection    = ECommDbConnectionDirectionOutgoing;
       
   298     prefs.iBearerSet    = KUidCSDBearerType | KUidPacketDataBearerType;
       
   299    
       
   300     // Launch the IAP Selector 
       
   301     iStatus = KRequestPending;
       
   302     iIapSelector.IapConnection( iSelectedIap, prefs, iStatus );
       
   303     SetActive();
       
   304 		return KErrNone;
       
   305 	}
       
   306 	
       
   307 	
       
   308 TInt COMASuplSettingsLauncher::GetIAPName(TDes& aIAPName,TUint32& aIAPId)	
       
   309 	{
       
   310 	    TRAPD( error, ConvertIAPIdtoNameL( iSelectedIap,aIAPName ));
       
   311 	    aIAPId = iSelectedIap;
       
   312 		return error;
       
   313 	}
       
   314 	
       
   315 // ---------------------------------------------------------------------------
       
   316 // TUint CLocSUPLSettingsUiEngine::ConvertIAPIdtoNameL()
       
   317 // Convert IAP ID to IAP Name. If a valid name exists for the IAP Id
       
   318 // then the name would be copied into the aIAPName field
       
   319 // 
       
   320 // @param   aIAPId      The IAP Id of the Access point
       
   321 // @param   aIAPName    The name field corresponding to the Access
       
   322 //                      point. 
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 void COMASuplSettingsLauncher::ConvertIAPIdtoNameL( const TUint    aIAPId,
       
   326                                                          TDes&    aIAPName )
       
   327     {
       
   328     // Create the ApSelect handle
       
   329     CCommsDatabase* commdb = CCommsDatabase::NewL();
       
   330     CleanupStack::PushL( commdb );
       
   331     
       
   332     // Open the IAP table on the IAP Field
       
   333     CCommsDbTableView* table = commdb->OpenViewMatchingUintLC( TPtrC( IAP ), 
       
   334                                                                TPtrC( COMMDB_ID ),
       
   335                                                                aIAPId );
       
   336     User::LeaveIfError( table->GotoFirstRecord() );
       
   337     table->ReadTextL( TPtrC( COMMDB_NAME ), aIAPName );
       
   338 
       
   339     // Pop and Destroy all the local objects                                                           
       
   340     CleanupStack::PopAndDestroy( table );
       
   341     CleanupStack::PopAndDestroy( commdb );
       
   342     }
       
   343 	
       
   344 // End of File