calendarui/controller/src/calendeleteui.cpp
changeset 50 579cc610882e
parent 37 360d55486d7f
child 58 ef813d54df51
--- a/calendarui/controller/src/calendeleteui.cpp	Wed Jun 23 18:11:28 2010 +0300
+++ b/calendarui/controller/src/calendeleteui.cpp	Tue Jul 06 14:14:56 2010 +0300
@@ -298,29 +298,25 @@
 		// Fetch the entry
 		AgendaEntry entry = iController.Services().agendaInterface()->fetchById(
 				iController.context().instanceId().mEntryLocalUid);
-
-		// Check if the entry is a To-Do
-		if (AgendaEntry::TypeTodo == entry.type()) {
-			if(!entry.isNull()) {
-				showDeleteQuery(entry.type() == AgendaEntry::TypeTodo ?
-															EDeleteToDo :
-															EDeleteEntry );
+			// Check if the entry is a To-Do
+			if (AgendaEntry::TypeTodo == entry.type()) {
+				showDeleteQuery(EDeleteToDo);
+			} else {
+				// Show the repeat entry delete query for repeating entries except Anniversary
+				// Even though the anniversary is repeating 
+				// all the instances will be deleted
+				if ((entry.isRepeating() || !entry.recurrenceId().isNull()) 
+							&& (AgendaEntry::TypeAnniversary != entry.type())) {
+					// Show a confirmation note whether the user
+					// wants to delete the single instance or all of them
+					showRepeatingEntryDeleteQuery();
+				} else {
+					// If the entry is not a repeating entry,
+					// delete it directly
+					// Save the entry for later reference in the slot
+					showDeleteQuery(EDeleteEntry);
+				}
 			}
-		}
-		else {
-			if (entry.isRepeating() || !entry.recurrenceId().isNull()) {
-				// Show a confirmation note whether the user
-				// wants to delete the single instance or all of them
-				showRepeatingEntryDeleteQuery();
-			} else {
-				// If the entry is not a repeating entry,
-				// delete it directly
-				// Save the entry for later reference in the slot
-				showDeleteQuery(entry.type() == AgendaEntry::TypeTodo ?
-															EDeleteToDo :
-															EDeleteEntry );
-			}
-		}
 	}
 	TRACE_EXIT_POINT;
 }
@@ -333,7 +329,9 @@
 //
 void CalenDeleteUi::DeleteAllEntriesL()
     {
-    ASSERT( !iIsDeleting );
+	if(iIsDeleting) {
+		return;
+	}
 
     showDeleteQuery(EDeleteAll );
 	}
@@ -347,8 +345,9 @@
 void CalenDeleteUi::DeleteEntriesBeforeDateL()
     {
     TRACE_ENTRY_POINT;
-    ASSERT( !iIsDeleting );
-    
+	if(iIsDeleting) {
+		return;
+	}    
     // launch the datepicker
     dateQuery();
     TRACE_EXIT_POINT;
@@ -380,9 +379,11 @@
 	mDatePicker->setDate(currentDate);
 
 	popUp->setContentWidget(mDatePicker);  
-	
-	popUp->addAction(new HbAction(hbTrId("txt_calendar_button_dialog_delete")));
-	popUp->addAction(new HbAction(hbTrId("txt_common_button_cancel"),popUp));
+	mDeleteAction = new HbAction(
+						hbTrId("txt_calendar_button_dialog_delete"), popUp);
+	popUp->addAction(mDeleteAction);
+	mCancelAction = new HbAction(hbTrId("txt_common_button_cancel"),popUp);
+	popUp->addAction(mCancelAction);
 	// Show the popup
 	popUp->open(this, SLOT(handleDateQuery(HbAction*)));
 	}
@@ -395,11 +396,38 @@
 //
 void CalenDeleteUi::handleDateQuery(HbAction* action)
 {
-	if(action->text() == hbTrId("txt_calendar_button_dialog_delete")) {
-		getSelectedDateAndDelete();
+	if(action == mDeleteAction) {
+		// User selected the date before which all the entries has to be deleted
+		QDate selectedDate(mDatePicker->date());
+		// Check if the date is within the range.
+		if(selectedDate.isValid()) {
+			QTime time(0,0,0,0);
+			QDateTime dateTime;
+			dateTime.setDate(selectedDate);
+			dateTime.setTime(time);
+			// Do delete only if inputted day is after beginning of range
+			if(dateTime > AgendaUtil::minTime()) {
+				// Two pass delete:
+				// 1. pass
+				// To prevent destroying entries starting and ending midnight
+				// subtract one second and do delete on that range.
+				dateTime = dateTime.addSecs(-1);
+				dateTime = ( dateTime > AgendaUtil::minTime()? 
+											dateTime :  AgendaUtil::minTime());
+
+				HandleDeleteMultipleEventsL( AgendaUtil::minTime(), 
+																 dateTime, 1);
+			}else {
+				iController.BroadcastNotification(ECalenNotifyDeleteFailed);
+			}
+		}
 	}else {
+		// User pressed cancel
 		handleDeleteCancel();
 	}
+	// Reset the member variables
+	mDeleteAction = NULL;
+	mCancelAction = NULL;
 }
 // ----------------------------------------------------------------------------
 // CalenDeleteUi::showRepeatingEntryDeleteQuery
@@ -457,62 +485,33 @@
 	iController.BroadcastNotification(ECalenNotifyDeleteFailed);
 }
 
-// ----------------------------------------------------------------------------
-// CalenDeleteUi::getSelectedDateAndDelete
-// Deletes the entries before the selected date
-// (other items were commented in a header).
-// ----------------------------------------------------------------------------
-//
-void CalenDeleteUi::getSelectedDateAndDelete()
+void CalenDeleteUi::handleRepeatedEntryDelete(int index)
 {
-	QDate selectedDate(mDatePicker->date());
+	// Fetch the entry
+	// Find all possible instances
+	AgendaEntry instance = CalenActionUiUtils::findPossibleInstanceL(
+									iController.context().instanceId(),
+									iController.Services().agendaInterface());
 
-	// Check if the date is within the range.
-	if(selectedDate.isValid()) {
-		QTime time(0,0,0,0);
-		QDateTime dateTime;
-		dateTime.setDate(selectedDate);
-		dateTime.setTime(time);
-		// Do delete only if inputted day is after beginning of range
-		if(dateTime > AgendaUtil::minTime()) {
-			// Two pass delete:
-			// 1. pass
-			// To prevent destroying entries starting and ending midnight
-			// subtract one second and do delete on that range.
-			dateTime = dateTime.addSecs(-1);
-			dateTime = ( dateTime > AgendaUtil::minTime()? dateTime :  AgendaUtil::minTime());
-
-			HandleDeleteMultipleEventsL( AgendaUtil::minTime(), dateTime,1 );
-		}else {
-			iController.BroadcastNotification(ECalenNotifyDeleteFailed);
+	if (!instance.isNull()) {
+		connect(iController.Services().agendaInterface(), 
+									SIGNAL(entryDeleted(ulong)),
+									this, SLOT(entryDeleted(ulong)));
+		switch(index) {
+			case 0:
+				// User wants to delete only this occurence
+				iController.Services().agendaInterface()->deleteRepeatedEntry(
+									instance, AgendaUtil::ThisOnly);
+				break;
+			case 1:
+				// User wants to delete all the occurences
+				iController.Services().agendaInterface()->deleteRepeatedEntry(
+									instance, AgendaUtil::ThisAndAll);
+				break;
 		}
 	}
 }
 
-void CalenDeleteUi::handleRepeatedEntryDelete(int index)
-{
-    // Fetch the entry
-    // Find all possible instances
-    AgendaEntry instance = CalenActionUiUtils::findPossibleInstanceL(
-                                iController.context().instanceId(),
-                                iController.Services().agendaInterface());
-
-    if (!instance.isNull()) {
-        connect(iController.Services().agendaInterface(), SIGNAL(entryDeleted(ulong)),
-                this, SLOT(entryDeleted(ulong)));
-        switch(index) {
-            case 0:
-                // User wants to delete only this occurence
-                iController.Services().agendaInterface()->deleteRepeatedEntry(instance, AgendaUtil::ThisOnly);
-                break;
-            case 1:
-                // User wants to delete all the occurences
-                iController.Services().agendaInterface()->deleteRepeatedEntry(instance, AgendaUtil::ThisAndAll);
-                break;
-        }
-    }
-}
-
 // ----------------------------------------------------------------------------
 // CalenDeleteUi::showDeleteQuery
 // Launches the popup for deleting the instance/instances
@@ -533,8 +532,7 @@
         {
         case EDeleteEntry:
             {
-            // TODO: Add the text id
-            text.append("Delete entry?");
+            text.append(hbTrId("txt_calendar_info_delete_meeting"));
             break;
             }
         case EDeleteToDo:
@@ -564,9 +562,11 @@
         {
         popup->removeAction(list[i]);
         }
-    popup->addAction(new HbAction(hbTrId("txt_calendar_button_delete"), popup));
-    popup->addAction(new HbAction(
-    		hbTrId("txt_calendar_button_cancel"), popup));
+    mDeleteAction = new HbAction(
+						hbTrId("txt_calendar_button_dialog_delete"), popup);
+    popup->addAction(mDeleteAction);
+    mCancelAction = new HbAction(hbTrId("txt_calendar_button_cancel"), popup);
+    popup->addAction(mCancelAction);
     popup->open(this, SLOT(handleDeletion(HbAction*)));
     }
 
@@ -580,19 +580,19 @@
 {
 	TCalenNotification notification = ECalenNotifyDeleteFailed;
 	
-	if(action->text() == hbTrId("txt_calendar_button_delete")) {
+	if(action == mDeleteAction) {
 		
 		switch (mDeleteCommand) {
 			
 			case ECalenDeleteCurrentEntry:
 			{
-				// Get the entry
-				AgendaEntry entry = 
-						iController.Services().agendaInterface()->fetchById(
-							iController.context().instanceId().mEntryLocalUid);
+				// Get the entry id
+				ulong id = iController.context().instanceId().mEntryLocalUid;
+				connect(iController.Services().agendaInterface(), 
+												SIGNAL(entryDeleted(ulong)),
+												this, SLOT(entryDeleted(ulong)));
 				// Delete the entry if the delete button is been pressed
-				iController.Services().agendaInterface()->deleteEntry(entry.id());
-				notification = ECalenNotifyEntryDeleted;
+				iController.Services().agendaInterface()->deleteEntry(id);
 			}
 				break;
 			
@@ -603,15 +603,18 @@
 						CalenActionUiUtils::findPossibleInstanceL(
 								iController.context().instanceId(),
 								iController.Services().agendaInterface() );
-				QDateTime recId = instance.recurrenceId().toUTC();
-				const bool child = recId.isNull();
-
-				if( !child || mRecurrenceRange == AgendaUtil::ThisOnly 
-						|| mRecurrenceRange == AgendaUtil::ThisAndAll) {
-					iController.Services().agendaInterface()->deleteRepeatedEntry( 
-							instance, mRecurrenceRange );
+				if(!instance.isNull()) {
+					QDateTime recId = instance.recurrenceId().toUTC();
+					const bool child = recId.isNull();
+					connect(iController.Services().agendaInterface(), 
+					        SIGNAL(entryDeleted(ulong)),
+					        this, SLOT(entryDeleted(ulong)));
+					if( !child || mRecurrenceRange == AgendaUtil::ThisOnly 
+							|| mRecurrenceRange == AgendaUtil::ThisAndAll) {
+						iController.Services().agendaInterface()->deleteRepeatedEntry( 
+								instance, mRecurrenceRange );
+					}
 				}
-				notification = ECalenNotifyEntryDeleted;
 			}
 				break;
 			
@@ -619,7 +622,6 @@
 			{
 				HandleDeleteMultipleEventsL( AgendaUtil::minTime(), 
 											AgendaUtil::maxTime(),1 );
-				notification = ECalenNotifyEntryDeleted;
 			}
 				break;
 			
@@ -632,6 +634,10 @@
 	// ECalenNotifyDeleteFailed as default.
 	// Notify the status
 	iController.BroadcastNotification(notification);
+	
+	// Reset the member variables
+	mDeleteAction = NULL;
+	mCancelAction = NULL;
 }
 
 void CalenDeleteUi::entryDeleted(ulong id)
@@ -654,9 +660,10 @@
                                                  int aConfNoteId )
     {
     TRACE_ENTRY_POINT;
-
     
-    ASSERT( !iIsDeleting );
+	if(iIsDeleting) {
+		return;
+	}
     iConfirmationNoteId = aConfNoteId;
     
     DeleteDayRangeL( aFirstDay, aLastDay );
@@ -754,7 +761,7 @@
         // for CCalEntry type.
 
         // First check that if _instance_ ends at midnight, but starts earlier
-        if( CalenAgendaUtils::endsAtStartOfDayL( entry, aMidnight ) )
+        if( CalenAgendaUtils::endsAtStartOfDay( entry, aMidnight ) )
             {
             // Second, check that _entry's_ endtime is exactly the midnight
             // This prevents us from destroying repeating entries, that has one
@@ -831,8 +838,7 @@
 
 	if( !aHasRepeatType && ( child || repeating ) && 
 			( aInstance.type() != AgendaEntry::TypeAnniversary ) ) {
-		//doDelete = CalenActionUiUtils::ShowRepeatTypeQueryL( aRepeatType,
-		//                                                 CalenActionUiUtils::EDelete );
+		showRepeatingEntryDeleteQuery();
 	}
 	else
 	{