meetingrequest/mrservices/src/cesmrcaluserutil.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2007-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:  MR user utility class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include "cesmrcaluserutil.h"
       
    21 //<cmail>
       
    22 #include "esmrdef.h"
       
    23 //</cmail>
       
    24 #include <calentry.h>
       
    25 #include <caluser.h>
       
    26 
       
    27 namespace { // codescanner::namespace
       
    28 
       
    29 // Definition for 0
       
    30 const TInt KZero = 0;
       
    31 
       
    32 // Definition for number of hours within day
       
    33 const TInt KHoursInDay = 24;
       
    34 
       
    35 } // namespace
       
    36 
       
    37 // ======== MEMBER FUNCTIONS ========
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CESMRCalUserUtil::CESMRCalUserUtil
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 inline CESMRCalUserUtil::CESMRCalUserUtil(
       
    44         CCalEntry& aEntry )
       
    45 :   iEntry( aEntry )
       
    46     {
       
    47     FUNC_LOG;
       
    48     //do nothing
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CESMRCalUserUtil::~CESMRCalUserUtil
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 EXPORT_C CESMRCalUserUtil::~CESMRCalUserUtil()
       
    56     {
       
    57     FUNC_LOG;
       
    58     //do nothing
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CESMRCalUserUtil::NewL
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 EXPORT_C CESMRCalUserUtil* CESMRCalUserUtil::NewL(
       
    66              CCalEntry& aEntry )
       
    67      {
       
    68     FUNC_LOG;
       
    69      CESMRCalUserUtil* self = NewLC( aEntry );
       
    70      CleanupStack::Pop( self );
       
    71      return self;
       
    72      }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CESMRCalUserUtil::NewLC
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C CESMRCalUserUtil* CESMRCalUserUtil::NewLC(
       
    79              CCalEntry& aEntry )
       
    80      {
       
    81     FUNC_LOG;
       
    82      CESMRCalUserUtil* self = new (ELeave) CESMRCalUserUtil( aEntry );
       
    83      CleanupStack::PushL( self );
       
    84      self->ConstructL();
       
    85      return self;
       
    86      }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CESMRCalUserUtil::ConstructL
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CESMRCalUserUtil::ConstructL()
       
    93     {
       
    94     FUNC_LOG;
       
    95     //do nothing
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CESMRCalUserUtil::GetAttendeesL
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 EXPORT_C void CESMRCalUserUtil::GetAttendeesL(
       
   103         RArray<CCalAttendee*>& aAttendeeArray,
       
   104         TUint aFilterFlags ) const
       
   105     {
       
   106     FUNC_LOG;
       
   107 
       
   108     aAttendeeArray.Reset();
       
   109     RPointerArray<CCalAttendee>& attendees = iEntry.AttendeesL();
       
   110 
       
   111     TBool includeRequired( EESMRRoleRequiredAttendee & aFilterFlags);
       
   112     TBool includeOptional( EESMRRoleOptionalAttendee & aFilterFlags);
       
   113 
       
   114     TInt attendeeCount( attendees.Count() );
       
   115     for (TInt i(0); i < attendeeCount; ++i )
       
   116         {
       
   117         CCalAttendee* attendee = attendees[i];
       
   118         CCalAttendee::TCalRole role(
       
   119                  attendee->RoleL() );
       
   120 
       
   121         TPtrC cn( attendee->CommonName() );
       
   122         TPtrC ad( attendee->Address() );
       
   123 
       
   124         if ( includeRequired &&
       
   125              CCalAttendee::EReqParticipant == role )
       
   126             {
       
   127             aAttendeeArray.Append(attendee);
       
   128             }
       
   129         else if ( includeRequired &&
       
   130                   CCalAttendee::EChair == role )
       
   131             {
       
   132             aAttendeeArray.Append(attendee);
       
   133             }
       
   134         else if ( includeOptional &&
       
   135                   CCalAttendee::EOptParticipant == role )
       
   136             {
       
   137             aAttendeeArray.Append(attendee);
       
   138             }
       
   139         }
       
   140 
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CESMRCalUserUtil::PhoneOwnerAttendeeRoleL
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 EXPORT_C TESMRRole CESMRCalUserUtil::PhoneOwnerRoleL() const
       
   148     {
       
   149     FUNC_LOG;
       
   150     
       
   151     TESMRRole role = EESMRRoleUndef;
       
   152     CCalUser* phoneOwner = iEntry.PhoneOwnerL();
       
   153     RPointerArray<CCalAttendee>& attendees = iEntry.AttendeesL();
       
   154 
       
   155     if ( phoneOwner )
       
   156         {
       
   157         CCalUser* organizer = iEntry.OrganizerL();
       
   158 
       
   159         if( phoneOwner && phoneOwner == organizer )
       
   160             {
       
   161             role = EESMRRoleOrganizer;
       
   162             }
       
   163         else
       
   164             {
       
   165             CCalAttendee* thisAttendee = NULL;
       
   166             TInt attendeeCount( attendees.Count() );
       
   167             for ( TInt i(0); (i < attendeeCount) && !thisAttendee; ++i )
       
   168                 {
       
   169                 if ( phoneOwner && phoneOwner == attendees[i] )
       
   170                     {
       
   171                     thisAttendee = attendees[i];
       
   172                     }
       
   173                 }
       
   174 
       
   175             if ( thisAttendee )
       
   176                 {
       
   177                 switch( thisAttendee->RoleL() )
       
   178                     {
       
   179                     case CCalAttendee::EChair://fallthrough
       
   180                     case CCalAttendee::EReqParticipant:
       
   181                         {
       
   182                         role = EESMRRoleRequiredAttendee;
       
   183                         }
       
   184                         break;
       
   185                     case CCalAttendee::EOptParticipant:
       
   186                         {
       
   187                         role = EESMRRoleOptionalAttendee;
       
   188                         }
       
   189                         break;
       
   190                     case CCalAttendee::ENonParticipant:
       
   191                         {
       
   192                         role = EESMRRoleNonParticipant;
       
   193                         }
       
   194                         break;
       
   195                     default:
       
   196                         {
       
   197                         role = EESMRRoleUndef;
       
   198                         }
       
   199                         break;
       
   200                     }
       
   201                 }
       
   202             }
       
   203         }
       
   204     
       
   205     return role;
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // CESMRCalUserUtil::IsAlldayEventL
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 EXPORT_C TBool CESMRCalUserUtil::IsAlldayEventL() const
       
   213     {
       
   214     FUNC_LOG;
       
   215     
       
   216     TBool allDayEvent(EFalse);
       
   217 
       
   218     TCalTime startTime = iEntry.StartTimeL();
       
   219     TCalTime stopTime  = iEntry.EndTimeL();
       
   220 
       
   221     TTimeIntervalHours hoursBetweenStartAndEnd;
       
   222     stopTime.TimeLocalL().HoursFrom(
       
   223             startTime.TimeLocalL(),
       
   224             hoursBetweenStartAndEnd );
       
   225 
       
   226     TCalTime::TTimeMode mode = startTime.TimeMode();
       
   227 
       
   228     TInt hoursBetweenStartAndEndAsInt(  hoursBetweenStartAndEnd.Int() );
       
   229     TInt alldayDivident(  hoursBetweenStartAndEndAsInt % KHoursInDay );
       
   230 
       
   231     TDateTime startTimeLocal = startTime.TimeLocalL().DateTime();
       
   232     TDateTime stopTimeLocal =  stopTime.TimeLocalL().DateTime();
       
   233     
       
   234     if ( hoursBetweenStartAndEndAsInt && KZero == alldayDivident )
       
   235         {
       
   236         if ( startTimeLocal.Hour() == stopTimeLocal.Hour() &&
       
   237              startTimeLocal.Minute() == stopTimeLocal.Minute() &&
       
   238              startTimeLocal.Second() == stopTimeLocal.Second() )
       
   239             {
       
   240             allDayEvent = ETrue;
       
   241             }
       
   242         }
       
   243     
       
   244     return allDayEvent;
       
   245     }
       
   246 
       
   247 // EOF
       
   248