calendarui/server/CalenSvr/src/CalenServer.cpp
branchRCL_3
changeset 5 42814f902fe6
parent 0 f979ecb2b13e
child 11 0f07cd1b5772
equal deleted inserted replaced
0:f979ecb2b13e 5:42814f902fe6
    20 #include <CalendarInternalCRKeys.h>
    20 #include <CalendarInternalCRKeys.h>
    21 #include <calsession.h>
    21 #include <calsession.h>
    22 #include <calcalendarinfo.h>
    22 #include <calcalendarinfo.h>
    23 #include <calenmulticalutil.h>
    23 #include <calenmulticalutil.h>
    24 #include <CalenInterimUtils2.h>
    24 #include <CalenInterimUtils2.h>
       
    25 #include <calensvrmissedalarmmanagerresource.rsg>
       
    26 #include <data_caging_path_literals.hrh>
       
    27 #include <bautils.h>
       
    28 #include <pathinfo.h>
    25 
    29 
    26 //debug
    30 //debug
    27 #include "calendarui_debug.h"
    31 #include "calendarui_debug.h"
    28 
    32 
    29 // INCLUDES
    33 // INCLUDES
    33 #include "CalSvrDef.h"
    37 #include "CalSvrDef.h"
    34 //#include "CalenSvrAlarmManager.h"
    38 //#include "CalenSvrAlarmManager.h"
    35 #include "CalenSvrBootManager.h"
    39 #include "CalenSvrBootManager.h"
    36 #include "CalenSvrDBManager.h"
    40 #include "CalenSvrDBManager.h"
    37 #include "calensvrmissedalarmmanager.h"
    41 #include "calensvrmissedalarmmanager.h"
       
    42 #include "calenmissedalarmconstants.h"
    38 
    43 
    39 // LOCAL CONSTANTS AND MACROS
    44 // LOCAL CONSTANTS AND MACROS
       
    45 
    40 const TInt KCalenServerPriority(CActive::EPriorityStandard);
    46 const TInt KCalenServerPriority(CActive::EPriorityStandard);
    41 _LIT( KCalendarDatabaseFilePath, "c:calendar" );
    47 _LIT( KCalendarDatabaseFilePath, "c:calendar" );
    42 const TInt KBufferStartingSize( 128 ); 
    48 const TInt KBufferStartingSize( 128 ); 
    43 const TInt KBufferSizeIncrement( 64 );
    49 const TInt KBufferSizeIncrement( 64 );
    44 const TInt KBuffLength = 128;
    50 const TInt KBuffLength = 128;
    45 
    51 
       
    52 
    46 const TInt KComma( ',' );
    53 const TInt KComma( ',' );
    47 
    54 
    48 // ================= MEMBER FUNCTIONS =======================
    55 // ================= MEMBER FUNCTIONS =======================
    49 //
    56 //
    50 // Construction and destruction 
    57 // Construction and destruction 
   300     TRACE_ENTRY_POINT;
   307     TRACE_ENTRY_POINT;
   301     
   308     
   302     CDesC16ArrayFlat* calendarNamesList = new (ELeave) CDesC16ArrayFlat(2);
   309     CDesC16ArrayFlat* calendarNamesList = new (ELeave) CDesC16ArrayFlat(2);
   303     CleanupStack::PushL(calendarNamesList);
   310     CleanupStack::PushL(calendarNamesList);
   304     // read calendar names from central repository
   311     // read calendar names from central repository
   305     ReadCalendarNamesFromCenrepL(*calendarNamesList);
   312     ReadCalendarNamesFromResourceL(*calendarNamesList);
   306     
   313     
   307     RArray<TInt> calendarColors;
   314     RArray<TInt> calendarColors;
   308     // read calendar colors from central repository
   315     // read calendar colors from central repository
   309     ReadCalendarColorsFromCenrepL(calendarColors);
   316     ReadCalendarColorsFromCenrepL(calendarColors);
   310     
   317     
   355 // -----------------------------------------------------------------------------
   362 // -----------------------------------------------------------------------------
   356 // CCalenServer::ReadCalendarNamesFromCenrepL
   363 // CCalenServer::ReadCalendarNamesFromCenrepL
   357 // Read calendar names from central repository
   364 // Read calendar names from central repository
   358 // -----------------------------------------------------------------------------
   365 // -----------------------------------------------------------------------------
   359 //
   366 //
   360 void CCalenServer::ReadCalendarNamesFromCenrepL(CDesC16ArrayFlat& aCalendarNames)
   367 void CCalenServer::ReadCalendarNamesFromResourceL(CDesC16ArrayFlat& aCalendarNames)
   361     {
   368     {
   362     TRACE_ENTRY_POINT;
   369     TRACE_ENTRY_POINT;
   363     
   370     
   364     CRepository* repository = CRepository::NewL( KCRUidCalendar );
   371     RFs fsSession;
   365     CleanupStack::PushL( repository );
   372     CleanupClosePushL( fsSession );
   366     
   373     RResourceFile resourceFile;
   367     TInt bufSize( KBufferStartingSize );
   374     CleanupClosePushL( resourceFile );
   368     TBool wasRead( EFalse );
   375     User::LeaveIfError( fsSession.Connect() );
   369     do
   376     TFileName resourceFileName( KMissedAlarmResourceFile );
   370         {
   377     
   371         RBuf buf;
   378     BaflUtils::NearestLanguageFile( fsSession, resourceFileName );
   372         CleanupClosePushL(buf);
   379     
   373         buf.CreateL(bufSize);
   380    // __PRINT(" resourcefileName : %s" , resourceFileName );
   374         // read default calendars information from cenrep
   381 
   375         TInt err = repository->Get(KCalendarDefaultCalendars, buf);
   382     resourceFile.OpenL(fsSession, resourceFileName );
   376         if (err == KErrNone)
   383     resourceFile.ConfirmSignatureL( 0 );
   377             {
   384     // personal
   378             wasRead = ETrue;
   385         HBufC8* personalBuffer = resourceFile.AllocReadLC( R_CALE_DB_PERSONAL );    
   379             PopulateCalendarNamesListL(buf, aCalendarNames);
   386        const TPtrC16 ptrPBuffer(( TText16*) personalBuffer->Ptr(),
   380             }
   387                                          ( personalBuffer->Length()+1 )>>1 );    
   381         else if (err == KErrOverflow)
   388        HBufC *personalCalendar = ptrPBuffer.AllocL();    
   382             {
   389        aCalendarNames.AppendL( personalCalendar->Des() );    
   383             bufSize += KBufferSizeIncrement;
   390        CleanupStack::PopAndDestroy( personalBuffer );
   384             }
   391        
   385         else
   392     // famliy
   386             {
   393        HBufC8* familyBuffer=resourceFile.AllocReadLC( R_CALE_DB_FAMILY );
   387             User::Leave(err);
   394        const TPtrC16 ptrFBuffer(( TText16*) familyBuffer->Ptr(),
   388             }
   395                ( familyBuffer->Length()+1 )>>1 );
   389         CleanupStack::PopAndDestroy(&buf);
   396        HBufC *familyCalendar = ptrFBuffer.AllocL();
   390         }
   397        aCalendarNames.AppendL( familyCalendar->Des() );
   391     while (!wasRead);
   398        CleanupStack::PopAndDestroy( familyBuffer );
   392 
   399        
   393     CleanupStack::PopAndDestroy(repository);
   400     //friends
       
   401        HBufC8* friendsBuffer = resourceFile.AllocReadLC( R_CALE_DB_FRIENDS );
       
   402        const TPtrC16 ptrFrBuffer(( TText16*) friendsBuffer->Ptr(),
       
   403                ( friendsBuffer->Length()+1 )>>1 );
       
   404        HBufC *friendsCalendar = ptrFrBuffer.AllocL();
       
   405        aCalendarNames.AppendL( friendsCalendar->Des() );
       
   406        CleanupStack::PopAndDestroy( friendsBuffer );
       
   407    
       
   408     CleanupStack::PopAndDestroy(&resourceFile);
       
   409     CleanupStack::PopAndDestroy(&fsSession);
       
   410     
   394     TRACE_EXIT_POINT;
   411     TRACE_EXIT_POINT;
   395     }
   412     }
   396 
   413 
   397 // -----------------------------------------------------------------------------
   414 // -----------------------------------------------------------------------------
   398 // CCalenServer::ReadCalendarColorsFromCenrepL
   415 // CCalenServer::ReadCalendarColorsFromCenrepL
   431         CleanupStack::PopAndDestroy(&buf);
   448         CleanupStack::PopAndDestroy(&buf);
   432         }
   449         }
   433     while (!wasRead);
   450     while (!wasRead);
   434 
   451 
   435     CleanupStack::PopAndDestroy(repository);
   452     CleanupStack::PopAndDestroy(repository);
   436     TRACE_EXIT_POINT;
       
   437     }
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 // CCalenServer::PopulateCalendarNamesListL
       
   441 // Populate calendar names list from central repository buffer
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 void CCalenServer::PopulateCalendarNamesListL( const TDesC& aRepositoryBuffer,
       
   445                     CDesC16ArrayFlat& aCalendarNames)
       
   446     {
       
   447     TRACE_ENTRY_POINT;
       
   448     
       
   449     TPtrC marker = aRepositoryBuffer;
       
   450     TInt calendarNameOffset;
       
   451     while ((calendarNameOffset = marker.Locate(TChar(KComma)))
       
   452             != KErrNotFound)
       
   453         {
       
   454         // append calendar name to list
       
   455         aCalendarNames.AppendL(marker.Left(calendarNameOffset));
       
   456         marker.Set(marker.Mid(calendarNameOffset + 1));
       
   457 
       
   458         if (marker.Locate(TChar(KComma)) == KErrNotFound)
       
   459             {
       
   460             aCalendarNames.AppendL(marker.Left(marker.Length()));
       
   461             }
       
   462         }
       
   463     TRACE_EXIT_POINT;
   453     TRACE_EXIT_POINT;
   464     }
   454     }
   465 
   455 
   466 // -----------------------------------------------------------------------------
   456 // -----------------------------------------------------------------------------
   467 // CCalenServer::PopulateCalendarColorListL
   457 // CCalenServer::PopulateCalendarColorListL