omads/omadsappui/AspSyncUtil/src/AspProfile.cpp
branchRCL_3
changeset 14 b922b9936679
parent 8 ad0f53516d84
child 15 3f1ffafb31ec
equal deleted inserted replaced
8:ad0f53516d84 14:b922b9936679
    19 
    19 
    20 // INCLUDES
    20 // INCLUDES
    21 
    21 
    22 #include <SyncMLTransportProperties.h>
    22 #include <SyncMLTransportProperties.h>
    23 #include <featmgr.h>   // FeatureManager
    23 #include <featmgr.h>   // FeatureManager
       
    24 #include <centralrepository.h> // CRepository
       
    25 #include <NSmlOperatorDataCRKeys.h> // KCRUidOperatorDatasyncInternalKeys
       
    26 
    24 #include <calsession.h>
    27 #include <calsession.h>
    25 #include <calcalendarinfo.h>
    28 #include <calcalendarinfo.h>
    26 #include <e32math.h>
    29 #include <e32math.h>
    27 #include <gdi.h>
    30 #include <gdi.h>
    28 
    31 
   405 	RArray<TSmlDataProviderId> arr;
   408 	RArray<TSmlDataProviderId> arr;
   406 	
   409 	
   407 	Session().ListDataProvidersL(arr);
   410 	Session().ListDataProvidersL(arr);
   408 	CleanupClosePushL(arr);
   411 	CleanupClosePushL(arr);
   409 
   412 
       
   413 	TBool operatorProfile = CAspProfile::IsOperatorProfileL(iProfile);
       
   414 	TInt operatorUid = CAspProfile::OperatorAdapterUidL();
       
   415 	TInt profileUid = CAspProfile::ProfileAdapterUidL();
       
   416 	
   410 	TInt count = arr.Count();
   417 	TInt count = arr.Count();
   411 	for (TInt i=0; i<count; i++)
   418 	for (TInt i=0; i<count; i++)
   412 		{
   419 		{
   413 		RSyncMLDataProvider provider;
   420 		RSyncMLDataProvider provider;
   414 		TInt id = arr[i];
   421 		TInt id = arr[i];
   428 		    	// providers must have display name
   435 		    	// providers must have display name
   429 		    	CleanupStack::PopAndDestroy(&provider);
   436 		    	CleanupStack::PopAndDestroy(&provider);
   430 		    	FTRACE( RDebug::Print(_L("### provider has no display name (id=%x) ###"), item.iDataProviderId) );
   437 		    	FTRACE( RDebug::Print(_L("### provider has no display name (id=%x) ###"), item.iDataProviderId) );
   431 		    	continue;
   438 		    	continue;
   432 		    	}
   439 		    	}
   433 	
   440 
   434 		    User::LeaveIfError(iProviderList.Append(item));
   441 		    if ( iApplicationId == 0 )
   435 	        
   442 		        {
       
   443 		        if ( operatorProfile )
       
   444 		            {
       
   445 		            if ( id != KUidNSmlAdapterContact.iUid )
       
   446 		                {
       
   447 		                User::LeaveIfError(iProviderList.Append(item)); 
       
   448 		                }
       
   449 		            }
       
   450 		        else
       
   451 		            {
       
   452 		            if ( id != operatorUid && id != profileUid )
       
   453 		                {
       
   454 		                User::LeaveIfError(iProviderList.Append(item));
       
   455 		                }
       
   456 		            }
       
   457 		        }
       
   458 		    else
       
   459 		        {
       
   460                 User::LeaveIfError(iProviderList.Append(item));
       
   461 		        }
       
   462             
   436 	        CleanupStack::PopAndDestroy(&provider);
   463 	        CleanupStack::PopAndDestroy(&provider);
   437 		    }
   464 		    }
   438 		    
   465 		    
   439 		if (err != KErrNone)
   466 		if (err != KErrNone)
   440 			{
   467 			{
  2240 	TAspProfileItem item;
  2267 	TAspProfileItem item;
  2241 	item.Init();
  2268 	item.Init();
  2242 
  2269 
  2243 	if (iApplicationId != EApplicationIdSync)
  2270 	if (iApplicationId != EApplicationIdSync)
  2244 		{
  2271 		{
  2245 		TInt dataProviderId = TUtil::ProviderIdFromAppId(iApplicationId);
  2272 		TInt dataProviderId = TUtil::ProviderIdFromAppId(iApplicationId, CAspProfile::IsOperatorProfileL(profile));
  2246 		TInt taskId = TAspTask::FindTaskIdL(profile, dataProviderId, KNullDesC);
  2273 		TInt taskId = TAspTask::FindTaskIdL(profile, dataProviderId, KNullDesC);
  2247 		item.iTaskId = taskId; // needed for syncing only one content 
  2274 		item.iTaskId = taskId; // needed for syncing only one content 
  2248 		}
  2275 		}
  2249 	
  2276 	
  2250 	ReadProfileItemL(profile, item);
  2277 	ReadProfileItemL(profile, item);
  2323 		else
  2350 		else
  2324 			{
  2351 			{
  2325 			profile->OpenL(id, CAspProfile::EOpenRead, CAspProfile::EAllProperties);
  2352 			profile->OpenL(id, CAspProfile::EOpenRead, CAspProfile::EAllProperties);
  2326 			}
  2353 			}
  2327 			
  2354 			
       
  2355 		
       
  2356 		// Hidden operator specific profile should not be visible
       
  2357 		if (profile->IsHiddenOperatorProfileL())
       
  2358 		    {
       
  2359 		    CleanupStack::PopAndDestroy(profile);
       
  2360 		    continue;
       
  2361 		    }
  2328 
  2362 
  2329 		TAspProfileItem item;
  2363 		TAspProfileItem item;
  2330 		item.Init();
  2364 		item.Init();
  2331 		
  2365 		
  2332 		if (iApplicationId != EApplicationIdSync)
  2366 		if (iApplicationId != EApplicationIdSync)
  2333 			{
  2367 			{
  2334 			TInt dataProviderId = TUtil::ProviderIdFromAppId(iApplicationId);
  2368 			TInt dataProviderId = TUtil::ProviderIdFromAppId(iApplicationId, CAspProfile::IsOperatorProfileL(profile));
  2335 			TInt taskId = TAspTask::FindTaskIdL(profile, dataProviderId, KNullDesC);
  2369 			TInt taskId = TAspTask::FindTaskIdL(profile, dataProviderId, KNullDesC);
  2336 			item.iTaskId = taskId; // needed for syncing only one content 
  2370 			item.iTaskId = taskId; // needed for syncing only one content 
  2337 			}
  2371 			}
  2338 		
  2372 		
  2339 		if (aListMode == EBasePropertiesOnly)
  2373 		if (aListMode == EBasePropertiesOnly)
  2565 	TInt serverIdLen = aServerId.Length();
  2599 	TInt serverIdLen = aServerId.Length();
  2566 	if (serverIdLen == 0)
  2600 	if (serverIdLen == 0)
  2567 		{
  2601 		{
  2568 		return ETrue;
  2602 		return ETrue;
  2569 		}
  2603 		}
  2570 		
  2604 
       
  2605     // Operator specific serverID is not considered as unique
       
  2606 	if (CAspProfile::EqualsToOperatorServerId(aServerId))
       
  2607 	    {
       
  2608 	    return EFalse;
       
  2609 	    }
       
  2610 
  2571 	TBool serverIdFound = EFalse;
  2611 	TBool serverIdFound = EFalse;
  2572 	
  2612 	
  2573 	TInt count = iList.Count();
  2613 	TInt count = iList.Count();
  2574 	for (TInt i=0; i<count; i++)
  2614 	for (TInt i=0; i<count; i++)
  2575 		{
  2615 		{
  2914 // CAspProfile::DeleteAllowed
  2954 // CAspProfile::DeleteAllowed
  2915 //
  2955 //
  2916 // -----------------------------------------------------------------------------
  2956 // -----------------------------------------------------------------------------
  2917 //
  2957 //
  2918 TBool CAspProfile::DeleteAllowed()
  2958 TBool CAspProfile::DeleteAllowed()
  2919 	{
  2959     {
  2920 	return iProfile.DeleteAllowed();
  2960     TBool operatorProfile = EFalse;
  2921 	}
  2961     TRAPD( err, operatorProfile = IsReadOnlyOperatorProfileL() );
       
  2962 
       
  2963     // Disallow deletion of operator specific profile
       
  2964     if( err == KErrNone && operatorProfile )
       
  2965         {
       
  2966         return EFalse;
       
  2967         }
       
  2968     else
       
  2969         {
       
  2970         return iProfile.DeleteAllowed();
       
  2971         }
       
  2972     }
  2922 
  2973 
  2923 
  2974 
  2924 // -----------------------------------------------------------------------------
  2975 // -----------------------------------------------------------------------------
  2925 // CAspProfile::IsSynced
  2976 // CAspProfile::IsSynced
  2926 //
  2977 //
  4121             	return;
  4172             	return;
  4122             }
  4173             }
  4123  		}
  4174  		}
  4124 }
  4175 }
  4125 
  4176 
  4126 
  4177 //-----------------------------------------------------------------------------
       
  4178 // CAspProfile:::IsOperatorProfileL
       
  4179 // 
       
  4180 //-----------------------------------------------------------------------------
       
  4181 //
       
  4182 TBool CAspProfile::IsOperatorProfileL( CAspProfile* aProfile )
       
  4183     {
       
  4184     if ( !aProfile )
       
  4185         {
       
  4186         return EFalse;
       
  4187         }
       
  4188 
       
  4189     TBuf<KBufSize255> serverId;
       
  4190     TBuf8<KBufSize255> serverIdUtf8;
       
  4191     TBuf8<KBufSize255> value;
       
  4192     
       
  4193     aProfile->GetServerId( serverId );
       
  4194     if ( serverId.Length() > 0 )
       
  4195         {
       
  4196         serverIdUtf8.Copy( serverId );
       
  4197     
       
  4198         CRepository* rep = CRepository::NewLC( KCRUidOperatorDatasyncInternalKeys );
       
  4199         TInt err = rep->Get( KNsmlOpDsOperatorSyncServerId, value );
       
  4200         CleanupStack::PopAndDestroy( rep );
       
  4201     
       
  4202         if ( !err && serverIdUtf8.Compare( value ) == 0 )
       
  4203             {
       
  4204             return ETrue;
       
  4205             }
       
  4206         }
       
  4207     return EFalse;
       
  4208     }
       
  4209 
       
  4210 //-----------------------------------------------------------------------------
       
  4211 // CAspProfile:::OperatorAdapterUidL
       
  4212 // 
       
  4213 //-----------------------------------------------------------------------------
       
  4214 //
       
  4215 TInt CAspProfile::OperatorAdapterUidL()
       
  4216     {
       
  4217     TInt value = 0;
       
  4218     CRepository* rep = CRepository::NewLC( KCRUidOperatorDatasyncInternalKeys );
       
  4219     rep->Get( KNsmlOpDsOperatorAdapterUid, value );
       
  4220     CleanupStack::PopAndDestroy( rep );
       
  4221     return value;
       
  4222     }
       
  4223 
       
  4224 //-----------------------------------------------------------------------------
       
  4225 // CAspProfile:::ProfileAdapterUidL
       
  4226 // 
       
  4227 //-----------------------------------------------------------------------------
       
  4228 //
       
  4229 TInt CAspProfile::ProfileAdapterUidL()
       
  4230     {
       
  4231     TInt value = 0;
       
  4232     CRepository* rep = CRepository::NewLC( KCRUidOperatorDatasyncInternalKeys );
       
  4233     rep->Get( KNsmlOpDsProfileAdapterUid, value );
       
  4234     CleanupStack::PopAndDestroy( rep );
       
  4235     return value;
       
  4236     }
       
  4237 
       
  4238 //-----------------------------------------------------------------------------
       
  4239 // CAspProfile:::ProfileVisibilityL
       
  4240 // 
       
  4241 //-----------------------------------------------------------------------------
       
  4242 //
       
  4243 TInt CAspProfile::ProfileVisibilityL()
       
  4244     {
       
  4245     TInt value = 0;
       
  4246     CRepository* rep = CRepository::NewLC( KCRUidOperatorDatasyncInternalKeys );
       
  4247     rep->Get( KNsmlOpDsSyncProfileVisibility, value );
       
  4248     CleanupStack::PopAndDestroy( rep );
       
  4249     return value;
       
  4250     }
       
  4251 
       
  4252 //-----------------------------------------------------------------------------
       
  4253 // CAspProfile:::IsReadOnlyOperatorProfileL
       
  4254 // 
       
  4255 //-----------------------------------------------------------------------------
       
  4256 //
       
  4257 TBool CAspProfile::IsReadOnlyOperatorProfileL()
       
  4258     {
       
  4259     return ( IsOperatorProfileL( this ) && 
       
  4260         ProfileVisibilityL() == EProfileVisibilityReadOnly );
       
  4261     }
       
  4262 
       
  4263 //-----------------------------------------------------------------------------
       
  4264 // CAspProfile:::IsHiddenOperatorProfileL
       
  4265 // 
       
  4266 //-----------------------------------------------------------------------------
       
  4267 //
       
  4268 TBool CAspProfile::IsHiddenOperatorProfileL()
       
  4269     {
       
  4270     return ( IsOperatorProfileL( this ) && 
       
  4271         ProfileVisibilityL() == EProfileVisibilityHidden );
       
  4272     }
       
  4273 
       
  4274 //-----------------------------------------------------------------------------
       
  4275 // CAspProfile:::EqualsToOperatorServerIdL
       
  4276 // 
       
  4277 //-----------------------------------------------------------------------------
       
  4278 //
       
  4279 TBool CAspProfile::EqualsToOperatorServerId( const TDesC& aServerId )
       
  4280     {
       
  4281     if ( aServerId.Length() > 0 )
       
  4282         {
       
  4283         TBuf8<KBufSize255> serverIdUtf8;
       
  4284         TBuf8<KBufSize255> value;
       
  4285         serverIdUtf8.Copy( aServerId );
       
  4286 
       
  4287         // Read operator specific serverId from cenrep
       
  4288         CRepository* rep = NULL;
       
  4289         TRAPD( err, rep = CRepository::NewL( KCRUidOperatorDatasyncInternalKeys ) );
       
  4290         if( err == KErrNone )
       
  4291             {
       
  4292             rep->Get( KNsmlOpDsOperatorSyncServerId, value );
       
  4293             delete rep;
       
  4294 
       
  4295             if ( serverIdUtf8.Compare( value ) == 0 )
       
  4296                 {
       
  4297                 return ETrue;
       
  4298                 }
       
  4299             }
       
  4300         }
       
  4301 
       
  4302     return EFalse;
       
  4303     }
  4127 
  4304 
  4128 /*******************************************************************************
  4305 /*******************************************************************************
  4129  * class TAspTask
  4306  * class TAspTask
  4130  *******************************************************************************/
  4307  *******************************************************************************/
  4131 
  4308