66
|
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::StopClockAlarm
|
|
105 |
// rest of the details are commented in the header
|
|
106 |
// ---------------------------------------------------------
|
|
107 |
//
|
|
108 |
EXPORT_C TInt CClkUiAlarmModel::AlarmRemoveSnooze ( TAlarmId aAlarmId )
|
|
109 |
{
|
|
110 |
|
|
111 |
TInt returnVal( KErrNone );
|
|
112 |
SClkAlarmInfo alarmInfo;
|
|
113 |
returnVal = ClockAlarmInfo( aAlarmId, alarmInfo);
|
|
114 |
if ( returnVal != KErrNone )
|
|
115 |
{
|
|
116 |
return returnVal;
|
|
117 |
}
|
|
118 |
returnVal = iAlarmSrvSes.AlarmDelete( aAlarmId );
|
|
119 |
if ( returnVal != KErrNone )
|
|
120 |
{
|
|
121 |
return returnVal;
|
|
122 |
}
|
|
123 |
alarmInfo.iState = EAlarmStateInPreparation;
|
|
124 |
alarmInfo.iAlarmTime = alarmInfo.iOrigExpiryTime;
|
|
125 |
return ClockAlarmSet( alarmInfo );
|
|
126 |
|
|
127 |
}
|
|
128 |
|
|
129 |
// ---------------------------------------------------------
|
|
130 |
// CClkUiAlarmModel::ClockAlarmEnable
|
|
131 |
// rest of the details are commented in the header
|
|
132 |
// ---------------------------------------------------------
|
|
133 |
//
|
|
134 |
EXPORT_C TInt CClkUiAlarmModel::ClockAlarmEnable( TAlarmId aAlarmId, TAlarmStatus aStatus )
|
|
135 |
{
|
|
136 |
TInt returnVal( KErrNone );
|
|
137 |
|
|
138 |
// If the alarm is enabled, we first disable it and then enable it.
|
|
139 |
if( EAlarmStatusEnabled == aStatus )
|
|
140 |
{
|
|
141 |
returnVal = iAlarmSrvSes.SetAlarmStatus( aAlarmId, EAlarmStatusDisabled );
|
|
142 |
|
|
143 |
if( KErrNone == returnVal )
|
|
144 |
{
|
|
145 |
returnVal = iAlarmSrvSes.SetAlarmStatus( aAlarmId, aStatus );
|
|
146 |
}
|
|
147 |
}
|
|
148 |
// If the request is to disable the alarm, we just do the same.
|
|
149 |
else
|
|
150 |
{
|
|
151 |
returnVal = iAlarmSrvSes.SetAlarmStatus( aAlarmId, aStatus );
|
|
152 |
}
|
|
153 |
|
|
154 |
return returnVal;
|
|
155 |
}
|
|
156 |
|
|
157 |
// ---------------------------------------------------------
|
|
158 |
// CClkUiAlarmModel::ClockAlarmStatus
|
|
159 |
// rest of the details are commented in the header
|
|
160 |
// ---------------------------------------------------------
|
|
161 |
//
|
|
162 |
EXPORT_C TAlarmStatus CClkUiAlarmModel::ClockAlarmStatus( TAlarmId aAlarmId ) const
|
|
163 |
{
|
|
164 |
TAlarmStatus alarmStatus;
|
|
165 |
|
|
166 |
// Pass the request to the server.
|
|
167 |
iAlarmSrvSes.GetAlarmStatus( aAlarmId, alarmStatus );
|
|
168 |
|
|
169 |
return alarmStatus;
|
|
170 |
}
|
|
171 |
|
|
172 |
// ---------------------------------------------------------
|
|
173 |
// CClkUiAlarmModel::ClockAlarmType
|
|
174 |
// rest of the details are commented in the header
|
|
175 |
// ---------------------------------------------------------
|
|
176 |
//
|
|
177 |
EXPORT_C TInt CClkUiAlarmModel::ClockAlarmType( TAlarmCategory& aCategory, TAlarmId aAlarmId ) const
|
|
178 |
{
|
|
179 |
return ( iAlarmSrvSes.GetAlarmCategory( aAlarmId, aCategory ) );
|
|
180 |
}
|
|
181 |
|
|
182 |
// ---------------------------------------------------------
|
|
183 |
// CClkUiAlarmModel::ClockAlarmSet
|
|
184 |
// rest of the details are commented in the header
|
|
185 |
// ---------------------------------------------------------
|
|
186 |
//
|
|
187 |
EXPORT_C TInt CClkUiAlarmModel::ClockAlarmSet( const SClkAlarmInfo& aAlarmInfo )
|
|
188 |
{
|
|
189 |
TASShdAlarm newAlarm;
|
|
190 |
|
|
191 |
// Build the alarm properties from the info provided.
|
|
192 |
newAlarm.Category() = KAlarmClockOne;
|
|
193 |
newAlarm.Message() = aAlarmInfo.iMessage;
|
|
194 |
newAlarm.OriginalExpiryTime() = aAlarmInfo.iAlarmTime;
|
|
195 |
newAlarm.RepeatDefinition() = aAlarmInfo.iRepeat;
|
|
196 |
newAlarm.SoundName() = aAlarmInfo.iSound;
|
|
197 |
newAlarm.NextDueTime() = aAlarmInfo.iAlarmTime;
|
|
198 |
|
|
199 |
// SSM related change.
|
|
200 |
#ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
|
|
201 |
newAlarm.SetWakeup( ETrue );
|
|
202 |
#else
|
|
203 |
newAlarm.ClientFlags().Set( KWakeupAlarmFlagIndex );
|
|
204 |
#endif
|
|
205 |
|
|
206 |
TInt returnVal = iAlarmSrvSes.AlarmAdd( newAlarm );
|
|
207 |
|
|
208 |
if( KErrNone == returnVal )
|
|
209 |
{
|
|
210 |
iAlarmObject = newAlarm;
|
|
211 |
iAlarmId = newAlarm.Id();
|
|
212 |
}
|
|
213 |
|
|
214 |
return returnVal;
|
|
215 |
}
|
|
216 |
|
|
217 |
// ---------------------------------------------------------
|
|
218 |
// CClkUiAlarmModel::ClockAlarmInfo
|
|
219 |
// rest of the details are commented in the header
|
|
220 |
// ---------------------------------------------------------
|
|
221 |
//
|
|
222 |
EXPORT_C TInt CClkUiAlarmModel::ClockAlarmInfo( TAlarmId aAlarmId, SClkAlarmInfo& aAlarmInfo ) const
|
|
223 |
{
|
|
224 |
TASShdAlarm tempAlarm;
|
|
225 |
|
|
226 |
if( !aAlarmId )
|
|
227 |
{
|
|
228 |
aAlarmInfo.iState = EAlarmStateInPreparation;
|
|
229 |
aAlarmInfo.iStatus = EAlarmStatusDisabled;
|
|
230 |
|
|
231 |
return KErrNone;
|
|
232 |
}
|
|
233 |
|
|
234 |
TInt returnVal = iAlarmSrvSes.GetAlarmDetails( aAlarmId, tempAlarm );
|
|
235 |
|
|
236 |
if( KErrNone == returnVal )
|
|
237 |
{
|
|
238 |
aAlarmInfo.iAlarmTime = tempAlarm.NextDueTime();
|
|
239 |
aAlarmInfo.iMessage = tempAlarm.Message();
|
|
240 |
aAlarmInfo.iOrigExpiryTime = tempAlarm.OriginalExpiryTime();
|
|
241 |
aAlarmInfo.iRepeat = tempAlarm.RepeatDefinition();
|
|
242 |
aAlarmInfo.iSound = tempAlarm.SoundName();
|
|
243 |
aAlarmInfo.iState = tempAlarm.State();
|
|
244 |
aAlarmInfo.iStatus = tempAlarm.Status();
|
|
245 |
iAlarmSrvSes.GetAlarmCategory( aAlarmId, aAlarmInfo.iCategory );
|
|
246 |
}
|
|
247 |
|
|
248 |
return returnVal;
|
|
249 |
}
|
|
250 |
|
|
251 |
// ---------------------------------------------------------
|
|
252 |
// CClkUiAlarmModel::ClockAlarmInfo
|
|
253 |
// rest of the details are commented in the header
|
|
254 |
// ---------------------------------------------------------
|
|
255 |
//
|
|
256 |
EXPORT_C const TAlarmId& CClkUiAlarmModel::AlarmId()
|
|
257 |
{
|
|
258 |
return iAlarmId;
|
|
259 |
}
|
|
260 |
|
|
261 |
// ---------------------------------------------------------
|
|
262 |
// CClkUiAlarmModel::SaveLatestAlarmId
|
|
263 |
// rest of the details are commented in the header
|
|
264 |
// ---------------------------------------------------------
|
|
265 |
//
|
|
266 |
EXPORT_C void CClkUiAlarmModel::SaveLatestAlarmId( TAlarmId aAlarmId )
|
|
267 |
{
|
|
268 |
iAlarmId = aAlarmId;
|
|
269 |
}
|
|
270 |
|
|
271 |
// ---------------------------------------------------------
|
|
272 |
// CClkUiAlarmModel::ClockAlarmInfo
|
|
273 |
// rest of the details are commented in the header
|
|
274 |
// ---------------------------------------------------------
|
|
275 |
//
|
|
276 |
EXPORT_C TBool CClkUiAlarmModel::GetAlarmQueuedOrSnoozedId( TAlarmId& aAlarmId, TBool aUpdatedId )
|
|
277 |
{
|
|
278 |
TBool alarmQueued( EFalse );
|
|
279 |
RArray< TAlarmId > alarmIds;
|
|
280 |
|
|
281 |
TRAP_IGNORE( iAlarmSrvSes.GetAlarmIdListForCategoryL( KAlarmClockOne, alarmIds ) );
|
|
282 |
|
|
283 |
TInt alarmCount( alarmIds.Count() );
|
|
284 |
for( TInt alarmIndex( KZerothIndex ); alarmIndex < alarmCount; alarmIndex++ )
|
|
285 |
{
|
|
286 |
const TAlarmId alarmId = alarmIds[ alarmIndex ];
|
|
287 |
TAlarmStatus alarmStatus;
|
|
288 |
TASShdAlarm tempAlarm;
|
|
289 |
|
|
290 |
// First get the alarm details.
|
|
291 |
TInt errorVal = iAlarmSrvSes.GetAlarmDetails( alarmId, tempAlarm );
|
|
292 |
// Then the status.
|
|
293 |
errorVal = iAlarmSrvSes.GetAlarmStatus( alarmId, alarmStatus );
|
|
294 |
|
|
295 |
// If the alarm status is enabled and the alarm is in either queued or snoozed state.
|
|
296 |
// The alarm ids we have received will be sorted based on the expiry time.
|
|
297 |
if( ( KErrNone == errorVal ) &&
|
|
298 |
( EAlarmStatusEnabled == tempAlarm.Status() ) &&
|
|
299 |
( EAlarmStateQueued == tempAlarm.State() ||
|
|
300 |
EAlarmStateSnoozed == tempAlarm.State() ) )
|
|
301 |
{
|
|
302 |
// The queued alarm is found.
|
|
303 |
aAlarmId = alarmId;
|
|
304 |
alarmQueued = ETrue;
|
|
305 |
|
|
306 |
if( aUpdatedId )
|
|
307 |
{
|
|
308 |
iAlarmId = alarmId;
|
|
309 |
}
|
|
310 |
break;
|
|
311 |
}
|
|
312 |
}
|
|
313 |
|
|
314 |
alarmIds.Close();
|
|
315 |
|
|
316 |
if( aUpdatedId && !alarmQueued )
|
|
317 |
{
|
|
318 |
iAlarmId = KZerothIndex;
|
|
319 |
}
|
|
320 |
|
|
321 |
return alarmQueued;
|
|
322 |
}
|
|
323 |
|
|
324 |
// ---------------------------------------------------------
|
|
325 |
// CClkUiAlarmModel::ConstructL
|
|
326 |
// rest of the details are commented in the header
|
|
327 |
// ---------------------------------------------------------
|
|
328 |
//
|
|
329 |
void CClkUiAlarmModel::ConstructL( MClkModelObserver* aObserver,
|
|
330 |
TInt aListenerPriority )
|
|
331 |
{
|
|
332 |
// First Set the observer.
|
|
333 |
SetModelObserver( aObserver );
|
|
334 |
|
|
335 |
// Connect to the alarm server.
|
|
336 |
User::LeaveIfError( iAlarmSrvSes.Connect() );
|
|
337 |
|
|
338 |
// Construct the listener and make it active.
|
|
339 |
CClkUiMdlAlarmListener* alarmListener = new( ELeave ) CClkUiMdlAlarmListener( iAlarmSrvSes,
|
|
340 |
*this,
|
|
341 |
aListenerPriority );
|
|
342 |
SetListenerActive( alarmListener );
|
|
343 |
|
|
344 |
// Get the latest alarm and store it.
|
|
345 |
TAlarmId latestAlarm;
|
|
346 |
GetAlarmQueuedOrSnoozedId( latestAlarm, ETrue );
|
|
347 |
}
|
|
348 |
|
|
349 |
// End of file
|