meetingrequest/mrbcplugin/bcmrevent/src/cmrbcpluginopenmrviewercmd.cpp
branchRCL_3
changeset 16 4ce476e64c59
child 24 b5fbb9b25d57
equal deleted inserted replaced
13:0396474f30f5 16:4ce476e64c59
       
     1 /*
       
     2  * Copyright (c) 2008 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:  MBUtils ECOM implementation
       
    15  *
       
    16  */
       
    17 
       
    18 #include "cmrbcpluginopenmrviewercmd.h"
       
    19 #include "cesmrviewerctrl.h"
       
    20 #include "esmrcommands.h"
       
    21 #include "tmroutputparams.h"
       
    22 #include "esmrhelper.h"
       
    23 #include "esmrconfig.hrh"
       
    24 
       
    25 #include <calenservices.h>
       
    26 #include <calencommands.hrh>
       
    27 #include <caleninterimutils2.h>
       
    28 #include <cmrviewers.h>
       
    29 #include <calentry.h>
       
    30 #include <caluser.h>
       
    31 #include <cmrmailboxutils.h>
       
    32 #include <ct/rcpointerarray.h>
       
    33 #include <aknlists.h>
       
    34 #include <aknpopup.h>
       
    35 #include <utf.h>
       
    36 #include <calentryview.h>
       
    37 #include <calinstanceview.h>
       
    38 
       
    39 #include "emailtrace.h"
       
    40 
       
    41 
       
    42 namespace {
       
    43 
       
    44 /**
       
    45  * Literal for BC viewer / editor
       
    46  */
       
    47 _LIT8( KBCViewer, "[2001F406]" );
       
    48 
       
    49 
       
    50 #ifdef _DEBUG
       
    51 
       
    52 /**
       
    53  * Panic literal
       
    54  */
       
    55 _LIT( KMRBCPluginOpenMRViewerCmd, "MRBCPluginOpenMRViewerCmd" );
       
    56 
       
    57 /**
       
    58  * Panic codes
       
    59  */
       
    60 enum TMRBCPluginOpenMRViewerCmdPanic
       
    61     {
       
    62     EInvalidCommand // Invalid command
       
    63     };
       
    64 
       
    65 void Panic( TMRBCPluginOpenMRViewerCmdPanic aPanic )
       
    66     {
       
    67     User::Panic( KMRBCPluginOpenMRViewerCmd, aPanic );
       
    68     }
       
    69 
       
    70 #endif // _DEBUG
       
    71 
       
    72 template <class T>
       
    73 class CleanupResetAndDestroy
       
    74     {
       
    75     public:
       
    76         inline static void PushL( T& aRef )
       
    77             {
       
    78             CleanupStack::PushL( TCleanupItem( &ResetAndDestroy, &aRef ) );
       
    79             }
       
    80 
       
    81     private:
       
    82         inline static void ResetAndDestroy( TAny* aPtr )
       
    83             {
       
    84             static_cast< T*>( aPtr )->ResetAndDestroy();
       
    85             }
       
    86     };
       
    87 
       
    88 template <class T>
       
    89 inline void CleanupResetAndDestroyPushL( T& aRef )
       
    90     {
       
    91     CleanupResetAndDestroy<T>::PushL( aRef );
       
    92     }
       
    93 }
       
    94 
       
    95 //TODO:- displace after nokia provide RIGHT CalenActionUiUtils::FindPossibleInstance
       
    96 CCalInstance* FindPossibleInstanceL(
       
    97         const TCalenInstanceId& aId, CCalInstanceView& aInstanceView )
       
    98         {
       
    99         FUNC_LOG;
       
   100 
       
   101         RPointerArray<CCalInstance> instances;
       
   102         CleanupResetAndDestroyPushL( instances );
       
   103 
       
   104         TCalTime moment;
       
   105         moment.SetTimeLocalL( aId.iInstanceTime );
       
   106         CalCommon::TCalTimeRange range( moment, moment );
       
   107         aInstanceView.FindInstanceL( instances, CalCommon::EIncludeAll, range );
       
   108 
       
   109         CCalInstance* result = NULL;
       
   110 
       
   111         // For instances finishing the next day (now possible with unified DateTime editor),
       
   112         // we have to do our best to match the instance time exactly - otherwise we could
       
   113         // match the LocalUid to the incorrect instance in a series.
       
   114         for ( TInt i=0; i < instances.Count() && !result; ++i )
       
   115             {
       
   116             if( instances[i]->Entry().LocalUidL() == aId.iEntryLocalUid )
       
   117                 {
       
   118                 // Check the instance time matches.
       
   119                 if( instances[i]->StartTimeL().TimeLocalL() == aId.iInstanceTime )
       
   120                     {
       
   121                     result = instances[i];
       
   122                     instances.Remove(i);
       
   123                     }
       
   124                 }
       
   125             }
       
   126 
       
   127         if( !result )
       
   128             {
       
   129             // Couldn't match the instance time exactly - just use the instance
       
   130             // with the same LocalUid as the one we're looking for.
       
   131             for ( TInt i=0; i < instances.Count() && !result; ++i )
       
   132                 {
       
   133                 if( instances[i]->Entry().LocalUidL() == aId.iEntryLocalUid )
       
   134                     {
       
   135                     result = instances[i];
       
   136                     instances.Remove(i);
       
   137                     }
       
   138                 }
       
   139             }
       
   140 
       
   141         CleanupStack::PopAndDestroy( &instances );
       
   142         return result;
       
   143         }
       
   144 
       
   145 
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CMRBCPluginOpenMRViewerCmd::CMRBCPluginOpenMRViewerCmd
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 CMRBCPluginOpenMRViewerCmd::CMRBCPluginOpenMRViewerCmd(
       
   152         MCalenServices& aServices )
       
   153 :   iServices( aServices )
       
   154             {
       
   155             FUNC_LOG;
       
   156             }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CMRBCPluginOpenMRViewerCmd::~CMRBCPluginOpenMRViewerCmd
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 CMRBCPluginOpenMRViewerCmd::~CMRBCPluginOpenMRViewerCmd()
       
   163     {
       
   164     FUNC_LOG;
       
   165     delete iEntry;
       
   166     delete iEditor;
       
   167     }
       
   168 
       
   169         // -----------------------------------------------------------------------------
       
   170 // CMRBCPluginOpenMRViewerCmd::NewL
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 CMRBCPluginOpenMRViewerCmd* CMRBCPluginOpenMRViewerCmd::NewL(
       
   174         MCalenServices& aServices)
       
   175     {
       
   176     FUNC_LOG;
       
   177 
       
   178     CMRBCPluginOpenMRViewerCmd* self = new (ELeave) CMRBCPluginOpenMRViewerCmd(
       
   179             aServices);
       
   180     CleanupStack::PushL(self);
       
   181     self->ConstructL();
       
   182     CleanupStack::Pop(self);
       
   183     return self;
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CMRBCPluginOpenMRViewerCmd::ConstructL
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CMRBCPluginOpenMRViewerCmd::ConstructL()
       
   191     {
       
   192     FUNC_LOG;
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CMRBCPluginOpenMRViewerCmd::ExecuteCommandL
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CMRBCPluginOpenMRViewerCmd::ExecuteCommandL(
       
   200         const TCalenCommand& aCommand )
       
   201     {
       
   202     FUNC_LOG;
       
   203 
       
   204     __ASSERT_DEBUG(
       
   205             aCommand.Command() == ECalenEventView,
       
   206             Panic( EInvalidCommand ) );
       
   207 
       
   208     if (aCommand.Command() != ECalenEventView)
       
   209         {
       
   210         ERROR( KErrArgument, "Invalid command" );
       
   211         User::Leave(KErrArgument);
       
   212         }
       
   213 
       
   214     GetEntryL(aCommand);
       
   215     LaunchMRViewerL( aCommand );
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // CMRBCPluginOpenMRViewerCmd::ProcessCommandL
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 void CMRBCPluginOpenMRViewerCmd::ProcessCommandL( TInt /* aCommandId */ )
       
   223     {
       
   224     FUNC_LOG;
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // CMRBCPluginOpenMRViewerCmd::ProcessCommandWithResultL
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 TInt CMRBCPluginOpenMRViewerCmd::ProcessCommandWithResultL(TInt /*aCommandId*/)
       
   232     {
       
   233     FUNC_LOG;
       
   234     return KErrNone;
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CMRBCPluginOpenMRViewerCmd::LaunchMRViewerL
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CMRBCPluginOpenMRViewerCmd::LaunchMRViewerL(
       
   242         const TCalenCommand& aCommand )
       
   243     {
       
   244     FUNC_LOG;
       
   245 
       
   246     const TUid KCalendarUid =
       
   247         {
       
   248         0x10005901
       
   249         };
       
   250     // Constructing input parameters
       
   251     INFO( "Constructing input parameters" );
       
   252     MAgnEntryUi::TAgnEntryUiInParams inParams(
       
   253             KCalendarUid,
       
   254             iServices.SessionL(),
       
   255             MAgnEntryUi::EViewEntry);
       
   256 
       
   257     // Set time for input parameters
       
   258     INFO( "Set time for input parameters" );
       
   259     TCalTime startTime = iEntry->StartTimeL();
       
   260     TCalTime::TTimeMode timemode = startTime.TimeMode();
       
   261     if (timemode == TCalTime::EFloating)
       
   262         {
       
   263         inParams.iInstanceDate.SetTimeLocalFloatingL(startTime.TimeLocalL());
       
   264         }
       
   265     else
       
   266         {
       
   267         RArray<TInt> colIds;
       
   268         CleanupClosePushL( colIds );
       
   269         TInt colId = iServices.Context().InstanceId().iColId;
       
   270         colIds.AppendL( colId );
       
   271         CCalInstance* instance = FindPossibleInstanceL(
       
   272                 iServices.Context().InstanceId(), *(iServices.InstanceViewL(colIds)));
       
   273         CleanupStack::PushL( instance );
       
   274         inParams.iInstanceDate.SetTimeUtcL(instance->Time().TimeUtcL());
       
   275         CleanupStack::PopAndDestroy( instance );
       
   276         CleanupStack::PopAndDestroy( &colIds );
       
   277         }
       
   278 
       
   279     inParams.iMsgSession = NULL;
       
   280 
       
   281     // Output parameters
       
   282     MAgnEntryUi::TAgnEntryUiOutParams outParams;
       
   283     TMROutputParams outputParams;
       
   284     outParams.iSpare = reinterpret_cast< TInt >( &outputParams );
       
   285 
       
   286     // Launch Entry UI
       
   287     INFO( "Launch Entry UI" );
       
   288     RPointerArray<CCalEntry> entries;
       
   289     CleanupClosePushL( entries );
       
   290     entries.AppendL( iEntry ); // Ownership not transferred.
       
   291 
       
   292     iEditor = CESMRViewerController::NewL(
       
   293             KBCViewer(),
       
   294             entries,
       
   295             inParams,
       
   296             outParams,
       
   297             *this );
       
   298 
       
   299     TRAPD( err, iEditor->ExecuteL() );
       
   300     if( KErrArgument == err )
       
   301         {
       
   302         delete iEditor;
       
   303         iEditor = NULL;
       
   304 
       
   305         // ES MR VIEWER controller was unable to show the
       
   306         // passed meeting request. Let's launch normal meeting viewer
       
   307         // for showing the entry
       
   308         CCalEntry* meetingEntry = ESMRHelper::CopyEntryLC(
       
   309                 *entries[0],
       
   310                 entries[0]->MethodL(),
       
   311                 ESMRHelper::ECopyFull,
       
   312                 EESMREventTypeAppt );
       
   313 
       
   314 #ifdef RD_USE_PS2_APIS
       
   315         meetingEntry->ClearMRSpecificDataL();
       
   316 #endif // RD_USE_PS2_APIS
       
   317 
       
   318         // Delete old entry and reset entry array
       
   319         delete iEntry;
       
   320         iEntry = NULL;
       
   321         entries.Reset();
       
   322 
       
   323         // Append entry to array.
       
   324         entries.AppendL( meetingEntry );
       
   325 
       
   326         // Take ownership of meeting entry
       
   327         iEntry = meetingEntry;
       
   328         CleanupStack::Pop( meetingEntry );
       
   329 
       
   330         iEditor = CESMRViewerController::NewL(
       
   331                 KBCViewer(),
       
   332                 entries,
       
   333                 inParams,
       
   334                 outParams,
       
   335                 *this );
       
   336 
       
   337         iEditor->ExecuteL();
       
   338         }
       
   339 
       
   340     // Issue notification if required.
       
   341     IssueNotifyL( aCommand, outParams );
       
   342 
       
   343     // Issue command if required.
       
   344     IssueCommandL( outParams );
       
   345 
       
   346     // Close and reset entry array
       
   347     CleanupStack::PopAndDestroy( &entries );
       
   348     }
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // CMRBCPluginOpenMRViewerCmd::GetEntryL
       
   352 // ---------------------------------------------------------------------------
       
   353 //
       
   354 void CMRBCPluginOpenMRViewerCmd::GetEntryL(const TCalenCommand& /*aCommand*/ )
       
   355     {
       
   356     FUNC_LOG;
       
   357 
       
   358     if (iEntry)
       
   359         {
       
   360         delete iEntry;
       
   361         iEntry = NULL;
       
   362         }
       
   363 
       
   364     MCalenContext& context = iServices.Context();
       
   365     TCalLocalUid instanceId = context.InstanceId().iEntryLocalUid;
       
   366     TInt colId = context.InstanceId().iColId;
       
   367 
       
   368     iEntry = iServices.EntryViewL(colId)->FetchL(instanceId);
       
   369     }
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // CMRBCPluginOpenMRViewerCmd::IssueNotifyL
       
   373 // Handle notify message
       
   374 // ---------------------------------------------------------------------------
       
   375 //
       
   376 void CMRBCPluginOpenMRViewerCmd::IssueNotifyL(
       
   377         const TCalenCommand& aCommand,
       
   378         MAgnEntryUi::TAgnEntryUiOutParams aOutParams )
       
   379     {
       
   380     FUNC_LOG;
       
   381 
       
   382     TCalenNotification notification = ECalenNotifyEntryClosed;
       
   383     switch ( aOutParams.iAction )
       
   384         {
       
   385         case MAgnEntryUi::EMeetingDeleted:
       
   386         case MAgnEntryUi::EInstanceDeleted:
       
   387             {
       
   388             notification = ECalenNotifyEntryDeleted;
       
   389             }
       
   390             break;
       
   391 
       
   392         case MAgnEntryUi::EMeetingSaved:
       
   393             {
       
   394             notification = ECalenNotifyEntrySaved;
       
   395             }
       
   396             break;
       
   397 
       
   398         case MAgnEntryUi::EInstanceRescheduled:
       
   399             {
       
   400             notification = ECalenNotifyEntrySaved;
       
   401             }
       
   402             break;
       
   403 
       
   404         case MAgnEntryUi::ENoAction:
       
   405             {
       
   406             TMROutputParams* params =
       
   407                 ( TMROutputParams* )( aOutParams.iSpare );
       
   408 
       
   409             // If viewer options menu exit is desired
       
   410             if( params->iCommand == EMRDialogOptionsMenuExit )
       
   411                 {
       
   412                 notification = ECalenNotifyRealExit;
       
   413                 }
       
   414             }
       
   415             break;
       
   416 
       
   417         default:
       
   418             break;
       
   419         }
       
   420 
       
   421     if ( MAgnEntryUi::ENoAction != aOutParams.iAction )
       
   422         {
       
   423         // Update context and issue notification before confirmation dialog
       
   424         // to avoid delay of updating title pane
       
   425         MCalenContext& context = iServices.Context();
       
   426         aCommand.GetContextL( context );
       
   427 
       
   428         // Update context and issue notification before confirmation dialog
       
   429         // to avoid delay of updating title pane
       
   430         TCalenInstanceId id = TCalenInstanceId::CreateL(
       
   431                 *iEntry,
       
   432                 aOutParams.iNewInstanceDate );
       
   433 
       
   434         context.SetInstanceIdL( id, context.ViewId() );
       
   435         }
       
   436 
       
   437     // Notify RECAL
       
   438     iServices.IssueNotificationL( notification );
       
   439     }
       
   440 
       
   441 // ---------------------------------------------------------------------------
       
   442 // CMRBCPluginOpenMRViewerCmd::IssueCommandL
       
   443 // Issue command for calendar to handle
       
   444 // ---------------------------------------------------------------------------
       
   445 //
       
   446 void CMRBCPluginOpenMRViewerCmd::IssueCommandL(
       
   447         MAgnEntryUi::TAgnEntryUiOutParams aOutParams )
       
   448     {
       
   449     FUNC_LOG;
       
   450     TInt command( KErrNotFound );
       
   451 
       
   452     TMROutputParams* params = ( TMROutputParams* )( aOutParams.iSpare );
       
   453 
       
   454     switch ( params->iCommand )
       
   455         {
       
   456         case EMRDialogOptionsMenuExit:
       
   457             {
       
   458             // Calendar app is not supposed to issue EAknCmdExit command.
       
   459             // It is always soft exit and faster app FW takes the call, and
       
   460             // decides the correct action.
       
   461             //
       
   462             // This is why we use command EAknSoftkeyExit, to exit
       
   463             // application from viewer options menu.
       
   464 
       
   465             command = EAknSoftkeyExit;
       
   466             }
       
   467             break;
       
   468 
       
   469         default:
       
   470             break;
       
   471         }
       
   472 
       
   473     // Issue command for RECAL
       
   474     if( command != KErrNotFound )
       
   475         {
       
   476         iServices.IssueCommandL( command );
       
   477         }
       
   478     }
       
   479 
       
   480 // EOF