omadm/omadmappui/src/NSmlDMSyncDocument.cpp
changeset 0 3ce708148e4d
child 8 0a8136f75056
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Methods for CNSmlDMSyncDocument
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <StringLoader.h>
       
    21 #include <eikenv.h>
       
    22 #include <centralrepository.h>
       
    23 #include <SyncMLNotifierDomainCRKeys.h>
       
    24 
       
    25 #include <e32const.h>
       
    26 #include <DevManInternalCRKeys.h>
       
    27 #include <e32property.h>
       
    28 #include "nsmldmsyncinternalpskeys.h"
       
    29 #include "NSmlDMSyncApp.h"
       
    30 #include "NSmlDMSyncAppEngine.h"
       
    31 #include "NSmlDMSyncDocument.h"
       
    32 #include "NSmlDMSyncAppUi.h"
       
    33 #include "NSmlDMSyncProfileList.h"
       
    34 #include "NSmlDMSyncProfile.h"
       
    35 #include "NSmlDMSyncDebug.h"
       
    36 #include <NSmlDMSync.rsg>
       
    37 #include <SyncService.h>
       
    38 #include <SyncServiceParams.h>
       
    39 #include <coreapplicationuisdomainpskeys.h>
       
    40 
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // Desctructor
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CNSmlDMSyncDocument::~CNSmlDMSyncDocument()
       
    49     {
       
    50     FLOG( "[OMADM] CNSmlDMSyncDocument::~CNSmlDMSyncDocument" );
       
    51     
       
    52     TInt err = RProperty::Delete(KPSUidNSmlDMSyncApp,KServerAlertType);
       
    53     FTRACE( FPrint(
       
    54             _L("CNSmlDMSyncDocument::~CNSmlDMSyncDocument KServerAlertType key deletion with error err = %d"),err ) );
       
    55     err = RProperty::Delete(KPSUidNSmlDMSyncApp, KFotaDLStatus);
       
    56     FTRACE( FPrint(
       
    57             _L("CNSmlDMSyncDocument::~CNSmlDMSyncDocumentKFotaDLStatus key deletion with error err = %d"),err ) );
       
    58    //IAD****
       
    59    
       
    60    err = RProperty::Delete(KPSUidNSmlDMSyncApp, KDMIdle);         
       
    61             
       
    62     err = RProperty::Delete(KPSUidNSmlDMSyncApp, KFotaDLRefresh);
       
    63     FTRACE( FPrint(
       
    64             _L("CNSmlDMSyncDocument::~CNSmlDMSyncDocumentKFotaDLRefresh key deletion with error err = %d"),err ) );
       
    65     err = RProperty::Delete(KPSUidNSmlDMSyncApp, KDmJobCancel);
       
    66     
       
    67     err = RProperty::Delete(KPSUidNSmlDMSyncApp, KSilentSession);
       
    68     
       
    69     FTRACE( FPrint(
       
    70             _L("CNSmlDMSyncDocument::~CNSmlDMSyncDocument KDmJobCancel key deletion with error err = %d"),err ) );
       
    71     delete iDbNotifier;
       
    72     delete iSyncProfileList;
       
    73 	delete iAppEngine;
       
    74 	if ( iProfileList )
       
    75 	    {
       
    76 	    iProfileList->Reset();
       
    77 	    delete iProfileList;
       
    78 	    }
       
    79     delete iServer;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CNSmlDMSyncDocument::ConstructL
       
    84 // Symbian 2nd phase constructor can leave.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CNSmlDMSyncDocument::ConstructL()
       
    88     {
       
    89     FLOG( "[OMADM] CNSmlDMSyncDocument::ConstructL" );
       
    90     
       
    91     iAppEngine = CNSmlDMSyncAppEngine::NewL( this );
       
    92     iSyncProfileList = CNSmlDMSyncProfileList::NewL( iAppEngine );
       
    93     iSilent = EFalse;
       
    94     iDbEventsBlocked = EFalse;
       
    95     iDbNotifier = CNSmlDMDbNotifier::NewL( iAppEngine->Session(), this );
       
    96     iDbNotifier->RequestL();
       
    97 
       
    98     iProfileList = new (ELeave) CArrayFixFlat< TNSmlDMProfileItem >(1);
       
    99     iCurrentIndex = 0;
       
   100     iEikEnv = CEikonEnv::Static();
       
   101     iOldProfileId = KErrNotFound;
       
   102     //SAN Spport
       
   103     TInt SanSupport( KErrNone );
       
   104     CRepository* centrep = NULL;
       
   105     TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys) );    
       
   106     if( err == KErrNone )
       
   107        {
       
   108     centrep->Get( KDevManSANUIBitVariation, SanSupport );
       
   109        }
       
   110     delete centrep;
       
   111     iSanSupport = SanSupport;
       
   112     
       
   113         _LIT_SECURITY_POLICY_S0( KWritePolicy, KUidSmlSyncApp.iUid );
       
   114         _LIT_SECURITY_POLICY_C1( KReadPolicy, ECapabilityReadDeviceData );
       
   115         _LIT_SECURITY_POLICY_C1( KWritePolicy1, ECapabilityWriteDeviceData );
       
   116         RProperty::Define( KPSUidNSmlDMSyncApp,
       
   117                            KServerAlertType,
       
   118                            RProperty::EInt,
       
   119                            KReadPolicy,
       
   120                            KWritePolicy );
       
   121     
       
   122      RProperty::Set( KPSUidNSmlDMSyncApp,
       
   123                 				    KServerAlertType,
       
   124                     				KErrNotFound );   	
       
   125 	err  = RProperty::Define( KPSUidNSmlDMSyncApp,
       
   126 			KFotaDLRefresh,
       
   127 			RProperty::EInt,KReadPolicy,KWritePolicy1); 
       
   128 	TInt err1 = KErrNotFound;
       
   129 	//if key defined then only set from DMUI, other wise fota sets it
       
   130 	if( err == KErrNone ) 
       
   131 		{
       
   132 		iDMDefinesFotaDLKey = ETrue;
       
   133 		err1 =      RProperty::Set( KPSUidNSmlDMSyncApp,
       
   134 				KFotaDLRefresh,KErrNone );    		 
       
   135 		}
       
   136 	FTRACE( FPrint(
       
   137 			_L("KFotaDLRefresh setting err = %d, err1 = %d"),err, err1 ) );
       
   138 //IAD ******//
       
   139 err  = RProperty::Define( KPSUidNSmlDMSyncApp,
       
   140 			KDMIdle,
       
   141 			RProperty::EInt); 
       
   142 err1 =  RProperty::Set( KPSUidNSmlDMSyncApp,
       
   143 			KDMIdle,KErrNone );
       
   144  if (err1)
       
   145  {
       
   146   FTRACE( FPrint(
       
   147 			_L("error in setting = %d, err1 = %d"),err, err1 ) );			
       
   148 
       
   149  }			 
       
   150 FTRACE( FPrint(
       
   151 			_L("KDMIdle setting err = %d, err1 = %d"),err, err1 ) );			
       
   152 			  
       
   153 
       
   154 	err  = RProperty::Define( KPSUidNSmlDMSyncApp,
       
   155 			KFotaDLStatus,
       
   156 			RProperty::EInt,KReadPolicy,KWritePolicy1); 
       
   157 	err1 =  RProperty::Set( KPSUidNSmlDMSyncApp,
       
   158 			KFotaDLStatus,KErrNotFound );   
       
   159 
       
   160     FLOG( "[OMADM] CNSmlDMSyncDocument::ConstructL() completed" );
       
   161 	FTRACE( FPrint(
       
   162 			_L("KFotaDLStatus setting err = %d, err1 = %d"),err, err1 ) );
       
   163 	err  = RProperty::Define( KPSUidNSmlDMSyncApp,
       
   164 			KDmJobCancel,
       
   165 			RProperty::EInt,KReadPolicy,KWritePolicy1); 
       
   166 	err1 =  RProperty::Set( KPSUidNSmlDMSyncApp,
       
   167 			KDmJobCancel, KErrNone );   
       
   168 			
       
   169 	// Define new P&S key to know whether these DM session started in Silent or
       
   170 	// User Interactive mode
       
   171 	
       
   172 	RProperty::Define( KPSUidNSmlDMSyncApp,
       
   173                            KSilentSession,
       
   174                            RProperty::EInt);
       
   175 	FTRACE( FPrint(
       
   176 			_L("KDmJobCancel setting err = %d, err1 = %d"),err, err1 ) );	
       
   177     FLOG( "[OMADM] CNSmlDMSyncDocument::ConstructL() completed" );
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CNSmlDMSyncDocument::NewL
       
   182 // Two-phased constructor.
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 CNSmlDMSyncDocument* CNSmlDMSyncDocument::NewL( CAknApplication& aApp )
       
   186     {
       
   187     FLOG( "[OMADM] CNSmlDMSyncDocument::NewL:" );
       
   188 
       
   189 	CNSmlDMSyncDocument* self = new (ELeave) CNSmlDMSyncDocument( aApp );
       
   190     CleanupStack::PushL( self );
       
   191     self->ConstructL();
       
   192     CleanupStack::Pop();  //self
       
   193 
       
   194     FLOG( "[OMADM] CNSmlDMSyncDocument::NewL() completed" );
       
   195     return self;
       
   196 	}
       
   197     
       
   198 // -----------------------------------------------------------------------------
       
   199 // CNSmlDMSyncDocument::CreateAppUiL
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 CEikAppUi* CNSmlDMSyncDocument::CreateAppUiL()
       
   203     {
       
   204     FLOG( "[OMADM] CNSmlDMSyncDocument::CreateAppUiL:" );
       
   205     
       
   206 	return new (ELeave) CNSmlDMSyncAppUi;
       
   207 	}
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CNSmlDMSyncDocument::DeleteProfile
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 TInt CNSmlDMSyncDocument::DeleteProfile( TInt& aIndex )
       
   214 	{
       
   215     FTRACE( FPrint(
       
   216         _L("[OMADM] CNSmlDMSyncDocument::DeleteProfile(), index = %d"),
       
   217         aIndex ) );
       
   218         
       
   219     TInt retVal = KErrNotFound;
       
   220 	if ( iProfileList->Count() <= 0 )
       
   221 		{
       
   222 		return retVal;
       
   223 		}
       
   224 	TRAP( retVal, iAppEngine->DeleteProfileL( 
       
   225 	                            (*iProfileList)[iCurrentIndex].iProfileId ) );
       
   226 	if ( retVal == KErrNone )
       
   227 		{
       
   228 		TRAP( retVal, ReadProfileListL() );
       
   229     	if ( retVal == KErrNone )
       
   230     		{		
       
   231     		if ( iCurrentIndex > iProfileList->Count() - 1 )
       
   232     			{
       
   233     			iCurrentIndex--;
       
   234     			}
       
   235     		aIndex = iCurrentIndex;
       
   236     		}
       
   237 		}
       
   238 
       
   239     FTRACE( FPrint(
       
   240         _L("[OMADM] CNSmlDMSyncDocument::DeleteProfile() completed, retval = %d, index = %d"),
       
   241         retVal, iCurrentIndex ) );
       
   242 	return retVal;
       
   243 	}
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CNSmlDMSyncDocument::ReadProfileListL
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 void CNSmlDMSyncDocument::ReadProfileListL()
       
   250 	{
       
   251 	ReadProfileListL( EFalse );
       
   252 	}
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CNSmlDMSyncDocument::ReadProfileListL
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void CNSmlDMSyncDocument::ReadProfileListL( TBool aIncludeHidden )
       
   259 	{
       
   260 	FLOG( "[OMADM] CNSmlDMSyncDocument::ReadProfileListL:" );
       
   261 
       
   262 	iProfileList->Reset();
       
   263 
       
   264 	TKeyArrayFix key(_FOFF( TNSmlDMProfileItem, iProfileName ), ECmpFolded16 );
       
   265 	iProfileList->Sort(key);
       
   266 
       
   267     iSyncProfileList->Reset();
       
   268 	
       
   269 	TRAPD( error, iSyncProfileList->ReadProfileItemsL( aIncludeHidden ) );
       
   270 	if ( error != KErrNone )
       
   271 	    {
       
   272 	    iSyncProfileList->Reset();
       
   273 	    }
       
   274 	
       
   275 	//read profile values
       
   276 	for ( TInt index = 0; index < iSyncProfileList->Count(); index++ )
       
   277 		{
       
   278 	    TNSmlDMProfileItem profile;
       
   279 		profile.iProfileName = iSyncProfileList->Item( index ).iProfileName;
       
   280 		if ( profile.iProfileName.Length() == 0 )
       
   281 			{
       
   282 			StringLoader::Load( profile.iProfileName, R_QTN_APPS_EMPTYPROFILE );
       
   283 			}		
       
   284     	profile.iProfileId   = iSyncProfileList->Item( index ).iProfileId;
       
   285 		profile.iBearer		 = iSyncProfileList->Item( index ).iBearer;
       
   286 		profile.iSynced      = iSyncProfileList->Item( index ).iSynced;
       
   287 		profile.iLastSync	 = iSyncProfileList->Item( index ).iLastSync;
       
   288 		profile.iLastSuccessSync	 = iSyncProfileList->Item( index ).iLastSuccessSync;
       
   289 		profile.iActive		 = iSyncProfileList->Item( index ).iActive;
       
   290         profile.iDeleteAllowed =  iSyncProfileList->Item( index ).iDeleteAllowed;
       
   291         profile.iProfileLocked =  iSyncProfileList->Item( index ).iProfileLocked;
       
   292         
       
   293 		TInt start = 0;
       
   294 		TBool found( EFalse );
       
   295 		
       
   296 		if ( iProfileList->Count() == 0 )
       
   297 			{
       
   298 			iProfileList->AppendL ( profile );		
       
   299 			}
       
   300 		else
       
   301 			{
       
   302 			while ( ( start < iProfileList->Count() ) && ( !found ) )
       
   303 				{
       
   304 				if ( iAppEngine->Compare( profile.iProfileName,
       
   305 				     iProfileList->At( start ).iProfileName ) < 1 )
       
   306 					{
       
   307 					iProfileList->InsertL( start, profile );
       
   308 					found = ETrue;
       
   309 					}
       
   310 				start++;
       
   311 				}
       
   312 			if ( !found ) //insert to the end of the list
       
   313 				{
       
   314 				iProfileList->AppendL( profile );
       
   315 				}
       
   316 			}
       
   317 		}
       
   318 	FLOG( "[OMADM] CNSmlDMSyncDocument::ReadProfileListL() completed" );
       
   319 	}
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // CNSmlDMSyncDocument::ProfileItem
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 TNSmlDMProfileItem* CNSmlDMSyncDocument::ProfileItem() const
       
   326 	{
       
   327     FTRACE( FPrint(
       
   328         _L("[OMADM] CNSmlDMSyncDocument::ProfileItem() iProfileList = 0x%x"),
       
   329         iProfileList ) );
       
   330 	
       
   331 	if ( iProfileList->Count() > 0 )
       
   332 		{
       
   333 		return &( *iProfileList )[ iCurrentIndex ];
       
   334 		}
       
   335 	return 0;
       
   336 	}
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CNSmlDMSyncDocument::ProfileItemAt
       
   340 // -----------------------------------------------------------------------------
       
   341 //
       
   342 TNSmlDMProfileItem* CNSmlDMSyncDocument::ProfileItemAt( TInt aIndex ) const
       
   343 	{
       
   344 	FLOG( "[OMADM] CNSmlDMSyncDocument::ProfileItemAt:" );
       
   345 	
       
   346 	if ( ( iProfileList->Count() > 0 ) &&
       
   347 	   ( ( aIndex >= 0 ) &&
       
   348 	   ( aIndex < iProfileList->Count() ) ) )
       
   349 		{
       
   350 		return &( *iProfileList )[aIndex];
       
   351 		}
       
   352 	return 0;
       
   353 	}
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CNSmlDMSyncDocument::FotaModel
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 CNSmlDMFotaModel* CNSmlDMSyncDocument::FotaModel() const
       
   360     {
       
   361     return ((CNSmlDMSyncAppUi*) iAppUi)->FotaModel();
       
   362     }
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // CNSmlDMSyncDocument::MarkFwUpdChangesStartL
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 void CNSmlDMSyncDocument::MarkFwUpdChangesStartL()
       
   369     {
       
   370     ((CNSmlDMSyncAppUi*) iAppUi)->MarkFwUpdChangesStartL();
       
   371     }
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // CNSmlDMSyncDocument::FwUpdStatesChangedL
       
   375 // -----------------------------------------------------------------------------
       
   376 //
       
   377 TBool CNSmlDMSyncDocument::FwUpdStatesChangedL()
       
   378     {
       
   379     return ((CNSmlDMSyncAppUi*) iAppUi)->FwUpdStatesChangedL();
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CNSmlDMSyncDocument::ProfileList
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 CArrayFixFlat< TNSmlDMProfileItem >* CNSmlDMSyncDocument::ProfileList( 
       
   387                                                                   TInt& aIndex )
       
   388 	{
       
   389 	FLOG( "[OMADM] CNSmlDMSyncDocument::ProfileList:" );
       
   390 	
       
   391 	if ( iCurrentIndex < 0 )
       
   392 		{
       
   393 		iCurrentIndex = 0;
       
   394 		}
       
   395 	aIndex = iCurrentIndex; 
       
   396 
       
   397 	FLOG( "[OMADM] CNSmlDMSyncDocument::ProfileList() completed" );
       
   398 	return iProfileList; 
       
   399 	}
       
   400 
       
   401 // -----------------------------------------------------------------------------
       
   402 // CNSmlDMSyncDocument::SetCurrentIndex
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 void CNSmlDMSyncDocument::SetCurrentIndex( TInt aIndex ) 
       
   406 	{
       
   407 	FLOG( "[OMADM] CNSmlDMSyncDocument::SetCurrentIndex:" );
       
   408 	
       
   409 	if ( ( aIndex > -1 ) && ( aIndex < iProfileList->Count() ) )
       
   410 		{
       
   411 		iCurrentIndex = aIndex; 
       
   412 		}
       
   413     FTRACE( FPrint(
       
   414         _L("[OMADM] CNSmlDMSyncDocument::SetCurrentIndex() completed, index = %d"),
       
   415         iCurrentIndex ) );
       
   416 	}
       
   417 
       
   418 // -----------------------------------------------------------------------------
       
   419 //  CNSmlDMSyncDocument::MoveIndexToProfile
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 void CNSmlDMSyncDocument::MoveIndexToProfile( TInt aProfileId )
       
   423 	{
       
   424     FTRACE( FPrint(
       
   425         _L("[OMADM] CNSmlDMSyncDocument::MoveIndexToProfile(), aProfileId = %d"),
       
   426         aProfileId ) );
       
   427 	
       
   428 	TInt index = 0;
       
   429 	TRAP_IGNORE( ReadProfileListL() );//new fix for the error  ELGO-6ZK8BD
       
   430 	TInt profileCount = iProfileList->Count();
       
   431 	
       
   432 	while ( ( index < profileCount ) &&
       
   433 	      ( (*iProfileList)[index].iProfileId != aProfileId ) )
       
   434 		{
       
   435 		index++;
       
   436 		}
       
   437 	if ( index < profileCount )
       
   438 		{
       
   439 		SetCurrentIndex( index );
       
   440 		}
       
   441 	else //Fix for SMAN-73XGBM
       
   442 		{
       
   443 		SetCurrentIndex( 0 );	
       
   444 		}
       
   445     FTRACE( FPrint(
       
   446         _L("[OMADM] CNSmlDMSyncDocument::MoveIndexToProfile() completed, index = %d"),
       
   447         index ) );
       
   448 	}
       
   449 
       
   450 // -----------------------------------------------------------------------------
       
   451 // CNSmlDMSyncDocument::GetCopyProfileL
       
   452 // -----------------------------------------------------------------------------
       
   453 //
       
   454 void CNSmlDMSyncDocument::GetCopyProfileL( TInt& aProfileId )
       
   455 	{
       
   456 	FLOG( "[OMADM] CNSmlDMSyncDocument::GetCopyProfileL:" );
       
   457 	
       
   458 	if ( iProfileList->Count() <= 0 )
       
   459 		{
       
   460 		return;
       
   461 		}
       
   462 	// save the original profileid, if it's not saved it can be deleted
       
   463 	iOldProfileId = ( *iProfileList )[iCurrentIndex].iProfileId;
       
   464 
       
   465 	CNSmlDMSyncProfile* profile = 
       
   466 	  iAppEngine->CreateCopyProfileL( (*iProfileList )[iCurrentIndex].iProfileId );
       
   467     
       
   468     profile->SetNameL( GetNextProfileNameLC()->Des() );
       
   469 	aProfileId = profile->ProfileId();
       
   470 	profile->SaveL();
       
   471 	iAppEngine->CloseProfile();
       
   472 	
       
   473 	CleanupStack::PopAndDestroy(); //name
       
   474 
       
   475 	FLOG( "[OMADM] CNSmlDMSyncDocument::GetCopyProfileL() completed" );
       
   476 	}
       
   477 
       
   478 // -----------------------------------------------------------------------------
       
   479 // CNSmlDMSyncDocument::GetNextProfileNameLC
       
   480 // -----------------------------------------------------------------------------
       
   481 HBufC* CNSmlDMSyncDocument::GetNextProfileNameLC()
       
   482 	{
       
   483 	FLOG( "[OMADM] CNSmlDMSyncDocument::GetNextProfileNameLC:" );
       
   484 	
       
   485 	TBool newNameFound = EFalse;
       
   486 	HBufC* profileName = NULL;
       
   487 	TInt nameIndex = 1;
       
   488 
       
   489 	while ( !newNameFound )
       
   490 		{
       
   491 		profileName = StringLoader::LoadLC( R_QTN_APPS_NEWPROFILE, nameIndex );
       
   492 		TNSmlDMProfileItem profileItem;
       
   493 		profileItem.iProfileName = *profileName;
       
   494 		TKeyArrayFix key(_FOFF(TNSmlDMProfileItem, iProfileName), ECmpFolded16 );
       
   495 
       
   496 		TInt foundIndex;
       
   497 		if ( iProfileList->Find( profileItem, key, foundIndex ) )
       
   498 			{
       
   499 			newNameFound = ETrue;
       
   500 			}
       
   501 		else
       
   502 			{
       
   503 			nameIndex++;
       
   504 			CleanupStack::PopAndDestroy( profileName );
       
   505 			}
       
   506 		}
       
   507 
       
   508     FTRACE( FPrint(
       
   509         _L("[OMADM] CNSmlDMSyncDocument::GetNextProfileNameLC() completed, name = \"%S\""),
       
   510         profileName ) );
       
   511 	return profileName;
       
   512 	}
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // DisableDbNotifications
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 void CNSmlDMSyncDocument::DisableDbNotifications( TBool aEvent )
       
   519     {
       
   520     iDbEventsBlocked = aEvent;
       
   521     }
       
   522 
       
   523 // -----------------------------------------------------------------------------
       
   524 // HandleDbEventL
       
   525 // -----------------------------------------------------------------------------
       
   526 //
       
   527 void CNSmlDMSyncDocument::HandleDbEventL( TNSmlDMDbEvent aEvent )
       
   528 	{
       
   529 	FLOG( "[OMADM] CNSmlDMSyncDocument::HandleDbEventL:" );
       
   530 	
       
   531 	if( !iDbEventsBlocked )
       
   532 	    {
       
   533         switch ( aEvent.iType )
       
   534     		{
       
   535     		case CNSmlDMDbNotifier::EClose:
       
   536     			iAppEngine->SyncCompleted( ENSmlRefreshMainView );
       
   537     			break;
       
   538     		
       
   539     		case CNSmlDMDbNotifier::EUpdate:
       
   540                 iSyncProfileList->ReadProfileItemL( aEvent.iProfileId );
       
   541                 iAppEngine->SyncCompleted( ENSmlRefreshMainView );
       
   542     			break;
       
   543 
       
   544     		case CNSmlDMDbNotifier::EDelete:
       
   545                 iSyncProfileList->Remove( aEvent.iProfileId );
       
   546                 iAppEngine->SyncCompleted( ENSmlRefreshMainView );
       
   547     			break;
       
   548 
       
   549     		case CNSmlDMDbNotifier::EUpdateAll:
       
   550                 iSyncProfileList->ReadProfileItemsL();
       
   551                 iAppEngine->SyncCompleted( ENSmlRefreshMainView );
       
   552     			break;
       
   553 
       
   554     		default:
       
   555     			break;
       
   556     		}
       
   557 	    }
       
   558 	FLOG( "[OMADM] CNSmlDMSyncDocument::HandleDbEventL() completed" );
       
   559 	}
       
   560 
       
   561 // -----------------------------------------------------------------------------
       
   562 // CNSmlDMSyncDocument::RestoreL
       
   563 //
       
   564 // Called (by the environment) when app is opened embedded.
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 void CNSmlDMSyncDocument::RestoreL( const CStreamStore& aStore,
       
   568                                     const CStreamDictionary& aStreamDic )
       
   569     {
       
   570 	FLOG( "[OMADM] CNSmlDMSyncDocument::RestoreL:" );
       
   571 	 
       
   572     TSyncParameters params;
       
   573     RStoreReadStream stream;
       
   574     stream.OpenLC( aStore, aStreamDic.At( KUidSyncParameterValue ) );
       
   575     params.InternalizeL( stream );
       
   576     CleanupStack::PopAndDestroy();  // stream
       
   577     switch ( params.iCommand )
       
   578         {
       
   579         case KSyncServCmdStartSync:
       
   580             {
       
   581             FLOG( "[OMADM] CNSmlDMSyncDocument::KSyncServCmdStartSync" );
       
   582             static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
       
   583    	        static _LIT_SECURITY_POLICY_C1(KAllowWriteDeviceDataPolicy, ECapabilityWriteDeviceData);
       
   584             TInt value = 1;
       
   585             TInt r=RProperty::Define(KUidSmlSyncApp,KNSmlDMSyncUiLaunchKey,RProperty::EInt,KAllowAllPolicy,KAllowWriteDeviceDataPolicy);
       
   586 	        if ( r!=KErrNone && r!=KErrAlreadyExists )
       
   587               {
       
   588     	       User::LeaveIfError(r);
       
   589               }
       
   590             if( r==KErrAlreadyExists || r==KErrNone )
       
   591              {
       
   592               TInt Value;
       
   593               TInt r=RProperty::Get(KUidSmlSyncApp,KNSmlDMSyncUiLaunchKey,Value);
       
   594             if( Value == 2 ) //DM UI launched from CP
       
   595              {
       
   596              FLOG( "[OMADM] CNSmlDMSyncDocument::RestoreL P& S value = 3:" );
       
   597              value = 3;	//DM UI launched from CP and now from server alert
       
   598              }
       
   599             else
       
   600              {FLOG( "[OMADM] CNSmlDMSyncDocument::RestoreL P& S value = 1:" );
       
   601              value = 1;	//DM UI launched as server alert             
       
   602              }              
       
   603             } 
       
   604             TInt r1=RProperty::Set(KUidSmlSyncApp,KNSmlDMSyncUiLaunchKey,value);   	  
       
   605             
       
   606 	    	AppEngine()->OpenProfileL( params.iProfileId );
       
   607             TInt bearer = AppEngine()->Profile()->BearerType();
       
   608             TBuf<KNSmlMaxProfileNameLength> serverName;
       
   609             AppEngine()->Profile()->GetName( serverName );
       
   610             
       
   611             // Server alerted sync should be checked to prevent the sending
       
   612             // the application to background in case the user has opened it.
       
   613            if ( iSanSupport == EOn )
       
   614            {
       
   615            	RProperty::Set( KPSUidNSmlDMSyncApp,
       
   616                 				    KServerAlertType,
       
   617                     				params.iSilent );            
       
   618             if ( params.iSilent == 1 )                 
       
   619             	{
       
   620                 iSilent = ETrue;  // For already DM app open case also
       
   621             	}             				            
       
   622             if ( IsServerAlertSync()
       
   623                 && params.iSilent == 1 
       
   624                  )
       
   625             	{
       
   626                 TApaTaskList taskList( iEikEnv->WsSession() );
       
   627                 TApaTask task(taskList.FindApp( KUidSmlSyncApp ) );
       
   628                 task.SetWgId( iEikEnv->RootWin().Identifier() ); 
       
   629                 task.SendToBackground();
       
   630             	}
       
   631            }
       
   632 		else if ( IsServerAlertSync())
       
   633 			{
       
   634 			if(AppEngine()->Profile()->SASyncState() == ESASyncStateEnable )
       
   635                 {
       
   636                 	//new fix for DD and DL not shown for Accepted "yes"
       
   637                 RProperty::Set( KPSUidNSmlDMSyncApp,
       
   638 						KServerAlertType, 1 );	
       
   639                 TApaTaskList taskList( iEikEnv->WsSession() );
       
   640                 TApaTask task(taskList.FindApp( KUidSmlSyncApp ) );
       
   641                 task.SetWgId( iEikEnv->RootWin().Identifier() ); 
       
   642                 task.SendToBackground();
       
   643                 }
       
   644 			else
       
   645 				{
       
   646 				RProperty::Set( KPSUidNSmlDMSyncApp,
       
   647 						KServerAlertType, 0 );	
       
   648 				}
       
   649 			}
       
   650 		    AppEngine()->CloseProfile();
       
   651 
       
   652             // Simpler FOTA progress note is not used in server initiated
       
   653             // management sessions and EFalse can be given as parameter.
       
   654         	AppEngine()->SynchronizeL( serverName, 
       
   655         	                           params.iProfileId,
       
   656         	                           params.iJobId,
       
   657         	                           bearer,
       
   658         	                           EFalse );
       
   659         	break;
       
   660             }
       
   661         case KSyncServCmdShowProgress:
       
   662             {
       
   663             FLOG( "[OMADM] CNSmlDMSyncDocument::KSyncServCmdShowProgress" );
       
   664             if ( iSanSupport == EOn )
       
   665               {
       
   666            	  RProperty::Set( KPSUidNSmlDMSyncApp,
       
   667                 				    KServerAlertType,
       
   668                     				params.iSilent );            
       
   669               if ( params.iSilent == 1 )                 
       
   670             	{
       
   671                 iSilent = ETrue;  
       
   672             	}
       
   673               }
       
   674                          
       
   675             if ( params.iJobId == KSyncServEnabled)
       
   676                 {                
       
   677                 AppEngine()->ShowProgressDialogL( ETrue );
       
   678                 }
       
   679             else
       
   680                 {                
       
   681                 AppEngine()->ShowProgressDialogL( EFalse );
       
   682                 }
       
   683             break;
       
   684             }
       
   685         default:
       
   686             {
       
   687             break;
       
   688             }
       
   689         }
       
   690     FLOG( "[OMADM] CNSmlDMSyncDocument::RestoreL() completed" );
       
   691     }
       
   692 
       
   693 // -----------------------------------------------------------------------------
       
   694 // CNSmlDMSyncDocument::IsServerAlertSync
       
   695 // -----------------------------------------------------------------------------
       
   696 //		
       
   697 TBool CNSmlDMSyncDocument::IsServerAlertSync()
       
   698     {
       
   699     FLOG( "CNSmlDMSyncDocument::IsServerAlertSync" );
       
   700     
       
   701     return iEikEnv->StartedAsServerApp();
       
   702     }
       
   703     
       
   704 // -----------------------------------------------------------------------------
       
   705 // CNSmlDMSyncDocument::StartServerL
       
   706 // -----------------------------------------------------------------------------
       
   707 //		
       
   708 void CNSmlDMSyncDocument::StartServerL()
       
   709     {
       
   710     FLOG( "CNSmlDMSyncDocument::StartServerL" );
       
   711    
       
   712 	CApaApplication* app = Application();
       
   713 	app->NewAppServerL( iServer ); 
       
   714 	TBuf<KMaxFullName> DmAppName;
       
   715     CRepository* centrep = NULL;
       
   716     centrep = CRepository::NewL( KCRUidNSmlNotifierDomainKeys );
       
   717     centrep->Get( KNSmlDMAppName, DmAppName );
       
   718     delete centrep;
       
   719     iServer->ConstructL( DmAppName );
       
   720 	
       
   721 	FLOG( "CNSmlDMSyncDocument::StartServerL Done" );
       
   722     }
       
   723 
       
   724 // -----------------------------------------------------------------------------    
       
   725 // CNSmlDMSyncDocument::SANSupport()
       
   726 // -----------------------------------------------------------------------------
       
   727 //
       
   728 TBool CNSmlDMSyncDocument::SANSupport()
       
   729     {
       
   730     FLOG( "CNSmlDMSyncDocument::SANSupport" );   		
       
   731     if ( iSanSupport == EOn )
       
   732         {
       
   733         	return ETrue;
       
   734         }	
       
   735     FLOG( "CNSmlDMSyncDocument::SANSupportDone" );    
       
   736     return EFalse;    
       
   737 	  
       
   738     }
       
   739     
       
   740 // -----------------------------------------------------------------------------    
       
   741 // CNSmlDMSyncDocument::SilentSession()
       
   742 // -----------------------------------------------------------------------------
       
   743 //
       
   744 TBool CNSmlDMSyncDocument::SilentSession()
       
   745     {
       
   746     FLOG( "CNSmlDMSyncDocument::SilentSession" );   		
       
   747     TBool silent = ETrue;
       
   748     TInt silentenabled = 0;
       
   749     TInt silentdisabled = 1; 
       
   750     if(iSilent == silent)
       
   751     {
       
   752     
       
   753     RProperty::Set( KPSUidNSmlDMSyncApp,
       
   754                     KSilentSession,
       
   755                     silentenabled );     
       
   756     } 
       
   757     else
       
   758     {
       
   759     RProperty::Set( KPSUidNSmlDMSyncApp,
       
   760                     KSilentSession,
       
   761                     silentdisabled ); 	
       
   762     }	
       
   763 
       
   764     // If trust is establish then default make application management silent
       
   765 
       
   766     TInt tarmtrustenabled = KErrNone;
       
   767     RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsTarmIndicator, tarmtrustenabled);
       
   768 
       
   769 
       
   770     if(tarmtrustenabled == ECoreAppUIsTarmTerminalSecurityOnIndicatorOn || 
       
   771        tarmtrustenabled ==ECoreAppUIsTarmMngActiveIndicatorOn )
       
   772     {
       
   773 
       
   774 	 RProperty::Set( KPSUidNSmlDMSyncApp,
       
   775                     KSilentSession,
       
   776                     silentenabled ); 
       
   777 
       
   778     }
       
   779 	
       
   780     return iSilent;    
       
   781     }    
       
   782     
       
   783 // -----------------------------------------------------------------------------    
       
   784 // CNSmlDMSyncDocument::ResetSession()
       
   785 // -----------------------------------------------------------------------------
       
   786 //   
       
   787 void CNSmlDMSyncDocument::ResetSession()
       
   788 	{
       
   789 	FLOG( "CNSmlDMSyncDocument::ResetSession" );   		
       
   790     iSilent = EFalse;
       
   791     FLOG( "CNSmlDMSyncDocument::ResetSession" );        	
       
   792 	}
       
   793 	
       
   794 // -----------------------------------------------------------------------------    
       
   795 // CNSmlDMSyncDocument::CurrentIndex()
       
   796 // -----------------------------------------------------------------------------
       
   797 //	
       
   798 TInt CNSmlDMSyncDocument::CurrentIndex()
       
   799   {
       
   800   return iCurrentIndex;	
       
   801   }	
       
   802 
       
   803 // -----------------------------------------------------------------------------    
       
   804 // CNSmlDMSyncDocument::DMDefinesFotaDLKey()
       
   805 // -----------------------------------------------------------------------------
       
   806 //
       
   807 TBool CNSmlDMSyncDocument::DMDefinesFotaDLKey()
       
   808 	{
       
   809 	return iDMDefinesFotaDLKey;
       
   810 	}
       
   811 // End of File