|
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 * Class implementation file |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include <miutset.h> |
|
22 #include <s32file.h> |
|
23 #include <eikenv.h> |
|
24 #include <eikrutil.h> |
|
25 #include <eikbtgpc.h> |
|
26 #include <iapprefs.h> |
|
27 #include <StringLoader.h> |
|
28 #include <aknnotewrappers.h> |
|
29 #include <sendui.h> |
|
30 #include <cntdb.h> |
|
31 #include <cntitem.h> |
|
32 #include <cntfield.h> |
|
33 #include <AknQueryDialog.h> |
|
34 #include <aknnotedialog.h> |
|
35 #include <StringLoader.h> |
|
36 #include <mmsvattachmentmanager.h> // MMsvAttachmentManager |
|
37 |
|
38 #include "ImumMtmLogging.h" |
|
39 #include "EmailMsgSizerOperation.h" |
|
40 |
|
41 // ---------------------------------------------------------------------------- |
|
42 // TMsvAttachmentNamesArray::TMsvAttachmentNamesArray() |
|
43 // ---------------------------------------------------------------------------- |
|
44 // |
|
45 TMsvAttachmentNamesArray::TMsvAttachmentNamesArray( |
|
46 const CArrayFixFlat<CMsvAttachment>& aAttachmentList) |
|
47 : |
|
48 iAttachments(aAttachmentList) |
|
49 { |
|
50 IMUM_CONTEXT( TMsvAttachmentNamesArray::TMsvAttachmentNamesArray, 0, KImumMtmLog ); |
|
51 IMUM_IN(); |
|
52 IMUM_OUT(); |
|
53 } |
|
54 |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // TMsvAttachmentNamesArray::MdcaCount() |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 TInt TMsvAttachmentNamesArray::MdcaCount() const |
|
61 { |
|
62 return iAttachments.Count(); |
|
63 } |
|
64 |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // TMsvAttachmentNamesArray::MdcaPoint() |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 TPtrC16 TMsvAttachmentNamesArray::MdcaPoint(TInt aIndex) const |
|
71 { |
|
72 return TPtrC( iAttachments[aIndex].AttachmentName() ); |
|
73 } |
|
74 |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // CEmailMsgSizerOperation::NewL() |
|
78 // ---------------------------------------------------------------------------- |
|
79 // |
|
80 CEmailMsgSizerOperation* CEmailMsgSizerOperation::NewL( |
|
81 CImumInternalApi& aMailboxApi, |
|
82 TRequestStatus& aObserverRequestStatus, |
|
83 TMsvId aMsgId, |
|
84 TUid aMtm) |
|
85 { |
|
86 IMUM_STATIC_CONTEXT( CEmailMsgSizerOperation::NewL, 0, mtm, KImumMtmLog ); |
|
87 IMUM_IN(); |
|
88 |
|
89 CEmailMsgSizerOperation* sizer = new(ELeave) CEmailMsgSizerOperation( |
|
90 aMailboxApi, aObserverRequestStatus, aMtm); |
|
91 CleanupStack::PushL(sizer); |
|
92 sizer->ConstructL(aMsgId); |
|
93 CleanupStack::Pop(); |
|
94 |
|
95 IMUM_OUT(); |
|
96 |
|
97 return sizer; |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // CEmailMsgSizerOperation::~CEmailMsgSizerOperation() |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 CEmailMsgSizerOperation::~CEmailMsgSizerOperation() |
|
105 { |
|
106 IMUM_CONTEXT( CEmailMsgSizerOperation::~CEmailMsgSizerOperation, 0, KImumMtmLog ); |
|
107 IMUM_IN(); |
|
108 IMUM_OUT(); |
|
109 delete iEmailMsg; |
|
110 delete iMsgEntry; |
|
111 } |
|
112 |
|
113 |
|
114 // ---------------------------------------------------------------------------- |
|
115 // CEmailMsgSizerOperation::ProgressL() |
|
116 // ---------------------------------------------------------------------------- |
|
117 // |
|
118 const TDesC8& CEmailMsgSizerOperation::ProgressL() |
|
119 { |
|
120 return iProgress; |
|
121 } |
|
122 |
|
123 |
|
124 // ---------------------------------------------------------------------------- |
|
125 // CEmailMsgSizerOperation::TotalMessageSize() |
|
126 // ---------------------------------------------------------------------------- |
|
127 // |
|
128 TInt32 CEmailMsgSizerOperation::TotalMessageSize() const |
|
129 { |
|
130 return iMsgEntry->Entry().iSize; |
|
131 } |
|
132 |
|
133 |
|
134 // ---------------------------------------------------------------------------- |
|
135 // CEmailMsgSizerOperation::BodyTextSizeL() |
|
136 // ---------------------------------------------------------------------------- |
|
137 // |
|
138 TInt32 CEmailMsgSizerOperation::BodyTextSizeL() const |
|
139 { |
|
140 return TotalMessageSize() - SizeOfAllAttachmentsL(); |
|
141 } |
|
142 |
|
143 |
|
144 // ---------------------------------------------------------------------------- |
|
145 // CEmailMsgSizerOperation::SizeOfAllAttachmentsL() |
|
146 // ---------------------------------------------------------------------------- |
|
147 // |
|
148 TInt32 CEmailMsgSizerOperation::SizeOfAllAttachmentsL() const |
|
149 { |
|
150 IMUM_CONTEXT( CEmailMsgSizerOperation::SizeOfAllAttachmentsL, 0, KImumMtmLog ); |
|
151 IMUM_IN(); |
|
152 |
|
153 TInt32 size = 0; |
|
154 |
|
155 MMsvAttachmentManager& attachments = iEmailMsg->AttachmentManager(); |
|
156 for( TInt i = attachments.AttachmentCount(); --i >= 0; ) |
|
157 { |
|
158 size += GetSizeL( i, attachments ); |
|
159 } |
|
160 |
|
161 IMUM_OUT(); |
|
162 return size; |
|
163 } |
|
164 |
|
165 |
|
166 // ---------------------------------------------------------------------------- |
|
167 // CEmailMsgSizerOperation::AttachmentSizeL() |
|
168 // ---------------------------------------------------------------------------- |
|
169 // |
|
170 TInt32 CEmailMsgSizerOperation::AttachmentSizeL( |
|
171 TMsvId aAttachmentId ) const |
|
172 { |
|
173 IMUM_CONTEXT( CEmailMsgSizerOperation::AttachmentSizeL, 0, KImumMtmLog ); |
|
174 IMUM_IN(); |
|
175 |
|
176 TInt32 size = 0; |
|
177 MMsvAttachmentManager& attachments = iEmailMsg->AttachmentManager(); |
|
178 |
|
179 // Search through the whole list of attachments |
|
180 TInt i = attachments.AttachmentCount(); |
|
181 while ( --i >= 0 && !size ) |
|
182 { |
|
183 // Create the object of the info item |
|
184 CMsvAttachment* attachment = attachments.GetAttachmentInfoL( i ); |
|
185 CleanupStack::PushL( attachment ); |
|
186 |
|
187 // if id of the attachment matches with the id provided, |
|
188 // increase the size |
|
189 if( attachment->Id() == aAttachmentId ) |
|
190 { |
|
191 size = attachment->Size(); |
|
192 } |
|
193 |
|
194 CleanupStack::PopAndDestroy( attachment ); |
|
195 attachment = NULL; |
|
196 } |
|
197 |
|
198 User::LeaveIfError( i ); |
|
199 // Leaves with KErrNotFound (-1) if attachment not found, |
|
200 // or no attachments. |
|
201 |
|
202 IMUM_OUT(); |
|
203 return size; |
|
204 } |
|
205 |
|
206 |
|
207 // ---------------------------------------------------------------------------- |
|
208 // CEmailMsgSizerOperation::HasAttachmentLargerThanL() |
|
209 // ---------------------------------------------------------------------------- |
|
210 // |
|
211 TBool CEmailMsgSizerOperation::HasAttachmentLargerThanL( TInt32 aSize ) const |
|
212 { |
|
213 IMUM_CONTEXT( CEmailMsgSizerOperation::HasAttachmentLargerThanL, 0, KImumMtmLog ); |
|
214 IMUM_IN(); |
|
215 |
|
216 TBool foundBigger = EFalse; |
|
217 MMsvAttachmentManager& attachments = iEmailMsg->AttachmentManager(); |
|
218 for( TInt i = attachments.AttachmentCount(); |
|
219 --i >= 0 && !foundBigger; |
|
220 foundBigger = GetSizeL( i, attachments ) > aSize ) {}; |
|
221 |
|
222 IMUM_OUT(); |
|
223 return foundBigger; |
|
224 } |
|
225 |
|
226 |
|
227 // ---------------------------------------------------------------------------- |
|
228 // CEmailMsgSizerOperation::DoCancel() |
|
229 // ---------------------------------------------------------------------------- |
|
230 // |
|
231 void CEmailMsgSizerOperation::DoCancel() |
|
232 { |
|
233 IMUM_CONTEXT( CEmailMsgSizerOperation::DoCancel, 0, KImumMtmLog ); |
|
234 IMUM_IN(); |
|
235 |
|
236 IMUM3(0,"Cancelling operation with iStatus (0x%x) with errorcode (%d) and msg object (0x%x)", iStatus.Int(), iProgress().iErrorCode, iEmailMsg); |
|
237 |
|
238 if(iEmailMsg) |
|
239 { |
|
240 iEmailMsg->Cancel(); |
|
241 iProgress().iErrorCode = KErrCancel; |
|
242 |
|
243 // if not already completed, then |
|
244 TRequestStatus* status = &iObserverRequestStatus; |
|
245 User::RequestComplete(status, KErrCancel); |
|
246 } |
|
247 |
|
248 IMUM_OUT(); |
|
249 } |
|
250 |
|
251 |
|
252 // ---------------------------------------------------------------------------- |
|
253 // CEmailMsgSizerOperation::RunL() |
|
254 // ---------------------------------------------------------------------------- |
|
255 // |
|
256 void CEmailMsgSizerOperation::RunL() |
|
257 { |
|
258 IMUM_CONTEXT( CEmailMsgSizerOperation::RunL, 0, KImumMtmLog ); |
|
259 IMUM_IN(); |
|
260 |
|
261 iProgress().iErrorCode = iStatus.Int(); |
|
262 TRequestStatus* status = &iObserverRequestStatus; |
|
263 User::RequestComplete(status, KErrNone); |
|
264 |
|
265 IMUM_OUT(); |
|
266 } |
|
267 |
|
268 |
|
269 // ---------------------------------------------------------------------------- |
|
270 // CEmailMsgSizerOperation::CEmailMsgSizerOperation() |
|
271 // ---------------------------------------------------------------------------- |
|
272 // |
|
273 CEmailMsgSizerOperation::CEmailMsgSizerOperation( |
|
274 CImumInternalApi& aMailboxApi, |
|
275 TRequestStatus& aObserverRequestStatus, |
|
276 TUid aMtm) |
|
277 : |
|
278 CMsvOperation(aMailboxApi.MsvSession(), KSizerOpPriority, aObserverRequestStatus) |
|
279 { |
|
280 IMUM_CONTEXT( CEmailMsgSizerOperation::CEmailMsgSizerOperation, 0, KImumMtmLog ); |
|
281 IMUM_IN(); |
|
282 |
|
283 CActiveScheduler::Add(this); |
|
284 iMtm = aMtm; |
|
285 IMUM_OUT(); |
|
286 } |
|
287 |
|
288 |
|
289 // ---------------------------------------------------------------------------- |
|
290 // CEmailMsgSizerOperation::ConstructL() |
|
291 // ---------------------------------------------------------------------------- |
|
292 // |
|
293 void CEmailMsgSizerOperation::ConstructL(TMsvId aMsgId) |
|
294 { |
|
295 IMUM_CONTEXT( CEmailMsgSizerOperation::ConstructL, 0, KImumMtmLog ); |
|
296 IMUM_IN(); |
|
297 |
|
298 // Create and start the CImEmailMessage active object. |
|
299 iMsgEntry = iMsvSession.GetEntryL(aMsgId); |
|
300 iEmailMsg = CImEmailMessage::NewL(*iMsgEntry); |
|
301 iStatus = KRequestPending; |
|
302 iEmailMsg->GetAttachmentsListL( |
|
303 iStatus, |
|
304 aMsgId, |
|
305 CImEmailMessage::EAllAttachments, |
|
306 CImEmailMessage::EThisMessageAndEmbeddedMessages); |
|
307 SetActive(); |
|
308 IMUM_OUT(); |
|
309 } |
|
310 |
|
311 // ---------------------------------------------------------------------------- |
|
312 // CEmailMsgSizerOperation::GetSizeL() |
|
313 // ---------------------------------------------------------------------------- |
|
314 // |
|
315 TInt CEmailMsgSizerOperation::GetSizeL( |
|
316 const TInt aIndex, |
|
317 MMsvAttachmentManager& aList ) const |
|
318 { |
|
319 IMUM_CONTEXT( CEmailMsgSizerOperation::GetSizeL, 0, KImumMtmLog ); |
|
320 IMUM_IN(); |
|
321 |
|
322 TInt size = 0; |
|
323 |
|
324 // Create the object of the info item |
|
325 CMsvAttachment* attachment = aList.GetAttachmentInfoL( aIndex ); |
|
326 CleanupStack::PushL( attachment ); |
|
327 |
|
328 size = attachment->Size(); |
|
329 |
|
330 CleanupStack::PopAndDestroy( attachment ); |
|
331 attachment = NULL; |
|
332 |
|
333 IMUM_OUT(); |
|
334 return size; |
|
335 } |
|
336 |
|
337 |