meetingui/meetingrequestutils/src/MREntryConsultant.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:   Static helper methods for analyzing entries
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "MREntryConsultant.h"
       
    23 #include "MRHelpers.h"
       
    24 #include <calentry.h>
       
    25 #include <caltime.h>
       
    26 #include <calrrule.h>
       
    27 #include <caluser.h>
       
    28 #include <msvids.h>
       
    29 #include "CMRUtilsInternal.h"
       
    30 #include <MsgMailUIDs.h>
       
    31 #include <cmrmailboxutils.h>
       
    32 
       
    33 // CONSTANTS
       
    34 
       
    35 /// Unnamed namespace for local definitions
       
    36 namespace {
       
    37     
       
    38 }  // namespace
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 
       
    43 TMsvId MREntryConsultant::SendingMailBoxL(
       
    44     const MAgnEntryUi::TAgnEntryUiInParams& aInParams,
       
    45     CMRMailboxUtils& aUtils )
       
    46 	{
       
    47 	if ( aInParams.iCallingApp.iUid == KUidMsgMailViewer )
       
    48 	    {
       
    49         return aInParams.iMailBoxId;	    
       
    50 	    }
       
    51     else
       
    52         {
       
    53         CMRMailboxUtils::TMailboxInfo info;
       
    54         // returns KMsvNullIndexEntryId if default box cannot be resolved:
       
    55         aUtils.GetDefaultMRMailBoxL( info );
       
    56         return info.iEntryId;
       
    57         }
       
    58 	}
       
    59 
       
    60 TBool MREntryConsultant::IsRepeatingMeetingL( const CCalEntry& aEntry )
       
    61     {
       
    62     TBool retVal( EFalse );
       
    63         
       
    64     if ( IsModifyingEntryL( aEntry ) )
       
    65         {
       
    66         retVal = ETrue;
       
    67         }
       
    68     else
       
    69         {
       
    70         TCalRRule dummyRule;
       
    71         if ( aEntry.GetRRuleL( dummyRule ) )
       
    72             {
       
    73             retVal = ETrue;
       
    74             }
       
    75         else
       
    76             {            
       
    77             RArray<TCalTime> dummyRDateList;
       
    78             CleanupClosePushL( dummyRDateList );
       
    79             aEntry.GetRDatesL( dummyRDateList );
       
    80             if ( dummyRDateList.Count() > 0 )
       
    81                 {
       
    82                 retVal = ETrue;
       
    83                 }
       
    84             CleanupStack::PopAndDestroy(); // dummyRDateList
       
    85             }
       
    86         }
       
    87     return retVal;
       
    88     }
       
    89 
       
    90 TBool MREntryConsultant::IsModifyingEntryL( const CCalEntry& aEntry )
       
    91     {
       
    92     return ( aEntry.RecurrenceIdL().TimeUtcL() !=
       
    93              Time::NullTTime() ) ? ETrue : EFalse;
       
    94     } 
       
    95 
       
    96 
       
    97 TBool MREntryConsultant::IsEditedL(
       
    98     const CCalEntry& aEntry,
       
    99     CMRUtilsInternal& aUtils )
       
   100     {
       
   101     TBool retVal( EFalse );
       
   102     CCalEntry* dbEntry = aUtils.FetchEntryL( aEntry.UidL(), 
       
   103                                              aEntry.RecurrenceIdL() );
       
   104     CleanupStack::PushL( dbEntry );
       
   105     if ( dbEntry )
       
   106         { // edited if differs from the db entry
       
   107         retVal = !( aEntry.CompareL( *dbEntry ) );
       
   108         }
       
   109     else
       
   110         { // no db entry exists -> edited
       
   111         retVal = ETrue;
       
   112         }            
       
   113     CleanupStack::PopAndDestroy( dbEntry );
       
   114     return retVal;
       
   115     }
       
   116 
       
   117 TBool MREntryConsultant::IsSentL( const CCalEntry& aEntry )
       
   118     {
       
   119     TBool retVal( EFalse );
       
   120     if ( aEntry.StatusL() != CCalEntry::ENullStatus )
       
   121         { // When we send a request for the first time we set it's status to
       
   122           // some other value than ENullStatus
       
   123         retVal = ETrue;
       
   124         }
       
   125     return retVal;
       
   126     }
       
   127 
       
   128 TBool MREntryConsultant::IsLatestSavedSentL(
       
   129     const CCalEntry& aEntry )
       
   130     {
       
   131     TBool retVal( EFalse );
       
   132     if ( aEntry.DTStampL().TimeUtcL() == Time::NullTTime() )
       
   133         {
       
   134         // If entries are synchronized to phone we must always assume that
       
   135         // they have been sent already. In case of our own requests we keep the
       
   136         // DTSTAMP as null until sending.    
       
   137 
       
   138         retVal = ETrue;
       
   139         }    
       
   140     return retVal;
       
   141     }
       
   142 
       
   143 TBool MREntryConsultant::IsCancelledL(
       
   144     const CCalEntry& aEntry,
       
   145     CMRMailboxUtils& aUtils )
       
   146     {
       
   147     TBool retVal( EFalse );
       
   148     // Check if either entire meeting is cancelled, or this attendee
       
   149     // has been removed from the participant list. According to RFC2446
       
   150     // in that case entry doesn't have status field set.
       
   151     if ( aEntry.StatusL() == CCalEntry::ECancelled ||
       
   152          ( aEntry.MethodL() == CCalEntry::EMethodCancel &&
       
   153          !aUtils.ThisAttendeeL( aEntry ) ) )
       
   154         {
       
   155         retVal = ETrue;
       
   156         }
       
   157     return retVal;
       
   158     }
       
   159 
       
   160 TBool MREntryConsultant::ExistsInDbL(
       
   161     const CCalEntry& aEntry,
       
   162     CMRUtilsInternal& aUtils,
       
   163     TBool aStrictMode )
       
   164     {
       
   165     TInt retVal( EFalse );
       
   166     CCalEntry* dbEntry = aUtils.FetchEntryL( aEntry.UidL(), 
       
   167                                              aEntry.RecurrenceIdL() );
       
   168     if ( dbEntry )
       
   169         {
       
   170         CleanupStack::PushL( dbEntry );
       
   171         if ( aStrictMode )
       
   172             {
       
   173             TInt seq( aEntry.SequenceNumberL() );
       
   174             TInt dbSeq( dbEntry->SequenceNumberL() );
       
   175             TTime stamp = aEntry.DTStampL().TimeUtcL();
       
   176             TTime dbStamp = dbEntry->DTStampL().TimeUtcL();            
       
   177             if ( ( seq == dbSeq ) && ( stamp == dbStamp ) )
       
   178                 {
       
   179                 retVal = ETrue;
       
   180                 }
       
   181             }
       
   182         else
       
   183             {
       
   184             retVal = ETrue;
       
   185             }
       
   186         CleanupStack::PopAndDestroy( dbEntry ); 
       
   187         }    
       
   188     return retVal;
       
   189     }
       
   190 
       
   191 TBool MREntryConsultant::IsEntryOutOfDateL( const CCalEntry& aEntry )
       
   192 	{
       
   193 	TBool retVal( EFalse );
       
   194 	TTime universalTime;
       
   195 	universalTime.UniversalTime();
       
   196 	TTime meetingUniversalTime = aEntry.StartTimeL().TimeUtcL();
       
   197 	if ( universalTime  > meetingUniversalTime )
       
   198 	    {	    
       
   199 		retVal = ETrue;
       
   200 	    }
       
   201 	return retVal;
       
   202 	}
       
   203 
       
   204 const TDesC& MREntryConsultant::PhoneOwnerAddrL(
       
   205     const CCalEntry& aEntry,
       
   206     CMRMailboxUtils& aUtils )
       
   207 	{
       
   208 	if ( aUtils.IsOrganizerL( aEntry ) )
       
   209 	    {
       
   210 	    return aEntry.OrganizerL()->Address();	    
       
   211 	    }
       
   212     else
       
   213 	    {	        
       
   214     	CCalAttendee* thisAttendee = aUtils.ThisAttendeeL( aEntry  );	
       
   215     	if ( thisAttendee )
       
   216     	    {	    
       
   217     		return thisAttendee->Address();
       
   218     	    }
       
   219     	else
       
   220     	    {	    
       
   221     		return KNullDesC;
       
   222     	    }
       
   223 	    }
       
   224 	}
       
   225 
       
   226 CCalAttendee* MREntryConsultant::EqualAttendeeL(
       
   227     const CCalAttendee& aAttendee,
       
   228     const CCalEntry& aEntry )
       
   229     {
       
   230 	TPtrC addr = MRHelpers::AddressWithoutMailtoPrefix( aAttendee.Address() );
       
   231     RPointerArray<CCalAttendee>& attendees = aEntry.AttendeesL();
       
   232     TInt count( attendees.Count() );
       
   233 	for ( TInt i ( 0 ); i < count; ++i )
       
   234 		{
       
   235 		TPtrC testAddr =
       
   236 		    MRHelpers::AddressWithoutMailtoPrefix( attendees[i]->Address() );
       
   237 		if ( addr.CompareF( testAddr ) == 0 )
       
   238 		    {
       
   239 		    return attendees[i];
       
   240 		    }
       
   241 		}
       
   242     return NULL;
       
   243     }
       
   244 
       
   245 TBool MREntryConsultant::SpansManyDaysL(
       
   246     const TCalTime& aStartTime,
       
   247     const TCalTime& aEndTime )
       
   248 	{
       
   249 	TBool retVal( EFalse );
       
   250 		
       
   251     // mustn't use UTC time here, local time specifies if the midnight
       
   252     // is crossed
       
   253 	TTime localStartTime = aStartTime.TimeLocalL();
       
   254 	TTime localEndTime = aEndTime.TimeLocalL();
       
   255 	
       
   256 	TTimeIntervalDays days = localEndTime.DaysFrom( localStartTime );
       
   257 	
       
   258 	if ( days.Int() > 0 )
       
   259 		{
       
   260 		retVal = ETrue;
       
   261 		}
       
   262 	return retVal;
       
   263 	}
       
   264 
       
   265 //  End of File