Description
The following code example demonstrates how to launch the Calendar application in day view. The date will be specified with the aDate parameter. If aDate is NULL, Calendar will open the view in current date (today).
Capability requirements: SwEvent
Headers:
#include <w32std.h> // RWsSession (ws32.lib) #include <apgtask.h> // TApaTaskList,TApaTask (apgrfx.lib) #include <apgcli.h> // RApaLsSession (apgrfx.lib) #include <apaid.h> // TApaAppInfo (apparc.lib) #include <apacmdln.h> // CApaCommandLine (apparc.lib)
Constants:
// UID of the Calendar Application:
const TUid KCalendarAppUID = { 0x10005901 };
// Format strings for constructing parameters passed to Calendar
_LIT( KCalCmdTODAY, "TODAY" );
_LIT( KCalCmdDATE, "DATE " );
_LIT( KCmdTimeFormat, "%F%Y %M %D %H %T %S %C" );
#define KCalTimeParamMaxLen 36
Implementation:
void LaunchCalendarL( const TTime* aDate )
{
TBuf<KCalTimeParamMaxLen> paramsBuf( KCalCmdTODAY );
// if a specific date is given, construct command line parameters
// using "DATE YYYY MM DD HH MM SS MMMMMM" format
if( aDate )
{
aDate->FormatL( paramsBuf, KCmdTimeFormat() );
paramsBuf.Insert( 0, KCalCmdDATE );
}
// package the parameters, so it can be passed
// as an 8-bit descriptor
TPckg< TBuf16<KCalTimeParamMaxLen> > paramsPkg( paramsBuf );
// Check if the Calendar is already running
TApaTaskList taskList( iCoeEnv->WsSession() );
TApaTask task = taskList.FindApp( KCalendarAppUID );
if( task.Exists() ) // Calendar already open
{
TInt ret = task.SendMessage( KNullUid, paramsPkg ); // requires SwEvent
task.BringToForeground();
}
else // Launch Calendar in day view
{
TApaAppInfo appInfo;
RApaLsSession lsSession;
User::LeaveIfError(lsSession.Connect());
CleanupClosePushL( lsSession );
if( lsSession.GetAppInfo( appInfo, KCalendarAppUID ) == KErrNone )
{
// Construct a CApaCommandLine instance and start Calendar
CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
cmdLine->SetExecutableNameL( appInfo.iFullName );
cmdLine->SetCommandL( EApaCommandRun );
cmdLine->SetTailEndL( paramsPkg );
lsSession.StartApp( *cmdLine );
CleanupStack::PopAndDestroy( cmdLine );
}
CleanupStack::PopAndDestroy(); // close lsSession
}
}
Bookmark
Email this
Hits: 362
Comments (0)

Write comment



