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