calendarui/controller/src/caleneditui.cpp
changeset 0 f979ecb2b13e
child 12 38571fd2a704
child 18 c198609911f9
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Controller class for editing related UI behavior
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <eikenv.h>
       
    20 #include <e32math.h>
       
    21 #include <StringLoader.h>
       
    22 #include <utf.h>
       
    23 #include <aknnotewrappers.h>
       
    24 #include <avkon.hrh>
       
    25 #include <CAgnEntryUi.h>
       
    26 #include <calentryview.h>
       
    27 #include <calentry.h>
       
    28 #include <calrrule.h>
       
    29 #include <caluser.h>
       
    30 #include <calenagendautils.h>
       
    31 #include <calendateutils.h>
       
    32 #include <CalenInterimUtils2.h>
       
    33 #include <CalenEditorsPlugin.h>
       
    34 #include <calenglobaldata.h>
       
    35 #include <Calendar.rsg>
       
    36 #include <calencommonui.rsg>
       
    37 #include <calencommands.hrh>            // Calendar commands
       
    38 #include <calencontext.h>
       
    39 #include <caleninstanceid.h>            // TCalenInstanceId
       
    40 #include <calentoolbar.h>
       
    41 #include <calenactionuiutils.h>
       
    42 #include <aknViewAppUi.h>           // CAknViewAppUi
       
    43 #include <aknview.h>
       
    44 
       
    45 #include "calendarui_debug.h"
       
    46 #include "caleneditui.h"
       
    47 #include "calencontroller.h"
       
    48 #include "calendar.hrh"
       
    49 #include "calensend.h"
       
    50 #include "CalenUid.h"
       
    51 #include "calenservicesimpl.h"
       
    52 #include "calenviewmanager.h"
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CCalenEditUi::NewL
       
    56 // First stage construction
       
    57 // (other items were commented in a header).
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 CCalenEditUi* CCalenEditUi::NewL( CCalenController& aController )
       
    61     {
       
    62     TRACE_ENTRY_POINT;
       
    63 
       
    64     CCalenEditUi* self = new(ELeave) CCalenEditUi( aController );
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop( self );
       
    68 
       
    69     TRACE_EXIT_POINT;
       
    70     return self;
       
    71     }
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // CCalenEditUi::~CCalenEditUi
       
    75 // Destructor
       
    76 // (other items were commented in a header).
       
    77 // ----------------------------------------------------------------------------
       
    78 //
       
    79 CCalenEditUi::~CCalenEditUi()
       
    80     {
       
    81     TRACE_ENTRY_POINT;
       
    82 
       
    83     delete iEditorsPlugin;
       
    84     delete iListItems;
       
    85     delete iListItemCommands;
       
    86     
       
    87     if( iWaitDialog )
       
    88         {
       
    89         delete iWaitDialog;
       
    90         }
       
    91 
       
    92     if( iGlobalData )
       
    93         {
       
    94         iGlobalData->Release();
       
    95         }
       
    96 
       
    97     TRACE_EXIT_POINT;
       
    98     }
       
    99 
       
   100 // ----------------------------------------------------------------------------
       
   101 // CCalenEditUi::CCalenEditUi
       
   102 // Constructor
       
   103 // (other items were commented in a header).
       
   104 // ----------------------------------------------------------------------------
       
   105 //
       
   106 CCalenEditUi::CCalenEditUi( CCalenController& aController )
       
   107     : iController( aController )
       
   108     {
       
   109     TRACE_ENTRY_POINT;
       
   110     TRACE_EXIT_POINT;
       
   111     }
       
   112 
       
   113 // ----------------------------------------------------------------------------
       
   114 // CCalenEditUi::ConstructL
       
   115 // Second stage construction
       
   116 // (other items were commented in a header).
       
   117 // ----------------------------------------------------------------------------
       
   118 //
       
   119 void CCalenEditUi::ConstructL()
       
   120     {
       
   121     TRACE_ENTRY_POINT;
       
   122 
       
   123     iGlobalData = CCalenGlobalData::InstanceL();
       
   124     iEntriesToComplete = 1;
       
   125     iMoreEntriesToComplete = EFalse;
       
   126     isEditorActive = EFalse;
       
   127     
       
   128     iController.RegisterForNotificationsL( this, ECalenNotifyCancelStatusUpdation );
       
   129 
       
   130     TRACE_EXIT_POINT;
       
   131     }
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 // CCalenEditUi::HandleActionUiCommandL
       
   135 // Handles action ui commands
       
   136 // (other items were commented in a header).
       
   137 // ----------------------------------------------------------------------------
       
   138 //
       
   139 TBool CCalenEditUi::HandleCommandL( const TCalenCommand& aCommand )
       
   140     {
       
   141     TRACE_ENTRY_POINT;
       
   142 
       
   143     TBool continueCommand(EFalse);
       
   144     TInt command = aCommand.Command();
       
   145 
       
   146     switch(command)
       
   147         {
       
   148         case ECalenNewMeeting:
       
   149         case ECalenNewDayNote:
       
   150         
       
   151             {
       
   152             TUid currentView = iController.ViewManager().CurrentView();
       
   153             if( KUidCalenTodoView == currentView )
       
   154                 {
       
   155                 // Open NewEntry as "To-Do", if editor is launched from To-Do view. 
       
   156                 EditNewEntryL( CCalEntry::ETodo );
       
   157                 }
       
   158             else
       
   159                 {
       
   160                 EditNewEntryL();
       
   161                 }
       
   162             }
       
   163             break;
       
   164         case ECalenNewTodo:
       
   165             EditNewEntryL( CCalEntry::ETodo );
       
   166             break;
       
   167         case ECalenNewAnniv:
       
   168             EditNewEntryL( CCalEntry::EAnniv );
       
   169             break;
       
   170         case ECalenNewMeetingRequest:
       
   171             {
       
   172             EditNewMeetingRequestL();
       
   173             }
       
   174             break;
       
   175         case ECalenEditCurrentEntry:
       
   176         case ECalenEditSeries:
       
   177         case ECalenEditOccurrence:
       
   178         case ECalenCompleteTodo:
       
   179         case ECalenRestoreTodo:
       
   180         case ECalenMarkEntryAsDone:
       
   181         case ECalenMarkEntryAsUnDone:
       
   182             {
       
   183             // These commands need the entry view
       
   184             // to be constructed before being called
       
   185             CCalEntryView* entryView = iGlobalData->EntryViewL();
       
   186             if( !entryView )
       
   187                 {
       
   188                 // Store the command and wait for notification
       
   189                 WaitForEntryViewNotificationL( aCommand );
       
   190                 }
       
   191             else
       
   192                 {
       
   193                 switch ( command )
       
   194                     {
       
   195                     case ECalenEditCurrentEntry:
       
   196                     	{
       
   197                         MCalenContext& context = iGlobalData->Context();
       
   198                         entryView = iGlobalData->EntryViewL(context.InstanceId().iColId);
       
   199                         CCalEntry* entry = entryView->FetchL(
       
   200                                                 context.InstanceId().iEntryLocalUid );
       
   201                         CleanupStack::PushL( entry );
       
   202                         User::LeaveIfNull( entry );
       
   203                         EditEntryL( entry,
       
   204                                     context.InstanceId().iInstanceTime,
       
   205                                     MAgnEntryUi::EEditExistingEntry );
       
   206 
       
   207                         CleanupStack::PopAndDestroy( entry );
       
   208                      
       
   209                     	break;
       
   210                     	}
       
   211                     case ECalenCompleteTodo:
       
   212                         SetTodoCompleteL( ETrue );
       
   213                         break;
       
   214                     case ECalenRestoreTodo:
       
   215                         SetTodoCompleteL( EFalse );
       
   216                         break;
       
   217                     case ECalenMarkEntryAsDone:
       
   218                         continueCommand = SetMultipleTodoCompleteL(ETrue );
       
   219                         break;
       
   220                      case ECalenMarkEntryAsUnDone:
       
   221                          continueCommand = SetMultipleTodoCompleteL(EFalse );
       
   222                         break;
       
   223                     default:
       
   224                          {
       
   225                          // Should never reach this point.
       
   226                          ASSERT( EFalse );   
       
   227                          }
       
   228                     }
       
   229                 }
       
   230             }
       
   231             break;
       
   232         case ECalenSend:
       
   233             {
       
   234             iGlobalData->CalenSendL().DisplaySendCascadeMenuL();
       
   235 
       
   236             if( iGlobalData->CalenSendL().CanSendL( ECalenSend ) )
       
   237                 {
       
   238                 SendEntryL();
       
   239                 iController.BroadcastNotification( ECalenNotifyEntrySent );
       
   240                 }
       
   241             // ECalenNotifyDialogClosed issued when Messaging Query is cancelled
       
   242             // by the user.
       
   243             else
       
   244                 {
       
   245                 iController.BroadcastNotification( ECalenNotifyDialogClosed );
       
   246                 }
       
   247                 
       
   248             }
       
   249             break;
       
   250         default:
       
   251             // Controller decided this class was the place to handle this
       
   252             // command
       
   253             break;
       
   254         }
       
   255 
       
   256     TRACE_EXIT_POINT;
       
   257     return continueCommand;
       
   258     }
       
   259 
       
   260 // ----------------------------------------------------------------------------
       
   261 // CCalenEditUi::CalenCommandHandlerExtensionL
       
   262 // Dummy implementation.
       
   263 // (other items were commented in a header).
       
   264 // ----------------------------------------------------------------------------
       
   265 //
       
   266 TAny* CCalenEditUi::CalenCommandHandlerExtensionL( TUid /*aExtensionUid*/ )
       
   267     {
       
   268     TRACE_ENTRY_POINT;
       
   269     TRACE_EXIT_POINT;
       
   270     return NULL;
       
   271     }
       
   272 
       
   273 // ----------------------------------------------------------------------------
       
   274 // CCalenEditUi::SetTodoCompleteL
       
   275 // Completes or restores a todo.
       
   276 // (other items were commented in a header).
       
   277 // ----------------------------------------------------------------------------
       
   278 //
       
   279 void CCalenEditUi::SetTodoCompleteL( TBool aComplete )
       
   280     {
       
   281     TRACE_ENTRY_POINT;
       
   282 
       
   283     MCalenContext& context = iGlobalData->Context();
       
   284     ASSERT( !( context.InstanceId() == ( TCalenInstanceId::NullInstanceId() ) ) );
       
   285 
       
   286     // HandleActionUiCommandL creates the entry view if it has
       
   287     // not already been created before SetTodoCompleteL is called.
       
   288     CCalEntryView* entryView = iGlobalData->EntryViewL(context.InstanceId().iColId);
       
   289     ASSERT( entryView );
       
   290 
       
   291     CCalEntry* entry = entryView->FetchL( context.InstanceId().iEntryLocalUid );
       
   292 
       
   293     CleanupStack::PushL( entry );
       
   294 
       
   295     if( entry )
       
   296         {
       
   297         CalenActionUiUtils::SetToDoCompleteStatusL( *entryView, entry, aComplete );
       
   298         //iContainer->NotifyEntryChangeL( *entry, entry->StartTimeL() );
       
   299         iController.BroadcastNotification( ECalenNotifyEntrySaved );
       
   300         }
       
   301 
       
   302     CleanupStack::PopAndDestroy( entry );
       
   303 
       
   304     TRACE_EXIT_POINT;
       
   305     }
       
   306 
       
   307 // ----------------------------------------------------------------------------
       
   308 // CCalenEditUi::SetTodoEntryCompleteL
       
   309 // Completes or restores a todo.
       
   310 // (other items were commented in a header).
       
   311 // ----------------------------------------------------------------------------
       
   312 //
       
   313 void CCalenEditUi::SetTodoEntryCompleteL(TBool aComplete,TCalLocalUid aEntryUid,TCalCollectionId colId)
       
   314     {
       
   315     TRACE_ENTRY_POINT;
       
   316 
       
   317     // HandleActionUiCommandL creates the entry view if it has
       
   318     // not already been created before SetTodoCompleteL is called.
       
   319    CCalEntryView* entryView = iGlobalData->EntryViewL(colId);
       
   320     ASSERT( entryView );
       
   321 
       
   322     CCalEntry* entry = entryView->FetchL( aEntryUid );
       
   323     CleanupStack::PushL( entry );
       
   324 
       
   325     if( entry )
       
   326         {
       
   327         CalenActionUiUtils::SetToDoCompleteStatusL( *entryView, entry, aComplete );
       
   328         }
       
   329 
       
   330     CleanupStack::PopAndDestroy( entry );    
       
   331     TRACE_EXIT_POINT;
       
   332     }
       
   333 
       
   334 // ----------------------------------------------------------------------------
       
   335 // CCalenEditUi::EditNewEntryL
       
   336 // Creates a new entry and opens it for editing
       
   337 // (other items were commented in a header).
       
   338 // ----------------------------------------------------------------------------
       
   339 //
       
   340 void CCalenEditUi::EditNewEntryL( CCalEntry::TType aEntryType)
       
   341     {
       
   342     TRACE_ENTRY_POINT;
       
   343 
       
   344     // Create unique ID.
       
   345     HBufC8* guid = iGlobalData->InterimUtilsL().GlobalUidL();
       
   346     CleanupStack::PushL( guid );
       
   347     CCalEntry* entry = CCalEntry::NewL( aEntryType, guid, CCalEntry::EMethodNone, 0 );
       
   348     CleanupStack::Pop( guid );
       
   349 
       
   350     CleanupStack::PushL( entry );
       
   351 
       
   352     // Set initial start and end times from Calendar context
       
   353     TTime focusedTime = CalculateActiveTimeFromContextL();
       
   354     TCalTime initialCalTime;
       
   355 
       
   356     initialCalTime.SetTimeLocalL( focusedTime );
       
   357 
       
   358     entry->SetStartAndEndTimeL( initialCalTime, initialCalTime );
       
   359     
       
   360     if( entry->EntryTypeL()==CCalEntry::EAnniv )
       
   361         {
       
   362         TCalRRule rrule( TCalRRule::EYearly );
       
   363         TCalTime startDate;
       
   364         rrule.SetDtStart( initialCalTime );
       
   365         rrule.SetInterval( 1 ); // once a year
       
   366         entry->SetRRuleL( rrule );
       
   367         }
       
   368     
       
   369     MCalenContext& context = iGlobalData->Context();
       
   370     TCalCollectionId colId = context.InstanceId().iColId;
       
   371     TCalenInstanceId id = TCalenInstanceId::CreateL( *entry, initialCalTime );
       
   372     id.iColId = colId;
       
   373     
       
   374     context.SetInstanceIdL( id, context.ViewId() ); 
       
   375     
       
   376     TTime instanceTime = entry->StartTimeL().TimeLocalL();
       
   377     EditEntryL( entry, instanceTime, MAgnEntryUi::ECreateNewEntry );
       
   378     CleanupStack::PopAndDestroy( entry );
       
   379 
       
   380     TRACE_EXIT_POINT;
       
   381     }
       
   382 
       
   383 // ----------------------------------------------------------------------------
       
   384 // CCalenEditUi::EditNewMeetingRequestL
       
   385 // Creates a new meeting request and opens it for editing
       
   386 // (other items were commented in a header).
       
   387 // ----------------------------------------------------------------------------
       
   388 //
       
   389 void CCalenEditUi::EditNewMeetingRequestL()
       
   390     {
       
   391     TRACE_ENTRY_POINT;
       
   392 
       
   393     CMRMailboxUtils::TMailboxInfo defaultMailBox;
       
   394 
       
   395     if( !iGlobalData->AttemptToRetrieveDefaultMailboxL( defaultMailBox ) )
       
   396         {
       
   397         // User either doesn't have any mailboxes or didn't select a default mailbox.
       
   398         // Don't create the meeting request.
       
   399         TRACE_EXIT_POINT;
       
   400         return;
       
   401         }
       
   402 
       
   403     // If we got this far, defaultMailBox should be initialised.
       
   404     HBufC8* guid = iGlobalData->InterimUtilsL().GlobalUidL();
       
   405 
       
   406     CleanupStack::PushL( guid );
       
   407     CCalEntry* entry = CCalEntry::NewL( CCalEntry::EAppt, 
       
   408                                                        guid,
       
   409                                                        CCalEntry::EMethodRequest,
       
   410                                                        0 );
       
   411     CleanupStack::Pop( guid );
       
   412     CleanupStack::PushL( entry );
       
   413 
       
   414     // Set initial start and end times from Active Calendar Context
       
   415     TTime focusedTime = iGlobalData->Context().FocusDateAndTimeL().TimeLocalL();
       
   416     TCalTime initialCalTime;
       
   417     // No need to handle floating time check here, as meetings are
       
   418     // always fixed.
       
   419     initialCalTime.SetTimeLocalL( focusedTime );
       
   420 
       
   421     entry->SetStartAndEndTimeL( initialCalTime, initialCalTime );
       
   422 
       
   423     //Set the organizer from the selected mailbox
       
   424     CCalUser* organizer = CCalUser::NewL( defaultMailBox.iEmailAddress );
       
   425     entry->SetOrganizerL( organizer );
       
   426 
       
   427     TTime instanceTime = entry->StartTimeL().TimeLocalL();
       
   428     EditEntryL( entry, instanceTime, MAgnEntryUi::ECreateNewEntry );
       
   429     CleanupStack::PopAndDestroy( entry );
       
   430 
       
   431     TRACE_EXIT_POINT;
       
   432     }
       
   433 
       
   434 // ----------------------------------------------------------------------------
       
   435 // CCalenEditUi::EditEntryL
       
   436 // Opens the entry aEntry for editing
       
   437 // (other items were commented in a header).
       
   438 // ----------------------------------------------------------------------------
       
   439 //
       
   440 void CCalenEditUi::EditEntryL( CCalEntry* aEntry, 
       
   441                                          const TTime& aInstanceDate,
       
   442                                          MAgnEntryUi::TAgnEntryUiEditorMode aEditorMode )
       
   443     {
       
   444     TRACE_ENTRY_POINT;
       
   445     
       
   446     // Set the flag
       
   447     isEditorActive = ETrue;
       
   448     
       
   449     if( !iEditorsPlugin )
       
   450         {
       
   451         //Only created on first use
       
   452         LoadEditorsPluginL();
       
   453         if( !iEditorsPlugin )
       
   454             {
       
   455             // User was prompted to set a default mailbox and hit cancel
       
   456             // Entry will not be opened
       
   457             TRACE_EXIT_POINT;
       
   458             return;
       
   459             }
       
   460         }
       
   461 
       
   462     MAgnEntryUi::TAgnEntryUiInParams inParams( KUidCalendar,
       
   463                                                iGlobalData->CalSessionL(),
       
   464                                                aEditorMode );
       
   465 
       
   466     // Use floating time for non-timed entries 
       
   467     if( !CalenAgendaUtils::IsTimedEntryL(aEntry->EntryTypeL()) )
       
   468         {
       
   469         inParams.iInstanceDate.SetTimeLocalFloatingL( aInstanceDate );
       
   470         }
       
   471     else
       
   472         {
       
   473         inParams.iInstanceDate.SetTimeLocalL( aInstanceDate );
       
   474         }
       
   475     
       
   476     inParams.iMsgSession = NULL;
       
   477 
       
   478     MAgnEntryUi::TAgnEntryUiOutParams outParams;
       
   479 
       
   480     // Launch Entry UI
       
   481     RPointerArray<CCalEntry> entries;
       
   482     CleanupClosePushL( entries );
       
   483     entries.AppendL( aEntry );  // aEntry already in cleanup stack -> safe
       
   484 
       
   485     // Editors need a services implementation.
       
   486     MCalenServices* svc = CCalenServicesImpl::NewL();
       
   487     CleanupReleasePushL( *svc );
       
   488     inParams.iSpare = ( TInt )svc;
       
   489 	
       
   490 	
       
   491     // Stop the population of the current view
       
   492     iController.ViewManager().InterruptPopulationL();
       
   493     
       
   494     // hide the toolbar
       
   495     MCalenToolbar* toolbar = iController.Services().ToolbarOrNull();
       
   496     if(toolbar)
       
   497         {
       
   498         toolbar->SetToolbarVisibilityL(EFalse);  
       
   499         }
       
   500 	
       
   501     
       
   502     // If a menubar is active,stop displaying it before launching editor
       
   503     TUid viewUid = iController.ViewManager().CurrentView();
       
   504     CEikMenuBar* menuBar = iController.AppUi().View(viewUid)->MenuBar();
       
   505     if(menuBar)
       
   506         {
       
   507         menuBar->StopDisplayingMenuBar();
       
   508         }
       
   509  
       
   510     // Launch the viewer / editor plugin
       
   511     iEditorsPlugin->ExecuteViewL( entries, inParams, outParams, *this );
       
   512     
       
   513     // Reset the flag
       
   514     isEditorActive = EFalse;
       
   515     
       
   516     // Unhide the toolbar when settings is closed
       
   517     if(toolbar)
       
   518         {
       
   519         toolbar->SetToolbarVisibilityL(ETrue); 
       
   520         }
       
   521 	
       
   522     CleanupStack::PopAndDestroy( svc );
       
   523 
       
   524     // Close the entries array
       
   525     CleanupStack::PopAndDestroy( &entries );
       
   526 
       
   527     switch( outParams.iAction )
       
   528         {
       
   529         case MAgnEntryUi::EMeetingSaved:
       
   530         case MAgnEntryUi::EInstanceRescheduled:
       
   531             {
       
   532             // Update context and issue notification before confirmation dialog
       
   533             // to avoid delay of updating title pane
       
   534             MCalenContext& context = iGlobalData->Context();
       
   535             TCalCollectionId colId = context.InstanceId().iColId;
       
   536             TCalenInstanceId id = TCalenInstanceId::CreateL( TCalLocalUid(
       
   537                     outParams.iSpare),
       
   538                     outParams.iNewInstanceDate.TimeLocalL(), EFalse );
       
   539             id.iColId = colId;
       
   540             id.iType = context.InstanceId().iType;
       
   541             if( aEditorMode != MAgnEntryUi::ECreateNewEntry )
       
   542                 {
       
   543                 id.iInstanceTime = context.InstanceId().iInstanceTime;
       
   544                 }
       
   545             context.SetInstanceIdL( id, context.ViewId() );
       
   546             iController.BroadcastNotification( ECalenNotifyEntrySaved );
       
   547 
       
   548             if( aEditorMode == MAgnEntryUi::ECreateNewEntry )
       
   549                 {
       
   550                 // Show saved note for new entries
       
   551                 TInt res;
       
   552                 if( aEntry->EntryTypeL() == CCalEntry::ETodo )
       
   553                     {
       
   554                     res = R_QTN_CALE_NOTE_TODO_SAVED;
       
   555                     }
       
   556                 else
       
   557                     {
       
   558                     res = R_TEXT_CALENDAR_NOTE_SAVED;
       
   559                     }
       
   560 
       
   561                 HBufC* prompt = StringLoader::LoadLC( res, CEikonEnv::Static() );
       
   562                 CAknConfirmationNote* dialog = new( ELeave )CAknConfirmationNote();
       
   563                 dialog->ExecuteLD( *prompt );
       
   564                 CleanupStack::PopAndDestroy( prompt );
       
   565                 }
       
   566             }
       
   567             break;
       
   568 
       
   569         case MAgnEntryUi::EMeetingDeleted:
       
   570             iController.BroadcastNotification( ECalenNotifyEntryDeleted );
       
   571             break;
       
   572 
       
   573         case MAgnEntryUi::EInstanceDeleted:
       
   574             iController.BroadcastNotification( ECalenNotifyInstanceDeleted );
       
   575             break;
       
   576 
       
   577         case MAgnEntryUi::ENoAction:
       
   578         default:
       
   579             iController.BroadcastNotification( ECalenNotifyEntrySaved );
       
   580             break;
       
   581         }
       
   582 
       
   583 
       
   584     TRACE_EXIT_POINT;
       
   585     }
       
   586 
       
   587 // ----------------------------------------------------------------------------
       
   588 // CCalenEditUi::LoadEditorsPluginL
       
   589 // Attempts to load the editors plugin into iEditorsPlugin. If failure occurs
       
   590 // (for example, if the user is prompted to select a default mailbox and hits
       
   591 // cancel), iEditorsPlugin is set to NULL.
       
   592 // (other items were commented in a header).
       
   593 // ----------------------------------------------------------------------------
       
   594 //
       
   595 void CCalenEditUi::LoadEditorsPluginL()
       
   596     {
       
   597     TRACE_ENTRY_POINT;
       
   598 
       
   599     delete iEditorsPlugin;
       
   600     iEditorsPlugin = NULL;
       
   601 
       
   602     if( iGlobalData->InterimUtilsL().MRViewersEnabledL() )
       
   603         {
       
   604         //Get the currently selected mailbox
       
   605         CMRMailboxUtils::TMailboxInfo defaultMailBox;
       
   606 
       
   607          if( iGlobalData->AttemptToRetrieveDefaultMailboxL( defaultMailBox ) )
       
   608              {
       
   609              //CAgnEntryUi resolves Meeting request viewer based on mtm uid
       
   610              TBuf8<KMaxUidName> mrMtm;
       
   611              CnvUtfConverter::ConvertFromUnicodeToUtf8( mrMtm, 
       
   612                                                                             defaultMailBox.iMtmUid.Name() );
       
   613              iEditorsPlugin = CAgnEntryUi::NewL( mrMtm );
       
   614              }
       
   615         }
       
   616     else
       
   617         {
       
   618         iEditorsPlugin = CCalenEditorsPlugin::NewL();
       
   619         }
       
   620 
       
   621     TRACE_EXIT_POINT;
       
   622     }
       
   623 
       
   624 
       
   625 // ----------------------------------------------------------------------------
       
   626 // CCalenEditUi::SendEntryL
       
   627 // Sends the current entry.
       
   628 // (other items were commented in a header).
       
   629 // ----------------------------------------------------------------------------
       
   630 //
       
   631 void CCalenEditUi::SendEntryL()
       
   632     {
       
   633     TRACE_ENTRY_POINT;
       
   634 
       
   635     MCalenContext& context = iGlobalData->Context();
       
   636     ASSERT( !( context.InstanceId() == TCalenInstanceId::NullInstanceId() ) );
       
   637 
       
   638     //If todo, use the LUid.
       
   639     //Todos returns the current time if start or end time has not been saved.
       
   640     if( CCalEntry::ETodo == context.InstanceId().iType )
       
   641         {
       
   642         CCalEntry* entry = iGlobalData->EntryViewL(context.InstanceId().iColId)->FetchL(
       
   643                                                       context.InstanceId().iEntryLocalUid );
       
   644         if( entry )
       
   645             {
       
   646             CleanupStack::PushL( entry );
       
   647             iGlobalData->CalenSendL().SendAsVCalendarL( ECalenSend, *entry );
       
   648             CleanupStack::PopAndDestroy( entry );
       
   649             }
       
   650         }
       
   651     else // Not todo
       
   652         {
       
   653         RArray<TInt> colIdArray;
       
   654         CleanupClosePushL(colIdArray);
       
   655         iController.GetActiveCollectionidsL(colIdArray);
       
   656         
       
   657         CCalInstance* instance = CalenActionUiUtils::FindPossibleInstanceL( 
       
   658                                                                 context.InstanceId(),
       
   659                                                                *iGlobalData->InstanceViewL(colIdArray) );
       
   660         CleanupStack::PushL( instance );
       
   661 
       
   662         if( instance )
       
   663             {
       
   664             CCalEntry& entry = instance->Entry();
       
   665             iGlobalData->CalenSendL().SendAsVCalendarL( ECalenSend, entry );
       
   666             }
       
   667 
       
   668         CleanupStack::PopAndDestroy( instance );
       
   669         CleanupStack::PopAndDestroy(&colIdArray);
       
   670         }
       
   671 
       
   672     TRACE_EXIT_POINT;
       
   673     }
       
   674 
       
   675 // ----------------------------------------------------------------------------
       
   676 // CCalenEditUi::ProcessCommandWithResultL
       
   677 // This is pure virtual from MAgnEntryUiCallback. We don't use it.
       
   678 // (other items were commented in a header).
       
   679 // ----------------------------------------------------------------------------
       
   680 //
       
   681 TInt CCalenEditUi::ProcessCommandWithResultL( TInt /*aCommandId*/ )
       
   682     {
       
   683     TRACE_ENTRY_POINT;
       
   684     TRACE_EXIT_POINT;
       
   685     return KErrNone;
       
   686     }
       
   687 
       
   688 // ----------------------------------------------------------------------------
       
   689 // CCalenEditUi::ProcessCommandL
       
   690 // This is pure virtual from MAgnEntryUiCallback. We don't use it.
       
   691 // (other items were commented in a header).
       
   692 // ----------------------------------------------------------------------------
       
   693 //
       
   694 void CCalenEditUi::ProcessCommandL( TInt /*aCommandId*/ )
       
   695     {
       
   696     TRACE_ENTRY_POINT;
       
   697     TRACE_EXIT_POINT;
       
   698     }
       
   699 
       
   700 // ----------------------------------------------------------------------------
       
   701 // CCalenEditUi::WaitForEntryViewNotificationL
       
   702 // Register for view created notification
       
   703 // (other items were commented in a header).
       
   704 // ----------------------------------------------------------------------------
       
   705 //
       
   706 void CCalenEditUi::WaitForEntryViewNotificationL( const TCalenCommand& aCommand )
       
   707     {
       
   708     TRACE_ENTRY_POINT;
       
   709 
       
   710     iStoredCommand = aCommand;
       
   711 
       
   712     // Only wait for an entry view if it doesn't already exist
       
   713     ASSERT( !( iGlobalData->EntryViewL() ) );
       
   714 
       
   715     // Register for notifications
       
   716     iController.RegisterForNotificationsL( this, ECalenNotifyEntryInstanceViewCreated );
       
   717 
       
   718     TRACE_EXIT_POINT;
       
   719     }
       
   720 
       
   721 // ----------------------------------------------------------------------------
       
   722 // CCalenEditUi::HandleECalenNotifyViewCreatedL
       
   723 // Handle ECalenNotifyViewCreated
       
   724 // (other items were commented in a header).
       
   725 // ----------------------------------------------------------------------------
       
   726 //
       
   727 void CCalenEditUi::HandleECalenNotifyViewCreatedL()
       
   728     {
       
   729     TRACE_ENTRY_POINT;
       
   730 
       
   731     if( iGlobalData->EntryViewL() )
       
   732         {
       
   733         // Handle the outstanding command
       
   734         HandleCommandL( iStoredCommand );
       
   735 
       
   736         // Cancel the notify as the entry view is now
       
   737         // constructed.
       
   738         iController.CancelNotifications( this );
       
   739         }
       
   740 
       
   741     TRACE_EXIT_POINT;
       
   742     }
       
   743 // ----------------------------------------------------------------------------
       
   744 // CCalenEditUi::HandleNotification
       
   745 // Handle notifications
       
   746 // (other items were commented in a header).
       
   747 // ----------------------------------------------------------------------------
       
   748 //
       
   749 void CCalenEditUi::HandleNotification(const TCalenNotification aNotification )
       
   750     {
       
   751     TRACE_ENTRY_POINT;
       
   752 
       
   753     if ( aNotification == ECalenNotifyEntryInstanceViewCreated )
       
   754         {
       
   755         PIM_TRAPD_HANDLE( HandleECalenNotifyViewCreatedL() );
       
   756         }
       
   757     if( aNotification == ECalenNotifyCancelStatusUpdation)
       
   758         {
       
   759         if(iMutlipleContextIdsCount)
       
   760             {
       
   761             // get the context
       
   762             MCalenContext& context = iGlobalData->Context();
       
   763             // reset the multiple contexts
       
   764             context.ResetMultipleContextIds();
       
   765             
       
   766             // dismiss the waitdialog
       
   767             if(iWaitDialog)
       
   768                 {
       
   769                 TRAP_IGNORE(iWaitDialog->ProcessFinishedL());
       
   770                 }
       
   771             }
       
   772         }
       
   773     TRACE_EXIT_POINT;
       
   774     }
       
   775 
       
   776 TBool CCalenEditUi::SetMultipleTodoCompleteL(TBool aComplete )
       
   777     {
       
   778     TRACE_ENTRY_POINT;
       
   779    TBool continueCommand(EFalse);
       
   780    
       
   781    // get the context
       
   782    MCalenContext& context = iGlobalData->Context();
       
   783    
       
   784    // get the multliple context ids count
       
   785    iMutlipleContextIdsCount = context.MutlipleContextIdsCount();
       
   786    
       
   787    ASSERT( iMutlipleContextIdsCount );
       
   788 
       
   789    if(!iMoreEntriesToComplete)   
       
   790        {
       
   791        DisplayWaitDialogL();
       
   792        }
       
   793    // get the multiple context instance ids
       
   794    RArray<TCalenInstanceId>& multipleContextIds = context.GetMutlipleContextIds();
       
   795    
       
   796    if(iMutlipleContextIdsCount <= iEntriesToComplete )
       
   797        {
       
   798        iMoreEntriesToComplete = EFalse; 
       
   799        iEntriesToComplete = iMutlipleContextIdsCount;
       
   800        }
       
   801    else
       
   802        {
       
   803        iMoreEntriesToComplete = ETrue;
       
   804        // set the continue command flag if more entries are there to delete
       
   805        continueCommand = ETrue;
       
   806        }
       
   807        
       
   808    TInt index(0);
       
   809    while(index<iEntriesToComplete)
       
   810        {
       
   811        // get the local uid of the entry through multiple context list
       
   812        TCalLocalUid entryLocalUid = multipleContextIds[0].iEntryLocalUid;
       
   813        TCalCollectionId colId = multipleContextIds[0].iColId;
       
   814        if(entryLocalUid)
       
   815            {
       
   816             SetTodoEntryCompleteL(aComplete, entryLocalUid,colId);
       
   817            }
       
   818        // remove mutliple context based on the instanceid
       
   819        context.RemoveMultipleContextId(multipleContextIds[0]);
       
   820        index++;
       
   821       }
       
   822 
       
   823    if(!iMoreEntriesToComplete)
       
   824        {
       
   825         MarkedEntriesCompletedL();
       
   826        }
       
   827  
       
   828    
       
   829    
       
   830    TRACE_EXIT_POINT;
       
   831    return continueCommand;    
       
   832    }
       
   833 // -----------------------------------------------------------------------------
       
   834 // CCalenEditUi::DisplayWaitDialogL
       
   835 // Display wait dialog
       
   836 // -----------------------------------------------------------------------------
       
   837 //
       
   838 void CCalenEditUi::DisplayWaitDialogL()
       
   839     {
       
   840     TRACE_ENTRY_POINT;
       
   841     
       
   842     delete iWaitDialog;
       
   843     iWaitDialog = NULL;
       
   844     iWaitDialog = new( ELeave )CAknWaitDialog( REINTERPRET_CAST( CEikDialog**, &iWaitDialog ), ETrue );
       
   845     iWaitDialog->ExecuteLD( R_TODO_UPDATING_STATUS_NOTE );
       
   846     iWaitDialog->SetCallback(this);
       
   847     
       
   848     TRACE_EXIT_POINT;
       
   849     }
       
   850 
       
   851 // -----------------------------------------------------------------------------
       
   852 // CCalenEditUi::MarkedEntriesDeletedL
       
   853 // Dismiss wait dialog and show information note
       
   854 // -----------------------------------------------------------------------------
       
   855 //
       
   856 void CCalenEditUi::MarkedEntriesCompletedL()
       
   857     {
       
   858     TRACE_ENTRY_POINT;
       
   859     
       
   860     // dismiss the waitdialog
       
   861     if(iWaitDialog)
       
   862         {
       
   863         iWaitDialog->ProcessFinishedL();
       
   864         }
       
   865     
       
   866     if(iMutlipleContextIdsCount)
       
   867         {
       
   868         // get the context
       
   869         MCalenContext& context = iGlobalData->Context();
       
   870         // reset the multiple contexts
       
   871         context.ResetMultipleContextIds();
       
   872         }
       
   873     // notify marked entries deleted
       
   874     iController.BroadcastNotification( ECalenNotifyMarkedEntryCompleted );
       
   875     
       
   876     TRACE_EXIT_POINT;
       
   877     }
       
   878 
       
   879 void CCalenEditUi::DialogDismissedL( const TInt /*aButtonId*/ )
       
   880    {
       
   881    TRACE_ENTRY_POINT;
       
   882   
       
   883    // no more entries to delete
       
   884    iMoreEntriesToComplete = EFalse;      
       
   885   
       
   886    // issue notification cancel delete
       
   887   // iController.BroadcastNotification(ECalenNotifyCancelStatusUpdation);   
       
   888   
       
   889    TRACE_EXIT_POINT;
       
   890    }
       
   891 
       
   892 // -----------------------------------------------------------------------------
       
   893 // CCalenEditUi::CalculateActiveTimeFromContextL
       
   894 // CCalculate active time from context
       
   895 // -----------------------------------------------------------------------------
       
   896 //
       
   897 TTime CCalenEditUi::CalculateActiveTimeFromContextL()
       
   898     {
       
   899     TRACE_ENTRY_POINT;
       
   900     // The active time is calculated based on the following table   
       
   901     //                          Current View
       
   902     //            Month        Day         Week        ToDo
       
   903     
       
   904     // Meeting*    CFD (@8am)  CFD (@8am)  CFD @ FCT   Today (@8am)
       
   905     // Day Note    CFD         CFD         CFD         Today
       
   906     // Anniv*      CFD         CFD         CFD         Today
       
   907     // ToDo*       CFD         CFD         CFD         Today
       
   908     
       
   909     // CFD = Currently Focused Date, the one shown in Navigator toolbar
       
   910     // FCT = Focused Cell's Time, applicable only to Week View
       
   911     // (*) Alarm Default times are also set using the values
       
   912         
       
   913     TTime activeTime(Time::NullTTime()); // initialize with NULL time
       
   914     TTime& activeTimeRef = activeTime;
       
   915     MCalenContext &context = iGlobalData->Context();
       
   916     TUid currentView = iController.ViewManager().CurrentView();
       
   917     if(currentView == KUidCalenWeekView)
       
   918         {
       
   919         // use CFD
       
   920          activeTime = CalenDateUtils::BeginningOfDay( 
       
   921                  context.FocusDateAndTimeL().TimeLocalL()); // CFD
       
   922          
       
   923          // CFD @ FCT
       
   924          // focus on empty nontimed cell
       
   925          if( context.FocusDateAndTimeL().TimeUtcL() == Time::NullTTime() )
       
   926              {
       
   927              activeTime = CalenDateUtils::DefaultTime( activeTimeRef );
       
   928              }
       
   929          else if(context.InstanceId().iType != CCalEntry::EAppt) 
       
   930              {
       
   931              activeTime = CalenDateUtils::DefaultTime( activeTimeRef );
       
   932              }
       
   933          else
       
   934              {
       
   935              activeTime += CalenDateUtils::TimeOfDay( 
       
   936                      context.FocusDateAndTimeL().TimeLocalL().DateTime() );
       
   937              }
       
   938          }
       
   939     else
       
   940         {
       
   941         // use Today @ 8 am
       
   942         activeTime = CalenDateUtils::Today();
       
   943         activeTime = CalenDateUtils::DefaultTime(context.FocusDateAndTimeL().TimeLocalL()); // 8 am
       
   944         }
       
   945     
       
   946     TRACE_EXIT_POINT;
       
   947     return activeTime;
       
   948     }
       
   949 
       
   950 // -----------------------------------------------------------------------------
       
   951 // CCalenEditUi::IsEditorActive
       
   952 // Tells framework whether editor is active or not
       
   953 // -----------------------------------------------------------------------------
       
   954 //
       
   955 TBool CCalenEditUi::IsEditorActive()
       
   956     {
       
   957     return isEditorActive;
       
   958     }
       
   959 // End of file