presencesettingsui/src/psuigspluginmodel.cpp
branchRCL_3
changeset 35 fbd2e7cec7ef
equal deleted inserted replaced
34:2669f8761a99 35:fbd2e7cec7ef
       
     1 /*
       
     2 * Copyright (c) 2006-2010 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:    Presence settings UI model implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <escapeutils.h>
       
    23 #include <sipmanagedprofileregistry.h>
       
    24 #include <sipprofileregistryobserver.h>
       
    25 #include <sipmanagedprofile.h>
       
    26 #include <sipprofile.h>
       
    27 #include <StringLoader.h>
       
    28 #include <psuigspluginrsc.rsg>
       
    29 #include <XdmSettingsApi.h>
       
    30 #include <spentry.h>
       
    31 #include <spproperty.h>
       
    32 #include <spsettings.h>
       
    33 
       
    34 #include "psuigspluginmodel.h"
       
    35 
       
    36 // ========================= MEMBER FUNCTIONS ================================
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CPSUIGSPluginModel::CPSUIGSPluginModel()
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CPSUIGSPluginModel::CPSUIGSPluginModel()
       
    45     {
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CPSUIGSPluginModel::~CPSUIGSPluginModel()
       
    50 // Destructor
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CPSUIGSPluginModel::~CPSUIGSPluginModel()
       
    54     {
       
    55     delete iSIPEngine;
       
    56     if ( iSIPProfiles )
       
    57         {
       
    58         iSIPProfiles->ResetAndDestroy();
       
    59         delete iSIPProfiles;
       
    60         }     
       
    61         
       
    62     iXdmIdArray.Close();
       
    63     delete iXdmNameArray;
       
    64     
       
    65     iPSIdArray.Close();
       
    66     delete iPSNameArray;    
       
    67     delete iVisibleSettingName;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CPSUIGSPluginModel::ConstructL
       
    72 // Symbian 2nd phase constructor can leave.
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CPSUIGSPluginModel::ConstructL()
       
    76     {
       
    77     RetrieveSettingsL();
       
    78     ReadSipArrayFromEngineL();
       
    79     iVisibleSettingName = HBufC::NewL( 
       
    80         KPresSetNameMaxLength + 2 );// max chars + KColumnListSeparator
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CPSUIGSPluginModel::NewL()
       
    85 // Two-phased constructor.
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 CPSUIGSPluginModel* CPSUIGSPluginModel::NewL()
       
    89     {
       
    90     CPSUIGSPluginModel* self = new ( ELeave ) CPSUIGSPluginModel();
       
    91     CleanupStack::PushL( self );
       
    92     self->ConstructL();
       
    93     CleanupStack::Pop( self ); // self
       
    94     return self;
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CPSUIGSPluginModel::RetrieveSettingsL()
       
    99 // See header for details.
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 void CPSUIGSPluginModel::RetrieveSettingsL()
       
   103     {
       
   104     RefreshPSArraysL();
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CPSUIGSPluginModel::SaveSettingsL()
       
   109 // See header for details.
       
   110 // ---------------------------------------------------------------------------
       
   111 //    
       
   112 void CPSUIGSPluginModel::SaveSettingsL()
       
   113     {
       
   114     if ( iSettingId == 0 )
       
   115         {// new settings
       
   116         iSettingId = PresSettingsApi::CreateSetL( iSettingSet );
       
   117         }
       
   118     else
       
   119         {// old & edited settings
       
   120         PresSettingsApi::UpdateSetL( iSettingSet, iSettingId );
       
   121         }
       
   122     RefreshPSArraysL();
       
   123     }
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CPSUIGSPluginModel::CreateDefaultSettingsL()
       
   127 // See header for details.
       
   128 // ---------------------------------------------------------------------------
       
   129 //    
       
   130 void CPSUIGSPluginModel::CreateDefaultSettingsL()
       
   131     {
       
   132     iSettingId = 0; // new settings
       
   133     
       
   134     iSettingSet.iSetName.Zero();
       
   135     HBufC* name = CreateSettingNameLC();
       
   136     iSettingSet.iSetName.Append( *name );
       
   137     CleanupStack::PopAndDestroy( name );// name
       
   138     
       
   139     iSettingSet.iSipProfile = KErrNotFound;
       
   140     iSettingSet.iXDMSetting = KErrNotFound;
       
   141     iSettingSet.iObjectSize = KErrNotFound;
       
   142     iSettingSet.iContSrvrAdd.Zero();
       
   143     iSettingSet.iPublicationInt = KErrNotFound;
       
   144     iSettingSet.iMaxSubscriptions = KErrNotFound;
       
   145     iSettingSet.iMaxContactsInList = KErrNotFound;
       
   146     iSettingSet.iDomainSyntax.Zero();
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CPSUIGSPluginModel::DuplicateExistingSettingsL()
       
   151 // See header for details.
       
   152 // ---------------------------------------------------------------------------
       
   153 //    
       
   154 void CPSUIGSPluginModel::DuplicateExistingSettingsL( TInt aIndex )
       
   155     {
       
   156     __ASSERT_DEBUG( aIndex < iPSIdArray.Count() ,User::Panic( KPSUIGSPluginPanicCategory, KErrOverflow ));
       
   157     
       
   158     iSettingId = 0; // new settings
       
   159     TPresSettingsSet originalSettings;
       
   160     PresSettingsApi::SettingsSetL( iPSIdArray[ aIndex ], originalSettings );
       
   161     
       
   162     iSettingSet.iSetName.Zero();
       
   163     HBufC* name = CreateSettingNameLC( originalSettings.iSetName.AllocL() );
       
   164     iSettingSet.iSetName.Append( *name );
       
   165     CleanupStack::PopAndDestroy( name );// name
       
   166     
       
   167     iSettingSet.iSipProfile = originalSettings.iSipProfile;
       
   168     iSettingSet.iXDMSetting = originalSettings.iXDMSetting;
       
   169     iSettingSet.iObjectSize = originalSettings.iObjectSize;
       
   170     iSettingSet.iContSrvrAdd = originalSettings.iContSrvrAdd;
       
   171     iSettingSet.iPublicationInt = originalSettings.iPublicationInt;
       
   172     iSettingSet.iMaxSubscriptions = originalSettings.iMaxSubscriptions;
       
   173     iSettingSet.iMaxContactsInList = originalSettings.iMaxContactsInList;
       
   174     iSettingSet.iDomainSyntax = originalSettings.iDomainSyntax;
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CPSUIGSPluginModel::AllCompulsoryFieldsFilled()
       
   179 // See header for details.
       
   180 // ---------------------------------------------------------------------------
       
   181 //    
       
   182 TBool CPSUIGSPluginModel::AllCompulsoryFieldsFilled()
       
   183     {
       
   184     TBool returnValue = ETrue;
       
   185     for ( TInt i = EPSUIServerNameId ; i <= EPSUIDomainSyntaxId && returnValue ; i++ )
       
   186         {
       
   187         switch( i ) 
       
   188             {
       
   189             case EPSUIServerNameId:
       
   190                 returnValue = ( iSettingSet.iSetName.Length() != 0 );
       
   191                 break;
       
   192             case EPSUISIPProfileId:
       
   193                 returnValue = ( iSettingSet.iSipProfile != KErrNotFound );
       
   194                 break;
       
   195             case EPSUIObjectSizeId:
       
   196                 returnValue = ( iSettingSet.iObjectSize != KErrNotFound );
       
   197                 break;
       
   198             case EPSUIDomainSyntaxId:
       
   199                 returnValue = ( iSettingSet.iDomainSyntax.Length() != 0 );
       
   200                 break;
       
   201             default:
       
   202                 // do nothing with non-compulsory ones
       
   203                 break;
       
   204             }        
       
   205         }    
       
   206     return returnValue;
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // CPSUIGSPluginModel::IsItDuplicatePSName()
       
   211 // See header for details.
       
   212 // ---------------------------------------------------------------------------
       
   213 // 
       
   214 TBool CPSUIGSPluginModel::IsItDuplicatePSName()
       
   215     {
       
   216     TBool found = KErrNone;
       
   217     TInt pos = 0;
       
   218     found = ( iPSNameArray->Find( iSettingSet.iSetName, pos ) == KErrNone );
       
   219     if ( found )
       
   220         {// dupe found, let's check it's not the same setting
       
   221         __ASSERT_DEBUG( pos < iPSIdArray.Count() ,User::Panic( KPSUIGSPluginPanicCategory, KErrOverflow ));
       
   222         found = !( iSettingId == iPSIdArray[ pos ]);
       
   223         }
       
   224     return found;
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // CPSUIGSPluginModel::EditSettingsL()
       
   229 // See header for details.
       
   230 // ---------------------------------------------------------------------------
       
   231 // 
       
   232 void CPSUIGSPluginModel::EditSettingsL( TInt aIndex )
       
   233     {
       
   234     __ASSERT_DEBUG( aIndex < iPSIdArray.Count() ,User::Panic( KPSUIGSPluginPanicCategory, KErrOverflow ));
       
   235     TInt settingId = iPSIdArray[ aIndex ];
       
   236     PresSettingsApi::SettingsSetL( settingId, iSettingSet );
       
   237     iSettingId = settingId;
       
   238     }
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // CPSUIGSPluginModel::DeleteSettingsL()
       
   242 // See header for details.
       
   243 // ---------------------------------------------------------------------------
       
   244 // 
       
   245 void CPSUIGSPluginModel::DeleteSettingsL( TInt aToBeDeleted, TBool aIsIndex )
       
   246     {
       
   247     if ( aIsIndex )
       
   248         {// is index
       
   249         __ASSERT_DEBUG( aToBeDeleted < iPSIdArray.Count() ,
       
   250             User::Panic( KPSUIGSPluginPanicCategory, KErrOverflow ));
       
   251         PresSettingsApi::RemoveSetL( iPSIdArray[ aToBeDeleted ]);
       
   252         CleanServiceProviderSettingsDataL( iPSIdArray[ aToBeDeleted ] );
       
   253         }
       
   254     else
       
   255         {// is id
       
   256         PresSettingsApi::RemoveSetL( aToBeDeleted );
       
   257         CleanServiceProviderSettingsDataL( aToBeDeleted );
       
   258         }
       
   259     RefreshPSArraysL();
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // CPSUIGSPluginModel::RefreshPSArraysL()
       
   264 // See header for details.
       
   265 // ---------------------------------------------------------------------------
       
   266 // 
       
   267 void CPSUIGSPluginModel::RefreshPSArraysL()
       
   268     {
       
   269     delete iPSNameArray;
       
   270     iPSNameArray = NULL;
       
   271     iPSIdArray.Reset();
       
   272     
       
   273     iPSNameArray = PresSettingsApi::GetAllSetsNamesLC( iPSIdArray );
       
   274     CleanupStack::Pop( iPSNameArray );// iPSNameArray
       
   275     ReArrangePresenceSettingsL();
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CPSUIGSPluginModel::ReArrangePresenceSettingsL()
       
   280 // See header for details.
       
   281 // ---------------------------------------------------------------------------
       
   282 // 
       
   283 void CPSUIGSPluginModel::ReArrangePresenceSettingsL()
       
   284     {
       
   285     const TInt settingsCount = iPSNameArray->Count();
       
   286     __ASSERT_DEBUG( 
       
   287         settingsCount == iPSIdArray.Count(), 
       
   288         User::Panic( KPSUIGSPluginPanicCategory, KErrArgument ));
       
   289    
       
   290     // make a tables of the original pairs
       
   291     RPointerArray<CPSUINameIDPair> pairArray;
       
   292     TCleanupItem clItem( ResetAndDestroy, &pairArray );
       
   293     CleanupStack::PushL( clItem );
       
   294     CPSUINameIDPair* pair = NULL;
       
   295     for( TInt i = 0;i < settingsCount;i++ )
       
   296         {
       
   297         pair = new ( ELeave ) CPSUINameIDPair;
       
   298         CleanupStack::PushL( pair );
       
   299         pair->iID = iPSIdArray[ i ];
       
   300         pair->iName = iPSNameArray->MdcaPoint( i ).AllocL();
       
   301         pairArray.AppendL( pair );
       
   302         CleanupStack::Pop( pair );// pair is in array's responsibility now
       
   303         }
       
   304 
       
   305     // sort the original
       
   306     iPSNameArray->Sort( ECmpCollated );
       
   307     
       
   308     // re-arrange the iPSIdArray based on order of iPSNameArray
       
   309     iPSIdArray.Reset();
       
   310     for( TInt i = 0;i < settingsCount;i++ )
       
   311         {
       
   312         for( TInt ii = 0;ii < pairArray.Count();ii++ )
       
   313             {
       
   314             if ( !iPSNameArray->MdcaPoint( i ).Compare(  
       
   315                 *pairArray[ii]->iName ))
       
   316                 {
       
   317                 iPSIdArray.AppendL( pairArray[ii]->iID );
       
   318                 delete pairArray[ii];
       
   319                 pairArray.Remove(ii);
       
   320                 break;// no need to go through if already found
       
   321                 }
       
   322             }
       
   323         }
       
   324     CleanupStack::PopAndDestroy( &pairArray );
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // CPSUIGSPluginModel::CleanServiceProviderSettingsDataL()
       
   329 // See header for details.
       
   330 // ---------------------------------------------------------------------------
       
   331 // 
       
   332 void CPSUIGSPluginModel::CleanServiceProviderSettingsDataL( TInt aPresenceId )
       
   333     {
       
   334     CSPSettings* spSettings = CSPSettings::NewLC();
       
   335     
       
   336     RArray<TUint> serviceIds; 
       
   337     CleanupClosePushL( serviceIds );
       
   338     spSettings->FindServiceIdsL( serviceIds );
       
   339 	
       
   340     for ( TInt i( 0 ) ; i < serviceIds.Count() ; i++ )
       
   341         {
       
   342         CSPEntry* spEntry = CSPEntry::NewLC(); 
       
   343         CSPProperty* property1 = CSPProperty::NewLC();
       
   344 
       
   345         TInt err = spSettings->FindPropertyL( 
       
   346             serviceIds[ i ],
       
   347             ESubPropertyPresenceSettingsId,
       
   348             *property1 );
       
   349 
       
   350         if ( KErrNone == err )
       
   351             {           
       
   352             User::LeaveIfError(
       
   353                 spSettings->FindEntryL( serviceIds[ i ], *spEntry ) );
       
   354 				
       
   355             TInt presenceId( 0 );
       
   356             User::LeaveIfError( property1->GetValue( presenceId ) );
       
   357 			
       
   358             if ( presenceId == aPresenceId )
       
   359                 {
       
   360                 // Delete all presence related properties from services which
       
   361                 // has this presence id (ESubPropertyPresenceSettingsId).                  
       
   362                 RPropertyNameArray propertyNameArray;
       
   363                 CleanupClosePushL( propertyNameArray );
       
   364                 RPropertyNameArray propertyNameArrayToBeDeleted;
       
   365                 CleanupClosePushL( propertyNameArrayToBeDeleted );
       
   366                 
       
   367                 // presence properties to be removed if found
       
   368                 propertyNameArray.Append( EPropertyPCSPluginId );
       
   369                 propertyNameArray.Append( EPropertyPresenceSubServicePluginId );
       
   370                 propertyNameArray.Append( ESubPropertyPresenceSettingsId );
       
   371                 propertyNameArray.Append( ESubPropertyPresencePreferredSNAPId );
       
   372                 propertyNameArray.Append( ESubPropertyPresencePreferredIAPId );
       
   373                 propertyNameArray.Append( ESubPropertyPresencePresentityIDFieldType );
       
   374                 propertyNameArray.Append( ESubPropertyPresenceLaunchMethod );
       
   375                 propertyNameArray.Append( ESubPropertyPresenceLaunchUid );
       
   376                 propertyNameArray.Append( ESubPropertyPresenceAddrScheme );
       
   377                 propertyNameArray.Append( ESubPropertyPresenceEnabled );
       
   378                 propertyNameArray.Append( ESubPropertyPresenceRequestPreference );
       
   379 
       
   380                 for ( TInt j( 0 ) ; j < propertyNameArray.Count() ; j++ )
       
   381                     {
       
   382                     CSPProperty* property2 = CSPProperty::NewLC();
       
   383                 
       
   384                     TInt err = spSettings->FindPropertyL( 
       
   385                         serviceIds[ i ],
       
   386                         propertyNameArray[ j ],
       
   387                         *property2 );
       
   388 						
       
   389                     // if property found add to be deleted array
       
   390                     if ( !err )
       
   391                         {
       
   392                         propertyNameArrayToBeDeleted.Append( 
       
   393                             propertyNameArray[ j ] );
       
   394                         }
       
   395                         
       
   396                     CleanupStack::PopAndDestroy( property2 ); 
       
   397                     }
       
   398                 
       
   399                 spSettings->DeleteServicePropertiesL( 
       
   400                     serviceIds[ i ], propertyNameArrayToBeDeleted );
       
   401 
       
   402                 CleanupStack::PopAndDestroy( &propertyNameArrayToBeDeleted );
       
   403                 CleanupStack::PopAndDestroy( &propertyNameArray );
       
   404                 }
       
   405             }
       
   406         
       
   407         CleanupStack::PopAndDestroy( property1 );
       
   408         CleanupStack::PopAndDestroy( spEntry );
       
   409         }
       
   410     
       
   411     CleanupStack::PopAndDestroy( &serviceIds );
       
   412     CleanupStack::PopAndDestroy( spSettings );
       
   413     }
       
   414 
       
   415 // ---------------------------------------------------------------------------
       
   416 // CPSUIGSPluginModel::MdcaCount()
       
   417 // See header for details.
       
   418 // ---------------------------------------------------------------------------
       
   419 // 
       
   420 TInt CPSUIGSPluginModel::MdcaCount() const
       
   421     {
       
   422     return iPSNameArray->MdcaCount();
       
   423     }
       
   424 
       
   425 // ---------------------------------------------------------------------------
       
   426 // CPSUIGSPluginModel::MdcaPoint()
       
   427 // See header for details.
       
   428 // ---------------------------------------------------------------------------
       
   429 // 
       
   430 TPtrC16 CPSUIGSPluginModel::MdcaPoint( TInt aIndex ) const
       
   431     {
       
   432     TPtr tempText = iVisibleSettingName->Des();
       
   433     tempText.Zero();
       
   434     tempText.Append( KColumnListSeparator );
       
   435     tempText.Append( iPSNameArray->MdcaPoint( aIndex ));
       
   436 
       
   437     return tempText;
       
   438     }
       
   439 
       
   440 // ---------------------------------------------------------------------------
       
   441 // CPSUIGSPluginModel::CreateSettingNameLC()
       
   442 // See header for details.
       
   443 // ---------------------------------------------------------------------------
       
   444 // 
       
   445 HBufC* CPSUIGSPluginModel::CreateSettingNameLC( HBufC* aOriginalName )
       
   446     {
       
   447     _LIT( KPSUIGSPluginNumbering, "(%N)" );
       
   448     const TInt KPSUIFormattingExtraLength = 6;
       
   449     
       
   450     // prepare
       
   451     HBufC* settingName = aOriginalName ? 
       
   452         aOriginalName : 
       
   453         StringLoader::LoadL( R_QTN_PRESENCE_NAME_DEFAULT );
       
   454 
       
   455     if ( settingName->Length() + KPSUIFormattingExtraLength > KPresSetNameMaxLength )
       
   456         {//if there is no room for duplicate-numbering, let user take care of that when saving settings
       
   457         CleanupStack::PushL( settingName );
       
   458         return settingName;
       
   459         }
       
   460     
       
   461     settingName = settingName->ReAlloc( 
       
   462         settingName->Length() + KPSUIFormattingExtraLength );// enough for formatting
       
   463     CleanupStack::PushL( settingName );
       
   464     HBufC* tempSetName = NULL;
       
   465     TInt pos = 0;// used as dummy
       
   466     TInt found = 0;
       
   467     TInt index = 1;
       
   468     TPtr ptr = settingName->Des();
       
   469     
       
   470     // do the actual checking of name
       
   471     found = iPSNameArray->Find( *settingName, pos );
       
   472     while ( found == 0 )
       
   473         {
       
   474         if ( !tempSetName )
       
   475             {
       
   476             if ( aOriginalName )
       
   477                 {// aOriginalName given
       
   478                 tempSetName = GetPrefixL( settingName );
       
   479                 tempSetName = tempSetName->ReAlloc( 
       
   480                     tempSetName->Length() + KPSUIFormattingExtraLength );// enough for formatting
       
   481                 CleanupStack::PushL( tempSetName );
       
   482                 tempSetName->Des().Append( KPSUIGSPluginNumbering );
       
   483                 }
       
   484             else
       
   485                 {// aOriginalName not given
       
   486                 tempSetName = StringLoader::LoadLC( R_QTN_PRESENCE_NAME_DEFAULT_NUMBER );
       
   487                 }
       
   488             }
       
   489         StringLoader::Format( ptr, *tempSetName, -1, index );
       
   490         found = iPSNameArray->Find( *settingName, pos );
       
   491         index++;
       
   492         }
       
   493 
       
   494     // cleanup
       
   495     if ( tempSetName )
       
   496         {
       
   497         CleanupStack::PopAndDestroy( tempSetName ); //tempSetName
       
   498         }
       
   499 
       
   500     return settingName;    
       
   501     }
       
   502 
       
   503 // ---------------------------------------------------------------------------
       
   504 // CPSUIGSPluginModel::GetPrefixL()
       
   505 // See header for details.
       
   506 // ---------------------------------------------------------------------------
       
   507 // 
       
   508 HBufC* CPSUIGSPluginModel::GetPrefixL( HBufC* aName )
       
   509     {
       
   510     TPtrC prefix = aName->Des();
       
   511     TInt lastBrace = aName->LocateReverse('(');
       
   512     if ( lastBrace != KErrNotFound )
       
   513         {
       
   514         // aName looks like "<prefix><brace><something>".
       
   515         // See if <something> is an integer number and
       
   516         // <something> ends to a brace.
       
   517         TPtrC num = aName->Right( aName->Length() - lastBrace - 1 );
       
   518         TInt val;
       
   519         TLex lex( num );
       
   520         if ( lex.Val( val ) == KErrNone && num.Locate(')') == num.Length() - 1 )
       
   521             {
       
   522             // Yes, the trailer is an integer.
       
   523             prefix.Set( aName->Left( lastBrace ) );
       
   524             }
       
   525         }
       
   526     return prefix.AllocL();
       
   527     }
       
   528 
       
   529 // ---------------------------------------------------------------------------
       
   530 // CPSUIGSPluginModel::CurrentSettingName()
       
   531 // See header for details.
       
   532 // ---------------------------------------------------------------------------
       
   533 // 
       
   534 HBufC* CPSUIGSPluginModel::SettingNameLC( TInt aIndex )
       
   535     {
       
   536     return iPSNameArray->MdcaPoint( aIndex ).AllocLC();
       
   537     }
       
   538 
       
   539 // ---------------------------------------------------------------------------
       
   540 // CPSUIGSPluginModel::SettingNames()
       
   541 // See header for details.
       
   542 // ---------------------------------------------------------------------------
       
   543 // 
       
   544 CDesCArray* CPSUIGSPluginModel::SettingNames()
       
   545     {
       
   546     return iPSNameArray;// ownership stays in CPSUIGSPluginModel
       
   547     }
       
   548 
       
   549 // ---------------------------------------------------------------------------
       
   550 // CPSUIGSPluginModel::SettingsSet()
       
   551 // See header for details.
       
   552 // ---------------------------------------------------------------------------
       
   553 // 
       
   554 TPresSettingsSet& CPSUIGSPluginModel::SettingsSet()
       
   555     {
       
   556     return iSettingSet;
       
   557     }
       
   558 
       
   559 // ---------------------------------------------------------------------------
       
   560 // CPSUIGSPluginModel::ClearInvalidSIPAndXDMSettingsL()
       
   561 // See header for details.
       
   562 // ---------------------------------------------------------------------------
       
   563 // 
       
   564 void CPSUIGSPluginModel::ClearInvalidSIPAndXDMSettingsL()
       
   565     {
       
   566     // SIP
       
   567     ReadSipArrayFromEngineL();
       
   568     if ( iSettingSet.iSipProfile != KErrNotFound && 
       
   569         KErrNotFound == SipProfileIndex( iSettingSet.iSipProfile ))
       
   570         {
       
   571         iSettingSet.iSipProfile = KErrNotFound;
       
   572         }
       
   573     // XDM
       
   574     XdmCollectionNamesL();
       
   575     if ( iSettingSet.iXDMSetting != KErrNotFound && 
       
   576         KErrNotFound == XdmSettingIndex( iSettingSet.iXDMSetting ))
       
   577         {
       
   578         iSettingSet.iXDMSetting = KErrNotFound;
       
   579         }
       
   580     }
       
   581     
       
   582 // ---------------------------------------------------------------------------
       
   583 // CPSUIGSPluginModel::SettingsId()
       
   584 // See header for details.
       
   585 // ---------------------------------------------------------------------------
       
   586 // 
       
   587 TInt& CPSUIGSPluginModel::SettingsId()
       
   588     {
       
   589     return iSettingId;
       
   590     }    
       
   591 
       
   592 // ---------------------------------------------------------------------------
       
   593 // CPSUIGSPluginModel::SettingsIDArray()
       
   594 // See header for details.
       
   595 // ---------------------------------------------------------------------------
       
   596 //
       
   597 RArray<TInt>& CPSUIGSPluginModel::SettingsIDArray()
       
   598     {
       
   599     return iPSIdArray;
       
   600     }
       
   601 
       
   602 // ---------------------------------------------------------------------------
       
   603 // CPSUIGSPluginModel::SipProfilesLC()
       
   604 // See header for details.
       
   605 // ---------------------------------------------------------------------------
       
   606 //   
       
   607 CDesCArray* CPSUIGSPluginModel::SipProfilesLC()
       
   608     {
       
   609     ReadSipArrayFromEngineL();
       
   610     CDesCArray* array = new ( ELeave ) CDesCArrayFlat( 2 );
       
   611     CleanupStack::PushL( array );
       
   612     const TInt arrayCount = iSIPProfiles->Count();
       
   613     for ( TInt i = 0; i < arrayCount; i++ )
       
   614         {
       
   615         const TDesC8* profileName;
       
   616         iSIPProfiles->At( i )->GetParameter( KSIPProviderName, profileName );
       
   617         HBufC* profileName16 = 
       
   618             EscapeUtils::ConvertToUnicodeFromUtf8L( *profileName );
       
   619         CleanupStack::PushL( profileName16 );
       
   620         array->AppendL( profileName16->Des() );
       
   621         CleanupStack::PopAndDestroy( profileName16 );// profileName16
       
   622         }
       
   623     return array;
       
   624     }
       
   625 
       
   626 // ---------------------------------------------------------------------------
       
   627 // CPSUIGSPluginModel::SipProfileId()
       
   628 // See header for details.
       
   629 // ---------------------------------------------------------------------------
       
   630 //   
       
   631 TInt CPSUIGSPluginModel::SipProfileId( TInt aIndex )
       
   632     {
       
   633     __ASSERT_DEBUG( iSIPProfiles, User::Panic( KPSUIGSPluginPanicCategory, KErrNotFound ));
       
   634 
       
   635     TUint32 id = 0;
       
   636     if ( aIndex < iSIPProfiles->Count())
       
   637         {        
       
   638         iSIPProfiles->At( aIndex )->GetParameter( KSIPProfileId, id );
       
   639         }
       
   640 
       
   641     __ASSERT_DEBUG( id < KMaxTInt ,User::Panic( KPSUIGSPluginPanicCategory, KErrOverflow ));
       
   642     return id ? TInt( id ) : KErrNotFound;
       
   643     }
       
   644 
       
   645 // ---------------------------------------------------------------------------
       
   646 // CPSUIGSPluginModel::SipProfileIndex()
       
   647 // See header for details.
       
   648 // ---------------------------------------------------------------------------
       
   649 //   
       
   650 TInt CPSUIGSPluginModel::SipProfileIndex( TInt aId )
       
   651     {
       
   652     __ASSERT_DEBUG( iSIPProfiles, User::Panic( KPSUIGSPluginPanicCategory, KErrNotFound ));    
       
   653     const TInt arrayCount = iSIPProfiles->Count();
       
   654     TUint32 idValue = aId;
       
   655     for ( TInt i = 0; i < arrayCount; i++ )
       
   656         {
       
   657         TUint32 tempValue;
       
   658         iSIPProfiles->At( i )->GetParameter( KSIPProfileId, tempValue );
       
   659         if ( tempValue == idValue )
       
   660             {
       
   661             return i;
       
   662             }
       
   663         }
       
   664     return KErrNotFound;
       
   665     }
       
   666 
       
   667 // ---------------------------------------------------------------------------
       
   668 // CPSUIGSPluginModel::SipProfileNameL()
       
   669 // See header for details.
       
   670 // ---------------------------------------------------------------------------
       
   671 //   
       
   672 HBufC* CPSUIGSPluginModel::SipProfileNameL( TInt aId )
       
   673     {
       
   674     const TInt arrayCount = iSIPProfiles->Count();
       
   675     TUint32 idValue = aId;
       
   676     for ( TInt i = 0; i < arrayCount; i++ )
       
   677         {
       
   678         TUint32 tempValue;
       
   679         iSIPProfiles->At( i )->GetParameter( KSIPProfileId, tempValue );
       
   680         if ( tempValue == idValue )
       
   681             {
       
   682             const TDesC8* profileName;
       
   683             iSIPProfiles->At( i )->GetParameter( KSIPProviderName, profileName );
       
   684             return EscapeUtils::ConvertToUnicodeFromUtf8L( *profileName );// name found
       
   685             }
       
   686         }
       
   687     return HBufC::NewL( 0 );// name not found
       
   688     }
       
   689 
       
   690 // ---------------------------------------------------------------------------
       
   691 // CPSUIGSPluginModel::IsSipProfileRegisteredL()
       
   692 // See header for details.
       
   693 // ---------------------------------------------------------------------------
       
   694 // 
       
   695 TBool CPSUIGSPluginModel::IsSipProfileRegisteredL( TInt aIndex )
       
   696     {
       
   697     TBool registered( EFalse );  
       
   698     TInt sipProfileId = SipProfileId( aIndex );
       
   699     const TInt arrayCount = iSIPProfiles->Count();
       
   700 	
       
   701     for ( TInt i = 0; i < arrayCount; i++ )
       
   702         {
       
   703         TUint32 tempValue;
       
   704         iSIPProfiles->At( i )->GetParameter( KSIPProfileId, tempValue );
       
   705 		
       
   706         if ( tempValue == sipProfileId )
       
   707             {
       
   708             iSIPProfiles->At( i )->GetParameter( 
       
   709                 KSIPProfileRegistered, registered );
       
   710             }
       
   711         }
       
   712 		
       
   713     return registered;
       
   714     }
       
   715  
       
   716 // ---------------------------------------------------------------------------
       
   717 // CPSUIGSPluginModel::ReadSipArrayFromEngineL()
       
   718 // See header for details.
       
   719 // ---------------------------------------------------------------------------
       
   720 //       
       
   721 void CPSUIGSPluginModel::ReadSipArrayFromEngineL()
       
   722     {
       
   723     RArray<TSIPProfileTypeInfo> array;
       
   724     CleanupClosePushL( array );
       
   725     
       
   726     if ( !iSIPEngine )
       
   727         {
       
   728         iSIPEngine = CSIPManagedProfileRegistry::NewL( *this );
       
   729         }
       
   730     
       
   731     // Get the supported profile types
       
   732     iSIPEngine->SupportedProfileTypesL( array );
       
   733     
       
   734     // check iSIPProfiles, if exists delete
       
   735     if ( iSIPProfiles )
       
   736         {
       
   737         iSIPProfiles->ResetAndDestroy();
       
   738         delete iSIPProfiles;
       
   739         }
       
   740 
       
   741     // Create the profile pointer array
       
   742     iSIPProfiles = 
       
   743         new ( ELeave ) CArrayPtrFlat<CSIPManagedProfile>( 2 );
       
   744 
       
   745     RPointerArray<CSIPProfile> profilePointerArray;
       
   746     TCleanupItem clItem( ResetAndDestroy, &profilePointerArray );
       
   747     CleanupStack::PushL( clItem );
       
   748     
       
   749     // Get all profiles based on profile types
       
   750     const TInt arrayCount = array.Count();
       
   751     for ( TInt i = 0; i < arrayCount; i++ )
       
   752         {        
       
   753         iSIPEngine->ProfilesL( array[i], profilePointerArray );
       
   754         while ( profilePointerArray.Count() > 0 )
       
   755             {
       
   756             CSIPManagedProfile* profile = 
       
   757                 static_cast<CSIPManagedProfile*>( profilePointerArray[ 0 ]);
       
   758             iSIPProfiles->AppendL( profile );
       
   759             profilePointerArray.Remove( 0 ); 
       
   760             }                    
       
   761         profilePointerArray.Reset();    
       
   762         }
       
   763 
       
   764     CleanupStack::PopAndDestroy( 2, &array ); // array
       
   765     }    
       
   766 
       
   767 // ---------------------------------------------------------------------------
       
   768 // CPSUIGSPluginModel::ResetAndDestroy()
       
   769 // See header for details.
       
   770 // ---------------------------------------------------------------------------
       
   771 //   
       
   772 void CPSUIGSPluginModel::ResetAndDestroy( 
       
   773     TAny* aPointerArray )
       
   774     {
       
   775     RPointerArray<CSIPProfile>* array =
       
   776         static_cast<RPointerArray<CSIPProfile>*>( aPointerArray );
       
   777     array->ResetAndDestroy();
       
   778     array->Close();
       
   779     }
       
   780 
       
   781 // ---------------------------------------------------------------------------
       
   782 // CPSUIGSPluginModel::ProfileRegistryEventOccurred()
       
   783 // See header for details.
       
   784 // ---------------------------------------------------------------------------
       
   785 //   
       
   786 void CPSUIGSPluginModel::ProfileRegistryEventOccurred( 
       
   787     TUint32 /*aSIPProfileId*/, TEvent aEvent )
       
   788     {
       
   789     switch( aEvent )    
       
   790         {
       
   791         case EProfileCreated:
       
   792         case EProfileUpdated:   
       
   793         case EProfileDestroyed:
       
   794             // update sip profile array
       
   795             TRAP_IGNORE( ReadSipArrayFromEngineL() );
       
   796             break;
       
   797         default:
       
   798             // do nothing.
       
   799             break;
       
   800         }
       
   801     }
       
   802     
       
   803 // ---------------------------------------------------------------------------
       
   804 // CPSUIGSPluginModel::ProfileRegistryErrorOccurred()
       
   805 // See header for details.
       
   806 // ---------------------------------------------------------------------------
       
   807 //       
       
   808 void CPSUIGSPluginModel::ProfileRegistryErrorOccurred(                  
       
   809     TUint32 /*aSIPProfileId*/,
       
   810     TInt /*aError*/ )
       
   811     {        
       
   812     // update sip profile array
       
   813     TRAP_IGNORE( ReadSipArrayFromEngineL() );
       
   814     }
       
   815 
       
   816 // ---------------------------------------------------------------------------
       
   817 // CPSUIGSPluginModel::XdmCollectionNamesL()
       
   818 // See header for details.
       
   819 // ---------------------------------------------------------------------------
       
   820 //  
       
   821 CDesCArray* CPSUIGSPluginModel::XdmCollectionNamesL()
       
   822     {
       
   823     delete iXdmNameArray;
       
   824     iXdmNameArray = NULL;
       
   825     iXdmIdArray.Reset();
       
   826     
       
   827     iXdmNameArray = TXdmSettingsApi::CollectionNamesLC( iXdmIdArray );
       
   828     CleanupStack::Pop( iXdmNameArray );// iXdmNameArray
       
   829     return iXdmNameArray;// pointer is given, but ownership stays here
       
   830     }
       
   831 
       
   832 // ---------------------------------------------------------------------------
       
   833 // CPSUIGSPluginModel::XdmCollectionNameL()
       
   834 // See header for details.
       
   835 // ---------------------------------------------------------------------------
       
   836 //  
       
   837 HBufC* CPSUIGSPluginModel::XdmCollectionNameL( TInt aId )
       
   838     {
       
   839     HBufC* buf = NULL;
       
   840     TRAPD( err, buf = TXdmSettingsApi::PropertyL( aId, EXdmPropName ));
       
   841     return ( err == KErrNone ) ? buf : HBufC::NewL( 0 );
       
   842     }
       
   843 
       
   844 // ---------------------------------------------------------------------------
       
   845 // CPSUIGSPluginModel::XdmSettingIndex()
       
   846 // See header for details.
       
   847 // ---------------------------------------------------------------------------
       
   848 //  
       
   849 TInt CPSUIGSPluginModel::XdmSettingIndex( TInt aId )
       
   850     {
       
   851     const TInt arrayCount = iXdmIdArray.Count();
       
   852     for ( TInt i = 0; i < arrayCount; i++ )
       
   853         {
       
   854         if ( aId == iXdmIdArray[ i ] )
       
   855             {
       
   856             return i;
       
   857             }
       
   858         }    
       
   859     return KErrNotFound;    
       
   860     }
       
   861     
       
   862 // ---------------------------------------------------------------------------
       
   863 // CPSUIGSPluginModel::XdmSettingId()
       
   864 // See header for details.
       
   865 // ---------------------------------------------------------------------------
       
   866 //  
       
   867 TInt CPSUIGSPluginModel::XdmSettingId( TInt aIndex )
       
   868     {
       
   869     TInt id = KErrNotFound;
       
   870     if ( aIndex+1 <= iXdmIdArray.Count())
       
   871         {        
       
   872         id = iXdmIdArray[ aIndex ];
       
   873         }
       
   874     return id;
       
   875     }
       
   876 
       
   877 // End of file