calendarui/controller/src/calendeleteui.cpp
branchRCL_3
changeset 66 bd7edf625bdd
parent 65 12af337248b1
child 86 ed599363c2d7
equal deleted inserted replaced
65:12af337248b1 66:bd7edf625bdd
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    13 *
    13 *
    14 * Description:  Handles deletion
    14 * Description:  Handles deletion
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 
    19 #include <QString>
    19 // INCLUDES
    20 #include <QtGui>
    20 #include <Calendar.rsg>
    21 #include <hbdatetimepicker.h>
    21 #include <calendateutils.h>
    22 #include <hbdialog.h>
    22 #include <calenagendautils.h>
    23 #include <hbmessagebox.h>
    23 #include <aknnotewrappers.h>
    24 #include <hbaction.h>
    24 #include <AknWaitDialog.h>
    25 #include <hblabel.h>
    25 #include <calcommon.h>
    26 #include <hbradiobuttonlist.h>
    26 #include <calentryview.h>
       
    27 #include <calinstance.h>
       
    28 #include <calinstanceview.h>
       
    29 #include <caltime.h>
    27 #include <centralrepository.h>
    30 #include <centralrepository.h>
    28 #include <agendaentry.h>
    31 #include <eikenv.h>
    29 
    32 #include <StringLoader.h>
    30 // User includes
    33 #include <sysutil.h>
    31 #include "calendarui_debug.h"
    34 #include <calenglobaldata.h>
       
    35 #include <calrrule.h>
       
    36 #include <calsession.h>
       
    37 #include <calencommands.hrh>            // Calendar commands
       
    38 #include <calencontext.h>
       
    39 #include <caleninstanceid.h>            // TCalenInstanceId
       
    40 #include <calenactionuiutils.h>
       
    41 #include <calcalendarinfo.h>
       
    42 #include <calentoolbar.h>
       
    43 #include <akntoolbar.h>
       
    44 #include <calenattachmentmodel.h>
       
    45 
       
    46 #include "calendarui_debug.h"           // Debug
    32 #include "calendeleteui.h"
    47 #include "calendeleteui.h"
    33 #include "calencontext.h"
       
    34 #include "calencontroller.h"
    48 #include "calencontroller.h"
    35 #include "CleanupResetAndDestroy.h"
    49 #include "CleanupResetAndDestroy.h"
    36 #include "caleninstanceid.h"
    50 #include "CalenInterimUtils2.h"
    37 #include "calenactionuiutils.h"
    51 #include "CalendarPrivateCRKeys.h"      // For CalendarInternalCRKeys.h
    38 #include "calendateutils.h"
    52 #include "calenmultipledbmanager.h"
    39 #include "calenagendautils.h"
       
    40 #include "OstTraceDefinitions.h"
       
    41 #ifdef OST_TRACE_COMPILER_IN_USE
       
    42 #include "calendeleteuiTraces.h"
       
    43 #endif
       
    44 
       
    45 
    53 
    46 // Local constants
    54 // Local constants
    47 const TInt KEntriesToDelete = 1;
    55 const TInt KEntriesToDelete = 1;
    48 
    56 
    49 // ----------------------------------------------------------------------------
    57 // ----------------------------------------------------------------------------
    50 // CalenDeleteUi::NewL
    58 // CCalenDeleteUi::NewL
    51 // Two phased constructor
    59 // Two phased constructor
    52 // (other items were commented in a header).
    60 // (other items were commented in a header).
    53 // ----------------------------------------------------------------------------
    61 // ----------------------------------------------------------------------------
    54 //
    62 //
    55 CalenDeleteUi* CalenDeleteUi::NewL( CCalenController& aController )
    63 CCalenDeleteUi* CCalenDeleteUi::NewL( CCalenController& aController )
    56     {
    64     {
    57     OstTraceFunctionEntry0( CALENDELETEUI_NEWL_ENTRY );
    65     TRACE_ENTRY_POINT;
    58     
    66 
    59     CalenDeleteUi* self = new( ELeave ) CalenDeleteUi( aController, NULL );
    67     CCalenDeleteUi* self = new( ELeave ) CCalenDeleteUi( aController );
    60     CleanupStack::PushL( self );
    68     CleanupStack::PushL( self );
    61     self->ConstructL();
    69     self->ConstructL();
    62     CleanupStack::Pop( self );
    70     CleanupStack::Pop( self );
    63 
    71 
    64     OstTraceFunctionExit0( CALENDELETEUI_NEWL_EXIT );
    72     TRACE_EXIT_POINT;
    65     return self;
    73     return self;
    66     }
    74     }
    67 
    75 
    68 // ----------------------------------------------------------------------------
    76 // ----------------------------------------------------------------------------
    69 // CalenDeleteUi::CalenDeleteUi
    77 // CCalenDeleteUi::CCalenDeleteUi
    70 // ?implementation_description
    78 // ?implementation_description
    71 // (other items were commented in a header).
    79 // (other items were commented in a header).
    72 // ----------------------------------------------------------------------------
    80 // ----------------------------------------------------------------------------
    73 //
    81 //
    74 CalenDeleteUi::CalenDeleteUi( CCalenController& aController, QObject *parent )
    82 CCalenDeleteUi::CCalenDeleteUi( CCalenController& aController )
    75     :QObject(parent), iController( aController )
    83     : iEikEnv( CEikonEnv::Static() ), iController( aController )
    76     {
    84     {
    77     OstTraceFunctionEntry0( CALENDELETEUI_CALENDELETEUI_ENTRY );
    85     TRACE_ENTRY_POINT;
    78     
    86     TRACE_EXIT_POINT;
    79     iIsDeleting = false;
    87     }
    80     
    88 
    81     OstTraceFunctionExit0( CALENDELETEUI_CALENDELETEUI_EXIT );
    89 // ----------------------------------------------------------------------------
    82     }
    90 // CCalenDeleteUi::~CCalenDeleteUi
    83 
       
    84 // ----------------------------------------------------------------------------
       
    85 // CalenDeleteUi::~CalenDeleteUi
       
    86 // Destructor
    91 // Destructor
    87 // (other items were commented in a header).
    92 // (other items were commented in a header).
    88 // ----------------------------------------------------------------------------
    93 // ----------------------------------------------------------------------------
    89 //
    94 //
    90 CalenDeleteUi::~CalenDeleteUi()
    95 CCalenDeleteUi::~CCalenDeleteUi()
    91     {
    96     {
    92     OstTraceFunctionEntry0( DUP1_CALENDELETEUI_CALENDELETEUI_ENTRY );
    97     TRACE_ENTRY_POINT;
    93     
    98 
    94     OstTraceFunctionExit0( DUP1_CALENDELETEUI_CALENDELETEUI_EXIT );
    99     if( iWaitDialog )
    95     }
   100         {
    96 
   101         delete iWaitDialog;
    97 // ----------------------------------------------------------------------------
   102         iWaitDialog = NULL;
    98 // CalenDeleteUi::ConstructL
   103         }
       
   104 
       
   105     if( iGlobalData )
       
   106         {
       
   107         iGlobalData->Release();
       
   108         }
       
   109 
       
   110     if( iDelAllRange )
       
   111         delete iDelAllRange;
       
   112 
       
   113     iDeleteColIds.Reset();
       
   114     
       
   115     TRACE_EXIT_POINT;
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // CCalenDeleteUi::ConstructL
    99 // Second phase of construction
   120 // Second phase of construction
   100 // (other items were commented in a header).
   121 // (other items were commented in a header).
   101 // ----------------------------------------------------------------------------
   122 // ----------------------------------------------------------------------------
   102 //
   123 //
   103 void CalenDeleteUi::ConstructL()
   124 void CCalenDeleteUi::ConstructL()
   104     {
   125     {
   105     OstTraceFunctionEntry0( CALENDELETEUI_CONSTRUCTL_ENTRY );
   126     TRACE_ENTRY_POINT;
   106     
   127 
       
   128     iGlobalData = CCalenGlobalData::InstanceL();
       
   129 
       
   130     // Both the entry view and instance views are needed
       
   131     // by the deleteUi commands, there queue the construction of both
       
   132     RArray<TInt> colArray;
       
   133     iController.GetActiveCollectionidsL(colArray);
       
   134     
       
   135     CCalInstanceView* instanceView = iGlobalData->InstanceViewL(colArray);
       
   136     colArray.Reset();
       
   137     if( !instanceView )
       
   138         {
       
   139         iController.RegisterForNotificationsL( this, ECalenNotifyEntryInstanceViewCreated );
       
   140         }
   107     iController.RegisterForNotificationsL( this, ECalenNotifyCancelDelete );
   141     iController.RegisterForNotificationsL( this, ECalenNotifyCancelDelete );
   108     iMoreEntriesToDelete = EFalse;
   142     iMoreEntriesToDelete = EFalse;
   109     iDisplayQuery = EFalse;
   143     iDisplayQuery = EFalse;
   110     iEntriesToDelete = KEntriesToDelete;
   144     iEntriesToDelete = KEntriesToDelete;
   111     
   145     iDelAllRange = NULL;
   112     OstTraceFunctionExit0( CALENDELETEUI_CONSTRUCTL_EXIT );
   146     TRACE_EXIT_POINT;
   113     }
   147     }
   114 
   148 
   115 // ----------------------------------------------------------------------------
   149 // ----------------------------------------------------------------------------
   116 // CalenDeleteUi::HandleNotification
   150 // CCalenDeleteUi::HandleECalenNotifyViewCreatedL
       
   151 // Handles ECalenNotifyViewCreated.
       
   152 // (other items were commented in a header).
       
   153 // ----------------------------------------------------------------------------
       
   154 //
       
   155 void CCalenDeleteUi::HandleECalenNotifyViewCreatedL()
       
   156     {
       
   157     TRACE_ENTRY_POINT;
       
   158     RArray<TInt> colArray;
       
   159     iController.GetActiveCollectionidsL(colArray);
       
   160     
       
   161     if( iGlobalData->InstanceViewL(colArray) )
       
   162         {
       
   163         // Handle the outstanding command
       
   164         HandleCommandL( iStoredCommand );
       
   165 
       
   166         // Cancel the notify as the entry view is now
       
   167         // constructed.
       
   168         iController.CancelNotifications( this );
       
   169         }
       
   170     colArray.Reset();
       
   171     TRACE_EXIT_POINT;
       
   172     }
       
   173 
       
   174 // ----------------------------------------------------------------------------
       
   175 // CCalenDeleteUi::HandleNotification
   117 // Handles notifications.
   176 // Handles notifications.
   118 // (other items were commented in a header).
   177 // (other items were commented in a header).
   119 // ----------------------------------------------------------------------------
   178 // ----------------------------------------------------------------------------
   120 //
   179 //
   121 void CalenDeleteUi::HandleNotification(const TCalenNotification aNotification )
   180 void CCalenDeleteUi::HandleNotification(const TCalenNotification aNotification )
   122     {
   181     {
   123     OstTraceFunctionEntry0( CALENDELETEUI_HANDLENOTIFICATION_ENTRY );
   182     TRACE_ENTRY_POINT;
   124 
   183 
       
   184     if ( aNotification == ECalenNotifyEntryInstanceViewCreated )
       
   185         {
       
   186         PIM_TRAPD_HANDLE( HandleECalenNotifyViewCreatedL() );
       
   187         }
   125     if( aNotification == ECalenNotifyCancelDelete)
   188     if( aNotification == ECalenNotifyCancelDelete)
   126         {
   189         {
   127         if(iMutlipleContextIdsCount)
   190         if(iMutlipleContextIdsCount)
   128             {
   191             {
   129             // get the context
   192             // get the context
   130             MCalenContext& context = iController.context();
   193             MCalenContext& context = iGlobalData->Context();
   131             // reset the multiple contexts
   194             // reset the multiple contexts
   132             context.resetMultipleContextIds();          
   195             context.ResetMultipleContextIds();
   133            
   196             
   134             }
   197             // dismiss the waitdialog
   135         }
   198             if(iWaitDialog)
   136     
   199                 {
   137     OstTraceFunctionExit0( CALENDELETEUI_HANDLENOTIFICATION_EXIT );
   200                 TRAP_IGNORE(iWaitDialog->ProcessFinishedL());
   138     }
   201                 }
   139 
   202             }
   140 // ----------------------------------------------------------------------------
   203         }
   141 // CalenDeleteUi::HandleCommandL
   204     TRACE_EXIT_POINT;
       
   205     }
       
   206 
       
   207 // ----------------------------------------------------------------------------
       
   208 // CCalenDeleteUi::HandleCommandL
   142 // Handles action ui commands
   209 // Handles action ui commands
   143 // (other items were commented in a header).
   210 // (other items were commented in a header).
   144 // ----------------------------------------------------------------------------
   211 // ----------------------------------------------------------------------------
   145 //
   212 //
   146 TBool CalenDeleteUi::HandleCommandL( const TCalenCommand& aCommand )
   213 TBool CCalenDeleteUi::HandleCommandL( const TCalenCommand& aCommand )
   147     {
   214     {
   148     OstTraceFunctionEntry0( CALENDELETEUI_HANDLECOMMANDL_ENTRY );
   215     TRACE_ENTRY_POINT;
   149     
       
   150     TBool continueCommand(EFalse);
   216     TBool continueCommand(EFalse);
   151     
   217     
   152     switch( aCommand.Command() )
   218     RArray<TInt> colArray;
   153         {
   219     iController.GetActiveCollectionidsL(colArray);
   154         case ECalenDeleteCurrentEntry:
   220     
   155         	mDeleteCommand = ECalenDeleteCurrentEntry;
   221     if( colArray.Count() && !( iGlobalData->InstanceViewL(colArray) ) )
   156         	DeleteCurrentEntryL(); // Entry & instance
   222         {
   157             break;
   223         iStoredCommand = aCommand;
   158 
   224         }
   159         case ECalenDeleteSeries:
   225     else
   160         	mDeleteCommand = ECalenDeleteSeries;
   226         {
   161         	DeleteThisOrAllL( AgendaUtil::ThisAndAll );
   227         switch( aCommand.Command() )
   162             break;
   228             {
       
   229             case ECalenDeleteCurrentEntry:
       
   230                 DeleteCurrentEntryL(); // Entry & instance
       
   231                 break;
       
   232 
       
   233             case ECalenDeleteSeries:
       
   234                 DeleteThisOrAllL( CalCommon::EThisAndAll );
       
   235                 break;
       
   236                 
       
   237             case ECalenDeleteCurrentOccurrence:
       
   238                 DeleteThisOrAllL( CalCommon::EThisOnly );
       
   239                 break;
       
   240                 
       
   241             case ECalenDeleteEntryWithoutQuery:
       
   242                 continueCommand = DeleteEntryWithoutQueryL();
       
   243                 break;
       
   244 
       
   245             case ECalenDeleteAllEntries:
       
   246                 HandleDeleteAllEntriesL();
       
   247                 break;
       
   248 
       
   249             case ECalenDeleteEntriesBeforeDate:
       
   250                 DeleteEntriesBeforeDateL(); // EntryView & instance
       
   251                 break;
       
   252 
       
   253             default:
       
   254                 // Controller decided this class was the place to handle this
       
   255                 // command but it wasn't in our list; something has gone wrong.
       
   256                 //ASSERT( EFalse );
       
   257                 break;
       
   258             }
       
   259         }
       
   260     colArray.Reset();
       
   261     TRACE_EXIT_POINT;
       
   262     return continueCommand;
       
   263     }
       
   264 
       
   265 // ----------------------------------------------------------------------------
       
   266 // CCalenDeleteUi::CalenCommandHandlerExtensionL
       
   267 // Dummy implementation.
       
   268 // (other items were commented in a header).
       
   269 // ----------------------------------------------------------------------------
       
   270 //
       
   271 TAny* CCalenDeleteUi::CalenCommandHandlerExtensionL( TUid /*aExtensionUid*/ )
       
   272     {
       
   273     TRACE_ENTRY_POINT;
       
   274     TRACE_EXIT_POINT;
       
   275     return NULL;
       
   276     }
       
   277 
       
   278 // ----------------------------------------------------------------------------
       
   279 // CCalenDeleteUi::DeleteThisOrAllL
       
   280 // Deletes series repeating entry
       
   281 // (other items were commented in a header).
       
   282 // ----------------------------------------------------------------------------
       
   283 //
       
   284 void CCalenDeleteUi::DeleteThisOrAllL( CalCommon::TRecurrenceRange aRepeatType )
       
   285     {
       
   286     TRACE_ENTRY_POINT;
       
   287     
       
   288     TBool isDeleted( EFalse );
       
   289     
       
   290     RArray<TInt> colIdArray;
       
   291     colIdArray.AppendL(iGlobalData->Context().InstanceId().iColId);
       
   292     
       
   293     if( iGlobalData->Context().InstanceId().iEntryLocalUid )
       
   294         {
       
   295         CCalInstance* instance = 
       
   296             CalenActionUiUtils::FindPossibleInstanceL( 
       
   297                                            iGlobalData->Context().InstanceId(),
       
   298                                            *iGlobalData->InstanceViewL(colIdArray) );
       
   299             if( instance )
       
   300             {
       
   301             CleanupStack::PushL( instance );
       
   302             isDeleted = DeleteSingleInstanceL( instance, aRepeatType );
   163             
   303             
   164         case ECalenDeleteCurrentOccurrence:
   304             if( isDeleted )
   165         	mDeleteCommand = ECalenDeleteCurrentOccurrence;
   305                 {
   166         	DeleteThisOrAllL( AgendaUtil::ThisOnly );
   306                 CleanupStack::Pop( instance );
   167             break;
   307                 }
   168             
   308             else
   169         case ECalenDeleteEntryWithoutQuery:
   309                 {
   170         	//TODO:
   310                 CleanupStack::PopAndDestroy( instance );
   171         	// This case is not handled currently as no such commands
   311                 }
   172         	// has been issued. So this has to be handled once we start 
   312             }
   173         	// issuing the command. 
   313         }
   174         	/*continueCommand = DeleteEntryWithoutQueryL();*/
   314     colIdArray.Reset();
   175             break;
   315     
   176 
   316     iController.BroadcastNotification( isDeleted? ECalenNotifyEntryDeleted :
   177         case ECalenDeleteAllEntries:
   317                                                                ECalenNotifyDeleteFailed );
   178         	mDeleteCommand = ECalenDeleteAllEntries;
   318     
   179         	DeleteAllEntriesL(); // EntryView & instance
   319     TRACE_EXIT_POINT;
   180             break;
   320     }
   181 
   321 
   182         case ECalenDeleteEntriesBeforeDate:
   322 // ----------------------------------------------------------------------------
   183             DeleteEntriesBeforeDateL(); // EntryView & instance
   323 // CCalenDeleteUi::DeleteEntryWithoutQueryL()
   184             break;
       
   185 
       
   186         default:
       
   187             // Controller decided this class was the place to handle this
       
   188             // command but it wasn't in our list; something has gone wrong.
       
   189             //ASSERT( EFalse );
       
   190             break;
       
   191         }
       
   192         
       
   193     OstTraceFunctionExit0( CALENDELETEUI_HANDLECOMMANDL_EXIT );
       
   194     return continueCommand;
       
   195     }
       
   196 
       
   197 
       
   198 // ----------------------------------------------------------------------------
       
   199 // CalenDeleteUi::DeleteThisOrAllL
       
   200 // Deletes series repeating entry
       
   201 // (other items were commented in a header).
       
   202 // ----------------------------------------------------------------------------
       
   203 //
       
   204 void CalenDeleteUi::DeleteThisOrAllL( AgendaUtil::RecurrenceRange aRepeatType )
       
   205 {
       
   206     OstTraceFunctionEntry0( CALENDELETEUI_DELETETHISORALLL_ENTRY );
       
   207 
       
   208 	if( iController.context().instanceId().mEntryLocalUid )
       
   209 	{
       
   210 		AgendaEntry instance = CalenActionUiUtils::findPossibleInstanceL(
       
   211 									iController.context().instanceId(),
       
   212 									iController.Services().agendaInterface() );
       
   213 		if( !instance.isNull() )
       
   214 		{
       
   215 			DeleteSingleInstanceL( instance, aRepeatType );
       
   216 		}
       
   217 	}
       
   218 	
       
   219 	OstTraceFunctionExit0( CALENDELETEUI_DELETETHISORALLL_EXIT );
       
   220 }
       
   221 
       
   222 // ----------------------------------------------------------------------------
       
   223 // CalenDeleteUi::DeleteEntryWithoutQueryL()
       
   224 // Deletes the current entry
   324 // Deletes the current entry
   225 // (other items were commented in a header).
   325 // (other items were commented in a header).
   226 // ----------------------------------------------------------------------------
   326 // ----------------------------------------------------------------------------
   227 //
   327 //
   228 TBool CalenDeleteUi::DeleteEntryWithoutQueryL()
   328 TBool CCalenDeleteUi::DeleteEntryWithoutQueryL()
   229     {
   329     {
   230     OstTraceFunctionEntry0( CALENDELETEUI_DELETEENTRYWITHOUTQUERYL_ENTRY );
   330     TRACE_ENTRY_POINT;
   231     
   331 	TBool continueCommand(EFalse);
   232 	bool continueCommand(EFalse);
       
   233     
   332     
   234 	// get the context
   333 	// get the context
   235 	MCalenContext& context = iController.context();
   334 	MCalenContext& context = iGlobalData->Context();
   236 	
   335 	
   237 	// get the multliple context ids count
   336 	// get the multliple context ids count
   238 	iMutlipleContextIdsCount = context.mutlipleContextIdsCount();
   337 	iMutlipleContextIdsCount = context.MutlipleContextIdsCount();
   239 	
   338 	
   240 	ASSERT( iMutlipleContextIdsCount );
   339 	ASSERT( iMutlipleContextIdsCount );
   241 
   340 
   242 	    if(!iMoreEntriesToDelete)
   341 	    if(!iMoreEntriesToDelete)
   243 		    {
   342 		    {
   244 		    //iDisplayQuery = ShowMultipleEntriesDeleteQueryL(iMutlipleContextIdsCount);
   343 		    iDisplayQuery = ShowMultipleEntriesDeleteQueryL(iMutlipleContextIdsCount);
   245 		    }
   344 		    }
   246 		
   345 		
   247 		if(iDisplayQuery)
   346 		if(iDisplayQuery)
   248 			{
   347 			{
   249 			if(!iMoreEntriesToDelete)	
   348 			if(!iMoreEntriesToDelete)	
   250 			    {
   349 			    {
   251 			    DisplayWaitDialogL();
   350 			    DisplayWaitDialogL();
   252 			    }
   351 			    }
   253 			// get the multiple context instance ids
   352 			// get the multiple context instance ids
   254 			QList<TCalenInstanceId>& multipleContextIds = context.getMutlipleContextIds();
   353 			RArray<TCalenInstanceId>& multipleContextIds = context.GetMutlipleContextIds();
   255 			
   354 			
   256 			if(iMutlipleContextIdsCount <= iEntriesToDelete )
   355 			if(iMutlipleContextIdsCount <= iEntriesToDelete )
   257 			    {
   356 			    {
   258 			    iMoreEntriesToDelete = EFalse; 
   357 			    iMoreEntriesToDelete = EFalse; 
   259 			    iEntriesToDelete = iMutlipleContextIdsCount;
   358 			    iEntriesToDelete = iMutlipleContextIdsCount;
   267 			    
   366 			    
   268 			TInt index(0);
   367 			TInt index(0);
   269 			while(index<iEntriesToDelete)
   368 			while(index<iEntriesToDelete)
   270 			    {
   369 			    {
   271 			    // get the local uid of the entry through multiple context list
   370 			    // get the local uid of the entry through multiple context list
   272 			    ulong entryLocalUid = multipleContextIds[0].mEntryLocalUid;
   371 			    TCalLocalUid entryLocalUid = multipleContextIds[0].iEntryLocalUid;			    
   273 			    if(entryLocalUid)
   372 			    if(entryLocalUid)
   274 			        {
   373 			        {
   275 			        DeleteEntryL(entryLocalUid);
   374 			        DeleteEntryL(entryLocalUid, multipleContextIds[0].iColId);
   276 			        }
   375 			        }
   277 			    // remove mutliple context based on the instanceid
   376 			    // remove mutliple context based on the instanceid
   278 			    context.removeMultipleContextId(multipleContextIds[0]);
   377 			    context.RemoveMultipleContextId(multipleContextIds[0]);
   279 			    index++;
   378 			    index++;
   280 			   }
   379 			   }
   281 
   380 
   282 			if(!iMoreEntriesToDelete)
   381 			if(!iMoreEntriesToDelete)
   283 			    {
   382 			    {
   284 			    MarkedEntriesDeletedL();    
   383 			    MarkedEntriesDeletedL();    
   285 			    }
   384 			    }
       
   385 			MCalenToolbar* toolbarImpl = iController.Services().ToolbarOrNull(); 
       
   386             if (toolbarImpl)
       
   387                 {
       
   388                 CAknToolbar& toolbar = toolbarImpl->Toolbar();
       
   389     
       
   390                 // dim clear and clear all toolbar buttons
       
   391                 toolbar.SetItemDimmed(ECalenNewMeeting, EFalse, ETrue);
       
   392                 }
   286 			}
   393 			}
   287         else
   394         else
   288             {
   395             {
   289             context.resetMultipleContextIds();
   396             context.ResetMultipleContextIds();
   290             // notify delete failed
   397             // notify delete failed
   291             iController.BroadcastNotification(ECalenNotifyDeleteFailed);    
   398             iController.BroadcastNotification(ECalenNotifyDeleteFailed);    
   292             }
   399             }
   293 	
   400 	
   294     OstTraceFunctionExit0( CALENDELETEUI_DELETEENTRYWITHOUTQUERYL_EXIT );
   401     TRACE_EXIT_POINT;
   295     return continueCommand;
   402     return continueCommand;
   296     }
   403     }
   297 
   404 
   298 // ----------------------------------------------------------------------------
   405 // ----------------------------------------------------------------------------
   299 // CalenDeleteUi::DeleteCurrentEntryL
   406 // CCalenDeleteUi::DeleteCurrentEntryL
   300 // Deletes the current entry
   407 // Deletes the current entry
   301 // (other items were commented in a header).
   408 // (other items were commented in a header).
   302 // ----------------------------------------------------------------------------
   409 // ----------------------------------------------------------------------------
   303 //
   410 //
   304 void CalenDeleteUi::DeleteCurrentEntryL()
   411 void CCalenDeleteUi::DeleteCurrentEntryL()
   305 {
   412     {
   306     OstTraceFunctionEntry0( CALENDELETEUI_DELETECURRENTENTRYL_ENTRY );
   413     TRACE_ENTRY_POINT;
   307     
   414 
   308 	// Make sure we're focused on an entry.
   415     TBool deleted( EFalse );
   309 	if (iController.context().instanceId().mEntryLocalUid) {
   416     TCalenNotification notification = ECalenNotifyDeleteFailed;
   310 		// Fetch the entry
   417     
   311 		AgendaEntry entry = iController.Services().agendaInterface()->fetchById(
   418     // Make sure we're focused on an entry.
   312 				iController.context().instanceId().mEntryLocalUid);
   419     if( iGlobalData->Context().InstanceId().iEntryLocalUid )
   313 			// Check if the entry is a To-Do
   420         {
   314 			if (AgendaEntry::TypeTodo == entry.type()) {
   421         //If todo, use the LUid.
   315 				showDeleteQuery(EDeleteToDo);
   422         //Todos returns the current time if start or end time has not been saved.
   316 			} else {
   423         if( CCalEntry::ETodo == iGlobalData->Context().InstanceId().iType )
   317 				// Show the repeat entry delete query for repeating entries except Anniversary
   424             {
   318 				// Even though the anniversary is repeating 
   425             CCalEntry* entry = iGlobalData->EntryViewL(iGlobalData->Context().InstanceId().iColId)->FetchL(
   319 				// all the instances will be deleted
   426                                     iGlobalData->Context().InstanceId().iEntryLocalUid );
   320 				if ((entry.isRepeating() || !entry.recurrenceId().isNull()) 
   427 
   321 							&& (AgendaEntry::TypeAnniversary != entry.type())) {
   428             if( entry )
   322 					// Show a confirmation note whether the user
   429                 {
   323 					// wants to delete the single instance or all of them
   430                 CleanupStack::PushL( entry );
   324 					showRepeatingEntryDeleteQuery();
   431                 deleted = DeleteEntryL( iGlobalData->EntryViewL(iGlobalData->Context().InstanceId().iColId), entry );
   325 				} else if (CalenAgendaUtils::isAlldayEvent(entry)) {
   432 
   326 					showDeleteQuery(EDeleteEvent);
   433                 if( deleted )
   327 				} else {
   434                     {
   328 					// If the entry is not a repeating entry,
   435                     CleanupStack::Pop( entry );
   329 					// delete it directly
   436                     notification = ECalenNotifyEntryDeleted;
   330 					// Save the entry for later reference in the slot
   437                     }
   331 					showDeleteQuery(EDeleteEntry);
   438                 else
   332 				}
   439                     {
       
   440                     CleanupStack::PopAndDestroy( entry );
       
   441                     }
       
   442                 }
       
   443             }
       
   444         else // Not todo
       
   445             {
       
   446             RArray<TInt> colIdArray;
       
   447             colIdArray.AppendL(iGlobalData->Context().InstanceId().iColId);
       
   448                 
       
   449             CCalInstance* instance = CalenActionUiUtils::FindPossibleInstanceL( 
       
   450                                                             iGlobalData->Context().InstanceId(),
       
   451                                                             *iGlobalData->InstanceViewL(colIdArray) );
       
   452             // if we have instance we will do delete other wise just return
       
   453             if( instance )
       
   454                 {
       
   455                 // Note: ownership handling of instance is dirty in this case, 
       
   456                 // because DeleteSingleInstanceLtakes ownership, if it's deletes 
       
   457                 // instance (property of CalInterimApi), otherwise not.
       
   458                 CleanupStack::PushL( instance );
       
   459                 deleted = DeleteSingleInstanceL( instance );
       
   460 
       
   461                 if( deleted )
       
   462                     {
       
   463                     CleanupStack::Pop( instance );
       
   464                     notification = ECalenNotifyEntryDeleted;
       
   465                     }
       
   466                 else
       
   467                     {
       
   468                     CleanupStack::PopAndDestroy( instance );
       
   469                     }
       
   470                 }
       
   471             colIdArray.Reset();
       
   472             }
       
   473         }
       
   474     else
       
   475         {
       
   476          TBool doDelete( ETrue );
       
   477          
       
   478          doDelete = CalenActionUiUtils::ShowDeleteConfirmationQueryL( 
       
   479                                                                    iGlobalData->Context().InstanceId().iType == CCalEntry::ETodo ?
       
   480                                                                    CalenActionUiUtils::EDeleteToDo :
       
   481                                                                    CalenActionUiUtils::EDeleteEntry );
       
   482 		if ( doDelete )
       
   483 			{
       
   484 			notification = ECalenNotifyEntryDeleted;	
   333 			}
   485 			}
   334 	}
   486         }
   335 	OstTraceFunctionExit0( CALENDELETEUI_DELETECURRENTENTRYL_EXIT );
   487         
   336 }
   488     iController.BroadcastNotification( notification );
   337 
   489 
   338 // ----------------------------------------------------------------------------
   490     TRACE_EXIT_POINT;
   339 // CalenDeleteUi::DeleteAllEntriesL
   491     }
       
   492 
       
   493 // ----------------------------------------------------------------------------
       
   494 // CCalenDeleteUi::DeleteAllEntriesL
   340 // Deletes all entries
   495 // Deletes all entries
   341 // (other items were commented in a header).
   496 // (other items were commented in a header).
   342 // ----------------------------------------------------------------------------
   497 // ----------------------------------------------------------------------------
   343 //
   498 //
   344 void CalenDeleteUi::DeleteAllEntriesL()
   499 void CCalenDeleteUi::DeleteAllEntriesL()
   345     {
   500     {
   346     OstTraceFunctionEntry0( CALENDELETEUI_DELETEALLENTRIESL_ENTRY );
   501     TRACE_ENTRY_POINT;
   347     
   502 
   348 	if(iIsDeleting) {
   503     ASSERT( !iIsDeleting );
   349 		OstTraceFunctionExit0( CALENDELETEUI_DELETEALLENTRIESL_EXIT );
   504 
   350 		return;
   505     const TInt buttonId = CalenActionUiUtils::ShowDeleteConfirmationQueryL( 
   351 	}
   506                                            CalenActionUiUtils::EDeleteAll );
   352 
   507 
   353     showDeleteQuery(EDeleteAll );
   508     if( buttonId )
   354 	OstTraceFunctionExit0( DUP1_CALENDELETEUI_DELETEALLENTRIESL_EXIT );
   509         {
   355 	}
   510         HandleDeleteMultipleEventsL( TCalTime::MinTime(), TCalTime::MaxTime(),
   356 
   511                                  R_QTN_CALE_CONF_ALL_NOTES_DELETED );
   357 // ----------------------------------------------------------------------------
   512         }
   358 // CalenDeleteUi::DeleteEntriesBeforeDateL
   513     else
       
   514         {
       
   515         // notify delete failed
       
   516         iController.BroadcastNotification(ECalenNotifyDeleteFailed); 
       
   517         }
       
   518 
       
   519     TRACE_EXIT_POINT;
       
   520     }
       
   521 
       
   522 // ----------------------------------------------------------------------------
       
   523 // CCalenDeleteUi::DeleteEntriesBeforeDateL
   359 // Deletes all entries before a set date.
   524 // Deletes all entries before a set date.
   360 // (other items were commented in a header).
   525 // (other items were commented in a header).
   361 // ----------------------------------------------------------------------------
   526 // ----------------------------------------------------------------------------
   362 //
   527 //
   363 void CalenDeleteUi::DeleteEntriesBeforeDateL()
   528 void CCalenDeleteUi::DeleteEntriesBeforeDateL()
   364     {
   529     {
   365     OstTraceFunctionEntry0( CALENDELETEUI_DELETEENTRIESBEFOREDATEL_ENTRY );
   530     TRACE_ENTRY_POINT;
   366     
   531 
   367 	if(iIsDeleting) {
   532     ASSERT( !iIsDeleting );
   368 		OstTraceFunctionExit0( CALENDELETEUI_DELETEENTRIESBEFOREDATEL_EXIT );
   533     TTime date;
   369 		return;
   534     date.HomeTime();
   370 	}    
   535     TTime today = date;
   371     // launch the datepicker
   536 
   372     dateQuery();
   537     TBool execute( EFalse );
   373     OstTraceFunctionExit0( DUP1_CALENDELETEUI_DELETEENTRIESBEFOREDATEL_EXIT );
   538     TBool exit( ETrue );
   374     }
   539     do{
   375 
   540         exit = ETrue;
   376 // ----------------------------------------------------------------------------
   541         execute = EFalse;
   377 // CalenDeleteUi::dateQuery
   542 
   378 // Launches the popup for the date selection
   543         TInt buttonId = CalenActionUiUtils::DateQueryL(date, R_CALEN_DEL_BEFORE_DATE_PROMPT);
   379 // (other items were commented in a header).
   544 
   380 // ----------------------------------------------------------------------------
   545         if( buttonId == EAknSoftkeyOk || buttonId == EEikBidOk )
   381 //
   546             {
   382 void CalenDeleteUi::dateQuery()
   547             execute = ETrue;
   383 	{
   548             if( today < date )
   384     OstTraceFunctionEntry0( CALENDELETEUI_DATEQUERY_ENTRY );
   549                 {
   385     
   550                 CAknNoteDialog* dialog = new( ELeave ) CAknNoteDialog( 
   386 	// Create a popup with datepicker to select the date.
   551                                                             CAknNoteDialog::EConfirmationTone,
   387 	HbDialog *popUp = new HbDialog();
   552                                                             CAknNoteDialog::ELongTimeout );
   388 	popUp->setDismissPolicy(HbDialog::NoDismiss);
   553                 dialog->ExecuteLD( R_CALEN_DELETEERROR_NOTE );
   389 	popUp->setTimeout(HbDialog::NoTimeout );
   554                 execute = EFalse;
   390 	popUp->setAttribute( Qt::WA_DeleteOnClose, true );
   555                 exit = EFalse;
   391 	popUp->setHeadingWidget(new HbLabel(hbTrId("txt_calendar_title_set_date")));
   556                 }
   392 	
   557             }
   393 	QDateTime currentDateTime(CalenDateUtils::today());
   558         }while( !exit );
   394 	QDate currentDate(currentDateTime.date());
   559 
   395 	if(mDatePicker) {
   560     // Do delete only if inputted day is after beginning of range
   396 		mDatePicker = NULL;
   561     if( execute && date > TCalTime::MinTime() )
   397 	}
   562         {
   398 	mDatePicker = new  HbDateTimePicker(popUp);
   563         // Two pass delete:
   399 	mDatePicker->setMinimumDate(CalenDateUtils::minTime().date());
   564         // 1. pass
   400 	mDatePicker->setMaximumDate(currentDate);
   565         // To prevent destroying entries starting and ending midnight
   401 	mDatePicker->setDate(currentDate);
   566         // subtract one microsecond and do delete on that range.
   402 
   567         date -= TTimeIntervalMicroSeconds32( 1 );
   403 	popUp->setContentWidget(mDatePicker);  
   568         date = Max( date, TCalTime::MinTime() );
   404 	mDeleteAction = new HbAction(
   569 
   405 						hbTrId("txt_common_button_delete"), popUp);
   570         HandleDeleteMultipleEventsL( TCalTime::MinTime(),
   406 	popUp->addAction(mDeleteAction);
   571                                                 date,
   407 	mCancelAction = new HbAction(hbTrId("txt_common_button_cancel"),popUp);
   572                                                R_QTN_CALE_CONF_PAST_NOTE_DELETED );
   408 	popUp->addAction(mCancelAction);
   573         }
   409 	// Show the popup
   574     else
   410 	popUp->open(this, SLOT(handleDateQuery(HbAction*)));
   575         {
   411 	
   576         iController.BroadcastNotification( ECalenNotifyDeleteFailed );
   412 	OstTraceFunctionExit0( CALENDELETEUI_DATEQUERY_EXIT );
   577         }
   413 	}
   578     
   414 
   579     TRACE_EXIT_POINT;
   415 // ----------------------------------------------------------------------------
   580     }
   416 // CalenDeleteUi::handleDateQuery
   581 
   417 // Handles the selection for the date query
   582 // ----------------------------------------------------------------------------
   418 // (other items were commented in a header).
   583 // CCalenDeleteUi::HandleDeleteMultipleEventsL
   419 // ----------------------------------------------------------------------------
       
   420 //
       
   421 void CalenDeleteUi::handleDateQuery(HbAction* action)
       
   422 {
       
   423     OstTraceFunctionEntry0( CALENDELETEUI_HANDLEDATEQUERY_ENTRY );
       
   424     
       
   425 	if(action == mDeleteAction) {
       
   426 		// User selected the date before which all the entries has to be deleted
       
   427 		QDate selectedDate(mDatePicker->date());
       
   428 		// Check if the date is within the range.
       
   429 		if(selectedDate.isValid()) {
       
   430 			QTime time(0,0,0,0);
       
   431 			QDateTime dateTime;
       
   432 			dateTime.setDate(selectedDate);
       
   433 			dateTime.setTime(time);
       
   434 			// Do delete only if inputted day is after beginning of range
       
   435 			if(dateTime > AgendaUtil::minTime()) {
       
   436 				// Two pass delete:
       
   437 				// 1. pass
       
   438 				// To prevent destroying entries starting and ending midnight
       
   439 				// subtract one second and do delete on that range.
       
   440 				dateTime = dateTime.addSecs(-1);
       
   441 				dateTime = ( dateTime > AgendaUtil::minTime()? 
       
   442 											dateTime :  AgendaUtil::minTime());
       
   443 
       
   444 				HandleDeleteMultipleEventsL( AgendaUtil::minTime(), 
       
   445 																 dateTime, 1);
       
   446 			}else {
       
   447 				iController.BroadcastNotification(ECalenNotifyDeleteFailed);
       
   448 			}
       
   449 		}
       
   450 	}else {
       
   451 		// User pressed cancel
       
   452 		handleDeleteCancel();
       
   453 	}
       
   454 	// Reset the member variables
       
   455 	mDeleteAction = NULL;
       
   456 	mCancelAction = NULL;
       
   457 	
       
   458 	OstTraceFunctionExit0( CALENDELETEUI_HANDLEDATEQUERY_EXIT );
       
   459 }
       
   460 // ----------------------------------------------------------------------------
       
   461 // CalenDeleteUi::showRepeatingEntryDeleteQuery
       
   462 // Launches the popup for deleting the repeating entry
       
   463 // (other items were commented in a header).
       
   464 // ----------------------------------------------------------------------------
       
   465 //
       
   466 void CalenDeleteUi::showRepeatingEntryDeleteQuery()
       
   467 {
       
   468     OstTraceFunctionEntry0( CALENDELETEUI_SHOWREPEATINGENTRYDELETEQUERY_ENTRY );
       
   469     
       
   470     HbDialog *popUp = new HbDialog();
       
   471     popUp->setDismissPolicy(HbDialog::NoDismiss);
       
   472     popUp->setTimeout(HbDialog::NoTimeout);
       
   473     popUp->setAttribute( Qt::WA_DeleteOnClose, true );
       
   474     
       
   475     QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
       
   476     HbWidget *editWidget = new HbWidget();
       
   477     editWidget->setLayout(layout);
       
   478     
       
   479     HbRadioButtonList *editButtonList = new HbRadioButtonList();
       
   480     
       
   481     QStringList list;
       
   482     list << hbTrId("txt_calendar_info_this_occurrence_only")
       
   483     		<< hbTrId("txt_calendar_info_all_occurences");
       
   484 
       
   485     editButtonList->setItems(list);
       
   486 
       
   487     layout->addItem(editButtonList);
       
   488     
       
   489     popUp->setContentWidget(editWidget);
       
   490     popUp->setHeadingWidget(new HbLabel(
       
   491 						hbTrId("txt_calendar_title_delete_repeated_entry")));
       
   492 
       
   493     // Add cancel action
       
   494     HbAction *cancelAction = new HbAction(
       
   495 							hbTrId("txt_common_button_cancel_singledialog"));
       
   496     popUp->addAction(cancelAction);
       
   497     connect(editButtonList, SIGNAL(itemSelected(int)), this,
       
   498 										SLOT(handleRepeatedEntryDelete(int)));
       
   499     connect(editButtonList, SIGNAL(itemSelected(int)), popUp, SLOT(close()));
       
   500     connect(cancelAction, SIGNAL(triggered()), this, 
       
   501 										SLOT(handleDeleteCancel()));
       
   502     
       
   503     // Show the popup
       
   504     popUp->open();
       
   505     
       
   506     OstTraceFunctionExit0( CALENDELETEUI_SHOWREPEATINGENTRYDELETEQUERY_EXIT );
       
   507 }
       
   508 
       
   509 // ----------------------------------------------------------------------------
       
   510 // CalenDeleteUi::handleDeleteCancel
       
   511 // Handles the cancel action
       
   512 // (other items were commented in a header).
       
   513 // ----------------------------------------------------------------------------
       
   514 //
       
   515 void CalenDeleteUi::handleDeleteCancel()
       
   516 {
       
   517     OstTraceFunctionEntry0( CALENDELETEUI_HANDLEDELETECANCEL_ENTRY );
       
   518     
       
   519 	iController.BroadcastNotification(ECalenNotifyDeleteFailed);
       
   520 	
       
   521 	OstTraceFunctionExit0( CALENDELETEUI_HANDLEDELETECANCEL_EXIT );
       
   522 }
       
   523 
       
   524 void CalenDeleteUi::handleRepeatedEntryDelete(int index)
       
   525 {
       
   526     OstTraceFunctionEntry0( CALENDELETEUI_HANDLEREPEATEDENTRYDELETE_ENTRY );
       
   527     
       
   528 	// Fetch the entry
       
   529 	// Find all possible instances
       
   530 	AgendaEntry instance = CalenActionUiUtils::findPossibleInstanceL(
       
   531 									iController.context().instanceId(),
       
   532 									iController.Services().agendaInterface());
       
   533 
       
   534 	if (!instance.isNull()) {
       
   535 		connect(iController.Services().agendaInterface(), 
       
   536 									SIGNAL(entryDeleted(ulong)),
       
   537 									this, SLOT(entryDeleted(ulong)));
       
   538 		switch(index) {
       
   539 			case 0:
       
   540 				// User wants to delete only this occurence
       
   541 				iController.Services().agendaInterface()->deleteRepeatedEntry(
       
   542 									instance, AgendaUtil::ThisOnly);
       
   543 				break;
       
   544 			case 1:
       
   545 				// User wants to delete all the occurences
       
   546 				iController.Services().agendaInterface()->deleteRepeatedEntry(
       
   547 									instance, AgendaUtil::ThisAndAll);
       
   548 				break;
       
   549 		}
       
   550 	}else {
       
   551 	    iController.BroadcastNotification(ECalenNotifyDeleteFailed);
       
   552 	}
       
   553 	OstTraceFunctionExit0( CALENDELETEUI_HANDLEREPEATEDENTRYDELETE_EXIT );
       
   554 }
       
   555 
       
   556 // ----------------------------------------------------------------------------
       
   557 // CalenDeleteUi::showDeleteQuery
       
   558 // Launches the popup for deleting the instance/instances
       
   559 // (other items were commented in a header).
       
   560 // ----------------------------------------------------------------------------
       
   561 //
       
   562 void CalenDeleteUi::showDeleteQuery(const TDeleteConfirmationType type,
       
   563                                                      const int count)
       
   564     {
       
   565     OstTraceFunctionEntry0( CALENDELETEUI_SHOWDELETEQUERY_ENTRY );
       
   566     
       
   567     HbMessageBox *popup = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
       
   568     popup->setDismissPolicy(HbDialog::NoDismiss);
       
   569     popup->setTimeout(HbDialog::NoTimeout);
       
   570     popup->setAttribute( Qt::WA_DeleteOnClose, true );
       
   571     
       
   572     QString text = 0;
       
   573     
       
   574     switch(type)
       
   575         {
       
   576         case EDeleteEntry:
       
   577             {
       
   578             text.append(hbTrId("txt_calendar_info_delete_meeting"));
       
   579             break;
       
   580             }
       
   581         case EDeleteToDo:
       
   582             {
       
   583             text.append(hbTrId("txt_calendar_info_delete_todo_note"));
       
   584             break;
       
   585             }
       
   586         case EDeleteToDos:
       
   587             {//"Delete %N to-do notes?"
       
   588             // TODO: Add the text id
       
   589             text.append("Delete %N to-do's?").arg(count);
       
   590             break;
       
   591             }
       
   592         case EDeleteAll:
       
   593             {
       
   594             text.append(hbTrId("txt_calendar_info_delete_all_calendar_entries"));
       
   595             break;
       
   596             }
       
   597         case EDeleteEvent:
       
   598             {
       
   599             text.append(hbTrId("txt_calendar_info_delete_allday_event"));
       
   600             break;
       
   601             }
       
   602         default:
       
   603             break;
       
   604         }
       
   605     
       
   606     popup->setText(text);
       
   607     	
       
   608     QList<QAction*> list = popup->actions();
       
   609     for(int i=0; i < list.count(); i++)
       
   610         {
       
   611         popup->removeAction(list[i]);
       
   612         }
       
   613     mDeleteAction = new HbAction(
       
   614 						hbTrId("txt_common_button_delete"), popup);
       
   615     popup->addAction(mDeleteAction);
       
   616     mCancelAction = new HbAction(hbTrId("txt_common_button_cancel"), popup); 
       
   617     popup->addAction(mCancelAction);
       
   618     popup->open(this, SLOT(handleDeletion(HbAction*)));
       
   619     
       
   620     OstTraceFunctionExit0( CALENDELETEUI_SHOWDELETEQUERY_EXIT );
       
   621     }
       
   622 
       
   623 // ----------------------------------------------------------------------------
       
   624 // CalenDeleteUi::handleDeletion
       
   625 // Deletes the entries based on the user selection
       
   626 // (other items were commented in a header).
       
   627 // ----------------------------------------------------------------------------
       
   628 //
       
   629 void CalenDeleteUi::handleDeletion(HbAction* action)
       
   630 {
       
   631     OstTraceFunctionEntry0( CALENDELETEUI_HANDLEDELETION_ENTRY );
       
   632     
       
   633 	TCalenNotification notification = ECalenNotifyDeleteFailed;
       
   634 	
       
   635 	if(action == mDeleteAction) {
       
   636 		
       
   637 		switch (mDeleteCommand) {
       
   638 			
       
   639 			case ECalenDeleteCurrentEntry:
       
   640 			{
       
   641 				// Get the entry id
       
   642 				ulong id = iController.context().instanceId().mEntryLocalUid;
       
   643 				connect(iController.Services().agendaInterface(), 
       
   644 												SIGNAL(entryDeleted(ulong)),
       
   645 												this, SLOT(entryDeleted(ulong)));
       
   646 				// Delete the entry if the delete button is been pressed
       
   647 				iController.Services().agendaInterface()->deleteEntry(id);
       
   648 			}
       
   649 				break;
       
   650 			
       
   651 			case ECalenDeleteSeries:
       
   652 			case ECalenDeleteCurrentOccurrence:
       
   653 			{
       
   654 				AgendaEntry instance = 
       
   655 						CalenActionUiUtils::findPossibleInstanceL(
       
   656 								iController.context().instanceId(),
       
   657 								iController.Services().agendaInterface() );
       
   658 				if(!instance.isNull()) {
       
   659 					QDateTime recId = instance.recurrenceId().toUTC();
       
   660 					const bool child = recId.isNull();
       
   661 					connect(iController.Services().agendaInterface(), 
       
   662 					        SIGNAL(entryDeleted(ulong)),
       
   663 					        this, SLOT(entryDeleted(ulong)));
       
   664 					if( !child || mRecurrenceRange == AgendaUtil::ThisOnly 
       
   665 							|| mRecurrenceRange == AgendaUtil::ThisAndAll) {
       
   666 						iController.Services().agendaInterface()->deleteRepeatedEntry( 
       
   667 								instance, mRecurrenceRange );
       
   668 					}
       
   669 				}else {
       
   670 				    iController.BroadcastNotification(ECalenNotifyDeleteFailed); 
       
   671 				}
       
   672 			}
       
   673 				break;
       
   674 			
       
   675 			case ECalenDeleteAllEntries:
       
   676 			{
       
   677 				HandleDeleteMultipleEventsL( AgendaUtil::minTime(), 
       
   678 											AgendaUtil::maxTime(),1 );
       
   679 			}
       
   680 				break;
       
   681 			
       
   682 			default:
       
   683 				break;
       
   684 				
       
   685 		}
       
   686 	} else {
       
   687 		// If the user presses cancel button the notification will be
       
   688 		// ECalenNotifyDeleteFailed as default.
       
   689 		// Notify the status
       
   690 		iController.BroadcastNotification(notification);
       
   691 	}
       
   692 	
       
   693 	// Reset the member variables
       
   694 	mDeleteAction = NULL;
       
   695 	mCancelAction = NULL;
       
   696 	
       
   697 	OstTraceFunctionExit0( CALENDELETEUI_HANDLEDELETION_EXIT );
       
   698 }
       
   699 
       
   700 void CalenDeleteUi::entryDeleted(ulong id)
       
   701 {
       
   702     OstTraceFunctionEntry0( CALENDELETEUI_ENTRYDELETED_ENTRY );
       
   703     
       
   704     if (iController.context().instanceId().mEntryLocalUid == id) {
       
   705         iController.BroadcastNotification(ECalenNotifyEntryDeleted);
       
   706     }
       
   707     disconnect(iController.Services().agendaInterface(), SIGNAL(entryDeleted(ulong)),
       
   708                this, SLOT(entryDeleted(ulong)));
       
   709     
       
   710     OstTraceFunctionExit0( CALENDELETEUI_ENTRYDELETED_EXIT );
       
   711 }
       
   712 
       
   713 // ----------------------------------------------------------------------------
       
   714 // CalenDeleteUi::HandleDeleteMultipleEventsL
       
   715 // Handles multiple delete events
   584 // Handles multiple delete events
   716 // (other items were commented in a header).
   585 // (other items were commented in a header).
   717 // ----------------------------------------------------------------------------
   586 // ----------------------------------------------------------------------------
   718 //
   587 //
   719 void CalenDeleteUi::HandleDeleteMultipleEventsL( const QDateTime& aFirstDay,
   588 void CCalenDeleteUi::HandleDeleteMultipleEventsL( const TTime& aFirstDay,
   720                                                  const QDateTime& aLastDay,
   589                                                                      const TTime& aLastDay,
   721                                                  int aConfNoteId )
   590                                                                      TInt /*aConfNoteId */)
   722     {
   591     {
   723     OstTraceFunctionEntry0( CALENDELETEUI_HANDLEDELETEMULTIPLEEVENTSL_ENTRY );
   592     TRACE_ENTRY_POINT;
   724     
   593 
   725 	if(iIsDeleting) {
   594     ASSERT( !iWaitDialog );
   726 		OstTraceFunctionExit0( CALENDELETEUI_HANDLEDELETEMULTIPLEEVENTSL_EXIT );
   595     ASSERT( !iIsDeleting );
   727 		return;
   596     //iConfirmationNoteId = aConfNoteId;
   728 	}
   597 
   729     iConfirmationNoteId = aConfNoteId;
   598     iWaitDialog = new( ELeave ) CAknWaitDialog( REINTERPRET_CAST( CEikDialog**, 
   730     
   599                                                                   &iWaitDialog ) );
       
   600     iWaitDialog->ExecuteLD( R_CALEN_DELETE_WAIT_NOTE );
       
   601 
   731     DeleteDayRangeL( aFirstDay, aLastDay );
   602     DeleteDayRangeL( aFirstDay, aLastDay );
   732 
   603 
   733     OstTraceFunctionExit0( DUP1_CALENDELETEUI_HANDLEDELETEMULTIPLEEVENTSL_EXIT );
   604     TRACE_EXIT_POINT;
   734     }
   605     }
   735 
   606 
   736 // ----------------------------------------------------------------------------
   607 // ----------------------------------------------------------------------------
   737 // CalenDeleteUi::DeleteDayRangeL
   608 // CCalenDeleteUi::DeleteDayRangeL
   738 // Deletes all entries in a given range.
   609 // Deletes all entries in a given range.
   739 // (other items were commented in a header).
   610 // (other items were commented in a header).
   740 // ----------------------------------------------------------------------------
   611 // ----------------------------------------------------------------------------
   741 //
   612 //
   742 void CalenDeleteUi::DeleteDayRangeL( const QDateTime& aStart,
   613 void CCalenDeleteUi::DeleteDayRangeL( const TTime& aStart,
   743                                                       const QDateTime& aEnd )
   614                                                       const TTime& aEnd )
   744     {
   615     {
   745     OstTraceFunctionEntry0( CALENDELETEUI_DELETEDAYRANGEL_ENTRY );
   616     TRACE_ENTRY_POINT;
   746     
   617 
   747     iStartTime = aStart;
   618     iStartTime = aStart;
   748     iEndTime = aEnd;
   619     iEndTime = aEnd;
   749     
   620 
   750     iIsDeleting = ETrue;
   621     TCalTime start, end;
   751     
   622     start.SetTimeLocalL( iStartTime );
   752     //AgendaUtil& agendaInterface = iController.agendaInterface();
   623     end.SetTimeLocalL( iEndTime );
   753     // Connect to the signal that gets generated when deletion is completed
   624 
   754     connect(iController.agendaInterface(), SIGNAL(entriesDeleted(int)), this,
   625     if( iDelAllRange )
   755             SLOT(doCompleted(int)));
   626         {
   756     AgendaUtil::FilterFlags filter =
   627         delete iDelAllRange;
   757     	        AgendaUtil::FilterFlags(AgendaUtil::IncludeAnniversaries
   628         iDelAllRange = NULL;
   758     	                | AgendaUtil::IncludeAppointments
   629         }
   759     	                | AgendaUtil::IncludeEvents
   630     
   760     	                | AgendaUtil::IncludeReminders
   631     iDelAllRange = new(ELeave) CalCommon::TCalTimeRange( start, end );
   761     	                | AgendaUtil::IncludeIncompletedTodos
   632     iDeleteColIds.Reset();
   762     	                | AgendaUtil::IncludeCompletedTodos
   633 
   763     	                | AgendaUtil::IncludeAnniversaries);
   634     iIsDeleting = ETrue;   
   764     // 1: First pass, delete all entries.
   635 
   765     iController.agendaInterface()->deleteEntries(iStartTime, iEndTime, filter);
   636     iController.GetActiveCollectionidsL(iDeleteColIds);
   766 
   637     
   767     OstTraceFunctionExit0( CALENDELETEUI_DELETEDAYRANGEL_EXIT );
   638     //remember the calenders, delete entries in each calendar one by one by calling DeleteL(...) after completed()
   768     }
   639     iNumberOfCalendars = iDeleteColIds.Count();
   769 
   640     iToShowDeleteNote = 0;
   770 // ----------------------------------------------------------------------------
   641     iGlobalData->EntryViewL(iDeleteColIds[iToShowDeleteNote])->DeleteL( *iDelAllRange, CalCommon::EIncludeAll, *this );
   771 // CalenDeleteUi::DoCompletedL
   642         
       
   643     TRACE_EXIT_POINT;
       
   644     }
       
   645 
       
   646 // ----------------------------------------------------------------------------
       
   647 // CCalenDeleteUi::Completed
       
   648 // Completed callback
       
   649 // (other items were commented in a header).
       
   650 // ----------------------------------------------------------------------------
       
   651 //
       
   652 void CCalenDeleteUi::Completed( TInt aFirstPassError )
       
   653     {
       
   654     TRACE_ENTRY_POINT;
       
   655 
       
   656     PIM_TRAPD_HANDLE( DoCompletedL( aFirstPassError ) );
       
   657 
       
   658     TRACE_EXIT_POINT;
       
   659     }
       
   660 
       
   661 // ----------------------------------------------------------------------------
       
   662 // CCalenDeleteUi::DoCompletedL
   772 // Handles delete callback
   663 // Handles delete callback
   773 // (other items were commented in a header).
   664 // (other items were commented in a header).
   774 // ----------------------------------------------------------------------------
   665 // ----------------------------------------------------------------------------
   775 //
   666 //
   776 void CalenDeleteUi::doCompleted( int aFirstPassError )
   667 void CCalenDeleteUi::DoCompletedL( TInt aFirstPassError )
   777     {
   668     {
   778     OstTraceFunctionEntry0( CALENDELETEUI_DOCOMPLETED_ENTRY );
   669     TRACE_ENTRY_POINT;
   779 
   670     iToShowDeleteNote++;
   780     if( aFirstPassError == KErrNone )
   671     if(iNumberOfCalendars == iToShowDeleteNote)
   781         {
   672         {
   782         // 2: Second pass, delete notes that end 00:00 of next day of iEndTime
   673 	    if( aFirstPassError == KErrNone )
   783         // We didn't delete them in first pass
   674 	        {
   784         QDateTime nextMidnight = CalenDateUtils::beginningOfDay( iEndTime.addDays(1) );
   675 	        // 2: Second pass, delete notes that end 00:00 of next day of iEndTime
   785         nextMidnight = ( nextMidnight < AgendaUtil::maxTime()? nextMidnight : AgendaUtil::maxTime() );
   676 	        // We didn't delete them in first pass
   786         PIM_TRAPD_HANDLE( deleteEntriesEndingAtMidnight( nextMidnight ) );
   677 	        TTime nextMidnight = CalenDateUtils::BeginningOfDay( iEndTime + TTimeIntervalDays( 1 ) );
   787         }
   678 	        nextMidnight = Min( nextMidnight, TCalTime::MaxTime() );
   788 
   679 	        PIM_TRAPD_HANDLE( DeleteEntriesEndingAtMidnightL( nextMidnight ) );
   789     // 3. End deleting, close wait dialog, and show confirmation or error note
   680 	        }
   790     iIsDeleting = EFalse;
   681 	        
   791     
   682 		// 3. End deleting, close wait dialog, and show confirmation or error note
   792     iController.BroadcastNotification( ECalenNotifyMultipleEntriesDeleted );
   683 		iIsDeleting = EFalse;
   793 
   684 		iToShowDeleteNote = 0;
   794     OstTraceFunctionExit0( CALENDELETEUI_DOCOMPLETED_EXIT );
   685 		// dismiss the waitdialog
   795     }
   686 		if(iWaitDialog)
   796 
   687 			{
   797 // ----------------------------------------------------------------------------
   688 			TRAP_IGNORE(iWaitDialog->ProcessFinishedL());
   798 // CalenDeleteUi::DeleteEntriesEndingAtMidnightL
   689 			}
       
   690 
       
   691 		if( aFirstPassError == KErrNone )
       
   692 			{
       
   693 			// Show confirmation note
       
   694 //			HBufC* buf = StringLoader::LoadLC( iConfirmationNoteId, iEikEnv );
       
   695 //			CAknConfirmationNote* dialog = new( ELeave ) CAknConfirmationNote();
       
   696 //			dialog->ExecuteLD(*buf);
       
   697 //			CleanupStack::PopAndDestroy( buf );
       
   698 			}
       
   699 		else
       
   700 			{
       
   701 			// Show error note
       
   702 			if(iEikEnv)
       
   703 			   {
       
   704 			   iEikEnv->ResolveError( aFirstPassError );
       
   705 			   }
       
   706 			}
       
   707 		iDeleteColIds.Reset();
       
   708 		delete iDelAllRange;
       
   709 		iDelAllRange = NULL;
       
   710 		
       
   711 	    iController.BroadcastNotification( ECalenNotifyMultipleEntriesDeleted );
       
   712         }
       
   713     else
       
   714         {
       
   715         //delete entries in next calendar...
       
   716         iGlobalData->EntryViewL(iDeleteColIds[iToShowDeleteNote])->DeleteL( *iDelAllRange, CalCommon::EIncludeAll, *this );
       
   717         }
       
   718 
       
   719     TRACE_EXIT_POINT;
       
   720     }
       
   721 
       
   722 // ----------------------------------------------------------------------------
       
   723 // CCalenDeleteUi::NotifyProgress
       
   724 // Delete progress notification
       
   725 // (other items were commented in a header).
       
   726 // ----------------------------------------------------------------------------
       
   727 //
       
   728 TBool CCalenDeleteUi::NotifyProgress()
       
   729     {
       
   730     TRACE_ENTRY_POINT;
       
   731     // Tell framework that we are not intrested in Progress notifications.
       
   732     TRACE_EXIT_POINT;
       
   733     return EFalse;
       
   734     }
       
   735 
       
   736 // ----------------------------------------------------------------------------
       
   737 // CCalenDeleteUi::Progress
       
   738 // Delete progress notification
       
   739 // (other items were commented in a header).
       
   740 // ----------------------------------------------------------------------------
       
   741 //
       
   742 void CCalenDeleteUi::Progress( TInt /*aPercentageCompleted*/ )
       
   743     {
       
   744     TRACE_ENTRY_POINT;
       
   745     // do nothing, we are not intrested in Progress notifications
       
   746     TRACE_EXIT_POINT;
       
   747     }
       
   748 
       
   749 // ----------------------------------------------------------------------------
       
   750 // CCalenDeleteUi::DeleteEntriesEndingAtMidnightL
   799 // Deletes entries ending at midnight on the given day
   751 // Deletes entries ending at midnight on the given day
   800 // (other items were commented in a header).
   752 // (other items were commented in a header).
   801 // ----------------------------------------------------------------------------
   753 // ----------------------------------------------------------------------------
   802 //
   754 //
   803 void CalenDeleteUi::deleteEntriesEndingAtMidnight( QDateTime aMidnight )
   755 void CCalenDeleteUi::DeleteEntriesEndingAtMidnightL( TTime aMidnight )
   804     {
   756     {
   805     OstTraceFunctionEntry0( CALENDELETEUI_DELETEENTRIESENDINGATMIDNIGHT_ENTRY );
   757     TRACE_ENTRY_POINT;
   806 
   758 
   807     QDateTime start, end;
   759     TCalTime start, end;
   808     QTime startTime(aMidnight.time());
   760     start.SetTimeLocalL( aMidnight - TTimeIntervalMinutes(1) );
   809     startTime.setHMS(startTime.hour(), startTime.minute() - 1,
   761     end.SetTimeLocalL( aMidnight );
   810                     startTime.second(), startTime.msec());
   762     CalCommon::TCalTimeRange midnightRange( start, end );
   811     start.setDate(aMidnight.date());
   763     
   812     start.setTime(startTime);
   764     RArray<TInt> colIdArray;
   813     
   765     iController.GetActiveCollectionidsL(colIdArray);
   814     end = aMidnight;
   766     
   815     
   767     // 1: Find instances falling on midnight moment
   816     QList<AgendaEntry> instances = iController.Services().agendaInterface()->fetchEntriesInRange( start, end );
   768     RPointerArray< CCalInstance > instances;
       
   769     CleanupResetAndDestroyPushL( instances );
       
   770     iGlobalData->InstanceViewL(colIdArray)->FindInstanceL( instances,
       
   771                                                  CalCommon::EIncludeAll, 
       
   772                                                  midnightRange );
       
   773     
       
   774     colIdArray.Reset();
   817 
   775 
   818     // 2. loop through them and delete those entries that end at midnight
   776     // 2. loop through them and delete those entries that end at midnight
   819     for( int i=0; i < instances.count(); ++i )
   777     for( TInt i=0; i < instances.Count(); ++i )
   820         {
   778         {
   821         AgendaEntry entry = instances[i];
   779         CCalInstance* item = instances[i];
   822 
   780         RArray<TInt> colIdArray;
       
   781         colIdArray.AppendL(item->InstanceIdL().iCollectionId);
       
   782         
   823         // Checking that if entry ends at midnight, is quite clumsy, but here goes:
   783         // Checking that if entry ends at midnight, is quite clumsy, but here goes:
   824         // EndsAtStartOfDay takes only CCalInstance, but here we mimic EndsAtStartOfDay
   784         // EndsAtStartOfDay takes only CCalInstance, but here we mimic EndsAtStartOfDay
   825         // for CCalEntry type.
   785         // for CCalEntry type.
   826 
   786 
   827         // First check that if _instance_ ends at midnight, but starts earlier
   787         // First check that if _instance_ ends at midnight, but starts earlier
   828         if( CalenAgendaUtils::endsAtStartOfDay( entry, aMidnight ) )
   788         if( CalenAgendaUtils::EndsAtStartOfDayL( item, aMidnight ) )
   829             {
   789             {
   830             // Second, check that _entry's_ endtime is exactly the midnight
   790             // Second, check that _entry's_ endtime is exactly the midnight
   831             // This prevents us from destroying repeating entries, that has one
   791             // This prevents us from destroying repeating entries, that has one
   832             // instance falling on given midnight.
   792             // instance falling on given midnight.
   833             if( entry.endTime() == aMidnight )
   793             if( item->Entry().EndTimeL().TimeLocalL() == aMidnight )
   834                 {
   794                 {
   835                 iController.Services().agendaInterface()->deleteRepeatedEntry(entry, AgendaUtil::ThisAndAll);
   795                 iGlobalData->InstanceViewL(colIdArray)->DeleteL( item, CalCommon::EThisOnly );
   836                 }
   796                 // Ownership was transferred to DeleteL.
   837             }
   797                 // Put null to array to prevent double-deletion
   838         }
   798                 instances[i] = NULL;                
   839 
   799                 }
   840     OstTraceFunctionExit0( CALENDELETEUI_DELETEENTRIESENDINGATMIDNIGHT_EXIT );
   800             }
   841     }
   801         colIdArray.Reset();
   842 
   802         }
   843 // -----------------------------------------------------------------------------
   803     CleanupStack::PopAndDestroy( &instances );
   844 // CalenDeleteUi::DeleteSingleInstanceL
   804 
       
   805     TRACE_EXIT_POINT;
       
   806     }
       
   807 
       
   808 // -----------------------------------------------------------------------------
       
   809 // CCalenDeleteUi::DeleteSingleInstanceL
   845 // Delete the given instance. Ask the user whether to delete the series or the instance.
   810 // Delete the given instance. Ask the user whether to delete the series or the instance.
   846 // (other items were commented in a header).
   811 // (other items were commented in a header).
   847 // -----------------------------------------------------------------------------
   812 // -----------------------------------------------------------------------------
   848 //
   813 //
   849 void CalenDeleteUi::DeleteSingleInstanceL( AgendaEntry& aInstance )
   814 TBool CCalenDeleteUi::DeleteSingleInstanceL( CCalInstance* aInstance )
   850     {
   815     {
   851     OstTraceFunctionEntry0( CALENDELETEUI_DELETESINGLEINSTANCEL_ENTRY );
   816     TRACE_ENTRY_POINT;
   852     
   817     TRACE_EXIT_POINT;
   853     DoDeleteSingleInstanceL( aInstance, EFalse, AgendaUtil::ThisAndAll );
   818     return DoDeleteSingleInstanceL( aInstance, EFalse, CalCommon::EThisAndAll );
   854     
   819     }
   855     OstTraceFunctionExit0( CALENDELETEUI_DELETESINGLEINSTANCEL_EXIT );
   820 
   856     }
   821 // -----------------------------------------------------------------------------
   857 
   822 // CCalenDeleteUi::DeleteSingleInstanceL
   858 // -----------------------------------------------------------------------------
       
   859 // CalenDeleteUi::DeleteSingleInstanceL
       
   860 // Delete the given instance. Delete the entry range given by aRepeatType.
   823 // Delete the given instance. Delete the entry range given by aRepeatType.
   861 // (other items were commented in a header).
   824 // (other items were commented in a header).
   862 // -----------------------------------------------------------------------------
   825 // -----------------------------------------------------------------------------
   863 //
   826 //
   864 void CalenDeleteUi::DeleteSingleInstanceL( AgendaEntry& aInstance, 
   827 TBool CCalenDeleteUi::DeleteSingleInstanceL( CCalInstance* aInstance, 
   865                                 AgendaUtil::RecurrenceRange aRepeatType )
   828                                                             CalCommon::TRecurrenceRange aRepeatType )
   866     {
   829     {
   867     OstTraceFunctionEntry0( DUP1_CALENDELETEUI_DELETESINGLEINSTANCEL_ENTRY );
   830     TRACE_ENTRY_POINT;
   868     
   831     TRACE_EXIT_POINT;
   869     DoDeleteSingleInstanceL( aInstance, ETrue, aRepeatType );
   832     return DoDeleteSingleInstanceL( aInstance, ETrue, aRepeatType );
   870     
   833     }
   871     OstTraceFunctionExit0( DUP1_CALENDELETEUI_DELETESINGLEINSTANCEL_EXIT );
   834 
   872     }
   835 // -----------------------------------------------------------------------------
   873 
   836 // CCalenDeleteUi::DoDeleteSingleInstanceL
   874 // -----------------------------------------------------------------------------
       
   875 // CalenDeleteUi::DoDeleteSingleInstanceL
       
   876 // Performs the deletion of the instance. If aHasRepeatType is EFalse, the user
   837 // Performs the deletion of the instance. If aHasRepeatType is EFalse, the user
   877 // is prompted to delete either the instance or the entire series. In this case,
   838 // is prompted to delete either the instance or the entire series. In this case,
   878 // aRepeatType is ignored. If aHasRepeatType is ETrue, aRepeatType determines
   839 // aRepeatType is ignored. If aHasRepeatType is ETrue, aRepeatType determines
   879 // whether to delete the instance or the entire series.
   840 // whether to delete the instance or the entire series.
   880 // (other items were commented in a header).
   841 // (other items were commented in a header).
   881 // -----------------------------------------------------------------------------
   842 // -----------------------------------------------------------------------------
   882 //
   843 //
   883 void CalenDeleteUi::DoDeleteSingleInstanceL(
   844 TBool CCalenDeleteUi::DoDeleteSingleInstanceL( CCalInstance* aInstance,
   884 									AgendaEntry& aInstance,
   845                                                            TBool aHasRepeatType,
   885 									bool aHasRepeatType,
   846                                                            CalCommon::TRecurrenceRange aRepeatType )
   886 									AgendaUtil::RecurrenceRange aRepeatType )
   847     {
   887 {
   848     TRACE_ENTRY_POINT;
   888     OstTraceFunctionEntry0( CALENDELETEUI_DODELETESINGLEINSTANCEL_ENTRY );
   849 
   889     
   850     CCalEntry& entry = aInstance->Entry();
   890 	bool repeating = aInstance.isRepeating();
   851     const CCalEntry::TType entryType = entry.EntryTypeL(); 
   891 
   852     RArray<TInt> colIdArray;
   892 	if( !repeating ) {
   853     colIdArray.AppendL(aInstance->InstanceIdL().iCollectionId);
   893 		// Even though there is no RRule, the entry might
   854     
   894 		// have a list of rdates.
   855 
   895 		QList<QDate> rDates = aInstance.rDates();
   856     TCalRRule rrule;
   896 		repeating = ( rDates.count() > 0 );
   857 
       
   858     TBool repeating = entry.GetRRuleL( rrule );
       
   859 
       
   860     if( !repeating )
       
   861         {
       
   862         // Even though there is no RRule, the entry might
       
   863         // have a list of rdates.
       
   864         RArray< TCalTime > rDateArray;
       
   865         CleanupClosePushL( rDateArray );
       
   866         entry.GetRDatesL( rDateArray );
       
   867         repeating = ( rDateArray.Count() > 0 );
       
   868         CleanupStack::PopAndDestroy(); // rDateArray
       
   869         }
       
   870 
       
   871     const TBool child = entry.RecurrenceIdL().TimeUtcL() != Time::NullTTime();
       
   872 
       
   873     if( !aHasRepeatType )
       
   874         {
       
   875         aRepeatType = CalCommon::EThisAndAll;
       
   876         }
       
   877 
       
   878     TBool doDelete( ETrue );
       
   879 
       
   880     if( !aHasRepeatType && ( child || repeating ) && ( entryType != CCalEntry::EAnniv ) )
       
   881         {
       
   882         doDelete = CalenActionUiUtils::ShowRepeatTypeQueryL( aRepeatType,
       
   883                                                            CalenActionUiUtils::EDelete );
       
   884         }
       
   885     else
       
   886         {
       
   887         doDelete = CalenActionUiUtils::ShowDeleteConfirmationQueryL( 
       
   888                                                                    entryType == CCalEntry::ETodo ?
       
   889                                                                    CalenActionUiUtils::EDeleteToDo :
       
   890                                                                    CalenActionUiUtils::EDeleteEntry );
       
   891         }
       
   892         
       
   893     if( doDelete )
       
   894         {
       
   895         //Before deleteing the entry reset the attachment model
       
   896         if(iController.Services().GetAttachmentData()->NumberOfItems())
       
   897             {
       
   898             iController.Services().GetAttachmentData()->Reset();
       
   899             }
       
   900         
       
   901         if( !TryDeleteWithMrUtilsL( aInstance, aRepeatType ) )
       
   902             {
       
   903             if( !child || aRepeatType == CalCommon::EThisOnly )
       
   904                 {
       
   905                 iGlobalData->InstanceViewL(colIdArray)->DeleteL( aInstance, aRepeatType );
       
   906                 }
       
   907             else if( aRepeatType == CalCommon::EThisAndAll )
       
   908                 {
       
   909                 // Unfortunately we can't pass the existing child instance through to the
       
   910                 // InstanceView DeleteL function because even if we pass in EThisAndAll, it
       
   911                 // only ever deletes the exception. We'll have to fetch the parent then
       
   912                 // delete it via the entry view.
       
   913                 RPointerArray<CCalEntry> entries;
       
   914                 CleanupResetAndDestroyPushL( entries );
       
   915                 iGlobalData->EntryViewL(aInstance->InstanceIdL().iCollectionId)->FetchL( aInstance->Entry().UidL(), entries );
       
   916                 iGlobalData->EntryViewL(aInstance->InstanceIdL().iCollectionId)->DeleteL( *entries[0] );
       
   917                 CleanupStack::PopAndDestroy( &entries );
       
   918                 if( aInstance )
       
   919                     {
       
   920                     delete aInstance;
       
   921                     aInstance = NULL;
       
   922                     }
       
   923                 }
       
   924             else
       
   925                 {
       
   926                 User::Leave( KErrNotSupported );
       
   927                 }
       
   928             }
       
   929         }
       
   930 
       
   931     colIdArray.Reset();
       
   932     TRACE_EXIT_POINT;
       
   933     return doDelete;
       
   934     }
       
   935 
       
   936 // -----------------------------------------------------------------------------
       
   937 // CCalenDeleteUi::DeleteEntryL
       
   938 // Deletes an entry from the database
       
   939 // (other items were commented in a header).
       
   940 // -----------------------------------------------------------------------------
       
   941 //
       
   942 TBool CCalenDeleteUi::DeleteEntryL( CCalEntryView* aEntryView, CCalEntry* aEntry )
       
   943     {
       
   944     TRACE_ENTRY_POINT;
       
   945     const CCalEntry::TType entryType = aEntry->EntryTypeL();
       
   946 
       
   947     TBool doDelete = CalenActionUiUtils::ShowDeleteConfirmationQueryL( 
       
   948                                                                     entryType == CCalEntry::ETodo ?
       
   949                                                                     CalenActionUiUtils::EDeleteToDo :
       
   950                                                                     CalenActionUiUtils::EDeleteEntry );
       
   951     if( doDelete )
       
   952         {
       
   953         //Before deleteing the attachment, reset the attachment model
       
   954         if(iController.Services().GetAttachmentData()->NumberOfItems())
       
   955             {
       
   956             iController.Services().GetAttachmentData()->Reset();
       
   957             }
       
   958         aEntryView->DeleteL( *aEntry );
       
   959 
       
   960         if( aEntry )
       
   961             {
       
   962             delete aEntry;
       
   963             aEntry = NULL;
       
   964             }
       
   965         }
       
   966 
       
   967     TRACE_EXIT_POINT;
       
   968     return doDelete;
       
   969     }
       
   970 
       
   971 // -----------------------------------------------------------------------------
       
   972 // CCalenDeleteUi::TryDeleteWithMrUtilsL
       
   973 // Attempt to delete the instance using the Meeting Request utilities,
       
   974 // if MR viewers is enabled.
       
   975 // (other items were commented in a header).
       
   976 // -----------------------------------------------------------------------------
       
   977 //
       
   978 TBool CCalenDeleteUi::TryDeleteWithMrUtilsL( CCalInstance* aInstance, 
       
   979                                                               CalCommon::TRecurrenceRange aRepeatType )
       
   980     {
       
   981     TRACE_ENTRY_POINT;
       
   982     
       
   983     TBool doDelete = ETrue;
       
   984 
       
   985 	if( iGlobalData->InterimUtilsL().MRViewersEnabledL() && 
       
   986         iGlobalData->InterimUtilsL().IsMeetingRequestL(aInstance->Entry()))
       
   987 
       
   988         {
       
   989         CMRMailboxUtils::TMailboxInfo info;
       
   990         if( iGlobalData->AttemptToRetrieveDefaultMailboxL( info ) )
       
   991             {
       
   992             if(aRepeatType == CalCommon::EThisAndAll )
       
   993                 {
       
   994                 iGlobalData->MeetingRequestUtilsL().DeleteWithUiL( aInstance->Entry(),
       
   995                                                                                       info.iEntryId );
       
   996                 if( aInstance )
       
   997                     {
       
   998                     delete aInstance;
       
   999                     aInstance = NULL;
       
  1000                     }
       
  1001                 }
       
  1002             else if( aRepeatType == CalCommon::EThisOnly )
       
  1003                 {
       
  1004                 iGlobalData->MeetingRequestUtilsL().DeleteWithUiL( aInstance, info.iEntryId );
       
  1005                 }
       
  1006             else
       
  1007                 {
       
  1008                 User::Leave( KErrNotSupported );
       
  1009                 }
       
  1010             }
       
  1011         else
       
  1012             {
       
  1013             doDelete = EFalse;
       
  1014             }
       
  1015         }
       
  1016     else
       
  1017         {
       
  1018         doDelete = EFalse;
       
  1019         }
       
  1020 
       
  1021     TRACE_EXIT_POINT;
       
  1022     return doDelete;
       
  1023     }
       
  1024 
       
  1025 // -----------------------------------------------------------------------------
       
  1026 // CCalenDeleteUi::ShowMultipleEntriesDeleteQueryL
       
  1027 // For displaying multiple entries deletion confirmation query
       
  1028 // -----------------------------------------------------------------------------
       
  1029 //
       
  1030 TInt CCalenDeleteUi::ShowMultipleEntriesDeleteQueryL(TInt aCount)
       
  1031 	{
       
  1032     TRACE_ENTRY_POINT;
       
  1033 
       
  1034     CAknQueryDialog *dialog = CAknQueryDialog::NewL( );
       
  1035     CleanupStack::PushL( dialog );
       
  1036     TInt resID;
       
  1037     HBufC* prompt;
       
  1038     if( aCount > 1 )
       
  1039         {
       
  1040         resID = R_CALEN_QTN_TODO_QUEST_DELETE_MARKED_NOTES;
       
  1041         prompt = StringLoader::LoadLC( resID, aCount );
       
  1042         }
       
  1043     else if( aCount ==  1 )
       
  1044         {
       
  1045         resID = R_CALEN_QTN_TODO_QUEST_DELETE_MARKED_NOTE;
       
  1046         prompt = StringLoader::LoadLC( resID );
       
  1047         }
       
  1048     else
       
  1049         {
       
  1050         CleanupStack::PopAndDestroy( dialog );
       
  1051         TRACE_EXIT_POINT;
       
  1052         return 0;   //return 0 for other invalid aCount value ( < 0 )
       
  1053         }
       
  1054     dialog->SetPromptL( *prompt );
       
  1055     CleanupStack::PopAndDestroy( prompt );
       
  1056 
       
  1057     CleanupStack::Pop( dialog );
       
  1058 
       
  1059     TRACE_EXIT_POINT;
       
  1060     return dialog->ExecuteLD( R_CALEN_ERASEQUERY_NOTE );
       
  1061 
   897 	}
  1062 	}
   898 	QDateTime recId = aInstance.recurrenceId().toUTC();
  1063 
   899 	const bool child = recId.isNull();
  1064 // -----------------------------------------------------------------------------
   900 
  1065 // CCalenDeleteUi::DialogDismissedL
   901 	if( !aHasRepeatType ) {
       
   902 		aRepeatType = AgendaUtil::ThisAndAll;
       
   903 	}
       
   904 	// For later reference in handleDeletion()
       
   905 	mRecurrenceRange = aRepeatType;
       
   906 
       
   907 	if( !aHasRepeatType && ( child || repeating ) && 
       
   908 			( aInstance.type() != AgendaEntry::TypeAnniversary ) ) {
       
   909 		showRepeatingEntryDeleteQuery();
       
   910 	}
       
   911 	else
       
   912 	{
       
   913 		showDeleteQuery(aInstance.type() == AgendaEntry::TypeTodo ?
       
   914 														EDeleteToDo :
       
   915 														EDeleteEntry );
       
   916 	}
       
   917 	OstTraceFunctionExit0( CALENDELETEUI_DODELETESINGLEINSTANCEL_EXIT );
       
   918 }
       
   919 
       
   920 
       
   921 // -----------------------------------------------------------------------------
       
   922 // CalenDeleteUi::DialogDismissedL
       
   923 // From MProgressDialogCallback
  1066 // From MProgressDialogCallback
   924 // Callback method
  1067 // Callback method
   925 // called when a dialog is dismissed.
  1068 // called when a dialog is dismissed.
   926 // -----------------------------------------------------------------------------
  1069 // -----------------------------------------------------------------------------
   927 //
  1070 //
   928 void CalenDeleteUi::DialogDismissedL( const TInt /*aButtonId*/ )
  1071 void CCalenDeleteUi::DialogDismissedL( const TInt /*aButtonId*/ )
   929     {
  1072     {
   930     OstTraceFunctionEntry0( CALENDELETEUI_DIALOGDISMISSEDL_ENTRY );
  1073     TRACE_ENTRY_POINT;
       
  1074     // dismiss the wait dialog
       
  1075     if(iWaitDialog)
       
  1076         {
       
  1077         iWaitDialog->ProcessFinishedL();
       
  1078         }
   931     
  1079     
   932     // no more entries to delete
  1080     // no more entries to delete
   933     iMoreEntriesToDelete = EFalse;
  1081     iMoreEntriesToDelete = EFalse;
   934     iDisplayQuery = EFalse;
  1082     iDisplayQuery = EFalse;
   935     
  1083     
   936     // issue notification cancel delete
  1084     // issue notification cancel delete
   937     iController.BroadcastNotification(ECalenNotifyCancelDelete);
  1085     iController.BroadcastNotification(ECalenNotifyCancelDelete);
   938     
  1086     TRACE_EXIT_POINT;
   939     OstTraceFunctionExit0( CALENDELETEUI_DIALOGDISMISSEDL_EXIT );
  1087     }
   940     }
  1088 
   941 
  1089 // -----------------------------------------------------------------------------
   942 // -----------------------------------------------------------------------------
  1090 // CCalenDeleteUi::DeleteEntryL
   943 // CalenDeleteUi::DeleteEntryL
       
   944 // Delete entry using entry local uid
  1091 // Delete entry using entry local uid
   945 // -----------------------------------------------------------------------------
  1092 // -----------------------------------------------------------------------------
   946 //
  1093 //
   947 void CalenDeleteUi::DeleteEntryL(ulong& aEntryLocalUid)
  1094 void CCalenDeleteUi::DeleteEntryL(TCalLocalUid& aEntryLocalUid, TInt aColId)
   948     {
  1095     {
   949     OstTraceFunctionEntry0( CALENDELETEUI_DELETEENTRYL_ENTRY );
  1096     TRACE_ENTRY_POINT;
   950     
  1097     
   951     iController.Services().agendaInterface()->deleteEntry(aEntryLocalUid);
  1098     // fetch the entry
   952     
  1099     CCalEntry* entry = iGlobalData->EntryViewL(aColId)->FetchL(aEntryLocalUid);
   953     OstTraceFunctionExit0( CALENDELETEUI_DELETEENTRYL_EXIT );
  1100     if( entry )
   954     }
  1101         {
   955 
  1102         CleanupStack::PushL( entry );
   956 // -----------------------------------------------------------------------------
  1103         iGlobalData->EntryViewL(aColId)->DeleteL( *entry );
   957 // CalenDeleteUi::DisplayWaitDialogL
  1104         CleanupStack::Pop( entry );
       
  1105         delete entry;
       
  1106         entry = NULL;
       
  1107         }   
       
  1108     
       
  1109     TRACE_EXIT_POINT;
       
  1110     }
       
  1111 
       
  1112 // -----------------------------------------------------------------------------
       
  1113 // CCalenDeleteUi::DisplayWaitDialogL
   958 // Display wait dialog
  1114 // Display wait dialog
   959 // -----------------------------------------------------------------------------
  1115 // -----------------------------------------------------------------------------
   960 //
  1116 //
   961 void CalenDeleteUi::DisplayWaitDialogL()
  1117 void CCalenDeleteUi::DisplayWaitDialogL()
   962     {
  1118     {
   963     OstTraceFunctionEntry0( CALENDELETEUI_DISPLAYWAITDIALOGL_ENTRY );
  1119     TRACE_ENTRY_POINT;
   964     
  1120     
   965     OstTraceFunctionExit0( CALENDELETEUI_DISPLAYWAITDIALOGL_EXIT );
  1121     delete iWaitDialog;
   966     }
  1122     iWaitDialog = NULL;
   967 
  1123     iWaitDialog = new( ELeave )CAknWaitDialog( REINTERPRET_CAST( CEikDialog**, &iWaitDialog ), ETrue );
   968 // -----------------------------------------------------------------------------
  1124     iWaitDialog->ExecuteLD( R_TODO_VIEW_DELETE_WAIT_NOTE );
   969 // CalenDeleteUi::MarkedEntriesDeletedL
  1125     iWaitDialog->SetCallback(this);
       
  1126     
       
  1127     TRACE_EXIT_POINT;
       
  1128     }
       
  1129 
       
  1130 // -----------------------------------------------------------------------------
       
  1131 // CCalenDeleteUi::MarkedEntriesDeletedL
   970 // Dismiss wait dialog and show information note
  1132 // Dismiss wait dialog and show information note
   971 // -----------------------------------------------------------------------------
  1133 // -----------------------------------------------------------------------------
   972 //
  1134 //
   973 void CalenDeleteUi::MarkedEntriesDeletedL()
  1135 void CCalenDeleteUi::MarkedEntriesDeletedL()
   974     {
  1136     {
   975     OstTraceFunctionEntry0( CALENDELETEUI_MARKEDENTRIESDELETEDL_ENTRY );
  1137     TRACE_ENTRY_POINT;
   976     
  1138     
       
  1139     // dismiss the waitdialog
       
  1140     if(iWaitDialog)
       
  1141         {
       
  1142         iWaitDialog->ProcessFinishedL();
       
  1143         }
       
  1144     
       
  1145     // Show confirmation note
       
  1146     //HBufC* buf = StringLoader::LoadLC( R_QTN_CALE_CONF_ALL_NOTES_DELETED, iEikEnv );
       
  1147     //CAknConfirmationNote* dialog = new( ELeave ) CAknConfirmationNote();
       
  1148     //dialog->ExecuteLD(*buf);
       
  1149     //CleanupStack::PopAndDestroy( buf );
       
  1150 
   977     // notify marked entries deleted
  1151     // notify marked entries deleted
   978     iController.BroadcastNotification( ECalenNotifyMarkedEntryDeleted );
  1152     iController.BroadcastNotification( ECalenNotifyMarkedEntryDeleted );
   979     
  1153     
   980     OstTraceFunctionExit0( CALENDELETEUI_MARKEDENTRIESDELETEDL_EXIT );
  1154     TRACE_EXIT_POINT;
   981     }
  1155     }
   982 
  1156 
       
  1157 // -----------------------------------------------------------------------------
       
  1158 // CCalenDeleteUi::HandleDeleteAllEntriesL
       
  1159 // Handles launching of the delete all entries list query
       
  1160 // -----------------------------------------------------------------------------
       
  1161 //
       
  1162 void CCalenDeleteUi::HandleDeleteAllEntriesL()
       
  1163     {
       
  1164     TRACE_ENTRY_POINT;
       
  1165     RPointerArray<CCalCalendarInfo> calendarInfoList;
       
  1166     CleanupClosePushL(calendarInfoList);
       
  1167 	iController.Services().GetAllCalendarInfoL(calendarInfoList);
       
  1168     TInt visibleCalendarsCount(0);
       
  1169     for(TInt index=0;index<calendarInfoList.Count();index++)
       
  1170         {
       
  1171         if(calendarInfoList[index]->Enabled())
       
  1172             {
       
  1173             visibleCalendarsCount++;
       
  1174             }
       
  1175         if(visibleCalendarsCount>1)
       
  1176             {
       
  1177             break;
       
  1178             }
       
  1179         }
       
  1180     CleanupStack::PopAndDestroy();
       
  1181     
       
  1182     TInt headingTextResourceId(0);
       
  1183     if(visibleCalendarsCount==1)
       
  1184         {
       
  1185         headingTextResourceId = R_CALE_SINGLE_CALENDAR_DELETE_ENTRIES;
       
  1186         }
       
  1187     else
       
  1188         {
       
  1189         headingTextResourceId = R_CALE_MULTI_CALENDAR_DELETE_ENTRIES;
       
  1190         }
       
  1191 
       
  1192     TInt selectedIndex(0);
       
  1193     CAknListQueryDialog* deleteEntriesListDialog = new(ELeave) CAknListQueryDialog(&selectedIndex);
       
  1194     deleteEntriesListDialog->PrepareLC(R_DELETE_ENTRIES_LIST_QUERY);
       
  1195     HBufC* buf = StringLoader::LoadLC( headingTextResourceId, iEikEnv );
       
  1196     deleteEntriesListDialog->QueryHeading()->SetTextL(buf->Des());
       
  1197     CleanupStack::PopAndDestroy( buf );
       
  1198     
       
  1199     if(deleteEntriesListDialog->RunLD())
       
  1200         {
       
  1201         if(selectedIndex)
       
  1202             {
       
  1203             DeleteAllEntriesL();
       
  1204             }
       
  1205         else
       
  1206             {
       
  1207             DeleteEntriesBeforeDateL();
       
  1208             }
       
  1209         }
       
  1210     else
       
  1211         {
       
  1212         iController.BroadcastNotification(ECalenNotifyDeleteFailed);
       
  1213         }
       
  1214     
       
  1215     TRACE_EXIT_POINT
       
  1216     }
       
  1217 	
   983 // End of File
  1218 // End of File