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