1 /* |
|
2 * Copyright (c) 2002-2005 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: Interface for service request |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cservicerequest.h" |
|
22 #include "mservicerequestobserver.h" |
|
23 #include <servicerequest.rsg> |
|
24 |
|
25 #include <AknWaitDialog.h> |
|
26 #include <AknGlobalNote.h> |
|
27 #include <aknnotewrappers.h> |
|
28 #include <avkon.hrh> |
|
29 |
|
30 #include <StringLoader.h> |
|
31 #include <gsmerror.h> |
|
32 #include <exterror.h> |
|
33 #include <ConeResLoader.h> |
|
34 #include <textresolver.h> |
|
35 |
|
36 |
|
37 // CONSTANTS |
|
38 _LIT( KSerqResourcesWithFullPath,"z:\\resource\\ServiceRequest.rsc" ); |
|
39 |
|
40 |
|
41 // ============================ MEMBER FUNCTIONS =============================== |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CServiceRequest::CServiceRequest |
|
45 // C++ default constructor can NOT contain any code that |
|
46 // might leave. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CServiceRequest::CServiceRequest( MServiceRequestObserver& aObserver ) |
|
50 : CActive(EPriorityStandard) , iObserver( aObserver ) |
|
51 { |
|
52 CActiveScheduler::Add( this ); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CServiceRequest::ConstructL |
|
57 // Symbian 2nd phase constructor can leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 void CServiceRequest::ConstructL() |
|
61 { |
|
62 iResourceLoader = new(ELeave) RConeResourceLoader( *CCoeEnv::Static() ); |
|
63 TFileName fileName( KSerqResourcesWithFullPath ); |
|
64 iResourceLoader->OpenL(fileName); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CServiceRequest::NewL |
|
69 // Two-phased constructor. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 EXPORT_C CServiceRequest* CServiceRequest::NewL( MServiceRequestObserver& aObserver ) |
|
73 { |
|
74 CServiceRequest* self = new( ELeave ) CServiceRequest( aObserver ); |
|
75 |
|
76 CleanupStack::PushL( self ); |
|
77 self->ConstructL(); |
|
78 CleanupStack::Pop( self ); |
|
79 |
|
80 return self; |
|
81 } |
|
82 |
|
83 // Destructor |
|
84 EXPORT_C CServiceRequest::~CServiceRequest() |
|
85 { |
|
86 Reset(); |
|
87 |
|
88 if ( iResourceLoader ) |
|
89 { |
|
90 iResourceLoader->Close(); |
|
91 } |
|
92 delete iResourceLoader; |
|
93 iResourceLoader = NULL; |
|
94 |
|
95 // If instance is deleted in call back - inform the function. |
|
96 if ( iDestroyed ) |
|
97 { |
|
98 *iDestroyed = ETrue; |
|
99 } |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CServiceRequest::Reset |
|
104 // Deletes used member data |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CServiceRequest::Reset() |
|
108 { |
|
109 Cancel(); |
|
110 |
|
111 delete iRequestingNote; |
|
112 iRequestingNote = NULL; |
|
113 |
|
114 delete iNoteText; |
|
115 iNoteText = NULL; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CServiceRequest::StartL |
|
120 // Launches the request note. |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 EXPORT_C void CServiceRequest::StartL( const TDesC& aText ) |
|
124 { |
|
125 |
|
126 // delete possible old data: |
|
127 Reset(); |
|
128 |
|
129 // Choose alternative "requesting" text if given |
|
130 if ( aText.Length() ) |
|
131 { |
|
132 iNoteText = aText.AllocL(); |
|
133 } |
|
134 |
|
135 // Create note and launch it. |
|
136 CAknWaitDialog* requestingNote = new(ELeave) CAknWaitDialog( |
|
137 (REINTERPRET_CAST(CEikDialog**,&iRequestingNote)) , ETrue ); |
|
138 iRequestingNote = requestingNote; |
|
139 requestingNote->PrepareLC( R_SERQ_REQUESTING_WAIT_NOTE ); |
|
140 if ( iNoteText ) |
|
141 { |
|
142 requestingNote->SetTextL( iNoteText->Des() ); |
|
143 } |
|
144 requestingNote->SetCallback( this ); |
|
145 requestingNote->RunLD(); |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CServiceRequest::DialogDismissedL |
|
150 // Called when the note is cancelled. Observer call made asyncronously. |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void CServiceRequest::DialogDismissedL( TInt aButtonId ) |
|
154 { |
|
155 Cancel(); |
|
156 |
|
157 if ( aButtonId == EAknSoftkeyQuit || aButtonId == EEikBidCancel ) |
|
158 { |
|
159 // Activate new request |
|
160 TRequestStatus* status = &iStatus; |
|
161 User::RequestComplete( status, aButtonId ); |
|
162 SetActive(); |
|
163 } |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CServiceRequest::ShowCompletionNoteL |
|
168 // Removes the wait note and shows another note if needed. |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 EXPORT_C void CServiceRequest::ShowCompletionNoteL( |
|
172 TBool aShowNote, |
|
173 TInt aError, |
|
174 TSerqNoteType aNoteType, |
|
175 const TDesC& aText ) |
|
176 { |
|
177 // delete old instances |
|
178 Reset(); |
|
179 |
|
180 // if new notes are not required |
|
181 if ( !aShowNote ) |
|
182 { |
|
183 return; |
|
184 } |
|
185 |
|
186 // Check default note appearance |
|
187 TInt defaultTextId; |
|
188 TSerqNoteType defaultNoteType; |
|
189 GetDefaultNote( aError , defaultNoteType , defaultTextId ); |
|
190 |
|
191 // Choose text |
|
192 if ( aText.Length() ) |
|
193 { |
|
194 iNoteText = aText.AllocL(); |
|
195 } |
|
196 else |
|
197 { |
|
198 // read from resources |
|
199 iNoteText = StringLoader::LoadL( defaultTextId, CCoeEnv::Static() ); |
|
200 } |
|
201 |
|
202 // Choose note type |
|
203 TSerqNoteType noteType; |
|
204 if ( aNoteType != ESerqDefault ) |
|
205 { |
|
206 noteType = aNoteType; |
|
207 } |
|
208 else |
|
209 { |
|
210 noteType = defaultNoteType; |
|
211 } |
|
212 |
|
213 // Start note |
|
214 LaunchNoteL( noteType ); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CServiceRequest::GetDefaultNote |
|
219 // Decides note type based on the given error value. |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CServiceRequest::GetDefaultNote( |
|
223 const TInt aError, |
|
224 TSerqNoteType& aNoteType, |
|
225 TInt& aResourceId ) |
|
226 { |
|
227 switch ( aError ) |
|
228 { |
|
229 case KErrNone: |
|
230 aResourceId = R_TEXT_DONE; |
|
231 aNoteType = ESerqGlobalConfirmationNote; |
|
232 break; |
|
233 case KErrCancel: |
|
234 aResourceId = R_TEXT_UNCONFIRMED; |
|
235 aNoteType = ESerqLocalInformationNote; |
|
236 break; |
|
237 case KErrInUse: |
|
238 case KErrAccessDenied: |
|
239 case KErrGsmSSUnknownSubscriber: |
|
240 case KErrGsmSSAbsentSubscriber: |
|
241 case KErrGsmSSIllegalOperation: |
|
242 case KErrGsmSSIllegalSubscriber: |
|
243 case KErrGsmSSSubscriptionViolation: |
|
244 case KErrGsmSSIllegalEquipment: |
|
245 aResourceId = R_TEXT_NOT_ALLOWED; |
|
246 aNoteType = ESerqGlobalInformationNote; |
|
247 break; |
|
248 case KErrGsmSSCallBarred: |
|
249 case KErrGsmSSIncompatibility: |
|
250 aResourceId = R_QTN_SRVRQ_INFO_CONFL; |
|
251 aNoteType = ESerqGlobalInformationNote; |
|
252 break; |
|
253 case KErrGsmSSSystemFailure: |
|
254 aResourceId = R_TEXT_RESULT_UNKNOWN; |
|
255 aNoteType = ESerqGlobalInformationNote; |
|
256 break; |
|
257 case KErrGsmSSErrorStatus: |
|
258 case KErrGsmSSUnexpectedDataValue: |
|
259 case KErrGsmSSResourcesUnavailable: |
|
260 aResourceId = R_TEXT_REQUEST_REJECTED; |
|
261 aNoteType = ESerqGlobalInformationNote; |
|
262 break; |
|
263 case KErrGsmSSPasswordAttemptsViolation: |
|
264 case KErrGsmSSNegativePasswordCheck: |
|
265 case KErrGsmSSPasswordRegistrationFailure: |
|
266 aResourceId = R_PASSWORD_ERROR_NOTE; |
|
267 aNoteType = ESerqGlobalErrorNote; |
|
268 break; |
|
269 case KErrGsmNoService: |
|
270 aResourceId = R_TEXT_NO_SERVICE; |
|
271 aNoteType = ESerqGlobalInformationNote; |
|
272 break; |
|
273 default: |
|
274 aResourceId = R_TEXT_NOT_DONE; |
|
275 aNoteType = ESerqGlobalInformationNote; |
|
276 break; |
|
277 } |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CServiceRequest::LaunchNoteL |
|
282 // Launches given note type. Text is got from iNoteText member variable. |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CServiceRequest::LaunchNoteL( const TSerqNoteType aNoteType) |
|
286 { |
|
287 |
|
288 switch ( aNoteType ) |
|
289 { |
|
290 case ESerqLocalInformationNote: |
|
291 case ESerqLocalConfirmationNote: |
|
292 { |
|
293 CAknResourceNoteDialog* dlg = NULL; |
|
294 if ( aNoteType == ESerqLocalInformationNote ) |
|
295 { |
|
296 dlg = new ( ELeave ) CAknInformationNote( ETrue ); |
|
297 } |
|
298 else |
|
299 { |
|
300 dlg = new ( ELeave ) CAknConfirmationNote( ETrue ); |
|
301 } |
|
302 dlg->ExecuteLD( iNoteText->Des() ); |
|
303 |
|
304 delete iNoteText; |
|
305 iNoteText = NULL; |
|
306 break; |
|
307 } |
|
308 case ESerqGlobalInformationNote: |
|
309 case ESerqGlobalErrorNote: |
|
310 case ESerqGlobalConfirmationNote: |
|
311 { |
|
312 CAknGlobalNote* dlg = CAknGlobalNote::NewLC(); |
|
313 if ( aNoteType == ESerqGlobalInformationNote ) |
|
314 { |
|
315 dlg->ShowNoteL( EAknGlobalInformationNote , iNoteText->Des() ); |
|
316 } |
|
317 else if ( aNoteType == ESerqGlobalErrorNote ) |
|
318 { |
|
319 dlg->ShowNoteL( EAknGlobalErrorNote , iNoteText->Des() ); |
|
320 } |
|
321 else |
|
322 { |
|
323 dlg->ShowNoteL( EAknGlobalConfirmationNote , iNoteText->Des() ); |
|
324 } |
|
325 CleanupStack::PopAndDestroy( dlg ); |
|
326 delete iNoteText; |
|
327 iNoteText = NULL; |
|
328 break; |
|
329 } |
|
330 default: |
|
331 User::Invariant(); |
|
332 break; |
|
333 } |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CServiceRequest::RunL |
|
338 // Calls observer interface to tell that the notes has been dismissed. |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 void CServiceRequest::RunL() |
|
342 { |
|
343 __ASSERT_ALWAYS( !iDestroyed, User::Invariant() ); |
|
344 |
|
345 TBool destr = EFalse; // Destructor changes to ETrue if deleted. |
|
346 iDestroyed = &destr; |
|
347 |
|
348 // Object still exists and the note is cancelled: |
|
349 TRAPD( error , |
|
350 iObserver.MServiceRequestNoteCancelledL( iStatus.Int() == EEikBidCancel ) ); |
|
351 |
|
352 // All OK |
|
353 if ( error == KErrNone ) |
|
354 { |
|
355 if ( !destr ) |
|
356 { |
|
357 iDestroyed = NULL; |
|
358 } |
|
359 return; |
|
360 } |
|
361 |
|
362 // We got an error value. |
|
363 if ( !destr ) |
|
364 { |
|
365 iDestroyed = NULL; |
|
366 User::Leave( error ); |
|
367 } |
|
368 else |
|
369 { |
|
370 CTextResolver* textResolver = CTextResolver::NewLC(); |
|
371 HBufC* buffer = textResolver->ResolveErrorString( error ).AllocLC(); |
|
372 CAknGlobalNote* note = CAknGlobalNote::NewLC(); |
|
373 note->ShowNoteL( EAknGlobalErrorNote, *buffer ); |
|
374 CleanupStack::PopAndDestroy( note ); |
|
375 CleanupStack::PopAndDestroy( buffer ); |
|
376 CleanupStack::PopAndDestroy( textResolver ); |
|
377 } |
|
378 } |
|
379 |
|
380 // --------------------------------------------------------- |
|
381 // CServiceRequest::RunError |
|
382 // Called when RunL leaves |
|
383 // (other items were commented in a header). |
|
384 // --------------------------------------------------------- |
|
385 // |
|
386 TInt CServiceRequest::RunError( TInt /*aError*/ ) |
|
387 { |
|
388 return KErrNone; |
|
389 } |
|
390 |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CServiceRequest::DoCancel |
|
394 // Does nothing. Must be implemented due inheritance. |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 void CServiceRequest::DoCancel() |
|
398 { |
|
399 } |
|
400 |
|
401 // End of File |
|