|
1 /* |
|
2 * Copyright (c) 2004-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: Implementation of the CVtUiExecuteCmdDialog class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CVtUiExecuteCmdDialog.h" |
|
22 #include "MVtUiEngineCommandManager.h" |
|
23 #include <mvtengcommandhandler.h> |
|
24 #include <cvtlogger.h> |
|
25 |
|
26 // MODULE DATA STRUCTURES |
|
27 |
|
28 /** |
|
29 * Active object to perform asynchronous commands. |
|
30 * @since Series 60 2.6 |
|
31 */ |
|
32 class CVtUiExecuteCmdDialog::CActiveCmd |
|
33 : public CActive |
|
34 { |
|
35 public: // Constructors and destructor |
|
36 |
|
37 /** |
|
38 * Constructor. |
|
39 */ |
|
40 CActiveCmd( |
|
41 CVtUiExecuteCmdDialog& aDialog, |
|
42 MVtEngCommandHandler& aCommandHandler, |
|
43 TVtEngCommandId aCommand, |
|
44 TDesC8* aParams ); |
|
45 |
|
46 /** |
|
47 * Destructor. |
|
48 */ |
|
49 ~CActiveCmd(); |
|
50 |
|
51 public: // New functions |
|
52 |
|
53 /** |
|
54 * Starts active object. Command will be performed in RunL. |
|
55 */ |
|
56 void Start(); |
|
57 |
|
58 /** |
|
59 * Checks if command has been performed. |
|
60 * @return ETrue if command has been performed. |
|
61 */ |
|
62 TBool CommandPerformed() const; |
|
63 |
|
64 private: |
|
65 |
|
66 /** |
|
67 * @see CActive::RunL |
|
68 */ |
|
69 void RunL(); |
|
70 |
|
71 /** |
|
72 * @see CActive::DoCancel. |
|
73 */ |
|
74 void DoCancel(); |
|
75 |
|
76 /** |
|
77 * @see CActive::RunError. |
|
78 */ |
|
79 TInt RunError( TInt aResult ); |
|
80 |
|
81 private: |
|
82 |
|
83 // Ref to dialog. |
|
84 CVtUiExecuteCmdDialog& iDialog; |
|
85 |
|
86 // Ref to command handler. |
|
87 MVtEngCommandHandler& iCommandHandler; |
|
88 |
|
89 // Command to be executed. |
|
90 TVtEngCommandId iCommand; |
|
91 |
|
92 // Owned parameters. |
|
93 TDesC8* iCommandParams; |
|
94 |
|
95 // ETrue if command has been performed. |
|
96 TBool iCommandPerformed; |
|
97 |
|
98 }; |
|
99 |
|
100 // ============================ MEMBER FUNCTIONS =============================== |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CVtUiExecuteCmdDialog::CVtUiExecuteCmdDialog |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 CVtUiExecuteCmdDialog::CVtUiExecuteCmdDialog( |
|
107 CEikDialog** aSelfPtr, |
|
108 MVtEngCommandHandler& aCommandHandler, |
|
109 MVtUiEngineCommandManager& aCommandManager ) |
|
110 : CVtUiBlankDialog( aSelfPtr ), |
|
111 iCommandHandler( aCommandHandler ), |
|
112 iCommandManager( aCommandManager ) |
|
113 { |
|
114 __VTPRINT2( DEBUG_GEN, "Ui.Dlg.Ctor this=%d", (TInt)this ) |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CVtUiExecuteCmdDialog::~CVtUiExecuteCmdDialog |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 CVtUiExecuteCmdDialog::~CVtUiExecuteCmdDialog() |
|
122 { |
|
123 __VTPRINTENTER( "VtUiExCmdDlg.~" ) |
|
124 __VTPRINT2( DEBUG_GEN, "VtUiExCmdDlg.~ this=%d", (TInt)this ) |
|
125 if ( iActiveCmd ) |
|
126 { |
|
127 if ( !iCommandCompleted && iActiveCmd->CommandPerformed() ) |
|
128 { |
|
129 iCommandHandler.CancelCommand( iCommand ); // ignore error |
|
130 } |
|
131 } |
|
132 delete iCommandParams; |
|
133 delete iActiveCmd; |
|
134 |
|
135 iCommandManager.RemoveObserver( *this ); |
|
136 __VTPRINTEXIT( "VtUiExCmdDlg.~" ) |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CVtUiExecuteCmdDialog::ExecuteCmdLD |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 void CVtUiExecuteCmdDialog::ExecuteCmdLD( |
|
144 const TVtEngCommandId aCommandId, |
|
145 TDesC8* aParams, |
|
146 TRequestStatus* aRequest ) |
|
147 { |
|
148 __VTPRINTENTER( "VtUiExCmdDlg.ExecuteCmd" ) |
|
149 __VTPRINT2( DEBUG_GEN, "Ui.Dlg.Exec this=%d", (TInt)this ) |
|
150 iCommand = aCommandId; |
|
151 CleanupStack::PushL( this ); |
|
152 if ( aParams ) |
|
153 { |
|
154 iCommandParams = aParams->AllocL(); |
|
155 } |
|
156 |
|
157 iCommandManager.AddObserverL( *this ); |
|
158 CleanupStack::Pop( this ); |
|
159 |
|
160 CVtUiBlankDialog::ExecuteDialogLD( aRequest ); |
|
161 __VTPRINTEXIT( "VtUiExCmdDlg.ExecuteCmd" ) |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CVtUiExecuteCmdDialog::PostLayoutDynInitL |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CVtUiExecuteCmdDialog::PostLayoutDynInitL() |
|
169 { |
|
170 __VTPRINTENTER( "VtUiExCmdDlg.PostL" ) |
|
171 iActiveCmd = |
|
172 new ( ELeave ) CActiveCmd( |
|
173 *this, iCommandHandler, iCommand, iCommandParams ); |
|
174 iActiveCmd->Start(); |
|
175 __VTPRINTEXITR( "VtUiExCmdDlg.PostL this=%d", (TInt)this ) |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CVtUiExecuteCmdDialog::HandleVTCommandPerformedL |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 void CVtUiExecuteCmdDialog::HandleVTCommandPerformedL( |
|
183 TVtEngCommandId aCommand, |
|
184 const TInt aError ) |
|
185 { |
|
186 __VTPRINTENTER( "VtUiExCmdDlg.HandleVTCommandPerformed" ) |
|
187 __VTPRINT2( DEBUG_GEN, "VtUiExCmdDlg.cmd.%d", aCommand ) |
|
188 __VTPRINT2( DEBUG_GEN, "VtUiExCmdDlg.err.%d", aError ) |
|
189 if ( iActiveCmd && ( aCommand == iCommand ) ) |
|
190 { |
|
191 if ( iActiveCmd->CommandPerformed() && !iCommandCompleted ) |
|
192 { |
|
193 __VTPRINT( DEBUG_GEN, "VtUiExCmdDlg.match" ) |
|
194 iCommandCompleted = ETrue; |
|
195 // Corrupted images may leave during initialization, thus we have |
|
196 // to mask out errors when they happen during share initialize. |
|
197 // Error code is handled correctly in CVtUiAppUi::CEventObserver:: |
|
198 // HandleVTCommandPerformedL() method, thus it will not be ignored. |
|
199 if ( aCommand == KVtEngInitializeShareImage ) |
|
200 { |
|
201 Complete( KErrNone ); |
|
202 } |
|
203 else |
|
204 { |
|
205 Complete( aError ); |
|
206 } |
|
207 } |
|
208 } |
|
209 __VTPRINTEXIT( "VtUiExCmdDlg.HandleVTCommandPerformed" ) |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CVtUiExecuteCmdDialog::HandleExecuteFailed |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CVtUiExecuteCmdDialog::HandleExecuteFailed( TInt aResult ) |
|
217 { |
|
218 __VTPRINT3( DEBUG_GEN, "VtUiExCmdDlg.Fail this=%d res=%d", |
|
219 (TInt)this, aResult ) |
|
220 Complete( aResult ); |
|
221 } |
|
222 |
|
223 // Implementation of CVtUiExecuteCmdDialog::CActiveCmd: |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CVtUiExecuteCmdDialog::CActiveCmd::CActiveCmd |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 CVtUiExecuteCmdDialog::CActiveCmd::CActiveCmd( |
|
230 CVtUiExecuteCmdDialog& aDialog, |
|
231 MVtEngCommandHandler& aCommandHandler, |
|
232 TVtEngCommandId aCommand, |
|
233 TDesC8* aParams) |
|
234 : CActive( CActive::EPriorityHigh ), |
|
235 iDialog( aDialog ), |
|
236 iCommandHandler( aCommandHandler ), |
|
237 iCommand( aCommand ), |
|
238 iCommandParams( aParams ) |
|
239 { |
|
240 CActiveScheduler::Add( this ); |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CVtUiExecuteCmdDialog::CActiveCmd::~CActiveCmd |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 CVtUiExecuteCmdDialog::CActiveCmd::~CActiveCmd() |
|
248 { |
|
249 __VTPRINT2( DEBUG_GEN, "VtUiExCmdDlgCmd.Dtor this=%d", (TInt)this ) |
|
250 Cancel(); |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CVtUiExecuteCmdDialog::CActiveCmd::Start |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 void CVtUiExecuteCmdDialog::CActiveCmd::Start() |
|
258 { |
|
259 __VTPRINTENTER( "VtUiExCmdDlgCmd.Start" ) |
|
260 TRequestStatus* status = &iStatus; |
|
261 User::RequestComplete( status, KErrNone ); |
|
262 SetActive(); |
|
263 __VTPRINTEXITR( "VtUiExCmdDlgCmd.Start this=%d", (TInt)this ) |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CVtUiExecuteCmdDialog::CActiveCmd::CommandPerformed |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 TBool CVtUiExecuteCmdDialog::CActiveCmd::CommandPerformed() const |
|
271 { |
|
272 __VTPRINT3( DEBUG_GEN, "VtUiExCmdDlgCmd.Perf this=%d,cmd=%d", |
|
273 (TInt)this, iCommandPerformed ) |
|
274 return iCommandPerformed; |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CVtUiExecuteCmdDialog::CActiveCmd::RunL |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CVtUiExecuteCmdDialog::CActiveCmd::RunL() |
|
282 { |
|
283 __VTPRINTENTER( "VtUiExCmdDlgCmd.RunL" ) |
|
284 iCommandHandler.ExecuteL( iCommand, iCommandParams ); |
|
285 iCommandPerformed = ETrue; |
|
286 __VTPRINTEXITR( "VtUiExCmdDlgCmd.RunL this=%d", (TInt)this ) |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CVtUiExecuteCmdDialog::CActiveCmd::DoCancel |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 void CVtUiExecuteCmdDialog::CActiveCmd::DoCancel() |
|
294 { |
|
295 __VTPRINT2( DEBUG_GEN, "VtUiExCmdDlgCmd.DoCnl this=%d", (TInt)this ) |
|
296 // Request is completed immediately. |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CVtUiExecuteCmdDialog::CActiveCmd::RunError |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 TInt CVtUiExecuteCmdDialog::CActiveCmd::RunError( TInt aResult ) |
|
304 { |
|
305 __VTPRINTENTER( "VtUiExCmdDlgCmd.RunError" ) |
|
306 // Exception was raised in RunL. Inform the dialog to close itself. |
|
307 iDialog.HandleExecuteFailed( aResult ); |
|
308 __VTPRINTEXITR( "VtUiExCmdDlgCmd.RunError this=%d", (TInt)this ) |
|
309 return KErrNone; |
|
310 } |
|
311 |
|
312 // End of File |