meetingrequest/mrcommon/src/esmrentryhelper.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Static helper methods for analyzing entries
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "emailtrace.h"
       
    22 #include "esmrentryhelper.h"
       
    23 #include "esmrhelper.h"
       
    24 #include "esmrdef.h"
       
    25 
       
    26 // From System
       
    27 #include <calentry.h>
       
    28 #include <caltime.h>
       
    29 #include <calrrule.h>
       
    30 #include <caluser.h>
       
    31 #include <msvids.h>
       
    32 #include <MsgMailUIDs.h>
       
    33 #include <cmrmailboxutils.h>
       
    34 #include <CalenInterimUtils2.h>
       
    35 
       
    36 // unnamed naespace for local definitions
       
    37 namespace { // codescanner::namespace
       
    38 
       
    39 // Definition for zero interval
       
    40 const TInt KZeroInterval( 0 );
       
    41 
       
    42 }
       
    43 
       
    44 // ======== MEMBER FUNCTIONS ========
       
    45 
       
    46 // ----------------------------------------------------------------------------
       
    47 // ESMREntryHelper::SendingMailBoxL
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 EXPORT_C TMsvId ESMREntryHelper::SendingMailBoxL(
       
    51     const MAgnEntryUi::TAgnEntryUiInParams& aInParams,
       
    52     CMRMailboxUtils& aUtils )
       
    53     {
       
    54     FUNC_LOG;
       
    55     TMsvId result(0); 
       
    56     if ( aInParams.iCallingApp.iUid == KUidMsgMailViewer )
       
    57         {
       
    58         result = aInParams.iMailBoxId;
       
    59         }
       
    60     else
       
    61         {
       
    62         CMRMailboxUtils::TMailboxInfo info;
       
    63         // returns KMsvNullIndexEntryId if default box cannot be resolved:
       
    64         aUtils.GetDefaultMRMailBoxL( info );
       
    65         result = info.iEntryId;
       
    66         }
       
    67     return result;
       
    68     }
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // ESMREntryHelper::IsRepeatingMeetingL
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C TBool ESMREntryHelper::IsRepeatingMeetingL(
       
    75         const CCalEntry& aEntry )
       
    76     {
       
    77     FUNC_LOG;
       
    78 
       
    79     TBool retVal( EFalse );
       
    80 
       
    81     if ( IsModifyingEntryL( aEntry ) )
       
    82         {
       
    83 
       
    84         retVal = ETrue;
       
    85         }
       
    86     else
       
    87         {
       
    88         TCalRRule dummyRule;
       
    89         if ( aEntry.GetRRuleL( dummyRule ) )
       
    90             {
       
    91 
       
    92             retVal = ETrue;
       
    93             }
       
    94         else
       
    95             {
       
    96             RArray<TCalTime> dummyRDateList;
       
    97             CleanupClosePushL( dummyRDateList );
       
    98             aEntry.GetRDatesL( dummyRDateList );
       
    99             if ( dummyRDateList.Count() > 0 )
       
   100                 {
       
   101 
       
   102                 retVal = ETrue;
       
   103                 }
       
   104             CleanupStack::PopAndDestroy( &dummyRDateList );
       
   105             }
       
   106         }
       
   107 
       
   108 
       
   109     return retVal;
       
   110     }
       
   111 
       
   112 // ----------------------------------------------------------------------------
       
   113 // ESMREntryHelper::IsModifyingEntryL
       
   114 // ----------------------------------------------------------------------------
       
   115 //
       
   116 EXPORT_C TBool ESMREntryHelper::IsModifyingEntryL( const CCalEntry& aEntry )
       
   117     {
       
   118     FUNC_LOG;
       
   119     return ( aEntry.RecurrenceIdL().TimeUtcL() !=
       
   120              Time::NullTTime() ) ? ETrue : EFalse;
       
   121     }
       
   122 
       
   123 // ----------------------------------------------------------------------------
       
   124 // ESMREntryHelper::IsLatestSavedSentL
       
   125 // ----------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C TBool ESMREntryHelper::IsLatestSavedSentL(
       
   128     const CCalEntry& aEntry )
       
   129     {
       
   130     FUNC_LOG;
       
   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 // ----------------------------------------------------------------------------
       
   144 // ESMREntryHelper::IsCancelledL
       
   145 // ----------------------------------------------------------------------------
       
   146 //
       
   147 EXPORT_C TBool ESMREntryHelper::IsCancelledL(
       
   148     const CCalEntry& aEntry,
       
   149     CMRMailboxUtils& aUtils )
       
   150     {
       
   151     FUNC_LOG;
       
   152     TBool retVal( EFalse );
       
   153     // Check if either entire meeting is cancelled, or this attendee
       
   154     // has been removed from the participant list. According to RFC2446
       
   155     // in that case entry doesn't have status field set.
       
   156     if ( aEntry.StatusL() == CCalEntry::ECancelled ||
       
   157          ( aEntry.MethodL() == CCalEntry::EMethodCancel &&
       
   158          !aUtils.ThisAttendeeL( aEntry ) ) )
       
   159         {
       
   160         retVal = ETrue;
       
   161         }
       
   162     return retVal;
       
   163     }
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // ESMREntryHelper::IsAllDayEventL
       
   167 // ----------------------------------------------------------------------------
       
   168 //
       
   169 EXPORT_C TBool ESMREntryHelper::IsAllDayEventL( const CCalEntry& aEntry )
       
   170     {
       
   171     FUNC_LOG;
       
   172     TBool retVal( EFalse );
       
   173    
       
   174     TDateTime start = aEntry.StartTimeL().TimeLocalL().DateTime();
       
   175     TDateTime end = aEntry.EndTimeL().TimeLocalL().DateTime();
       
   176 
       
   177     // All-day events: 
       
   178     // From one days 00:00:00 to at least next days 00:00:00.
       
   179     // Start times hour, minute and second need to be the same.
       
   180     // Start and end time days need to be different
       
   181     if( start.Hour() == end.Hour() && 
       
   182             start.Minute() == end.Minute() &&
       
   183                 start.Second() == end.Second() && 
       
   184                     start.Day() != end.Day() )
       
   185         {
       
   186         if( start.Hour() == 0 && 
       
   187                 start.Minute() == 0 &&
       
   188                     start.Second() == 0 )
       
   189             {
       
   190             retVal = ETrue;
       
   191             }
       
   192         }
       
   193 
       
   194     return retVal;
       
   195     }
       
   196 
       
   197 // ----------------------------------------------------------------------------
       
   198 // ESMREntryHelper::OccursInPastL
       
   199 // ----------------------------------------------------------------------------
       
   200 //
       
   201 EXPORT_C TBool ESMREntryHelper::OccursInPastL( const CCalEntry& aEntry )
       
   202     {
       
   203     FUNC_LOG;
       
   204     TBool retVal( EFalse );
       
   205     TTime universalTime;
       
   206     universalTime.UniversalTime();
       
   207     TTime meetingUniversalTime = aEntry.StartTimeL().TimeUtcL();
       
   208     if ( universalTime  > meetingUniversalTime )
       
   209         {
       
   210         retVal = ETrue;
       
   211         }
       
   212     return retVal;
       
   213     }
       
   214 
       
   215 // ----------------------------------------------------------------------------
       
   216 // ESMREntryHelper::PhoneOwnerAddrL
       
   217 // ----------------------------------------------------------------------------
       
   218 //
       
   219 EXPORT_C const TDesC& ESMREntryHelper::PhoneOwnerAddrL(
       
   220     const CCalEntry& aEntry,
       
   221     CMRMailboxUtils& aUtils )
       
   222     {
       
   223     FUNC_LOG;
       
   224     if ( aUtils.IsOrganizerL( aEntry ) )
       
   225         {
       
   226         return aEntry.OrganizerL()->Address();
       
   227         }
       
   228     else
       
   229         {
       
   230         CCalAttendee* thisAttendee = aUtils.ThisAttendeeL( aEntry  );
       
   231         if ( thisAttendee )
       
   232             {
       
   233             return thisAttendee->Address();
       
   234             }
       
   235         else
       
   236             {
       
   237             return KNullDesC;
       
   238             }
       
   239         }
       
   240     }
       
   241 
       
   242 // ----------------------------------------------------------------------------
       
   243 // ESMREntryHelper::EqualAttendeeL
       
   244 // ----------------------------------------------------------------------------
       
   245 //
       
   246 EXPORT_C CCalAttendee* ESMREntryHelper::EqualAttendeeL(
       
   247     const CCalAttendee& aAttendee,
       
   248     const CCalEntry& aEntry )
       
   249     {
       
   250     FUNC_LOG;
       
   251     TPtrC addr = ESMRHelper::AddressWithoutMailtoPrefix(
       
   252                     aAttendee.Address() );
       
   253 
       
   254     RPointerArray<CCalAttendee>& attendees = aEntry.AttendeesL();
       
   255     TInt count( attendees.Count() );
       
   256     for ( TInt i ( 0 ); i < count; ++i )
       
   257         {
       
   258         TPtrC testAddr =
       
   259             ESMRHelper::AddressWithoutMailtoPrefix(
       
   260                     attendees[i]->Address() );
       
   261 
       
   262         if ( addr.CompareF( testAddr ) == 0 )
       
   263             {
       
   264             return attendees[i];
       
   265             }
       
   266         }
       
   267     return NULL;
       
   268     }
       
   269 
       
   270 // ----------------------------------------------------------------------------
       
   271 // ESMREntryHelper::SpansManyDaysL
       
   272 // ----------------------------------------------------------------------------
       
   273 //
       
   274 EXPORT_C TBool ESMREntryHelper::SpansManyDaysL(
       
   275     const TCalTime& aStartTime,
       
   276     const TCalTime& aEndTime )
       
   277     {
       
   278     FUNC_LOG;
       
   279     TBool retVal( EFalse );
       
   280 
       
   281     // mustn't use UTC time here, local time specifies if the midnight
       
   282     // is crossed
       
   283     TTime localStartTime = aStartTime.TimeLocalL();
       
   284     TTime localEndTime = aEndTime.TimeLocalL();
       
   285 
       
   286     TTimeIntervalDays days = localEndTime.DaysFrom( localStartTime );
       
   287 
       
   288     if ( days.Int() > 0 )
       
   289         {
       
   290         retVal = ETrue;
       
   291         }
       
   292     return retVal;
       
   293     }
       
   294 
       
   295 // ----------------------------------------------------------------------------
       
   296 // ESMREntryHelper::EventTypeL
       
   297 // ----------------------------------------------------------------------------
       
   298 //
       
   299 EXPORT_C TESMRCalendarEventType ESMREntryHelper::EventTypeL(
       
   300             const CCalEntry& aCalEntry )
       
   301     {
       
   302     FUNC_LOG;
       
   303     
       
   304     TESMRCalendarEventType type( EESMREventTypeNone );
       
   305     
       
   306     switch ( aCalEntry.EntryTypeL() )
       
   307         {
       
   308         case CCalEntry::EAppt:
       
   309             if ( CCalenInterimUtils2::IsMeetingRequestL( 
       
   310                     const_cast< CCalEntry& >( aCalEntry ) ) )
       
   311                 {
       
   312                 type = EESMREventTypeMeetingRequest;
       
   313                 }
       
   314             else
       
   315                 {
       
   316                 type = EESMREventTypeAppt;
       
   317                 }
       
   318             break;
       
   319             
       
   320         case CCalEntry::ETodo:
       
   321             type = EESMREventTypeETodo;
       
   322             break;
       
   323             
       
   324         case CCalEntry::EEvent:
       
   325             type = EESMREventTypeEEvent;
       
   326             break;
       
   327             
       
   328         case CCalEntry::EReminder:
       
   329             type = EESMREventTypeEReminder;
       
   330             break;
       
   331             
       
   332         case CCalEntry::EAnniv:
       
   333             type = EESMREventTypeEAnniv;
       
   334             break;
       
   335             
       
   336         }
       
   337 
       
   338     return type;
       
   339     }
       
   340 
       
   341 // ----------------------------------------------------------------------------
       
   342 // ESMREntryHelper::SetInstanceStartAndEndL
       
   343 // ----------------------------------------------------------------------------
       
   344 //
       
   345 EXPORT_C void ESMREntryHelper::SetInstanceStartAndEndL(
       
   346         CCalEntry& aChild,
       
   347         const CCalEntry& aParent,
       
   348         const TCalTime& aChildStart )
       
   349     {
       
   350     TTime parentStart( aParent.StartTimeL().TimeUtcL() );
       
   351     TTime parentEnd( aParent.EndTimeL().TimeUtcL() );
       
   352     const TTime KNullTime( Time::NullTTime() );
       
   353 
       
   354     if ( KNullTime == parentStart ||
       
   355          KNullTime == parentEnd ||
       
   356          KNullTime == aChildStart.TimeUtcL() )
       
   357         {
       
   358         // Invalid time --> Leaving
       
   359         User::Leave( KErrArgument );
       
   360         }
       
   361 
       
   362     TTimeIntervalMicroSeconds duration( KZeroInterval );
       
   363     duration = parentEnd.MicroSecondsFrom( parentStart );
       
   364     TCalTime childStart;
       
   365     TCalTime childEnd;
       
   366     
       
   367     // Meeting time mode is Fixed Utc
       
   368     if( aChild.EntryTypeL() == CCalEntry::EAppt )
       
   369         {
       
   370         const TTime startTime = aChildStart.TimeUtcL();
       
   371         childStart.SetTimeUtcL( startTime );
       
   372         childEnd.SetTimeUtcL( startTime + duration );   
       
   373         }
       
   374     
       
   375     // Anniversary time mode is local floating
       
   376     if( aChild.EntryTypeL() == CCalEntry::EAnniv )
       
   377         {
       
   378         const TTime startTime = aChildStart.TimeLocalL();
       
   379         childStart.SetTimeLocalFloatingL( startTime );
       
   380         childEnd.SetTimeLocalFloatingL( startTime + duration );  
       
   381         }
       
   382 
       
   383     aChild.SetStartAndEndTimeL( childStart, childEnd );
       
   384     }
       
   385 
       
   386 // ----------------------------------------------------------------------------
       
   387 // ESMREntryHelper::CheckRepeatUntilValidityL
       
   388 // ----------------------------------------------------------------------------
       
   389 //
       
   390 EXPORT_C void ESMREntryHelper::CheckRepeatUntilValidityL(
       
   391         CCalEntry& aEntry,
       
   392         const TCalTime& aInstanceTime )
       
   393     {    
       
   394     if ( ESMREntryHelper::IsRepeatingMeetingL(aEntry) &&
       
   395          !ESMREntryHelper::IsModifyingEntryL(aEntry) )
       
   396         {
       
   397         TCalRRule originalRRule;
       
   398         if ( aEntry.GetRRuleL( originalRRule ) )
       
   399             {
       
   400             TCalTime endTime = aEntry.EndTimeL();
       
   401             TCalTime startTime = aEntry.StartTimeL();
       
   402 
       
   403             TTimeIntervalMicroSeconds duration =
       
   404                 endTime.TimeLocalL().MicroSecondsFrom(
       
   405                         startTime.TimeLocalL() );
       
   406 
       
   407             TTime instanceEndTime( aInstanceTime.TimeLocalL() );
       
   408             instanceEndTime += duration;
       
   409             TCalTime repeatUntilTime = originalRRule.Until();
       
   410             
       
   411             TDateTime repeat = repeatUntilTime.TimeLocalL().DateTime();
       
   412             TDateTime instanceEndDatetime = instanceEndTime.DateTime();
       
   413 
       
   414             if ( repeatUntilTime.TimeLocalL() < instanceEndTime )
       
   415                 {
       
   416                 // reset the recurrence so, that the repeat until
       
   417                 // time is included in repeat range. This is done,
       
   418                 // because when setting the instance start and end
       
   419                 // time, the CCalEntry implementation clears the
       
   420                 // recurrence information if the end time is
       
   421                 // after repeat until end time.
       
   422                 // CCalEntry forces the repeat until time to be
       
   423                 // same than last entry's start time when storing the
       
   424                 // entry to db. Reason uknown.
       
   425                 TCalRRule rRule = originalRRule;
       
   426 
       
   427                 TCalTime newUntil;
       
   428                 newUntil.SetTimeLocalL( instanceEndTime );
       
   429                 rRule.SetUntil( newUntil );
       
   430                 
       
   431                 aEntry.SetRRuleL( rRule );
       
   432                 }
       
   433             }
       
   434         }
       
   435     }
       
   436 
       
   437 //  End of File
       
   438