|
1 /* |
|
2 * Copyright (c) 2002-2007 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: MMsgMailOpObserver |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cmsgmailbaseop.h" |
|
22 #include "mmsgmailappuiopdelegate.h" |
|
23 #include "MailLog.h" |
|
24 #include "MsgMailEditorDocument.h" |
|
25 #include <StringLoader.h> |
|
26 #include <eikenv.h> |
|
27 #include <MsgEditorAppUi.rsg> |
|
28 #include <MsgMailEditor.rsg> |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CMsgMailBaseOp::CMsgMailBaseOp |
|
34 // C++ default constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CMsgMailBaseOp::CMsgMailBaseOp( |
|
39 CMsgMailEditorDocument& aDocument ) |
|
40 : CActive( CActive::EPriorityStandard ), |
|
41 iDocument( aDocument ), |
|
42 iState( EIdleState ), |
|
43 iWaitingError( KMaxTInt ) |
|
44 { |
|
45 CActiveScheduler::Add( this ); |
|
46 } |
|
47 |
|
48 // Destructor |
|
49 CMsgMailBaseOp::~CMsgMailBaseOp() |
|
50 { |
|
51 LOG( "CMsgMailBaseOp::~CMsgMailBaseOp" ); |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CMsgMailBaseOp::DoCancel |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void CMsgMailBaseOp::DoCancel() |
|
59 { |
|
60 LOG1( "CMsgMailBaseOp::DoCancel @ iState:%d", iState ); |
|
61 HandleOperationCancel(); // let subclass cancel outstanding request |
|
62 CompleteOperation( KErrCancel ); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CMsgMailBaseOp::RunL |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CMsgMailBaseOp::RunL() |
|
70 { |
|
71 LOG1( "CMsgMailBaseOp::RunL @ iState:%d", iState ); |
|
72 TInt completionCode = iStatus.Int(); |
|
73 if ( completionCode != KErrNone ) |
|
74 { // entering this branch means that latest request (iteration) was |
|
75 // completed with an error code |
|
76 LOG1( "CMsgMailBaseOp::RunL, completed with error: %d", |
|
77 completionCode ); |
|
78 if ( !HandleStateActionError( completionCode ) ) |
|
79 { // error wasn't handled -> complete operation |
|
80 LOG( "CMsgMailBaseOp::RunL, error wasn't handled -> stopping" ); |
|
81 CompleteOperation( completionCode ); |
|
82 return; |
|
83 } |
|
84 } |
|
85 |
|
86 if( iWaitingError <= KErrNone && |
|
87 iState == EIdleState ) |
|
88 { |
|
89 // Wait note was dismissed and we can complete the operation. |
|
90 LOG1( "CMsgMailBaseOp::RunL, wait note dismissed -> operation done: %d", |
|
91 iWaitingError ); |
|
92 NotifyObservers( iWaitingError ); |
|
93 } |
|
94 else |
|
95 { |
|
96 // Start handling next state |
|
97 SetNextState(); |
|
98 |
|
99 if ( iState == EIdleState ) |
|
100 { |
|
101 CompleteOperation( KErrNone ); |
|
102 } |
|
103 else |
|
104 { |
|
105 HandleStateActionL(); // call subclass to handle the action |
|
106 } |
|
107 } |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CMsgMailBaseOp::RunError |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 TInt CMsgMailBaseOp::RunError( TInt aError ) |
|
115 { |
|
116 LOG2( "CMsgMailBaseOp::RunError @ iState: %d, aError:%d", iState, aError ); |
|
117 |
|
118 // Usually we must return KErrNone, but with KLeaveExit,KErrDiskFull and KErrNoMemory |
|
119 // we must return error code. |
|
120 // We have to return KLeaveExit to get appui deleted. We also don't want |
|
121 // to notify observer anymore in that case. |
|
122 // KErrDiskFull and KErrNoMemory are returned because otherwise error note is not shown. |
|
123 if ( aError == KLeaveExit ) |
|
124 { |
|
125 LOG1("ERROR %d", aError); |
|
126 return aError; |
|
127 } |
|
128 else if(aError == KErrDiskFull || aError == KErrNoMemory) |
|
129 { |
|
130 LOG1("ERROR KErrDiskFull or KErrNoMemory: %d", aError); |
|
131 CompleteOperation( KErrCancel ); |
|
132 return aError; |
|
133 } |
|
134 else if ( HandleStateActionError( aError ) ) |
|
135 { // error was handled -> we can continue with next step |
|
136 LOG( "CMsgMailBaseOp::RunError, error was handled" ); |
|
137 return KErrNone; |
|
138 } |
|
139 else |
|
140 { // error wasn't handled -> complete operation |
|
141 LOG( "CMsgMailBaseOp::RunError, error wasn't handled -> stopping" ); |
|
142 CompleteOperation( aError ); |
|
143 return KErrNone; |
|
144 } |
|
145 } |
|
146 |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CMsgMailBaseOp::DialogDismissedL |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CMsgMailBaseOp::DialogDismissedL( TInt /*aButtonId*/ ) |
|
153 { |
|
154 LOG( "CMsgMailBaseOp::DialogDismissedL" ); |
|
155 TRequestStatus* status = &iStatus; |
|
156 User::RequestComplete( status, KErrNone ); |
|
157 SetActive(); |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CMsgMailBaseOp::HandleStateActionError |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 TBool CMsgMailBaseOp::HandleStateActionError( TInt /*aError*/ ) |
|
165 { |
|
166 // By default errors are not handled or tolerated |
|
167 return EFalse; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CMsgMailBaseOp::StartOp |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void CMsgMailBaseOp::StartOp( MMsgMailOpObserver& aObserver ) |
|
175 { |
|
176 LOG( "CMsgMailBaseOp::StartOp" ); |
|
177 Cancel(); |
|
178 ASSERT( iState == EIdleState ); |
|
179 iObserver = &( aObserver ); |
|
180 // start iterating through operation states |
|
181 CompleteStateAction(); |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CMsgMailBaseOp::StartOp |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 void CMsgMailBaseOp::StartOp( TRequestStatus& aStatus ) |
|
189 { |
|
190 LOG( "CMsgMailBaseOp::StartOp" ); |
|
191 Cancel(); |
|
192 ASSERT( iState == EIdleState ); |
|
193 iExtRequestStatus = &( aStatus ); |
|
194 *iExtRequestStatus = KRequestPending; |
|
195 // start iterating through operation states |
|
196 CompleteStateAction(); |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CMsgMailBaseOp::CompleteStateAction |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CMsgMailBaseOp::CompleteStateAction( TInt aError ) |
|
204 { |
|
205 LOG1( "CMsgMailBaseOp::CompleteStateAction @ aError:%d", aError ); |
|
206 TRequestStatus* status = &iStatus; |
|
207 User::RequestComplete( status, aError ); |
|
208 SetActive(); |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CMsgMailBaseOp::CompleteOperation |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void CMsgMailBaseOp::CompleteOperation( TInt aError ) |
|
216 { |
|
217 LOG1( "CMsgMailBaseOp::CompleteOperation @ aError:%d", aError ); |
|
218 iState = EIdleState; |
|
219 StopWaitNote(); // not necessarily started |
|
220 |
|
221 if( iWaitDialog ) |
|
222 { |
|
223 // wait note is still active. we have to wait for it before |
|
224 // completing the operation. |
|
225 iWaitDialog->SetCallback( this ); |
|
226 iWaitingError = aError; |
|
227 } |
|
228 else |
|
229 { |
|
230 // Nothing to wait, we can complete now. |
|
231 NotifyObservers( aError ); |
|
232 } |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CMsgMailBaseOp::NotifyObservers |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 void CMsgMailBaseOp::NotifyObservers( TInt aError ) |
|
240 { |
|
241 LOG1( "CMsgMailBaseOp::NotifyObservers @ aError:%d", aError ); |
|
242 if ( iObserver ) |
|
243 { |
|
244 iObserver->HandleOpCompleted( *this, aError ); |
|
245 iObserver = NULL; // mustn't reuse observer |
|
246 } |
|
247 if ( iExtRequestStatus ) |
|
248 { |
|
249 LOG( "NotifyObservers, completing external request" ); |
|
250 ASSERT( iExtRequestStatus ); |
|
251 User::RequestComplete( iExtRequestStatus, aError ); |
|
252 iExtRequestStatus = NULL; // mustn't reuse request status |
|
253 } |
|
254 } |
|
255 |
|
256 // ---------------------------------------------------------------------------- |
|
257 // CMsgMailBaseOp::StartWaitNoteL |
|
258 // ---------------------------------------------------------------------------- |
|
259 // |
|
260 void CMsgMailBaseOp::StartWaitNoteL( |
|
261 TInt aTextResourceId, |
|
262 TBool aDelayOff, |
|
263 TInt aResouceID ) |
|
264 { |
|
265 LOG( "CMsgMailBaseOp::StartWaitNoteL" ); |
|
266 StopWaitNote(); |
|
267 iWaitDialog = new( ELeave ) CAknWaitDialog( |
|
268 reinterpret_cast<CEikDialog**>( &iWaitDialog ), aDelayOff ); |
|
269 iWaitDialog->PrepareLC( aResouceID ); |
|
270 HBufC* text = StringLoader::LoadLC( aTextResourceId, CEikonEnv::Static() ); // CSI: 27 # Must be used because of |
|
271 // iEikEnv is not accessible. |
|
272 iWaitDialog->SetTextL( *text ); |
|
273 CleanupStack::PopAndDestroy( text ); // text |
|
274 |
|
275 // safe to call LD even as a member variable, since sets itself to NULL when deleting |
|
276 iWaitDialog->RunLD(); // CSI: 50 # see comment above |
|
277 } |
|
278 |
|
279 // ---------------------------------------------------------------------------- |
|
280 // CMsgMailBaseOp::StopWaitNote |
|
281 // ---------------------------------------------------------------------------- |
|
282 // |
|
283 void CMsgMailBaseOp::StopWaitNote() |
|
284 { |
|
285 LOG( "CMsgMailBaseOp::StopWaitNote" ); |
|
286 if ( iWaitDialog ) |
|
287 { |
|
288 TRAP_IGNORE( iWaitDialog->ProcessFinishedL() ); |
|
289 LOG1( "StopWaitNote - process finished @ iWaitDialog:%x", iWaitDialog ); |
|
290 } |
|
291 } |
|
292 |
|
293 // End Of File |