alarmui/alarmalertwidget/alarmalertplugin/src/alarmalertwidget_p.cpp
branchRCL_3
changeset 65 12af337248b1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/alarmui/alarmalertwidget/alarmalertplugin/src/alarmalertwidget_p.cpp	Tue Aug 31 15:13:43 2010 +0300
@@ -0,0 +1,555 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+// alarmalertwidget_p.cpp
+
+// System includes
+#include <QApplication>
+#include <QGesture>
+#include <QGestureEvent>
+#include <QGraphicsSceneMouseEvent>
+
+#include <hbdocumentloader.h>
+#include <hbpushbutton.h>
+#include <hblabel.h>
+#include <hbinstance.h>
+#include <hbextendedlocale.h>
+#include <hbi18ndef.h>
+#include <hbaction.h>
+#include <hbtranslator.h>
+
+// User includes
+#include "alarmalertwidget_p.h"
+#include "alarmalert.h"
+#include "alarmalertdocloader.h"
+#include "OstTraceDefinitions.h"
+#ifdef OST_TRACE_COMPILER_IN_USE
+#include "alarmalertwidget_pTraces.h"
+#endif
+
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::AlarmAlertDialogPrivate
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+AlarmAlertDialogPrivate::AlarmAlertDialogPrivate(const QVariantMap &parameters):
+	mTranslator(new HbTranslator("alarmui")),
+	mClosedByClient(false),
+	mIsSilenceKey(false)
+	{
+	OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_ALARMALERTDIALOGPRIVATE_ENTRY );
+	// Extract all the parameters sent by the client
+	parseAndFetchParams(parameters);
+
+	// Set the dismiss policy and timeout property
+	setDismissPolicy(HbPopup::NoDismiss);
+	setTimeout(HbPopup::NoTimeout);
+	
+	// Listen the signal when alarmui is about to display so that we can start playing the alarm tone.
+	connect(this, SIGNAL(aboutToShow()), this, SLOT(aboutToDisplay()) );
+
+	// Initialize the user response
+	mUserResponse = Other;
+
+	// TODO: Gestures not working. Integrate once support is available from Qt
+	grabGesture(Qt::SwipeGesture);
+	OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_ALARMALERTDIALOGPRIVATE_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::~AlarmAlertDialogPrivate
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+AlarmAlertDialogPrivate::~AlarmAlertDialogPrivate()
+{
+    OstTraceFunctionEntry0( DUP1_ALARMALERTDIALOGPRIVATE_ALARMALERTDIALOGPRIVATE_ENTRY );
+    // Cleanup
+	if (mAlertDocLoader) {
+		delete mAlertDocLoader;
+	}
+    // Cancel any ongoing animations
+    HbEffect::cancel(mSlider, "slideDownPortrait", false, false, false);
+    HbEffect::cancel(mSlider, "slideDownLandscape", false, false, false);
+    
+    // Remove the effect
+    HbEffect::remove(mSlider);
+
+	// Remove the translator
+	if (mTranslator) {
+		delete mTranslator;
+		mTranslator = 0;
+	}
+	OstTraceFunctionExit0( DUP1_ALARMALERTDIALOGPRIVATE_ALARMALERTDIALOGPRIVATE_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::setDeviceDialogParameters
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+bool AlarmAlertDialogPrivate::setDeviceDialogParameters(const QVariantMap &parameters)
+{
+    OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_SETDEVICEDIALOGPARAMETERS_ENTRY );
+    Q_UNUSED(parameters);
+    
+    //TODO: Handle parameters to be set
+    OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_SETDEVICEDIALOGPARAMETERS_EXIT );
+    return 0;
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::deviceDialogError
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+int AlarmAlertDialogPrivate::deviceDialogError() const
+{
+    OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_DEVICEDIALOGERROR_ENTRY );
+    // TODO: Return any errors that might have occured
+    OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_DEVICEDIALOGERROR_EXIT );
+    return 0;
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::AlarmAlertDialogPrivate
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+void AlarmAlertDialogPrivate::closeDeviceDialog(bool byClient)
+{
+    OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_CLOSEDEVICEDIALOG_ENTRY );
+    Q_UNUSED(byClient);
+    mClosedByClient = byClient;
+	close();
+	OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_CLOSEDEVICEDIALOG_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::deviceDialogWidget
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+HbDialog *AlarmAlertDialogPrivate::deviceDialogWidget() const
+{
+    OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_DEVICEDIALOGWIDGET_ENTRY );
+    return const_cast<AlarmAlertDialogPrivate*> (this);
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::showEvent
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+void AlarmAlertDialogPrivate::showEvent(QShowEvent *event)
+{
+	OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_SHOWEVENT_ENTRY );
+	HbDialog::showEvent(event);
+	QVariantMap param;
+	param.insert(alarmCommand, mUserResponse);
+	emit deviceDialogData(param);
+	OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_SHOWEVENT_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::closeEvent
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+void AlarmAlertDialogPrivate::closeEvent(QCloseEvent *event)
+{
+    OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_CLOSEEVENT_ENTRY );
+    
+	// Do not notify the client back if the close was initiated by client itself
+	if(!mClosedByClient) {
+		// Package the user response and send it
+		QVariantMap param;
+		param.insert(alarmCommand, mUserResponse);
+		emit deviceDialogData(param);
+	}
+	// This signal has to be emitted so that the dialog can be cleaned up later
+	emit deviceDialogClosed();
+	
+	// Forward the call to the base class
+	HbDialog::closeEvent(event);
+	OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_CLOSEEVENT_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::handleOrientationChange
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+void AlarmAlertDialogPrivate::handleOrientationChange ()
+{
+    OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_HANDLEORIENTATIONCHANGE_ENTRY );
+    // TODO: Need to change this as per the UI concept
+    OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_HANDLEORIENTATIONCHANGE_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::snoozed
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+void AlarmAlertDialogPrivate::snoozed()
+{
+	OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_SNOOZED_ENTRY );
+	mUserResponse = Snooze;
+	close();
+	OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_SNOOZED_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::silenced
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+void AlarmAlertDialogPrivate::silenced()
+{
+	OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_SILENCED_ENTRY );
+	if (mIsSilenceKey) {
+		mUserResponse = Silence;
+		mSnoozeAction->setText(hbTrId("txt_calendar_button_alarm_snooze"));
+		mIsSilenceKey = false;
+		QVariantMap param;
+		param.insert(alarmCommand, mUserResponse);
+		emit deviceDialogData(param);
+	}else {
+		mUserResponse = Snooze;
+		close();
+	}
+	OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_SILENCED_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::aboutToDisplay
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+void AlarmAlertDialogPrivate::aboutToDisplay()
+    {
+    OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_ABOUTTODISPLAY_ENTRY );
+    mUserResponse = Shown;
+    QVariantMap param;
+    param.insert(alarmCommand, mUserResponse);
+    emit deviceDialogData(param);
+    OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_ABOUTTODISPLAY_EXIT );
+    }
+	
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::dismissed
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+void AlarmAlertDialogPrivate::dismissed()
+{
+	OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_DISMISSED_ENTRY );
+	mUserResponse = Stop;
+	close();
+	OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_DISMISSED_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::parseAndFetchParams
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+void AlarmAlertDialogPrivate::parseAndFetchParams(const QVariantMap &parameters)
+{
+    OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_PARSEANDFETCHPARAMS_ENTRY );
+    // Iterate thru the list and extract all relevant parameters
+    QVariantMap::const_iterator iter = parameters.constBegin();
+    int count = parameters.size();
+    while (iter != parameters.constEnd()) {
+        QString key(iter.key());
+        if (alarmSubject == key) {
+            mSubject = iter.value().toString();
+        } else if (alarmLocation == key) {
+            mLocation = iter.value().toString();
+        } else if (alarmTime == key) {
+            mAlarmTime = iter.value().toString();
+        } else if (alarmDate == key) {
+            mAlarmDate = iter.value().toString();
+        } else if (alarmType == key) {
+            mAlarmAlertType = static_cast <AlarmType> (iter.value().toInt());
+        } else if (alarmCanSnooze == key) {
+            mCanSnooze = iter.value().toBool();
+        } else if (alarmRingingType == key) {
+            mIsSilent = iter.value().toBool();
+        } else if (alarmIsTimed == key) {
+            mIsTimedAlarm = iter.value().toBool();
+        }else {
+            break;
+        }
+        iter++;
+    }
+    OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_PARSEANDFETCHPARAMS_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::setupNormalUI
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+
+void AlarmAlertDialogPrivate::setupNormalUI(AlarmAlertDocLoader *alertDocLoader)
+    {
+	OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_SETUPNORMALUI_ENTRY );
+	if(!alertDocLoader) {
+		// Nothing can be done. Simply return
+		OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_SETUPNORMALUI_EXIT );
+		return;
+	}
+	mAlertDocLoader = alertDocLoader;
+
+	if (mAlarmAlertType == ClockAlarm) {
+        handleClockAlarms();
+    }else if(mAlarmAlertType == TodoAlarm) {
+        handleToDoAlarms();
+    }else if(mAlarmAlertType == CalendarAlarm) {
+    	handleCalendarAlarms();
+    }
+	OstTraceFunctionExit0( DUP1_ALARMALERTDIALOGPRIVATE_SETUPNORMALUI_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::handleClockAlarms
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+void AlarmAlertDialogPrivate::handleClockAlarms()
+{
+	OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_HANDLECLOCKALARMS_ENTRY );
+	QGraphicsWidget *headingWidget = mAlertDocLoader->findWidget("heading");
+	if (!headingWidget) {
+		qFatal("Unable to load the heading Widget");
+	}
+
+	mAlarmDateTime = qobject_cast<HbLabel*> (
+			mAlertDocLoader->findWidget("alarmTime"));
+	if (!mAlarmDateTime) {
+		qFatal("Unable to load the alarmTime label");
+	}
+	HbExtendedLocale locale = HbExtendedLocale::system();
+
+	mAlarmDateTime->setPlainText(mAlarmTime);
+	
+	mAlarmDescription = qobject_cast<HbLabel*> (
+			mAlertDocLoader->findWidget("alarmDescription"));
+	if (!mAlarmDescription) {
+		qFatal("Unable to load the alarmDescription label");
+	}
+	mAlarmDescription->setPlainText(mSubject);
+
+	mAlarmIcon = qobject_cast<HbLabel*> (
+				mAlertDocLoader->findWidget("alarmIcon"));
+	if (!mAlarmIcon) {
+		qFatal("Unable to load the alarm icon");
+	}
+
+	HbAction *snoozeAction = qobject_cast<HbAction*> (
+			mAlertDocLoader->findObject("snoozeAction"));
+	if (!snoozeAction) {
+		qFatal("Unable to load the snoozeAction softkey");
+	}
+	snoozeAction->setText(hbTrId("txt_calendar_button_alarm_snooze"));
+	disconnect(snoozeAction, SIGNAL(triggered()), this, SLOT(close()));
+	connect(snoozeAction, SIGNAL(triggered()), this, SLOT(snoozed()));
+
+	HbAction *stopAction = qobject_cast<HbAction*> (
+			mAlertDocLoader->findObject("stopAction"));
+	if (!stopAction) {
+		qFatal("Unable to load the stopAction softkey");
+	}
+	stopAction->setText(hbTrId("txt_calendar_button_alarm_stop"));
+	disconnect(stopAction, SIGNAL(triggered()), this, SLOT(close()));
+	connect(stopAction, SIGNAL(triggered()), this, SLOT(dismissed()));
+
+	if (!mCanSnooze) {
+		snoozeAction->setVisible(false);
+	}
+	OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_HANDLECLOCKALARMS_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::handleCalendarAlarms
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+void AlarmAlertDialogPrivate::handleCalendarAlarms()
+{
+	OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_HANDLECALENDARALARMS_ENTRY );
+	bool success = false;
+	HbExtendedLocale locale = HbExtendedLocale::system();
+	// Check if the alarm has the time info or not.
+	// For all day events the time label has to be hidden
+	// So load the proper sections accordingly
+	if ( mIsTimedAlarm ) {
+		mAlertDocLoader->load(
+				alarmNormalUICalendarDocml, "calendarTimed",&success);
+		if (!success) {
+			qFatal("Unable to load the calendarTimed section");
+		}
+		mAlarmDateTime = qobject_cast<HbLabel*> (
+				mAlertDocLoader->findWidget("alarmTime"));
+		if (!mAlarmDateTime) {
+			qFatal("Unable to find the alarmTime label");
+		}
+		mAlarmDateTime->setPlainText(mAlarmTime);
+		HbLabel *alarmDate = qobject_cast<HbLabel*> (
+				mAlertDocLoader->findWidget("alarmDate"));
+		if (!alarmDate) {
+			qFatal("Unable to find the alarmDate label");
+		}
+		alarmDate->setPlainText(mAlarmDate);
+	}else {
+		mAlertDocLoader->load(
+				alarmNormalUICalendarDocml, "nonTimedAlarm",&success);
+		if (!success) {
+			qFatal("Unable to load the nonTimedAlarm section");
+		}
+		mAlarmDateTime = qobject_cast<HbLabel*> (
+				mAlertDocLoader->findWidget("alarmTime"));
+		if (!mAlarmDateTime) {
+			qFatal("Unable to find the alarmTime label");
+		}
+		mAlarmDateTime->hide();
+		HbLabel *alarmDate = qobject_cast<HbLabel*> (
+				mAlertDocLoader->findWidget("alarmDate"));
+		if (!alarmDate) {
+			qFatal("Unable to find the alarmDate label");
+		}
+		alarmDate->setPlainText(mAlarmDate);
+	}
+
+	QGraphicsWidget *headingWidget = mAlertDocLoader->findWidget("heading");
+	if (!headingWidget) {
+		qFatal("Unable to find the heading widget");
+	}
+	mAlarmDescription = qobject_cast<HbLabel*> (
+			mAlertDocLoader->findWidget("alarmDescription"));
+	if (!mAlarmDescription) {
+		qFatal("Unable to find the alarmDescription label");
+	}
+	mAlarmDescription->setPlainText(mSubject);
+
+	HbLabel *alarmLocation = qobject_cast<HbLabel*> (
+			mAlertDocLoader->findWidget("alarmLocation"));
+	if (!alarmLocation) {
+		qFatal("Unable to find the alarmLocation label");
+	}
+	alarmLocation->setPlainText(mLocation);
+	
+	mAlarmIcon = qobject_cast<HbLabel*> (
+			mAlertDocLoader->findWidget("alarmIcon"));
+	if (!mAlarmIcon) {
+		qFatal("Unable to find the alarm Icon");
+	}
+
+	mSnoozeAction = qobject_cast<HbAction*> (
+			mAlertDocLoader->findObject("snoozeAction"));
+	if (!mSnoozeAction) {
+		qFatal("Unable to find the snoozeAction softkey");
+	}
+	disconnect(mSnoozeAction, SIGNAL(triggered()), this, SLOT(close()));
+	if (!mCanSnooze) {
+		mSnoozeAction->setVisible(false);
+	}else { 
+		if(!mIsSilent) {
+			mSnoozeAction->setText(hbTrId("txt_calendar_button_alarm_silence"));
+			connect(mSnoozeAction, SIGNAL(triggered()), this, SLOT(silenced()));
+			mIsSilenceKey = true;
+		} 	else {
+			mSnoozeAction->setText(hbTrId("txt_calendar_button_alarm_snooze"));
+			connect(mSnoozeAction, SIGNAL(triggered()), this, SLOT(snoozed()));
+		}
+	}
+	HbAction *stopAction = qobject_cast<HbAction*> (
+			mAlertDocLoader->findObject("stopAction"));
+	if (!stopAction) {
+		qFatal("Unable to find the stopAction softkey");
+	}
+	stopAction->setText(hbTrId("txt_calendar_button_alarm_stop"));
+	disconnect(stopAction, SIGNAL(triggered()), this, SLOT(close()));
+	connect(stopAction, SIGNAL(triggered()), this, SLOT(dismissed()));
+	OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_HANDLECALENDARALARMS_EXIT );
+}
+
+// ---------------------------------------------------------
+// AlarmAlertDialogPrivate::handleToDoAlarms
+// rest of the details are commented in the header
+// ---------------------------------------------------------
+//
+void AlarmAlertDialogPrivate::handleToDoAlarms()
+{
+	OstTraceFunctionEntry0( ALARMALERTDIALOGPRIVATE_HANDLETODOALARMS_ENTRY );
+	QGraphicsWidget *headingWidget = mAlertDocLoader->findWidget("heading");
+	if (!headingWidget) {
+		qFatal("Unable to load the heading widget");
+	}
+	HbExtendedLocale locale = HbExtendedLocale::system();
+	
+	HbLabel *alarmDate = qobject_cast<HbLabel*> (
+							mAlertDocLoader->findWidget("alarmDate"));
+	if (!alarmDate) {
+		qFatal("Unable to load the alarmDate label");
+	}
+	alarmDate->setPlainText(mAlarmDate);
+	
+	mAlarmDescription = qobject_cast<HbLabel*> (
+							mAlertDocLoader->findWidget("alarmDescription"));
+	if (!mAlarmDescription) {
+		qFatal("Unable to load the alarmDescription label");
+	}
+	mAlarmDescription->setPlainText(mSubject);
+	
+	mAlarmIcon = qobject_cast<HbLabel*> (
+									mAlertDocLoader->findWidget("alarmIcon"));
+	if (!mAlarmIcon) {
+		qFatal("Unable to load the alarm Icon");
+	}
+	mSnoozeAction = qobject_cast<HbAction*> (
+								mAlertDocLoader->findObject("snoozeAction"));
+	if (!mSnoozeAction) {
+		qFatal("Unable to load the snoozeAction softkey");
+	}
+	disconnect(mSnoozeAction, SIGNAL(triggered()), this, SLOT(close()));
+	if (!mCanSnooze) {
+		mSnoozeAction->setVisible(false);
+	}else { 
+		if(!mIsSilent) {
+			mSnoozeAction->setText(hbTrId("txt_calendar_button_alarm_silence"));
+			connect(mSnoozeAction, SIGNAL(triggered()), this, SLOT(silenced()));
+			mIsSilenceKey = true;
+		} 	else {
+			mSnoozeAction->setText(hbTrId("txt_calendar_button_alarm_snooze"));
+			connect(mSnoozeAction, SIGNAL(triggered()), this, SLOT(snoozed()));
+		}
+	}
+	HbAction *stopAction = qobject_cast<HbAction*> (
+									mAlertDocLoader->findObject("stopAction"));
+	if (!stopAction) {
+		qFatal("Unable to load the stopAction softkey");
+	}
+	stopAction->setText(hbTrId("txt_calendar_button_alarm_stop"));
+	disconnect(stopAction, SIGNAL(triggered()), this, SLOT(close()));
+	connect(stopAction, SIGNAL(triggered()), this, SLOT(dismissed()));
+	OstTraceFunctionExit0( ALARMALERTDIALOGPRIVATE_HANDLETODOALARMS_EXIT );
+}
+
+// End of file  --Don't remove this.