calendarui/controller/src/calendeleteui.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 51 0b38fc5b94c6
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    18 // System includes
    18 // System includes
    19 #include <QString>
    19 #include <QString>
    20 #include <QtGui>
    20 #include <QtGui>
    21 #include <hbdatetimepicker.h>
    21 #include <hbdatetimepicker.h>
    22 #include <hbdialog.h>
    22 #include <hbdialog.h>
       
    23 #include <hbmessagebox.h>
    23 #include <hbaction.h>
    24 #include <hbaction.h>
    24 #include <hblabel.h>
    25 #include <hblabel.h>
    25 #include <hbradiobuttonlist.h>
    26 #include <hbradiobuttonlist.h>
    26 #include <centralrepository.h>
    27 #include <centralrepository.h>
    27 #include <agendaentry.h>
    28 #include <agendaentry.h>
    28 
    29 
    29 // User includes
    30 // User includes
    30 #include "calendarui_debug.h"
    31 #include "calendarui_debug.h"
    31 #include "calendeleteui.h"
    32 #include "calendeleteui.h"
    32 #include "hb_calencommands.hrh"
       
    33 #include "calencontext.h"
    33 #include "calencontext.h"
    34 #include "calencontroller.h"
    34 #include "calencontroller.h"
    35 #include "CleanupResetAndDestroy.h"
    35 #include "CleanupResetAndDestroy.h"
    36 #include "caleninstanceid.h"
    36 #include "caleninstanceid.h"
    37 #include "calenactionuiutils.h"
    37 #include "calenactionuiutils.h"
    38 #include "CalendarPrivateCRKeys.h"  // includes CalendarInternalCRKeys.h
       
    39 #include "calendateutils.h"
    38 #include "calendateutils.h"
    40 #include "calenagendautils.h"
    39 #include "calenagendautils.h"
    41 
    40 
    42 
    41 
    43 // Local constants
    42 // Local constants
   137 //
   136 //
   138 TBool CalenDeleteUi::HandleCommandL( const TCalenCommand& aCommand )
   137 TBool CalenDeleteUi::HandleCommandL( const TCalenCommand& aCommand )
   139     {
   138     {
   140     TRACE_ENTRY_POINT;
   139     TRACE_ENTRY_POINT;
   141     TBool continueCommand(EFalse);
   140     TBool continueCommand(EFalse);
   142    
   141     
   143     switch( aCommand.Command() )
   142     switch( aCommand.Command() )
   144         {
   143         {
   145         case ECalenDeleteCurrentEntry:
   144         case ECalenDeleteCurrentEntry:
   146             
   145         	mDeleteCommand = ECalenDeleteCurrentEntry;
   147             DeleteCurrentEntryL(); // Entry & instance
   146         	DeleteCurrentEntryL(); // Entry & instance
   148             break;
   147             break;
   149 
   148 
   150         case ECalenDeleteSeries:
   149         case ECalenDeleteSeries:
   151             DeleteThisOrAllL( AgendaUtil::ThisAndAll );
   150         	mDeleteCommand = ECalenDeleteSeries;
       
   151         	DeleteThisOrAllL( AgendaUtil::ThisAndAll );
   152             break;
   152             break;
   153             
   153             
   154         case ECalenDeleteCurrentOccurrence:
   154         case ECalenDeleteCurrentOccurrence:
   155             DeleteThisOrAllL( AgendaUtil::ThisOnly );
   155         	mDeleteCommand = ECalenDeleteCurrentOccurrence;
       
   156         	DeleteThisOrAllL( AgendaUtil::ThisOnly );
   156             break;
   157             break;
   157             
   158             
   158         case ECalenDeleteEntryWithoutQuery:
   159         case ECalenDeleteEntryWithoutQuery:
   159             continueCommand = DeleteEntryWithoutQueryL();
   160         	//TODO:
       
   161         	// This case is not handled currently as no such commands
       
   162         	// has been issued. So this has to be handled once we start 
       
   163         	// issuing the command. 
       
   164         	/*continueCommand = DeleteEntryWithoutQueryL();*/
   160             break;
   165             break;
   161 
   166 
   162         case ECalenDeleteAllEntries:
   167         case ECalenDeleteAllEntries:
   163             DeleteAllEntriesL(); // EntryView & instance
   168         	mDeleteCommand = ECalenDeleteAllEntries;
       
   169         	DeleteAllEntriesL(); // EntryView & instance
   164             break;
   170             break;
   165 
   171 
   166         case ECalenDeleteEntriesBeforeDate:
   172         case ECalenDeleteEntriesBeforeDate:
   167             DeleteEntriesBeforeDateL(); // EntryView & instance
   173             DeleteEntriesBeforeDateL(); // EntryView & instance
   168             break;
   174             break;
   184 // Deletes series repeating entry
   190 // Deletes series repeating entry
   185 // (other items were commented in a header).
   191 // (other items were commented in a header).
   186 // ----------------------------------------------------------------------------
   192 // ----------------------------------------------------------------------------
   187 //
   193 //
   188 void CalenDeleteUi::DeleteThisOrAllL( AgendaUtil::RecurrenceRange aRepeatType )
   194 void CalenDeleteUi::DeleteThisOrAllL( AgendaUtil::RecurrenceRange aRepeatType )
   189     {
   195 {
   190     TRACE_ENTRY_POINT;
   196 	TRACE_ENTRY_POINT;
   191     
   197 
   192     bool isDeleted( false );
   198 	if( iController.context().instanceId().mEntryLocalUid )
   193     
   199 	{
   194     if( iController.context().instanceId().mEntryLocalUid )
   200 		AgendaEntry instance = CalenActionUiUtils::findPossibleInstanceL(
   195         {
   201 									iController.context().instanceId(),
   196         AgendaEntry instance = 
   202 									iController.Services().agendaInterface() );
   197             CalenActionUiUtils::findPossibleInstanceL(iController.context().instanceId(),
   203 		if( !instance.isNull() )
   198                                                    iController.Services().agendaInterface() );
   204 		{
   199          if( !instance.isNull() )
   205 			DeleteSingleInstanceL( instance, aRepeatType );
   200             {
   206 		}
   201             isDeleted = DeleteSingleInstanceL( instance, aRepeatType );
   207 	}
   202             }
   208 	TRACE_EXIT_POINT;
   203         }
   209 }
   204     iController.BroadcastNotification( isDeleted? ECalenNotifyEntryDeleted :
       
   205                                                                ECalenNotifyDeleteFailed );
       
   206     
       
   207     TRACE_EXIT_POINT;
       
   208     }
       
   209 
   210 
   210 // ----------------------------------------------------------------------------
   211 // ----------------------------------------------------------------------------
   211 // CalenDeleteUi::DeleteEntryWithoutQueryL()
   212 // CalenDeleteUi::DeleteEntryWithoutQueryL()
   212 // Deletes the current entry
   213 // Deletes the current entry
   213 // (other items were commented in a header).
   214 // (other items were commented in a header).
   226 	
   227 	
   227 	ASSERT( iMutlipleContextIdsCount );
   228 	ASSERT( iMutlipleContextIdsCount );
   228 
   229 
   229 	    if(!iMoreEntriesToDelete)
   230 	    if(!iMoreEntriesToDelete)
   230 		    {
   231 		    {
   231 		    iDisplayQuery = ShowMultipleEntriesDeleteQueryL(iMutlipleContextIdsCount);
   232 		    //iDisplayQuery = ShowMultipleEntriesDeleteQueryL(iMutlipleContextIdsCount);
   232 		    }
   233 		    }
   233 		
   234 		
   234 		if(iDisplayQuery)
   235 		if(iDisplayQuery)
   235 			{
   236 			{
   236 			if(!iMoreEntriesToDelete)	
   237 			if(!iMoreEntriesToDelete)	
   288 // (other items were commented in a header).
   289 // (other items were commented in a header).
   289 // ----------------------------------------------------------------------------
   290 // ----------------------------------------------------------------------------
   290 //
   291 //
   291 void CalenDeleteUi::DeleteCurrentEntryL()
   292 void CalenDeleteUi::DeleteCurrentEntryL()
   292 {
   293 {
   293     TRACE_ENTRY_POINT;
   294 	TRACE_ENTRY_POINT;
   294 
   295 
   295     bool deleted( false );
   296 	// Make sure we're focused on an entry.
   296     TCalenNotification notification = ECalenNotifyDeleteFailed;
   297 	if (iController.context().instanceId().mEntryLocalUid) {
   297     
   298 		// Fetch the entry
   298     // Make sure we're focused on an entry.
   299 		AgendaEntry entry = iController.Services().agendaInterface()->fetchById(
   299     if (iController.context().instanceId().mEntryLocalUid) {
   300 				iController.context().instanceId().mEntryLocalUid);
   300         // Fetch the entry
   301 			// Check if the entry is a To-Do
   301         AgendaEntry entry = iController.Services().agendaInterface()->fetchById(
   302 			if (AgendaEntry::TypeTodo == entry.type()) {
   302                                 iController.context().instanceId().mEntryLocalUid);
   303 				showDeleteQuery(EDeleteToDo);
   303         
   304 			} else {
   304         // Check if the entry is a To-Do
   305 				// Show the repeat entry delete query for repeating entries except Anniversary
   305         if (AgendaEntry::TypeTodo == entry.type()) {
   306 				// Even though the anniversary is repeating 
   306             if(!entry.isNull()) {
   307 				// all the instances will be deleted
   307                 deleted = DeleteEntryL(entry);
   308 				if ((entry.isRepeating() || !entry.recurrenceId().isNull()) 
   308                 if(deleted) {
   309 							&& (AgendaEntry::TypeAnniversary != entry.type())) {
   309                     // Delete is successful
   310 					// Show a confirmation note whether the user
   310                     notification = ECalenNotifyEntryDeleted;
   311 					// wants to delete the single instance or all of them
   311                 }
   312 					showRepeatingEntryDeleteQuery();
   312             }
   313 				} else {
   313         }
   314 					// If the entry is not a repeating entry,
   314         else {
   315 					// delete it directly
   315             if (entry.isRepeating() || !entry.recurrenceId().isNull()) {
   316 					// Save the entry for later reference in the slot
   316                 // Show a confirmation note whether the user
   317 					showDeleteQuery(EDeleteEntry);
   317                 // wants to delete the single instance or all of them
   318 				}
   318                 showRepeatingEntryDeleteQuery();
   319 			}
   319             } else {
   320 	}
   320                 // If the entry is not a repeating entry,
   321 	TRACE_EXIT_POINT;
   321                 // delete it directly
       
   322                 deleted = DeleteEntryL(entry);
       
   323                 if (deleted) {
       
   324                     // Delete is successful
       
   325                     notification = ECalenNotifyEntryDeleted;
       
   326                 }
       
   327             }
       
   328         }
       
   329     }
       
   330 
       
   331     iController.BroadcastNotification( notification );
       
   332 
       
   333     TRACE_EXIT_POINT;
       
   334 }
   322 }
   335 
   323 
   336 // ----------------------------------------------------------------------------
   324 // ----------------------------------------------------------------------------
   337 // CalenDeleteUi::DeleteAllEntriesL
   325 // CalenDeleteUi::DeleteAllEntriesL
   338 // Deletes all entries
   326 // Deletes all entries
   339 // (other items were commented in a header).
   327 // (other items were commented in a header).
   340 // ----------------------------------------------------------------------------
   328 // ----------------------------------------------------------------------------
   341 //
   329 //
   342 void CalenDeleteUi::DeleteAllEntriesL()
   330 void CalenDeleteUi::DeleteAllEntriesL()
   343     {
   331     {
   344     TRACE_ENTRY_POINT;
   332 	if(iIsDeleting) {
   345 
   333 		return;
   346     ASSERT( !iIsDeleting );
   334 	}
   347 
   335 
   348     const int buttonId = CalenActionUiUtils::showDeleteConfirmationQueryL( 
   336     showDeleteQuery(EDeleteAll );
   349                                                                         CalenActionUiUtils::EDeleteAll );   
   337 	}
   350     if( buttonId )
       
   351         {
       
   352         HandleDeleteMultipleEventsL( AgendaUtil::minTime(), AgendaUtil::maxTime(),1 );
       
   353         }
       
   354     else
       
   355         {
       
   356         // notify delete failed
       
   357         iController.BroadcastNotification(ECalenNotifyDeleteFailed); 
       
   358         }
       
   359 
       
   360     TRACE_EXIT_POINT;
       
   361     }
       
   362 
   338 
   363 // ----------------------------------------------------------------------------
   339 // ----------------------------------------------------------------------------
   364 // CalenDeleteUi::DeleteEntriesBeforeDateL
   340 // CalenDeleteUi::DeleteEntriesBeforeDateL
   365 // Deletes all entries before a set date.
   341 // Deletes all entries before a set date.
   366 // (other items were commented in a header).
   342 // (other items were commented in a header).
   367 // ----------------------------------------------------------------------------
   343 // ----------------------------------------------------------------------------
   368 //
   344 //
   369 void CalenDeleteUi::DeleteEntriesBeforeDateL()
   345 void CalenDeleteUi::DeleteEntriesBeforeDateL()
   370     {
   346     {
   371     TRACE_ENTRY_POINT;
   347     TRACE_ENTRY_POINT;
   372 
   348 	if(iIsDeleting) {
   373     ASSERT( !iIsDeleting );
   349 		return;
   374 
   350 	}    
   375     TCalenNotification notification = ECalenNotifyDeleteFailed;
       
   376     
       
   377     // launch the datepicker
   351     // launch the datepicker
   378     mIsDateValid = false;
       
   379     dateQuery();
   352     dateQuery();
   380 
   353     TRACE_EXIT_POINT;
   381     if( mIsDateValid )
   354     }
   382         {
   355 
   383         // Do delete only if inputted day is after beginning of range
   356 // ----------------------------------------------------------------------------
   384         if( mDateTime > AgendaUtil::minTime() )
   357 // CalenDeleteUi::dateQuery
   385             {
   358 // Launches the popup for the date selection
   386             // Two pass delete:
   359 // (other items were commented in a header).
   387             // 1. pass
   360 // ----------------------------------------------------------------------------
   388             // To prevent destroying entries starting and ending midnight
   361 //
   389             // subtract one second and do delete on that range.
       
   390             mDateTime = mDateTime.addSecs(-1);
       
   391             mDateTime = ( mDateTime > AgendaUtil::minTime()? mDateTime :  AgendaUtil::minTime());
       
   392 
       
   393             HandleDeleteMultipleEventsL( AgendaUtil::minTime(),
       
   394                                                     mDateTime,1 );
       
   395             notification = ECalenNotifyMultipleEntriesDeleted;
       
   396             }
       
   397         }
       
   398 
       
   399     iController.BroadcastNotification( notification );
       
   400     TRACE_EXIT_POINT;
       
   401     }
       
   402     
       
   403 void CalenDeleteUi::dateQuery()
   362 void CalenDeleteUi::dateQuery()
   404 	{
   363 	{
   405 	// Create a popup with datepicker to select the date.
   364 	// Create a popup with datepicker to select the date.
       
   365 	HbDialog *popUp = new HbDialog();
       
   366 	popUp->setDismissPolicy(HbDialog::NoDismiss);
       
   367 	popUp->setTimeout(HbDialog::NoTimeout );
       
   368 	popUp->setAttribute( Qt::WA_DeleteOnClose, true );
       
   369 	popUp->setHeadingWidget(new HbLabel(hbTrId("txt_calendar_title_set_date")));
       
   370 	
   406 	QDateTime currentDateTime(CalenDateUtils::today());
   371 	QDateTime currentDateTime(CalenDateUtils::today());
   407 	QDate currentDate(currentDateTime.date());
   372 	QDate currentDate(currentDateTime.date());
   408 	mDatePicker = new  HbDateTimePicker(currentDate);
   373 	if(mDatePicker) {
       
   374 		mDatePicker = NULL;
       
   375 	}
       
   376 	mDatePicker = new  HbDateTimePicker(popUp);
   409 	mDatePicker->setMinimumDate(CalenDateUtils::minTime().date());
   377 	mDatePicker->setMinimumDate(CalenDateUtils::minTime().date());
   410 	mDatePicker->setMaximumDate(currentDate);
   378 	mDatePicker->setMaximumDate(currentDate);
   411 	HbDialog popUp;
   379 	mDatePicker->setDate(currentDate);
   412 	popUp.setDismissPolicy(HbDialog::NoDismiss);
   380 
   413 	popUp.setTimeout(HbDialog::NoTimeout );
   381 	popUp->setContentWidget(mDatePicker);  
   414 	popUp.setHeadingWidget(new HbLabel(hbTrId("txt_calendar_title_set_date")));
   382 	mDeleteAction = new HbAction(
   415 	popUp.setContentWidget(mDatePicker);  
   383 						hbTrId("txt_calendar_button_dialog_delete"), popUp);
   416 	HbAction *okAction = new HbAction(hbTrId("txt_calendar_button_dialog_delete"));
   384 	popUp->addAction(mDeleteAction);
   417 	popUp.setPrimaryAction(okAction);
   385 	mCancelAction = new HbAction(hbTrId("txt_common_button_cancel"),popUp);
   418 	connect(okAction,SIGNAL(triggered()),this,SLOT(getSelectedDate()));
   386 	popUp->addAction(mCancelAction);
   419 	connect(okAction,SIGNAL(triggered()),&popUp,SLOT(close()));
   387 	// Show the popup
   420 	popUp.setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"),&popUp));
   388 	popUp->open(this, SLOT(handleDateQuery(HbAction*)));
   421 	popUp.exec();
   389 	}
   422 	}
   390 
   423 
   391 // ----------------------------------------------------------------------------
       
   392 // CalenDeleteUi::handleDateQuery
       
   393 // Handles the selection for the date query
       
   394 // (other items were commented in a header).
       
   395 // ----------------------------------------------------------------------------
       
   396 //
       
   397 void CalenDeleteUi::handleDateQuery(HbAction* action)
       
   398 {
       
   399 	if(action == mDeleteAction) {
       
   400 		// User selected the date before which all the entries has to be deleted
       
   401 		QDate selectedDate(mDatePicker->date());
       
   402 		// Check if the date is within the range.
       
   403 		if(selectedDate.isValid()) {
       
   404 			QTime time(0,0,0,0);
       
   405 			QDateTime dateTime;
       
   406 			dateTime.setDate(selectedDate);
       
   407 			dateTime.setTime(time);
       
   408 			// Do delete only if inputted day is after beginning of range
       
   409 			if(dateTime > AgendaUtil::minTime()) {
       
   410 				// Two pass delete:
       
   411 				// 1. pass
       
   412 				// To prevent destroying entries starting and ending midnight
       
   413 				// subtract one second and do delete on that range.
       
   414 				dateTime = dateTime.addSecs(-1);
       
   415 				dateTime = ( dateTime > AgendaUtil::minTime()? 
       
   416 											dateTime :  AgendaUtil::minTime());
       
   417 
       
   418 				HandleDeleteMultipleEventsL( AgendaUtil::minTime(), 
       
   419 																 dateTime, 1);
       
   420 			}else {
       
   421 				iController.BroadcastNotification(ECalenNotifyDeleteFailed);
       
   422 			}
       
   423 		}
       
   424 	}else {
       
   425 		// User pressed cancel
       
   426 		handleDeleteCancel();
       
   427 	}
       
   428 	// Reset the member variables
       
   429 	mDeleteAction = NULL;
       
   430 	mCancelAction = NULL;
       
   431 }
       
   432 // ----------------------------------------------------------------------------
       
   433 // CalenDeleteUi::showRepeatingEntryDeleteQuery
       
   434 // Launches the popup for deleting the repeating entry
       
   435 // (other items were commented in a header).
       
   436 // ----------------------------------------------------------------------------
       
   437 //
   424 void CalenDeleteUi::showRepeatingEntryDeleteQuery()
   438 void CalenDeleteUi::showRepeatingEntryDeleteQuery()
   425 {
   439 {
   426     HbDialog popUp;
   440     HbDialog *popUp = new HbDialog();
   427     popUp.setDismissPolicy(HbDialog::NoDismiss);
   441     popUp->setDismissPolicy(HbDialog::NoDismiss);
   428     popUp.setTimeout(HbDialog::NoTimeout);
   442     popUp->setTimeout(HbDialog::NoTimeout);
       
   443     popUp->setAttribute( Qt::WA_DeleteOnClose, true );
   429     
   444     
   430     QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
   445     QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
   431     HbWidget *editWidget = new HbWidget();
   446     HbWidget *editWidget = new HbWidget();
   432     editWidget->setLayout(layout);
   447     editWidget->setLayout(layout);
   433     
   448     
   439 
   454 
   440     editButtonList->setItems(list);
   455     editButtonList->setItems(list);
   441 
   456 
   442     layout->addItem(editButtonList);
   457     layout->addItem(editButtonList);
   443     
   458     
   444     popUp.setContentWidget(editWidget);
   459     popUp->setContentWidget(editWidget);
   445     popUp.setHeadingWidget(new HbLabel(
   460     popUp->setHeadingWidget(new HbLabel(
   446 						hbTrId("txt_calendar_title_delete_repeated_entry")));
   461 						hbTrId("txt_calendar_title_delete_repeated_entry")));
   447 
   462 
   448     connect(editButtonList, SIGNAL(itemSelected(int)), this,
   463     // Add cancel action
   449             SLOT(handleRepeatedEntryDelete(int)));
       
   450     connect(editButtonList, SIGNAL(itemSelected(int)), &popUp, SLOT(close()));
       
   451 
       
   452     // Create secondary action
       
   453     HbAction *cancelAction = new HbAction(
   464     HbAction *cancelAction = new HbAction(
   454 							hbTrId("txt_calendar_button_softkey1_cancel"));
   465 							hbTrId("txt_calendar_button_softkey1_cancel"));
   455     popUp.setSecondaryAction(cancelAction);
   466     popUp->addAction(cancelAction);
   456     connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleCancel()));
   467     connect(editButtonList, SIGNAL(itemSelected(int)), this,
   457     connect(cancelAction, SIGNAL(triggered()), &popUp, SLOT(close()));
   468 										SLOT(handleRepeatedEntryDelete(int)));
       
   469     connect(editButtonList, SIGNAL(itemSelected(int)), popUp, SLOT(close()));
       
   470     connect(cancelAction, SIGNAL(triggered()), this, 
       
   471 										SLOT(handleDeleteCancel()));
   458     
   472     
   459     // Show the popup
   473     // Show the popup
   460     popUp.exec();
   474     popUp->open();
   461 }
   475 }
   462 
   476 
   463 void CalenDeleteUi::getSelectedDate()
   477 // ----------------------------------------------------------------------------
   464 	{  
   478 // CalenDeleteUi::handleDeleteCancel
   465     QDate selectedDate(mDatePicker->date());
   479 // Handles the cancel action
   466         
   480 // (other items were commented in a header).
   467 	// Check if the date is within the range.
   481 // ----------------------------------------------------------------------------
   468 	if(selectedDate.isValid())
   482 //
   469 		{
   483 void CalenDeleteUi::handleDeleteCancel()
   470 		QTime time(0,0,0,0);
   484 {
   471 		mDateTime.setDate(selectedDate);
   485 	iController.BroadcastNotification(ECalenNotifyDeleteFailed);
   472 		mDateTime.setTime(time);
   486 }
   473 		mIsDateValid = true;
       
   474 		}
       
   475     }
       
   476 
   487 
   477 void CalenDeleteUi::handleRepeatedEntryDelete(int index)
   488 void CalenDeleteUi::handleRepeatedEntryDelete(int index)
   478 {
   489 {
   479     // Fetch the entry
   490 	// Fetch the entry
   480     // Find all possible instances
   491 	// Find all possible instances
   481     AgendaEntry instance = CalenActionUiUtils::findPossibleInstanceL(
   492 	AgendaEntry instance = CalenActionUiUtils::findPossibleInstanceL(
   482                                 iController.context().instanceId(),
   493 									iController.context().instanceId(),
   483                                 iController.Services().agendaInterface());
   494 									iController.Services().agendaInterface());
   484 
   495 
   485     if (!instance.isNull()) {
   496 	if (!instance.isNull()) {
   486         connect(iController.Services().agendaInterface(), SIGNAL(entryDeleted(ulong)),
   497 		connect(iController.Services().agendaInterface(), 
   487                 this, SLOT(entryDeleted(ulong)));
   498 									SIGNAL(entryDeleted(ulong)),
   488         switch(index) {
   499 									this, SLOT(entryDeleted(ulong)));
   489             case 0:
   500 		switch(index) {
   490                 // User wants to delete only this occurence
   501 			case 0:
   491                 iController.Services().agendaInterface()->deleteRepeatedEntry(instance, AgendaUtil::ThisOnly);
   502 				// User wants to delete only this occurence
   492                 break;
   503 				iController.Services().agendaInterface()->deleteRepeatedEntry(
   493             case 1:
   504 									instance, AgendaUtil::ThisOnly);
   494                 // User wants to delete all the occurences
   505 				break;
   495                 iController.Services().agendaInterface()->deleteRepeatedEntry(instance, AgendaUtil::ThisAndAll);
   506 			case 1:
   496                 break;
   507 				// User wants to delete all the occurences
       
   508 				iController.Services().agendaInterface()->deleteRepeatedEntry(
       
   509 									instance, AgendaUtil::ThisAndAll);
       
   510 				break;
       
   511 		}
       
   512 	}
       
   513 }
       
   514 
       
   515 // ----------------------------------------------------------------------------
       
   516 // CalenDeleteUi::showDeleteQuery
       
   517 // Launches the popup for deleting the instance/instances
       
   518 // (other items were commented in a header).
       
   519 // ----------------------------------------------------------------------------
       
   520 //
       
   521 void CalenDeleteUi::showDeleteQuery(const TDeleteConfirmationType type,
       
   522                                                      const int count)
       
   523     {
       
   524     HbMessageBox *popup = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
       
   525     popup->setDismissPolicy(HbDialog::NoDismiss);
       
   526     popup->setTimeout(HbDialog::NoTimeout);
       
   527     popup->setAttribute( Qt::WA_DeleteOnClose, true );
       
   528     
       
   529     QString text = 0;
       
   530     
       
   531     switch(type)
       
   532         {
       
   533         case EDeleteEntry:
       
   534             {
       
   535             text.append(hbTrId("txt_calendar_info_delete_meeting"));
       
   536             break;
       
   537             }
       
   538         case EDeleteToDo:
       
   539             {
       
   540             text.append(hbTrId("txt_calendar_info_delete_todo_note"));
       
   541             break;
       
   542             }
       
   543         case EDeleteToDos:
       
   544             {//"Delete %N to-do notes?"
       
   545             // TODO: Add the text id
       
   546             text.append("Delete %N to-do's?").arg(count);
       
   547             break;
       
   548             }
       
   549         case EDeleteAll:
       
   550             {
       
   551             text.append(hbTrId("txt_calendar_info_delete_all_calendar_entries"));
       
   552             break;
       
   553             }
       
   554         default:
       
   555             break;
   497         }
   556         }
   498     }
   557     
       
   558     popup->setText(text);
       
   559     	
       
   560     QList<QAction*> list = popup->actions();
       
   561     for(int i=0; i < list.count(); i++)
       
   562         {
       
   563         popup->removeAction(list[i]);
       
   564         }
       
   565     mDeleteAction = new HbAction(
       
   566 						hbTrId("txt_calendar_button_dialog_delete"), popup);
       
   567     popup->addAction(mDeleteAction);
       
   568     mCancelAction = new HbAction(hbTrId("txt_calendar_button_cancel"), popup);
       
   569     popup->addAction(mCancelAction);
       
   570     popup->open(this, SLOT(handleDeletion(HbAction*)));
       
   571     }
       
   572 
       
   573 // ----------------------------------------------------------------------------
       
   574 // CalenDeleteUi::handleDeletion
       
   575 // Deletes the entries based on the user selection
       
   576 // (other items were commented in a header).
       
   577 // ----------------------------------------------------------------------------
       
   578 //
       
   579 void CalenDeleteUi::handleDeletion(HbAction* action)
       
   580 {
       
   581 	TCalenNotification notification = ECalenNotifyDeleteFailed;
       
   582 	
       
   583 	if(action == mDeleteAction) {
       
   584 		
       
   585 		switch (mDeleteCommand) {
       
   586 			
       
   587 			case ECalenDeleteCurrentEntry:
       
   588 			{
       
   589 				// Get the entry id
       
   590 				ulong id = iController.context().instanceId().mEntryLocalUid;
       
   591 				connect(iController.Services().agendaInterface(), 
       
   592 												SIGNAL(entryDeleted(ulong)),
       
   593 												this, SLOT(entryDeleted(ulong)));
       
   594 				// Delete the entry if the delete button is been pressed
       
   595 				iController.Services().agendaInterface()->deleteEntry(id);
       
   596 			}
       
   597 				break;
       
   598 			
       
   599 			case ECalenDeleteSeries:
       
   600 			case ECalenDeleteCurrentOccurrence:
       
   601 			{
       
   602 				AgendaEntry instance = 
       
   603 						CalenActionUiUtils::findPossibleInstanceL(
       
   604 								iController.context().instanceId(),
       
   605 								iController.Services().agendaInterface() );
       
   606 				if(!instance.isNull()) {
       
   607 					QDateTime recId = instance.recurrenceId().toUTC();
       
   608 					const bool child = recId.isNull();
       
   609 					connect(iController.Services().agendaInterface(), 
       
   610 					        SIGNAL(entryDeleted(ulong)),
       
   611 					        this, SLOT(entryDeleted(ulong)));
       
   612 					if( !child || mRecurrenceRange == AgendaUtil::ThisOnly 
       
   613 							|| mRecurrenceRange == AgendaUtil::ThisAndAll) {
       
   614 						iController.Services().agendaInterface()->deleteRepeatedEntry( 
       
   615 								instance, mRecurrenceRange );
       
   616 					}
       
   617 				}
       
   618 			}
       
   619 				break;
       
   620 			
       
   621 			case ECalenDeleteAllEntries:
       
   622 			{
       
   623 				HandleDeleteMultipleEventsL( AgendaUtil::minTime(), 
       
   624 											AgendaUtil::maxTime(),1 );
       
   625 			}
       
   626 				break;
       
   627 			
       
   628 			default:
       
   629 				break;
       
   630 				
       
   631 		}
       
   632 	}
       
   633 	// If the user presses cancel button the notification will be
       
   634 	// ECalenNotifyDeleteFailed as default.
       
   635 	// Notify the status
       
   636 	iController.BroadcastNotification(notification);
       
   637 	
       
   638 	// Reset the member variables
       
   639 	mDeleteAction = NULL;
       
   640 	mCancelAction = NULL;
   499 }
   641 }
   500 
   642 
   501 void CalenDeleteUi::entryDeleted(ulong id)
   643 void CalenDeleteUi::entryDeleted(ulong id)
   502 {
   644 {
   503     if (iController.context().instanceId().mEntryLocalUid == id) {
   645     if (iController.context().instanceId().mEntryLocalUid == id) {
   516 void CalenDeleteUi::HandleDeleteMultipleEventsL( const QDateTime& aFirstDay,
   658 void CalenDeleteUi::HandleDeleteMultipleEventsL( const QDateTime& aFirstDay,
   517                                                  const QDateTime& aLastDay,
   659                                                  const QDateTime& aLastDay,
   518                                                  int aConfNoteId )
   660                                                  int aConfNoteId )
   519     {
   661     {
   520     TRACE_ENTRY_POINT;
   662     TRACE_ENTRY_POINT;
   521 
   663     
   522     
   664 	if(iIsDeleting) {
   523     ASSERT( !iIsDeleting );
   665 		return;
       
   666 	}
   524     iConfirmationNoteId = aConfNoteId;
   667     iConfirmationNoteId = aConfNoteId;
   525     
   668     
   526     DeleteDayRangeL( aFirstDay, aLastDay );
   669     DeleteDayRangeL( aFirstDay, aLastDay );
   527 
   670 
   528     TRACE_EXIT_POINT;
   671     TRACE_EXIT_POINT;
   616         // Checking that if entry ends at midnight, is quite clumsy, but here goes:
   759         // Checking that if entry ends at midnight, is quite clumsy, but here goes:
   617         // EndsAtStartOfDay takes only CCalInstance, but here we mimic EndsAtStartOfDay
   760         // EndsAtStartOfDay takes only CCalInstance, but here we mimic EndsAtStartOfDay
   618         // for CCalEntry type.
   761         // for CCalEntry type.
   619 
   762 
   620         // First check that if _instance_ ends at midnight, but starts earlier
   763         // First check that if _instance_ ends at midnight, but starts earlier
   621         if( CalenAgendaUtils::endsAtStartOfDayL( entry, aMidnight ) )
   764         if( CalenAgendaUtils::endsAtStartOfDay( entry, aMidnight ) )
   622             {
   765             {
   623             // Second, check that _entry's_ endtime is exactly the midnight
   766             // Second, check that _entry's_ endtime is exactly the midnight
   624             // This prevents us from destroying repeating entries, that has one
   767             // This prevents us from destroying repeating entries, that has one
   625             // instance falling on given midnight.
   768             // instance falling on given midnight.
   626             if( entry.endTime() == aMidnight )
   769             if( entry.endTime() == aMidnight )
   637 // CalenDeleteUi::DeleteSingleInstanceL
   780 // CalenDeleteUi::DeleteSingleInstanceL
   638 // Delete the given instance. Ask the user whether to delete the series or the instance.
   781 // Delete the given instance. Ask the user whether to delete the series or the instance.
   639 // (other items were commented in a header).
   782 // (other items were commented in a header).
   640 // -----------------------------------------------------------------------------
   783 // -----------------------------------------------------------------------------
   641 //
   784 //
   642 TBool CalenDeleteUi::DeleteSingleInstanceL( AgendaEntry& aInstance )
   785 void CalenDeleteUi::DeleteSingleInstanceL( AgendaEntry& aInstance )
   643     {
   786     {
   644     TRACE_ENTRY_POINT;
   787     TRACE_ENTRY_POINT;
   645     TRACE_EXIT_POINT;
   788     DoDeleteSingleInstanceL( aInstance, EFalse, AgendaUtil::ThisAndAll );
   646     return DoDeleteSingleInstanceL( aInstance, EFalse, AgendaUtil::ThisAndAll );
   789     TRACE_EXIT_POINT;
   647     }
   790     }
   648 
   791 
   649 // -----------------------------------------------------------------------------
   792 // -----------------------------------------------------------------------------
   650 // CalenDeleteUi::DeleteSingleInstanceL
   793 // CalenDeleteUi::DeleteSingleInstanceL
   651 // Delete the given instance. Delete the entry range given by aRepeatType.
   794 // Delete the given instance. Delete the entry range given by aRepeatType.
   652 // (other items were commented in a header).
   795 // (other items were commented in a header).
   653 // -----------------------------------------------------------------------------
   796 // -----------------------------------------------------------------------------
   654 //
   797 //
   655 TBool CalenDeleteUi::DeleteSingleInstanceL( AgendaEntry& aInstance, 
   798 void CalenDeleteUi::DeleteSingleInstanceL( AgendaEntry& aInstance, 
   656                                 AgendaUtil::RecurrenceRange aRepeatType )
   799                                 AgendaUtil::RecurrenceRange aRepeatType )
   657     {
   800     {
   658     TRACE_ENTRY_POINT;
   801     TRACE_ENTRY_POINT;
   659     TRACE_EXIT_POINT;
   802     DoDeleteSingleInstanceL( aInstance, ETrue, aRepeatType );
   660     return DoDeleteSingleInstanceL( aInstance, ETrue, aRepeatType );
   803     TRACE_EXIT_POINT;
       
   804     
   661     }
   805     }
   662 
   806 
   663 // -----------------------------------------------------------------------------
   807 // -----------------------------------------------------------------------------
   664 // CalenDeleteUi::DoDeleteSingleInstanceL
   808 // CalenDeleteUi::DoDeleteSingleInstanceL
   665 // Performs the deletion of the instance. If aHasRepeatType is EFalse, the user
   809 // Performs the deletion of the instance. If aHasRepeatType is EFalse, the user
   667 // aRepeatType is ignored. If aHasRepeatType is ETrue, aRepeatType determines
   811 // aRepeatType is ignored. If aHasRepeatType is ETrue, aRepeatType determines
   668 // whether to delete the instance or the entire series.
   812 // whether to delete the instance or the entire series.
   669 // (other items were commented in a header).
   813 // (other items were commented in a header).
   670 // -----------------------------------------------------------------------------
   814 // -----------------------------------------------------------------------------
   671 //
   815 //
   672 TBool CalenDeleteUi::DoDeleteSingleInstanceL( AgendaEntry& aInstance,
   816 void CalenDeleteUi::DoDeleteSingleInstanceL(
   673                                                bool aHasRepeatType,
   817 									AgendaEntry& aInstance,
   674                                                AgendaUtil::RecurrenceRange aRepeatType )
   818 									bool aHasRepeatType,
   675     {
   819 									AgendaUtil::RecurrenceRange aRepeatType )
   676     TRACE_ENTRY_POINT;
   820 {
   677 
   821 	TRACE_ENTRY_POINT;
   678     bool repeating = aInstance.isRepeating();
   822 	bool repeating = aInstance.isRepeating();
   679 
   823 
   680     if( !repeating )
   824 	if( !repeating ) {
   681         {
   825 		// Even though there is no RRule, the entry might
   682         // Even though there is no RRule, the entry might
   826 		// have a list of rdates.
   683         // have a list of rdates.
   827 		QList<QDate> rDates = aInstance.rDates();
   684        QList<QDate> rDates = aInstance.rDates();
   828 		repeating = ( rDates.count() > 0 );
   685         repeating = ( rDates.count() > 0 );
   829 	}
   686         }
   830 	QDateTime recId = aInstance.recurrenceId().toUTC();
   687     QDateTime recId = aInstance.recurrenceId().toUTC();
   831 	const bool child = recId.isNull();
   688     const bool child = recId.isNull();
   832 
   689 
   833 	if( !aHasRepeatType ) {
   690     if( !aHasRepeatType )
   834 		aRepeatType = AgendaUtil::ThisAndAll;
   691         {
   835 	}
   692         aRepeatType = AgendaUtil::ThisAndAll;
   836 	// For later reference in handleDeletion()
   693         }
   837 	mRecurrenceRange = aRepeatType;
   694 
   838 
   695     bool doDelete( ETrue );
   839 	if( !aHasRepeatType && ( child || repeating ) && 
   696 
   840 			( aInstance.type() != AgendaEntry::TypeAnniversary ) ) {
   697     if( !aHasRepeatType && ( child || repeating ) && ( aInstance.type() != AgendaEntry::TypeAnniversary ) )
   841 		showRepeatingEntryDeleteQuery();
   698         {
   842 	}
   699         //doDelete = CalenActionUiUtils::ShowRepeatTypeQueryL( aRepeatType,
   843 	else
   700           //                                                 CalenActionUiUtils::EDelete );
       
   701         }
       
   702     else
       
   703         {
       
   704         doDelete = CalenActionUiUtils::showDeleteConfirmationQueryL(aInstance.type() == AgendaEntry::TypeTodo ?
       
   705                                                                    CalenActionUiUtils::EDeleteToDo :
       
   706                                                                    CalenActionUiUtils::EDeleteEntry );
       
   707         }
       
   708         
       
   709     if( doDelete )
       
   710         {
       
   711         if( !child || aRepeatType == AgendaUtil::ThisOnly )
       
   712             {
       
   713             iController.Services().agendaInterface()->deleteRepeatedEntry( aInstance, aRepeatType );
       
   714             }
       
   715         else if( aRepeatType == AgendaUtil::ThisAndAll )
       
   716             {
       
   717             iController.Services().agendaInterface()->deleteRepeatedEntry( aInstance, aRepeatType );
       
   718             }
       
   719         }
       
   720 
       
   721     TRACE_EXIT_POINT;
       
   722     return doDelete;
       
   723     }
       
   724 
       
   725 // -----------------------------------------------------------------------------
       
   726 // CalenDeleteUi::DeleteEntryL
       
   727 // Deletes an entry from the database
       
   728 // (other items were commented in a header).
       
   729 // -----------------------------------------------------------------------------
       
   730 //
       
   731 TBool CalenDeleteUi::DeleteEntryL( AgendaEntry& entry )
       
   732     {
       
   733     TRACE_ENTRY_POINT;
       
   734 
       
   735     TBool doDelete = CalenActionUiUtils::showDeleteConfirmationQueryL(entry.type() == AgendaEntry::TypeTodo ?
       
   736                                                                       CalenActionUiUtils::EDeleteToDo :
       
   737                                                                       CalenActionUiUtils::EDeleteEntry );
       
   738     
       
   739     if( doDelete )
       
   740         {
       
   741         iController.Services().agendaInterface()->deleteEntry(entry.id());
       
   742         }
       
   743 
       
   744     TRACE_EXIT_POINT;
       
   745     return doDelete;
       
   746     }
       
   747 
       
   748 // -----------------------------------------------------------------------------
       
   749 // CalenDeleteUi::ShowMultipleEntriesDeleteQueryL
       
   750 // For displaying multiple entries deletion confirmation query
       
   751 // -----------------------------------------------------------------------------
       
   752 //
       
   753 TInt CalenDeleteUi::ShowMultipleEntriesDeleteQueryL(int aCount)
       
   754 	{
   844 	{
   755     TRACE_ENTRY_POINT;
   845 		showDeleteQuery(aInstance.type() == AgendaEntry::TypeTodo ?
   756     if( aCount > 1 )
   846 														EDeleteToDo :
   757         {
   847 														EDeleteEntry );
   758         TRACE_EXIT_POINT;
   848 	}
   759         return CalenActionUiUtils::showDeleteConfirmationQueryL(CalenActionUiUtils::EDeleteToDos, aCount );
   849 	TRACE_EXIT_POINT;
   760         }
   850 }
   761     else if( aCount ==  1 )
   851 
   762         {
       
   763         TRACE_EXIT_POINT;
       
   764         return CalenActionUiUtils::showDeleteConfirmationQueryL(CalenActionUiUtils::EDeleteToDo);
       
   765         }
       
   766     else
       
   767         {        
       
   768         TRACE_EXIT_POINT;
       
   769         return 0;   //return 0 for other invalid aCount value ( < 0 )
       
   770         }   
       
   771     
       
   772 	}
       
   773 
   852 
   774 // -----------------------------------------------------------------------------
   853 // -----------------------------------------------------------------------------
   775 // CalenDeleteUi::DialogDismissedL
   854 // CalenDeleteUi::DialogDismissedL
   776 // From MProgressDialogCallback
   855 // From MProgressDialogCallback
   777 // Callback method
   856 // Callback method