omadm/omadmappui/src/NSmlDMSyncAppEngine.cpp
branchRCL_3
changeset 25 5b858729772b
equal deleted inserted replaced
24:6757f1e2efd2 25:5b858729772b
       
     1 /*
       
     2 * Copyright (c) 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 CNSmlDMSyncAppEngine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "NSmlDMSyncAppEngine.h"
       
    20 #include "NSmlDMSyncDebug.h"
       
    21 #include "NSmlDMSyncHandler.h"
       
    22 #include <collate.h>
       
    23 #include <e32property.h>
       
    24 #include "nsmldmsyncinternalpskeys.h"
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ==============================
       
    27 //
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CNSmlDMSyncAppEngine::CNSmlDMSyncAppEngine
       
    31 // C++ default constructor can NOT contain any code, that
       
    32 // might leave.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CNSmlDMSyncAppEngine::CNSmlDMSyncAppEngine() : iProgressShown( ETrue )
       
    36 	{
       
    37 	FLOG( "[OMADM] CNSmlDMSyncAppEngine::CNSmlDMSyncAppEngine:" );
       
    38 	
       
    39 	}
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CNSmlDMSyncAppEngine::ConstructL
       
    43 // Symbian 2nd phase constructor can leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 void CNSmlDMSyncAppEngine::ConstructL( CNSmlDMSyncDocument* aSyncDocument )
       
    47     {
       
    48     FLOG( "[OMADM] CNSmlDMSyncAppEngine::ConstructL:" );
       
    49     
       
    50     iSyncMLSession.OpenL();
       
    51     iSyncHandler = CNSmlDMSyncHandler::NewL( &iSyncMLSession,
       
    52                                              this,
       
    53                                              aSyncDocument );
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CNSmlDMSyncAppEngine::NewL
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CNSmlDMSyncAppEngine* CNSmlDMSyncAppEngine::NewL(
       
    62     CNSmlDMSyncDocument* aSyncDocument )
       
    63 	{
       
    64 	FLOG( "[OMADM] CNSmlDMSyncAppEngine::NewL:" );
       
    65 	
       
    66 	CNSmlDMSyncAppEngine* self = new( ELeave ) CNSmlDMSyncAppEngine();
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL( aSyncDocument );
       
    69     CleanupStack::Pop();
       
    70 
       
    71     return self;
       
    72 	}
       
    73 
       
    74 // ------------------------------------------------------------------------------
       
    75 // Destructor
       
    76 // ------------------------------------------------------------------------------
       
    77 //
       
    78 CNSmlDMSyncAppEngine::~CNSmlDMSyncAppEngine()
       
    79     {
       
    80     FLOG( "[OMADM] CNSmlDMSyncAppEngine::~CNSmlDMSyncAppEngine:" );
       
    81     
       
    82     delete iSyncHandler;
       
    83     delete iProfile;        
       
    84     iSyncMLSession.Close();
       
    85 	}
       
    86 
       
    87 // ------------------------------------------------------------------------------
       
    88 // CNSmlDMSyncAppEngine::DeleteProfileL
       
    89 // ------------------------------------------------------------------------------
       
    90 //
       
    91 void CNSmlDMSyncAppEngine::DeleteProfileL( TInt aProfileId )
       
    92     {
       
    93     FLOG( "[OMADM] CNSmlDMSyncAppEngine::DeleteProfileL:" );
       
    94     
       
    95     delete iProfile;
       
    96     iProfile = NULL;
       
    97     iSyncMLSession.DeleteProfileL( aProfileId );
       
    98 	}
       
    99 
       
   100 // ------------------------------------------------------------------------------
       
   101 // CNSmlDMSyncAppEngine::CreateProfileL
       
   102 // ------------------------------------------------------------------------------
       
   103 //
       
   104 TInt CNSmlDMSyncAppEngine::CreateProfileL()
       
   105     {
       
   106     FLOG( "[OMADM] CNSmlDMSyncAppEngine::CreateProfileL:" );
       
   107     
       
   108     delete iProfile;
       
   109     iProfile = NULL;
       
   110     iProfile = CNSmlDMSyncProfile::NewL( KUidSmlSyncApp.iUid, &iSyncMLSession );
       
   111     return iProfile->CreateL();
       
   112 	}
       
   113 
       
   114 // ------------------------------------------------------------------------------
       
   115 // CNSmlDMSyncAppEngine::Profile
       
   116 // ------------------------------------------------------------------------------
       
   117 //
       
   118 CNSmlDMSyncProfile* CNSmlDMSyncAppEngine::Profile( )
       
   119     {
       
   120     FLOG( "[OMADM] CNSmlDMSyncAppEngine::Profile:" );
       
   121     
       
   122     return iProfile;
       
   123 	}
       
   124 	
       
   125 // ------------------------------------------------------------------------------
       
   126 // CNSmlDMSyncAppEngine::CreateCopyProfileL
       
   127 // ------------------------------------------------------------------------------
       
   128 //
       
   129 CNSmlDMSyncProfile* CNSmlDMSyncAppEngine::CreateCopyProfileL( TInt aProfileId )
       
   130     {
       
   131     FLOG( "[OMADM] CNSmlDMSyncAppEngine::CreateCopyProfileL:" );
       
   132     
       
   133     delete iProfile;
       
   134     iProfile = NULL;
       
   135     iProfile = CNSmlDMSyncProfile::NewL( KUidSmlSyncApp.iUid, &iSyncMLSession );
       
   136     
       
   137     iProfile->CreateCopyL( aProfileId );
       
   138     return iProfile;
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CNSmlDMSyncAppEngine::Session
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 RSyncMLSession* CNSmlDMSyncAppEngine::Session()
       
   146 	{
       
   147 	FLOG( "[OMADM] CNSmlDMSyncAppEngine::Session:" );
       
   148 	
       
   149 	return &iSyncMLSession;
       
   150 	}
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CNSmlDMSyncAppEngine::OpenL
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 CNSmlDMSyncProfile* CNSmlDMSyncAppEngine::OpenProfileL( TInt aProfileId,
       
   157                                                         TInt aOpenMode )
       
   158     {
       
   159 	FLOG( "[OMADM] CNSmlDMSyncAppEngine::OpenL:" );
       
   160 	
       
   161     delete iProfile;
       
   162     iProfile = NULL;
       
   163     iProfile = CNSmlDMSyncProfile::NewL( KUidSmlSyncApp.iUid, &iSyncMLSession );
       
   164    	iProfile->OpenL( aProfileId, aOpenMode );
       
   165    	return iProfile;
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CNSmlDMSyncAppEngine::Close
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CNSmlDMSyncAppEngine::CloseProfile()
       
   173     {
       
   174     FLOG(  "[OMADM] CNSmlDMSyncAppEngine::Close:" );
       
   175 
       
   176     delete iProfile;
       
   177     iProfile = NULL;
       
   178     }
       
   179     
       
   180 // -----------------------------------------------------------------------------
       
   181 // CNSmlDMSyncAppEngine::SynchronizeL
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void CNSmlDMSyncAppEngine::SynchronizeL( TDesC& aServerName,
       
   185                                          TInt aProfileId,
       
   186                                          TInt aConnectionBearer,
       
   187                                          const TBool aUseFotaProgressNote )
       
   188     {
       
   189     FLOG( "[OMADM] CNSmlDMSyncAppEngine::SynchronizeL:" );
       
   190     	
       
   191     iProgressShown = ETrue;
       
   192     iSyncHandler->SynchronizeL( aServerName,
       
   193                                 aProfileId,
       
   194                                 aConnectionBearer,
       
   195                                 aUseFotaProgressNote );
       
   196     }
       
   197     
       
   198 // -----------------------------------------------------------------------------
       
   199 // CNSmlDMSyncAppEngine::SynchronizeL
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CNSmlDMSyncAppEngine::SynchronizeL( TDesC& aServerName,
       
   203                                          TInt aProfileId,
       
   204                                          TInt aJobId,
       
   205                                          TInt aConnectionBearer,
       
   206                                          const TBool aUseFotaProgressNote,
       
   207                                          TBool aSilent)
       
   208     {
       
   209    	FLOG( "[OMADM] CNSmlDMSyncAppEngine::SynchronizeL:" );
       
   210 
       
   211     iProgressShown = ETrue;
       
   212     TInt err = RProperty::Set( KPSUidNSmlDMSyncApp,
       
   213     				KDmJobCancel, KErrNone );
       
   214     FTRACE(FPrint(
       
   215     	_L("CNSmlDMSyncAppEngine::SynchronizeL()KDmJobCancel reset to 0 err = %d"),
       
   216     										err ) );
       
   217     iSyncHandler->SynchronizeL( aServerName, 
       
   218                                 aProfileId, 
       
   219                                 aJobId, 
       
   220                                 aConnectionBearer,
       
   221                                 aUseFotaProgressNote,
       
   222                                 aSilent);
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CNSmlDMSyncAppEngine::ShowProgressDialogL
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void CNSmlDMSyncAppEngine::ShowProgressDialogL( TBool aShow )
       
   230     {
       
   231  	FLOG( "[OMADM] CNSmlDMSyncAppEngine::ShowProgressDialog()" );
       
   232     
       
   233     if ( aShow != iProgressShown )
       
   234         {
       
   235         if ( aShow )
       
   236             {
       
   237             iSyncHandler->ShowProgressDialogL();
       
   238             }
       
   239         else
       
   240             {
       
   241             iSyncHandler->HideProgressDialogL();
       
   242             }
       
   243         iProgressShown = aShow;
       
   244         }
       
   245     }
       
   246     
       
   247 // -----------------------------------------------------------------------------
       
   248 // CNSmlDMSyncAppEngine::ServerIdFoundL
       
   249 // -----------------------------------------------------------------------------
       
   250 //    
       
   251 TBool CNSmlDMSyncAppEngine::ServerIdFoundL( const TDesC& aServerId,
       
   252                                             const TInt aProfileId )
       
   253     {
       
   254     FLOG( "[OMADM] CNSmlDMSyncAppEngine::ServerIdFoundL:" );
       
   255     
       
   256 	RArray<TSmlProfileId> arr;
       
   257     iSyncMLSession.ListProfilesL( arr, ESmlDevMan );
       
   258     TBool ret = EFalse;
       
   259    	CleanupClosePushL(arr);
       
   260    	
       
   261 	for ( TInt index = 0; index < arr.Count(); index++ )
       
   262 		{
       
   263 	    TRAPD( error, OpenProfileL( arr[index], ESmlOpenRead ) );
       
   264 	    if ( error == KErrNone )
       
   265 	        {
       
   266 	        if ( aProfileId != Profile()->ProfileId() )
       
   267 	            {	        
       
   268     	        TBuf<KNSmlMaxItemLength> buf;
       
   269     	        Profile()->GetServerId( buf );
       
   270     	        if ( buf.Compare( aServerId ) == 0 )
       
   271     	            {
       
   272     	            FLOG( "[OMADM] CNSmlDMSyncAppEngine::ServerIdFoundL: Match" );
       
   273                     ret = ETrue;
       
   274                     CloseProfile();
       
   275                     break;
       
   276                     }
       
   277 	            }
       
   278 		    CloseProfile();
       
   279 	        }
       
   280 		}
       
   281     CleanupStack::PopAndDestroy( &arr );
       
   282     return ret;
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 //  CNSmlDMSyncAppEngine::Compare
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 TInt CNSmlDMSyncAppEngine::Compare( const TDesC& aLeft, const TDesC& aRight )
       
   290 	{
       
   291 	FLOG( "[OMADM] CNSmlDMSyncAppEngine::Compare:" );
       
   292 	
       
   293 	// Empty Name() is always greater than non-empty Name()
       
   294     if (aLeft.Length() == 0 && aRight.Length() == 0)
       
   295         {
       
   296         return 0;
       
   297         }
       
   298     if (aLeft.Length() == 0)
       
   299         {
       
   300         return 1;
       
   301         }
       
   302     if (aRight.Length() == 0)
       
   303         {
       
   304         return -1;
       
   305         }
       
   306 
       
   307     // None of the Name()s was empty, use TDesC::CompareC to do the comparison.
       
   308     // This is from cntmodel.
       
   309     TCollationMethod collateMethod;
       
   310     // get the standard method
       
   311 	collateMethod = *Mem::CollationMethodByIndex(0);
       
   312     // dont ignore punctuation and spaces
       
   313 	collateMethod.iFlags |= TCollationMethod::EIgnoreNone; 
       
   314 	TInt comparison( aLeft.CompareC(aRight, 3, &collateMethod) );
       
   315 	return comparison;	
       
   316 	}
       
   317 	
       
   318 // -----------------------------------------------------------------------------
       
   319 //  CNSmlDMSyncAppEngine::SyncRunning
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 TBool CNSmlDMSyncAppEngine::SyncRunning()
       
   323     {
       
   324     FLOG( "[OMADM] CNSmlDMSyncAppEngine::SyncRunning:" );
       
   325     
       
   326     return iSyncHandler->SyncRunning();
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 //  CNSmlDMSyncAppEngine::CancelSyncL
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 void CNSmlDMSyncAppEngine::CancelSyncL()
       
   334     {
       
   335     FLOG( "[OMADM] CNSmlDMSyncAppEngine::CancelSyncL()" );
       
   336     iSyncHandler->CancelSynchronizeL();
       
   337     }
       
   338 
       
   339 // -----------------------------------------------------------------------------
       
   340 //  CNSmlDMSyncAppEngine::SyncCompleted
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 void CNSmlDMSyncAppEngine::SyncCompleted( TNSmlStatus aStatus )
       
   344     {
       
   345     FLOG( "[OMADM] CNSmlDMSyncAppEngine::SyncCompleted:" );
       
   346     
       
   347     if( iSyncObserver )
       
   348         {
       
   349         FLOG( "[OMADM] CNSmlDMSyncAppEngine::SyncCompleted: inform observer" );
       
   350         
       
   351         iSyncObserver->SyncComplete( aStatus );
       
   352         }    
       
   353     }
       
   354     
       
   355 // -----------------------------------------------------------------------------
       
   356 // CNSmlDMSyncAppEngine::RequestSyncStatus
       
   357 // -----------------------------------------------------------------------------
       
   358 //	
       
   359 void CNSmlDMSyncAppEngine::RequestSyncStatus( 
       
   360                                            MNSmlDMSyncObserver* aSyncObserver )
       
   361     {
       
   362     FLOG( "[OMADM] CNSmlDMSyncAppEngine::RequestSyncStatus:" );
       
   363     
       
   364     if( aSyncObserver )
       
   365         {
       
   366         FLOG( "[OMADM] CNSmlDMSyncAppEngine::RequestSyncStatus: added observer" );
       
   367         iSyncObserver = aSyncObserver;
       
   368         }
       
   369     }
       
   370 
       
   371 // End of File