omads/omadsextensions/adapters/contactsgroup/src/contactsgrpdataprovider.cpp
branchRCL_3
changeset 24 8e7494275d3a
equal deleted inserted replaced
23:2bb96f4ecad8 24:8e7494275d3a
       
     1 /*
       
     2 * Copyright (c) 2008-2010 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:  Part ContactsGroup Plug In Adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <ecom/implementationproxy.h>
       
    20 #include <data_caging_path_literals.hrh>
       
    21 #include <bautils.h>
       
    22 #include <barsc.h> 
       
    23 #include <contactsgrpdatastore.rsg>
       
    24 
       
    25 #include "contactsgrpdataprovider.h"
       
    26 #include "contactsgrpdatastore.h"
       
    27 #include "contactsgrpdataproviderdefs.h"
       
    28 #include "logger.h"
       
    29 
       
    30 const TUint KContactsGrpDataProviderImplUid = 0x101FF972;
       
    31 
       
    32 // Resource file for CSmlDataStoreFormat
       
    33 
       
    34 // The following works with DS plugin added into ROM image 
       
    35 _LIT(KContactsGrpStoreFormatRscRom,"z:contactsgrpdatastore.rsc");
       
    36 
       
    37 // The following works with DS plugin installed from SIS
       
    38 _LIT(KContactsGrpStoreFormatRsc,"contactsgrpdatastore.rsc");
       
    39 
       
    40 
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CContactsGrpDataProvider::CContactsGrpDataProvider
       
    44 // C++ default constructor can NOT contain any code, that might leave
       
    45 // -----------------------------------------------------------------------------
       
    46 CContactsGrpDataProvider::CContactsGrpDataProvider(): iFilters( 1 )
       
    47     {
       
    48     TRACE_FUNC;
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CContactsGrpDataProvider::ConstructL
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 void CContactsGrpDataProvider::ConstructL()
       
    56     {
       
    57     TRACE_FUNC_ENTRY;
       
    58     
       
    59     User::LeaveIfError( iFs.Connect() );
       
    60     iStringPool.OpenL();
       
    61     
       
    62     TRACE_FUNC_EXIT;
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CContactsGrpDataProvider::NewL
       
    67 // Two-phased constructor.
       
    68 // -----------------------------------------------------------------------------
       
    69 CContactsGrpDataProvider* CContactsGrpDataProvider::NewL()
       
    70     {
       
    71     TRACE_FUNC_ENTRY;
       
    72     CContactsGrpDataProvider* self = new ( ELeave ) CContactsGrpDataProvider();
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL();
       
    75     CleanupStack::Pop( self );
       
    76     TRACE_FUNC_EXIT;
       
    77     return self;
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CContactsGrpDataProvider::~CContactsGrpDataProvider
       
    82 // Destructor.
       
    83 // -----------------------------------------------------------------------------
       
    84 CContactsGrpDataProvider::~CContactsGrpDataProvider()
       
    85     {
       
    86     TRACE_FUNC_ENTRY;
       
    87     delete iOwnStoreFormat;
       
    88     iStringPool.Close();
       
    89     iFilters.Close();
       
    90     iFs.Close();
       
    91 
       
    92     TRACE_FUNC_EXIT;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CContactsGrpDataProvider::DoOnFrameworkEvent
       
    97 // Not used
       
    98 // -----------------------------------------------------------------------------
       
    99 void CContactsGrpDataProvider::DoOnFrameworkEvent( TSmlFrameworkEvent, TInt /*aParam1*/, TInt /*aParam2*/ )
       
   100     {
       
   101     TRACE_FUNC;
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CContactsGrpDataProvider::DoSupportsOperation
       
   106 // Checks whether data provider supports specific operation
       
   107 // -----------------------------------------------------------------------------
       
   108 TBool CContactsGrpDataProvider::DoSupportsOperation( TUid /*aOpId*/ ) const
       
   109     {
       
   110     TRACE_FUNC;
       
   111     return EFalse; // optional operations are not supported
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CContactsGrpDataProvider::DoStoreFormatL
       
   116 // Creates data store format
       
   117 // -----------------------------------------------------------------------------
       
   118 const CSmlDataStoreFormat& CContactsGrpDataProvider::DoStoreFormatL()
       
   119     {
       
   120     TRACE_FUNC_ENTRY;
       
   121 
       
   122     if (!iOwnStoreFormat)
       
   123         {
       
   124         iOwnStoreFormat = DoOwnStoreFormatL();
       
   125         }
       
   126     	
       
   127     TRACE_FUNC_EXIT;
       
   128     	
       
   129     return *iOwnStoreFormat;	
       
   130     }
       
   131 	
       
   132 // -----------------------------------------------------------------------------
       
   133 // CContactsGrpDataProvider::DoListStoresLC
       
   134 // Returns array fo data stores that can be opened
       
   135 // -----------------------------------------------------------------------------
       
   136 CDesCArray* CContactsGrpDataProvider::DoListStoresLC()
       
   137     {
       
   138     TRACE_FUNC_ENTRY;
       
   139 
       
   140     CDesCArrayFlat* stores = new ( ELeave ) CDesCArrayFlat( 1 );
       
   141     CleanupStack::PushL( stores );
       
   142     
       
   143     stores->AppendL( KContactsGrpStoreName );
       
   144 
       
   145     TRACE_FUNC_EXIT;
       
   146 
       
   147     return stores;	
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CContactsGrpDataProvider::DoDefaultStoreL
       
   152 // Returns the name of the default data store
       
   153 // -----------------------------------------------------------------------------
       
   154 const TDesC& CContactsGrpDataProvider::DoDefaultStoreL()
       
   155     {
       
   156     TRACE_FUNC;
       
   157     return KContactsGrpStoreName;
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CContactsGrpDataProvider::DoNewStoreInstanceLC
       
   162 // Creates a new data store object, which can be used for synchronization
       
   163 // ----------------------------------------------------------------------------- 
       
   164 CSmlDataStore* CContactsGrpDataProvider::DoNewStoreInstanceLC()
       
   165     {
       
   166     TRACE_FUNC_ENTRY;
       
   167     CContactsGrpDataStore* newStore = CContactsGrpDataStore::NewLC();
       
   168     TRACE_FUNC_EXIT;
       
   169     return newStore;
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CContactsGrpDataProvider::DoSupportedServerFiltersL
       
   174 // Filters are not supported
       
   175 // ----------------------------------------------------------------------------- 
       
   176 const RPointerArray<CSyncMLFilter>& CContactsGrpDataProvider::DoSupportedServerFiltersL()
       
   177     {
       
   178     TRACE_FUNC;
       
   179     return iFilters; // empty array
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CContactsGrpDataProvider::DoCheckSupportedServerFiltersL
       
   184 // Filters are not supported
       
   185 // ----------------------------------------------------------------------------- 
       
   186 void CContactsGrpDataProvider::DoCheckSupportedServerFiltersL(
       
   187     const CSmlDataStoreFormat& /*aServerDataStoreFormat*/,
       
   188     RPointerArray<CSyncMLFilter>& /*aFilters*/,
       
   189     TSyncMLFilterChangeInfo& /*aChangeInfo*/ )
       
   190     {
       
   191     TRACE_FUNC;
       
   192     User::Leave( KErrNotSupported );
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CContactsGrpDataProvider::DoCheckServerFiltersL
       
   197 // Filters are not supported
       
   198 // ----------------------------------------------------------------------------- 
       
   199 void CContactsGrpDataProvider::DoCheckServerFiltersL( RPointerArray<CSyncMLFilter>& /*aFilters*/,
       
   200     TSyncMLFilterChangeInfo& /*aChangeInfo*/ )
       
   201     {
       
   202     TRACE_FUNC;
       
   203     User::Leave( KErrNotSupported );
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CContactsGrpDataProvider::DoGenerateRecordFilterQueryLC
       
   208 // Filters are not supported
       
   209 // ----------------------------------------------------------------------------- 
       
   210 HBufC* CContactsGrpDataProvider::DoGenerateRecordFilterQueryLC(
       
   211     const RPointerArray<CSyncMLFilter>& /*aFilters*/, TSyncMLFilterMatchType /*aMatch*/,
       
   212     TDes& /*aFilterMimeType*/, TSyncMLFilterType& /*aFilterType*/, TDesC& /*aStoreName*/ )
       
   213     {
       
   214     TRACE_FUNC;
       
   215     User::Leave( KErrNotSupported );
       
   216     return NULL;
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CContactsGrpDataProvider::DoGenerateFieldFilterQueryL
       
   221 // Filters are not supported
       
   222 // ----------------------------------------------------------------------------- 
       
   223 void CContactsGrpDataProvider::DoGenerateFieldFilterQueryL(
       
   224     const RPointerArray<CSyncMLFilter>& /*aFilters*/, TDes& /*aFilterMimeType*/,
       
   225     RPointerArray<CSmlDataProperty>& /*aProperties*/, TDesC& /*aStoreName*/ )
       
   226     {	
       
   227     TRACE_FUNC;
       
   228     User::Leave( KErrNotSupported );
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CContactsGrpDataProvider::DoOwnStoreFormatL
       
   233 // Creates data store format
       
   234 // -----------------------------------------------------------------------------
       
   235 CSmlDataStoreFormat* CContactsGrpDataProvider::DoOwnStoreFormatL()
       
   236     {
       
   237     TRACE_FUNC_ENTRY;
       
   238 
       
   239     TParse* parse = new ( ELeave ) TParse();
       
   240     CleanupStack::PushL(parse);
       
   241     TFileName fileName;
       
   242     RResourceFile resourceFile;
       
   243     
       
   244     parse->Set( KContactsGrpStoreFormatRsc, &KDC_RESOURCE_FILES_DIR, NULL );
       
   245     fileName = parse->FullName();
       
   246     BaflUtils::NearestLanguageFile( iFs, fileName );
       
   247     LOGGER_WRITE_1( "file: %S", &fileName );
       
   248     
       
   249     TRAPD( error, resourceFile.OpenL( iFs, fileName ) );
       
   250     if ( error )
       
   251         {
       
   252         LOGGER_WRITE_1( "RResourceFile::OpenL leaved with %d - try again", error );
       
   253         parse->Set( KContactsGrpStoreFormatRscRom, &KDC_RESOURCE_FILES_DIR, NULL );
       
   254         fileName = parse->FullName();
       
   255         BaflUtils::NearestLanguageFile( iFs, fileName );
       
   256         LOGGER_WRITE_1( "file: %S", &fileName );
       
   257         resourceFile.OpenL( iFs, fileName );
       
   258         }
       
   259     CleanupClosePushL( resourceFile );
       
   260     HBufC8* buffer = resourceFile.AllocReadLC( CONTACTSGROUP_DATA_STORE );
       
   261 
       
   262     TResourceReader reader;
       
   263     reader.SetBuffer( buffer );
       
   264     
       
   265     CSmlDataStoreFormat* dsFormat = NULL;
       
   266     dsFormat = CSmlDataStoreFormat::NewLC( iStringPool, reader );
       
   267 
       
   268     CleanupStack::Pop( dsFormat );
       
   269     CleanupStack::PopAndDestroy( buffer );
       
   270     CleanupStack::PopAndDestroy( &resourceFile );
       
   271     CleanupStack::PopAndDestroy( parse );
       
   272     
       
   273     TRACE_FUNC_EXIT;
       
   274 
       
   275     return dsFormat;
       
   276     }
       
   277 	
       
   278 // -----------------------------------------------------------------------------
       
   279 // ImplementationTable
       
   280 // Required by ECom plugin interface, tells the entry point of the library
       
   281 // -----------------------------------------------------------------------------
       
   282 const TImplementationProxy ImplementationTable[] = 
       
   283     {
       
   284     IMPLEMENTATION_PROXY_ENTRY( KContactsGrpDataProviderImplUid, CContactsGrpDataProvider::NewL )
       
   285     };
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // ImplementationGroupProxy
       
   289 // Returns the implementation table, required by the ECom plugin interface
       
   290 // -----------------------------------------------------------------------------
       
   291 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
   292     {
       
   293     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   294     return ImplementationTable;
       
   295     }