calendarui/server/CalenSvr/src/CalenServer.cpp
branchRCL_3
changeset 60 96907930389d
parent 30 d68a4b5d5885
child 67 1539a383d7b6
equal deleted inserted replaced
59:aba12c885d83 60:96907930389d
    24 #include <CalenInterimUtils2.h>
    24 #include <CalenInterimUtils2.h>
    25 #include <calensvrmissedalarmmanagerresource.rsg>
    25 #include <calensvrmissedalarmmanagerresource.rsg>
    26 #include <data_caging_path_literals.hrh>
    26 #include <data_caging_path_literals.hrh>
    27 #include <bautils.h>
    27 #include <bautils.h>
    28 #include <pathinfo.h>
    28 #include <pathinfo.h>
       
    29 #include <calsession.h>
    29 
    30 
    30 //debug
    31 //debug
    31 #include "calendarui_debug.h"
    32 #include "calendarui_debug.h"
    32 
    33 
    33 // INCLUDES
    34 // INCLUDES
    99 // -----------------------------------------------------------------------------
   100 // -----------------------------------------------------------------------------
   100 //
   101 //
   101 CCalenServer::~CCalenServer()
   102 CCalenServer::~CCalenServer()
   102     {
   103     {
   103     TRACE_ENTRY_POINT;
   104     TRACE_ENTRY_POINT;
       
   105     if( iSession )
       
   106         {
       
   107         // stop listening for calendar file change notifications
       
   108         iSession->StopFileChangeNotification();
       
   109         delete iSession;
       
   110         }
   104     
   111     
   105     //delete iAlarmManager;
   112     //delete iAlarmManager;
   106     delete iDBManager;
   113     delete iDBManager;
   107     delete iBootManager;
   114     delete iBootManager;
   108     delete iMissedAlarmHandler;
   115     delete iMissedAlarmHandler;
   134 
   141 
   135     iBootManager = CCalenSvrBootManager::NewL( *this );
   142     iBootManager = CCalenSvrBootManager::NewL( *this );
   136     iDBManager = CCalenSvrDBManager::NewL();
   143     iDBManager = CCalenSvrDBManager::NewL();
   137     //iAlarmManager = CCalenSvrAlarmManager::NewL();
   144     //iAlarmManager = CCalenSvrAlarmManager::NewL();
   138     iMissedAlarmHandler = CCalenSvrMissedAlarmManager::NewL();
   145     iMissedAlarmHandler = CCalenSvrMissedAlarmManager::NewL();
       
   146     
       
   147     
       
   148     // create cal session
       
   149     iSession = CCalSession::NewL();
       
   150     // start listening for calendar file change notifications
       
   151     iSession->StartFileChangeNotificationL(*this);
       
   152 
   139     StartL( KCalendarServerName );
   153     StartL( KCalendarServerName );
   140     
   154     
   141     TRACE_EXIT_POINT;
   155     TRACE_EXIT_POINT;
   142     }
   156     }
   143 
   157 
   560     aCalendarInfo.SetPropertyL(keyBuff, pkgMarkAsDelete);
   574     aCalendarInfo.SetPropertyL(keyBuff, pkgMarkAsDelete);
   561 
   575 
   562     TRACE_EXIT_POINT    
   576     TRACE_EXIT_POINT    
   563     }
   577     }
   564 
   578 
       
   579 // ----------------------------------------------------------------------------
       
   580 // CCalenServer::CalendarInfoChangeNotificationL
       
   581 // Handle calendar file change notifications
       
   582 // ----------------------------------------------------------------------------
       
   583 void CCalenServer::CalendarInfoChangeNotificationL( 
       
   584         RPointerArray<CCalFileChangeInfo>& aCalendarInfoChangeEntries)
       
   585     {
       
   586     TRACE_ENTRY_POINT;
       
   587 
       
   588     // get the file change count
       
   589     TInt calenInfoChangeCount = aCalendarInfoChangeEntries.Count();
       
   590     RArray<TInt> calendarColors;
       
   591     // read calendar colors from central repository
       
   592     ReadCalendarColorsFromCenrepL(calendarColors);
       
   593 
       
   594     for(TInt index = 0;index < calenInfoChangeCount;index++)
       
   595         {
       
   596         // default calendar is deleted/updated.
       
   597         if( !aCalendarInfoChangeEntries[index]->FileNameL().CompareF(KCalendarDatabaseFilePath) )
       
   598             {
       
   599             MCalFileChangeObserver::TChangeType changeType = 
       
   600             aCalendarInfoChangeEntries[index]->ChangeType();
       
   601             switch(changeType)
       
   602                 {
       
   603                 case MCalFileChangeObserver::ECalendarFileDeleted:
       
   604                     {
       
   605                     // create cal session
       
   606                     CCalSession* session = CCalSession::NewL();
       
   607                     CleanupStack::PushL(session);
       
   608                     
       
   609                     // create and set metadata information from central repository
       
   610                     CCalCalendarInfo* calendarInfo = CCalCalendarInfo::NewL();
       
   611                     CleanupStack::PushL(calendarInfo);
       
   612                     
       
   613                     // EFolderLUID
       
   614                     TBuf8<KBuffLength> keyBuff;
       
   615                     keyBuff.AppendNum(EFolderLUID);
       
   616                     TRAPD(err,calendarInfo->PropertyValueL(keyBuff));
       
   617 
       
   618                     //First set the folder uid as 100000 for default calendar.
       
   619                     // Later set the other properties
       
   620                     if (KErrNotFound == err)
       
   621                         {
       
   622                         TUint calValue = 0;
       
   623                         //Get the available offset value and set as property value.
       
   624                         calValue = 100000;
       
   625                         TPckgC<TUint> calValuePckg(calValue);
       
   626                         calendarInfo->SetPropertyL(keyBuff, calValuePckg);
       
   627                         }
       
   628                     SetCalendarAddPropertiesL(*calendarInfo);
       
   629                     calendarInfo->SetNameL(KCalendarDatabaseFilePath);
       
   630                     calendarInfo->SetColor(TRgb(calendarColors[0]));
       
   631                     calendarInfo->SetEnabled(ETrue);
       
   632                     TBuf<KMaxFileName> calendarFileName;
       
   633                     calendarFileName.Append(KCalendarDatabaseFilePath);
       
   634                     //create the default calendar.
       
   635                     TRAPD(error,session->CreateCalFileL(calendarFileName,*calendarInfo));
       
   636                     User::LeaveIfError(error);
       
   637                     CleanupStack::PopAndDestroy(calendarInfo);
       
   638                     CleanupStack::PopAndDestroy(session);
       
   639                     }
       
   640                 break;
       
   641                 case MCalFileChangeObserver::ECalendarInfoUpdated:
       
   642                     {
       
   643                     // create cal session
       
   644                     CCalSession* session = CCalSession::NewL();
       
   645                     CleanupStack::PushL(session);
       
   646                     session->OpenL(KCalendarDatabaseFilePath);
       
   647                     
       
   648                     CCalCalendarInfo* calendarInfo = session->CalendarInfoL();
       
   649                     CleanupStack::PushL(calendarInfo);
       
   650 
       
   651                     TBuf8<KBuffLength> keyBuff;
       
   652                     keyBuff.AppendNum(EMarkAsDelete);
       
   653 
       
   654                     TBool markAsdelete;
       
   655                     TPckgC<TBool> pkgMarkAsDelete(markAsdelete);
       
   656                     TRAPD(err,pkgMarkAsDelete.Set(calendarInfo->PropertyValueL(keyBuff)));
       
   657                     markAsdelete = pkgMarkAsDelete();
       
   658                     if( markAsdelete )
       
   659                         {
       
   660                         // Mark the CalFile as visible.
       
   661                         calendarInfo->SetEnabled( ETrue );
       
   662                         TBuf8<KBuffLength> keyBuff;
       
   663 
       
   664                         // Set the modification time as home time.
       
   665                         keyBuff.Zero();
       
   666                         keyBuff.AppendNum(EModificationTime);
       
   667                         TTime modificationTime;
       
   668                         modificationTime.HomeTime();
       
   669                         TPckgC<TTime> pkgModificationTime(modificationTime);
       
   670                         calendarInfo->SetPropertyL(keyBuff, pkgModificationTime);
       
   671                         
       
   672                         // Set the SyncStatus to ETrue
       
   673                         keyBuff.Zero();
       
   674                         keyBuff.AppendNum( ESyncStatus );
       
   675                         TBool syncstatus( ETrue );
       
   676                         TPckgC<TBool> pckgSyncStatusValue( syncstatus );
       
   677                         calendarInfo->SetPropertyL( keyBuff, pckgSyncStatusValue );
       
   678                         
       
   679                         // Mark the meta property as SoftDeleted
       
   680                         keyBuff.Zero();
       
   681                         keyBuff.AppendNum(EMarkAsDelete);
       
   682                         TPckgC<TBool> pkgSoftDelete( EFalse );
       
   683                         calendarInfo->SetPropertyL(keyBuff, pkgSoftDelete);
       
   684 
       
   685                         session->SetCalendarInfoL( *calendarInfo );
       
   686                         }
       
   687                     CleanupStack::PopAndDestroy(calendarInfo);
       
   688                     CleanupStack::PopAndDestroy(session);
       
   689                     }
       
   690                 }
       
   691             }
       
   692         }
       
   693     TRACE_EXIT_POINT;
       
   694     }
   565 // End of File
   695 // End of File