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