meetingui/meetingrequestviewers/src/CMRRequestModel.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:   Model for method REQUEST
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CMRRequestModel.h"
       
    22 #include "CMRModelBase.h"
       
    23 #include "MMRDataFillerInterface.h"
       
    24 #include "MREntryConsultant.h"
       
    25 #include "CMRDataFillerMeetingRequest.h"
       
    26 #include "meetingrequestviewers.hrh"
       
    27 #include "MRViewersPanic.h"
       
    28 #include "ICalUILog.h"
       
    29 #include "CMRProcessor.h"
       
    30 #include "CMRUtilsInternal.h"
       
    31 #include "ProcessingStructs.h" //meeting request scenarios
       
    32 #include <eikenv.h> //CEikonEnv
       
    33 #include <CRichBio.h> //rich bio
       
    34 #include <MsgMailUIDs.h> //uid for mail application
       
    35 #include <MRCommands.hrh> // meeting request common commands
       
    36 #include <senduimtmuids.h> //mailbox id's
       
    37 #include <stringloader.h> //loading of string resources
       
    38 #include <meetingrequestviewersuires.rsg> //resource definitions
       
    39 #include <cmrmailboxutils.h>
       
    40 
       
    41 // CONSTANTS
       
    42 /// Unnamed namespace for local definitions
       
    43 namespace {
       
    44 
       
    45 _LIT( KPanicMsg, "CMRRequestModel" );
       
    46 
       
    47 void Panic( TPanicCode aReason )
       
    48     {
       
    49     User::Panic( KPanicMsg, aReason );
       
    50     }
       
    51 
       
    52 }  // namespace
       
    53 
       
    54 // ============================ MEMBER FUNCTIONS ===============================
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // ?classname::?classname
       
    58 // C++ default constructor can NOT contain any code, that
       
    59 // might leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CMRRequestModel::CMRRequestModel(
       
    63     CMRMailboxUtils& aMRMailboxUtils,
       
    64     CMRUtilsInternal& aMRUtils,
       
    65     const MAgnEntryUi::TAgnEntryUiInParams& aInParams )
       
    66     : CMRModelBase( aMRMailboxUtils, aMRUtils, aInParams )
       
    67     {
       
    68     
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // ?classname::ConstructL
       
    73 // Symbian 2nd phase constructor can leave.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 void CMRRequestModel::ConstructL( RPointerArray<CCalEntry>& aEntries )
       
    77     {
       
    78     CMRModelBase::ConstructL( aEntries );
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // ?classname::NewL
       
    83 // Two-phased constructor.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CMRRequestModel* CMRRequestModel::NewL(
       
    87     RPointerArray<CCalEntry>& aEntries,
       
    88     CMRMailboxUtils& aMRMailboxUtils,
       
    89     CMRUtilsInternal& aMRUtils,
       
    90     const MAgnEntryUi::TAgnEntryUiInParams& aInParams )
       
    91     {
       
    92     CMRRequestModel* self = new( ELeave ) CMRRequestModel( aMRMailboxUtils,
       
    93                                                            aMRUtils,
       
    94                                                            aInParams );
       
    95 
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL( aEntries );
       
    98     CleanupStack::Pop();
       
    99 
       
   100     return self;
       
   101     }
       
   102 
       
   103 // Destructor
       
   104 CMRRequestModel::~CMRRequestModel()
       
   105     {
       
   106     }
       
   107 
       
   108 MMRModelInterface::TClosingStatus CMRRequestModel::ClosingStatusL()
       
   109 	{
       
   110 	TClosingStatus retVal( ENone );
       
   111 	const CCalEntry& request = *( CombinedEntry() );
       
   112 	
       
   113     if ( iMRProcessor->OwnerRole() == CMRProcessor::EOrganiser )
       
   114         { // We are an organizer -> check savind & sending statuses
       
   115         if ( IsEntryEdited() )
       
   116             { // user has edited the request somehow
       
   117             if ( IsSendableL( request ) )
       
   118                 {
       
   119                 if ( MREntryConsultant::IsSentL( request ) )
       
   120                     { // edited, i.e. an update request
       
   121                     retVal = ENotSentUpdate;
       
   122                     }
       
   123                 else
       
   124                     { // completely new request
       
   125                     retVal = ENotSentNew;
       
   126                     }
       
   127                 }
       
   128             else
       
   129                 { // not sendable, just save the request
       
   130                 retVal = ENotSaved;
       
   131                 }
       
   132             }
       
   133         }        
       
   134 	else
       
   135 	    { // Not organizer -> check if response should be proposed
       
   136     	CCalAttendee* attendee = iMRMailboxUtils.ThisAttendeeL( request );
       
   137     	if ( IsEntryUsableL( request ) && attendee )
       
   138     		{
       
   139     		CCalAttendee::TCalStatus status( attendee->StatusL() );
       
   140     		if ( status == CCalAttendee::ENeedsAction )
       
   141     		    {
       
   142     		    retVal = ENotResponded;
       
   143     		    }
       
   144     		}
       
   145 	    }		
       
   146 	return retVal;
       
   147 	}
       
   148 
       
   149 MMRDataFillerInterface* CMRRequestModel::DataFillerL( CRichBio* aRichBio )
       
   150 	{
       
   151 	__ASSERT_DEBUG( aRichBio, Panic( ECRichBioNull ) );
       
   152 	return CMRDataFillerMeetingRequest::NewL( *aRichBio,
       
   153 	                                          *this,
       
   154 	                                          *CEikonEnv::Static(),
       
   155 	                                          iMRMailboxUtils,
       
   156 	                                          iInParams );
       
   157 	}
       
   158 
       
   159 TBool CMRRequestModel::IsCmdAvailableL( TInt aCommandId )
       
   160     {
       
   161     TInt retVal( EFalse );
       
   162     switch ( aCommandId )
       
   163         {
       
   164         case EMRCommandSend:
       
   165             {
       
   166             retVal = CanSendL();
       
   167             break;
       
   168             }
       
   169         case EMRCommandSendUpdate:
       
   170             {
       
   171             retVal = CanSendUpdateL();
       
   172             break;
       
   173             }
       
   174         case EMRCommandCancelMR:
       
   175             {
       
   176             retVal = CanCancelMRL();            
       
   177             break;
       
   178             }
       
   179         case EMRCommandDeleteMR:
       
   180             {
       
   181             retVal = CanDeleteMRL();            
       
   182             break;
       
   183             }
       
   184         case EMRCommandRespondAccept:
       
   185         case EMRCommandRespondTentative:
       
   186         case EMRCommandRespondDecline:                
       
   187             {
       
   188             retVal = CanRespondL( aCommandId );            
       
   189             break;
       
   190             }
       
   191         case EMRCommandReplyToOrganiser:
       
   192             {
       
   193             retVal = CanReplyToOrganiserL();            
       
   194             break;
       
   195             }
       
   196         case EMRCommandReplyToSender:
       
   197             {
       
   198             retVal = CanReplyToSenderL();            
       
   199             break;
       
   200             }
       
   201         case EMRCommandReplyToAll:
       
   202             {
       
   203             retVal = CanReplyToAllL();            
       
   204             break;
       
   205             }
       
   206         case EMRCommandForward:
       
   207             {
       
   208             retVal = CanForwardL();            
       
   209             break;
       
   210             }       
       
   211         default:
       
   212             {
       
   213             retVal = CMRModelBase::IsCmdAvailableL( aCommandId );
       
   214             break;
       
   215             }                                     
       
   216         }
       
   217     return retVal;
       
   218     }
       
   219 
       
   220 TBool CMRRequestModel::CanSendL()
       
   221     { 
       
   222     TBool retVal( EFalse );   
       
   223 	const CCalEntry& request = *( CombinedEntry() );     
       
   224     if ( iInParams.iCallingApp.iUid == KUidCalendarApplication )
       
   225 		{
       
   226         // Return ETrue if request is sendable, but hasn't been sent at all
       
   227         retVal = ( IsSendableL( request ) &&
       
   228                    !MREntryConsultant::IsSentL( request ) );
       
   229 		}
       
   230     return retVal;
       
   231     }
       
   232 
       
   233 TBool CMRRequestModel::CanSendUpdateL()
       
   234     {
       
   235     // Return ETrue if request is sendable but has been sent already
       
   236     TBool retVal( EFalse );  
       
   237 	const CCalEntry& request = *( CombinedEntry() );      
       
   238     if ( iInParams.iCallingApp.iUid == KUidCalendarApplication )
       
   239 		{
       
   240         // Return ETrue if request is sendable, is an update in nature,
       
   241         // but updated content hasn't been sent yet
       
   242         TBool unsentEdits = IsEntryEdited() ||
       
   243                             !MREntryConsultant::IsLatestSavedSentL( request );                                    
       
   244         retVal = ( IsSendableL( request ) &&
       
   245                    MREntryConsultant::IsSentL( request ) &&
       
   246                    unsentEdits );
       
   247 		}
       
   248     return retVal;
       
   249     }
       
   250     
       
   251 TBool CMRRequestModel::CanCancelMRL()
       
   252     {
       
   253     TBool retVal( EFalse );
       
   254 	const CCalEntry& request = *( CombinedEntry() );     
       
   255     if ( iInParams.iCallingApp.iUid == KUidCalendarApplication &&
       
   256          iMRProcessor->OwnerRole() == CMRProcessor::EOrganiser )
       
   257 		{
       
   258         // can cancel if at least one version of the request has been sent
       
   259         // and request is ok
       
   260         retVal = ( IsEntryUsableL( request ) &&
       
   261                    MREntryConsultant::IsSentL( request ) );
       
   262         }
       
   263     return retVal;    
       
   264     }
       
   265     
       
   266 TBool CMRRequestModel::CanDeleteMRL()
       
   267     {
       
   268     TBool retVal( EFalse );
       
   269 	const CCalEntry& request = *( CombinedEntry() );
       
   270     if ( iInParams.iCallingApp.iUid == KUidCalendarApplication &&
       
   271          MREntryConsultant::ExistsInDbL( request, iMRUtils ) )
       
   272 		{
       
   273 		if ( iMRProcessor->OwnerRole() == CMRProcessor::EOrganiser )
       
   274 		    {		    
       
   275             // deletion is shown when cancellation not and vice versa
       
   276             retVal = !CanCancelMRL();    
       
   277 		    }
       
   278         else
       
   279             { // if not organizer then can delete
       
   280             retVal = ETrue;
       
   281             }
       
   282         }  
       
   283     return retVal;        
       
   284     }
       
   285 
       
   286 TBool CMRRequestModel::CanRespondL( TInt aCommandId )
       
   287 	{
       
   288 	TBool retVal( EFalse );
       
   289 	const CCalEntry& request = *( CombinedEntry() );
       
   290     CCalAttendee* attendee = iMRMailboxUtils.ThisAttendeeL( request );
       
   291     if ( IsEntryUsableL( request ) && attendee )
       
   292         {
       
   293         CCalAttendee::TCalStatus status( attendee->StatusL() );
       
   294         if ( aCommandId == EMRCommandRespondAccept &&
       
   295              ( status != CCalAttendee::EAccepted ||
       
   296                status != CCalAttendee::EConfirmed ) )
       
   297             {
       
   298             retVal = ETrue;
       
   299             }
       
   300         else if ( aCommandId == EMRCommandRespondTentative &&
       
   301                   status != CCalAttendee::ETentative )
       
   302             {
       
   303             retVal = ETrue;
       
   304             }
       
   305         else if ( aCommandId == EMRCommandRespondDecline &&
       
   306                   status != CCalAttendee::EDeclined )
       
   307             {
       
   308             retVal = ETrue;
       
   309             }            
       
   310         }
       
   311 	return retVal;
       
   312 	}	
       
   313 
       
   314 TBool CMRRequestModel::CanReplyToOrganiserL()
       
   315     {
       
   316     TBool retVal( EFalse );
       
   317     if ( iMRProcessor->OwnerRole() != CMRProcessor::EOrganiser )
       
   318         {        
       
   319         retVal = ETrue;
       
   320         }
       
   321 	return retVal;
       
   322     }
       
   323 
       
   324 TBool CMRRequestModel::CanReplyToSenderL()
       
   325     {    
       
   326     TBool retVal( EFalse );    
       
   327 	if ( iInParams.iCallingApp.iUid == KUidMailApplication )
       
   328 		{
       
   329         if ( iMRProcessor->OwnerRole() != CMRProcessor::EOrganiser )
       
   330             { // can reply to sender if sender is not also organizer
       
   331             retVal =!IsSenderOrganizerL();
       
   332             }
       
   333 		}
       
   334 	return retVal;
       
   335     }
       
   336 
       
   337 TBool CMRRequestModel::CanReplyToAllL()
       
   338     {    
       
   339 	return ETrue;
       
   340     }
       
   341 
       
   342 TBool CMRRequestModel::CanForwardL()
       
   343 	{
       
   344 	LOG("CMRRequestModel::CanForwardL");
       
   345 	TBool retVal( EFalse );
       
   346 	const CCalEntry& request = *( CombinedEntry() );	
       
   347 	if ( iInParams.iCallingApp.iUid == KUidMailApplication &&
       
   348 	     IsEntryUsableL( request ) )
       
   349 		{
       
   350 		LOG("CMRRequestModel::CanForwardL returning ETrue");
       
   351         return ETrue;
       
   352 		}
       
   353     LOG("CMRRequestModel::CanForwardL -> End");
       
   354 	return retVal;
       
   355 	}
       
   356 
       
   357 //  End of File