clock/clockui/clockalarmeditor/src/clockalarmeditor.cpp
changeset 45 b6db4fd4947b
parent 18 c198609911f9
child 51 0b38fc5b94c6
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <QDateTime>
    19 #include <QDateTime>
    20 
       
    21 #include <HbDataForm>
    20 #include <HbDataForm>
    22 #include <HbDataFormModel>
    21 #include <HbDataFormModel>
    23 #include <HbDataFormModelItem>
    22 #include <HbDataFormModelItem>
    24 #include <HbDataFormViewItem>
    23 #include <HbDataFormViewItem>
    25 #include <HbInstance>
    24 #include <HbInstance>
    26 #include <HbAction>
    25 #include <HbAction>
    27 #include <HbMenu>
    26 #include <HbMenu>
    28 #include <HbToolBar>
       
    29 #include <HbLineEdit>
       
    30 #include <HbLabel>
    27 #include <HbLabel>
    31 #include <HbComboBox>
       
    32 #include <HbPushButton>
       
    33 #include <HbNotificationDialog>
    28 #include <HbNotificationDialog>
    34 #include <HbDialog>
    29 #include <HbDialog>
    35 #include <HbDateTimePicker>
    30 #include <HbDateTimePicker>
    36 #include <HbApplication>
    31 #include <HbCheckBox>
       
    32 #include <HbExtendedLocale>
       
    33 #include <HbGroupBox>
       
    34 #include <HbDocumentLoader>
       
    35 #include <HbTranslator>
    37 #include <xqsettingsmanager.h>
    36 #include <xqsettingsmanager.h>
    38 #include <xqsettingskey.h>
    37 #include <xqsettingskey.h>
    39 #include <QTranslator>
    38 
    40 
    39 
    41 // User includes
    40 // User includes
    42 #include "clockcommon.h"
    41 #include "clockprivatecrkeys.h"
    43 #include "clockalarmeditor.h"
    42 #include "clockalarmeditor.h"
    44 #include "alarmclient.h"
    43 #include "alarmclient.h"
    45 #include "settingsutility.h"
    44 #include "settingsutility.h"
    46 #include "timezoneclient.h"
    45 #include "timezoneclient.h"
    47 #include "clockalarmcustomitem.h"
    46 #include "clockalarmcustomitem.h"
    50 const int KOneHourInMinute(60);
    49 const int KOneHourInMinute(60);
    51 const int KOneMinuteInSecons(60);
    50 const int KOneMinuteInSecons(60);
    52 const int KOneMinute(1);
    51 const int KOneMinute(1);
    53 const int KOneHour(1);
    52 const int KOneHour(1);
    54 const int KSecondsInOneDay(24 * 60 * 60);
    53 const int KSecondsInOneDay(24 * 60 * 60);
       
    54 const int KDaysInWeek(7);
    55 
    55 
    56 /*!
    56 /*!
    57     \class ClockAlarmEditor
    57     \class ClockAlarmEditor
    58 
    58 
    59     This object loads the clock alarm editor view. The view is added to the top
    59     This object loads the clock alarm editor view. The view is added to the top
    66     \param parentViewIndex Previous view Index.
    66     \param parentViewIndex Previous view Index.
    67     \param alarmId Id of the alarm, if new alarm(0) or else id of alarm to be
    67     \param alarmId Id of the alarm, if new alarm(0) or else id of alarm to be
    68     edit.
    68     edit.
    69     \param parent The parent object.
    69     \param parent The parent object.
    70  */
    70  */
    71 ClockAlarmEditor::ClockAlarmEditor(int alarmId, QGraphicsWidget *parent)
    71 ClockAlarmEditor::ClockAlarmEditor(
    72 :HbView(parent),
    72 		AlarmClient &alarmClient, int alarmId,
       
    73 		QObject *parent)
       
    74 :QObject(parent),
    73  mAlarmId(alarmId),
    75  mAlarmId(alarmId),
       
    76  mStartOfWeek(0),
    74  mAlarmDayItemInserted(false),
    77  mAlarmDayItemInserted(false),
    75  mAlarmEditorForm(0),
    78  mAlarmEditorForm(0),
    76  mAlarmEditorModel(0),
    79  mAlarmEditorModel(0),
    77  mAlarmTimeItem(0),
    80  mAlarmTimeItem(0),
    78  mAlarmOccurenceItem(0),
    81  mAlarmOccurenceItem(0),
    79  mAlarmDayItem(0),
    82  mAlarmDayItem(0),
    80  mAlarmSoundItem(0),
    83  mAlarmSoundItem(0),
    81  mAlarmDescription(0),
    84  mAlarmDescription(0),
    82  mAlarmClient(0)
    85  mAlarmClient(alarmClient)
    83  {
    86 {
    84  	
       
    85  	// Load the translation file and install the alarmeditor specific translator
    87  	// Load the translation file and install the alarmeditor specific translator
    86 	mTranslator = new QTranslator;
    88 	mTranslator = new HbTranslator("clockalarmeditor");
    87 	//QString lang = QLocale::system().name();
    89 	mTranslator->loadCommon();
    88 	//QString path = "Z:/resource/qt/translations/";
    90 	
    89 	mTranslator->load("clockalarmeditor",":/translations");
       
    90 	// TODO: Load the appropriate .qm file based on locale
       
    91 	//bool loaded = mTranslator->load("caleneditor_" + lang, path);
       
    92 	HbApplication::instance()->installTranslator(mTranslator);
       
    93 
       
    94 	// Create the Alarm Editor DataForm.
       
    95 	mAlarmEditorForm = new HbDataForm(this);
       
    96 
       
    97 	// Set the title text of the Clock Alarm Editor view.
       
    98 	setTitle(hbTrId("txt_common_common_clock"));
       
    99 
       
   100 	// Create the alarm client object.
       
   101 	mAlarmClient = new AlarmClient(this);
       
   102 
       
   103 	// Set the heading of the Alarm Editor DataForm.
       
   104 	if (mAlarmId && mAlarmClient) {
       
   105 		mAlarmEditorForm->setHeading(
       
   106 				hbTrId("txt_clock_subhead_alarm"));
       
   107 	}
       
   108 	else
       
   109 	{
       
   110 		mAlarmEditorForm->setHeading(hbTrId("txt_clock_subhead_new_alarm"));
       
   111 	}
       
   112 
       
   113 	// create the timezone client object
    91 	// create the timezone client object
   114 	mTimezoneClient = new TimezoneClient(this);
    92 	mTimezoneClient = TimezoneClient::getInstance();
   115 	// Create the settings manager.
    93 	// Create the settings manager.
   116 	mSettingsManager = new XQSettingsManager(this);
    94 	mSettingsManager = new XQSettingsManager(this);
   117 
    95 
   118 	mPreviosAlarmTime = new XQSettingsKey(
    96 	mPreviosAlarmTime = new XQSettingsKey(
   119 			XQSettingsKey::TargetCentralRepository,
    97 			XQSettingsKey::TargetCentralRepository,
   122 
   100 
   123 	// Create settings utility object. To get the date & time format.
   101 	// Create settings utility object. To get the date & time format.
   124 	// TODO: do i need to delete this object ??
   102 	// TODO: do i need to delete this object ??
   125 	SettingsUtility *settingsUtil = new SettingsUtility(this);
   103 	SettingsUtility *settingsUtil = new SettingsUtility(this);
   126 	mTimeFormat = settingsUtil->timeFormatString();
   104 	mTimeFormat = settingsUtil->timeFormatString();
       
   105 	
       
   106 	// Get start of week from the locale.
       
   107     HbExtendedLocale locale = HbExtendedLocale::system();
       
   108     mStartOfWeek = locale.startOfWeek();
       
   109 
       
   110 	// Create the HbDocumentLoader object.
       
   111 	HbDocumentLoader *loader = new HbDocumentLoader();
       
   112 	bool success;
       
   113 	loader->load(":/xml/clockalarmeditor.docml", &success);
       
   114 
       
   115 	mAlarmEditorView = qobject_cast<HbView *>(
       
   116 			loader->findWidget("alarmEditorView"));
       
   117 
       
   118 	// Get the subtitle groupBox.
       
   119 	HbGroupBox *subtitleGroupBox = qobject_cast<HbGroupBox *>(
       
   120 			loader->findWidget("subtitleGroupBox"));
       
   121 
       
   122 	// Set the heading of the subtitle groupBox.
       
   123 	if (mAlarmId) {
       
   124 		subtitleGroupBox->setHeading(hbTrId("txt_clock_subhead_alarm"));
       
   125 	} else {
       
   126 		subtitleGroupBox->setHeading(hbTrId("txt_clock_subhead_new_alarm"));
       
   127 	}
       
   128 
       
   129 	// Get the Alarm Editor DataForm.
       
   130 	mAlarmEditorForm = qobject_cast<HbDataForm *> (
       
   131 			loader->findWidget("alarmEditorForm"));
       
   132 
   127 
   133 
   128 	// Create the alarm info structure with desired values.
   134 	// Create the alarm info structure with desired values.
   129 	initAlarmInfo();
   135 	initAlarmInfo();
   130 
   136 
   131 	// Creates & initializes the DataFormModel for the AlarmEditor DataForm.
   137 	// Creates & initializes the DataFormModel for the AlarmEditor DataForm.
   132 	initModel();
   138 	initModel();
   133 	
   139 
   134 	QList <HbAbstractViewItem*> prototypes = mAlarmEditorForm->itemPrototypes();
   140 	QList <HbAbstractViewItem*> prototypes = mAlarmEditorForm->itemPrototypes();
   135 	ClockAlarmCustomItem *customItem =
   141 	ClockAlarmCustomItem *customItem =
   136 			new ClockAlarmCustomItem(mAlarmEditorForm);
   142 			new ClockAlarmCustomItem(mAlarmEditorForm);
   137 	prototypes.append(customItem);
   143 	prototypes.append(customItem);
   138 	mAlarmEditorForm->setItemPrototypes(prototypes);
   144 	mAlarmEditorForm->setItemPrototypes(prototypes);
   139 
   145 
   140 	// Create the menu.
   146 	// Get the menu items for the alarm editor.
   141 	createMenu();
   147 	mDeleteAction = qobject_cast<HbAction *> (
       
   148 			loader->findObject("deleteAction"));
       
   149 	mDiscardAction = qobject_cast<HbAction *>(
       
   150 			loader->findObject("discardChanges"));
       
   151 
       
   152 	// Connect the signals for the menu item.
       
   153 	connect(
       
   154 			mDeleteAction, SIGNAL(triggered()),
       
   155 			this, SLOT(handleDeleteAction()));
       
   156 	connect(
       
   157 			mDiscardAction, SIGNAL(triggered()),
       
   158 			this, SLOT(handleDiscardAction()));
   142 
   159 
   143 	// Add the done soft key action.
   160 	// Add the done soft key action.
   144 	mDoneAction = new HbAction(Hb::DoneAction);
   161 	mDoneAction = new HbAction(Hb::DoneNaviAction);
   145 	connect(
   162 	connect(
   146 			mDoneAction, SIGNAL(triggered()),
   163 			mDoneAction, SIGNAL(triggered()),
   147 			this, SLOT(handleDoneAction()));
   164 			this, SLOT(handleDoneAction()));
   148 	setNavigationAction(mDoneAction);
   165 	mAlarmEditorView->setNavigationAction(mDoneAction);
   149 
   166 
   150 	// Sets the AlarmEditor DataForm to the Clock AlarmEditor view.
       
   151 	setWidget(mAlarmEditorForm);
       
   152 }
   167 }
   153 
   168 
   154 /*!
   169 /*!
   155     Destructor.
   170     Destructor.
   156  */
   171  */
   157 ClockAlarmEditor::~ClockAlarmEditor()
   172 ClockAlarmEditor::~ClockAlarmEditor()
   158 {
   173 {
   159 	if (mAlarmClient) {
       
   160 		delete mAlarmClient;
       
   161 		mAlarmClient = 0;
       
   162 	}
       
   163 	if(mTimezoneClient) {
       
   164 		delete mTimezoneClient;
       
   165 		mTimezoneClient = 0;
       
   166 	}
       
   167 	// Remove the translator
   174 	// Remove the translator
   168 	HbApplication::instance()->removeTranslator(mTranslator);
       
   169 	if (mTranslator) {
   175 	if (mTranslator) {
   170 		delete mTranslator;
   176 		delete mTranslator;
   171 		mTranslator = 0;
   177 		mTranslator = 0;
   172 	}
   178 	}
   173 
   179 
   178  */
   184  */
   179 void ClockAlarmEditor::showAlarmEditor()
   185 void ClockAlarmEditor::showAlarmEditor()
   180 {
   186 {
   181 	// Store the current view and set alarm editor as current view.
   187 	// Store the current view and set alarm editor as current view.
   182 	HbMainWindow *window = hbInstance->allMainWindows().first();
   188 	HbMainWindow *window = hbInstance->allMainWindows().first();
   183 	mPreviousView = window->currentView();
   189 	window->addView(mAlarmEditorView);
   184 	window->addView(this);
   190 	window->setCurrentView(mAlarmEditorView);
   185 	window->setCurrentView(this);
       
   186 }
   191 }
   187 
   192 
   188 /*!
   193 /*!
   189     Handles done action on the editor. Saves the alarm
   194     Handles done action on the editor. Saves the alarm
   190  */
   195  */
   191 void ClockAlarmEditor::handleDoneAction()
   196 void ClockAlarmEditor::handleDoneAction()
   192 {
   197 {
   193 	int alarmDayIndex = -1;
   198 	int alarmDayIndex = -1;
   194 	if (mAlarmDayItemInserted) {
   199 	if (mAlarmDayItemInserted) {
   195 		alarmDayIndex = mAlarmDayItem->contentWidgetData("currentIndex").toInt();
   200 		alarmDayIndex = mAlarmDayItem->contentWidgetData("currentIndex").toInt();
       
   201 		alarmDayIndex += mStartOfWeek;
       
   202 		if(alarmDayIndex >= KDaysInWeek){
       
   203 		   alarmDayIndex -= KDaysInWeek;
       
   204 		}
   196 	}
   205 	}
   197 
   206 
   198 	setAlarm(
   207 	setAlarm(
   199 			mAlarmTimeItem->contentWidgetData("text").toString(),
   208 			mAlarmTimeItem->contentWidgetData("text").toString(),
   200 			mAlarmDescription->contentWidgetData("text").toString(),
   209 			mAlarmDescription->contentWidgetData("text").toString(),
   227 	// Reset repeat info.
   236 	// Reset repeat info.
   228 	mAlarmOccurenceItem->setContentWidgetData("currentIndex", mAlarmInfo.repeatType);
   237 	mAlarmOccurenceItem->setContentWidgetData("currentIndex", mAlarmInfo.repeatType);
   229 
   238 
   230 	// Reset alarm day item.
   239 	// Reset alarm day item.
   231 	if (mAlarmDayItemInserted) {
   240 	if (mAlarmDayItemInserted) {
       
   241     	int currentIndex = mAlarmInfo.alarmDateTime.dayOfWeek() - 1;
       
   242         currentIndex -= mStartOfWeek;
       
   243         if(0 > currentIndex){
       
   244            currentIndex += KDaysInWeek;
       
   245         }
   232 		mAlarmDayItem->setContentWidgetData(
   246 		mAlarmDayItem->setContentWidgetData(
   233 				"currentIndex",
   247 				"currentIndex",currentIndex);
   234 				mAlarmInfo.alarmDateTime.dayOfWeek() - 1);
       
   235 	}
   248 	}
   236 
   249 
   237 	// Reset for alarm sound.
   250 	// Reset for alarm sound.
   238 	QStringList alarmSoundOptions;
       
   239 	alarmSoundOptions << tr("On")
       
   240 			<< tr("Off");
       
   241 
       
   242 	if (AlarmVolumeOn == mAlarmInfo.volumeStatus) {
   251 	if (AlarmVolumeOn == mAlarmInfo.volumeStatus) {
   243 		mAlarmSoundItem->setContentWidgetData("text", alarmSoundOptions[0]);
   252 		mAlarmSoundItem->setContentWidgetData("checkState", Qt::Checked);
   244 		mAlarmSoundItem->setContentWidgetData(
       
   245 				"additionalText", alarmSoundOptions[1]);
       
   246 	} else {
   253 	} else {
   247 		mAlarmSoundItem->setContentWidgetData("text", alarmSoundOptions[1]);
   254 		mAlarmSoundItem->setContentWidgetData("checkState", Qt::Unchecked);
   248 		mAlarmSoundItem->setContentWidgetData(
       
   249 				"additionalText", alarmSoundOptions[0]);
       
   250 	}
   255 	}
   251 
   256 
   252 	mAlarmDescription->setContentWidgetData("text", mAlarmInfo.alarmDesc);
   257 	mAlarmDescription->setContentWidgetData("text", mAlarmInfo.alarmDesc);
   253 }
   258 }
   254 
   259 
   278 		}
   283 		}
   279 		if (7 == alarmDayIndex) {
   284 		if (7 == alarmDayIndex) {
   280 			alarmDayIndex = 0;
   285 			alarmDayIndex = 0;
   281 		}
   286 		}
   282 		if (mAlarmDayItemInserted) {
   287 		if (mAlarmDayItemInserted) {
       
   288   		    alarmDayIndex -= mStartOfWeek;
       
   289 
       
   290             if(0 > alarmDayIndex){
       
   291                alarmDayIndex += KDaysInWeek;
       
   292             }
   283 			mAlarmDayItem->setContentWidgetData(
   293 			mAlarmDayItem->setContentWidgetData(
   284 					"currentIndex",
   294 					"currentIndex",
   285 					alarmDayIndex);
   295 					alarmDayIndex);
   286 		}
   296 		}
   287 	}
   297 	}
   318 			mAlarmDayItem = new HbDataFormModelItem(
   328 			mAlarmDayItem = new HbDataFormModelItem(
   319 					HbDataFormModelItem::ComboBoxItem,
   329 					HbDataFormModelItem::ComboBoxItem,
   320 					QString(hbTrId("txt_clock_formlabel_day")),
   330 					QString(hbTrId("txt_clock_formlabel_day")),
   321 					mAlarmEditorModel->invisibleRootItem());
   331 					mAlarmEditorModel->invisibleRootItem());
   322 
   332 
       
   333 			// Add the alarm days beginning from the start of week.
   323 			QStringList alarmDays;
   334 			QStringList alarmDays;
   324 			alarmDays << hbTrId("txt_clk_setlabel_val_monday")
   335 			sortAlarmDaysList(alarmDays);
   325 					<< hbTrId("txt_clk_setlabel_val_tuesday")
   336 			alarmDayIndex -= mStartOfWeek;
   326 					<< hbTrId("txt_clk_setlabel_val_wednesday")
   337 
   327 					<< hbTrId("txt_clk_setlabel_val_thursday")
   338 			if(0 > alarmDayIndex){
   328 					<< hbTrId("txt_clk_setlabel_val_friday")
   339 				alarmDayIndex += KDaysInWeek;
   329 					<< hbTrId("txt_clk_setlabel_val_saturday")
   340 			}
   330 					<< hbTrId("txt_clk_setlabel_val_sunday");
       
   331 
       
   332 			mAlarmDayItem->setContentWidgetData("items", alarmDays);
   341 			mAlarmDayItem->setContentWidgetData("items", alarmDays);
   333 			mAlarmDayItem->setContentWidgetData(
   342 			mAlarmDayItem->setContentWidgetData(
   334 					"currentIndex",
   343 					"currentIndex",
   335 					alarmDayIndex);
   344 					alarmDayIndex);
   336 
   345 
   349 		}
   358 		}
   350 	}
   359 	}
   351 }
   360 }
   352 
   361 
   353 /*!
   362 /*!
   354 	Called when `Cancel' is pressed on the Dialog.
       
   355  */
       
   356 void ClockAlarmEditor::handleCancelAction()
       
   357 {
       
   358 	// Close the dialog.
       
   359 	mTimePickerDialog->close();
       
   360 	mTimePickerDialog->deleteLater();
       
   361 }
       
   362 
       
   363 /*!
       
   364     Called when `OK' is pressed on the Dialog.
   363     Called when `OK' is pressed on the Dialog.
   365  */
   364  */
   366 void ClockAlarmEditor::handleOkAction()
   365 void ClockAlarmEditor::handleOkAction()
   367 {
   366 {
   368 	// Get the time from the time picker.
   367 	// Get the time from the time picker.
   370 			mTimePickerDialog->contentWidget())->time();
   369 			mTimePickerDialog->contentWidget())->time();
   371 
   370 
   372 	// Update the selected time value.
   371 	// Update the selected time value.
   373 	mAlarmTimeItem->setContentWidgetData("text",newAlarmTime.toString(mTimeFormat));
   372 	mAlarmTimeItem->setContentWidgetData("text",newAlarmTime.toString(mTimeFormat));
   374 
   373 
   375 	// Close the dialog.
       
   376 	handleCancelAction();
       
   377 
       
   378 	if (mAlarmInfo.nextDueTime != newAlarmTime ) {
   374 	if (mAlarmInfo.nextDueTime != newAlarmTime ) {
   379 		handleTimeChange(newAlarmTime.toString(mTimeFormat));
   375 		handleTimeChange(newAlarmTime.toString(mTimeFormat));
   380 	}
   376 	}
   381 }
   377 }
   382 
   378 
   383 /*!
   379 /*!
   384     Launches datetimepicker when Alarm time button is clicked.
   380     Launches datetimepicker when Alarm time button is clicked.
   385  */
   381  */
   386 void ClockAlarmEditor::launchTimePicker()
   382 void ClockAlarmEditor::launchTimePicker()
   387 {
   383 {
   388 
   384 	if (mTimePickerDialog) {
   389 
   385 		delete mTimePickerDialog;
   390 		if (mTimePickerDialog) {
   386 	}
   391 			delete mTimePickerDialog;
   387 
   392 		}
   388 	// Create the dialog.
   393 
   389 	mTimePickerDialog = new HbDialog;
   394 		// Create the dialog.
   390 	mTimePickerDialog->setTimeout(HbDialog::NoTimeout);
   395 		mTimePickerDialog = new HbDialog;
   391 	mTimePickerDialog->setDismissPolicy(HbDialog::NoDismiss);
   396 		mTimePickerDialog->setTimeout(HbDialog::NoTimeout);
   392 	mTimePickerDialog->setAttribute(Qt::WA_DeleteOnClose, true);
   397 		mTimePickerDialog->setDismissPolicy(HbDialog::NoDismiss);
   393 	// Set the heading for the dialog.
   398 
   394 	HbLabel * timeLabel =
   399 		// Set the heading for the dialog.
   395 		new HbLabel(hbTrId("txt_tumbler_title_alarm_time"),
   400 		HbLabel * timeLabel =
   396 			mTimePickerDialog);
   401 			new HbLabel(hbTrId("txt_tumbler_title_alarm_time"),
   397 	mTimePickerDialog->setHeadingWidget(timeLabel);
   402 			    mTimePickerDialog);
   398 
   403 		mTimePickerDialog->setHeadingWidget(timeLabel);
   399 	SettingsUtility *settingsUtil = new SettingsUtility(this);
   404 
   400 	QStringList timeSeparator;
   405 		SettingsUtility *settingsUtil = new SettingsUtility(this);
   401 	int index = settingsUtil->timeFormat(timeSeparator);
   406 		QStringList timeSeparator;
   402 	
   407 		int index = settingsUtil->timeFormat(timeSeparator);
   403 	QString tumblerDisplayFormat =
   408 		QString tumblerDisplayFormat =
   404 			mTimeFormat.replace(timeSeparator.at(index), QString("."));
   409 				mTimeFormat.replace(timeSeparator.at(index), QString("."));
   405 
   410 
   406 	// Create the tumbler.
   411 		// Create the tumbler.
   407 	HbDateTimePicker *timePicker = new HbDateTimePicker(mTimePickerDialog);
   412 		HbDateTimePicker *timePicker = new HbDateTimePicker(mTimePickerDialog);
   408 	timePicker->setDisplayFormat(tumblerDisplayFormat);
   413 		timePicker->setDisplayFormat(tumblerDisplayFormat);
   409 
   414 		// Set the tumbler as the content widget.
   410 	mTimePickerDialog->setContentWidget(timePicker);
   415 		mTimePickerDialog->setContentWidget(timePicker);
   411 
   416 		
   412 	QString timeString = mAlarmTimeItem->contentWidgetData("text").toString();
   417 		QString timeString = mAlarmTimeItem->contentWidgetData("text").toString();
   413 	QTime time = QTime::fromString(timeString, mTimeFormat);
   418 		QTime time = QTime::fromString(timeString, mTimeFormat);
   414 	timePicker->setTime(time);
   419 		timePicker->setTime(time);
   415 
   420 
   416 	mOkAction =
   421 		mOkAction =
   417 		new HbAction(QString(hbTrId("txt_common_button_ok")),
   422 			new HbAction(QString(hbTrId("txt_common_button_ok")),
   418 			mTimePickerDialog);
   423 			    mTimePickerDialog);
   419 
   424 		mTimePickerDialog->setPrimaryAction(mOkAction);
   420 	mCancelAction =
   425 		connect(
   421 		new HbAction(QString(hbTrId("txt_common_button_cancel")),
   426 				mOkAction, SIGNAL(triggered()),
   422 			mTimePickerDialog);
   427 				this, SLOT(handleOkAction()));
   423 
   428 
   424 	mTimePickerDialog->addAction(mOkAction);
   429 		mCancelAction =
   425 	mTimePickerDialog->addAction(mCancelAction);
   430 			new HbAction(QString(hbTrId("txt_common_button_cancel")),
   426 
   431 			    mTimePickerDialog);
   427 	mTimePickerDialog->open(this, SLOT(selectedAction(HbAction*)));
   432 		mTimePickerDialog->setSecondaryAction( mCancelAction );
       
   433 		connect(
       
   434 				mCancelAction, SIGNAL(triggered()),
       
   435 				this, SLOT(handleCancelAction()));
       
   436 
       
   437 		mTimePickerDialog->exec();
       
   438 
       
   439 
       
   440 }
   428 }
   441 
   429 
   442 /*!
   430 /*!
   443 	Handles the alarm sound change.
   431 	Handles the alarm sound change.
   444  */
   432  */
   445 void ClockAlarmEditor::handleAlarmSoundChanged()
   433 void ClockAlarmEditor::handleAlarmSoundChanged(int checkedState)
   446 {
   434 {
       
   435 	Q_UNUSED(checkedState)
   447 	if (AlarmVolumeOff == mAlarmInfo.volumeStatus) {
   436 	if (AlarmVolumeOff == mAlarmInfo.volumeStatus) {
   448 		mAlarmInfo.volumeStatus = AlarmVolumeOn;
   437 		mAlarmInfo.volumeStatus = AlarmVolumeOn;
   449 	} else {
   438 	} else {
   450 		mAlarmInfo.volumeStatus = AlarmVolumeOff;
   439 		mAlarmInfo.volumeStatus = AlarmVolumeOff;
       
   440 	}
       
   441 }
       
   442 
       
   443 /*!
       
   444 	Slot to handle the selected action
       
   445  */
       
   446 void ClockAlarmEditor::selectedAction(HbAction *action)
       
   447 {
       
   448 	if (action == mOkAction) {
       
   449 		handleOkAction();
   451 	}
   450 	}
   452 }
   451 }
   453 
   452 
   454 /*!
   453 /*!
   455 	Initialises the Model & sets for the AlarmEditorForm.
   454 	Initialises the Model & sets for the AlarmEditorForm.
   515 			mAlarmDayItem = mAlarmEditorModel->appendDataFormItem(
   514 			mAlarmDayItem = mAlarmEditorModel->appendDataFormItem(
   516 					HbDataFormModelItem::ComboBoxItem,
   515 					HbDataFormModelItem::ComboBoxItem,
   517 					QString(hbTrId("txt_clk_setlabel_day")),
   516 					QString(hbTrId("txt_clk_setlabel_day")),
   518 					mAlarmEditorModel->invisibleRootItem());
   517 					mAlarmEditorModel->invisibleRootItem());
   519 
   518 
       
   519 			// Add the alarm days beginning from the start of week.
   520 			QStringList alarmDays;
   520 			QStringList alarmDays;
   521 			alarmDays << hbTrId("txt_clk_setlabel_val_monday")
   521 			sortAlarmDaysList(alarmDays);
   522 					<< hbTrId("txt_clk_setlabel_val_tuesday")
   522 
   523 					<< hbTrId("txt_clk_setlabel_val_wednesday")
   523 			int currentIndex = mAlarmInfo.alarmDateTime.dayOfWeek() - 1;
   524 					<< hbTrId("txt_clk_setlabel_val_thursday")
   524 			currentIndex -= mStartOfWeek;
   525 					<< hbTrId("txt_clk_setlabel_val_friday")
   525 			if(0 > currentIndex){
   526 					<< hbTrId("txt_clk_setlabel_val_saturday")
   526 			   currentIndex += KDaysInWeek;
   527 					<< hbTrId("txt_clk_setlabel_val_sunday");
   527 			}
   528 
       
   529 			mAlarmDayItem->setContentWidgetData("items", alarmDays);
   528 			mAlarmDayItem->setContentWidgetData("items", alarmDays);
   530 			mAlarmDayItem->setContentWidgetData(
   529 			mAlarmDayItem->setContentWidgetData(
   531 					"currentIndex",
   530 					"currentIndex",currentIndex);
   532 					mAlarmInfo.alarmDateTime.dayOfWeek() - 1);
       
   533 
   531 
   534 			mAlarmDayItemInserted = true;
   532 			mAlarmDayItemInserted = true;
   535 		}/* else { TODO: check and remove this else block.
   533 		}/* else { TODO: check and remove this else block.
   536 			HbDataFormModelItem *dayItem = formItem(2);
   534 			HbDataFormModelItem *dayItem = formItem(2);
   537 			dayItem->setData(mAlarmInfo.alarmDateTime.dayOfWeek() - 1,
   535 			dayItem->setData(mAlarmInfo.alarmDateTime.dayOfWeek() - 1,
   541 	}
   539 	}
   542 
   540 
   543 
   541 
   544 	// Alarm sound.
   542 	// Alarm sound.
   545 	mAlarmSoundItem = mAlarmEditorModel->appendDataFormItem(
   543 	mAlarmSoundItem = mAlarmEditorModel->appendDataFormItem(
   546 			HbDataFormModelItem::ToggleValueItem,
   544 			HbDataFormModelItem::CheckBoxItem,
   547 			QString(hbTrId("txt_clk_setlabel_alarm_sound")),
   545 			QString(hbTrId("")),
   548 			mAlarmEditorModel->invisibleRootItem());
   546 			mAlarmEditorModel->invisibleRootItem());
   549 	QStringList alarmSoundOptions;
   547 
   550 	alarmSoundOptions << tr("On")
   548 	mAlarmSoundItem->setContentWidgetData(
   551 			<< tr("Off");
   549 			"text", QString(hbTrId("txt_clk_setlabel_alarm_sound")));
   552 
   550 
   553 	if (AlarmVolumeOn == mAlarmInfo.volumeStatus) {
   551 	if (AlarmVolumeOn == mAlarmInfo.volumeStatus) {
   554 		mAlarmSoundItem->setContentWidgetData("text", alarmSoundOptions[0]);
   552 		mAlarmSoundItem->setContentWidgetData("checkState",Qt::Checked);
   555 		mAlarmSoundItem->setContentWidgetData(
   553 	}
   556 				"additionalText", alarmSoundOptions[1]);
   554 
   557 	} else {
   555 	mAlarmEditorForm->addConnection(
   558 		mAlarmSoundItem->setContentWidgetData("text", alarmSoundOptions[1]);
   556 			mAlarmSoundItem, SIGNAL(stateChanged(int)),
   559 		mAlarmSoundItem->setContentWidgetData(
   557 			this,SLOT(handleAlarmSoundChanged(int)));
   560 				"additionalText", alarmSoundOptions[0]);
       
   561 	}
       
   562 
   558 
   563 	// Description.
   559 	// Description.
   564 	mAlarmDescription = mAlarmEditorModel->appendDataFormItem(
   560 	mAlarmDescription = mAlarmEditorModel->appendDataFormItem(
   565 			HbDataFormModelItem::TextItem,
   561 			HbDataFormModelItem::TextItem,
   566 			QString(hbTrId("txt_clk_formlabel_description")),
   562 			QString(hbTrId("txt_clk_formlabel_description")),
   590 			QTime::currentTime().toString(mTimeFormat), mTimeFormat);
   586 			QTime::currentTime().toString(mTimeFormat), mTimeFormat);
   591 	if (homeTime > alarmTime) {
   587 	if (homeTime > alarmTime) {
   592 		mAlarmInfo.alarmDateTime = mAlarmInfo.alarmDateTime.addDays(1);
   588 		mAlarmInfo.alarmDateTime = mAlarmInfo.alarmDateTime.addDays(1);
   593 	}
   589 	}
   594 
   590 
   595 	// Set the alarm volume on by default.
   591 	if (!mAlarmId) {
   596 	mAlarmInfo.volumeStatus = AlarmVolumeOn;
   592 		// Set the alarm volume On by default for new alarms..
       
   593 		mAlarmInfo.volumeStatus = AlarmVolumeOn;
       
   594 	}
   597 
   595 
   598 	// If editor state is a reset alarm, then its an already existing alarm
   596 	// If editor state is a reset alarm, then its an already existing alarm
   599 	// get the alarm details and fill it in mAlarmInfo.
   597 	// get the alarm details and fill it in mAlarmInfo.
   600 	if (mAlarmId && mAlarmClient) {
   598 	if (mAlarmId) {
   601 		mAlarmClient->getAlarmInfo(mAlarmId, mAlarmInfo);
   599 		mAlarmClient.getAlarmInfo(mAlarmId, mAlarmInfo);
   602 		mAlarmClient->deleteAlarm(mAlarmId);
   600 		mAlarmClient.deleteAlarm(mAlarmId);
   603 	}
   601 	}
   604 }
       
   605 
       
   606 /*!
       
   607     Creates menu items.
       
   608  */
       
   609 void ClockAlarmEditor::createMenu()
       
   610 {
       
   611 	// Set the menu for the alarm editor.
       
   612 	mDeleteAction = menu()->addAction(hbTrId("txt_clock_opt_delete"));
       
   613 	mDiscardAction = menu()->addAction(hbTrId("txt_clock_opt_discard_changes"));
       
   614 
       
   615 	// Connect the signals for the menu item.
       
   616 	connect(
       
   617 			mDeleteAction, SIGNAL(triggered()),
       
   618 			this, SLOT(handleDeleteAction()));
       
   619 	connect(
       
   620 			mDiscardAction, SIGNAL(triggered()),
       
   621 			this, SLOT(handleDiscardAction()));
       
   622 }
   602 }
   623 
   603 
   624 /*!
   604 /*!
   625 	Sets the alarm to the alarm server.
   605 	Sets the alarm to the alarm server.
   626  */
   606  */
   651 
   631 
   652 	// Fill the alarm volume status
   632 	// Fill the alarm volume status
   653 	alarmInfo.volumeStatus = mAlarmInfo.volumeStatus;
   633 	alarmInfo.volumeStatus = mAlarmInfo.volumeStatus;
   654 
   634 
   655 	// Request the listener to set the alarm.
   635 	// Request the listener to set the alarm.
   656 	mAlarmClient->setAlarm(alarmInfo);
   636 	mAlarmClient.setAlarm(alarmInfo);
   657 
   637 
   658 	// Check if DST rule gets applied in 24hrs.
   638 	// Check if DST rule gets applied in 24hrs.
   659 	// If so we don't display the remaining time.
   639 	// If so we don't display the remaining time.
   660 	bool displayDSTRolloverNote(false);
   640 	bool displayDSTRolloverNote(false);
   661 	// Check if DST rule gets applied in 24hrs.
   641 	// Check if DST rule gets applied in 24hrs.
   713 
   693 
   714 void ClockAlarmEditor::closeAlarmEditor()
   694 void ClockAlarmEditor::closeAlarmEditor()
   715 {
   695 {
   716 	// Remove the alarm editor.
   696 	// Remove the alarm editor.
   717 	HbMainWindow *window = hbInstance->allMainWindows().first();
   697 	HbMainWindow *window = hbInstance->allMainWindows().first();
   718 
   698 	window->removeView(mAlarmEditorView);
   719 	window->removeView(this);
   699 	deleteLater();
   720 	window->setCurrentView(mPreviousView);
       
   721 }
   700 }
   722 
   701 
   723 /*!
   702 /*!
   724 	Displays DST rollover note
   703 	Displays DST rollover note
   725 
   704 
   731 	QString alarmTime = alarmInfo.nextDueTime.toString(mTimeFormat);
   710 	QString alarmTime = alarmInfo.nextDueTime.toString(mTimeFormat);
   732 	QString dstRollOverText =
   711 	QString dstRollOverText =
   733 	hbTrId("txt_clock_dpopinfo_alarm_will_occur_at_1_after_au");
   712 	hbTrId("txt_clock_dpopinfo_alarm_will_occur_at_1_after_au");
   734 	QString displayText = dstRollOverText.arg(alarmTime);
   713 	QString displayText = dstRollOverText.arg(alarmTime);
   735 	// show the note
   714 	// show the note
   736 	HbNotificationDialog::launchDialog(displayText);
   715 	launchDialog(displayText);
   737 }
   716 }
   738 
   717 
   739 /*!
   718 /*!
   740 	Displays remaining time note after saving the alarm
   719 	Displays remaining time note after saving the alarm
   741 
   720 
   795 		break;
   774 		break;
   796 		default:
   775 		default:
   797 			break;
   776 			break;
   798 	}
   777 	}
   799 	if (Enabled == alarmInfo.alarmStatus && !(displayText.isEmpty())) {
   778 	if (Enabled == alarmInfo.alarmStatus && !(displayText.isEmpty())) {
   800 		//HbNotificationDialog::launchDialog(displayText);
       
   801 		showDisplayText = true;
   779 		showDisplayText = true;
   802 	}
   780 	}
   803 
   781 
   804 	QString remainingTimeText;
   782 	QString remainingTimeText;
   805 	// Dislpay the second note.
   783 	// Dislpay the second note.
   868 
   846 
   869 		if ( Enabled == alarmInfo.alarmStatus
   847 		if ( Enabled == alarmInfo.alarmStatus
   870 				&& 	!(remainingTimeText.isEmpty())) {
   848 				&& 	!(remainingTimeText.isEmpty())) {
   871 
   849 
   872 			if (!(displayText.isEmpty()) ) {
   850 			if (!(displayText.isEmpty()) ) {
   873 				HbNotificationDialog::launchDialog(
   851 				launchDialog(displayText, remainingTimeText);
   874 						displayText, remainingTimeText);
       
   875 				showDisplayText = false;
   852 				showDisplayText = false;
   876 			}
   853 			}
   877 			else {
   854 			else {
   878 				HbNotificationDialog::launchDialog(remainingTimeText);
   855 				launchDialog(remainingTimeText);
   879 			}
   856 			}
   880 		}
   857 		}
   881 	}
   858 	}
   882 	if (showDisplayText) {
   859 	if (showDisplayText) {
   883 		HbNotificationDialog::launchDialog(displayText);
   860 		launchDialog(displayText);
   884 	}
   861 	}
   885 }
   862 }
   886 
   863 
   887 /*!
   864 /*!
   888 	 gets day text for the week day
   865 	 gets day text for the week day
   939 
   916 
   940 	int remainingSeconds = alarmDateTimeSec - currentDateTimeSec;
   917 	int remainingSeconds = alarmDateTimeSec - currentDateTimeSec;
   941 	return remainingSeconds;
   918 	return remainingSeconds;
   942 }
   919 }
   943 
   920 
       
   921 /*!
       
   922 	Launches the soft notification.
       
   923  */
       
   924 void ClockAlarmEditor::launchDialog(QString title, QString text)
       
   925 {
       
   926 	HbNotificationDialog *notificationDialog = new HbNotificationDialog();
       
   927 	notificationDialog->setTitle(title);
       
   928 
       
   929 	if (!text.isNull()) {
       
   930 		notificationDialog->setText(text);
       
   931 	}
       
   932 
       
   933 	notificationDialog->setTimeout(HbPopup::ConfirmationNoteTimeout);
       
   934 	notificationDialog->show();
       
   935 }
       
   936 
       
   937 /*!
       
   938     Sorts and appends alarm days on the basis of start of week.
       
   939  */
       
   940 void ClockAlarmEditor::sortAlarmDaysList(QStringList& alarmDaysList)
       
   941 
       
   942 {
       
   943     for(int index=(mStartOfWeek + 1),j=KDaysInWeek;j!=0 ;index++,j--){
       
   944         if(index > KDaysInWeek){
       
   945            index = index - KDaysInWeek;
       
   946         }
       
   947         QString alarmDayText;
       
   948         getDayText(index, alarmDayText );
       
   949         alarmDaysList.append(alarmDayText);
       
   950     }
       
   951 }
   944 // End of file	--Don't remove this.
   952 // End of file	--Don't remove this.