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 class interfaces with Context Framework Client API
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <coemain.h>
|
|
19 |
#include <f32file.h>
|
|
20 |
#include <pathinfo.h>
|
|
21 |
#include <cfclient.h>
|
|
22 |
#include <cfcontextobject.h>
|
|
23 |
#include <cfactionsubscription.h>
|
|
24 |
#include <cfactionindication.h>
|
|
25 |
#include <cfcontextindication.h>
|
|
26 |
#include <cfcontextobject.h>
|
|
27 |
#include <cfcontextsubscription.h>
|
|
28 |
#include <cfcontextobject.h>
|
|
29 |
#include "CleanupResetAndDestroy.h"
|
|
30 |
#include "calenalarmmanager.h"
|
|
31 |
#include "calencontextfwlistener.h"
|
|
32 |
#include <alarmsourcecontextdef.h>
|
|
33 |
#include "calendarui_debug.h"
|
|
34 |
|
|
35 |
// ======== MEMBER FUNCTIONS ========
|
|
36 |
|
|
37 |
// ---------------------------------------------------------------------------
|
|
38 |
// CCalenContextFWListener::NewL
|
|
39 |
// Symbian constructor.
|
|
40 |
// ---------------------------------------------------------------------------
|
|
41 |
//
|
|
42 |
CCalenContextFWListener* CCalenContextFWListener::NewL(CCalenAlarmManager& aAlarmManager)
|
|
43 |
{
|
|
44 |
TRACE_ENTRY_POINT;
|
|
45 |
CCalenContextFWListener* self = new( ELeave )CCalenContextFWListener(aAlarmManager);
|
|
46 |
CleanupStack::PushL( self );
|
|
47 |
self->ConstructL();
|
|
48 |
CleanupStack::Pop( self );
|
|
49 |
TRACE_EXIT_POINT;
|
|
50 |
return self;
|
|
51 |
}
|
|
52 |
|
|
53 |
// ---------------------------------------------------------------------------
|
|
54 |
// CCalenContextFWListener::~CCalenContextFWListener
|
|
55 |
// destructor
|
|
56 |
// ---------------------------------------------------------------------------
|
|
57 |
//
|
|
58 |
CCalenContextFWListener::~CCalenContextFWListener()
|
|
59 |
{
|
|
60 |
TRACE_ENTRY_POINT;
|
|
61 |
CloseCFClient();
|
|
62 |
TRACE_EXIT_POINT;
|
|
63 |
}
|
|
64 |
|
|
65 |
// ---------------------------------------------------------------------------
|
|
66 |
// CCalenContextFWListener::ContextIndicationL
|
|
67 |
// Indicates a change in context for subscribed clients.
|
|
68 |
// ---------------------------------------------------------------------------
|
|
69 |
//
|
|
70 |
void CCalenContextFWListener::ContextIndicationL(const CCFContextIndication& aChangedContext)
|
|
71 |
{
|
|
72 |
TRACE_ENTRY_POINT;
|
|
73 |
const CCFContextObject& co = aChangedContext.Context();
|
|
74 |
|
|
75 |
#ifdef _DEBUG
|
|
76 |
RDebug::Print( _L("----- CalendarUI - context indication:") );
|
|
77 |
RDebug::RawPrint( co.Source() );
|
|
78 |
RDebug::RawPrint( co.Type() );
|
|
79 |
RDebug::RawPrint( co.Value() );
|
|
80 |
#endif
|
|
81 |
|
|
82 |
// exit alarm mode as soon as alarm is snoozed or stopped
|
|
83 |
if( co.Source() == KAlarmUISource() && co.Type() == KAlarmUISourceResult() )
|
|
84 |
{
|
|
85 |
#ifdef _DEBUG
|
|
86 |
RDebug::Print( _L("### source OK!") );
|
|
87 |
#endif
|
|
88 |
if( co.Value() == TPtrC( KAlarmUISourceResultValues[EResultAlarmStopped] ) )
|
|
89 |
{
|
|
90 |
#ifdef _DEBUG
|
|
91 |
RDebug::Print( _L("### EResultAlarmStopped") );
|
|
92 |
#endif
|
|
93 |
// should close the Event view open
|
|
94 |
iAlarmManager.StopAlarmContextListener();
|
|
95 |
}
|
|
96 |
else if( co.Value() == TPtrC( KAlarmUISourceResultValues[EResultAlarmSnoozed] ) )
|
|
97 |
{
|
|
98 |
#ifdef _DEBUG
|
|
99 |
RDebug::Print( _L("### EResultAlarmSnoozed") );
|
|
100 |
#endif
|
|
101 |
// should leave the Event view
|
|
102 |
iAlarmManager.StopAlarmContextListener(ETrue);
|
|
103 |
}
|
|
104 |
//should close the event view in case of power on/off and missed alarm.
|
|
105 |
else if( co.Value() == TPtrC( KAlarmUISourceResultValues[EResultAlarmStoppedAndExit] ) )
|
|
106 |
{
|
|
107 |
#ifdef _DEBUG
|
|
108 |
RDebug::Print( _L("### EResultAlarmMissed") );
|
|
109 |
#endif
|
|
110 |
// should leave the Event view
|
|
111 |
//iAlarmManager.StopAlarmContextListener(ETrue);
|
|
112 |
iAlarmManager.StopContextListenerForAutoSnooze();
|
|
113 |
}
|
|
114 |
else
|
|
115 |
{
|
|
116 |
#ifdef _DEBUG
|
|
117 |
RDebug::Print( _L("### value didn't match!") );
|
|
118 |
#endif
|
|
119 |
}
|
|
120 |
}
|
|
121 |
else
|
|
122 |
{
|
|
123 |
#ifdef _DEBUG
|
|
124 |
RDebug::Print( _L("### source didn't match!") );
|
|
125 |
#endif
|
|
126 |
}
|
|
127 |
UnsubscribeContexts();
|
|
128 |
CloseCFClient();
|
|
129 |
TRACE_EXIT_POINT;
|
|
130 |
}
|
|
131 |
|
|
132 |
// ---------------------------------------------------------------------------
|
|
133 |
// CCalenContextFWListener::ActionIndicationL
|
|
134 |
// Indicates that specified action is needed to be executed.
|
|
135 |
// ---------------------------------------------------------------------------
|
|
136 |
//
|
|
137 |
void CCalenContextFWListener::ActionIndicationL(const CCFActionIndication& aActionToExecute)
|
|
138 |
{
|
|
139 |
TRACE_ENTRY_POINT;
|
|
140 |
#ifdef _DEBUG
|
|
141 |
RDebug::Print( _L("----- CalendarUI - action:") );
|
|
142 |
RDebug::RawPrint( aActionToExecute.Identifier() );
|
|
143 |
#endif
|
|
144 |
TRACE_EXIT_POINT;
|
|
145 |
}
|
|
146 |
|
|
147 |
// ---------------------------------------------------------------------------
|
|
148 |
// CCalenContextFWListener::HandleContextFrameworkError
|
|
149 |
// Indicates that error has occured.
|
|
150 |
// ---------------------------------------------------------------------------
|
|
151 |
//
|
|
152 |
void CCalenContextFWListener::HandleContextFrameworkError( TCFError aError,
|
|
153 |
const TDesC& aSource,
|
|
154 |
const TDesC& aType )
|
|
155 |
{
|
|
156 |
TRACE_ENTRY_POINT;
|
|
157 |
// no implementation
|
|
158 |
#ifdef _DEBUG
|
|
159 |
RDebug::Print( _L("----- CalendarUI - CF error:") );
|
|
160 |
RDebug::Print( _L("aError: %d"), aError );
|
|
161 |
RDebug::RawPrint( aSource );
|
|
162 |
RDebug::RawPrint( aType );
|
|
163 |
RDebug::Print( _L("-----------------------------") );
|
|
164 |
#endif
|
|
165 |
ASSERT( !aError );
|
|
166 |
TRACE_EXIT_POINT;
|
|
167 |
}
|
|
168 |
|
|
169 |
// ---------------------------------------------------------------------------
|
|
170 |
// CCalenContextFWListener::CCalenContextFWListener
|
|
171 |
// c++ constructor
|
|
172 |
// ---------------------------------------------------------------------------
|
|
173 |
//
|
|
174 |
CCalenContextFWListener::CCalenContextFWListener(CCalenAlarmManager& aAlarmManager)
|
|
175 |
:iAlarmManager(aAlarmManager)
|
|
176 |
{
|
|
177 |
TRACE_ENTRY_POINT;
|
|
178 |
TRACE_EXIT_POINT;
|
|
179 |
}
|
|
180 |
|
|
181 |
// ---------------------------------------------------------------------------
|
|
182 |
// CCalenContextFWListener::ConstructL
|
|
183 |
// Symbian 2nd phase constructor.
|
|
184 |
// ---------------------------------------------------------------------------
|
|
185 |
//
|
|
186 |
void CCalenContextFWListener::ConstructL()
|
|
187 |
{
|
|
188 |
TRACE_ENTRY_POINT;
|
|
189 |
// Context Framework client side API
|
|
190 |
OpenCFClientL();
|
|
191 |
|
|
192 |
if( !IsCalendarAlarmActiveL() )
|
|
193 |
{
|
|
194 |
// alarm not active anymore >> cancel the alarm mode
|
|
195 |
User::Leave( KErrCancel );
|
|
196 |
}
|
|
197 |
|
|
198 |
// subscribe to alarm 'Result' context
|
|
199 |
CCFContextSubscription* cs = CCFContextSubscription::NewLC();
|
|
200 |
cs->SetContextSourceL( KAlarmUISource );
|
|
201 |
cs->SetContextTypeL( KAlarmUISourceResult );
|
|
202 |
User::LeaveIfError( iCFClient->SubscribeContext( *cs ) );
|
|
203 |
User::LeaveIfError( iSubscribedContexts.Append( cs ) );
|
|
204 |
CleanupStack::Pop( cs );
|
|
205 |
TRACE_EXIT_POINT;
|
|
206 |
}
|
|
207 |
|
|
208 |
// ---------------------------------------------------------------------------
|
|
209 |
// CCalenContextFWListener::PublishContextL
|
|
210 |
// publish a context for the alarm
|
|
211 |
// ---------------------------------------------------------------------------
|
|
212 |
//
|
|
213 |
void CCalenContextFWListener::PublishContextL( const TDesC& aSource,
|
|
214 |
const TDesC& aType,
|
|
215 |
const TDesC& aValue )
|
|
216 |
{
|
|
217 |
TRACE_ENTRY_POINT;
|
|
218 |
CCFContextObject* co = CCFContextObject::NewLC( aSource, aType, aValue );
|
|
219 |
if(iCFClient)
|
|
220 |
{
|
|
221 |
const TInt err = iCFClient->PublishContext( *co );
|
|
222 |
|
|
223 |
#ifdef _DEBUG
|
|
224 |
RDebug::Print( _L("### PublishContext - err: %d"), err );
|
|
225 |
#endif
|
|
226 |
User::LeaveIfError( err );
|
|
227 |
}
|
|
228 |
CleanupStack::PopAndDestroy( co );
|
|
229 |
TRACE_EXIT_POINT;
|
|
230 |
}
|
|
231 |
|
|
232 |
// ---------------------------------------------------------------------------
|
|
233 |
// CCalenContextFWListener::AlarmStopL
|
|
234 |
// Publish a context to stop alarm
|
|
235 |
// ---------------------------------------------------------------------------
|
|
236 |
//
|
|
237 |
void CCalenContextFWListener::AlarmStopL()
|
|
238 |
{
|
|
239 |
TRACE_ENTRY_POINT;
|
|
240 |
// no need for the subscription(s) anymore...
|
|
241 |
// ...we'll exit the alarm mode anyway
|
|
242 |
// publish a new context for the alarm stop command
|
|
243 |
PublishContextL( KAlarmUISource,
|
|
244 |
KAlarmUISourceCommand,
|
|
245 |
TPtrC( KAlarmUISourceCommandValues[ ECommandAlarmStop] ) );
|
|
246 |
|
|
247 |
TRACE_EXIT_POINT;
|
|
248 |
}
|
|
249 |
|
|
250 |
// ---------------------------------------------------------------------------
|
|
251 |
// CCalenContextFWListener::AlarmSnoozeL
|
|
252 |
// Publish a context to snooze alarm
|
|
253 |
// ---------------------------------------------------------------------------
|
|
254 |
//
|
|
255 |
void CCalenContextFWListener::AlarmSnoozeL()
|
|
256 |
{
|
|
257 |
TRACE_ENTRY_POINT;
|
|
258 |
// no need for the subscription(s) anymore...
|
|
259 |
// ...we'll exit the alarm mode anyway
|
|
260 |
// publish a new context for the alarm snooze command
|
|
261 |
PublishContextL( KAlarmUISource,
|
|
262 |
KAlarmUISourceCommand,
|
|
263 |
TPtrC( KAlarmUISourceCommandValues[ ECommandAlarmSnooze] ) );
|
|
264 |
TRACE_EXIT_POINT;
|
|
265 |
}
|
|
266 |
|
|
267 |
// ---------------------------------------------------------------------------
|
|
268 |
// CCalenContextFWListener::OpenCFClientL
|
|
269 |
// Open the CCFClient session
|
|
270 |
// ---------------------------------------------------------------------------
|
|
271 |
//
|
|
272 |
void CCalenContextFWListener::OpenCFClientL()
|
|
273 |
{
|
|
274 |
TRACE_ENTRY_POINT;
|
|
275 |
if( !iCFClient )
|
|
276 |
{
|
|
277 |
iCFClient = CCFClient::NewL( *this );
|
|
278 |
}
|
|
279 |
TRACE_EXIT_POINT;
|
|
280 |
}
|
|
281 |
|
|
282 |
// ---------------------------------------------------------------------------
|
|
283 |
// CCalenContextFWListener::CloseCFClient
|
|
284 |
// Unsusbscribe all actions and close the session.
|
|
285 |
// ---------------------------------------------------------------------------
|
|
286 |
//
|
|
287 |
void CCalenContextFWListener::CloseCFClient()
|
|
288 |
{
|
|
289 |
TRACE_ENTRY_POINT;
|
|
290 |
UnsubscribeContexts();
|
|
291 |
delete iCFClient;
|
|
292 |
iCFClient = NULL;
|
|
293 |
TRACE_EXIT_POINT;
|
|
294 |
}
|
|
295 |
|
|
296 |
// ---------------------------------------------------------------------------
|
|
297 |
// CCalenContextFWListener::UnsubscribeContexts
|
|
298 |
// Unsusbscribe all actions
|
|
299 |
// ---------------------------------------------------------------------------
|
|
300 |
//
|
|
301 |
void CCalenContextFWListener::UnsubscribeContexts()
|
|
302 |
{
|
|
303 |
TRACE_ENTRY_POINT;
|
|
304 |
// unsubscribe all subscriptions
|
|
305 |
while( iSubscribedContexts.Count() )
|
|
306 |
{
|
|
307 |
CCFContextSubscription* cs = iSubscribedContexts[0];
|
|
308 |
iSubscribedContexts.Remove( 0 );
|
|
309 |
PIM_ASSERT( iCFClient->UnsubscribeContext( *cs ) );
|
|
310 |
delete cs;
|
|
311 |
}
|
|
312 |
iSubscribedContexts.Close();
|
|
313 |
TRACE_EXIT_POINT;
|
|
314 |
}
|
|
315 |
|
|
316 |
// ---------------------------------------------------------------------------
|
|
317 |
// CCalenContextFWListener::IsCalendarAlarmActiveL
|
|
318 |
// check if a calendar alarm is still active
|
|
319 |
// (alarm might have been dismissed before the viewer was fully constructed)
|
|
320 |
// ---------------------------------------------------------------------------
|
|
321 |
//
|
|
322 |
TBool CCalenContextFWListener::IsCalendarAlarmActiveL()
|
|
323 |
{
|
|
324 |
TRACE_ENTRY_POINT;
|
|
325 |
TBool retVal( EFalse );
|
|
326 |
|
|
327 |
RContextObjectArray arr;
|
|
328 |
CleanupResetAndDestroyPushL( arr );
|
|
329 |
|
|
330 |
CCFContextQuery* query = CCFContextQuery::NewLC( KAlarmUISource, KAlarmUISourceState );
|
|
331 |
const TInt err = iCFClient->RequestContext( *query, arr );
|
|
332 |
CleanupStack::PopAndDestroy( query );
|
|
333 |
|
|
334 |
if( !err )
|
|
335 |
{
|
|
336 |
for( TInt i(0); i < arr.Count(); i++ )
|
|
337 |
{
|
|
338 |
CCFContextObject* obj = arr[i];
|
|
339 |
#ifdef _DEBUG
|
|
340 |
RDebug::Print( _L("### found alarm context: %S"), &(obj->Value()) );
|
|
341 |
#endif
|
|
342 |
|
|
343 |
if( obj->Value() == TPtrC( KAlarmUISourceStateValues[EStateCalendarAlarm] ) )
|
|
344 |
{
|
|
345 |
retVal = ETrue;
|
|
346 |
break;
|
|
347 |
}
|
|
348 |
}
|
|
349 |
}
|
|
350 |
CleanupStack::PopAndDestroy( &arr );
|
|
351 |
TRACE_EXIT_POINT;
|
|
352 |
return retVal;
|
|
353 |
}
|
|
354 |
|
|
355 |
// ---------------------------------------------------------------------------
|
|
356 |
// CCalenContextFWListener::Extension
|
|
357 |
// ---------------------------------------------------------------------------
|
|
358 |
//
|
|
359 |
TAny* CCalenContextFWListener::Extension( const TUid&/* aExtensionUid */)const
|
|
360 |
{
|
|
361 |
TRACE_ENTRY_POINT;
|
|
362 |
TRACE_EXIT_POINT;
|
|
363 |
return NULL;
|
|
364 |
}
|
|
365 |
|
|
366 |
// End of File
|