|
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: |
|
15 * Operation to copy or move messages |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <eikenv.h> |
|
20 #include <imum.rsg> |
|
21 #include <MsvPrgReporter.h> |
|
22 #include <ImumInMailboxUtilities.h> |
|
23 |
|
24 #include "MsvConnectionValidation.h" |
|
25 #include "MsvEmailConnectionProgressProvider.h" |
|
26 #include "EmailUtils.H" |
|
27 #include "ImumDisconnectOperation.h" |
|
28 #include "MsvPop3CopyMoveOperation.h" |
|
29 #include "MsvPop3FetchOperation.h" |
|
30 #include "IMSSettingsNoteUi.h" |
|
31 |
|
32 // Constants and defines |
|
33 const TInt KCopyOrMoveOpPriority = CActive::EPriorityStandard; |
|
34 |
|
35 |
|
36 // ---------------------------------------------------------------------------- |
|
37 // NewL |
|
38 // ---------------------------------------------------------------------------- |
|
39 CMsvPop3CopyMoveOperation* CMsvPop3CopyMoveOperation::NewL( |
|
40 CImumInternalApi& aMailboxApi, |
|
41 TRequestStatus& aObserverRequestStatus, |
|
42 MMsvProgressReporter& aReporter, |
|
43 TMsvId aService, TMsvId aTarget, |
|
44 const CMsvEntrySelection& aSel, |
|
45 TBool aMoveMsgs) |
|
46 { |
|
47 IMUM_STATIC_CONTEXT( CMsvPop3CopyMoveOperation::NewL, 0, mtm, KImumMtmLog ); |
|
48 IMUM_IN(); |
|
49 // static |
|
50 CMsvPop3CopyMoveOperation* op = new(ELeave) CMsvPop3CopyMoveOperation( |
|
51 aMailboxApi, |
|
52 aObserverRequestStatus, |
|
53 aReporter, |
|
54 aService, |
|
55 aTarget, |
|
56 aMoveMsgs); |
|
57 CleanupStack::PushL(op); |
|
58 op->ConstructL(aSel); |
|
59 CleanupStack::Pop(); |
|
60 IMUM_OUT(); |
|
61 return op; |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // ~CMsvPop3CopyMoveOperation |
|
66 // ---------------------------------------------------------------------------- |
|
67 CMsvPop3CopyMoveOperation::~CMsvPop3CopyMoveOperation() |
|
68 { |
|
69 IMUM_CONTEXT( CMsvPop3CopyMoveOperation::~CMsvPop3CopyMoveOperation, 0, KImumMtmLog ); |
|
70 IMUM_IN(); |
|
71 |
|
72 delete iLocalSel; |
|
73 delete iRemoteSel; |
|
74 IMUM_OUT(); |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // DoRunL |
|
79 // ---------------------------------------------------------------------------- |
|
80 void CMsvPop3CopyMoveOperation::DoRunL() |
|
81 { |
|
82 IMUM_CONTEXT( CMsvPop3CopyMoveOperation::DoRunL, 0, KImumMtmLog ); |
|
83 IMUM_IN(); |
|
84 |
|
85 switch(iState) |
|
86 { |
|
87 case ELocalMsgs: |
|
88 if(GetOperationCompletionCodeL() != KErrNone) |
|
89 { |
|
90 // Failed to copy local messages. |
|
91 iState = EIdle; |
|
92 CompleteObserver(); |
|
93 } |
|
94 else |
|
95 { |
|
96 DoRemoteFetchL(); |
|
97 } |
|
98 break; |
|
99 case ERemoteMsgs: |
|
100 iState = EIdle; |
|
101 CompleteObserver(); |
|
102 break; |
|
103 default: |
|
104 break; |
|
105 } |
|
106 if(iOperation) |
|
107 iMtm = iOperation->Mtm(); |
|
108 else |
|
109 iMtm = KUidMsgTypePOP3; |
|
110 IMUM_OUT(); |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // GetErrorProgressL |
|
115 // ---------------------------------------------------------------------------- |
|
116 const TDesC8& CMsvPop3CopyMoveOperation::GetErrorProgressL(TInt aError) |
|
117 { |
|
118 IMUM_CONTEXT( CMsvPop3CopyMoveOperation::GetErrorProgressL, 0, KImumMtmLog ); |
|
119 IMUM_IN(); |
|
120 |
|
121 iError = aError; |
|
122 switch(iState) |
|
123 { |
|
124 case ERemoteMsgs: |
|
125 if(iOperation) |
|
126 { |
|
127 // iOperation is a CMsvPop3FetchOperation. |
|
128 return STATIC_CAST(CImumOnlineOperation*,iOperation)-> |
|
129 GetErrorProgressL(aError); |
|
130 } |
|
131 break; |
|
132 case ELocalMsgs: |
|
133 default: |
|
134 break; |
|
135 } |
|
136 TPop3Progress& progress = iErrorProgress(); |
|
137 progress.iTotalMsgs = 0; |
|
138 progress.iMsgsToProcess = 0; |
|
139 progress.iBytesDone = 0; |
|
140 progress.iTotalBytes = 0; |
|
141 progress.iErrorCode = iError; |
|
142 progress.iPop3Progress = (iMoving) ? |
|
143 (TPop3Progress::EPopMoving) : (TPop3Progress::EPopCopying); |
|
144 progress.iPop3SubStateProgress = progress.iPop3Progress; |
|
145 IMUM_OUT(); |
|
146 return iErrorProgress; |
|
147 } |
|
148 |
|
149 // ---------------------------------------------------------------------------- |
|
150 // SortMessageSelectionL |
|
151 // ---------------------------------------------------------------------------- |
|
152 void CMsvPop3CopyMoveOperation::SortMessageSelectionL( |
|
153 const CMsvEntrySelection& aSel) |
|
154 { |
|
155 IMUM_CONTEXT( CMsvPop3CopyMoveOperation::SortMessageSelectionL, 0, KImumMtmLog ); |
|
156 IMUM_IN(); |
|
157 |
|
158 // Sort messages into complete and incomplete selections. |
|
159 delete iLocalSel; |
|
160 iLocalSel = NULL; |
|
161 iLocalSel = new(ELeave) CMsvEntrySelection; |
|
162 delete iRemoteSel; |
|
163 iRemoteSel = NULL; |
|
164 iRemoteSel = new(ELeave) CMsvEntrySelection; |
|
165 |
|
166 TInt err; |
|
167 TMsvId id; |
|
168 TMsvId service; |
|
169 TMsvEntry tentry; |
|
170 for(TInt count=0; count<aSel.Count(); count++) |
|
171 { |
|
172 id = aSel[count]; |
|
173 err = iMsvSession.GetEntry(id, service, tentry); |
|
174 if(KErrNone == err) |
|
175 { |
|
176 if(tentry.Complete()) |
|
177 { |
|
178 iLocalSel->AppendL(id); |
|
179 } |
|
180 else |
|
181 { |
|
182 iRemoteSel->AppendL(id); |
|
183 } |
|
184 } |
|
185 } |
|
186 IMUM_OUT(); |
|
187 } |
|
188 |
|
189 // ---------------------------------------------------------------------------- |
|
190 // DoLocalCopyMoveL |
|
191 // ---------------------------------------------------------------------------- |
|
192 void CMsvPop3CopyMoveOperation::DoLocalCopyMoveL() |
|
193 { |
|
194 IMUM_CONTEXT( CMsvPop3CopyMoveOperation::DoLocalCopyMoveL, 0, KImumMtmLog ); |
|
195 IMUM_IN(); |
|
196 |
|
197 if(iLocalSel->Count()) |
|
198 { |
|
199 CMsvEntry* centry = iMsvSession.GetEntryL(iService); |
|
200 CleanupStack::PushL(centry); |
|
201 iStatus = KRequestPending; |
|
202 delete iOperation; |
|
203 iOperation = NULL; |
|
204 iOperation = MsvEmailMtmUiUtils::DoCEntryCopyMoveL( |
|
205 *centry, |
|
206 *iLocalSel, |
|
207 iTarget, |
|
208 iStatus, |
|
209 !iMoving); |
|
210 CleanupStack::PopAndDestroy(); // centry |
|
211 } |
|
212 else |
|
213 { |
|
214 CompleteThis(); |
|
215 } |
|
216 iState = ELocalMsgs; |
|
217 SetActive(); |
|
218 IMUM_OUT(); |
|
219 } |
|
220 |
|
221 // ---------------------------------------------------------------------------- |
|
222 // DoRemoteFetchL |
|
223 // ---------------------------------------------------------------------------- |
|
224 void CMsvPop3CopyMoveOperation::DoRemoteFetchL() |
|
225 { |
|
226 IMUM_CONTEXT( CMsvPop3CopyMoveOperation::DoRemoteFetchL, 0, KImumMtmLog ); |
|
227 IMUM_IN(); |
|
228 |
|
229 TInt msgCount = iRemoteSel->Count(); |
|
230 if(msgCount) |
|
231 { |
|
232 CMsvEntry* centry = iMsvSession.GetEntryL(iService); |
|
233 TBool doIt = centry->Entry().Connected(); |
|
234 delete centry; |
|
235 if(!doIt) |
|
236 { |
|
237 // Prompt user before connecting. |
|
238 iReporter.MakeProgressVisibleL(EFalse); |
|
239 TInt queryResouce = msgCount > 1 ? |
|
240 R_EMAIL_FETCH_MESSAGES_BEFORE_COPY_QUERY : |
|
241 R_EMAIL_FETCH_MESSAGE_BEFORE_COPY_QUERY; |
|
242 doIt = CIMSSettingsNoteUi::ShowQueryL( |
|
243 queryResouce, R_EMAIL_CONFIRMATION_QUERY ); |
|
244 } |
|
245 if(doIt) |
|
246 { |
|
247 iReporter.MakeProgressVisibleL(ETrue); |
|
248 TImPop3GetMailInfo info; |
|
249 info.iMaxEmailSize = KMaxTInt32; |
|
250 info.iDestinationFolder = iTarget; |
|
251 TInt fnId = (iMoving) ? (KPOP3MTMMoveMailSelectionWhenAlreadyConnected) : (KPOP3MTMCopyMailSelectionWhenAlreadyConnected); |
|
252 iStatus = KRequestPending; |
|
253 delete iOperation; |
|
254 iOperation = NULL; |
|
255 iOperation = CMsvPop3FetchOperation::NewL( |
|
256 iMailboxApi, |
|
257 iStatus, |
|
258 iReporter, |
|
259 fnId, |
|
260 iService, |
|
261 info, |
|
262 *iRemoteSel); |
|
263 } |
|
264 } |
|
265 if(iStatus != KRequestPending) |
|
266 { |
|
267 CompleteThis(); |
|
268 } |
|
269 iState = ERemoteMsgs; |
|
270 SetActive(); |
|
271 IMUM_OUT(); |
|
272 } |
|
273 |
|
274 // ---------------------------------------------------------------------------- |
|
275 // CMsvPop3CopyMoveOperation |
|
276 // ---------------------------------------------------------------------------- |
|
277 CMsvPop3CopyMoveOperation::CMsvPop3CopyMoveOperation( |
|
278 CImumInternalApi& aMailboxApi, |
|
279 TRequestStatus& aObserverRequestStatus, |
|
280 MMsvProgressReporter& aReporter, |
|
281 TMsvId aService, |
|
282 TMsvId aTarget, |
|
283 TBool aMoveMsgs) |
|
284 : |
|
285 CImumDiskSpaceObserverOperation( |
|
286 aMailboxApi, |
|
287 KCopyOrMoveOpPriority, |
|
288 aObserverRequestStatus, |
|
289 aReporter), |
|
290 iMoving(aMoveMsgs), |
|
291 iTarget(aTarget) |
|
292 { |
|
293 IMUM_CONTEXT( CMsvPop3CopyMoveOperation::CMsvPop3CopyMoveOperation, 0, KImumMtmLog ); |
|
294 IMUM_IN(); |
|
295 |
|
296 iService = aService; |
|
297 IMUM_OUT(); |
|
298 } |
|
299 |
|
300 // ---------------------------------------------------------------------------- |
|
301 // ConstructL |
|
302 // ---------------------------------------------------------------------------- |
|
303 void CMsvPop3CopyMoveOperation::ConstructL(const CMsvEntrySelection& aSel) |
|
304 { |
|
305 IMUM_CONTEXT( CMsvPop3CopyMoveOperation::ConstructL, 0, KImumMtmLog ); |
|
306 IMUM_IN(); |
|
307 |
|
308 SortMessageSelectionL(aSel); |
|
309 BaseConstructL(KUidMsgTypePOP3); |
|
310 DoLocalCopyMoveL(); |
|
311 IMUM_OUT(); |
|
312 } |
|
313 |