omads/omadsextensions/adapters/contacts/src/NSmlContactsDataProvider.cpp
changeset 0 dab8a81a92de
child 10 b922b9936679
equal deleted inserted replaced
-1:000000000000 0:dab8a81a92de
       
     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:  DS contacts dataprovider
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <utf.h>
       
    21 #include <e32base.h>
       
    22 #include <s32strm.h>
       
    23 #include <cntdb.h>
       
    24 #include <e32cmn.h>
       
    25 #include <cntitem.h>
       
    26 #include <sysutil.h>
       
    27 #include <barsc.h>
       
    28 #include <bautils.h>
       
    29 #include <SmlDataProvider.h>
       
    30 #include <implementationproxy.h>
       
    31 #include <NSmlContactsDataStoreFormat_1_1_2.rsg>
       
    32 #include <NSmlContactsDataStoreFormat_1_2.rsg>
       
    33 #include <data_caging_path_literals.hrh>
       
    34 #include <vtoken.h>
       
    35 #include <e32property.h>
       
    36 #include <DataSyncInternalPSKeys.h>
       
    37 #include "NSmlContactsDataProvider.h"
       
    38 #include "nsmldebug.h"
       
    39 #include "nsmlconstants.h"
       
    40 #include "NSmlDataModBase.h"
       
    41 #include "nsmldsimpluids.h"
       
    42 #include "nsmlchangefinder.h"
       
    43 
       
    44 // ============================ MEMBER FUNCTIONS ===============================
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CNSmlContactsDataProvider::NewL
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CNSmlContactsDataProvider* CNSmlContactsDataProvider::NewL()
       
    51 	{
       
    52 	_DBG_FILE("CNSmlContactsDataProvider::NewL(): begin");
       
    53 	CNSmlContactsDataProvider* self = NewLC();
       
    54 	CleanupStack::Pop();
       
    55 	_DBG_FILE("CNSmlContactsDataProvider::NewL(): end");
       
    56 	return self;
       
    57 	}
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CNSmlContactsDataProvider::NewLC
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CNSmlContactsDataProvider* CNSmlContactsDataProvider::NewLC()
       
    64 	{
       
    65 	_DBG_FILE("CNSmlContactsDataProvider::NewLC(): begin");
       
    66 	
       
    67 	CNSmlContactsDataProvider* self = new (ELeave) CNSmlContactsDataProvider();
       
    68 	CleanupStack::PushL( self );
       
    69 	self->ConstructL();
       
    70 	_DBG_FILE("CNSmlContactsDataProvider::NewLC(): end");
       
    71 	return self;
       
    72 	}
       
    73 	
       
    74 // -----------------------------------------------------------------------------
       
    75 // CNSmlContactsDataProvider::CNSmlContactsDataProvider
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CNSmlContactsDataProvider::CNSmlContactsDataProvider()
       
    79 	{
       
    80 	_DBG_FILE("CNSmlContactsDataProvider::CNSmlContactsDataProvider(): begin");
       
    81 	_DBG_FILE("CNSmlContactsDataProvider::CNSmlContactsDataProvider(): end");
       
    82 	}
       
    83 	
       
    84 // -----------------------------------------------------------------------------
       
    85 // CNSmlContactsDataProvider::ConstructL
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CNSmlContactsDataProvider::ConstructL()
       
    89 	{
       
    90 	_DBG_FILE("CNSmlContactsDataProvider::ConstructL(): begin");
       
    91 	
       
    92 	User::LeaveIfError( iRfs.Connect() );
       
    93 
       
    94 	iContactsDataStore = CNSmlContactsDataStore::NewL();	
       
    95 	
       
    96 	iStringPool.OpenL();
       
    97 	
       
    98 	_DBG_FILE("CNSmlContactsDataProvider::ConstructL(): end");
       
    99 	}
       
   100 	
       
   101 // -----------------------------------------------------------------------------
       
   102 // CNSmlContactsDataProvider::~CNSmlContactsDataProvider
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 CNSmlContactsDataProvider::~CNSmlContactsDataProvider()
       
   106 	{
       
   107 	_DBG_FILE("CNSmlContactsDataProvider::~CNSmlContactsDataProvider(): begin");
       
   108 
       
   109 	iRfs.Close();
       
   110 
       
   111 	delete iContactsDataStore;
       
   112 	delete iStoreFormat;
       
   113 	iFilterArray.ResetAndDestroy();
       
   114 	iFilterArray.Close();
       
   115 
       
   116 	iStringPool.Close();
       
   117 
       
   118 	_DBG_FILE("CNSmlContactsDataProvider::~CNSmlContactsDataProvider(): end");
       
   119 	}
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CNSmlContactsDataProvider::DoOnFrameworkEvent
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void CNSmlContactsDataProvider::DoOnFrameworkEvent( TSmlFrameworkEvent /*aFrameworkEvent*/, TInt /*aParam1*/, TInt /*aParam2*/ )
       
   126 	{
       
   127 	_DBG_FILE("CNSmlContactsDataProvider::DoOnFrameworkEvent(): begin");
       
   128 	_DBG_FILE("CNSmlContactsDataProvider::DoOnFrameworkEvent(): end");
       
   129 	}
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CNSmlContactsDataProvider::DoSupportsOperation
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 TBool CNSmlContactsDataProvider::DoSupportsOperation( TUid aOpId ) const
       
   136 	{
       
   137 	_DBG_FILE("CNSmlContactsDataProvider::DoSupportsOperation(): begin");
       
   138 
       
   139 	if ( aOpId == KUidSmlSupportBatch ||
       
   140 	     aOpId == KUidSmlSupportMultipleStores )
       
   141 		{
       
   142 		return ETrue;
       
   143 		}
       
   144 
       
   145 	_DBG_FILE("CNSmlContactsDataProvider::DoSupportsOperation(): end");
       
   146 
       
   147 	return EFalse; // KUidSmlSupportTransaction ,KUidSmlSupportSuspendResume, KUidSmlSupportUserSelectableMatchType
       
   148 	}
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CNSmlContactsDataProvider::DoStoreFormatL
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 const CSmlDataStoreFormat& CNSmlContactsDataProvider::DoStoreFormatL()
       
   155 	{
       
   156 	_DBG_FILE("CNSmlContactsDataProvider::DoStoreFormatL(): begin");
       
   157 	
       
   158 	delete iStoreFormat;
       
   159 	iStoreFormat = NULL;
       
   160 	
       
   161 	TFileName fileName;
       
   162 	TParse parse;
       
   163 	
       
   164 	// Locate the resource file
       
   165 	TFileName dllFileName;
       
   166 	Dll::FileName( dllFileName );
       
   167     
       
   168 	TFileName resourceFileName;
       
   169 	resourceFileName.Copy( TParsePtrC( dllFileName ).Drive() );  
       
   170 	// Check correct Data Sync protocol
       
   171     TInt value( EDataSyncNotRunning );
       
   172     TInt error = RProperty::Get( KPSUidDataSynchronizationInternalKeys,
       
   173                                  KDataSyncStatus,
       
   174                                  value );
       
   175     if ( error == KErrNone &&
       
   176          value == EDataSyncRunning )
       
   177         {
       
   178         resourceFileName.Append(KNSmlContactsStoreFormatRsc_1_1_2);
       
   179         parse.Set( resourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   180         }
       
   181     else // error or protocol version 1.2 
       
   182         {
       
   183         resourceFileName.Append(KNSmlContactsStoreFormatRsc_1_2);
       
   184         parse.Set( resourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   185         }		
       
   186 
       
   187 	fileName = parse.FullName();
       
   188 
       
   189 	RResourceFile resourceFile; 
       
   190 	BaflUtils::NearestLanguageFile( iRfs, fileName );
       
   191 
       
   192 	resourceFile.OpenL( iRfs,fileName );
       
   193 	CleanupClosePushL( resourceFile );
       
   194 	
       
   195 	HBufC8* contactsDataFormat = resourceFile.AllocReadLC( NSML_CONTACTS_DATA_STORE_FORMAT );
       
   196 
       
   197 	TResourceReader reader;
       
   198 	reader.SetBuffer( contactsDataFormat );
       
   199 
       
   200 	iStoreFormat = CSmlDataStoreFormat::NewLC( iStringPool, reader );
       
   201 	CleanupStack::Pop(); // iStoreFormat
       
   202 	
       
   203 	CleanupStack::PopAndDestroy( 2 ); // contactsDataFormat,resourceFile  
       
   204 	
       
   205 	_DBG_FILE("CNSmlContactsDataProvider::DoStoreFormatL(): end");
       
   206 
       
   207 	return *iStoreFormat;
       
   208 	}
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CNSmlContactsDataProvider::DoListStoresLC
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 CDesCArray* CNSmlContactsDataProvider::DoListStoresLC()
       
   215 	{
       
   216 	_DBG_FILE("CNSmlContactsDataProvider::DoListStoresLC(): begin");
       
   217 	_DBG_FILE("CNSmlContactsDataProvider::DoListStoresLC(): end");
       
   218 	
       
   219 	return iContactsDataStore->DoListStoresLC();
       
   220 	}
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CNSmlContactsDataProvider::DoDefaultStoreL
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 const TDesC& CNSmlContactsDataProvider::DoDefaultStoreL()
       
   227 	{
       
   228 	_DBG_FILE("CNSmlContactsDataProvider::DoIdentifier(): begin");
       
   229 	_DBG_FILE("CNSmlContactsDataProvider::DoIdentifier(): end");
       
   230 
       
   231 	return iContactsDataStore->DefaultStoreNameL();
       
   232 	}
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CNSmlContactsDataProvider::DoNewStoreInstanceLC
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 CSmlDataStore* CNSmlContactsDataProvider::DoNewStoreInstanceLC()
       
   239 	{
       
   240 	_DBG_FILE("CNSmlContactsDataProvider::DoNewStoreInstanceLC(): begin");
       
   241 
       
   242 	CNSmlContactsDataStore* newDataStore = CNSmlContactsDataStore::NewL();
       
   243 	CleanupStack::PushL( newDataStore );
       
   244 
       
   245 	_DBG_FILE("CNSmlContactsDataProvider::DoNewStoreInstanceLC(): end");
       
   246 
       
   247 	return newDataStore;
       
   248 	}
       
   249 
       
   250 // ------------------------------------------------------------------------------------------------
       
   251 // CNSmlContactsDataProvider::DoSupportedServerFiltersL
       
   252 // 
       
   253 // ------------------------------------------------------------------------------------------------
       
   254 const RPointerArray<CSyncMLFilter>& CNSmlContactsDataProvider::DoSupportedServerFiltersL()
       
   255 	{
       
   256 	// This method returns empty array. It means that this Data Provider does not support filtering
       
   257 	_DBG_FILE("CNSmlContactsDataProvider::DoSupportedServerFiltersL(): BEGIN");
       
   258 	_DBG_FILE("CNSmlContactsDataProvider::DoSupportedServerFiltersL(): END");
       
   259 	return iFilterArray;
       
   260 	}
       
   261 
       
   262 // ------------------------------------------------------------------------------------------------
       
   263 // CNSmlContactsDataProvider::DoCheckSupportedServerFiltersL
       
   264 // 
       
   265 // ------------------------------------------------------------------------------------------------
       
   266 void CNSmlContactsDataProvider::DoCheckSupportedServerFiltersL( const CSmlDataStoreFormat& /*aServerDataStoreFormat*/, RPointerArray<CSyncMLFilter>& /*aFilters*/, TSyncMLFilterChangeInfo& /*aChangeInfo*/ )
       
   267 	{
       
   268 	_DBG_FILE("CNSmlContactsDataProvider::DoCheckSupportedServerFiltersL(): BEGIN");
       
   269 	User::Leave( KErrNotSupported );
       
   270 	_DBG_FILE("CNSmlContactsDataProvider::DoCheckSupportedServerFiltersL(): END");
       
   271 	}
       
   272 
       
   273 // ------------------------------------------------------------------------------------------------
       
   274 // CNSmlContactsDataProvider::CheckServerFiltersL
       
   275 // 
       
   276 // ------------------------------------------------------------------------------------------------
       
   277 void CNSmlContactsDataProvider::DoCheckServerFiltersL( RPointerArray<CSyncMLFilter>& /*aFilters*/, TSyncMLFilterChangeInfo& /*aChangeInfo*/ )
       
   278 	{
       
   279 	_DBG_FILE("CNSmlContactsDataProvider::DoCheckServerFiltersL(): BEGIN");
       
   280 	User::Leave( KErrNotSupported );
       
   281 	_DBG_FILE("CNSmlContactsDataProvider::DoCheckServerFiltersL(): END");
       
   282 	}
       
   283 
       
   284 // ------------------------------------------------------------------------------------------------
       
   285 // CNSmlContactsDataProvider::DoGenerateRecordFilterQueryLC
       
   286 // 
       
   287 // ------------------------------------------------------------------------------------------------
       
   288 HBufC* CNSmlContactsDataProvider::DoGenerateRecordFilterQueryLC( const RPointerArray<CSyncMLFilter>& /*aFilters*/, TSyncMLFilterMatchType /*aMatch*/, TDes& /*aFilterMimeType*/, TSyncMLFilterType& /*aFilterType*/, TDesC& /*aStoreName*/ )
       
   289 	{
       
   290 	_DBG_FILE("CNSmlContactsDataProvider::DoGenerateRecordFilterQueryLC(): BEGIN");
       
   291 	User::Leave( KErrNotSupported );
       
   292 	_DBG_FILE("CNSmlContactsDataProvider::DoGenerateRecordFilterQueryLC(): END");
       
   293 	return NULL;
       
   294 	}
       
   295 	
       
   296 // ------------------------------------------------------------------------------------------------
       
   297 // CNSmlContactsDataProvider::DoGenerateFieldFilterQueryL
       
   298 // 
       
   299 // ------------------------------------------------------------------------------------------------
       
   300 void CNSmlContactsDataProvider::DoGenerateFieldFilterQueryL( const RPointerArray<CSyncMLFilter>& /*aFilters*/, TDes& /*aFilterMimeType*/, RPointerArray<CSmlDataProperty>& /*aProperties*/, TDesC& /*aStoreName*/ )
       
   301 	{
       
   302 	_DBG_FILE("CNSmlContactsDataProvider::DoGenerateFieldFilterQueryL(): BEGIN");
       
   303 	User::Leave( KErrNotSupported );
       
   304 	_DBG_FILE("CNSmlContactsDataProvider::DoGenerateFieldFilterQueryL(): END");
       
   305 	}
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // ImplementationGroupProxy array
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 #ifndef IMPLEMENTATION_PROXY_ENTRY
       
   312 #define IMPLEMENTATION_PROXY_ENTRY( aUid, aFuncPtr ) {{aUid},(aFuncPtr)}
       
   313 #endif
       
   314 
       
   315 const TImplementationProxy ImplementationTable[] = 
       
   316     {
       
   317 	IMPLEMENTATION_PROXY_ENTRY( KNSmlContactsAdapterImplUid, CNSmlContactsDataProvider::NewL )
       
   318     };
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // ImplementationGroupProxy
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
   325     {
       
   326 	_DBG_FILE("ImplementationGroupProxy() for CNSmlContactsDataProvider: begin");
       
   327     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   328 	_DBG_FILE("ImplementationGroupProxy() for CNSmlContactsDataProvider: end");
       
   329     return ImplementationTable;
       
   330 	}
       
   331 
       
   332 // End of File