|
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: Handler for notifier on Event |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include <AknGlobalNote.h> // CAknGlobalNote |
|
22 |
|
23 #include "evtdebug.h" |
|
24 #include "evtnotifierhandler.h" |
|
25 #include "evtnotifierobserver.h" |
|
26 #include "evttoneaction.h" |
|
27 #include "evtglobalquery.h" |
|
28 |
|
29 // EXTERNAL DATA STRUCTURES |
|
30 |
|
31 // EXTERNAL FUNCTION PROTOTYPES |
|
32 |
|
33 // CONSTANTS |
|
34 //S60 Event Notifier plugin id |
|
35 const TUid KEvtNotifierUidS60 = { 0x2001E66C }; |
|
36 |
|
37 // MACROS |
|
38 |
|
39 // LOCAL CONSTANTS AND MACROS |
|
40 |
|
41 // MODULE DATA STRUCTURES |
|
42 |
|
43 // LOCAL FUNCTION PROTOTYPES |
|
44 |
|
45 // FORWARD DECLARATIONS |
|
46 |
|
47 // ============================= LOCAL FUNCTIONS =============================== |
|
48 |
|
49 // ============================ MEMBER FUNCTIONS =============================== |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CEvtNotifierHandler::NewL |
|
53 // ----------------------------------------------------------------------------- |
|
54 CEvtNotifierHandler* CEvtNotifierHandler::NewL( |
|
55 MEvtNotifierObserver& aNotifierObserver, |
|
56 TEvtEventInfo aEventInfo ) |
|
57 { |
|
58 CEvtNotifierHandler* self = new ( ELeave ) CEvtNotifierHandler( aNotifierObserver, aEventInfo ); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CEvtNotifierHandler::CEvtNotifierHandler |
|
67 // ----------------------------------------------------------------------------- |
|
68 CEvtNotifierHandler::CEvtNotifierHandler( |
|
69 MEvtNotifierObserver& aNotifierObserver, TEvtEventInfo aEventInfo ) |
|
70 : CActive( EPriorityStandard ), |
|
71 iNotifierObserver( aNotifierObserver ),iEventInfo(aEventInfo) |
|
72 { |
|
73 CActiveScheduler::Add( this ); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CEvtNotifierHandler::~CEvtNotifierHandler |
|
78 // ----------------------------------------------------------------------------- |
|
79 CEvtNotifierHandler::~CEvtNotifierHandler() |
|
80 { |
|
81 delete iInputParam; |
|
82 delete iInputBuffer; |
|
83 |
|
84 Cancel(); |
|
85 |
|
86 if(iEvtGlobalQuery) |
|
87 { |
|
88 delete iEvtGlobalQuery; |
|
89 iEvtGlobalQuery = NULL; |
|
90 } |
|
91 |
|
92 iNotifier.Close(); |
|
93 |
|
94 delete iEvent; |
|
95 delete iEventManager; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CEvtNotifierHandler::ConstructL |
|
100 // ----------------------------------------------------------------------------- |
|
101 void CEvtNotifierHandler::ConstructL() |
|
102 { |
|
103 EVTUIDEBUG("+ CEvtNotifierHandler::ConstructL"); |
|
104 iInputBuffer = CBufFlat::NewL( KEvtNotifierBufferLength ); |
|
105 iInputParam = CEvtInfoNoteInputParam::NewL(); |
|
106 iResponseBuffer.Zero(); |
|
107 iResponseBuffer.SetLength( KEventIdLength ); |
|
108 iEventManager = CEvtEventManager::NewL(); |
|
109 EVTUIDEBUG( "- CEvtNotifierHandler::ConstructL" ); |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CEvtNotifierHandler::IsLaunchable |
|
114 // ----------------------------------------------------------------------------- |
|
115 TBool CEvtNotifierHandler::IsLaunchable() |
|
116 { |
|
117 EVTUIDEBUG( "+ CEvtNotifierHandler::IsLaunchable" ); |
|
118 TBool launchable = EFalse; |
|
119 |
|
120 TRAPD( evtErr, iEvent = iEventManager->GetEventL( iEventInfo.iEventId ) ); |
|
121 if( !evtErr && iEvent && iEvent->EventStatus() == EActive ) |
|
122 { |
|
123 launchable = ETrue; |
|
124 } |
|
125 |
|
126 return launchable; |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CEvtNotifierHandler::StartEvtNotifier |
|
131 // ----------------------------------------------------------------------------- |
|
132 void CEvtNotifierHandler::StartEvtNotifierL() |
|
133 { |
|
134 EVTUIDEBUG( "+ CEvtNotifierHandler::StartEvtNotifierL" ); |
|
135 |
|
136 if( iEvent ) |
|
137 { |
|
138 CEvtInfoNoteInputParam::TEvtTriggerAccuracy accuracy; |
|
139 accuracy = static_cast< CEvtInfoNoteInputParam::TEvtTriggerAccuracy>(iEventInfo.iAccuracy); |
|
140 // set the subject and description of notifier |
|
141 iInputParam->SetSubjectL( iEvent->Subject() ); |
|
142 iInputParam->SetDescriptionL( iEvent->Description() ); |
|
143 iInputParam->SetTrigerringAccuracy( accuracy ); |
|
144 iInputParam->SetToneEnabled( iEventInfo.iPlayTone ); |
|
145 iInputParam->SetShowSnooze( iEventInfo.iSnooze ); |
|
146 if( iEventInfo.iPlayTone && iEvent->HasAction() ) |
|
147 { |
|
148 // Populate the Tone. |
|
149 CEvtToneAction* tone = CEvtToneAction::NewLC(); |
|
150 tone->InternalizeL( iEvent->Action() ); |
|
151 iInputParam->SetToneL( tone->FileName() ); |
|
152 iInputParam->SetToneRepeat( tone->ToneLoop() ); |
|
153 CleanupStack::PopAndDestroy(tone); |
|
154 } |
|
155 |
|
156 EVTUIDEBUG( "Trigger Fired Event" ); |
|
157 |
|
158 if(iEvent->Subject().Length()) |
|
159 { |
|
160 TPtrC subject( iEvent->Subject() ); |
|
161 EVTUIDEBUG1( "Subject = %S", &subject ); |
|
162 } |
|
163 EVTUIDEBUG1( "Tigger ID = %d", iEvent->EventId() ); |
|
164 |
|
165 RBufWriteStream writeStream( *iInputBuffer, 0 ); |
|
166 CleanupClosePushL( writeStream ); |
|
167 |
|
168 iInputParam->ExternalizeL( writeStream ); |
|
169 |
|
170 TPtr8 bufPtr( const_cast< TUint8 *>( iInputBuffer->Ptr( 0 ).Ptr() ), |
|
171 iInputBuffer->Ptr( 0 ).Length(), |
|
172 iInputBuffer->Ptr( 0 ).Length() ); |
|
173 |
|
174 iHandlerType = EHandlerNotifier; |
|
175 User::LeaveIfError( iNotifier.Connect()); |
|
176 iNotifier.StartNotifierAndGetResponse( iStatus, KEvtNotifierUidS60, bufPtr, iResponseBuffer ); |
|
177 SetActive(); |
|
178 |
|
179 CleanupStack::Pop(); // writeStream |
|
180 } |
|
181 EVTUIDEBUG( "- CEvtNotifierHandler::StartEvtNotifierL" ); |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CEvtNotifierHandler::RunL |
|
186 // ----------------------------------------------------------------------------- |
|
187 void CEvtNotifierHandler::RunL() |
|
188 { |
|
189 EVTUIDEBUG1( "+ CEvtNotifierHandler::RunL %d", iStatus.Int() ); |
|
190 TEvtInfoNoteResult result = ECloseInfoNote; |
|
191 switch( iStatus.Int() ) |
|
192 { |
|
193 case KErrNone: |
|
194 { |
|
195 TInt retVal = 0; |
|
196 TLex8 lexer( iResponseBuffer ); |
|
197 TInt error = lexer.Val( retVal ); |
|
198 |
|
199 EVTUIDEBUG1( "Event %d", retVal ); |
|
200 switch( retVal ) |
|
201 { |
|
202 case EOpenTrigger: |
|
203 { |
|
204 result = EOpenTrigger; |
|
205 break; |
|
206 } |
|
207 case EShowDetails: |
|
208 { |
|
209 result = EShowDetails; |
|
210 break; |
|
211 } |
|
212 case ESnoozeTrigger: |
|
213 { |
|
214 result = ESnoozeTrigger; |
|
215 break; |
|
216 } |
|
217 case ECloseInfoNote: |
|
218 default: |
|
219 { |
|
220 result = ECloseInfoNote; |
|
221 break; |
|
222 } |
|
223 } |
|
224 // Complete the event note launching |
|
225 iNotifierObserver.HandlerCompleteL( result, iEvent ); |
|
226 break; |
|
227 } |
|
228 default: |
|
229 { |
|
230 if(iHandlerType == EHandlerNotifier) |
|
231 { |
|
232 iHandlerType = EHandlerGlobalNote; |
|
233 iStatus = KRequestPending; |
|
234 if(iEvtGlobalQuery) |
|
235 { |
|
236 delete iEvtGlobalQuery; |
|
237 iEvtGlobalQuery = NULL; |
|
238 } |
|
239 iEvtGlobalQuery = CEvtGlobalQuery::NewL(*iInputParam); |
|
240 iEvtGlobalQuery->StartGlobalQueryL( iStatus, iResponseBuffer ); |
|
241 SetActive(); |
|
242 } |
|
243 else |
|
244 { |
|
245 // Complete the event note launching |
|
246 iNotifierObserver.HandlerCompleteL( result, iEvent ); |
|
247 } |
|
248 break; |
|
249 } |
|
250 } |
|
251 |
|
252 EVTUIDEBUG( "- CEvtNotifierHandler::RunL" ); |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CEvtNotifierHandler::DoCancel |
|
257 // ----------------------------------------------------------------------------- |
|
258 void CEvtNotifierHandler::DoCancel() |
|
259 { |
|
260 EVTUIDEBUG( "+ CEvtNotifierHandler::DoCancel()" ); |
|
261 if(iHandlerType == EHandlerNotifier) |
|
262 { |
|
263 iNotifier.CancelNotifier( KEvtNotifierUidS60 ); |
|
264 } |
|
265 else |
|
266 { |
|
267 iEvtGlobalQuery->CancelDialog(); |
|
268 } |
|
269 EVTUIDEBUG( "- CEvtNotifierHandler::DoCancel()" ); |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CEvtNotifierHandler::RunError |
|
274 // ----------------------------------------------------------------------------- |
|
275 TInt CEvtNotifierHandler::RunError( TInt /*aError*/ ) |
|
276 { |
|
277 return KErrNone; |
|
278 } |
|
279 |
|
280 // End of File |