presencesettingsui/src/psuigspluginmodel.cpp
changeset 0 c8caa15ef882
child 11 52d91a16fec3
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     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         aOriginalName : 
       
   358         StringLoader::LoadL( R_QTN_PRESENCE_NAME_DEFAULT );
       
   359 
       
   360     if ( settingName->Length() + KPSUIFormattingExtraLength > KPresSetNameMaxLength )
       
   361         {//if there is no room for duplicate-numbering, let user take care of that when saving settings
       
   362         CleanupStack::PushL( settingName );
       
   363         return settingName;
       
   364         }
       
   365     
       
   366     settingName = settingName->ReAlloc( 
       
   367         settingName->Length() + KPSUIFormattingExtraLength );// enough for formatting
       
   368     CleanupStack::PushL( settingName );
       
   369     HBufC* tempSetName = NULL;
       
   370     TInt pos = 0;// used as dummy
       
   371     TInt found = 0;
       
   372     TInt index = 1;
       
   373     TPtr ptr = settingName->Des();
       
   374     
       
   375     // do the actual checking of name
       
   376     found = iPSNameArray->Find( *settingName, pos );
       
   377     while ( found == 0 )
       
   378         {
       
   379         if ( !tempSetName )
       
   380             {
       
   381             if ( aOriginalName )
       
   382                 {// aOriginalName given
       
   383                 tempSetName = GetPrefixL( settingName );
       
   384                 tempSetName = tempSetName->ReAlloc( 
       
   385                     tempSetName->Length() + KPSUIFormattingExtraLength );// enough for formatting
       
   386                 CleanupStack::PushL( tempSetName );
       
   387                 tempSetName->Des().Append( KPSUIGSPluginNumbering );
       
   388                 }
       
   389             else
       
   390                 {// aOriginalName not given
       
   391                 tempSetName = StringLoader::LoadLC( R_QTN_PRESENCE_NAME_DEFAULT_NUMBER );
       
   392                 }
       
   393             }
       
   394         StringLoader::Format( ptr, *tempSetName, -1, index );
       
   395         found = iPSNameArray->Find( *settingName, pos );
       
   396         index++;
       
   397         }
       
   398 
       
   399     // cleanup
       
   400     if ( tempSetName )
       
   401         {
       
   402         CleanupStack::PopAndDestroy( tempSetName ); //tempSetName
       
   403         }
       
   404 
       
   405     return settingName;    
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 // CPSUIGSPluginModel::GetPrefixL()
       
   410 // See header for details.
       
   411 // ---------------------------------------------------------------------------
       
   412 // 
       
   413 HBufC* CPSUIGSPluginModel::GetPrefixL( HBufC* aName )
       
   414     {
       
   415     TPtrC prefix = aName->Des();
       
   416     TInt lastBrace = aName->LocateReverse('(');
       
   417     if ( lastBrace != KErrNotFound )
       
   418         {
       
   419         // aName looks like "<prefix><brace><something>".
       
   420         // See if <something> is an integer number and
       
   421         // <something> ends to a brace.
       
   422         TPtrC num = aName->Right( aName->Length() - lastBrace - 1 );
       
   423         TInt val;
       
   424         TLex lex( num );
       
   425         if ( lex.Val( val ) == KErrNone && num.Locate(')') == num.Length() - 1 )
       
   426             {
       
   427             // Yes, the trailer is an integer.
       
   428             prefix.Set( aName->Left( lastBrace ) );
       
   429             }
       
   430         }
       
   431     return prefix.AllocL();
       
   432     }
       
   433 
       
   434 // ---------------------------------------------------------------------------
       
   435 // CPSUIGSPluginModel::CurrentSettingName()
       
   436 // See header for details.
       
   437 // ---------------------------------------------------------------------------
       
   438 // 
       
   439 HBufC* CPSUIGSPluginModel::SettingNameLC( TInt aIndex )
       
   440     {
       
   441     return iPSNameArray->MdcaPoint( aIndex ).AllocLC();
       
   442     }
       
   443 
       
   444 // ---------------------------------------------------------------------------
       
   445 // CPSUIGSPluginModel::SettingNames()
       
   446 // See header for details.
       
   447 // ---------------------------------------------------------------------------
       
   448 // 
       
   449 CDesCArray* CPSUIGSPluginModel::SettingNames()
       
   450     {
       
   451     return iPSNameArray;// ownership stays in CPSUIGSPluginModel
       
   452     }
       
   453 
       
   454 // ---------------------------------------------------------------------------
       
   455 // CPSUIGSPluginModel::SettingsSet()
       
   456 // See header for details.
       
   457 // ---------------------------------------------------------------------------
       
   458 // 
       
   459 TPresSettingsSet& CPSUIGSPluginModel::SettingsSet()
       
   460     {
       
   461     return iSettingSet;
       
   462     }
       
   463 
       
   464 // ---------------------------------------------------------------------------
       
   465 // CPSUIGSPluginModel::ClearInvalidSIPAndXDMSettingsL()
       
   466 // See header for details.
       
   467 // ---------------------------------------------------------------------------
       
   468 // 
       
   469 void CPSUIGSPluginModel::ClearInvalidSIPAndXDMSettingsL()
       
   470     {
       
   471     // SIP
       
   472     ReadSipArrayFromEngineL();
       
   473     if ( iSettingSet.iSipProfile != KErrNotFound && 
       
   474         KErrNotFound == SipProfileIndex( iSettingSet.iSipProfile ))
       
   475         {
       
   476         iSettingSet.iSipProfile = KErrNotFound;
       
   477         }
       
   478     // XDM
       
   479     XdmCollectionNamesL();
       
   480     if ( iSettingSet.iXDMSetting != KErrNotFound && 
       
   481         KErrNotFound == XdmSettingIndex( iSettingSet.iXDMSetting ))
       
   482         {
       
   483         iSettingSet.iXDMSetting = KErrNotFound;
       
   484         }
       
   485     }
       
   486     
       
   487 // ---------------------------------------------------------------------------
       
   488 // CPSUIGSPluginModel::SettingsId()
       
   489 // See header for details.
       
   490 // ---------------------------------------------------------------------------
       
   491 // 
       
   492 TInt& CPSUIGSPluginModel::SettingsId()
       
   493     {
       
   494     return iSettingId;
       
   495     }    
       
   496 
       
   497 // ---------------------------------------------------------------------------
       
   498 // CPSUIGSPluginModel::SettingsIDArray()
       
   499 // See header for details.
       
   500 // ---------------------------------------------------------------------------
       
   501 //
       
   502 RArray<TInt>& CPSUIGSPluginModel::SettingsIDArray()
       
   503     {
       
   504     return iPSIdArray;
       
   505     }
       
   506 
       
   507 // ---------------------------------------------------------------------------
       
   508 // CPSUIGSPluginModel::SipProfilesLC()
       
   509 // See header for details.
       
   510 // ---------------------------------------------------------------------------
       
   511 //   
       
   512 CDesCArray* CPSUIGSPluginModel::SipProfilesLC()
       
   513     {
       
   514     ReadSipArrayFromEngineL();
       
   515     CDesCArray* array = new ( ELeave ) CDesCArrayFlat( 2 );
       
   516     CleanupStack::PushL( array );
       
   517     const TInt arrayCount = iSIPProfiles->Count();
       
   518     for ( TInt i = 0; i < arrayCount; i++ )
       
   519         {
       
   520         const TDesC8* profileName;
       
   521         iSIPProfiles->At( i )->GetParameter( KSIPProviderName, profileName );
       
   522         HBufC* profileName16 = 
       
   523             EscapeUtils::ConvertToUnicodeFromUtf8L( *profileName );
       
   524         CleanupStack::PushL( profileName16 );
       
   525         array->AppendL( profileName16->Des() );
       
   526         CleanupStack::PopAndDestroy( profileName16 );// profileName16
       
   527         }
       
   528     return array;
       
   529     }
       
   530 
       
   531 // ---------------------------------------------------------------------------
       
   532 // CPSUIGSPluginModel::SipProfileId()
       
   533 // See header for details.
       
   534 // ---------------------------------------------------------------------------
       
   535 //   
       
   536 TInt CPSUIGSPluginModel::SipProfileId( TInt aIndex )
       
   537     {
       
   538     __ASSERT_DEBUG( iSIPProfiles, User::Panic( KPSUIGSPluginPanicCategory, KErrNotFound ));
       
   539 
       
   540     TUint32 id = 0;
       
   541     if ( aIndex < iSIPProfiles->Count())
       
   542         {        
       
   543         iSIPProfiles->At( aIndex )->GetParameter( KSIPProfileId, id );
       
   544         }
       
   545 
       
   546     __ASSERT_DEBUG( id < KMaxTInt ,User::Panic( KPSUIGSPluginPanicCategory, KErrOverflow ));
       
   547     return id ? TInt( id ) : KErrNotFound;
       
   548     }
       
   549 
       
   550 // ---------------------------------------------------------------------------
       
   551 // CPSUIGSPluginModel::SipProfileIndex()
       
   552 // See header for details.
       
   553 // ---------------------------------------------------------------------------
       
   554 //   
       
   555 TInt CPSUIGSPluginModel::SipProfileIndex( TInt aId )
       
   556     {
       
   557     __ASSERT_DEBUG( iSIPProfiles, User::Panic( KPSUIGSPluginPanicCategory, KErrNotFound ));    
       
   558     const TInt arrayCount = iSIPProfiles->Count();
       
   559     TUint32 idValue = aId;
       
   560     for ( TInt i = 0; i < arrayCount; i++ )
       
   561         {
       
   562         TUint32 tempValue;
       
   563         iSIPProfiles->At( i )->GetParameter( KSIPProfileId, tempValue );
       
   564         if ( tempValue == idValue )
       
   565             {
       
   566             return i;
       
   567             }
       
   568         }
       
   569     return KErrNotFound;
       
   570     }
       
   571 
       
   572 // ---------------------------------------------------------------------------
       
   573 // CPSUIGSPluginModel::SipProfileNameL()
       
   574 // See header for details.
       
   575 // ---------------------------------------------------------------------------
       
   576 //   
       
   577 HBufC* CPSUIGSPluginModel::SipProfileNameL( TInt aId )
       
   578     {
       
   579     const TInt arrayCount = iSIPProfiles->Count();
       
   580     TUint32 idValue = aId;
       
   581     for ( TInt i = 0; i < arrayCount; i++ )
       
   582         {
       
   583         TUint32 tempValue;
       
   584         iSIPProfiles->At( i )->GetParameter( KSIPProfileId, tempValue );
       
   585         if ( tempValue == idValue )
       
   586             {
       
   587             const TDesC8* profileName;
       
   588             iSIPProfiles->At( i )->GetParameter( KSIPProviderName, profileName );
       
   589             return EscapeUtils::ConvertToUnicodeFromUtf8L( *profileName );// name found
       
   590             }
       
   591         }
       
   592     return HBufC::NewL( 0 );// name not found
       
   593     }
       
   594  
       
   595 // ---------------------------------------------------------------------------
       
   596 // CPSUIGSPluginModel::ReadSipArrayFromEngineL()
       
   597 // See header for details.
       
   598 // ---------------------------------------------------------------------------
       
   599 //       
       
   600 void CPSUIGSPluginModel::ReadSipArrayFromEngineL()
       
   601     {
       
   602     RArray<TSIPProfileTypeInfo> array;
       
   603     CleanupClosePushL( array );
       
   604     
       
   605     if ( !iSIPEngine )
       
   606         {
       
   607         iSIPEngine = CSIPManagedProfileRegistry::NewL( *this );
       
   608         }
       
   609     
       
   610     // Get the supported profile types
       
   611     iSIPEngine->SupportedProfileTypesL( array );
       
   612     
       
   613     // check iSIPProfiles, if exists delete
       
   614     if ( iSIPProfiles )
       
   615         {
       
   616         iSIPProfiles->ResetAndDestroy();
       
   617         delete iSIPProfiles;
       
   618         }
       
   619 
       
   620     // Create the profile pointer array
       
   621     iSIPProfiles = 
       
   622         new ( ELeave ) CArrayPtrFlat<CSIPManagedProfile>( 2 );
       
   623 
       
   624     RPointerArray<CSIPProfile> profilePointerArray;
       
   625     TCleanupItem clItem( ResetAndDestroy, &profilePointerArray );
       
   626     CleanupStack::PushL( clItem );
       
   627     
       
   628     // Get all profiles based on profile types
       
   629     const TInt arrayCount = array.Count();
       
   630     for ( TInt i = 0; i < arrayCount; i++ )
       
   631         {        
       
   632         iSIPEngine->ProfilesL( array[i], profilePointerArray );
       
   633         while ( profilePointerArray.Count() > 0 )
       
   634             {
       
   635             CSIPManagedProfile* profile = 
       
   636                 static_cast<CSIPManagedProfile*>( profilePointerArray[ 0 ]);
       
   637             iSIPProfiles->AppendL( profile );
       
   638             profilePointerArray.Remove( 0 ); 
       
   639             }                    
       
   640         profilePointerArray.Reset();    
       
   641         }
       
   642 
       
   643     CleanupStack::PopAndDestroy( 2, &array ); // array
       
   644     }    
       
   645 
       
   646 // ---------------------------------------------------------------------------
       
   647 // CPSUIGSPluginModel::ResetAndDestroy()
       
   648 // See header for details.
       
   649 // ---------------------------------------------------------------------------
       
   650 //   
       
   651 void CPSUIGSPluginModel::ResetAndDestroy( 
       
   652     TAny* aPointerArray )
       
   653     {
       
   654     RPointerArray<CSIPProfile>* array =
       
   655         static_cast<RPointerArray<CSIPProfile>*>( aPointerArray );
       
   656     array->ResetAndDestroy();
       
   657     array->Close();
       
   658     }
       
   659 
       
   660 // ---------------------------------------------------------------------------
       
   661 // CPSUIGSPluginModel::ProfileRegistryEventOccurred()
       
   662 // See header for details.
       
   663 // ---------------------------------------------------------------------------
       
   664 //   
       
   665 void CPSUIGSPluginModel::ProfileRegistryEventOccurred( 
       
   666     TUint32 /*aSIPProfileId*/, TEvent aEvent )
       
   667     {
       
   668     switch( aEvent )    
       
   669         {
       
   670         case EProfileCreated:
       
   671         case EProfileUpdated:   
       
   672         case EProfileDestroyed:
       
   673             // update sip profile array
       
   674             TRAP_IGNORE( ReadSipArrayFromEngineL() );
       
   675             break;
       
   676         default:
       
   677             // do nothing.
       
   678             break;
       
   679         }
       
   680     }
       
   681     
       
   682 // ---------------------------------------------------------------------------
       
   683 // CPSUIGSPluginModel::ProfileRegistryErrorOccurred()
       
   684 // See header for details.
       
   685 // ---------------------------------------------------------------------------
       
   686 //       
       
   687 void CPSUIGSPluginModel::ProfileRegistryErrorOccurred(                  
       
   688     TUint32 /*aSIPProfileId*/,
       
   689     TInt /*aError*/ )
       
   690     {        
       
   691     // update sip profile array
       
   692     TRAP_IGNORE( ReadSipArrayFromEngineL() );
       
   693     }
       
   694 
       
   695 // ---------------------------------------------------------------------------
       
   696 // CPSUIGSPluginModel::XdmCollectionNamesL()
       
   697 // See header for details.
       
   698 // ---------------------------------------------------------------------------
       
   699 //  
       
   700 CDesCArray* CPSUIGSPluginModel::XdmCollectionNamesL()
       
   701     {
       
   702     delete iXdmNameArray;
       
   703     iXdmNameArray = NULL;
       
   704     iXdmIdArray.Reset();
       
   705     
       
   706     iXdmNameArray = TXdmSettingsApi::CollectionNamesLC( iXdmIdArray );
       
   707     CleanupStack::Pop( iXdmNameArray );// iXdmNameArray
       
   708     return iXdmNameArray;// pointer is given, but ownership stays here
       
   709     }
       
   710 
       
   711 // ---------------------------------------------------------------------------
       
   712 // CPSUIGSPluginModel::XdmCollectionNameL()
       
   713 // See header for details.
       
   714 // ---------------------------------------------------------------------------
       
   715 //  
       
   716 HBufC* CPSUIGSPluginModel::XdmCollectionNameL( TInt aId )
       
   717     {
       
   718     HBufC* buf = NULL;
       
   719     TRAPD( err, buf = TXdmSettingsApi::PropertyL( aId, EXdmPropName ));
       
   720     return ( err == KErrNone ) ? buf : HBufC::NewL( 0 );
       
   721     }
       
   722 
       
   723 // ---------------------------------------------------------------------------
       
   724 // CPSUIGSPluginModel::XdmSettingIndex()
       
   725 // See header for details.
       
   726 // ---------------------------------------------------------------------------
       
   727 //  
       
   728 TInt CPSUIGSPluginModel::XdmSettingIndex( TInt aId )
       
   729     {
       
   730     const TInt arrayCount = iXdmIdArray.Count();
       
   731     for ( TInt i = 0; i < arrayCount; i++ )
       
   732         {
       
   733         if ( aId == iXdmIdArray[ i ] )
       
   734             {
       
   735             return i;
       
   736             }
       
   737         }    
       
   738     return KErrNotFound;    
       
   739     }
       
   740     
       
   741 // ---------------------------------------------------------------------------
       
   742 // CPSUIGSPluginModel::XdmSettingId()
       
   743 // See header for details.
       
   744 // ---------------------------------------------------------------------------
       
   745 //  
       
   746 TInt CPSUIGSPluginModel::XdmSettingId( TInt aIndex )
       
   747     {
       
   748     TInt id = KErrNotFound;
       
   749     if ( aIndex+1 <= iXdmIdArray.Count())
       
   750         {        
       
   751         id = iXdmIdArray[ aIndex ];
       
   752         }
       
   753     return id;
       
   754     }
       
   755 
       
   756 // End of file