|
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: Encapuslates the Wait dialog in an Active Object interface |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Includes |
|
20 #include <evtmgmteditorui.rsg> |
|
21 #include <eikenv.h> |
|
22 |
|
23 // User Includes |
|
24 #include "evtmgmtuiwaitdlglauncher.h" |
|
25 #include "evtdebug.h" |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CLmkWaitDialogLauncher::CLmkWaitDialogLauncher |
|
29 // C++ Overloaded constructor can NOT contain any code, that |
|
30 // might leave. |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CEvtMgmtUiWaitDialogLauncher::CEvtMgmtUiWaitDialogLauncher() |
|
34 :CActive( EPriorityUserInput ) |
|
35 { |
|
36 iIsCancelAvailable = ETrue; |
|
37 iObserver = NULL; |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CEvtMgmtUiWaitDialogLauncher::~CEvtMgmtUiWaitDialogLauncher |
|
42 // C++ destructor |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CEvtMgmtUiWaitDialogLauncher::~CEvtMgmtUiWaitDialogLauncher() |
|
46 { |
|
47 Cancel(); |
|
48 |
|
49 if ( iSchedWait->IsStarted() ) |
|
50 { |
|
51 iSchedWait->AsyncStop(); |
|
52 } |
|
53 |
|
54 delete iSchedWait; |
|
55 iSchedWait =NULL; |
|
56 |
|
57 delete iWaitText; |
|
58 iWaitText =NULL; |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CEvtMgmtUiWaitDialogLauncher* CEvtMgmtUiWaitDialogLauncher::NewL |
|
63 // Two phase constructor |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CEvtMgmtUiWaitDialogLauncher* CEvtMgmtUiWaitDialogLauncher::NewL() |
|
67 { |
|
68 CEvtMgmtUiWaitDialogLauncher* self = |
|
69 new ( ELeave ) CEvtMgmtUiWaitDialogLauncher(); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop( self ); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // void CEvtMgmtUiWaitDialogLauncher::ConstructL |
|
78 // Second phase constructor |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void CEvtMgmtUiWaitDialogLauncher::ConstructL() |
|
82 { |
|
83 iSchedWait = new ( ELeave )CActiveSchedulerWait; |
|
84 CActiveScheduler::Add( this); |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // void CEvtMgmtUiWaitDialogLauncher::SetObserver |
|
89 // ----------------------------------------------------------------------------- |
|
90 void CEvtMgmtUiWaitDialogLauncher::SetObserver( MEvtMgmtUiWaitDialogLauncherObserver* aObserver) |
|
91 { |
|
92 iObserver = aObserver; |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // void CEvtMgmtUiWaitDialogLauncher::SetTextL |
|
97 // ----------------------------------------------------------------------------- |
|
98 void CEvtMgmtUiWaitDialogLauncher::SetTextL(const TDesC& aText) |
|
99 { |
|
100 if(iWaitText) |
|
101 { |
|
102 delete iWaitText; |
|
103 iWaitText = NULL; |
|
104 } |
|
105 |
|
106 iWaitText = aText.AllocL(); |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // void CEvtMgmtUiWaitDialogLauncher::SetTextL |
|
111 // ----------------------------------------------------------------------------- |
|
112 void CEvtMgmtUiWaitDialogLauncher::SetTextL( const TInt aResourceId ) |
|
113 { |
|
114 if(iWaitText) |
|
115 { |
|
116 delete iWaitText; |
|
117 iWaitText = NULL; |
|
118 } |
|
119 iWaitText = CEikonEnv::Static()->AllocReadResourceAsDes16L( aResourceId ); |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // void CEvtMgmtUiWaitDialoaLauncher::AllowUserToCancel |
|
124 // ----------------------------------------------------------------------------- |
|
125 void CEvtMgmtUiWaitDialogLauncher::AllowUserToCancel( TBool aIsCancelAvailable ) |
|
126 { |
|
127 iIsCancelAvailable = aIsCancelAvailable; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // void CEvtMgmtUiWaitDialogLauncher::StartWaitDialogL |
|
132 // Starts the wait dialog |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CEvtMgmtUiWaitDialogLauncher::StartWaitDialogL() |
|
136 { |
|
137 EVTUIDEBUG("+ CEvtMgmtUiWaitDialogLauncher::StartWaitDialogL" ); |
|
138 if( IsActive()) |
|
139 { |
|
140 User::Leave( KErrInUse ); |
|
141 } |
|
142 |
|
143 // Issue a request for Wait dialog launching |
|
144 |
|
145 TRequestStatus* status = &iStatus; |
|
146 User::RequestComplete( status, KErrNone ); |
|
147 SetActive(); |
|
148 EVTUIDEBUG("- CEvtMgmtUiWaitDialogLauncher::StartWaitDialogL" ); |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // void CEvtMgmtUiWaitDialogLauncher::StartWaitDialogL |
|
153 // Stops the wait dialog |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 TInt CEvtMgmtUiWaitDialogLauncher::StopWaitDialogL() |
|
157 { |
|
158 EVTUIDEBUG("+ CEvtMgmtUiWaitDialogLauncher::StopWaitDialogL" ); |
|
159 if ( iWaitNote ) |
|
160 { |
|
161 TRAPD( err, iWaitNote->ProcessFinishedL() ); |
|
162 if (err != KErrNone) |
|
163 { |
|
164 delete iWaitNote; |
|
165 iWaitNote = NULL; |
|
166 return KErrNone; |
|
167 } |
|
168 } |
|
169 |
|
170 // Rechecking the Wait note is required since, the value might get modified |
|
171 // in DialogDismissedL call |
|
172 |
|
173 if( iWaitNote ) |
|
174 { |
|
175 EVTUIDEBUG("= Start Scheduler wait loop" ); |
|
176 if ( !iSchedWait->IsStarted() ) |
|
177 iSchedWait->Start(); |
|
178 } |
|
179 EVTUIDEBUG("- CEvtMgmtUiWaitDialogLauncher::StopWaitDialogL" ); |
|
180 |
|
181 // Return the Button ID with which the dialog was dismissed |
|
182 return iButtonId; |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // void CEvtMgmtUiWaitDialogLauncher::DialogDismissedL |
|
187 // Inherited from MProgressDialogCallback |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CEvtMgmtUiWaitDialogLauncher::DialogDismissedL( TInt aButtonId ) |
|
191 { |
|
192 EVTUIDEBUG1("+ CEvtMgmtUiWaitDialogLauncher::DialogDismissedL - %d", aButtonId ); |
|
193 // Store the Button ID for later retrival |
|
194 iButtonId = aButtonId; |
|
195 |
|
196 if ( iSchedWait->IsStarted() ) |
|
197 { |
|
198 iSchedWait->AsyncStop(); |
|
199 } |
|
200 iWaitNote = NULL; |
|
201 if(iObserver) |
|
202 { |
|
203 iObserver->HandleDialogDismissed( iButtonId ); |
|
204 } |
|
205 EVTUIDEBUG("- CEvtMgmtUiWaitDialogLauncher::DialogDismissedL" ); |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // void CEvtMgmtUiWaitDialogLauncher::RunL |
|
210 // Inherited from CActive |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CEvtMgmtUiWaitDialogLauncher::RunL() |
|
214 { |
|
215 EVTUIDEBUG("+ CEvtMgmtUiWaitDialogLauncher::RunL" ); |
|
216 if( iStatus.Int() == KErrNone ) |
|
217 { |
|
218 // Launch the Wait dialog |
|
219 iWaitNote = new (ELeave) CAknWaitDialog |
|
220 ((REINTERPRET_CAST(CEikDialog**,&iWaitNote)), ETrue ); |
|
221 iWaitNote->SetCallback( this ); |
|
222 iWaitNote->SetTextL(*iWaitText); |
|
223 |
|
224 TInt resourceId ; |
|
225 if(iIsCancelAvailable) |
|
226 resourceId = R_EVTMGMTUI_WAITDLG_CANCEL; |
|
227 else |
|
228 resourceId = R_EVTEDITOR_WAITDLG; |
|
229 |
|
230 EVTUIDEBUG("= Before Dialog Launch" ); |
|
231 if ( !iWaitNote->ExecuteLD( resourceId ) ) |
|
232 { |
|
233 EVTUIDEBUG("= After Dialog Launch" ); |
|
234 //making iWaitNote null, since framework destroys waitnote |
|
235 //dialog on pressing cancel. |
|
236 iWaitNote = NULL; |
|
237 } |
|
238 } |
|
239 EVTUIDEBUG("+ CEvtMgmtUiWaitDialogLauncher::RunL" ); |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // void CEvtMgmtUiWaitDialogLauncher::DoCancel |
|
244 // Inherited from CActive |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 void CEvtMgmtUiWaitDialogLauncher::DoCancel() |
|
248 { |
|
249 TRAP_IGNORE(StopWaitDialogL()); |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // void CEvtMgmtUiWaitDialogLauncher::StartWaitDialogSyncL |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 void CEvtMgmtUiWaitDialogLauncher::StartWaitDialogSyncL() |
|
257 { |
|
258 // Check if there is any outstanding operation. If Yes, the one cannot |
|
259 // proceed |
|
260 if ( iWaitNote || IsActive()) |
|
261 { |
|
262 User::Leave( KErrInUse ); |
|
263 } |
|
264 |
|
265 // Launch the Wait dialog |
|
266 iWaitNote = new ( ELeave ) CAknWaitDialog |
|
267 (( REINTERPRET_CAST( CEikDialog**,&iWaitNote )), ETrue ); |
|
268 iWaitNote->SetTextL( *iWaitText ); |
|
269 |
|
270 TInt resourceId ; |
|
271 if(iIsCancelAvailable) |
|
272 { |
|
273 resourceId = R_EVTMGMTUI_WAITDLG_CANCEL; |
|
274 } |
|
275 else |
|
276 { |
|
277 resourceId = R_EVTEDITOR_WAITDLG; |
|
278 } |
|
279 |
|
280 if ( !iWaitNote->ExecuteLD( resourceId ) ) |
|
281 { |
|
282 //making iWaitNote null, since framework destroys waitnote |
|
283 //dialog on pressing cancel. |
|
284 iWaitNote = NULL; |
|
285 } |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // TInt CEvtMgmtUiWaitDialogLauncher::StopWaitDialogSyncL |
|
290 // ----------------------------------------------------------------------------- |
|
291 // |
|
292 TInt CEvtMgmtUiWaitDialogLauncher::StopWaitDialogSyncL() |
|
293 { |
|
294 // Dismiss the Wait note |
|
295 if ( iWaitNote ) |
|
296 { |
|
297 TRAPD( err, iWaitNote->ProcessFinishedL() ); |
|
298 if (err != KErrNone) |
|
299 { |
|
300 delete iWaitNote; |
|
301 iWaitNote = NULL; |
|
302 return KErrNone; |
|
303 } |
|
304 } |
|
305 |
|
306 // Return the stored button ID |
|
307 return iButtonId; |
|
308 } |
|
309 // End of File |
|
310 |