|
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: State machine -based operation for fetching files as attachments. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cmsgmailfetchfileop.h" |
|
22 #include "MsgMailEditorDocument.h" |
|
23 #include "MailLog.h" |
|
24 #include "Msgattachmentverifier.h" |
|
25 #include "cmsgmailrestoresuperop.h" |
|
26 #include "MailUtils.h" |
|
27 #include <MsgEditorAppUi.rsg> |
|
28 #include <MsgMailEditor.rsg> |
|
29 #include <coemain.h> |
|
30 #include <mmsvattachmentmanager.h> |
|
31 |
|
32 // LOCAL CONSTANT |
|
33 |
|
34 // appoximated 3 attachments / message |
|
35 const TInt KFetchFileGranularity = 3; |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CMsgMailFetchFileOp::CMsgMailFetchFileOp |
|
41 // C++ default constructor can NOT contain any code, that |
|
42 // might leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CMsgMailFetchFileOp::CMsgMailFetchFileOp( |
|
46 MsgAttachmentUtils::TMsgAttachmentFetchType aFetchType, |
|
47 CMsgMailEditorDocument& aDocument ) |
|
48 : CMsgMailBaseOp( aDocument ), |
|
49 iFetchType( aFetchType ) |
|
50 { |
|
51 //We set a higher priority to fetch op so that touch events won´t get |
|
52 //leaked to editors toolbar |
|
53 SetPriority( EActivePriorityWsEvents + 1 ); |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CMsgMailFetchFileOp::ConstructL |
|
58 // Symbian 2nd phase constructor can leave. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 void CMsgMailFetchFileOp::ConstructL() |
|
62 { |
|
63 LOG( "CMsgMailFetchFileOp::ConstructL" ); |
|
64 iFetchArray = new( ELeave ) CDesCArrayFlat( KFetchFileGranularity ); |
|
65 iManager = &( iDocument.GetAttachmentManagerL() ); |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CMsgMailFetchFileOp::NewL |
|
70 // Two-phased constructor. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CMsgMailFetchFileOp* CMsgMailFetchFileOp::NewL( |
|
74 MsgAttachmentUtils::TMsgAttachmentFetchType aFetchType, |
|
75 CMsgMailEditorDocument& aDocument ) |
|
76 { |
|
77 CMsgMailFetchFileOp* self = |
|
78 new( ELeave ) CMsgMailFetchFileOp( aFetchType, aDocument ); |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL(); |
|
81 |
|
82 CleanupStack::Pop(self); |
|
83 return self; |
|
84 } |
|
85 |
|
86 // Destructor |
|
87 CMsgMailFetchFileOp::~CMsgMailFetchFileOp() |
|
88 { |
|
89 LOG( "CMsgMailFetchFileOp::~CMsgMailFetchFileOp" ); |
|
90 if( iBlocker ) |
|
91 { |
|
92 // iBlocker is deleted in AknInputBlockCancel |
|
93 iBlocker->Cancel(); |
|
94 } |
|
95 Cancel(); |
|
96 delete iFetchArray; |
|
97 delete iRestoreSuperOp; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CMsgMailFetchFileOp::HandleStateActionL |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CMsgMailFetchFileOp::HandleStateActionL() |
|
105 { |
|
106 switch ( iState ) |
|
107 { |
|
108 case ESelectFiles: |
|
109 { |
|
110 SelectFilesL(); |
|
111 break; |
|
112 } |
|
113 case EAddAttas: |
|
114 { |
|
115 AddAttasL(); |
|
116 break; |
|
117 } |
|
118 case ERestoreAllAttas: |
|
119 { |
|
120 RestoreAllAttasL(); |
|
121 break; |
|
122 } |
|
123 case EFinalize: |
|
124 { |
|
125 FinalizeL(); |
|
126 break; |
|
127 } |
|
128 default: |
|
129 { |
|
130 // should never come here |
|
131 ASSERT( EFalse ); |
|
132 break; |
|
133 } |
|
134 } |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CMsgMailFetchFileOp::SetNextState |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void CMsgMailFetchFileOp::SetNextState() |
|
142 { |
|
143 switch ( iState ) |
|
144 { |
|
145 case EIdleState: |
|
146 { |
|
147 iState = ESelectFiles; |
|
148 break; |
|
149 } |
|
150 case ESelectFiles: |
|
151 { |
|
152 iState = EAddAttas; |
|
153 break; |
|
154 } |
|
155 case EAddAttas: |
|
156 { |
|
157 iState = ERestoreAllAttas; |
|
158 break; |
|
159 } |
|
160 case ERestoreAllAttas: |
|
161 { |
|
162 iState = EFinalize; |
|
163 break; |
|
164 } |
|
165 case EFinalize: |
|
166 default: |
|
167 { |
|
168 iState = EIdleState; |
|
169 break; |
|
170 } |
|
171 } |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CMsgMailFetchFileOp::HandleOperationCancel |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CMsgMailFetchFileOp::HandleOperationCancel() |
|
179 { |
|
180 LOG( "CMsgMailFetchFileOp::HandleOperationCancel, deleting iRestoreSuperOp" ); |
|
181 if( iBlocker ) |
|
182 { |
|
183 iBlocker->Cancel(); |
|
184 } |
|
185 delete iRestoreSuperOp; |
|
186 iRestoreSuperOp = NULL; |
|
187 if ( iState == EAddAttas ) |
|
188 { |
|
189 // cancel possibly ongoing AddAttachmentL() request, doesn't do |
|
190 // anything if request isn't outstanding |
|
191 LOG( "HandleOperationCancel, cancel manager's request" ); |
|
192 iManager->CancelRequest(); |
|
193 } |
|
194 LOG( "HandleOperationCancel, ...finished" ); |
|
195 } |
|
196 |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CMsgMailFetchFileOp::AknInputBlockCancel |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 void CMsgMailFetchFileOp::AknInputBlockCancel() |
|
203 { |
|
204 delete iBlocker; |
|
205 iBlocker = NULL; |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CMsgMailFetchFileOp::SelectFilesL |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void CMsgMailFetchFileOp::SelectFilesL() |
|
213 { |
|
214 TInt fetchResult( EFalse ); |
|
215 |
|
216 // starting phase -> initialize operation data |
|
217 iFetchCount = 0; |
|
218 iFileName = KNullDesC; |
|
219 iFetchArray->Reset(); |
|
220 |
|
221 CMsgAttachmentVerifier* verifier = |
|
222 CMsgAttachmentVerifier::NewLC( iDocument.Session() ); |
|
223 |
|
224 if ( iFetchType == MsgAttachmentUtils::EUnknown ) |
|
225 { |
|
226 if ( MsgAttachmentUtils::FetchAnyFileL( iFileName, |
|
227 *( CCoeEnv::Static() ), |
|
228 verifier ) ) |
|
229 { |
|
230 fetchResult = ETrue; |
|
231 iFetchCount = 1; |
|
232 } |
|
233 } |
|
234 else |
|
235 { |
|
236 fetchResult = MsgAttachmentUtils::FetchFileL( iFetchType, |
|
237 iFileName, |
|
238 *iFetchArray, |
|
239 ETrue, |
|
240 EFalse, |
|
241 verifier ); |
|
242 iFetchCount = iFetchArray->Count(); |
|
243 } |
|
244 // Check fetch results. EFalse if user cancels the fetch. |
|
245 if ( fetchResult == EFalse ) |
|
246 { |
|
247 User::Leave( KErrCancel ); |
|
248 } |
|
249 CleanupStack::PopAndDestroy( verifier ); // verifier |
|
250 CompleteStateAction(); |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CMsgMailFetchFileOp::AddAttasL |
|
255 // In current implementation multiple attachments are added as a one step, and |
|
256 // failure with one attachment interrupts entire procedure. |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 void CMsgMailFetchFileOp::AddAttasL() |
|
260 { |
|
261 StartWaitNoteL( R_WAIT_INSERTING_ATTACHMENT, EFalse, R_MEB_WAIT_NOTE ); |
|
262 ASSERT( iFetchCount > 0 ); // op was cancelled if nothing was selected |
|
263 |
|
264 if( iBlocker ) |
|
265 { |
|
266 iBlocker->Cancel(); |
|
267 } |
|
268 // NewL version does not exist |
|
269 iBlocker = CAknInputBlock::NewCancelHandlerLC( this ); |
|
270 CleanupStack::Pop( iBlocker ); |
|
271 |
|
272 if ( iFetchCount > 1 ) |
|
273 { |
|
274 AddMultipleAttachmentsL( *iFetchArray, iDocument, iStatus ); |
|
275 } |
|
276 else |
|
277 { |
|
278 AddSingleAttachmentL( iFileName, iDocument, iStatus ); |
|
279 } |
|
280 SetActive(); |
|
281 } |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CMsgMailFetchFileOp::RestoreAllAttasL |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 void CMsgMailFetchFileOp::RestoreAllAttasL() |
|
288 { |
|
289 delete iRestoreSuperOp; |
|
290 iRestoreSuperOp = NULL; |
|
291 iRestoreSuperOp = CMsgMailRestoreSuperOp::NewL( iDocument ); |
|
292 iRestoreSuperOp->StartOp( iStatus ); |
|
293 SetActive(); |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CMsgMailFetchFileOp::FinalizeL |
|
298 // ----------------------------------------------------------------------------- |
|
299 // |
|
300 void CMsgMailFetchFileOp::FinalizeL() |
|
301 { |
|
302 StopWaitNote(); |
|
303 if( iBlocker ) |
|
304 { |
|
305 iBlocker->Cancel(); |
|
306 } |
|
307 |
|
308 TBool invalidAttas = iRestoreSuperOp->ShowNoteIfInvalidAttaL(); |
|
309 TBool drmAttas = iRestoreSuperOp->ShowNoteIfDRMAttaL(); |
|
310 if ( !invalidAttas && !drmAttas ) |
|
311 { // Restore operation reported no problems so we determine that the |
|
312 // attachment was really added. Note that we actually restored ALL |
|
313 // the attachments and some of them could have theoretically reported |
|
314 // a problem, but in practise this should correctly indicate the |
|
315 // success of attachment adding operation. |
|
316 MailUtils::ConfirmationNoteL( R_MAIL_EDITOR_ADDED_ATTACH_TEXT ); |
|
317 } |
|
318 CompleteStateAction(); |
|
319 } |
|
320 |
|
321 // ----------------------------------------------------------------------------- |
|
322 // CMsgMailFetchFileOp::AddMultipleAttachmentsL |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 void CMsgMailFetchFileOp::AddMultipleAttachmentsL( |
|
326 CDesCArray& aAttachments, |
|
327 CMsgMailEditorDocument& aDocument, |
|
328 TRequestStatus& aStatus ) const |
|
329 { |
|
330 TInt count( aAttachments.Count() ); |
|
331 for ( TInt i( 0 ); i < count; i++ ) |
|
332 { |
|
333 TPtrC attaName = aAttachments.MdcaPoint( i ); |
|
334 AddSingleAttachmentL( attaName, aDocument, aStatus ); |
|
335 } |
|
336 } |
|
337 |
|
338 // ----------------------------------------------------------------------------- |
|
339 // CMsgMailFetchFileOp::AddSingleAttachmentL |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 void CMsgMailFetchFileOp::AddSingleAttachmentL( |
|
343 const TDesC& aAttachmentName, |
|
344 CMsgMailEditorDocument& /*aDocument*/, |
|
345 TRequestStatus& aStatus ) const |
|
346 { |
|
347 // Add attachment to message |
|
348 TInt attaSize( MailUtils::FileSize( aAttachmentName ) ); |
|
349 User::LeaveIfError( attaSize ); |
|
350 |
|
351 CMsvAttachment* info = CMsvAttachment::NewL( CMsvAttachment::EMsvFile ); |
|
352 CleanupStack::PushL(info); |
|
353 |
|
354 // info needs to be updated before attachment |
|
355 // is saved to mail message. |
|
356 // Mime type needs to be set later, see RestoreAttachmentsL |
|
357 info->SetAttachmentNameL( aAttachmentName ); |
|
358 info->SetSize( attaSize ); |
|
359 iManager->AddAttachmentL( aAttachmentName, info, aStatus ); |
|
360 CleanupStack::Pop( info ); // info, ownership transferred |
|
361 } |
|
362 |
|
363 // End Of File |