9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 // alarmalertwidget.cpp |
17 // alarmalertwidget.cpp |
18 |
18 |
19 // System includes |
19 // System includes |
20 #include <QDateTime> |
20 #include <hbsymbianvariant.h> |
21 #include <hbdevicedialog.h> |
|
22 #include <QDebug> |
|
23 |
21 |
24 // User includes |
22 // User includes |
25 #include "alarmalertwidget.h" |
23 #include "alarmalertwidget.h" |
26 #include "alarmalert.h" |
24 #include "alarmalert.h" |
27 #include "alarmalertobserver.h" |
25 #include "alarmalertobserver.h" |
28 |
26 |
|
27 // Constants. |
|
28 const TInt KMaxlength=30; |
|
29 |
29 // --------------------------------------------------------- |
30 // --------------------------------------------------------- |
30 // AlarmAlertWidget::AlarmAlertWidget |
31 // AlarmAlertWidget::AlarmAlertWidget |
31 // rest of the details are commented in the header |
32 // rest of the details are commented in the header |
32 // --------------------------------------------------------- |
33 // --------------------------------------------------------- |
33 // |
34 // |
34 AlarmAlertWidget::AlarmAlertWidget(AlarmAlertObserver *observer) : |
35 AlarmAlertWidget::AlarmAlertWidget(AlarmAlertObserver *observer) : |
35 mObserver(observer) |
36 mObserver(observer) |
36 { |
37 { |
37 // Create a session with the device dialog server |
38 } |
38 mDeviceDialog = new HbDeviceDialog(HbDeviceDialog::NoFlags, this); |
39 |
|
40 // --------------------------------------------------------- |
|
41 // AlarmAlertWidget::~AlarmAlertWidget |
|
42 // rest of the details are commented in the header |
|
43 // --------------------------------------------------------- |
|
44 // |
|
45 AlarmAlertWidget::~AlarmAlertWidget() |
|
46 { |
|
47 // Cleanup |
|
48 |
|
49 if (mAlarmSubject) { |
|
50 delete mAlarmSubject; |
|
51 } |
|
52 |
|
53 if (mLocation) { |
|
54 delete mLocation; |
|
55 } |
|
56 |
|
57 if (mAlarmTime) { |
|
58 delete mAlarmTime; |
|
59 } |
|
60 |
|
61 if (mAlarmDate) { |
|
62 delete mAlarmDate; |
|
63 } |
|
64 |
|
65 if (mAlarmAlertType) { |
|
66 delete mAlarmAlertType; |
|
67 } |
|
68 |
|
69 if (mCanSnooze) { |
|
70 delete mCanSnooze; |
|
71 } |
|
72 |
|
73 if (mIsSilent) { |
|
74 delete mIsSilent; |
|
75 } |
|
76 |
|
77 if (mIsTimedAlarm) { |
|
78 delete mIsTimedAlarm; |
|
79 } |
|
80 |
|
81 if (mVariantMap) { |
|
82 delete mVariantMap; |
|
83 } |
|
84 |
|
85 if (mDeviceDialog) { |
|
86 delete mDeviceDialog; |
|
87 } |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------- |
|
91 // AlarmAlertWidget::ShowAlarmDialog |
|
92 // rest of the details are commented in the header |
|
93 // --------------------------------------------------------- |
|
94 // |
|
95 bool AlarmAlertWidget::showAlarmDialog(SAlarmInfo *alarmInfo) |
|
96 { |
|
97 // Get the alarm date and time |
|
98 TBuf<KMaxlength> timeString; |
|
99 TBuf<KMaxlength> dateString; |
39 |
100 |
40 // Connect to signals to receive events sent by the dialog |
101 TBuf<KMaxlength> timeFormat(_L("%-B%:0%J%:1%T%:3%+B")); |
41 connect(mDeviceDialog, SIGNAL(dataReceived(QVariantMap)), this, SLOT(triggerAction(QVariantMap))); |
102 TBuf<KMaxlength> dateFormat; |
42 } |
103 TLocale locale; |
43 |
104 switch (locale.DateFormat()) { |
44 // --------------------------------------------------------- |
105 case EDateEuropean: |
45 // AlarmAlertWidget::~AlarmAlertWidget |
106 dateFormat.Copy(_L("%F%/0%D%/1%M%/2%Y%/3")); |
46 // rest of the details are commented in the header |
107 break; |
47 // --------------------------------------------------------- |
108 case EDateAmerican: |
48 // |
109 dateFormat.Copy(_L("%F%/0%M%/1%D%/2%Y%/3")); |
49 AlarmAlertWidget::~AlarmAlertWidget() |
110 break; |
50 { |
111 case EDateJapanese: |
51 // Cleanup |
112 dateFormat.Copy(_L("%F%/0%Y%/1%M%/2%D%/3")); |
52 if (mDeviceDialog) { |
113 break; |
53 delete mDeviceDialog; |
114 default: |
54 } |
115 // Nothing yet. |
55 } |
116 break; |
56 |
117 } |
57 // --------------------------------------------------------- |
118 |
58 // AlarmAlertWidget::ShowAlarmDialog |
119 |
59 // rest of the details are commented in the header |
120 alarmInfo->iTime.FormatL(timeString, timeFormat); |
60 // --------------------------------------------------------- |
121 alarmInfo->iTime.FormatL(dateString, dateFormat); |
61 // |
122 |
62 bool AlarmAlertWidget::showAlarmDialog(SAlarmInfo *alarmInfo) |
123 // Create a session with the device dialog server |
63 { |
124 mDeviceDialog = CHbDeviceDialogSymbian::NewL(); |
64 // Get the subject of the alarm (description for clock alarms |
125 |
65 // and subject for calendar alarms) |
126 |
66 mSubject = QString::fromUtf16(alarmInfo->iSubject->Ptr(), |
127 // Package the different parameters to send |
67 alarmInfo->iSubject->Length()); |
128 mVariantMap = CHbSymbianVariantMap::NewL(); |
68 |
129 |
|
130 // Get the subject of the alarm (description for clock alarms |
|
131 // and subject for calendar alarms) |
|
132 mAlarmSubject = CHbSymbianVariant::NewL( |
|
133 alarmInfo->iSubject, CHbSymbianVariant::EDes ); |
|
134 mVariantMap->Add(alarmSubjectSymbian, mAlarmSubject); |
|
135 |
69 // Get the location (for calendar alarms) |
136 // Get the location (for calendar alarms) |
70 mLocation = QString::fromUtf16(alarmInfo->iLocation->Ptr(), |
137 mLocation = CHbSymbianVariant::NewL( |
71 alarmInfo->iLocation->Length()); |
138 alarmInfo->iLocation, CHbSymbianVariant::EDes); |
72 |
139 mVariantMap->Add(alarmLocationSymbian, mLocation); |
73 // Get the alarm date and time |
140 |
74 // TODO: Check QDateTime to TTime compatibility |
141 mAlarmTime = CHbSymbianVariant::NewL( |
75 mAlarmTime.setTime(QTime(alarmInfo->iTime.DateTime().Hour(), |
142 &timeString, CHbSymbianVariant::EDes); |
76 alarmInfo->iTime.DateTime().Minute(), |
143 mVariantMap->Add(alarmTimeSymbian, mAlarmTime); |
77 alarmInfo->iTime.DateTime().Second())); |
144 |
78 mAlarmTime.setDate(QDate(alarmInfo->iDate.DateTime().Year(), |
145 mAlarmDate = CHbSymbianVariant::NewL( |
79 alarmInfo->iDate.DateTime().Month(), |
146 &dateString, CHbSymbianVariant::EDes); |
80 alarmInfo->iDate.DateTime().Day())); |
147 mVariantMap->Add(alarmDateSymbian, mAlarmDate); |
81 |
148 |
82 mCanSnooze = alarmInfo->iCanSnooze; |
149 mIsSilent = CHbSymbianVariant::NewL( |
83 mIsSilent = alarmInfo->iIsSilent; |
150 &alarmInfo->iIsSilent, CHbSymbianVariant::EBool); |
84 mAlarmAlertType = alarmInfo->iAlarmAlertType; |
151 mVariantMap->Add(alarmRingingTypeSymbian, mIsSilent); |
85 mIsTimedAlarm = alarmInfo->iIsTimed; |
152 |
86 |
153 mCanSnooze = CHbSymbianVariant::NewL( |
87 // Package the different parameters to send |
154 &alarmInfo->iCanSnooze, CHbSymbianVariant::EBool); |
88 QVariantMap params; |
155 mVariantMap->Add(alarmCanSnoozeSymbain, mCanSnooze); |
89 params.insert(alarmSubject, mSubject); |
156 |
90 params.insert(alarmLocation, mLocation); |
157 mAlarmAlertType = CHbSymbianVariant::NewL( |
91 params.insert(alarmDateTime, mAlarmTime); |
158 &alarmInfo->iAlarmAlertType, CHbSymbianVariant::EInt); |
92 params.insert(alarmRingingType, mIsSilent); |
159 mVariantMap->Add(alarmTypeSymbian, mAlarmAlertType); |
93 params.insert(alarmCanSnooze, mCanSnooze); |
160 |
94 params.insert(alarmType, mAlarmAlertType); |
161 mIsTimedAlarm = CHbSymbianVariant::NewL( |
95 params.insert(alarmIsTimed, mIsTimedAlarm); |
162 &alarmInfo->iIsTimed, CHbSymbianVariant::EBool); |
96 |
163 mVariantMap->Add(alarmIsTimedSymbian, mIsTimedAlarm); |
97 return mDeviceDialog->show(ALARM_ALERT_PLUGIN, params); |
164 |
|
165 // Package the different parameters to send |
|
166 return mDeviceDialog->Show(ALARM_ALERT_PLUGIN_SYMBIAN, *mVariantMap, this); |
|
167 |
98 } |
168 } |
99 |
169 |
100 // --------------------------------------------------------- |
170 // --------------------------------------------------------- |
101 // AlarmAlertWidget::DismissAlarmDialog |
171 // AlarmAlertWidget::DismissAlarmDialog |
102 // rest of the details are commented in the header |
172 // rest of the details are commented in the header |
103 // --------------------------------------------------------- |
173 // --------------------------------------------------------- |
104 // |
174 // |
105 bool AlarmAlertWidget::dismissAlarmDialog() |
175 void AlarmAlertWidget::dismissAlarmDialog() |
106 { |
176 { |
107 // Dismiss the dialog |
177 // Dismiss the dialog |
108 return mDeviceDialog->cancel(); |
178 mDeviceDialog->Cancel(); |
109 } |
179 } |
110 |
180 |
111 // --------------------------------------------------------- |
181 // --------------------------------------------------------- |
112 // AlarmAlertWidget::UpdateAlarmDialog |
182 // AlarmAlertWidget::UpdateAlarmDialog |
113 // rest of the details are commented in the header |
183 // rest of the details are commented in the header |
114 // --------------------------------------------------------- |
184 // --------------------------------------------------------- |
115 // |
185 // |
116 bool AlarmAlertWidget::updateAlarmDialog(SAlarmInfo* alarmInfo) |
186 bool AlarmAlertWidget::updateAlarmDialog(SAlarmInfo* /*alarmInfo*/) |
117 { |
187 { |
118 Q_UNUSED(alarmInfo); |
|
119 // Update the dialog with any new information |
188 // Update the dialog with any new information |
120 // TODO: Pass the updated information sent by the observer |
189 // TODO: Pass the updated information sent by the observer |
121 QVariantMap params; |
190 /*CHbSymbianVariantMap params; |
122 return mDeviceDialog->update(params); |
191 mDeviceDialog->Update(params);*/ |
|
192 return false; |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------- |
|
196 // AlarmAlertWidget::DataReceived |
|
197 // rest of the details are commented in the header |
|
198 // --------------------------------------------------------- |
|
199 // |
|
200 void AlarmAlertWidget::DataReceived(CHbSymbianVariantMap& aData) |
|
201 { |
|
202 if (!aData.Keys().MdcaCount()) { |
|
203 return; |
|
204 } |
|
205 |
|
206 triggerAction(aData.Get(alarmCommandSymbian)); |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------- |
|
210 // AlarmAlertWidget::DeviceDialogClosed |
|
211 // rest of the details are commented in the header |
|
212 // --------------------------------------------------------- |
|
213 // |
|
214 void AlarmAlertWidget::DeviceDialogClosed(TInt /*aCompletionCode*/) |
|
215 { |
|
216 |
123 } |
217 } |
124 |
218 |
125 // --------------------------------------------------------- |
219 // --------------------------------------------------------- |
126 // AlarmAlertWidget::triggerAction |
220 // AlarmAlertWidget::triggerAction |
127 // rest of the details are commented in the header |
221 // rest of the details are commented in the header |
128 // --------------------------------------------------------- |
222 // --------------------------------------------------------- |
129 // |
223 // |
130 void AlarmAlertWidget::triggerAction(QVariantMap params) |
224 void AlarmAlertWidget::triggerAction(const CHbSymbianVariant* source) |
131 { |
225 { |
132 // Check what is the command being sent by the dialog |
226 AlarmCommand command(AlarmCmdLast); |
133 // Based on that, update the command to be sent |
227 |
134 QVariantMap::const_iterator iter = params.find(alarmCommand); |
228 if (*source->Value<TInt>() == Stop) { |
135 if (iter != params.constEnd()) { |
229 command = AlarmStop; |
136 AlarmCommand command(AlarmCmdLast); |
230 } else if (*source->Value<TInt>() == Snooze) { |
137 if (iter.value().toInt() == Stop) { |
231 command = AlarmSnooze; |
138 command = AlarmStop; |
232 } else if (*source->Value<TInt>() == Silence) { |
139 } |
233 command = AlarmSilence; |
140 else if (iter.value().toInt() == Snooze) { |
234 } else if (*source->Value<TInt>() == Shown) { |
141 command = AlarmSnooze; |
235 command = AlarmShown; |
142 } |
236 mObserver->alertDisplayed(command); |
143 else if (iter.value().toInt() == Silence) { |
237 return; |
144 command = AlarmSilence; |
238 } else { |
145 } else if (iter.value().toInt() == Shown) { |
239 command = AlarmCmdLast; |
146 command = AlarmShown; |
240 } |
147 mObserver->alertDisplayed(command); |
241 |
148 return; |
242 if (command != AlarmCmdLast) { |
149 } else { |
243 // Notify the observer with the command |
150 command = AlarmCmdLast; |
244 mObserver->alertCompleted(command); |
151 } |
245 } |
152 if (command != AlarmCmdLast) { |
246 } |
153 // Notify the observer with the command |
247 |
154 mObserver->alertCompleted(command); |
|
155 } |
|
156 |
|
157 } |
|
158 } |
|
159 // End of file --Don't remove this. |
248 // End of file --Don't remove this. |