|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 // alarmalertwidget.cpp |
|
18 |
|
19 // System includes |
|
20 #include <hbsymbianvariant.h> |
|
21 |
|
22 // User includes |
|
23 #include "alarmalertwidget.h" |
|
24 #include "alarmalert.h" |
|
25 #include "alarmalertobserver.h" |
|
26 #include "OstTraceDefinitions.h" |
|
27 #ifdef OST_TRACE_COMPILER_IN_USE |
|
28 #include "alarmalertwidgetTraces.h" |
|
29 #endif |
|
30 |
|
31 // Constants. |
|
32 const TInt KMaxlength=30; |
|
33 |
|
34 // --------------------------------------------------------- |
|
35 // AlarmAlertWidget::AlarmAlertWidget |
|
36 // rest of the details are commented in the header |
|
37 // --------------------------------------------------------- |
|
38 // |
|
39 AlarmAlertWidget::AlarmAlertWidget(AlarmAlertObserver *observer) : |
|
40 mObserver(observer) |
|
41 { |
|
42 OstTraceFunctionEntry0( ALARMALERTWIDGET_ALARMALERTWIDGET_ENTRY ); |
|
43 OstTraceFunctionExit0( ALARMALERTWIDGET_ALARMALERTWIDGET_EXIT ); |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------- |
|
47 // AlarmAlertWidget::~AlarmAlertWidget |
|
48 // rest of the details are commented in the header |
|
49 // --------------------------------------------------------- |
|
50 // |
|
51 AlarmAlertWidget::~AlarmAlertWidget() |
|
52 { |
|
53 OstTraceFunctionEntry0( DUP1_ALARMALERTWIDGET_ALARMALERTWIDGET_ENTRY ); |
|
54 // Cleanup |
|
55 |
|
56 if (mAlarmSubject) { |
|
57 delete mAlarmSubject; |
|
58 } |
|
59 |
|
60 if (mLocation) { |
|
61 delete mLocation; |
|
62 } |
|
63 |
|
64 if (mAlarmTime) { |
|
65 delete mAlarmTime; |
|
66 } |
|
67 |
|
68 if (mAlarmDate) { |
|
69 delete mAlarmDate; |
|
70 } |
|
71 |
|
72 if (mAlarmAlertType) { |
|
73 delete mAlarmAlertType; |
|
74 } |
|
75 |
|
76 if (mCanSnooze) { |
|
77 delete mCanSnooze; |
|
78 } |
|
79 |
|
80 if (mIsSilent) { |
|
81 delete mIsSilent; |
|
82 } |
|
83 |
|
84 if (mIsTimedAlarm) { |
|
85 delete mIsTimedAlarm; |
|
86 } |
|
87 |
|
88 if (mVariantMap) { |
|
89 delete mVariantMap; |
|
90 } |
|
91 |
|
92 if (mDeviceDialog) { |
|
93 delete mDeviceDialog; |
|
94 } |
|
95 OstTraceFunctionExit0( DUP1_ALARMALERTWIDGET_ALARMALERTWIDGET_EXIT ); |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------- |
|
99 // AlarmAlertWidget::ShowAlarmDialog |
|
100 // rest of the details are commented in the header |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 bool AlarmAlertWidget::showAlarmDialog(SAlarmInfo *alarmInfo) |
|
104 { |
|
105 OstTraceFunctionEntry0( ALARMALERTWIDGET_SHOWALARMDIALOG_ENTRY ); |
|
106 // Get the alarm date and time |
|
107 TBuf<KMaxlength> timeString; |
|
108 TBuf<KMaxlength> dateString; |
|
109 |
|
110 TBuf<KMaxlength> timeFormat(_L("%-B%:0%J%:1%T%:3%+B")); |
|
111 TBuf<KMaxlength> dateFormat; |
|
112 TLocale locale; |
|
113 switch (locale.DateFormat()) { |
|
114 case EDateEuropean: |
|
115 dateFormat.Copy(_L("%F%/0%D%/1%M%/2%Y%/3")); |
|
116 break; |
|
117 case EDateAmerican: |
|
118 dateFormat.Copy(_L("%F%/0%M%/1%D%/2%Y%/3")); |
|
119 break; |
|
120 case EDateJapanese: |
|
121 dateFormat.Copy(_L("%F%/0%Y%/1%M%/2%D%/3")); |
|
122 break; |
|
123 default: |
|
124 // Nothing yet. |
|
125 break; |
|
126 } |
|
127 |
|
128 |
|
129 alarmInfo->iTime.FormatL(timeString, timeFormat); |
|
130 alarmInfo->iTime.FormatL(dateString, dateFormat); |
|
131 |
|
132 // Create a session with the device dialog server |
|
133 mDeviceDialog = CHbDeviceDialogSymbian::NewL(); |
|
134 |
|
135 |
|
136 // Package the different parameters to send |
|
137 mVariantMap = CHbSymbianVariantMap::NewL(); |
|
138 |
|
139 // Get the subject of the alarm (description for clock alarms |
|
140 // and subject for calendar alarms) |
|
141 mAlarmSubject = CHbSymbianVariant::NewL( |
|
142 alarmInfo->iSubject, CHbSymbianVariant::EDes ); |
|
143 mVariantMap->Add(alarmSubjectSymbian, mAlarmSubject); |
|
144 |
|
145 // Get the location (for calendar alarms) |
|
146 mLocation = CHbSymbianVariant::NewL( |
|
147 alarmInfo->iLocation, CHbSymbianVariant::EDes); |
|
148 mVariantMap->Add(alarmLocationSymbian, mLocation); |
|
149 |
|
150 mAlarmTime = CHbSymbianVariant::NewL( |
|
151 &timeString, CHbSymbianVariant::EDes); |
|
152 mVariantMap->Add(alarmTimeSymbian, mAlarmTime); |
|
153 |
|
154 mAlarmDate = CHbSymbianVariant::NewL( |
|
155 &dateString, CHbSymbianVariant::EDes); |
|
156 mVariantMap->Add(alarmDateSymbian, mAlarmDate); |
|
157 |
|
158 mIsSilent = CHbSymbianVariant::NewL( |
|
159 &alarmInfo->iIsSilent, CHbSymbianVariant::EBool); |
|
160 mVariantMap->Add(alarmRingingTypeSymbian, mIsSilent); |
|
161 |
|
162 mCanSnooze = CHbSymbianVariant::NewL( |
|
163 &alarmInfo->iCanSnooze, CHbSymbianVariant::EBool); |
|
164 mVariantMap->Add(alarmCanSnoozeSymbain, mCanSnooze); |
|
165 |
|
166 mAlarmAlertType = CHbSymbianVariant::NewL( |
|
167 &alarmInfo->iAlarmAlertType, CHbSymbianVariant::EInt); |
|
168 mVariantMap->Add(alarmTypeSymbian, mAlarmAlertType); |
|
169 |
|
170 mIsTimedAlarm = CHbSymbianVariant::NewL( |
|
171 &alarmInfo->iIsTimed, CHbSymbianVariant::EBool); |
|
172 mVariantMap->Add(alarmIsTimedSymbian, mIsTimedAlarm); |
|
173 |
|
174 // Package the different parameters to send |
|
175 return mDeviceDialog->Show(ALARM_ALERT_PLUGIN_SYMBIAN, *mVariantMap, this); |
|
176 |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------- |
|
180 // AlarmAlertWidget::DismissAlarmDialog |
|
181 // rest of the details are commented in the header |
|
182 // --------------------------------------------------------- |
|
183 // |
|
184 void AlarmAlertWidget::dismissAlarmDialog() |
|
185 { |
|
186 OstTraceFunctionEntry0( ALARMALERTWIDGET_DISMISSALARMDIALOG_ENTRY ); |
|
187 // Dismiss the dialog |
|
188 mDeviceDialog->Cancel(); |
|
189 OstTraceFunctionExit0( ALARMALERTWIDGET_DISMISSALARMDIALOG_EXIT ); |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------- |
|
193 // AlarmAlertWidget::UpdateAlarmDialog |
|
194 // rest of the details are commented in the header |
|
195 // --------------------------------------------------------- |
|
196 // |
|
197 bool AlarmAlertWidget::updateAlarmDialog(SAlarmInfo* /*alarmInfo*/) |
|
198 { |
|
199 OstTraceFunctionEntry0( ALARMALERTWIDGET_UPDATEALARMDIALOG_ENTRY ); |
|
200 // Update the dialog with any new information |
|
201 // TODO: Pass the updated information sent by the observer |
|
202 /*CHbSymbianVariantMap params; |
|
203 mDeviceDialog->Update(params);*/ |
|
204 OstTraceFunctionExit0( ALARMALERTWIDGET_UPDATEALARMDIALOG_EXIT ); |
|
205 return false; |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------- |
|
209 // AlarmAlertWidget::DataReceived |
|
210 // rest of the details are commented in the header |
|
211 // --------------------------------------------------------- |
|
212 // |
|
213 void AlarmAlertWidget::DataReceived(CHbSymbianVariantMap& aData) |
|
214 { |
|
215 OstTraceFunctionEntry0( ALARMALERTWIDGET_DATARECEIVED_ENTRY ); |
|
216 if (!aData.Keys().MdcaCount()) { |
|
217 OstTraceFunctionExit0( ALARMALERTWIDGET_DATARECEIVED_EXIT ); |
|
218 return; |
|
219 } |
|
220 |
|
221 triggerAction(aData.Get(alarmCommandSymbian)); |
|
222 OstTraceFunctionExit0( DUP1_ALARMALERTWIDGET_DATARECEIVED_EXIT ); |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------- |
|
226 // AlarmAlertWidget::DeviceDialogClosed |
|
227 // rest of the details are commented in the header |
|
228 // --------------------------------------------------------- |
|
229 // |
|
230 void AlarmAlertWidget::DeviceDialogClosed(TInt /*aCompletionCode*/) |
|
231 { |
|
232 OstTraceFunctionEntry0( ALARMALERTWIDGET_DEVICEDIALOGCLOSED_ENTRY ); |
|
233 |
|
234 OstTraceFunctionExit0( ALARMALERTWIDGET_DEVICEDIALOGCLOSED_EXIT ); |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------- |
|
238 // AlarmAlertWidget::triggerAction |
|
239 // rest of the details are commented in the header |
|
240 // --------------------------------------------------------- |
|
241 // |
|
242 void AlarmAlertWidget::triggerAction(const CHbSymbianVariant* source) |
|
243 { |
|
244 OstTraceFunctionEntry0( ALARMALERTWIDGET_TRIGGERACTION_ENTRY ); |
|
245 AlarmCommand command(AlarmCmdLast); |
|
246 |
|
247 if (*source->Value<TInt>() == Stop) { |
|
248 command = AlarmStop; |
|
249 } else if (*source->Value<TInt>() == Snooze) { |
|
250 command = AlarmSnooze; |
|
251 } else if (*source->Value<TInt>() == Silence) { |
|
252 command = AlarmSilence; |
|
253 } else if (*source->Value<TInt>() == Shown) { |
|
254 command = AlarmShown; |
|
255 mObserver->alertDisplayed(command); |
|
256 OstTraceFunctionExit0( ALARMALERTWIDGET_TRIGGERACTION_EXIT ); |
|
257 return; |
|
258 } else { |
|
259 command = AlarmCmdLast; |
|
260 } |
|
261 |
|
262 if (command != AlarmCmdLast) { |
|
263 // Notify the observer with the command |
|
264 mObserver->alertCompleted(command); |
|
265 } |
|
266 OstTraceFunctionExit0( DUP1_ALARMALERTWIDGET_TRIGGERACTION_EXIT ); |
|
267 } |
|
268 |
|
269 // End of file --Don't remove this. |