1 /* |
|
2 * Copyright (c) 2009 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: Handler for Snoozing of Event |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <centralrepository.h> |
|
21 |
|
22 #include "evthandlerserverconsts.h" |
|
23 #include "evtdebug.h" |
|
24 #include "evtsnoozehandler.h" |
|
25 #include "evtstoragedomaincrkeys.h" |
|
26 |
|
27 // EXTERNAL DATA STRUCTURES |
|
28 |
|
29 // EXTERNAL FUNCTION PROTOTYPES |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 // MACROS |
|
34 |
|
35 // LOCAL CONSTANTS AND MACROS |
|
36 |
|
37 // MODULE DATA STRUCTURES |
|
38 |
|
39 // LOCAL FUNCTION PROTOTYPES |
|
40 |
|
41 // FORWARD DECLARATIONS |
|
42 |
|
43 // ============================= LOCAL FUNCTIONS =============================== |
|
44 |
|
45 // ============================ MEMBER FUNCTIONS =============================== |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CEvtSnoozeHandler::NewL |
|
49 // ----------------------------------------------------------------------------- |
|
50 CEvtSnoozeHandler* CEvtSnoozeHandler::NewL( |
|
51 MEvtSnoozeObserver& aSnoozeObserver ) |
|
52 { |
|
53 CEvtSnoozeHandler* self = new ( ELeave ) CEvtSnoozeHandler( aSnoozeObserver ); |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop(); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CEvtSnoozeHandler::CEvtSnoozeHandler |
|
62 // ----------------------------------------------------------------------------- |
|
63 CEvtSnoozeHandler::CEvtSnoozeHandler( |
|
64 MEvtSnoozeObserver& aSnoozeObserver ) |
|
65 : CTimer( EPriorityStandard ), iSnoozeObserver( aSnoozeObserver ), |
|
66 iSnoozeQueue( KEvtItemArrayGranularity ), |
|
67 iSnoozeCompleteQueue( KEvtItemArrayGranularity ) |
|
68 { |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CEvtSnoozeHandler::~CEvtSnoozeHandler |
|
73 // ----------------------------------------------------------------------------- |
|
74 CEvtSnoozeHandler::~CEvtSnoozeHandler() |
|
75 { |
|
76 if( iIntervalNotifyHandler ) |
|
77 { |
|
78 iIntervalNotifyHandler->StopListening(); |
|
79 } |
|
80 |
|
81 if( iPeriodNotifyHandler ) |
|
82 { |
|
83 iPeriodNotifyHandler->StopListening(); |
|
84 } |
|
85 |
|
86 delete iIntervalNotifyHandler; |
|
87 delete iPeriodNotifyHandler; |
|
88 delete iSettingSession; |
|
89 |
|
90 iSnoozeQueue.Reset(); |
|
91 iSnoozeQueue.Close(); |
|
92 iSnoozeCompleteQueue.Reset(); |
|
93 iSnoozeCompleteQueue.Close(); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CEvtSnoozeHandler::ConstructL |
|
98 // ----------------------------------------------------------------------------- |
|
99 void CEvtSnoozeHandler::ConstructL() |
|
100 { |
|
101 EVTUIDEBUG("+ CEvtSnoozeHandler::ConstructL"); |
|
102 CTimer::ConstructL(); |
|
103 CActiveScheduler::Add( this ); |
|
104 |
|
105 // Create the Session to EventsUi Settings |
|
106 iSettingSession = CRepository::NewL( TUid::Uid( KCRUidEvtStorageDb ) ); |
|
107 |
|
108 // Create the Cenrep Key observer for Interval and Period. |
|
109 iIntervalNotifyHandler = CCenRepNotifyHandler::NewL(*this, |
|
110 *iSettingSession, |
|
111 CCenRepNotifyHandler::EIntKey, |
|
112 KEvtSnoozeInterval); |
|
113 |
|
114 iPeriodNotifyHandler = CCenRepNotifyHandler::NewL(*this, |
|
115 *iSettingSession, |
|
116 CCenRepNotifyHandler::EIntKey, |
|
117 KEvtSnoozePeriod); |
|
118 |
|
119 // Get the Initial values from settings. |
|
120 TInt period; |
|
121 User::LeaveIfError( iSettingSession->Get( KEvtSnoozeInterval, iSnoozeInterval ) ); |
|
122 User::LeaveIfError( iSettingSession->Get( KEvtSnoozePeriod, period ) ); |
|
123 |
|
124 // Start Listening. |
|
125 iIntervalNotifyHandler->StartListeningL(); |
|
126 iPeriodNotifyHandler->StartListeningL(); |
|
127 |
|
128 iSnoozeCount = 1; |
|
129 if( period && iSnoozeInterval/period ) |
|
130 iSnoozeCount = iSnoozeInterval/period; |
|
131 |
|
132 EVTUIDEBUG( "- CEvtSnoozeHandler::ConstructL" ); |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CEvtSnoozeHandler::RemoveIfPresent |
|
137 // ----------------------------------------------------------------------------- |
|
138 void CEvtSnoozeHandler::RemoveIfPresent(const TEvtSnoozeItem& aSnoozeItem) |
|
139 { |
|
140 EVTUIDEBUG( "+ CEvtSnoozeHandler::RemoveIfPresent" ); |
|
141 |
|
142 // Remove if already present |
|
143 TIdentityRelation<TEvtSnoozeItem> matcher(TEvtSnoozeItem::Match); |
|
144 TInt index = iSnoozeCompleteQueue.Find(aSnoozeItem,matcher); |
|
145 |
|
146 if( index != KErrNotFound ) |
|
147 { |
|
148 iSnoozeCompleteQueue.Remove( index ); |
|
149 } |
|
150 else |
|
151 { |
|
152 index = iSnoozeQueue.Find(aSnoozeItem,matcher); |
|
153 if( index != KErrNotFound ) |
|
154 { |
|
155 iSnoozeQueue.Remove( index ); |
|
156 |
|
157 // Cancel the timer if it is already snoozing for |
|
158 // requested event id |
|
159 if( index == 0 ) |
|
160 { |
|
161 Cancel(); |
|
162 |
|
163 // Start the Timer for next Item |
|
164 if( !IsActive() && iSnoozeQueue.Count() ) |
|
165 At( iSnoozeQueue[ 0 ].iTime ); |
|
166 } |
|
167 } |
|
168 } |
|
169 |
|
170 EVTUIDEBUG( "- CEvtSnoozeHandler::RemoveIfPresent" ); |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CEvtSnoozeHandler::IsSnoozeQueEmpty |
|
175 // ----------------------------------------------------------------------------- |
|
176 TBool CEvtSnoozeHandler::IsSnoozeQueEmpty() |
|
177 { |
|
178 EVTUIDEBUG( "+ CEvtSnoozeHandler::IsSnoozeQueEmpty" ); |
|
179 |
|
180 if( IsActive() || iSnoozeCompleteQueue.Count() || iSnoozeCompleteQueue.Count() ) |
|
181 { |
|
182 return EFalse; |
|
183 } |
|
184 return ETrue; |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CEvtSnoozeHandler::Snooze |
|
189 // ----------------------------------------------------------------------------- |
|
190 void CEvtSnoozeHandler::Snooze(TEvtSnoozeItem aSnoozeItem) |
|
191 { |
|
192 EVTUIDEBUG( "+ CEvtSnoozeHandler::Snooze" ); |
|
193 |
|
194 TTimeIntervalMinutes interval(iSnoozeInterval); |
|
195 aSnoozeItem.iTime.HomeTime(); |
|
196 |
|
197 // Add the Snooze Time |
|
198 aSnoozeItem.iTime = aSnoozeItem.iTime + interval; |
|
199 |
|
200 TIdentityRelation<TEvtSnoozeItem> matcher(TEvtSnoozeItem::Match); |
|
201 TInt index = iSnoozeCompleteQueue.Find(aSnoozeItem,matcher); |
|
202 |
|
203 if( index != KErrNotFound ) |
|
204 { |
|
205 // Increment Snooze count |
|
206 aSnoozeItem.iCount = iSnoozeCompleteQueue[index].iCount + 1; |
|
207 |
|
208 // Remove the already present item |
|
209 iSnoozeCompleteQueue.Remove( index ); |
|
210 } |
|
211 else |
|
212 { |
|
213 index = iSnoozeQueue.Find(aSnoozeItem,matcher); |
|
214 if( index != KErrNotFound ) |
|
215 { |
|
216 // Cancel the timer if it is already snoozing for |
|
217 // requested event id |
|
218 if( index == 0 ) |
|
219 { |
|
220 Cancel(); |
|
221 } |
|
222 |
|
223 // Increment Snooze count |
|
224 aSnoozeItem.iCount = iSnoozeQueue[index].iCount + 1; |
|
225 |
|
226 // Remove the already present item |
|
227 iSnoozeQueue.Remove( index ); |
|
228 } |
|
229 else |
|
230 { |
|
231 // First Snooze |
|
232 aSnoozeItem.iCount = 1; |
|
233 } |
|
234 } |
|
235 |
|
236 // Append this element to the queue |
|
237 iSnoozeQueue.Append( aSnoozeItem ); |
|
238 |
|
239 // Start the Timer if it is not already started |
|
240 if(!IsActive()) |
|
241 At( iSnoozeQueue[ 0 ].iTime ); |
|
242 |
|
243 EVTUIDEBUG( "- CEvtSnoozeHandler::Snooze" ); |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CEvtSnoozeHandler::RunL |
|
248 // ----------------------------------------------------------------------------- |
|
249 void CEvtSnoozeHandler::RunL() |
|
250 { |
|
251 EVTUIDEBUG1( "+ CEvtSnoozeHandler::RunL %d", iStatus.Int() ); |
|
252 |
|
253 if( iSnoozeQueue.Count() > 1 ) |
|
254 At( iSnoozeQueue[ 1 ].iTime ); |
|
255 |
|
256 if( iSnoozeQueue[ 0 ].iCount < iSnoozeCount ) |
|
257 { |
|
258 // Notify on Snooze complete |
|
259 iSnoozeObserver.SnoozeCompleteL( iSnoozeQueue[ 0 ], ETrue ); |
|
260 |
|
261 // Move the snooze item to complete |
|
262 iSnoozeCompleteQueue.Append( iSnoozeQueue[ 0 ] ); |
|
263 iSnoozeQueue.Remove(0); |
|
264 } |
|
265 else |
|
266 { |
|
267 // Notify on Snooze complete |
|
268 iSnoozeObserver.SnoozeCompleteL( iSnoozeQueue[ 0 ], EFalse); |
|
269 |
|
270 // Remove Snoozed Item |
|
271 iSnoozeQueue.Remove(0); |
|
272 } |
|
273 |
|
274 EVTUIDEBUG( "- CEvtSnoozeHandler::RunL" ); |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CEvtSnoozeHandler::HandleNotifyInt() |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CEvtSnoozeHandler::HandleNotifyInt(TUint32 aId, TInt aNewValue) |
|
282 { |
|
283 |
|
284 if ( aId == KEvtSnoozeInterval ) |
|
285 { |
|
286 iSnoozeInterval = aNewValue; |
|
287 } |
|
288 else if ( aId == KEvtSnoozePeriod ) |
|
289 { |
|
290 if( aNewValue && iSnoozeInterval/aNewValue ) |
|
291 iSnoozeCount = iSnoozeInterval/aNewValue; |
|
292 } |
|
293 } |
|
294 |
|
295 // End of File |
|