calendarui/editors/src/calenunifiededitor.cpp
changeset 89 b57382753122
equal deleted inserted replaced
83:5aadd1120515 89:b57382753122
       
     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 : Class description for unified editor
       
    15 *
       
    16 */
       
    17 
       
    18 // user includes
       
    19 #include "calenunifiededitor.h"
       
    20 #include "CalenDefaultEditors.hrh"
       
    21 #include "calenglobaldata.h"
       
    22 #include "calenunifiededitorcontrol.h"
       
    23 #include "calendbfield.h"
       
    24 #include "calenlocationutil.h"
       
    25 #include "CalenEntryUpdater.h"
       
    26 #include "CalenEditorDataHandler.h"
       
    27 #include "calenentryutil.h"
       
    28 #include "calensend.h"
       
    29 #include "CalenDescription.h"
       
    30 #include "calenattachmentinfo.h"
       
    31 #include "calenattachmentmodel.h"
       
    32 #include "CleanupResetAndDestroy.h"
       
    33 #include "CalendarPrivateCRKeys.h"
       
    34 #include "KoreanLunarDateEditor.h"
       
    35 #include <featmgr.h>
       
    36 #include "CalenUid.h"
       
    37 
       
    38 // system includes
       
    39 #include <coemain.h>
       
    40 #include <eikdialg.h>
       
    41 #include <bacntf.h>
       
    42 #include <eikspane.h>
       
    43 #include <akntitle.h>
       
    44 #include <aknnavi.h>
       
    45 #include <eikcapc.h>
       
    46 #include <StringLoader.h>
       
    47 #include <featmgr.h>
       
    48 #include <hlplch.h>
       
    49 #include <AknQueryDialog.h>
       
    50 #include <AknUtils.h>
       
    51 #include <AknIconUtils.h>
       
    52 #include <aknlayoutscalable_apps.cdl.h>
       
    53 #include <eikrted.h>
       
    54 #include <txtrich.h>
       
    55 #include <aknnotewrappers.h>
       
    56 #include <sysutil.h>
       
    57 #include <ErrorUI.h>
       
    58 #include <EPos_CPosLandmark.h>
       
    59 #include <lbsposition.h>
       
    60 #include <calentry.h>
       
    61 #include <CalenDefaultEditorsData.rsg>
       
    62 #include <Calendar.rsg>
       
    63 #include <calenagendautils.h> // Need to conform the access.
       
    64 #include <calrrule.h>
       
    65 #include <calendateutils.h>
       
    66 #include <CalenInterimUtils2.h>
       
    67 #include <centralrepository.h>
       
    68 #include <calencommands.hrh>            // Calendar commands
       
    69 #include <calencontext.h>
       
    70 #include <caleninstanceid.h>            // TCalenInstanceId
       
    71 #include <calenservices.h>
       
    72 #include <calcalendarinfo.h>
       
    73 #include <vwsdef.h>
       
    74 
       
    75 // debug
       
    76 #include "calendarui_debug.h"
       
    77 
       
    78 const TInt KCalenMaxELAFTextEditorLength(160);
       
    79 const TInt KCalenMaxAPACTextEditorLength(70);
       
    80 
       
    81 // Custom id for command to close form without any checks.
       
    82 // We need just to close form without saving, when entry is deleted from options menu
       
    83 const TInt KCalenButtonIdCloseForm(-400);
       
    84 
       
    85 _LIT(KComma, ",");
       
    86 _LIT(KEmpty,"");
       
    87 _LIT(KAttachmentSeparator,"; ");
       
    88 _LIT( KReplaceWhitespaceChars, "\x0009\x000A\x000B\x000C\x000D\x2028\x2029" );
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CCalenUnifiedEditor::NewL
       
    92 // Two-phased constructor.
       
    93 // -----------------------------------------------------------------------------
       
    94 //  
       
    95 CCalenUnifiedEditor* CCalenUnifiedEditor::NewL( CCalEntry& aEntry,
       
    96                                                 const TAgnEntryUiInParams& aParams,
       
    97                                                 MAgnEntryUiCallback& aCallback,
       
    98                                                 TAgnEntryUiOutParams& aOutParams,
       
    99                                                 CalCommon::TRecurrenceRange aRepeatType)
       
   100     {
       
   101     TRACE_ENTRY_POINT;
       
   102     
       
   103     CCalenUnifiedEditor* self = 
       
   104         new (ELeave) CCalenUnifiedEditor( aEntry, aParams, aCallback, aOutParams, aRepeatType );
       
   105     CleanupStack::PushL( self );
       
   106     self->ConstructL();
       
   107     CleanupStack::Pop();
       
   108     
       
   109     TRACE_EXIT_POINT;
       
   110     return self;
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CCalenUnifiedEditor::NewL
       
   115 // Two-phased constructor.
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 CCalenUnifiedEditor* CCalenUnifiedEditor::NewL( CCalEntry& aEntry,
       
   119                                                 const TAgnEntryUiInParams& aParams,
       
   120                                                 MAgnEntryUiCallback& aCallback,
       
   121                                                 TAgnEntryUiOutParams& aOutParams )
       
   122     {
       
   123     TRACE_ENTRY_POINT;
       
   124 
       
   125     CCalenUnifiedEditor* self = 
       
   126         new (ELeave) CCalenUnifiedEditor( aEntry, aParams, aCallback, aOutParams );
       
   127     CleanupStack::PushL(self);
       
   128     self->ConstructL();
       
   129     CleanupStack::Pop();
       
   130     
       
   131     TRACE_EXIT_POINT;
       
   132     return self;
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CCalenUnifiedEditor::~CCalenUnifiedEditor
       
   137 // Destructor
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 CCalenUnifiedEditor::~CCalenUnifiedEditor()
       
   141     {
       
   142     TRACE_ENTRY_POINT;
       
   143 
       
   144 	iFetchedEntries.ResetAndDestroy();
       
   145 
       
   146     if( iGlobalData )
       
   147         {
       
   148         iGlobalData->Release();
       
   149         }
       
   150     
       
   151     // Remove default status pane
       
   152     if( iNaviContainer )
       
   153         {
       
   154         iNaviContainer->Pop();
       
   155         iNaviContainer = NULL;
       
   156         }
       
   157     
       
   158     if( iIdle )
       
   159         {
       
   160         delete iIdle;
       
   161         }
       
   162     iCoeEnv->RemoveFepObserver( *this );
       
   163     
       
   164     if( iServices )
       
   165         {
       
   166         iServices->CancelNotifications( this );
       
   167         }
       
   168     delete iLocaleChangeNotifier;
       
   169     delete iOriginalCalEntry;
       
   170     delete iEditorDataHandler;
       
   171     delete iEntryUpdater;
       
   172     delete iUnifiedEditorControl;
       
   173     
       
   174     iCollectionIds.Reset();
       
   175     
       
   176     iAsyncCallback->Cancel();
       
   177     delete iAsyncCallback;
       
   178     
       
   179     // Do not call UnInitializeLib() if InitalizeLib() leaves.
       
   180     if ( iFeatMgrInitialized )
       
   181         {
       
   182         // Frees the TLS. Must be done after FeatureManager is used.
       
   183         FeatureManager::UnInitializeLib();  
       
   184         }  
       
   185 
       
   186     
       
   187     TRACE_EXIT_POINT;
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CCalenUnifiedEditor::CCalenUnifiedEditor
       
   192 // Default constructor
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 CCalenUnifiedEditor::CCalenUnifiedEditor( CCalEntry& aEntry,
       
   196                      const TAgnEntryUiInParams& aParams,
       
   197                      MAgnEntryUiCallback& aCallback,
       
   198                      TAgnEntryUiOutParams& aOutParams,
       
   199                      CalCommon::TRecurrenceRange aRepeatType )
       
   200                 : iEditedCalEntry( aEntry ), iEntryUiInParams( aParams ), 
       
   201                 iEntryUiCallback( aCallback ), iEntryUiOutParams( aOutParams ),
       
   202                 iRepeatType( aRepeatType ), iEntryType( aEntry.EntryTypeL() ),
       
   203                 iHasChosenRepeatType( ETrue ), iIgnoreFirstLocaleChange( ETrue ),
       
   204                 iCurrentDurationDay( 0 ), iTwoSeconds( 2 )
       
   205 
       
   206 
       
   207     {
       
   208     TRACE_ENTRY_POINT;
       
   209     
       
   210     TRACE_EXIT_POINT;
       
   211     }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CCalenUnifiedEditor::CCalenUnifiedEditor
       
   215 // Default constructor
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 CCalenUnifiedEditor::CCalenUnifiedEditor( CCalEntry& aEntry,
       
   219                      const TAgnEntryUiInParams& aParams,
       
   220                      MAgnEntryUiCallback& aCallback,
       
   221                      TAgnEntryUiOutParams& aOutParams )
       
   222                 : iEditedCalEntry( aEntry ), iEntryUiInParams( aParams ),
       
   223                 iEntryUiCallback( aCallback ), iEntryUiOutParams( aOutParams ),
       
   224                 iRepeatType( CalCommon::EThisAndAll ),
       
   225                 iEntryType( aEntry.EntryTypeL() ),
       
   226                 iHasChosenRepeatType( EFalse ),
       
   227                 iIgnoreFirstLocaleChange( ETrue ),
       
   228                 iCurrentDurationDay( 0 ), iTwoSeconds( 2 )
       
   229 
       
   230                 
       
   231     {
       
   232     TRACE_ENTRY_POINT;
       
   233     TRACE_EXIT_POINT;
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CCalenUnifiedEditor::ConstructL
       
   238 // Second phase construction
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 void CCalenUnifiedEditor::ConstructL()
       
   242     {
       
   243     TRACE_ENTRY_POINT;
       
   244     
       
   245     // Construct dialog
       
   246     CAknDialog::ConstructL( R_CALEN_UNIFIED_EDITOR_MENUBAR );
       
   247     
       
   248     // Take a timestamp of the editors opening time - 2 seconds
       
   249     // We use this to compare against the last database change time
       
   250     // to determine if the current entry has been deleted through
       
   251     // another CCalSession
       
   252     iTimeStamp.UniversalTime();
       
   253     
       
   254     iGlobalData = CCalenGlobalData::InstanceL( iEntryUiInParams.iCalSession );
       
   255     
       
   256     iOriginalCalEntry = CCalenUnifiedEditor::CreateCopyL( iEditedCalEntry );
       
   257     
       
   258     // Setup title and status panes
       
   259     CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane();
       
   260     CAknTitlePane* tp = static_cast<CAknTitlePane*>( sp->ControlL( TUid::Uid(EEikStatusPaneUidTitle) ) );
       
   261     HBufC* titleText = StringLoader::LoadLC( R_QTN_CALE_UNIFIED_EDITOR_TITLE, iCoeEnv );
       
   262     tp->SetTextL( *titleText );
       
   263     CleanupStack::PopAndDestroy( titleText );
       
   264     
       
   265     // Put default, empty Status Pane.
       
   266     iNaviContainer = static_cast<CAknNavigationControlContainer *>( sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi) ) );
       
   267     iNaviContainer->PushDefaultL();
       
   268      
       
   269     // Connect to services, and register for notifications of
       
   270     // changes to the database.
       
   271     TInt services( iEntryUiInParams.iSpare );
       
   272     iServices = reinterpret_cast< MCalenServices* >( services );
       
   273     
       
   274     RArray<TCalenNotification> notificationArray;
       
   275     notificationArray.Append( ECalenNotifyEntryDeleted );
       
   276     notificationArray.Append( ECalenNotifyInstanceDeleted );
       
   277     notificationArray.Append( ECalenNotifyDeleteFailed );
       
   278     notificationArray.Append( ECalenNotifyEntryInstanceViewCreated );
       
   279     notificationArray.Append( ECalenNotifyExternalDatabaseChanged );
       
   280     notificationArray.Append( ECalenNotifyMapClosed );
       
   281     notificationArray.Append( ECalenNotifyAttachmentAdded );
       
   282     notificationArray.Append( ECalenNotifyAttachmentRemoved );
       
   283     notificationArray.Append( ECalenNotifyCalendarFileDeleted );
       
   284     
       
   285     
       
   286     iServices->RegisterForNotificationsL( this, notificationArray );
       
   287     notificationArray.Reset();
       
   288     
       
   289     GetAllCollectionidsL(iCollectionIds);
       
   290     
       
   291     iEditorDataHandler = CCalenEditorDataHandler::NewL( iEditedCalEntry,
       
   292                                                iEntryUiInParams.iInstanceDate,
       
   293                                                IsCreatingNewEntry(),
       
   294                                                MaxTextEditorLength(),
       
   295                                                *iServices , iCollectionIds);
       
   296     iEntryUpdater = CCalenEntryUpdater::NewL( *iServices , iCollectionIds);
       
   297     
       
   298     
       
   299 
       
   300     //iServices->EntryViewL(iServices->Context().InstanceId().iColId);
       
   301 
       
   302     iUnifiedEditorControl = CCalenUnifiedEditorControl::NewL( *this,*iServices );
       
   303     
       
   304     isReplaceLocation = EFalse;
       
   305     
       
   306     iCheck = EFalse;
       
   307     TCallBack callback(CCalenUnifiedEditor::AsyncProcessCommandL,this);
       
   308     iAsyncCallback = new(ELeave) CAsyncCallBack(callback,CActive::EPriorityStandard);
       
   309     
       
   310     
       
   311     iIdle = CIdle::NewL( CActive::EPriorityUserInput );
       
   312     iIdle->Start( TCallBack( KeyCallBack, this) );
       
   313     iCoeEnv->AddFepObserverL( *this );
       
   314     
       
   315     // Sets up TLS, must be done before FeatureManager is used.
       
   316     FeatureManager::InitializeLibL();
       
   317     // Used in destructor. 
       
   318     iFeatMgrInitialized = ETrue;
       
   319     
       
   320     TRACE_EXIT_POINT;
       
   321     }
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CCalenUnifiedEditor::ExecuteViewL
       
   325 // Dummy implementation. Use ExecuteLD() instead.
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 TInt CCalenUnifiedEditor::ExecuteViewL( RPointerArray<CCalEntry>& /*aEntries*/,
       
   329                                         const TAgnEntryUiInParams& /*aInParams*/,
       
   330                                         TAgnEntryUiOutParams& /*aOutParams*/,
       
   331                                         MAgnEntryUiCallback& /*aCallback*/ )
       
   332     {
       
   333     TRACE_ENTRY_POINT;
       
   334     TRACE_EXIT_POINT;
       
   335     return KErrNone;
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CCalenUnifiedEditor::SetHelpContext
       
   340 // Sets the help context.
       
   341 // (other items were commented in a header).
       
   342 // -----------------------------------------------------------------------------
       
   343 //
       
   344 void CCalenUnifiedEditor::SetHelpContext( const TCoeHelpContext& /*aContext*/ )
       
   345     {
       
   346     TRACE_ENTRY_POINT;
       
   347     TRACE_EXIT_POINT;
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CCalenUnifiedEditor::HandleNotification
       
   352 // Handles calendar notifications
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 void CCalenUnifiedEditor::HandleNotification( TCalenNotification aNotification )
       
   356     {
       
   357     TRACE_ENTRY_POINT;
       
   358     
       
   359     switch( aNotification )
       
   360         {
       
   361         case ECalenNotifyExternalDatabaseChanged:
       
   362             {
       
   363             iLastDbChangeNotification.UniversalTime();
       
   364             }
       
   365             break;
       
   366         case ECalenNotifyEntryDeleted:
       
   367             {
       
   368             iEntryUiOutParams.iAction = MAgnEntryUi::EMeetingDeleted;
       
   369             PIM_TRAPD_HANDLE( CloseFormWithoutActionsL() );
       
   370             }
       
   371             break;
       
   372         case ECalenNotifyInstanceDeleted:
       
   373             {
       
   374             iEntryUiOutParams.iAction = MAgnEntryUi::EInstanceDeleted;
       
   375             PIM_TRAPD_HANDLE( CloseFormWithoutActionsL() );
       
   376             }
       
   377             break;
       
   378         case ECalenNotifyMapClosed:
       
   379             {
       
   380             // User has closed the map, store/update necessary details
       
   381             PIM_TRAPD_HANDLE( UpdateLocationInfoToFormL() );
       
   382             }
       
   383             break;
       
   384         case ECalenNotifyDeleteFailed:
       
   385             {
       
   386             iEntryUiOutParams.iAction = MAgnEntryUi::ENoAction;
       
   387             }
       
   388             break;
       
   389         case ECalenNotifyAttachmentAdded:
       
   390         case ECalenNotifyAttachmentRemoved:    
       
   391             {
       
   392             // TODO: Uncomment this when enabling attachment support
       
   393             PIM_TRAPD_HANDLE( UpdateAttachmentInfoToEditorL() );
       
   394             }
       
   395             break;
       
   396     
       
   397         case ECalenNotifyEntryInstanceViewCreated:
       
   398             break;
       
   399         case ECalenNotifyCalendarFileDeleted:
       
   400             {
       
   401             TRAP_IGNORE(HandleCalendarDeleteL());
       
   402             }
       
   403             break;
       
   404         default:
       
   405             break;
       
   406         }
       
   407     TRACE_EXIT_POINT;
       
   408     }
       
   409 	
       
   410 	
       
   411 void CCalenUnifiedEditor::HandleCalendarDeleteL()
       
   412     {
       
   413             TPtrC fileNamePtr = iServices->Context().GetCalendarFileNameL();
       
   414     TInt index = iUnifiedEditorControl->GetCalendarNameForEntryL(fileNamePtr);
       
   415             if(index == KErrNotFound)
       
   416                 {
       
   417                 DisplayErrorMsgL( CCalenEditorDataHandler::EFormErrDbConflictEntryDeleted );
       
   418                 iEntryUiOutParams.iAction = EMeetingDeleted;
       
   419                 TryExitL( KCalenButtonIdCloseForm );
       
   420         }
       
   421     
       
   422     }
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // CCalenUnifiedEditor::InsertFieldL
       
   426 // Inserts dialog line (form field) defined by aResourceI
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 void CCalenUnifiedEditor::InsertFieldL( TInt aResourceId, TInt aControlId,
       
   430                                         TInt aPrevControlId )
       
   431     {
       
   432     TRACE_ENTRY_POINT;
       
   433 
       
   434     CCoeControl* prevControl = Control( aPrevControlId );
       
   435     __ASSERT_DEBUG( prevControl, User::Invariant() );
       
   436     TInt pos = FindLineIndex( *prevControl );
       
   437     pos = pos + 1;
       
   438     InsertLineL( pos, aResourceId );
       
   439     
       
   440     // We need to activate line, otherwise drawing doesn't work correctly
       
   441     Line( aControlId )->ActivateL();
       
   442     
       
   443     TRACE_EXIT_POINT;
       
   444     }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // CCalenUnifiedEditor::HasField
       
   448 // Check for field exists in unified editor
       
   449 // -----------------------------------------------------------------------------
       
   450 //
       
   451 TBool CCalenUnifiedEditor::HasField( TInt aField )
       
   452     {
       
   453     TRACE_ENTRY_POINT;
       
   454     TRACE_EXIT_POINT;
       
   455     return ControlOrNull( aField ) != NULL;
       
   456     }
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 // CCalenUnifiedEditor::UpdateFormL
       
   460 // Update form. You can force update of form with this,
       
   461 // if you modify some of the field values dynamically. 
       
   462 // -----------------------------------------------------------------------------
       
   463 //
       
   464 void CCalenUnifiedEditor::UpdateFormL()
       
   465     {
       
   466     TRACE_ENTRY_POINT;
       
   467     
       
   468     UpdatePageL(ETrue);
       
   469     
       
   470     TRACE_EXIT_POINT;
       
   471     }
       
   472 
       
   473 // --------------------------------------------------------------------------
       
   474 // CreateCopyL
       
   475 // Create a copy of the given entry.
       
   476 // --------------------------------------------------------------------------
       
   477 //
       
   478 CCalEntry* CCalenUnifiedEditor::CreateCopyL( CCalEntry& aOther )
       
   479     {
       
   480     TRACE_ENTRY_POINT;
       
   481 
       
   482     HBufC8* guid = aOther.UidL().AllocLC();
       
   483     CCalEntry* entry;
       
   484     if( aOther.RecurrenceIdL().TimeUtcL() != Time::NullTTime() )
       
   485         {
       
   486         entry = CCalEntry::NewL( aOther.EntryTypeL(), guid,
       
   487                                  aOther.MethodL(),
       
   488                                  aOther.SequenceNumberL(),
       
   489                                  aOther.RecurrenceIdL(),
       
   490                                  aOther.RecurrenceRangeL() );
       
   491         }
       
   492     else
       
   493         {
       
   494         entry = CCalEntry::NewL( aOther.EntryTypeL(), guid,
       
   495                                  aOther.MethodL(),
       
   496                                  aOther.SequenceNumberL() );
       
   497         }
       
   498     CleanupStack::Pop( guid ); // ownership was passed
       
   499     CleanupStack::PushL( entry );
       
   500     aOther.DescriptionL();  // make sure entry is fully loaded
       
   501     entry->CopyFromL( aOther );
       
   502     entry->DescriptionL();  // make sure entry is fully copied
       
   503     CleanupStack::Pop( entry );
       
   504 
       
   505     TRACE_EXIT_POINT;
       
   506     return entry;
       
   507     }
       
   508 
       
   509 // -----------------------------------------------------------------------------
       
   510 // CCalenUnifiedEditor::OkToExitL
       
   511 // Handles exiting of the unified editor
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 TBool CCalenUnifiedEditor::OkToExitL( TInt aButtonId )
       
   515     {
       
   516     TRACE_ENTRY_POINT;
       
   517     TBool isExitForm( ETrue );
       
   518     TBool active = EFalse;
       
   519 	
       
   520     TCalCollectionId colId = iEditorDataHandler->CurrentDbCollectionId(); 
       
   521     VerifyCollectionIdL(colId);
       
   522     
       
   523 	TInt newCtrlId=IdOfFocusControl();
       
   524     switch ( aButtonId )
       
   525         {
       
   526         case EAknSoftkeyChange:
       
   527             {
       
   528             isExitForm=EFalse;
       
   529 
       
   530             // to Handle MSK key 'Change'
       
   531 			if(newCtrlId == ECalenEditorEventType || newCtrlId == ECalenEditorRepeat
       
   532 			                                      || newCtrlId == ECalenEditorDBName
       
   533 			                                      || newCtrlId == ECalenEditorPriority)
       
   534 				{
       
   535 				
       
   536 	            CEikCaptionedControl* line=CurrentLine();
       
   537 	            TInt type=line->iControlType;
       
   538 	            TBool isPopUp=( type && EAknCtPopupField ) || ( type == EAknCtPopupFieldText );
       
   539 	            if (isPopUp)
       
   540 	                {
       
   541 	                CAknPopupField* ctrl = static_cast<CAknPopupField*>( line->iControl );
       
   542 	                ctrl->ActivateSelectionListL();
       
   543 	                }
       
   544 				}
       
   545 			else if( newCtrlId == ECalenEditorReminder ) 
       
   546                 {
       
   547                 if( iUnifiedEditorControl->IsAlarmActiveInForm() )
       
   548                     { 
       
   549                     SetAlarmFieldOnOffL( EFalse );           
       
   550                     active = EFalse;
       
   551                     } 
       
   552                 else
       
   553                     {
       
   554                     SetAlarmFieldOnOffL( ETrue );                
       
   555                     active = ETrue;
       
   556                     }
       
   557                 iUnifiedEditorControl->CheckAlarmActive( active );
       
   558                 TryChangeFocusToL( ECalenEditorReminder );
       
   559                 }
       
   560             else if( newCtrlId == ECalenEditorAllDayItem )
       
   561                 {
       
   562                 if( iUnifiedEditorControl->IsAllDayEvent() )
       
   563                     {
       
   564                     SetAllDayFieldL( EFalse );
       
   565                     active = EFalse;
       
   566                     }
       
   567                 else
       
   568                     {
       
   569                     SetAllDayFieldL( ETrue );
       
   570                     active = ETrue;
       
   571                     }
       
   572                 iUnifiedEditorControl->SetAllDayEventL( active );
       
   573                 
       
   574                 }
       
   575             break;
       
   576             }
       
   577         case EAknSoftkeyOptions:
       
   578             {
       
   579             DisplayMenuL();
       
   580             isExitForm = EFalse;
       
   581             break;
       
   582             }
       
   583         case KCalenButtonIdCloseForm:
       
   584             {
       
   585             // Do nothing, just close.
       
   586             // This is called when entry is deleted
       
   587             // via menu or clearing texts
       
   588             isExitForm = ETrue;
       
   589             break;
       
   590             }
       
   591         case ECalenCmdCloseDialog:
       
   592              {
       
   593              // Forced close of the dialog when calendar is reopened from the 
       
   594              // command line.  We do not want to update calendars stored focus
       
   595              // in case we override any command line parameters
       
   596              // Intentional fall through to EEikBidCancel below
       
   597              iEntryUiOutParams.iAction = ENoAction;
       
   598              iEntryUiOutParams.iSpare = 0;
       
   599              MCalenContext& context = iServices->Context();
       
   600              HBufC* fileNamePtr = context.GetCalAlarmEntryFileNameL();             
       
   601              TCalLocalUid localUid = context.CalAlarmLocalUidL();           
       
   602              if (fileNamePtr != NULL && !fileNamePtr->CompareF(iGlobalData->GetCalFileNameForCollectionId(context.InstanceId().iColId)) 
       
   603                      && localUid == context.InstanceId().iEntryLocalUid)
       
   604                  {
       
   605                  context.ResetCalAlarmEntryFileName();
       
   606                  break;
       
   607                  }
       
   608              // Fall through...
       
   609              }
       
   610          case ECalenEditSeries:
       
   611          case ECalenEditOccurrence:
       
   612          case EAknCmdExit:
       
   613          case EAknSoftkeyExit:
       
   614          case EEikBidCancel:
       
   615              {
       
   616              // EEikBidCancel is called when Red End key is pressed or
       
   617              // MMC card is taken out or application is killed via Swap Window
       
   618              // EAknCmdExit is called, when user selects Options->Exit
       
   619              //   (see OnCmdExit)
       
   620 
       
   621              // At this point, CAknShutter fires us EEikBidCancel key events
       
   622              // offering it to our dialog control. Firing key events continues
       
   623              // until our dialog is closed, which is detected by FW.                    
       
   624 
       
   625              // Entry can't be stored if EntryView does not exist. 
       
   626              // Will exit and lose some data if entry was really edited.
       
   627             
       
   628              if( iServices->EntryViewL(colId) )
       
   629                  {
       
   630                  PIM_TRAPD_HANDLE( TryToSaveNoteOnForcedExitL() );
       
   631                  iCheck = EFalse;
       
   632                  }
       
   633              if(EAknSoftkeyExit == aButtonId)
       
   634                  iServices->IssueCommandL(aButtonId);
       
   635              
       
   636              break;
       
   637              }
       
   638          case EAknSoftkeyDone:
       
   639              {
       
   640              // Need an entry view before starting to
       
   641              // handle the done button. 
       
   642              if( iServices->EntryViewL(colId) )
       
   643                  {
       
   644                  isExitForm = HandleDoneL();
       
   645                  }
       
   646              else
       
   647                  {
       
   648                  // The entry view has not been constructed yet
       
   649                  //iCreatingEntryView = EFalse;
       
   650                  isExitForm = EFalse;
       
   651                  } 
       
   652              }
       
   653              break;
       
   654          case ECalenGetLocation:
       
   655         	{
       
   656         	// Issue command to framework to launch the map
       
   657         	isExitForm=EFalse;
       
   658         	ReadPlaceFromEditorL(); // to remove any picture characters in location string
       
   659             TBuf<ECalenAbsoluteMaxTextEditorLength> location;
       
   660             GetEdwinText(location, ECalenEditorPlace);
       
   661             CCalGeoValue* geoValue = iEditorDataHandler->Entry().GeoValueL();
       
   662             if(geoValue)
       
   663                 {
       
   664                 CPosLandmark* landmark = CPosLandmark::NewL();
       
   665                 landmark->SetLandmarkNameL(location);
       
   666                 TReal latitude;
       
   667                 TReal longitude;
       
   668                 geoValue->GetLatLong(latitude, longitude);
       
   669                 TPosition position;
       
   670                 position.SetCoordinate(latitude, longitude);
       
   671                 landmark->SetPositionL(position);
       
   672                 delete geoValue;
       
   673                 MCalenContext& context = iServices->Context();
       
   674                 context.SetLandMark(landmark);
       
   675                 }
       
   676             else if(location.Length())
       
   677                 {
       
   678                 CPosLandmark* landmark = CPosLandmark::NewL();
       
   679                 landmark->SetLandmarkNameL(location);
       
   680                 MCalenContext& context = iServices->Context();
       
   681                 context.SetLandMark(landmark);
       
   682                 }
       
   683             iServices->IssueCommandL(ECalenGetLocation);
       
   684         	}
       
   685             break;
       
   686          default:
       
   687              isExitForm = EFalse;
       
   688              break;
       
   689         }
       
   690     TRACE_EXIT_POINT;
       
   691     return isExitForm;
       
   692     }
       
   693           
       
   694 // -----------------------------------------------------------------------------
       
   695 // CCalenUnifiedEditor::OfferKeyEventL
       
   696 // Handles key events
       
   697 // -----------------------------------------------------------------------------
       
   698 //
       
   699 TKeyResponse CCalenUnifiedEditor::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   700                                                   TEventCode aType )
       
   701     {
       
   702     
       
   703      TRACE_ENTRY_POINT;
       
   704     TKeyResponse keyResponse( EKeyWasNotConsumed );
       
   705     TInt ctrlid=IdOfFocusControl();
       
   706    
       
   707     /* If KeyCallBack has not been called after construction 
       
   708      * (= initialization of iIdle) call it now to 
       
   709      * handle key event queue.
       
   710      */
       
   711     if ( iIdle )
       
   712         {
       
   713         KeyCallBack( this );
       
   714         }
       
   715     
       
   716     if ( aType == EEventKey )
       
   717         {
       
   718         switch ( aKeyEvent.iCode )
       
   719             {
       
   720             case EKeyOK:
       
   721                 // TODO: Uncomment this when enabling attachment support
       
   722                 
       
   723                 if(ctrlid == ECalenEditorAttachment)
       
   724                     {
       
   725                     if(Edited().AttachmentCount() || iServices->GetAttachmentData()->NumberOfItems())
       
   726                         {
       
   727                         iServices->IssueCommandL( ECalenViewAttachmentList );
       
   728                         }
       
   729                     else
       
   730                         {
       
   731                         iServices->IssueCommandL( ECalenAddAttachment );
       
   732                         }
       
   733                     }
       
   734                 else if ( ctrlid == ECalenEditorAllDayItem )
       
   735                     {
       
   736                     // Tap on AllDay field, Switch the status of AllDay field  
       
   737                     iUnifiedEditorControl->SetAllDayEventL(
       
   738                             !( iUnifiedEditorControl->IsAllDayEvent() ) );
       
   739                     }
       
   740                 else if ( ctrlid == ECalenEditorReminder )
       
   741                     {
       
   742                     TBool active;
       
   743                     if( iUnifiedEditorControl->IsAlarmActiveInForm() )
       
   744                         { 
       
   745                         SetAlarmFieldOnOffL( EFalse );           
       
   746                         active = EFalse;
       
   747                         } 
       
   748                     else
       
   749                         {
       
   750                         SetAlarmFieldOnOffL( ETrue );                
       
   751                         active = ETrue;
       
   752                         }
       
   753                     iUnifiedEditorControl->CheckAlarmActive( active );
       
   754                     }
       
   755                 else
       
   756                     {
       
   757                         keyResponse = CAknForm::OfferKeyEventL( aKeyEvent, aType );    
       
   758                     }
       
   759                 break;
       
   760             case EKeyEscape:
       
   761                 // Calendar relaunched from cmd line - close viewer
       
   762                 // NOTE: This was changed from EAknCmdExit to ECalenCmdCloseDialog since launching
       
   763                 // the calanedar from cmd line or opening missed alarm view while calendar editor is
       
   764                 // opened is closing the application.
       
   765                 TryExitL( ECalenCmdCloseDialog );
       
   766                 keyResponse = EKeyWasConsumed;
       
   767                 break;
       
   768             case EKeyEnter: // For Enter key
       
   769                 {
       
   770                 if(ctrlid == ECalenEditorAttachment)
       
   771                     {
       
   772                     if(Edited().AttachmentCount() || iServices->GetAttachmentData()->NumberOfItems())
       
   773                         {
       
   774                         iServices->IssueCommandL( ECalenViewAttachmentList );
       
   775                         }
       
   776                     else
       
   777                         {
       
   778                         iServices->IssueCommandL( ECalenAddAttachment );
       
   779                         }
       
   780                     }
       
   781                 keyResponse = CAknForm::OfferKeyEventL(aKeyEvent,aType); // Let framework handle the key event
       
   782                 }
       
   783                 break;
       
   784             case EKeyDelete: // For Delete key
       
   785 				{
       
   786 				keyResponse = CAknForm::OfferKeyEventL(aKeyEvent,aType); // Let framework handle the key event
       
   787 				}
       
   788 				break;
       
   789 			case EKeyBackspace:  // For back space character
       
   790 				{
       
   791 				if(ctrlid == ECalenEditorPlace || ECalenEditorSubject)
       
   792 					{
       
   793 					keyResponse = CAknForm::OfferKeyEventL(aKeyEvent,aType);
       
   794 					}
       
   795 				break;
       
   796 				}
       
   797             case EKeyLeftArrow:
       
   798             case EKeyRightArrow:
       
   799                 {
       
   800                 if( ECalenEditorEventType == IdOfFocusControl() )
       
   801                     {
       
   802                     keyResponse = EKeyWasConsumed; 
       
   803                     }
       
   804                 else
       
   805                     {
       
   806                     keyResponse = CAknForm::OfferKeyEventL( aKeyEvent, aType );    
       
   807                     }
       
   808                 }
       
   809                 break;
       
   810  
       
   811             default:
       
   812                 {
       
   813                 keyResponse = CAknForm::OfferKeyEventL(aKeyEvent,aType); 
       
   814                 }
       
   815                 break;
       
   816             }
       
   817         }
       
   818         
       
   819     // For handling geokeys on corolla hardware
       
   820 	// For Add location hard key
       
   821 	if( aKeyEvent.iScanCode == EStdKeyApplication1C && aType == EEventKeyUp )
       
   822 		{
       
   823 		if(CCalenLocationUtil::IsMapProviderAvailableL())
       
   824 			{
       
   825 			TryChangeFocusToL(ECalenEditorPlace);
       
   826 			ReadPlaceFromEditorL(); // to remove any picture characters in location string
       
   827 			TBuf<ECalenAbsoluteMaxTextEditorLength> location;
       
   828 			GetEdwinText(location, ECalenEditorPlace);
       
   829 			CPosLandmark* landmark = NULL;
       
   830 			if(location.Length())
       
   831 				{
       
   832 				landmark = CPosLandmark::NewL();
       
   833 				landmark->SetLandmarkNameL(location);
       
   834 				}
       
   835 				CCalGeoValue* geoValue = iEditorDataHandler->Entry().GeoValueL();
       
   836 				if(geoValue)
       
   837 					{
       
   838 					if(!landmark)
       
   839 						{
       
   840 						landmark = CPosLandmark::NewL();
       
   841 						}
       
   842 					TReal latitude;
       
   843 					TReal longitude;
       
   844 					geoValue->GetLatLong(latitude, longitude);
       
   845 					TPosition position;
       
   846 					position.SetCoordinate(latitude, longitude);
       
   847 					landmark->SetPositionL(position);
       
   848 					delete geoValue;
       
   849 					}
       
   850 				MCalenContext& context = iServices->Context();
       
   851 				context.SetLandMark(landmark);	
       
   852 			iServices->IssueCommandL(ECalenGetLocation);
       
   853 			keyResponse = EKeyWasConsumed;
       
   854 			}
       
   855 		}
       
   856 	// For Show location hard key
       
   857 	else if( aKeyEvent.iScanCode == EStdKeyApplication1B && aType == EEventKeyUp )
       
   858 		{
       
   859 		ReadPlaceFromEditorL();
       
   860 		TBuf<ECalenAbsoluteMaxTextEditorLength> location;
       
   861 		GetEdwinText(location, ECalenEditorPlace);
       
   862 		if(CCalenLocationUtil::IsMapProviderAvailableL())
       
   863 			{
       
   864 			TryChangeFocusToL(ECalenEditorPlace);
       
   865 			MCalenContext& context = iServices->Context();
       
   866 			CCalGeoValue* geoValue = iEditorDataHandler->Entry().GeoValueL();
       
   867 			if(geoValue)
       
   868 				{
       
   869 				CPosLandmark* landmark = CPosLandmark::NewL();
       
   870 				landmark->SetLandmarkNameL(location);
       
   871 				TReal latitude;
       
   872 				TReal longitude;
       
   873 				geoValue->GetLatLong(latitude, longitude);
       
   874 				TPosition position;
       
   875 				position.SetCoordinate(latitude, longitude);
       
   876 				landmark->SetPositionL(position);
       
   877 				context.SetLandMark(landmark);
       
   878 				iServices->IssueCommandL(ECalenShowLocation);
       
   879 				delete geoValue;
       
   880 				}
       
   881 			else if(location.Length())
       
   882 				{
       
   883 				CPosLandmark* landmark = CPosLandmark::NewL();
       
   884 				landmark->SetLandmarkNameL(location);
       
   885 				context.SetLandMark(landmark);
       
   886 				isReplaceLocation = ETrue;
       
   887 				iServices->IssueCommandL(ECalenGetLocation);
       
   888 				}
       
   889 			keyResponse = EKeyWasConsumed;
       
   890 			}
       
   891 		}
       
   892 		
       
   893 		// Swallow all other keyevents to prevent the active container processing them.
       
   894     keyResponse = EKeyWasConsumed;
       
   895 
       
   896     TRACE_EXIT_POINT;
       
   897     return keyResponse;    
       
   898     }
       
   899 
       
   900 // -----------------------------------------------------------------------------
       
   901 // CCalenUnifiedEditor::HandleCompletionOfTransactionL
       
   902 // Is called when fep transaction has been completed. If this
       
   903 // happens before key event queue has been simulated, events in 
       
   904 // key buffer must be ignored. If key events are simulated after this
       
   905 // result is duplicate characters or wrong order of characters.
       
   906 // (other items were commented in a header).
       
   907 // -----------------------------------------------------------------------------
       
   908 void CCalenUnifiedEditor::HandleCompletionOfTransactionL()
       
   909     {
       
   910     TRACE_ENTRY_POINT;
       
   911     if( iIdle )
       
   912         {
       
   913         delete iIdle;
       
   914         iIdle = NULL;
       
   915         iServices->ResetKeyEventQueue();/*ignore all events*/
       
   916         }
       
   917     TRACE_EXIT_POINT;
       
   918     }
       
   919 
       
   920 // -----------------------------------------------------------------------------
       
   921 // CCalenUnifiedEditor::KeyCallBack
       
   922 // Handles key events in key event queue
       
   923 // (other items were commented in a header).
       
   924 // -----------------------------------------------------------------------------
       
   925 TInt CCalenUnifiedEditor::KeyCallBack( TAny *aSelf )
       
   926     {
       
   927     TRACE_ENTRY_POINT;
       
   928     CCalenUnifiedEditor *self = static_cast<CCalenUnifiedEditor*>( aSelf );
       
   929     delete self->iIdle;
       
   930     self->iIdle = NULL;
       
   931 
       
   932     TKeyEvent event;
       
   933     TEventCode type;
       
   934 
       
   935     while( self->iServices->GetQueuedKeyEvent( event, type ) )
       
   936         {
       
   937         TRAPD(err,
       
   938               self->iCoeEnv->SimulateKeyEventL( event, type );
       
   939               );
       
   940         if ( err != KErrNone )
       
   941             {
       
   942             CEikEdwin* edwin = static_cast<CEikEdwin*>( self->Control( self->IdOfFocusControl() ) );
       
   943             edwin->CancelFepTransaction(); // indispensable to avoid crash
       
   944             self->iCoeEnv->HandleError( err );
       
   945             }
       
   946         }
       
   947     TRACE_EXIT_POINT;
       
   948     return EFalse;
       
   949     }
       
   950 
       
   951 // -----------------------------------------------------------------------------
       
   952 //  CCalenUnifiedEditor::LocaleCallback
       
   953 //  This function is called when a locale(or today) is changed.
       
   954 // -----------------------------------------------------------------------------
       
   955 //
       
   956 TInt CCalenUnifiedEditor::LocaleCallback( TAny* aThisPtr ) // A CCalenFormBase pointer
       
   957     {
       
   958     TRACE_ENTRY_POINT;
       
   959     CCalenUnifiedEditor* unifiededitor = static_cast<CCalenUnifiedEditor*>( aThisPtr );
       
   960 
       
   961     if( unifiededitor->iIgnoreFirstLocaleChange )
       
   962         {
       
   963         // Ignore the first locale change so we don't rebuild for no reason.
       
   964         unifiededitor->iIgnoreFirstLocaleChange = EFalse;
       
   965         TRACE_ENTRY_POINT;
       
   966         return EFalse;
       
   967         }
       
   968 
       
   969     TRACE_EXIT_POINT;
       
   970     return unifiededitor->HandleLocaleChange( unifiededitor->iLocaleChangeNotifier->Change() );
       
   971     }
       
   972 
       
   973 // -----------------------------------------------------------------------------
       
   974 //  CCalenUnifiedEditor::HandleLocaleChange
       
   975 //  CCalenUnifiedEditor::LocaleCallback() methods calls this method
       
   976 // -----------------------------------------------------------------------------
       
   977 //
       
   978 TInt CCalenUnifiedEditor::HandleLocaleChange( TInt aChange )
       
   979     {
       
   980     TRACE_ENTRY_POINT;
       
   981     
       
   982     PIM_TRAPD_HANDLE( DoHandleLocaleChangeL( aChange ) );
       
   983     
       
   984     TRACE_EXIT_POINT;
       
   985     return FALSE;    
       
   986     }
       
   987 
       
   988 // -----------------------------------------------------------------------------
       
   989 //  CCalenUnifiedEditor::DoHandleLocaleChange
       
   990 //  HandleLocaleChange calls this function
       
   991 // -----------------------------------------------------------------------------
       
   992 //
       
   993 void CCalenUnifiedEditor::DoHandleLocaleChangeL( TInt aChange )
       
   994     {
       
   995     TRACE_ENTRY_POINT;
       
   996 
       
   997     if( aChange & EChangesSystemTime )
       
   998         {
       
   999         // System time zone change.  Recreate the handler, so that
       
  1000         // the new local time is shown in the viewer.
       
  1001         if( !IsCreatingNewEntry() )
       
  1002             {
       
  1003             if( !iEditorDataHandler->IsEditedL() )
       
  1004                 {
       
  1005                 delete iEditorDataHandler;
       
  1006                 iEditorDataHandler = NULL;
       
  1007                 iEditorDataHandler = CCalenEditorDataHandler::NewL( iEditedCalEntry,
       
  1008                                                   iEntryUiInParams.iInstanceDate,
       
  1009                                                   IsCreatingNewEntry(),
       
  1010                                                   MaxTextEditorLength(),
       
  1011                                                   *iServices ,iCollectionIds);
       
  1012                 }
       
  1013             else
       
  1014                 {
       
  1015                 iEditorDataHandler->ResetOriginalDataL();
       
  1016                 }
       
  1017             }
       
  1018         iUnifiedEditorControl->SetDataToEditorL(ETrue);
       
  1019         }
       
  1020 
       
  1021     if ( aChange & EChangesLocale )
       
  1022         {
       
  1023         iUnifiedEditorControl->ReadDataFromEditorL( ETrue );
       
  1024         iUnifiedEditorControl->UpdateLinesOnLocaleChangeL();
       
  1025         }
       
  1026     TRACE_EXIT_POINT;
       
  1027     }
       
  1028 
       
  1029 // -----------------------------------------------------------------------------
       
  1030 // CCalenUnifiedEditor::PreLayoutDynInitL
       
  1031 // Initializes the dialog's controls before the dialog is sized
       
  1032 // -----------------------------------------------------------------------------
       
  1033 //
       
  1034 void CCalenUnifiedEditor::PreLayoutDynInitL()
       
  1035     {
       
  1036     TRACE_ENTRY_POINT;
       
  1037 
       
  1038     iUnifiedEditorControl->MakeUnifiedEditorL();
       
  1039     // Hides Entry type and Calendar Field for exceptional entry/single
       
  1040     // instance of recurrent entry.
       
  1041     HideFieldsForEditSingleInstanceL();
       
  1042 
       
  1043     TRACE_EXIT_POINT;         
       
  1044     }
       
  1045         
       
  1046 // -----------------------------------------------------------------------------
       
  1047 // CCalenUnifiedEditor::PostLayoutDynInitL
       
  1048 // Initializes the dialog's controls after the dialog has been sized 
       
  1049 // -----------------------------------------------------------------------------
       
  1050 //
       
  1051 void CCalenUnifiedEditor::PostLayoutDynInitL()
       
  1052     {
       
  1053     TRACE_ENTRY_POINT;
       
  1054     
       
  1055     SetEditableL(ETrue);
       
  1056 
       
  1057     TCallBack callback( LocaleCallback, this );
       
  1058     iLocaleChangeNotifier =
       
  1059         CEnvironmentChangeNotifier::NewL( EActivePriorityLogonA, callback );
       
  1060 
       
  1061     iLocaleChangeNotifier->Start();
       
  1062     
       
  1063     TRACE_EXIT_POINT;     
       
  1064     }
       
  1065 
       
  1066 // -----------------------------------------------------------------------------
       
  1067 // CCalenUnifiedEditor::HandleControlStateChangeL
       
  1068 // IHandles a state change in the control with id aControlId.
       
  1069 // -----------------------------------------------------------------------------
       
  1070 //
       
  1071 void CCalenUnifiedEditor::HandleControlStateChangeL( TInt aControlId )
       
  1072     {
       
  1073     TRACE_ENTRY_POINT;
       
  1074     
       
  1075     iUnifiedEditorControl->HandleControlStateChangeL( aControlId );
       
  1076     
       
  1077     TRACE_EXIT_POINT;
       
  1078     }
       
  1079 
       
  1080 // -----------------------------------------------------------------------------
       
  1081 // CCalenUnifiedEditor::PrepareForFocusTransitionL
       
  1082 // Tries to change focus to the specified line.
       
  1083 // -----------------------------------------------------------------------------
       
  1084 //
       
  1085 void CCalenUnifiedEditor::PrepareForFocusTransitionL()
       
  1086     {
       
  1087     TRACE_ENTRY_POINT;
       
  1088     
       
  1089     CEikDialog::PrepareForFocusTransitionL();
       
  1090     
       
  1091     iUnifiedEditorControl->PrepareForFocusTransitionL( IdOfFocusControl() );
       
  1092 
       
  1093     TRACE_EXIT_POINT;
       
  1094     }
       
  1095 
       
  1096 // -----------------------------------------------------------------------------
       
  1097 // CCalenUnifiedEditor::ActivateL
       
  1098 // Try to change item focus here 
       
  1099 // -----------------------------------------------------------------------------
       
  1100 //
       
  1101 void CCalenUnifiedEditor::ActivateL()
       
  1102     {
       
  1103     TRACE_ENTRY_POINT;
       
  1104     
       
  1105     CAknForm::ActivateL();
       
  1106     TryChangeFocusToL( ECalenEditorSubject );
       
  1107     
       
  1108     TRACE_EXIT_POINT;
       
  1109     }
       
  1110 
       
  1111 // -----------------------------------------------------------------------------
       
  1112 // CCalenUnifiedEditor::ProcessCommandL
       
  1113 // Handles editor menu commands
       
  1114 // -----------------------------------------------------------------------------
       
  1115 //
       
  1116 void CCalenUnifiedEditor::ProcessCommandL( TInt aCommandId )
       
  1117     {
       
  1118     TRACE_ENTRY_POINT;
       
  1119 
       
  1120     HideMenu();
       
  1121     switch( aCommandId )
       
  1122         {
       
  1123         case ECalenCmdCancel:
       
  1124             OnCmdCancelL();
       
  1125             break;
       
  1126         case ECalenDeleteCurrentEntry:
       
  1127             OnCmdDeleteNoteL();
       
  1128             break;
       
  1129         case EAknCmdExit:
       
  1130         case EAknSoftkeyExit:            
       
  1131             OnCmdExitL(aCommandId);
       
  1132             break;
       
  1133         case EAknCmdHelp:
       
  1134             OnCmdHelpL();
       
  1135             break;
       
  1136         case ECalenGetLocation:
       
  1137           {
       
  1138             ReadPlaceFromEditorL(); // to remove any picture characters in location string
       
  1139         	TBuf<ECalenAbsoluteMaxTextEditorLength> location;
       
  1140     		GetEdwinText(location, ECalenEditorPlace);
       
  1141         	CCalGeoValue* geoValue = iEditorDataHandler->Entry().GeoValueL();
       
  1142         	if(geoValue)
       
  1143         		{
       
  1144         		CPosLandmark* landmark = CPosLandmark::NewL();
       
  1145         		landmark->SetLandmarkNameL(location);
       
  1146         		TReal latitude;
       
  1147 				TReal longitude;
       
  1148 				geoValue->GetLatLong(latitude, longitude);
       
  1149         		TPosition position;
       
  1150         		position.SetCoordinate(latitude, longitude);
       
  1151         		landmark->SetPositionL(position);
       
  1152         		delete geoValue;
       
  1153         		MCalenContext& context = iServices->Context();
       
  1154         		context.SetLandMark(landmark);
       
  1155         		}
       
  1156         	else if(location.Length())
       
  1157         	    {
       
  1158                 AknTextUtils::ReplaceCharacters(location, KReplaceWhitespaceChars, TChar(' '));
       
  1159         	    CPosLandmark* landmark = CPosLandmark::NewL();
       
  1160                 landmark->SetLandmarkNameL(location);
       
  1161                 MCalenContext& context = iServices->Context();
       
  1162                 context.SetLandMark( landmark );
       
  1163                 }
       
  1164                 iServices->IssueCommandL( ECalenGetLocation );
       
  1165             } 
       
  1166           break;
       
  1167         case ECalenCmdAddAttachment:
       
  1168             {
       
  1169             // TODO: Uncomment this when enabling attachment support
       
  1170             iServices->IssueCommandL( ECalenAddAttachment );
       
  1171             }
       
  1172             break;
       
  1173         case ECalenCmdViewAttachmentList:
       
  1174             {
       
  1175             iServices->IssueCommandL(ECalenViewAttachmentList);
       
  1176             }
       
  1177             break;
       
  1178         case ECalenCmdRemoveAttachment:
       
  1179             {
       
  1180             // TODO: Uncomment this when enabling attachment support
       
  1181             
       
  1182             TInt attachmentCount = iServices->GetAttachmentData()->NumberOfItems();            
       
  1183             
       
  1184             if(Edited().AttachmentCount() || attachmentCount)
       
  1185                 {                                
       
  1186                 iServices->IssueCommandL( ECalenRemoveAttachment );                               
       
  1187                 }
       
  1188             }
       
  1189             break;
       
  1190         default:
       
  1191             {
       
  1192             if( iUnifiedEditorControl->Description() )
       
  1193                 {
       
  1194                 iUnifiedEditorControl->Description()->ProcessCommandL( aCommandId );
       
  1195                 } 
       
  1196             }
       
  1197             // NOP, pass command through (for FEP etc.)
       
  1198             break;
       
  1199         }
       
  1200 
       
  1201     TRACE_EXIT_POINT;     
       
  1202     }
       
  1203         
       
  1204 //Single click integration
       
  1205 // -----------------------------------------------------------------------------
       
  1206 // CCalenUnifiedEditor::HandleDialogPageEventL
       
  1207 // -----------------------------------------------------------------------------
       
  1208 //
       
  1209 void CCalenUnifiedEditor::HandleDialogPageEventL( TInt aEventID )
       
  1210     {
       
  1211     CAknForm::HandleDialogPageEventL( aEventID );
       
  1212     if ( aEventID == MEikDialogPageObserver::EDialogPageTapped )
       
  1213         {
       
  1214         TInt focusControl( IdOfFocusControl() );
       
  1215         if ( focusControl == ECalenEditorAttachment
       
  1216                 || focusControl == ECalenEditorDescription )
       
  1217             {
       
  1218             
       
  1219             
       
  1220                 switch ( focusControl )
       
  1221                     {
       
  1222                     case ECalenEditorAttachment:
       
  1223                         {
       
  1224                         
       
  1225                         if(Edited().AttachmentCount() || iServices->GetAttachmentData()->NumberOfItems())
       
  1226                             {
       
  1227                                 ProcessCommandL( ECalenCmdViewAttachmentList );
       
  1228                             }
       
  1229                         else
       
  1230                             {
       
  1231                                 ProcessCommandL( ECalenCmdAddAttachment );
       
  1232                             }
       
  1233                         break;
       
  1234                         }
       
  1235                        
       
  1236                     case ECalenEditorDescription:
       
  1237                         {
       
  1238 //                        CEikEdwin* edwin = static_cast<CEikEdwin*>( Control( focusControl ) );  
       
  1239 //                        if ( edwin && edwin->Text()->DocumentLength() == 0 )
       
  1240 //                            {
       
  1241 //                                ProcessCommandL( ECalenCmdAddDescription );
       
  1242 //                            }
       
  1243 //                        else
       
  1244 //                            {
       
  1245 //                                ProcessCommandL( ECalenCmdShowDescription );
       
  1246 //                            }
       
  1247                         iAsyncCallback->CallBack();
       
  1248                         break;
       
  1249                         }
       
  1250                        
       
  1251                     default:
       
  1252                         {
       
  1253                         break;
       
  1254                         }
       
  1255                     }
       
  1256                 
       
  1257             }
       
  1258         else if ( focusControl == ECalenEditorAllDayItem )
       
  1259             {
       
  1260             // Tap on AllDay field, Switch the status of AllDay field  
       
  1261             iUnifiedEditorControl->SetAllDayEventL(
       
  1262                     !( iUnifiedEditorControl->IsAllDayEvent() ) );
       
  1263             }
       
  1264         else if ( focusControl == ECalenEditorReminder )
       
  1265             {
       
  1266             TBool active;
       
  1267             if( iUnifiedEditorControl->IsAlarmActiveInForm() )
       
  1268                 { 
       
  1269                 SetAlarmFieldOnOffL( EFalse );           
       
  1270                 active = EFalse;
       
  1271                 } 
       
  1272             else
       
  1273                 {
       
  1274                 SetAlarmFieldOnOffL( ETrue );                
       
  1275                 active = ETrue;
       
  1276                 }
       
  1277             iUnifiedEditorControl->CheckAlarmActive( active );
       
  1278             TryChangeFocusToL( ECalenEditorReminder );
       
  1279             }
       
  1280         }
       
  1281     }
       
  1282 
       
  1283 
       
  1284 TInt CCalenUnifiedEditor::AsyncProcessCommandL( TAny* aThisPtr )
       
  1285     {
       
  1286     TInt focusControl( static_cast<CCalenUnifiedEditor*>(aThisPtr)->IdOfFocusControl() );
       
  1287     if(focusControl == ECalenEditorDescription)
       
  1288         {
       
  1289         CEikEdwin* edwin = static_cast<CEikEdwin*>( static_cast<CCalenUnifiedEditor*>(aThisPtr)->Control( focusControl ) );  
       
  1290         if ( edwin && edwin->Text()->DocumentLength() == 0 )
       
  1291             {
       
  1292             static_cast<CCalenUnifiedEditor*>(aThisPtr)->ProcessCommandL(ECalenCmdAddDescription);
       
  1293             }
       
  1294         else
       
  1295             {
       
  1296             static_cast<CCalenUnifiedEditor*>(aThisPtr)->ProcessCommandL(ECalenCmdShowDescription);
       
  1297             }
       
  1298         }
       
  1299     return 0;
       
  1300     }
       
  1301 
       
  1302 
       
  1303 // -----------------------------------------------------------------------------
       
  1304 //  CCalenUnifiedEditor::HandleResourceChange
       
  1305 //  Handdles the resource change
       
  1306 // -----------------------------------------------------------------------------
       
  1307 //
       
  1308 void CCalenUnifiedEditor::HandleResourceChange( TInt aType )
       
  1309     {
       
  1310     TRACE_ENTRY_POINT;
       
  1311     
       
  1312     if( aType == KEikDynamicLayoutVariantSwitch )
       
  1313         {
       
  1314         CAknForm::HandleResourceChange( aType );
       
  1315         }
       
  1316 
       
  1317     CCoeControl::HandleResourceChange( aType );
       
  1318     
       
  1319     TRACE_EXIT_POINT;
       
  1320     }
       
  1321 
       
  1322 // -----------------------------------------------------------------------------
       
  1323 // CCalenUnifiedEditor::DynInitMenuPaneL
       
  1324 // Dynamic initialistaion of menu pane
       
  1325 // -----------------------------------------------------------------------------
       
  1326 //
       
  1327 void CCalenUnifiedEditor::DynInitMenuPaneL( 
       
  1328         TInt aResourceId, 
       
  1329         CEikMenuPane* aMenuPane )
       
  1330     {
       
  1331     TInt ctrlid=IdOfFocusControl();
       
  1332     
       
  1333     switch ( aResourceId )
       
  1334         {
       
  1335         case R_CALEN_UNIFIED_EDITOR_MENUPANE:
       
  1336             {
       
  1337             // Here we have to call other classes DynInitMenuPaneL
       
  1338             // in that order that we want items to appear!
       
  1339             if( ctrlid == ECalenEditorDescription )
       
  1340                 {
       
  1341                 iUnifiedEditorControl->Description()->DynInitMenuPaneL( 
       
  1342                         aResourceId, 
       
  1343                         aMenuPane );
       
  1344                 }
       
  1345 
       
  1346             // TODO: Uncomment this when enabling attachment support
       
  1347             
       
  1348             if( ctrlid == ECalenEditorAttachment )
       
  1349                 {
       
  1350                 aMenuPane->AddMenuItemsL( R_CALEN_EDITOR_ATTACHMENTS_MENUPANE );
       
  1351                 if( !EntryHasAttachments() )
       
  1352                     {
       
  1353                     aMenuPane->DeleteMenuItem( ECalenCmdRemoveAttachment );
       
  1354                     }
       
  1355                 }
       
  1356             
       
  1357             aMenuPane->AddMenuItemsL( R_CALEN_UNIFIED_EDITOR_DEFAULT_MENUPANE );
       
  1358 
       
  1359             if( (iEntryType == CCalEntry::ETodo) || !(CCalenLocationUtil::IsMapProviderAvailableL()) )   
       
  1360                 {
       
  1361                 aMenuPane->DeleteMenuItem( ECalenGetLocation );
       
  1362                 }
       
  1363             
       
  1364             if( IsCreatingNewEntry() )
       
  1365                 {
       
  1366                 // Always remove the `Discard Changes' option from the menu-
       
  1367                 // pane when a new entry is being created.
       
  1368                 aMenuPane->DeleteMenuItem( ECalenCmdCancel );
       
  1369                 }
       
  1370             else
       
  1371                 {
       
  1372                 // While editing, first check if any of the fields have changed.
       
  1373                 // Then check if the entry type field has changed.
       
  1374                 if( !EditorDataHandler().IsEditedL() )
       
  1375                     {
       
  1376                     if( !EditorDataHandler().IsEntryTypeEdited() )
       
  1377                         {
       
  1378                         aMenuPane->DeleteMenuItem( ECalenCmdCancel );
       
  1379                         }
       
  1380                     }
       
  1381                 }
       
  1382                 
       
  1383             if( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
  1384                 {
       
  1385                 aMenuPane->DeleteMenuItem( EAknCmdHelp );
       
  1386                 }
       
  1387             
       
  1388             if( ctrlid != ECalenEditorPeople )
       
  1389                 {
       
  1390                 aMenuPane->DeleteMenuItem( ECalenCmdAddPeople );
       
  1391                 }
       
  1392             }
       
  1393             break;
       
  1394 
       
  1395         default:
       
  1396             {
       
  1397             break;
       
  1398             }
       
  1399         }
       
  1400 
       
  1401     TRACE_EXIT_POINT;
       
  1402     }
       
  1403 
       
  1404 // -----------------------------------------------------------------------------
       
  1405 // CCalenUnifiedEditor::OnCmdCancelL
       
  1406 // Handles cancel command.
       
  1407 // -----------------------------------------------------------------------------
       
  1408 //
       
  1409 void CCalenUnifiedEditor::OnCmdCancelL()
       
  1410     {
       
  1411     TRACE_ENTRY_POINT;
       
  1412 
       
  1413     CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
  1414     if( dlg->ExecuteLD( R_CALEN_CANCEL_CHANGES_QUERY ) )
       
  1415         {
       
  1416         CloseFormWithoutActionsL();
       
  1417         }
       
  1418 
       
  1419     TRACE_EXIT_POINT;
       
  1420     }
       
  1421 
       
  1422 // -----------------------------------------------------------------------------
       
  1423 // CCalenUnifiedEditor::OnCmdDeleteNoteL
       
  1424 // Handles delete command.
       
  1425 // -----------------------------------------------------------------------------
       
  1426 //
       
  1427 void CCalenUnifiedEditor::OnCmdDeleteNoteL()
       
  1428     {
       
  1429     TRACE_ENTRY_POINT;
       
  1430 
       
  1431     TryToDeleteNoteL( ETrue );
       
  1432     
       
  1433     TRACE_EXIT_POINT;
       
  1434     }
       
  1435 
       
  1436 // -----------------------------------------------------------------------------
       
  1437 // CCalenUnifiedEditor::OnCmdHelpL
       
  1438 // Handles help command.
       
  1439 // -----------------------------------------------------------------------------
       
  1440 //
       
  1441 void CCalenUnifiedEditor::OnCmdHelpL()
       
  1442     {
       
  1443     TRACE_ENTRY_POINT;
       
  1444 
       
  1445     if( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
  1446         {
       
  1447         HlpLauncher::LaunchHelpApplicationL(
       
  1448             iCoeEnv->WsSession(),
       
  1449             static_cast<CCoeAppUi*>( iCoeEnv->AppUi() )->AppHelpContextL() );
       
  1450         }
       
  1451 
       
  1452     TRACE_EXIT_POINT;
       
  1453     }
       
  1454 
       
  1455 // -----------------------------------------------------------------------------
       
  1456 // CCalenUnifiedEditor::OnCmdExitL
       
  1457 // Handles exit command.
       
  1458 // (other items were commented in a header).
       
  1459 // -----------------------------------------------------------------------------
       
  1460 //
       
  1461 void CCalenUnifiedEditor::OnCmdExitL(TInt aCmd)
       
  1462     {
       
  1463     TRACE_ENTRY_POINT;   
       
  1464     
       
  1465             TryExitL( aCmd );
       
  1466        
       
  1467     TRACE_EXIT_POINT;
       
  1468     }
       
  1469 
       
  1470 // -----------------------------------------------------------------------------
       
  1471 // CCalenUnifiedEditor::TryToDeleteNoteL
       
  1472 // Deletes the note from agenda.
       
  1473 // (other items were commented in a header).
       
  1474 // -----------------------------------------------------------------------------
       
  1475 //
       
  1476 void CCalenUnifiedEditor::TryToDeleteNoteL( TBool /* aIsViaDeleteMenu */ )
       
  1477     {
       
  1478     TRACE_ENTRY_POINT;
       
  1479 	
       
  1480 	TInt attachmentCount = iServices->GetAttachmentData()->NumberOfItems(); 		   
       
  1481 	 if(Edited().AttachmentCount() || attachmentCount)
       
  1482 		 {
       
  1483 		 iServices->GetAttachmentData()->Reset();
       
  1484 		 }
       
  1485     if (IsCreatingNewEntry())
       
  1486         {
       
  1487         iEntryUpdater->TryDeleteInstanceWithUiL( EditorDataHandler().Entry() ,
       
  1488                                         EditorDataHandler().InstanceDateTime() ,
       
  1489                                         *iServices );
       
  1490         }
       
  1491     else 
       
  1492         {
       
  1493         // FIXME. With new MAgnEntryUi we could use MAgnEntryUi::EInstanceDeleted
       
  1494         iEntryUpdater->TryDeleteInstanceWithUiL( EditorDataHandler().Entry() ,
       
  1495                                     EditorDataHandler().InstanceDateTime() ,
       
  1496                                    iRepeatType, *iServices );
       
  1497         }
       
  1498     TRACE_EXIT_POINT;
       
  1499     }
       
  1500 
       
  1501 // -----------------------------------------------------------------------------
       
  1502 // CCalenUnifiedEditor::CloseFormWithoutActionsL
       
  1503 // Closes the form. We have to do it via dialog's exit mechanism
       
  1504 // with custom id (KCalenButtonIdCloseForm).
       
  1505 // (other items were commented in a header).
       
  1506 // -----------------------------------------------------------------------------
       
  1507 //
       
  1508 void CCalenUnifiedEditor::CloseFormWithoutActionsL()
       
  1509     {
       
  1510     TRACE_ENTRY_POINT;
       
  1511 
       
  1512     TryExitL( KCalenButtonIdCloseForm );
       
  1513 
       
  1514     TRACE_EXIT_POINT;
       
  1515     }
       
  1516 
       
  1517 // -----------------------------------------------------------------------------
       
  1518 // CCalenUnifiedEditor::CreateCustomControlL
       
  1519 // Returns a new custom control.
       
  1520 // -----------------------------------------------------------------------------
       
  1521 //
       
  1522 SEikControlInfo CCalenUnifiedEditor::CreateCustomControlL( TInt aControlType )
       
  1523     {
       
  1524     TRACE_ENTRY_POINT;
       
  1525     if( aControlType == ECalenCtLunarDateEditor  && FeatureManager::FeatureSupported( KFeatureIdKorean ) ) 
       
  1526             {
       
  1527             SEikControlInfo controlInfo;
       
  1528             controlInfo.iControl =  new (ELeave) CKoreanLunarDateEditor(iServices);
       
  1529             controlInfo.iControl->SetParent( this );
       
  1530             controlInfo.iFlags = 0;
       
  1531             controlInfo.iTrailerTextId = 0;
       
  1532             return controlInfo;
       
  1533             }
       
  1534     __ASSERT_ALWAYS( aControlType==ECalenCtDescriptionField, User::Invariant() );
       
  1535 
       
  1536     TRACE_EXIT_POINT;
       
  1537     return iUnifiedEditorControl->Description()->CreateFieldL();
       
  1538     }
       
  1539 
       
  1540 // -----------------------------------------------------------------------------
       
  1541 // CCalenUnifiedEditor::ConvertCustomControlTypeToBaseControlType
       
  1542 // This method has to be implemented, otherwise custom components do not work with forms.
       
  1543 // -----------------------------------------------------------------------------
       
  1544 //
       
  1545 MEikDialogPageObserver::TFormControlTypes 
       
  1546     CCalenUnifiedEditor::ConvertCustomControlTypeToBaseControlType( TInt aControlType ) const
       
  1547     {
       
  1548     TRACE_ENTRY_POINT;
       
  1549 
       
  1550     if( aControlType == ECalenCtDescriptionField )
       
  1551         {
       
  1552         TRACE_EXIT_POINT;
       
  1553         return MEikDialogPageObserver::EEdwinDerived;
       
  1554         }
       
  1555     if( aControlType == ECalenCtLunarDateEditor  && FeatureManager::FeatureSupported( KFeatureIdKorean ) )
       
  1556         {
       
  1557         TRACE_EXIT_POINT;
       
  1558         return MEikDialogPageObserver::EMfneDerived;
       
  1559         }
       
  1560 
       
  1561     TRACE_EXIT_POINT;
       
  1562     return MEikDialogPageObserver::EUnknownType;
       
  1563     }
       
  1564 
       
  1565 
       
  1566 // -----------------------------------------------------------------------------
       
  1567 // CCalenUnifiedEditor::AskRepeatingNoteQueriesL
       
  1568 // (other items were commented in a header).
       
  1569 // -----------------------------------------------------------------------------
       
  1570 //
       
  1571 CCalenEditorDataHandler::TError CCalenUnifiedEditor::AskRepeatingNoteQueriesL(
       
  1572     CalCommon::TRecurrenceRange& aRepeatType )
       
  1573     {
       
  1574     TRACE_ENTRY_POINT
       
  1575     CCalenEditorDataHandler::TError error = CCalenEditorDataHandler::EFormErrNone;
       
  1576 
       
  1577     switch( GetEntryType() )
       
  1578         {
       
  1579         case CCalEntry::EAnniv:
       
  1580             {
       
  1581 
       
  1582             if ( ShouldQueryForStartDateChange() )
       
  1583                 {
       
  1584                 // Query for StartDate change
       
  1585                 error = QueryStartDateChangeL();
       
  1586                 }
       
  1587 
       
  1588             TRACE_EXIT_POINT;
       
  1589             return error;
       
  1590             }
       
  1591             //break;           
       
  1592             
       
  1593         case CCalEntry::EAppt:
       
  1594             {
       
  1595             if ( ShouldQueryForStartDateChange() )
       
  1596                 {
       
  1597                 if ( EditorDataHandler().IsStartDateChanged() )
       
  1598                     {
       
  1599                     TRACE_EXIT_POINT;
       
  1600 
       
  1601                     // Query for StartDate change
       
  1602                     return QueryStartDateChangeL();
       
  1603                     }
       
  1604                 }
       
  1605 
       
  1606             if( iHasChosenRepeatType )
       
  1607                 {
       
  1608                 // Don't ask the "this/series" question when we have chosen already.
       
  1609                 return error;
       
  1610                 }
       
  1611             TRACE_EXIT_POINT;
       
  1612             return iUnifiedEditorControl->AskRepeatingNoteQueriesL(aRepeatType);
       
  1613             }
       
  1614             //break;
       
  1615 
       
  1616         case CCalEntry::ETodo:
       
  1617         case CCalEntry::EEvent:
       
  1618             {
       
  1619             TRACE_EXIT_POINT;
       
  1620             return error;
       
  1621             }
       
  1622             //break;  
       
  1623 
       
  1624         default:
       
  1625             break;
       
  1626         }
       
  1627 	return error;
       
  1628     }
       
  1629 
       
  1630 
       
  1631 
       
  1632 TBool CCalenUnifiedEditor::ShouldQueryForStartDateChange()
       
  1633     {
       
  1634     TBool shouldQuery = EFalse;
       
  1635     // For Meeting entry type.
       
  1636     if( GetEntryType() == CCalEntry::EAppt )
       
  1637         {
       
  1638         TRACE_EXIT_POINT;
       
  1639 		shouldQuery = ! IsCreatingNewEntry() &&
       
  1640             ( Edited().IsRepeating() && EditorDataHandler().Original().IsRepeating() );
       
  1641         }
       
  1642     
       
  1643     // For Anniversary enty type
       
  1644     if( GetEntryType() == CCalEntry::EAnniv )
       
  1645         {
       
  1646         TRACE_EXIT_POINT;
       
  1647         shouldQuery = ! IsCreatingNewEntry();
       
  1648         }
       
  1649 	return shouldQuery;
       
  1650     TRACE_EXIT_POINT;
       
  1651     }
       
  1652 
       
  1653 // -----------------------------------------------------------------------------
       
  1654 // CCalenUnifiedEditor::QueryStartDateChangeL
       
  1655 // If the entry is repeating, and the edited start date is different from the
       
  1656 // original start date, prompt the user and ask if they are sure they want to
       
  1657 // change the start date of the repeating entry.
       
  1658 // (other items were commented in a header).
       
  1659 // -----------------------------------------------------------------------------
       
  1660 //
       
  1661 CCalenEditorDataHandler::TError CCalenUnifiedEditor::QueryStartDateChangeL()
       
  1662     {
       
  1663     TRACE_ENTRY_POINT;
       
  1664     TTime oldStartDate = EditorDataHandler().Original().StartDateTime();
       
  1665     TTime newStartDate = Edited().StartDateTime();
       
  1666 
       
  1667     // The "Are you sure you want to change start date of repeating note?"
       
  1668     // query should only be shown for repeating notes.
       
  1669     if ( iRepeatType == CalCommon::EThisAndAll
       
  1670         && ! CalenDateUtils::OnSameDay( oldStartDate, newStartDate ) )
       
  1671         {
       
  1672         CAknQueryDialog* queryDlg = CAknQueryDialog::NewL();
       
  1673         TInt answer = queryDlg->ExecuteLD( R_CALEN_REPEAT_NOTE_START_CHANGED );
       
  1674         if (!answer) // Answer "No"
       
  1675             {
       
  1676             TRACE_EXIT_POINT;
       
  1677             return CCalenEditorDataHandler::EFormErrCancelSaveRepNoteWhenStartChange;
       
  1678             }
       
  1679         }
       
  1680     TRACE_EXIT_POINT;
       
  1681     return CCalenEditorDataHandler::EFormErrNone;
       
  1682     }
       
  1683 // -----------------------------------------------------------------------------
       
  1684 // CCalenUnifiedEditor::IsCreatingNewEntry
       
  1685 // Returns ETrue if the entry has just been created, EFalse if the entry
       
  1686 // already existed in agenda.
       
  1687 // -----------------------------------------------------------------------------
       
  1688 //
       
  1689 TBool CCalenUnifiedEditor::IsCreatingNewEntry() const
       
  1690     {
       
  1691     TRACE_ENTRY_POINT;
       
  1692 
       
  1693     TRACE_EXIT_POINT;
       
  1694     return iEntryUiInParams.iEditorMode == MAgnEntryUi::ECreateNewEntry;
       
  1695     }
       
  1696 
       
  1697 // -----------------------------------------------------------------------------
       
  1698 // CCalenUnifiedEditor::MaxTextEditorLength
       
  1699 // Returns the maximum length the text editor can be.
       
  1700 // -----------------------------------------------------------------------------
       
  1701 //
       
  1702 TInt CCalenUnifiedEditor::MaxTextEditorLength() const
       
  1703     {
       
  1704     TRACE_ENTRY_POINT;
       
  1705 
       
  1706     switch ( AknLayoutUtils::Variant() )
       
  1707         {
       
  1708         case EEuropeanVariant:
       
  1709             {
       
  1710             TRACE_EXIT_POINT;
       
  1711             return KCalenMaxELAFTextEditorLength;
       
  1712             }
       
  1713         case EApacVariant:
       
  1714             {
       
  1715             TRACE_EXIT_POINT;
       
  1716             return KCalenMaxAPACTextEditorLength;
       
  1717             }
       
  1718         }
       
  1719 
       
  1720     TRACE_EXIT_POINT;
       
  1721     return 0;
       
  1722     }
       
  1723 
       
  1724 // -----------------------------------------------------------------------------
       
  1725 // CCalenUnifiedEditor::EditorDataHandler
       
  1726 // Returns the editor data handler.
       
  1727 // -----------------------------------------------------------------------------
       
  1728 //
       
  1729 CCalenEditorDataHandler& CCalenUnifiedEditor::EditorDataHandler()
       
  1730     {
       
  1731     TRACE_ENTRY_POINT;
       
  1732 
       
  1733     TRACE_EXIT_POINT;
       
  1734     return *iEditorDataHandler;
       
  1735     }
       
  1736 
       
  1737 // -----------------------------------------------------------------------------
       
  1738 // CCalenUnifiedEditor::Edited
       
  1739 // Returns the data being edited.
       
  1740 // -----------------------------------------------------------------------------
       
  1741 //
       
  1742 CCalenEntryUtil& CCalenUnifiedEditor::Edited()
       
  1743     {
       
  1744     TRACE_ENTRY_POINT;
       
  1745 
       
  1746     TRACE_EXIT_POINT;
       
  1747     return iEditorDataHandler->Edited();
       
  1748     }
       
  1749 
       
  1750 // -----------------------------------------------------------------------------
       
  1751 // CCalenUnifiedEditor::Original
       
  1752 // Returns the original data.
       
  1753 // -----------------------------------------------------------------------------
       
  1754 //
       
  1755 const CCalenEntryUtil& CCalenUnifiedEditor::Original() const
       
  1756     {
       
  1757     TRACE_ENTRY_POINT;
       
  1758 
       
  1759     TRACE_EXIT_POINT;
       
  1760     return iEditorDataHandler->Original();
       
  1761     }
       
  1762 
       
  1763 // -----------------------------------------------------------------------------
       
  1764 // CCalenUnifiedEditor::SetEditorTextL
       
  1765 // Sets editor text
       
  1766 // -----------------------------------------------------------------------------
       
  1767 //
       
  1768 void CCalenUnifiedEditor::SetEditorTextL( TInt aControlId, const TDesC* aDes )
       
  1769     {
       
  1770     TRACE_ENTRY_POINT;
       
  1771     
       
  1772     SetEdwinTextL( aControlId, aDes );
       
  1773     
       
  1774     TRACE_EXIT_POINT;
       
  1775     }
       
  1776 
       
  1777 // -----------------------------------------------------------------------------
       
  1778 // CCalenUnifiedEditor::ReadSubjectFromEditorL
       
  1779 //  Reads subject field from unified editor
       
  1780 // -----------------------------------------------------------------------------
       
  1781 //
       
  1782 void CCalenUnifiedEditor::ReadSubjectFromEditorL()
       
  1783     {
       
  1784     TRACE_ENTRY_POINT;
       
  1785     
       
  1786     TBuf<ECalenAbsoluteMaxTextEditorLength> editorText;
       
  1787     GetEdwinText( editorText,ECalenEditorSubject );
       
  1788     Edited().SetSummaryL( editorText );
       
  1789     
       
  1790     TRACE_EXIT_POINT;
       
  1791     }
       
  1792 
       
  1793 // -----------------------------------------------------------------------------
       
  1794 // CCalenUnifiedEditor::ReadPlaceFromEditorL
       
  1795 // Reads "Place" item from unified editor
       
  1796 // -----------------------------------------------------------------------------
       
  1797 //
       
  1798 void CCalenUnifiedEditor::ReadPlaceFromEditorL()
       
  1799     {
       
  1800     TRACE_ENTRY_POINT;
       
  1801     
       
  1802     // Location
       
  1803     TBuf<ECalenAbsoluteMaxTextEditorLength> location;
       
  1804     GetEdwinText(location, ECalenEditorPlace);
       
  1805 
       
  1806     TInt pos = location.Locate(TChar(CEditableText::EPictureCharacter));
       
  1807     while(pos != KErrNotFound)
       
  1808         {
       
  1809         location.Delete(pos, 1);
       
  1810         pos = location.Locate(TChar(CEditableText::EPictureCharacter));
       
  1811         }
       
  1812 
       
  1813     Edited().SetLocationL( location );
       
  1814     SetEdwinTextL( ECalenEditorPlace, &location );
       
  1815     
       
  1816     TRACE_EXIT_POINT;    
       
  1817     }
       
  1818 
       
  1819 // -----------------------------------------------------------------------------
       
  1820 // CCalenUnifiedEditor::SetEntryType
       
  1821 // Sets the unified editor's entry type
       
  1822 // -----------------------------------------------------------------------------
       
  1823 //
       
  1824 void CCalenUnifiedEditor::SetEntryType( CCalEntry::TType aEntryType )
       
  1825     {
       
  1826     TRACE_ENTRY_POINT;
       
  1827     iEntryType = aEntryType;
       
  1828     TRACE_EXIT_POINT;
       
  1829     }
       
  1830 
       
  1831 // -----------------------------------------------------------------------------
       
  1832 // CCalenUnifiedEditor::GetEntryType
       
  1833 // Gets unified editor entry type
       
  1834 // -----------------------------------------------------------------------------
       
  1835 //
       
  1836 CCalEntry::TType CCalenUnifiedEditor::GetEntryType()
       
  1837     {
       
  1838     TRACE_ENTRY_POINT;
       
  1839     TRACE_EXIT_POINT;
       
  1840     return iEntryType;
       
  1841     }
       
  1842 
       
  1843 
       
  1844 // -----------------------------------------------------------------------------
       
  1845 // CCalenUnifiedEditor::EditorFields
       
  1846 // Access to the unified editor's fields
       
  1847 // -----------------------------------------------------------------------------
       
  1848 //
       
  1849 CCalenUnifiedEditorControl& CCalenUnifiedEditor::EditorFields()
       
  1850     {
       
  1851     TRACE_ENTRY_POINT;
       
  1852     TRACE_EXIT_POINT;
       
  1853     return *iUnifiedEditorControl;
       
  1854     }
       
  1855 
       
  1856 // -----------------------------------------------------------------------------
       
  1857 // CCalenUnifiedEditor::SetAlarmFieldOnOffL
       
  1858 // Set alarm field on or off
       
  1859 // -----------------------------------------------------------------------------
       
  1860 //
       
  1861 void CCalenUnifiedEditor::SetAlarmFieldOnOffL( TBool aOnOff )
       
  1862     {
       
  1863     TRACE_ENTRY_POINT;
       
  1864     
       
  1865     HBufC* String;
       
  1866     CEikEdwin* alarmFieldText =( CEikEdwin* )Control( ECalenEditorReminder );
       
  1867     if( aOnOff )
       
  1868         {
       
  1869         // load string 'ON'
       
  1870         String = StringLoader::LoadLC( R_QTN_ALARM_ACTIVE, iCoeEnv );
       
  1871         }
       
  1872     else
       
  1873         {
       
  1874         // load string 'OFF'
       
  1875         String = StringLoader::LoadLC( R_QTN_ALARM_OFF,iCoeEnv );
       
  1876         }
       
  1877     // set Alarm field string as 'ON'/'OFF'
       
  1878     alarmFieldText->SetTextL(String);
       
  1879     CleanupStack::PopAndDestroy(String);
       
  1880     
       
  1881     TRACE_EXIT_POINT;
       
  1882     } 
       
  1883 
       
  1884 // -----------------------------------------------------------------------------
       
  1885 // CCalenUnifiedEditor::SetAllDayFieldL
       
  1886 // Set alarm field on or off
       
  1887 // -----------------------------------------------------------------------------
       
  1888 //
       
  1889 void CCalenUnifiedEditor::SetAllDayFieldL(TBool aYesNo)
       
  1890     {
       
  1891     TRACE_ENTRY_POINT;
       
  1892     
       
  1893     HBufC* String;
       
  1894     CEikEdwin* allDayFieldText =( CEikEdwin* )ControlOrNull( ECalenEditorAllDayItem );
       
  1895     if( aYesNo )
       
  1896         {
       
  1897         // load string 'YES'
       
  1898         String = StringLoader::LoadLC( R_QTN_ALLDAY_EVENT_YES,iCoeEnv );
       
  1899         }
       
  1900     else
       
  1901         {
       
  1902         // load string 'NO'
       
  1903         String = StringLoader::LoadLC( R_QTN_ALLDAY_EVENT_NO,iCoeEnv );
       
  1904         }
       
  1905     if( allDayFieldText )
       
  1906         {
       
  1907         // Set AllDay field text as 'YES'/'NO'
       
  1908         allDayFieldText->SetTextL( String );
       
  1909         }
       
  1910     CleanupStack::PopAndDestroy( String );
       
  1911     
       
  1912     TRACE_EXIT_POINT;
       
  1913     } 
       
  1914 
       
  1915 // -----------------------------------------------------------------------------
       
  1916 // CCalenUnifiedEditor::IdOfFocusedControl
       
  1917 // For getting Id of the focused control
       
  1918 // -----------------------------------------------------------------------------
       
  1919 //
       
  1920 TInt CCalenUnifiedEditor::IdOfFocusedControl()
       
  1921     {
       
  1922     TRACE_ENTRY_POINT;
       
  1923     TRACE_EXIT_POINT;
       
  1924     return IdOfFocusControl();
       
  1925     }
       
  1926 
       
  1927 // -----------------------------------------------------------------------------
       
  1928 // CCalenUnifiedEditor::HandleDoneL
       
  1929 // Handle pressing of Done (LSK). Entry is saved or deleted, or if not edited
       
  1930 // nothing is done.
       
  1931 // -----------------------------------------------------------------------------
       
  1932 //
       
  1933 TBool CCalenUnifiedEditor::HandleDoneL()
       
  1934     {
       
  1935     TRACE_ENTRY_POINT;
       
  1936 
       
  1937     const TBool continueOnError = EFalse;
       
  1938     iUnifiedEditorControl->ReadDataFromEditorL( continueOnError );
       
  1939     
       
  1940     TEntryExistenceStatus status;
       
  1941     
       
  1942 	if(!IsCreatingNewEntry())
       
  1943 		{
       
  1944         status = EntryStillExistsL();
       
  1945 		}
       
  1946     else
       
  1947 		{
       
  1948 		status = EEntryOk;
       
  1949 		}
       
  1950 	 
       
  1951     TTimeIntervalDays aDay(0);
       
  1952     if( iCurrentDurationDay<aDay )
       
  1953         {
       
  1954         DisplayErrorMsgL( CCalenEditorDataHandler::EFormErrStopTimeEarlierThanStartTime );
       
  1955         return EFalse;
       
  1956         }
       
  1957     
       
  1958     if ( status == EEntryOk )
       
  1959         {
       
  1960         
       
  1961         TTime startDate = Edited().StartDateTime();
       
  1962         TTime endDate = Edited().EndDateTime();
       
  1963         TTimeIntervalDays differenceInTime = endDate.DaysFrom(startDate); // fix for AllDayEntry issue
       
  1964         
       
  1965         if( startDate == CalenDateUtils::BeginningOfDay( startDate ) &&
       
  1966                 endDate == CalenDateUtils::BeginningOfDay( endDate ) )
       
  1967             {
       
  1968             if( CCalEntry::EAppt == Edited().EntryType() && startDate != endDate && differenceInTime.Int() >= 1 )
       
  1969                 {
       
  1970                 Edited().SetEntryType( CCalEntry::EEvent );
       
  1971                 }
       
  1972             }
       
  1973         if(differenceInTime.Int() == 0 && (CCalEntry::EAppt == Edited().EntryType() || CCalEntry::EEvent == Edited().EntryType()))
       
  1974             {
       
  1975             Edited().SetEntryType( CCalEntry::EAppt ); //changed
       
  1976             }
       
  1977         
       
  1978         switch ( EditorDataHandler().ShouldSaveOrDeleteOrDoNothingL() ) 
       
  1979             {
       
  1980             case CCalenEditorDataHandler::EActionSave:
       
  1981                 {
       
  1982                 TRACE_EXIT_POINT;
       
  1983                 return TryToSaveNoteL();
       
  1984                 }
       
  1985             case CCalenEditorDataHandler::EActionDelete:
       
  1986                 {
       
  1987                 TryToDeleteNoteL( EFalse );
       
  1988                 TRACE_EXIT_POINT;
       
  1989                 // don't exit from the editor dialog here
       
  1990                 // wait for the delete success/ delete failed notification
       
  1991                 // exit from CCalenFormBase::HandleNotification( aNotification );
       
  1992                 // return ETrue;
       
  1993                 return EFalse;
       
  1994                 }
       
  1995             case CCalenEditorDataHandler::EActionNothing:
       
  1996                 {
       
  1997                 TRACE_EXIT_POINT;
       
  1998                 return ETrue;
       
  1999                 }
       
  2000             }
       
  2001         }
       
  2002     else
       
  2003         {
       
  2004         if( status == EEntryModifiedByAnotherProcess )
       
  2005             {
       
  2006             // Entry no longer exists. Show an error message then return to the viewer.
       
  2007             DisplayErrorMsgL( CCalenEditorDataHandler::EFormErrDbConflictEntryModified );
       
  2008             // Other process may have changed start day/time.
       
  2009 
       
  2010             // FIXME
       
  2011             // Assumes the entry view is not null
       
  2012             CCalEntry *newEntry = NULL;
       
  2013             for(TInt i = 0 ; i < iCollectionIds.Count() ; i++)
       
  2014                 {
       
  2015                 newEntry = ( *( iServices->EntryViewL(iCollectionIds[i]) ) )
       
  2016                                                                 .FetchL( iOriginalCalEntry->LocalUidL() );
       
  2017                 }
       
  2018             
       
  2019             if(newEntry)
       
  2020                 {
       
  2021                 CleanupStack::PushL( newEntry );
       
  2022                 iEntryUiOutParams.iNewInstanceDate = newEntry->StartTimeL();
       
  2023                 iEntryUiOutParams.iSpare = (TUint32) newEntry->LocalUidL();
       
  2024                 CleanupStack::PopAndDestroy(newEntry);
       
  2025                 iEntryUiOutParams.iAction = EMeetingSaved;
       
  2026                 }
       
  2027             }
       
  2028         else
       
  2029             {
       
  2030             if( status == EEntryDeletedByAnotherProcess )
       
  2031                 {
       
  2032                 // Entry no longer exists. Show an error message then close the form.
       
  2033                 DisplayErrorMsgL( CCalenEditorDataHandler::EFormErrDbConflictEntryDeleted );
       
  2034                 iEntryUiOutParams.iAction = EMeetingDeleted;
       
  2035                 }            
       
  2036             }
       
  2037 
       
  2038         TRACE_EXIT_POINT;
       
  2039         return ETrue;
       
  2040         }
       
  2041 
       
  2042     // All cases should be handled above
       
  2043     __ASSERT_ALWAYS( EFalse, User::Invariant() );
       
  2044     TRACE_EXIT_POINT;
       
  2045     return EFalse;
       
  2046     }
       
  2047 
       
  2048 // -----------------------------------------------------------------------------
       
  2049 // CheckSpaceBelowCriticalLevelL
       
  2050 // Checks if the Flash File System storage will fall below critical level. 
       
  2051 // If there is not enough space, display an error message and return EFalse.
       
  2052 // Return ETrue otherwise.
       
  2053 // (other items were commented in a header).
       
  2054 // -----------------------------------------------------------------------------
       
  2055 //
       
  2056 TBool CCalenUnifiedEditor::CheckSpaceBelowCriticalLevelL()
       
  2057     {
       
  2058     TRACE_ENTRY_POINT;
       
  2059     // FIXME: Could be moved to commonui 
       
  2060     TBool retcode(EFalse);
       
  2061 
       
  2062     if ( SysUtil::FFSSpaceBelowCriticalLevelL( &( iCoeEnv->FsSession() ) ) )
       
  2063         {
       
  2064         CErrorUI* errorUi = CErrorUI::NewLC();
       
  2065         errorUi->ShowGlobalErrorNoteL( KErrDiskFull );
       
  2066         CleanupStack::PopAndDestroy( errorUi ); 
       
  2067         retcode = ETrue;
       
  2068         }
       
  2069     TRACE_EXIT_POINT;
       
  2070     return retcode;
       
  2071     }
       
  2072 
       
  2073 // -----------------------------------------------------------------------------
       
  2074 // CCalenUnifiedEditor::TryToSaveNoteL
       
  2075 // Save form data. Return ETrue if saving is successful, EFalse otherwise.
       
  2076 // (other items were commented in a header).
       
  2077 // -----------------------------------------------------------------------------
       
  2078 //
       
  2079 TBool CCalenUnifiedEditor::TryToSaveNoteL()
       
  2080     {
       
  2081     TRACE_ENTRY_POINT;
       
  2082     
       
  2083     if( CheckSpaceBelowCriticalLevelL() )
       
  2084         {
       
  2085         TRACE_EXIT_POINT;
       
  2086         return EFalse; 
       
  2087         }
       
  2088     
       
  2089     // Check if location field is edited manually
       
  2090     CheckManualEditionOfLocationL();
       
  2091     
       
  2092     
       
  2093     CCalenEditorDataHandler::TError error = CCalenEditorDataHandler::EFormErrNone;
       
  2094     
       
  2095     if( ( !iHasChosenRepeatType && ! EditorDataHandler().IsChildL() ) || 
       
  2096          (iHasChosenRepeatType && iRepeatType == CalCommon::EThisAndAll ) )
       
  2097         {
       
  2098         // Check for the errors, with the entered data
       
  2099         error = EditorDataHandler().CheckErrorsForThisAndAllL();
       
  2100         }
       
  2101     else if( EditorDataHandler().IsChildL() || iRepeatType == CalCommon::EThisOnly )
       
  2102         {
       
  2103         // Check for the errors, for editing Child entry.
       
  2104         error = EditorDataHandler().CheckErrorsForThisOnlyL( ParentEntryL(), *(iServices->InstanceViewL(iCollectionIds) ));
       
  2105         }
       
  2106 
       
  2107     if ( error == CCalenEditorDataHandler::EFormErrNone )
       
  2108         {
       
  2109         error = AskRepeatingNoteQueriesL(iRepeatType);
       
  2110         if(error == CCalenEditorDataHandler::EFormErrNone)
       
  2111             {
       
  2112              iHasChosenRepeatType = ETrue;
       
  2113             }
       
  2114         }
       
  2115 
       
  2116     if ( error == CCalenEditorDataHandler::EFormErrNone ) 
       
  2117         {
       
  2118 		ModifyDbFieldL();//default calendar code
       
  2119         EditorDataHandler().WriteChangesToEntryL( iRepeatType );
       
  2120         
       
  2121         TCalTime newInstanceStartDate, newInstanceEndDate;
       
  2122         CalculateNewInstanceStartAndEndDateL( newInstanceStartDate, newInstanceEndDate );
       
  2123         if(EditorDataHandler().IsRepeatRuleEdited() && !IsCreatingNewEntry())
       
  2124         	{
       
  2125             MCalenContext& context = iServices->Context();
       
  2126             TCalenInstanceId instanceId = context.InstanceId();
       
  2127 			context.SetFocusDateAndTimeL(newInstanceStartDate,TVwsViewId( KUidCalendar, KUidCalenEventView));
       
  2128             }
       
  2129 
       
  2130         TInt saveErr( 0 );
       
  2131         TBool dbChange = iEditorDataHandler->IsCalendarEditedL();
       
  2132         if( iEditedCalEntry.EntryTypeL() != Edited().EntryType() || dbChange )
       
  2133             {
       
  2134             // If calendar EntryType is changed,
       
  2135             // Entry should be re-created with new EntryType and Save.
       
  2136             saveErr = TryToSaveEntryWithEntryChangeL( EFalse );
       
  2137             }
       
  2138         else
       
  2139             {
       
  2140             TRAP( saveErr, iEntryUpdater->UpdateInstanceL( 
       
  2141                        EditorDataHandler().Entry(),
       
  2142                        *iOriginalCalEntry,
       
  2143                        EditorDataHandler().InstanceDateTime(),
       
  2144                        iRepeatType,
       
  2145                        newInstanceStartDate,
       
  2146                        newInstanceEndDate,
       
  2147                        iUnifiedEditorControl->GetCalendarNameForEntryL() ) );
       
  2148 
       
  2149             iEntryUiOutParams.iSpare
       
  2150                     = (TUint32) EditorDataHandler().Entry().LocalUidL();
       
  2151             }
       
  2152 
       
  2153         if ( saveErr != KErrNone )
       
  2154             {
       
  2155             iEikonEnv->ResolveError( saveErr );
       
  2156             }
       
  2157         else
       
  2158             {
       
  2159             iEntryUiOutParams.iAction = MAgnEntryUi::EMeetingSaved;
       
  2160             iEntryUiOutParams.iNewInstanceDate = newInstanceStartDate;
       
  2161             }
       
  2162         TRACE_EXIT_POINT;
       
  2163         return ETrue;
       
  2164         }
       
  2165 
       
  2166     else
       
  2167         {
       
  2168         // If save error occurs, display error message.
       
  2169         DisplayErrorMsgL( error );
       
  2170         iUnifiedEditorControl->HandleErrorL(error);
       
  2171         TRACE_EXIT_POINT;
       
  2172         return EFalse;
       
  2173         }
       
  2174     }
       
  2175 
       
  2176 // -----------------------------------------------------------------------------
       
  2177 // CCalenUnifiedEditor::TryToSaveEntryWithEntryTypeChangeL
       
  2178 // Save form data. Return EErrNone if saving is successful, error value otherwise.
       
  2179 // (other items were commented in a header).
       
  2180 // -----------------------------------------------------------------------------
       
  2181 //
       
  2182 
       
  2183 TInt CCalenUnifiedEditor::TryToSaveEntryWithEntryChangeL( TBool aForcedExit)
       
  2184     {
       
  2185     CCalEntry* entry;
       
  2186     
       
  2187     //Get the guid from original entry and set it to new entry.
       
  2188     HBufC8* guid = iOriginalCalEntry->UidL().AllocL();
       
  2189     
       
  2190 
       
  2191     if( iEditedCalEntry.RecurrenceIdL().TimeUtcL() != Time::NullTTime() )
       
  2192         {
       
  2193         entry = CCalEntry::NewL( Edited().EntryType(), 
       
  2194                                  guid,
       
  2195                                  iEditedCalEntry.MethodL(),
       
  2196                                  iEditedCalEntry.SequenceNumberL(),
       
  2197                                  iEditedCalEntry.RecurrenceIdL(),
       
  2198                                  iEditedCalEntry.RecurrenceRangeL() );
       
  2199     
       
  2200         }
       
  2201     else
       
  2202         {
       
  2203         entry = CCalEntry::NewL( Edited().EntryType(),
       
  2204                                  guid,
       
  2205                                  iEditedCalEntry.MethodL(),
       
  2206                                  iEditedCalEntry.SequenceNumberL() );
       
  2207     
       
  2208         }
       
  2209 
       
  2210      //   CleanupStack::Pop( guid ); // ownership was passed
       
  2211 
       
  2212     CleanupStack::PushL( entry );
       
  2213     iEditedCalEntry.DescriptionL();  // make sure entry is fully loaded
       
  2214     if (CCalEntry::ETodo == entry->EntryTypeL())//check the entry type
       
  2215         {//remove GeoValue and Location info from a ToDo as ToDo does specs
       
  2216     //does not include them
       
  2217         iEditedCalEntry.ClearGeoValueL();
       
  2218         iEditedCalEntry.SetLocationL(KNullDesC);
       
  2219         }
       
  2220     
       
  2221     entry->CopyFromL(iEditedCalEntry, CCalEntry::EDontCopyId);
       
  2222     entry->DescriptionL();  // make sure entry is fully copied
       
  2223     
       
  2224     TCalTime newInstanceStartDate, newInstanceEndDate;
       
  2225     CalculateNewInstanceStartAndEndDateL( newInstanceStartDate, newInstanceEndDate );
       
  2226     entry->SetStartAndEndTimeL( newInstanceStartDate, newInstanceEndDate );
       
  2227     if(iEditedCalEntry.EntryTypeL() != GetEntryType())
       
  2228         {
       
  2229         if( entry->EntryTypeL() == CCalEntry::EAnniv )
       
  2230             {
       
  2231 			if( !( FeatureManager::FeatureSupported( KFeatureIdKorean ) 
       
  2232 					&& entry->UserInt32L() != ESolar ) )
       
  2233 				{
       
  2234 				// Set yearly rule to Anniversary entry, to create Annaiversary instance yearly 
       
  2235 				TCalRRule rrule( TCalRRule::EYearly );
       
  2236 				TCalTime startDate;
       
  2237 				rrule.SetDtStart( newInstanceStartDate );
       
  2238 				rrule.SetInterval( 1 ); // once a year
       
  2239 				entry->SetRRuleL( rrule );
       
  2240 				}
       
  2241             }
       
  2242 		}
       
  2243     
       
  2244 
       
  2245     
       
  2246     TInt saveErr( KErrNone );
       
  2247     if( aForcedExit )
       
  2248         {
       
  2249         iEntryUpdater->UpdateInstanceL( 
       
  2250                 *entry,
       
  2251                 *iOriginalCalEntry,
       
  2252                 EditorDataHandler().InstanceDateTime(),
       
  2253                 iRepeatType,
       
  2254                 newInstanceStartDate,
       
  2255                 newInstanceEndDate,
       
  2256                 iUnifiedEditorControl->GetCalendarNameForEntryL() );
       
  2257 
       
  2258         }
       
  2259     else
       
  2260         {
       
  2261         TRAP( saveErr, iEntryUpdater->UpdateInstanceL( 
       
  2262                    *entry,
       
  2263                    *iOriginalCalEntry,
       
  2264                    EditorDataHandler().InstanceDateTime(),
       
  2265                    iRepeatType,
       
  2266                    newInstanceStartDate,
       
  2267                    newInstanceEndDate,
       
  2268                    iUnifiedEditorControl->GetCalendarNameForEntryL() ) );
       
  2269         }
       
  2270     
       
  2271     //Agenda server is taking care of deleting the old entry when only entrytype is changing
       
  2272     //so calendar is not deleting the old entry here, when only entry type has changed.
       
  2273     if(!IsCreatingNewEntry() && iEditorDataHandler->IsCalendarEditedL())
       
  2274         {
       
  2275         iServices->GetAttachmentData()->Reset();
       
  2276         iServices->EntryViewL(iEditorDataHandler->PreviousDbCollectionId())
       
  2277                                                 ->DeleteL(*iOriginalCalEntry);
       
  2278         }
       
  2279     iEntryUiOutParams.iSpare = (TUint32) entry->LocalUidL();
       
  2280 
       
  2281     CleanupStack::PopAndDestroy(entry);
       
  2282     return saveErr;
       
  2283     
       
  2284     }
       
  2285 
       
  2286 // -----------------------------------------------------------------------------
       
  2287 // CCalenUnifiedEditor::TryToSaveNoteOnForcedExitL
       
  2288 // Try to save note when editors are forced to exit.
       
  2289 // This can happen when the user presses the red key, power off, Options->Exit,
       
  2290 // or in out-of-memory situations.
       
  2291 // (other items were commented in a header).
       
  2292 // -----------------------------------------------------------------------------
       
  2293 //
       
  2294 void CCalenUnifiedEditor::TryToSaveNoteOnForcedExitL()
       
  2295     {
       
  2296     TRACE_ENTRY_POINT;
       
  2297     iCheck = ETrue;
       
  2298     if( EntryStillExistsL() == EEntryOk )
       
  2299         {
       
  2300         if( CheckSpaceBelowCriticalLevelL() )
       
  2301             {
       
  2302             TRACE_EXIT_POINT;
       
  2303             return;
       
  2304             }
       
  2305         
       
  2306         // Check if location field is edited manually
       
  2307         CheckManualEditionOfLocationL();
       
  2308 
       
  2309         const TBool continueOnError = ETrue;
       
  2310         iUnifiedEditorControl->ReadDataFromEditorL( continueOnError );
       
  2311 
       
  2312         CCalenEditorDataHandler::TAction action =
       
  2313             EditorDataHandler().ShouldSaveOrDeleteOrDoNothingL();
       
  2314         if( iHasChosenRepeatType && iRepeatType == CalCommon::EThisAndAll ) 
       
  2315         {
       
  2316         // Check for the errors, with the entered data
       
  2317             if ( EditorDataHandler().CheckErrorsForThisAndAllL() != KErrNone )
       
  2318                 return;
       
  2319         }
       
  2320         if ( action == CCalenEditorDataHandler::EActionSave )
       
  2321             {
       
  2322             EditorDataHandler().ForceValidValuesL( iHasChosenRepeatType? iRepeatType 
       
  2323                                                                                   : CalCommon::EThisAndAll );
       
  2324             ModifyDbFieldL();//Default Calendar code
       
  2325             EditorDataHandler().WriteChangesToEntryL( iHasChosenRepeatType? iRepeatType
       
  2326                                                                                   : CalCommon::EThisAndAll );
       
  2327 
       
  2328             TCalTime newInstanceStartDate, newInstanceEndDate;
       
  2329             CalculateNewInstanceStartAndEndDateL( newInstanceStartDate, 
       
  2330                                                                     newInstanceEndDate );
       
  2331             
       
  2332             TBool onDbChange = iEditorDataHandler->IsCalendarEditedL();
       
  2333             if( iEditedCalEntry.EntryTypeL() != GetEntryType() || onDbChange)
       
  2334                 {
       
  2335                 TryToSaveEntryWithEntryChangeL( ETrue );
       
  2336                 }
       
  2337             else
       
  2338                 {
       
  2339                 iEntryUpdater->UpdateInstanceL( EditorDataHandler().Entry(),
       
  2340                                                    *iOriginalCalEntry,
       
  2341                                                    EditorDataHandler().InstanceDateTime(),
       
  2342                                                    iRepeatType,
       
  2343                                                    newInstanceStartDate,
       
  2344                                                    newInstanceEndDate,
       
  2345                                                    iUnifiedEditorControl->GetCalendarNameForEntryL() );
       
  2346                 }
       
  2347             }
       
  2348         else
       
  2349             {
       
  2350             if ( action == CCalenEditorDataHandler::EActionDelete )
       
  2351                 {
       
  2352                 // FIXME, should we write date/time changes to entry?
       
  2353                 if ( !IsCreatingNewEntry() )
       
  2354                     {				
       
  2355                     if( iHasChosenRepeatType && iRepeatType == CalCommon::EThisOnly )
       
  2356                         {					
       
  2357                         iEntryUpdater->DeleteInstanceL( EditorDataHandler().Entry(), EditorDataHandler().CalenInstanceId() );
       
  2358                         }
       
  2359                     else
       
  2360                         {						
       
  2361                         iEntryUpdater->DeleteEntryL( EditorDataHandler().Entry(), EditorDataHandler().CalenInstanceId() );
       
  2362                         }
       
  2363                     }
       
  2364                 }            
       
  2365             }            
       
  2366         }
       
  2367     TRACE_EXIT_POINT;
       
  2368     }
       
  2369 
       
  2370 
       
  2371 // -----------------------------------------------------------------------------
       
  2372 // CCalenUnifiedEditor::CalculateNewInstanceStartAndEndDateL
       
  2373 // Calculate the new start and end time and date of the instance.
       
  2374 // -----------------------------------------------------------------------------
       
  2375 //
       
  2376 void CCalenUnifiedEditor::CalculateNewInstanceStartAndEndDateL( TCalTime& aNewInstanceStartDate,
       
  2377                                                              TCalTime& aNewInstanceEndDate )
       
  2378     {
       
  2379     TRACE_ENTRY_POINT;
       
  2380    
       
  2381     // Use floating time for non-timed entries 
       
  2382     if (EditorDataHandler().UseFloatingTimeL())
       
  2383         {
       
  2384         aNewInstanceStartDate.SetTimeLocalFloatingL( EditorDataHandler().Edited().StartDateTime() );
       
  2385         aNewInstanceEndDate.SetTimeLocalFloatingL( EditorDataHandler().Edited().EndDateTime() );
       
  2386         }
       
  2387     else
       
  2388         {
       
  2389         aNewInstanceStartDate.SetTimeLocalL( EditorDataHandler().Edited().StartDateTime() );
       
  2390         aNewInstanceEndDate.SetTimeLocalL( EditorDataHandler().Edited().EndDateTime() );
       
  2391         }
       
  2392     
       
  2393     TRACE_EXIT_POINT;
       
  2394     }
       
  2395 
       
  2396 // -----------------------------------------------------------------------------
       
  2397 // CCalenUnifiedEditor::DisplayErrorMsgL
       
  2398 // Display the given error message.
       
  2399 // -----------------------------------------------------------------------------
       
  2400 //
       
  2401 void CCalenUnifiedEditor::DisplayErrorMsgL( const TInt& aError )
       
  2402     {
       
  2403     TRACE_ENTRY_POINT;
       
  2404     TBool toContinue( ETrue );
       
  2405     TInt resourceId( -1 );
       
  2406 
       
  2407     switch ( aError )
       
  2408         {
       
  2409         case CCalenEditorDataHandler::EFormErrStopTimeEarlierThanStartTime:
       
  2410             {
       
  2411             resourceId = R_QTN_CALE_INFO_NOTE_ENDS_BEFORE;
       
  2412             break;
       
  2413             }
       
  2414         case CCalenEditorDataHandler::EFormErrAlarmTimeLaterThanNote:
       
  2415             {
       
  2416             resourceId = R_QTN_CALE_LATER_DATE;
       
  2417             break;
       
  2418             }
       
  2419         case CCalenEditorDataHandler::EFormErrAlarmTimePast:
       
  2420             {
       
  2421             resourceId = R_QTN_CALE_NOT_EXPIRED;
       
  2422             break;
       
  2423             }
       
  2424         case CCalenEditorDataHandler::EFormErrAlarmDateTooManyDaysBeforeNote:
       
  2425             {
       
  2426             resourceId = R_QTN_CALE_DATE_ALARM_PAST;
       
  2427             break;
       
  2428             }
       
  2429         case CCalenEditorDataHandler::EFormErrRepeatUntilEarlierThanNote:
       
  2430             {
       
  2431             resourceId = R_QTN_CALE_INFO_REPEAT_INVALID;
       
  2432             break;
       
  2433             }
       
  2434         case CCalenEditorDataHandler::EFormErrDbConflictEntryModified:
       
  2435             {//"Calendar database conflict. This entry has been modified by another application."
       
  2436             DisplayErrorMsgInNoteDlgL( R_QTN_CALE_NOTE_DB_MODIFIED );
       
  2437             toContinue = EFalse;
       
  2438             break;
       
  2439             }
       
  2440         case CCalenEditorDataHandler::EFormErrDbConflictEntryDeleted:
       
  2441             {//"Calendar database conflict. This entry has been deleted by another application."
       
  2442             DisplayErrorMsgInNoteDlgL( R_QTN_CALE_NOTE_DB_CONFLICT );
       
  2443             toContinue = EFalse;
       
  2444             break;
       
  2445             }
       
  2446         case CCalenEditorDataHandler::EFormErrDurationGreaterThanRepeatInterval:
       
  2447             {
       
  2448             DispalyErrorMsgByRepeatTypeL();
       
  2449             toContinue = EFalse;
       
  2450             break;
       
  2451             }
       
  2452         case CCalenEditorDataHandler::EFormErrOverlapsExistingInstance:
       
  2453             {
       
  2454             resourceId = R_QTN_CALE_NOTE_CHILD_OVERLAP;
       
  2455             break;
       
  2456             }
       
  2457         case CCalenEditorDataHandler::EFormErrOutOfSequence:
       
  2458             {
       
  2459             resourceId = R_QTN_CALE_NOTE_CHILD_OUT_OF_SEQUENCE;
       
  2460             break;
       
  2461             }
       
  2462         case CCalenEditorDataHandler::EFormErrInstanceAlreadyExistsOnThisDay:
       
  2463             {
       
  2464             resourceId = R_QTN_CALE_NOTE_CHILD_SAME_DAY;
       
  2465             break;
       
  2466             }
       
  2467         default:
       
  2468             {
       
  2469             toContinue = EFalse;
       
  2470             }
       
  2471         }
       
  2472     if( toContinue )
       
  2473         {
       
  2474         CAknInformationNote* dialog = new ( ELeave ) CAknInformationNote();
       
  2475         HBufC* buf = StringLoader::LoadLC( resourceId, iEikonEnv );
       
  2476         dialog->ExecuteLD( *buf );
       
  2477         CleanupStack::PopAndDestroy( buf );
       
  2478         }
       
  2479 
       
  2480     TRACE_EXIT_POINT;
       
  2481     }
       
  2482 
       
  2483 // -----------------------------------------------------------------------------
       
  2484 // CCalenUnifiedEditor::ParentEntryL
       
  2485 // Returns the parent entry of the entry being edited.
       
  2486 // -----------------------------------------------------------------------------
       
  2487 //
       
  2488 CCalEntry& CCalenUnifiedEditor::ParentEntryL()
       
  2489     {
       
  2490     TRACE_ENTRY_POINT;
       
  2491     TCalCollectionId colId = iEditorDataHandler->CurrentDbCollectionId(); 
       
  2492     VerifyCollectionIdL(colId);
       
  2493 
       
  2494     if( iFetchedEntries.Count() == 0 )
       
  2495         {
       
  2496         iServices->EntryViewL(colId)
       
  2497                     ->FetchL( EditorDataHandler().Entry().UidL(), iFetchedEntries );
       
  2498         }
       
  2499 
       
  2500     TRACE_EXIT_POINT;
       
  2501     return *iFetchedEntries[0];
       
  2502     }
       
  2503 
       
  2504 // -----------------------------------------------------------------------------
       
  2505 // CCalenUnifiedEditor::DisplayErrorMsgInNoteDlgL
       
  2506 // Display conflict error message.
       
  2507 // -----------------------------------------------------------------------------
       
  2508 //
       
  2509 void CCalenUnifiedEditor::DisplayErrorMsgInNoteDlgL( TInt resourceId )
       
  2510     {
       
  2511     TRACE_ENTRY_POINT;
       
  2512 
       
  2513     CAknNoteDialog *note = new(ELeave) CAknNoteDialog( CAknNoteDialog::EWarningTone,
       
  2514                                                        CAknNoteDialog::ENoTimeout );
       
  2515     HBufC* buf = StringLoader::LoadLC( resourceId, iEikonEnv );
       
  2516     note->SetTextL( *buf );
       
  2517     note->ExecuteLD( R_CALEN_DB_CONFLICT_DIALOG );
       
  2518     CleanupStack::PopAndDestroy( buf );
       
  2519 
       
  2520     TRACE_EXIT_POINT;
       
  2521     }
       
  2522 
       
  2523 // -----------------------------------------------------------------------------
       
  2524 // CCalenUnifiedEditor::DisplayErrorMsgByRepeatTypeL
       
  2525 // Display conflict error message.
       
  2526 // -----------------------------------------------------------------------------
       
  2527 //
       
  2528 void CCalenUnifiedEditor::DispalyErrorMsgByRepeatTypeL()
       
  2529     {
       
  2530     TRACE_ENTRY_POINT;
       
  2531 
       
  2532     TTimeIntervalDays dur = Edited().EndDateTime().DaysFrom( Edited().StartDateTime() );
       
  2533     CAknInformationNote* dialog = new (ELeave) CAknInformationNote();
       
  2534     TInt resourceId( -1 );
       
  2535     TBool toContinue( ETrue );
       
  2536     // to find total num of days entry span . 
       
  2537     TInt numDaysEntrySpan = dur.Int() + 1 ; 
       
  2538     
       
  2539     switch( Edited().RepeatType() )
       
  2540         {
       
  2541         case ERepeatDaily:
       
  2542         case ERepeatWorkdays:
       
  2543             {
       
  2544             resourceId = R_QTN_CALE_INFO_NOTE_DURATION_TOO_LONG_FOR_DAILY;
       
  2545             }
       
  2546             break;
       
  2547         case ERepeatWeekly:
       
  2548             {
       
  2549             resourceId = R_QTN_CALE_INFO_NOTE_DURATION_TOO_LONG_FOR_WEEKLY;
       
  2550             }
       
  2551             break;
       
  2552         case ERepeatBiWeekly:
       
  2553             {
       
  2554             resourceId = R_QTN_CALE_INFO_NOTE_DURATION_TOO_LONG_FOR_BIWEEKLY;
       
  2555             }
       
  2556             break;
       
  2557         case ERepeatMonthly:
       
  2558             {
       
  2559             resourceId = R_QTN_CALE_INFO_NOTE_DURATION_TOO_LONG_FOR_MONTHLY;
       
  2560             }
       
  2561             break;
       
  2562         case ERepeatYearly:
       
  2563             {
       
  2564             resourceId = R_QTN_CALE_INFO_NOTE_DURATION_TOO_LONG_FOR_YEARLY;
       
  2565             }
       
  2566             break;
       
  2567         default:
       
  2568             toContinue = EFalse;
       
  2569         }
       
  2570     if( toContinue )
       
  2571         {
       
  2572         HBufC* buf = StringLoader::LoadLC( resourceId,numDaysEntrySpan, iEikonEnv );
       
  2573         dialog->ExecuteLD( *buf );        
       
  2574         CleanupStack::PopAndDestroy( buf );
       
  2575         }
       
  2576     else
       
  2577         {
       
  2578         CleanupStack::PopAndDestroy( dialog );
       
  2579         }
       
  2580 
       
  2581     TRACE_EXIT_POINT;
       
  2582     }
       
  2583 
       
  2584 // -----------------------------------------------------------------------------
       
  2585 // CCalenUnifiedEditor::EntryStillExistsL
       
  2586 // Checks the entry still exists in the database. If the entry has been
       
  2587 // removed or modified, the appropriate action is returned.
       
  2588 // -----------------------------------------------------------------------------
       
  2589 //
       
  2590 CCalenUnifiedEditor::TEntryExistenceStatus CCalenUnifiedEditor::EntryStillExistsL()
       
  2591     {
       
  2592     TRACE_ENTRY_POINT;
       
  2593     TEntryExistenceStatus status = EEntryOk;
       
  2594 
       
  2595     // Check to see if the entry open in the editor still exists
       
  2596     if ( iLastDbChangeNotification >= iTimeStamp )
       
  2597         {
       
  2598         // The database was changed through another session while the editor was open.
       
  2599         // Search for our entry to check it still exists.
       
  2600         
       
  2601         CCalEntry* dbEntry = NULL;
       
  2602         for(TInt i = 0 ;i < iCollectionIds.Count() ; i++)
       
  2603             {
       
  2604             //check the exsists in one of the calendars
       
  2605             PIM_TRAPD_HANDLE( ( dbEntry = iServices->EntryViewL(iCollectionIds[i])
       
  2606                                                ->FetchL( iOriginalCalEntry->LocalUidL() ) ) );
       
  2607             if(dbEntry)
       
  2608                 {
       
  2609                 break;
       
  2610                 }
       
  2611             }
       
  2612         
       
  2613         // I would have thought we could check for KErrNotFound here, but we just get a NULL
       
  2614         // entry returned if it doesn't exist anymore.
       
  2615         if ( !dbEntry )
       
  2616             {
       
  2617             // The entry we are editing has been deleted.
       
  2618             status = EEntryDeletedByAnotherProcess;
       
  2619             }
       
  2620         else
       
  2621             {
       
  2622             CleanupStack::PushL( dbEntry );
       
  2623             //Check the last modified time of the entry we retrieved from the database
       
  2624             if ( dbEntry->LastModifiedDateL().TimeUtcL() >= iTimeStamp )
       
  2625                 {
       
  2626                 // This entry has been modified in some way, but not by us.
       
  2627                 // Abandon our changes
       
  2628                 status = EEntryModifiedByAnotherProcess;
       
  2629                 }
       
  2630             CleanupStack::PopAndDestroy( dbEntry );
       
  2631             }
       
  2632         }
       
  2633 
       
  2634     TRACE_EXIT_POINT;
       
  2635     return status;
       
  2636     }
       
  2637 
       
  2638 // -----------------------------------------------------------------------------
       
  2639 // CCalenUnifiedEditor::UpdateLocationInfoToFormL
       
  2640 // Updates the user selected landmark details into current meeting editor form 
       
  2641 // -----------------------------------------------------------------------------
       
  2642 //
       
  2643 void CCalenUnifiedEditor::UpdateLocationInfoToFormL()
       
  2644     {
       
  2645     TRACE_ENTRY_POINT;
       
  2646     // set the focus to location field as the address is inserted/updated to location field.
       
  2647     TryChangeFocusToL(ECalenEditorPlace);
       
  2648 	// Get location details from context
       
  2649 	MCalenContext& context = iServices->Context();
       
  2650 	CPosLandmark* landmark = context.GetLandMark();
       
  2651 	TBuf<ECalenAbsoluteMaxTextEditorLength> locationInfo;
       
  2652 	GetEdwinText(locationInfo, ECalenEditorPlace);
       
  2653 	if(landmark) // If user has selected location from Map
       
  2654 		{
       
  2655 		TBuf<ECalenAbsoluteMaxTextEditorLength> location;
       
  2656 		GetEdwinText(location, ECalenEditorPlace);
       
  2657 		CCalGeoValue* geoValue = iEditorDataHandler->Entry().GeoValueL();
       
  2658 		if(geoValue || isReplaceLocation)
       
  2659 			{
       
  2660 			isReplaceLocation = EFalse;
       
  2661             HandleEntryWithGeoValueEditionL(landmark);
       
  2662             delete geoValue;	
       
  2663 			}
       
  2664 		else if(locationInfo.Length() && !isReplaceLocation)
       
  2665 		    {
       
  2666 		    HandleEntryWithLocationEditionL(landmark);
       
  2667 		    }
       
  2668 		else // This is the new entry being created and nothing is there in location field
       
  2669 			{
       
  2670 			isReplaceLocation = EFalse;
       
  2671 			StoreLocationDetailsToEntryL(landmark);
       
  2672 			}
       
  2673 		}
       
  2674 		
       
  2675 	TRACE_EXIT_POINT;
       
  2676 	}
       
  2677 
       
  2678 // -----------------------------------------------------------------------------
       
  2679 // CCalenUnifiedEditor::HandleEntryWithGeoValueEditionL
       
  2680 // Shows suery to the user to replace gthe exisitng saved address
       
  2681 // -----------------------------------------------------------------------------
       
  2682 //	
       
  2683 void CCalenUnifiedEditor::HandleEntryWithGeoValueEditionL(CPosLandmark* landmark)
       
  2684 	{
       
  2685 	TRACE_ENTRY_POINT;
       
  2686 
       
  2687 	// User is tyring to update the location field of an entry which 
       
  2688 	// already has location text as well as geo coordinates
       
  2689 	TPtrC locationName;
       
  2690 	landmark->GetLandmarkName(locationName);
       
  2691 	TInt userResponse = ShowLocationReplaceNoticeL(locationName);
       
  2692 	if(userResponse)
       
  2693 		{
       
  2694 		StoreLocationDetailsToEntryL(landmark);
       
  2695 		}
       
  2696 		
       
  2697 	TRACE_EXIT_POINT;	
       
  2698 	}
       
  2699 
       
  2700 // -----------------------------------------------------------------------------
       
  2701 // CCalenUnifiedEditor::HandleEntryWithLocationEditionL
       
  2702 // Shows suery to the user to replace gthe exisitng saved address
       
  2703 // -----------------------------------------------------------------------------
       
  2704 //  
       
  2705 void CCalenUnifiedEditor::HandleEntryWithLocationEditionL(CPosLandmark* landmark)
       
  2706     {
       
  2707     TRACE_ENTRY_POINT;
       
  2708 
       
  2709     // User is tyring to update the location field of an entry which 
       
  2710     // already has location text as well as geo coordinates
       
  2711     TBuf<ECalenAbsoluteMaxTextEditorLength> locationInfo;
       
  2712     GetEdwinText(locationInfo, ECalenEditorPlace);
       
  2713     TPtrC landmarkname;
       
  2714         landmark->GetLandmarkName(landmarkname);
       
  2715     RPointerArray<HBufC> locationStrings;
       
  2716     HBufC* oldLocation = HBufC::NewL(MaxTextEditorLength());
       
  2717     oldLocation->Des().Copy(locationInfo);
       
  2718     
       
  2719     HBufC* oldNewLocation = HBufC::NewL(MaxTextEditorLength());
       
  2720     TBuf<2*ECalenAbsoluteMaxTextEditorLength> combLocation;
       
  2721     combLocation.Append(locationInfo);
       
  2722     combLocation.Append(KComma);
       
  2723     combLocation.Append(landmarkname);
       
  2724     oldNewLocation->Des().Copy(combLocation.Left(MaxTextEditorLength()));
       
  2725     
       
  2726     HBufC* newLocation = HBufC::NewL(MaxTextEditorLength());
       
  2727     newLocation->Des().Copy(landmarkname);
       
  2728     locationStrings.Append(oldNewLocation);
       
  2729     locationStrings.Append(newLocation);
       
  2730     locationStrings.Append(oldLocation);
       
  2731     TInt userResponse = CCalenLocationUtil::ShowLocationAppendOrReplaceL(locationStrings);
       
  2732     locationStrings.ResetAndDestroy();
       
  2733     if(userResponse == KErrCancel)
       
  2734         {
       
  2735         return;
       
  2736         }
       
  2737     switch(userResponse)
       
  2738         {
       
  2739         case 0:
       
  2740             {
       
  2741             landmark->SetLandmarkNameL(combLocation.Left(MaxTextEditorLength()));
       
  2742             }
       
  2743             break;
       
  2744         case 1:
       
  2745             {
       
  2746             landmark->SetLandmarkNameL(landmarkname);
       
  2747             }
       
  2748             break;
       
  2749         case 2:
       
  2750             {
       
  2751             landmark->SetLandmarkNameL(locationInfo);
       
  2752             }
       
  2753             break;
       
  2754         default:
       
  2755             break;
       
  2756         }
       
  2757         StoreLocationDetailsToEntryL(landmark);
       
  2758         
       
  2759     TRACE_EXIT_POINT;   
       
  2760     }
       
  2761 
       
  2762 // -----------------------------------------------------------------------------
       
  2763 // CCalenUnifiedEditor::StoreLocationDetailsToEntryL
       
  2764 // Stores landmark details and displays selected location details on the 
       
  2765 // currently shown editor form
       
  2766 // -----------------------------------------------------------------------------
       
  2767 //	
       
  2768 void CCalenUnifiedEditor::StoreLocationDetailsToEntryL(CPosLandmark* landmark)
       
  2769 	{
       
  2770 	TRACE_ENTRY_POINT;
       
  2771 	
       
  2772 	TLocality position;
       
  2773     landmark->GetPosition(position);
       
  2774     
       
  2775     TBuf<ECalenAbsoluteMaxTextEditorLength> existingLocationInfo;
       
  2776     GetEdwinText(existingLocationInfo, ECalenEditorPlace);
       
  2777     
       
  2778      //Store the geo coordinates
       
  2779     CCalGeoValue* geoValue = CCalGeoValue::NewL();
       
  2780     geoValue->SetLatLongL( position.Latitude(), position.Longitude() );
       
  2781     EditorDataHandler().Entry().SetGeoValueL( *geoValue );
       
  2782     delete geoValue;
       
  2783     
       
  2784     TBuf<ECalenAbsoluteMaxTextEditorLength> locationDetails;
       
  2785     TPtrC landmarkname;
       
  2786     landmark->GetLandmarkName( landmarkname );
       
  2787     locationDetails.Append( landmarkname );
       
  2788     
       
  2789     TPtrC landmarkDesc;
       
  2790     landmark->GetLandmarkDescription( landmarkDesc );
       
  2791     if( landmarkDesc.Size() )
       
  2792         {
       
  2793         locationDetails.Append( KComma );
       
  2794         locationDetails.Append( landmarkDesc );
       
  2795         }
       
  2796     
       
  2797     Edited().SetLocationL( locationDetails.Left( MaxTextEditorLength()) );
       
  2798 
       
  2799     TPtrC location = Edited().Location().Left( MaxTextEditorLength() );
       
  2800     EditorDataHandler().Entry().SetLocationL( location );
       
  2801 
       
  2802 	SetEdwinTextL(ECalenEditorPlace, &location);
       
  2803 	if(existingLocationInfo.Length())
       
  2804         {
       
  2805         ShowAddressUpdatedNoticeL();
       
  2806         }
       
  2807 	 
       
  2808 	
       
  2809 	TRACE_EXIT_POINT;	
       
  2810 	}
       
  2811 	
       
  2812 // ----------------------------------------------------------------------------
       
  2813 // CCalenUnifiedEditor::ShowLocationReplaceNoticeL
       
  2814 // Function to query user whether to replace or keep existing location details
       
  2815 // (other items were commented in a header).
       
  2816 // ----------------------------------------------------------------------------
       
  2817 //
       
  2818 TInt CCalenUnifiedEditor::ShowLocationReplaceNoticeL(TPtrC aLocationName)
       
  2819 	{
       
  2820 	TRACE_ENTRY_POINT;
       
  2821 	
       
  2822 	CAknQueryDialog *dialog = CAknQueryDialog::NewL( );
       
  2823     CleanupStack::PushL( dialog );
       
  2824     TInt resID = R_CALEN_QTN_REPLACE_LOCATION;
       
  2825     
       
  2826     TBuf<ECalenAbsoluteMaxTextEditorLength> location;
       
  2827     TChar quote = '"';
       
  2828     location.Append(quote);
       
  2829     location.Append(aLocationName);
       
  2830     location.Append(quote);
       
  2831     
       
  2832     CEikonEnv* eikEnv = CEikonEnv::Static();
       
  2833     
       
  2834      HBufC* prompt = StringLoader::LoadLC( resID, location, eikEnv );
       
  2835 	
       
  2836 	dialog->SetPromptL( *prompt );
       
  2837     CleanupStack::PopAndDestroy( prompt );
       
  2838 
       
  2839     CleanupStack::Pop( dialog );
       
  2840 	
       
  2841 	return dialog->ExecuteLD( R_CALEN_LOCATION_REPLACE_NOTE );
       
  2842 	
       
  2843 	TRACE_EXIT_POINT;	
       
  2844 	}
       
  2845 	
       
  2846 // ----------------------------------------------------------------------------
       
  2847 // CCalenUnifiedEditor::ShowAddressUpdatedNoticeL
       
  2848 // Displays "Address Updated" transient notice
       
  2849 // (other items were commented in a header).
       
  2850 // ----------------------------------------------------------------------------
       
  2851 //  
       
  2852 void CCalenUnifiedEditor::ShowAddressUpdatedNoticeL()
       
  2853     {
       
  2854     HBufC* buf = StringLoader::LoadLC( R_CALEN_QTN_ADDRESS_UPDATED, CEikonEnv::Static() );
       
  2855     CAknConfirmationNote* dialog = new( ELeave ) CAknConfirmationNote();
       
  2856     dialog->ExecuteLD(*buf);
       
  2857     CleanupStack::PopAndDestroy( buf );     
       
  2858     }
       
  2859 
       
  2860 // -----------------------------------------------------------------------------
       
  2861 //  CCalenUnifiedEditor::CheckManualEditionOfLocationL
       
  2862 //  Checks if user has edited location field manually
       
  2863 // -----------------------------------------------------------------------------
       
  2864 //
       
  2865 void CCalenUnifiedEditor::CheckManualEditionOfLocationL()
       
  2866     {
       
  2867     TRACE_ENTRY_POINT;
       
  2868     
       
  2869     CCalEntry& entry = EditorDataHandler().Entry();
       
  2870     CCalGeoValue* geoValue = entry.GeoValueL();
       
  2871     if( !geoValue )
       
  2872         {
       
  2873         return;
       
  2874         }
       
  2875     delete geoValue;
       
  2876     
       
  2877     TPtrC entryLocation = entry.LocationL();    
       
  2878     TBuf<ECalenAbsoluteMaxTextEditorLength> location;
       
  2879     location.Copy(Edited().Location());
       
  2880     
       
  2881     if( entryLocation != location )
       
  2882         {
       
  2883         // USer has manually edited the location field
       
  2884         TInt response = ShowLocationChangeNoticeL();
       
  2885         if( !response )
       
  2886             {
       
  2887             // Clear the geo coordinates for the entry
       
  2888             entry.ClearGeoValueL();
       
  2889             Edited().SetLocationL( location );
       
  2890             EditorDataHandler().Entry().SetLocationL(location);
       
  2891             SetEdwinTextL(ECalenEditorPlace, &location);
       
  2892             }
       
  2893         else
       
  2894             {
       
  2895             EditorDataHandler().Entry().SetLocationL(location);   
       
  2896             }
       
  2897         }
       
  2898         
       
  2899     TRACE_EXIT_POINT;
       
  2900     }
       
  2901 
       
  2902 // -----------------------------------------------------------------------------
       
  2903 //  CCalenUnifiedEditor::ShowLocationChangeNoticeL
       
  2904 //  Queries user whether to keep the exisiting coordianates or not
       
  2905 // -----------------------------------------------------------------------------
       
  2906 //  
       
  2907 TInt CCalenUnifiedEditor::ShowLocationChangeNoticeL()
       
  2908     {
       
  2909     TRACE_ENTRY_POINT;
       
  2910     
       
  2911     CAknQueryDialog *dialog = CAknQueryDialog::NewL( );
       
  2912     CleanupStack::PushL( dialog );
       
  2913     TInt resID = R_CALEN_QTN_GEOVALUES_REMOVAL;
       
  2914     
       
  2915     HBufC* prompt;
       
  2916     prompt = StringLoader::LoadLC( resID, iCoeEnv );
       
  2917     dialog->SetPromptL( *prompt );
       
  2918     CleanupStack::PopAndDestroy( prompt );
       
  2919     CleanupStack::Pop( dialog );
       
  2920     
       
  2921     return dialog->ExecuteLD( R_CALEN_GEOVALUES_REMOVAL_NOTE ); 
       
  2922     TRACE_EXIT_POINT;
       
  2923     }
       
  2924 
       
  2925 // -----------------------------------------------------------------------------
       
  2926 // CCalenUnifiedEditor::UpdateAttachmentInfoToEditorL
       
  2927 // Update attachment info to editor whenever an file is selected
       
  2928 // -----------------------------------------------------------------------------
       
  2929 // 
       
  2930 void CCalenUnifiedEditor::UpdateAttachmentInfoToEditorL()
       
  2931     {
       
  2932     TRACE_ENTRY_POINT;
       
  2933     const TDesC& emptyText = KEmpty;
       
  2934     SetEdwinTextL(ECalenEditorAttachment, &emptyText);
       
  2935     
       
  2936     TInt attachmentCount = iServices->GetAttachmentData()->NumberOfItems();
       
  2937     if( attachmentCount )
       
  2938         {
       
  2939         RPointerArray<CCalenAttachmentInfo> attachmentInfoList;      
       
  2940         iServices->GetAttachmentData()->GetAttachmentListL(attachmentInfoList);
       
  2941         
       
  2942         TInt attachmentLength(0);
       
  2943         for( TInt index =0; index<attachmentCount; index++ )
       
  2944             {
       
  2945             if(index>0)
       
  2946                 {
       
  2947                 attachmentLength++;
       
  2948                 }
       
  2949             CCalenAttachmentInfo* attachmentInfo = attachmentInfoList[index];
       
  2950             TParsePtrC fileNameParser( attachmentInfo->FileName() );
       
  2951             attachmentLength += fileNameParser.NameAndExt().Length();
       
  2952             }
       
  2953         
       
  2954         // Additional space is for appending "; " after each attachment to separate multiple attachments
       
  2955         HBufC* attachmentNames = HBufC::NewLC( attachmentLength + 
       
  2956                                              ( attachmentCount - 1 ) * KAttachmentSeparator.iTypeLength );
       
  2957         CleanupStack::Pop( attachmentNames );
       
  2958         TPtr ptr( attachmentNames->Des() );
       
  2959         for( TInt index=0; index<attachmentCount; index++ )
       
  2960             { 
       
  2961             if( index>0 )
       
  2962                 {
       
  2963                 ptr.Append( KAttachmentSeparator );
       
  2964                 }
       
  2965             CCalenAttachmentInfo* attachmentInfo = attachmentInfoList[index];
       
  2966             TParsePtrC fileNameParser( attachmentInfo->FileName()) ;
       
  2967             ptr.Append( fileNameParser.NameAndExt() );
       
  2968             }
       
  2969         
       
  2970         SetUnderLineForAttachmentL( EUnderlineOn );
       
  2971         SetEdwinTextL( ECalenEditorAttachment, &ptr );
       
  2972         delete attachmentNames;
       
  2973         
       
  2974         attachmentInfoList.Close();
       
  2975         UpdateFormL();
       
  2976         }
       
  2977     
       
  2978     // Update the attachment cound in editedentryutil as attachment would have added or deleted
       
  2979     CheckForAttachmentsInEditorL();
       
  2980     TRACE_EXIT_POINT;
       
  2981     }
       
  2982 
       
  2983 // -----------------------------------------------------------------------------
       
  2984 // CCalenUnifiedEditor::SetUnderLineForAttachmentL
       
  2985 // Sets the undeline for the attachment field's text
       
  2986 // -----------------------------------------------------------------------------
       
  2987 // 
       
  2988 void CCalenUnifiedEditor::SetUnderLineForAttachmentL( TFontUnderline aUnderLine )
       
  2989     {
       
  2990     TRACE_ENTRY_POINT;
       
  2991     
       
  2992     CEikRichTextEditor* attachmentControl = static_cast<CEikRichTextEditor*>(
       
  2993                                                 Control( ECalenEditorAttachment ) );
       
  2994     TCharFormat charFormat;
       
  2995     TCharFormatMask charFormatMask;
       
  2996     charFormatMask.SetAttrib( EAttFontUnderline );
       
  2997     charFormat.iFontPresentation.iUnderline = aUnderLine;
       
  2998     
       
  2999     attachmentControl->ApplyCharFormatL( charFormat,charFormatMask );
       
  3000     attachmentControl->HandleTextChangedL();
       
  3001     TRACE_EXIT_POINT;
       
  3002     }
       
  3003 
       
  3004 // -----------------------------------------------------------------------------
       
  3005 // CCalenUnifiedEditor::GetAttachmentNamesString
       
  3006 // Merges individual attachment names into a single string
       
  3007 // -----------------------------------------------------------------------------
       
  3008 // 
       
  3009 void CCalenUnifiedEditor::GetAttachmentNamesString( RPointerArray<HBufC>& aAttachmentNames,
       
  3010                                                     HBufC& aAttachmentNamesString)
       
  3011     {
       
  3012     TRACE_ENTRY_POINT;
       
  3013    TInt attachmentCount = aAttachmentNames.Count();        
       
  3014    TPtr ptr( aAttachmentNamesString.Des() );
       
  3015    for( TInt index=0; index<attachmentCount; index++ )
       
  3016        { 
       
  3017        if( index>0 )
       
  3018            {
       
  3019            ptr.Append( KAttachmentSeparator );
       
  3020            }
       
  3021        ptr.Append( aAttachmentNames[index]->Des() );
       
  3022        }
       
  3023     TRACE_EXIT_POINT;
       
  3024     }
       
  3025 
       
  3026 // -----------------------------------------------------------------------------
       
  3027 // CCalenUnifiedEditor::CheckForAttachmentsInEditorL
       
  3028 // Check for attachments in editor,if present save the attachment count which is
       
  3029 // used while saving the attachments to the calentry
       
  3030 // -----------------------------------------------------------------------------
       
  3031 // 
       
  3032 void CCalenUnifiedEditor::CheckForAttachmentsInEditorL()
       
  3033     {
       
  3034     TRACE_ENTRY_POINT;
       
  3035     
       
  3036     TInt attachmentCount = iServices->GetAttachmentData()->NumberOfItems();
       
  3037     Edited().SetAttachmentCount( attachmentCount );
       
  3038     
       
  3039     TRACE_EXIT_POINT;
       
  3040     }
       
  3041 
       
  3042 // -----------------------------------------------------------------------------
       
  3043 // CCalenUnifiedEditor::SetAttachmentNamesToEditorL
       
  3044 // Set attachment names to the editor,if entry is already having the attachments
       
  3045 // and is being opened in editor
       
  3046 // -----------------------------------------------------------------------------
       
  3047 //
       
  3048 void CCalenUnifiedEditor::SetAttachmentNamesToEditorL()
       
  3049     {
       
  3050     TRACE_ENTRY_POINT;
       
  3051     TInt attachmentCount = Edited().AttachmentCount();
       
  3052     if( attachmentCount )
       
  3053         {
       
  3054         RPointerArray<HBufC> attachmentNames;
       
  3055         CleanupResetAndDestroyPushL(attachmentNames);
       
  3056         GetAttachmentNamesL(attachmentNames);
       
  3057         attachmentCount = attachmentNames.Count();            
       
  3058         TInt attachmentLength(0);        
       
  3059         for( TInt index =0; index<attachmentCount; index++ )
       
  3060             {
       
  3061             if(index>0)
       
  3062                 {
       
  3063                 attachmentLength++;
       
  3064                 }
       
  3065             
       
  3066             attachmentLength += attachmentNames[index]->Length();
       
  3067             // We need two extra spaces for adding "; " between multiple attachments
       
  3068             attachmentLength += KAttachmentSeparator.iTypeLength;
       
  3069             }
       
  3070         
       
  3071         HBufC* attachmentNamesString = HBufC::NewLC( attachmentLength );
       
  3072         CleanupStack::Pop( attachmentNamesString );
       
  3073         GetAttachmentNamesString(attachmentNames, *attachmentNamesString);
       
  3074         
       
  3075         SetUnderLineForAttachmentL( EUnderlineOn );
       
  3076         SetEdwinTextL( ECalenEditorAttachment, attachmentNamesString );
       
  3077         
       
  3078         // Cleanup
       
  3079         delete attachmentNamesString;
       
  3080         CleanupStack::PopAndDestroy(&attachmentNames);
       
  3081         }
       
  3082     
       
  3083     TRACE_EXIT_POINT;
       
  3084     }
       
  3085 
       
  3086 // -----------------------------------------------------------------------------
       
  3087 // CCalenUnifiedEditor::EntryHasAttachments
       
  3088 // check whether the entry has attachments or not
       
  3089 // -----------------------------------------------------------------------------
       
  3090 //
       
  3091 TBool CCalenUnifiedEditor::EntryHasAttachments()
       
  3092     {
       
  3093     TRACE_ENTRY_POINT;
       
  3094     TBool attachmentExists(EFalse);
       
  3095     TInt attachmentCountFromModel = iServices->GetAttachmentData()->NumberOfItems();
       
  3096     if( Edited().AttachmentCount() || attachmentCountFromModel )
       
  3097         {
       
  3098         attachmentExists = ETrue;
       
  3099         }
       
  3100     TRACE_EXIT_POINT;
       
  3101     
       
  3102     return attachmentExists;
       
  3103     }
       
  3104 
       
  3105 // -----------------------------------------------------------------------------
       
  3106 // CCalenController::GetAllCollectionidsL
       
  3107 // -----------------------------------------------------------------------------
       
  3108 //
       
  3109 void CCalenUnifiedEditor::GetAllCollectionidsL(
       
  3110                                            RArray<TInt>& aCollectionIds)
       
  3111     {
       
  3112     TRACE_ENTRY_POINT
       
  3113     RPointerArray<CCalCalendarInfo> calendarInfoList;
       
  3114     CleanupClosePushL(calendarInfoList);
       
  3115     iServices->GetAllCalendarInfoL(calendarInfoList);
       
  3116     
       
  3117     for(TInt index=0;index<calendarInfoList.Count();index++)
       
  3118         {
       
  3119         aCollectionIds.Append( iServices->SessionL( 
       
  3120                calendarInfoList[index]->FileNameL() ).CollectionIdL() );
       
  3121         }
       
  3122     
       
  3123     CleanupStack::PopAndDestroy(&calendarInfoList);
       
  3124     TRACE_EXIT_POINT
       
  3125     }
       
  3126 // -----------------------------------------------------------------------------
       
  3127 // From CEikDialog
       
  3128 // We will hit this event each time a line has changed in the form
       
  3129 // -----------------------------------------------------------------------------
       
  3130 // 
       
  3131 void CCalenUnifiedEditor::LineChangedL( TInt /* aControlId */ )
       
  3132     {
       
  3133     TRACE_ENTRY_POINT;
       
  3134 
       
  3135     SetMskFromResourceL();
       
  3136     TRACE_EXIT_POINT;
       
  3137     }
       
  3138 
       
  3139 
       
  3140 // -----------------------------------------------------------------------------
       
  3141 // Update CBA with corresponding MSK button.
       
  3142 // This function is e.g. called from HanleControlEvent()
       
  3143 // Will issue HandleControlStateChangeL() call.
       
  3144 // -----------------------------------------------------------------------------
       
  3145 // 
       
  3146 void CCalenUnifiedEditor::SetMskFromResourceL()
       
  3147     {
       
  3148     TRACE_ENTRY_POINT;
       
  3149     CEikButtonGroupContainer&  cba = ButtonGroupContainer ();
       
  3150         TInt resid=0;
       
  3151         TInt ctrlid=IdOfFocusControl();
       
  3152 
       
  3153         switch( ctrlid )
       
  3154             {
       
  3155 
       
  3156             // for these fields we use change button
       
  3157             case ECalenEditorReminder:    /* fall through... */
       
  3158             case ECalenEditorRepeat:     /* fall through... */
       
  3159                 
       
  3160                 resid=R_CALEN_MSK_CHANGE_CBA;
       
  3161                 break;
       
  3162             // for description field it is open
       
  3163             case ECalenEditorDescription:
       
  3164                // resid=R_CALEN_MSK_OPEN_CBA;
       
  3165                // break;
       
  3166             // for location field
       
  3167             case ECalenEditorPlace:
       
  3168                 if(CCalenLocationUtil::IsMapProviderAvailableL())
       
  3169                     {
       
  3170                     resid = R_CALEN_MSK_FROMMAP_CBA;    
       
  3171                     }
       
  3172                 else
       
  3173                     {
       
  3174                     resid=R_CALEN_MSK_EMPTY_CBA;    
       
  3175                     }
       
  3176                 break;
       
  3177             // otherwise use empty MSK
       
  3178             case ECalenEditorSubject:            /* fall through... */
       
  3179             case ECalenEditorReminderDate:    
       
  3180             case ECalenEditorReminderTime:    /* fall through... */
       
  3181             case ECalenEditorEndDate:          /* fall through... */
       
  3182             case ECalenEditorEndTime:
       
  3183             case ECalenEditorDueDate:
       
  3184             case ECalenEditorStartDate:
       
  3185             case ECalenEditorStartTime:
       
  3186             case ECalenEditorBirthDayYear:                
       
  3187             default:
       
  3188                 resid=R_CALEN_MSK_EMPTY_CBA;
       
  3189                 break;
       
  3190 
       
  3191             case ECalenEditorRepeatUntil:      
       
  3192 			case ECalenEditorAllDayItem:
       
  3193 			case ECalenEditorEventType:
       
  3194 			case ECalenEditorDBName:
       
  3195 			case ECalenEditorPriority:
       
  3196 				resid=R_CALEN_MSK_CHANGE_CBA;
       
  3197 				
       
  3198             }
       
  3199         
       
  3200         
       
  3201         // set desired CBA
       
  3202         cba.SetCommandSetL(resid);
       
  3203         cba.DrawNow();
       
  3204 
       
  3205     TRACE_EXIT_POINT;
       
  3206     }
       
  3207 
       
  3208 // -----------------------------------------------------------------------------
       
  3209 // CCalenUnifiedEditor::VerifyCollectionId
       
  3210 // Verify if the collectionid exsists in the array of collecteids
       
  3211 // -----------------------------------------------------------------------------
       
  3212 //
       
  3213 void CCalenUnifiedEditor::VerifyCollectionIdL(const TCalCollectionId aColId)
       
  3214     {
       
  3215     TRACE_ENTRY_POINT
       
  3216     TInt errVal = KErrNotFound;
       
  3217     errVal = iCollectionIds.Find((TInt)aColId);
       
  3218     User::LeaveIfError(errVal);
       
  3219     TRACE_EXIT_POINT
       
  3220     }
       
  3221 
       
  3222 // -----------------------------------------------------------------------------
       
  3223 // CCalenUnifiedEditor::ModifyDbField
       
  3224 // modifies the DB filed in cenrep if user has edited it.
       
  3225 // -----------------------------------------------------------------------------
       
  3226 //
       
  3227 void CCalenUnifiedEditor::ModifyDbFieldL()
       
  3228     {
       
  3229     if(IsCreatingNewEntry())
       
  3230         {                
       
  3231         RPointerArray<CCalCalendarInfo> calendarInfoList; 
       
  3232         iServices->GetAllCalendarInfoL(calendarInfoList);
       
  3233         CleanupClosePushL( calendarInfoList );
       
  3234         TInt pos = iUnifiedEditorControl->GetCalendarIndexForEntryL();
       
  3235         TPtrC  lastUsedCalendarName = calendarInfoList[pos]->FileNameL();
       
  3236         CleanupStack::PopAndDestroy( &calendarInfoList );
       
  3237         
       
  3238         CRepository* cenRep = CRepository::NewLC(KCRUidCalendar); 
       
  3239         User::LeaveIfError( cenRep->Set( KCalendarLastUsedCalendar, lastUsedCalendarName ) );
       
  3240         CleanupStack::PopAndDestroy( cenRep );
       
  3241         }       
       
  3242     }
       
  3243 // -----------------------------------------------------------------------------
       
  3244 // CCalenUnifiedEditor::HideFieldsForEditSingleInstance
       
  3245 // Hides Entry type and Calendar Field for exceptional entry/single
       
  3246 // instance of recurrent entry.
       
  3247 // -----------------------------------------------------------------------------
       
  3248 //
       
  3249 void CCalenUnifiedEditor::HideFieldsForEditSingleInstanceL()
       
  3250     {
       
  3251     TRACE_ENTRY_POINT;
       
  3252     
       
  3253     if( !IsCreatingNewEntry() )
       
  3254         {
       
  3255         if((CalenAgendaUtils::IsRepeatingL(*iOriginalCalEntry) 
       
  3256                 && iRepeatType == CalCommon::EThisOnly)
       
  3257                 || iOriginalCalEntry->RecurrenceIdL().TimeUtcL() != Time::NullTTime())
       
  3258             {
       
  3259             //Hides Entry Type Filed            
       
  3260             CCoeControl* entryTypeControl = ControlOrNull( ECalenEditorEventType );
       
  3261             if( entryTypeControl )
       
  3262                 {
       
  3263                 DeleteLine(ECalenEditorEventType);
       
  3264                 }
       
  3265             //Hides All Day Event Field
       
  3266             CCoeControl* allDayEventControl = ControlOrNull( ECalenEditorAllDayItem );
       
  3267             if( allDayEventControl )
       
  3268                 {
       
  3269                 DeleteLine(ECalenEditorAllDayItem);
       
  3270                 }
       
  3271             //Hides Calendar Field
       
  3272             CCoeControl* calendarControl = ControlOrNull( ECalenEditorDBName );
       
  3273             if( calendarControl )
       
  3274                 {  
       
  3275                 DeleteLine(ECalenEditorDBName);
       
  3276                 }       
       
  3277             //Hides Repeat Field
       
  3278             CCoeControl* repeatControl = ControlOrNull( ECalenEditorRepeat );
       
  3279             if( repeatControl )
       
  3280                 {
       
  3281                 DeleteLine(ECalenEditorRepeat);
       
  3282                 }            
       
  3283             //Hides Repeatuntil Field
       
  3284             CCoeControl* repeatUntilControl = ControlOrNull( ECalenEditorRepeatUntil );
       
  3285             if( repeatUntilControl )
       
  3286                 {       
       
  3287                 DeleteLine(ECalenEditorRepeatUntil);
       
  3288                 }            
       
  3289             }
       
  3290         }
       
  3291     UpdateFormL();
       
  3292     TRACE_EXIT_POINT;
       
  3293     }
       
  3294 
       
  3295 
       
  3296 // -----------------------------------------------------------------------------
       
  3297 // CCalenUnifiedEditor::AttachmentNamesL
       
  3298 // Provides all the attachments names
       
  3299 // -----------------------------------------------------------------------------
       
  3300 // 
       
  3301 void CCalenUnifiedEditor::GetAttachmentNamesL(RPointerArray<HBufC>& aAttachmentNames)
       
  3302     {
       
  3303     TInt attachCount = iServices->GetAttachmentData()->NumberOfItems();
       
  3304     if( attachCount )
       
  3305         {    
       
  3306         RPointerArray<CCalenAttachmentInfo> attachmentInfoList;  
       
  3307 		CleanupClosePushL( attachmentInfoList );
       
  3308         iServices->GetAttachmentData()->GetAttachmentListL(attachmentInfoList);
       
  3309         for( TInt index =0; index<attachCount; index++ )
       
  3310             {
       
  3311             CCalenAttachmentInfo* attachmentInfo = attachmentInfoList[index];
       
  3312             TParsePtrC fileNameParser( attachmentInfo->FileName() );
       
  3313             HBufC* attachmentName = HBufC::NewL(fileNameParser.NameAndExt().Length());
       
  3314             attachmentName->Des().Copy(fileNameParser.NameAndExt());
       
  3315             aAttachmentNames.Append(attachmentName);
       
  3316             }
       
  3317 		CleanupStack::PopAndDestroy( &attachmentInfoList );		
       
  3318         }
       
  3319     else
       
  3320         {
       
  3321         Edited().AttachmentNamesL(aAttachmentNames);
       
  3322         }
       
  3323     }
       
  3324 
       
  3325 // -----------------------------------------------------------------------------
       
  3326 // CCalenUnifiedEditor::GetServices
       
  3327 // Gets services reference
       
  3328 // -----------------------------------------------------------------------------
       
  3329 //
       
  3330 MCalenServices& CCalenUnifiedEditor::GetServices()
       
  3331     {
       
  3332     return *iServices;
       
  3333     }
       
  3334 	
       
  3335 // -----------------------------------------------------------------------------
       
  3336 // CMapsIconPicture::CMapsIconPicture
       
  3337 // C++ Constructor
       
  3338 // -----------------------------------------------------------------------------
       
  3339 //
       
  3340 CMapsIconPicture::CMapsIconPicture( MCalenServices& aServices, TRect aRect ) 
       
  3341 : iServices( aServices ), 
       
  3342   iRect( aRect ) 
       
  3343     {
       
  3344     TRACE_ENTRY_POINT;
       
  3345     TRACE_EXIT_POINT;   
       
  3346     }
       
  3347 
       
  3348 // -----------------------------------------------------------------------------
       
  3349 // CMapsIconPicture::ExternalizeL
       
  3350 // Pure virtual from CPicture, intentionally empty.
       
  3351 // -----------------------------------------------------------------------------
       
  3352 //  
       
  3353 void CMapsIconPicture::ExternalizeL( RWriteStream& /*aStream*/ ) const 
       
  3354     {
       
  3355     TRACE_ENTRY_POINT;
       
  3356     TRACE_EXIT_POINT;   
       
  3357     }
       
  3358 
       
  3359 // -----------------------------------------------------------------------------
       
  3360 // CMapsIconPicture::GetOriginalSizeInTwips
       
  3361 // Convert size to twips
       
  3362 // -----------------------------------------------------------------------------
       
  3363 //
       
  3364 void CMapsIconPicture::GetOriginalSizeInTwips( TSize & /* aSize */ ) const 
       
  3365     {
       
  3366     TRACE_ENTRY_POINT;
       
  3367     TRACE_EXIT_POINT;    
       
  3368     }
       
  3369 
       
  3370 // -----------------------------------------------------------------------------
       
  3371 // CMapsIconPicture::Draw
       
  3372 // Draw funtion to draw the map icon
       
  3373 // -----------------------------------------------------------------------------
       
  3374 //
       
  3375 void CMapsIconPicture::Draw( CGraphicsContext& aGc, 
       
  3376                              const TPoint& /* aTopLeft */,
       
  3377                              const TRect& /* aClipRect */,
       
  3378                              MGraphicsDeviceMap* /* aMap */) const
       
  3379     {
       
  3380     TRACE_ENTRY_POINT;
       
  3381     
       
  3382     aGc.Reset();
       
  3383     
       
  3384     // Create the icon
       
  3385     CGulIcon* icon = NULL;
       
  3386     PIM_TRAPD_HANDLE( icon = iServices.GetIconL( MCalenServices::ECalenMapIcon ) );   
       
  3387 
       
  3388     TAknLayoutRect icon_layout_rect;
       
  3389     icon_layout_rect.LayoutRect( iRect, AknLayoutScalable_Apps::field_cale_ev_pane_g1( 0 ).LayoutLine() );
       
  3390     TRect area = icon_layout_rect.Rect();
       
  3391     AknIconUtils::SetSize( icon->Bitmap(), area.Size() );
       
  3392     
       
  3393     aGc.DrawBitmapMasked( area, icon->Bitmap(), area.Size(), icon->Mask(), ETrue );
       
  3394     delete icon;
       
  3395     
       
  3396     TRACE_EXIT_POINT;   
       
  3397     }
       
  3398 // End of file
       
  3399