meetingui/meetingrequestviewers/src/CMRSummaryDlgBase.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:   Implementation of base summary dialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CMRSummaryDlgBase.h"
       
    22 #include "ICalUILog.h"
       
    23 #include "MMRModelInterface.h" //MRModelInterface
       
    24 #include "MMRInfoPopup.h"
       
    25 #include "meetingrequestviewers.hrh" //common constants and commands
       
    26 #include <MAgnEntryUi.h> //MAgnEntryUi
       
    27 #include "MRViewersPanic.h" //panic codes
       
    28 #include <eikmenup.h> //menupane
       
    29 #include <MRCommands.hrh>
       
    30 #include <e32std.h> //standard epoc
       
    31 #include <avkon.hrh> 	//enums
       
    32 #include <aknlists.h>	//CAknDoubleLargeStyleListBox
       
    33 #include <gulicon.h>	//icons
       
    34 #include <AknIconArray.h>
       
    35 #include <meetingrequestviewers.mbg>
       
    36 #include <meetingrequestviewersuires.rsg>
       
    37 #include <stringloader.h> //stringloader for resources
       
    38 #include <AknListQueryDialog.h>
       
    39 #include <AknQueryDialog.h>
       
    40 
       
    41 // CONSTANTS
       
    42 /// Unnamed namespace for local definitions
       
    43 namespace {
       
    44 
       
    45 _LIT( KPanicMsg, "CMRSummaryDlgBase" );
       
    46 
       
    47 void Panic( TPanicCode aReason )
       
    48     {
       
    49     User::Panic( KPanicMsg, aReason );
       
    50     }
       
    51 
       
    52 }  // namespace
       
    53 
       
    54 // ============================ MEMBER FUNCTIONS ===============================
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CMRSummaryDlgBase::CMRSummaryDlgBase
       
    58 // C++ default constructor can NOT contain any code, that
       
    59 // might leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CMRSummaryDlgBase::CMRSummaryDlgBase(
       
    63     MAgnEntryUiCallback& aHandlerCallback,
       
    64     MAgnEntryUi::TAgnEntryUiEditorMode aEditorMode )
       
    65     : CMRDialogBase( aHandlerCallback ),
       
    66       iEditorMode( aEditorMode )
       
    67     {
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CMRSummaryDlgBase::ConstructL
       
    72 // Symbian 2nd phase constructor can leave.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CMRSummaryDlgBase::ConstructL()
       
    76     {
       
    77     CAknDialog::ConstructL( R_MR_SUMMARYDLG_OPTIONS_MENUBAR );
       
    78 	
       
    79     //idle timer for dialog exit from list box
       
    80     iIdleDialogExit = CIdle::NewL( CActive::EPriorityIdle );
       
    81     }
       
    82 
       
    83 void CMRSummaryDlgBase::ConstructListBoxL()   
       
    84 	{		
       
    85     LOG("CMRSummaryDlgBase::ConstructListBoxL, creating iLBModel");
       
    86     	
       
    87 	iLBModel = CMRSummaryListBoxModel::NewL( iEikonEnv );  
       
    88 	
       
    89     // if iMRModel not yet available it will be set later	
       
    90 	if ( iMRModel )  
       
    91 	    {	    
       
    92 	    iLBModel->SetModel( *iMRModel );
       
    93 	    }
       
    94 	
       
    95     LOG("CMRSummaryDlgBase::ConstructListBoxL, creating iListBox");	
       
    96 	iListBox = new (ELeave) CAknDoubleLargeStyleListBox;	
       
    97 	iListBox->SetContainerWindowL( *this );
       
    98 	TInt flags( EAknGenericListBoxFlags );
       
    99 	iListBox->ConstructL( this, flags ); 	
       
   100 	iListBox->SetListBoxObserver( this );
       
   101 	
       
   102 	// Create scroll bar
       
   103 	iListBox->CreateScrollBarFrameL( ETrue );
       
   104     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   105         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   106        
       
   107     CTextListBoxModel* lbModel = iListBox->Model();
       
   108     lbModel->SetItemTextArray( iLBModel );
       
   109     lbModel->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   110     
       
   111     LOG("CMRSummaryDlgBase::ConstructListBoxL, creating icon list");	    
       
   112     CAknIconArray* iconList = new( ELeave ) CAknIconArray( 2 );
       
   113     CleanupStack::PushL( iconList );
       
   114     iconList->ConstructFromResourceL( R_LISTBOX_ICONS );
       
   115     iListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL( iconList );
       
   116         
       
   117 	CleanupStack::Pop( iconList );
       
   118 
       
   119     LOG("CMRSummaryDlgBase::ConstructListBoxL -> End");	    	
       
   120 	}
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CMRSummaryDlgBase::NewL
       
   124 // Two-phased constructor.
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 CMRSummaryDlgBase* CMRSummaryDlgBase::NewL(
       
   128     MAgnEntryUiCallback& aHandlerCallback,
       
   129     MAgnEntryUi::TAgnEntryUiEditorMode aEditorMode )
       
   130     {
       
   131     CMRSummaryDlgBase* self =
       
   132         new( ELeave ) CMRSummaryDlgBase( aHandlerCallback, aEditorMode );
       
   133 
       
   134     CleanupStack::PushL( self );
       
   135     self->ConstructL();
       
   136     CleanupStack::Pop();
       
   137 
       
   138     return self;
       
   139     }
       
   140 
       
   141 
       
   142 // Destructor
       
   143 CMRSummaryDlgBase::~CMRSummaryDlgBase()
       
   144     {
       
   145     LOG("CMRSummaryDlgBase::~CMRSummaryDlgBase");    
       
   146     delete iInfoPopup;
       
   147     delete iListBox;
       
   148 	delete iLBModel;    
       
   149     delete iIdleDialogExit;
       
   150     LOG("CMRSummaryDlgBase::~CMRSummaryDlgBase -> End");       
       
   151     }
       
   152 
       
   153 TInt CMRSummaryDlgBase::ExecuteLD()
       
   154 	{
       
   155 	TInt retVal( 0 );
       
   156     TInt resource( iEditorMode == MAgnEntryUi::EViewEntry ?
       
   157         R_MR_SUMMARY_VIEW_DLG : R_MR_SUMMARY_EDIT_DLG );
       
   158     LOG("CMRSummaryDlgBase::ExecuteViewL, executing dialog");
       
   159     retVal = CAknDialog::ExecuteLD( resource );
       
   160     LOG1( "CMRSummaryDlgBase::ExecuteViewL return code: %d", retVal );
       
   161 	return retVal;
       
   162 	}
       
   163 
       
   164 //-----------------------------------------------------------------------------
       
   165 //  CMRSummaryDlgBase::GetHelpContext()
       
   166 //-----------------------------------------------------------------------------
       
   167 void CMRSummaryDlgBase::GetHelpContext( TCoeHelpContext& /*aContext*/) const
       
   168     {
       
   169     //aContext.iMajor = TUid::Uid( KUidMsgMailEditor );
       
   170     //aContext.iContext = KMAIL_HLP_SENDING_OPTIONS;
       
   171     }
       
   172 	
       
   173 void CMRSummaryDlgBase::DynInitMenuPaneL(
       
   174     TInt aMenuId,
       
   175     CEikMenuPane* aMenuPane )
       
   176 	{
       
   177     LOG("CMRSummaryDlgBase::DynInitMenuPaneL");	
       
   178 	if( iMRModel )
       
   179 		{
       
   180 		if ( aMenuId == R_MR_SUMMARYDLG_MENUPANE )
       
   181 			{
       
   182 			//actual item is decided by what listbox item is selected
       
   183 			if ( iListBox->CurrentItemIndex() == EMRDescriptionItem )
       
   184 				{
       
   185 				aMenuPane->SetItemDimmed( EMRCommandShowDescriptionView, EFalse );
       
   186 				aMenuPane->SetItemDimmed( EMRCommandShowAttendeesView, ETrue );
       
   187 				}
       
   188 			else if ( iListBox->CurrentItemIndex() == EMRAttendeeItem )
       
   189 				{
       
   190 				aMenuPane->SetItemDimmed( EMRCommandShowAttendeesView, EFalse );
       
   191 				aMenuPane->SetItemDimmed( EMRCommandShowDescriptionView, ETrue );
       
   192 				}
       
   193             aMenuPane->SetItemDimmed( EMRCommandSend,
       
   194                                       !iMRModel->IsCmdAvailable( EMRCommandSend ) );
       
   195             aMenuPane->SetItemDimmed( EMRCommandSendUpdate,
       
   196                                       !iMRModel->IsCmdAvailable( EMRCommandSendUpdate ) );
       
   197             aMenuPane->SetItemDimmed( EMRCommandCancelMR,
       
   198                                       !iMRModel->IsCmdAvailable( EMRCommandCancelMR ) );
       
   199             aMenuPane->SetItemDimmed( EMRCommandDeleteMR,
       
   200                                       !iMRModel->IsCmdAvailable( EMRCommandDeleteMR ) );
       
   201             TBool canRespond( iMRModel->IsCmdAvailable( EMRCommandRespondAccept ) ||
       
   202 	                          iMRModel->IsCmdAvailable( EMRCommandRespondTentative ) ||
       
   203 	                          iMRModel->IsCmdAvailable( EMRCommandRespondDecline ) );
       
   204 			aMenuPane->SetItemDimmed( EMRCommandRespondSubmenu, !canRespond );
       
   205 			aMenuPane->SetItemDimmed( EMRCommandRemoveFromCalendar, 
       
   206 			                          !iMRModel->IsCmdAvailable( EMRCommandRemoveFromCalendar ) );			
       
   207             TBool canReply( iMRModel->IsCmdAvailable( EMRCommandReplyToSender ) ||
       
   208 	                        iMRModel->IsCmdAvailable( EMRCommandReplyToOrganiser ) ||
       
   209 	                        iMRModel->IsCmdAvailable( EMRCommandReplyToAll ) );
       
   210 			aMenuPane->SetItemDimmed( EMRCommandReplySubmenu, !canReply );
       
   211 			aMenuPane->SetItemDimmed( EMRCommandForward,
       
   212 			                          !iMRModel->IsCmdAvailable( EMRCommandForward) );
       
   213 			aMenuPane->SetItemDimmed( EMRCommandSaveFromFile, 
       
   214 			                          !iMRModel->IsCmdAvailable( EMRCommandSaveFromFile ) );
       
   215             TBool canRetrieve( iMRModel->IsCmdAvailable( EMRCommandRetrieve ) &&
       
   216                                iHandlerCallback.IsCommandAvailable( EMRCommandRetrieve ) );
       
   217 			aMenuPane->SetItemDimmed( EMRCommandRetrieve, !canRetrieve );
       
   218             TBool canShowAtta( iMRModel->IsCmdAvailable( EMRCommandAttachments ) &&
       
   219                                iHandlerCallback.IsCommandAvailable( EMRCommandAttachments ) );                      
       
   220 			aMenuPane->SetItemDimmed( EMRCommandAttachments, !canShowAtta );
       
   221 			aMenuPane->SetItemDimmed( EMRCommandMessageDetails,
       
   222 			                          !iMRModel->IsCmdAvailable( EMRCommandMessageDetails ) );
       
   223 			aMenuPane->SetItemDimmed( EMRCommandDisableAlarm,
       
   224 			                          !iMRModel->IsCmdAvailable( EMRCommandDisableAlarm ) );
       
   225 			}
       
   226 		else if ( aMenuId == R_MR_RESPOND_SUBMENU )
       
   227 			{		
       
   228 			aMenuPane->SetItemDimmed( EMRCommandRespondAccept,
       
   229 			                          !iMRModel->IsCmdAvailable( EMRCommandRespondAccept ) );
       
   230 			aMenuPane->SetItemDimmed( EMRCommandRespondTentative,
       
   231 			                          !iMRModel->IsCmdAvailable( EMRCommandRespondTentative ) );
       
   232 			aMenuPane->SetItemDimmed( EMRCommandRespondDecline,
       
   233 			                          !iMRModel->IsCmdAvailable( EMRCommandRespondDecline ) );
       
   234 			}
       
   235 		else if ( aMenuId == R_MR_REPLY_TO_SUBMENU )
       
   236 			{
       
   237 			aMenuPane->SetItemDimmed( EMRCommandReplyToSender,
       
   238 			                          !iMRModel->IsCmdAvailable( EMRCommandReplyToSender ) );
       
   239 			aMenuPane->SetItemDimmed( EMRCommandReplyToOrganiser,
       
   240 			                          !iMRModel->IsCmdAvailable( EMRCommandReplyToOrganiser ) );
       
   241 			aMenuPane->SetItemDimmed( EMRCommandReplyToAll,
       
   242 			                          !iMRModel->IsCmdAvailable( EMRCommandReplyToAll ) );
       
   243 			}
       
   244 		}
       
   245 	else
       
   246 		{
       
   247 		if ( aMenuId == R_MR_SUMMARYDLG_MENUPANE )
       
   248 			{		
       
   249 			aMenuPane->SetItemDimmed( EMRCommandShowAttendeesView, ETrue );
       
   250 			aMenuPane->SetItemDimmed( EMRCommandShowDescriptionView, ETrue );
       
   251             aMenuPane->SetItemDimmed( EMRCommandSend, ETrue );
       
   252             aMenuPane->SetItemDimmed( EMRCommandSendUpdate, ETrue );
       
   253             aMenuPane->SetItemDimmed( EMRCommandCancelMR, ETrue );
       
   254             aMenuPane->SetItemDimmed( EMRCommandDeleteMR, ETrue );				
       
   255 			aMenuPane->SetItemDimmed( EMRCommandRespondSubmenu, ETrue );
       
   256 			aMenuPane->SetItemDimmed( EMRCommandRemoveFromCalendar, ETrue );
       
   257 			aMenuPane->SetItemDimmed( EMRCommandReplySubmenu, ETrue );
       
   258 			aMenuPane->SetItemDimmed( EMRCommandForward, ETrue );
       
   259 			aMenuPane->SetItemDimmed( EMRCommandRetrieve, ETrue );
       
   260 			aMenuPane->SetItemDimmed( EMRCommandSaveFromFile, ETrue );			
       
   261 			aMenuPane->SetItemDimmed( EMRCommandAttachments, ETrue );
       
   262 			aMenuPane->SetItemDimmed( EMRCommandMessageDetails, ETrue );
       
   263 			aMenuPane->SetItemDimmed( EMRCommandDisableAlarm, ETrue);
       
   264 			}
       
   265 		}
       
   266     LOG("CMRSummaryDlgBase::DynInitMenuPaneL -> End");
       
   267 	}
       
   268 
       
   269 void CMRSummaryDlgBase::HandleSetModelL()
       
   270 	{
       
   271     LOG("CMRSummaryDlgBase::HandleSetModelL");				
       
   272 	if ( iListBox )
       
   273 	    { // if listbox not yet created then it's model is set later	    
       
   274         iLBModel->SetModel( *iMRModel );
       
   275         iListBox->HandleItemAdditionL();
       
   276 	    }
       
   277 	    
       
   278     __ASSERT_DEBUG( !iInfoPopup, Panic( EUnexpectedNonNull ) );
       
   279     iInfoPopup = iMRModel->CreateInfoPopupL();
       
   280     iInfoPopup->ShowInfoPopupL();
       
   281     LOG("CMRSummaryDlgBase::HandleSetModelL -> End");	    
       
   282 	}
       
   283 
       
   284 void CMRSummaryDlgBase::RefreshData()
       
   285     {
       
   286     // Listbox should definitely exist at this point
       
   287 	__ASSERT_DEBUG( iListBox, Panic( EListboxNull ) );
       
   288     TRAP_IGNORE( iListBox->HandleItemAdditionL() );
       
   289     
       
   290     // Info popup should also exist:
       
   291     __ASSERT_DEBUG( iInfoPopup, Panic( EInfopopupNull ) );    
       
   292     TRAP_IGNORE( iInfoPopup->RefreshTextL( *( iMRModel->CombinedEntry() ),
       
   293                                            iListBox->CurrentItemIndex() ) );
       
   294     }
       
   295 
       
   296 TInt CMRSummaryDlgBase::CountComponentControls() const	
       
   297 	{
       
   298 	return 1;
       
   299 	}
       
   300 	
       
   301 CCoeControl* CMRSummaryDlgBase::ComponentControl( TInt aIndex ) const 
       
   302 	{
       
   303 	switch ( aIndex )
       
   304         {
       
   305         case 0:
       
   306             return iListBox;
       
   307         default:
       
   308             return NULL;
       
   309         }
       
   310 	}
       
   311 	
       
   312 void CMRSummaryDlgBase::PreLayoutDynInitL()
       
   313 	{
       
   314     LOG("CMRSummaryDlgBase::PreLayoutDynInitL");	
       
   315 	ConstructListBoxL();
       
   316     LOG("CMRSummaryDlgBase::PreLayoutDynInitL -> End");	
       
   317 	}
       
   318 
       
   319 void CMRSummaryDlgBase::SizeChanged()
       
   320 	{	
       
   321 	if ( iListBox )
       
   322 	    {	    
       
   323 	    iListBox->SetRect( Rect() );
       
   324 	    }
       
   325 	}
       
   326 	
       
   327 TKeyResponse CMRSummaryDlgBase::OfferKeyEventL(
       
   328     const TKeyEvent& aKeyEvent, 
       
   329     TEventCode aType )
       
   330     {
       
   331     TKeyResponse retVal( EKeyWasNotConsumed );
       
   332     TInt callBackResult( KErrNone );
       
   333 
       
   334 	if ( aType == EEventKey && aKeyEvent.iCode == EKeyLeftArrow )
       
   335 		{
       
   336 		callBackResult = iHandlerCallback.ProcessCommandWithResultL(
       
   337 		    EMRCommandNavigateBackward );
       
   338 		if ( callBackResult != KErrNotSupported)
       
   339 		    {		    
       
   340 			retVal = EKeyWasConsumed;
       
   341 		    }
       
   342 		}
       
   343 	else if ( aType == EEventKey && aKeyEvent.iCode == EKeyRightArrow )
       
   344 		{
       
   345 		callBackResult = iHandlerCallback.ProcessCommandWithResultL(
       
   346 		    EMRCommandNavigateForward );
       
   347 		if ( callBackResult != KErrNotSupported )
       
   348 		    {		    
       
   349 			retVal = EKeyWasConsumed;
       
   350 		    }
       
   351 		}
       
   352 	else
       
   353 		{
       
   354 		// listbox handles the keyevent if it is not right or left arrow
       
   355 		retVal = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   356 		
       
   357 		// if navigating up or down we must switch info popup data
       
   358 		if ( aType == EEventKey && 
       
   359 		     ( aKeyEvent.iCode == EKeyUpArrow ||
       
   360 		       aKeyEvent.iCode == EKeyDownArrow ) )
       
   361             {		        
       
   362 		    iInfoPopup->RefreshTextL( *( iMRModel->CombinedEntry() ),
       
   363 		                              iListBox->CurrentItemIndex() );
       
   364             }
       
   365 		}
       
   366 	return retVal;
       
   367     }
       
   368 
       
   369 void CMRSummaryDlgBase::HandleListBoxEventL(
       
   370     CEikListBox* aListBox,
       
   371     TListBoxEvent aEventType )
       
   372 	{
       
   373 	// we mustn't accept any further events if already exiting
       
   374 	if ( aEventType == EEventEnterKeyPressed && !iIdleDialogExit->IsActive() )
       
   375 		{
       
   376 		TInt listboxCmd( EEikCmdCanceled ); // EEikCmdCanceled == 0
       
   377 		if ( aListBox->CurrentItemIndex() == EMRDescriptionItem )
       
   378 			{
       
   379 			listboxCmd = EMRCommandShowDescriptionView;
       
   380 			}
       
   381         else if ( aListBox->CurrentItemIndex() == EMRAttendeeItem )
       
   382             {
       
   383             listboxCmd = EMRCommandShowAttendeesView;
       
   384             }
       
   385             
       
   386         if ( listboxCmd != EEikCmdCanceled )
       
   387             { // either description or attendee view can be opened
       
   388 			iHandlerCallback.ProcessCommandL( listboxCmd );
       
   389 			
       
   390 			// use idle timer to exit dialog, so that it is in stable state
       
   391 			// this is required, otherwise dialog will panic
       
   392 			iIdleDialogExit->Start( TCallBack( DelayedDialogExitCallBack, this ) );
       
   393             }
       
   394 		}
       
   395 	}
       
   396 
       
   397 TInt CMRSummaryDlgBase::DelayedDialogExitCallBack( TAny* aSummaryDlg )
       
   398 	{
       
   399     LOG("CMRSummaryDlgBase::DelayedDialogExitCallBack");	    
       
   400 	CMRSummaryDlgBase* dlg = static_cast<CMRSummaryDlgBase*>( aSummaryDlg );
       
   401 	TRAP_IGNORE( dlg->TryExitL( EKeyOK ) );
       
   402     LOG("CMRSummaryDlgBase::DelayedDialogExitCallBack -> End");	    	
       
   403 	return EFalse;
       
   404 	}
       
   405 
       
   406 // ----------------------------------------------------------------------------
       
   407 // CMRSummaryDlgBase::HandleDlgExitingL
       
   408 // There are only a few commands that require special exiting action.
       
   409 // Exiting action is needed if there may be unsaved data, or if user has
       
   410 // pressed "Back" and entry needs some action. With other commands that cause
       
   411 // closing the viewer (e.g. "Respond") this kind of slow exit is not performed.
       
   412 // ----------------------------------------------------------------------------
       
   413 //
       
   414 TInt CMRSummaryDlgBase::HandleDlgExitingL( TInt aCommandId )
       
   415     {
       
   416     TInt retCmd( EEikCmdCanceled );
       
   417     if ( aCommandId == EKeyOK || 
       
   418          aCommandId == EMRCommandShowDescriptionView || 
       
   419          aCommandId == EMRCommandShowAttendeesView )
       
   420         { // opening another view, not exiting viewer -> no action
       
   421         retCmd = EEikCmdCanceled; // == no special exit action
       
   422         }
       
   423     else if ( iMRModel )
       
   424         {                           
       
   425         MMRModelInterface::TClosingStatus status( iMRModel->ClosingStatusL() );
       
   426     	if ( aCommandId == EAknSoftkeyBack )
       
   427             {
       
   428         	if ( status == MMRModelInterface::ENotResponded )
       
   429         		{
       
   430         		retCmd = HandleDlgExitingResponseL();
       
   431         		}
       
   432             else
       
   433                 {                
       
   434                 retCmd = EMRCommandExitDialogs;
       
   435                 }
       
   436             }
       
   437         else if ( aCommandId == EAknSoftkeyDone )
       
   438     	    {	    
       
   439     	    if ( status == MMRModelInterface::ENotSaved )
       
   440     	        {
       
   441     	        retCmd = EMRCommandSaveAndExit;
       
   442     	        }
       
   443     	    else if ( status == MMRModelInterface::ENotSentNew )
       
   444     	        {
       
   445     	        retCmd = EMRCommandSend;
       
   446     	        }
       
   447     	    else if ( status == MMRModelInterface::ENotSentUpdate )
       
   448     	        {
       
   449     	        retCmd = EMRCommandSendUpdate;
       
   450     	        }
       
   451             else
       
   452                 {                
       
   453                 retCmd = EMRCommandExitDialogs;
       
   454                 }    	        	    
       
   455     	    }
       
   456         else if ( aCommandId == EAknCmdExit || aCommandId == EEikCmdExit )
       
   457             { // quiet mode, quick exit -> just save if needed
       
   458     	    if ( status == MMRModelInterface::ENotSaved )
       
   459     	        {
       
   460     	        retCmd = EMRCommandSaveAndExit;
       
   461     	        }        
       
   462             }
       
   463         }
       
   464     return retCmd;
       
   465     }
       
   466 	
       
   467 // ----------------------------------------------------------------------------
       
   468 // CMRSummaryDlgBase::HandleDlgExitingResponseL
       
   469 // 
       
   470 // ----------------------------------------------------------------------------
       
   471 //
       
   472 TInt CMRSummaryDlgBase::HandleDlgExitingResponseL()
       
   473     {
       
   474     TInt retCmd( 0 );    
       
   475 	TInt actionIndex( -1 );
       
   476 	CAknListQueryDialog* dlg =
       
   477 	    new( ELeave ) CAknListQueryDialog( &actionIndex );
       
   478     dlg->PrepareLC( R_NOT_RESPONDED_LIST_QUERY );
       
   479     if ( !iMRModel->IsCmdAvailable( EMRCommandDeleteMR ) )
       
   480         { // we set another text array if cannot allow delete
       
   481         MDesCArray* listArray = iCoeEnv->ReadDesCArrayResourceL(
       
   482             R_NOT_RESPONDED_ITEM_LIST_ARRAY_NO_DELETE );                    
       
   483         dlg->SetItemTextArray( listArray );
       
   484         dlg->SetOwnershipType( ELbmOwnsItemArray );
       
   485         }
       
   486         
       
   487     if ( dlg->RunLD() )
       
   488         {                
       
   489         if ( actionIndex == 0 )
       
   490             { // respond
       
   491 	        TInt statusIndex( -1 );
       
   492 	        CAknListQueryDialog* statusDlg =
       
   493 	            new( ELeave ) CAknListQueryDialog( &statusIndex );
       
   494             if ( statusDlg->ExecuteLD( R_RESPOND_LIST_QUERY ) )
       
   495                 {
       
   496                 if ( statusIndex == 0 )
       
   497                     {
       
   498                     retCmd = EMRCommandRespondAccept;
       
   499                     }
       
   500                 else if ( statusIndex == 1 )
       
   501                     {
       
   502                     retCmd = EMRCommandRespondTentative;
       
   503                     }
       
   504                 else
       
   505                     {
       
   506                     retCmd = EMRCommandRespondDecline;
       
   507                     }
       
   508                 }
       
   509             }
       
   510         else if ( actionIndex == 1 )
       
   511             { // do not respond
       
   512             retCmd = EMRCommandExitDialogs;
       
   513             }
       
   514         else
       
   515             { // delete request
       
   516             CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   517             if ( dlg->ExecuteLD( R_CONFIRM_DELETE_FROM_CALENDAR ) )
       
   518                 {
       
   519                 retCmd = EMRCommandRemoveFromCalendar;
       
   520                 }
       
   521             }
       
   522         }
       
   523     return retCmd;
       
   524     }
       
   525 	
       
   526 // ============================ MEMBER FUNCTIONS ==============================
       
   527 // ----------------------------------------------------------------------------
       
   528 // CAttendeeLBModel::NewL
       
   529 // Two-phased constructor.
       
   530 // ----------------------------------------------------------------------------
       
   531 //
       
   532 CMRSummaryListBoxModel* CMRSummaryListBoxModel::NewL( CEikonEnv* aEnv )
       
   533     {
       
   534     CMRSummaryListBoxModel* self = new( ELeave )CMRSummaryListBoxModel( aEnv );
       
   535     CleanupStack::PushL( self );
       
   536     self->ConstructL();
       
   537     CleanupStack::Pop( self );
       
   538     return self;
       
   539     }
       
   540 
       
   541 // ---------------------------------------------------------
       
   542 // CAttendeeLBModel::ConstructL
       
   543 // ---------------------------------------------------------
       
   544 //
       
   545 void CMRSummaryListBoxModel::ConstructL()
       
   546     {    
       
   547     iBuffer = HBufC::NewL( 256 ); // TODO: magic number
       
   548     
       
   549     iNoSubjectText =
       
   550         StringLoader::LoadL( R_QTN_CALE_SUMMARY_DESCRIPTION_NO_SUBJECT, iEnv );
       
   551     iAttendeesText =
       
   552         StringLoader::LoadL( R_QTN_CALE_SUMMARY_ATTENDEES, iEnv );
       
   553     iNoInvitedAttendeesText =
       
   554         StringLoader::LoadL( R_QTN_CALE_NO_INVITED_ATTENDEES, iEnv );
       
   555     }
       
   556 
       
   557 // ----------------------------------------------------------------------------
       
   558 // CAttendeeLBModel::CAttendeeLBModel
       
   559 // C++ default constructor can NOT contain any code, that
       
   560 // might leave.
       
   561 // ----------------------------------------------------------------------------
       
   562 //
       
   563 CMRSummaryListBoxModel::CMRSummaryListBoxModel( CEikonEnv* aEnv )
       
   564     : iEnv( aEnv )
       
   565     {
       
   566     }
       
   567 
       
   568 // ---------------------------------------------------------
       
   569 // CAttendeeLBModel::~CAttendeeLBModel
       
   570 // ---------------------------------------------------------
       
   571 //
       
   572 CMRSummaryListBoxModel::~CMRSummaryListBoxModel()
       
   573     {
       
   574     delete iBuffer;    
       
   575     delete iNoSubjectText;
       
   576     delete iAttendeesText;
       
   577     delete iNoInvitedAttendeesText;
       
   578     delete iInvitedAttendees;
       
   579     }
       
   580 
       
   581 
       
   582 
       
   583 void CMRSummaryListBoxModel::SetModel( MMRModelInterface& aMRModel )
       
   584     {
       
   585     iMRModel = &aMRModel;    
       
   586     }
       
   587 
       
   588 // ---------------------------------------------------------
       
   589 // CAttendeeLBModel::MdcaCount
       
   590 // ---------------------------------------------------------
       
   591 //
       
   592 TInt CMRSummaryListBoxModel::MdcaCount() const
       
   593     {    
       
   594     return 2;
       
   595     }
       
   596 
       
   597 // ---------------------------------------------------------
       
   598 // CAttendeeLBModel::MdcaPoint
       
   599 // ---------------------------------------------------------
       
   600 //
       
   601 TPtrC16 CMRSummaryListBoxModel::MdcaPoint( TInt aIndex ) const
       
   602     {
       
   603     TPtr ptr( iBuffer->Des() );
       
   604     ptr.Zero();
       
   605     
       
   606     if ( iMRModel )
       
   607     	{
       
   608     	if ( aIndex == EMRDescriptionItem )
       
   609     		{
       
   610     		AppendDescriptionIcon( ptr );
       
   611     		// TODO: investigate if trapping is proper way of handling error here
       
   612     		TRAP_IGNORE( 
       
   613     		    {
       
   614     		    AppendDescriptionPrimaryL( ptr );
       
   615     		    AppendDescriptionSecondaryL( ptr );
       
   616     		    } );
       
   617     		}
       
   618     	else if ( aIndex == EMRAttendeeItem )
       
   619     		{
       
   620     		AppendAttendeeIcon( ptr );
       
   621     		AppendAttendeePrimary( ptr );
       
   622     		TRAP_IGNORE( AppendAttendeeSecondaryL( ptr ) );
       
   623     		}
       
   624     	}
       
   625     else
       
   626     	{
       
   627     	if ( aIndex == EMRDescriptionItem )
       
   628     		{
       
   629        		ptr.AppendNum( 0 );
       
   630     		ptr.Append( EKeyTab );
       
   631     		ptr.Append( *iNoSubjectText );
       
   632     		ptr.Append( EKeyTab );
       
   633        		}
       
   634     		
       
   635    		else if ( aIndex == EMRAttendeeItem )
       
   636    			{
       
   637    			ptr.AppendNum( 0 );
       
   638     		ptr.Append( EKeyTab );
       
   639     		ptr.Append( *iAttendeesText );
       
   640     		ptr.Append( EKeyTab );
       
   641     		ptr.Append( *iNoInvitedAttendeesText );
       
   642    			}
       
   643     	}	    
       
   644     return iBuffer->Des();
       
   645     }
       
   646 
       
   647 void CMRSummaryListBoxModel::AppendDescriptionIcon( TPtr& aPtr ) const
       
   648 	{
       
   649 	aPtr.AppendNum( 0 );
       
   650 	}
       
   651 void CMRSummaryListBoxModel::AppendDescriptionPrimaryL( TPtr& aPtr ) const
       
   652 	{
       
   653 	__ASSERT_DEBUG( iMRModel, Panic( EUnexpectedNullMRModel ) );
       
   654 	
       
   655 	CCalEntry* entry = iMRModel->CombinedEntry();
       
   656 	
       
   657 	const TDesC& description = entry->SummaryL();
       
   658 	aPtr.Append( EKeyTab );
       
   659 	if ( description.Length() > 0 )
       
   660 		{
       
   661 		aPtr.Append( description );
       
   662 		}
       
   663 	else
       
   664 		{
       
   665 		aPtr.Append( *iNoSubjectText );
       
   666 		}
       
   667 		
       
   668 	}
       
   669 void CMRSummaryListBoxModel::AppendDescriptionSecondaryL( TPtr& aPtr ) const
       
   670 	{
       
   671 	__ASSERT_DEBUG( iMRModel, Panic( EUnexpectedNullMRModel ) );
       
   672 		
       
   673 	CCalEntry* entry = iMRModel->CombinedEntry();
       
   674 	
       
   675 	const TDesC& location = entry->LocationL();
       
   676 	
       
   677 	aPtr.Append( EKeyTab );
       
   678 	aPtr.Append( location );
       
   679 	}
       
   680 
       
   681 void CMRSummaryListBoxModel::AppendAttendeeIcon( TPtr& aPtr ) const
       
   682 	{
       
   683 	aPtr.AppendNum( 1 );
       
   684 	}
       
   685 	
       
   686 void CMRSummaryListBoxModel::AppendAttendeePrimary( TPtr& aPtr ) const
       
   687 	{
       
   688 	aPtr.Append( EKeyTab );
       
   689 	aPtr.Append( *iAttendeesText );
       
   690 	}
       
   691 	
       
   692 void CMRSummaryListBoxModel::AppendAttendeeSecondaryL( TPtr& aPtr ) const 
       
   693 	{
       
   694 	__ASSERT_DEBUG( iMRModel, Panic( EUnexpectedNullMRModel ) );
       
   695 		
       
   696 	CCalEntry* entry = iMRModel->CombinedEntry();
       
   697 	TInt attendeeCount = entry->AttendeesL().Count();
       
   698 	
       
   699 	aPtr.Append( EKeyTab );
       
   700 	if ( iInvitedAttendees )
       
   701 	    {	    
       
   702 		delete iInvitedAttendees;
       
   703 		iInvitedAttendees = NULL;
       
   704 	    }
       
   705 	iInvitedAttendees = StringLoader::LoadL( R_QTN_CALE_INVITED_ATTENDEES,
       
   706 	                                         attendeeCount, 
       
   707 	                                         iEnv );
       
   708 	
       
   709 	if ( attendeeCount > 0 )
       
   710 		{
       
   711 		aPtr.Append( *iInvitedAttendees );
       
   712 		}
       
   713 	else
       
   714 		{
       
   715 		aPtr.Append( _L("No attendees") );
       
   716 		}
       
   717 	}
       
   718 
       
   719 
       
   720 //  End of File
       
   721