calendarui/caleneditor/src/caleneditor_p.cpp
changeset 55 2c54b51f39c4
parent 51 0b38fc5b94c6
child 57 bb2d3e476f29
equal deleted inserted replaced
51:0b38fc5b94c6 55:2c54b51f39c4
    65 #include "OstTraceDefinitions.h"
    65 #include "OstTraceDefinitions.h"
    66 #ifdef OST_TRACE_COMPILER_IN_USE
    66 #ifdef OST_TRACE_COMPILER_IN_USE
    67 #include "caleneditor_pTraces.h"
    67 #include "caleneditor_pTraces.h"
    68 #endif
    68 #endif
    69 
    69 
       
    70 // Constants
       
    71 const int SecsInOneYear( 3600 );
       
    72 
    70 
    73 
    71 /*!
    74 /*!
    72 	\class CalenEditorPrivate
    75 	\class CalenEditorPrivate
    73 	This object loads the calendar editor view. The view is added to the top
    76 	This object loads the calendar editor view. The view is added to the top
    74 	of the HbMainWindow.
    77 	of the HbMainWindow.
   195 	\param parent HbView pointer.
   198 	\param parent HbView pointer.
   196  */
   199  */
   197 CalenEditorPrivate::CalenEditorPrivate(AgendaUtil *agendaUtil, 
   200 CalenEditorPrivate::CalenEditorPrivate(AgendaUtil *agendaUtil, 
   198                                        QObject *parent) :
   201                                        QObject *parent) :
   199 									QObject(parent),
   202 									QObject(parent),
   200 									mAgendaUtil(NULL),
   203 									mEditorDocLoader(0),
   201 									mEditorDocLoader(NULL),
   204 									mEditorView(0),
   202 									mEditorView(NULL),
       
   203 									mDataHandler(NULL),
   205 									mDataHandler(NULL),
   204 									mCalenEditorForm(NULL),
   206 									mCalenEditorForm(0),
   205 									mCalenEditorModel(NULL),
   207 									mCalenEditorModel(0),
   206 									mSubjectItem(NULL),
   208 									mSubjectItem(0),
   207 									mViewFromItem(NULL),
   209 									mViewFromItem(0),
   208 									mViewToItem(NULL),
   210 									mViewToItem(0),
   209                                     mViewLocationItem(NULL),
   211                                     mViewLocationItem(0),
   210 									mAllDayCheckBoxItem(NULL),		                            
   212 									mAllDayCheckBoxItem(0),		                            
   211 									mReminderField(NULL),
   213 									mReminderField(0),
   212 									mRepeatField(NULL),
   214 									mRepeatField(0),
   213 									mDescriptionItem(NULL),
   215 									mDescriptionItem(0),
   214 									mEditRange(ThisAndAll),
   216 									mEditRange(ThisAndAll),
   215 									mOriginalEntry(NULL),
   217 									mOriginalEntry(NULL),
   216 									mEditedEntry(NULL),
   218 									mEditedEntry(NULL),
   217 									mTranslator(new HbTranslator("caleneditor")),
   219 									mTranslator(new HbTranslator("caleneditor")),
   218 									mNewEntry(true),
   220 									mNewEntry(true),
   223 									mMenuItemAdded(false)
   225 									mMenuItemAdded(false)
   224 {
   226 {
   225 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_CALENEDITORPRIVATE_ENTRY );
   227 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_CALENEDITORPRIVATE_ENTRY );
   226 	// First get the q-pointer.
   228 	// First get the q-pointer.
   227 	q_ptr = static_cast<CalenEditor *> (parent);
   229 	q_ptr = static_cast<CalenEditor *> (parent);
   228 	mMainWindow = NULL;
   230 	mMainWindow = 0;
   229 	mTranslator->loadCommon();
   231 	mTranslator->loadCommon();
   230 	
   232 	
   231 	if (!agendaUtil) {
   233 	if (!agendaUtil) {
   232 		mAgendaUtil = new AgendaUtil(this);
   234 		mAgendaUtil = new AgendaUtil(this);
   233 		mOwnsAgendaUtil = true;
   235 		mOwnsAgendaUtil = true;
   244 CalenEditorPrivate::~CalenEditorPrivate()
   246 CalenEditorPrivate::~CalenEditorPrivate()
   245 {
   247 {
   246 	OstTraceFunctionEntry0( DUP1_CALENEDITORPRIVATE_CALENEDITORPRIVATE_ENTRY );
   248 	OstTraceFunctionEntry0( DUP1_CALENEDITORPRIVATE_CALENEDITORPRIVATE_ENTRY );
   247 	if(mOwnsAgendaUtil) {
   249 	if(mOwnsAgendaUtil) {
   248 		delete mAgendaUtil;
   250 		delete mAgendaUtil;
   249 		mAgendaUtil = NULL;
   251 		mAgendaUtil = 0;
   250 	}
   252 	}
   251 	if (mOriginalEntry) {
   253 	if (mOriginalEntry) {
   252 		delete mOriginalEntry;
   254 		delete mOriginalEntry;
   253 		mOriginalEntry = NULL;
   255 		mOriginalEntry = NULL;
   254 	}
   256 	}
   256 		delete mEditedEntry;
   258 		delete mEditedEntry;
   257 		mEditedEntry = NULL;
   259 		mEditedEntry = NULL;
   258 	}
   260 	}
   259 	if(mEditorDocLoader) {
   261 	if(mEditorDocLoader) {
   260 		delete mEditorDocLoader;
   262 		delete mEditorDocLoader;
   261 		mEditorDocLoader = NULL;
   263 		mEditorDocLoader = 0;
   262 	}
   264 	}
   263 	if(mReminderField) {
   265 	if(mReminderField) {
   264 		delete mReminderField;
   266 		delete mReminderField;
   265 		mReminderField = NULL;
   267 		mReminderField = 0;
   266 	}
   268 	}
   267 	if(mRepeatField) {
   269 	if(mRepeatField) {
   268 		delete mRepeatField;
   270 		delete mRepeatField;
   269 		mRepeatField = NULL;
   271 		mRepeatField = 0;
   270 	}
   272 	}
   271 	if(mDataHandler) {
   273 	if(mDataHandler) {
   272 		delete mDataHandler;
   274 		delete mDataHandler;
   273 		mDataHandler = NULL;
   275 		mDataHandler = 0;
   274 	}
   276 	}
   275 	if (mCalenEditorModel) {
   277 	if (mCalenEditorModel) {
   276 		delete mCalenEditorModel;
   278 		delete mCalenEditorModel;
   277 		mCalenEditorModel = NULL;
   279 		mCalenEditorModel = 0;
   278 	}
   280 	}
   279 	// Remove the translator
   281 	// Remove the translator
   280 	if (mTranslator) {
   282 	if (mTranslator) {
   281 		delete mTranslator;
   283 		delete mTranslator;
   282 		mTranslator = 0;
   284 		mTranslator = 0;
   283 	}
   285 	}
   284 	
   286 	
   285 	// delete the mainwindow object if created any
   287 	// delete the mainwindow object if created any
   286 	if (mMainWindow) {
   288 	if (mMainWindow) {
   287 		delete mMainWindow;
   289 		delete mMainWindow;
   288 		mMainWindow = NULL;
   290 		mMainWindow = 0;
   289 	}
   291 	}
   290 	OstTraceFunctionExit0( DUP1_CALENEDITORPRIVATE_CALENEDITORPRIVATE_EXIT );
   292 	OstTraceFunctionExit0( DUP1_CALENEDITORPRIVATE_CALENEDITORPRIVATE_EXIT );
   291 }
   293 }
   292 
   294 
   293 /*!
   295 /*!
   419 	popUp->setContentWidget(editWidget);
   421 	popUp->setContentWidget(editWidget);
   420 	popUp->setHeadingWidget(new HbLabel(hbTrId("txt_calendar_title_edit")));
   422 	popUp->setHeadingWidget(new HbLabel(hbTrId("txt_calendar_title_edit")));
   421 
   423 
   422 	// Create cancel action
   424 	// Create cancel action
   423 	HbAction *cancelAction =
   425 	HbAction *cancelAction =
   424 	        new HbAction(hbTrId("txt_calendar_button_softkey1_cancel"));
   426 	        new HbAction(hbTrId("txt_common_button_cancel_singledialog"));
   425 	popUp->addAction(cancelAction);
   427 	popUp->addAction(cancelAction);
   426 	connect(editButtonList, SIGNAL(itemSelected(int)), popUp, SLOT(close()));
   428 	connect(editButtonList, SIGNAL(itemSelected(int)), popUp, SLOT(close()));
   427 	connect(editButtonList, SIGNAL(itemSelected(int)), this,
   429 	connect(editButtonList, SIGNAL(itemSelected(int)), this,
   428 	        SLOT(handleEditOccurence(int)));
   430 	        SLOT(handleEditOccurence(int)));
   429 	connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleCancel()));
   431 	connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleCancel()));
   577 	if (!mNewEntry) {
   579 	if (!mNewEntry) {
   578 		AgendaEntry::Type entryType = mEditedEntry->type();
   580 		AgendaEntry::Type entryType = mEditedEntry->type();
   579 		if( entryType == AgendaEntry::TypeAppoinment) {
   581 		if( entryType == AgendaEntry::TypeAppoinment) {
   580 			headingWidget->setHeading(hbTrId("txt_calendar_subhead_meeting"));
   582 			headingWidget->setHeading(hbTrId("txt_calendar_subhead_meeting"));
   581 		}else if(entryType == AgendaEntry::TypeEvent) {
   583 		}else if(entryType == AgendaEntry::TypeEvent) {
   582 			//TODO: Add the text id once available
   584 			headingWidget->setHeading(hbTrId("txt_calendar_subhead_all_day_event"));
   583 			headingWidget->setHeading(hbTrId("All-day event"));
       
   584 		}else if (entryType == AgendaEntry::TypeTodo) {
   585 		}else if (entryType == AgendaEntry::TypeTodo) {
   585 			headingWidget->setHeading(hbTrId("txt_calendar_subhead_to_do"));
   586 			headingWidget->setHeading(hbTrId("txt_calendar_subhead_to_do"));
   586 		}
   587 		}
   587 		
   588 		
   588 	}
   589 	}
   773 void CalenEditorPrivate::handleDescriptionAction()
   774 void CalenEditorPrivate::handleDescriptionAction()
   774 {
   775 {
   775 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_HANDLEDESCRIPTIONACTION_ENTRY );
   776 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_HANDLEDESCRIPTIONACTION_ENTRY );
   776 	if (!mDescriptionItemAdded) {
   777 	if (!mDescriptionItemAdded) {
   777 		populateDescriptionItem();
   778 		populateDescriptionItem();
       
   779 		//Scroll to the description item added
       
   780 		mCalenEditorForm->scrollTo(mCalenEditorModel->indexFromItem(mDescriptionItem), HbAbstractItemView::EnsureVisible);
   778 		mDescriptionAction->setText(
   781 		mDescriptionAction->setText(
   779 							hbTrId("txt_calendar_opt_remove_description"));
   782 							hbTrId("txt_calendar_opt_remove_description"));
   780 	} else {
   783 	} else {
   781 		removeDescriptionItem();
   784 		removeDescriptionItem();
   782 		mDescriptionAction->setText(
   785 		mDescriptionAction->setText(
   847 
   850 
   848 	OstTraceFunctionExit0( CALENEDITORPRIVATE_POPULATEALLDAYITEM_EXIT );
   851 	OstTraceFunctionExit0( CALENEDITORPRIVATE_POPULATEALLDAYITEM_EXIT );
   849 }
   852 }
   850 
   853 
   851 /*!
   854 /*!
       
   855 	Calculates default time when Event is on same day.
       
   856  */
       
   857 QTime CalenEditorPrivate::defaultTimeSameDay()
       
   858 {
       
   859 	QTime currentTime = QTime::currentTime();
       
   860 	
       
   861 	//Start time should be one hour more than current time.
       
   862 	currentTime = currentTime.addSecs(SecsInOneYear);
       
   863 
       
   864 	int hour = currentTime.hour();
       
   865 	int minutes = currentTime.minute();
       
   866 	bool addHour = 0;
       
   867 
       
   868 	//If the current time is within 15 mins after adding one hour, minutes will be rounded off to 0.
       
   869 	// Like if current time is 7:14 am, plus one hour is 8:14 am and it will be rounded off to 8:00am
       
   870 	//For time between 15 and 45 mins, its rounded off to 30 mins 
       
   871 	//and anything more than that we round it to the next hour.
       
   872 	if (minutes >= 0 && minutes <= 15) {
       
   873 		minutes = 0;
       
   874 	} else if (minutes > 15 && minutes <= 45) { 
       
   875 		minutes = 30;
       
   876 	}else {
       
   877 		minutes = 0;
       
   878 		addHour = 1;
       
   879 	}
       
   880 	currentTime.setHMS(hour, minutes, 0, 0);
       
   881 	if (addHour) {
       
   882 		currentTime = currentTime.addSecs(SecsInOneYear);
       
   883 	}
       
   884 	return currentTime;
       
   885 }
       
   886 
       
   887 /*!
       
   888 	Sets to default time, when AllDay is unchecked
       
   889  */
       
   890 void CalenEditorPrivate::refreshTimeForUncheckAllDay()
       
   891 {
       
   892 	//Get the default time as 8:00 am from CalenDateUtils.
       
   893 	QDateTime fromDateTime = CalenDateUtils::defaultTime(mEditedEntry->startTime());
       
   894 	QDateTime toDateTime;
       
   895 	
       
   896 	// The default time will be 8.00 am only if its not on current day
       
   897 	// else the time is calculated accordingly
       
   898 	bool isSameDay = CalenDateUtils::isOnToday(fromDateTime);
       
   899 	if (isSameDay) {
       
   900 		fromDateTime.setDate(fromDateTime.date());
       
   901 		fromDateTime.setTime(defaultTimeSameDay());
       
   902 	}
       
   903 	mNewEntryDateTime = fromDateTime;
       
   904 	toDateTime = fromDateTime.addSecs(SecsInOneYear);
       
   905 
       
   906 	// Set the default start time to the event.
       
   907 	mEditedEntry->setStartAndEndTime(fromDateTime, toDateTime);
       
   908 }	
       
   909 
       
   910 /*!
   852 	Populates the start and end time of the event item.
   911 	Populates the start and end time of the event item.
   853  */
   912  */
   854 void CalenEditorPrivate::populateCustomItemDateTime()
   913 void CalenEditorPrivate::populateCustomItemDateTime()
   855 {
   914 {
   856 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_POPULATECUSTOMITEMDATETIME_ENTRY );
   915 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_POPULATECUSTOMITEMDATETIME_ENTRY );
   869 										 mCalenEditorForm->itemByIndex(index));
   928 										 mCalenEditorForm->itemByIndex(index));
   870 	connect(mViewFromItem, SIGNAL(dateTimeUpdated(QDateTime &)), this,
   929 	connect(mViewFromItem, SIGNAL(dateTimeUpdated(QDateTime &)), this,
   871 										SLOT(saveFromDateTime(QDateTime &)));
   930 										SLOT(saveFromDateTime(QDateTime &)));
   872 	// Pass the start time of the event according to new or existing event.
   931 	// Pass the start time of the event according to new or existing event.
   873 	QDateTime fromDateTime = mNewEntryDateTime;
   932 	QDateTime fromDateTime = mNewEntryDateTime;
   874 	QTime currentTime = QTime::currentTime();
       
   875 	if (!mNewEntry) {
   933 	if (!mNewEntry) {
   876 		// Check if we are going to create an exception here
   934 		// Check if we are going to create an exception here
   877 		if (mEditRange == ThisOnly) {
   935 		if (mEditRange == ThisOnly) {
   878 			// Update the end time of the instance properly as we would have got 
   936 			// Update the end time of the instance properly as we would have got 
   879 			// parent entry from the caller - this is acheived by adding the
   937 			// parent entry from the caller - this is acheived by adding the
   890 		}
   948 		}
   891 		fromDateTime = mEditedEntry->startTime();
   949 		fromDateTime = mEditedEntry->startTime();
   892 	} else {
   950 	} else {
   893 		// Check if it is on same day and set the default time and date accordingly.
   951 		// Check if it is on same day and set the default time and date accordingly.
   894 		bool isSameDay = CalenDateUtils::isOnToday(fromDateTime);
   952 		bool isSameDay = CalenDateUtils::isOnToday(fromDateTime);
   895 		int minutes = 0;
       
   896 		int hour = currentTime.hour();
       
   897 		if (isSameDay) {
   953 		if (isSameDay) {
   898 			minutes = currentTime.minute();
       
   899 			if (minutes > 0 && minutes < 31) {
       
   900 				minutes = 30;
       
   901 			} else {
       
   902 				minutes = 0;
       
   903 			}
       
   904 			currentTime.setHMS(hour, minutes, 0, 0);
       
   905 			if (minutes == 0) {
       
   906 				currentTime = currentTime.addSecs(60 * 60);
       
   907 			}
       
   908 			fromDateTime.setDate(fromDateTime.date());
   954 			fromDateTime.setDate(fromDateTime.date());
   909 			fromDateTime.setTime(currentTime);
   955 			fromDateTime.setTime(defaultTimeSameDay());
   910 		}
   956 		}
   911 	}
   957 	}
   912 	mViewFromItem->populateDateTime(fromDateTime, true);
   958 	mViewFromItem->populateDateTime(fromDateTime, true);
   913 	mNewEntryDateTime = fromDateTime;
   959 	mNewEntryDateTime = fromDateTime;
   914 
   960 
   974 				nextInstanceStartTime.date()) == 1)) {
  1020 				nextInstanceStartTime.date()) == 1)) {
   975 				mViewFromItem->disableFromToDateField();
  1021 				mViewFromItem->disableFromToDateField();
   976 			}
  1022 			}
   977 		}
  1023 		}
   978 	} else {
  1024 	} else {
   979 		toDateTime = fromDateTime.addSecs(60 * 60);
  1025 		toDateTime = fromDateTime.addSecs(SecsInOneYear);
   980 	}
  1026 	}
   981 	mViewToItem->populateDateTime(toDateTime, false);
  1027 	mViewToItem->populateDateTime(toDateTime, false);
   982 
  1028 
   983 	// Set the default start time to the event.
  1029 	// Set the default start time to the event.
   984 	mEditedEntry->setStartAndEndTime(fromDateTime, toDateTime);
  1030 	mEditedEntry->setStartAndEndTime(fromDateTime, toDateTime);
   991 		|| (!mNewEntry && mEditedEntry->type() == AgendaEntry::TypeEvent)) {
  1037 		|| (!mNewEntry && mEditedEntry->type() == AgendaEntry::TypeEvent)) {
   992         
  1038         
   993         // For all-day, we need to substratc 1 minute to get the actual end time
  1039         // For all-day, we need to substratc 1 minute to get the actual end time
   994         // as we store all-day as 12.00AM to 12.00 AM next day
  1040         // as we store all-day as 12.00AM to 12.00 AM next day
   995         QDateTime actualEndTime = mEditedEntry->endTime().addSecs(-60);
  1041         QDateTime actualEndTime = mEditedEntry->endTime().addSecs(-60);
       
  1042         // Set it back to mEditedEntry
       
  1043         mEditedEntry->setStartAndEndTime(mEditedEntry->startTime(), actualEndTime);
   996         mViewToItem->populateDateTime(actualEndTime, false);
  1044         mViewToItem->populateDateTime(actualEndTime, false);
   997         
  1045         
   998 		// If the all day option is checked, we need to
  1046 		// If the all day option is checked, we need to
   999 		// disable the time fields
  1047 		// disable the time fields
  1000 		enableFromTotimeFileds(false, mEditedEntry->startTime(),
  1048 		enableFromTotimeFileds(false, mEditedEntry->startTime(),
  1046 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_SAVEFROMDATETIME_ENTRY );
  1094 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_SAVEFROMDATETIME_ENTRY );
  1047 	QDateTime endTime = mEditedEntry->endTime();
  1095 	QDateTime endTime = mEditedEntry->endTime();
  1048 	// Update the end time accordingly on UI - duration will be 60 mins
  1096 	// Update the end time accordingly on UI - duration will be 60 mins
  1049 	// bydefault only while creating new entry and if it crossed the endtime
  1097 	// bydefault only while creating new entry and if it crossed the endtime
  1050 	if (mNewEntry && fromDateTime > endTime) {
  1098 	if (mNewEntry && fromDateTime > endTime) {
  1051 		endTime = fromDateTime.addSecs(3600);
  1099 		endTime = fromDateTime.addSecs(SecsInOneYear);
  1052 	} else { // for existing entry
  1100 	} else { // for existing entry
  1053 		// we need to see if user has moved start time beyond the end time
  1101 		// we need to see if user has moved start time beyond the end time
  1054 		// then add the duration of the meeting that was saved earlier to the 
  1102 		// then add the duration of the meeting that was saved earlier to the 
  1055 		// new start time to get the new end time
  1103 		// new start time to get the new end time
  1056 		if (fromDateTime > endTime) {
  1104 		if (fromDateTime > endTime) {
  1126 	QDateTime startTime = mEditedEntry->startTime();
  1174 	QDateTime startTime = mEditedEntry->startTime();
  1127 	bool fromDateChanged = false;
  1175 	bool fromDateChanged = false;
  1128 	// Update the start time accordingly on UI - duration will be 60 mins
  1176 	// Update the start time accordingly on UI - duration will be 60 mins
  1129 	// bydefault for new entry and if it crosses the starttime
  1177 	// bydefault for new entry and if it crosses the starttime
  1130 	if (mNewEntry && toDateTime < startTime) {
  1178 	if (mNewEntry && toDateTime < startTime) {
  1131 		startTime = toDateTime.addSecs(-3600);
  1179 		startTime = toDateTime.addSecs(-SecsInOneYear);
  1132 		fromDateChanged = true;
  1180 		fromDateChanged = true;
  1133 	} else { 
  1181 	} else { 
  1134 		// for exisitng entry
  1182 		// for exisitng entry
  1135 		// we need to see if user has moved end time before the start time
  1183 		// we need to see if user has moved end time before the start time
  1136 		// then substract the duration of the meeting that was saved earlier to 
  1184 		// then substract the duration of the meeting that was saved earlier to 
  1215 	mCalenEditorForm->addConnection(
  1263 	mCalenEditorForm->addConnection(
  1216 								mDescriptionItem,
  1264 								mDescriptionItem,
  1217 								SIGNAL(textChanged(const QString)), this,
  1265 								SIGNAL(textChanged(const QString)), this,
  1218 								SLOT(handleDescriptionChange(const QString)));
  1266 								SLOT(handleDescriptionChange(const QString)));
  1219 	mDescriptionItemAdded = true;
  1267 	mDescriptionItemAdded = true;
  1220     //Scroll to the description item added.
       
  1221 	mCalenEditorForm->scrollTo(mCalenEditorModel->index(descIndex, 0), HbAbstractItemView::EnsureVisible);
       
  1222 	OstTraceFunctionExit0( CALENEDITORPRIVATE_POPULATEDESCRIPTIONITEM_EXIT );
  1268 	OstTraceFunctionExit0( CALENEDITORPRIVATE_POPULATEDESCRIPTIONITEM_EXIT );
  1223 }
  1269 }
  1224 
  1270 
  1225 /*!
  1271 /*!
  1226 	Removes the description item.
  1272 	Removes the description item.
  1247 	}
  1293 	}
  1248 	mCalenEditorModel->removeItem(mCalenEditorModel->index(descIndex, 0));
  1294 	mCalenEditorModel->removeItem(mCalenEditorModel->index(descIndex, 0));
  1249 	// Remove the description from the entry
  1295 	// Remove the description from the entry
  1250 	mEditedEntry->setDescription("");
  1296 	mEditedEntry->setDescription("");
  1251 
  1297 
  1252 	mDescriptionItem = NULL;
  1298 	mDescriptionItem = 0;
  1253 	mDescriptionItemAdded = false;
  1299 	mDescriptionItemAdded = false;
  1254 	OstTraceFunctionExit0( CALENEDITORPRIVATE_REMOVEDESCRIPTIONITEM_EXIT );
  1300 	OstTraceFunctionExit0( CALENEDITORPRIVATE_REMOVEDESCRIPTIONITEM_EXIT );
  1255 }
  1301 }
  1256 
  1302 
  1257 
  1303 
  1299 		QTime tempEndQTime = tempEndTime.time();
  1345 		QTime tempEndQTime = tempEndTime.time();
  1300 		tempEndQTime.setHMS(23, 59, 59);
  1346 		tempEndQTime.setHMS(23, 59, 59);
  1301 		tempEndTime.setTime(tempEndQTime);
  1347 		tempEndTime.setTime(tempEndQTime);
  1302 
  1348 
  1303 		enableFromTotimeFileds(false, tempSartTime, tempEndTime);
  1349 		enableFromTotimeFileds(false, tempSartTime, tempEndTime);
       
  1350 		mEditedEntry->setStartAndEndTime(tempSartTime, tempEndTime);
       
  1351 		
  1304 		QDate referenceDate;
  1352 		QDate referenceDate;
  1305 		if (mRepeatField->isRepeatUntilItemAdded()) {
  1353 		if (mRepeatField->isRepeatUntilItemAdded()) {
  1306 			referenceDate = mRepeatField->repeatUntilDate();
  1354 			referenceDate = mRepeatField->repeatUntilDate();
  1307 		} else {
  1355 		} else {
  1308 			referenceDate = mEditedEntry->startTime().date();
  1356 			referenceDate = mEditedEntry->startTime().date();
  1318 			// Remove reminder time field.
  1366 			// Remove reminder time field.
  1319 			mReminderField->removeReminderTimeField();
  1367 			mReminderField->removeReminderTimeField();
  1320 		}
  1368 		}
  1321 	} else {
  1369 	} else {
  1322 		// AllDayCheckBox in un-checked
  1370 		// AllDayCheckBox in un-checked
       
  1371 		// then we need to refresh the Time to show default time
       
  1372 		refreshTimeForUncheckAllDay();
  1323 		// Set From/To times buttons editable
  1373 		// Set From/To times buttons editable
  1324 		// Update Start/End Times with Edited entry values
  1374 		// Update Start/End Times with Edited entry values
  1325 		enableFromTotimeFileds(true, mEditedEntry->startTime(),
  1375 		enableFromTotimeFileds(true, mEditedEntry->startTime(),
  1326 		                       mEditedEntry->endTime());
  1376 		                       mEditedEntry->endTime());
  1327 		// If original entry was an All-day, then we need to save the date that
       
  1328 		// is shown on the "To" date push button
       
  1329 		if (mOriginalEntry->type() == AgendaEntry::TypeEvent) {
       
  1330             mEditedEntry->setStartAndEndTime(mViewFromItem->getDateTime(),
       
  1331                                     mViewToItem->getDateTime());
       
  1332 		}
       
  1333 		int index;
       
  1334 		if (mIsAllDayItemAdded) {
       
  1335 			index = ReminderTimeForAllDayItem;
       
  1336 		} else {
       
  1337 			index = ReminderTimeForAllDayItem - 1;
       
  1338 		}
       
  1339 		mReminderField->removeReminderTimeField();
  1377 		mReminderField->removeReminderTimeField();
  1340 		mReminderField->setReminderChoices();
  1378 		mReminderField->setReminderChoices();
  1341 		updateReminderChoices();
  1379 		updateReminderChoices();
  1342 	}
  1380 	}
  1343 
  1381 
  1394            confirmationQuery->setDismissPolicy(HbDialog::NoDismiss);
  1432            confirmationQuery->setDismissPolicy(HbDialog::NoDismiss);
  1395            confirmationQuery->setTimeout(HbDialog::NoTimeout);
  1433            confirmationQuery->setTimeout(HbDialog::NoTimeout);
  1396            confirmationQuery->setIconVisible(true);  
  1434            confirmationQuery->setIconVisible(true);  
  1397            
  1435            
  1398            QString displayText;
  1436            QString displayText;
  1399            displayText = displayText.append("Location changed. Keep existing location on Map?");
  1437            displayText = displayText.append(hbTrId("txt_calendar_info_location_updated_keep_existing"));
  1400            
  1438            
  1401            confirmationQuery->setText(displayText);
  1439            confirmationQuery->setText(displayText);
  1402            
  1440            
  1403            // Remove the default actions.
  1441            // Remove the default actions.
  1404            QList<QAction *> defaultActions = confirmationQuery->actions();
  1442            QList<QAction *> defaultActions = confirmationQuery->actions();
  1406            {
  1444            {
  1407                confirmationQuery->removeAction(defaultActions[index]);
  1445                confirmationQuery->removeAction(defaultActions[index]);
  1408            }
  1446            }
  1409            
  1447            
  1410            defaultActions.clear();
  1448            defaultActions.clear();
  1411            
  1449            confirmationQuery->addAction(new HbAction(hbTrId("txt_common_button_yes")));
  1412            confirmationQuery->addAction(new HbAction("Yes"));
  1450            confirmationQuery->addAction(new HbAction(hbTrId("txt_common_button_no")));
  1413            confirmationQuery->addAction(new HbAction("No"));
       
  1414            confirmationQuery->open(this, SLOT(selectEditingFinishedAction(HbAction*)));
  1451            confirmationQuery->open(this, SLOT(selectEditingFinishedAction(HbAction*)));
  1415        }
  1452        }
  1416     }       
  1453     }       
  1417     OstTraceFunctionExit0( CALENEDITORPRIVATE_HANDLELOCATIONEDITINGFINISHED_EXIT );
  1454     OstTraceFunctionExit0( CALENEDITORPRIVATE_HANDLELOCATIONEDITINGFINISHED_EXIT );
  1418 }
  1455 }
  1557     QList<QAction*> list = popup->actions();
  1594     QList<QAction*> list = popup->actions();
  1558     for(int i=0; i < list.count(); i++)
  1595     for(int i=0; i < list.count(); i++)
  1559         {
  1596         {
  1560         popup->removeAction(list[i]);
  1597         popup->removeAction(list[i]);
  1561         }
  1598         }
  1562 	HbAction *deleteAction = new HbAction(hbTrId("txt_calendar_button_dialog_delete"),
  1599 	HbAction *deleteAction = new HbAction(hbTrId("txt_common_button_delete"),
  1563 										popup);
  1600 										popup);
  1564 	popup->addAction(deleteAction);
  1601 	popup->addAction(deleteAction);
  1565 	connect(deleteAction, SIGNAL(triggered()), this, 
  1602 	connect(deleteAction, SIGNAL(triggered()), this, 
  1566 										SLOT(handleDeleteAction()));
  1603 										SLOT(handleDeleteAction()));
  1567 	HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"), 
  1604 	HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"), 
  1602 {
  1639 {
  1603 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_HANDLEDONE_ENTRY );
  1640 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_HANDLEDONE_ENTRY );
  1604 	if (mEditRange == ThisAndAll) {
  1641 	if (mEditRange == ThisAndAll) {
  1605 		mRepeatField->saveRepeatRule();
  1642 		mRepeatField->saveRepeatRule();
  1606 	}
  1643 	}
       
  1644 	
       
  1645  	// Set back the all day endtime back 
       
  1646 	 if(mOriginalEntry->type() == AgendaEntry::TypeEvent) { 
       
  1647 		 // The time has to be set for the allday exceptional entries and 
       
  1648 		 // while editing all the instances of a repeating all day entry 
       
  1649 		 if(mEditRange == ThisOnly || 
       
  1650 		 	(mAllDayCheckBoxItem && 
       
  1651 		 	mAllDayCheckBoxItem->contentWidgetData("checkState") == Qt::Checked)) {
       
  1652  			// Set EndTime of AllDay event to 00:00:00 of next day
       
  1653 			QDateTime actualEndTime = mEditedEntry->endTime().addSecs(60);
       
  1654 			mEditedEntry->setStartAndEndTime(mEditedEntry->startTime(), actualEndTime);
       
  1655 		}
       
  1656 	}
       
  1657 	
  1607 	// TODO: Need to check entry status here. EntryStillExistsL
  1658 	// TODO: Need to check entry status here. EntryStillExistsL
  1608 	switch (mDataHandler->shouldSaveOrDeleteOrDoNothing(mLaunchCalendar)) {
  1659 	switch (mDataHandler->shouldSaveOrDeleteOrDoNothing(mLaunchCalendar)) {
  1609 		case CalenEditorPrivate::ActionSave:
  1660 		case CalenEditorPrivate::ActionSave:
  1610 			if (saveEntry()) {
  1661 			if (saveEntry()) {
  1611 				OstTraceFunctionExit0( CALENEDITORPRIVATE_HANDLEDONE_EXIT );
  1662 				OstTraceFunctionExit0( CALENEDITORPRIVATE_HANDLEDONE_EXIT );
  1631 	\return true if entry is saved ,false otherwise
  1682 	\return true if entry is saved ,false otherwise
  1632  */
  1683  */
  1633 bool CalenEditorPrivate::saveEntry()
  1684 bool CalenEditorPrivate::saveEntry()
  1634 {
  1685 {
  1635 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_SAVEENTRY_ENTRY );
  1686 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_SAVEENTRY_ENTRY );
  1636 	// check if we are editing child
  1687 
  1637 	if (mIsChild && (mEditRange == ThisOnly)) {
  1688 	if (!handleAllDayToSave()) {
  1638 		// Add the entry
  1689 		// creating an exceptional entry
  1639 		mAgendaUtil->updateEntry(*mEditedEntry, true);
  1690 		if (!mIsChild && (mEditRange == ThisOnly)) {
  1640 		// TODO: Add the text id once available
  1691 			mAgendaUtil->store(*mEditedEntry, AgendaUtil::ThisOnly);
       
  1692 		} else {
       
  1693 			mAgendaUtil->store(*mEditedEntry);
       
  1694 		}
       
  1695 	}
       
  1696 	if (mNewEntry) {
  1641 		if(mEditedEntry->type() == AgendaEntry::TypeAppoinment) {
  1697 		if(mEditedEntry->type() == AgendaEntry::TypeAppoinment) {
  1642 			HbNotificationDialog::launchDialog(hbTrId("Meeting updated"));
  1698 			HbNotificationDialog::launchDialog(hbTrId("txt_calendar_dpopinfo_new_meeting_saved"));
  1643 		}else if(mEditedEntry->type() == AgendaEntry::TypeEvent) {
  1699 		} else if(mEditedEntry->type() == AgendaEntry::TypeEvent) {
  1644 			HbNotificationDialog::launchDialog(hbTrId("All day event updated"));
  1700 			HbNotificationDialog::launchDialog(hbTrId("txt_calendar_dpopinfo_new_all_day_event_saved"));
  1645 		}
  1701 		}
  1646 		emit q_ptr->entrySaved();
  1702 	} else {
  1647 		OstTraceFunctionExit0( CALENEDITORPRIVATE_SAVEENTRY_EXIT );
  1703 		if(mEditedEntry->type() == AgendaEntry::TypeAppoinment) {
  1648 		return true;
  1704 			HbNotificationDialog::launchDialog(hbTrId("txt_calendar_dpopinfo_meeting_updated"));
  1649 	} else if ((mEditRange == ThisOnly)) {
  1705 		} else if(mEditedEntry->type() == AgendaEntry::TypeEvent) {
  1650 		// If we are editing only this occurence, then 
  1706 			HbNotificationDialog::launchDialog(hbTrId("txt_calendar_dpopinfo_all_day_event_updated"));
  1651 		// clear the repeating properties of it
  1707 		}
  1652 		mAgendaUtil->clearRepeatingProperties(*mEditedEntry);
  1708 	}
  1653 	}
  1709 	emit q_ptr->entrySaved();
  1654 
       
  1655 	CalenEditorPrivate::Error error = CalenEditorPrivate::CalenEditorErrorNone;
       
  1656 	error = mDataHandler->checkErrorsForThisAndAll();
       
  1657 	if (CalenEditorPrivate::CalenEditorErrorNone == error) {
       
  1658 		if (!handleAllDayToSave()) {
       
  1659 			if (mNewEntry) {
       
  1660 				mAgendaUtil->addEntry(*mEditedEntry);
       
  1661 			} else if (mEditRange == ThisAndAll && mOriginalEntry->isRepeating()) {
       
  1662 				mAgendaUtil->storeRepeatingEntry(*mEditedEntry, true);
       
  1663 			} else if (!mIsChild && (mEditRange == ThisOnly)) {
       
  1664 				// Create the new exception
       
  1665 				mAgendaUtil->createException(*mEditedEntry, 
       
  1666 												mOriginalEntry->startTime());
       
  1667 			} else {
       
  1668 				// Normal entry updation
       
  1669 				mAgendaUtil->updateEntry(*mEditedEntry, false);
       
  1670 			}
       
  1671 		}
       
  1672 		if (mNewEntry) {
       
  1673 			// TODO: Add the text id once available
       
  1674 			if(mEditedEntry->type() == AgendaEntry::TypeAppoinment) {
       
  1675 				HbNotificationDialog::launchDialog(hbTrId("New meeting saved"));
       
  1676 			} else if(mEditedEntry->type() == AgendaEntry::TypeEvent) {
       
  1677 				HbNotificationDialog::launchDialog(hbTrId("New all-day saved"));
       
  1678 			}
       
  1679 		} else {
       
  1680 			// TODO: Add the text id once available
       
  1681 			if(mEditedEntry->type() == AgendaEntry::TypeAppoinment) {
       
  1682 				HbNotificationDialog::launchDialog(hbTrId("Meeting updated"));
       
  1683 			} else if(mEditedEntry->type() == AgendaEntry::TypeEvent) {
       
  1684 				HbNotificationDialog::launchDialog(hbTrId("All day event updated"));
       
  1685 			}
       
  1686 		}
       
  1687 		emit q_ptr->entrySaved();
       
  1688 	} else if (error) {
       
  1689 		mDataHandler->displayErrorMsg(error);
       
  1690 		OstTraceFunctionExit0( DUP1_CALENEDITORPRIVATE_SAVEENTRY_EXIT );
       
  1691 		return false;
       
  1692 	}
       
  1693 	OstTraceFunctionExit0( DUP2_CALENEDITORPRIVATE_SAVEENTRY_EXIT );
  1710 	OstTraceFunctionExit0( DUP2_CALENEDITORPRIVATE_SAVEENTRY_EXIT );
  1694 	return true;
  1711 	return true;
  1695 
  1712 
  1696 }
  1713 }
  1697 
  1714 
  1726 /*!
  1743 /*!
  1727  Change the entry before saving, depending on AllDay checkbox state
  1744  Change the entry before saving, depending on AllDay checkbox state
  1728  */
  1745  */
  1729 bool CalenEditorPrivate::handleAllDayToSave()
  1746 bool CalenEditorPrivate::handleAllDayToSave()
  1730 {
  1747 {
  1731 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_HANDLEALLDAYTOSAVE_ENTRY );
  1748     OstTraceFunctionEntry0( CALENEDITORPRIVATE_HANDLEALLDAYTOSAVE_ENTRY );
  1732 	if (!mIsAllDayItemAdded) {
  1749 
  1733 		// All day item was not added, return true
  1750     QDateTime tempSartTime =
       
  1751             CalenDateUtils::beginningOfDay(mEditedEntry->startTime());
       
  1752 
       
  1753     // Set EndTime of AllDay event to 00:00:00 of next day
       
  1754     QDateTime tempEndTime = mEditedEntry->endTime().addDays(1);
       
  1755     QTime tempEndQTime = tempEndTime.time();
       
  1756     tempEndQTime.setHMS(0, 0, 0);
       
  1757     tempEndTime.setTime(tempEndQTime);
       
  1758 	
       
  1759     // Check the state of AllDay checkBox and 
       
  1760     // Check whether allday event is exceptional or not.
       
  1761 	if (!mIsAllDayItemAdded && (mOriginalEntry->type() == AgendaEntry::TypeEvent)) {
       
  1762 		
       
  1763 	    // All day item was not added, return false
       
  1764 	    mEditedEntry->setStartAndEndTime(tempSartTime, tempEndTime);
  1734 		OstTraceFunctionExit0( CALENEDITORPRIVATE_HANDLEALLDAYTOSAVE_EXIT );
  1765 		OstTraceFunctionExit0( CALENEDITORPRIVATE_HANDLEALLDAYTOSAVE_EXIT );
  1735 		return false;
  1766 		return false;
  1736 	}
  1767 	}
  1737 	// Check the state of AllDay checkBox
       
  1738 
  1768 
  1739 	// If Creating new Entry and AllDay Box is checked.
  1769 	// If Creating new Entry and AllDay Box is checked.
  1740 	// Clone the entry to AllDay 
  1770 	// Clone the entry to AllDay 
  1741 
       
  1742 	QDateTime tempSartTime =
       
  1743 	        CalenDateUtils::beginningOfDay(mEditedEntry->startTime());
       
  1744 
       
  1745 	// Set EndTime of AllDay event to 00:00:00 of next day
       
  1746 	QDateTime tempEndTime = mEditedEntry->endTime().addDays(1);
       
  1747 	QTime tempEndQTime = tempEndTime.time();
       
  1748 	tempEndQTime.setHMS(0, 0, 0);
       
  1749 	tempEndTime.setTime(tempEndQTime);
       
  1750 
       
  1751 	if (mNewEntry && (mAllDayCheckBoxItem->contentWidgetData("checkState")
  1771 	if (mNewEntry && (mAllDayCheckBoxItem->contentWidgetData("checkState")
  1752 	        == Qt::Checked)) {
  1772 	        == Qt::Checked)) {
  1753 		// changes Start/End times of entry to Beginning ot the day
  1773 		// changes Start/End times of entry to Beginning ot the day
  1754 		mEditedEntry->setStartAndEndTime(tempSartTime, tempEndTime);
  1774 		mEditedEntry->setStartAndEndTime(tempSartTime, tempEndTime);
  1755 		mEditedEntry->setType(AgendaEntry::TypeEvent);
  1775 		mEditedEntry->setType(AgendaEntry::TypeEvent);
  1943 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_ISALLDAYFIELDADDED_ENTRY );
  1963 	OstTraceFunctionEntry0( CALENEDITORPRIVATE_ISALLDAYFIELDADDED_ENTRY );
  1944 	OstTraceFunctionExit0( CALENEDITORPRIVATE_ISALLDAYFIELDADDED_EXIT );
  1964 	OstTraceFunctionExit0( CALENEDITORPRIVATE_ISALLDAYFIELDADDED_EXIT );
  1945 	return mIsAllDayItemAdded;
  1965 	return mIsAllDayItemAdded;
  1946 }
  1966 }
  1947 
  1967 
       
  1968 /*!
       
  1969     save the entry from other views.
       
  1970  */
       
  1971 void CalenEditorPrivate::forcedSaveEntry()
       
  1972 {
       
  1973     saveAndCloseEditor();   
       
  1974 }
  1948 // End of file	--Don't remove this.
  1975 // End of file	--Don't remove this.