|
1 /* |
|
2 * Copyright (c) 2008 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: This is the source file for the CClkUiAlarmModel class. |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <asclisession.h> |
|
20 #include <almconst.h> |
|
21 #include <wakeupalarm.h> |
|
22 |
|
23 // User includes |
|
24 #include "clkuimdlbase.h" |
|
25 #include "clkuialarmmodel.h" |
|
26 #include "clkuialarmlistener.h" |
|
27 |
|
28 // Constants |
|
29 |
|
30 // Literals |
|
31 |
|
32 // --------------------------------------------------------- |
|
33 // CClkUiAlarmModel::NewL |
|
34 // rest of the details are commented in the header |
|
35 // --------------------------------------------------------- |
|
36 // |
|
37 EXPORT_C CClkUiAlarmModel* CClkUiAlarmModel::NewL( MClkModelObserver* aObserver, |
|
38 TInt aListenerPriority ) |
|
39 { |
|
40 CClkUiAlarmModel *self = new( ELeave ) CClkUiAlarmModel; |
|
41 |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL( aObserver, aListenerPriority ); |
|
44 CleanupStack::Pop( self ); |
|
45 |
|
46 return self; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // CClkUiAlarmModel::~CClkUiAlarmModel |
|
51 // rest of the details are commented in the header |
|
52 // --------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C CClkUiAlarmModel::~CClkUiAlarmModel() |
|
55 { |
|
56 // Stop the listener first and close the session with alarm server. |
|
57 Stop(); |
|
58 iAlarmSrvSes.Close(); |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------- |
|
62 // CClkUiAlarmModel::ProcessListenerL |
|
63 // rest of the details are commented in the header |
|
64 // --------------------------------------------------------- |
|
65 // |
|
66 void CClkUiAlarmModel::ProcessListenerL( TInt aStatus ) |
|
67 { |
|
68 if( ( KErrNone != aStatus ) && |
|
69 ( KErrCancel != aStatus ) ) |
|
70 { |
|
71 NotifyL( aStatus ); |
|
72 } |
|
73 else |
|
74 { |
|
75 NotifyL( KErrNone ); |
|
76 } |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------- |
|
80 // CClkUiAlarmModel::GetClkAlarmIds |
|
81 // rest of the details are commented in the header |
|
82 // --------------------------------------------------------- |
|
83 // |
|
84 EXPORT_C void CClkUiAlarmModel::GetClkAlarmIds( RArray< TAlarmId >& aAlarmIds ) |
|
85 { |
|
86 // Return the alarm ids of category clock. |
|
87 TRAP_IGNORE( iAlarmSrvSes.GetAlarmIdListForCategoryL( KAlarmClockOne, aAlarmIds ) ); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------- |
|
91 // CClkUiAlarmModel::DeleteClockAlarm |
|
92 // rest of the details are commented in the header |
|
93 // --------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C TInt CClkUiAlarmModel::DeleteClockAlarm( TAlarmId aAlarmId ) |
|
96 { |
|
97 // Pass the request to the server. |
|
98 TInt errorVal = iAlarmSrvSes.AlarmDelete( aAlarmId ); |
|
99 |
|
100 return errorVal; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------- |
|
104 // CClkUiAlarmModel::ClockAlarmEnable |
|
105 // rest of the details are commented in the header |
|
106 // --------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C TInt CClkUiAlarmModel::ClockAlarmEnable( TAlarmId aAlarmId, TAlarmStatus aStatus ) |
|
109 { |
|
110 TInt returnVal( KErrNone ); |
|
111 |
|
112 // If the alarm is enabled, we first disable it and then enable it. |
|
113 if( EAlarmStatusEnabled == aStatus ) |
|
114 { |
|
115 returnVal = iAlarmSrvSes.SetAlarmStatus( aAlarmId, EAlarmStatusDisabled ); |
|
116 |
|
117 if( KErrNone == returnVal ) |
|
118 { |
|
119 returnVal = iAlarmSrvSes.SetAlarmStatus( aAlarmId, aStatus ); |
|
120 } |
|
121 } |
|
122 // If the request is to disable the alarm, we just do the same. |
|
123 else |
|
124 { |
|
125 returnVal = iAlarmSrvSes.SetAlarmStatus( aAlarmId, aStatus ); |
|
126 } |
|
127 |
|
128 return returnVal; |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------- |
|
132 // CClkUiAlarmModel::ClockAlarmStatus |
|
133 // rest of the details are commented in the header |
|
134 // --------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C TAlarmStatus CClkUiAlarmModel::ClockAlarmStatus( TAlarmId aAlarmId ) const |
|
137 { |
|
138 TAlarmStatus alarmStatus; |
|
139 |
|
140 // Pass the request to the server. |
|
141 iAlarmSrvSes.GetAlarmStatus( aAlarmId, alarmStatus ); |
|
142 |
|
143 return alarmStatus; |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------- |
|
147 // CClkUiAlarmModel::ClockAlarmType |
|
148 // rest of the details are commented in the header |
|
149 // --------------------------------------------------------- |
|
150 // |
|
151 EXPORT_C TInt CClkUiAlarmModel::ClockAlarmType( TAlarmCategory& aCategory, TAlarmId aAlarmId ) const |
|
152 { |
|
153 return ( iAlarmSrvSes.GetAlarmCategory( aAlarmId, aCategory ) ); |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------- |
|
157 // CClkUiAlarmModel::ClockAlarmSet |
|
158 // rest of the details are commented in the header |
|
159 // --------------------------------------------------------- |
|
160 // |
|
161 EXPORT_C TInt CClkUiAlarmModel::ClockAlarmSet( const SClkAlarmInfo& aAlarmInfo ) |
|
162 { |
|
163 TASShdAlarm newAlarm; |
|
164 |
|
165 // Build the alarm properties from the info provided. |
|
166 newAlarm.Category() = KAlarmClockOne; |
|
167 newAlarm.Message() = aAlarmInfo.iMessage; |
|
168 newAlarm.OriginalExpiryTime() = aAlarmInfo.iAlarmTime; |
|
169 newAlarm.RepeatDefinition() = aAlarmInfo.iRepeat; |
|
170 newAlarm.SoundName() = aAlarmInfo.iSound; |
|
171 newAlarm.NextDueTime() = aAlarmInfo.iAlarmTime; |
|
172 |
|
173 // SSM related change. |
|
174 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
175 newAlarm.SetWakeup( ETrue ); |
|
176 #else |
|
177 newAlarm.ClientFlags().Set( KWakeupAlarmFlagIndex ); |
|
178 #endif |
|
179 |
|
180 TInt returnVal = iAlarmSrvSes.AlarmAdd( newAlarm ); |
|
181 |
|
182 if( KErrNone == returnVal ) |
|
183 { |
|
184 iAlarmObject = newAlarm; |
|
185 iAlarmId = newAlarm.Id(); |
|
186 } |
|
187 |
|
188 return returnVal; |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------- |
|
192 // CClkUiAlarmModel::ClockAlarmInfo |
|
193 // rest of the details are commented in the header |
|
194 // --------------------------------------------------------- |
|
195 // |
|
196 EXPORT_C TInt CClkUiAlarmModel::ClockAlarmInfo( TAlarmId aAlarmId, SClkAlarmInfo& aAlarmInfo ) const |
|
197 { |
|
198 TASShdAlarm tempAlarm; |
|
199 |
|
200 if( !aAlarmId ) |
|
201 { |
|
202 aAlarmInfo.iState = EAlarmStateInPreparation; |
|
203 aAlarmInfo.iStatus = EAlarmStatusDisabled; |
|
204 |
|
205 return KErrNone; |
|
206 } |
|
207 |
|
208 TInt returnVal = iAlarmSrvSes.GetAlarmDetails( aAlarmId, tempAlarm ); |
|
209 |
|
210 if( KErrNone == returnVal ) |
|
211 { |
|
212 aAlarmInfo.iAlarmTime = tempAlarm.NextDueTime(); |
|
213 aAlarmInfo.iMessage = tempAlarm.Message(); |
|
214 aAlarmInfo.iOrigExpiryTime = tempAlarm.OriginalExpiryTime(); |
|
215 aAlarmInfo.iRepeat = tempAlarm.RepeatDefinition(); |
|
216 aAlarmInfo.iSound = tempAlarm.SoundName(); |
|
217 aAlarmInfo.iState = tempAlarm.State(); |
|
218 aAlarmInfo.iStatus = tempAlarm.Status(); |
|
219 iAlarmSrvSes.GetAlarmCategory( aAlarmId, aAlarmInfo.iCategory ); |
|
220 } |
|
221 |
|
222 return returnVal; |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------- |
|
226 // CClkUiAlarmModel::ClockAlarmInfo |
|
227 // rest of the details are commented in the header |
|
228 // --------------------------------------------------------- |
|
229 // |
|
230 EXPORT_C const TAlarmId& CClkUiAlarmModel::AlarmId() |
|
231 { |
|
232 return iAlarmId; |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------- |
|
236 // CClkUiAlarmModel::SaveLatestAlarmId |
|
237 // rest of the details are commented in the header |
|
238 // --------------------------------------------------------- |
|
239 // |
|
240 EXPORT_C void CClkUiAlarmModel::SaveLatestAlarmId( TAlarmId aAlarmId ) |
|
241 { |
|
242 iAlarmId = aAlarmId; |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------- |
|
246 // CClkUiAlarmModel::ClockAlarmInfo |
|
247 // rest of the details are commented in the header |
|
248 // --------------------------------------------------------- |
|
249 // |
|
250 EXPORT_C TBool CClkUiAlarmModel::GetAlarmQueuedOrSnoozedId( TAlarmId& aAlarmId, TBool aUpdatedId ) |
|
251 { |
|
252 TBool alarmQueued( EFalse ); |
|
253 RArray< TAlarmId > alarmIds; |
|
254 |
|
255 TRAP_IGNORE( iAlarmSrvSes.GetAlarmIdListForCategoryL( KAlarmClockOne, alarmIds ) ); |
|
256 |
|
257 TInt alarmCount( alarmIds.Count() ); |
|
258 for( TInt alarmIndex( KZerothIndex ); alarmIndex < alarmCount; alarmIndex++ ) |
|
259 { |
|
260 const TAlarmId alarmId = alarmIds[ alarmIndex ]; |
|
261 TAlarmStatus alarmStatus; |
|
262 TASShdAlarm tempAlarm; |
|
263 |
|
264 // First get the alarm details. |
|
265 TInt errorVal = iAlarmSrvSes.GetAlarmDetails( alarmId, tempAlarm ); |
|
266 // Then the status. |
|
267 errorVal = iAlarmSrvSes.GetAlarmStatus( alarmId, alarmStatus ); |
|
268 |
|
269 // If the alarm status is enabled and the alarm is in either queued or snoozed state. |
|
270 // The alarm ids we have received will be sorted based on the expiry time. |
|
271 if( ( KErrNone == errorVal ) && |
|
272 ( EAlarmStatusEnabled == tempAlarm.Status() ) && |
|
273 ( EAlarmStateQueued == tempAlarm.State() || |
|
274 EAlarmStateSnoozed == tempAlarm.State() ) ) |
|
275 { |
|
276 // The queued alarm is found. |
|
277 aAlarmId = alarmId; |
|
278 alarmQueued = ETrue; |
|
279 |
|
280 if( aUpdatedId ) |
|
281 { |
|
282 iAlarmId = alarmId; |
|
283 } |
|
284 break; |
|
285 } |
|
286 } |
|
287 |
|
288 alarmIds.Close(); |
|
289 |
|
290 if( aUpdatedId && !alarmQueued ) |
|
291 { |
|
292 iAlarmId = KZerothIndex; |
|
293 } |
|
294 |
|
295 return alarmQueued; |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------- |
|
299 // CClkUiAlarmModel::ConstructL |
|
300 // rest of the details are commented in the header |
|
301 // --------------------------------------------------------- |
|
302 // |
|
303 void CClkUiAlarmModel::ConstructL( MClkModelObserver* aObserver, |
|
304 TInt aListenerPriority ) |
|
305 { |
|
306 // First Set the observer. |
|
307 SetModelObserver( aObserver ); |
|
308 |
|
309 // Connect to the alarm server. |
|
310 User::LeaveIfError( iAlarmSrvSes.Connect() ); |
|
311 |
|
312 // Construct the listener and make it active. |
|
313 CClkUiMdlAlarmListener* alarmListener = new( ELeave ) CClkUiMdlAlarmListener( iAlarmSrvSes, |
|
314 *this, |
|
315 aListenerPriority ); |
|
316 SetListenerActive( alarmListener ); |
|
317 |
|
318 // Get the latest alarm and store it. |
|
319 TAlarmId latestAlarm; |
|
320 GetAlarmQueuedOrSnoozedId( latestAlarm, ETrue ); |
|
321 } |
|
322 |
|
323 // End of file |