omads/omadsextensions/dsutils/nsmldefaultagendahandler/src/nsmldefaultagendahandlerplugin.cpp
changeset 1 95fdac6ccb5c
child 13 a564f66a2339
equal deleted inserted replaced
0:dab8a81a92de 1:95fdac6ccb5c
       
     1 /*
       
     2 * Copyright (c) 2009 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include <gdi.h>
       
    19 #include <utf.h>
       
    20 #include <barsc.h>
       
    21 #include <e32std.h>
       
    22 #include <bautils.h>
       
    23 #include <implementationproxy.h>
       
    24 #include <calsession.h>
       
    25 #include <calenmulticalutil.h>
       
    26 #include <calenmulticaluids.hrh>
       
    27 #include <calcalendarinfo.h>
       
    28 #include <nsmlfolderparser.h>
       
    29 #include <nsmldefaultagendahandler_1_2.rsg>
       
    30 #include "nsmldefaultagendahandlerplugin.h"
       
    31 #include "nsmldefaultagendahandlerutil.h"
       
    32 #include "nsmldefaultagendahandlerdebug.h"
       
    33 
       
    34 
       
    35 
       
    36 // CONSTANTS
       
    37 const TInt KBuffLength = 128;
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // CNSmlDefaultAgendaHandlerPlugin::NewL
       
    41 // Two Phase Construction
       
    42 // ----------------------------------------------------------------------------
       
    43 EXPORT_C CNSmlDefaultAgendaHandlerPlugin* CNSmlDefaultAgendaHandlerPlugin::NewL()
       
    44 	{
       
    45 	FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::NewL, BEGIN"));
       
    46 
       
    47 	CNSmlDefaultAgendaHandlerPlugin* self = new ( ELeave ) CNSmlDefaultAgendaHandlerPlugin();	
       
    48 	self->ConstructL();
       
    49 	
       
    50 	FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::NewL, END"));
       
    51 	return self;
       
    52 	}
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CNSmlDefaultAgendaHandlerPlugin::~CNSmlDefaultAgendaHandlerPlugin
       
    56 // Destructor
       
    57 // ----------------------------------------------------------------------------
       
    58 CNSmlDefaultAgendaHandlerPlugin::~CNSmlDefaultAgendaHandlerPlugin()
       
    59 	{
       
    60 	FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::~CNSmlDefaultAgendaHandlerPlugin, BEGIN"));	 
       
    61   
       
    62 	FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::~CNSmlDefaultAgendaHandlerPlugin, END"));
       
    63 	}
       
    64 
       
    65 // ----------------------------------------------------------------------------  
       
    66 // C++ constructor - not exported;
       
    67 // implicitly called from NewL()
       
    68 // ----------------------------------------------------------------------------  
       
    69 CNSmlDefaultAgendaHandlerPlugin::CNSmlDefaultAgendaHandlerPlugin() 
       
    70 	{
       
    71 	FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::CNSmlDefaultAgendaHandlerPlugin, BEGIN"));  
       
    72 	FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::CNSmlDefaultAgendaHandlerPlugin, END"));
       
    73 	}
       
    74 
       
    75 // ----------------------------------------------------------------------------  
       
    76 // 2nd phase constructor
       
    77 // ----------------------------------------------------------------------------       
       
    78 void CNSmlDefaultAgendaHandlerPlugin::ConstructL()
       
    79     {
       
    80     FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::ConstructL, BEGIN"));
       
    81     
       
    82     // Initialize server supports for folder
       
    83     iServerSupportsForFolder.iSSName = EFalse;
       
    84     iServerSupportsForFolder.iSSCreated = EFalse;
       
    85     iServerSupportsForFolder.iSSModified = EFalse;
       
    86         
       
    87     FLOG( _L("CNSmlDefaultAgendaHandlerPlugin::ConstructL, END"));
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder
       
    92 // Method to check if needed properties are supported by remote server.
       
    93 // -----------------------------------------------------------------------------
       
    94 void CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder( const CSmlDataStoreFormat& aServerDataStoreFormat )
       
    95     {
       
    96     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder: BEGIN"));
       
    97         
       
    98     iServerSupportsForFolder.iSSName = EFalse;
       
    99     iServerSupportsForFolder.iSSCreated = EFalse;
       
   100     iServerSupportsForFolder.iSSModified = EFalse;
       
   101     
       
   102     if ( aServerDataStoreFormat.FolderPropertyCount() == 0 )
       
   103         {
       
   104         // Server has no restricition on folder property
       
   105         iServerSupportsForFolder.iSSName = ETrue;
       
   106         iServerSupportsForFolder.iSSCreated = ETrue;
       
   107         iServerSupportsForFolder.iSSModified = ETrue;
       
   108         return;
       
   109         }
       
   110     else
       
   111         {
       
   112         for ( TInt i = 0; 
       
   113                    i < aServerDataStoreFormat.FolderPropertyCount(); 
       
   114                    i++ )
       
   115             {
       
   116             if ( aServerDataStoreFormat.FolderProperty( i ).Field().Name().DesC().Compare( KNSmlDataObjectNAME ) == 0 )
       
   117                 {
       
   118                 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder: Supports NAME Property"));
       
   119                 iServerSupportsForFolder.iSSName = ETrue;
       
   120                 }
       
   121             else if ( aServerDataStoreFormat.FolderProperty( i ).Field().Name().DesC().Compare( KNSmlDataObjectCREATED ) == 0 )
       
   122                 {
       
   123                 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder: Supports CREATED Property"));
       
   124                 iServerSupportsForFolder.iSSCreated = ETrue;
       
   125                 }
       
   126             else if ( aServerDataStoreFormat.FolderProperty( i ).Field().Name().DesC().Compare( KNSmlDataObjectMODIFIED ) == 0 )
       
   127                 {
       
   128                 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder: Supports MODIFIED Property"));
       
   129                 iServerSupportsForFolder.iSSModified = ETrue;
       
   130                 }
       
   131             }
       
   132         }
       
   133     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CheckServerSupportForFolder: END"));
       
   134     }
       
   135          
       
   136 // -----------------------------------------------------------------------------
       
   137 // CNSmlDefaultAgendaHandlerPlugin::FetchFolderL
       
   138 // Method to read folder item from database.
       
   139 // -----------------------------------------------------------------------------
       
   140 void CNSmlDefaultAgendaHandlerPlugin::FetchFolderL( const TSmlDbItemUid aUid, RBufWriteStream& aStream )
       
   141     {
       
   142     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FetchFolderL: begin"));
       
   143             
       
   144     // Create parser and set properties
       
   145     CNSmlFolderParser* parser = CNSmlFolderParser::NewLC();
       
   146     TNSmlParserGeneratorError parseError = EErrorNone;
       
   147     HBufC8* generatedBuf = NULL;
       
   148     HBufC8* nameBuf = NULL;
       
   149     
       
   150     //Get the Folder Information
       
   151     CNSmlDefaultAgendaHandlerUtil* agendautil = CalendarInfoL(aUid);
       
   152     if( NULL == agendautil )
       
   153         {
       
   154         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FetchFolderL:Invalid CalendarInfo"));
       
   155         CleanupStack::PopAndDestroy( parser );
       
   156         User::Leave( KErrNotFound );
       
   157         }
       
   158         
       
   159     if ( iServerSupportsForFolder.iSSCreated )
       
   160         {
       
   161         parser->iCreated = agendautil->iCreated;
       
   162         }
       
   163     else
       
   164         {
       
   165         parser->iCreated = Time::NullTTime();
       
   166         }
       
   167     
       
   168     if ( iServerSupportsForFolder.iSSName )
       
   169         {
       
   170         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FetchFolderL: retrieving name"));
       
   171         nameBuf = HBufC8::NewL( agendautil->iName->Length() );
       
   172         TPtr8 name( nameBuf->Des() );
       
   173         CnvUtfConverter::ConvertFromUnicodeToUtf8(name , agendautil->iName->Des());
       
   174         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FetchFolderL: name converted"));
       
   175         parser->iName = nameBuf;        
       
   176         }    
       
   177 
       
   178     // Generate data and write it to buffer   
       
   179     generatedBuf = HBufC8::NewLC( 1 );
       
   180     generatedBuf->Des() = KNullDesC8;
       
   181     CleanupStack::Pop(); // generatedBuf
       
   182     parseError = parser->GenerateXml( generatedBuf );
       
   183     CleanupStack::PushL( generatedBuf );
       
   184     
       
   185     aStream.WriteL( generatedBuf->Des() );
       
   186     
       
   187     delete agendautil;
       
   188     CleanupStack::PopAndDestroy( generatedBuf ); 
       
   189     CleanupStack::PopAndDestroy( parser );
       
   190     
       
   191     if ( parseError != EErrorNone )
       
   192         {       
       
   193         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FetchFolderL(): end with leave"));
       
   194         User::Leave( KErrGeneral );
       
   195         }
       
   196     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FetchFolderL: end"));
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL
       
   201 // Retrieve the CalendarFile ID
       
   202 // -----------------------------------------------------------------------------
       
   203 void CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL( CArrayFixFlat<TUint>* aFolderUidArray )
       
   204     {
       
   205     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL BEGIN"));
       
   206         
       
   207     CCalSession* vCalSession = NULL;
       
   208     CCalSession* vCalSubSession = NULL;   
       
   209     TBuf8<KBuffLength> keyBuff;
       
   210     
       
   211     aFolderUidArray->Reset();
       
   212             
       
   213     vCalSession = CCalSession::NewL();
       
   214     CleanupStack::PushL(vCalSession);
       
   215     
       
   216     CDesCArray* calfilearr = vCalSession->ListCalFilesL();            
       
   217     CleanupStack::PushL(calfilearr);
       
   218     
       
   219     for(TInt i = 0; i < calfilearr->Count(); i++)
       
   220         {
       
   221         TInt err = KErrNone;
       
   222         vCalSubSession = CCalSession::NewL();
       
   223         CleanupStack::PushL(vCalSubSession);
       
   224         vCalSubSession->OpenL(calfilearr->MdcaPoint(i));
       
   225         
       
   226         CCalCalendarInfo* caleninfo = vCalSubSession->CalendarInfoL(); 
       
   227         CleanupStack::PushL(caleninfo);
       
   228         
       
   229         //Get UID value associated with the CalFile
       
   230         keyBuff.Zero();
       
   231         TUint UidVal;
       
   232         keyBuff.AppendNum( EFolderLUID );
       
   233         TPckgC<TUint> pckUidValue(UidVal);
       
   234         TRAP(err,pckUidValue.Set(caleninfo->PropertyValueL( keyBuff )));
       
   235         UidVal = pckUidValue();
       
   236                     
       
   237         if( err != KErrNone )
       
   238             {
       
   239             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL: Error while retrieving CalFile Property: '%d'"), err);
       
   240             }
       
   241         
       
   242         //Get OWNER value associated with the CalFile
       
   243         keyBuff.Zero();
       
   244         TInt SyncServiceOwnerVal;
       
   245         keyBuff.AppendNum( EDeviceSyncServiceOwner );
       
   246         TPckgC<TInt> pckOwnerValue(SyncServiceOwnerVal);
       
   247         TRAP(err,pckOwnerValue.Set(caleninfo->PropertyValueL( keyBuff )));
       
   248         SyncServiceOwnerVal = pckOwnerValue();
       
   249                     
       
   250         if( err == KErrNotFound )
       
   251             {
       
   252             // Set DS Application as owner
       
   253             SyncServiceOwnerVal = KCRUidNSmlDSApp.iUid;
       
   254             TPckgC<TInt> pckOwnerValue(SyncServiceOwnerVal);
       
   255             caleninfo->SetPropertyL( keyBuff, pckOwnerValue );
       
   256             vCalSubSession->SetCalendarInfoL( *caleninfo );
       
   257             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL: Empty Owner LUID '%d'"), UidVal );
       
   258             aFolderUidArray->AppendL(UidVal);
       
   259             }
       
   260         else if( err == KErrNone )
       
   261             {
       
   262             if( KCRUidNSmlDSApp.iUid == SyncServiceOwnerVal )
       
   263                 {
       
   264                 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL: DS Owner LUID '%d'"), UidVal );
       
   265                 aFolderUidArray->AppendL(UidVal);
       
   266                 }
       
   267             }
       
   268         else
       
   269             {
       
   270             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL: Error while retrieving Owner Property: '%d'"), err);
       
   271             }
       
   272         CleanupStack::PopAndDestroy(caleninfo);
       
   273         CleanupStack::PopAndDestroy(vCalSubSession); 
       
   274         }
       
   275     CleanupStack::PopAndDestroy(calfilearr);
       
   276     CleanupStack::PopAndDestroy(vCalSession);
       
   277     
       
   278     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::SynchronizableCalendarIdsL END"));
       
   279     }
       
   280  
       
   281 // -----------------------------------------------------------------------------
       
   282 // CNSmlDefaultAgendaHandlerPlugin::CreateFolderItemL
       
   283 // Creates the Folder item with the stream provided 
       
   284 // -----------------------------------------------------------------------------
       
   285 TCalLocalUid CNSmlDefaultAgendaHandlerPlugin::CreateFolderL( RBufReadStream& aStream )
       
   286     {
       
   287     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderItemL BEGIN"));
       
   288    
       
   289     TBuf8<KBuffLength> keyBuff;
       
   290     TUint calValue = 0;
       
   291     CNSmlDefaultAgendaHandlerUtil* agendautil = NULL;
       
   292     CCalCalendarInfo* calinfo = CCalCalendarInfo::NewL();
       
   293     CleanupStack::PushL(calinfo);    
       
   294     
       
   295     // Parse the buffer for the folder data and construct the calendar info   
       
   296     agendautil = ParseFolderDataL( aStream );
       
   297     
       
   298     if( agendautil )
       
   299         {
       
   300         // Visibility
       
   301         calinfo->SetEnabled( agendautil->iEnabled );
       
   302         
       
   303         // LUID Meta Property
       
   304         keyBuff.Zero();
       
   305         keyBuff.AppendNum( EFolderLUID );
       
   306         calValue = CCalenMultiCalUtil::GetNextAvailableOffsetL();
       
   307         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderItemL: nextoffset: '%d'"), calValue);
       
   308         TPckgC<TUint> pckgUidValue( calValue );
       
   309         calinfo->SetPropertyL( keyBuff, pckgUidValue );      
       
   310       
       
   311         // Create & Modified Time Meta Property
       
   312         keyBuff.Zero();
       
   313         keyBuff.AppendNum( ECreationTime );
       
   314         TTime time;
       
   315         time.HomeTime();
       
   316         TPckgC<TTime> pckgCreateTimeValue( time );
       
   317         calinfo->SetPropertyL( keyBuff, pckgCreateTimeValue );
       
   318         keyBuff.Zero();
       
   319         keyBuff.AppendNum( EModificationTime );
       
   320         calinfo->SetPropertyL( keyBuff, pckgCreateTimeValue );
       
   321         
       
   322         // Sync Status Meta Property
       
   323         keyBuff.Zero();
       
   324         keyBuff.AppendNum( ESyncStatus );
       
   325         TBool syncstatus( ETrue );
       
   326         TPckgC<TBool> pckgSyncStatusValue( syncstatus );
       
   327         calinfo->SetPropertyL( keyBuff, pckgSyncStatusValue );
       
   328         
       
   329         // Add
       
   330         CCalSession* calsession = CCalSession::NewL();
       
   331         TInt err(KErrNone);
       
   332         if( agendautil->iName != NULL )
       
   333             {
       
   334             calinfo->SetNameL( agendautil->iName->Des() );
       
   335             TRAP( err, calsession->CreateCalFileL( agendautil->iName->Des(), *calinfo ) );
       
   336             }
       
   337         else
       
   338             {
       
   339             err = KErrNotFound;
       
   340             }
       
   341         
       
   342         delete calsession;
       
   343         delete agendautil;
       
   344         CleanupStack::PopAndDestroy(calinfo);
       
   345         
       
   346         if( err != KErrNone )
       
   347             {
       
   348             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderItemL: Error while Creating Calfile"));
       
   349             User::Leave( KErrGeneral );
       
   350             }
       
   351         }
       
   352     else
       
   353         {
       
   354         CleanupStack::PopAndDestroy(calinfo);
       
   355         User::Leave( KErrGeneral );
       
   356         }
       
   357     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderItemL END"));
       
   358     return calValue;   
       
   359     }
       
   360  
       
   361 // -----------------------------------------------------------------------------
       
   362 // CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL
       
   363 // Replaces the Folder item with the ID provided 
       
   364 // -----------------------------------------------------------------------------
       
   365 void CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderL( const TCalLocalUid& aUid, 
       
   366                                                       RBufReadStream& aStream, TBool& aSyncStatus )
       
   367     {
       
   368     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL: BEGIN"));
       
   369     
       
   370     TBuf8<KBuffLength> keyBuff;
       
   371     CNSmlDefaultAgendaHandlerUtil* agendautil = NULL;
       
   372     
       
   373     // Parse the buffer for the folder data and construct the calendar info   
       
   374     agendautil = ParseFolderDataL( aStream );
       
   375     
       
   376     if( agendautil )
       
   377         {
       
   378         //Get the associated Calendar File 
       
   379         CNSmlDefaultAgendaHandlerUtil* updateagendautil = CalendarInfoL( aUid );
       
   380         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL: After CalendarInfoL '%d'"), updateagendautil);
       
   381         
       
   382         if( NULL == updateagendautil )
       
   383             {
       
   384             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Invalid Updatable CalendarInfo"));
       
   385             delete agendautil;
       
   386             User::Leave( KErrNotFound );
       
   387             }
       
   388         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:valid CalendarInfo"));
       
   389         if( updateagendautil->iFileName != NULL )            
       
   390             {            
       
   391             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:valid name '%S'"), updateagendautil->iFileName);
       
   392             CCalSession* vCalSession = CCalSession::NewL();
       
   393             CleanupStack::PushL(vCalSession);
       
   394             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Open the session")); 
       
   395             vCalSession->OpenL(updateagendautil->iFileName->Des());          
       
   396             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Get the Calendar Info")); 
       
   397             CCalCalendarInfo* caleninfo = vCalSession->CalendarInfoL();  
       
   398             CleanupStack::PushL(caleninfo);
       
   399             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Set the status"));
       
   400             caleninfo->SetEnabled(agendautil->iEnabled);            
       
   401             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Set the name"));
       
   402             caleninfo->SetNameL(agendautil->iName->Des());
       
   403             
       
   404             // Modified Time Meta Property
       
   405             keyBuff.Zero();
       
   406             keyBuff.AppendNum( EModificationTime );
       
   407             TTime time;
       
   408             time.HomeTime();
       
   409             TPckgC<TTime> pckgCreateTimeValue( time );
       
   410             caleninfo->SetPropertyL( keyBuff, pckgCreateTimeValue );
       
   411             
       
   412             aSyncStatus = updateagendautil->iSyncStatus;
       
   413             
       
   414             // Update
       
   415             vCalSession->SetCalendarInfoL(*caleninfo);
       
   416             
       
   417             CleanupStack::PopAndDestroy(caleninfo);
       
   418             CleanupStack::PopAndDestroy( vCalSession );
       
   419             }
       
   420         else
       
   421             {
       
   422             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Invalid Updatable CalendarInfo Name"));
       
   423             delete agendautil;
       
   424             delete updateagendautil;
       
   425             User::Leave( KErrNotFound );
       
   426             }
       
   427         }
       
   428     else
       
   429         {
       
   430         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL:Invalid Parsed CalendarInfo"));
       
   431         User::Leave( KErrNotFound );
       
   432         }
       
   433     
       
   434     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ReplaceFolderItemL: END"));
       
   435     }
       
   436 
       
   437 // -----------------------------------------------------------------------------
       
   438 // CNSmlDefaultAgendaHandlerPlugin::FolderNameL
       
   439 // Returns the FolderName for the given ID
       
   440 // -----------------------------------------------------------------------------
       
   441 HBufC* CNSmlDefaultAgendaHandlerPlugin::FolderNameL( TSmlDbItemUid aUid )
       
   442     {
       
   443     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderNameL: BEGIN"));
       
   444     
       
   445     HBufC* calfilename = NULL;
       
   446     CNSmlDefaultAgendaHandlerUtil* agendautil = CalendarInfoL( aUid );
       
   447     
       
   448     if( agendautil != NULL )
       
   449         {
       
   450         calfilename = agendautil->iFileName->Alloc();
       
   451         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::foldername: '%S'"), calfilename);
       
   452         }    
       
   453     delete agendautil;
       
   454     
       
   455     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderNameL: END"));
       
   456     
       
   457     return calfilename;
       
   458     }
       
   459 
       
   460 // -----------------------------------------------------------------------------
       
   461 // CNSmlDefaultAgendaHandlerPlugin::StoreFormatL
       
   462 // Returns adapters supported store format which is read from Calendar Plug
       
   463 // In Adapter own resource file.
       
   464 // -----------------------------------------------------------------------------
       
   465 CSmlDataStoreFormat* CNSmlDefaultAgendaHandlerPlugin::StoreFormatL( RStringPool& aStringPool )
       
   466     {
       
   467     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::StoreFormatL: BEGIN"));
       
   468     
       
   469     TFileName fileName;
       
   470     TParse* parse = new(ELeave) TParse();
       
   471     CleanupStack::PushL( parse );
       
   472     
       
   473     parse->Set( KNSmlDefaultAgendaHandlerRsc_1_2,
       
   474                 &KDC_RESOURCE_FILES_DIR, NULL );
       
   475     
       
   476     fileName = parse->FullName();
       
   477     RResourceFile resourceFile;
       
   478     RFs rfs;
       
   479     User::LeaveIfError(rfs.Connect());
       
   480     
       
   481     BaflUtils::NearestLanguageFile( rfs, fileName );
       
   482 
       
   483     TRAPD( leavecode, resourceFile.OpenL( rfs,fileName ) );
       
   484     if ( leavecode != 0 )
       
   485         {
       
   486         CleanupStack::PopAndDestroy(); // parse
       
   487         rfs.Close();
       
   488         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin:::StoreFormatL(): Error END"));
       
   489         User::Leave( leavecode );
       
   490         }
       
   491     
       
   492     CleanupClosePushL( resourceFile );
       
   493     HBufC8* buffer = resourceFile.AllocReadLC( NSML_DEFAULT_AGENDA_HANDLER );
       
   494     TResourceReader reader;
       
   495     reader.SetBuffer( buffer );
       
   496 
       
   497     CSmlDataStoreFormat* dsFormat = NULL;
       
   498     dsFormat = CSmlDataStoreFormat::NewLC( aStringPool, reader );
       
   499     CleanupStack::Pop(); // dsFormat
       
   500     CleanupStack::PopAndDestroy( 3 ); // buffer, resourceFile, parse
       
   501     rfs.Close();
       
   502     
       
   503     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::StoreFormatL: END"));
       
   504     return dsFormat;
       
   505     }
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // CNSmlDefaultAgendaHandlerPlugin::DeviceSyncOwner
       
   509 // Returns the DS Application UID
       
   510 // -----------------------------------------------------------------------------
       
   511 TInt CNSmlDefaultAgendaHandlerPlugin::DeviceSyncOwner()
       
   512     {
       
   513     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::DeviceSyncOwner: BEGIN"));
       
   514     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::DeviceSyncOwner: '%d' END"), KCRUidNSmlDSApp.iUid );
       
   515     return KCRUidNSmlDSApp.iUid;
       
   516     }
       
   517 
       
   518 // -----------------------------------------------------------------------------
       
   519 // CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL
       
   520 // Returns the Sync Status for the given UID
       
   521 // -----------------------------------------------------------------------------
       
   522 TBool CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL( TSmlDbItemUid aUid )
       
   523     {
       
   524     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL: BEGIN"));
       
   525     
       
   526     TBool syncstatus( EFalse );
       
   527     CNSmlDefaultAgendaHandlerUtil* agendautil = CalendarInfoL( aUid );        
       
   528     if( agendautil != NULL )
       
   529         {
       
   530         syncstatus = agendautil->iSyncStatus;
       
   531         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::syncstatus: '%d'"), syncstatus );
       
   532         }    
       
   533     delete agendautil;
       
   534         
       
   535     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL: END"));
       
   536     
       
   537     return syncstatus;
       
   538     }
       
   539 
       
   540 // -----------------------------------------------------------------------------
       
   541 // CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL
       
   542 // Returns the Sync Status for the given FolderName
       
   543 // -----------------------------------------------------------------------------
       
   544 TBool CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL( HBufC* aFolderName )
       
   545     {
       
   546     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL: BEGIN"));
       
   547     
       
   548     TBool syncstatus( EFalse );
       
   549     TBuf8<KBuffLength> keyBuff;    
       
   550     CCalSession *calsession = CCalSession::NewL();
       
   551     CleanupStack::PushL(calsession);
       
   552     calsession->OpenL(aFolderName->Des());    
       
   553     CCalCalendarInfo* caleninfo = calsession->CalendarInfoL();
       
   554     CleanupStack::PushL(caleninfo);
       
   555     // Sync Status
       
   556     keyBuff.Zero();
       
   557     keyBuff.AppendNum( ESyncStatus ); 
       
   558     TPckgC<TBool> pckgSyncStatusValue(syncstatus);
       
   559     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL: Get sync status"));
       
   560     TRAPD(err,pckgSyncStatusValue.Set(caleninfo->PropertyValueL( keyBuff )));
       
   561                 
       
   562     syncstatus = pckgSyncStatusValue();
       
   563     if( err != KErrNone )
       
   564         {
       
   565         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL: Error while retrieving CalFile SYNC Property"));
       
   566         }
       
   567     CleanupStack::PopAndDestroy(caleninfo);
       
   568     CleanupStack::PopAndDestroy(calsession);
       
   569         
       
   570     
       
   571     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::FolderSyncStatusL: END"));
       
   572     
       
   573     return syncstatus;
       
   574     }
       
   575 
       
   576 // -----------------------------------------------------------------------------
       
   577 // CNSmlDefaultAgendaHandlerPlugin::CreateFolderSnapShotItemL
       
   578 // Create the Folder SnapShot Item
       
   579 // -----------------------------------------------------------------------------
       
   580 TNSmlSnapshotItem CNSmlDefaultAgendaHandlerPlugin::CreateFolderSnapShotItemL( const TCalLocalUid& aUid )
       
   581     {
       
   582     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderSnapShotItemL: BEGIN"));
       
   583     
       
   584     TNSmlSnapshotItem item( 0 );
       
   585     
       
   586     CNSmlDefaultAgendaHandlerUtil* agendautil = CalendarInfoL( aUid );
       
   587     if( NULL == agendautil )
       
   588         {
       
   589         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderSnapShotItemL:Invalid CalendarInfo"));
       
   590         return item;
       
   591         }
       
   592     item.SetItemId( aUid );   
       
   593     item.SetLastChangedDate(agendautil->iModified);
       
   594     item.SetSoftDelete(EFalse);
       
   595     delete agendautil; 
       
   596     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CreateFolderSnapShotItemL: END"));
       
   597     
       
   598     return item; 
       
   599     }
       
   600 
       
   601 // -----------------------------------------------------------------------------
       
   602 // CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL
       
   603 // Method to Parse the Folder Data Obtained
       
   604 // -----------------------------------------------------------------------------
       
   605 CNSmlDefaultAgendaHandlerUtil* CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL( RBufReadStream& aStream )
       
   606     {
       
   607     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL: BEGIN"));
       
   608         
       
   609     CNSmlDefaultAgendaHandlerUtil* agendautil = CNSmlDefaultAgendaHandlerUtil::NewL();
       
   610     
       
   611     // Create parser and parse data from Buffer
       
   612     CNSmlFolderParser* folderparser = CNSmlFolderParser::NewLC();
       
   613     TParse name;
       
   614          
       
   615     TInt size = aStream.Source()->SizeL();
       
   616     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL: size:'%d'"), size);
       
   617     CBufFlat* buffer = CBufFlat::NewL( 64 );
       
   618     CleanupStack::PushL( buffer );
       
   619     buffer->ResizeL( size );
       
   620     TPtr8 ptr = buffer->Ptr( 0 );
       
   621     aStream.ReadL( ptr, size );
       
   622     HBufC8* dataBuffer = HBufC8::NewLC( buffer->Size() );
       
   623     TPtr8 dataBufferPtr = dataBuffer->Des();
       
   624     buffer->Read( 0, dataBufferPtr, buffer->Size() );
       
   625         
       
   626     TNSmlParserGeneratorError parseError = 
       
   627                                     folderparser->ParseXml( dataBuffer );
       
   628     CleanupStack::PopAndDestroy( 2 ); // dataBuffer, buffer
       
   629     
       
   630     if ( parseError != EErrorNone )
       
   631         {
       
   632         delete agendautil;
       
   633         CleanupStack::PopAndDestroy( ); // folderparser
       
   634         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL: end with leave"));
       
   635         User::Leave( KErrGeneral );
       
   636         return NULL;
       
   637         }
       
   638     
       
   639     // Every folder item must have NAME property. Even replace because this 
       
   640     // Plug In does not support field level update for folders.
       
   641     if ( !folderparser->iName )
       
   642         {
       
   643         delete agendautil;
       
   644         CleanupStack::PopAndDestroy( ); // folderparser
       
   645         FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL: end with leave"));
       
   646         User::Leave( KErrArgument );
       
   647         return NULL;
       
   648         }
       
   649     
       
   650     // Create Calendar info
       
   651     agendautil->iName = CnvUtfConverter::ConvertToUnicodeFromUtf8L(folderparser->iName->Des());
       
   652     CleanupStack::PopAndDestroy( ); // folderparser;    
       
   653     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::ParseFolderDataL: END"));
       
   654     return agendautil;
       
   655     }   
       
   656 
       
   657 // -----------------------------------------------------------------------------
       
   658 // CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL
       
   659 // Retrieve the CalendarFile Info using the aUid value
       
   660 // -----------------------------------------------------------------------------
       
   661 CNSmlDefaultAgendaHandlerUtil* CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL( TSmlDbItemUid aUid )
       
   662     {
       
   663     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: BEGIN"));   
       
   664         
       
   665     TBuf8<KBuffLength> keyBuff;
       
   666     CNSmlDefaultAgendaHandlerUtil* agendautil = NULL;
       
   667     CCalSession* vCalSession = NULL;
       
   668     CCalSession* vCalSubSession = NULL;   
       
   669     
       
   670     vCalSession = CCalSession::NewL();
       
   671     CleanupStack::PushL(vCalSession);
       
   672     
       
   673     CDesCArray* calfilearr = vCalSession->ListCalFilesL();            
       
   674     CleanupStack::PushL(calfilearr);
       
   675     
       
   676     for(TInt i = 0; i < calfilearr->Count(); i++)
       
   677         {
       
   678         vCalSubSession = CCalSession::NewL(*vCalSession);
       
   679         CleanupStack::PushL(vCalSubSession);
       
   680         vCalSubSession->OpenL(calfilearr->MdcaPoint(i));
       
   681         
       
   682         CCalCalendarInfo* caleninfo = vCalSubSession->CalendarInfoL();
       
   683         CleanupStack::PushL(caleninfo);
       
   684         
       
   685         TUint UidVal;
       
   686         keyBuff.Zero();
       
   687         keyBuff.AppendNum( EFolderLUID );
       
   688         TPckgC<TUint> intBuf(UidVal);
       
   689         TRAPD(err,intBuf.Set(caleninfo->PropertyValueL(keyBuff)));
       
   690                     
       
   691         if( err != KErrNone )
       
   692             {
       
   693             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Error while retrieving CalFile Property"));
       
   694             CleanupStack::PopAndDestroy(caleninfo); 
       
   695             CleanupStack::PopAndDestroy(vCalSubSession); 
       
   696             CleanupStack::PopAndDestroy(calfilearr); 
       
   697             CleanupStack::PopAndDestroy(vCalSession); 
       
   698             return agendautil;
       
   699             }
       
   700         
       
   701         UidVal = intBuf();
       
   702         
       
   703         if(aUid == UidVal)
       
   704             {
       
   705             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Found a match"));
       
   706             agendautil = CNSmlDefaultAgendaHandlerUtil::NewL();
       
   707             agendautil->iEnabled  = caleninfo->Enabled();
       
   708             agendautil->iName     = caleninfo->NameL().AllocL();
       
   709             agendautil->iFileName = caleninfo->FileNameL().AllocL();
       
   710             
       
   711             TInt err(KErrNone);
       
   712             
       
   713             // Created Time
       
   714             TTime timeval;
       
   715             keyBuff.Zero();
       
   716             keyBuff.AppendNum( ECreationTime );     
       
   717             TPckgC<TTime> pckgCreateTimeValue( timeval );
       
   718             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Get Creation date"));
       
   719             TRAP(err,pckgCreateTimeValue.Set(caleninfo->PropertyValueL( keyBuff )));
       
   720                         
       
   721             if( err != KErrNone )
       
   722                 {
       
   723                 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Error while retrieving CalFile CREATED Property"));
       
   724                 }
       
   725             agendautil->iCreated = pckgCreateTimeValue();
       
   726             
       
   727             // Modified Time
       
   728             keyBuff.Zero();
       
   729             keyBuff.AppendNum( EModificationTime );      
       
   730             TPckgC<TTime> pckgModifyTimeValue( timeval );
       
   731             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Get Modified date"));
       
   732             TRAP(err,pckgModifyTimeValue.Set(caleninfo->PropertyValueL( keyBuff )));
       
   733                         
       
   734             if( err != KErrNone )
       
   735                 {
       
   736                 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Error while retrieving CalFile MODIFIED Property"));
       
   737                 }
       
   738             agendautil->iModified = pckgModifyTimeValue();
       
   739             
       
   740             // Sync Status
       
   741             TBool syncstatus;
       
   742             keyBuff.Zero();
       
   743             keyBuff.AppendNum( ESyncStatus ); 
       
   744             TPckgC<TBool> pckgSyncStatusValue(syncstatus);
       
   745             FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL(): Get sync status"));
       
   746             TRAP(err,pckgSyncStatusValue.Set(caleninfo->PropertyValueL( keyBuff )));
       
   747                         
       
   748             if( err != KErrNone )
       
   749                 {
       
   750                 FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: Error while retrieving CalFile SYNC Property"));
       
   751                 }
       
   752             agendautil->iSyncStatus = pckgSyncStatusValue();
       
   753             }        
       
   754         CleanupStack::PopAndDestroy(caleninfo);
       
   755         CleanupStack::PopAndDestroy(vCalSubSession); 
       
   756         }  
       
   757     CleanupStack::PopAndDestroy(calfilearr);
       
   758     CleanupStack::PopAndDestroy(vCalSession); 
       
   759     
       
   760     FLOG(_L("CNSmlDefaultAgendaHandlerPlugin::CalendarInfoL: END"));   
       
   761     
       
   762     return agendautil;
       
   763     }
       
   764 
       
   765 /** 
       
   766  *  Provides a key value pair table, this is used to identify
       
   767  *  the correct construction function for the requested interface.
       
   768  */
       
   769 const TImplementationProxy ImplementationTable[] =
       
   770 {
       
   771         IMPLEMENTATION_PROXY_ENTRY(0x20029F16, CNSmlDefaultAgendaHandlerPlugin::NewL )
       
   772 };
       
   773     
       
   774 /** 
       
   775  * Function used to return an instance of the proxy table.+
       
   776  */
       
   777 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
   778 {
       
   779         aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   780         return ImplementationTable;
       
   781 }
       
   782 
       
   783 #ifdef EKA2 
       
   784 GLDEF_C TInt E32Dll() 
       
   785 #else 
       
   786 GLDEF_C TInt E32Dll(TDllReason /*aReason*/) 
       
   787 #endif 
       
   788 // DLL entry point
       
   789     {
       
   790     return(KErrNone);
       
   791     }
       
   792 
       
   793 //End of file
       
   794