|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <aknlistquerydialog.h> |
|
19 #include <AiwGenericParam.hrh> |
|
20 #include <AiwGenericParam.h> |
|
21 #include <AiwVariant.h> |
|
22 #include <eikappui.h> |
|
23 #include <aknnotewrappers.h> |
|
24 #include <AknWaitDialog.h> |
|
25 #include <coemain.h> |
|
26 #include <calattachment.h> |
|
27 #include <CalenInterimUtils2.h> |
|
28 #include <calencommonui.rsg> |
|
29 #include <StringLoader.h> // StringLoader |
|
30 #include <DRMHelper.h> |
|
31 #include <caf/data.h> |
|
32 #include <caf/caf.h> |
|
33 #include <calencommandhandler.h> |
|
34 #include <calencontext.h> |
|
35 #include <calentoolbar.h> |
|
36 |
|
37 #include "calenattachmentui.h" |
|
38 #include "calendarui_debug.h" |
|
39 #include "calenattachmentutils.h" |
|
40 #include "calencontroller.h" |
|
41 #include "calenviewattachmentsdialog.h" |
|
42 #include "calendar.hrh" |
|
43 #include "calenattachmentmodel.h" |
|
44 #include "calenattachmentinfo.h" |
|
45 #include "CleanupResetAndDestroy.h" |
|
46 #include "calenviewmanager.h" |
|
47 |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // CCalenAttachmentUi::NewL |
|
51 // 1st phase of construction |
|
52 // ---------------------------------------------------------------------------- |
|
53 // |
|
54 CCalenAttachmentUi* CCalenAttachmentUi::NewL(CCalenController& aController) |
|
55 { |
|
56 TRACE_ENTRY_POINT; |
|
57 |
|
58 CCalenAttachmentUi* self = new (ELeave) CCalenAttachmentUi(aController); |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(self); |
|
62 |
|
63 TRACE_EXIT_POINT; |
|
64 return self; |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // CCalenAttachmentUi::~CCalenAttachmentUi |
|
69 // Destructor |
|
70 // ---------------------------------------------------------------------------- |
|
71 // |
|
72 CCalenAttachmentUi::~CCalenAttachmentUi() |
|
73 { |
|
74 TRACE_ENTRY_POINT; |
|
75 delete iTitle; |
|
76 iController.CancelNotifications( this ); |
|
77 TRACE_EXIT_POINT; |
|
78 } |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // CCalenAttachmentUi::CCalenAttachmentUi |
|
82 // Default constructor |
|
83 // ---------------------------------------------------------------------------- |
|
84 // |
|
85 CCalenAttachmentUi::CCalenAttachmentUi(CCalenController& aController) |
|
86 : iController(aController), iAttachmentLoadingOn(EFalse), |
|
87 iAddAttachmentFromViewer(EFalse),iViewerActive(EFalse) |
|
88 { |
|
89 TRACE_ENTRY_POINT; |
|
90 TRACE_EXIT_POINT; |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------------------------- |
|
94 // CCalenAttachmentUi::ConstructL |
|
95 // 2nd phase constructor |
|
96 // ---------------------------------------------------------------------------- |
|
97 // |
|
98 void CCalenAttachmentUi::ConstructL() |
|
99 { |
|
100 TRACE_ENTRY_POINT; |
|
101 |
|
102 RArray<TCalenNotification> notificationArray; |
|
103 notificationArray.Append(ECalenNotifyEntrySaved); |
|
104 notificationArray.Append(ECalenNotifyEntryDeleted); |
|
105 notificationArray.Append(ECalenNotifyEntryClosed); |
|
106 notificationArray.Append(ECalenNotifyInstanceDeleted); |
|
107 notificationArray.Append(ECalenNotifyMarkedEntryDeleted); |
|
108 notificationArray.Append(ECalenNotifyMultipleEntriesDeleted); |
|
109 //notificationArray.Append(ECalenNotifyDialogClosed); |
|
110 notificationArray.Append(ECalenNotifyAttachmentViewerClosed); |
|
111 iController.RegisterForNotificationsL( this, notificationArray ); |
|
112 notificationArray.Reset(); |
|
113 |
|
114 iAttachmentModel = &iController.AttachmentData(); |
|
115 iAttachmentModel->SetObserver(this); |
|
116 iAttachmentAlreadyExists = EFalse; |
|
117 iAttachmentInfoIntialized = EFalse; |
|
118 |
|
119 TRACE_EXIT_POINT; |
|
120 } |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // CCalenAttachmentUi::HandleCommandL |
|
124 // Handles the attachement commands |
|
125 // ---------------------------------------------------------------------------- |
|
126 // |
|
127 TBool CCalenAttachmentUi::HandleCommandL(const TCalenCommand& aCommand) |
|
128 { |
|
129 TRACE_ENTRY_POINT; |
|
130 |
|
131 TInt continueCommand(EFalse); |
|
132 switch(aCommand.Command()) |
|
133 { |
|
134 case ECalenAddAttachment: |
|
135 { |
|
136 HandleAddAttachmentL(); |
|
137 } |
|
138 break; |
|
139 case ECalenAddAttachmentFromViewer: |
|
140 { |
|
141 |
|
142 iAddAttachmentFromViewer = ETrue; |
|
143 HandleAddAttachmentL(); |
|
144 } |
|
145 break; |
|
146 case ECalenViewAttachmentList: |
|
147 { |
|
148 DoAttachmentL(); |
|
149 } |
|
150 break; |
|
151 case ECalenRemoveAttachment: |
|
152 { |
|
153 CheckForExistingAttachmentsL(); |
|
154 |
|
155 RPointerArray<CCalenAttachmentInfo> attachmentInfoList; |
|
156 iAttachmentModel->GetAttachmentListL(attachmentInfoList); |
|
157 |
|
158 if(!iAddAttachmentFromViewer && (attachmentInfoList.Count())) |
|
159 { |
|
160 iAttachmentModel->Reset(); |
|
161 iController.BroadcastNotification(ECalenNotifyAttachmentRemoved); |
|
162 RemoveTemporaryFilesL(); |
|
163 } |
|
164 else |
|
165 { |
|
166 iAttachmentModel->DeleteAttachment(0); |
|
167 } |
|
168 attachmentInfoList.Close(); |
|
169 } |
|
170 break; |
|
171 default: |
|
172 break; |
|
173 } |
|
174 |
|
175 TRACE_EXIT_POINT; |
|
176 return continueCommand; |
|
177 } |
|
178 |
|
179 // ---------------------------------------------------------------------------- |
|
180 // CCalenAttachmentUi::CalenCommandHandlerExtensionL |
|
181 // Dummy implementation. |
|
182 // (other items were commented in a header). |
|
183 // ---------------------------------------------------------------------------- |
|
184 // |
|
185 TAny* CCalenAttachmentUi::CalenCommandHandlerExtensionL( TUid /*aExtensionUid*/ ) |
|
186 { |
|
187 TRACE_ENTRY_POINT; |
|
188 TRACE_EXIT_POINT; |
|
189 return NULL; |
|
190 } |
|
191 |
|
192 // ---------------------------------------------------------------------------- |
|
193 // CCalenAttachmentUi::HandleNotification |
|
194 // Handle notifications |
|
195 // ---------------------------------------------------------------------------- |
|
196 // |
|
197 void CCalenAttachmentUi::HandleNotification(const TCalenNotification aNotification) |
|
198 { |
|
199 TRACE_ENTRY_POINT; |
|
200 |
|
201 TRAP_IGNORE(DoHandleNotificationL(aNotification)); |
|
202 |
|
203 TRACE_EXIT_POINT; |
|
204 } |
|
205 |
|
206 // ---------------------------------------------------------------------------- |
|
207 // CCalenAttachmentUi::DoHandleNotificationL |
|
208 // Handle notifications |
|
209 // ---------------------------------------------------------------------------- |
|
210 // |
|
211 void CCalenAttachmentUi::DoHandleNotificationL(const TCalenNotification aNotification ) |
|
212 { |
|
213 TRACE_ENTRY_POINT; |
|
214 switch(aNotification) |
|
215 { |
|
216 case ECalenNotifyEntrySaved: |
|
217 case ECalenNotifyEntryDeleted: |
|
218 case ECalenNotifyInstanceDeleted: |
|
219 { |
|
220 if(!(iAddAttachmentFromViewer)) |
|
221 { |
|
222 iAttachmentModel->Reset(); |
|
223 } |
|
224 // clear calendar editor's folder |
|
225 RemoveTemporaryFilesL(); |
|
226 iAttachmentInfoIntialized = EFalse; |
|
227 } |
|
228 break; |
|
229 case ECalenNotifyEntryClosed: |
|
230 case ECalenNotifyMarkedEntryDeleted: |
|
231 case ECalenNotifyMultipleEntriesDeleted: |
|
232 //case ECalenNotifyDialogClosed: |
|
233 { |
|
234 if(!(iAddAttachmentFromViewer) && !(iAttachmentAlreadyExists)) |
|
235 { |
|
236 iAttachmentModel->Reset(); |
|
237 } |
|
238 iAttachmentAlreadyExists = EFalse; |
|
239 iAttachmentInfoIntialized = EFalse; |
|
240 } |
|
241 break; |
|
242 case ECalenNotifyAttachmentViewerClosed: |
|
243 { |
|
244 if(iAddAttachmentFromViewer) |
|
245 { |
|
246 |
|
247 |
|
248 // Do not reset the model if the attachment list has been opened from the editor. |
|
249 if(!iController.IsEditorActive()) |
|
250 { |
|
251 // add attachments to the entry being viewed in event viewer |
|
252 AddAttachmentsToEntryL(); |
|
253 // clear calendar editor's folder |
|
254 RemoveTemporaryFilesL(); |
|
255 |
|
256 iAttachmentModel->Reset(); |
|
257 } |
|
258 |
|
259 iAddAttachmentFromViewer = EFalse; |
|
260 |
|
261 // refresh the event view |
|
262 iController.ViewManager().StartActiveStepL(); |
|
263 } |
|
264 MCalenToolbar* toolbar = iController.Services().ToolbarOrNull(); |
|
265 if(toolbar) |
|
266 { |
|
267 if(iShowToolbar) |
|
268 { |
|
269 toolbar->SetToolbarVisibilityL(ETrue); |
|
270 } |
|
271 iShowToolbar = EFalse; |
|
272 } |
|
273 |
|
274 iAttachmentInfoIntialized = EFalse; |
|
275 iViewerActive = EFalse; |
|
276 } |
|
277 break; |
|
278 default: |
|
279 break; |
|
280 } |
|
281 |
|
282 TRACE_EXIT_POINT; |
|
283 } |
|
284 |
|
285 // ---------------------------------------------------------------------------- |
|
286 // CCalenAttachmentUi::HandleAddAttachmentL |
|
287 // Handles the command ECalenAddAttachment |
|
288 // ---------------------------------------------------------------------------- |
|
289 // |
|
290 void CCalenAttachmentUi::HandleAddAttachmentL() |
|
291 { |
|
292 TRACE_ENTRY_POINT; |
|
293 |
|
294 TInt selectedIndex(0); |
|
295 CAknListQueryDialog* dlg = new (ELeave) CAknListQueryDialog(&selectedIndex); |
|
296 dlg->PrepareLC( R_ATTACHMENT_LIST_QUERY ); |
|
297 |
|
298 if(dlg->RunLD()) |
|
299 { |
|
300 iSelectedCommand = selectedIndex; |
|
301 switch(selectedIndex) |
|
302 { |
|
303 case ECalenAddImage: |
|
304 { |
|
305 FetchFileL(CCalenAttachmentUtils::EImage); |
|
306 } |
|
307 break; |
|
308 case ECalenAddNote: |
|
309 { |
|
310 FetchFileL(CCalenAttachmentUtils::ENote); |
|
311 } |
|
312 break; |
|
313 case ECalenAddAudio: |
|
314 { |
|
315 FetchFileL(CCalenAttachmentUtils::EAudio); |
|
316 } |
|
317 break; |
|
318 case ECalenAddVideo: |
|
319 { |
|
320 FetchFileL(CCalenAttachmentUtils::EVideo); |
|
321 } |
|
322 break; |
|
323 case ECalenAddOtherFiles: |
|
324 { |
|
325 FetchFileL(CCalenAttachmentUtils::EUnknown); |
|
326 } |
|
327 break; |
|
328 default: |
|
329 break; |
|
330 } |
|
331 } |
|
332 else |
|
333 { |
|
334 iController.BroadcastNotification(ECalenNotifyDialogClosed); |
|
335 } |
|
336 TRACE_EXIT_POINT; |
|
337 } |
|
338 |
|
339 // ---------------------------------------------------------------------------- |
|
340 // CCalenAttachmentUi::FetchFileL |
|
341 // For fetching the file from other apps |
|
342 // ---------------------------------------------------------------------------- |
|
343 // |
|
344 TBool CCalenAttachmentUi::FetchFileL( |
|
345 CCalenAttachmentUtils::TCalenAttachmentFileType aFetchType) |
|
346 { |
|
347 TRACE_ENTRY_POINT; |
|
348 |
|
349 |
|
350 CDesCArrayFlat* files = new( ELeave ) CDesC16ArrayFlat(1); |
|
351 CleanupStack::PushL(files); |
|
352 |
|
353 TBool fetchOk(EFalse); |
|
354 if(aFetchType == CCalenAttachmentUtils::EUnknown) |
|
355 { |
|
356 TFileName fileName(KNullDesC); |
|
357 // used for fetching any file from the file system |
|
358 if(CCalenAttachmentUtils::FetchAnyFileL( fileName, this )) |
|
359 { |
|
360 fetchOk = ETrue; |
|
361 } |
|
362 } |
|
363 else |
|
364 { |
|
365 // used for fetching media file and notes |
|
366 fetchOk = CCalenAttachmentUtils::FetchFileL( aFetchType, *files, |
|
367 NULL, EFalse, EFalse, this ); |
|
368 |
|
369 |
|
370 if(fetchOk && iSelectedCommand == ECalenAddNote) |
|
371 { |
|
372 AddAttachmentL(files->MdcaPoint(0)); |
|
373 } |
|
374 } |
|
375 CleanupStack::PopAndDestroy( files ); |
|
376 |
|
377 if(!fetchOk) |
|
378 { |
|
379 iController.BroadcastNotification(ECalenNotifyDialogClosed); |
|
380 } |
|
381 |
|
382 TRACE_EXIT_POINT; |
|
383 return fetchOk; |
|
384 } |
|
385 |
|
386 // ---------------------------------------------------------------------------- |
|
387 // CCalenAttachmentUi::VerifySelectionL |
|
388 // Interface for verifying fetched media files selection |
|
389 // ---------------------------------------------------------------------------- |
|
390 // |
|
391 TBool CCalenAttachmentUi::VerifySelectionL(const MDesCArray* aSelectedFiles) |
|
392 { |
|
393 TRACE_ENTRY_POINT; |
|
394 |
|
395 TInt selectedFilesCount = aSelectedFiles->MdcaCount(); |
|
396 for(TInt index=0;index<selectedFilesCount;index++) |
|
397 { |
|
398 RFile file; |
|
399 CEikonEnv* eikonEnv = CEikonEnv::Static(); |
|
400 RFs& fs = eikonEnv->FsSession(); |
|
401 User::LeaveIfError(fs.ShareProtected()); |
|
402 TInt err = file.Open( fs, aSelectedFiles->MdcaPoint(index), EFileRead ); |
|
403 file.Close(); |
|
404 if( KErrNone != err ) |
|
405 { |
|
406 // if any error in opening file then return EFalse |
|
407 return EFalse; |
|
408 } |
|
409 AddAttachmentL(aSelectedFiles->MdcaPoint(index)); |
|
410 } |
|
411 |
|
412 TRACE_EXIT_POINT; |
|
413 |
|
414 return ETrue; |
|
415 } |
|
416 |
|
417 // ---------------------------------------------------------------------------- |
|
418 // CCalenAttachmentUi::OkToExitL |
|
419 // Get's called when user selects any file from file system through common |
|
420 // memory dialogs |
|
421 // ---------------------------------------------------------------------------- |
|
422 // |
|
423 TBool CCalenAttachmentUi::OkToExitL( const TDesC& aDriveAndPath, const TEntry& aEntry ) |
|
424 { |
|
425 TRACE_ENTRY_POINT; |
|
426 |
|
427 TInt length = aDriveAndPath.Length() + aEntry.iName.Length(); |
|
428 if(length) |
|
429 { |
|
430 HBufC* filename = HBufC::NewLC( length ); |
|
431 TPtr ptr = filename->Des(); |
|
432 ptr.Append( aDriveAndPath ); |
|
433 ptr.Append( aEntry.iName ); |
|
434 |
|
435 RFile file; |
|
436 CEikonEnv* eikonEnv = CEikonEnv::Static(); |
|
437 RFs& fs = eikonEnv->FsSession(); |
|
438 User::LeaveIfError(fs.ShareProtected()); |
|
439 TInt err = file.Open( fs, *filename, EFileRead ); |
|
440 file.Close(); |
|
441 if( KErrNone != err ) |
|
442 { |
|
443 // if any error in opening file then return EFalse |
|
444 CleanupStack::PopAndDestroy(filename); |
|
445 return EFalse; |
|
446 } |
|
447 |
|
448 AddAttachmentL(*filename); |
|
449 |
|
450 CleanupStack::PopAndDestroy(filename); |
|
451 } |
|
452 |
|
453 TRACE_EXIT_POINT; |
|
454 return ETrue; |
|
455 } |
|
456 |
|
457 // ---------------------------------------------------------------------------- |
|
458 // CCalenAttachmentUi::CheckForExistingAttachmentsL |
|
459 // check for already existing attachments from the entry |
|
460 // ---------------------------------------------------------------------------- |
|
461 // |
|
462 void CCalenAttachmentUi::CheckForExistingAttachmentsL() |
|
463 { |
|
464 TRACE_ENTRY_POINT; |
|
465 |
|
466 if( iAttachmentInfoIntialized ) |
|
467 return; |
|
468 |
|
469 MCalenContext& context = iController.Services().Context(); |
|
470 TCalLocalUid entryUid = context.InstanceId().iEntryLocalUid; |
|
471 |
|
472 if(entryUid) // If it is not for new entry |
|
473 { |
|
474 CCalEntry* entry = iController.Services().EntryViewL(context.InstanceId().iColId)->FetchL(entryUid); |
|
475 CleanupStack::PushL(entry); |
|
476 if(entry) |
|
477 { |
|
478 iAttachmentModel->CheckForExistingAttachmentsL(entry); |
|
479 iAttachmentInfoIntialized = ETrue; |
|
480 } |
|
481 CleanupStack::PopAndDestroy(entry); |
|
482 } |
|
483 TRACE_EXIT_POINT; |
|
484 } |
|
485 |
|
486 // ---------------------------------------------------------------------------- |
|
487 // CCalenAttachmentUi::NotifyChanges |
|
488 // Notify if attachment added or removed |
|
489 // ---------------------------------------------------------------------------- |
|
490 // |
|
491 void CCalenAttachmentUi::NotifyChanges( TCalenAttachmentCommand aCommand, |
|
492 TInt aAttachmentIndex ) |
|
493 { |
|
494 TRACE_ENTRY_POINT; |
|
495 |
|
496 if(iViewerActive) |
|
497 { |
|
498 iController.ViewManager().SetRepopulation(ETrue); |
|
499 } |
|
500 |
|
501 if(aCommand == ECalenAttachmentAdded) |
|
502 { |
|
503 iController.BroadcastNotification(ECalenNotifyAttachmentAdded); |
|
504 } |
|
505 else if(aCommand == ECalenAttachmentRemoved) |
|
506 { |
|
507 TRAP_IGNORE(RemoveAttachmentFromEntryL(aAttachmentIndex)); |
|
508 iController.BroadcastNotification(ECalenNotifyAttachmentRemoved); |
|
509 } |
|
510 |
|
511 TRACE_ENTRY_POINT; |
|
512 } |
|
513 |
|
514 // ---------------------------------------------------------------------------- |
|
515 // CCalenAttachmentUi::GetAttachmentFileL |
|
516 // Notify if attachment added or removed |
|
517 // ---------------------------------------------------------------------------- |
|
518 // |
|
519 RFile CCalenAttachmentUi::GetAttachmentFileL(TInt aIndex) |
|
520 { |
|
521 TRACE_ENTRY_POINT; |
|
522 |
|
523 MCalenContext& context = iController.Services().Context(); |
|
524 TCalLocalUid entryUid = context.InstanceId().iEntryLocalUid; |
|
525 RFile fileHandle; |
|
526 CCalEntry* entry = iController.Services().EntryViewL(context.InstanceId().iColId)->FetchL(entryUid); |
|
527 CleanupStack::PushL(entry); |
|
528 if(entry) |
|
529 { |
|
530 TInt attachmentCount = entry->AttachmentCountL(); |
|
531 if(attachmentCount) |
|
532 { |
|
533 CCalAttachment* attachment = entry->AttachmentL(aIndex); |
|
534 if(attachment->FileAttachment()) |
|
535 { |
|
536 attachment->FileAttachment()->LoadBinaryDataL(); |
|
537 CleanupClosePushL(fileHandle); |
|
538 attachment->FileAttachment()->FetchFileHandleL(fileHandle); |
|
539 CleanupStack::Pop(&fileHandle); |
|
540 } |
|
541 } |
|
542 } |
|
543 |
|
544 CleanupStack::PopAndDestroy(entry); |
|
545 |
|
546 TRACE_EXIT_POINT; |
|
547 return fileHandle; |
|
548 } |
|
549 |
|
550 // ---------------------------------------------------------------------------- |
|
551 // CCalenAttachmentUi::AddAttachmentL |
|
552 // Adds attachments to the model |
|
553 // ---------------------------------------------------------------------------- |
|
554 // |
|
555 void CCalenAttachmentUi::AddAttachmentL(const TDesC& aSourceFilePath) |
|
556 { |
|
557 TRACE_ENTRY_POINT; |
|
558 |
|
559 TParsePtrC fileNameParser(aSourceFilePath); |
|
560 TPtrC parsedFileName = fileNameParser.NameAndExt(); |
|
561 TBool drmProtected; |
|
562 |
|
563 if(!iAttachmentModel->NumberOfItems()) |
|
564 { |
|
565 CheckForExistingAttachmentsL(); |
|
566 } |
|
567 |
|
568 TBool isAlreadyExists = IsDuplicateNameL(parsedFileName); |
|
569 CheckDRMStatusL(aSourceFilePath,drmProtected); |
|
570 |
|
571 if(drmProtected || isAlreadyExists) |
|
572 { |
|
573 iAttachmentAlreadyExists = ETrue; |
|
574 iController.BroadcastNotification(ECalenNotifyDialogClosed); |
|
575 return; |
|
576 } |
|
577 |
|
578 TFileName destinationfileName; |
|
579 CopyFetchedFilesL( destinationfileName, aSourceFilePath ); |
|
580 iAttachmentModel->AddAttachmentL(destinationfileName, destinationfileName); |
|
581 |
|
582 TRACE_EXIT_POINT; |
|
583 } |
|
584 |
|
585 // ---------------------------------------------------------------------------- |
|
586 // CCalenAttachmentUi::RemoveAttachmentFromEntryL |
|
587 // Remove attachments from the entry |
|
588 // ---------------------------------------------------------------------------- |
|
589 // |
|
590 void CCalenAttachmentUi::RemoveAttachmentFromEntryL(TInt aAttachmentIndex) |
|
591 { |
|
592 TRACE_ENTRY_POINT; |
|
593 |
|
594 // If user is deleting it from editors, then dont save it now as there is a chance that user discards these |
|
595 // changes. If user saves it, then editors will save these newly deleted attachments. |
|
596 if(iController.IsEditorActive()) |
|
597 { |
|
598 return; |
|
599 } |
|
600 |
|
601 MCalenContext& context = iController.Services().Context(); |
|
602 TCalLocalUid entryUid = context.InstanceId().iEntryLocalUid; |
|
603 |
|
604 CCalEntry* entry = iController.Services().EntryViewL(context.InstanceId().iColId)->FetchL(entryUid); |
|
605 CleanupStack::PushL(entry); |
|
606 if(entry) |
|
607 { |
|
608 if(entry->AttachmentCountL()) |
|
609 { |
|
610 CCalAttachment* attachment = entry->AttachmentL(aAttachmentIndex); |
|
611 if(attachment) |
|
612 { |
|
613 entry->DeleteAttachmentL(*attachment); |
|
614 |
|
615 CCalEntryView* entryView = iController.Services().EntryViewL(context.InstanceId().iColId); |
|
616 CCalenInterimUtils2::StoreL( *entryView, *entry, ETrue ); |
|
617 } |
|
618 } |
|
619 } |
|
620 CleanupStack::PopAndDestroy(entry); |
|
621 |
|
622 TRACE_EXIT_POINT; |
|
623 } |
|
624 |
|
625 // ---------------------------------------------------------------------------- |
|
626 // CCalenAttachmentUi::AddAttachmentsToEntryL |
|
627 // Adds attachments to the entry from event view |
|
628 // ---------------------------------------------------------------------------- |
|
629 // |
|
630 void CCalenAttachmentUi::AddAttachmentsToEntryL() |
|
631 { |
|
632 TRACE_ENTRY_POINT; |
|
633 |
|
634 TInt attachmentCount = iAttachmentModel->NumberOfItems(); |
|
635 if(attachmentCount) |
|
636 { |
|
637 MCalenContext& context = iController.Services().Context(); |
|
638 TCalLocalUid entryUid = context.InstanceId().iEntryLocalUid; |
|
639 |
|
640 CCalEntry* entry = iController.Services().EntryViewL(context.InstanceId().iColId)->FetchL(entryUid); |
|
641 CleanupStack::PushL(entry); |
|
642 |
|
643 if(entry) |
|
644 { |
|
645 RPointerArray<CCalenAttachmentInfo> attachmentInfoList; |
|
646 |
|
647 iAttachmentModel->GetAttachmentListL(attachmentInfoList); |
|
648 for(TInt index=0;index<attachmentCount;index++) |
|
649 { |
|
650 CCalenAttachmentInfo* attachmentInfo = attachmentInfoList[index]; |
|
651 // check if attachmentinfo created for new attachment,to avoid adding |
|
652 // the attachments which already exists in the entry |
|
653 if(attachmentInfo->StoreType() == CCalenAttachmentInfo::ECalenNewAttachment) |
|
654 { |
|
655 TParsePtrC fileNameParser(attachmentInfo->SystemFileName()); |
|
656 RFile fileHandle = iAttachmentModel->GetAttachmentFileL(index); |
|
657 CleanupClosePushL(fileHandle); |
|
658 TInt aSize; |
|
659 TInt error = fileHandle.Size(aSize); |
|
660 HBufC8* data = HBufC8::NewLC(aSize); |
|
661 TPtr8 fileData = data->Des(); |
|
662 if (error == KErrNone) |
|
663 { |
|
664 TInt readingError = fileHandle.Read(fileData,aSize); |
|
665 if(readingError == KErrNone) |
|
666 { |
|
667 CCalAttachment* attachment = CCalAttachment::NewFileL(data); |
|
668 CleanupStack::Pop(data); |
|
669 CleanupStack::PushL(attachment); |
|
670 |
|
671 // sets the label for the attachment |
|
672 attachment->SetLabelL(fileNameParser.NameAndExt()); |
|
673 // sets mime type for the attachment |
|
674 attachment->SetMimeTypeL(attachmentInfo->DataType().Des8()); |
|
675 entry->AddAttachmentL(*attachment); |
|
676 CleanupStack::Pop(attachment); |
|
677 } |
|
678 else |
|
679 { |
|
680 CleanupStack::PopAndDestroy(data); |
|
681 } |
|
682 } |
|
683 else |
|
684 { |
|
685 CleanupStack::PopAndDestroy(data); |
|
686 } |
|
687 CleanupStack::PopAndDestroy(&fileHandle); |
|
688 } |
|
689 } |
|
690 |
|
691 attachmentInfoList.Close(); |
|
692 |
|
693 if(!iController.IsEditorActive()) |
|
694 { |
|
695 CCalEntryView* entryView = iController.Services().EntryViewL(context.InstanceId().iColId); |
|
696 CCalenInterimUtils2::StoreL( *entryView, *entry, ETrue ); |
|
697 } |
|
698 } |
|
699 CleanupStack::PopAndDestroy(entry); |
|
700 } |
|
701 TRACE_EXIT_POINT; |
|
702 } |
|
703 |
|
704 // ---------------------------------------------------------------------------- |
|
705 // CCalenAttachmentUi::CopyFetchedFilesL |
|
706 // Copy fetched files in to temporary dir,adding the attachment to the entry |
|
707 // will move the file from temporary to symbian calendar db |
|
708 // ---------------------------------------------------------------------------- |
|
709 // |
|
710 void CCalenAttachmentUi::CopyFetchedFilesL( TFileName& aTempPath, |
|
711 const TDesC& aSourceFilePath) |
|
712 { |
|
713 TRACE_ENTRY_POINT; |
|
714 |
|
715 TParsePtrC fileNameParser(aSourceFilePath); |
|
716 TFileName destinationfilePath; |
|
717 const TDesC& destinatiofileName = fileNameParser.NameAndExt(); |
|
718 CCalenAttachmentUtils::GetCalenEditorTempPath( destinationfilePath, |
|
719 &destinatiofileName ); |
|
720 aTempPath.Append(destinationfilePath); |
|
721 |
|
722 CFileMan* fileManager = CFileMan::NewL(CEikonEnv::Static()->FsSession()); |
|
723 CleanupStack::PushL(fileManager); |
|
724 fileManager->Copy( aSourceFilePath, destinationfilePath, CFileMan::ERecurse ); |
|
725 CleanupStack::PopAndDestroy(fileManager); |
|
726 |
|
727 TRACE_EXIT_POINT; |
|
728 } |
|
729 |
|
730 // ------------------------------------------------------------------------------ |
|
731 // void CCalenAttachmentUi::DoAttachmentL() |
|
732 // Opens an attachment dialog. |
|
733 // ------------------------------------------------------------------------------ |
|
734 // |
|
735 void CCalenAttachmentUi::DoAttachmentL() |
|
736 { |
|
737 TRACE_ENTRY_POINT; |
|
738 |
|
739 CheckForExistingAttachmentsL(); |
|
740 //Check if iTitle allready exists |
|
741 if(!iTitle) |
|
742 { |
|
743 iTitle = CCoeEnv::Static()->AllocReadResourceLC( |
|
744 R_VIEWER_TITLE_ATTACHMENTS); |
|
745 |
|
746 CleanupStack::Pop(iTitle); |
|
747 } |
|
748 |
|
749 CCalenAttachmentModel* attmodel = iAttachmentModel; |
|
750 |
|
751 iAttachmentdlg = CCalenViewAttachmentsDialog::NewL(*iTitle,*attmodel,iController ); |
|
752 |
|
753 // Hide the toolbar before we display settings menu |
|
754 MCalenToolbar* toolbar = iController.Services().ToolbarOrNull(); |
|
755 |
|
756 if(toolbar&&toolbar->IsVisible()&& !iController.IsEditorActive()) |
|
757 { |
|
758 toolbar->SetToolbarVisibilityL(EFalse); |
|
759 iShowToolbar = ETrue; |
|
760 } |
|
761 //To make sure we are viewer, so for delete attachment, notification will be issued |
|
762 // only when viewer is closed (EFalse) |
|
763 iViewerActive = ETrue; |
|
764 |
|
765 // safe to call LD even as a member variable, since sets itself to NULL when deleting |
|
766 iAttachmentdlg->ExecuteLD(R_CALEN_ATTACHMENT_DIALOG); // CSI: 50 # see comment above |
|
767 |
|
768 |
|
769 if(iAttachmentLoadingOn) |
|
770 { |
|
771 ShowWaitNoteL( ETrue ); |
|
772 if ( iWaitDialog ) |
|
773 { |
|
774 iWaitDialog->SetCallback( this ); |
|
775 } |
|
776 } |
|
777 else |
|
778 { |
|
779 //Update attachment models fetched-flags |
|
780 //if we are not currently loading attachments. |
|
781 if(iAttachmentdlg) |
|
782 { |
|
783 iAttachmentdlg->UpdateAttachmentsFetchFlags(); |
|
784 } |
|
785 |
|
786 } |
|
787 |
|
788 // Dialer is always enabled in attachment dialog |
|
789 // SetDialerEnabled( ETrue ); |
|
790 TRACE_EXIT_POINT; |
|
791 } |
|
792 |
|
793 // ------------------------------------------------------------------------------ |
|
794 // CCalenAttachmentUi::ShowWaitNoteL() |
|
795 // Shows wait note |
|
796 // ------------------------------------------------------------------------------ |
|
797 // |
|
798 void CCalenAttachmentUi::ShowWaitNoteL( TBool aCanCancel ) |
|
799 { |
|
800 TRACE_ENTRY_POINT; |
|
801 |
|
802 if (!iWaitDialog) |
|
803 { |
|
804 // safe to call LD even as a member variable, |
|
805 // since sets itself to NULL when deleting |
|
806 iWaitDialog = new(ELeave)CAknWaitDialog( |
|
807 (reinterpret_cast<CEikDialog**>( &iWaitDialog )), ETrue); |
|
808 |
|
809 // safe to call LD even as a member variable, since sets itself to NULL when deleting |
|
810 iWaitDialog->ExecuteLD(R_VIEWER_WAIT_OPEN_DIALOG_NOTE); // CSI: 50 # see comment above |
|
811 iWaitDialog->MakePanelButtonVisible( EAknSoftkeyCancel, aCanCancel ); |
|
812 } |
|
813 TRACE_EXIT_POINT; |
|
814 } |
|
815 |
|
816 // ------------------------------------------------------------------------------ |
|
817 // From MProgressDialogCallback called when wait note dismissed |
|
818 // called when dialog is dismissed |
|
819 // ------------------------------------------------------------------------------ |
|
820 // |
|
821 void CCalenAttachmentUi::DialogDismissedL( TInt aButtonId ) |
|
822 { |
|
823 TRACE_ENTRY_POINT; |
|
824 |
|
825 if ( aButtonId == EAknSoftkeyCancel ) |
|
826 { |
|
827 delete iAttachmentdlg; |
|
828 iAttachmentdlg = NULL; |
|
829 iWaitDialog = NULL; |
|
830 } |
|
831 TRACE_EXIT_POINT; |
|
832 } |
|
833 |
|
834 // ----------------------------------------------------------------------------- |
|
835 // CCalenAttachmentUi::CheckDRMStatus() |
|
836 // ----------------------------------------------------------------------------- |
|
837 // |
|
838 void CCalenAttachmentUi::CheckDRMStatusL( const TDesC& aFileName,TBool& aProtection ) |
|
839 { |
|
840 TRACE_ENTRY_POINT; |
|
841 |
|
842 RFile file; |
|
843 file.Close(); |
|
844 RFs& fs = CEikonEnv::Static()->FsSession(); |
|
845 TInt err1 = file.Open( fs, aFileName, EFileRead | EFileShareReadersOnly ); |
|
846 CleanupClosePushL( file ); |
|
847 |
|
848 CContent* content = CContent::NewLC(file); |
|
849 TInt isDRMProtected = 0; |
|
850 |
|
851 //Check if file is drm protected. If not no need for further checks. |
|
852 User::LeaveIfError(content->GetAttribute(EIsProtected, isDRMProtected)); |
|
853 if (isDRMProtected) |
|
854 { |
|
855 aProtection = ETrue; |
|
856 |
|
857 //DRM protected file: can't attach the DRM protected file |
|
858 HBufC* cannotAttach = StringLoader::LoadLC( |
|
859 R_QTN_CALEN_INFO_CANNOT_OPEN, CCoeEnv::Static() ); |
|
860 CAknInformationNote* note = new ( ELeave ) CAknInformationNote(ETrue); |
|
861 note->ExecuteLD( *cannotAttach ); |
|
862 CleanupStack::PopAndDestroy( cannotAttach ); |
|
863 } |
|
864 else |
|
865 { |
|
866 aProtection = EFalse; |
|
867 } |
|
868 CleanupStack::PopAndDestroy(content); |
|
869 CleanupStack::PopAndDestroy(&file); |
|
870 |
|
871 TRACE_EXIT_POINT; |
|
872 } |
|
873 |
|
874 // ----------------------------------------------------------------------------- |
|
875 // CCalenAttachmentUi::IsDuplicateNameL() |
|
876 // Compares the name of the already attached and currently |
|
877 // attached attachment names. |
|
878 // returns ETrue if match is found, EFalse otherwise. |
|
879 // ----------------------------------------------------------------------------- |
|
880 // |
|
881 TBool CCalenAttachmentUi::IsDuplicateNameL(const TDesC& aSelectedFile) |
|
882 { |
|
883 TRACE_ENTRY_POINT; |
|
884 |
|
885 TInt attachmentCount = iAttachmentModel->NumberOfItems(); |
|
886 TBool matchNotFound(ETrue); |
|
887 if(attachmentCount>0) |
|
888 { |
|
889 RPointerArray<CCalenAttachmentInfo> attachmentInfoList; |
|
890 iAttachmentModel->GetAttachmentListL(attachmentInfoList); |
|
891 |
|
892 TParsePtrC fileNameParser(aSelectedFile); |
|
893 TPtrC parsedFileName = fileNameParser.Ext(); |
|
894 for(TInt index=0; index<attachmentCount && matchNotFound; index++) |
|
895 { |
|
896 TParsePtrC fileNameParser(attachmentInfoList[index]->FileName()); |
|
897 TPtrC parsedFileName = fileNameParser.NameAndExt(); |
|
898 matchNotFound = aSelectedFile.Compare(parsedFileName); |
|
899 } |
|
900 attachmentInfoList.Close(); |
|
901 } |
|
902 |
|
903 if(!matchNotFound) |
|
904 { |
|
905 //though attachment is aleady attached to this entry, show the info note for this info. |
|
906 CAknInformationNote* note = new ( ELeave ) CAknInformationNote(ETrue); |
|
907 HBufC* cannotAttach = StringLoader::LoadLC( |
|
908 R_QTN_CALEN_INFO_ALREADY_ATTACHED, CCoeEnv::Static() ); |
|
909 note->ExecuteLD( *cannotAttach ); |
|
910 CleanupStack::PopAndDestroy( cannotAttach ); |
|
911 } |
|
912 |
|
913 |
|
914 TRACE_EXIT_POINT; |
|
915 return !matchNotFound; |
|
916 } |
|
917 |
|
918 // ----------------------------------------------------------------------------- |
|
919 // CCalenAttachmentUi::CompareContentOfTextFiles() |
|
920 // Compares the binary data of already attached and currently selected text file. |
|
921 // ----------------------------------------------------------------------------- |
|
922 // |
|
923 TBool CCalenAttachmentUi::CompareContentOfTextFilesL( const TDesC& aSelectedFile, |
|
924 const TDesC& aAlreadyAttachedFile) |
|
925 { |
|
926 TRACE_ENTRY_POINT; |
|
927 |
|
928 TBool matchFound(EFalse); |
|
929 //get the binary data of both the files and compare. |
|
930 RFile fileHandle; |
|
931 CEikonEnv* eikonEnv = CEikonEnv::Static(); |
|
932 RFs& fs = eikonEnv->FsSession(); |
|
933 User::LeaveIfError(fs.ShareProtected()); |
|
934 |
|
935 //for newly selected file |
|
936 TInt aSelectedFileSize; |
|
937 TInt openErrForSelectedFile = fileHandle.Open(fs, aSelectedFile, EFileWrite); |
|
938 if( KErrNone != openErrForSelectedFile ) |
|
939 { |
|
940 //Not Handling the Error case as of now. |
|
941 } |
|
942 |
|
943 TInt sizeErrorForSelectedFile = fileHandle.Size(aSelectedFileSize); |
|
944 HBufC8* aNewlySelectedFile = HBufC8::NewLC(aSelectedFileSize); |
|
945 TPtr8 aSelectedFileData = aNewlySelectedFile->Des(); |
|
946 |
|
947 // create one more file handle, because for |
|
948 // the same file its coming as "Already in use". |
|
949 RFile fileHandleForAlreadySelected; |
|
950 |
|
951 // for already selected file |
|
952 TInt aAlreadySelectedFileSize; |
|
953 TInt openErrorForAlreadyAttachedFile = |
|
954 fileHandleForAlreadySelected.Open(fs, aAlreadyAttachedFile, EFileWrite); |
|
955 |
|
956 if( KErrNone != openErrorForAlreadyAttachedFile ) |
|
957 { |
|
958 fileHandleForAlreadySelected.Close(); |
|
959 openErrorForAlreadyAttachedFile = |
|
960 fileHandleForAlreadySelected.Open(fs, aAlreadyAttachedFile, EFileWrite); |
|
961 } |
|
962 |
|
963 TInt sizeErrorForAlreadyAttachedFile = |
|
964 fileHandleForAlreadySelected.Size(aAlreadySelectedFileSize); |
|
965 HBufC8* aAttachedFile = HBufC8::NewLC(aAlreadySelectedFileSize); |
|
966 TPtr8 aAttachedFileData = aAttachedFile->Des(); |
|
967 |
|
968 if(!(aAttachedFileData.Compare(aSelectedFileData))) |
|
969 { |
|
970 matchFound=ETrue; |
|
971 } |
|
972 |
|
973 CleanupStack::Pop(2); |
|
974 CleanupClosePushL(fileHandle); |
|
975 CleanupStack::PopAndDestroy(&fileHandle); |
|
976 |
|
977 TRACE_EXIT_POINT; |
|
978 return matchFound; |
|
979 } |
|
980 |
|
981 // ----------------------------------------------------------------------------- |
|
982 // CCalenAttachmentUi::RemoveTemporaryFiles() |
|
983 // removes the temporary files, those we have added to temp path. |
|
984 // ----------------------------------------------------------------------------- |
|
985 // |
|
986 void CCalenAttachmentUi::RemoveTemporaryFilesL() |
|
987 { |
|
988 TRACE_ENTRY_POINT; |
|
989 |
|
990 CEikonEnv* eikonEnv = CEikonEnv::Static(); |
|
991 CFileMan* fileMan = CFileMan::NewL( eikonEnv->FsSession() ); |
|
992 CleanupStack::PushL( fileMan ); |
|
993 |
|
994 // delete files from temp directory. |
|
995 TFileName temppath; |
|
996 CCalenAttachmentUtils::GetCalenEditorTempPath( temppath ); |
|
997 fileMan->Delete( temppath ); |
|
998 CleanupStack::PopAndDestroy( fileMan ); |
|
999 |
|
1000 TRACE_EXIT_POINT; |
|
1001 } |
|
1002 // end of file |