|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <aknnotewrappers.h> |
|
21 #include <documenthandlerui.rsg> // Resource ids |
|
22 #include "DocSaver.h" |
|
23 #include "DocumentHandlerUI.hrh" |
|
24 #include "DocDefaultHandler.h" |
|
25 |
|
26 |
|
27 // EXTERNAL DATA STRUCTURES |
|
28 |
|
29 // EXTERNAL FUNCTION PROTOTYPES |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 // MACROS |
|
34 |
|
35 // LOCAL CONSTANTS AND MACROS |
|
36 |
|
37 // MODULE DATA STRUCTURES |
|
38 |
|
39 // LOCAL FUNCTION PROTOTYPES |
|
40 |
|
41 // ==================== LOCAL FUNCTIONS ==================== |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 |
|
45 // C++ default constructor can NOT contain any code, that |
|
46 // might leave. |
|
47 // |
|
48 CDocSaver::CDocSaver() |
|
49 { |
|
50 } |
|
51 |
|
52 // EPOC default constructor can leave. |
|
53 void CDocSaver::ConstructL() |
|
54 { |
|
55 } |
|
56 |
|
57 // Two-phased constructor. |
|
58 CDocSaver* CDocSaver::NewL() |
|
59 { |
|
60 CDocSaver* self = new (ELeave) CDocSaver; |
|
61 |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(); |
|
65 |
|
66 return self; |
|
67 } |
|
68 |
|
69 // Destructor |
|
70 CDocSaver::~CDocSaver() |
|
71 { |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------- |
|
75 // CDocSaver::ConfNoteL |
|
76 // "File saved to SomeApplication" confirmation note. |
|
77 // |
|
78 // --------------------------------------------------------- |
|
79 // |
|
80 void CDocSaver::ConfNoteL( const TDesC& aText, TBool aWait ) |
|
81 { |
|
82 #ifdef _DEBUG |
|
83 RDebug::Print( _L("DocumentHandler: CDocSaver::ConfNoteL: Called")); |
|
84 #endif |
|
85 CAknConfirmationNote* myNote = new ( ELeave ) CAknConfirmationNote( aWait ); |
|
86 |
|
87 myNote->ExecuteLD( aText ); |
|
88 #ifdef _DEBUG |
|
89 RDebug::Print( _L("DocumentHandler: CDocSaver::ConfNoteL: Returns")); |
|
90 #endif |
|
91 } |
|
92 |
|
93 |
|
94 // ================= MEMBER FUNCTIONS ======================= |
|
95 |
|
96 // C++ default constructor can NOT contain any code, that |
|
97 // might leave. |
|
98 // |
|
99 |
|
100 |
|
101 // CDocWaitDialog |
|
102 // ---------------------------------------------------------------- |
|
103 |
|
104 CDocWaitDialog::CDocWaitDialog( |
|
105 CEikDialog** aSelfPtr, |
|
106 const TDesC& aText): |
|
107 CAknWaitDialog(aSelfPtr, EFalse), |
|
108 iText(aText), |
|
109 iFinished(EFalse) |
|
110 { |
|
111 } |
|
112 // --------------------------------------------------------- |
|
113 // CDocWaitDialog::ExecuteDlgLD() |
|
114 // |
|
115 // |
|
116 // --------------------------------------------------------- |
|
117 // |
|
118 TInt CDocWaitDialog::ExecuteDlgLD() |
|
119 { |
|
120 PrepareLC(R_DOCHANDLER_WAIT_NOTE); |
|
121 SetTextL( iText ); |
|
122 TInt ret = RunDlgLD(CAknNoteDialog::ENoTone); |
|
123 return ret; |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------- |
|
127 // CDocWaitDialog::Finish() |
|
128 // |
|
129 // |
|
130 // --------------------------------------------------------- |
|
131 // |
|
132 TBool CDocWaitDialog::Finish() |
|
133 { |
|
134 #ifdef _DEBUG |
|
135 RDebug::Print( _L("DocumentHandler: CDocWaitDialog::Finish: Called")); |
|
136 #endif |
|
137 TBool state = ETrue; |
|
138 if (iState == EProcessOnDisplayOff) |
|
139 { |
|
140 iProgressDialogTimer->Cancel(); |
|
141 state = EFalse; |
|
142 iFinished = ETrue; |
|
143 } |
|
144 TRAP_IGNORE( ProcessFinishedL() ); |
|
145 #ifdef _DEBUG |
|
146 if (state) |
|
147 { |
|
148 RDebug::Print( _L("DocumentHandler: CDocWaitDialog::Finish: state=ETRUE")); |
|
149 } |
|
150 else |
|
151 { |
|
152 RDebug::Print( _L("DocumentHandler: CDocWaitDialog::Finish: state=EFALSE")); |
|
153 } |
|
154 #endif |
|
155 return state; |
|
156 } |
|
157 |
|
158 |
|
159 // CDocAsyncSaver |
|
160 // ---------------------------------------------------------------- |
|
161 // C++ default constructor can NOT contain any code, that |
|
162 // might leave. |
|
163 // |
|
164 |
|
165 CDocAsyncSaver::CDocAsyncSaver(): |
|
166 CActive(EPriorityStandard), |
|
167 iShowDialog(EFalse), |
|
168 iSilent(EFalse) |
|
169 { |
|
170 } |
|
171 |
|
172 // EPOC default constructor can leave. |
|
173 void CDocAsyncSaver::ConstructL() |
|
174 { |
|
175 |
|
176 } |
|
177 |
|
178 // Two-phased constructor. |
|
179 CDocAsyncSaver* CDocAsyncSaver::NewL() |
|
180 { |
|
181 CDocAsyncSaver* self = NewLC(); |
|
182 CleanupStack::Pop(); |
|
183 |
|
184 return self; |
|
185 } |
|
186 |
|
187 CDocAsyncSaver* CDocAsyncSaver::NewLC() |
|
188 { |
|
189 CDocAsyncSaver* self = new (ELeave) CDocAsyncSaver(); |
|
190 |
|
191 CleanupStack::PushL( self ); |
|
192 self->ConstructL(); |
|
193 CActiveScheduler::Add(self); |
|
194 |
|
195 return self; |
|
196 } |
|
197 |
|
198 |
|
199 // Destructor |
|
200 CDocAsyncSaver::~CDocAsyncSaver() |
|
201 { |
|
202 if (iDocWaitDialog) |
|
203 { |
|
204 delete iDocWaitDialog; |
|
205 iDocWaitDialog = NULL; |
|
206 } |
|
207 Cancel(); |
|
208 Deque(); |
|
209 } |
|
210 // --------------------------------------------------------- |
|
211 // CDocAsyncSaver::WriteToFileL() |
|
212 // |
|
213 // |
|
214 // --------------------------------------------------------- |
|
215 // |
|
216 void CDocAsyncSaver::WriteToFileL( |
|
217 const TDesC8& aContent, |
|
218 RFile& aDestFile, |
|
219 const TDesC& aText ) |
|
220 { |
|
221 iDocWaitDialog = |
|
222 new (ELeave) CDocWaitDialog( |
|
223 ( REINTERPRET_CAST( |
|
224 CEikDialog**, |
|
225 &iDocWaitDialog ) ), |
|
226 aText ); |
|
227 iDocWaitDialog->ExecuteDlgLD(); |
|
228 aDestFile.Write( aContent, iStatus ); |
|
229 SetActive(); |
|
230 iWait.Start(); |
|
231 |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------- |
|
235 // CDocAsyncSaver::CopyFileL() |
|
236 // |
|
237 // |
|
238 // --------------------------------------------------------- |
|
239 // |
|
240 void CDocAsyncSaver::CopyFileL( |
|
241 CFileMan* aFileManager, |
|
242 const TFileName& aSourceFile, |
|
243 const TFileName& aDestFile, |
|
244 TUint aSwitch, |
|
245 const TDesC& aText ) |
|
246 { |
|
247 iDocWaitDialog = |
|
248 new (ELeave) CDocWaitDialog( |
|
249 ( REINTERPRET_CAST( |
|
250 CEikDialog**, |
|
251 &iDocWaitDialog ) ), |
|
252 aText ); |
|
253 iDocWaitDialog->ExecuteDlgLD(); |
|
254 |
|
255 TInt error = |
|
256 aFileManager->Copy( |
|
257 aSourceFile, |
|
258 aDestFile, |
|
259 aSwitch, |
|
260 iStatus ); |
|
261 |
|
262 if ( error != KErrNone ) |
|
263 { |
|
264 iStatus = error; |
|
265 iDocWaitDialog->Finish(); |
|
266 } |
|
267 else |
|
268 { |
|
269 SetActive(); |
|
270 iWait.Start(); |
|
271 } |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------- |
|
275 // CDocAsyncSaver::CopyFileL() |
|
276 // |
|
277 // |
|
278 // --------------------------------------------------------- |
|
279 // |
|
280 void CDocAsyncSaver::CopyFileL( |
|
281 CFileMan* aFileManager, |
|
282 const RFile& aSourceFile, |
|
283 const TFileName& aDestFile, |
|
284 TUint aSwitch, |
|
285 const TDesC& aText ) |
|
286 { |
|
287 iDocWaitDialog = |
|
288 new (ELeave) CDocWaitDialog( |
|
289 ( REINTERPRET_CAST( |
|
290 CEikDialog**, |
|
291 &iDocWaitDialog ) ), |
|
292 aText ); |
|
293 iDocWaitDialog->ExecuteDlgLD(); |
|
294 |
|
295 TInt error = |
|
296 aFileManager->Copy( |
|
297 aSourceFile, |
|
298 aDestFile, |
|
299 aSwitch, |
|
300 iStatus ); |
|
301 |
|
302 if ( error != KErrNone ) |
|
303 { |
|
304 iStatus = error; |
|
305 iDocWaitDialog->Finish(); |
|
306 } |
|
307 else |
|
308 { |
|
309 SetActive(); |
|
310 iWait.Start(); |
|
311 } |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------- |
|
315 // CDocAsyncSaver::MoveFileL() |
|
316 // |
|
317 // |
|
318 // --------------------------------------------------------- |
|
319 // |
|
320 void CDocAsyncSaver::MoveFileL( |
|
321 CFileMan* aFileManager, |
|
322 const TFileName& aSourceFile, |
|
323 const TFileName& aDestFile, |
|
324 TUint aSwitch, |
|
325 const TDesC& aText, |
|
326 const TBool aSilent ) |
|
327 { |
|
328 iSilent = aSilent; |
|
329 if (!iSilent) |
|
330 { |
|
331 iDocWaitDialog = |
|
332 new (ELeave) CDocWaitDialog( |
|
333 ( REINTERPRET_CAST( |
|
334 CEikDialog**, |
|
335 &iDocWaitDialog ) ), |
|
336 aText ); |
|
337 iDocWaitDialog->ExecuteDlgLD(); |
|
338 } |
|
339 |
|
340 TInt error = |
|
341 aFileManager->Move( |
|
342 aSourceFile, |
|
343 aDestFile, |
|
344 aSwitch, |
|
345 iStatus ); |
|
346 if ( error != KErrNone ) |
|
347 { |
|
348 iStatus = error; |
|
349 if (!iSilent) |
|
350 { |
|
351 iDocWaitDialog->Finish(); |
|
352 } |
|
353 } |
|
354 else |
|
355 { |
|
356 SetActive(); |
|
357 iWait.Start(); |
|
358 } |
|
359 } |
|
360 |
|
361 // --------------------------------------------------------- |
|
362 // CDocAsyncSaver::Status() |
|
363 // |
|
364 // |
|
365 // --------------------------------------------------------- |
|
366 // |
|
367 TRequestStatus CDocAsyncSaver::Status() |
|
368 { |
|
369 return iStatus; |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------- |
|
373 // CDocAsyncSaver::ShowDialog() |
|
374 // |
|
375 // |
|
376 // --------------------------------------------------------- |
|
377 // |
|
378 TBool CDocAsyncSaver::ShowDialog() |
|
379 { |
|
380 #ifdef _DEBUG |
|
381 RDebug::Print( _L("DocumentHandler: CDocAsyncSaver::ShowDialog: Called")); |
|
382 #endif |
|
383 iShowDialog = EFalse; |
|
384 if (iSilent) |
|
385 { |
|
386 iShowDialog = EFalse; |
|
387 } |
|
388 else if (!iDocWaitDialog->Finish()) |
|
389 { |
|
390 iShowDialog = ETrue; |
|
391 #ifdef _DEBUG |
|
392 RDebug::Print( _L("DocumentHandler: CDocAsyncSaver::ShowDialog: Returns ETRUE")); |
|
393 #endif |
|
394 } |
|
395 return iShowDialog; |
|
396 } |
|
397 // --------------------------------------------------------- |
|
398 // CDocAsyncSaver::RunL() |
|
399 // |
|
400 // |
|
401 // --------------------------------------------------------- |
|
402 // |
|
403 void CDocAsyncSaver::RunL() |
|
404 { |
|
405 iWait.AsyncStop(); |
|
406 } |
|
407 |
|
408 |
|
409 // --------------------------------------------------------- |
|
410 // CDocAsyncSaver::DoCancel() |
|
411 // |
|
412 // |
|
413 // --------------------------------------------------------- |
|
414 // |
|
415 void CDocAsyncSaver::DoCancel() |
|
416 { |
|
417 } |
|
418 |
|
419 // End of File |