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