syncmlfw/ds/settings/src/NSmlDSProfile.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 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:  DS-settings 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <sysutil.h>
       
    22 
       
    23 #include <nsmlconstants.h>
       
    24 #include <nsmldsconstants.h>
       
    25 #include "nsmldssettings.h"
       
    26 
       
    27 
       
    28 //=============================================
       
    29 //
       
    30 //		CNSmlDSProfile
       
    31 //
       
    32 //=============================================
       
    33 
       
    34 //=============================================
       
    35 //		CNSmlDSProfile::NewL()
       
    36 //		Creates a new instance of CNSmlDSProfile object. 
       
    37 //=============================================
       
    38 
       
    39 CNSmlDSProfile* CNSmlDSProfile::NewL( RDbNamedDatabase* aDatabase )
       
    40 	{
       
    41 	CNSmlDSProfile* self = CNSmlDSProfile::NewLC( aDatabase );
       
    42 	CleanupStack::Pop();
       
    43 	return self;
       
    44 	}
       
    45 
       
    46 //=============================================
       
    47 //		CNSmlDSProfile::NewLC()
       
    48 //		Creates a new instance of CNSmlDSProfile object. 
       
    49 //		Pushes and leaves new instance into CleanupStack.
       
    50 //=============================================
       
    51 	
       
    52 CNSmlDSProfile* CNSmlDSProfile::NewLC( RDbNamedDatabase* aDatabase )
       
    53 	{
       
    54 	CNSmlDSProfile* self = new( ELeave ) CNSmlDSProfile;
       
    55 	CleanupStack::PushL( self );
       
    56 	self->ConstructL( aDatabase );
       
    57 	return self;
       
    58 	}
       
    59 
       
    60 //=============================================
       
    61 //		CNSmlDSProfile::ConstructL()
       
    62 //		Second phase constructor.
       
    63 //=============================================
       
    64 
       
    65 void CNSmlDSProfile::ConstructL( RDbNamedDatabase* aDatabase )
       
    66 	{
       
    67 	iDatabase = aDatabase;
       
    68 	iId = KNSmlNewObject;
       
    69 
       
    70 	User::LeaveIfError( iTableProfiles.Open( *iDatabase, KNSmlTableProfiles ) );
       
    71     iColSetProfiles = iTableProfiles.ColSetL();
       
    72 	
       
    73 	User::LeaveIfError( iTableAdapters.Open( *iDatabase, KNSmlTableAdapters ) );	
       
    74 	iColSetAdapters = iTableAdapters.ColSetL();
       
    75 	
       
    76 	iDisplayName = HBufC::NewL( KNSmlMaxProfileNameLength );
       
    77 	iSyncServerUsername = HBufC::NewL( KNSmlMaxUsernameLength );
       
    78 	iSyncServerPassword = HBufC::NewL( KNSmlMaxPasswordLength );
       
    79 	iServerURL = HBufC::NewL( KNSmlMaxURLLength );
       
    80 	iServerId = HBufC::NewL( KNSmlMaxServerIdLength );
       
    81 	
       
    82 	iHttpAuthUsername = HBufC::NewL( KNSmlMaxHttpAuthUsernameLength );
       
    83 	iHttpAuthPassword = HBufC::NewL( KNSmlMaxHttpAuthPasswordLength );
       
    84 
       
    85 	iContentTypes = new ( ELeave ) CArrayPtrFlat<CNSmlDSContentType>( KSmlArrayGranularity );
       
    86 	}
       
    87 
       
    88 //=============================================
       
    89 //		CNSmlDSProfile::~CNSmlDSProfile()
       
    90 //		Destructor.
       
    91 //=============================================
       
    92 
       
    93 EXPORT_C CNSmlDSProfile::~CNSmlDSProfile()
       
    94 	{
       
    95 	delete iDisplayName;
       
    96 	delete iSyncServerUsername;
       
    97 	delete iSyncServerPassword;
       
    98 	delete iServerURL;
       
    99 	delete iServerId;
       
   100 
       
   101 	delete iHttpAuthUsername;
       
   102 	delete iHttpAuthPassword;
       
   103 
       
   104 	iView.Close();
       
   105 	iRSView.Close();
       
   106 	iWSView.Close();
       
   107 	
       
   108 	delete iColSetProfiles;
       
   109 	delete iColSetAdapters;
       
   110 
       
   111 	iTableAdapters.Close();
       
   112 	iTableProfiles.Close();
       
   113 
       
   114 	iContentTypes->ResetAndDestroy();
       
   115 	delete iContentTypes;
       
   116 	}
       
   117 
       
   118 //=============================================
       
   119 //		CNSmlDSProfile::AddContentTypeL()
       
   120 //		Appends a new content type to iContentTypes -list,
       
   121 //		if it doesn't exist before.
       
   122 //=============================================
       
   123 
       
   124  EXPORT_C CNSmlDSContentType* CNSmlDSProfile::AddContentTypeL( TInt aImplementationUID, TDesC& aClientDataSource, TDesC& aServerDataSource )
       
   125 	{
       
   126 	if ( ContentType( aImplementationUID ) ) // Check if type already on the list
       
   127 		{
       
   128 		return NULL;
       
   129 		}
       
   130 
       
   131 	iAdapterId = KNSmlNewObject;
       
   132 
       
   133 	iContentTypes->AppendL( CNSmlDSContentType::NewLC( this->iDatabase ) );
       
   134 	CleanupStack::Pop();
       
   135 
       
   136 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterTableId,   iAdapterId);	
       
   137 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterProfileId, iId);	
       
   138 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterImplementationId, aImplementationUID);	
       
   139 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterEnabled, TRUE);	
       
   140 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterCreatorId, iCreatorId);	
       
   141 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetStrValue( EDSAdapterServerDataSource, aServerDataSource );	
       
   142 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetStrValue( EDSAdapterClientDataSource, aClientDataSource );	
       
   143 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterFilterMatchType, ESyncMLMatchDisabled );	
       
   144 	
       
   145 	return iContentTypes->At( iContentTypes->Count() - 1 );
       
   146 	}
       
   147 
       
   148 //=============================================
       
   149 //		CNSmlDSProfile::ContentType()
       
   150 //		Returns a pointer to a CNSmlDSContentType 
       
   151 //		object with given ImplementationUID.
       
   152 //=============================================
       
   153 
       
   154 EXPORT_C CNSmlDSContentType* CNSmlDSProfile::ContentType( TInt aImplementationUID ) const
       
   155 	{
       
   156 	for ( TInt i = 0; i < iContentTypes->Count(); i++ )
       
   157 		{
       
   158 		if ( iContentTypes->At( i )->IntValue( EDSAdapterImplementationId ) == aImplementationUID )
       
   159 			{
       
   160 			return iContentTypes->At( i );
       
   161 			}
       
   162 		}
       
   163 		
       
   164 	return NULL;
       
   165 	}
       
   166 
       
   167 //=============================================
       
   168 //		CNSmlDSProfile::ContentTypeId()
       
   169 //		Returns a pointer to a CNSmlDSContentType 
       
   170 //		object with given content id.
       
   171 //=============================================
       
   172 
       
   173 EXPORT_C CNSmlDSContentType* CNSmlDSProfile::ContentTypeId( TInt aId ) const
       
   174 	{
       
   175 	for ( TInt i = 0; i < iContentTypes->Count(); i++ )
       
   176 		{
       
   177 		if ( iContentTypes->At( i )->IntValue( EDSAdapterTableId ) == aId )
       
   178 			{
       
   179 			return iContentTypes->At( i );
       
   180 			}
       
   181 		}
       
   182 	return NULL;
       
   183 	}
       
   184 
       
   185 //=============================================
       
   186 //		CNSmlDSProfile::DeleteContentTypeL()
       
   187 //		Delete object with given task id.
       
   188 //		
       
   189 //=============================================
       
   190 
       
   191 EXPORT_C TBool CNSmlDSProfile::DeleteContentTypeL( TInt aTaskId ) 
       
   192 	{
       
   193 	HBufC* sqlStatement = HBufC::NewLC( KDSSQLGetAdapterId().Length() + KNSmlDsSettingsMaxIntegerLength);
       
   194 	TPtr sqlStatementPtr = sqlStatement->Des();
       
   195 
       
   196 	TInt err;
       
   197 
       
   198 	for ( TInt i = 0; i < iContentTypes->Count(); i++ )
       
   199 		{
       
   200 		if ( iContentTypes->At( i )->IntValue( EDSAdapterTableId ) == aTaskId )
       
   201 			{
       
   202 //
       
   203 //			Remove first from database
       
   204 //
       
   205 			iDatabase->Begin();
       
   206 
       
   207 			sqlStatementPtr.Format( KDSSQLGetAdapterId, aTaskId );
       
   208 
       
   209 			PrepareViewL( sqlStatementPtr, iView.EUpdatable );
       
   210 
       
   211 			if ( iView.FirstL() )
       
   212 				{
       
   213 				iView.GetL();
       
   214 				iAdapterId = iView.ColUint( iColSetAdapters->ColNo( KNSmlAdapterId ) );
       
   215 				}
       
   216 
       
   217 			sqlStatementPtr.Format( KDSSQLDeleteAdapterById, iAdapterId );
       
   218 			err = iDatabase->Execute( sqlStatementPtr );
       
   219 			CleanupStack::PopAndDestroy(); // sqlStatement
       
   220 			if ( err < KErrNone )
       
   221 				{
       
   222 				iDatabase->Rollback();
       
   223 				return EFalse;
       
   224 				}
       
   225 
       
   226 			CommitAndCompact();
       
   227 //
       
   228 //			Delete object from list
       
   229 //
       
   230 			CNSmlDSContentType* contentType = ContentTypeId( iAdapterId );
       
   231 			delete contentType;
       
   232 			contentType = 0;
       
   233 //
       
   234 //			Remove it also from list
       
   235 //
       
   236 			iContentTypes->Delete( i );
       
   237 			iContentTypes->Compress();
       
   238 
       
   239 			return ETrue;
       
   240 			}
       
   241 		}
       
   242 
       
   243 	CleanupStack::PopAndDestroy(); // sqlStatement
       
   244 	return EFalse;
       
   245 	}
       
   246 
       
   247 
       
   248 //=============================================
       
   249 //		CNSmlDSProfile::SaveL()
       
   250 //		Saves a profile ie. writes all profile data to the database.
       
   251 //		If save is successful returns KErrNone,
       
   252 //		otherwise returns negative integer (defined in EPOC error codes).
       
   253 //=============================================
       
   254 
       
   255 EXPORT_C TInt CNSmlDSProfile::SaveL()
       
   256 	{
       
   257 	
       
   258 	if ( iDatabase->InTransaction() )
       
   259 		{
       
   260 		return ( KErrAccessDenied );
       
   261 		}	
       
   262 
       
   263 	iDatabase->Begin();
       
   264 
       
   265 	CNSmlDSCrypt* crypt = new( ELeave ) CNSmlDSCrypt;
       
   266 	CleanupStack::PushL( crypt );
       
   267 
       
   268 	if ( iId == KNSmlNewObject )
       
   269 		{
       
   270 		// Check OOD before saving a New profile
       
   271 		RFs fs;
       
   272 		User::LeaveIfError( fs.Connect() );
       
   273 		CleanupClosePushL(fs);
       
   274 
       
   275 		if (SysUtil::FFSSpaceBelowCriticalLevelL(&fs, KNSmlDsSettingsFatMinSize))
       
   276 			{
       
   277 			CleanupStack::PopAndDestroy(2); // fs, crypt
       
   278 			iDatabase->Rollback();
       
   279 			return KErrDiskFull;
       
   280 			// do not write
       
   281 			}
       
   282 		CleanupStack::PopAndDestroy(); //fs
       
   283 
       
   284 		//new profile
       
   285 		iTableProfiles.InsertL();
       
   286 		
       
   287 		TableProfilesSetColDesL( KNSmlDSProfileDisplayName,	*iDisplayName );
       
   288 		TableProfilesSetColIntL( KNSmlDSProfileTransportId, iTransportId );
       
   289 		TableProfilesSetColIntL( KNSmlDSProfileIAPId, iIAPId );
       
   290 
       
   291 		TableProfilesSetColDesL( KNSmlDSProfileSyncServerUsername, *iSyncServerUsername );
       
   292 		TableProfilesSetColDesL( KNSmlDSProfileSyncServerPassword, crypt->EncryptedL( *iSyncServerPassword) );	
       
   293 
       
   294 		TableProfilesSetColDesL( KNSmlDSProfileServerURL,	*iServerURL );
       
   295 		TableProfilesSetColDesL( KNSmlDSProfileServerId,	*iServerId );
       
   296 
       
   297 		TableProfilesSetColIntL( KNSmlDSProfileServerAlertedAction, iServerAlertedAction );
       
   298 		TableProfilesSetColIntL( KNSmlDSProfileDeleteAllowed, iDeleteAllowed );
       
   299 		TableProfilesSetColIntL( KNSmlDSProfileHidden, iProfileHidden );
       
   300 
       
   301 		TableProfilesSetColIntL( KNSmlDSProfileHttpAuthUsed, iHttpAuthUsed );
       
   302 		TableProfilesSetColDesL( KNSmlDSProfileHttpAuthUsername, *iHttpAuthUsername );
       
   303 		TableProfilesSetColDesL( KNSmlDSProfileHttpAuthPassword, crypt->EncryptedL( *iHttpAuthPassword) );	
       
   304 		TableProfilesSetColIntL( KNSmlDSProfileAutoChangeIAP, iAutoChangeIAP );
       
   305 		TableProfilesSetColIntL( KNSmlDSProfileCreatorID, iCreatorId );
       
   306 
       
   307 		HBufC* v = GetVisibilityStrL();
       
   308 		CleanupStack::PushL(v);
       
   309 		TableProfilesSetColDesL( KNSmlDSProfileVisibilityStr, *v);
       
   310 		CleanupStack::PopAndDestroy(); // v
       
   311 
       
   312 		TableProfilesSetColIntL( KNSmlDSProfileProtocolVersion, iProtocolVersion );
       
   313 
       
   314         TBuf<64> sqlStatement;
       
   315         sqlStatement.Format( KDSSQLCountProfiles );
       
   316     	PrepareViewL( sqlStatement, iView.EReadOnly );
       
   317 
       
   318 		iId = iTableProfiles.ColUint( iColSetProfiles->ColNo( KNSmlDSProfileId) ); // Use autoincrement
       
   319 
       
   320   		iTableProfiles.PutL();
       
   321 		
       
   322 		for ( TInt i = 0; i < iContentTypes->Count(); i++ )
       
   323 			{
       
   324 			if( iContentTypes->At(i)->StrValue( EDSAdapterClientDataSource ).Compare( 
       
   325 				iContentTypes->At(i)->StrValue( EDSAdapterServerDataSource ) ) == 0 )
       
   326 				{
       
   327 				iDatabase->Rollback();
       
   328 				CleanupStack::PopAndDestroy();  //crypt
       
   329 				return KErrArgument;			
       
   330 				}
       
   331 			InsertTableAdaptersL( i );
       
   332 												
       
   333 			}
       
   334 		}
       
   335 	else
       
   336 		{
       
   337 		//existing profile
       
   338 		TBuf<64> sqlStatement;
       
   339 		sqlStatement.Format( KDSSQLGetProfile, iId );
       
   340 
       
   341 		PrepareViewL( sqlStatement, iView.EUpdatable );
       
   342 		if ( iView.FirstL() )
       
   343 			{
       
   344 			iView.GetL();
       
   345 			iView.UpdateL();
       
   346 
       
   347 			ViewSetColDesL( KNSmlDSProfileDisplayName, *iDisplayName );
       
   348 			ViewSetColIntL( KNSmlDSProfileTransportId, iTransportId );
       
   349 			ViewSetColIntL( KNSmlDSProfileIAPId, iIAPId );
       
   350 			ViewSetColDesL( KNSmlDSProfileSyncServerUsername, *iSyncServerUsername );
       
   351 			ViewSetColDesL( KNSmlDSProfileSyncServerPassword, crypt->EncryptedL( *iSyncServerPassword ) );
       
   352 			ViewSetColDesL( KNSmlDSProfileServerURL, *iServerURL );
       
   353 			ViewSetColDesL( KNSmlDSProfileServerId, *iServerId );
       
   354 			
       
   355 			ViewSetColIntL( KNSmlDSProfileServerAlertedAction, iServerAlertedAction );
       
   356 			ViewSetColIntL( KNSmlDSProfileDeleteAllowed, iDeleteAllowed );
       
   357 			ViewSetColIntL( KNSmlDSProfileHidden, iProfileHidden );
       
   358 
       
   359 			ViewSetColIntL( KNSmlDSProfileHttpAuthUsed, iHttpAuthUsed );
       
   360 			ViewSetColDesL( KNSmlDSProfileHttpAuthUsername, *iHttpAuthUsername );
       
   361 			ViewSetColDesL( KNSmlDSProfileHttpAuthPassword, crypt->EncryptedL( *iHttpAuthPassword) );	
       
   362 			ViewSetColIntL( KNSmlDSProfileAutoChangeIAP, iAutoChangeIAP );
       
   363 			ViewSetColIntL( KNSmlDSProfileCreatorID, iCreatorId );
       
   364             
       
   365 			HBufC* v = GetVisibilityStrL();
       
   366 			CleanupStack::PushL(v);
       
   367 			ViewSetColDesL( KNSmlDSProfileVisibilityStr, *v);
       
   368 			CleanupStack::PopAndDestroy(); // v
       
   369 
       
   370 			ViewSetColIntL( KNSmlDSProfileProtocolVersion, iProtocolVersion );
       
   371 
       
   372 			iView.PutL();
       
   373 			}
       
   374 		else
       
   375 			{
       
   376 			iDatabase->Rollback();
       
   377 			CleanupStack::PopAndDestroy();  //crypt
       
   378 			return KErrNotFound;
       
   379 			}
       
   380 
       
   381 		for ( TInt i = 0; i < iContentTypes->Count(); i++ )
       
   382 			{
       
   383 			if( iContentTypes->At(i)->StrValue( EDSAdapterClientDataSource ).Compare( 
       
   384 				iContentTypes->At(i)->StrValue( EDSAdapterServerDataSource ) ) == 0 )
       
   385 				{
       
   386 				iDatabase->Rollback();
       
   387 				CleanupStack::PopAndDestroy();  //crypt
       
   388 				return KErrArgument;			
       
   389 				}
       
   390 			if ( iContentTypes->At( i )->IntValue( EDSAdapterTableId ) == KNSmlNewObject )
       
   391 				{
       
   392 				//existing profile & new contentType
       
   393 				InsertTableAdaptersL( i );
       
   394 				}
       
   395 			else
       
   396 				{
       
   397 				//existing profile & existing contentType
       
   398 				sqlStatement.Format( KDSSQLFindContentType, iContentTypes->At( i )->IntValue( EDSAdapterTableId ) );
       
   399 
       
   400 				PrepareViewL( sqlStatement, iView.EUpdatable );
       
   401 				if ( iView.FirstL() )
       
   402 					{
       
   403 					iView.GetL();
       
   404 					iView.UpdateL();
       
   405 
       
   406 					iView.SetColL( iColSetAdapters->ColNo( KNSmlAdapterEnabled ), ( TInt ) iContentTypes->At( i )->IntValue( EDSAdapterEnabled ) );
       
   407 					iView.SetColL( iColSetAdapters->ColNo( KNSmlAdapterImlementationUID ), ( TInt ) iContentTypes->At( i )->IntValue( EDSAdapterImplementationId ) );
       
   408 					iView.SetColL( iColSetAdapters->ColNo( KNSmlAdapterCreatorID ), ( TInt ) iContentTypes->At( i )->IntValue( EDSAdapterCreatorId ) );
       
   409 					iView.SetColL( iColSetAdapters->ColNo( KNSmlAdapterDisplayName ), iContentTypes->At( i )->StrValue( EDSAdapterDisplayName ) );
       
   410 					iView.SetColL( iColSetAdapters->ColNo( KNSmlAdapterClientDataSource ), iContentTypes->At( i )->StrValue( EDSAdapterClientDataSource ) );
       
   411 					iView.SetColL( iColSetAdapters->ColNo( KNSmlAdapterServerDataSource ), iContentTypes->At( i )->StrValue( EDSAdapterServerDataSource ) );
       
   412 					iView.SetColL( iColSetAdapters->ColNo( KNSmlAdapterSyncType ), ( TInt ) iContentTypes->At( i )->IntValue( EDSAdapterSyncType ) );
       
   413 					iView.SetColL( iColSetAdapters->ColNo( KNSmlAdapterFilterMatchType ), ( TInt ) iContentTypes->At( i )->IntValue( EDSAdapterFilterMatchType ) );
       
   414 					iView.PutL();
       
   415 					}
       
   416 				else
       
   417 					{
       
   418 					iDatabase->Rollback();
       
   419 					CleanupStack::PopAndDestroy();  //crypt
       
   420 					return KErrNotFound;
       
   421 					}
       
   422 				}
       
   423 
       
   424 			}
       
   425 		}
       
   426 		 
       
   427 	CleanupStack::PopAndDestroy();  //crypt
       
   428 	CommitAndCompact();
       
   429 
       
   430 	return KErrNone;
       
   431 	}
       
   432 
       
   433 //=============================================
       
   434 //		CNSmlDSProfile::IsNew()
       
   435 //		Returns true if profile is new, otherwise false.
       
   436 //=============================================
       
   437 
       
   438 EXPORT_C TBool CNSmlDSProfile::IsNew() const
       
   439 	{
       
   440 	return ( iId == KNSmlNewObject );
       
   441 	}
       
   442 
       
   443 //=============================================
       
   444 //		CNSmlDSProfile::SetHiddenL()
       
   445 //		Returns true if update done otherwise false.
       
   446 //=============================================
       
   447 
       
   448 EXPORT_C TBool CNSmlDSProfile::SetHiddenL(TBool aHidden)
       
   449 	{
       
   450 	TBool ret = EFalse;
       
   451 
       
   452 	if (iId < 1) 
       
   453 		{
       
   454 		return ret;			
       
   455 		}
       
   456 
       
   457 	HBufC* sqlStatement = HBufC::NewLC( KDSSQLGetProfile().Length() + KNSmlDsSettingsMaxIntegerLength);
       
   458 	TPtr sqlStatementPtr = sqlStatement->Des();
       
   459 
       
   460 	sqlStatementPtr.Format( KDSSQLGetProfile, iId );
       
   461 
       
   462 	PrepareViewL( sqlStatementPtr, iView.EUpdatable );
       
   463 	
       
   464 	CleanupStack::PopAndDestroy(); // sqlStatement
       
   465 
       
   466 	if ( iView.FirstL() )
       
   467 		{
       
   468 		iView.GetL();
       
   469 		iView.UpdateL();
       
   470 		iView.SetColL( iColSetProfiles->ColNo( KNSmlDSProfileHidden ), aHidden );
       
   471 		iView.PutL();
       
   472 	
       
   473 		ret = ETrue;
       
   474 
       
   475 		// Also profile value set for SaveL()
       
   476 		SetIntValue( EDSProfileHidden, aHidden);
       
   477 		}
       
   478 
       
   479 	return ret;
       
   480 	}
       
   481 
       
   482 //=============================================
       
   483 //		CNSmlDSProfile::IsNullL()
       
   484 //		Returns true if profile data is NULL, 
       
   485 //      otherwise false.
       
   486 //=============================================
       
   487 
       
   488 EXPORT_C TBool CNSmlDSProfile::IsNullL( const TDesC& aFieldName ) 
       
   489 	{
       
   490 	HBufC* sqlStatement = HBufC::NewLC( KDSSQLGetProfile().Length() + KNSmlDsSettingsMaxIntegerLength);
       
   491 	TPtr sqlStatementPtr = sqlStatement->Des();
       
   492 
       
   493 	sqlStatementPtr.Format( KDSSQLGetProfile, iId );
       
   494 
       
   495 	PrepareViewL( sqlStatementPtr, iView.EReadOnly );
       
   496 	
       
   497 	CleanupStack::PopAndDestroy(); // sqlStatement
       
   498 	
       
   499 	if ( iView.FirstL() )
       
   500 		{
       
   501 		iView.GetL();
       
   502 		if ( iView.IsColNull( iColSetProfiles->ColNo( aFieldName ) ) )
       
   503 			{
       
   504 			return ETrue;
       
   505 			}
       
   506 		}
       
   507 	return EFalse;
       
   508 	}
       
   509 
       
   510 //=============================================
       
   511 //		CNSmlDSProfile::StrValue()
       
   512 //		Returns a given string value.
       
   513 //=============================================
       
   514 
       
   515 EXPORT_C const TDesC& CNSmlDSProfile::StrValue( TNSmlDSProfileData aProfileItem ) const
       
   516 	{	
       
   517 	HBufC* result = 0;
       
   518 	switch ( aProfileItem )
       
   519 		{
       
   520 		case ( EDSProfileDisplayName ) :
       
   521 			{
       
   522 			result = iDisplayName;
       
   523 			}
       
   524 		break;
       
   525 
       
   526 		case ( EDSProfileSyncServerUsername ) :
       
   527 			{
       
   528 			result = iSyncServerUsername;
       
   529 			}
       
   530 		break;
       
   531 
       
   532 		case ( EDSProfileSyncServerPassword ) :
       
   533 			{
       
   534 			result = iSyncServerPassword;
       
   535 			}
       
   536 		break;
       
   537 
       
   538 		case ( EDSProfileServerURL ) :
       
   539 			{
       
   540 			result = iServerURL;
       
   541 			}
       
   542 		break;
       
   543 		
       
   544 		case ( EDSProfileServerId ) :
       
   545 			{
       
   546 			result = iServerId;
       
   547 			}
       
   548 		break;
       
   549 
       
   550 		case ( EDSProfileHttpAuthUsername ) :
       
   551 			{
       
   552 			result = iHttpAuthUsername;
       
   553 			}
       
   554 		break;
       
   555 
       
   556 		case ( EDSProfileHttpAuthPassword ) :
       
   557 			{
       
   558 			result = iHttpAuthPassword;
       
   559 			}
       
   560 		break;
       
   561 		
       
   562 		default:
       
   563 			{
       
   564 			User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound );
       
   565 			}
       
   566 		}
       
   567 	return *result; 
       
   568 	}
       
   569 
       
   570 //=============================================
       
   571 //		CNSmlDSProfile::IntValue()
       
   572 //		Returns a given int value.
       
   573 //=============================================
       
   574 
       
   575 EXPORT_C TInt CNSmlDSProfile::IntValue( TNSmlDSProfileData aProfileItem ) const
       
   576 	{	
       
   577 	TInt result( 0 );
       
   578 	switch ( aProfileItem )
       
   579 		{
       
   580 		case ( EDSProfileId ) :
       
   581 			{
       
   582 			result = iId;
       
   583 			}
       
   584 		break;
       
   585 		
       
   586 		case ( EDSProfileIAPId ) :
       
   587 			{
       
   588 			result = iIAPId;
       
   589 			}
       
   590 		break;
       
   591 
       
   592 		case ( EDSProfileTransportId ) :
       
   593 			{
       
   594 			result = iTransportId;
       
   595 			}
       
   596 		break;
       
   597 	
       
   598 		case ( EDSProfileServerAlertedAction ) :
       
   599 			{
       
   600 			result = iServerAlertedAction;
       
   601 			}
       
   602 		break;
       
   603 		
       
   604 		case ( EDSProfileDeleteAllowed ) :
       
   605 			{
       
   606 			result = iDeleteAllowed;
       
   607 			}
       
   608 		break;
       
   609 
       
   610 		case ( EDSProfileHidden ) :
       
   611 			{
       
   612 			result = iProfileHidden;
       
   613 			}
       
   614 		break;
       
   615 
       
   616 		case ( EDSProfileHttpAuthUsed ) :
       
   617 			{
       
   618 			result = iHttpAuthUsed;
       
   619 			}
       
   620 			break;
       
   621 			
       
   622 		case ( EDSProfileAutoChangeIAP ) :
       
   623 			{
       
   624 			result = iAutoChangeIAP;
       
   625 			}
       
   626 			break;
       
   627 		
       
   628 		case ( EDSProfileProtocolVersion ) :
       
   629 			{
       
   630 			result = iProtocolVersion;
       
   631 			}
       
   632 			break;
       
   633 
       
   634 		case ( EDSProfileCreatorId ) :
       
   635 			{
       
   636 			result = iCreatorId;
       
   637 			}
       
   638 			break;
       
   639 		
       
   640 		case ( EDSProfileDefaultProfile ) :
       
   641             {
       
   642             result = iDefaultProfile;
       
   643             }
       
   644 		    break;
       
   645 
       
   646 		default:
       
   647 			{
       
   648 			User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound );
       
   649 			}
       
   650 		}
       
   651 	return result;
       
   652 	}
       
   653 
       
   654 //=============================================
       
   655 //		CNSmlDSProfile::SetStrValue()
       
   656 //		Sets a given string value.
       
   657 //=============================================
       
   658 
       
   659 EXPORT_C void CNSmlDSProfile::SetStrValue( TNSmlDSProfileData aProfileItem, const TDesC& aNewValue )
       
   660 	{
       
   661 	switch ( aProfileItem )
       
   662 		{
       
   663 		case ( EDSProfileDisplayName ) :
       
   664 			{
       
   665 			*iDisplayName = aNewValue;
       
   666 			}
       
   667 		break;
       
   668 
       
   669 		case ( EDSProfileSyncServerUsername ) :
       
   670 			{
       
   671 			*iSyncServerUsername = aNewValue;
       
   672 			}
       
   673 		break;
       
   674 
       
   675 		case ( EDSProfileSyncServerPassword ) :
       
   676 			{
       
   677 			*iSyncServerPassword = aNewValue;
       
   678 			}
       
   679 		break;
       
   680 
       
   681 		case ( EDSProfileServerURL ) :
       
   682 			{
       
   683 			*iServerURL = aNewValue;
       
   684 			}
       
   685 		break;
       
   686 
       
   687 		case ( EDSProfileServerId ) :
       
   688 			{
       
   689 			*iServerId = aNewValue;
       
   690 			}
       
   691 		break;
       
   692 
       
   693 		case ( EDSProfileHttpAuthUsername ) :
       
   694 			{
       
   695 			*iHttpAuthUsername = aNewValue;
       
   696 			}
       
   697 			break;
       
   698 			
       
   699 		case ( EDSProfileHttpAuthPassword ) :
       
   700 			{
       
   701 			*iHttpAuthPassword = aNewValue;
       
   702 			}
       
   703 			break;
       
   704 
       
   705 		default:
       
   706 			{
       
   707 			User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound );
       
   708 			}
       
   709 		}
       
   710 	}	
       
   711 
       
   712 //=============================================
       
   713 //		CNSmlDSProfile::SetIntValue()
       
   714 //		Sets a given int value.
       
   715 //=============================================
       
   716 
       
   717 EXPORT_C void CNSmlDSProfile::SetIntValue( TNSmlDSProfileData aProfileItem, const TInt aNewValue )
       
   718 	{
       
   719 	switch ( aProfileItem )
       
   720 		{
       
   721 		case ( EDSProfileId ) :
       
   722 			{
       
   723 			iId = aNewValue;
       
   724 			}
       
   725 		break;
       
   726 
       
   727 		case ( EDSProfileIAPId ) :
       
   728 			{
       
   729 			iIAPId = aNewValue;
       
   730 			}
       
   731 		break;
       
   732 
       
   733 		case ( EDSProfileTransportId ) :
       
   734 			{
       
   735 			iTransportId = aNewValue;
       
   736 			}
       
   737 		break;
       
   738 		
       
   739 		case ( EDSProfileServerAlertedAction ) :
       
   740 			{
       
   741 			iServerAlertedAction = aNewValue;
       
   742 			}
       
   743 		break;
       
   744 		
       
   745 		case ( EDSProfileDeleteAllowed ) :
       
   746 			{
       
   747 			iDeleteAllowed = aNewValue;
       
   748 			}
       
   749 		break;
       
   750 		
       
   751 		case ( EDSProfileHidden ) :
       
   752 			{
       
   753 			iProfileHidden = aNewValue;
       
   754 			}
       
   755 		break;
       
   756 		
       
   757 		case ( EDSProfileHttpAuthUsed ) :
       
   758 			{
       
   759 			iHttpAuthUsed = aNewValue;
       
   760 			}
       
   761 			break;
       
   762 			
       
   763 		case ( EDSProfileAutoChangeIAP ) :
       
   764 			{
       
   765 			iAutoChangeIAP = aNewValue;
       
   766 			}
       
   767 			break;
       
   768 			
       
   769 		case ( EDSProfileProtocolVersion ) :
       
   770 			{
       
   771 			iProtocolVersion = aNewValue;
       
   772 			}
       
   773 			break;
       
   774 
       
   775 		case ( EDSProfileCreatorId ) :
       
   776 			{
       
   777 			iCreatorId = aNewValue;
       
   778 			}
       
   779 			break;
       
   780 			
       
   781 		case ( EDSProfileDefaultProfile ) :
       
   782             {
       
   783             iDefaultProfile = aNewValue;
       
   784             }
       
   785 		    break;
       
   786 		    
       
   787 		default:
       
   788 			{
       
   789 			User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound );
       
   790 			}
       
   791 		}
       
   792 	}
       
   793 
       
   794 //=============================================
       
   795 //		CNSmlDSProfile::Visibility()
       
   796 //		Returns the visibility of the given 
       
   797 //		dataitem.
       
   798 //=============================================
       
   799 
       
   800 EXPORT_C TNSmlDSFieldVisibility CNSmlDSProfile::Visibility( TNSmlDSProfileData aProfileItem ) const
       
   801 	{
       
   802 
       
   803 	TInt index = (TInt)aProfileItem;
       
   804 
       
   805 	if (index >= iVisibilityArray.Count() || index < 0) 
       
   806 		{
       
   807 		// unknown field. TNSmlDSProfileData-enum has been changed without changing 
       
   808 		// the size of iVisibilityArray, or negative 
       
   809 		// values has been assigned to some of those fields
       
   810 		User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound );
       
   811 		}
       
   812 
       
   813 	return iVisibilityArray[index];
       
   814 	}
       
   815 
       
   816 //=============================================
       
   817 //		CNSmlDSProfile::SetVisibility()
       
   818 //		Sets the visibility of the given 
       
   819 //		dataitem.
       
   820 //=============================================
       
   821 
       
   822 EXPORT_C void CNSmlDSProfile::SetVisibility( TNSmlDSProfileData aProfileItem,
       
   823 							const TNSmlDSFieldVisibility aVisibility )
       
   824 	{
       
   825 
       
   826 	TInt index = (TInt)aProfileItem;
       
   827 
       
   828 	if (index >= iVisibilityArray.Count() || index < 0) 
       
   829 		{
       
   830 		// unknown field. TNSmlDSProfileData-enum has been changed without changing 
       
   831 		// the size of iVisibilityArray, or negative 
       
   832 		// values has been assigned to some of those fields
       
   833 		User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound );
       
   834 		}
       
   835 
       
   836 	iVisibilityArray[index] = aVisibility;
       
   837 	}
       
   838 
       
   839 //=============================================
       
   840 //		CNSmlDSProfile::InitVisibilityArray()
       
   841 //		Method for initializing the 
       
   842 //		visibilityArray, i.e. parses the given 
       
   843 //		string's characters and maps them to 
       
   844 //		dataitem's visibilities.
       
   845 //=============================================
       
   846 
       
   847 void CNSmlDSProfile::InitVisibilityArray( const TDesC& aVisibilityStr )
       
   848 	{
       
   849 
       
   850 	if ( aVisibilityStr.Length() != iVisibilityArray.Count())
       
   851 		{
       
   852 		// The given string must be equal in size to visibilityarray, otherwise
       
   853 		// there is something wrong with the format
       
   854 		User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound );
       
   855 		}
       
   856 
       
   857 	for (TInt i=0; i < aVisibilityStr.Length(); ++i)
       
   858 		{
       
   859 		iVisibilityArray[i] = CharToVisibility( aVisibilityStr[i] );
       
   860 		}
       
   861 
       
   862 	}
       
   863 
       
   864 //=============================================
       
   865 //		CNSmlDSProfile::GetVisibilityStrL()
       
   866 //		Return the visibility array as a 
       
   867 //		string (the form in which it is written 
       
   868 //		and read from the database).
       
   869 //=============================================
       
   870 
       
   871 HBufC* CNSmlDSProfile::GetVisibilityStrL() const
       
   872 	{
       
   873 
       
   874 	HBufC* result = HBufC::NewL(KNSmlDSVisibilityArraySize);
       
   875 	TPtr ptr = result->Des();
       
   876 
       
   877 	for (TInt i=0; i < iVisibilityArray.Count(); ++i)
       
   878 		{
       
   879 		ptr += VisibilityToChar( iVisibilityArray[i] );
       
   880 		}
       
   881 
       
   882 	return result;
       
   883 	}
       
   884 	
       
   885 //=============================================
       
   886 //		CNSmlDSProfile::CharToVisibility()
       
   887 //		Turns the given char into 
       
   888 //		TNSmlDSFieldVisibility.
       
   889 //=============================================
       
   890 TNSmlDSFieldVisibility CNSmlDSProfile::CharToVisibility( const TText aCh ) const
       
   891 	{
       
   892 	switch ( aCh )
       
   893 		{
       
   894 		case KNSmlDSNormalChar:
       
   895 			{
       
   896 			return EVisibilityNormal;
       
   897 			}
       
   898 		case KNSmlDSReadOnlyChar:
       
   899 			{
       
   900 			return EVisibilityReadOnly;
       
   901 			}
       
   902 		case KNSmlDSHiddenChar:
       
   903 			{
       
   904 			return EVisibilityHidden;
       
   905 			}
       
   906 		default:
       
   907 			{
       
   908 			User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound );
       
   909 			return EVisibilityNormal;
       
   910 			}
       
   911 		}
       
   912 	}
       
   913 
       
   914 
       
   915 //=============================================
       
   916 //		CNSmlDSProfile::VisibilityToChar()
       
   917 //		Turns the given visibility into char.
       
   918 //=============================================
       
   919 TPtrC CNSmlDSProfile::VisibilityToChar( const TNSmlDSFieldVisibility aVisibility ) const
       
   920 	{
       
   921 	switch (aVisibility)
       
   922 		{
       
   923 		case EVisibilityNormal:
       
   924 			{
       
   925 			return KNSmlDSVisibilityNormal();
       
   926 			}
       
   927 		case EVisibilityReadOnly:
       
   928 			{
       
   929 			return KNSmlDSVisibilityReadOnly();
       
   930 			}
       
   931 		case EVisibilityHidden:
       
   932 			{
       
   933 			return KNSmlDSVisibilityHidden();
       
   934 			}
       
   935 		default:
       
   936 			{
       
   937 			User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound );
       
   938 			return KNullDesC();
       
   939 			}
       
   940 		}
       
   941 	}
       
   942 
       
   943 //=============================================
       
   944 //		CNSmlDSProfile::HasLogL()
       
   945 //		Returns true if profile has Log-data, 
       
   946 //      otherwise false.
       
   947 //=============================================
       
   948 
       
   949 EXPORT_C TBool CNSmlDSProfile::HasLogL() 
       
   950 	{
       
   951 	HBufC* sqlStatement = HBufC::NewLC( KDSSQLGetProfile().Length() + KNSmlDsSettingsMaxIntegerLength);
       
   952 	TPtr sqlStatementPtr = sqlStatement->Des();
       
   953 
       
   954 	sqlStatementPtr.Format( KDSSQLGetProfile, iId );
       
   955 
       
   956 	PrepareViewL( sqlStatementPtr, iView.EReadOnly );
       
   957 	
       
   958 	CleanupStack::PopAndDestroy(); // sqlStatement
       
   959 	
       
   960 	if ( iView.FirstL() )
       
   961 		{
       
   962 		iView.GetL();
       
   963 		if ( iView.IsColNull( iColSetProfiles->ColNo( KNSmlDSProfileLog ) ) )
       
   964 			{
       
   965 			return EFalse;
       
   966 			}
       
   967 		}
       
   968 	return ETrue;
       
   969 	}
       
   970 
       
   971 //=============================================
       
   972 //		CNSmlDSProfile::LogReadStreamL()
       
   973 //		Reads log-data from database
       
   974 //=============================================
       
   975 EXPORT_C RReadStream& CNSmlDSProfile::LogReadStreamL()
       
   976 {
       
   977 	HBufC* sqlStatement = HBufC::NewLC( KDSSQLGetProfile().Length() + KNSmlDsSettingsMaxIntegerLength);
       
   978 	TPtr sqlStatementPtr = sqlStatement->Des();
       
   979 
       
   980 	sqlStatementPtr.Format(KDSSQLGetProfile, iId);
       
   981 
       
   982 	User::LeaveIfError(iRSView.Prepare(*iDatabase, TDbQuery( sqlStatementPtr ), RDbRowSet::EReadOnly));
       
   983 	User::LeaveIfError(iRSView.EvaluateAll());
       
   984 	
       
   985 	CleanupStack::PopAndDestroy(); // sqlStatement
       
   986 	
       
   987 	// Get the structure of rowset
       
   988 	CDbColSet* colSet = iRSView.ColSetL(); 
       
   989 	TDbColNo col = colSet->ColNo(KNSmlDSProfileLog()); // Ordinal position of long column
       
   990 	delete colSet;
       
   991 	colSet = NULL;
       
   992 	
       
   993 	// get row
       
   994 	if( iRSView.FirstL() )
       
   995 		{
       
   996 		iRSView.GetL();
       
   997 		iRs.OpenL(iRSView, col);
       
   998 		}
       
   999 
       
  1000 	return iRs;
       
  1001 }
       
  1002 
       
  1003 //=============================================
       
  1004 //		CNSmlDSProfile::LogWriteStreamL()
       
  1005 //      Writes given stream-data to database
       
  1006 //=============================================
       
  1007 
       
  1008 EXPORT_C RWriteStream& CNSmlDSProfile::LogWriteStreamL()
       
  1009 	{
       
  1010 	HBufC* sqlStatement = HBufC::NewLC( KDSSQLGetProfile().Length() + KNSmlDsSettingsMaxIntegerLength);
       
  1011 	TPtr sqlStatementPtr = sqlStatement->Des();
       
  1012 
       
  1013 	sqlStatementPtr.Format(KDSSQLGetProfile, iId);
       
  1014 	
       
  1015 	// create a view on the database
       
  1016 	User::LeaveIfError(iWSView.Prepare(*iDatabase, TDbQuery(sqlStatementPtr), RDbRowSet::EUpdatable));
       
  1017 	User::LeaveIfError(iWSView.EvaluateAll());
       
  1018 	
       
  1019 	CleanupStack::PopAndDestroy(); // sqlStatement
       
  1020 	
       
  1021 	// Get the structure of rowset
       
  1022 	CDbColSet* colSet = iWSView.ColSetL(); 
       
  1023 	TDbColNo col = colSet->ColNo(KNSmlDSProfileLog()); // Ordinal position of long column
       
  1024 	delete colSet;
       
  1025 	colSet = NULL;
       
  1026 	
       
  1027 	// get row
       
  1028 	iDatabase->Begin();	
       
  1029 	if( iWSView.FirstL() )
       
  1030 		{
       
  1031 		iWSView.GetL();
       
  1032 		iWSView.UpdateL();
       
  1033 		iWs.OpenL(iWSView, col);
       
  1034 		}
       
  1035 
       
  1036 	return iWs;
       
  1037 	}
       
  1038 
       
  1039 
       
  1040 //=============================================
       
  1041 //		CNSmlDSProfile::WriteStreamCommitL()
       
  1042 //	
       
  1043 //		
       
  1044 //=============================================
       
  1045 EXPORT_C void CNSmlDSProfile::WriteStreamCommitL()
       
  1046 	{
       
  1047 	iWSView.PutL();
       
  1048 	iWSView.Close();
       
  1049 	CommitAndCompact();
       
  1050 	}
       
  1051 
       
  1052 //=============================================
       
  1053 //		CNSmlDSProfile::PrepareViewL()
       
  1054 //		Closes and prepares the view
       
  1055 //		
       
  1056 //=============================================
       
  1057 void CNSmlDSProfile::PrepareViewL( const TDesC& aSql, RDbRowSet::TAccess aAccess )
       
  1058 	{
       
  1059 	iView.Close();
       
  1060 	User::LeaveIfError( iView.Prepare( *iDatabase, TDbQuery( aSql ), aAccess ) );
       
  1061 	}
       
  1062 
       
  1063 //=============================================
       
  1064 //		CNSmlDSProfile::UpdateToDeleteAllowedL()
       
  1065 //	
       
  1066 //		
       
  1067 //=============================================
       
  1068 void CNSmlDSProfile::UpdateToDeleteAllowedL()
       
  1069 	{
       
  1070 	iView.GetL();
       
  1071 	iView.UpdateL();
       
  1072 	iView.SetColL( iColSetProfiles->ColNo( KNSmlDSProfileDeleteAllowed ), ( TInt ) EDSAllowed );
       
  1073 	iView.PutL();
       
  1074 	}
       
  1075 
       
  1076 //=============================================
       
  1077 //		CNSmlDSProfile::CommitAndCompact
       
  1078 //		Commits update and compacts the database
       
  1079 //		
       
  1080 //=============================================
       
  1081 void CNSmlDSProfile::CommitAndCompact() 
       
  1082 	{
       
  1083 	iDatabase->Commit();
       
  1084 	iDatabase->Compact();
       
  1085 	}
       
  1086 
       
  1087 //=============================================
       
  1088 //		CNSmlDSProfile::ResetContentTypesL()
       
  1089 //	
       
  1090 //		
       
  1091 //=============================================
       
  1092 void CNSmlDSProfile::ResetContentTypesL()
       
  1093 	{
       
  1094 	iView.GetL();
       
  1095 	iContentTypes->AppendL( CNSmlDSContentType::NewLC( this->iDatabase ) );
       
  1096 	CleanupStack::Pop();
       
  1097 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterTableId, iView.ColUint( iColSetAdapters->ColNo( KNSmlAdapterId ) ) );
       
  1098 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterProfileId, iView.ColInt( iColSetAdapters->ColNo( KNSmlAdapterProfileId ) ) );
       
  1099 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterImplementationId, iView.ColUint( iColSetAdapters->ColNo( KNSmlAdapterImlementationUID ) ) );
       
  1100 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterEnabled, iView.ColInt( iColSetAdapters->ColNo( KNSmlAdapterEnabled) ) );
       
  1101 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterCreatorId, iView.ColInt( iColSetAdapters->ColNo( KNSmlAdapterCreatorID) ) );
       
  1102 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetStrValue( EDSAdapterDisplayName, iView.ColDes( iColSetAdapters->ColNo( KNSmlAdapterDisplayName) ) );
       
  1103 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetStrValue( EDSAdapterServerDataSource, iView.ColDes( iColSetAdapters->ColNo( KNSmlAdapterServerDataSource) ) );
       
  1104 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetStrValue( EDSAdapterClientDataSource, iView.ColDes( iColSetAdapters->ColNo( KNSmlAdapterClientDataSource) ) );
       
  1105 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterSyncType, iView.ColInt( iColSetAdapters->ColNo( KNSmlAdapterSyncType) ) );
       
  1106 	( iContentTypes->At( iContentTypes->Count() -1 ) )->SetIntValue( EDSAdapterFilterMatchType, iView.ColInt( iColSetAdapters->ColNo( KNSmlAdapterFilterMatchType) ) );
       
  1107 	}
       
  1108 
       
  1109 //=============================================
       
  1110 //		CNSmlDSProfile::TableProfilesSetColIntL
       
  1111 //	
       
  1112 //		
       
  1113 //=============================================
       
  1114 void CNSmlDSProfile::TableProfilesSetColIntL( const TDesC& aFieldName, TInt aValue)
       
  1115 	{
       
  1116 	iTableProfiles.SetColL( iColSetProfiles->ColNo( aFieldName ), aValue );
       
  1117 	}
       
  1118 
       
  1119 //=============================================
       
  1120 //		CNSmlDSProfile::TableProfilesSetColDesL
       
  1121 //	
       
  1122 //		
       
  1123 //=============================================
       
  1124 void CNSmlDSProfile::TableProfilesSetColDesL( const TDesC& aFieldName, TDesC& aValue)
       
  1125 	{
       
  1126 	iTableProfiles.SetColL( iColSetProfiles->ColNo( aFieldName ), aValue );
       
  1127 	}
       
  1128 
       
  1129 //=============================================
       
  1130 //		CNSmlDSProfile::ViewSetColIntL
       
  1131 //	
       
  1132 //		
       
  1133 //=============================================
       
  1134 void CNSmlDSProfile::ViewSetColIntL( const TDesC& aFieldName, TInt aValue)
       
  1135 	{
       
  1136 	iView.SetColL( iColSetProfiles->ColNo( aFieldName ), aValue );
       
  1137 	}
       
  1138 
       
  1139 //=============================================
       
  1140 //		CNSmlDSProfile::ViewSetColDesL
       
  1141 //	
       
  1142 //		
       
  1143 //=============================================
       
  1144 void CNSmlDSProfile::ViewSetColDesL( const TDesC& aFieldName, TDesC& aValue)
       
  1145 	{
       
  1146 	iView.SetColL( iColSetProfiles->ColNo( aFieldName ), aValue );
       
  1147 	}
       
  1148 
       
  1149 //=============================================
       
  1150 //		CNSmlDSProfile::InsertTableAdaptersL
       
  1151 //		Insert adapterdata to database
       
  1152 //		
       
  1153 //=============================================
       
  1154 void CNSmlDSProfile::InsertTableAdaptersL( TInt aInd)
       
  1155 	{
       
  1156 	iTableAdapters.InsertL();
       
  1157 	
       
  1158 	iTableAdapters.SetColL( iColSetAdapters->ColNo( KNSmlAdapterProfileId ), iId );
       
  1159 	iTableAdapters.SetColL( iColSetAdapters->ColNo( KNSmlAdapterImlementationUID ), ( TInt ) iContentTypes->At( aInd )->IntValue( EDSAdapterImplementationId ) );
       
  1160 	iTableAdapters.SetColL( iColSetAdapters->ColNo( KNSmlAdapterEnabled ), iContentTypes->At( aInd )->IntValue( EDSAdapterEnabled ) );
       
  1161 	iTableAdapters.SetColL( iColSetAdapters->ColNo( KNSmlAdapterCreatorID ), iContentTypes->At( aInd )->IntValue( EDSAdapterCreatorId ) );
       
  1162 	iTableAdapters.SetColL( iColSetAdapters->ColNo( KNSmlAdapterDisplayName ), iContentTypes->At( aInd )->StrValue( EDSAdapterDisplayName ) );
       
  1163 	iTableAdapters.SetColL( iColSetAdapters->ColNo( KNSmlAdapterServerDataSource ), iContentTypes->At( aInd )->StrValue( EDSAdapterServerDataSource ) );
       
  1164 	iTableAdapters.SetColL( iColSetAdapters->ColNo( KNSmlAdapterClientDataSource ), iContentTypes->At( aInd )->StrValue( EDSAdapterClientDataSource ) );
       
  1165 	iTableAdapters.SetColL( iColSetAdapters->ColNo( KNSmlAdapterSyncType ), iContentTypes->At( aInd )->IntValue( EDSAdapterSyncType ) );
       
  1166 	iTableAdapters.SetColL( iColSetAdapters->ColNo( KNSmlAdapterFilterMatchType ), iContentTypes->At( aInd )->IntValue( EDSAdapterFilterMatchType ) );
       
  1167 
       
  1168 	TInt id = iTableAdapters.ColUint( iColSetAdapters->ColNo(KNSmlAdapterId ));
       
  1169 	
       
  1170 	iTableAdapters.PutL();
       
  1171 	
       
  1172 	iContentTypes->At( aInd )->SetIntValue( EDSAdapterTableId,  id);
       
  1173 	}
       
  1174 
       
  1175 //=============================================
       
  1176 //		CNSmlDSProfile::GetContentTypesL()
       
  1177 //		Member iContentTypes is resetted and appended
       
  1178 //		with CNSmlDSContentType objects.
       
  1179 //		Depending on parameter aMode method appends all or active content types.
       
  1180 //=============================================
       
  1181 
       
  1182 void CNSmlDSProfile::GetContentTypesL( const TNSmlDSContentTypeGetMode aMode )
       
  1183 	{
       
  1184 	HBufC* sqlStatement = HBufC::NewLC( KDSSQLGetAllContentTypes().Length() + KNSmlDsSettingsMaxIntegerLength);
       
  1185 	TPtr sqlStatementPtr = sqlStatement->Des();
       
  1186 
       
  1187 	switch ( aMode )
       
  1188 		{
       
  1189 		case ( EDSAllContentTypes ) :
       
  1190 			{
       
  1191 			sqlStatementPtr.Format( KDSSQLGetAllContentTypes, iId );
       
  1192 			}
       
  1193 		break;
       
  1194 		
       
  1195 		default:
       
  1196 			{
       
  1197 			CleanupStack::PopAndDestroy(); // sqlStatement
       
  1198 
       
  1199 			User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound );
       
  1200 			}
       
  1201 		}		
       
  1202 
       
  1203 	iContentTypes->Reset();
       
  1204 	
       
  1205 	PrepareViewL( sqlStatementPtr, iView.EReadOnly );
       
  1206 	
       
  1207 	CleanupStack::PopAndDestroy(); // sqlStatement
       
  1208 
       
  1209 	if ( iView.FirstL() )
       
  1210 		{
       
  1211 		ResetContentTypesL();
       
  1212 		while ( iView.NextL() )
       
  1213 			{
       
  1214 			ResetContentTypesL();
       
  1215 			}
       
  1216 		}
       
  1217 	}
       
  1218 	
       
  1219 
       
  1220 //=============================================
       
  1221 //		CNSmlDSProfile::GetContentTypeL( TInt aImplementationUID )
       
  1222 //		Gets contenttype with given impl. id.
       
  1223 //=============================================
       
  1224 CNSmlDSContentType* CNSmlDSProfile::GetContentTypeL( TInt aImplementationUID )
       
  1225 	{
       
  1226 	HBufC* sqlStatement = HBufC::NewLC( KDSSQLGetAllContentTypesByImplementationId().Length() + KNSmlDsSettingsMaxIntegerLength);
       
  1227 	TPtr sqlStatementPtr = sqlStatement->Des();
       
  1228 	sqlStatementPtr.Format( KDSSQLGetAllContentTypesByImplementationId, iId, aImplementationUID );
       
  1229 	
       
  1230 	PrepareViewL( sqlStatementPtr, iView.EReadOnly );
       
  1231 	
       
  1232 	CleanupStack::PopAndDestroy(); // sqlStatement
       
  1233 
       
  1234 	if ( iView.FirstL() )
       
  1235 		{
       
  1236 		ResetContentTypesL();
       
  1237 		}
       
  1238 
       
  1239 	return iContentTypes->At( iContentTypes->Count() - 1 );
       
  1240 	}
       
  1241 
       
  1242 //  End of File