meetingui/meetingrequestviewers/src/MRHelpers.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2005 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
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "MRHelpers.h"
       
    23 #include "MREntryConsultant.h"
       
    24 #include <caluser.h> // CCalUser
       
    25 #include <miuthdr.h> // CImHeader
       
    26 #include <msvapi.h> // CMsvSession
       
    27 #include <msvuids.h> // KUidMsvMessageEntry
       
    28 #include <miutpars.h> // TImMessageField
       
    29 #include <bautils.h> // BaflUtils
       
    30 #include <coemain.h> // CCoeEnv
       
    31 
       
    32 // CONSTANTS
       
    33 
       
    34 /// Unnamed namespace for local definitions
       
    35 namespace {
       
    36 
       
    37 _LIT( KMailtoMatchPattern, "mailto:*" ); // this is never localized
       
    38 const TInt KMailtoLength = 7; // "mailto:" length
       
    39 
       
    40 enum TPanicCode
       
    41     {
       
    42     EPanicNullMsvId = 1,
       
    43     EIllegalMsvEntryType,
       
    44     EPanicNoOrganizer
       
    45     };
       
    46 
       
    47 _LIT( KPanicMsg, "MRHelpers" );
       
    48 
       
    49 void Panic( TPanicCode aReason )
       
    50     {
       
    51     User::Panic( KPanicMsg, aReason );
       
    52     }
       
    53     
       
    54 }  // namespace
       
    55 
       
    56 // ============================ MEMBER FUNCTIONS ===============================
       
    57 
       
    58 // ----------------------------------------------------------------------------
       
    59 // MRHelpers::CopyAttendeeL
       
    60 // ----------------------------------------------------------------------------
       
    61 //    
       
    62 CCalAttendee* MRHelpers::CopyAttendeeL( CCalAttendee& aSource )
       
    63 	{
       
    64 	CCalAttendee* copy = CopyAttendeeLC( aSource );
       
    65 	CleanupStack::Pop( copy );
       
    66 	return copy;
       
    67 	}
       
    68 
       
    69 // ----------------------------------------------------------------------------
       
    70 // MRHelpers::CopyAttendeeLC
       
    71 // ----------------------------------------------------------------------------
       
    72 //    
       
    73 CCalAttendee* MRHelpers::CopyAttendeeLC( CCalAttendee& aSource )
       
    74 	{
       
    75 	CCalAttendee* copy = CCalAttendee::NewL( aSource.Address(), 
       
    76 	                                         aSource.SentBy() );
       
    77     CleanupStack::PushL( copy );
       
    78     copy->SetCommonNameL( aSource.CommonName() );
       
    79     copy->SetRoleL( aSource.RoleL() );
       
    80 	copy->SetStatusL( aSource.StatusL() );
       
    81 	copy->SetResponseRequested( aSource.ResponseRequested() );
       
    82 	return copy;
       
    83 	}
       
    84 
       
    85 // ----------------------------------------------------------------------------
       
    86 // MRHelpers::CopyUserL
       
    87 // ----------------------------------------------------------------------------
       
    88 //    
       
    89 CCalUser* MRHelpers::CopyUserL( CCalUser& aSource )
       
    90 	{
       
    91 	CCalUser* copy = CopyUserLC( aSource );
       
    92 	CleanupStack::Pop( copy );
       
    93 	return copy;
       
    94 	}
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // MRHelpers::CopyUserLC
       
    98 // ----------------------------------------------------------------------------
       
    99 //    
       
   100 CCalUser* MRHelpers::CopyUserLC( CCalUser& aSource )
       
   101 	{
       
   102 	CCalUser* copy = CCalUser::NewL( aSource.Address(), 
       
   103 	                                 aSource.SentBy() );
       
   104     CleanupStack::PushL( copy );
       
   105     copy->SetCommonNameL( aSource.CommonName() );
       
   106 	return copy;
       
   107 	}
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // MRHelpers::CopyEntryL
       
   111 // ----------------------------------------------------------------------------
       
   112 //          
       
   113 CCalEntry* MRHelpers::CopyEntryL(
       
   114     const CCalEntry& aEntry,
       
   115     CCalEntry::TMethod aMethod,
       
   116     TCopyFields aCopyType )
       
   117     {
       
   118 	CCalEntry* copy = CopyEntryLC( aEntry, aMethod, aCopyType );
       
   119 	CleanupStack::Pop( copy );
       
   120 	return copy;    
       
   121     }
       
   122 	
       
   123 // ----------------------------------------------------------------------------
       
   124 // MRHelpers::CopyEntryLC
       
   125 // ----------------------------------------------------------------------------
       
   126 //          
       
   127 CCalEntry* MRHelpers::CopyEntryLC(
       
   128     const CCalEntry& aEntry,
       
   129     CCalEntry::TMethod aMethod,
       
   130     TCopyFields aCopyType )
       
   131     {
       
   132     CCalEntry* copy = NULL;
       
   133     HBufC8* uid = aEntry.UidL().AllocLC();
       
   134     if ( MREntryConsultant::IsModifyingEntryL( aEntry ) )
       
   135         {
       
   136         copy = CCalEntry::NewL( aEntry.EntryTypeL(),
       
   137                                 uid,
       
   138                                 aMethod,
       
   139                                 aEntry.SequenceNumberL(),
       
   140                                 aEntry.RecurrenceIdL(),
       
   141                                 aEntry.RecurrenceRangeL() );
       
   142         }    
       
   143     else
       
   144         {
       
   145         copy = CCalEntry::NewL( aEntry.EntryTypeL(),
       
   146                                 uid,
       
   147                                 aMethod,
       
   148                                 aEntry.SequenceNumberL() );
       
   149         }
       
   150     CleanupStack::Pop( uid ); // ownership transferred to the copy entry
       
   151     CleanupStack::PushL( copy );
       
   152 
       
   153     CopyFieldsL( aEntry, *copy, aCopyType );
       
   154             
       
   155     return copy;
       
   156     } 
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // MRHelpers::CopyFieldsL
       
   160 // ----------------------------------------------------------------------------
       
   161 //   
       
   162 void MRHelpers::CopyFieldsL(
       
   163     const CCalEntry& aSource,
       
   164     CCalEntry& aTarget,
       
   165     TCopyFields aCopyType )
       
   166     {
       
   167     if ( aCopyType == ECopyFull )
       
   168         {
       
   169         CCalEntry::TMethod tmpMethod( aTarget.MethodL() );    
       
   170         aTarget.CopyFromL( aSource );
       
   171         // We must re-set the method to the original value
       
   172         aTarget.SetMethodL( tmpMethod );
       
   173         }
       
   174     else
       
   175         {
       
   176         if ( aCopyType == ECopyOrganizer )
       
   177             {
       
   178             __ASSERT_DEBUG( aSource.OrganizerL(), Panic( EPanicNoOrganizer ) );
       
   179             CCalUser* organizer = CopyUserLC( *( aSource.OrganizerL() ) );
       
   180             aTarget.SetOrganizerL( organizer );
       
   181             CleanupStack::Pop(); // ownership transferred
       
   182             }
       
   183         
       
   184         // these are required for entries (start and end time actually not
       
   185         // for cancels and responses, but won't do any harm either):
       
   186         aTarget.SetStartAndEndTimeL( aSource.StartTimeL(), aSource.EndTimeL() );
       
   187         aTarget.SetDTStampL( aSource.DTStampL() );
       
   188         }
       
   189     }
       
   190     
       
   191 // ----------------------------------------------------------------------------
       
   192 // MRHelpers::SenderAddressLC
       
   193 // ----------------------------------------------------------------------------
       
   194 //    
       
   195 HBufC* MRHelpers::SenderAddressLC(
       
   196     CMsvSession& aSession,
       
   197     TMsvId aMsgId,
       
   198     TBool aStripAlias )
       
   199     {
       
   200 	__ASSERT_DEBUG( aMsgId != KMsvNullIndexEntryId, Panic( EPanicNullMsvId ) );
       
   201     CMsvEntry* entry = aSession.GetEntryL( aMsgId );
       
   202     __ASSERT_ALWAYS( entry->Entry().iType == KUidMsvMessageEntry,
       
   203                      Panic( EIllegalMsvEntryType ) );
       
   204 
       
   205     // Read sender from the message headers and allocate heap descriptor:
       
   206 
       
   207     CleanupStack::PushL( entry );
       
   208     CMsvStore* store = entry->ReadStoreL();
       
   209     CleanupStack::PushL( store );
       
   210     CImHeader* header = CImHeader::NewLC();
       
   211     header->RestoreL( *store );    
       
   212     TPtrC senderPtr( header->From() );
       
   213     if ( aStripAlias )
       
   214         {
       
   215         TImMessageField addrParser;
       
   216         senderPtr.Set(
       
   217             addrParser.GetValidInternetEmailAddressFromString( senderPtr ) );
       
   218         }
       
   219     HBufC* senderAddr = senderPtr.AllocL();
       
   220     CleanupStack::PopAndDestroy( 3, entry ); // header, store, entry
       
   221     CleanupStack::PushL( senderAddr );            
       
   222     return senderAddr;
       
   223     }
       
   224 
       
   225 // ----------------------------------------------------------------------------
       
   226 // MRHelpers::AddressWithoutMailtoPrefix
       
   227 // ----------------------------------------------------------------------------
       
   228 //    
       
   229 TPtrC MRHelpers::AddressWithoutMailtoPrefix( const TDesC& aAddress )
       
   230 	{
       
   231 	TPtrC addrWithoutPrefix;
       
   232     if ( aAddress.MatchF( KMailtoMatchPattern ) != KErrNotFound )
       
   233     	{
       
   234         addrWithoutPrefix.Set( aAddress.Mid( KMailtoLength ) );
       
   235         }
       
   236     else
       
   237     	{
       
   238         addrWithoutPrefix.Set( aAddress );
       
   239         }
       
   240     return addrWithoutPrefix;
       
   241 	}
       
   242 	
       
   243 // ----------------------------------------------------------------------------
       
   244 // MRHelpers::GetCorrectDllDriveL
       
   245 // ----------------------------------------------------------------------------
       
   246 //    
       
   247 void MRHelpers::GetCorrectDllDriveL( TFileName& aDriveName )
       
   248     {
       
   249     TParse parse;
       
   250     Dll::FileName( aDriveName );
       
   251 	User::LeaveIfError( parse.Set( aDriveName, NULL, NULL ) );
       
   252     aDriveName = parse.Drive(); // contains drive, e.g. "c:"
       
   253     }
       
   254 
       
   255 // ----------------------------------------------------------------------------
       
   256 // MRHelpers::LoadResourceL
       
   257 // ----------------------------------------------------------------------------
       
   258 //    
       
   259 TInt MRHelpers::LoadResourceL(
       
   260     const TDesC& aResourceFile,
       
   261     const TDesC& aResourcePath )
       
   262     {
       
   263     TFileName pathAndFile;
       
   264     MRHelpers::GetCorrectDllDriveL( pathAndFile ); // contains drive, e.g. "c:"    
       
   265     pathAndFile.Append( aResourceFile ); // e.g. "c:MyResource.rsc"
       
   266     
       
   267     TParse parse;
       
   268     parse.Set( pathAndFile, &aResourcePath, NULL );
       
   269     pathAndFile = parse.FullName(); // now we have full (unlocalized) file name
       
   270     
       
   271     // Find the resource file for the nearest language
       
   272     BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(),
       
   273                                     pathAndFile );
       
   274     TInt offset = CCoeEnv::Static()->AddResourceFileL( pathAndFile );
       
   275     return offset;
       
   276     }
       
   277 
       
   278 //  End of File