calendarui/caleneditor/src/caleneditor_p.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 51 0b38fc5b94c6
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <QObject>
    19 #include <QObject>
    20 #include <QTimer>
    20 #include <QTimer>
    21 #include <QGraphicsLinearLayout>
    21 #include <QGraphicsLinearLayout>
    22 #include <qtranslator.h>
    22 #include <QApplication>
    23 #include <qapplication.h>
    23 
    24 #include <hbdataform.h>
    24 #include <hbdataform.h>
    25 #include <hbmainwindow.h>
    25 #include <hbmainwindow.h>
    26 #include <hbinstance.h>
    26 #include <hbinstance.h>
    27 #include <hbdataformmodel.h>
    27 #include <hbdataformmodel.h>
    28 #include <hbdataformmodelitem.h>
    28 #include <hbdataformmodelitem.h>
    39 #include <hblabel.h>
    39 #include <hblabel.h>
    40 #include <hbview.h>
    40 #include <hbview.h>
    41 #include <hbextendedlocale.h>
    41 #include <hbextendedlocale.h>
    42 #include <hbi18ndef.h>
    42 #include <hbi18ndef.h>
    43 #include <qdatetime.h>
    43 #include <qdatetime.h>
    44 #include <HbMessageBox>
       
    45 #include <hbgroupbox.h>
    44 #include <hbgroupbox.h>
    46 #include <hbapplication.h>
       
    47 #include <hbradiobuttonlist.h>
    45 #include <hbradiobuttonlist.h>
    48 #include <hbnotificationdialog.h>
    46 #include <hbnotificationdialog.h>
       
    47 #include <hbtranslator.h>
    49 
    48 
    50 // User includes
    49 // User includes
    51 #include <CalenLauncher>
    50 #include <CalenLauncher>
    52 #include <agendaentry.h>
    51 #include <agendaentry.h>
    53 #include <agendautil.h>
    52 #include <agendautil.h>
   208 									mRepeatField(NULL),
   207 									mRepeatField(NULL),
   209 									mDescriptionItem(NULL),
   208 									mDescriptionItem(NULL),
   210 									mEditRange(ThisAndAll),
   209 									mEditRange(ThisAndAll),
   211 									mOriginalEntry(NULL),
   210 									mOriginalEntry(NULL),
   212 									mEditedEntry(NULL),
   211 									mEditedEntry(NULL),
       
   212 									mTranslator(new HbTranslator("caleneditor")),
   213 									mNewEntry(true),
   213 									mNewEntry(true),
   214 									mDescriptionItemAdded(false),
   214 									mDescriptionItemAdded(false),
   215 									mIsChild(false),
   215 									mIsChild(false),
   216 									mIsAllDayItemAdded(false),
   216 									mIsAllDayItemAdded(false),
   217 									mLaunchCalendar(false),
   217 									mLaunchCalendar(false),
   218 									mMenuItemAdded(false)
   218 									mMenuItemAdded(false)
   219 {
   219 {
   220 	// First get the q-pointer.
   220 	// First get the q-pointer.
   221 	q_ptr = static_cast<CalenEditor *> (parent);
   221 	q_ptr = static_cast<CalenEditor *> (parent);
   222 	mMainWindow = NULL;
   222 	mMainWindow = NULL;
       
   223 	mTranslator->loadCommon();
   223 	
   224 	
   224 	if (!agendaUtil) {
   225 	if (!agendaUtil) {
   225 		mAgendaUtil = new AgendaUtil(this);
   226 		mAgendaUtil = new AgendaUtil(this);
   226 		mOwnsAgendaUtil = true;
   227 		mOwnsAgendaUtil = true;
   227 	} else {
   228 	} else {
   228 		mAgendaUtil = agendaUtil;
   229 		mAgendaUtil = agendaUtil;
   229 		mOwnsAgendaUtil = false;
   230 		mOwnsAgendaUtil = false;
   230 	}
   231 	}
   231 
       
   232 	// Load the translation file and install the editor specific translator
       
   233 	mTranslator = new QTranslator;
       
   234 	QString lang = QLocale::system().name();
       
   235 	QString path = "Z:/resource/qt/translations/";
       
   236 	mTranslator->load("caleneditor_en_GB", ":/translations");
       
   237 	// TODO: Load the appropriate .qm file based on locale
       
   238 	//bool loaded = mTranslator->load("caleneditor_" + lang, path);
       
   239 	HbApplication::instance()->installTranslator(mTranslator);
       
   240 }
   232 }
   241 
   233 
   242 /*!
   234 /*!
   243 	Destructor.
   235 	Destructor.
   244  */
   236  */
   245 CalenEditorPrivate::~CalenEditorPrivate()
   237 CalenEditorPrivate::~CalenEditorPrivate()
   246 {
   238 {
       
   239 	if(mOwnsAgendaUtil) {
       
   240 		delete mAgendaUtil;
       
   241 		mAgendaUtil = NULL;
       
   242 	}
   247 	if (mOriginalEntry) {
   243 	if (mOriginalEntry) {
   248 		delete mOriginalEntry;
   244 		delete mOriginalEntry;
   249 		mOriginalEntry = NULL;
   245 		mOriginalEntry = NULL;
   250 	}
   246 	}
   251 	if (mEditedEntry) {
   247 	if (mEditedEntry) {
   252 		delete mEditedEntry;
   248 		delete mEditedEntry;
   253 		mEditedEntry = NULL;
   249 		mEditedEntry = NULL;
   254 	}
   250 	}
       
   251 	if(mEditorDocLoader) {
       
   252 		delete mEditorDocLoader;
       
   253 		mEditorDocLoader = NULL;
       
   254 	}
       
   255 	if(mReminderField) {
       
   256 		delete mReminderField;
       
   257 		mReminderField = NULL;
       
   258 	}
       
   259 	if(mRepeatField) {
       
   260 		delete mRepeatField;
       
   261 		mRepeatField = NULL;
       
   262 	}
       
   263 	if(mDataHandler) {
       
   264 		delete mDataHandler;
       
   265 		mDataHandler = NULL;
       
   266 	}
   255 	if (mCalenEditorModel) {
   267 	if (mCalenEditorModel) {
   256 		delete mCalenEditorModel;
   268 		delete mCalenEditorModel;
   257 		mCalenEditorModel = NULL;
   269 		mCalenEditorModel = NULL;
   258 	}
   270 	}
   259 	// Remove the translator
   271 	// Remove the translator
   260 	HbApplication::instance()->removeTranslator(mTranslator);
       
   261 	if (mTranslator) {
   272 	if (mTranslator) {
   262 		delete mTranslator;
   273 		delete mTranslator;
   263 		mTranslator = 0;
   274 		mTranslator = 0;
   264 	}
   275 	}
   265 	
   276 	
   288  */
   299  */
   289 void CalenEditorPrivate::edit(AgendaEntry entry, bool launchCalendar)
   300 void CalenEditorPrivate::edit(AgendaEntry entry, bool launchCalendar)
   290 {
   301 {
   291 	mNewEntry = false;
   302 	mNewEntry = false;
   292 	mLaunchCalendar = launchCalendar;
   303 	mLaunchCalendar = launchCalendar;
   293 	showEditor(entry);
   304 	openEditor(entry);
   294 }
   305 }
   295 
   306 
   296 /*!
   307 /*!
   297 	Shows the caleneditor, by using the entry id provided.
   308 	Shows the caleneditor, by using the entry id provided.
   298 	\param id entry id.
   309 	\param id entry id.
   299  */
   310  */
   300 void CalenEditorPrivate::edit(ulong id, bool launchCalendar)
   311 void CalenEditorPrivate::edit(ulong id, bool launchCalendar)
   301 {
   312 {
   302 	mNewEntry = false;
   313 	mNewEntry = false;
   303 	AgendaEntry entry = mAgendaUtil->fetchById(id);
   314 	AgendaEntry entry = mAgendaUtil->fetchById(id);
       
   315 	if(entry.isNull()) {
       
   316 		return;
       
   317 	}
   304 	edit(entry, launchCalendar);
   318 	edit(entry, launchCalendar);
   305 }
   319 }
   306 
   320 
   307 /*!
   321 /*!
   308 	Creates a new entry based on the create type.It launches the
   322 	Creates a new entry based on the create type.It launches the
   319 	switch(type){
   333 	switch(type){
   320 		case CalenEditor::TypeAppointment: {
   334 		case CalenEditor::TypeAppointment: {
   321 			entry.setType(AgendaEntry::TypeAppoinment);
   335 			entry.setType(AgendaEntry::TypeAppoinment);
   322 		}
   336 		}
   323 		break;
   337 		break;
   324 		case CalenEditor::TypeUnKnown:
       
   325 		default:
   338 		default:
       
   339 			// What ever be the type of entry, currently editor supports only to
       
   340 			// open the entries of TypeAppoinment
       
   341 			entry.setType(AgendaEntry::TypeAppoinment);
   326 			break;
   342 			break;
   327 	}
   343 	}
   328 	mLaunchCalendar = launchCalendar;
   344 	mLaunchCalendar = launchCalendar;
   329 	showEditor(entry);
   345 	openEditor(entry);
   330 }
   346 }
   331 
   347 
   332 /*!
   348 /*!
   333 	Creates a new entry based on the create type.It launches the
   349 	Creates a new entry based on the create type.It launches the
   334 	editor for editing
   350 	editor for editing
   342 	switch(type){
   358 	switch(type){
   343 		case CalenEditor::TypeAppointment: {
   359 		case CalenEditor::TypeAppointment: {
   344 			entry.setType(AgendaEntry::TypeAppoinment);
   360 			entry.setType(AgendaEntry::TypeAppoinment);
   345 		}
   361 		}
   346 		break;
   362 		break;
   347 		case CalenEditor::TypeUnKnown:
       
   348 		default:
   363 		default:
       
   364 			// What ever be the type of entry, currently editor supports only to
       
   365 			// open the entries of TypeAppoinment
       
   366 			entry.setType(AgendaEntry::TypeAppoinment);
   349 			break;
   367 			break;
   350 	}
   368 	}
   351 	mNewEntryDateTime = entry.startTime();
   369 	mNewEntryDateTime = entry.startTime();
   352 	mLaunchCalendar = launchCalendar;
   370 	mLaunchCalendar = launchCalendar;
   353 	showEditor(entry);
   371 	openEditor(entry);
   354 }
   372 }
   355 
   373 
   356 /*!
   374 /*!
   357 	Queries user whether to edit whole series or just this single occurence
   375 	Queries user whether to edit whole series or just this single occurence
   358  */
   376  */
   359 void CalenEditorPrivate::showEditOccurencePopup()
   377 void CalenEditorPrivate::showEditOccurencePopup()
   360 {
   378 {
   361 	HbDialog popUp;
   379 	HbDialog *popUp = new HbDialog();
   362 	popUp.setDismissPolicy(HbDialog::NoDismiss);
   380 	popUp->setDismissPolicy(HbDialog::NoDismiss);
   363 	popUp.setTimeout(HbDialog::NoTimeout);
   381 	popUp->setTimeout(HbDialog::NoTimeout);
   364 
   382 	popUp->setAttribute( Qt::WA_DeleteOnClose, true );
       
   383 	
   365 	QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
   384 	QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
   366 	HbWidget *editWidget = new HbWidget();
   385 	HbWidget *editWidget = new HbWidget();
   367 	editWidget->setLayout(layout);
   386 	editWidget->setLayout(layout);
   368 
   387 
   369 	HbRadioButtonList *editButtonList = new HbRadioButtonList();
   388 	HbRadioButtonList *editButtonList = new HbRadioButtonList();
   374 
   393 
   375 	editButtonList->setItems(list);
   394 	editButtonList->setItems(list);
   376 
   395 
   377 	layout->addItem(editButtonList);
   396 	layout->addItem(editButtonList);
   378 
   397 
   379 	popUp.setContentWidget(editWidget);
   398 	popUp->setContentWidget(editWidget);
   380 	popUp.setHeadingWidget(new HbLabel(hbTrId("txt_calendar_title_edit")));
   399 	popUp->setHeadingWidget(new HbLabel(hbTrId("txt_calendar_title_edit")));
   381 
   400 
   382 	// Create secondary action
   401 	// Create cancel action
   383 	HbAction *cancelAction =
   402 	HbAction *cancelAction =
   384 	        new HbAction(hbTrId("txt_calendar_button_softkey1_cancel"));
   403 	        new HbAction(hbTrId("txt_calendar_button_softkey1_cancel"));
   385 	popUp.setSecondaryAction(cancelAction);
   404 	popUp->addAction(cancelAction);
       
   405 	connect(editButtonList, SIGNAL(itemSelected(int)), popUp, SLOT(close()));
   386 	connect(editButtonList, SIGNAL(itemSelected(int)), this,
   406 	connect(editButtonList, SIGNAL(itemSelected(int)), this,
   387 	        SLOT(handleEditOccurence(int)));
   407 	        SLOT(handleEditOccurence(int)));
   388 	connect(editButtonList, SIGNAL(itemSelected(int)), &popUp, SLOT(close()));
       
   389 
       
   390 	connect(cancelAction, SIGNAL(triggered()), &popUp, SLOT(close()));
       
   391 	connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleCancel()));
   408 	connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleCancel()));
   392 
   409 
   393 	// Show the popup
   410 	// Show the popup
   394 	popUp.exec();
   411 	popUp->open();
   395 }
   412 }
   396 
   413 
   397 /*!
   414 /*!
   398 	Slot to handle User selection for series editing or single occurence popup
   415 	Slot to handle User selection for series editing or single occurence popup
   399  */
   416  */
   407 		case 1:
   424 		case 1:
   408 			// User wants to edit all the occurences
   425 			// User wants to edit all the occurences
   409 			mEditRange = ThisAndAll;
   426 			mEditRange = ThisAndAll;
   410 			break;
   427 			break;
   411 	}
   428 	}
       
   429 	// If user has selected to edit all the occurences, 
       
   430 	// then get the parent of it
       
   431 	AgendaEntry entryToBeEdited = mEntry;
       
   432 	if (mEditRange == ThisAndAll) {
       
   433 		entryToBeEdited = mAgendaUtil->parentEntry(mEntry);
       
   434 	}
       
   435 	showEditor(entryToBeEdited);
   412 }
   436 }
   413 
   437 
   414 /*!
   438 /*!
   415 	Slot to handle cancel action on the popup
   439 	Slot to handle cancel action on the popup
   416  */
   440  */
   417 void CalenEditorPrivate::handleCancel()
   441 void CalenEditorPrivate::handleCancel()
   418 {
   442 {
   419 	// User has chosen not to edit the event, hence return
   443 	// User has chosen not to edit the event, hence return
   420 	mEditRange = UserCancelled;
   444 	mEditRange = UserCancelled;
   421 }
   445 	// Do cleanup and return
   422 
   446 	emit q_ptr->dialogClosed();
   423 /*!
   447 	return;
   424 	Displays the editor.
   448 }
   425  */
   449 
   426 void CalenEditorPrivate::showEditor(AgendaEntry entry)
   450 /*!
   427 {
   451 	Opens the editor.
   428 	
   452  */
       
   453 void CalenEditorPrivate::openEditor(AgendaEntry entry)
       
   454 {
   429 	if (0 < entry.id()) {
   455 	if (0 < entry.id()) {
   430 		mNewEntry = false;
   456 		mNewEntry = false;
   431 	}
   457 	}
   432 
       
   433 	AgendaEntry entryToBeEdited = entry;
       
   434 	if (!mNewEntry) {
   458 	if (!mNewEntry) {
   435 		// Before we do anything, check in the entry is repeating
   459 		// Before we do anything, check in the entry is repeating
   436 		// OR its a child item
   460 		// OR its a child item
   437 		mIsChild = !(entry.recurrenceId().isNull());
   461 		mIsChild = !(entry.recurrenceId().isNull());
   438 		bool isRepeating = entry.isRepeating();
   462 		bool isRepeating = entry.isRepeating();
       
   463 		// For later reference
       
   464 		mEntry = entry;
   439 		if (mIsChild || isRepeating) {
   465 		if (mIsChild || isRepeating) {
   440 			// Query user if he wants to edit whole series 
   466 			// Query user if he wants to edit whole series 
   441 			// or just this occurence
   467 			// or just this occurence
   442 			showEditOccurencePopup();
   468 			showEditOccurencePopup();
   443 			// If user has selected to edit all the occurences, 
   469 			return;
   444 			// then get the parent of it
   470 		}else {
   445 			if (mEditRange == ThisAndAll) {
       
   446 				entryToBeEdited = mAgendaUtil->parentEntry(entry);
       
   447 			} else if (mEditRange == UserCancelled) {
       
   448 				// Do cleanup and return
       
   449 				emit q_ptr->dialogClosed();
       
   450 				return;
       
   451 			}
       
   452 		} else {
       
   453 			mEditRange = ThisAndAll;
   471 			mEditRange = ThisAndAll;
   454 		}
   472 		}
   455 	}
   473 	}
   456 
   474 	showEditor(entry);
   457 	mOriginalEntry = new AgendaEntry(entryToBeEdited);
   475 }
   458 	mEditedEntry = new AgendaEntry(entryToBeEdited);
   476 
       
   477 /*!
       
   478 	Displays the editor.
       
   479  */
       
   480 void CalenEditorPrivate::showEditor(AgendaEntry entry)
       
   481 {
       
   482 	mOriginalEntry = new AgendaEntry(entry);
       
   483 	mEditedEntry = new AgendaEntry(entry);
   459 
   484 
   460 	if (!mEditedEntry->description().isEmpty()) {
   485 	if (!mEditedEntry->description().isEmpty()) {
   461 		mDescriptionItemAdded = true;
   486 		mDescriptionItemAdded = true;
   462 	}
   487 	}
   463 	// Construct the view using docloader
   488 	// Construct the view using docloader
   464 	setUpView();
   489 	setUpView();
   465 		
   490 
   466 	// Set the title text. 
   491 	// Set the title text. 
   467 	mEditorView->setTitle(hbTrId("txt_calendar_title_calendar"));
   492 	mEditorView->setTitle(hbTrId("txt_calendar_title_calendar"));
   468 
   493 
   469 	mSoftKeyAction = new HbAction(Hb::BackAction);
   494 	mSoftKeyAction = new HbAction(Hb::BackNaviAction);
   470 	mEditorView->setNavigationAction(mSoftKeyAction);
   495 	mEditorView->setNavigationAction(mSoftKeyAction);
   471 	connect(mSoftKeyAction, SIGNAL(triggered()), this,
   496 	connect(mSoftKeyAction, SIGNAL(triggered()), this,
   472 	        SLOT(saveAndCloseEditor()));
   497 	        SLOT(saveAndCloseEditor()));
   473 	
   498 
   474 	// Create the data handler
   499 	// Create the data handler
   475 	mDataHandler = new CalenEditorDataHandler(this,mEditedEntry, mOriginalEntry);
   500 	mDataHandler = new CalenEditorDataHandler(this,mEditedEntry, mOriginalEntry);
   476 }
   501 }
   477 
   502 
   478 /*!
   503 /*!
   511 							SLOT(handleDescriptionAction()));
   536 							SLOT(handleDescriptionAction()));
   512 
   537 
   513 	HbAction *deleteEventAction = qobject_cast<HbAction *> (
   538 	HbAction *deleteEventAction = qobject_cast<HbAction *> (
   514 							mEditorDocLoader->findObject(
   539 							mEditorDocLoader->findObject(
   515 										CALEN_EDITOR_DELETE_EVENT_ACTION));
   540 										CALEN_EDITOR_DELETE_EVENT_ACTION));
       
   541 	deleteEventAction->setText(hbTrId("txt_common_menu_delete"));
   516 	connect(deleteEventAction, SIGNAL(triggered()), this,
   542 	connect(deleteEventAction, SIGNAL(triggered()), this,
   517 							SLOT(handleDeleteAction()));
   543 							SLOT(showDeleteConfirmationQuery()));
   518 
   544 
   519 	if (!mNewEntry) {
   545 	if (!mNewEntry) {
   520 		//TODO: Add the text id based on the entry type Anniversary or meeting
   546 		AgendaEntry::Type entryType = mEditedEntry->type();
   521 		headingWidget->setHeading(hbTrId("txt_calendar_subhead_event"));
   547 		if( entryType == AgendaEntry::TypeAppoinment) {
       
   548 			headingWidget->setHeading(hbTrId("txt_calendar_subhead_meeting"));
       
   549 		}else if(entryType == AgendaEntry::TypeEvent) {
       
   550 			//TODO: Add the text id once available
       
   551 			headingWidget->setHeading(hbTrId("All-day event"));
       
   552 		}else if (entryType == AgendaEntry::TypeTodo) {
       
   553 			headingWidget->setHeading(hbTrId("txt_calendar_subhead_to_do"));
       
   554 		}
       
   555 		
   522 	}
   556 	}
   523 
   557 
   524 	initModel();
   558 	initModel();
   525 	// Set the custom item.
   559 	// Set the custom item.
   526 	CalenEditorCustomItem *customItem =
   560 	CalenEditorCustomItem *customItem =
   580 	// Add the fields to the DataForm.
   614 	// Add the fields to the DataForm.
   581 	addSubjectItem();
   615 	addSubjectItem();
   582 
   616 
   583 	// Add all day check box for new entry creation or while editing
   617 	// Add all day check box for new entry creation or while editing
   584 	// parent entry or existing non repeating event
   618 	// parent entry or existing non repeating event
   585 	if (mNewEntry) {
   619 	if (mNewEntry || (mEditRange == ThisAndAll)) {
   586 		addAllDayCheckBoxItem();
   620 		addAllDayCheckBoxItem();
   587 	} else { 
   621 	}
   588 		if (!mEditedEntry->isRepeating() || (mEditRange == ThisAndAll)) {
       
   589 			addAllDayCheckBoxItem();
       
   590 		}
       
   591 	}
       
   592 	
       
   593 	addCustomItemFrom();
   622 	addCustomItemFrom();
   594 	addCustomItemTo();
   623 	addCustomItemTo();
   595 	addCustomItemLocation();
   624 	addCustomItemLocation();
   596 	addReminderItem();
   625 	addReminderItem();
   597 	// Add the repeat information only if particular occurence is not being 
   626 	// Add the repeat information only if particular occurence is not being 
   598 	if (mEditRange == ThisAndAll) {
   627 	if (mEditRange == ThisAndAll) {
   599 		addRepeatItem();
   628 		addRepeatItem();
   600 	}
   629 	}
   601 
       
   602 	mCalenEditorForm->setModel(mCalenEditorModel);
   630 	mCalenEditorForm->setModel(mCalenEditorModel);
   603 }
   631 }
   604 
   632 
   605 /*!
   633 /*!
   606 	Appends the Subject Item to the Data form Model.
   634 	Appends the Subject Item to the Data form Model.
   791 			AgendaEntry parentEntry = mAgendaUtil->parentEntry(*mEditedEntry);
   819 			AgendaEntry parentEntry = mAgendaUtil->parentEntry(*mEditedEntry);
   792 			int durationInSeconds = parentEntry.durationInSecs();
   820 			int durationInSeconds = parentEntry.durationInSecs();
   793 			QDateTime endTime =
   821 			QDateTime endTime =
   794 			        mEditedEntry-> startTime().addSecs(durationInSeconds);
   822 			        mEditedEntry-> startTime().addSecs(durationInSeconds);
   795 
   823 
   796 			// set this to the original entr as well as edited entry
   824 			// set this to the original entry as well as edited entry
   797 			mOriginalEntry->setStartAndEndTime(mOriginalEntry->startTime(),
   825 			mOriginalEntry->setStartAndEndTime(mOriginalEntry->startTime(),
   798 										endTime);
   826 										endTime);
   799 			mEditedEntry->setStartAndEndTime(mEditedEntry->startTime(), endTime);
   827 			mEditedEntry->setStartAndEndTime(mEditedEntry->startTime(), endTime);
   800 		}
   828 		}
   801 		fromDateTime = mEditedEntry->startTime();
   829 		fromDateTime = mEditedEntry->startTime();
   852 			QDateTime nextInstanceStartTime;
   880 			QDateTime nextInstanceStartTime;
   853 			QDateTime nextInstanceEndTime;
   881 			QDateTime nextInstanceEndTime;
   854 			mAgendaUtil->getNextInstanceTimes(*mEditedEntry,
   882 			mAgendaUtil->getNextInstanceTimes(*mEditedEntry,
   855 			                                  nextInstanceStartTime,
   883 			                                  nextInstanceStartTime,
   856 			                                  nextInstanceEndTime);
   884 			                                  nextInstanceEndTime);
       
   885 			
       
   886 			// If no instances earlier then set it to 01/01/1900.
       
   887 			if (prevInstanceStartTime.isNull()) {
       
   888 				prevInstanceStartTime.setDate(QDate(1900, 01, 01));
       
   889 				prevInstanceStartTime.setTime(QTime(0, 0, 0));
       
   890 			}
       
   891 			
       
   892 			// If no instances later then set it to 30/01/2100.
       
   893 			if (nextInstanceEndTime.isNull()) {
       
   894 				nextInstanceEndTime.setDate(QDate(2100, 12, 30));
       
   895 				nextInstanceEndTime.setTime(QTime(0, 0, 0));
       
   896 			}
   857 			mViewFromItem->setDateRange(
   897 			mViewFromItem->setDateRange(
   858 									prevInstanceStartTime.addDays(1).date(),
   898 									prevInstanceStartTime.addDays(1).date(),
   859 									nextInstanceStartTime.addDays(-1).date());
   899 									nextInstanceStartTime.addDays(-1).date());
   860 			mViewToItem->setDateRange(prevInstanceEndTime.date().addDays(1),
   900 			mViewToItem->setDateRange(prevInstanceEndTime.date().addDays(1),
   861 			                        nextInstanceEndTime.date().addDays(-1));
   901 			                        nextInstanceEndTime.date().addDays(-1));
       
   902 			
       
   903 			// If repeating daily then disable the date fields as 
       
   904 			// date cannot be changed
       
   905  			if ((prevInstanceEndTime.date().daysTo(
       
   906 				mEditedEntry->startTime().date()) == 1) && 
       
   907 				(mEditedEntry->endTime().date().daysTo(
       
   908 				nextInstanceStartTime.date()) == 1)) {
       
   909 				mViewFromItem->disableFromToDateField();
       
   910 			}
   862 		}
   911 		}
   863 	} else {
   912 	} else {
   864 		toDateTime = fromDateTime.addSecs(60 * 60);
   913 		toDateTime = fromDateTime.addSecs(60 * 60);
   865 	}
   914 	}
   866 	mViewToItem->populateDateTime(toDateTime, false);
   915 	mViewToItem->populateDateTime(toDateTime, false);
   869 	mEditedEntry->setStartAndEndTime(fromDateTime, toDateTime);
   918 	mEditedEntry->setStartAndEndTime(fromDateTime, toDateTime);
   870 	// Set the default start time to the Original entry if its a new event.
   919 	// Set the default start time to the Original entry if its a new event.
   871 	if (mNewEntry) {
   920 	if (mNewEntry) {
   872 		mOriginalEntry->setStartAndEndTime(fromDateTime, toDateTime);
   921 		mOriginalEntry->setStartAndEndTime(fromDateTime, toDateTime);
   873 	}
   922 	}
   874 	if (mAllDayCheckBoxItem
   923 	if ((mAllDayCheckBoxItem && 
   875 	        && (mAllDayCheckBoxItem->contentWidgetData("checkState")
   924 		(mAllDayCheckBoxItem->contentWidgetData("checkState") == Qt::Checked))
   876 	                == Qt::Checked)) {
   925 		|| (!mNewEntry && mEditedEntry->type() == AgendaEntry::TypeEvent)) {
       
   926         
       
   927         // For all-day, we need to substratc 1 minute to get the actual end time
       
   928         // as we store all-day as 12.00AM to 12.00 AM next day
       
   929         QDateTime actualEndTime = mEditedEntry->endTime().addSecs(-60);
       
   930         mViewToItem->populateDateTime(actualEndTime, false);
       
   931         
   877 		// If the all day option is checked, we need to
   932 		// If the all day option is checked, we need to
   878 		// disable the time fields
   933 		// disable the time fields
   879 		enableFromTotimeFileds(false, mEditedEntry->startTime(),
   934 		enableFromTotimeFileds(false, mEditedEntry->startTime(),
   880 		                       mEditedEntry->endTime());
   935                                 actualEndTime);
   881 	}
   936 	}
   882 }
   937 }
   883 /*!
   938 /*!
   884 	Populate location item from the editor model and set it in the widget and listen 
   939 	Populate location item from the editor model and set it in the widget and listen 
   885 	text change happend in the widget. 
   940 	text change happend in the widget. 
   896 	else {
   951 	else {
   897 		itemIndex = LocationItem - 1;
   952 		itemIndex = LocationItem - 1;
   898 	}
   953 	}
   899 	QModelIndex index = mCalenEditorModel->index(itemIndex, 0);
   954 	QModelIndex index = mCalenEditorModel->index(itemIndex, 0);
   900 	mViewLocationItem = qobject_cast<CalenEditorCustomItem *> 
   955 	mViewLocationItem = qobject_cast<CalenEditorCustomItem *> 
   901 	                      (mCalenEditorForm->dataFormViewItem(index));        
   956 	                      (mCalenEditorForm->itemByIndex(index));
   902                 
   957 
   903 	connect(mViewLocationItem, SIGNAL(locationTextChanged(const QString)),
   958 	connect(mViewLocationItem, SIGNAL(locationTextChanged(const QString)),
   904 			this, SLOT(handleLocationChange(const QString)));
   959 			this, SLOT(handleLocationChange(const QString)));
   905                     
   960 	
   906 	mViewLocationItem->populateLocation(mEditedEntry->location());
   961 	connect(mViewLocationItem, SIGNAL(locationTextChanged(const QString, const double, const double)),
       
   962 			this, SLOT(handleLocationChange(const QString, const double, const double)));
       
   963 
       
   964 	mViewLocationItem->populateLocation(mEditedEntry->location());	
       
   965 	
       
   966     connect(mViewLocationItem, SIGNAL(locationEditingFinished()),
       
   967             this, SLOT(handleLocationEditingFinished()));
       
   968 	        
   907 }
   969 }
   908 /*!
   970 /*!
   909 	Save the changed start time of the event.
   971 	Save the changed start time of the event.
   910  */
   972  */
   911 void CalenEditorPrivate::saveFromDateTime(QDateTime& fromDateTime)
   973 void CalenEditorPrivate::saveFromDateTime(QDateTime& fromDateTime)
   933 	
   995 	
   934 	if (mEditRange == ThisAndAll) {
   996 	if (mEditRange == ThisAndAll) {
   935 		// update the repeat choices depending on the meeting duration
   997 		// update the repeat choices depending on the meeting duration
   936 		mRepeatField->updateRepeatChoices();
   998 		mRepeatField->updateRepeatChoices();
   937 	}
   999 	}
       
  1000 
       
  1001 	updateReminderChoices();
       
  1002 }
       
  1003 
       
  1004 void CalenEditorPrivate::updateReminderChoices()
       
  1005 {
       
  1006 	QDate referenceDate;
       
  1007 	
       
  1008 	// Start date or repeat until date will be the reference to decide 
       
  1009 	// whether the event is in past or future.
       
  1010 	if (mRepeatField && mRepeatField->isRepeatUntilItemAdded()) {
       
  1011 		referenceDate = mRepeatField->repeatUntilDate();
       
  1012 	} else {
       
  1013 		referenceDate = mEditedEntry->startTime().date();
       
  1014 	}
       
  1015 	
       
  1016 	// Check if all day event or not.
       
  1017 	if (isAllDayEvent()) {
       
  1018 		int currentIndex = mReminderField->currentReminderIndex();
       
  1019 		mReminderField->updateReminderChoicesForAllDay(referenceDate);
       
  1020 		int numberOfReminderChoices = mReminderField->reminderItemsCount();
       
  1021 		if (currentIndex >= numberOfReminderChoices) {
       
  1022 			currentIndex = 0;
       
  1023 			mReminderField->disableReminderTimeField();
       
  1024 		} 
       
  1025 		mReminderField->setCurrentIndex(currentIndex);
       
  1026 		if(currentIndex == 0 && mReminderField->isReminderTimeForAllDayAdded()) {
       
  1027 			mReminderField->removeReminderTimeField();
       
  1028 		}
       
  1029 	} else { 
       
  1030 		if ((referenceDate < QDate::currentDate())
       
  1031 						|| (referenceDate == QDate::currentDate()
       
  1032 				&& (mEditedEntry->startTime().time() < QTime::currentTime())))
       
  1033 				 {
       
  1034 					mReminderField->setReminderOff();
       
  1035 		} else {
       
  1036 			// Enabled implies future. If changing from future to future do not 
       
  1037 			// do anything.
       
  1038 			if (!mReminderField->isReminderFieldEnabled()) {
       
  1039 				mReminderField->setReminderChoices();
       
  1040 			}
       
  1041 		}
       
  1042 	}
   938 }
  1043 }
   939 
  1044 
   940 /*!
  1045 /*!
   941 	Save the changed end time of the event.
  1046 	Save the changed end time of the event.
   942  */
  1047  */
   943 void CalenEditorPrivate::saveToDateTime(QDateTime& toDateTime)
  1048 void CalenEditorPrivate::saveToDateTime(QDateTime& toDateTime)
   944 {
  1049 {
   945 	QDateTime startTime = mEditedEntry->startTime();
  1050 	QDateTime startTime = mEditedEntry->startTime();
       
  1051 	bool fromDateChanged = false;
   946 	// Update the start time accordingly on UI - duration will be 60 mins
  1052 	// Update the start time accordingly on UI - duration will be 60 mins
   947 	// bydefault for new entry and if it crosses the starttime
  1053 	// bydefault for new entry and if it crosses the starttime
   948 	if (mNewEntry && toDateTime < startTime) {
  1054 	if (mNewEntry && toDateTime < startTime) {
   949 		startTime = toDateTime.addSecs(-3600);
  1055 		startTime = toDateTime.addSecs(-3600);
   950 	} else { // for exisitng entry
  1056 		fromDateChanged = true;
       
  1057 	} else { 
       
  1058 		// for exisitng entry
   951 		// we need to see if user has moved end time before the start time
  1059 		// we need to see if user has moved end time before the start time
   952 		// then substract the duration of the meeting that was saved earlier to 
  1060 		// then substract the duration of the meeting that was saved earlier to 
   953 		// the new end time to get the new start time
  1061 		// the new end time to get the new start time
   954 		if (toDateTime < startTime) {
  1062 		if (toDateTime < startTime) {
   955 			int duration = mEditedEntry->durationInSecs();
  1063 			int duration = mEditedEntry->durationInSecs();
   956 			startTime = toDateTime.addSecs(-duration);
  1064 			startTime = toDateTime.addSecs(-duration);
       
  1065 			fromDateChanged = true;
   957 		}
  1066 		}
   958 	}
  1067 	}
   959 	// Set the new start time to the form
  1068 	// Set the new start time to the form
   960 	if (mViewFromItem) {
  1069 	if (mViewFromItem) {
   961 		mViewFromItem->populateDateTime(startTime, true);
  1070 		mViewFromItem->populateDateTime(startTime, true);
   966 
  1075 
   967 	if (mEditRange == ThisAndAll) {
  1076 	if (mEditRange == ThisAndAll) {
   968 		// update the repeat choices depending on the meeting duration
  1077 		// update the repeat choices depending on the meeting duration
   969 		mRepeatField->updateRepeatChoices();
  1078 		mRepeatField->updateRepeatChoices();
   970 	}
  1079 	}
       
  1080 	
       
  1081 	// Update reminder choices if start time got changed.
       
  1082 	if (fromDateChanged) {
       
  1083 		updateReminderChoices();
       
  1084 	}
   971 }
  1085 }
   972 
  1086 
   973 /*!
  1087 /*!
   974 	Populates the repeat item.
  1088 	Populates the repeat item.
   975  */
  1089  */
   976 void CalenEditorPrivate::populateRepeatItem()
  1090 void CalenEditorPrivate::populateRepeatItem()
   977 {
  1091 {
   978 	// Check if all day has been added or not 
  1092 	// Check if all day has been added or not 
   979 	// and calculate the index accordingly
  1093 	// and calculate the index accordingly
       
  1094 	// all day added implies reminder time field is also added
   980 	int index;
  1095 	int index;
   981 	if (mIsAllDayItemAdded) {
  1096 	if (mIsAllDayItemAdded && !isReminderTimeForAllDayAdded()) {
       
  1097 		index = RepeatItem - 1;
       
  1098 	} else if (!mNewEntry && isReminderTimeForAllDayAdded()) {
   982 		index = RepeatItem;
  1099 		index = RepeatItem;
   983 	} else {
  1100 	} else {
   984 		index = RepeatItem - 1;
  1101 		index = RepeatItem - 2;
   985 	}
  1102 	}
   986 	
  1103 	
   987 	mRepeatField->populateRepeatItem(index);
  1104 	mRepeatField->populateRepeatItem(index);
   988 }
  1105 }
   989 
  1106 
  1070 	\param subject Contains the string displayed in the subject item.
  1187 	\param subject Contains the string displayed in the subject item.
  1071  */
  1188  */
  1072 void CalenEditorPrivate::handleSubjectChange(const QString subject)
  1189 void CalenEditorPrivate::handleSubjectChange(const QString subject)
  1073 {
  1190 {
  1074 	mEditedEntry->setSummary(subject);
  1191 	mEditedEntry->setSummary(subject);
  1075 	addDiscardAction();
  1192 	if(!mNewEntry ){
       
  1193 		addDiscardAction();
       
  1194 	}
  1076 }
  1195 }
  1077 
  1196 
  1078 /*!
  1197 /*!
  1079  Triggered when the Allday Checkbox is being edited.
  1198  Triggered when the Allday Checkbox is being edited.
  1080  \param state of checkbox.
  1199  \param state of checkbox.
  1094 		QTime tempEndQTime = tempEndTime.time();
  1213 		QTime tempEndQTime = tempEndTime.time();
  1095 		tempEndQTime.setHMS(23, 59, 59);
  1214 		tempEndQTime.setHMS(23, 59, 59);
  1096 		tempEndTime.setTime(tempEndQTime);
  1215 		tempEndTime.setTime(tempEndQTime);
  1097 
  1216 
  1098 		enableFromTotimeFileds(false, tempSartTime, tempEndTime);
  1217 		enableFromTotimeFileds(false, tempSartTime, tempEndTime);
       
  1218 		QDate referenceDate;
       
  1219 		if (mRepeatField->isRepeatUntilItemAdded()) {
       
  1220 			referenceDate = mRepeatField->repeatUntilDate();
       
  1221 		} else {
       
  1222 			referenceDate = mEditedEntry->startTime().date();
       
  1223 		}
       
  1224 		mReminderField->updateReminderChoicesForAllDay(referenceDate);
       
  1225 		// If the reminder field is enabled and it is not off 
       
  1226 		// it implies default alarm day and time is being displayed.
       
  1227 		if (mReminderField->isReminderFieldEnabled() && 
       
  1228 					mReminderField->currentReminderIndex() != 0) {
       
  1229 			// Set the default alarm for all day.
       
  1230 			mReminderField->setDefaultAlarmForAllDay();
       
  1231 		} else {
       
  1232 			// Remove reminder time field.
       
  1233 			mReminderField->removeReminderTimeField();
       
  1234 		}
  1099 	} else {
  1235 	} else {
  1100 		// AllDayCheckBox in un-checked
  1236 		// AllDayCheckBox in un-checked
  1101 		// Set From/To times buttons editable
  1237 		// Set From/To times buttons editable
  1102 		// Update Start/End Times with Edited entry values
  1238 		// Update Start/End Times with Edited entry values
  1103 		enableFromTotimeFileds(true, mEditedEntry->startTime(),
  1239 		enableFromTotimeFileds(true, mEditedEntry->startTime(),
  1104 		                       mEditedEntry->endTime());
  1240 		                       mEditedEntry->endTime());
  1105 
  1241 		// If original entry was an All-day, then we need to save the date that
  1106 	}
  1242 		// is shown on the "To" date push button
  1107 	addDiscardAction();
  1243 		if (mOriginalEntry->type() == AgendaEntry::TypeEvent) {
       
  1244             mEditedEntry->setStartAndEndTime(mViewFromItem->getDateTime(),
       
  1245                                     mViewToItem->getDateTime());
       
  1246 		}
       
  1247 		int index;
       
  1248 		if (mIsAllDayItemAdded) {
       
  1249 			index = ReminderTimeForAllDayItem;
       
  1250 		} else {
       
  1251 			index = ReminderTimeForAllDayItem - 1;
       
  1252 		}
       
  1253 		mReminderField->removeReminderTimeField();
       
  1254 		mReminderField->setReminderChoices();
       
  1255 		updateReminderChoices();
       
  1256 	}
       
  1257 
       
  1258 	if(!mNewEntry){
       
  1259 		addDiscardAction();
       
  1260 	}
  1108 }
  1261 }
  1109 
  1262 
  1110 /*!
  1263 /*!
  1111 	Triggered when the location editor is being edited.
  1264 	Triggered when the location editor is being edited.
  1112 	\param subject Contains the string displayed in the subject item.
  1265 	\param subject Contains the string displayed in the subject item.
  1113  */
  1266  */
  1114 void CalenEditorPrivate::handleLocationChange(const QString location)
  1267 void CalenEditorPrivate::handleLocationChange(const QString location)
  1115 {
  1268 {
  1116 	mEditedEntry->setLocation(location);
  1269 	mEditedEntry->setLocation(location);
       
  1270 	if(!mNewEntry){
       
  1271 		addDiscardAction();
       
  1272 	}
       
  1273 }
       
  1274 
       
  1275 
       
  1276 /*!
       
  1277 	Triggered when the location editor is being edited.
       
  1278 	\param subject Contains the string displayed in the subject item.
       
  1279  */
       
  1280 void CalenEditorPrivate::handleLocationChange(const QString location,
       
  1281     const double /*geoLatitude*/, const double /*geoLongitude*/)
       
  1282 {
       
  1283 	mEditedEntry->setLocation(location);
       
  1284 	mEditedEntry->clearGeoValue();
  1117 	addDiscardAction();
  1285 	addDiscardAction();
  1118 }
  1286 }
  1119 
  1287 
       
  1288 /*!
       
  1289  * Handles the completion of location editing
       
  1290  */
       
  1291 void CalenEditorPrivate::handleLocationEditingFinished()
       
  1292 {
       
  1293     if ( !mOriginalEntry->location().isEmpty() )
       
  1294     {
       
  1295        AgendaGeoValue entryGeoValue =mAgendaUtil->fetchById(mEditedEntry->id()).geoValue();
       
  1296        if ( !entryGeoValue.isNull() && (mEditedEntry->location()!=mOriginalEntry->location()) )
       
  1297        {   
       
  1298           
       
  1299            mEditedEntry->setGeoValue(entryGeoValue);
       
  1300            HbMessageBox* confirmationQuery = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
       
  1301                    
       
  1302            confirmationQuery->setDismissPolicy(HbDialog::NoDismiss);
       
  1303            confirmationQuery->setTimeout(HbDialog::NoTimeout);
       
  1304            confirmationQuery->setIconVisible(true);  
       
  1305            
       
  1306            QString displayText;
       
  1307            displayText = displayText.append("Location changed. Keep existing location on Map?");
       
  1308            
       
  1309            confirmationQuery->setText(displayText);
       
  1310            
       
  1311            // Remove the default actions.
       
  1312            QList<QAction *> defaultActions = confirmationQuery->actions();
       
  1313            for (int index=0;index<defaultActions.count();index++) 
       
  1314            {
       
  1315                confirmationQuery->removeAction(defaultActions[index]);
       
  1316            }
       
  1317            
       
  1318            defaultActions.clear();
       
  1319            
       
  1320            confirmationQuery->addAction(new HbAction("Yes"));
       
  1321            confirmationQuery->addAction(new HbAction("No"));
       
  1322            confirmationQuery->open(this, SLOT(selectEditingFinishedAction(HbAction*)));
       
  1323        }
       
  1324     }       
       
  1325 }
       
  1326 
       
  1327 /*!
       
  1328  * Handles the editing finished action.
       
  1329  */
       
  1330 void CalenEditorPrivate::selectEditingFinishedAction(HbAction* action)
       
  1331 {
       
  1332     HbMessageBox* dlg = static_cast<HbMessageBox*>(sender());    
       
  1333 
       
  1334     if (action == dlg->actions().at(1))
       
  1335     {           
       
  1336         mEditedEntry->clearGeoValue();
       
  1337     } 
       
  1338 }
  1120 
  1339 
  1121 /*!
  1340 /*!
  1122 	Triggered when the description editor is being edited.
  1341 	Triggered when the description editor is being edited.
  1123 	\param description Contains the string displayed in the description item.
  1342 	\param description Contains the string displayed in the description item.
  1124  */
  1343  */
  1125 void CalenEditorPrivate::handleDescriptionChange(const QString description)
  1344 void CalenEditorPrivate::handleDescriptionChange(const QString description)
  1126 {
  1345 {
  1127 	mEditedEntry->setDescription(description);
  1346 	mEditedEntry->setDescription(description);
  1128 	addDiscardAction();
  1347 	if(!mNewEntry){
       
  1348 		addDiscardAction();
       
  1349 	}
  1129 }
  1350 }
  1130 
  1351 
  1131 /*!
  1352 /*!
  1132 	Saves the entry & closes the editor.
  1353 	Saves the entry & closes the editor.
  1133 	If mLaunchCalendar is true, then it tries to launch the calendar
  1354 	If mLaunchCalendar is true, then it tries to launch the calendar
  1134  */
  1355  */
  1135 void CalenEditorPrivate::saveAndCloseEditor()
  1356 void CalenEditorPrivate::saveAndCloseEditor()
  1136 {
  1357 {
  1137 	Action action = handleDone();
  1358 	Action action = handleDone();
  1138 	closeEditor();
  1359 	if (CalenEditorPrivate::ActionDelete != action) {
       
  1360 		closeEditor();
       
  1361 	}
  1139 
  1362 
  1140 	if (CalenEditorPrivate::ActionSave == action) {
  1363 	if (CalenEditorPrivate::ActionSave == action) {
  1141 		// check if we need to launch the calendar application
  1364 		// check if we need to launch the calendar application
  1142 		if (mLaunchCalendar) {
  1365 		if (mLaunchCalendar) {
  1143 			CalenLauncher* launcher = new CalenLauncher(this);
  1366 			CalenLauncher* launcher = new CalenLauncher(this);
  1144 			QDateTime startTime = mEditedEntry->startTime();
  1367 			QDateTime startTime = mEditedEntry->startTime();
  1145 			launcher->launchCalendarApp(CalenLauncher::DayView, startTime);
  1368 			launcher->launchCalendarApp(CalenLauncher::AgendaView, startTime);
  1146 
  1369 
  1147 			// connect to the error signal
  1370 			// connect to the error signal
  1148 			connect(launcher, SIGNAL(calendarLaunchFailed(int)), this,
  1371 			connect(launcher, SIGNAL(calendarLaunchFailed(int)), this,
  1149 									SLOT(handleCalendarLaunchError(int)));
  1372 									SLOT(handleCalendarLaunchError(int)));
  1150 		}
  1373 		}
  1163 /*!
  1386 /*!
  1164 	Deletes the entry.
  1387 	Deletes the entry.
  1165  */
  1388  */
  1166 void CalenEditorPrivate::handleDeleteAction()
  1389 void CalenEditorPrivate::handleDeleteAction()
  1167 {
  1390 {
  1168 
  1391 	// If its a new entry just close the editor
  1169 	if (mNewEntry) {
  1392 	if (mNewEntry) {
  1170 		if (showDeleteConfirmationQuery()) {
  1393 		closeEditor();
  1171 			closeEditor();
       
  1172 		}
       
  1173 		return;
  1394 		return;
  1174 	}
  1395 	}else {
  1175 	
  1396 		// Delete entry and close editor
  1176 	// Delete entry and close editor
  1397 		deleteEntry(true);
  1177 	deleteEntry(true);
  1398 	}
  1178 
       
  1179 }
  1399 }
  1180 
  1400 
  1181 /*!
  1401 /*!
  1182 	Launches the Settings view.
  1402 	Launches the Settings view.
  1183  */
  1403  */
  1196 }
  1416 }
  1197 
  1417 
  1198 /*!
  1418 /*!
  1199  * Show delete confirmation query
  1419  * Show delete confirmation query
  1200  */
  1420  */
  1201 int CalenEditorPrivate::showDeleteConfirmationQuery()
  1421 void CalenEditorPrivate::showDeleteConfirmationQuery(bool closeEditor)
  1202 {
  1422 {
  1203 	int retStatus = 0;
  1423 	HbMessageBox *popup = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
  1204 
  1424 	popup->setDismissPolicy(HbDialog::NoDismiss);
  1205 	HbMessageBox popup(HbMessageBox::MessageTypeQuestion);
  1425 	popup->setTimeout(HbDialog::NoTimeout);
  1206 	popup.setDismissPolicy(HbDialog::NoDismiss);
  1426 	popup->setAttribute( Qt::WA_DeleteOnClose, true );
  1207 	popup.setTimeout(HbDialog::NoTimeout);
       
  1208 	popup.setIconVisible(true);
       
  1209 
  1427 
  1210 	QString text = 0;
  1428 	QString text = 0;
  1211 
  1429 
  1212 	switch (mOriginalEntry->type()) {
  1430 	switch (mOriginalEntry->type()) {
  1213 		case AgendaEntry::TypeAppoinment:
  1431 		case AgendaEntry::TypeAppoinment:
  1223 			text.append(hbTrId("txt_calendar_info_delete_anniversary"));
  1441 			text.append(hbTrId("txt_calendar_info_delete_anniversary"));
  1224 			break;
  1442 			break;
  1225 		}
  1443 		}
  1226 	}
  1444 	}
  1227 
  1445 
  1228 	popup.setText(text);
  1446 	popup->setText(text);
  1229 
  1447 	
  1230 	popup.setPrimaryAction(new HbAction(hbTrId("txt_calendar_button_delete"),
  1448     QList<QAction*> list = popup->actions();
  1231 	                                    &popup));
  1449     for(int i=0; i < list.count(); i++)
  1232 	popup.setSecondaryAction(new HbAction(hbTrId("txt_calendar_button_cancel"),
  1450         {
  1233 	                                      &popup));
  1451         popup->removeAction(list[i]);
  1234 	HbAction *selected = popup.exec();
  1452         }
  1235 	if (selected == popup.primaryAction()) {
  1453 	HbAction *deleteAction = new HbAction(hbTrId("txt_calendar_button_delete"),
  1236 		retStatus = 1;
  1454 										popup);
  1237 	}
  1455 	popup->addAction(deleteAction);
  1238 
  1456 	connect(deleteAction, SIGNAL(triggered()), this, 
  1239 	return retStatus;
  1457 										SLOT(handleDeleteAction()));
       
  1458 	HbAction *cancelAction = new HbAction(hbTrId("txt_calendar_button_cancel"),
       
  1459 											popup);
       
  1460 	// Editor should not be closed for all the cases when cancel is pressed
       
  1461 	if(closeEditor) {
       
  1462 		connect(cancelAction, SIGNAL(triggered()), this, 
       
  1463 											SLOT(closeEditor()));
       
  1464 	}
       
  1465 	popup->addAction(cancelAction);
       
  1466 	popup->open();
  1240 }
  1467 }
  1241 
  1468 
  1242 /*!
  1469 /*!
  1243 	Returns true if the entry is a child ,else false.
  1470 	Returns true if the entry is a child ,else false.
  1244 	\return true if the entry is a child, false otherwise.
  1471 	\return true if the entry is a child, false otherwise.
  1271 			if (saveEntry()) {
  1498 			if (saveEntry()) {
  1272 				return CalenEditorPrivate::ActionSave;
  1499 				return CalenEditorPrivate::ActionSave;
  1273 			}
  1500 			}
  1274 			return CalenEditorPrivate::ActionNothing;
  1501 			return CalenEditorPrivate::ActionNothing;
  1275 		case CalenEditorPrivate::ActionDelete:
  1502 		case CalenEditorPrivate::ActionDelete:
  1276 			deleteEntry();
  1503 			showDeleteConfirmationQuery(true);
  1277 			return CalenEditorPrivate::ActionDelete;
  1504 			return CalenEditorPrivate::ActionDelete;
  1278 		case CalenEditorPrivate::ActionNothing:
  1505 		case CalenEditorPrivate::ActionNothing:
  1279 			return CalenEditorPrivate::ActionNothing;
  1506 			return CalenEditorPrivate::ActionNothing;
  1280 		default:
  1507 		default:
  1281 			break;
  1508 			break;
  1291 {
  1518 {
  1292 	// check if we are editing child
  1519 	// check if we are editing child
  1293 	if (mIsChild && (mEditRange == ThisOnly)) {
  1520 	if (mIsChild && (mEditRange == ThisOnly)) {
  1294 		// Add the entry
  1521 		// Add the entry
  1295 		mAgendaUtil->updateEntry(*mEditedEntry, true);
  1522 		mAgendaUtil->updateEntry(*mEditedEntry, true);
  1296 		// TODO: Add the text id based on meeting or anniversary
  1523 		// TODO: Add the text id once available
  1297 		HbNotificationDialog::launchDialog(hbTrId("Event updated"));
  1524 		if(mEditedEntry->type() == AgendaEntry::TypeAppoinment) {
       
  1525 			HbNotificationDialog::launchDialog(hbTrId("Meeting updated"));
       
  1526 		}else if(mEditedEntry->type() == AgendaEntry::TypeEvent) {
       
  1527 			HbNotificationDialog::launchDialog(hbTrId("All day event updated"));
       
  1528 		}
  1298 		emit q_ptr->entrySaved();
  1529 		emit q_ptr->entrySaved();
  1299 		return true;
  1530 		return true;
  1300 	} else if ((mEditRange == ThisOnly)) {
  1531 	} else if ((mEditRange == ThisOnly)) {
  1301 		// If we are editing only this occurence, then 
  1532 		// If we are editing only this occurence, then 
  1302 		// clear the repeating properties of it
  1533 		// clear the repeating properties of it
  1307 	error = mDataHandler->checkErrorsForThisAndAll();
  1538 	error = mDataHandler->checkErrorsForThisAndAll();
  1308 	if (CalenEditorPrivate::CalenEditorErrorNone == error) {
  1539 	if (CalenEditorPrivate::CalenEditorErrorNone == error) {
  1309 		if (!handleAllDayToSave()) {
  1540 		if (!handleAllDayToSave()) {
  1310 			if (mNewEntry) {
  1541 			if (mNewEntry) {
  1311 				mAgendaUtil->addEntry(*mEditedEntry);
  1542 				mAgendaUtil->addEntry(*mEditedEntry);
  1312 			} else if (mEditRange == ThisAndAll) {
  1543 			} else if (mEditRange == ThisAndAll && mOriginalEntry->isRepeating()) {
  1313 				mAgendaUtil->storeRepeatingEntry(*mEditedEntry, true);
  1544 				mAgendaUtil->storeRepeatingEntry(*mEditedEntry, true);
  1314 			} else if (!mIsChild && (mEditRange == ThisOnly)) {
  1545 			} else if (!mIsChild && (mEditRange == ThisOnly)) {
  1315 				// Create the new exception
  1546 				// Create the new exception
  1316 				mAgendaUtil->createException(*mEditedEntry);
  1547 				mAgendaUtil->createException(*mEditedEntry, 
       
  1548 												mOriginalEntry->startTime());
  1317 			} else {
  1549 			} else {
  1318 				// Normal entry updation
  1550 				// Normal entry updation
  1319 				mAgendaUtil->updateEntry(*mEditedEntry, false);
  1551 				mAgendaUtil->updateEntry(*mEditedEntry, false);
  1320 			}
  1552 			}
  1321 		}
  1553 		}
  1322 		if (mNewEntry) {
  1554 		if (mNewEntry) {
  1323 			// TODO: Add the text id based on meeting or anniversary
  1555 			// TODO: Add the text id once available
  1324 			HbNotificationDialog::launchDialog(hbTrId("New Event saved"));
  1556 			if(mEditedEntry->type() == AgendaEntry::TypeAppoinment) {
       
  1557 				HbNotificationDialog::launchDialog(hbTrId("New meeting saved"));
       
  1558 			} else if(mEditedEntry->type() == AgendaEntry::TypeEvent) {
       
  1559 				HbNotificationDialog::launchDialog(hbTrId("New all-day saved"));
       
  1560 			}
  1325 		} else {
  1561 		} else {
  1326 			// TODO: Add the text id based on meeting or anniversary
  1562 			// TODO: Add the text id once available
  1327 			HbNotificationDialog::launchDialog(hbTrId("Event updated"));
  1563 			if(mEditedEntry->type() == AgendaEntry::TypeAppoinment) {
       
  1564 				HbNotificationDialog::launchDialog(hbTrId("Meeting updated"));
       
  1565 			} else if(mEditedEntry->type() == AgendaEntry::TypeEvent) {
       
  1566 				HbNotificationDialog::launchDialog(hbTrId("All day event updated"));
       
  1567 			}
  1328 		}
  1568 		}
  1329 		emit q_ptr->entrySaved();
  1569 		emit q_ptr->entrySaved();
  1330 	} else if (error) {
  1570 	} else if (error) {
  1331 		mDataHandler->displayErrorMsg(error);
  1571 		mDataHandler->displayErrorMsg(error);
  1332 		return false;
  1572 		return false;
  1339 	Delete the entry 
  1579 	Delete the entry 
  1340 	@param closeEditor set true to close editor else default value is false
  1580 	@param closeEditor set true to close editor else default value is false
  1341  */
  1581  */
  1342 void CalenEditorPrivate::deleteEntry(bool close)
  1582 void CalenEditorPrivate::deleteEntry(bool close)
  1343 {
  1583 {
  1344 
       
  1345 	// if editor is launched from Notes then don't delete entry
  1584 	// if editor is launched from Notes then don't delete entry
  1346 	// Just exit from calendar editor
  1585 	// Just exit from calendar editor
  1347 	if (mOriginalEntry->id() > 0) {
  1586 	if (mOriginalEntry->id() > 0) {
  1348 
       
  1349 		// If user is editing single instanc then delete single instance 
  1587 		// If user is editing single instanc then delete single instance 
  1350 		// else delete entry
  1588 		// else delete entry
  1351 		if (showDeleteConfirmationQuery()) {
  1589 		if (mEditRange == ThisOnly) {
  1352 			if (mEditRange == ThisOnly) {
  1590 			// User wants to delete only this occurence
  1353 				// User wants to delete only this occurence
  1591 			mAgendaUtil->deleteRepeatedEntry(*mOriginalEntry,
  1354 				mAgendaUtil->deleteRepeatedEntry(*mOriginalEntry,
  1592 			                                 AgendaUtil::ThisOnly);
  1355 				                                 AgendaUtil::ThisOnly);
  1593 		} else {
  1356 			} else {
  1594 			// Delete the entry.
  1357 				// Delete the entry.
  1595 			mAgendaUtil->deleteEntry(mOriginalEntry->id());
  1358 				mAgendaUtil->deleteEntry(mOriginalEntry->id());
  1596 		}
  1359 			}
  1597 
  1360 
  1598 		if (close) {
  1361 			if (close) {
  1599 			closeEditor();
  1362 				closeEditor();
       
  1363 			}
       
  1364 		}
  1600 		}
  1365 	}
  1601 	}
  1366 }
  1602 }
  1367 
  1603 
  1368 /*!
  1604 /*!
  1380 	// Clone the entry to AllDay 
  1616 	// Clone the entry to AllDay 
  1381 
  1617 
  1382 	QDateTime tempSartTime =
  1618 	QDateTime tempSartTime =
  1383 	        CalenDateUtils::beginningOfDay(mEditedEntry->startTime());
  1619 	        CalenDateUtils::beginningOfDay(mEditedEntry->startTime());
  1384 
  1620 
  1385 	// Set EndTime of AllDay event to 23:59:59
  1621 	// Set EndTime of AllDay event to 00:00:00 of next day
  1386 	QDateTime tempEndTime = mEditedEntry->endTime();
  1622 	QDateTime tempEndTime = mEditedEntry->endTime().addDays(1);
  1387 	QTime tempEndQTime = tempEndTime.time();
  1623 	QTime tempEndQTime = tempEndTime.time();
  1388 	tempEndQTime.setHMS(23, 59, 59);
  1624 	tempEndQTime.setHMS(0, 0, 0);
  1389 	tempEndTime.setTime(tempEndQTime);
  1625 	tempEndTime.setTime(tempEndQTime);
  1390 
  1626 
  1391 	if (mNewEntry && (mAllDayCheckBoxItem->contentWidgetData("checkState")
  1627 	if (mNewEntry && (mAllDayCheckBoxItem->contentWidgetData("checkState")
  1392 	        == Qt::Checked)) {
  1628 	        == Qt::Checked)) {
  1393 		// changes Start/End times of entry to Beginning ot the day
  1629 		// changes Start/End times of entry to Beginning ot the day
  1401 		// changes Start/End times of entry to Beginning ot the day
  1637 		// changes Start/End times of entry to Beginning ot the day
  1402 		mEditedEntry->setStartAndEndTime(tempSartTime, tempEndTime);
  1638 		mEditedEntry->setStartAndEndTime(tempSartTime, tempEndTime);
  1403 
  1639 
  1404 		// Clone the entry to AllDayEntry, Delete old entry from Database
  1640 		// Clone the entry to AllDayEntry, Delete old entry from Database
  1405 		mAgendaUtil->cloneEntry(*mEditedEntry, AgendaEntry::TypeEvent);
  1641 		mAgendaUtil->cloneEntry(*mEditedEntry, AgendaEntry::TypeEvent);
  1406 		mAgendaUtil->deleteEntry(mEditedEntry->id());
  1642 		// For later reference for the notification popup
  1407 
  1643 		mEditedEntry->setType(AgendaEntry::TypeEvent);
  1408 		return true;
  1644 		return true;
  1409 	} else if ((mAllDayCheckBoxItem->contentWidgetData("checkState")
  1645 	} else if (mAllDayCheckBoxItem->contentWidgetData("checkState")
  1410 	        != Qt::Checked) && (mEditedEntry->type()
  1646 	        != Qt::Checked) {
  1411 	        != AgendaEntry::TypeAppoinment)) {
  1647              if (mEditedEntry->type() != AgendaEntry::TypeAppoinment) {
  1412 		// Editing exissting AllDayentry, and Alldat Box is Not-Checked
  1648 	            // Editing existing AllDayentry, and Alldat Box is Not-Checked
  1413 		// Clone the entry to MeetingEntry, Delete old entry from Database
  1649 	            // Clone the entry to MeetingEntry, Delete old entry from Database
  1414 		mAgendaUtil->cloneEntry(*mEditedEntry, AgendaEntry::TypeAppoinment);
  1650 	            mAgendaUtil->cloneEntry(*mEditedEntry, AgendaEntry::TypeAppoinment);
  1415 		mAgendaUtil->deleteEntry(mEditedEntry->id());
  1651 	            // For later reference for the notification popup
  1416 
  1652 	            mEditedEntry->setType(AgendaEntry::TypeAppoinment);
  1417 		return true;
  1653 	            return true;
  1418 	}
  1654 	        }
       
  1655             // Check if the duration of the meeting is matching the all-day criteria
       
  1656             // if yes, then we need to store it as all-day instead of normal meeting
       
  1657              else if (mEditedEntry->startTime() == CalenDateUtils::beginningOfDay(mEditedEntry->startTime())) {
       
  1658             // Get the end time and see if it is at the beginning of the end date day
       
  1659             if (mEditedEntry->endTime() == CalenDateUtils::beginningOfDay(mEditedEntry->endTime())) {
       
  1660                 // Store it as all-day
       
  1661                 mEditedEntry->setType(AgendaEntry::TypeEvent);
       
  1662                 // Check if this was an all-day earlier and now user has changed it like that
       
  1663                 // or it is a new entry
       
  1664                 if (mOriginalEntry->type() == AgendaEntry::TypeEvent ||
       
  1665                         mNewEntry) {
       
  1666                     return false;
       
  1667                 } else {
       
  1668                     // It was a meeting
       
  1669                     // Clone the entry to AllDayEntry, Delete old entry from Database
       
  1670                     mEditedEntry->setStartAndEndTime(tempSartTime, tempEndTime);
       
  1671                     mAgendaUtil->cloneEntry(*mEditedEntry, AgendaEntry::TypeEvent);
       
  1672                     // For later reference for the notification popup
       
  1673                     mEditedEntry->setType(AgendaEntry::TypeEvent);
       
  1674                     return true;
       
  1675                 }
       
  1676             }
       
  1677         } 
       
  1678 	} 
  1419 	return false;
  1679 	return false;
  1420 }
  1680 }
  1421 
  1681 
  1422 /*!
  1682 /*!
  1423  Enable/Disable TimeFields depending on AllDay checkbox state
  1683  Enable/Disable TimeFields depending on AllDay checkbox state
  1460  */
  1720  */
  1461 HbDataFormModelItem* CalenEditorPrivate::allDayCheckBoxItem()
  1721 HbDataFormModelItem* CalenEditorPrivate::allDayCheckBoxItem()
  1462 {
  1722 {
  1463 	return mAllDayCheckBoxItem;
  1723 	return mAllDayCheckBoxItem;
  1464 }
  1724 }
       
  1725 
       
  1726 /*!
       
  1727 	Checks if all day item is added and if selected implies reminder time is added.
       
  1728 	When editing single occurence irrespective of type of the event 
       
  1729 	the all day item is not shown.
       
  1730 	Used to calculate the index of other items which are dependant on this.
       
  1731  */
       
  1732 bool CalenEditorPrivate::isReminderTimeForAllDayAdded()
       
  1733 {
       
  1734 	return mReminderField->isReminderTimeForAllDayAdded();
       
  1735 }
       
  1736 
       
  1737 /*!
       
  1738 	Checks if it is an all day event or not.
       
  1739  */
       
  1740 bool CalenEditorPrivate::isAllDayEvent()
       
  1741 {
       
  1742 	if (mAllDayCheckBoxItem) {
       
  1743 		return (mAllDayCheckBoxItem->contentWidgetData("checkState") 
       
  1744 													== Qt::Checked)? true:false;
       
  1745 	} else if (!mNewEntry && mEditedEntry->type() == AgendaEntry::TypeEvent) {
       
  1746 		// If editing single occurence then all day item not shown but still it 
       
  1747 		// is an all day event..
       
  1748 		return true;;
       
  1749 	} else {
       
  1750 		return false;
       
  1751 	}
       
  1752 }
       
  1753 
       
  1754 /*!
       
  1755 	Returns the current index of the reminder field.
       
  1756  */
       
  1757 int CalenEditorPrivate::currentIndexOfReminderField()
       
  1758 {
       
  1759 	return mReminderField->currentReminderIndex();
       
  1760 }
       
  1761 
       
  1762 /*!
       
  1763 	Sets the index. 
       
  1764 	/param index indicates the index value to be set.
       
  1765  */
       
  1766 void CalenEditorPrivate::setCurrentIndexOfReminderField(int index)
       
  1767 {
       
  1768 	mReminderField->setCurrentIndex(index);
       
  1769 }
       
  1770 
       
  1771 /*!
       
  1772 	Sets the reminder choices for a non all day event.
       
  1773  */
       
  1774 void CalenEditorPrivate::setReminderChoices()
       
  1775 {
       
  1776 		mReminderField->setReminderChoices();
       
  1777 }
       
  1778 
       
  1779 /*!
       
  1780 	Checks if editing all occurences or a single occurence.
       
  1781  */
       
  1782 bool CalenEditorPrivate::isEditRangeThisOnly()
       
  1783 {
       
  1784 	return (mEditRange == ThisOnly);
       
  1785 }
       
  1786 
       
  1787 /*!
       
  1788 	Checks if all day field is added.
       
  1789  */
       
  1790 bool CalenEditorPrivate::isAllDayFieldAdded()
       
  1791 {
       
  1792 	return mIsAllDayItemAdded;
       
  1793 }
       
  1794 
  1465 // End of file	--Don't remove this.
  1795 // End of file	--Don't remove this.