|
1 /* |
|
2 * Copyright (c) 2006 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: Reactive authorization handling utilities |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //INCLUDES |
|
20 #include "CCAReactiveAuthorization.h" |
|
21 #include "CCAAppUi.h" |
|
22 #include "IMDialogUtils.h" |
|
23 #include "StringLoader.h" |
|
24 #include "IMUtils.h" |
|
25 #include "CCAContactEditor.h" |
|
26 #include "CAUtils.h" |
|
27 #include "CCABlockingUI.h" |
|
28 #include "ChatDebugAssert.h" |
|
29 #include "MCAReactiveAuthPC.h" |
|
30 #include "MCASettingsPC.h" |
|
31 #include "MCAProcessManager.h" |
|
32 #include "MCABlockingPC.h" |
|
33 #include <chatNG.rsg> |
|
34 #include <chatNG.mbg> |
|
35 #include "CCAUINGUtils.h" |
|
36 #include "CCAPCUtils.h" |
|
37 |
|
38 // The Settings have been moved to Cenrep (also retained in the Resource file), |
|
39 // so the enums for keys and central repository header is added here |
|
40 #include "VariantKeys.h" |
|
41 |
|
42 |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CCAReactiveAuthorization::CCAReactiveAuthorization |
|
48 // C++ default constructor can NOT contain any code, that |
|
49 // might leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CCAReactiveAuthorization::CCAReactiveAuthorization( CCAAppUi& aAppUi, |
|
53 MCAReactiveAuthPC* aReactiveAuthPC ) |
|
54 : iAppUi( aAppUi ), |
|
55 iReactiveAuthPC( aReactiveAuthPC ) |
|
56 { |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CCAReactiveAuthorization::NewLC |
|
61 // Two-phased constructor. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CCAReactiveAuthorization* CCAReactiveAuthorization::NewLC( CCAAppUi& aAppUi, |
|
65 MCAReactiveAuthPC* aReactiveAuthPC ) |
|
66 { |
|
67 CCAReactiveAuthorization* temp = |
|
68 new( ELeave )CCAReactiveAuthorization( aAppUi, aReactiveAuthPC ); |
|
69 CleanupStack::PushL( temp ); |
|
70 temp->ConstructL(); |
|
71 return temp; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CCAReactiveAuthorization::NewL |
|
76 // Two-phased constructor. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CCAReactiveAuthorization* CCAReactiveAuthorization::NewL( CCAAppUi& aAppUi, |
|
80 MCAReactiveAuthPC* aReactiveAuthPC ) |
|
81 { |
|
82 CCAReactiveAuthorization* temp = CCAReactiveAuthorization::NewLC( aAppUi, aReactiveAuthPC ); |
|
83 CleanupStack::Pop( temp ); |
|
84 return temp; |
|
85 } |
|
86 |
|
87 // Destructor |
|
88 CCAReactiveAuthorization::~CCAReactiveAuthorization() |
|
89 { |
|
90 delete iIdle; |
|
91 delete iBlockingUI; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CCAReactiveAuthorization::ConstructL |
|
96 // Symbian 2nd phase constructor can leave. |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CCAReactiveAuthorization::ConstructL() |
|
100 { |
|
101 iIdle = CIdle::NewL( CActive::EPriorityIdle ); |
|
102 |
|
103 // iBlockingUI is constructed when it's needed, |
|
104 // because of the login speedup |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CCAReactiveAuthorization::HandleRAPendingReqL |
|
109 // New pending request |
|
110 // (other items were commented in a header). |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CCAReactiveAuthorization::HandleRAPendingReqL() |
|
114 { |
|
115 if ( ! IMUtils::IntResourceValueL( |
|
116 RSC_CHAT_VARIATION_REACTIVE_PRESENCE_AUTH ) ) |
|
117 { |
|
118 // no RA active |
|
119 return; |
|
120 } |
|
121 |
|
122 // launch consumer method via CIdle |
|
123 if ( !iIdle->IsActive() && !iRequestPending ) |
|
124 { |
|
125 // not active, launch it again |
|
126 iIdle->Start( TCallBack( ConsumerCallback, this ) ); |
|
127 iRequestPending = ETrue; |
|
128 } |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CCAReactiveAuthorization::HandleRAStatusL |
|
133 // New RA status message |
|
134 // (other items were commented in a header). |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 void CCAReactiveAuthorization::HandleRAStatusL() |
|
138 { |
|
139 if ( ! IMUtils::IntResourceValueL( |
|
140 RSC_CHAT_VARIATION_REACTIVE_PRESENCE_AUTH ) ) |
|
141 { |
|
142 // no RA active |
|
143 return; |
|
144 } |
|
145 |
|
146 // launch consumer via CIdle |
|
147 if ( ! iIdle->IsActive() && !iRequestPending ) |
|
148 { |
|
149 // not active, launch it again |
|
150 iIdle->Start( TCallBack( ConsumerCallback, this ) ); |
|
151 iRequestPending = ETrue; |
|
152 } |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CCAReactiveAuthorization::HandleRAError |
|
157 // Error case, some of the RA observer methods left. |
|
158 // (other items were commented in a header). |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CCAReactiveAuthorization::HandleRAError( TInt aError ) |
|
162 { |
|
163 if ( aError ) |
|
164 { |
|
165 CActiveScheduler::Current()->Error( aError ); |
|
166 } |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CCAReactiveAuthorization::ConsumerCallback |
|
171 // (other items were commented in a header). |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 TInt CCAReactiveAuthorization::ConsumerCallback( TAny* aInstance ) |
|
175 { |
|
176 return static_cast<CCAReactiveAuthorization*>( aInstance )->Consumer(); |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CCAReactiveAuthorization::Consumer |
|
181 // (other items were commented in a header). |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 TInt CCAReactiveAuthorization::Consumer() |
|
185 { |
|
186 TRAPD( err, iRequestPending = DoConsumerL() ); |
|
187 |
|
188 if ( err ) |
|
189 { |
|
190 CActiveScheduler::Current()->Error( err ); |
|
191 iRequestPending = EFalse; |
|
192 } |
|
193 |
|
194 return iRequestPending; |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CCAReactiveAuthorization::DoConsumerL |
|
199 // (other items were commented in a header). |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 TInt CCAReactiveAuthorization::DoConsumerL() |
|
203 { |
|
204 // 1. get pending messages from IM Presence |
|
205 // - handle queue |
|
206 // 2. Get pending statuses from IM Presence |
|
207 // - handle queue |
|
208 // 3. If both queues are empty, get out |
|
209 |
|
210 |
|
211 |
|
212 HBufC* userId = HBufC::NewLC( KMaxWVIDLength ); |
|
213 |
|
214 // since this method got called, there has to be at least one (1) in either |
|
215 // array |
|
216 TPtr userIdPtr( userId->Des() ); |
|
217 TInt id = 0; |
|
218 TInt lastPendingPos = 0; |
|
219 |
|
220 // eat up the request queue |
|
221 // can get the whole list at once on pc side( like have been done for |
|
222 // status queue) n then handle here |
|
223 // can do later if it is a performance issue |
|
224 while ( iReactiveAuthPC->GetNextPendingRARequestL( id, userIdPtr, |
|
225 lastPendingPos ) ) |
|
226 { |
|
227 // keep on emptying the queue |
|
228 TBool response = DoHandleRAPendingReqL( *userId ); |
|
229 iReactiveAuthPC->SendReactiveAuthResponseL( id, response ); |
|
230 } |
|
231 |
|
232 |
|
233 // eat up the status queue |
|
234 CDesCArray* userIdsArray = new ( ELeave ) CDesCArrayFlat( 1 ); |
|
235 CleanupStack::PushL( userIdsArray ); |
|
236 |
|
237 iReactiveAuthPC->GetListOfRAStatusL( userIdPtr, *userIdsArray ); |
|
238 TInt count = userIdsArray->Count(); |
|
239 for ( TInt i( 0 ); i < count; i++ ) |
|
240 { |
|
241 // the user rejected us |
|
242 DoHandleRAStatusL( userIdsArray->MdcaPoint( i ) ); |
|
243 } |
|
244 |
|
245 CleanupStack::PopAndDestroy( userIdsArray ); |
|
246 CleanupStack::PopAndDestroy( userId ); |
|
247 return EFalse; |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CCAReactiveAuthorization::DoHandleRAPendingReqL |
|
252 // (other items were commented in a header). |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 TBool CCAReactiveAuthorization::DoHandleRAPendingReqL( const TDesC& aId ) |
|
256 { |
|
257 // reactive authorization pending request |
|
258 |
|
259 TBool accepted = EFalse; |
|
260 |
|
261 |
|
262 TInt authorizePresence = iAppUi.GetProcessManager().GetSettingsInterface() |
|
263 ->GetIntValuePC( TEnumsPC::EAuthorizeIMPresence, NULL ); |
|
264 if ( !IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_HAVEPRESENCEAUTH ) ) |
|
265 { |
|
266 // if VARIATION_HAVEPRESENCEAUTH is disabled, we always show RA query |
|
267 authorizePresence = TEnumsPC::EFriends; |
|
268 } |
|
269 |
|
270 switch ( authorizePresence ) |
|
271 { |
|
272 case TEnumsPC::EAllValue: |
|
273 { |
|
274 accepted = ETrue; |
|
275 break; |
|
276 } |
|
277 case TEnumsPC::ENobody: |
|
278 { |
|
279 accepted = EFalse; |
|
280 break; |
|
281 } |
|
282 case TEnumsPC::EFriends: |
|
283 { |
|
284 // check if we have that contact |
|
285 |
|
286 TBool isContactFound( iReactiveAuthPC->FindAnyContactL( aId ) ); |
|
287 MCABlockingPC* blockingPC = iAppUi.GetProcessManager().GetBlockingInterface(); |
|
288 TBool isContactBlocked = blockingPC->IsContactBlocked( aId ); |
|
289 |
|
290 if ( isContactFound && !isContactBlocked ) |
|
291 { |
|
292 // we have the user in our contactlist |
|
293 accepted = ETrue; |
|
294 } |
|
295 else if ( isContactBlocked ) |
|
296 { |
|
297 // we have the user in our blocked list |
|
298 accepted = EFalse; |
|
299 } |
|
300 else |
|
301 { |
|
302 TInt aliasErr( 0 ); |
|
303 HBufC* aliasTxt = NULL; |
|
304 HBufC* queryTxt = NULL; |
|
305 |
|
306 // Get alias |
|
307 |
|
308 TRAP( aliasErr, aliasTxt = iReactiveAuthPC->GetAliasL( aId ) ); |
|
309 CleanupStack::PushL( aliasTxt ); |
|
310 |
|
311 TBool validAlias( EFalse ); |
|
312 if ( aliasTxt ) |
|
313 { |
|
314 validAlias = TBool( aliasTxt->Length() ); |
|
315 } |
|
316 |
|
317 if ( aliasErr == KErrNotFound || !validAlias ) |
|
318 { |
|
319 // no alias, use wvid |
|
320 queryTxt = StringLoader::LoadLC( |
|
321 R_QTN_CHAT_REACTIVE_AUTHORIZE_QUERY, |
|
322 CCAPCUtils::DisplayId( aId ) ); |
|
323 } |
|
324 else |
|
325 { |
|
326 if ( aliasErr == KErrNone ) |
|
327 { |
|
328 // alias found |
|
329 queryTxt = StringLoader::LoadLC( R_QTN_CHAT_REACTIVE_AUTHORIZE_QUERY, |
|
330 *aliasTxt ); |
|
331 } |
|
332 else |
|
333 { |
|
334 // all other errors |
|
335 User::Leave( aliasErr ); |
|
336 } |
|
337 } |
|
338 |
|
339 // Ask from user to accept authorization |
|
340 TInt result = IMDialogUtils::DisplayQueryDialogL( |
|
341 R_GENERIC_YES_NO_CONFIRMATION_QUERY, |
|
342 *queryTxt ); |
|
343 |
|
344 CleanupStack::PopAndDestroy( queryTxt ); |
|
345 CleanupStack::PopAndDestroy( aliasTxt ); |
|
346 |
|
347 if ( ( result == EAknSoftkeyOk ) || ( result == EAknSoftkeyYes ) ) |
|
348 { |
|
349 // recipient has accepted authorization |
|
350 accepted = ETrue; |
|
351 |
|
352 // we don't have the contact, |
|
353 // so ask if the user wants to add it |
|
354 queryTxt = StringLoader::LoadLC( R_QTN_CHAT_REACTIVE_ADD_LIST, |
|
355 CCAPCUtils::DisplayId( aId ) ); |
|
356 result = IMDialogUtils::DisplayQueryDialogL( |
|
357 R_GENERIC_YES_NO_CONFIRMATION_QUERY, |
|
358 *queryTxt ); |
|
359 |
|
360 CleanupStack::PopAndDestroy( queryTxt ); |
|
361 |
|
362 if ( ( result == EAknSoftkeyOk ) || ( result == EAknSoftkeyYes ) ) |
|
363 { |
|
364 // verify that we have a contact list |
|
365 if ( CCAUINGUtils::VerifyContactlistL() == |
|
366 CCAUINGUtils::EChatNoContactList ) |
|
367 { |
|
368 // Could not create contact list |
|
369 break; |
|
370 } |
|
371 |
|
372 // add the contact to friends list |
|
373 TBool contactSaved = EFalse; |
|
374 |
|
375 CCAContactEditor* contactEditor = |
|
376 CCAContactEditor::NewL( -1, contactSaved ); |
|
377 TInt err; |
|
378 TRAP( err, contactEditor->EditContactLD( |
|
379 TEnumsPC::EAddToContact, KNullDesC(), aId ) ); |
|
380 } |
|
381 } |
|
382 else |
|
383 { |
|
384 // user did not auth, ask whether to block |
|
385 queryTxt = StringLoader::LoadLC( R_QTN_CHAT_REACTIVE_BLOCK, |
|
386 CCAPCUtils::DisplayId( aId ) ); |
|
387 result = IMDialogUtils::DisplayQueryDialogL( |
|
388 R_GENERIC_YES_NO_CONFIRMATION_QUERY, *queryTxt ); |
|
389 CleanupStack::PopAndDestroy( queryTxt ); |
|
390 |
|
391 if ( ( result == EAknSoftkeyOk ) || |
|
392 ( result == EAknSoftkeyYes ) ) |
|
393 { |
|
394 // make sure that blocking interface exists |
|
395 iAppUi.FinalizeChatConstructionL(); |
|
396 |
|
397 // block the contact |
|
398 if ( !iBlockingUI ) |
|
399 { |
|
400 |
|
401 iBlockingUI = CCABlockingUI::NewL( blockingPC ); |
|
402 |
|
403 } |
|
404 |
|
405 iBlockingUI->BlockUserL( aId ); |
|
406 } |
|
407 |
|
408 accepted = EFalse; |
|
409 } |
|
410 } |
|
411 break; |
|
412 } |
|
413 default: |
|
414 { |
|
415 // We should not get here... some strange value |
|
416 __CHAT_ASSERT_DEBUG( EFalse ); |
|
417 break; |
|
418 } |
|
419 } |
|
420 |
|
421 return accepted; |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CCAReactiveAuthorization::DoHandleRAStatusL |
|
426 // (other items were commented in a header). |
|
427 // ----------------------------------------------------------------------------- |
|
428 // |
|
429 void CCAReactiveAuthorization::DoHandleRAStatusL( const TDesC& aId ) |
|
430 { |
|
431 // reactive authorization status |
|
432 HBufC* text = StringLoader::LoadLC( |
|
433 R_QTN_CHAT_REACTIVE_NOT_AUTHORIZED, CCAPCUtils::DisplayId( aId ) ); |
|
434 IMDialogUtils::DisplayNoteDialogL( *text, R_AVKON_SOFTKEYS_OK_EMPTY__OK, |
|
435 CAknNoteDialog::ENoTimeout ); |
|
436 CleanupStack::PopAndDestroy( text ); |
|
437 } |
|
438 |
|
439 // End of file |
|
440 |