sipplugins/sippsipsettingsui/src/sipsettlistsipprofsetmodel.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2005 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:  The model of the profile setting view
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include    "sipsettlistsipprofsetmodel.h"
       
    22 #include    "gssipmodel.h"
       
    23 #include    "tsipsettingsdata.h"
       
    24 #include    "mgssipprofilehandler.h"
       
    25 #include    "gssippanics.h"
       
    26 #include    <aknsettingitemlist.h>
       
    27 #include    <commdb.h>
       
    28 #include    <eikenv.h>
       
    29 #include    <eikappui.h>
       
    30 #include    <StringLoader.h>
       
    31 #include    <gssipsettingspluginrsc.rsg> //GUI Resource
       
    32 #include    <featmgr.h>
       
    33 #include    <cmmanager.h>
       
    34 #include    <cmdestination.h>
       
    35 #include    <cmconnectionmethoddef.h>
       
    36 #include    "gssippluginlogger.h"
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CSIPSettListSIPProfSetModel::CSIPSettListSIPProfSetModel
       
    42 // C++ default constructor can NOT contain any code, that
       
    43 // might leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CSIPSettListSIPProfSetModel::CSIPSettListSIPProfSetModel(
       
    47     MGSSIPProfileHandler* aHandler ) :
       
    48     iHandler( aHandler ),
       
    49     iLocked( EFalse )
       
    50     { 
       
    51     __GSLOGSTRING("CSIPSettListSIPProfSetModel::CSIPSettListSIPProfSetModel" )
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CSIPSettListSIPProfSetModel::ConstructL
       
    56 // Symbian 2nd phase constructor can leave.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 void CSIPSettListSIPProfSetModel::ConstructL()
       
    60     {
       
    61     __GSLOGSTRING("CSIPSettListSIPProfSetModel::ConstructL" )
       
    62     iProfileData = iHandler->ProfileData();
       
    63     // Find right profile from SIP profile array.
       
    64     CArrayPtr<CSIPManagedProfile>* list = iHandler->ProfileArray();
       
    65     for ( TInt i = 0; i < list->Count(); i++ )
       
    66         {
       
    67         TUint32 profileId ( KErrNone );
       
    68         list->At( i )->GetParameter( KSIPProfileId, profileId );
       
    69         if ( profileId == iProfileData->iID )
       
    70             {
       
    71              // Get SIP profile lock information.
       
    72             list->At( i )->GetParameter( KSIPProfileLocked, iLocked );
       
    73             list->At( i )->GetParameter( KSIPProfileRegistered, iRegistered );
       
    74             if ( iLocked && iRegistered )
       
    75                 {
       
    76                 list->At( i )->GetParameter( KSIPAccessPointId, 
       
    77                                         iProfileData->iAPIndex );
       
    78                 }
       
    79             }
       
    80         }
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CSIPSettListSIPProfSetModel::NewL
       
    85 // Two-phased constructor.
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 CSIPSettListSIPProfSetModel* CSIPSettListSIPProfSetModel::NewL(
       
    89     MGSSIPProfileHandler* aHandler )
       
    90     {
       
    91     __GSLOGSTRING("CSIPSettListSIPProfSetModel::NewL" )
       
    92     CSIPSettListSIPProfSetModel* self = 
       
    93         new ( ELeave ) CSIPSettListSIPProfSetModel( aHandler );
       
    94     
       
    95     CleanupStack::PushL( self );
       
    96     self->ConstructL();
       
    97     CleanupStack::Pop( self );
       
    98 
       
    99     return self;
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CSIPSettListSIPProfSetModel::~CSIPSettListSIPProfSetModel   
       
   104 // Destructor
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 CSIPSettListSIPProfSetModel::~CSIPSettListSIPProfSetModel()
       
   108     {
       
   109     __GSLOGSTRING("CSIPSettListSIPProfSetModel::~CSIPSettListSIPProfSetModel" )
       
   110     if ( iTypeInfo )
       
   111         {
       
   112         iTypeInfo->Close();
       
   113         delete iTypeInfo;
       
   114         }
       
   115 	iAPsUIDs.Close();
       
   116 	iSNAPUIDs.Close();
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CSIPSettListSIPProfSetModel::Settings()
       
   121 // Fetches settings of the modified profile
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 TSIPSettingsData& CSIPSettListSIPProfSetModel::Settings()    
       
   125     {
       
   126     return *iProfileData;    
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CSIPSettListSIPProfSetModel::GetAPListL
       
   131 // Fetches Access Point settings
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void CSIPSettListSIPProfSetModel::GetAPListL( 
       
   135     CArrayPtr<CAknEnumeratedText>* aArray,
       
   136     TInt& aIndex )
       
   137     {
       
   138     __GSLOGSTRING("CSIPSettListSIPProfSetModel::GetAPListL Start" )
       
   139     using namespace CMManager;
       
   140     TInt i( 0 );
       
   141     iAPsUIDs.Reset();
       
   142 
       
   143     RCmManager cmManager;
       
   144     cmManager.OpenL();
       
   145     CleanupClosePushL( cmManager );
       
   146 
       
   147     RArray< TUint32 > connectionMethodsIds;
       
   148     CleanupClosePushL( connectionMethodsIds );
       
   149     TBool checkBearerType(ETrue);
       
   150     TBool legacyOnly(EFalse);
       
   151     TBool easyWlan(EFalse);
       
   152     cmManager.ConnectionMethodL( connectionMethodsIds,
       
   153     							 checkBearerType,
       
   154     							 legacyOnly,
       
   155     							 easyWlan );
       
   156     
       
   157     for( i = 0; i < connectionMethodsIds.Count(); i++ )
       
   158         {                
       
   159         // New
       
   160         TUint32 iapId = connectionMethodsIds[i];
       
   161         HBufC* apName = 
       
   162             cmManager.GetConnectionMethodInfoStringL( iapId, ECmName );
       
   163         CleanupStack::PushL( apName );
       
   164         // Add Access Point name to enumerated text list.
       
   165         CAknEnumeratedText* item = 
       
   166             new( ELeave )CAknEnumeratedText( i, apName );
       
   167         CleanupStack::Pop( apName ); // Ownership is transferred to item    
       
   168         CleanupStack::PushL( item );
       
   169         aArray->AppendL( item );
       
   170         CleanupStack::Pop( item );
       
   171         
       
   172         // Add Access Point id to id list.
       
   173         iAPsUIDs.AppendL( iapId );        
       
   174         }
       
   175         
       
   176     CleanupStack::PopAndDestroy(); // connectionMethodsId
       
   177     CleanupStack::PopAndDestroy(); // cmManager       
       
   178     
       
   179     // Get LAN AP's also if we are under emulator environment.        
       
   180     #ifdef __WINS__
       
   181     CCommsDatabase* db = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
   182     CleanupStack::PushL( db );
       
   183     CCommsDbTableView* table = db->OpenIAPTableViewMatchingBearerSetLC(
       
   184         KCommDbBearerLAN, ECommDbConnectionDirectionOutgoing );
       
   185     TInt error = table->GotoFirstRecord();
       
   186     while ( error == KErrNone )
       
   187         {
       
   188         TUint32 id( 0 );
       
   189         TPtrC ptr( COMMDB_ID );
       
   190         TPtrC ptr2( COMMDB_NAME );
       
   191     
       
   192         // Get AP id and name from CommsDB.
       
   193         table->ReadUintL( ptr, id );
       
   194         
       
   195         if ( iAPsUIDs.Find( id ) < 0 )
       
   196             {
       
   197             // AP not in the list yet        
       
   198             HBufC* txt = table->ReadLongTextLC( ptr2 );
       
   199 
       
   200             CAknEnumeratedText* item = 
       
   201                 new( ELeave )CAknEnumeratedText( i, txt );
       
   202             CleanupStack::Pop( txt );    // ownership of txt changes to item
       
   203             CleanupStack::PushL( item );
       
   204             aArray->AppendL( item );
       
   205             CleanupStack::Pop( item );
       
   206         
       
   207             // Add Access Point id to id list. 
       
   208             iAPsUIDs.AppendL( id );
       
   209             }
       
   210 
       
   211         error = table->GotoNextRecord();
       
   212         i++;    // To next enumeration
       
   213         }
       
   214     CleanupStack::PopAndDestroy( table );
       
   215     CleanupStack::PopAndDestroy( db );
       
   216     #endif  //  __WINS__    
       
   217     
       
   218     // Loop through the list to find seleced profile.
       
   219 	for ( TInt j = 0; j < iAPsUIDs.Count(); j++ )
       
   220 		{
       
   221 		if ( iProfileData->iAPIndex == TInt( iAPsUIDs[j] ) )
       
   222 			{
       
   223 			// Set the currently active access point
       
   224 			aIndex = j;
       
   225 			}
       
   226 		}   
       
   227     __GSLOGSTRING("CSIPSettListSIPProfSetModel::GetAPListL End" )
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CSIPSettListSIPProfSetModel::GetDestinationsListL
       
   232 // Fetches destinations settings
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CSIPSettListSIPProfSetModel::GetDestinationsListL( 
       
   236     CArrayPtr<CAknEnumeratedText>* aArray,
       
   237     TInt& aIndex )
       
   238     {
       
   239     __GSLOGSTRING("CSIPSettListSIPProfSetModel::GetDestinationsListL Start" )
       
   240     iSNAPUIDs.Reset();
       
   241 
       
   242     RCmManager cmManager;
       
   243     cmManager.OpenL();
       
   244     CleanupClosePushL(cmManager);
       
   245     
       
   246     RArray<TUint32> destinations;
       
   247     CleanupClosePushL(destinations);
       
   248     cmManager.AllDestinationsL(destinations);
       
   249     
       
   250     RCmDestination destination;
       
   251     HBufC *destinationName;
       
   252     
       
   253     for( TInt i = 0; i < destinations.Count(); i++)
       
   254         {
       
   255         destination = cmManager.DestinationL(destinations[i]);
       
   256         CleanupClosePushL(destination);
       
   257         
       
   258         destinationName = destination.NameLC();
       
   259         CAknEnumeratedText* destItem = 
       
   260             new( ELeave )CAknEnumeratedText( i, destinationName );
       
   261         CleanupStack::PushL( destItem );
       
   262         aArray->AppendL( destItem );
       
   263         CleanupStack::Pop( destItem );
       
   264         TUint32 destId = destination.Id();
       
   265         iSNAPUIDs.Append( destId );
       
   266         CleanupStack::Pop( destinationName ); // Ownership is transferred to item    
       
   267         destinationName = NULL;
       
   268         CleanupStack::PopAndDestroy(); // destination
       
   269         }
       
   270     
       
   271     CleanupStack::PopAndDestroy(); // destinations
       
   272     CleanupStack::PopAndDestroy(); // cmManager
       
   273 
       
   274     // Loop through the list to find seleced profile.
       
   275 	for ( TInt j = 0; j < iSNAPUIDs.Count(); j++ )
       
   276 		{
       
   277 		if ( iProfileData->iSNAPIndex == TInt( iSNAPUIDs[j] ) )
       
   278 			{
       
   279 			// Set the currently active access point
       
   280 			aIndex = j;
       
   281 			}
       
   282 		}
       
   283     __GSLOGSTRING("CSIPSettListSIPProfSetModel::GetDestinationsListL End" )
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CSIPSettListSIPProfSetModel::GetTypeListL
       
   288 // Fetches Service type list settings
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 void CSIPSettListSIPProfSetModel::GetTypeListL( 
       
   292     CArrayPtr<CAknEnumeratedText>* aArray,
       
   293     TInt& aIndex )
       
   294     {
       
   295     __GSLOGSTRING("CSIPSettListSIPProfSetModel::GetTypeListL Start" )
       
   296     if ( iTypeInfo )
       
   297         {
       
   298         iTypeInfo->Close();
       
   299         delete iTypeInfo;
       
   300         iTypeInfo = NULL;
       
   301         }
       
   302 
       
   303     iTypeInfo = iHandler->TypeListL();       
       
   304 
       
   305     TInt i( 0 );
       
   306     TInt count( iTypeInfo->Count() );
       
   307 
       
   308     // Set aIndex to be the first item if no service profile is set
       
   309     aIndex = 0;    
       
   310     for ( i  = 0; i < count; i++ )
       
   311         { 
       
   312         TSIPProfileTypeInfo info = ProfileTypeInfo( i );
       
   313         if ( ( info.iSIPProfileName == 
       
   314                iProfileData->iServiceProfile.iSIPProfileName ) &&
       
   315              ( info.iSIPProfileClass == 
       
   316                iProfileData->iServiceProfile.iSIPProfileClass ) )
       
   317             {
       
   318             // Found the currently active index
       
   319             aIndex = i;
       
   320             }
       
   321         
       
   322         // Set correct names based on profile type.
       
   323         HBufC* profTxt = NULL;
       
   324         if ( info.iSIPProfileClass == TSIPProfileTypeInfo::EInternet )
       
   325             {
       
   326             profTxt = StringLoader::LoadLC( R_QTN_SIP_IETF );
       
   327             }
       
   328         else if ( info.iSIPProfileClass == TSIPProfileTypeInfo::EIms )
       
   329             {
       
   330             profTxt = StringLoader::LoadLC( R_QTN_SIP_THREE_GPP );
       
   331             }
       
   332         else
       
   333             {
       
   334             profTxt = HBufC::NewLC( KMaxServiceTypeName );
       
   335             profTxt->Des().Copy( ProfileTypeInfo( i ).iSIPProfileName );
       
   336             }    
       
   337         
       
   338         CAknEnumeratedText* item = 
       
   339             new ( ELeave ) CAknEnumeratedText( i, profTxt );
       
   340         CleanupStack::Pop( profTxt );
       
   341 
       
   342         CleanupStack::PushL( item );
       
   343         aArray->AppendL( item );        
       
   344         CleanupStack::Pop( item );
       
   345         }
       
   346     __GSLOGSTRING("CSIPSettListSIPProfSetModel::GetTypeListL End" )
       
   347     }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CSIPSettListSIPProfSetModel::ProviderNameLC
       
   351 // Returns the name of the service provider
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 HBufC* CSIPSettListSIPProfSetModel::ProviderNameLC()
       
   355     {
       
   356     HBufC* buf = iProfileData->iProviderName.AllocLC();
       
   357     return buf;
       
   358     }
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // CSIPSettListSIPProfSetModel::StoreServiceProfileSetting
       
   362 // Stores the service profile setting, i.e. matches the chosen
       
   363 // index to the TSIPProfileTypeInfo struct accordingly
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 void CSIPSettListSIPProfSetModel::StoreServiceProfileSetting()
       
   367     {
       
   368     iProfileData->iServiceProfile = 
       
   369         ProfileTypeInfo( iProfileData->iServiceProfileIndex );
       
   370     }
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // CSIPSettListSIPProfSetModel::ProfileTypeInfo
       
   374 // Returns the profile setting with the provided index.
       
   375 // -----------------------------------------------------------------------------
       
   376 TSIPProfileTypeInfo& CSIPSettListSIPProfSetModel::ProfileTypeInfo( TInt aIndex )
       
   377     {
       
   378     __GSLOGSTRING("CSIPSettListSIPProfSetModel::ProfileTypeInfo" )
       
   379 	TInt index;
       
   380 	if ( aIndex <= 0 )
       
   381 		{
       
   382 		index = 0;
       
   383 		}
       
   384 	else if ( iTypeInfo->Count() <= aIndex )
       
   385 		{
       
   386 		index = aIndex - 1;
       
   387 		}
       
   388 	else
       
   389 		{
       
   390 		index = aIndex;
       
   391 		}
       
   392     return ( (*iTypeInfo)[ index ] );
       
   393     }
       
   394 
       
   395 // -----------------------------------------------------------------------------
       
   396 // CSIPSettListSIPProfSetModel::SaveProfileL
       
   397 // Starts saving the modified settings
       
   398 // -----------------------------------------------------------------------------
       
   399 //
       
   400 void CSIPSettListSIPProfSetModel::SaveProfileL()
       
   401     {
       
   402     __GSLOGSTRING("CSIPSettListSIPProfSetModel::SaveProfileL" )
       
   403     StoreServiceProfileSetting();
       
   404     iHandler->SaveProfileL();   
       
   405     }
       
   406 
       
   407 // -----------------------------------------------------------------------------
       
   408 // CSIPSettListSIPProfSetModel::APUID
       
   409 // Returns Access Point UID based on the index
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 TUint32 CSIPSettListSIPProfSetModel::APUID( const TInt aIndex ) const
       
   413 	{
       
   414 	return iAPsUIDs[aIndex];
       
   415 	} 
       
   416 	
       
   417 // -----------------------------------------------------------------------------
       
   418 // CSIPSettListSIPProfSetModel::APUID
       
   419 // Returns Access Point UID
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 TUint32 CSIPSettListSIPProfSetModel::APUID( ) const
       
   423 	{
       
   424 	return iProfileData->iAPIndex;
       
   425 	} 
       
   426 	
       
   427 // -----------------------------------------------------------------------------
       
   428 // CSIPSettListSIPProfSetModel::SNAPUID
       
   429 // Returns SNAP UID based on the index
       
   430 // -----------------------------------------------------------------------------
       
   431 //
       
   432 TUint32 CSIPSettListSIPProfSetModel::SNAPUID( const TInt aIndex ) const
       
   433 	{
       
   434 	return iSNAPUIDs[aIndex];
       
   435 	} 
       
   436 
       
   437 // -----------------------------------------------------------------------------
       
   438 // CSIPSettListSIPProfSetModel::CheckDuplicateNameL
       
   439 // Checks that given name is not already exists.
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 TBool CSIPSettListSIPProfSetModel::CheckDuplicateNameL( TDes& aName )
       
   443 	{
       
   444     __GSLOGSTRING("CSIPSettListSIPProfSetModel::CheckDuplicateNameL" )
       
   445 	TBool ret( EFalse );
       
   446 	TBuf<KMaxSIPProviderNameLength> savedName ( KNullDesC );
       
   447 	savedName.Copy( aName );
       
   448 	iHandler->CheckDuplicateNameL( iProfileData->iID, aName );
       
   449 	
       
   450 	// Return ETrue if name unique.
       
   451 	if ( !savedName.Compare( aName ) )
       
   452 	    {
       
   453 	    ret = ETrue;
       
   454 	    }
       
   455 	    
       
   456 	return ret;    
       
   457 	} 
       
   458 
       
   459 // -----------------------------------------------------------------------------
       
   460 // CSIPSettListSIPProfSetModel::ProfileLocked
       
   461 // Checks is currently shown profile locked.
       
   462 // -----------------------------------------------------------------------------
       
   463 //    
       
   464 TBool CSIPSettListSIPProfSetModel::ProfileLocked()
       
   465     {
       
   466     return iLocked;
       
   467     }
       
   468     	
       
   469 // -----------------------------------------------------------------------------
       
   470 // CSIPSettListSIPProfSetModel::APLocked
       
   471 // Checks is SNAP is defined and so AP setting is locked.
       
   472 // -----------------------------------------------------------------------------
       
   473 //    
       
   474 TBool CSIPSettListSIPProfSetModel::APLocked()
       
   475     {
       
   476     return iAPLocked;
       
   477     }
       
   478     	
       
   479 // -----------------------------------------------------------------------------
       
   480 // CSIPSettListSIPProfSetModel::SetApLocked
       
   481 // SNAPid defined, lock AP setting.
       
   482 // -----------------------------------------------------------------------------
       
   483 //    
       
   484 void CSIPSettListSIPProfSetModel::SetApLocked()
       
   485     {
       
   486     iAPLocked = ETrue;
       
   487     }
       
   488 
       
   489 // ---------------------------------------------------------------------------
       
   490 // CSIPSettListSIPProfSetModel::IsRegistered
       
   491 // Profile registration status.
       
   492 // ---------------------------------------------------------------------------
       
   493 //
       
   494 TBool CSIPSettListSIPProfSetModel::IsRegistered()
       
   495 	{
       
   496 	return iRegistered;
       
   497 	}
       
   498 	
       
   499 // ---------------------------------------------------------------------------
       
   500 // CSIPSettListSIPProfSetModel::CleanAPUid
       
   501 // Remove defined AP UID .
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 void CSIPSettListSIPProfSetModel::CleanAPUid()
       
   505 	{
       
   506     iProfileData->iAPIndex = -1;
       
   507 	}
       
   508 	
       
   509 // -----------------------------------------------------------------------------
       
   510 // CSIPSettListSIPProfSetModel::DestinationsCountL
       
   511 // Gets the destinations count.
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 TInt CSIPSettListSIPProfSetModel::DestinationsCountL( )
       
   515     {
       
   516     __GSLOGSTRING("CSIPSettListSIPProfSetModel::DestinationsCountL" )
       
   517     TInt count = 0;
       
   518     
       
   519     RCmManager cmManager;
       
   520     cmManager.OpenL();
       
   521     CleanupClosePushL(cmManager);
       
   522     
       
   523     RArray<TUint32> destinations;
       
   524     CleanupClosePushL(destinations);
       
   525     cmManager.AllDestinationsL(destinations);
       
   526     
       
   527     count = destinations.Count();
       
   528     
       
   529     CleanupStack::PopAndDestroy(); // destinations
       
   530     CleanupStack::PopAndDestroy(); // cmManager
       
   531     
       
   532     return count;
       
   533     }
       
   534 //  End of File