syncmlfw/dm/settings/src/NSmlDMResourceProfiles.cpp
changeset 0 b497e44ab2fc
child 59 13d7c31c74e0
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  DM-settings 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "nsmldmsettings.h"
       
    22 #include "NSmlDMResourceProfile.h"
       
    23 #include <featmgr.h>
       
    24 const TInt KNSmlDmBluetoothType = 0x101F99F1;
       
    25 // ----------------------------------------------------------
       
    26 // CNSmlDMResourceProfiles implementation 
       
    27 // ----------------------------------------------------------
       
    28 
       
    29 // ----------------------------------------------------------
       
    30 // CNSmlDMResourceProfiles::~CNSmlDMResourceProfiles()
       
    31 // ----------------------------------------------------------
       
    32 CNSmlDMResourceProfiles::~CNSmlDMResourceProfiles()
       
    33 	{
       
    34 	if(iProfileArray)
       
    35 		{
       
    36 		iProfileArray->ResetAndDestroy();			
       
    37 		}
       
    38 	delete iProfileArray;
       
    39 	FeatureManager::UnInitializeLib();
       
    40 	}
       
    41 
       
    42 // ----------------------------------------------------------
       
    43 // CNSmlDMResourceProfiles* CNSmlDMResourceProfiles::NewLC( TResourceReader& aReader, CNSmlDMSettings& aSettings )
       
    44 // ----------------------------------------------------------
       
    45 CNSmlDMResourceProfiles* CNSmlDMResourceProfiles::NewLC( TResourceReader& aReader, CNSmlDMSettings* aSettings )
       
    46 	{
       
    47 	CNSmlDMResourceProfiles* self = new (ELeave) CNSmlDMResourceProfiles;
       
    48 	CleanupStack::PushL( self );
       
    49 	self->ConstructL( aReader, aSettings );
       
    50 	return self;
       
    51 	}
       
    52 // ----------------------------------------------------------
       
    53 // void CNSmlDMResourceProfiles::RemoveDuplicateEntry()
       
    54 // ----------------------------------------------------------
       
    55 void CNSmlDMResourceProfiles::RemoveDuplicateEntry()
       
    56 {
       
    57 	TInt count = iProfileArray->Count();
       
    58 	for ( TInt i = 0; i < count; i++ )
       
    59 	{
       
    60 		for(TInt j = i+1; j <count; j++)
       
    61 		{
       
    62 			if((iProfileArray->At(i)->GetServerId()->Des().Compare(iProfileArray->At(j)->GetServerId()->Des()) == 0) &&
       
    63 			(iProfileArray->At(i)->GetServerId()->Length() == iProfileArray->At(j)->GetServerId()->Length()))
       
    64 			{
       
    65 				iProfileArray->Delete(j);
       
    66 				iProfileArray->Compress();
       
    67 				j--;
       
    68 				count--;
       
    69 			}
       
    70 		}
       
    71 	}
       
    72 }
       
    73 // ----------------------------------------------------------
       
    74 // void CNSmlDMResourceProfiles::SaveProfilesL()
       
    75 // ----------------------------------------------------------
       
    76 void CNSmlDMResourceProfiles::SaveProfilesL()
       
    77 	{
       
    78 	RemoveDuplicateEntry();
       
    79 	RemoveObexEntryL();
       
    80 	for ( TInt i = 0; i < iProfileArray->Count(); i++ )
       
    81 		{
       
    82 		CNSmlDMProfile* profile = iSettings->CreateProfileL();
       
    83 		CleanupStack::PushL( profile );
       
    84 		iProfileArray->At(i)->SaveProfileL( profile );
       
    85 		profile->SaveL();
       
    86 		CleanupStack::PopAndDestroy(); // profile
       
    87 		}
       
    88 	}
       
    89 
       
    90 // ----------------------------------------------------------
       
    91 // void CNSmlDMResourceProfiles::ConstructL( TResourceReader& aReader )
       
    92 // ----------------------------------------------------------
       
    93 void CNSmlDMResourceProfiles::ConstructL( TResourceReader& aReader, CNSmlDMSettings* aSettings )
       
    94 	{
       
    95 	iSettings = aSettings;
       
    96 	iProfileArray = new (ELeave) CArrayPtrFlat<CNSmlDMResourceProfile> (3);
       
    97 	FeatureManager::InitializeLibL();
       
    98 	AddDataL( aReader );
       
    99 	}
       
   100 
       
   101 // ----------------------------------------------------------
       
   102 // void CNSmlDMResourceProfiles::AddDataL( TResourceReader& aReader )
       
   103 // ----------------------------------------------------------
       
   104 void CNSmlDMResourceProfiles::AddDataL( TResourceReader& aReader )
       
   105 	{
       
   106 	TInt index;
       
   107 	TInt number = aReader.ReadInt16();
       
   108 	for ( index = 0; index < number; index++ )
       
   109 		{
       
   110 		CNSmlDMResourceProfile* profile = CNSmlDMResourceProfile::NewLC( aReader );
       
   111 		iProfileArray->AppendL( profile );
       
   112 		CleanupStack::Pop();		
       
   113 		}
       
   114 	}
       
   115 
       
   116 // ----------------------------------------------------------
       
   117 // void CNSmlDMResourceProfiles::RemoveObexEntryL( )
       
   118 // ----------------------------------------------------------	
       
   119 void CNSmlDMResourceProfiles::RemoveObexEntryL()
       
   120  {   
       
   121     TInt count = iProfileArray->Count();
       
   122     for ( TInt i = 0; i < count; i++ )
       
   123     {
       
   124         if((! FeatureManager::FeatureSupported ( KFeatureIdSyncMlDmObex )) &&
       
   125 		   ( iProfileArray->At(i)->iTransportId == KNSmlDmBluetoothType))
       
   126          {
       
   127             iProfileArray->Delete(i);
       
   128             iProfileArray->Compress();
       
   129             i--;
       
   130             count--;            
       
   131          }               
       
   132     } 
       
   133  }
       
   134 //  End of File