meetingrequest/mricalviewer/src/esmricalviewerutils.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:  ESMRIcalViewer utility methods
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include "esmricalviewerutils.h"
       
    21 #include "cfsmailmessagepart.h"
       
    22 #include "cfsmailclient.h"
       
    23 #include "cfsmailmessage.h"
       
    24 #include "cfsmailbox.h"
       
    25 
       
    26 #include <calentry.h>
       
    27 #include <caluser.h>
       
    28 #include <cmrmailboxutils.h>
       
    29 
       
    30 // Unnamed namespace for local definitions
       
    31 namespace {
       
    32 
       
    33 const TInt KZero( 0 );
       
    34 _LIT( KTextCalendar, "text/calendar");
       
    35 
       
    36 }//namespace
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // ESMRIcalViewerUtils::EmailOperation
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 TESMRIcalViewerOperationType ESMRIcalViewerUtils::EmailOperation(
       
    43         TInt aCommandId )
       
    44     {
       
    45     FUNC_LOG;
       
    46     TESMRIcalViewerOperationType command( EESMRCmdOpenAttachment );
       
    47 
       
    48     switch ( aCommandId )
       
    49         {
       
    50         case EESMRCmdAcceptMR://fallthrough
       
    51         case EESMRCmdTentativeMR://fallthrough
       
    52         case EESMRCmdDeclineMR:
       
    53             {
       
    54             command = EESMRCmdOpenAttachmentView;
       
    55             }
       
    56         break;
       
    57         default:
       
    58             {
       
    59             command = static_cast<TESMRIcalViewerOperationType>( aCommandId );
       
    60             }
       
    61         break;
       
    62         }
       
    63 
       
    64     return command;
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // ESMRIcalViewerUtils::ContainsAttachments
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 TBool ESMRIcalViewerUtils::ContainsAttachments(
       
    72         TESMRInputParams& /*aParams*/ )
       
    73     {
       
    74     FUNC_LOG;
       
    75     TBool retValue( EFalse );
       
    76 
       
    77     return retValue;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // ESMRIcalViewerUtils::IsAsyncEmailCommand
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 TBool ESMRIcalViewerUtils::IsAsyncEmailCommand(
       
    85         TESMRIcalViewerOperationType aCommand )
       
    86     {
       
    87     FUNC_LOG;
       
    88     TBool retValue( ETrue );
       
    89 
       
    90     if ( EESMRCmdMailMarkUnread == aCommand ||
       
    91          EESMRCmdMailMarkRead == aCommand ||
       
    92          EESMRCmdMailFlagMessage == aCommand )
       
    93         {
       
    94         retValue = EFalse;
       
    95         }
       
    96 
       
    97     return retValue;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // ESMRIcalViewerUtils::MRResponseCommandWithoutAttachmentCheck
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 TESMRCommand ESMRIcalViewerUtils::MRResponseCommandWithoutAttachmentCheck(
       
   105         TInt aCommand )
       
   106     {
       
   107     FUNC_LOG;
       
   108     TESMRCommand command( EESMRAcceptWithoutAttachmentCheck );
       
   109 
       
   110     switch ( aCommand )
       
   111         {
       
   112         case EESMRCmdAcceptMR:
       
   113             {
       
   114             command = EESMRAcceptWithoutAttachmentCheck;
       
   115             break;
       
   116             }
       
   117         case EESMRCmdTentativeMR:
       
   118             {
       
   119             command = EESMRTentativeWithoutAttachmentCheck;
       
   120             break;
       
   121             }
       
   122         case EESMRCmdDeclineMR:
       
   123             {
       
   124             command = EESMRDeclineWithoutAttachmentCheck;
       
   125             break;
       
   126             }
       
   127         default:
       
   128             break;
       
   129         }
       
   130 
       
   131     return command;
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // ESMRIcalViewerUtils::LocateChildPartLC
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 CFSMailMessagePart* ESMRIcalViewerUtils::LocateChildPartLC(
       
   139         CFSMailMessagePart& aParentPart,
       
   140         const TDesC& aMimeType )
       
   141     {
       
   142     FUNC_LOG;
       
   143     CFSMailMessagePart* child = NULL;
       
   144 
       
   145     TBool partFound( EFalse );
       
   146 
       
   147     RPointerArray<CFSMailMessagePart> messageParts;
       
   148     CleanupStack::PushL(
       
   149             TCleanupItem(
       
   150                 ESMRIcalViewerUtils::MessagePartPointerArrayCleanup,
       
   151                 &messageParts    ) );
       
   152 
       
   153     aParentPart.ChildPartsL( messageParts );
       
   154 
       
   155     TInt msgPartCount( messageParts.Count() );
       
   156     for ( TInt i(0); (i < msgPartCount) && !partFound; ++i )
       
   157         {
       
   158         CFSMailMessagePart* part = messageParts[i];
       
   159 
       
   160         HBufC* contentType = part->GetContentType().AllocLC();
       
   161         TPtr ptrContentType( contentType->Des() );
       
   162         ptrContentType.LowerCase();
       
   163 
       
   164         // Check part's content type
       
   165         if ( KErrNotFound != ptrContentType.Find( aMimeType ) )
       
   166             {
       
   167             partFound = ETrue;
       
   168             child = messageParts[i];
       
   169             messageParts.Remove(i);
       
   170             }
       
   171         CleanupStack::PopAndDestroy( contentType );
       
   172         contentType = NULL;
       
   173         }
       
   174 
       
   175     CleanupStack::PopAndDestroy(); // messageParts
       
   176 
       
   177     CleanupStack::PushL( child );
       
   178     return child;
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // ESMRIcalViewerUtils::LocateCalendarPartL
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 CFSMailMessagePart* ESMRIcalViewerUtils::LocateCalendarPartL( CFSMailMessage& aMessage )
       
   186     {
       
   187     FUNC_LOG;
       
   188 
       
   189     CFSMailMessagePart* calendarPart( NULL );
       
   190     CFSMailMessagePart* multipart( NULL );
       
   191 
       
   192     // 1st, try to find 'TEXT/CALENDAR' part from 'MULTIPART/ALTERNATIVE' part of message
       
   193     multipart = ESMRIcalViewerUtils::LocateChildPartLC(
       
   194         aMessage,
       
   195         KFSMailContentTypeMultipartAlternative );
       
   196     if ( multipart )
       
   197         {
       
   198         // multipart found
       
   199         calendarPart = ESMRIcalViewerUtils::LocateChildPartLC( *multipart, KTextCalendar );
       
   200         if ( calendarPart )
       
   201             {
       
   202             // calendar part under multipart found
       
   203             CleanupStack::Pop( calendarPart );
       
   204             CleanupStack::PopAndDestroy( multipart );
       
   205             multipart = NULL;
       
   206             CleanupStack::PushL( calendarPart );
       
   207             }
       
   208         else
       
   209             {
       
   210             // no calendar part under multipart
       
   211             CleanupStack::PopAndDestroy( 2 );
       
   212             multipart = NULL;
       
   213             calendarPart = NULL;
       
   214             }
       
   215         }
       
   216     else
       
   217         {
       
   218         CleanupStack::PopAndDestroy( multipart );
       
   219         }
       
   220 
       
   221     if ( !calendarPart )
       
   222         {
       
   223         // If there's no 'MULTIPART/ALTERNATIVE' or it doesn't have
       
   224         // 'TEXT/CALENDAR' entry, try looking from message root
       
   225         calendarPart = ESMRIcalViewerUtils::LocateChildPartLC(
       
   226             aMessage,
       
   227             KTextCalendar );
       
   228         }
       
   229     CleanupStack::Pop();
       
   230     return calendarPart;
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // ESMRIcalViewerUtils::MessagePartPointerArrayCleanup
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 void ESMRIcalViewerUtils::MessagePartPointerArrayCleanup( TAny* aArray )
       
   238     {
       
   239     FUNC_LOG;
       
   240     RPointerArray<CFSMailMessagePart>* messagePartArray =
       
   241         static_cast<RPointerArray<CFSMailMessagePart>*>( aArray );
       
   242 
       
   243     messagePartArray->ResetAndDestroy();
       
   244     messagePartArray->Close();
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // ESMRIcalViewerUtils::UserResponsedToMRL
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 TESMRAttendeeStatus ESMRIcalViewerUtils::UserResponsedToMRL(
       
   252             CCalEntry& aEntry )
       
   253     {
       
   254     FUNC_LOG;
       
   255     TESMRAttendeeStatus attendeeStatus( EESMRAttendeeStatusUnknown );
       
   256 
       
   257     CCalEntry::TStatus status( aEntry.StatusL() );
       
   258 
       
   259     if ( status == CCalEntry::EConfirmed  )
       
   260         {
       
   261         CMRMailboxUtils* mbUtils =
       
   262                 CMRMailboxUtils::NewL();
       
   263 
       
   264         CleanupStack::PushL( mbUtils );
       
   265 
       
   266         CCalAttendee* attendee = mbUtils->ThisAttendeeL( aEntry );
       
   267 
       
   268         if ( attendee )
       
   269             {
       
   270             CCalAttendee::TCalStatus status( attendee->StatusL() );
       
   271 
       
   272             switch( status )
       
   273                 {
       
   274                 case CCalAttendee::EAccepted:
       
   275                     {
       
   276                     attendeeStatus = EESMRAttendeeStatusAccept;
       
   277                     break;
       
   278                     }
       
   279                 case CCalAttendee::ETentative:
       
   280                     {
       
   281                     attendeeStatus = EESMRAttendeeStatusTentative;
       
   282                     break;
       
   283                     }
       
   284                 case CCalAttendee::EDeclined:
       
   285                     {
       
   286                     attendeeStatus = EESMRAttendeeStatusDecline;
       
   287                     break;
       
   288                     }
       
   289                 default:
       
   290                     {
       
   291                     attendeeStatus = EESMRAttendeeStatusUnknown;
       
   292                     break;
       
   293                     }
       
   294                 }
       
   295             }
       
   296 
       
   297         CleanupStack::PopAndDestroy( mbUtils );
       
   298         mbUtils = NULL;
       
   299         }
       
   300 
       
   301     return attendeeStatus;
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // ESMRIcalViewerUtils::MailboxOwnerRoleL
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 TESMRRole ESMRIcalViewerUtils::MailboxOwnerRoleL(
       
   309         CCalEntry& aEntry,
       
   310         CFSMailClient& aMailClient,
       
   311         CFSMailMessage& aMessage )
       
   312     {
       
   313     FUNC_LOG;
       
   314     TESMRRole role( EESMRRoleUndef );
       
   315 
       
   316     TFSMailMsgId mailboxId( aMessage.GetMailBoxId() );
       
   317     CFSMailBox* mailbox = aMailClient.GetMailBoxByUidL( mailboxId );
       
   318 
       
   319     CleanupStack::PushL( mailbox );
       
   320 
       
   321     TPtrC mailboxOwnerAddName(
       
   322             mailbox->OwnMailAddress().GetEmailAddress() );
       
   323 
       
   324     CCalUser* organizer = aEntry.OrganizerL();
       
   325 
       
   326     if ( organizer &&  KZero == organizer->Address().CompareF(mailboxOwnerAddName) )
       
   327         {
       
   328         role = EESMRRoleOrganizer;
       
   329         }
       
   330     else
       
   331         {
       
   332         RPointerArray<CCalAttendee>& attendees = aEntry.AttendeesL();
       
   333         TInt attendeeCount( attendees.Count() );
       
   334 
       
   335         for( TInt i(0); i < attendeeCount; ++i )
       
   336             {
       
   337             CCalAttendee* attendee = attendees[i];
       
   338             if ( KZero == attendee->Address().CompareF(mailboxOwnerAddName) )
       
   339                 {
       
   340                 switch( attendee->RoleL() )
       
   341                     {
       
   342                     case CCalAttendee::EChair:
       
   343                     case CCalAttendee::EReqParticipant:
       
   344                         {
       
   345                         role = EESMRRoleRequiredAttendee;
       
   346                         }
       
   347                     break;
       
   348                     case CCalAttendee::EOptParticipant:
       
   349                         {
       
   350                         role = EESMRRoleOptionalAttendee;
       
   351                         }
       
   352                     break;
       
   353                     case CCalAttendee::ENonParticipant:
       
   354                         {
       
   355                         role = EESMRRoleNonParticipant;
       
   356                         }
       
   357                     break;
       
   358                     default:
       
   359                         {
       
   360                         role = EESMRRoleUndef;
       
   361                         }
       
   362                     break;
       
   363                     }
       
   364                 }
       
   365             }
       
   366         }
       
   367 
       
   368     CleanupStack::PopAndDestroy( mailbox );
       
   369 
       
   370     return role;
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // ESMRIcalViewerUtils::IsMailboxOwnerAttendeeL
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 TBool ESMRIcalViewerUtils::IsMailboxOwnerAttendeeL(
       
   378         CCalEntry& aEntry,
       
   379         CFSMailClient& aMailClient,
       
   380         CFSMailMessage& aMessage )
       
   381     {
       
   382     FUNC_LOG;
       
   383     TBool retValue( EFalse );
       
   384 
       
   385     TESMRRole role(
       
   386             ESMRIcalViewerUtils::MailboxOwnerRoleL(
       
   387                     aEntry,
       
   388                     aMailClient,
       
   389                     aMessage ) );
       
   390 
       
   391     if ( EESMRRoleRequiredAttendee == role ||
       
   392             EESMRRoleOptionalAttendee == role ||
       
   393             EESMRRoleNonParticipant == role )
       
   394         {
       
   395         retValue = ETrue;
       
   396         }
       
   397 
       
   398     return retValue;
       
   399     }
       
   400 
       
   401 // EOF
       
   402