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