calendarengines/calenlauncher/src/CalenLauncherImpl.cpp
changeset 0 f979ecb2b13e
child 48 bf573002ff72
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Wrapper implementation class for launching S60 Calendar
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20 * Include files
       
    21 */
       
    22 #include "CalenLauncherImpl.h"	                            // CCalenLauncherImpl
       
    23 #include <calenlauncher.h>                                 // View UIDs
       
    24 
       
    25 #include <apgcli.h>                                         // RApaLsSession
       
    26 #include <apgtask.h>                                        // TApaTask, TApaTaskList
       
    27 #include <eikenv.h>                                         // CEikEnv
       
    28 #include <e32std.h>
       
    29 
       
    30 /**
       
    31 * Constants
       
    32 */
       
    33 const TUid KCalendarUid             = {0x10005901};         // Calendar application UID
       
    34 const TInt KMaxCmdLineLength        = 128;                  // Max length of cmd line string
       
    35 
       
    36 /**
       
    37 * Command line parameter strings.  Should NOT be localised.
       
    38 */
       
    39 _LIT(KCmdNewMeeting,                "NEW_MEETING");         // Launch to new meeting editor
       
    40 _LIT(KCmdNewAnniv,                  "NEW_ANNIV");           // Launch to new anniv editor
       
    41 _LIT(KCmdNewTodo,                   "NEW_TODO");            // Launch to new todo editor
       
    42 _LIT(KCmdDefault,                   "DEFAULT");             // Launch to default view
       
    43 _LIT(KCmdMonth,                     "MONTH");               // Launch to month view
       
    44 _LIT(KCmdWeek,                      "WEEK");                // Launch to week view
       
    45 _LIT(KCmdDay,                       "DAY");                 // Launch to day view
       
    46 _LIT(KCmdTodo,                      "TODO");                // Launch to todo view
       
    47 _LIT(KCmdLUid,                      "LUID");                // Launch to editor
       
    48 _LIT(KCmdLUidViewer,                "LUIDVIEWER");          // Launch to viewer
       
    49 _LIT(KCommandAlarmViewer,           "LUIDALARMVIEWER");     // Launch to alarm viewer
       
    50 _LIT(KCommandAlarmViewerNoSnooze,   "LUIDALARMVIEWER_NOSNOOZE"); // Launch to alarm viewer (with only stop key available)
       
    51 _LIT(KLUidFormat,                   "%u");                  // TLocalUid is unsigned int
       
    52 _LIT(KDateParamFormat,              "%d");                  // Date components are signed ints
       
    53 _LIT(KFlagFormat,                   "%d");                  // Flag is int
       
    54 _LIT(KSpace,                        " ");                   // Space
       
    55 
       
    56 /**
       
    57 * First stage constructor.
       
    58 * Creates an instance of CCalenLauncherImpl and places it
       
    59 * on the cleanup stack before passing ownership to the caller.
       
    60 */
       
    61 CCalenLauncherImpl* CCalenLauncherImpl::NewLC()
       
    62     {
       
    63     CCalenLauncherImpl* self = new (ELeave) CCalenLauncherImpl;
       
    64     CleanupStack::PushL(self);
       
    65     self->ConstructL();
       
    66     return self;
       
    67     }
       
    68 
       
    69 /**
       
    70 * Second stage constructor.
       
    71 * Performs any leaving operations needed for construction.
       
    72 */
       
    73 void CCalenLauncherImpl::ConstructL()
       
    74     {
       
    75     iLaunchUnicode = HBufC::NewL( KMaxCmdLineLength );
       
    76     }
       
    77 
       
    78 /**
       
    79 * Private constructor
       
    80 */
       
    81 CCalenLauncherImpl::CCalenLauncherImpl()
       
    82     {
       
    83     // Nothing to do.
       
    84     }
       
    85 
       
    86 /**
       
    87 * Destructor
       
    88 */
       
    89 CCalenLauncherImpl::~CCalenLauncherImpl()
       
    90     {
       
    91     delete iLaunchUnicode;
       
    92     delete iLaunchParams;
       
    93     }
       
    94 
       
    95 /**
       
    96 * Opens Calendar directly to the new entry editor.
       
    97 * Calendar will be closed when the editor is closed.
       
    98 * Any open dialogs (eg entry viewer or editor) will be closed.
       
    99 * @param aEntryType Type of entry editor to open
       
   100 */
       
   101 void CCalenLauncherImpl::NewEntryL( const CCalEntry::TType& aEntryType, TInt aFlag )
       
   102     {
       
   103     switch (aEntryType)
       
   104         {
       
   105         case CCalEntry::EAppt:
       
   106 		case CCalEntry::EEvent:
       
   107             // Add string 'NEW_MEETING'
       
   108             AddLaunchParamL( KCmdNewMeeting );
       
   109             break;
       
   110 
       
   111         case CCalEntry::ETodo:
       
   112             // Add string 'NEW_TODO'
       
   113             AddLaunchParamL( KCmdNewTodo );
       
   114             break;
       
   115 
       
   116         case CCalEntry::EAnniv:
       
   117             // Add string 'NEW_ANNIV'
       
   118             AddLaunchParamL( KCmdNewAnniv );
       
   119             break;
       
   120 
       
   121         case CCalEntry::EReminder:
       
   122             User::Leave( KErrNotSupported );
       
   123             break;
       
   124 
       
   125         default:
       
   126             User::Leave( KErrNotSupported );
       
   127             break;
       
   128         }
       
   129 
       
   130     AddFlagParamL( aFlag );
       
   131     // Launch Calendar
       
   132     LaunchAppL();
       
   133     }
       
   134 
       
   135 /**
       
   136 * Opens a Calendar entry directly in the entry viewer.  If the
       
   137 * entry is a repeating entry then entire series will be opened.
       
   138 * The entry editor may be launched from the entry viewer.
       
   139 * Calendar will be closed when the viewer is closed.
       
   140 * Any open dialogs (eg entry viewer or editor) will be closed.
       
   141 * @param aLocalUid LocalUid of the entry to view
       
   142 */
       
   143 void CCalenLauncherImpl::ViewEntryL( const TCalLocalUid& aLocalUid )
       
   144     {
       
   145     // Add string 'LUIDVIEWER'
       
   146     AddLaunchParamL( KCmdLUidViewer );
       
   147 
       
   148     // Add the local uid
       
   149     AddUidParamL( aLocalUid );
       
   150 
       
   151     // Launch Calendar
       
   152     LaunchAppL();
       
   153     }
       
   154 
       
   155 /**
       
   156 * Opens an instance of a repeating Calendar entry directly in the
       
   157 * entry viewer.
       
   158 * The entry editor may be launched from the entry viewer.
       
   159 * Calendar will be closed when the viewer is closed.
       
   160 * Any open dialogs (eg entry viewer or editor) will be closed.
       
   161 * @param aLocalUid LocalUid of the entry to view
       
   162 * @param aInstanceTime Instance time of the repeated entry
       
   163 */
       
   164 void CCalenLauncherImpl::ViewEntryL( const TCalLocalUid& aLocalUid, const TCalTime& aInstanceTime, TInt aFlags )
       
   165     {
       
   166     if( aFlags & CalenLauncher::EAlarmViewer )
       
   167         {
       
   168         // Add string 'LUIDALARMVIEWER'
       
   169         AddLaunchParamL( KCommandAlarmViewer );
       
   170         }
       
   171     else if( aFlags & CalenLauncher::EAlarmViewerNoSnooze )
       
   172         {
       
   173         // Add string 'LUIDALARMVIEWER_NOSNOOZE'
       
   174         AddLaunchParamL( KCommandAlarmViewerNoSnooze );
       
   175         }
       
   176     else // aFlags == 0
       
   177         {
       
   178         // Add string 'LUIDVIEWER'
       
   179         AddLaunchParamL( KCmdLUidViewer );
       
   180         }
       
   181 
       
   182     // Add the local uid
       
   183     AddUidParamL( aLocalUid );
       
   184 
       
   185     // Add the time
       
   186     AddTimeParamL( aInstanceTime );
       
   187 
       
   188     // Launch Calendar
       
   189     LaunchAppL();
       
   190     }
       
   191 
       
   192 /**
       
   193 * Opens an instance of a repeating Calendar entry directly in the
       
   194 * entry viewer.
       
   195 * The entry editor may be launched from the entry viewer.
       
   196 * Calendar will be closed when the viewer is closed.
       
   197 * Any open dialogs (eg entry viewer or editor) will be closed.
       
   198 * @param aLocalUid LocalUid of the entry to view
       
   199 * @param aInstanceTime Instance time of the repeated entry
       
   200 * @param aCalFileName Calendar DB name of the repeated entry
       
   201 */
       
   202 void CCalenLauncherImpl::ViewEntryL( const TCalLocalUid& aLocalUid, const TCalTime& aInstanceTime, const TDesC& aCalFileName, TInt aFlags )
       
   203     {
       
   204     if( aFlags & CalenLauncher::EAlarmViewer )
       
   205         {
       
   206         // Add string 'LUIDALARMVIEWER'
       
   207         AddLaunchParamL( KCommandAlarmViewer );
       
   208         }
       
   209     else if( aFlags & CalenLauncher::EAlarmViewerNoSnooze )
       
   210         {
       
   211         // Add string 'LUIDALARMVIEWER_NOSNOOZE'
       
   212         AddLaunchParamL( KCommandAlarmViewerNoSnooze );
       
   213         }
       
   214     else // aFlags == 0
       
   215         {
       
   216         // Add string 'LUIDVIEWER'
       
   217         AddLaunchParamL( KCmdLUidViewer );
       
   218         }
       
   219 
       
   220     // Add the local uid
       
   221     AddUidParamL( aLocalUid );
       
   222 
       
   223     AddLaunchParamL( aCalFileName );
       
   224 
       
   225     // Add the time
       
   226     AddTimeParamL( aInstanceTime );
       
   227 
       
   228     // Launch Calendar
       
   229     LaunchAppL();
       
   230     }
       
   231 /**
       
   232 * Opens a Calendar entry directly in the entry editor.  If the
       
   233 * entry is a repeating entry then entire series will be opened.
       
   234 * Calendar will be closed when the editor is closed.
       
   235 * Any open dialogs (eg entry viewer or editor) will be closed.
       
   236 * @param aLocalUid LocalUid of the entry to view
       
   237 */
       
   238 void CCalenLauncherImpl::EditEntryL( const TCalLocalUid& aLocalUid )
       
   239     {
       
   240     // Add string 'LUID'
       
   241     AddLaunchParamL( KCmdLUid );
       
   242 
       
   243     // Add the local uid
       
   244     AddUidParamL( aLocalUid );
       
   245 
       
   246     // Launch Calendar
       
   247     LaunchAppL();
       
   248     }
       
   249 
       
   250 /**
       
   251 * Opens an instance of a repeating Calendar entry directly in the
       
   252 * entry editor.
       
   253 * Calendar will be closed when the editor is closed.
       
   254 * Any open dialogs (eg entry viewer or editor) will be closed.
       
   255 * @param aLocalUid LocalUid of the entry to view
       
   256 * @param aInstanceTime Instance time of the repeated entry
       
   257 */
       
   258 void CCalenLauncherImpl::EditEntryL( const TCalLocalUid& aLocalUid, const TCalTime& aInstanceTime )
       
   259     {
       
   260     // Add string 'LUID'
       
   261     AddLaunchParamL( KCmdLUid );
       
   262 
       
   263     // Add the local uid
       
   264     AddUidParamL( aLocalUid );
       
   265 
       
   266     // Add the time
       
   267     AddTimeParamL( aInstanceTime );
       
   268 
       
   269     // Launch Calendar
       
   270     LaunchAppL();
       
   271     }
       
   272 
       
   273 /**
       
   274 * Launches Calendar in the specified view.
       
   275 * If Calendar is already running it will be brought to the foreground
       
   276 * in the specified view.
       
   277 * Any open dialogs (eg entry viewer or editor) will be closed.
       
   278 * @param aViewUid UID of the Calendar view to use.
       
   279 */
       
   280 void CCalenLauncherImpl::LaunchL( const TUid& aViewUid )
       
   281     {
       
   282     // Add the view command
       
   283     AddViewUidParamL( aViewUid );
       
   284 
       
   285     // Launch Calendar
       
   286     LaunchAppL();
       
   287     }
       
   288 
       
   289 /**
       
   290 * Launches Calendar in the specified view, focused to the specified time
       
   291 * If Calendar is already running it will be brought to the foreground
       
   292 * in the specified view.
       
   293 * Any open dialogs (eg entry viewer or editor) will be closed.
       
   294 * @param aViewUid UID of the Calendar view to use.
       
   295 * @param aLaunchTime Initial focus time
       
   296 */
       
   297 void CCalenLauncherImpl::LaunchL( const TUid& aViewUid, const TCalTime& aInstanceTime )
       
   298     {
       
   299     // Add the view command
       
   300     AddViewUidParamL( aViewUid );
       
   301 
       
   302     // Add the time
       
   303     AddTimeParamL( aInstanceTime );
       
   304 
       
   305     // Launch Calendar
       
   306     LaunchAppL();
       
   307     }
       
   308 
       
   309 /**
       
   310 * AddLaunchParamL
       
   311 * Adds a parameter to the unicode launch string
       
   312 * @param aLaunchParam Parameter to add
       
   313 */
       
   314 void CCalenLauncherImpl::AddLaunchParamL( const TDesC& aLaunchParam )
       
   315     {
       
   316     TPtr ptr = iLaunchUnicode->Des();
       
   317     ptr.Append( aLaunchParam );
       
   318     ptr.Append( KSpace );
       
   319     }
       
   320 
       
   321 /**
       
   322 * AddTimeParamL
       
   323 * Expands a TCalTime and adds the individual components to the
       
   324 * unicode launch string.
       
   325 * @param aCalTime Time to add.
       
   326 */
       
   327 void CCalenLauncherImpl::AddTimeParamL( const TCalTime& aCalTime )
       
   328     {
       
   329     TBuf<10> dateBuf;
       
   330     TDateTime dateTime = aCalTime.TimeLocalL().DateTime();
       
   331 
       
   332     // Add year
       
   333     TInt dateParam = dateTime.Year();
       
   334     dateBuf.Format( KDateParamFormat, dateParam );
       
   335     AddLaunchParamL( dateBuf );
       
   336 
       
   337     // Add month
       
   338     dateParam = dateTime.Month();
       
   339     ++dateParam;    // Month is offset from 0
       
   340     dateBuf.Format( KDateParamFormat, dateParam );
       
   341     AddLaunchParamL( dateBuf );
       
   342 
       
   343     // Add day
       
   344     dateParam = dateTime.Day();
       
   345     ++dateParam;    // Day is offset from 0
       
   346     dateBuf.Format( KDateParamFormat, dateParam );
       
   347     AddLaunchParamL( dateBuf );
       
   348 
       
   349     // Add hour
       
   350     dateParam = dateTime.Hour();
       
   351     dateBuf.Format( KDateParamFormat, dateParam );
       
   352     AddLaunchParamL( dateBuf );
       
   353 
       
   354     // Add minutes
       
   355     dateParam = dateTime.Minute();
       
   356     dateBuf.Format( KDateParamFormat, dateParam );
       
   357     AddLaunchParamL( dateBuf );
       
   358     }
       
   359 
       
   360 /**
       
   361 * AddUidParamL
       
   362 * Adds a local uid to the unicode launch string.
       
   363 * @param aLocalUid Uid to add.
       
   364 */
       
   365 void CCalenLauncherImpl::AddUidParamL( const TCalLocalUid& aLocalUid )
       
   366     {
       
   367     TBuf<10> uidBuf;
       
   368     uidBuf.Format( KLUidFormat, aLocalUid );
       
   369     AddLaunchParamL( uidBuf );
       
   370     }
       
   371 
       
   372 /**
       
   373 * AddViewUidParamL
       
   374 * Adds a view uid to the unicode launch string as a command.
       
   375 * @param aViewUid Uid to add.
       
   376 */
       
   377 void CCalenLauncherImpl::AddViewUidParamL( const TUid& aViewUid )
       
   378     {
       
   379     if ( aViewUid.iUid == KCalMonthViewUid.iUid )
       
   380         {
       
   381         // Add string "MONTH"
       
   382         AddLaunchParamL( KCmdMonth );
       
   383         }
       
   384 
       
   385     else if ( aViewUid.iUid == KCalWeekViewUid.iUid )
       
   386         {
       
   387         // Add string "WEEK"
       
   388         AddLaunchParamL( KCmdWeek );
       
   389         }
       
   390 
       
   391     else if ( aViewUid.iUid == KCalDayViewUid.iUid )
       
   392         {
       
   393         // Add string "DAY"
       
   394         AddLaunchParamL( KCmdDay );
       
   395         }
       
   396 
       
   397     else if ( aViewUid.iUid == KCalTodoViewUid.iUid )
       
   398         {
       
   399         // Add string "TODO"
       
   400         AddLaunchParamL( KCmdTodo );
       
   401         }
       
   402 
       
   403     else if ( aViewUid.iUid == KCalDefaultViewUid.iUid )
       
   404         {
       
   405         // Add string "DEFAULT"
       
   406         AddLaunchParamL( KCmdDefault );
       
   407         }
       
   408 
       
   409     else
       
   410         {
       
   411         // Need to handle custom views here at some point...
       
   412         User::Leave( KErrNotSupported );
       
   413         }
       
   414     }
       
   415 
       
   416 /**
       
   417 * ConvertLaunchParamsFromUnicodeL
       
   418 * Converts the launch parameters to pass to calendar.  For some obscure reason,
       
   419 * lost in the midsts of time and space, Calendar is expecting an 8 bit
       
   420 * descriptor containing 16 bit unicode.  No one knows why.  Nice.
       
   421 */
       
   422 void CCalenLauncherImpl::ConvertLaunchParamsFromUnicodeL()
       
   423     {
       
   424     // copy the 16-bit data from iLaunchUnicode to iLaunchParams
       
   425     iLaunchParams = HBufC8::NewL( iLaunchUnicode->Length() *2 );
       
   426     TPtr8 ptr = iLaunchParams->Des();
       
   427     ptr.Copy( reinterpret_cast<const TUint8*>( iLaunchUnicode->Ptr()), iLaunchUnicode->Length() *2 );
       
   428     }
       
   429 
       
   430 /**
       
   431 * LaunchAppL
       
   432 * Starts Calendar with command line parameters.  This will call
       
   433 * TApaTask::SendMessage if Calendar is running, or launch Calendar normally.
       
   434 * Either way, the command line parameters will end up in
       
   435 * CCalenAppUi::ProcessCommandParametersL
       
   436 */
       
   437 void CCalenLauncherImpl::LaunchAppL()
       
   438     {
       
   439     // Convert the launch parameters to 8-bit unicode
       
   440     ConvertLaunchParamsFromUnicodeL();
       
   441 
       
   442     // See if Calendar is running or not.
       
   443     TApaTaskList taskList(CEikonEnv::Static()->WsSession());
       
   444     TApaTask calenTask = taskList.FindApp(KCalendarUid);
       
   445 
       
   446     // If Calendar is running we can just send a message with the parameters
       
   447     if (calenTask.Exists())
       
   448         {
       
   449         const TUid dummyUID = { 0x0 };
       
   450         calenTask.SendMessage(dummyUID, *iLaunchParams);
       
   451         calenTask.BringToForeground();
       
   452         }
       
   453 
       
   454     // If Calendar is not running we launch from the command line
       
   455     else
       
   456         {
       
   457         // Construct the command line object
       
   458         CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   459         cmdLine->SetCommandL(EApaCommandRun);
       
   460         cmdLine->SetExecutableNameL(_L("calendar.exe"));
       
   461 
       
   462         // Set the command line parameters
       
   463         cmdLine->SetTailEndL(*iLaunchParams);
       
   464 
       
   465         // Connect to the application architecture server
       
   466         RApaLsSession appArcSession;
       
   467         CleanupClosePushL(appArcSession);
       
   468         TInt error = appArcSession.Connect();
       
   469         User::LeaveIfError( error != KErrNone );
       
   470 
       
   471         // Start the app (standard command line launch)
       
   472         appArcSession.StartApp(*cmdLine);
       
   473 
       
   474         // Clean up
       
   475         CleanupStack::PopAndDestroy(&appArcSession);
       
   476         CleanupStack::PopAndDestroy(cmdLine);
       
   477         }
       
   478     }
       
   479 
       
   480 /**
       
   481 * AddFlagParamL
       
   482 * Adds a parameter to the unicode launch string
       
   483 * @param aFlag Parameter to add
       
   484 */
       
   485 void CCalenLauncherImpl::AddFlagParamL( TInt aFlag )
       
   486     {
       
   487     TBuf<10> flagBuf;
       
   488     flagBuf.Format( KFlagFormat, aFlag );
       
   489     AddLaunchParamL( flagBuf );
       
   490     }
       
   491 
       
   492 // End of File