author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:11:15 +0300 | |
branch | RCL_3 |
changeset 80 | 726fba06891a |
parent 64 | 3533d4323edc |
permissions | -rw-r--r-- |
64 | 1 |
/* |
2 |
* Copyright (c) 2009 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: MR attahcment field implementation |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include "cmrattachmentcommandhandler.h" |
|
19 |
#include "cmropenattachmentcommand.h" |
|
20 |
#include "cmrremoveattachmentcommand.h" |
|
21 |
#include "cmrsaveattachmentcommand.h" |
|
22 |
#include "cmrsaveandopenattachmentcommand.h" |
|
23 |
#include "cesmrrichtextlink.h" |
|
24 |
#include "mcalremoteattachmentinfo.h" |
|
25 |
#include "mcalremoteattachment.h" |
|
26 |
#include "mcalremoteattachmentoperation.h" |
|
27 |
#include "ccalremoteattachmentinfo.h" |
|
28 |
#include "ccalremoteattachmentapi.h" |
|
29 |
#include "cesmrgenericfieldevent.h" |
|
30 |
#include "cesmrfieldcommandevent.h" |
|
31 |
#include "mesmrfieldeventqueue.h" |
|
32 |
#include "esmrdef.h" |
|
33 |
||
34 |
#include <esmrgui.rsg> |
|
35 |
#include <calentry.h> |
|
36 |
#include <calattachment.h> |
|
37 |
#include <f32file.h> |
|
38 |
#include <apgcli.h> |
|
39 |
#include <DocumentHandler.h> |
|
40 |
#include <StringLoader.h> |
|
41 |
#include <AknGlobalNote.h> |
|
42 |
||
43 |
// DEBUG |
|
44 |
#include "emailtrace.h" |
|
45 |
||
46 |
||
47 |
// unnamed namespace for local definitions |
|
48 |
namespace { // codescanner::namespace |
|
49 |
||
50 |
_LIT8( KUnknownDatatype, "unknown"); |
|
51 |
||
52 |
#if defined(_DEBUG) |
|
53 |
||
54 |
// Panic literal |
|
55 |
_LIT( KMRAttachmentCommandHandler, "MRAttachmentCommandHandler" ); |
|
56 |
||
57 |
/** |
|
58 |
* Panic codes |
|
59 |
*/ |
|
60 |
enum TMRAttachmentCommandHandlerPanic |
|
61 |
{ |
|
62 |
// Invalid command |
|
63 |
EMRAttachmentCommandHandlerInvalidCommand, |
|
64 |
// Attachment is not found |
|
65 |
EMRAttachmentCommandHandlerAttachmentNotFound, |
|
66 |
// Remote attachment information not set |
|
67 |
EMRAttachmentCommandHandlerRemoteInfoNotSet, |
|
68 |
// Remote command cannot be found |
|
69 |
EMRAttachmentCommandHandlerRemoteCommandNotFound, |
|
70 |
// Remote attachment is not found |
|
71 |
EMRAttachmentCommandHandlerRemoteAttachmentNotFound |
|
72 |
}; |
|
73 |
||
74 |
void Panic( TMRAttachmentCommandHandlerPanic aPanic ) |
|
75 |
{ |
|
76 |
User::Panic( KMRAttachmentCommandHandler, aPanic ); |
|
77 |
} |
|
78 |
||
79 |
#endif // _DEBUG |
|
80 |
||
81 |
/** |
|
82 |
* Shows information note when one attachment is saved. |
|
83 |
*/ |
|
84 |
void ShowInfoNoteL() |
|
85 |
{ |
|
86 |
CAknGlobalNote* note = CAknGlobalNote::NewLC(); |
|
87 |
HBufC* text = |
|
88 |
StringLoader::LoadLC( R_MEET_REQ_INFO_NOTE_ONE_ATTACHMENT_SAVED ); |
|
89 |
note->ShowNoteL( |
|
90 |
EAknGlobalInformationNote, |
|
91 |
*text ); |
|
92 |
CleanupStack::PopAndDestroy( 2, note ); |
|
93 |
} |
|
94 |
||
95 |
/** |
|
96 |
* Shows information note when multiple attachments have been saved. |
|
97 |
*/ |
|
98 |
void ShowInfoNoteL( TInt aAttachmentCount ) |
|
99 |
{ |
|
100 |
CAknGlobalNote* note = CAknGlobalNote::NewLC(); |
|
101 |
HBufC* text = StringLoader::LoadLC( |
|
102 |
R_MEET_REQ_INFO_NOTE_MULTIPLE_ATTACHMENTS_SAVED, |
|
103 |
aAttachmentCount ); |
|
104 |
note->ShowNoteL( |
|
105 |
EAknGlobalInformationNote, |
|
106 |
*text ); |
|
107 |
CleanupStack::PopAndDestroy( 2, note ); |
|
108 |
} |
|
109 |
||
110 |
} // namespace |
|
111 |
||
112 |
// ======== MEMBER FUNCTIONS ======== |
|
113 |
||
114 |
// --------------------------------------------------------------------------- |
|
115 |
// CMRAttachmentCommandHandler::CMRAttachmentCommandHandler |
|
116 |
// --------------------------------------------------------------------------- |
|
117 |
// |
|
118 |
CMRAttachmentCommandHandler::CMRAttachmentCommandHandler( |
|
119 |
CCalEntry& aEntry, |
|
120 |
MESMRFieldEventQueue& aEventQueue) : |
|
121 |
iEntry( aEntry ), |
|
122 |
iEventQueue( aEventQueue ) |
|
123 |
{ |
|
124 |
FUNC_LOG; |
|
125 |
} |
|
126 |
||
127 |
// --------------------------------------------------------------------------- |
|
128 |
// CMRAttachmentCommandHandler::~CMRAttachmentCommandHandler |
|
129 |
// --------------------------------------------------------------------------- |
|
130 |
// |
|
131 |
CMRAttachmentCommandHandler::~CMRAttachmentCommandHandler() |
|
132 |
{ |
|
133 |
FUNC_LOG; |
|
134 |
||
135 |
iDownloadOperations.ResetAndDestroy(); |
|
136 |
delete iDocHandler; |
|
137 |
} |
|
138 |
||
139 |
||
140 |
// --------------------------------------------------------------------------- |
|
141 |
// CMRAttachmentCommandHandler::NewL |
|
142 |
// --------------------------------------------------------------------------- |
|
143 |
// |
|
144 |
CMRAttachmentCommandHandler* CMRAttachmentCommandHandler::NewL( |
|
145 |
CCalEntry& aEntry, |
|
146 |
MESMRFieldEventQueue& aEventQueue ) |
|
147 |
{ |
|
148 |
FUNC_LOG; |
|
149 |
||
150 |
CMRAttachmentCommandHandler* self = |
|
151 |
new (ELeave) CMRAttachmentCommandHandler( aEntry, aEventQueue ); |
|
152 |
CleanupStack::PushL( self ); |
|
153 |
self->ConstructL(); |
|
154 |
CleanupStack::Pop( self ); |
|
155 |
return self; |
|
156 |
} |
|
157 |
||
158 |
// --------------------------------------------------------------------------- |
|
159 |
// CMRAttachmentCommandHandler::ConstructL |
|
160 |
// --------------------------------------------------------------------------- |
|
161 |
// |
|
162 |
void CMRAttachmentCommandHandler::ConstructL() |
|
163 |
{ |
|
164 |
FUNC_LOG; |
|
165 |
||
166 |
iDocHandler = CDocumentHandler::NewL(); |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
167 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
168 |
iAttachmentIndex = KErrNotFound; |
64 | 169 |
} |
170 |
||
171 |
// --------------------------------------------------------------------------- |
|
172 |
// CMRAttachmentCommandHandler::HandleAttachmentCommandL |
|
173 |
// --------------------------------------------------------------------------- |
|
174 |
// |
|
175 |
void CMRAttachmentCommandHandler::HandleAttachmentCommandL( |
|
176 |
TInt aCommandId, |
|
177 |
const CESMRRichTextLink& aSelectedLink ) |
|
178 |
{ |
|
179 |
FUNC_LOG; |
|
180 |
||
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
181 |
// If attachment index is not found, we must resolve it |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
182 |
if( iAttachmentIndex == KErrNotFound ) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
183 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
184 |
iAttachmentIndex = ResolveAttachmentIndexL( aSelectedLink.Value() ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
185 |
} |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
186 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
187 |
HandleAttachmentCommandInternalL( aCommandId, iAttachmentIndex ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
188 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
189 |
// Attachment index can be cleared after the command is executed. |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
190 |
iAttachmentIndex = KErrNotFound; |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
191 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
192 |
// If save all attachments command is in progress ... |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
193 |
if( iSaveAllAttachmentsCommand ) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
194 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
195 |
if ( iAttachmentInfo->AttachmentCount() > 0 ) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
196 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
197 |
// ... Let's continue the download process by starting the |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
198 |
// next download |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
199 |
SaveNextRemoteAttachmentL(); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
200 |
} |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
201 |
else |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
202 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
203 |
// ... Or show a note if all remote attachments have been saved. |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
204 |
ShowInfoNoteL( iEntry.AttachmentCountL() ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
205 |
iSaveAllAttachmentsCommand = EFalse; |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
206 |
} |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
207 |
} |
64 | 208 |
} |
209 |
||
210 |
// --------------------------------------------------------------------------- |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
211 |
// CMRAttachmentCommandHandler::IsSaveAllAttachmentsInProgress |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
212 |
// --------------------------------------------------------------------------- |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
213 |
// |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
214 |
TBool CMRAttachmentCommandHandler::IsSaveAllAttachmentsInProgress( ) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
215 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
216 |
return iSaveAllAttachmentsCommand;// return the flag state |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
217 |
} |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
218 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
219 |
// --------------------------------------------------------------------------- |
64 | 220 |
// CMRAttachmentCommandHandler::IsRemoteAttachmentL |
221 |
// --------------------------------------------------------------------------- |
|
222 |
// |
|
223 |
TBool CMRAttachmentCommandHandler::IsRemoteAttachmentL( |
|
224 |
const CESMRRichTextLink& aSelectedLink ) |
|
225 |
{ |
|
226 |
FUNC_LOG; |
|
227 |
||
228 |
TInt index = ResolveAttachmentIndexL( aSelectedLink.Value() ); |
|
229 |
||
230 |
CCalAttachment* attachment = iEntry.AttachmentL( index ); |
|
231 |
||
232 |
TBool remoteAttachment( ETrue ); |
|
233 |
||
234 |
if ( CCalAttachment::EFile == attachment->Type() ) |
|
235 |
{ |
|
236 |
remoteAttachment = EFalse; |
|
237 |
} |
|
238 |
||
239 |
return remoteAttachment; |
|
240 |
} |
|
241 |
||
242 |
// --------------------------------------------------------------------------- |
|
243 |
// CMRAttachmentCommandHandler::SetRemoteAttachmentInformationL |
|
244 |
// --------------------------------------------------------------------------- |
|
245 |
// |
|
246 |
void CMRAttachmentCommandHandler::SetRemoteAttachmentInformationL( |
|
247 |
CCalRemoteAttachmentApi& aRemoteAttaApi, |
|
248 |
CCalRemoteAttachmentInfo& aAttachmentInfo ) |
|
249 |
{ |
|
250 |
FUNC_LOG; |
|
251 |
||
252 |
iRemoteAttachmentApi = &aRemoteAttaApi; |
|
253 |
iAttachmentInfo = &aAttachmentInfo; |
|
254 |
} |
|
255 |
||
256 |
// --------------------------------------------------------------------------- |
|
257 |
// CMRAttachmentCommandHandler::SetRemoteAttachmentInformationL |
|
258 |
// --------------------------------------------------------------------------- |
|
259 |
// |
|
260 |
void CMRAttachmentCommandHandler::HandleRemoteAttachmentCommandL( |
|
261 |
TInt aCommandId, |
|
262 |
const CESMRRichTextLink& aSelectedLink ) |
|
263 |
{ |
|
264 |
FUNC_LOG; |
|
265 |
||
266 |
// Check that remote attachment information is being set |
|
267 |
__ASSERT_DEBUG( |
|
268 |
iRemoteAttachmentApi, |
|
269 |
Panic(EMRAttachmentCommandHandlerRemoteInfoNotSet) ); |
|
270 |
||
271 |
__ASSERT_DEBUG( |
|
272 |
iAttachmentInfo, |
|
273 |
Panic(EMRAttachmentCommandHandlerRemoteInfoNotSet) ); |
|
274 |
||
275 |
HandleRemoteAttachmentCommandInternalL( |
|
276 |
aCommandId, |
|
277 |
aSelectedLink.Value() ); |
|
278 |
} |
|
279 |
||
280 |
// --------------------------------------------------------------------------- |
|
281 |
// CMRAttachmentCommandHandler::RemoteOperations |
|
282 |
// --------------------------------------------------------------------------- |
|
283 |
// |
|
284 |
RPointerArray<MCalRemoteAttachmentOperation>& |
|
285 |
CMRAttachmentCommandHandler::RemoteOperations() |
|
286 |
{ |
|
287 |
FUNC_LOG; |
|
288 |
return iDownloadOperations; |
|
289 |
} |
|
290 |
||
291 |
// --------------------------------------------------------------------------- |
|
292 |
// CMRAttachmentCommandHandler::CurrentCommandInProgress |
|
293 |
// --------------------------------------------------------------------------- |
|
294 |
// |
|
295 |
TInt CMRAttachmentCommandHandler::CurrentCommandInProgress() const |
|
296 |
{ |
|
297 |
FUNC_LOG; |
|
298 |
||
299 |
return iCommandInProgress; |
|
300 |
} |
|
301 |
||
302 |
// --------------------------------------------------------------------------- |
|
303 |
// CMRAttachmentCommandHandler::Progress |
|
304 |
// --------------------------------------------------------------------------- |
|
305 |
// |
|
306 |
void CMRAttachmentCommandHandler::Progress( |
|
307 |
MCalRemoteAttachmentOperation* aOperation, |
|
308 |
TInt aPercentageCompleted ) |
|
309 |
{ |
|
310 |
FUNC_LOG; |
|
311 |
||
312 |
TRAP_IGNORE( NotifyProgressL( |
|
313 |
aOperation->AttachmentInformation().AttachmentLabel(), |
|
314 |
aPercentageCompleted )); |
|
315 |
} |
|
316 |
||
317 |
// --------------------------------------------------------------------------- |
|
318 |
// CMRAttachmentCommandHandler::OperationCompleted |
|
319 |
// --------------------------------------------------------------------------- |
|
320 |
// |
|
321 |
void CMRAttachmentCommandHandler::OperationCompleted( |
|
322 |
MCalRemoteAttachmentOperation* aOperation, |
|
323 |
RFile& aAttachment ) |
|
324 |
{ |
|
325 |
FUNC_LOG; |
|
326 |
||
327 |
TRAP_IGNORE( HandleOperationCompletedL( aOperation, aAttachment ) ); |
|
328 |
} |
|
329 |
||
330 |
// --------------------------------------------------------------------------- |
|
331 |
// CMRAttachmentCommandHandler::OperationError |
|
332 |
// --------------------------------------------------------------------------- |
|
333 |
// |
|
334 |
void CMRAttachmentCommandHandler::OperationError( |
|
335 |
MCalRemoteAttachmentOperation* /*aOperation*/, |
|
336 |
TInt aErrorCode ) |
|
337 |
{ |
|
338 |
FUNC_LOG; |
|
339 |
||
340 |
// Operation failed or cancelled, hide download indicator |
|
341 |
TRAP_IGNORE( HideDownloadIndicatorL() ); |
|
342 |
iCommandInProgress = 0; |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
343 |
iSaveAllAttachmentsCommand = EFalse; |
64 | 344 |
|
345 |
if ( aErrorCode != KErrCancel ) |
|
346 |
{ |
|
347 |
// Operation failed, show error note |
|
348 |
CCoeEnv::Static()->HandleError( aErrorCode ); |
|
349 |
} |
|
350 |
} |
|
351 |
||
352 |
// --------------------------------------------------------------------------- |
|
353 |
// CMRAttachmentCommandHandler::ResolveAttachmentIndexL |
|
354 |
// --------------------------------------------------------------------------- |
|
355 |
// |
|
356 |
TInt CMRAttachmentCommandHandler::ResolveAttachmentIndexL( |
|
357 |
const TDesC& aAttachmentLabel ) |
|
358 |
{ |
|
359 |
FUNC_LOG; |
|
360 |
||
361 |
TInt index( KErrNotFound ); |
|
362 |
||
363 |
TInt attachmentCount( iEntry.AttachmentCountL() ); |
|
364 |
for (TInt i(0); i < attachmentCount && KErrNotFound == index; ++i ) |
|
365 |
{ |
|
366 |
CCalAttachment* attachment = iEntry.AttachmentL(i); |
|
367 |
||
368 |
TPtrC attachmentLabel( attachment->Label() ); |
|
369 |
if ( !aAttachmentLabel.Compare(attachmentLabel) ) |
|
370 |
{ |
|
371 |
index = i; |
|
372 |
} |
|
373 |
} |
|
374 |
||
375 |
// Check that attachment is always found |
|
376 |
// If attachment is not found --> Our data is corrupted |
|
377 |
__ASSERT_DEBUG( |
|
378 |
KErrNotFound != index, |
|
379 |
Panic( EMRAttachmentCommandHandlerAttachmentNotFound) ); |
|
380 |
||
381 |
return index; |
|
382 |
} |
|
383 |
||
384 |
// --------------------------------------------------------------------------- |
|
385 |
// CMRAttachmentCommandHandler::ResolveAttachmentIndexL |
|
386 |
// --------------------------------------------------------------------------- |
|
387 |
// |
|
388 |
TInt CMRAttachmentCommandHandler::CommandIndex( |
|
389 |
const TDesC& aAttachmentLabel ) |
|
390 |
{ |
|
391 |
FUNC_LOG; |
|
392 |
||
393 |
TInt index( KErrNotFound ); |
|
394 |
||
395 |
TInt commandCount( iDownloadOperations.Count() ); |
|
396 |
for ( TInt i(0); i < commandCount && KErrNotFound == index; ++i ) |
|
397 |
{ |
|
398 |
// There are download operations in progress |
|
399 |
const MCalRemoteAttachment& attachInfo = |
|
400 |
iDownloadOperations[i]->AttachmentInformation(); |
|
401 |
||
402 |
TPtrC label( attachInfo.AttachmentLabel() ); |
|
403 |
if ( !label.Compare( aAttachmentLabel ) ) |
|
404 |
{ |
|
405 |
index = i; |
|
406 |
} |
|
407 |
} |
|
408 |
||
409 |
return index; |
|
410 |
} |
|
411 |
||
412 |
// --------------------------------------------------------------------------- |
|
413 |
// CMRAttachmentCommandHandler::RemoteAttachmentIndex |
|
414 |
// --------------------------------------------------------------------------- |
|
415 |
// |
|
416 |
TInt CMRAttachmentCommandHandler::RemoteAttachmentIndexL( |
|
417 |
const TDesC& aAttachmentLabel ) |
|
418 |
{ |
|
419 |
FUNC_LOG; |
|
420 |
||
421 |
TInt index( KErrNotFound ); |
|
422 |
||
423 |
TInt remoteAttCount( iAttachmentInfo->AttachmentCount() ); |
|
424 |
for ( TInt i(0); i < remoteAttCount && index == KErrNotFound; ++i ) |
|
425 |
{ |
|
426 |
TPtrC remoteAttName( iAttachmentInfo->AttachmentL(i).AttachmentLabel() ); |
|
427 |
||
428 |
if ( !remoteAttName.Compare( aAttachmentLabel ) ) |
|
429 |
{ |
|
430 |
index = i; |
|
431 |
} |
|
432 |
} |
|
433 |
||
434 |
return index; |
|
435 |
} |
|
436 |
||
437 |
// --------------------------------------------------------------------------- |
|
438 |
// CMRAttachmentCommandHandler::HandleOperationCompleted |
|
439 |
// --------------------------------------------------------------------------- |
|
440 |
// |
|
441 |
void CMRAttachmentCommandHandler::HandleOperationCompletedL( |
|
442 |
MCalRemoteAttachmentOperation* aOperation, |
|
443 |
RFile& aAttachment ) |
|
444 |
{ |
|
445 |
FUNC_LOG; |
|
446 |
||
447 |
// Notify 'download ready' event |
|
448 |
CESMRFieldCommandEvent* event = CESMRFieldCommandEvent::NewLC( |
|
449 |
NULL, |
|
450 |
EMRCmdHideAttachmentIndicator ); |
|
451 |
||
452 |
iEventQueue.NotifyEventAsyncL( event ); |
|
453 |
||
454 |
CleanupStack::Pop( event ); |
|
455 |
||
456 |
// First search the correct operation from the list |
|
457 |
TInt operationIndex( CommandIndex(aOperation->AttachmentInformation().AttachmentLabel() ) ); |
|
458 |
||
459 |
__ASSERT_DEBUG( |
|
460 |
operationIndex != KErrNotFound, |
|
461 |
Panic( EMRAttachmentCommandHandlerRemoteCommandNotFound) ); |
|
462 |
||
463 |
// Resolve current download operation in progress |
|
464 |
MCalRemoteAttachmentOperation* operation = iDownloadOperations[ operationIndex ]; |
|
465 |
CleanupDeletePushL( operation ); |
|
466 |
iDownloadOperations.Remove( operationIndex ); |
|
467 |
||
468 |
TInt attachmentIndex( ResolveAttachmentIndexL( |
|
469 |
operation->AttachmentInformation().AttachmentLabel() ) ); |
|
470 |
||
471 |
if ( KErrNotFound == attachmentIndex ) |
|
472 |
{ |
|
473 |
User::Leave( KErrNotFound ); |
|
474 |
} |
|
475 |
||
476 |
if ( EESMRViewerCancelAttachmentDownload != iCommandInProgress ) |
|
477 |
{ |
|
478 |
// Update the remote attachment to be local attachment ... |
|
479 |
UpdateLocalAttachmentL( |
|
480 |
operation->AttachmentInformation().AttachmentLabel(), |
|
481 |
aAttachment, |
|
482 |
attachmentIndex ); |
|
483 |
} |
|
484 |
||
485 |
// Then execute normal local file attachment command |
|
486 |
if ( EESMRViewerOpenAttachment == iCommandInProgress || |
|
487 |
EESMRViewerSaveAttachment == iCommandInProgress || |
|
488 |
EESMRViewerSaveAllAttachments == iCommandInProgress ) |
|
489 |
{ |
|
490 |
TInt attachmentIndex( |
|
491 |
ResolveAttachmentIndexL( |
|
492 |
operation->AttachmentInformation().AttachmentLabel() ) ); |
|
493 |
||
494 |
if ( EESMRViewerOpenAttachment == iCommandInProgress ) |
|
495 |
{ |
|
496 |
// When opening attachment from remote storage --> Ask user to |
|
497 |
// save attachment first as well. |
|
498 |
HandleAttachmentCommandInternalL( |
|
499 |
EESMRViewerOpenAndSaveAttachment, attachmentIndex ); |
|
500 |
||
501 |
iCommandInProgress = 0; |
|
502 |
} |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
503 |
else // Save and Save All attachments commands |
64 | 504 |
{ |
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
505 |
// Let's keep in mind, if save all attachments command |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
506 |
// is in progress. |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
507 |
if( EESMRViewerSaveAllAttachments == iCommandInProgress ) |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
508 |
{ |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
509 |
iSaveAllAttachmentsCommand = ETrue; |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
510 |
} |
64 | 511 |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
512 |
// Send asynchronous event, that attachment with |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
513 |
// given index is saved. This command will return to |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
514 |
// HandleAttachmentCommandL in this class. Async command |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
515 |
// is used to avoid system caused error where memory selection |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
516 |
// query in document handler does not receive key events |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
517 |
// correctly. |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
518 |
CESMRFieldCommandEvent* event = CESMRFieldCommandEvent::NewLC( |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
519 |
NULL, |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
520 |
EESMRViewerSaveAttachment ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
521 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
522 |
// Record attachment index |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
523 |
iAttachmentIndex = attachmentIndex; |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
524 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
525 |
// Send async event |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
526 |
iEventQueue.NotifyEventAsyncL( event ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
527 |
CleanupStack::Pop( event ); |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
528 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
529 |
// Set to zero for the duration of the saving. |
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
530 |
iCommandInProgress = 0; |
64 | 531 |
} |
532 |
} |
|
533 |
||
534 |
CleanupStack::PopAndDestroy( operation ); |
|
535 |
} |
|
536 |
||
537 |
// --------------------------------------------------------------------------- |
|
538 |
// CMRAttachmentCommandHandler::HandleAttachmentCommandInternalL |
|
539 |
// --------------------------------------------------------------------------- |
|
540 |
// |
|
541 |
void CMRAttachmentCommandHandler::HandleAttachmentCommandInternalL( |
|
542 |
TInt aCommandId, |
|
543 |
TInt aAttachmentIndex ) |
|
544 |
{ |
|
545 |
FUNC_LOG; |
|
546 |
||
547 |
if ( iDownloadOperations.Count() ) |
|
548 |
{ |
|
549 |
// Cancel ongoing remote operations ... |
|
550 |
iDownloadOperations.ResetAndDestroy(); |
|
551 |
} |
|
552 |
||
553 |
CMRAttachmentCommand* command = NULL; |
|
554 |
||
555 |
// Creating command |
|
556 |
switch ( aCommandId ) |
|
557 |
{ |
|
558 |
case EESMRViewerOpenAttachment: |
|
559 |
case EESMREditorOpenAttachment: |
|
560 |
{ |
|
561 |
command = CMROpenAttachmentCommand::NewL( *iDocHandler ); |
|
562 |
} |
|
563 |
break; |
|
564 |
case EESMREditorRemoveAttachment: |
|
565 |
case EESMREditorRemoveAllAttachments: |
|
566 |
{ |
|
567 |
command = CMRRemoveAttachmentCommand::NewL(); |
|
568 |
} |
|
569 |
break; |
|
570 |
case EESMRViewerSaveAttachment: |
|
571 |
{ |
|
572 |
command = CMRSaveAttachmentCommand::NewL( *iDocHandler ); |
|
573 |
} |
|
574 |
break; |
|
575 |
case EESMRViewerOpenAndSaveAttachment: |
|
576 |
{ |
|
577 |
command = CMRSaveAndOpenAttachmentCommand::NewL( *iDocHandler ); |
|
578 |
} |
|
579 |
break; |
|
580 |
case EESMRViewerSaveAllAttachments: |
|
581 |
{ |
|
582 |
SaveAllAttachmentsL(); |
|
583 |
} |
|
584 |
break; |
|
585 |
default: |
|
586 |
break; |
|
587 |
} |
|
588 |
||
589 |
if ( command ) |
|
590 |
{ |
|
591 |
CleanupDeletePushL( command ); |
|
592 |
||
593 |
// Executing command. TRAP errors so cancellation can be handled |
|
594 |
// without an extra error note. |
|
595 |
TRAPD( error, |
|
596 |
ExecuteCommandL( aCommandId, *command, aAttachmentIndex ) ) |
|
597 |
||
598 |
if ( error != KErrCancel ) |
|
599 |
{ |
|
600 |
User::LeaveIfError( error ); |
|
601 |
||
602 |
if ( aCommandId == EESMRViewerSaveAttachment |
|
603 |
&& iCommandInProgress != EESMRViewerSaveAllAttachments ) |
|
604 |
{ |
|
605 |
ShowInfoNoteL(); |
|
606 |
} |
|
607 |
} |
|
608 |
else // KErrCancel |
|
609 |
{ |
|
610 |
iCommandInProgress = 0; |
|
611 |
} |
|
612 |
||
613 |
CleanupStack::PopAndDestroy( command ); |
|
614 |
} |
|
615 |
} |
|
616 |
||
617 |
// --------------------------------------------------------------------------- |
|
618 |
// CMRAttachmentCommandHandler::UpdateLocalAttachmentL |
|
619 |
// --------------------------------------------------------------------------- |
|
620 |
// |
|
621 |
void CMRAttachmentCommandHandler::UpdateLocalAttachmentL( |
|
622 |
const TDesC& aAttachmentLabel, |
|
623 |
RFile& aAttachment, |
|
624 |
TInt aAttachmentIndex ) |
|
625 |
{ |
|
626 |
FUNC_LOG; |
|
627 |
||
628 |
// Create file attachment and add to calendar entry |
|
629 |
CCalAttachment* fileAttachment = CCalAttachment::NewFileL( aAttachment ); |
|
630 |
CleanupStack::PushL( fileAttachment ); |
|
631 |
||
632 |
RApaLsSession apaSession; |
|
633 |
TDataRecognitionResult dataType; |
|
634 |
User::LeaveIfError( apaSession.Connect() ); |
|
635 |
apaSession.RecognizeData( aAttachment, dataType ); |
|
636 |
apaSession.Close(); |
|
637 |
||
638 |
// set attachment properties |
|
639 |
TPtrC8 contentType( dataType.iDataType.Des8() ); |
|
640 |
||
641 |
if ( contentType.Length() ) |
|
642 |
{ |
|
643 |
fileAttachment->SetMimeTypeL( contentType ); |
|
644 |
} |
|
645 |
else |
|
646 |
{ |
|
647 |
fileAttachment->SetMimeTypeL( KUnknownDatatype ); |
|
648 |
} |
|
649 |
||
650 |
fileAttachment->SetLabelL( aAttachmentLabel ); |
|
651 |
iEntry.AddAttachmentL( *fileAttachment ); // calEntry takes ownership |
|
652 |
CleanupStack::Pop( fileAttachment ); |
|
653 |
||
654 |
// Remove remote attachment |
|
655 |
CCalAttachment* attachment = iEntry.AttachmentL( aAttachmentIndex ); |
|
656 |
iEntry.DeleteAttachmentL( *attachment ); |
|
657 |
attachment = NULL; |
|
658 |
||
659 |
TInt remoteAttachmentIndex( RemoteAttachmentIndexL( aAttachmentLabel ) ); |
|
660 |
if ( KErrNotFound != remoteAttachmentIndex ) |
|
661 |
{ |
|
662 |
iAttachmentInfo->RemoveAttachmentAtL( remoteAttachmentIndex ); |
|
663 |
} |
|
664 |
} |
|
665 |
||
666 |
// --------------------------------------------------------------------------- |
|
667 |
// CMRAttachmentCommandHandler::NotifyProgressL |
|
668 |
// --------------------------------------------------------------------------- |
|
669 |
// |
|
670 |
void CMRAttachmentCommandHandler::NotifyProgressL( |
|
671 |
const TDesC& aAttachmentLabel, |
|
672 |
TInt aPercentageCompleted ) |
|
673 |
{ |
|
674 |
FUNC_LOG; |
|
675 |
||
676 |
CDesCArray* descArray = new (ELeave) CDesCArrayFlat( 1 ); |
|
677 |
CleanupStack::PushL( descArray ); |
|
678 |
descArray->AppendL( aAttachmentLabel ); |
|
679 |
CArrayFix<TInt>* intArray = new (ELeave) CArrayFixFlat<TInt>( 1 ); |
|
680 |
CleanupStack::PushL( intArray ); |
|
681 |
intArray->AppendL( aPercentageCompleted ); |
|
682 |
||
683 |
HBufC* statusText = StringLoader::LoadL( |
|
684 |
R_QTN_MEET_REQ_ATTACHMENTS_DOWNLOAD_PREFIX, |
|
685 |
*descArray, |
|
686 |
*intArray ); |
|
687 |
||
688 |
CleanupStack::PushL( statusText ); |
|
689 |
||
690 |
// Create field change event |
|
691 |
CESMRGenericFieldEvent* event = CESMRGenericFieldEvent::NewLC( |
|
692 |
NULL, |
|
693 |
MESMRFieldEvent::EESMRFieldChangeEvent ); |
|
694 |
||
695 |
// Add this field as parameter |
|
696 |
TInt fieldId = EESMRFieldViewerAttachments; |
|
697 |
CESMRFieldEventValue* field = CESMRFieldEventValue::NewLC( |
|
698 |
MESMRFieldEventValue::EESMRInteger, |
|
699 |
&fieldId ); |
|
700 |
event->AddParamL( field ); |
|
701 |
CleanupStack::Pop( field ); |
|
702 |
||
703 |
// Add new value as parameter |
|
704 |
CESMRFieldEventValue* value = CESMRFieldEventValue::NewLC( |
|
705 |
CESMRFieldEventValue::EESMRString, |
|
706 |
statusText ); |
|
707 |
||
708 |
// Encapsulate value, so receiver gets the field value type |
|
709 |
event->AddParamL( value, ETrue ); |
|
710 |
CleanupStack::Pop( value ); |
|
711 |
||
712 |
// Send event |
|
713 |
iEventQueue.NotifyEventAsyncL( event ); |
|
714 |
CleanupStack::Pop( event ); |
|
715 |
||
716 |
// Ownership transferred to field event value |
|
717 |
CleanupStack::Pop( statusText ); |
|
718 |
CleanupStack::PopAndDestroy( intArray ); |
|
719 |
CleanupStack::PopAndDestroy( descArray ); |
|
720 |
} |
|
721 |
||
722 |
// --------------------------------------------------------------------------- |
|
723 |
// CMRAttachmentCommandHandler::HandleRemoteAttachmentCommandInternalL |
|
724 |
// --------------------------------------------------------------------------- |
|
725 |
// |
|
726 |
void CMRAttachmentCommandHandler::HandleRemoteAttachmentCommandInternalL( |
|
727 |
TInt aCommandId, |
|
728 |
const TDesC& aRemoteAttachmentLabel ) |
|
729 |
{ |
|
730 |
FUNC_LOG; |
|
731 |
||
732 |
// Fetch correct attachment from the entry |
|
733 |
TInt index = ResolveAttachmentIndexL( aRemoteAttachmentLabel ); |
|
734 |
CCalAttachment* attachment = iEntry.AttachmentL( index ); |
|
735 |
||
736 |
if ( CCalAttachment::EFile == attachment->Type() ) |
|
737 |
{ |
|
738 |
// This is local attachment ... |
|
739 |
User::Leave( KErrArgument ); |
|
740 |
} |
|
741 |
||
742 |
switch ( aCommandId ) |
|
743 |
{ |
|
744 |
case EESMRViewerOpenAttachment: |
|
745 |
case EESMRViewerSaveAttachment: |
|
746 |
{ |
|
747 |
TInt remoteAttIndex( |
|
748 |
RemoteAttachmentIndexL( aRemoteAttachmentLabel ) ); |
|
749 |
||
750 |
RPointerArray<MCalRemoteAttachment> attachmentArray; |
|
751 |
CleanupClosePushL( attachmentArray ); |
|
752 |
const MCalRemoteAttachment& remoteAttachment( |
|
753 |
iAttachmentInfo->AttachmentL(remoteAttIndex) ); |
|
754 |
attachmentArray.Append( &remoteAttachment ); |
|
755 |
||
756 |
if ( !iCommandInProgress ) |
|
757 |
{ |
|
758 |
// There are no ongoing command for this attachment |
|
759 |
// ==> We can start new one ... |
|
760 |
||
761 |
iCommandInProgress = aCommandId; |
|
762 |
||
763 |
// Before we can execute the actual command, we need to be sure |
|
764 |
// that attachments are being downloaded to device. |
|
765 |
iRemoteAttachmentApi->DownloadAttachmentsL( |
|
766 |
attachmentArray, |
|
767 |
iDownloadOperations, |
|
768 |
*this ); |
|
769 |
} |
|
770 |
||
771 |
CleanupStack::PopAndDestroy( &attachmentArray ); |
|
772 |
} |
|
773 |
break; |
|
774 |
||
775 |
case EESMRViewerCancelAttachmentDownload: |
|
776 |
{ |
|
777 |
if ( EESMRViewerSaveAllAttachments == iCommandInProgress ) |
|
778 |
{ |
|
779 |
iCommandInProgress = aCommandId; |
|
780 |
iDownloadOperations.ResetAndDestroy(); |
|
781 |
} |
|
782 |
else |
|
783 |
{ |
|
784 |
// Cancelling is done by simply deleting the command |
|
785 |
iCommandInProgress = aCommandId; |
|
786 |
TInt remoteCommand( CommandIndex( |
|
787 |
aRemoteAttachmentLabel )); |
|
788 |
||
789 |
MCalRemoteAttachmentOperation* command = |
|
790 |
iDownloadOperations[remoteCommand]; |
|
791 |
||
792 |
iDownloadOperations.Remove( remoteCommand ); |
|
793 |
delete command; |
|
794 |
} |
|
80
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
795 |
|
726fba06891a
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
64
diff
changeset
|
796 |
iSaveAllAttachmentsCommand = EFalse; |
64 | 797 |
} |
798 |
break; |
|
799 |
case EESMRViewerSaveAllAttachments: |
|
800 |
{ |
|
801 |
SaveAllAttachmentsL(); |
|
802 |
} |
|
803 |
break; |
|
804 |
default: |
|
805 |
break; |
|
806 |
} |
|
807 |
} |
|
808 |
||
809 |
// --------------------------------------------------------------------------- |
|
810 |
// CMRAttachmentCommandHandler::HideDownloadIndicatorL |
|
811 |
// --------------------------------------------------------------------------- |
|
812 |
// |
|
813 |
void CMRAttachmentCommandHandler::HideDownloadIndicatorL() |
|
814 |
{ |
|
815 |
FUNC_LOG; |
|
816 |
||
817 |
CESMRFieldCommandEvent* event = CESMRFieldCommandEvent::NewLC( |
|
818 |
NULL, |
|
819 |
EMRCmdHideAttachmentIndicator ); |
|
820 |
iEventQueue.NotifyEventAsyncL(event); |
|
821 |
CleanupStack::Pop(event); |
|
822 |
} |
|
823 |
||
824 |
// --------------------------------------------------------------------------- |
|
825 |
// CMRAttachmentCommandHandler::ExecuteCommandL |
|
826 |
// --------------------------------------------------------------------------- |
|
827 |
// |
|
828 |
void CMRAttachmentCommandHandler::ExecuteCommandL( |
|
829 |
TInt aCommandId, |
|
830 |
CMRAttachmentCommand& aCommand, |
|
831 |
TInt aAttachmentIndex ) |
|
832 |
{ |
|
833 |
// Executing command |
|
834 |
switch ( aCommandId ) |
|
835 |
{ |
|
836 |
case EESMREditorRemoveAllAttachments: |
|
837 |
{ |
|
838 |
for( TInt i = iEntry.AttachmentCountL() ; i > 0; --i ) |
|
839 |
{ |
|
840 |
aCommand.ExecuteAttachmentCommandL( iEntry, i - 1 ); |
|
841 |
} |
|
842 |
} |
|
843 |
case EESMRViewerSaveAllAttachments: |
|
844 |
{ |
|
845 |
for( TInt i = 0; i < iEntry.AttachmentCountL(); ++i ) |
|
846 |
{ |
|
847 |
aCommand.ExecuteAttachmentCommandL( iEntry, i ); |
|
848 |
} |
|
849 |
} |
|
850 |
break; |
|
851 |
default: |
|
852 |
{ |
|
853 |
aCommand.ExecuteAttachmentCommandL( iEntry, aAttachmentIndex ); |
|
854 |
} |
|
855 |
break; |
|
856 |
} |
|
857 |
||
858 |
} |
|
859 |
||
860 |
// --------------------------------------------------------------------------- |
|
861 |
// CMRAttachmentCommandHandler::SaveAllAttachmentsL |
|
862 |
// --------------------------------------------------------------------------- |
|
863 |
// |
|
864 |
void CMRAttachmentCommandHandler::SaveAllAttachmentsL() |
|
865 |
{ |
|
866 |
// Save local attachments |
|
867 |
CMRAttachmentCommand* command = |
|
868 |
CMRSaveAttachmentCommand::NewL( *iDocHandler ); |
|
869 |
||
870 |
TRAPD( error, |
|
871 |
ExecuteCommandL( EESMRViewerSaveAllAttachments, *command, 0 ) ) |
|
872 |
||
873 |
delete command; |
|
874 |
||
875 |
if ( error != KErrCancel ) |
|
876 |
{ |
|
877 |
// Check if error happened during local attachment saving |
|
878 |
User::LeaveIfError( error ); |
|
879 |
||
880 |
// Proceed with remote attachments |
|
881 |
if ( iAttachmentInfo && iAttachmentInfo->AttachmentCount() > 0 ) |
|
882 |
{ |
|
883 |
SaveNextRemoteAttachmentL(); |
|
884 |
} |
|
885 |
else // Show Save all info note |
|
886 |
{ |
|
887 |
ShowInfoNoteL( iEntry.AttachmentCountL() ); |
|
888 |
} |
|
889 |
} |
|
890 |
} |
|
891 |
||
892 |
// --------------------------------------------------------------------------- |
|
893 |
// CMRAttachmentCommandHandler::SaveNextRemoteAttachmentL |
|
894 |
// --------------------------------------------------------------------------- |
|
895 |
// |
|
896 |
void CMRAttachmentCommandHandler::SaveNextRemoteAttachmentL() |
|
897 |
{ |
|
898 |
__ASSERT_DEBUG( iAttachmentInfo->AttachmentCount() > 0, |
|
899 |
Panic( EMRAttachmentCommandHandlerRemoteAttachmentNotFound ) ); |
|
900 |
||
901 |
// Save first remote attachment of attachment info |
|
902 |
RPointerArray<MCalRemoteAttachment> attachmentArray; |
|
903 |
CleanupClosePushL( attachmentArray ); |
|
904 |
const MCalRemoteAttachment& remoteAttachment( |
|
905 |
iAttachmentInfo->AttachmentL( 0 ) ); |
|
906 |
attachmentArray.AppendL( &remoteAttachment ); |
|
907 |
||
908 |
if ( !iCommandInProgress ) |
|
909 |
{ |
|
910 |
// There are no ongoing command for this attachment |
|
911 |
// ==> We can start new one ... |
|
912 |
iCommandInProgress = EESMRViewerSaveAllAttachments; |
|
913 |
||
914 |
// Before we can execute the actual command, we need to be sure |
|
915 |
// that attachments are being downloaded to device. |
|
916 |
iRemoteAttachmentApi->DownloadAttachmentsL( |
|
917 |
attachmentArray, |
|
918 |
iDownloadOperations, |
|
919 |
*this ); |
|
920 |
} |
|
921 |
||
922 |
CleanupStack::PopAndDestroy( &attachmentArray ); |
|
923 |
} |
|
924 |
||
925 |
// EOF |