|
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 FILES ================================ |
|
19 |
|
20 #include <eikspane.h> |
|
21 #include <eikmenup.h> |
|
22 #include <AknDef.h> |
|
23 #include <aknappui.h> |
|
24 #include <akntitle.h> |
|
25 #include <aknnavi.h> |
|
26 #include <aknlists.h> |
|
27 #include <gulicon.h> |
|
28 #include <coeutils.h> // for ConeUtils::FileExists |
|
29 #include <bautils.h> |
|
30 #include <aknnotewrappers.h> |
|
31 #include <AknWaitDialog.h> // CAknWaitDialog |
|
32 #include <DocumentHandler.h> |
|
33 #include <StringLoader.h> // StringLoader |
|
34 #include <AiwCommon.h> |
|
35 #include <NpdApi.h> |
|
36 #include <avkon.hrh> |
|
37 #include <aknlayout.cdl.h> |
|
38 #include <aknlayoutscalable_avkon.cdl.h> |
|
39 #include <AknUtils.h> |
|
40 #include <AknsUtils.h> // skinned icons |
|
41 #include <AknsConstants.h> // skinned icon ids |
|
42 #include <barsread.h> |
|
43 #include <calendar.mbg> |
|
44 #include <Calendar.rsg> |
|
45 #include <StringLoader.h> |
|
46 #include <AknsBasicBackgroundControlContext.h> |
|
47 #include <calencommonui.rsg> |
|
48 #include <aknlistloadertfx.h> |
|
49 #include <aknlistboxtfxinternal.h> |
|
50 #include <hlplch.h> |
|
51 #include <csxhelp/mail.hlp.hrh> |
|
52 #include <featmgr.h> |
|
53 #include <sysutil.h> |
|
54 #include <ErrorUI.h> |
|
55 #include <calentoolbar.h> |
|
56 |
|
57 #include "calenviewattachmentsdialog.h" |
|
58 #include "calencontroller.h" |
|
59 #include "calenattachmentinfo.h" |
|
60 #include "calenattachmentmodel.h" |
|
61 #include "calenattachmentutils.h" |
|
62 #include "calendarui_debug.h" |
|
63 #include "calendar.hrh" |
|
64 #include "calenmultidbeditor.h" |
|
65 #include "CalendarPrivateCRKeys.h" |
|
66 #include "calendarui_debug.h" |
|
67 #include "calenattachmentutils.h" |
|
68 |
|
69 //CONSTANTS |
|
70 |
|
71 const TInt KMSKControlID(3); |
|
72 _LIT8( KNotePadTextDataType, "text/plain" ); |
|
73 |
|
74 // ========================= MEMBER FUNCTIONS ================================ |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // CCalenAttachmentSelectionObserver::NewL |
|
78 // 1st phase of construction |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 CCalenViewAttachmentsDialog* CCalenViewAttachmentsDialog::NewL(TDesC& aTitle, |
|
82 CCalenAttachmentModel& aAttachmentModel, |
|
83 CCalenController& aController) |
|
84 { |
|
85 TRACE_ENTRY_POINT; |
|
86 |
|
87 CCalenViewAttachmentsDialog* self = new (ELeave) CCalenViewAttachmentsDialog(aTitle, |
|
88 aAttachmentModel, |
|
89 aController); |
|
90 CleanupStack::PushL(self); |
|
91 self->ConstructL(); |
|
92 CleanupStack::Pop(self); |
|
93 |
|
94 TRACE_EXIT_POINT; |
|
95 return self; |
|
96 } |
|
97 |
|
98 // ---------------------------------------------------------------------------- |
|
99 // CCalenViewAttachmentsDialog::CCalenViewAttachmentsDialog |
|
100 // Constructor. |
|
101 // (other items were commented in a header). |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 CCalenViewAttachmentsDialog::CCalenViewAttachmentsDialog(TDesC& aTitle, |
|
105 CCalenAttachmentModel& aAttachmentModel,CCalenController& aController ) |
|
106 : iAttachmentModel( aAttachmentModel ), |
|
107 iController(aController), |
|
108 iNewTitle( aTitle ) |
|
109 { |
|
110 TRACE_ENTRY_POINT; |
|
111 TRACE_EXIT_POINT; |
|
112 } |
|
113 |
|
114 // ---------------------------------------------------------------------------- |
|
115 // CCalenViewAttachmentsDialog::~CCalenViewAttachmentsDialog |
|
116 // Destructor. |
|
117 // (other items were commented in a header). |
|
118 // ---------------------------------------------------------------------------- |
|
119 // |
|
120 CCalenViewAttachmentsDialog::~CCalenViewAttachmentsDialog() |
|
121 { |
|
122 TRACE_ENTRY_POINT; |
|
123 |
|
124 delete iOldTitle; |
|
125 |
|
126 // because it's not possible to set externally owned icon array |
|
127 // for listbox, we delete our icon array here and set listbox |
|
128 // icon array to NULL. |
|
129 delete iIconArray; |
|
130 if ( iListBox ) |
|
131 { |
|
132 TRAP_IGNORE( iListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL( NULL ) ); |
|
133 } |
|
134 |
|
135 delete iListItems; |
|
136 delete iDocHandler; |
|
137 |
|
138 // remove empty navi pane. |
|
139 if ( iNaviPane ) |
|
140 { |
|
141 iNaviPane->Pop(); |
|
142 } |
|
143 delete iOpenParamList; |
|
144 |
|
145 iController.CancelNotifications( this ); |
|
146 |
|
147 TRACE_EXIT_POINT; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CCalenViewAttachmentsDialog::ConstructL |
|
152 // 2nd phase constructor. |
|
153 // (other items were commented in a header). |
|
154 // ---------------------------------------------------------------------------- |
|
155 // |
|
156 void CCalenViewAttachmentsDialog::ConstructL() |
|
157 { |
|
158 TRACE_ENTRY_POINT; |
|
159 |
|
160 DoConstructL(); |
|
161 |
|
162 TRACE_EXIT_POINT; |
|
163 } |
|
164 |
|
165 // ---------------------------------------------------------------------------- |
|
166 // CCalenViewAttachmentsDialog::DoConstructL |
|
167 // (other items were commented in a header). |
|
168 // ---------------------------------------------------------------------------- |
|
169 // |
|
170 void CCalenViewAttachmentsDialog::DoConstructL() |
|
171 { |
|
172 TRACE_ENTRY_POINT; |
|
173 |
|
174 CAknDialog::ConstructL( R_CALENDAR_ATTACHMENT_MENUBAR ); |
|
175 |
|
176 iDocHandler = CDocumentHandler::NewL( iEikonEnv->Process() ); |
|
177 |
|
178 // replace navi pane with empty one. |
|
179 iNaviPane = static_cast<CAknNavigationControlContainer*> |
|
180 ( iEikonEnv->AppUiFactory()->StatusPane()->ControlL( |
|
181 TUid::Uid( EEikStatusPaneUidNavi ) ) ); |
|
182 |
|
183 // CAknNavigationControlContainer internal array of decorators seem to |
|
184 // have big enough granularity that it does not need realloc |
|
185 // and therefore PushDefaultL does not leave. |
|
186 iNaviPane->PushDefaultL(); |
|
187 |
|
188 iDocHandler->SetExitObserver( this ); |
|
189 |
|
190 iController.RegisterForNotificationsL( this, ECalenNotifyAttachmentAdded ); |
|
191 |
|
192 TRACE_EXIT_POINT; |
|
193 } |
|
194 |
|
195 // ---------------------------------------------------------------------------- |
|
196 // CCalenViewAttachmentsDialog::CurrentListItemIndex |
|
197 // returns current item index. |
|
198 // (other items were commented in a header). |
|
199 // ---------------------------------------------------------------------------- |
|
200 // |
|
201 TInt CCalenViewAttachmentsDialog::CurrentListItemIndex() |
|
202 { |
|
203 TRACE_ENTRY_POINT; |
|
204 TRACE_EXIT_POINT; |
|
205 return iListBox->CurrentItemIndex(); |
|
206 } |
|
207 |
|
208 // ---------------------------------------------------------------------------- |
|
209 // CCalenViewAttachmentsDialog::UpdateIcon |
|
210 // (other items were commented in a header). |
|
211 // ---------------------------------------------------------------------------- |
|
212 // |
|
213 void CCalenViewAttachmentsDialog::UpdateIcon( TInt aListIndex ) |
|
214 { |
|
215 TRACE_ENTRY_POINT; |
|
216 |
|
217 iListBox->DrawItem( aListIndex ); |
|
218 |
|
219 TRACE_EXIT_POINT; |
|
220 } |
|
221 |
|
222 // ---------------------------------------------------------------------------- |
|
223 // CCalenViewAttachmentsDialog::ProcessCommandL |
|
224 // (other items were commented in a header). |
|
225 // ---------------------------------------------------------------------------- |
|
226 // |
|
227 void CCalenViewAttachmentsDialog::ProcessCommandL( TInt aCommandId ) |
|
228 { |
|
229 TRACE_ENTRY_POINT; |
|
230 |
|
231 HideMenu(); |
|
232 |
|
233 TFileName filename; |
|
234 TInt index = iListBox->CurrentItemIndex(); |
|
235 |
|
236 switch ( aCommandId ) |
|
237 { |
|
238 case ECalenViewAttachmentCmdOpen: |
|
239 { |
|
240 if ( CheckSpaceBelowCriticalLevelL() ) |
|
241 { |
|
242 TRACE_EXIT_POINT; |
|
243 |
|
244 return; |
|
245 } |
|
246 else if(index!=KErrNotFound) |
|
247 { |
|
248 //get the attachmentinfo for the current index |
|
249 CCalenAttachmentInfo& attInfo = |
|
250 iAttachmentModel.AttachmentInfoAt( index ); |
|
251 |
|
252 TDataType datatype( attInfo.DataType() ); |
|
253 RFile file = iAttachmentModel.GetAttachmentFileL( index ); |
|
254 OpenAttachmentViewerL(file, *this); |
|
255 } |
|
256 } |
|
257 break; |
|
258 |
|
259 case ECalenViewAttachmentCmdSave: |
|
260 { |
|
261 if ( CheckSpaceBelowCriticalLevelL() ) |
|
262 { |
|
263 TRACE_EXIT_POINT; |
|
264 return; |
|
265 } |
|
266 //get the attachmentinfo for the current index |
|
267 CCalenAttachmentInfo& attInfo = |
|
268 iAttachmentModel.AttachmentInfoAt( index ); |
|
269 |
|
270 TDataType datatype( attInfo.DataType() ); |
|
271 RFile file = iAttachmentModel.GetAttachmentFileL( index ); |
|
272 CleanupClosePushL(file); |
|
273 CCalenAttachmentUtils::SaveAttachmentL(file, *this); |
|
274 CleanupStack::PopAndDestroy(&file); |
|
275 } |
|
276 break; |
|
277 |
|
278 case ECalenViewAttachmentCmdRemove: |
|
279 { |
|
280 if ( index != KErrNotFound ) |
|
281 { |
|
282 //modify the model |
|
283 if(RemoveAttachmentL(index)) |
|
284 { |
|
285 //update the ui |
|
286 ItemRemovedL( index ); |
|
287 } |
|
288 } |
|
289 break; |
|
290 } |
|
291 case ECalenViewAttachmentAdd: |
|
292 { |
|
293 //issue this command and it will be handled by attachmentui. |
|
294 iController.Services().IssueCommandL(ECalenAddAttachmentFromViewer); |
|
295 |
|
296 } |
|
297 break; |
|
298 case ECalenViewerCmdAttachmentCmdExit: |
|
299 TryExitL(EAknSoftkeyOk); |
|
300 break; |
|
301 case EAknCmdHelp: |
|
302 // Launch help |
|
303 HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), |
|
304 iEikonEnv->EikAppUi()->AppHelpContextL() ); |
|
305 break; |
|
306 case EAknCmdExit: |
|
307 case EEikCmdExit: |
|
308 { |
|
309 static_cast<MEikCommandObserver*>( iEikonEnv->EikAppUi() ) |
|
310 ->ProcessCommandL( EAknCmdExit ); |
|
311 break; |
|
312 } |
|
313 default: |
|
314 { |
|
315 break; |
|
316 } |
|
317 } |
|
318 TRACE_EXIT_POINT; |
|
319 } |
|
320 |
|
321 // ---------------------------------------------------------------------------- |
|
322 // CCalenViewAttachmentsDialog::DynInitMenuPaneL |
|
323 // (other items were commented in a header). |
|
324 // ---------------------------------------------------------------------------- |
|
325 // |
|
326 void CCalenViewAttachmentsDialog::DynInitMenuPaneL( |
|
327 TInt aMenuId, CEikMenuPane* aMenuPane ) |
|
328 { |
|
329 TRACE_ENTRY_POINT; |
|
330 |
|
331 switch(aMenuId) |
|
332 { |
|
333 case R_CALENDAR_ATTACHMENT_MENUPANE: |
|
334 { |
|
335 const TInt index(CurrentListItemIndex()); |
|
336 // this shouldn't happen... |
|
337 if (index == KErrNotFound) |
|
338 { |
|
339 return; |
|
340 } |
|
341 |
|
342 if(!(iAttachmentModel.NumberOfItems())) |
|
343 { |
|
344 //remove the options open and remove if count is 0. |
|
345 |
|
346 aMenuPane->SetItemDimmed(ECalenViewAttachmentCmdOpen,ETrue); |
|
347 aMenuPane->SetItemDimmed(ECalenViewAttachmentCmdSave,ETrue); |
|
348 aMenuPane->SetItemDimmed(ECalenViewAttachmentCmdRemove,ETrue); |
|
349 } |
|
350 else |
|
351 { |
|
352 aMenuPane->SetItemDimmed(ECalenViewAttachmentCmdOpen,EFalse); |
|
353 aMenuPane->SetItemDimmed(ECalenViewAttachmentCmdSave,EFalse); |
|
354 aMenuPane->SetItemDimmed(ECalenViewAttachmentCmdRemove,EFalse); |
|
355 } |
|
356 } |
|
357 break; |
|
358 default: |
|
359 break; |
|
360 } |
|
361 |
|
362 TRACE_EXIT_POINT; |
|
363 } |
|
364 |
|
365 // ---------------------------------------------------------------------------- |
|
366 // CCalenViewAttachmentsDialog::HandleResourceChangeL |
|
367 // (other items were commented in a header). |
|
368 // ---------------------------------------------------------------------------- |
|
369 // |
|
370 void CCalenViewAttachmentsDialog::HandleResourceChange(TInt aType) |
|
371 { |
|
372 TRACE_ENTRY_POINT; |
|
373 |
|
374 if ( aType == KEikDynamicLayoutVariantSwitch || |
|
375 aType == KAknsMessageSkinChange ) |
|
376 { |
|
377 TRAP_IGNORE( iAttachmentModel.LoadResourcesL() ); |
|
378 } |
|
379 CEikDialog::HandleResourceChange( aType ); |
|
380 |
|
381 TRACE_EXIT_POINT; |
|
382 } |
|
383 |
|
384 // ---------------------------------------------------------------------------- |
|
385 // CCalenViewAttachmentsDialog::HandleServerAppExit |
|
386 // (other items were commented in a header). |
|
387 // ---------------------------------------------------------------------------- |
|
388 // |
|
389 void CCalenViewAttachmentsDialog::HandleServerAppExit( TInt aReason) |
|
390 { |
|
391 TRACE_ENTRY_POINT; |
|
392 |
|
393 if (aReason == EAknCmdExit) |
|
394 { |
|
395 //issue this notification, which will be handled by attachmentui. |
|
396 iController.BroadcastNotification(ECalenNotifyAttachmentViewerClosed); |
|
397 } |
|
398 |
|
399 TRACE_EXIT_POINT; |
|
400 } |
|
401 |
|
402 // ---------------------------------------------------------------------------- |
|
403 // CCalenViewAttachmentsDialog::HandleControlStateChangeL |
|
404 // (other items were commented in a header). |
|
405 // ---------------------------------------------------------------------------- |
|
406 // |
|
407 void CCalenViewAttachmentsDialog::HandleControlStateChangeL( TInt aControlId ) |
|
408 { |
|
409 TRACE_ENTRY_POINT; |
|
410 |
|
411 if ( aControlId == ECalenAttachmentListBoxId ) |
|
412 { |
|
413 DoUpdateUiL(); |
|
414 } |
|
415 |
|
416 CAknDialog::HandleControlStateChangeL( aControlId ); |
|
417 |
|
418 TRACE_EXIT_POINT; |
|
419 } |
|
420 |
|
421 // ---------------------------------------------------------------------------- |
|
422 // CCalenViewAttachmentsDialog::OkToExitL |
|
423 // (other items were commented in a header). |
|
424 // ---------------------------------------------------------------------------- |
|
425 // |
|
426 TBool CCalenViewAttachmentsDialog::HandleOkToExitL( TInt aButtonId ) |
|
427 { |
|
428 TRACE_ENTRY_POINT; |
|
429 |
|
430 |
|
431 if ( aButtonId == EAknSoftkeyBack ) |
|
432 { |
|
433 iTitlePane->SetTextL( *iOldTitle ); |
|
434 |
|
435 //issue this notification, which will be handled by attachmentui. |
|
436 iController.BroadcastNotification(ECalenNotifyAttachmentViewerClosed); |
|
437 } |
|
438 else if ( aButtonId == EAknSoftkeyOpen ) |
|
439 { |
|
440 if(iAttachmentModel.NumberOfItems()!= 0) |
|
441 { |
|
442 //open the attachment if user taps on the item. |
|
443 ProcessCommandL( ECalenViewAttachmentCmdOpen ); |
|
444 } |
|
445 TRACE_EXIT_POINT; |
|
446 |
|
447 return EFalse; |
|
448 } |
|
449 TRACE_EXIT_POINT; |
|
450 |
|
451 return CAknDialog::OkToExitL( aButtonId ); |
|
452 } |
|
453 |
|
454 // ---------------------------------------------------------------------------- |
|
455 // CCalenViewAttachmentsDialog::CreateCustomControlL |
|
456 // (other items were commented in a header). |
|
457 // ---------------------------------------------------------------------------- |
|
458 // |
|
459 SEikControlInfo CCalenViewAttachmentsDialog::CreateCustomControlL( TInt aControlType ) |
|
460 { |
|
461 TRACE_ENTRY_POINT; |
|
462 |
|
463 SEikControlInfo controlInfo; |
|
464 controlInfo.iControl = NULL; |
|
465 controlInfo.iTrailerTextId = 0; |
|
466 controlInfo.iFlags = 0; |
|
467 |
|
468 if ( aControlType == ECalenAttachmentListBox ) |
|
469 { |
|
470 //create the attachment listbox to list all the attachments |
|
471 controlInfo.iControl = new ( ELeave ) CCalenAttachmentsListBox( iAttachmentModel ); |
|
472 } |
|
473 TRACE_EXIT_POINT; |
|
474 |
|
475 return controlInfo; |
|
476 } |
|
477 |
|
478 // ---------------------------------------------------------------------------- |
|
479 // CCalenViewAttachmentsDialog::HandleListBoxEventL |
|
480 // (other items were commented in a header). |
|
481 // ---------------------------------------------------------------------------- |
|
482 // |
|
483 #ifdef RD_SCALABLE_UI_V2 |
|
484 void CCalenViewAttachmentsDialog::HandleListBoxEventL( CEikListBox* /*aListBox*/, |
|
485 TListBoxEvent aEventType ) |
|
486 { |
|
487 TRACE_ENTRY_POINT; |
|
488 |
|
489 if ( !MenuShowing() ) |
|
490 { |
|
491 //Single click integration |
|
492 if ( aEventType == EEventEnterKeyPressed || |
|
493 |
|
494 aEventType == EEventItemSingleClicked ) |
|
495 { |
|
496 const TInt index(CurrentListItemIndex()); |
|
497 if ( index != KErrNotFound ) |
|
498 { |
|
499 UpdateMiddleSoftKeyL( index ); |
|
500 OpenAttachmentL(); |
|
501 } |
|
502 } |
|
503 } |
|
504 TRACE_EXIT_POINT; |
|
505 } |
|
506 #else |
|
507 void CCalenViewAttachmentsDialog::HandleListBoxEventL( CEikListBox* /*aListBox*/, |
|
508 TListBoxEvent /*aEventType*/ ) |
|
509 { |
|
510 TRACE_ENTRY_POINT; |
|
511 TRACE_EXIT_POINT; |
|
512 } |
|
513 #endif // RD_SCALABLE_UI_V2 |
|
514 |
|
515 |
|
516 // ---------------------------------------------------------------------------- |
|
517 // CCalenViewAttachmentsDialog::PreLayoutDynInitL |
|
518 // (other items were commented in a header). |
|
519 // ---------------------------------------------------------------------------- |
|
520 // |
|
521 void CCalenViewAttachmentsDialog::PreLayoutDynInitL() |
|
522 { |
|
523 TRACE_ENTRY_POINT; |
|
524 |
|
525 CEikStatusPane *sp = static_cast<CAknAppUi*> |
|
526 ( iEikonEnv->EikAppUi() )->StatusPane(); |
|
527 |
|
528 iTitlePane = static_cast<CAknTitlePane*> |
|
529 ( sp->ControlL( TUid::Uid(EEikStatusPaneUidTitle ) ) ); |
|
530 |
|
531 const TDesC* title = iTitlePane->Text(); |
|
532 iOldTitle = title->AllocL(); |
|
533 |
|
534 iTitlePane->SetTextL( iNewTitle ); |
|
535 |
|
536 iListBox = static_cast<CCalenAttachmentsListBox*> |
|
537 ( Control( ECalenAttachmentListBoxId ) ); |
|
538 |
|
539 iListBox->SetContainerWindowL( *this); |
|
540 iListBox->CreateScrollBarFrameL( ETrue ); |
|
541 |
|
542 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
543 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
544 |
|
545 iListBox->SetListBoxObserver( this ); |
|
546 |
|
547 LoadFormDataL(); |
|
548 |
|
549 if(iAttachmentModel.NumberOfItems() == 0) |
|
550 { |
|
551 UpdateButtonVisiblity( ECalenViewAttachmentCmdOpen, EFalse ); |
|
552 } |
|
553 |
|
554 TRACE_EXIT_POINT; |
|
555 } |
|
556 |
|
557 // ---------------------------------------------------------------------------- |
|
558 // CCalenViewAttachmentsDialog::LoadFormDataL |
|
559 // (other items were commented in a header). |
|
560 // ---------------------------------------------------------------------------- |
|
561 // |
|
562 void CCalenViewAttachmentsDialog::LoadFormDataL() |
|
563 { |
|
564 TRACE_ENTRY_POINT; |
|
565 |
|
566 // iconarray for two icons. |
|
567 // index 0: application icon. |
|
568 // index 1: indicator. |
|
569 iIconArray = new ( ELeave ) CArrayPtrFlat<CGulIcon>( 2 ); |
|
570 |
|
571 iListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL( iIconArray ); |
|
572 |
|
573 // list items is not actually an array but object that returns |
|
574 // list item text for listbox in MdcaPoint method. |
|
575 iListItems = CCalenAttaListItemArray::NewL( iAttachmentModel, iIconArray ); |
|
576 iListBox->Model()->SetItemTextArray( iListItems ); |
|
577 iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
578 } |
|
579 |
|
580 // ---------------------------------------------------------------------------- |
|
581 // CCalenViewAttachmentsDialog::ItemAddedL |
|
582 // (other items were commented in a header). |
|
583 // ---------------------------------------------------------------------------- |
|
584 void CCalenViewAttachmentsDialog::ItemAddedL( TInt aIndex ) |
|
585 { |
|
586 iTitlePane->SetTextL( iNewTitle ); |
|
587 iListBox->View()->CalcBottomItemIndex(); |
|
588 |
|
589 TInt itemIndex = aIndex; |
|
590 |
|
591 if ( aIndex == -1 ) |
|
592 { |
|
593 itemIndex = Max( iListBox->Model()->NumberOfItems() - 1, 0 ); |
|
594 } |
|
595 |
|
596 iListBox->SetCurrentItemIndexAndDraw(itemIndex); |
|
597 |
|
598 if ( !ButtonGroupContainer().IsCommandVisible( EAknSoftkeyOpen ) ) |
|
599 { |
|
600 // Set middle button visible if invisible and inserted attachment |
|
601 // has content (i.e. it is not empty) |
|
602 UpdateButtonVisiblity( ECalenViewAttachmentCmdOpen, ETrue ); |
|
603 } |
|
604 |
|
605 iListBox->HandleItemAdditionL(); |
|
606 iListBox->DrawNow(); |
|
607 |
|
608 TRACE_EXIT_POINT; |
|
609 } |
|
610 |
|
611 // ---------------------------------------------------------------------------- |
|
612 // CCalenViewAttachmentsDialog::ItemRemovedL |
|
613 // (other items were commented in a header). |
|
614 // ---------------------------------------------------------------------------- |
|
615 void CCalenViewAttachmentsDialog::ItemRemovedL( TInt aIndex ) |
|
616 { |
|
617 TRACE_ENTRY_POINT; |
|
618 |
|
619 iTitlePane->SetTextL( iNewTitle ); |
|
620 iListBox->HandleItemRemovalL(); |
|
621 TInt lastItem = Max( iListBox->Model()->NumberOfItems() - 1, 0 ); |
|
622 |
|
623 if ( aIndex - 1 == lastItem ) |
|
624 { |
|
625 TInt numItems = iListBox->View()->NumberOfItemsThatFitInRect( |
|
626 iListBox->View()->ViewRect() ); |
|
627 TInt topItem = Max( lastItem - numItems, 0 ); |
|
628 iListBox->SetTopItemIndex( topItem ); |
|
629 } |
|
630 |
|
631 iListBox->SetCurrentItemIndex( Min( aIndex, lastItem ) ); |
|
632 iListBox->DrawNow(); |
|
633 |
|
634 if ( iAttachmentModel.NumberOfItems() == 0 ) |
|
635 { |
|
636 UpdateButtonVisiblity( ECalenViewAttachmentCmdOpen, EFalse ); |
|
637 } |
|
638 TRACE_EXIT_POINT; |
|
639 } |
|
640 |
|
641 |
|
642 // ---------------------------------------------------------------------------- |
|
643 // CCalenViewAttachmentsDialog::RemoveAttachmentL |
|
644 // (other items were commented in a header). |
|
645 // ---------------------------------------------------------------------------- |
|
646 // |
|
647 TBool CCalenViewAttachmentsDialog::RemoveAttachmentL( TInt aIndex ) |
|
648 { |
|
649 TRACE_ENTRY_POINT; |
|
650 |
|
651 TBool attachmentDeleted(EFalse); |
|
652 // delete item from attachment model (notifies its observer about deletion). |
|
653 attachmentDeleted = iAttachmentModel.DeleteAttachment( aIndex ); |
|
654 |
|
655 TRACE_EXIT_POINT; |
|
656 return attachmentDeleted; |
|
657 } |
|
658 |
|
659 // ---------------------------------------------------------------------------- |
|
660 // CCalenViewAttachmentsDialog::CleanupWaitDialog |
|
661 // (other items were commented in a header). |
|
662 // ---------------------------------------------------------------------------- |
|
663 // |
|
664 void CCalenViewAttachmentsDialog::CleanupWaitDialog( TAny* aAny ) |
|
665 { |
|
666 TRACE_ENTRY_POINT; |
|
667 |
|
668 //not used as of now, but we can use when attaching is in progress |
|
669 CAknWaitDialog** dialog = (CAknWaitDialog**) aAny; |
|
670 if ( dialog && *dialog ) |
|
671 { |
|
672 delete *dialog; |
|
673 } |
|
674 |
|
675 TRACE_EXIT_POINT; |
|
676 } |
|
677 |
|
678 // ---------------------------------------------------------------------------- |
|
679 // CCalenViewAttachmentsDialog::DoUpdateUiL |
|
680 // (other items were commented in a header). |
|
681 // ---------------------------------------------------------------------------- |
|
682 // |
|
683 void CCalenViewAttachmentsDialog::DoUpdateUiL() |
|
684 { |
|
685 TRACE_ENTRY_POINT; |
|
686 |
|
687 if ( iAttachmentModel.NumberOfItems() == 0 ) |
|
688 { |
|
689 UpdateButtonVisiblity( ECalenViewAttachmentCmdOpen, EFalse ); |
|
690 } |
|
691 else |
|
692 { |
|
693 UpdateButtonVisiblity( ECalenViewAttachmentCmdOpen, ETrue ); |
|
694 } |
|
695 |
|
696 TRACE_EXIT_POINT; |
|
697 } |
|
698 |
|
699 // ---------------------------------------------------------------------------- |
|
700 // CCalenViewAttachmentsDialog::UpdateButtonVisiblity |
|
701 // (other items were commented in a header). |
|
702 // ---------------------------------------------------------------------------- |
|
703 // |
|
704 void CCalenViewAttachmentsDialog::UpdateButtonVisiblity( TInt aCommandId, TBool aValue ) |
|
705 { |
|
706 TRACE_ENTRY_POINT; |
|
707 |
|
708 if ( ButtonGroupContainer().ControlOrNull( aCommandId ) ) |
|
709 { |
|
710 ButtonGroupContainer().MakeCommandVisible( aCommandId, aValue ); |
|
711 } |
|
712 |
|
713 TRACE_EXIT_POINT; |
|
714 } |
|
715 |
|
716 // ---------------------------------------------------------------------------- |
|
717 // CCalenViewAttachmentsDialog::HandleNotification |
|
718 // Calls back when notifications that it has been registered for are broadcast |
|
719 // (other items were commented in a header). |
|
720 // ---------------------------------------------------------------------------- |
|
721 // |
|
722 void CCalenViewAttachmentsDialog::HandleNotification(const TCalenNotification aNotification ) |
|
723 { |
|
724 TRACE_ENTRY_POINT; |
|
725 |
|
726 PIM_TRAPD_HANDLE( HandleNotificationL( aNotification ) ); |
|
727 |
|
728 TRACE_EXIT_POINT; |
|
729 } |
|
730 |
|
731 // ---------------------------------------------------------------------------- |
|
732 // CCalenViewAttachmentsDialog::HandleNotificationL |
|
733 // Called from HandleNotification() when notifications that it has been |
|
734 // registered for are broadcast |
|
735 // (other items were commented in a header). |
|
736 // ---------------------------------------------------------------------------- |
|
737 // |
|
738 void CCalenViewAttachmentsDialog::HandleNotificationL( TCalenNotification aNotification ) |
|
739 { |
|
740 TRACE_ENTRY_POINT; |
|
741 |
|
742 switch( aNotification ) |
|
743 { |
|
744 case ECalenNotifyAttachmentAdded: |
|
745 { |
|
746 TInt currentItemIndex = iAttachmentModel.NumberOfItems()-1; |
|
747 ItemAddedL(currentItemIndex); |
|
748 } |
|
749 break; |
|
750 default: |
|
751 break; |
|
752 } |
|
753 |
|
754 TRACE_EXIT_POINT; |
|
755 } |
|
756 |
|
757 // ----------------------------------------------------------------------------- |
|
758 // CCalenViewAttachmentsDialog::CountComponentControls |
|
759 // Gets the number of controls contained in a compound control. |
|
760 // ----------------------------------------------------------------------------- |
|
761 // |
|
762 TInt CCalenViewAttachmentsDialog::CountComponentControls() const |
|
763 { |
|
764 TRACE_ENTRY_POINT; |
|
765 TRACE_EXIT_POINT; |
|
766 |
|
767 return 1; |
|
768 } |
|
769 |
|
770 // ----------------------------------------------------------------------------- |
|
771 // CCalenViewAttachmentsDialog::ComponentControl |
|
772 // Gets the specified component of a compound control. |
|
773 // ----------------------------------------------------------------------------- |
|
774 // |
|
775 CCoeControl* CCalenViewAttachmentsDialog::ComponentControl(TInt aIndex) const |
|
776 { |
|
777 TRACE_ENTRY_POINT; |
|
778 TRACE_EXIT_POINT; |
|
779 switch (aIndex) |
|
780 { |
|
781 case 0: |
|
782 return iListBox; |
|
783 default: |
|
784 return NULL; |
|
785 } |
|
786 } |
|
787 |
|
788 |
|
789 // ---------------------------------------------------------------------------- |
|
790 // CCalenViewAttachmentsDialog::HandlePointerEventL |
|
791 // Process pointer event. |
|
792 // (other items were commented in a header). |
|
793 // ---------------------------------------------------------------------------- |
|
794 // |
|
795 void CCalenViewAttachmentsDialog::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
796 { |
|
797 TRACE_ENTRY_POINT; |
|
798 //Single click integration |
|
799 if ( iListBox ) |
|
800 { |
|
801 iListBox->HandlePointerEventL( aPointerEvent ); |
|
802 } |
|
803 TRACE_EXIT_POINT; |
|
804 } |
|
805 |
|
806 |
|
807 // ----------------------------------------------------------------------------- |
|
808 // CCalenViewAttachmentsDialog::NotifySizeChanged |
|
809 // ----------------------------------------------------------------------------- |
|
810 // |
|
811 void CCalenViewAttachmentsDialog::NotifySizeChanged() |
|
812 { |
|
813 TRACE_ENTRY_POINT; |
|
814 |
|
815 if(iListBox) |
|
816 { |
|
817 iListBox->SizeChanged(); |
|
818 } |
|
819 TRACE_EXIT_POINT; |
|
820 } |
|
821 |
|
822 // ---------------------------------------------------------------------------- |
|
823 // CCalenViewAttachmentsDialog::UpdateAttachmentsFetchFlags |
|
824 // ---------------------------------------------------------------------------- |
|
825 // |
|
826 void CCalenViewAttachmentsDialog::UpdateAttachmentsFetchFlags() |
|
827 { |
|
828 TRACE_ENTRY_POINT; |
|
829 |
|
830 //Update attachmentmodel to secure model is up to date. |
|
831 for(TInt itemIndex=0; itemIndex<iAttachmentModel.NumberOfItems(); itemIndex++) |
|
832 { |
|
833 CCalenAttachmentInfo& attInfo = |
|
834 iAttachmentModel.AttachmentInfoAt(itemIndex); |
|
835 attInfo.SetFetched( ETrue ); |
|
836 } |
|
837 |
|
838 //If there are attachments update the middle soft key |
|
839 //according to the first attachment |
|
840 if( iAttachmentModel.NumberOfItems() > 0 ) |
|
841 { |
|
842 TRAP_IGNORE( UpdateMiddleSoftKeyL(CurrentListItemIndex()) ); |
|
843 } |
|
844 TRACE_EXIT_POINT; |
|
845 |
|
846 } |
|
847 |
|
848 // ---------------------------------------------------------------------------- |
|
849 // CCalenViewAttachmentsDialog::OfferKeyEventL |
|
850 // (other items were commented in a header). |
|
851 // ---------------------------------------------------------------------------- |
|
852 // |
|
853 TKeyResponse CCalenViewAttachmentsDialog::OfferKeyEventL( |
|
854 const TKeyEvent& aKeyEvent, TEventCode aType) |
|
855 { |
|
856 TRACE_ENTRY_POINT; |
|
857 |
|
858 // Consume send keys, so that they are not handled in the appui |
|
859 if( aType == EEventKey && aKeyEvent.iCode == EKeyYes ) |
|
860 { |
|
861 TRACE_EXIT_POINT; |
|
862 |
|
863 return EKeyWasConsumed; |
|
864 } |
|
865 |
|
866 TInt index( CurrentListItemIndex() ); |
|
867 if ( index != KErrNotFound && !MenuShowing() ) |
|
868 { |
|
869 if ( aType == EEventKey ) |
|
870 { |
|
871 if( aKeyEvent.iCode == EKeyOK ) |
|
872 { |
|
873 //Single click integration |
|
874 iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
875 return EKeyWasConsumed; |
|
876 } |
|
877 else if( aKeyEvent.iCode == EKeyBackspace |
|
878 && iMenuBar->ItemSpecificCommandsEnabled() ) |
|
879 { |
|
880 //todo isssue a confirmation query |
|
881 CCalenAttachmentInfo& attaInfo = |
|
882 iAttachmentModel.AttachmentInfoAt(index); |
|
883 if ( CanRemoveAttachment( attaInfo ) ) |
|
884 { |
|
885 ProcessCommandL(ECalenViewAttachmentCmdRemove); |
|
886 } |
|
887 TRACE_EXIT_POINT; |
|
888 |
|
889 return EKeyWasConsumed; |
|
890 } |
|
891 else if(aKeyEvent.iCode == EKeyNo) |
|
892 { |
|
893 iController.BroadcastNotification(ECalenNotifyAttachmentViewerClosed); |
|
894 } |
|
895 else if(aKeyEvent.iCode == EKeyEscape) |
|
896 { |
|
897 MCalenToolbar* toolbar = iController.Services().ToolbarOrNull(); |
|
898 if(toolbar) |
|
899 { |
|
900 toolbar->SetToolbarVisibilityL(ETrue); |
|
901 } |
|
902 iController.BroadcastNotification(ECalenNotifyAttachmentViewerClosed); |
|
903 } |
|
904 } |
|
905 else if ( aType == EEventKeyUp ) |
|
906 { |
|
907 UpdateMiddleSoftKeyL( index ); |
|
908 } |
|
909 } |
|
910 TRACE_EXIT_POINT; |
|
911 |
|
912 return CAknDialog::OfferKeyEventL(aKeyEvent, aType); |
|
913 } |
|
914 |
|
915 // ---------------------------------------------------------------------------- |
|
916 // CCalenViewAttachmentsDialog::OpenAttachmentL |
|
917 // ---------------------------------------------------------------------------- |
|
918 // |
|
919 void CCalenViewAttachmentsDialog::OpenAttachmentL() |
|
920 { |
|
921 TRACE_ENTRY_POINT; |
|
922 |
|
923 if ( CheckSpaceBelowCriticalLevelL() ) |
|
924 { |
|
925 TRACE_EXIT_POINT; |
|
926 |
|
927 return; |
|
928 } |
|
929 else |
|
930 { |
|
931 CCalenViewAttachmentsDialog::ProcessCommandL(ECalenViewAttachmentCmdOpen); |
|
932 } |
|
933 TRACE_EXIT_POINT; |
|
934 |
|
935 } |
|
936 |
|
937 // ---------------------------------------------------------------------------- |
|
938 // CCalenViewAttachmentsDialog::CanRemoveAttachment |
|
939 // ---------------------------------------------------------------------------- |
|
940 // |
|
941 TBool CCalenViewAttachmentsDialog::CanRemoveAttachment( |
|
942 CCalenAttachmentInfo& aInfo ) |
|
943 { |
|
944 TRACE_ENTRY_POINT; |
|
945 TRACE_EXIT_POINT; |
|
946 return (aInfo.IsFetched() ); |
|
947 } |
|
948 |
|
949 // --------------------------------------------------------------------------- |
|
950 // CCalenViewAttachmentsDialog::SetMiddleSoftKeyLabelL |
|
951 // --------------------------------------------------------------------------- |
|
952 // |
|
953 void CCalenViewAttachmentsDialog::SetMiddleSoftKeyLabelL( |
|
954 TInt aResourceId, TInt aCommandId ) |
|
955 { |
|
956 TRACE_ENTRY_POINT; |
|
957 |
|
958 HBufC* middleSKText = StringLoader::LoadLC( aResourceId ); |
|
959 |
|
960 ButtonGroupContainer().AddCommandToStackL( |
|
961 KMSKControlID, |
|
962 aCommandId, |
|
963 *middleSKText ); |
|
964 CleanupStack::PopAndDestroy( middleSKText ); |
|
965 |
|
966 TRACE_EXIT_POINT; |
|
967 } |
|
968 |
|
969 // --------------------------------------------------------------------------- |
|
970 // CCalenViewAttachmentsDialog::UpdateMiddleSoftKeyL |
|
971 // --------------------------------------------------------------------------- |
|
972 // |
|
973 void CCalenViewAttachmentsDialog::UpdateMiddleSoftKeyL( TInt aIndex ) |
|
974 { |
|
975 TRACE_ENTRY_POINT; |
|
976 |
|
977 ASSERT( aIndex >= 0 && aIndex < iAttachmentModel.NumberOfItems() ); |
|
978 |
|
979 // set command as "open" |
|
980 ButtonGroupContainer().RemoveCommandFromStack( |
|
981 KMSKControlID, EAknSoftkeyOpen ); |
|
982 SetMiddleSoftKeyLabelL( |
|
983 R_QTN_MSK_FETCH, ECalenViewAttachmentCmdOpen ); |
|
984 |
|
985 TRACE_EXIT_POINT; |
|
986 } |
|
987 |
|
988 // ---------------------------------------------------------------------------- |
|
989 // CCalenViewAttachmentsDialog::GetHelpContext |
|
990 // This function is called when Help application is launched. |
|
991 // ---------------------------------------------------------------------------- |
|
992 // |
|
993 void CCalenViewAttachmentsDialog::GetHelpContext(TCoeHelpContext& /*aContext*/) const |
|
994 { |
|
995 TRACE_ENTRY_POINT; |
|
996 TRACE_EXIT_POINT; |
|
997 } |
|
998 |
|
999 // ----------------------------------------------------------------------------- |
|
1000 // CCalenViewAttachmentsDialog::OkToExitL |
|
1001 // ----------------------------------------------------------------------------- |
|
1002 // |
|
1003 TBool CCalenViewAttachmentsDialog::OkToExitL(TInt aButtonId) |
|
1004 { |
|
1005 TRACE_ENTRY_POINT; |
|
1006 |
|
1007 //Check if user has selected exit from menu |
|
1008 // -> whole application shall be closed. |
|
1009 if ( aButtonId == EAknSoftkeyOk ) |
|
1010 { |
|
1011 if ( CCalenViewAttachmentsDialog::HandleOkToExitL(aButtonId) ) |
|
1012 { |
|
1013 CEikAppUi* appUi = iEikonEnv->EikAppUi(); |
|
1014 static_cast<MEikCommandObserver*>(appUi)->ProcessCommandL( |
|
1015 EAknCmdExit ); |
|
1016 return ETrue; |
|
1017 } |
|
1018 else |
|
1019 { |
|
1020 TRACE_EXIT_POINT; |
|
1021 |
|
1022 return EFalse; |
|
1023 } |
|
1024 } |
|
1025 |
|
1026 else if ( aButtonId == ECalenViewAttachmentCmdOpen ) |
|
1027 { |
|
1028 ProcessCommandL( aButtonId ); |
|
1029 |
|
1030 TRACE_EXIT_POINT; |
|
1031 |
|
1032 return EFalse; |
|
1033 } |
|
1034 TRACE_EXIT_POINT; |
|
1035 |
|
1036 //Let base class decide if it ok to exit |
|
1037 return CCalenViewAttachmentsDialog::HandleOkToExitL(aButtonId); |
|
1038 } |
|
1039 |
|
1040 |
|
1041 // ----------------------------------------------------------------------------- |
|
1042 // CCalenViewAttachmentsDialog::UpdateAttatchmentListL |
|
1043 // Update attatchmentlist |
|
1044 // ----------------------------------------------------------------------------- |
|
1045 // |
|
1046 void CCalenViewAttachmentsDialog::UpdateAttatchmentListL() |
|
1047 { |
|
1048 TRACE_ENTRY_POINT; |
|
1049 |
|
1050 // Handles item addition |
|
1051 ItemAddedL(); |
|
1052 TRACE_EXIT_POINT; |
|
1053 } |
|
1054 |
|
1055 // ----------------------------------------------------------------------------- |
|
1056 // CCalenViewAttachmentsDialog::CheckSpaceBelowCriticalLevelL |
|
1057 // Checks if the Flash File System storage will fall below critical level. |
|
1058 // If there is not enough space, display an error message and return EFalse. |
|
1059 // Return ETrue otherwise. |
|
1060 // (other items were commented in a header). |
|
1061 // ----------------------------------------------------------------------------- |
|
1062 // |
|
1063 TBool CCalenViewAttachmentsDialog::CheckSpaceBelowCriticalLevelL() |
|
1064 { |
|
1065 TRACE_ENTRY_POINT; |
|
1066 |
|
1067 // FIXME: Could be moved to commonui |
|
1068 TBool retcode(EFalse); |
|
1069 |
|
1070 if (SysUtil::FFSSpaceBelowCriticalLevelL(&(iCoeEnv->FsSession()))) |
|
1071 { |
|
1072 CErrorUI* errorUi = CErrorUI::NewLC(); |
|
1073 errorUi->ShowGlobalErrorNoteL(KErrDiskFull); |
|
1074 CleanupStack::PopAndDestroy( errorUi ); |
|
1075 retcode = ETrue; |
|
1076 } |
|
1077 TRACE_EXIT_POINT; |
|
1078 |
|
1079 return retcode; |
|
1080 } |
|
1081 |
|
1082 // ----------------------------------------------------------------------------- |
|
1083 // CCalenViewAttachmentsDialog::OpenAttachmentL |
|
1084 // Opens a particular attachment |
|
1085 // ----------------------------------------------------------------------------- |
|
1086 // |
|
1087 void CCalenViewAttachmentsDialog::OpenAttachmentViewerL(RFile& file, MAknServerAppExitObserver& /*aExitObserver*/) |
|
1088 { |
|
1089 TRACE_ENTRY_POINT; |
|
1090 |
|
1091 TBuf<250> fileName; |
|
1092 file.FullName(fileName); |
|
1093 TDataType datatype( CCalenAttachmentUtils::GetMimeTypeL(fileName) ); |
|
1094 |
|
1095 TInt ret = KErrNone; |
|
1096 |
|
1097 file.Close(); |
|
1098 RFs& fs = CEikonEnv::Static()->FsSession(); |
|
1099 |
|
1100 //open the file, before giving it to Notepad. |
|
1101 TInt err1 = file.Open( fs, fileName, EFileRead | EFileShareReadersOnly ); |
|
1102 CleanupClosePushL( file ); |
|
1103 |
|
1104 if(datatype == KNotePadTextDataType()) |
|
1105 { |
|
1106 const TDesC& notepadTitle = _L("NotePad"); |
|
1107 // file handle ownership transferred. |
|
1108 |
|
1109 // 1.File handle from arg has problem for notes since junk chars are reported in file. |
|
1110 // so we use another file handle exclusively open with filename an pass to note viewer. |
|
1111 // |
|
1112 // 2.Pass ETrue to 4th param ExecFileViewerL , to guess encoding. |
|
1113 RFile fileForNotes; |
|
1114 TInt err = fileForNotes.Open( fs, fileName, EFileRead | EFileShareReadersOnly ); |
|
1115 CleanupClosePushL( fileForNotes ); |
|
1116 ret = CNotepadApi::ExecFileViewerL( fileForNotes, |
|
1117 ¬epadTitle, |
|
1118 ETrue, |
|
1119 ETrue, |
|
1120 KCharacterSetIdentifierIso88591 ); |
|
1121 |
|
1122 CleanupStack::PopAndDestroy(&fileForNotes); |
|
1123 } |
|
1124 else |
|
1125 { |
|
1126 //doc handler will open the other files (other than text file). |
|
1127 TRAP( ret, iDocHandler->OpenFileEmbeddedL( file, datatype ) ); |
|
1128 } |
|
1129 CleanupStack::PopAndDestroy(&file); |
|
1130 |
|
1131 switch(ret) |
|
1132 { |
|
1133 case KErrNone: |
|
1134 break; |
|
1135 default: |
|
1136 { |
|
1137 CAknInformationNote* note = new ( ELeave ) CAknInformationNote; |
|
1138 HBufC* cannotOpen = StringLoader::LoadLC( |
|
1139 R_QTN_CALEN_INFO_CANNOT_OPEN, CEikonEnv::Static() ); |
|
1140 note->ExecuteLD( *cannotOpen ); |
|
1141 CleanupStack::PopAndDestroy(); |
|
1142 } |
|
1143 break; |
|
1144 } |
|
1145 TRACE_EXIT_POINT |
|
1146 } |
|
1147 |
|
1148 // End of File |