meetingrequest/mrbcplugin/bcmrevent/src/cmrbcpluginnewcaleventcommand.cpp
branchRCL_3
changeset 12 4ce476e64c59
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
       
     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:  Implementation for new event commands
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cmrbcpluginnewcaleventcommand.h"
       
    20 #include "tesmrscenariodata.h"
       
    21 #include "cesmrviewerctrl.h"
       
    22 #include "esmrcommands.h"
       
    23 #include "tmroutputparams.h"
       
    24 #include "esmrconfig.hrh"
       
    25 
       
    26 #include <ct/rcpointerarray.h>
       
    27 #include <eikenv.h>
       
    28 #include <avkon.hrh>
       
    29 #include <calentry.h>
       
    30 #include <eikappui.h>
       
    31 #include <eikcmobs.h>
       
    32 #include <magnentryui.h>
       
    33 #include <calenservices.h>
       
    34 #include <aknglobalnote.h>
       
    35 #include <caleninterimutils2.h>
       
    36 #include <calencommandhandler.h>
       
    37 #include <bccaleventpolicies.rsg>
       
    38 #include <data_caging_path_literals.hrh>
       
    39 
       
    40 #include "emailtrace.h"
       
    41 
       
    42 /// Unnamed namespace for local definitions
       
    43 namespace {
       
    44 
       
    45 /**
       
    46  * Constant for default duration in minutes
       
    47  */
       
    48 const TInt KDefaultDurationInMinutes( 60 );
       
    49 
       
    50 } // namespace
       
    51 
       
    52 // ======== MEMBER FUNCTIONS ========
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CMRPluginNewCalEntryCommand::CMRPluginNewCalEntryCommand
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CMRPluginNewCalEntryCommand::CMRPluginNewCalEntryCommand(
       
    59         MCalenServices& aServices,
       
    60         CCalEntry::TType aEntryType )
       
    61     : iServices( aServices ),
       
    62       iEntryType( aEntryType )
       
    63     {
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CMRPluginNewCalEntryCommand::~CMRPluginNewCalEntryCommand
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CMRPluginNewCalEntryCommand::~CMRPluginNewCalEntryCommand()
       
    71     {
       
    72     delete iCalEntry;
       
    73     delete iViewer;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CMRPluginNewCalEntryCommand::NewL
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CMRPluginNewCalEntryCommand* CMRPluginNewCalEntryCommand::NewL(
       
    81         MCalenServices& aServices,
       
    82         CCalEntry::TType aEntryType )
       
    83     {
       
    84     FUNC_LOG;
       
    85 
       
    86     CMRPluginNewCalEntryCommand* self = CMRPluginNewCalEntryCommand::NewLC(
       
    87             aServices,
       
    88             aEntryType );
       
    89     CleanupStack::Pop( self );
       
    90     return self;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CMRPluginNewCalEntryCommand::NewLC
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 CMRPluginNewCalEntryCommand* CMRPluginNewCalEntryCommand::NewLC(
       
    98         MCalenServices& aServices,
       
    99         CCalEntry::TType aEntryType )
       
   100     {
       
   101     FUNC_LOG;
       
   102 
       
   103     CMRPluginNewCalEntryCommand* self =
       
   104             new(ELeave) CMRPluginNewCalEntryCommand(
       
   105                     aServices,
       
   106                     aEntryType );
       
   107     CleanupStack::PushL(self);
       
   108     self->ConstructL();
       
   109 
       
   110     return self;
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CMRPluginNewCalEntryCommand::ConstructL
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CMRPluginNewCalEntryCommand::ConstructL()
       
   118     {
       
   119     FUNC_LOG;
       
   120     // No implementation yet
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CMRPluginNewCalEntryCommand::ExecuteCommandL
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 void CMRPluginNewCalEntryCommand::ExecuteCommandL(
       
   128         const TCalenCommand& aCommand )
       
   129     {
       
   130     FUNC_LOG;
       
   131 
       
   132     CreateEntryL( aCommand );
       
   133     CreateAndExecuteViewL( aCommand );
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CMRPluginNewCalEntryCommand::ProcessCommandL
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CMRPluginNewCalEntryCommand::ProcessCommandL(
       
   141         TInt aCommandId )
       
   142     {
       
   143     FUNC_LOG;
       
   144     User::LeaveIfError( ProcessCommandWithResultL(aCommandId) );
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CMRPluginNewCalEntryCommand::ProcessCommandWithResultL
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 TInt CMRPluginNewCalEntryCommand::ProcessCommandWithResultL(
       
   152         TInt /*aCommandId*/ )
       
   153     {
       
   154     FUNC_LOG;
       
   155     ASSERT( EFalse );
       
   156 
       
   157     return KErrNotSupported;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CMRPluginNewCalEntryCommand::CreateAndExecuteViewL
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CMRPluginNewCalEntryCommand::CreateAndExecuteViewL(
       
   165         const TCalenCommand& aCommand )
       
   166     {
       
   167     FUNC_LOG;
       
   168 
       
   169     const TUid KCalendarUid = { 0x10005901 };
       
   170 
       
   171     // Constructing input parameters
       
   172     INFO( "Constructing input parameters" );
       
   173     MAgnEntryUi::TAgnEntryUiInParams inParams(
       
   174             KCalendarUid,
       
   175             iServices.SessionL(),
       
   176             MAgnEntryUi::ECreateNewEntry );
       
   177 
       
   178     // Set time for input parameters
       
   179     INFO( "Set time for input parameters" );
       
   180     TCalTime startTime = iCalEntry->StartTimeL();
       
   181     TCalTime::TTimeMode timemode = startTime.TimeMode();
       
   182     if (timemode == TCalTime::EFloating )
       
   183         {
       
   184         inParams.iInstanceDate.SetTimeLocalFloatingL (
       
   185               startTime.TimeLocalL() );
       
   186         }
       
   187     else
       
   188         {
       
   189         inParams.iInstanceDate.SetTimeUtcL (
       
   190                 startTime.TimeUtcL() );
       
   191         }
       
   192     inParams.iMsgSession = NULL;
       
   193 
       
   194     // Output parameters
       
   195     MAgnEntryUi::TAgnEntryUiOutParams outParams;
       
   196     TMROutputParams outputParams;
       
   197     outParams.iSpare = reinterpret_cast< TInt >( &outputParams );
       
   198 
       
   199     // Launch Entry UI
       
   200     INFO( "Launch Entry UI" );
       
   201     RCPointerArray<CCalEntry> entries;
       
   202     CleanupClosePushL(entries);
       
   203     entries.AppendL(iCalEntry);
       
   204 
       
   205     CCalenInterimUtils2& utils = iServices.InterimUtilsL();
       
   206 
       
   207     iViewer = CESMRViewerController::NewL(
       
   208             KNullDesC8(),
       
   209             entries,
       
   210             inParams,
       
   211             outParams,
       
   212             *this );
       
   213 
       
   214     iViewer->ExecuteL();
       
   215 
       
   216     TCalenNotification notification( ECalenNotifyEntryClosed );
       
   217 
       
   218     if ( MAgnEntryUi::ENoAction != outParams.iAction )
       
   219         {
       
   220         // Update context and issue notification before confirmation dialog
       
   221         // to avoid delay of updating title pane
       
   222         MCalenContext& context = iServices.Context();
       
   223         aCommand.GetContextL( context );
       
   224 
       
   225         // Update context and issue notification before confirmation dialog
       
   226         // to avoid delay of updating title pane
       
   227         TCalenInstanceId id = TCalenInstanceId::CreateL(
       
   228                 *iCalEntry,
       
   229                 outParams.iNewInstanceDate );
       
   230 
       
   231         context.SetInstanceIdL( id, context.ViewId() );
       
   232         notification = ECalenNotifyEntrySaved;
       
   233         }
       
   234     else
       
   235         {
       
   236         TMROutputParams* params =
       
   237             ( TMROutputParams* )( outParams.iSpare );
       
   238 
       
   239         // If viewer options menu exit is desired
       
   240         if( params->iCommand == EMRDialogOptionsMenuExit )
       
   241             {
       
   242             notification = ECalenNotifyRealExit;
       
   243             }
       
   244         }
       
   245 
       
   246     iServices.IssueNotificationL(  notification );
       
   247     IssueCommandL( outParams );
       
   248     CleanupStack::PopAndDestroy( &entries );
       
   249     iCalEntry = NULL;
       
   250 
       
   251     delete iViewer;
       
   252     iViewer = NULL;
       
   253     }
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // CMRPluginNewCalEntryCommand::CreateEntryL
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 void CMRPluginNewCalEntryCommand::CreateEntryL(
       
   260         const TCalenCommand& aCommand )
       
   261     {
       
   262     FUNC_LOG;
       
   263 
       
   264     if ( iCalEntry )
       
   265         {
       
   266         delete iCalEntry;
       
   267         iCalEntry = NULL;
       
   268         }
       
   269     CCalenInterimUtils2& utils = iServices.InterimUtilsL();
       
   270     // Create unique ID.
       
   271     HBufC8* guid = utils.GlobalUidL();
       
   272     CleanupStack::PushL(guid);
       
   273     iCalEntry = CCalEntry::NewL(
       
   274             iEntryType,
       
   275             guid,
       
   276             CCalEntry::EMethodNone,
       
   277             0 );
       
   278 
       
   279     // Ownership transferred
       
   280     CleanupStack::Pop( guid );
       
   281 
       
   282     MCalenContext& context = iServices.Context();
       
   283     aCommand.GetContextL( context );
       
   284 
       
   285     TCalTime startTime, stopTime;
       
   286 
       
   287 #ifdef RD_USE_PS2_APIS
       
   288     // Business Calendar day view with visual selection
       
   289     TTime start( 0 );
       
   290     TTime end( 0 );
       
   291 
       
   292     context.GetStartAndEndTimeForNewInstance( start, end );
       
   293 
       
   294 const TTime zeroTime(0);
       
   295     if ( start != zeroTime && end != zeroTime &&
       
   296             ECalenNewMeetingTimeSpan == aCommand.Command() )
       
   297         {
       
   298         startTime.SetTimeLocalL( start );
       
   299         stopTime.SetTimeLocalL( end );
       
   300 
       
   301         //clean the start/end time in Context
       
   302         context.SetStartAndEndTimeForNewInstance( zeroTime, zeroTime );
       
   303         }
       
   304     else
       
   305 #endif // RD_USE_PS2_APIS
       
   306         {
       
   307         startTime = context.FocusDateAndTimeL();
       
   308 
       
   309         TTimeIntervalMinutes interval = KDefaultDurationInMinutes;
       
   310 
       
   311         stopTime.SetTimeLocalL(
       
   312                startTime.TimeLocalL() +
       
   313                interval );
       
   314         }
       
   315 
       
   316     iCalEntry->SetStartAndEndTimeL( startTime, stopTime );
       
   317 
       
   318     // Set default priority for the entry also
       
   319     if ( CCalEntry::ETodo == iCalEntry->EntryTypeL() )
       
   320         {
       
   321         iCalEntry->SetPriorityL( EFSCalenTodoPriorityNormal );
       
   322         }
       
   323     else
       
   324         {
       
   325         iCalEntry->SetPriorityL( EFSCalenMRPriorityNormal );
       
   326         }
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // CMRPluginNewCalEntryCommand::IssueCommandL
       
   331 // Issue command for calendar to handle
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 void CMRPluginNewCalEntryCommand::IssueCommandL(
       
   335         MAgnEntryUi::TAgnEntryUiOutParams aOutParams )
       
   336     {
       
   337     FUNC_LOG;
       
   338     TInt command( KErrNotFound );
       
   339 
       
   340     TMROutputParams* params = ( TMROutputParams* )( aOutParams.iSpare );
       
   341 
       
   342     switch ( params->iCommand )
       
   343         {
       
   344         case EMRDialogOptionsMenuExit:
       
   345             {
       
   346             // Calendar app is not supposed to issue EAknCmdExit command.
       
   347             // It is always soft exit and faster app FW takes the call, and
       
   348             // decides the correct action.
       
   349             //
       
   350             // This is why we use command EAknSoftkeyExit, to exit
       
   351             // application from editor options menu.
       
   352 
       
   353             command = EAknSoftkeyExit;
       
   354             }
       
   355             break;
       
   356 
       
   357         default:
       
   358             break;
       
   359         }
       
   360 
       
   361     // Issue command for RECAL
       
   362     if( command != KErrNotFound )
       
   363         {
       
   364         iServices.IssueCommandL( command );
       
   365         }
       
   366     }
       
   367