meetingrequest/mrgui/src/cesmreditordialog.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2009 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:  ESMR editor dialog
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cesmreditordialog.h"
       
    19 #include "esmrgui.hrh"
       
    20 #include "cesmrview.h"
       
    21 #include "mesmrmeetingrequestentry.h"
       
    22 #include "cesmrconfirmationquery.h"
       
    23 #include "cesmrlistquery.h"
       
    24 #include "cesmreditorfieldstorage.h"
       
    25 #include "cesmrmixedfieldstorage.h"
       
    26 #include "cesmrsendui.h"
       
    27 #include "cesmrfield.h"
       
    28 #include "cesmrfieldbuilderinterface.h"
       
    29 #include "mesmrresponseobserver.h"
       
    30 #include "cesmrglobalnote.h"
       
    31 #include "cesmrtitlepanehandler.h"
       
    32 #include "esmrinternaluid.h"
       
    33 #include "cesmrlocationpluginhandler.h"
       
    34 #include "cesmraddressinfohandler.h"
       
    35 #include "cesmrfeaturesettings.h"
       
    36 #include "mesmrfieldevent.h"
       
    37 #include "esmrconfig.hrh"
       
    38 #include "esmrdef.h"
       
    39 #include "esmrcommands.h"
       
    40 #include "cesmrpolicy.h"
       
    41 #include "cmrtoolbar.h"
       
    42 #include "mmrpolicyprovider.h"
       
    43 #include "mmrinfoprovider.h"
       
    44 #include "cesmrcaldbmgr.h"
       
    45 #include "cmrfocusstrategyeditor.h"
       
    46 #include "cesmrfieldbuilderinterface.h"
       
    47 
       
    48 #include <esmrgui.rsg>
       
    49 #include <apgcli.h>
       
    50 #include <eikenv.h>
       
    51 #include <eikappui.h>
       
    52 #include <avkon.hrh>
       
    53 #include <eikmenup.h>
       
    54 #include <MAgnEntryUi.h>
       
    55 #include <layoutmetadata.cdl.h>
       
    56 #include <AknDef.h>
       
    57 #include <AknUtils.h>
       
    58 #include <AknIndicatorContainer.h>
       
    59 #include <aknenv.h>
       
    60 #include <aknEditStateIndicator.h>
       
    61 #include <aknnotewrappers.h>
       
    62 #include <DocumentHandler.h>
       
    63 #include <NpdApi.h>
       
    64 #include <calentry.h>
       
    65 #include <calattachment.h>
       
    66 #include <CalenInterimUtils2.h>
       
    67 #include <akntitle.h>
       
    68 #include <StringLoader.h>
       
    69 
       
    70 // DEBUG
       
    71 #include "emailtrace.h"
       
    72 
       
    73 // <cmail> Removed profiling. </cmail>
       
    74 
       
    75 // Unnamed namespace for local definitions
       
    76 namespace { // codescanner::namespace
       
    77 
       
    78 #ifdef _DEBUG
       
    79     /** Enumeration for panic codes */
       
    80     enum TESMREditDlgPanicCode
       
    81         {
       
    82         // Recurrence series query result error
       
    83         EESMREditDlgInvalidSeriesResult = 0,
       
    84         EESMREditDlgDialogLeave
       
    85         };
       
    86 
       
    87     void Panic( TESMREditDlgPanicCode aPanic )
       
    88         {
       
    89         _LIT( KESMREditDlgPanicTxt, "ESMREDITORDIALOG" );
       
    90         User::Panic ( KESMREditDlgPanicTxt, aPanic );
       
    91         }
       
    92 #endif
       
    93 
       
    94 /**
       
    95  * Sets recurrence modification rule to entry. Rule is queried
       
    96  * from the user. Invalid result will cause panic.
       
    97  * @param aEntry Reference to meeting request.
       
    98  */
       
    99 void SetRecurrenceModRuleL(
       
   100         MESMRCalEntry& aEntry,
       
   101         CESMRListQuery::TESMRListQueryType aQueryType )
       
   102     {
       
   103     if ( aEntry.IsRecurrentEventL() &&
       
   104          aEntry.IsStoredL() )
       
   105         {
       
   106         TInt result =
       
   107             CESMRListQuery::ExecuteL( aQueryType );
       
   108 
       
   109         if( KErrCancel == result )
       
   110             {
       
   111             // User has cancelled selecting opening the instance
       
   112             User::Leave( KErrCancel );
       
   113             }
       
   114 
       
   115         TESMRThisOccurenceOrSeriesQuery recurrenceModRule =
       
   116             static_cast<TESMRThisOccurenceOrSeriesQuery>( result );
       
   117 
       
   118         switch( recurrenceModRule )
       
   119             {
       
   120             case EESMRThisOccurence:
       
   121                 {
       
   122                 aEntry.SetModifyingRuleL(
       
   123                         MESMRMeetingRequestEntry::EESMRThisOnly );
       
   124                 }
       
   125                 break;
       
   126             case EESMRSeries:
       
   127                 {
       
   128                 aEntry.SetModifyingRuleL(
       
   129                         MESMRMeetingRequestEntry::EESMRAllInSeries );
       
   130                 }
       
   131                 break;
       
   132             default:
       
   133                 __ASSERT_DEBUG( EFalse, Panic(EESMREditDlgInvalidSeriesResult));
       
   134                 break;
       
   135             }
       
   136         }
       
   137     else
       
   138         {
       
   139         aEntry.SetModifyingRuleL(
       
   140                 MESMRMeetingRequestEntry::EESMRThisOnly );
       
   141         }
       
   142     }
       
   143 
       
   144 /**
       
   145  * Creates correct type of storage for editing calendar entry.
       
   146  * @param aCommandObserver Reference to command observer
       
   147  * @param aEntry Reference to ES calendar entry
       
   148  * @param aPolicyProvider. Pointer to used policy.
       
   149  * @param aResponseObserver Pointer to response observer.
       
   150  */
       
   151 CESMRFieldStorage* CreateCorrectStorageLC(
       
   152         MESMRFieldEventObserver& aEventObserver,
       
   153         MESMRCalEntry& aEntry,
       
   154         const CESMRPolicy& aPolicy,
       
   155         MESMRResponseObserver* aResponseObserver )
       
   156     {
       
   157     CESMRFieldStorage* storage = NULL;
       
   158 
       
   159     MESMRCalEntry::TESMRRecurrenceModifyingRule rule(
       
   160             aEntry.RecurrenceModRule() );
       
   161 
       
   162     TESMRViewMode mode( aPolicy.ViewMode() );
       
   163 
       
   164     if ( ( aEntry.IsRecurrentEventL() &&
       
   165            rule == MESMRCalEntry::EESMRThisOnly ) ||
       
   166            mode == EESMRForwardMR )
       
   167         {
       
   168         // instance editing or forwarding entry
       
   169         storage = CESMRMixedFieldStorage::NewL(
       
   170                 aEventObserver,
       
   171                 aPolicy,
       
   172                 aResponseObserver,
       
   173                 aEntry );
       
   174         CleanupStack::PushL ( storage );
       
   175         }
       
   176     else if ( aEntry.IsRecurrentEventL() &&
       
   177               rule == MESMRCalEntry::EESMRAllInSeries  )
       
   178         {
       
   179         // Editing all in series
       
   180         storage = CESMRMixedFieldStorage::NewL(
       
   181                 aEventObserver,
       
   182                 aPolicy,
       
   183                 aResponseObserver,
       
   184                 aEntry );
       
   185         CleanupStack::PushL ( storage );
       
   186         }
       
   187     else
       
   188         {
       
   189         storage = CESMREditorFieldStorage::NewL ( aPolicy, aEventObserver );
       
   190         CleanupStack::PushL ( storage );
       
   191         }
       
   192 
       
   193     return storage;
       
   194     }
       
   195 
       
   196 /**
       
   197  * Tests if two datetime objects has same day or not.
       
   198  * @param aLhs Reference to left hand side datetime object.
       
   199  * @param aRhs Reference to right hand side datetime object.
       
   200  */
       
   201 TBool IsSameDay(
       
   202         TDateTime& aLhs,
       
   203         TDateTime& aRhs )
       
   204     {
       
   205     TBool retValue( ETrue );
       
   206 
       
   207     if ( aLhs.Day()     != aRhs.Day() ||
       
   208          aLhs.Month() != aRhs.Month() ||
       
   209          aLhs.Year()  != aRhs.Year() )
       
   210         {
       
   211         retValue = EFalse;
       
   212         }
       
   213 
       
   214     return retValue;
       
   215     }
       
   216 
       
   217 } // namespace
       
   218 
       
   219 // ======== MEMBER FUNCTIONS ========
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CESMREditorDialog::CESMREditorDialog
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 CESMREditorDialog::CESMREditorDialog(
       
   226         MMRInfoProvider& aInfoProvider,
       
   227         MAgnEntryUiCallback& aCallback ) :
       
   228     iInfoProvider( aInfoProvider ),
       
   229     iCallback( aCallback)
       
   230     {
       
   231     FUNC_LOG;
       
   232     // Do nothing
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // CESMREditorDialog::~CESMREditorDialog
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 CESMREditorDialog::~CESMREditorDialog( )
       
   240     {
       
   241     FUNC_LOG;
       
   242 
       
   243     delete iESMRSendUI;
       
   244     if ( iTitlePane )
       
   245         {
       
   246         // Returns the previous title back to titlepane
       
   247         iTitlePane->Rollback();
       
   248         delete iTitlePane;
       
   249         }
       
   250     delete iInterimUtils;
       
   251     delete iLocationPluginHandler;
       
   252     delete iAddressInfoHandler;
       
   253     delete iFeatures;
       
   254     delete iToolbar;
       
   255     delete iFocusStrategy;
       
   256 
       
   257     // iView is deleted by framework because it uses the
       
   258     // custom control mechanism.
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CESMREditorDialog::NewL
       
   263 // ---------------------------------------------------------------------------
       
   264 //
       
   265 EXPORT_C CESMREditorDialog* CESMREditorDialog::NewL(
       
   266         MMRInfoProvider& aInfoProvider,
       
   267         MAgnEntryUiCallback& aCallback )
       
   268     {
       
   269     FUNC_LOG;
       
   270     CESMREditorDialog* self =
       
   271     new (ELeave) CESMREditorDialog( aInfoProvider, aCallback );
       
   272     CleanupStack::PushL( self );
       
   273     self->ConstructL();
       
   274     CleanupStack::Pop( self );
       
   275     return self;
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CESMREditorDialog::ConstructL
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 void CESMREditorDialog::ConstructL()
       
   283     {
       
   284     FUNC_LOG;
       
   285     CAknDialog::ConstructL ( R_MREDITOR_MENUBAR );
       
   286 
       
   287     iESMRSendUI = CESMRSendUI::NewL (EESMRCmdSendAs );
       
   288 
       
   289     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
   290     CESMRFieldStorage* storage = CreateCorrectStorageLC(
       
   291             *this,
       
   292             *entry,
       
   293             iInfoProvider.PolicyProvider().CurrentPolicy(),
       
   294             this );
       
   295 
       
   296     iStartTimeUtc = entry->Entry().StartTimeL().TimeUtcL();
       
   297 
       
   298     //clean previous toolbar if there is, and be sure restore toolbar area to EMainPane
       
   299     iToolbar = CMRToolbar::NewL();
       
   300 
       
   301     TRect clientRect;
       
   302     AknLayoutUtils::LayoutMetricsRect(
       
   303             AknLayoutUtils::EMainPane,
       
   304             clientRect );
       
   305 
       
   306     // Create focus strategy
       
   307     iFocusStrategy = CMRFocusStrategyEditor::NewL( *storage );
       
   308 
       
   309     // storage ownership is transferred to CESMRView
       
   310     iView = CESMRView::NewL( 
       
   311             storage, 
       
   312             *entry, 
       
   313             clientRect, 
       
   314             *iFocusStrategy,
       
   315             *iToolbar );
       
   316     
       
   317     iView->SetViewMode( EESMREditMR );
       
   318     CleanupStack::Pop( storage );
       
   319 
       
   320     // try to find subject field and set title pane observer
       
   321     CESMRField* field = NULL;
       
   322     TInt fieldCount( storage->Count() );
       
   323     for ( TInt i(0); i < fieldCount; ++i )
       
   324         {
       
   325         field = storage->Field( i );
       
   326         TESMREntryFieldId fieldId( field->FieldId() );
       
   327 
       
   328         switch (fieldId)
       
   329             {
       
   330             case EESMRFieldSubject: //Fall through
       
   331             case EESMRFieldOccasion://Fall through
       
   332             case EESMRFieldPriority://Fall through
       
   333             case EESMRFieldDetailedSubject:
       
   334                 {
       
   335                 field->SetTitlePaneObserver( iView );
       
   336                 break;
       
   337                 }
       
   338             default:
       
   339                 break;
       
   340             }
       
   341         }
       
   342 
       
   343     SetTitleL();
       
   344 
       
   345     if(!iInterimUtils)
       
   346         {
       
   347         iInterimUtils = CCalenInterimUtils2::NewL();
       
   348         }
       
   349 
       
   350     iFeatures = CESMRFeatureSettings::NewL();
       
   351 
       
   352     }
       
   353 
       
   354 // ---------------------------------------------------------------------------
       
   355 // CESMREditorDialog::CreateCustomControlL
       
   356 // ---------------------------------------------------------------------------
       
   357 //
       
   358 SEikControlInfo CESMREditorDialog::CreateCustomControlL(
       
   359         TInt aType )
       
   360     {
       
   361     FUNC_LOG;
       
   362     SEikControlInfo controlInfo;
       
   363     controlInfo.iControl = NULL;
       
   364     controlInfo.iFlags = 0;
       
   365     controlInfo.iTrailerTextId = 0;
       
   366 
       
   367     if ( aType == EEsMrEditorType )
       
   368         {
       
   369         controlInfo.iControl = iView;
       
   370         }
       
   371 
       
   372     return controlInfo;
       
   373     }
       
   374 
       
   375 // ---------------------------------------------------------------------------
       
   376 // CESMREditorDialog::OfferKeyEventL
       
   377 // ---------------------------------------------------------------------------
       
   378 //
       
   379 TKeyResponse CESMREditorDialog::OfferKeyEventL(
       
   380         const TKeyEvent& aEvent,
       
   381         TEventCode aType )
       
   382     {
       
   383     FUNC_LOG;
       
   384 
       
   385     TKeyResponse response( EKeyWasNotConsumed);
       
   386     if ( aEvent.iCode != EKeyEscape && !MenuShowing() && aType == EEventKey)
       
   387         {
       
   388         response = iView->OfferKeyEventL ( aEvent, aType );
       
   389         }
       
   390 
       
   391     if ( response == EKeyWasNotConsumed  )
       
   392         {
       
   393         response = CAknDialog::OfferKeyEventL ( aEvent, aType );
       
   394         }
       
   395 
       
   396     return response;
       
   397     }
       
   398 
       
   399 // ---------------------------------------------------------------------------
       
   400 // CESMREditorDialog::OkToExitL
       
   401 // ---------------------------------------------------------------------------
       
   402 //
       
   403 TBool CESMREditorDialog::OkToExitL( TInt aButtonId )
       
   404     {
       
   405     FUNC_LOG;
       
   406     TBool res( EFalse );
       
   407     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
   408     switch ( aButtonId )
       
   409         {
       
   410         case EAknSoftkeyOptions:
       
   411             {
       
   412             // Show options menu
       
   413             CAknDialog::DisplayMenuL();
       
   414             break;
       
   415             }
       
   416         case EAknSoftkeySend:
       
   417         	{
       
   418             if ( MESMRCalEntry::EESMRCalEntryMeetingRequest == entry->Type() )
       
   419                 {
       
   420                 MESMRMeetingRequestEntry* mrEntry =
       
   421                         static_cast<MESMRMeetingRequestEntry*>( 
       
   422                                 iInfoProvider.EntryL() );
       
   423                         	
       
   424                 const CESMRPolicy& policy = Policy();
       
   425                 if ( policy.IsDefaultCommand(EESMRCmdSendMRUpdate ) &&
       
   426                         ( mrEntry->IsSentL() && mrEntry->IsStoredL() ) )
       
   427                     {
       
   428                     ProcessCommandL( EESMRCmdSendMRUpdate );
       
   429                     }
       
   430                 else
       
   431                     {
       
   432                     ProcessCommandL( EESMRCmdSendMR );
       
   433                     }
       
   434                 }
       
   435         	break;
       
   436             }
       
   437         case EESMRCmdSaveMR:
       
   438             {
       
   439             ProcessCommandL( EESMRCmdSaveMR );
       
   440             break;
       
   441             }
       
   442         case EESMREditorAddAttachment:
       
   443             {
       
   444             ProcessCommandL( EESMREditorAddAttachment );
       
   445             break;
       
   446             }
       
   447 
       
   448         case EESMRCmdLongtapDetected:
       
   449         case EAknSoftkeyContextOptions:
       
   450             {
       
   451             if( SetContextMenuL() )
       
   452                 {
       
   453                 ShowContextMenuL();;
       
   454                 }
       
   455             break;
       
   456             }
       
   457         case EESMRCmdAlarmOn:
       
   458         case EESMRCmdAlarmOff:
       
   459         case EESMRCmdOpenPriorityQuery:
       
   460         case EESMRCmdOpenSyncQuery:
       
   461         case EESMRCmdOpenUnifiedEditorQuery:
       
   462         case EESMRCmdOpenMultiCalenSelectQuery:
       
   463         case EESMRCmdOpenRecurrenceQuery:
       
   464         case EESMRCmdOpenAlarmQuery:
       
   465         case EESMRCmdCheckEvent:
       
   466         case EESMRCmdAttendeeSoftkeySelect:
       
   467         case EESMRCmdAttendeeSoftkeyCancel:
       
   468         case EESMRCmdAttendeeInsertContact:
       
   469             {
       
   470             // Forward to editor
       
   471             TRAPD( err, iView->ProcessEditorCommandL( aButtonId ) )
       
   472             if ( err != KErrNone &&
       
   473                  err != KErrCancel &&
       
   474                  err != KErrArgument )
       
   475                 {
       
   476                 User::Leave(err);
       
   477                 }
       
   478             break;
       
   479             }
       
   480         case EESMRCmdForceExit:
       
   481         case EESMRCmdCalEntryUIDelete:
       
   482         case EESMRCmdDeleteMR:
       
   483             {
       
   484             res = ETrue;
       
   485             break;
       
   486             }
       
   487         case EAknSoftkeyDone:
       
   488             {
       
   489             // Exit dialog
       
   490             TRAPD( err, HandleExitL() )
       
   491 
       
   492             switch ( err )
       
   493                 {
       
   494                 case KErrNone:
       
   495                     {
       
   496                     res = ETrue;
       
   497                     break;
       
   498                     }
       
   499                 case KErrArgument:
       
   500                     {
       
   501                     res = EFalse;
       
   502                     break;
       
   503                     }
       
   504                 default:
       
   505                     {
       
   506                     User::Leave( err );
       
   507                     break;
       
   508                     }
       
   509                 }
       
   510             break;
       
   511             }
       
   512         case EAknCmdExit:
       
   513         case EEikBidCancel:
       
   514             {
       
   515             // Force exit. Don't care about exceptions
       
   516             // just close the dialog
       
   517             TRAP_IGNORE( HandleForcedExitL( aButtonId == EAknCmdExit ) )
       
   518             res = ETrue;
       
   519             break;
       
   520             }
       
   521         default:
       
   522             {
       
   523             break;
       
   524             }
       
   525         }
       
   526 
       
   527     return res;
       
   528     }
       
   529 
       
   530 // ---------------------------------------------------------------------------
       
   531 // CESMREditorDialog::ActivateL
       
   532 // ---------------------------------------------------------------------------
       
   533 //
       
   534 void CESMREditorDialog::ActivateL( )
       
   535     {
       
   536     FUNC_LOG;
       
   537     CAknDialog::ActivateL();
       
   538     iView->InternalizeL();
       
   539 
       
   540     // Notification that MR editor is ready to be shown on screen.
       
   541     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
   542     if ( entry->Type() == MESMRCalEntry::EESMRCalEntryMeetingRequest )
       
   543         {
       
   544         iCallback.ProcessCommandL( EESMRCmdEditorInitializationComplete );
       
   545         }
       
   546 
       
   547     // initial stripe color
       
   548     MESMRCalDbMgr& dbMgr = entry->GetDBMgr();
       
   549     TPtrC calenName = dbMgr.GetCalendarNameByEntryL( *entry );
       
   550     dbMgr.SetCurCalendarByNameL( calenName );
       
   551     }
       
   552 
       
   553 // ---------------------------------------------------------------------------
       
   554 // CESMREditorDialog::IsAllowedToSaveL
       
   555 // ---------------------------------------------------------------------------
       
   556 //
       
   557 TBool CESMREditorDialog::IsAllowedToSaveL()
       
   558     {
       
   559     FUNC_LOG;
       
   560     TBool ret(ETrue);
       
   561 
       
   562     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
   563     if ( ( entry->Type() == MESMRCalEntry::EESMRCalEntryMeetingRequest ||
       
   564             entry->Type() == MESMRCalEntry::EESMRCalEntryMeeting ) &&
       
   565          entry->IsStoredL() && entry->IsRecurrentEventL() &&
       
   566          MESMRCalEntry::EESMRAllInSeries == entry->RecurrenceModRule() )
       
   567         {
       
   568         TDateTime originalDate =
       
   569                 entry->OriginalEntry().StartTimeL().TimeLocalL().DateTime();
       
   570         TDateTime modifiedDate =
       
   571                 entry->Entry().StartTimeL().TimeLocalL().DateTime();
       
   572 
       
   573         if ( !IsSameDay( originalDate, modifiedDate ) )
       
   574         {
       
   575             if ( !CESMRConfirmationQuery::ExecuteL(
       
   576                    CESMRConfirmationQuery::EESMRSaveMeetingChangedStartDay ) )
       
   577                 {
       
   578                 ret = EFalse;
       
   579                 }
       
   580             }
       
   581         }
       
   582 
       
   583     return ret;
       
   584     }
       
   585 
       
   586 // ---------------------------------------------------------------------------
       
   587 // CESMREditorDialog::ProcessCommandL
       
   588 // ---------------------------------------------------------------------------
       
   589 //
       
   590 void CESMREditorDialog::ProcessCommandL(
       
   591         TInt aCommand )
       
   592     {
       
   593     FUNC_LOG;
       
   594     TRAPD( err, DoProcessCommandL( aCommand ) );
       
   595     if ( err != KErrNone &&
       
   596          err != KErrCancel &&
       
   597          err != KErrArgument )
       
   598         {
       
   599         User::Leave(err);
       
   600         }
       
   601     }
       
   602 
       
   603 // ---------------------------------------------------------------------------
       
   604 // CESMREditorDialog::DoProcessCommandL
       
   605 // ---------------------------------------------------------------------------
       
   606 //
       
   607 void CESMREditorDialog::DoProcessCommandL(
       
   608         TInt aCommand )
       
   609     {
       
   610     FUNC_LOG;
       
   611     CAknDialog::ProcessCommandL ( aCommand );
       
   612 
       
   613     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
   614 
       
   615     switch ( aCommand )
       
   616         {
       
   617         case EESMRCmdSendAs:
       
   618             {
       
   619             SendCalendarEntryL (aCommand );
       
   620             break;
       
   621             }
       
   622             // pass-through all calentryui related command to call back
       
   623         case EESMRCmdCalEntryUISend:
       
   624             {
       
   625             User::LeaveIfError(
       
   626                     iCallback.ProcessCommandWithResultL ( aCommand ));
       
   627             break;
       
   628             }
       
   629         case EESMRCmdCalEntryUIAddParticipants:
       
   630             {
       
   631             TRAPD( err,  SwitchEntryTypeL( EMRCommandSwitchToMR, ETrue ) )
       
   632 
       
   633             if (KErrArgument == err )
       
   634             	{
       
   635             	// There was validation error --> Just show the
       
   636             	// existing editor.
       
   637             	err = KErrNone;
       
   638             	}
       
   639             else if ( err )
       
   640                 {
       
   641                 iCoeEnv->HandleError( err );
       
   642                 TryExitL( EESMRCmdForceExit );
       
   643                 }
       
   644 
       
   645             break;
       
   646             }
       
   647         case EAknSoftkeyClose:
       
   648             {
       
   649             TryExitL ( EAknCmdExit );
       
   650             break;
       
   651             }
       
   652         case EEikBidCancel: //Fall through
       
   653         case EAknCmdExit:
       
   654             {
       
   655             TryExitL ( aCommand );
       
   656             break;
       
   657             }
       
   658         case EAknCmdHelp:
       
   659             {
       
   660             iView->LaunchEditorHelpL ( );
       
   661             break;
       
   662             }
       
   663         case EESMRCmdViewTrack:
       
   664             {
       
   665             TInt res = iCallback.ProcessCommandWithResultL( aCommand );
       
   666             break;
       
   667             }
       
   668         case EESMRCmdAddOptAttendee: //Fall through
       
   669         case EESMRCmdPriorityHigh: //Fall through
       
   670         case EESMRCmdPriorityNormal: //Fall through
       
   671         case EESMRCmdPriorityLow:
       
   672             {
       
   673             iView->ProcessEditorCommandL ( aCommand );
       
   674             }
       
   675             break;
       
   676         case EESMRCmdSaveMR:
       
   677             {
       
   678             TInt ret( KErrGeneral );
       
   679             iView->ExternalizeL (); // no force validation
       
   680             if ( IsAllowedToSaveL() )
       
   681                 {
       
   682                 ret = iCallback.ProcessCommandWithResultL ( aCommand );
       
   683                 }
       
   684             if ( ret == KErrNone )
       
   685                 {
       
   686                 if ( iFeatures->FeatureSupported(
       
   687                         CESMRFeatureSettings::EESMRUIPreviousLocationsList ) )
       
   688                     {
       
   689                     LocationPluginHandlerL().StoreLocationToHistoryL( *entry );
       
   690                     }
       
   691 
       
   692                 if ( entry->Type() == MESMRCalEntry::EESMRCalEntryTodo )
       
   693                     {
       
   694                     CESMRGlobalNote* note =
       
   695                         CESMRGlobalNote::NewL(
       
   696                                 CESMRGlobalNote::EESMRTodoEntrySaved );
       
   697                     note->ExecuteLD();
       
   698                     }
       
   699                 else
       
   700                     {
       
   701                     CESMRGlobalNote* note =
       
   702                         CESMRGlobalNote::NewL(
       
   703                                 CESMRGlobalNote::EESMREntrySaved );
       
   704                     note->ExecuteLD();
       
   705                     }
       
   706                 }
       
   707             }
       
   708             break;
       
   709         case EESMRCmdSaveCloseMR:
       
   710         	{
       
   711             TryExitL( EAknSoftkeyDone );
       
   712         	break;
       
   713         	}
       
   714         case EESMRCmdSendMR: //Fall through
       
   715         case EESMRCmdSendMRUpdate:
       
   716             {
       
   717             TInt ret( KErrGeneral );
       
   718             iView->ExternalizeL();
       
   719             if ( IsAllowedToSaveL() )
       
   720                 {
       
   721                 ret = iCallback.ProcessCommandWithResultL ( aCommand );
       
   722                 }
       
   723 
       
   724             if ( ret == KErrNone )
       
   725                 {
       
   726                 if ( iFeatures->FeatureSupported(
       
   727                              CESMRFeatureSettings::EESMRUIPreviousLocationsList ) )
       
   728                     {
       
   729                     LocationPluginHandlerL().StoreLocationToHistoryL( *entry );
       
   730                     }
       
   731 
       
   732                 TInt exitCode = aCommand ==
       
   733                         EESMRCmdDeleteMR ? EESMRCmdDeleteMR : EAknSoftkeyDone;
       
   734                 TryExitL ( exitCode );
       
   735                 }
       
   736             }
       
   737             break;
       
   738 
       
   739         case EESMRCmdDeleteMR:
       
   740         case EESMRCmdCalEntryUIDelete:
       
   741             {
       
   742             TBool okToDelete = ETrue;
       
   743 
       
   744             if ( entry->IsRecurrentEventL() )
       
   745                 {
       
   746                 SetRecurrenceModRuleL(
       
   747                    *entry,
       
   748                    CESMRListQuery::EESMRDeleteThisOccurenceOrSeriesQuery );
       
   749                 }
       
   750             else
       
   751                 {
       
   752                 if( CCalenInterimUtils2::IsMeetingRequestL( entry->Entry() ) )
       
   753                     {
       
   754                     okToDelete = CESMRConfirmationQuery::ExecuteL(
       
   755                             CESMRConfirmationQuery::EESMRDeleteMR );
       
   756                     }
       
   757                 else
       
   758                     {
       
   759                     okToDelete = CESMRConfirmationQuery::ExecuteL(
       
   760                              CESMRConfirmationQuery::EESMRDeleteEntry );
       
   761                     }
       
   762                 }
       
   763 
       
   764             if ( okToDelete )
       
   765                 {
       
   766                 // When deleting we do not need to externalize entry
       
   767                 if( entry->IsStoredL() )
       
   768                     {
       
   769                     TInt res = iCallback.ProcessCommandWithResultL( aCommand );
       
   770                     if ( res != KErrCancel )
       
   771                         {
       
   772                         TryExitL( EESMRCmdDeleteMR );
       
   773                         }
       
   774                     }
       
   775                 else
       
   776                     {
       
   777                     TryExitL( EESMRCmdDeleteMR );
       
   778                     }
       
   779                 }
       
   780             }
       
   781             break;
       
   782 
       
   783         case EESMRCmdAssignFromMap:
       
   784         case EESMRCmdLandmarks:
       
   785         case EESMRCmdPreviousLocations:
       
   786             {
       
   787             if ( iFeatures->FeatureSupported(
       
   788                     CESMRFeatureSettings::EESMRUIMnFwIntegration
       
   789                     | CESMRFeatureSettings::EESMRUILandmarksIntegration
       
   790                     | CESMRFeatureSettings::EESMRUIPreviousLocationsList ) )
       
   791                 {
       
   792                 TBool ignoreQuery = EFalse;
       
   793 
       
   794                 if ( aCommand == EESMRCmdAssignFromMap )
       
   795                     {
       
   796                     HBufC* oldLocation = entry->Entry().LocationL().AllocLC();
       
   797                     iView->ExternalizeL();
       
   798 
       
   799                     // if old and new locations are different and old location
       
   800                     // exists, the user is updating existing location. Let's discard
       
   801                     // the existing coordinates by using command EESMRCmdUpdateFromMap
       
   802                     if ( ( entry->Entry().LocationL().Compare( *oldLocation ) != 0
       
   803                            && oldLocation->Length() != 0 )
       
   804                          || iLocationModified )
       
   805                         {
       
   806                         aCommand = EESMRCmdUpdateFromMap;
       
   807                         }
       
   808                     else if ( oldLocation->Length() == 0 )
       
   809                         {
       
   810                         // Assigning location from Maps for first time.
       
   811                         ignoreQuery = EFalse;
       
   812                         }
       
   813                     CleanupStack::PopAndDestroy( oldLocation );
       
   814                     oldLocation = NULL;
       
   815                     }
       
   816                 else
       
   817                     {
       
   818                     iView->ExternalizeL();
       
   819                     }
       
   820 
       
   821                 iLocationModified |=
       
   822                     LocationPluginHandlerL().HandleCommandL( aCommand,
       
   823                                                          *entry,
       
   824                                                          ignoreQuery );
       
   825                 iView->InternalizeL();
       
   826                 iView->SetControlFocusedL( EESMRFieldLocation );
       
   827                 }
       
   828             break;
       
   829             }
       
   830         case EESMRCmdSearchFromContacts:
       
   831             {
       
   832             if ( iFeatures->FeatureSupported(
       
   833                     CESMRFeatureSettings::EESMRUIContactsIntegration ) )
       
   834                  {
       
   835                  iView->ExternalizeL();
       
   836                  iLocationModified |=
       
   837                      AddressInfoHandlerL().SearchAddressFromContactsL( *entry );
       
   838                  iView->InternalizeL();
       
   839                  iView->SetControlFocusedL( EESMRFieldLocation );
       
   840                  }
       
   841             break;
       
   842             }
       
   843         // Scenarios with viewer location field in editor dialog.
       
   844         case EESMRCmdShowOnMap:
       
   845         case EESMRCmdSearchFromMap:
       
   846             {
       
   847             if ( iFeatures->FeatureSupported(
       
   848                     CESMRFeatureSettings::EESMRUIMnFwIntegration ) )
       
   849                 {
       
   850                 LocationPluginHandlerL().HandleCommandL(aCommand, *entry );
       
   851                 }
       
   852             break;
       
   853             }
       
   854         case EAknCmdOpen:
       
   855             {
       
   856             HandleOpenCmdL();
       
   857             break;
       
   858             }
       
   859         case EESMRCmdAttendeeInsertContact:
       
   860             {
       
   861             OkToExitL(EESMRCmdAttendeeInsertContact);
       
   862             break;
       
   863             }
       
   864         /*
       
   865         * Attachment field editor context menu commands
       
   866         */
       
   867         case EESMREditorOpenAttachment:
       
   868         case EESMREditorRemoveAttachment:
       
   869         case EESMREditorRemoveAllAttachments:
       
   870         case EESMREditorAddAttachment:
       
   871            {
       
   872            iView->ProcessEditorCommandL( aCommand );
       
   873            break;
       
   874            }
       
   875 
       
   876         case EMRCommandMyLocations:
       
   877             {
       
   878             iView->ExternalizeL();
       
   879             iLocationModified |=
       
   880                 LocationPluginHandlerL().HandleCommandL( aCommand,
       
   881                                                          *entry,
       
   882                                                          EFalse );
       
   883             iView->InternalizeL();
       
   884             iView->SetControlFocusedL( EESMRFieldLocation );
       
   885             break;
       
   886             }
       
   887         default:
       
   888             break;
       
   889         }
       
   890     }
       
   891 
       
   892 // ---------------------------------------------------------------------------
       
   893 // CESMREditorDialog::DynInitMenuPaneL()
       
   894 // ---------------------------------------------------------------------------
       
   895 //
       
   896 void CESMREditorDialog::DynInitMenuPaneL(
       
   897         TInt aResourceId,
       
   898         CEikMenuPane* aMenu )
       
   899     {
       
   900     FUNC_LOG;
       
   901     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
   902 
       
   903     TMRMenuStyle menuStyle( EMROptionsMenu );
       
   904 
       
   905     if ( aResourceId == R_MR_EDITOR_ORGANIZER_MENU )
       
   906         {
       
   907         const CESMRPolicy& policy = Policy();
       
   908         const TInt count(aMenu->NumberOfItemsInPane());
       
   909         for ( TInt i(0); i < count; i++ )
       
   910             {
       
   911             CEikMenuPaneItem::SData& item = aMenu->ItemDataByIndexL ( i );
       
   912 
       
   913             if ( item.iCommandId )
       
   914                 {
       
   915                 // Checking from policy for commands that has valid command id and
       
   916                 aMenu->SetItemDimmed (
       
   917                             item.iCommandId,
       
   918                             !policy.IsDefaultCommand(item.iCommandId) );
       
   919                 }
       
   920             }
       
   921 
       
   922         //Open command
       
   923         if ( iView->IsComponentFocused( EESMRFieldSync ) ||
       
   924              iView->IsComponentFocused( EESMRFieldRecurrence ) ||
       
   925              iView->IsComponentFocused( EESMRFieldAlarm ) ||
       
   926              iView->IsComponentFocused( EESMRFieldPriority ))
       
   927             {
       
   928             aMenu->SetItemDimmed( EAknCmdOpen, EFalse );
       
   929             }
       
   930 
       
   931         if( iInterimUtils && !(iInterimUtils->MRViewersEnabledL()))
       
   932             {
       
   933             aMenu->SetItemDimmed( EESMRCmdCalEntryUIAddParticipants, ETrue );
       
   934             }
       
   935 
       
   936         
       
   937         TBool sendEnabled( EFalse );
       
   938         TBool sentAndStored( EFalse );
       
   939         
       
   940         if ( MESMRCalEntry::EESMRCalEntryMeetingRequest == entry->Type() )
       
   941             {
       
   942             MESMRMeetingRequestEntry* mrEntry =
       
   943                     static_cast<MESMRMeetingRequestEntry*>( iInfoProvider.EntryL() );
       
   944         
       
   945             // if the entry is saved (stored) and sent to recipients,
       
   946             // show 'Send update', otherwise just 'Send'
       
   947             sentAndStored = mrEntry->IsSentL() && mrEntry->IsStoredL();
       
   948 
       
   949             // enable send only if attendee editors contain attendees and
       
   950             // entry does not occur in past.
       
   951             TBool bOccursInPast( OccursInPast( iStartTimeUtc ) );
       
   952                 
       
   953             TBool sendEnabled = ( !bOccursInPast &&
       
   954                     ( mrEntry->RoleL() == EESMRRoleOrganizer ) &&            
       
   955                     ( iRequiredAttendeesEnabled | iOptionalAttendeesEnabled ) &&
       
   956                     ((( mrEntry->RoleL() == EESMRRoleOrganizer ) &&
       
   957                     ( iInfoProvider.PolicyProvider().CurrentPolicy().ViewMode() == EESMREditMR )) ||
       
   958                     ( iInfoProvider.PolicyProvider().CurrentPolicy().ViewMode() == EESMRForwardMR )
       
   959                     ));
       
   960             }
       
   961         
       
   962         if ( policy.IsDefaultCommand( EESMRCmdSendMR ) )
       
   963            {
       
   964            aMenu->SetItemDimmed ( EESMRCmdSendMR, !sendEnabled );
       
   965            }
       
   966 
       
   967         if ( policy.IsDefaultCommand(EESMRCmdSendMRUpdate ) )
       
   968            {
       
   969            if ( sendEnabled )
       
   970                {
       
   971                //EESMRCmdSendMRUpdate and EESMRCmdSendMR shouldn't
       
   972                //be visible at the same time
       
   973                aMenu->SetItemDimmed( EESMRCmdSendMRUpdate, !sentAndStored );
       
   974                if( policy.IsDefaultCommand( EESMRCmdSendMR ) )
       
   975                    {
       
   976                    aMenu->SetItemDimmed( EESMRCmdSendMR, sentAndStored );
       
   977                    }
       
   978                }
       
   979            else
       
   980                {
       
   981                aMenu->SetItemDimmed( EESMRCmdSendMRUpdate, ETrue );
       
   982                }
       
   983            }
       
   984 
       
   985         if ( policy.IsDefaultCommand( EESMRCmdAddOptAttendee ) )
       
   986             {
       
   987             // if optional attendee (recipient) is already visible, don't show
       
   988             // the menu item.
       
   989             TBool isVisible =
       
   990                     iView->IsControlVisible( EESMRFieldOptAttendee );
       
   991             aMenu->SetItemDimmed( EESMRCmdAddOptAttendee, isVisible );
       
   992             }
       
   993 
       
   994         if ( policy.IsDefaultCommand( EESMRCmdViewTrack ) )
       
   995             {
       
   996             //only show tracking view option when item is sent, stored
       
   997             //and when cfsmailbox actually supports attendee status
       
   998 
       
   999             if ( SupportsMailBoxCapabilityL(
       
  1000                     MESMRBuilderExtension::EMRCFSAttendeeStatus ) )
       
  1001                 {
       
  1002                 aMenu->SetItemDimmed( EESMRCmdViewTrack, !sentAndStored );
       
  1003                 }
       
  1004             else
       
  1005                 {
       
  1006                 aMenu->SetItemDimmed( EESMRCmdViewTrack, ETrue );
       
  1007                 }
       
  1008             }
       
  1009 
       
  1010         // Insert send ui menu for all other entry types than meeting request
       
  1011         if ( entry->Type ( )!= MESMRCalEntry::EESMRCalEntryMeetingRequest )
       
  1012             {
       
  1013             TryInsertSendMenuL( aMenu );
       
  1014             }
       
  1015 		}
       
  1016 
       
  1017     if ( aResourceId == R_LOCATION_OPTIONS
       
  1018          || aResourceId == R_MR_EDITOR_LOCATION_MENU
       
  1019          || aResourceId == R_MR_VIEWER_LOCATION_MENU )
       
  1020         {
       
  1021         menuStyle = EMRContextMenu;
       
  1022         HandleLocationOptionsL( aResourceId, aMenu );
       
  1023         }
       
  1024     if ( aResourceId == R_MR_EDITOR_ATTACHMENT_CONTEXT_MENU
       
  1025          || aResourceId == R_MR_EDITOR_ATTENDEE_CONTEXT_MENU )
       
  1026         {
       
  1027         menuStyle = EMRContextMenu;
       
  1028         }
       
  1029 
       
  1030     // Field specific context menu
       
  1031     iView->DynInitMenuPaneL( menuStyle, aResourceId, aMenu );
       
  1032     }
       
  1033 
       
  1034 // ---------------------------------------------------------------------------
       
  1035 // CESMREditorDialog::SupportsAttendeeStatusL
       
  1036 // ---------------------------------------------------------------------------
       
  1037 //
       
  1038 TBool CESMREditorDialog::SupportsMailBoxCapabilityL(
       
  1039         MESMRBuilderExtension::TMRCFSMailBoxCapability aCapa )
       
  1040     {
       
  1041     FUNC_LOG;
       
  1042     TBool supportsCapability( EFalse );
       
  1043     CESMRFieldBuilderInterface* plugin = NULL;
       
  1044     TRAPD( error,
       
  1045             plugin = CESMRFieldBuilderInterface::CreatePluginL(
       
  1046                         TUid::Uid( KESMRUIFieldBuilderPluginImplUId ) ) );
       
  1047     CleanupStack::PushL( plugin );
       
  1048 
       
  1049     if ( error == KErrNone && plugin )
       
  1050         {
       
  1051         TUid uid = {0};
       
  1052         MESMRBuilderExtension* extension =
       
  1053             static_cast<MESMRBuilderExtension*>( plugin->ExtensionL( uid ) );
       
  1054 
       
  1055         if ( extension )
       
  1056             {
       
  1057             supportsCapability =
       
  1058                 extension->CFSMailBoxCapabilityL( aCapa );
       
  1059             }
       
  1060         }
       
  1061 
       
  1062     CleanupStack::PopAndDestroy( plugin );
       
  1063 
       
  1064     return supportsCapability;
       
  1065     }
       
  1066 
       
  1067 // ---------------------------------------------------------------------------
       
  1068 // CESMREditorDialog::ExecuteViewLD
       
  1069 // ---------------------------------------------------------------------------
       
  1070 //
       
  1071 TInt CESMREditorDialog::ExecuteViewLD( )
       
  1072     {
       
  1073     return ExecuteLD( R_MREDITOR_DIALOG );
       
  1074     }
       
  1075 
       
  1076 // ---------------------------------------------------------------------------
       
  1077 // CESMRViewerDialog::Response
       
  1078 // ---------------------------------------------------------------------------
       
  1079 //
       
  1080 TBool CESMREditorDialog::Response(
       
  1081         TInt /*aCommand*/)
       
  1082     {
       
  1083     return EFalse;
       
  1084     }
       
  1085 
       
  1086 // ---------------------------------------------------------------------------
       
  1087 // CESMRViewerDialog::ExitDialog
       
  1088 // ---------------------------------------------------------------------------
       
  1089 //
       
  1090 void CESMREditorDialog::ExitDialog()
       
  1091     {
       
  1092     // This is for mixed field storage's viewer fields.
       
  1093     // Not actual used in editor dialog
       
  1094     }
       
  1095 
       
  1096 // ---------------------------------------------------------------------------
       
  1097 // CESMRViewerDialog::ChangeReadyResponseL
       
  1098 // ---------------------------------------------------------------------------
       
  1099 //
       
  1100 void CESMREditorDialog::ChangeReadyResponseL() // codescanner::LFunctionCantLeave
       
  1101     {
       
  1102     // This is for mixed field storage's viewer fields.
       
  1103     // Not actual used in editor dialog
       
  1104     }
       
  1105 
       
  1106 // ---------------------------------------------------------------------------
       
  1107 // CESMREditorDialog::HandleExitL
       
  1108 // ---------------------------------------------------------------------------
       
  1109 //
       
  1110 TInt CESMREditorDialog::HandleExitL() // codescanner::intleaves
       
  1111     {
       
  1112     FUNC_LOG;
       
  1113     TInt res( KErrNone);
       
  1114     
       
  1115     iView->ExternalizeL(); // no force validation
       
  1116 
       
  1117     // If no attendees, switch MR to regular meeting
       
  1118     VerifyMeetingRequestL();
       
  1119 
       
  1120     // Get the entry to be confirmed for saving
       
  1121     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
  1122     
       
  1123     // if entry is stored and type changed, we will always save it
       
  1124     if( entry->IsStoredL() && entry->IsEntryTypeChangedL() )
       
  1125         {
       
  1126         res = TryToSaveEntryL();
       
  1127         }
       
  1128     // If entry is new and type changed, we have to see, if something has
       
  1129     // changed, before we save it.
       
  1130     else if( !entry->IsStoredL() && entry->IsEntryTypeChangedL() )
       
  1131         {
       
  1132         if( entry->IsEntryEditedL() )
       
  1133             {
       
  1134             res = TryToSaveEntryL();
       
  1135             }
       
  1136         }
       
  1137     // Entry is not type changed, we will use normal procedure to
       
  1138     // see if entry will be saved or not.
       
  1139     else
       
  1140         {
       
  1141         if( entry->IsEntryEditedL() )
       
  1142             {
       
  1143             res = TryToSaveEntryL();
       
  1144             }
       
  1145         }
       
  1146 
       
  1147     return res;
       
  1148     }
       
  1149 
       
  1150 // ---------------------------------------------------------------------------
       
  1151 // CESMREditorDialog::HandleForcedExitL
       
  1152 // ---------------------------------------------------------------------------
       
  1153 //
       
  1154 TInt CESMREditorDialog::HandleForcedExitL( TBool aShowConfirmationQuery ) // codescanner::intleaves
       
  1155     {
       
  1156     FUNC_LOG;
       
  1157 
       
  1158     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
  1159 
       
  1160     TInt res( KErrNone);
       
  1161 
       
  1162     iView->ExternalizeL ( ETrue ); // force validation should be used
       
  1163 
       
  1164     // If no attendees, switch MR to regular meeting
       
  1165     VerifyMeetingRequestL();
       
  1166 
       
  1167     // The entry data may be changed by the above function VerifyMeetingRequestL()
       
  1168     entry = iInfoProvider.EntryL();
       
  1169 
       
  1170     if ( entry->IsEntryEditedL() )
       
  1171         {
       
  1172         if ( !aShowConfirmationQuery ||
       
  1173              CESMRConfirmationQuery::ExecuteL(
       
  1174                 CESMRConfirmationQuery::EESMRSaveChanges ))
       
  1175             {
       
  1176             res = iCallback.ProcessCommandWithResultL( EESMRCmdSaveMR );
       
  1177 
       
  1178             if ( res == KErrNone
       
  1179                  && iFeatures->FeatureSupported(
       
  1180                          CESMRFeatureSettings::EESMRUIPreviousLocationsList ) )
       
  1181                 {
       
  1182                 LocationPluginHandlerL().StoreLocationToHistoryL( *entry );
       
  1183                 }
       
  1184             }
       
  1185         }
       
  1186 
       
  1187     return res;
       
  1188     }
       
  1189 
       
  1190 // ---------------------------------------------------------------------------
       
  1191 // CESMREditorDialog::SendCalendarEntryL
       
  1192 // ---------------------------------------------------------------------------
       
  1193 //
       
  1194 void CESMREditorDialog::SendCalendarEntryL(
       
  1195         TInt aCommandId )
       
  1196     {
       
  1197     FUNC_LOG;
       
  1198 
       
  1199     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
  1200 
       
  1201     iView->ExternalizeL(); // no force validation
       
  1202     TInt res(KErrGeneral);
       
  1203     res = iCallback.ProcessCommandWithResultL( EESMRCmdSaveMR );
       
  1204 
       
  1205     if ( res == KErrNone )
       
  1206         {
       
  1207         if ( iFeatures->FeatureSupported(
       
  1208                 CESMRFeatureSettings::EESMRUIPreviousLocationsList ) )
       
  1209             {
       
  1210             LocationPluginHandlerL().StoreLocationToHistoryL( *entry );
       
  1211             }
       
  1212 
       
  1213         // we don't need MenuPane in CCalSend but we need it for the API
       
  1214         CEikMenuPane* pane = NULL;
       
  1215 
       
  1216         // Show menu to user
       
  1217         // CCalenSend handles selection internally,
       
  1218         // so we don't get anything in return
       
  1219         iESMRSendUI->DisplaySendCascadeMenuL( *pane );
       
  1220 
       
  1221         // Try to send
       
  1222         if (iESMRSendUI->CanSendL( aCommandId ) )
       
  1223             {
       
  1224             iESMRSendUI->SendAsVCalendarL( aCommandId, entry->Entry ( ) );
       
  1225             }
       
  1226         }
       
  1227     }
       
  1228 
       
  1229 // ---------------------------------------------------------------------------
       
  1230 // CESMREditorDialog::TryInsertSendMenuL
       
  1231 // ---------------------------------------------------------------------------
       
  1232 //
       
  1233 void CESMREditorDialog::TryInsertSendMenuL(
       
  1234         CEikMenuPane* aMenuPane )
       
  1235     {
       
  1236     FUNC_LOG;
       
  1237     // Insert send menu to the next position from "delete"
       
  1238     TInt index(KErrNotFound);
       
  1239     aMenuPane->ItemAndPos(EESMRCmdCalEntryUIDelete, index);
       
  1240     if (index == KErrNotFound)
       
  1241         {
       
  1242         aMenuPane->ItemAndPos(EESMRCmdDeleteMR, index);
       
  1243         }
       
  1244     index++;
       
  1245     iESMRSendUI->DisplaySendMenuItemL(*aMenuPane, index);
       
  1246     }
       
  1247 
       
  1248 // ---------------------------------------------------------------------------
       
  1249 // CESMREditorDialog::HandleOpenCmdL
       
  1250 // ---------------------------------------------------------------------------
       
  1251 //
       
  1252 void CESMREditorDialog::HandleOpenCmdL()
       
  1253     {
       
  1254     FUNC_LOG;
       
  1255     iView->ProcessEditorCommandL( EAknCmdOpen );
       
  1256     }
       
  1257 
       
  1258 // ---------------------------------------------------------------------------
       
  1259 // CESMREditorDialog::HandleLocationOptionsL
       
  1260 // ---------------------------------------------------------------------------
       
  1261 //
       
  1262 void CESMREditorDialog::HandleLocationOptionsL( TInt aResourceId,
       
  1263                                                 CEikMenuPane* aMenuPane )
       
  1264     {
       
  1265     FUNC_LOG;
       
  1266 
       
  1267     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
  1268 
       
  1269     if ( aResourceId == R_MR_VIEWER_LOCATION_MENU )
       
  1270         {
       
  1271         TBool showOnMap = EFalse;
       
  1272         TBool searchFromMap = EFalse;
       
  1273 
       
  1274         if ( iFeatures->FeatureSupported(
       
  1275                 CESMRFeatureSettings::EESMRUIMnFwIntegration ) )
       
  1276             {
       
  1277             showOnMap = LocationPluginHandlerL().IsCommandAvailableL(
       
  1278                     EESMRCmdShowOnMap,
       
  1279                     *entry );
       
  1280             searchFromMap = !showOnMap;
       
  1281             }
       
  1282 
       
  1283         aMenuPane->SetItemDimmed( EESMRCmdShowOnMap, !showOnMap );
       
  1284         aMenuPane->SetItemDimmed( EESMRCmdSearchFromMap, !searchFromMap );
       
  1285 
       
  1286         const CESMRPolicy& policy = Policy();
       
  1287         aMenuPane->SetItemDimmed( EESMRCmdEdit,
       
  1288                                   !policy.IsDefaultCommand( EESMRCmdEdit ) );
       
  1289         aMenuPane->SetItemDimmed( EESMRCmdEditLocal,
       
  1290                                   !policy.IsDefaultCommand( EESMRCmdEditLocal ) );
       
  1291         aMenuPane->SetItemDimmed( EESMRCmdCalEntryUIEdit,
       
  1292                                   !policy.IsDefaultCommand( EESMRCmdCalEntryUIEdit ) );
       
  1293         }
       
  1294     }
       
  1295 
       
  1296 // ---------------------------------------------------------------------------
       
  1297 // CESMREditorDialog::LocationPluginHandlerL
       
  1298 // ---------------------------------------------------------------------------
       
  1299 //
       
  1300 CESMRLocationPluginHandler& CESMREditorDialog::LocationPluginHandlerL()
       
  1301     {
       
  1302     FUNC_LOG;
       
  1303     if ( !iLocationPluginHandler )
       
  1304         {
       
  1305         iLocationPluginHandler = CESMRLocationPluginHandler::NewL( *this );
       
  1306         }
       
  1307 
       
  1308     return *iLocationPluginHandler;
       
  1309     }
       
  1310 
       
  1311 // ---------------------------------------------------------------------------
       
  1312 // CESMREditorDialog::AddressInfoHandlerL
       
  1313 // ---------------------------------------------------------------------------
       
  1314 //
       
  1315 CESMRAddressInfoHandler& CESMREditorDialog::AddressInfoHandlerL()
       
  1316     {
       
  1317     FUNC_LOG;
       
  1318     if ( !iAddressInfoHandler )
       
  1319         {
       
  1320         iAddressInfoHandler = CESMRAddressInfoHandler::NewL();
       
  1321         }
       
  1322 
       
  1323     return *iAddressInfoHandler;
       
  1324     }
       
  1325 
       
  1326 // ---------------------------------------------------------------------------
       
  1327 // CESMREditorDialog::HandleFieldEventL
       
  1328 // ---------------------------------------------------------------------------
       
  1329 //
       
  1330 void CESMREditorDialog::HandleFieldEventL( // codescanner::LFunctionCantLeave
       
  1331         const MESMRFieldEvent& aEvent )
       
  1332     {
       
  1333     FUNC_LOG;
       
  1334     switch ( aEvent.Type() )
       
  1335         {
       
  1336         case MESMRFieldEvent::EESMRFieldCommandEvent:
       
  1337             {
       
  1338             HandleFieldCommandEventL( aEvent );
       
  1339             break;
       
  1340             }
       
  1341         case MESMRFieldEvent::EESMRFieldChangeEvent:
       
  1342             {
       
  1343             HandleFieldChangeEventL( aEvent );
       
  1344             break;
       
  1345             }
       
  1346         default:
       
  1347             {
       
  1348             break;
       
  1349             }
       
  1350         }
       
  1351     }
       
  1352 
       
  1353 // ---------------------------------------------------------------------------
       
  1354 // CESMREditorDialog::HandleFieldCommandEventL
       
  1355 // ---------------------------------------------------------------------------
       
  1356 //
       
  1357 void CESMREditorDialog::HandleFieldCommandEventL(
       
  1358         const MESMRFieldEvent& aEvent )
       
  1359     {
       
  1360     FUNC_LOG;
       
  1361     CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
  1362     TInt* command = static_cast< TInt* >( aEvent.Param( 0 ) );
       
  1363     switch ( *command )
       
  1364         {
       
  1365         case EESMRCmdAttendeeRequiredEnabled:
       
  1366             {
       
  1367             iRequiredAttendeesEnabled = ETrue;
       
  1368             break;
       
  1369             }
       
  1370         case EESMRCmdAttendeeRequiredDisabled:
       
  1371             {
       
  1372             iRequiredAttendeesEnabled = EFalse;
       
  1373             break;
       
  1374             }
       
  1375         case EESMRCmdAttendeeOptionalEnabled:
       
  1376             {
       
  1377             iOptionalAttendeesEnabled = ETrue;
       
  1378             break;
       
  1379             }
       
  1380         case EESMRCmdAttendeeOptionalDisabled:
       
  1381             {
       
  1382             iOptionalAttendeesEnabled = EFalse;
       
  1383             break;
       
  1384             }
       
  1385         case EESMRCmdRestoreMiddleSoftKey:
       
  1386             {
       
  1387             iContextMenuResourceId = 0;
       
  1388 
       
  1389             if ( Policy().FieldL(
       
  1390                     iView->FocusedField() ).iFieldMode == EESMRFieldModeView )
       
  1391                 {
       
  1392                 // Dim default MSK if editor contains viewer fields
       
  1393                 cba.MakeCommandVisibleByPosition(
       
  1394                         CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
  1395                         EFalse );
       
  1396                 }
       
  1397             else
       
  1398                 {
       
  1399                 cba.SetCommandL(
       
  1400                     CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
  1401                     R_MR_SELECT_SOFTKEY );
       
  1402 
       
  1403                 cba.MakeCommandVisibleByPosition(
       
  1404                         CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
  1405                         ETrue );
       
  1406                 cba.DrawDeferred();
       
  1407                 }
       
  1408             }
       
  1409             break;
       
  1410         case EESMRCmdSizeExceeded:
       
  1411             iView->ProcessEditorCommandL( *command );
       
  1412             break;
       
  1413 
       
  1414         case EMRCommandSwitchToMR:
       
  1415         case EMRCommandSwitchToMeeting:
       
  1416         case EMRCommandSwitchToMemo:
       
  1417         case EMRCommandSwitchToAnniversary:
       
  1418         case EMRCommandSwitchToTodo:
       
  1419             {
       
  1420             TRAPD( err, SwitchEntryTypeL( *command, ETrue ) )
       
  1421 
       
  1422             if (KErrArgument == err )
       
  1423                  {
       
  1424                  // There was validation error --> Just show the
       
  1425                  // existing editor.
       
  1426                  err = KErrNone;
       
  1427                  }
       
  1428              else if ( err )
       
  1429                 {
       
  1430                 // UI and engine not consistent. Show error and exit
       
  1431                 iCoeEnv->HandleError( err );
       
  1432                 TryExitL( EESMRCmdForceExit );
       
  1433                 }
       
  1434 
       
  1435             break;
       
  1436             }
       
  1437         case EESMRCmdLongtapDetected:
       
  1438             {
       
  1439             OkToExitL(EESMRCmdLongtapDetected);
       
  1440             break;
       
  1441             }
       
  1442         case EMRLaunchAttachmentContextMenu:
       
  1443         case EAknSoftkeyContextOptions:
       
  1444             {
       
  1445             OkToExitL( EAknSoftkeyContextOptions );
       
  1446             break;
       
  1447             }
       
  1448         case EESMRCmdCalendarChange:
       
  1449             {
       
  1450             DrawDeferred();
       
  1451             break;
       
  1452             }
       
  1453         case EESMRCmdAssignFromMap:
       
  1454         case EMRCommandMyLocations:
       
  1455             {
       
  1456             DoProcessCommandL( *command );
       
  1457             break;
       
  1458             }
       
  1459         default:
       
  1460             {
       
  1461             break;
       
  1462             }
       
  1463         }
       
  1464 
       
  1465 
       
  1466     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
  1467     if ( entry->Type() == MESMRCalEntry::EESMRCalEntryMeetingRequest )
       
  1468     	{
       
  1469 		MESMRMeetingRequestEntry* mrEntry =
       
  1470             static_cast<MESMRMeetingRequestEntry*>( iInfoProvider.EntryL() );
       
  1471 
       
  1472 		TBool bOccursInPast( OccursInPast( iStartTimeUtc ) );
       
  1473 		
       
  1474 		TBool sendEnabled = ( !bOccursInPast &&
       
  1475 			( mrEntry->RoleL() == EESMRRoleOrganizer || mrEntry->IsForwardedL() ) &&            
       
  1476 			( iRequiredAttendeesEnabled | iOptionalAttendeesEnabled ) &&
       
  1477 			(( ( iInfoProvider.PolicyProvider().CurrentPolicy().ViewMode() == EESMREditMR )) ||
       
  1478 			( iInfoProvider.PolicyProvider().CurrentPolicy().ViewMode() == EESMRForwardMR )
       
  1479 			));
       
  1480 
       
  1481 		if( sendEnabled )
       
  1482 			{
       
  1483 			cba.SetCommandL(
       
  1484                     CEikButtonGroupContainer::ERightSoftkeyPosition,
       
  1485                     R_MR_SEND_SOFTKEY);
       
  1486             cba.MakeCommandVisibleByPosition(
       
  1487                     CEikButtonGroupContainer::ERightSoftkeyPosition,
       
  1488                     ETrue );
       
  1489 			cba.DrawDeferred();
       
  1490 			}
       
  1491 		else
       
  1492 			{
       
  1493 			cba.SetCommandL(
       
  1494                     CEikButtonGroupContainer::ERightSoftkeyPosition,
       
  1495                     R_MR_DONE_SOFTKEY);
       
  1496             cba.MakeCommandVisibleByPosition(
       
  1497                     CEikButtonGroupContainer::ERightSoftkeyPosition,
       
  1498                     ETrue );
       
  1499 			cba.DrawDeferred();
       
  1500 			}
       
  1501     	}
       
  1502 	else
       
  1503 		{
       
  1504 		cba.SetCommandL(
       
  1505                 CEikButtonGroupContainer::ERightSoftkeyPosition,
       
  1506                 R_MR_DONE_SOFTKEY);
       
  1507         cba.MakeCommandVisibleByPosition(
       
  1508                 CEikButtonGroupContainer::ERightSoftkeyPosition,
       
  1509                 ETrue );
       
  1510 		cba.DrawDeferred();
       
  1511 		}
       
  1512     }
       
  1513 
       
  1514 // ---------------------------------------------------------------------------
       
  1515 // CESMREditorDialog::HandleFieldChangeEventL
       
  1516 // ---------------------------------------------------------------------------
       
  1517 //
       
  1518 void CESMREditorDialog::HandleFieldChangeEventL(
       
  1519         const MESMRFieldEvent& aEvent )
       
  1520     {
       
  1521     FUNC_LOG;
       
  1522 
       
  1523     TInt* fieldId = static_cast< TInt* >( aEvent.Param( 0 ) );
       
  1524     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
  1525 
       
  1526     switch ( *fieldId )
       
  1527         {
       
  1528         case EESMRFieldLocation:
       
  1529             {
       
  1530             MESMRFieldEventValue* value =
       
  1531                 static_cast< MESMRFieldEventValue* >( aEvent.Param( 1 ) );
       
  1532             if ( entry->Entry().LocationL() != value->StringValue() )
       
  1533                 {
       
  1534                 // Show query dialog only if entry has geocoordinates.
       
  1535                 // It can be verified by checking if "Show on map" is available
       
  1536                 // for iEntry as geocoordinates are required for that.
       
  1537                 TBool enableQuery =
       
  1538                     LocationPluginHandlerL().IsCommandAvailableL(
       
  1539                             EESMRCmdShowOnMap, *entry );
       
  1540 
       
  1541                 if ( enableQuery
       
  1542                      && CESMRConfirmationQuery::ExecuteL(
       
  1543                         CESMRConfirmationQuery::EESMRAssignUpdatedLocation ) )
       
  1544                     {
       
  1545                     HBufC* oldLocation = entry->Entry().LocationL().AllocLC();
       
  1546                     iView->ExternalizeL();
       
  1547 
       
  1548                     // if old and new locations are different and old location
       
  1549                     // exists, the user is updating existing location. Let's discard
       
  1550                     // the existing coordinates by using command EESMRCmdUpdateFromMap
       
  1551                     if ( entry->Entry().LocationL().Compare( *oldLocation ) != 0 &&
       
  1552                             oldLocation->Length() != 0 )
       
  1553                         {
       
  1554                         LocationPluginHandlerL().HandleCommandL(
       
  1555                                 EESMRCmdUpdateFromMap,
       
  1556                                 *entry );
       
  1557                         }
       
  1558                     else
       
  1559                         {
       
  1560                         LocationPluginHandlerL().HandleCommandL(
       
  1561                             EESMRCmdAssignFromMap,
       
  1562                             *entry,
       
  1563                             EFalse );
       
  1564                         }
       
  1565 
       
  1566                     iView->InternalizeL();
       
  1567                     iView->SetControlFocusedL( EESMRFieldLocation );
       
  1568 
       
  1569                     CleanupStack::PopAndDestroy( oldLocation );
       
  1570                     oldLocation = NULL;
       
  1571                     }
       
  1572                 else if ( enableQuery )
       
  1573                     {
       
  1574                     // Externalize entry, so query won't be displayed
       
  1575                     // again for the same text.
       
  1576                     iView->ExternalizeL();
       
  1577                     }
       
  1578                 }
       
  1579             break;
       
  1580             }
       
  1581 
       
  1582         case EESMRFieldStartDate:
       
  1583             {
       
  1584 			// for update iStartTimeUtc when meeting & mr event changing start time
       
  1585             TBool bOccursInPast( OccursInPastL( aEvent ) );
       
  1586             
       
  1587             if ( entry->Type() == MESMRCalEntry::EESMRCalEntryMeetingRequest )
       
  1588             	{
       
  1589         		MESMRMeetingRequestEntry* mrEntry =
       
  1590                     static_cast<MESMRMeetingRequestEntry*>( iInfoProvider.EntryL() );
       
  1591  	            TBool bIsOrganizer( mrEntry->RoleL() == EESMRRoleOrganizer );            
       
  1592 				
       
  1593             	ChangeRightSoftkeyL( bOccursInPast, bIsOrganizer );
       
  1594             	}
       
  1595             break;
       
  1596             }
       
  1597             
       
  1598         case EESMRFieldAllDayEvent:
       
  1599             {
       
  1600             TBool bOccursInPast( OccursInPast( iStartTimeUtc ) );   
       
  1601             TInt* bChecked = static_cast< TInt* >( aEvent.Param( 1 ) );
       
  1602             if( *bChecked == 1 )
       
  1603             	{
       
  1604 				TDateTime startTime = iStartTimeUtc.DateTime();
       
  1605 				startTime.SetHour( 0 );
       
  1606 				startTime.SetMinute( 0 );
       
  1607 				startTime.SetSecond( 0 );
       
  1608 				bOccursInPast = OccursInPast( startTime );
       
  1609             	}               
       
  1610 
       
  1611             if ( entry->Type() == MESMRCalEntry::EESMRCalEntryMeetingRequest )
       
  1612             	{
       
  1613         		MESMRMeetingRequestEntry* mrEntry =
       
  1614                     static_cast<MESMRMeetingRequestEntry*>( iInfoProvider.EntryL() );
       
  1615                 TBool bIsOrganizer( mrEntry->RoleL() == EESMRRoleOrganizer );
       
  1616 				
       
  1617             	ChangeRightSoftkeyL( bOccursInPast, bIsOrganizer );
       
  1618             	}
       
  1619             break;
       
  1620             }              
       
  1621         default:
       
  1622             {
       
  1623             break;
       
  1624             }
       
  1625         }
       
  1626     }
       
  1627 
       
  1628 // ---------------------------------------------------------------------------
       
  1629 // CESMREditorDialog::SetContextMenuL
       
  1630 // ---------------------------------------------------------------------------
       
  1631 //
       
  1632 TBool CESMREditorDialog::SetContextMenuL()
       
  1633     {
       
  1634     FUNC_LOG;
       
  1635     TInt ret( EFalse );
       
  1636 
       
  1637     TESMREntryFieldId fieldId = iView->ClickedOrFocusedField();
       
  1638 
       
  1639     switch( fieldId )
       
  1640         {
       
  1641         case EESMRFieldLocation:
       
  1642             {
       
  1643             ret = ETrue;
       
  1644 
       
  1645             if ( Policy().FieldL( EESMRFieldLocation ).iFieldMode
       
  1646                     == EESMRFieldModeEdit )
       
  1647                 {
       
  1648                 iContextMenuResourceId =
       
  1649                         R_MR_EDITOR_LOCATION_CONTEXT_MENU;
       
  1650                 }
       
  1651             else
       
  1652                 {
       
  1653                 iContextMenuResourceId =
       
  1654                         R_MR_VIEWER_CONTEXT_MENU;
       
  1655                 }
       
  1656 
       
  1657             if ( !iFeatures->FeatureSupported(
       
  1658                     CESMRFeatureSettings::EESMRUIMnFwIntegration )
       
  1659                  && iContextMenuResourceId == R_MR_EDITOR_LOCATION_CONTEXT_MENU )
       
  1660                 {
       
  1661 #ifndef RD_USE_MYLOCATIONUI
       
  1662                 // Maps not supported and My Locations UI disabled
       
  1663                 ret = EFalse;
       
  1664 #endif //RD_USE_MYLOCATIONUI
       
  1665                 }
       
  1666             }
       
  1667             break;
       
  1668 
       
  1669         case EESMRFieldAttachments:
       
  1670             {
       
  1671             if ( Policy().FieldL(
       
  1672                     EESMRFieldAttachments ).iFieldMode
       
  1673                     == EESMRFieldModeEdit )
       
  1674                 {
       
  1675                 iContextMenuResourceId = R_MR_EDITOR_ATTACHMENT_CONTEXT_MENU;
       
  1676                 ret = ETrue;
       
  1677                 }
       
  1678             }
       
  1679             break;
       
  1680         case EESMRFieldAttendee:
       
  1681         case EESMRFieldOptAttendee:
       
  1682             {
       
  1683             if ( Policy().FieldL(
       
  1684                     EESMRFieldAttendee ).iFieldMode == EESMRFieldModeEdit  ||
       
  1685                  Policy().FieldL(
       
  1686                     EESMRFieldOptAttendee ).iFieldMode == EESMRFieldModeEdit )
       
  1687                 {
       
  1688                 iContextMenuResourceId = R_MR_EDITOR_ATTENDEE_CONTEXT_MENU;
       
  1689                 ret = ETrue;
       
  1690                 }
       
  1691             }
       
  1692             break;
       
  1693         default:
       
  1694             break;
       
  1695         }
       
  1696 
       
  1697     if ( ret )
       
  1698         {
       
  1699         iMenuBar->SetContextMenuTitleResourceId(
       
  1700                 iContextMenuResourceId );
       
  1701         }
       
  1702     else
       
  1703         {
       
  1704         iContextMenuResourceId = 0;
       
  1705         }
       
  1706 
       
  1707     return ret;
       
  1708     }
       
  1709 
       
  1710 // ---------------------------------------------------------------------------
       
  1711 // CESMREditorDialog::SwitchEntryTypeL
       
  1712 // ---------------------------------------------------------------------------
       
  1713 //
       
  1714 void CESMREditorDialog::SwitchEntryTypeL(
       
  1715         TInt aCommand,
       
  1716         TBool aAdjustView )
       
  1717     {
       
  1718     FUNC_LOG;
       
  1719     TBool change( EFalse );
       
  1720     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
  1721 
       
  1722     switch ( aCommand )
       
  1723         {
       
  1724         case EMRCommandSwitchToMR:
       
  1725             {
       
  1726             TBool ret( ETrue );
       
  1727 
       
  1728             // Show confirmation note if current mailbox does not
       
  1729             // support attachments and attachments exist in the entry
       
  1730             if( entry->Entry().AttachmentCountL() > 0 &&
       
  1731                     !SupportsMailBoxCapabilityL(
       
  1732                             MESMRBuilderExtension::
       
  1733                                 EMRCFSSupportsAttachmentsInMR ) )
       
  1734                 {
       
  1735                 if ( !CESMRConfirmationQuery::ExecuteL(
       
  1736                                    CESMRConfirmationQuery::
       
  1737                                        EESMRAttachmentsNotSupported ) )
       
  1738                     {
       
  1739                     ret = EFalse;
       
  1740                     }
       
  1741                 }
       
  1742 
       
  1743             if( ret )
       
  1744                 {
       
  1745                 change =
       
  1746                     ( entry->Type() !=
       
  1747                         MESMRCalEntry::EESMRCalEntryMeetingRequest );
       
  1748                 }
       
  1749 
       
  1750             break;
       
  1751             }
       
  1752         case EMRCommandSwitchToMeeting:
       
  1753             {
       
  1754             change =
       
  1755                 ( entry->Type() != MESMRCalEntry::EESMRCalEntryMeeting );
       
  1756             break;
       
  1757             }
       
  1758         case EMRCommandSwitchToMemo:
       
  1759             {
       
  1760             change =
       
  1761                 ( entry->Type() != MESMRCalEntry::EESMRCalEntryMemo );
       
  1762             break;
       
  1763             }
       
  1764         case EMRCommandSwitchToAnniversary:
       
  1765             {
       
  1766             change =
       
  1767                 ( entry->Type() != MESMRCalEntry::EESMRCalEntryAnniversary );
       
  1768             break;
       
  1769             }
       
  1770         case EMRCommandSwitchToTodo:
       
  1771             {
       
  1772             change =
       
  1773                 ( entry->Type() != MESMRCalEntry::EESMRCalEntryTodo);
       
  1774             break;
       
  1775             }
       
  1776         default:
       
  1777             {
       
  1778             break;
       
  1779             }
       
  1780         }
       
  1781 
       
  1782     if ( change )
       
  1783         {
       
  1784         iView->ExternalizeL(ETrue);
       
  1785         iStartTimeUtc = entry->Entry().StartTimeL().TimeUtcL();
       
  1786         iCallback.ProcessCommandL( aCommand );
       
  1787 
       
  1788         if( aAdjustView )
       
  1789             {
       
  1790             MESMRCalEntry* entry = iInfoProvider.EntryL();
       
  1791             iView->AdjustViewL( entry, Policy() );
       
  1792             SetTitleL();
       
  1793             }
       
  1794         }
       
  1795     }
       
  1796 
       
  1797 // ---------------------------------------------------------------------------
       
  1798 // CESMREditorDialog::Policy
       
  1799 // ---------------------------------------------------------------------------
       
  1800 //
       
  1801 const CESMRPolicy& CESMREditorDialog::Policy() const
       
  1802     {
       
  1803     FUNC_LOG;
       
  1804     return iInfoProvider.PolicyProvider().CurrentPolicy();
       
  1805     }
       
  1806 
       
  1807 // ---------------------------------------------------------------------------
       
  1808 // CESMREditorDialog::DynInitToolbarL
       
  1809 // ---------------------------------------------------------------------------
       
  1810 //
       
  1811 void CESMREditorDialog::DynInitToolbarL ( TInt /*aResourceId*/,
       
  1812         CAknToolbar* /*aToolbar*/ )
       
  1813     {
       
  1814 
       
  1815     }
       
  1816 
       
  1817 // ---------------------------------------------------------------------------
       
  1818 // CESMREditorDialog::OfferToolbarEventL
       
  1819 // ---------------------------------------------------------------------------
       
  1820 //
       
  1821 void CESMREditorDialog::OfferToolbarEventL ( TInt aCommand )
       
  1822     {
       
  1823     DoProcessCommandL(aCommand);
       
  1824     }
       
  1825 
       
  1826 
       
  1827 // ---------------------------------------------------------------------------
       
  1828 // CESMREditorDialog::SetTitleL
       
  1829 // ---------------------------------------------------------------------------
       
  1830 //
       
  1831 void CESMREditorDialog::SetTitleL ()
       
  1832     {
       
  1833     FUNC_LOG;
       
  1834 
       
  1835     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
  1836 
       
  1837     // Setting title to status pane's title pane
       
  1838     TInt titleStringId = -1;
       
  1839     switch ( entry->Type() )
       
  1840         {
       
  1841         case MESMRCalEntry::EESMRCalEntryMeetingRequest:
       
  1842             titleStringId = R_QTN_MEET_REQ_TITLE_MEETING;
       
  1843             break;
       
  1844         case MESMRCalEntry::EESMRCalEntryMeeting:
       
  1845             titleStringId = R_QTN_CALENDAR_TITLE_MEETING;
       
  1846             break;
       
  1847         case MESMRCalEntry::EESMRCalEntryTodo:
       
  1848             titleStringId = R_QTN_CALENDAR_TITLE_TODO;
       
  1849             break;
       
  1850         case MESMRCalEntry::EESMRCalEntryMemo:
       
  1851             titleStringId = R_QTN_CALENDAR_TITLE_MEMO;
       
  1852             break;
       
  1853         case MESMRCalEntry::EESMRCalEntryReminder:
       
  1854             break;
       
  1855         case MESMRCalEntry::EESMRCalEntryAnniversary:
       
  1856             titleStringId = R_QTN_CALENDAR_TITLE_ANNIVERSARY;
       
  1857             break;
       
  1858         default:
       
  1859             break;
       
  1860         }
       
  1861 
       
  1862     if ( titleStringId != -1 )
       
  1863         {
       
  1864         if( !iTitlePane )
       
  1865             {
       
  1866             iTitlePane = CESMRTitlePaneHandler::NewL( *iEikonEnv );
       
  1867             }
       
  1868 
       
  1869         HBufC* titleText = StringLoader::LoadLC( titleStringId, iCoeEnv );
       
  1870         iTitlePane->SetNewTitle( titleText );
       
  1871         CleanupStack::PopAndDestroy( titleText );
       
  1872         }
       
  1873 
       
  1874     // If subject does not exist, let's update the title also
       
  1875     // to main window
       
  1876     if( entry->Entry().SummaryL().Length() <= 0 )
       
  1877         {
       
  1878         HBufC* title ;
       
  1879         switch( entry->Type() )
       
  1880            {
       
  1881            case MESMRCalEntry::EESMRCalEntryTodo:
       
  1882                {
       
  1883                title = StringLoader::LoadLC ( R_QTN_CALENDAR_TITLE_NEW_TODO );
       
  1884                break;
       
  1885                }
       
  1886            case MESMRCalEntry::EESMRCalEntryMemo:
       
  1887                {
       
  1888                title = StringLoader::LoadLC ( R_QTN_CALENDAR_TITLE_NEW_MEMO );
       
  1889                break;
       
  1890                }
       
  1891            case MESMRCalEntry::EESMRCalEntryAnniversary:
       
  1892                {
       
  1893                title = StringLoader::LoadLC(R_QTN_CALENDAR_TITLE_NEW_ANNIVERSARY);
       
  1894                break;
       
  1895                }
       
  1896            case MESMRCalEntry::EESMRCalEntryMeetingRequest: // Fall through
       
  1897            case MESMRCalEntry::EESMRCalEntryMeeting: // Fall through
       
  1898            case MESMRCalEntry::EESMRCalEntryReminder: // Fall through
       
  1899            default:
       
  1900                {
       
  1901                title = StringLoader::LoadLC( R_QTN_MEET_REQ_TITLE );
       
  1902                break;
       
  1903                }
       
  1904            }
       
  1905         iView->SetTitleL( *title );
       
  1906         CleanupStack::PopAndDestroy( title );
       
  1907         }
       
  1908     }
       
  1909 
       
  1910 // ---------------------------------------------------------------------------
       
  1911 // CESMREditorDialog::VerifyMeetingRequestL
       
  1912 // ---------------------------------------------------------------------------
       
  1913 //
       
  1914 void CESMREditorDialog::VerifyMeetingRequestL()
       
  1915     {
       
  1916     FUNC_LOG;
       
  1917 
       
  1918     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
  1919 
       
  1920     // If entry is meeting request, but no attendees have been added,
       
  1921     // entry is switched to and saved as regular meeting
       
  1922     if( CCalenInterimUtils2::IsMeetingRequestL( entry->Entry() ) )
       
  1923         {
       
  1924         RPointerArray<CCalAttendee>& attendees(
       
  1925                 entry->Entry().AttendeesL() );
       
  1926 
       
  1927         TInt attendeeCount = attendees.Count();
       
  1928 
       
  1929         if( ( attendeeCount == 0 ) &&
       
  1930         	(iInfoProvider.PolicyProvider().CurrentPolicy().ViewMode() != EESMRForwardMR) )
       
  1931             {
       
  1932             TRAPD( err, SwitchEntryTypeL( EMRCommandSwitchToMeeting, EFalse ) )
       
  1933 
       
  1934             if ( err )
       
  1935                {
       
  1936                // UI and engine not consistent. Show error and exit
       
  1937                iCoeEnv->HandleError( err );
       
  1938                TryExitL( EESMRCmdForceExit );
       
  1939                }
       
  1940             }
       
  1941         }
       
  1942     }
       
  1943 
       
  1944 // -----------------------------------------------------------------------------
       
  1945 // CESMREditorDialog::ShowContextMenuL
       
  1946 // -----------------------------------------------------------------------------
       
  1947 //
       
  1948 void CESMREditorDialog::ShowContextMenuL()
       
  1949     {
       
  1950     FUNC_LOG;
       
  1951 
       
  1952     if ( iMenuBar )
       
  1953         {
       
  1954         iMenuBar->TryDisplayContextMenuBarL();
       
  1955         }
       
  1956     }
       
  1957 
       
  1958 
       
  1959 // -----------------------------------------------------------------------------
       
  1960 // CESMREditorDialog::OccursInPast
       
  1961 // -----------------------------------------------------------------------------
       
  1962 //
       
  1963 TBool CESMREditorDialog::OccursInPastL( const MESMRFieldEvent& aEvent )
       
  1964     {
       
  1965     FUNC_LOG;
       
  1966     MESMRFieldEventValue* value = static_cast< MESMRFieldEventValue* >( aEvent.Param( 1) );
       
  1967 
       
  1968     TCalTime startCalTime;
       
  1969     startCalTime.SetTimeLocalL( value->TimeValue() );
       
  1970 
       
  1971     iStartTimeUtc = startCalTime.TimeUtcL();
       
  1972 
       
  1973 	return OccursInPast( iStartTimeUtc );
       
  1974     }
       
  1975 
       
  1976 // -----------------------------------------------------------------------------
       
  1977 // CESMREditorDialog::OccursInPast
       
  1978 // -----------------------------------------------------------------------------
       
  1979 //
       
  1980 TBool CESMREditorDialog::OccursInPast( const TTime& aStartUtc )
       
  1981 	{
       
  1982     FUNC_LOG;
       
  1983 	TBool bOccursInPast(EFalse);
       
  1984 
       
  1985 	TTime now;
       
  1986     now.UniversalTime();
       
  1987 
       
  1988     if ( aStartUtc < now )
       
  1989     	{
       
  1990     	bOccursInPast = ETrue;
       
  1991     	}
       
  1992 
       
  1993     return bOccursInPast;
       
  1994 	}
       
  1995 
       
  1996 // -----------------------------------------------------------------------------
       
  1997 // CESMREditorDialog::ChangeRightSoftkeyL
       
  1998 // -----------------------------------------------------------------------------
       
  1999 //
       
  2000 void CESMREditorDialog::ChangeRightSoftkeyL( TBool aOccursInPast, TBool aIsOrganizer )
       
  2001 	{
       
  2002     FUNC_LOG;
       
  2003 	TBool sendEnabled = 
       
  2004 		( iRequiredAttendeesEnabled | iOptionalAttendeesEnabled ) && 
       
  2005 		!aOccursInPast && aIsOrganizer;
       
  2006 
       
  2007 	CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
  2008 	
       
  2009 	if( sendEnabled )
       
  2010 		{
       
  2011 		cba.SetCommandL(
       
  2012                 CEikButtonGroupContainer::ERightSoftkeyPosition,
       
  2013                 R_MR_SEND_SOFTKEY);
       
  2014 		cba.DrawDeferred();
       
  2015 		}
       
  2016 	else
       
  2017 		{
       
  2018 		cba.SetCommandL(
       
  2019                 CEikButtonGroupContainer::ERightSoftkeyPosition,
       
  2020                 R_MR_DONE_SOFTKEY);
       
  2021 		cba.DrawDeferred();   
       
  2022 		}	
       
  2023 	}
       
  2024 
       
  2025 // -----------------------------------------------------------------------------
       
  2026 // CESMREditorDialog::TryToSaveEntryL
       
  2027 // -----------------------------------------------------------------------------
       
  2028 //
       
  2029 TInt CESMREditorDialog::TryToSaveEntryL()
       
  2030     {
       
  2031     FUNC_LOG;
       
  2032     TInt res( KErrNone );
       
  2033     
       
  2034     MESMRCalEntry* entry = iInfoProvider.EntryL();
       
  2035 
       
  2036     if ( IsAllowedToSaveL() )
       
  2037         {
       
  2038         res = iCallback.ProcessCommandWithResultL( EESMRCmdSaveMR );
       
  2039 
       
  2040         if ( res == KErrNone
       
  2041              && iFeatures->FeatureSupported(
       
  2042                      CESMRFeatureSettings::EESMRUIPreviousLocationsList ) )
       
  2043             {
       
  2044             LocationPluginHandlerL().StoreLocationToHistoryL( *entry );
       
  2045             }
       
  2046             if ( entry->Type() == MESMRCalEntry::EESMRCalEntryTodo )
       
  2047                 {
       
  2048                 CESMRGlobalNote* note =
       
  2049                     CESMRGlobalNote::NewL(
       
  2050                             CESMRGlobalNote::EESMRTodoEntrySaved );
       
  2051                 note->ExecuteLD();
       
  2052                 }
       
  2053 			else if( entry->Type() == MESMRCalEntry::EESMRCalEntryMeetingRequest )
       
  2054 				{
       
  2055 				MESMRMeetingRequestEntry* mrEntry =
       
  2056 									static_cast<MESMRMeetingRequestEntry*>( entry );
       
  2057 				if( !mrEntry->IsForwardedL() )
       
  2058 					{
       
  2059 					CESMRGlobalNote* note =
       
  2060 								CESMRGlobalNote::NewL(
       
  2061 										CESMRGlobalNote::EESMREntrySaved );
       
  2062 					note->ExecuteLD();
       
  2063 					}
       
  2064 				}
       
  2065             else
       
  2066                 {
       
  2067                 CESMRGlobalNote* note =
       
  2068                     CESMRGlobalNote::NewL(
       
  2069                             CESMRGlobalNote::EESMREntrySaved );
       
  2070                 note->ExecuteLD();
       
  2071                 }
       
  2072         }
       
  2073     else
       
  2074         {
       
  2075         res = KErrCancel;
       
  2076         }
       
  2077     
       
  2078     return res;
       
  2079     }
       
  2080 
       
  2081 // EOF