meetingrequest/mrcommon/src/esmrhelper.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 0 8466d47a6819
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include "emailtrace.h"
       
    21 #include "esmrhelper.h"
    20 #include "esmrhelper.h"
    22 #include "esmrentryhelper.h"
    21 #include "esmrentryhelper.h"
       
    22 #include "esmrconfig.hrh"
    23 #include <f32file.h>
    23 #include <f32file.h>
    24 #include <caluser.h>
    24 #include <caluser.h>
    25 #include <miuthdr.h>
    25 #include <miuthdr.h>
    26 #include <msvapi.h>
    26 #include <msvapi.h>
    27 #include <msvuids.h>
    27 #include <msvuids.h>
    28 #include <miutpars.h>
    28 #include <miutpars.h>
    29 #include <bautils.h>
    29 #include <bautils.h>
    30 #include <coemain.h>
    30 #include <coemain.h>
    31 #include <msvids.h>
    31 #include <msvids.h>
    32 #include <SendUiConsts.h>
    32 #include <senduiconsts.h>
       
    33 #include <caleninterimutils2.h>
       
    34 #include <calalarm.h>
       
    35 #include <calrrule.h>
       
    36 #include <calattachment.h>
       
    37 #include <centralrepository.h>
       
    38 #include <cmrmailboxutils.h>
       
    39 #include <ct/rcpointerarray.h>
       
    40 #include <utf.h>
       
    41 #include <aknlists.h>
       
    42 #include <aknpopup.h>
       
    43 #include <calendarinternalcrkeys.h>
    33 #include <data_caging_path_literals.hrh>
    44 #include <data_caging_path_literals.hrh>
    34 //<cmail> hardcoded paths removal
    45 //<cmail> hardcoded paths removal
    35 #include <pathinfo.h>
    46 #include <pathinfo.h>
    36 //</cmail>
    47 //</cmail>
    37 
    48 
       
    49 #include "emailtrace.h"
       
    50 
    38 // CONSTANTS
    51 // CONSTANTS
    39 
    52 
    40 /// Unnamed namespace for local definitions
    53 /// Unnamed namespace for local definitions
    41 namespace { // codescanner::namespace
    54 namespace { // codescanner::namespace
    42 
    55 
    49 
    62 
    50 const TInt KMinTwoDigitLanguageCode = 10;
    63 const TInt KMinTwoDigitLanguageCode = 10;
    51 
    64 
    52 _LIT (KResourceFormat, "rsc" );
    65 _LIT (KResourceFormat, "rsc" );
    53 
    66 
       
    67 // Definition for max hours, minutes, seconds in day for Memo
       
    68 const TInt KMaxHoursForMemo( 23 );
       
    69 const TInt KMaxMinutesForMemo( 59 );
       
    70 const TInt KMaxSecondsForMemo( 59 );
       
    71 
       
    72 // Definition for max hours, minutes, seconds in day for To-Do
       
    73 const TInt KMaxHoursForTodo( 23 );
       
    74 const TInt KMaxMinutesForTodo( 59 );
       
    75 const TInt KMaxSecondsForTodo( 00 );
       
    76 
       
    77 const TInt KDefaultAnniversaryAlarmHours( 12 );
       
    78 
       
    79 const TInt KDefaultTodoAlarmHours( 12 );
       
    80 
       
    81 // Definition for default alarm time for meeting
       
    82 const TInt KDefaultMeetingAlarmMinutes( 15 );
       
    83 
       
    84 // Constant for default meeeting start hour
       
    85 const TInt KDefaultMeetingStartHour( 8 );
       
    86 
       
    87 // Constant for default meeeting end hour
       
    88 const TInt KDefaultMeetingEndHour( 9 );
       
    89 
       
    90 
    54 #ifdef _DEBUG
    91 #ifdef _DEBUG
    55 
    92 
    56 enum TPanicCode
    93 enum TPanicCode
    57     {
    94     {
    58     EPanicNullMsvId = 1,
    95     EPanicNullMsvId = 1,
    59     EIllegalMsvEntryType,
    96     EIllegalMsvEntryType,
    60     EPanicNoOrganizer
    97     EPanicNoOrganizer,
       
    98     EInvalidEntryType,
       
    99     EInvalidSwitchType
    61     };
   100     };
    62 
   101 
    63 // Panic message definition
   102 // Panic message definition
    64 _LIT( KPanicMsg, "ESMRHelper" );
   103 _LIT( KPanicMsg, "ESMRHelper" );
    65 
   104 
    67     {
   106     {
    68     User::Panic( KPanicMsg, aReason );
   107     User::Panic( KPanicMsg, aReason );
    69     }
   108     }
    70 
   109 
    71 #endif // _DEBUG
   110 #endif // _DEBUG
       
   111 
       
   112 CCalEntry::TType MapType( TESMRCalendarEventType aEntryType )
       
   113     {
       
   114     CCalEntry::TType type( CCalEntry::EAppt );
       
   115 
       
   116     switch ( aEntryType )
       
   117         {
       
   118         case EESMREventTypeAppt:
       
   119         case EESMREventTypeMeetingRequest:
       
   120             {
       
   121             type = CCalEntry::EAppt;
       
   122             break;
       
   123             }
       
   124         case EESMREventTypeETodo:
       
   125             {
       
   126             type = CCalEntry::ETodo;
       
   127             break;
       
   128             }
       
   129         case EESMREventTypeEEvent:
       
   130             {
       
   131             type = CCalEntry::EEvent;
       
   132             break;
       
   133             }
       
   134         case EESMREventTypeEReminder:
       
   135             {
       
   136             type = CCalEntry::EReminder;
       
   137             break;
       
   138             }
       
   139         case EESMREventTypeEAnniv:
       
   140             {
       
   141             type = CCalEntry::EAnniv;
       
   142             break;
       
   143             }
       
   144         default:
       
   145             {
       
   146             __ASSERT_DEBUG( EFalse, Panic( EInvalidEntryType ) );
       
   147             }
       
   148         }
       
   149 
       
   150     return type;
       
   151     }
       
   152 
       
   153 /**
       
   154  * Fetches the supported mailboxes.
       
   155  * @param aMBUtils utils class
       
   156  * @param aMailBoxes to test
       
   157  */
       
   158 void SupportedMailboxesL(
       
   159         CMRMailboxUtils& aMBUtils,
       
   160         RArray<CMRMailboxUtils::TMailboxInfo>& aMailBoxes )
       
   161     {
       
   162     FUNC_LOG;
       
   163     aMBUtils.ListMailBoxesL( aMailBoxes );
       
   164 
       
   165     RCPointerArray<CImplementationInformation> implArray;
       
   166     CleanupClosePushL( implArray );
       
   167 
       
   168     //Get all MRViewers Implementation
       
   169     const TUid mrViewersIface = TUid::Uid(KMRViewersInterfaceUID);
       
   170     REComSession::ListImplementationsL(mrViewersIface, implArray );
       
   171     TInt mrviewerCount( implArray.Count() );
       
   172 
       
   173     TInt index(0);
       
   174     TInt mailboxCount( aMailBoxes.Count() );
       
   175     while ( index < mailboxCount )
       
   176          {
       
   177          TBool supported( EFalse );
       
   178 
       
   179          for ( TInt i(0); (i < mrviewerCount) && !supported; ++ i )
       
   180              {
       
   181              TBuf16<KMaxUidName> mbName;
       
   182              CnvUtfConverter::ConvertToUnicodeFromUtf8(
       
   183                      mbName,
       
   184                      implArray[i]->DataType() );
       
   185 
       
   186              if( aMailBoxes[index].iMtmUid.Name().CompareF(mbName) == 0)
       
   187                   {
       
   188                   supported = ETrue;
       
   189                  }
       
   190              }
       
   191 
       
   192          if ( supported )
       
   193              {
       
   194              index++;
       
   195              }
       
   196          else
       
   197              {
       
   198              aMailBoxes.Remove( index );
       
   199              mailboxCount = aMailBoxes.Count();
       
   200              }
       
   201          }
       
   202     CleanupStack::PopAndDestroy( &implArray );
       
   203     }
       
   204 
       
   205 /**
       
   206  * Prompts user to select default mailbox.
       
   207  * @param aMailBoxes Reference to mailbox list
       
   208  */
       
   209 TInt PromptForDefaultMailboxL(
       
   210         RArray<CMRMailboxUtils::TMailboxInfo>& aMailBoxes )
       
   211     {
       
   212     FUNC_LOG;
       
   213     TInt selected( KErrCancel );
       
   214 
       
   215     TInt mbCount = aMailBoxes.Count();
       
   216     if( mbCount > 0)
       
   217         {
       
   218         CAknSinglePopupMenuStyleListBox* list =
       
   219             new (ELeave) CAknSinglePopupMenuStyleListBox;
       
   220         CleanupStack::PushL(list);
       
   221 
       
   222         CAknPopupList* popupList = CAknPopupList::NewL(
       
   223                                             list,
       
   224                                             R_AVKON_SOFTKEYS_OK_CANCEL);
       
   225         CleanupStack::PushL(popupList);
       
   226 
       
   227         list->ConstructL(popupList, CEikListBox::ELeftDownInViewRect);
       
   228         list->CreateScrollBarFrameL(ETrue);
       
   229         list->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   230             CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   231 
       
   232         CEikonEnv* eikEnv = CEikonEnv::Static();// codescanner::eikonenvstatic
       
   233 
       
   234         CDesCArrayFlat* items = new (ELeave)CDesCArrayFlat(mbCount);
       
   235         CleanupStack::PushL(items);
       
   236         for(TInt i=0; i<mbCount; ++i)
       
   237             {
       
   238             items->AppendL( aMailBoxes[i].iName );
       
   239             }
       
   240         CleanupStack::Pop(items);
       
   241         CTextListBoxModel* model = list->Model();
       
   242 
       
   243         //Pass ownersip of items to model
       
   244         model->SetItemTextArray(items);
       
   245 
       
   246         HBufC* title = KNullDesC().AllocLC();
       
   247         popupList->SetTitleL(*title);
       
   248         CleanupStack::PopAndDestroy(title);
       
   249 
       
   250         TBool accepted = popupList->ExecuteLD();
       
   251         CleanupStack::Pop( popupList );
       
   252 
       
   253         if(accepted)
       
   254             {
       
   255             selected = list->CurrentItemIndex();
       
   256             }
       
   257         else
       
   258             {
       
   259             selected = KErrCancel;
       
   260             }
       
   261 
       
   262         CleanupStack::PopAndDestroy( list );
       
   263         }
       
   264     else
       
   265         {
       
   266         //No mailboxes defined.  Could prompt user to define one here.
       
   267         selected = KErrCancel;
       
   268         }
       
   269 
       
   270     return selected;
       
   271     }
       
   272 
       
   273 /**
       
   274  * Converts to-do specific priority to normal priority
       
   275  * @param Calendar entry, which priority is converted
       
   276  */
       
   277 void ConvertTodoPriorityToNormalL( CCalEntry& entry )
       
   278     {
       
   279     FUNC_LOG;
       
   280     TInt priority( 0 );
       
   281     if( entry.PriorityL() == EFSCalenTodoPriorityHigh )
       
   282         {
       
   283         priority = EFSCalenMRPriorityHigh;
       
   284         }
       
   285 
       
   286     else if( entry.PriorityL() == EFSCalenTodoPriorityNormal )
       
   287         {
       
   288         priority = EFSCalenMRPriorityNormal;
       
   289         }
       
   290 
       
   291     else if( entry.PriorityL() == EFSCalenTodoPriorityLow )
       
   292         {
       
   293         priority = EFSCalenMRPriorityLow;
       
   294         }
       
   295 
       
   296     else
       
   297         {
       
   298         // Priority unknown, let's set it to normal then
       
   299         priority = EFSCalenMRPriorityNormal;
       
   300         }
       
   301 
       
   302     entry.SetPriorityL( priority );
       
   303     }
    72 
   304 
    73 }  // namespace
   305 }  // namespace
    74 
   306 
    75 // ======== MEMBER FUNCTIONS ========
   307 // ======== MEMBER FUNCTIONS ========
    76 
   308 
   134 // ----------------------------------------------------------------------------
   366 // ----------------------------------------------------------------------------
   135 //
   367 //
   136 EXPORT_C CCalEntry* ESMRHelper::CopyEntryL(
   368 EXPORT_C CCalEntry* ESMRHelper::CopyEntryL(
   137     const CCalEntry& aEntry,
   369     const CCalEntry& aEntry,
   138     CCalEntry::TMethod aMethod,
   370     CCalEntry::TMethod aMethod,
   139     TCopyFields aCopyType )
   371     TCopyFields aCopyType,
   140     {
   372     TESMRCalendarEventType aEntryType )
   141     FUNC_LOG;
   373     {
   142     CCalEntry* copy = CopyEntryLC( aEntry, aMethod, aCopyType );
   374     FUNC_LOG;
       
   375     CCalEntry* copy = CopyEntryLC( aEntry, aMethod, aCopyType, aEntryType );
   143     CleanupStack::Pop( copy );
   376     CleanupStack::Pop( copy );
   144     return copy;
   377     return copy;
   145     }
   378     }
   146 
   379 
   147 // ----------------------------------------------------------------------------
   380 // ----------------------------------------------------------------------------
   149 // ----------------------------------------------------------------------------
   382 // ----------------------------------------------------------------------------
   150 //
   383 //
   151 EXPORT_C CCalEntry* ESMRHelper::CopyEntryLC(
   384 EXPORT_C CCalEntry* ESMRHelper::CopyEntryLC(
   152     const CCalEntry& aEntry,
   385     const CCalEntry& aEntry,
   153     CCalEntry::TMethod aMethod,
   386     CCalEntry::TMethod aMethod,
   154     TCopyFields aCopyType )
   387     TCopyFields aCopyType,
       
   388     TESMRCalendarEventType aEntryType )
   155     {
   389     {
   156     FUNC_LOG;
   390     FUNC_LOG;
   157     CCalEntry* copy = NULL;
   391     CCalEntry* copy = NULL;
   158     HBufC8* uid = aEntry.UidL().AllocLC();
   392 
   159     if ( ESMREntryHelper::IsModifyingEntryL( aEntry ) )
   393     TESMRCalendarEventType type = ESMREntryHelper::EventTypeL( aEntry );
   160         {
   394 
   161         copy = CCalEntry::NewL( aEntry.EntryTypeL(),
   395     if( aEntryType == EESMREventTypeNone ||
   162                                 uid,
   396             type == aEntryType )
   163                                 aMethod,
   397         {
   164                                 aEntry.SequenceNumberL(),
   398         HBufC8* uid = aEntry.UidL().AllocLC();
   165                                 aEntry.RecurrenceIdL(),
   399 
   166                                 aEntry.RecurrenceRangeL() );
   400         CCalEntry::TType entryType = aEntry.EntryTypeL();
       
   401 
       
   402         if ( aEntryType != EESMREventTypeNone )
       
   403             {
       
   404             entryType = MapType( aEntryType );
       
   405             }
       
   406 
       
   407         if ( ESMREntryHelper::IsModifyingEntryL( aEntry ) )
       
   408             {
       
   409             copy = CCalEntry::NewL( entryType,
       
   410                                     uid,
       
   411                                     aMethod,
       
   412                                     aEntry.SequenceNumberL(),
       
   413                                     aEntry.RecurrenceIdL(),
       
   414                                     aEntry.RecurrenceRangeL() );
       
   415             }
       
   416         else
       
   417             {
       
   418             copy = CCalEntry::NewL( entryType,
       
   419                                     uid,
       
   420                                     aMethod,
       
   421                                     aEntry.SequenceNumberL() );
       
   422             }
       
   423         CleanupStack::Pop( uid ); // ownership transferred to the copy entry
       
   424         CleanupStack::PushL( copy );
       
   425 
       
   426         CopyFieldsL( aEntry, *copy, aCopyType );
       
   427         copy->SetLastModifiedDateL();
       
   428 
   167         }
   429         }
   168     else
   430     else
   169         {
   431         {
   170         copy = CCalEntry::NewL( aEntry.EntryTypeL(),
   432         copy = CopyEntryAndSwitchTypeL( aEntry, aEntryType );
   171                                 uid,
   433         CleanupStack::PushL( copy );
   172                                 aMethod,
   434         }
   173                                 aEntry.SequenceNumberL() );
       
   174         }
       
   175     CleanupStack::Pop( uid ); // ownership transferred to the copy entry
       
   176     CleanupStack::PushL( copy );
       
   177 
       
   178     CopyFieldsL( aEntry, *copy, aCopyType );
       
   179     copy->SetLastModifiedDateL();
       
   180 
   435 
   181     return copy;
   436     return copy;
   182     }
   437     }
   183 
   438 
   184 // ----------------------------------------------------------------------------
   439 // ----------------------------------------------------------------------------
   232 //
   487 //
   233 EXPORT_C TPtrC ESMRHelper::AddressWithoutMailtoPrefix( const TDesC& aAddress )
   488 EXPORT_C TPtrC ESMRHelper::AddressWithoutMailtoPrefix( const TDesC& aAddress )
   234     {
   489     {
   235     FUNC_LOG;
   490     FUNC_LOG;
   236     TPtrC addrWithoutPrefix( aAddress );
   491     TPtrC addrWithoutPrefix( aAddress );
   237 	TInt pos = KErrNotFound;
   492     TInt pos = KErrNotFound;
   238 		
   493 
   239 	do
   494     do
   240         {
   495         {
   241 		pos = addrWithoutPrefix.MatchF( KMailtoMatchPattern );
   496         pos = addrWithoutPrefix.MatchF( KMailtoMatchPattern );
   242 		if ( pos != KErrNotFound )
   497         if ( pos != KErrNotFound )
   243         {
   498         {
   244 			addrWithoutPrefix.Set( addrWithoutPrefix.Mid( KMailtoLength ) );
   499             addrWithoutPrefix.Set( addrWithoutPrefix.Mid( KMailtoLength ) );
   245 			}
   500             }
   246         }
   501         }
   247 	while ( pos != KErrNotFound );
   502     while ( pos != KErrNotFound );
   248     
   503 
   249     return addrWithoutPrefix;
   504     return addrWithoutPrefix;
   250     }
   505     }
   251 
   506 
   252 // ----------------------------------------------------------------------------
   507 // ----------------------------------------------------------------------------
   253 // ESMRHelper::GetCorrectDllDriveL
   508 // ESMRHelper::GetCorrectDllDriveL
   448     if ( KErrNone == err )
   703     if ( KErrNone == err )
   449         {
   704         {
   450         aResourceFile.Copy( resourceFile.File() );
   705         aResourceFile.Copy( resourceFile.File() );
   451         }
   706         }
   452     else
   707     else
   453     	{
   708         {
   454     	const TChar KFileFormatDelim( '.' );
   709         const TChar KFileFormatDelim( '.' );
   455     	TFileName locResourceFile;
   710         TFileName locResourceFile;
   456 
   711 
   457 
   712 
   458     	TInt pos = aResource.LocateReverse( KFileFormatDelim );
   713         TInt pos = aResource.LocateReverse( KFileFormatDelim );
   459     	if ( pos != KErrNotFound )
   714         if ( pos != KErrNotFound )
   460     		{		
   715             {
   461     		locResourceFile.Copy( aResource.Mid(0, pos + 1) );
   716             locResourceFile.Copy( aResource.Mid(0, pos + 1) );
   462 
   717 
   463     		TInt language( User::Language() );
   718             TInt language( User::Language() );
   464     		if (language < KMinTwoDigitLanguageCode )
   719             if (language < KMinTwoDigitLanguageCode )
   465     			{
   720                 {
   466     			locResourceFile.AppendFormat( KResourceFileLocFormat1, language );
   721                 locResourceFile.AppendFormat( KResourceFileLocFormat1, language );
   467     			}
   722                 }
   468     		else
   723             else
   469     			{
   724                 {
   470     			locResourceFile.AppendFormat( KResourceFileLocFormat2, language );
   725                 locResourceFile.AppendFormat( KResourceFileLocFormat2, language );
   471     			}
   726                 }
   472 
   727 
   473     		TFindFile resourceFile( *fsSession );
   728             TFindFile resourceFile( *fsSession );
   474     		err = resourceFile.FindByDir(
   729             err = resourceFile.FindByDir(
   475     				locResourceFile,
   730                     locResourceFile,
   476     				aPath );
   731                     aPath );
   477 
   732 
   478     		if ( KErrNone == err )
   733             if ( KErrNone == err )
   479     			{
   734                 {
   480     			TFileName tempName;
   735                 TFileName tempName;
   481     			tempName.Copy( resourceFile.File() );
   736                 tempName.Copy( resourceFile.File() );
   482     			TInt dotpos= tempName.LocateReverse(KFileFormatDelim);
   737                 TInt dotpos= tempName.LocateReverse(KFileFormatDelim);
   483     			aResourceFile.Copy(tempName.Mid(0,dotpos+1) );
   738                 aResourceFile.Copy(tempName.Mid(0,dotpos+1) );
   484     			aResourceFile.Append(KResourceFormat);				
   739                 aResourceFile.Append(KResourceFormat);
   485     			}
   740                 }
   486     		}
   741             }
   487     	}
   742         }
   488 
   743 
   489 
   744 
   490     if ( KErrNone != err )
   745     if ( KErrNone != err )
   491         {
   746         {
   492         }
   747         }
   496 //<cmail>
   751 //<cmail>
   497 // ----------------------------------------------------------------------------
   752 // ----------------------------------------------------------------------------
   498 // ESMRHelper::CreateAndAppendPrivateDirToFileName
   753 // ESMRHelper::CreateAndAppendPrivateDirToFileName
   499 // ----------------------------------------------------------------------------
   754 // ----------------------------------------------------------------------------
   500 //
   755 //
   501 EXPORT_C TInt ESMRHelper::CreateAndAppendPrivateDirToFileName(TFileName& aFileName)
   756 EXPORT_C TInt ESMRHelper::CreateAndAppendPrivateDirToFileName(
   502     {
   757         TFileName& aFileName)
   503     TFileName KPath;
   758     {
       
   759     FUNC_LOG;
       
   760 
       
   761     TFileName path;
   504     RFs fsSession;
   762     RFs fsSession;
   505     TInt result = fsSession.Connect();
   763     TInt result = fsSession.Connect();
   506     if(result==KErrNone)
   764     if ( KErrNone == result )
   507         {
   765         {
   508         fsSession.PrivatePath(KPath);
   766         TBool createPrivatePath( ETrue );
       
   767 
       
   768         fsSession.PrivatePath(path);
       
   769 
   509         TFindFile findFile(fsSession);
   770         TFindFile findFile(fsSession);
   510 
   771         result = findFile.FindByDir(path, KNullDesC);
   511         result = findFile.FindByDir(KPath, KNullDesC);
   772         if (KErrNone == result )
   512         if (result != KErrNone) //create path if doesn't exists
   773             {
   513             {
   774             // Check that we are able to drive into private path location
   514             fsSession.CreatePrivatePath(TDriveUnit(PathInfo::PhoneMemoryRootPath()));
   775             createPrivatePath = EFalse;
   515             result = findFile.FindByDir(KPath, KNullDesC);
   776 
   516             }
   777             path = findFile.File();
   517         KPath = findFile.File();
   778             TInt drive = TDriveUnit( path );
   518         aFileName.Insert(0,KPath);
   779             TInt KRomDrive = TDriveUnit( PathInfo::RomRootPath() );
       
   780 
       
   781             if ( drive == KRomDrive )
       
   782                 {
       
   783                 // Private path locates in ROM
       
   784                 createPrivatePath = ETrue;
       
   785                 }
       
   786             }
       
   787 
       
   788         TPtrC phoneMemoryPath( PathInfo::PhoneMemoryRootPath() );
       
   789 
       
   790         if ( createPrivatePath )
       
   791             {
       
   792             //create path if doesn't exists
       
   793             TInt drive = TDriveUnit(phoneMemoryPath);
       
   794             fsSession.CreatePrivatePath( drive );
       
   795             }
       
   796 
       
   797         result = findFile.FindByDir(path, KNullDesC);
       
   798         path = findFile.File();
       
   799         path[0] = phoneMemoryPath[0];
       
   800         aFileName.Insert(0,path);
       
   801 
   519         fsSession.MkDirAll(aFileName);
   802         fsSession.MkDirAll(aFileName);
   520         fsSession.Close();
   803         result = KErrNone;
   521         }
   804         }
       
   805 
       
   806     // fsSession
       
   807     fsSession.Close();
   522     return result;
   808     return result;
   523     }
   809     }
   524 //</cmail>
   810 //</cmail>
   525 
   811 
       
   812 // ----------------------------------------------------------------------------
       
   813 // ESMRHelper::CreateAndAppendOthersDirToFileName
       
   814 // ----------------------------------------------------------------------------
       
   815 //
       
   816 EXPORT_C TInt ESMRHelper::CreateAndAppendOthersDirToFileName(
       
   817             TFileName& aFileName)
       
   818     {
       
   819     FUNC_LOG;
       
   820 
       
   821     TFileName path;
       
   822     RFs fsSession;
       
   823     TInt result = fsSession.Connect();
       
   824     if ( KErrNone == result )
       
   825         {
       
   826         aFileName.Insert(0, PathInfo::OthersPath() );
       
   827         aFileName.Insert(0, PathInfo::PhoneMemoryRootPath() );
       
   828 
       
   829         fsSession.MkDirAll(aFileName);
       
   830 
       
   831         result = KErrNone;
       
   832         }
       
   833 
       
   834     // fsSession
       
   835     fsSession.Close();
       
   836     return result;
       
   837     }
       
   838 
       
   839 // ----------------------------------------------------------------------------
       
   840 // ESMRHelper::CopyEntryAndSwitchTypeL
       
   841 // ----------------------------------------------------------------------------
       
   842 //
       
   843 CCalEntry* ESMRHelper::CopyEntryAndSwitchTypeL(
       
   844         const CCalEntry& aSourceEntry,
       
   845         TESMRCalendarEventType aTargetType )
       
   846     {
       
   847     FUNC_LOG;
       
   848     CCalEntry* entry = NULL;
       
   849 
       
   850     TESMRSwitchEventType switchType;
       
   851 
       
   852     switchType = ResolveSwitchType(
       
   853             ESMREntryHelper::EventTypeL( aSourceEntry ), aTargetType );
       
   854 
       
   855     switch ( switchType )
       
   856         {
       
   857         case EMRSwitchMRToMeeting:
       
   858             {
       
   859             entry = SwitchToMeetingL( aSourceEntry );
       
   860             break;
       
   861             }
       
   862         case EMRSwitchMRToMemo:
       
   863             {
       
   864             entry = SwitchToMemoL( aSourceEntry );
       
   865             break;
       
   866             }
       
   867         case EMRSwitchMRToAnniversary:
       
   868             {
       
   869             entry = SwitchToAnniversaryL( aSourceEntry );
       
   870             break;
       
   871             }
       
   872         case EMRSwitchMRToTodo:
       
   873             {
       
   874             entry = SwitchToTodoL( aSourceEntry );
       
   875             break;
       
   876             }
       
   877         case EMRSwitchMeetingToMR:
       
   878             {
       
   879             entry = SwitchToMRL( aSourceEntry );
       
   880             break;
       
   881             }
       
   882         case EMRSwitchMeetingToMemo:
       
   883             {
       
   884             entry = SwitchToMemoL( aSourceEntry );
       
   885             break;
       
   886             }
       
   887         case EMRSwitchMeetingToAnniversary:
       
   888             {
       
   889             entry = SwitchToAnniversaryL( aSourceEntry );
       
   890             break;
       
   891             }
       
   892         case EMRSwitchMeetingToTodo:
       
   893             {
       
   894             entry = SwitchToTodoL( aSourceEntry );
       
   895             break;
       
   896             }
       
   897         case EMRSwitchMemoToMR:
       
   898             {
       
   899             entry = SwitchToMRL( aSourceEntry );
       
   900             break;
       
   901             }
       
   902         case EMRSwitchMemoToMeeting:
       
   903             {
       
   904             entry = SwitchToMeetingL( aSourceEntry );
       
   905             break;
       
   906             }
       
   907         case EMRSwitchMemoToAnniversary:
       
   908             {
       
   909             entry = SwitchToAnniversaryL( aSourceEntry );
       
   910             break;
       
   911             }
       
   912         case EMRSwitchMemoToTodo:
       
   913             {
       
   914             entry = SwitchToTodoL( aSourceEntry );
       
   915             break;
       
   916             }
       
   917         case EMRSwitchAnniversaryToMR:
       
   918             {
       
   919             entry = SwitchToMRL( aSourceEntry );
       
   920             break;
       
   921             }
       
   922         case EMRSwitchAnniversaryToMeeting:
       
   923             {
       
   924             entry = SwitchToMeetingL( aSourceEntry );
       
   925             break;
       
   926             }
       
   927         case EMRSwitchAnniversaryToMemo:
       
   928             {
       
   929             entry = SwitchToMemoL( aSourceEntry );
       
   930             break;
       
   931             }
       
   932         case EMRSwitchAnniversaryToTodo:
       
   933             {
       
   934             entry = SwitchToTodoL( aSourceEntry );
       
   935             break;
       
   936             }
       
   937         case EMRSwitchTodoToMR:
       
   938             {
       
   939             entry = SwitchToMRL( aSourceEntry );
       
   940             break;
       
   941             }
       
   942         case EMRSwitchTodoToMeeting:
       
   943             {
       
   944             entry = SwitchToMeetingL( aSourceEntry );
       
   945             break;
       
   946             }
       
   947         case EMRSwitchTodoToMemo:
       
   948             {
       
   949             entry = SwitchToMemoL( aSourceEntry );
       
   950             break;
       
   951             }
       
   952         case EMRSwitchTodoToAnniversary:
       
   953             {
       
   954             entry = SwitchToAnniversaryL( aSourceEntry );
       
   955             break;
       
   956             }
       
   957 
       
   958         default:
       
   959             {
       
   960             __ASSERT_DEBUG( EFalse, Panic( EInvalidEntryType ) );
       
   961             }
       
   962         }
       
   963 
       
   964     return entry;
       
   965     }
       
   966 
       
   967 // ----------------------------------------------------------------------------
       
   968 // ESMRHelper::ResolveSwitchType
       
   969 // ----------------------------------------------------------------------------
       
   970 //
       
   971 ESMRHelper::TESMRSwitchEventType ESMRHelper::ResolveSwitchType(
       
   972         TESMRCalendarEventType aSourceType,
       
   973         TESMRCalendarEventType aTargetType )
       
   974     {
       
   975     FUNC_LOG;
       
   976 
       
   977     TESMRSwitchEventType type( EMRSwitchUnknown );
       
   978 
       
   979     if( aSourceType == EESMREventTypeMeetingRequest ) // Meeting request
       
   980         {
       
   981         if( aTargetType == EESMREventTypeAppt )
       
   982             {
       
   983             type = EMRSwitchMRToMeeting;
       
   984             }
       
   985 
       
   986         if( aTargetType == EESMREventTypeEEvent )
       
   987              {
       
   988              type = EMRSwitchMRToMemo;
       
   989              }
       
   990 
       
   991         if( aTargetType == EESMREventTypeEAnniv )
       
   992              {
       
   993              type = EMRSwitchMRToAnniversary;
       
   994              }
       
   995 
       
   996         if( aTargetType == EESMREventTypeETodo )
       
   997              {
       
   998              type = EMRSwitchMRToTodo;
       
   999              }
       
  1000         }
       
  1001 
       
  1002     if( aSourceType == EESMREventTypeAppt ) // Meeting
       
  1003         {
       
  1004         if( aTargetType == EESMREventTypeMeetingRequest )
       
  1005             {
       
  1006             type = EMRSwitchMeetingToMR;
       
  1007             }
       
  1008 
       
  1009         if( aTargetType == EESMREventTypeEEvent )
       
  1010              {
       
  1011              type = EMRSwitchMeetingToMemo;
       
  1012              }
       
  1013 
       
  1014         if( aTargetType == EESMREventTypeEAnniv )
       
  1015              {
       
  1016              type = EMRSwitchMeetingToAnniversary;
       
  1017              }
       
  1018 
       
  1019         if( aTargetType == EESMREventTypeETodo )
       
  1020              {
       
  1021              type = EMRSwitchMeetingToTodo;
       
  1022              }
       
  1023         }
       
  1024 
       
  1025     if( aSourceType == EESMREventTypeEEvent ) // Memo
       
  1026         {
       
  1027         if( aTargetType == EESMREventTypeMeetingRequest )
       
  1028             {
       
  1029             type = EMRSwitchMemoToMR;
       
  1030             }
       
  1031 
       
  1032         if( aTargetType == EESMREventTypeAppt )
       
  1033              {
       
  1034              type = EMRSwitchMemoToMeeting;
       
  1035              }
       
  1036 
       
  1037         if( aTargetType == EESMREventTypeEAnniv )
       
  1038              {
       
  1039              type = EMRSwitchMemoToAnniversary;
       
  1040              }
       
  1041 
       
  1042         if( aTargetType == EESMREventTypeETodo )
       
  1043              {
       
  1044              type = EMRSwitchMemoToTodo;
       
  1045              }
       
  1046         }
       
  1047 
       
  1048     if( aSourceType == EESMREventTypeEAnniv ) // Anniversary
       
  1049         {
       
  1050         if( aTargetType == EESMREventTypeMeetingRequest )
       
  1051             {
       
  1052             type = EMRSwitchAnniversaryToMR;
       
  1053             }
       
  1054 
       
  1055         if( aTargetType == EESMREventTypeAppt  )
       
  1056              {
       
  1057              type = EMRSwitchAnniversaryToMeeting;
       
  1058              }
       
  1059 
       
  1060         if( aTargetType == EESMREventTypeEEvent  )
       
  1061              {
       
  1062              type = EMRSwitchAnniversaryToMemo;
       
  1063              }
       
  1064 
       
  1065         if( aTargetType == EESMREventTypeETodo )
       
  1066              {
       
  1067              type = EMRSwitchAnniversaryToTodo;
       
  1068              }
       
  1069         }
       
  1070 
       
  1071     if( aSourceType == EESMREventTypeETodo ) // To-do
       
  1072         {
       
  1073         if( aTargetType == EESMREventTypeMeetingRequest )
       
  1074             {
       
  1075             type = EMRSwitchTodoToMR;
       
  1076             }
       
  1077 
       
  1078         if( aTargetType == EESMREventTypeAppt )
       
  1079              {
       
  1080              type = EMRSwitchTodoToMeeting;
       
  1081              }
       
  1082 
       
  1083         if( aTargetType == EESMREventTypeEEvent )
       
  1084              {
       
  1085              type = EMRSwitchTodoToMemo;
       
  1086              }
       
  1087 
       
  1088         if( aTargetType == EESMREventTypeEAnniv )
       
  1089              {
       
  1090              type = EMRSwitchTodoToAnniversary;
       
  1091              }
       
  1092         }
       
  1093 
       
  1094     __ASSERT_DEBUG( type != EMRSwitchUnknown, Panic( EInvalidSwitchType ) );
       
  1095 
       
  1096     return type;
       
  1097     }
       
  1098 
       
  1099 // ----------------------------------------------------------------------------
       
  1100 // ESMRHelper::SwitchToMemoL
       
  1101 // ----------------------------------------------------------------------------
       
  1102 //
       
  1103 CCalEntry* ESMRHelper::SwitchToMemoL(
       
  1104         const CCalEntry& aSourceEntry )
       
  1105     {
       
  1106     FUNC_LOG;
       
  1107     CCalEntry* entry = CreateEntryL(
       
  1108                 CCalEntry::EEvent,
       
  1109                 aSourceEntry.UidL(),
       
  1110                 CCalEntry::EMethodNone,
       
  1111                 CalCommon::EThisOnly );
       
  1112 
       
  1113     CleanupStack::PushL( entry );
       
  1114 
       
  1115     // Copy all data from existing entry to new entry
       
  1116     entry->CopyFromL( aSourceEntry );
       
  1117     // We must re-set the method to the original value
       
  1118     entry->SetMethodL( CCalEntry::EMethodNone );
       
  1119 
       
  1120 #ifdef RD_USE_PS2_APIS
       
  1121     // If source entry is a meeting request...
       
  1122     if( CCalenInterimUtils2::IsMeetingRequestL( *entry ) )
       
  1123         {
       
  1124         // ... we need to clear all MR specific data
       
  1125         entry->ClearMRSpecificDataL();
       
  1126         }
       
  1127 #endif // RD_USE_PS2_APIS
       
  1128 
       
  1129     // Memo is never a repeating event
       
  1130     entry->ClearRepeatingPropertiesL();
       
  1131 
       
  1132     // Memo has start and stop date without time value.
       
  1133     // Let's change the entry's start and stop times to memo specific
       
  1134     // Setting start date and stop date
       
  1135     TDateTime start = entry->StartTimeL().TimeLocalL().DateTime();
       
  1136     start.SetHour( 0 );
       
  1137     start.SetMinute( 0 );
       
  1138     start.SetSecond( 0 );
       
  1139 
       
  1140     TTime tempEnd = entry->EndTimeL().TimeLocalL();
       
  1141 
       
  1142     if( ESMREntryHelper::IsAllDayEventL( aSourceEntry ) )
       
  1143         {
       
  1144         // If source is all day event, we need to reduce one from the day,
       
  1145         // otherwise the new memo would be spanned over one day too long
       
  1146         tempEnd -= TTimeIntervalDays( 1 );
       
  1147         }
       
  1148 
       
  1149     TDateTime end = tempEnd.DateTime();
       
  1150     end.SetHour( KMaxHoursForMemo );
       
  1151     end.SetMinute( KMaxMinutesForMemo );
       
  1152     end.SetSecond( KMaxSecondsForMemo );
       
  1153 
       
  1154     TCalTime startDate;
       
  1155     startDate.SetTimeLocalFloatingL( start );
       
  1156     TCalTime stopDate;
       
  1157     stopDate.SetTimeLocalFloatingL( end );
       
  1158     entry->SetStartAndEndTimeL( startDate, stopDate );
       
  1159 
       
  1160     // Memo does not have any alarm value
       
  1161     entry->SetAlarmL( NULL );
       
  1162 
       
  1163     // If source entry is to-do, we need to convert the
       
  1164     // priority from to-do priority to normal priority
       
  1165     if( aSourceEntry.EntryTypeL() == CCalEntry::ETodo )
       
  1166         {
       
  1167         ConvertTodoPriorityToNormalL( *entry );
       
  1168         }
       
  1169 
       
  1170     CleanupStack::Pop( entry ); // ownership transferred to caller
       
  1171     return entry;
       
  1172     }
       
  1173 
       
  1174 // ----------------------------------------------------------------------------
       
  1175 // ESMRHelper::SwitchToAnniversaryL
       
  1176 // ----------------------------------------------------------------------------
       
  1177 //
       
  1178 CCalEntry* ESMRHelper::SwitchToAnniversaryL(
       
  1179         const CCalEntry& aSourceEntry )
       
  1180     {
       
  1181     FUNC_LOG;
       
  1182     // Create an entry
       
  1183     CCalEntry* entry = CreateEntryL(
       
  1184             CCalEntry::EAnniv,
       
  1185             aSourceEntry.UidL(),
       
  1186             CCalEntry::EMethodNone,
       
  1187             CalCommon::EThisOnly );
       
  1188 
       
  1189     CleanupStack::PushL( entry );
       
  1190 
       
  1191     // Copy all data from existing entry to new entry
       
  1192     entry->CopyFromL( aSourceEntry );
       
  1193     // We must re-set the method to the original value
       
  1194     entry->SetMethodL( CCalEntry::EMethodNone );
       
  1195 
       
  1196 #ifdef RD_USE_PS2_APIS
       
  1197     // If source entry is a meeting request...
       
  1198     if( CCalenInterimUtils2::IsMeetingRequestL( *entry ) )
       
  1199         {
       
  1200         // ... we need to clear all MR specific data
       
  1201         entry->ClearMRSpecificDataL();
       
  1202         }
       
  1203 #endif // RD_USE_PS2_APIS
       
  1204 
       
  1205     // Anniversary repeats once a year, so
       
  1206     // we clear existing repeating rules...
       
  1207     entry->ClearRepeatingPropertiesL();
       
  1208 
       
  1209     // ... and create a new rule, to repeat once a year
       
  1210     TCalRRule rrule( TCalRRule::EYearly );
       
  1211     rrule.SetDtStart( entry->StartTimeL() );
       
  1212     rrule.SetInterval( 1 );
       
  1213     rrule.SetCount( 0 );
       
  1214     entry->SetRRuleL( rrule );
       
  1215 
       
  1216     // Anniversary default alarm is previous day at noon.
       
  1217     // Let's set that also.
       
  1218     TTime eventTime = entry->StartTimeL().TimeLocalL();
       
  1219     TTime alarmTime = eventTime - TTimeIntervalDays( 1 );
       
  1220     TDateTime alarmDateTime = alarmTime.DateTime();
       
  1221     alarmDateTime.SetHour( KDefaultAnniversaryAlarmHours );
       
  1222     alarmDateTime.SetMinute( 0 );
       
  1223     alarmDateTime.SetSecond( 0 );
       
  1224     alarmDateTime.SetMicroSecond( 0 );
       
  1225     alarmTime = alarmDateTime;
       
  1226 
       
  1227     // Calculating alarm offset
       
  1228     TTimeIntervalMinutes alarmOffset( 0 );
       
  1229     eventTime.MinutesFrom( alarmTime, alarmOffset );
       
  1230 
       
  1231     // Creating alarm
       
  1232     CCalAlarm* alarm = CCalAlarm::NewL();
       
  1233     CleanupStack::PushL( alarm );
       
  1234     alarm->SetTimeOffset( alarmOffset );
       
  1235 
       
  1236     // Setting alarm
       
  1237     entry->SetAlarmL( alarm );
       
  1238     CleanupStack::PopAndDestroy( alarm );
       
  1239     alarm = NULL;
       
  1240 
       
  1241     // If source entry is to-do, we need to convert the
       
  1242     // priority from to-do priority to normal priority
       
  1243     if( aSourceEntry.EntryTypeL() == CCalEntry::ETodo )
       
  1244         {
       
  1245         ConvertTodoPriorityToNormalL( *entry );
       
  1246         }
       
  1247 
       
  1248     CleanupStack::Pop( entry ); // ownership transferred to caller
       
  1249     return entry;
       
  1250     }
       
  1251 
       
  1252 // ----------------------------------------------------------------------------
       
  1253 // ESMRHelper::SwitchToTodoL
       
  1254 // ----------------------------------------------------------------------------
       
  1255 //
       
  1256 CCalEntry* ESMRHelper::SwitchToTodoL(
       
  1257         const CCalEntry& aSourceEntry )
       
  1258     {
       
  1259     FUNC_LOG;
       
  1260     CCalEntry* entry = CreateEntryL(
       
  1261             CCalEntry::ETodo,
       
  1262             aSourceEntry.UidL(),
       
  1263             CCalEntry::EMethodNone,
       
  1264             CalCommon::EThisOnly );
       
  1265 
       
  1266     CleanupStack::PushL( entry );
       
  1267 
       
  1268     // Copy all data from existing entry to new entry
       
  1269     entry->CopyFromL( aSourceEntry );
       
  1270     // We must re-set the method to the original value
       
  1271     entry->SetMethodL( CCalEntry::EMethodNone );
       
  1272 
       
  1273 #ifdef RD_USE_PS2_APIS
       
  1274     // If source entry is a meeting request...
       
  1275     if( CCalenInterimUtils2::IsMeetingRequestL( *entry ) )
       
  1276         {
       
  1277         // ... we need to clear all MR specific data
       
  1278         entry->ClearMRSpecificDataL();
       
  1279         }
       
  1280 #endif // RD_USE_PS2_APIS
       
  1281 
       
  1282     // To-do is never a repeating event
       
  1283     entry->ClearRepeatingPropertiesL();
       
  1284 
       
  1285     // To-do has a due date only. Let's change the entry's start and stop
       
  1286     // times to To-do specific ones
       
  1287     TTime tempEnd = entry->EndTimeL().TimeLocalL();
       
  1288 
       
  1289     if( ESMREntryHelper::IsAllDayEventL( aSourceEntry ) )
       
  1290         {
       
  1291         // If source is all day event, we need to reduce one from the day,
       
  1292         // otherwise the new todos due date would be one day late
       
  1293         tempEnd -= TTimeIntervalDays( 1 );
       
  1294         }
       
  1295 
       
  1296     TDateTime tempDue = tempEnd.DateTime();
       
  1297 
       
  1298     tempDue.SetHour( KMaxHoursForTodo );
       
  1299     tempDue.SetMinute( KMaxMinutesForTodo );
       
  1300     tempDue.SetSecond( KMaxSecondsForTodo );
       
  1301 
       
  1302     TCalTime dueDate;
       
  1303     dueDate.SetTimeLocalFloatingL( tempDue );
       
  1304 
       
  1305     entry->SetStartAndEndTimeL( dueDate, dueDate );
       
  1306 
       
  1307     // Setting to-do specific alarm
       
  1308     if( entry->AlarmL() )
       
  1309         {
       
  1310         // Setting default To-do alarm for entry
       
  1311         TTime eventTime = entry->EndTimeL().TimeLocalL();
       
  1312 
       
  1313         // Calculate alarm time (due date at 12:00am)
       
  1314         TTime alarmTime = eventTime;
       
  1315         TDateTime alarmDateTime = alarmTime.DateTime();
       
  1316         alarmDateTime.SetHour( KDefaultTodoAlarmHours );
       
  1317         alarmDateTime.SetMinute( 0 );
       
  1318         alarmDateTime.SetSecond( 0 );
       
  1319         alarmDateTime.SetMicroSecond( 0 );
       
  1320         alarmTime = alarmDateTime;
       
  1321 
       
  1322         TTime currentTime;
       
  1323         currentTime.HomeTime();
       
  1324 
       
  1325         // If alarm is in the future
       
  1326         if ( alarmTime > currentTime )
       
  1327             {
       
  1328             CCalAlarm* alarm = CCalAlarm::NewL();
       
  1329             CleanupStack::PushL( alarm );
       
  1330             TTimeIntervalMinutes alarmOffset( 0 );
       
  1331             eventTime.MinutesFrom( alarmTime, alarmOffset );
       
  1332             alarm->SetTimeOffset( alarmOffset );
       
  1333             entry->SetAlarmL( alarm );
       
  1334             CleanupStack::PopAndDestroy( alarm );
       
  1335             }
       
  1336         // Alarm is in the past, let's set it to NULL
       
  1337         else
       
  1338             {
       
  1339             entry->SetAlarmL( NULL );
       
  1340             }
       
  1341         }
       
  1342 
       
  1343     // Setting to-do specific priority
       
  1344     TInt priority( 0 );
       
  1345     if( entry->PriorityL() == EFSCalenMRPriorityHigh )
       
  1346         {
       
  1347         priority = EFSCalenTodoPriorityHigh;
       
  1348         }
       
  1349 
       
  1350     else if( entry->PriorityL() == EFSCalenMRPriorityNormal )
       
  1351         {
       
  1352         priority = EFSCalenTodoPriorityNormal;
       
  1353         }
       
  1354 
       
  1355     else if( entry->PriorityL() == EFSCalenMRPriorityLow )
       
  1356         {
       
  1357         priority = EFSCalenTodoPriorityLow;
       
  1358         }
       
  1359 
       
  1360     else
       
  1361         {
       
  1362         // Priority unknown, let's set it to normal then
       
  1363         priority = EFSCalenTodoPriorityNormal;
       
  1364         }
       
  1365 
       
  1366     entry->SetPriorityL( priority );
       
  1367 
       
  1368     CleanupStack::Pop( entry ); // ownership transferred to caller
       
  1369     return entry;
       
  1370     }
       
  1371 
       
  1372 // ----------------------------------------------------------------------------
       
  1373 // ESMRHelper::SwitchToMeetingL
       
  1374 // ----------------------------------------------------------------------------
       
  1375 //
       
  1376 CCalEntry* ESMRHelper::SwitchToMeetingL(
       
  1377         const CCalEntry& aSourceEntry )
       
  1378     {
       
  1379     FUNC_LOG;
       
  1380 
       
  1381     CCalEntry* entry = CreateEntryL(
       
  1382             CCalEntry::EAppt,
       
  1383             aSourceEntry.UidL(),
       
  1384             CCalEntry::EMethodNone,
       
  1385             CalCommon::EThisOnly );
       
  1386 
       
  1387     CleanupStack::PushL( entry );
       
  1388 
       
  1389     // Copy all data from existing entry to new entry
       
  1390     entry->CopyFromL( aSourceEntry );
       
  1391 
       
  1392     // If source was to-do, priority needs converting
       
  1393     if( aSourceEntry.EntryTypeL() == CCalEntry::ETodo )
       
  1394     	{
       
  1395 		ConvertTodoPriorityToNormalL( *entry );
       
  1396     	}
       
  1397 
       
  1398     // We must re-set the method to the original value
       
  1399     entry->SetMethodL( CCalEntry::EMethodNone );
       
  1400 
       
  1401 #ifdef RD_USE_PS2_APIS
       
  1402     // If source entry is a meeting request...
       
  1403     if( CCalenInterimUtils2::IsMeetingRequestL( *entry ) )
       
  1404         {
       
  1405         // ... we need to clear all MR specific data,
       
  1406         // but otherwise the enrty is now converted
       
  1407         // correctly from MR to meeting
       
  1408         entry->ClearMRSpecificDataL();
       
  1409         }
       
  1410     else
       
  1411 #endif // RD_USE_PS2_APIS
       
  1412         {
       
  1413         // Repeating rules from memo, to-do and anniversary
       
  1414         // are not compatible with a meeting
       
  1415         entry->ClearRepeatingPropertiesL();
       
  1416 
       
  1417         // Setting meeting time, since memo, to-do and anniversary
       
  1418         // start / end times are not compatible with meeting's corresponding
       
  1419         // values
       
  1420         SetMeetingTimeL( *entry, aSourceEntry );
       
  1421 
       
  1422         // If source is not an appointment, we'll set default
       
  1423         // alarm for meeting, since memo, to-do and anniversary
       
  1424         // alarms are not compatible with meeting alarm
       
  1425         if( entry->AlarmL() &&
       
  1426                 aSourceEntry.EntryTypeL() != CCalEntry::EAppt )
       
  1427             {
       
  1428             SetDefaultAlarmForMeetingL( *entry );
       
  1429             }
       
  1430 
       
  1431         // If source entry is to-do, we need to convert the
       
  1432         // priority from to-do priority to normal priority
       
  1433         if( aSourceEntry.EntryTypeL() == CCalEntry::ETodo )
       
  1434             {
       
  1435             ConvertTodoPriorityToNormalL( *entry );
       
  1436             }
       
  1437         }
       
  1438 
       
  1439     CleanupStack::Pop( entry ); // ownership transferred to caller
       
  1440     return entry;
       
  1441     }
       
  1442 
       
  1443 // ----------------------------------------------------------------------------
       
  1444 // ESMRHelper::SwitchToMRL
       
  1445 // ----------------------------------------------------------------------------
       
  1446 //
       
  1447 CCalEntry* ESMRHelper::SwitchToMRL(
       
  1448         const CCalEntry& aSourceEntry )
       
  1449     {
       
  1450     FUNC_LOG;
       
  1451     CCalEntry* entry = CreateEntryL(
       
  1452             CCalEntry::EAppt,
       
  1453             aSourceEntry.UidL(),
       
  1454             CCalEntry::EMethodRequest,
       
  1455             CalCommon::EThisOnly );
       
  1456 
       
  1457     CleanupStack::PushL( entry );
       
  1458 
       
  1459     // Copy all data from existing entry to new entry
       
  1460     entry->CopyFromL( aSourceEntry );
       
  1461 
       
  1462     // If source was to-do, priority needs converting
       
  1463     if( aSourceEntry.EntryTypeL() == CCalEntry::ETodo )
       
  1464     	{
       
  1465 		ConvertTodoPriorityToNormalL( *entry );
       
  1466     	}
       
  1467 
       
  1468     // We must re-set the method to the original value
       
  1469     entry->SetMethodL( CCalEntry::EMethodRequest );
       
  1470 
       
  1471     // If source is a meeting...
       
  1472     if( aSourceEntry.EntryTypeL() != CCalEntry::EAppt )
       
  1473         {
       
  1474         // Repeating rules from memo, to-do and anniversary
       
  1475         // are not compatible with MR
       
  1476         entry->ClearRepeatingPropertiesL();
       
  1477 
       
  1478         // Setting meeting time, since memo, to-do and anniversary
       
  1479         // start / end times are not compatible with MR's corresponding
       
  1480         // values
       
  1481         SetMeetingTimeL( *entry, aSourceEntry );
       
  1482 
       
  1483         // If source is not an appointment, we'll set default
       
  1484         // alarm for MR, since memo, to-do and anniversary
       
  1485         // alarms are not compatible with MR alarm
       
  1486         if( entry->AlarmL() &&
       
  1487                 aSourceEntry.EntryTypeL() != CCalEntry::EAppt )
       
  1488             {
       
  1489             SetDefaultAlarmForMeetingL( *entry );
       
  1490             }
       
  1491 
       
  1492         // If source entry is to-do, we need to convert the
       
  1493         // priority from to-do priority to normal priority
       
  1494         if( aSourceEntry.EntryTypeL() == CCalEntry::ETodo )
       
  1495             {
       
  1496             ConvertTodoPriorityToNormalL( *entry );
       
  1497             }
       
  1498         }
       
  1499 
       
  1500     // Add organizer
       
  1501     AddOrganizerL( *entry );
       
  1502 
       
  1503     // Set organizer as phone owner
       
  1504     entry->SetPhoneOwnerL( entry->OrganizerL() );
       
  1505 
       
  1506     CleanupStack::Pop( entry ); // ownership transferred to caller
       
  1507     return entry;
       
  1508     }
       
  1509 
       
  1510 // ----------------------------------------------------------------------------
       
  1511 // ESMRHelper::CreateEntryL
       
  1512 // ----------------------------------------------------------------------------
       
  1513 //
       
  1514 CCalEntry* ESMRHelper::CreateEntryL(
       
  1515         CCalEntry::TType aType,
       
  1516         const TDesC8& aUid,
       
  1517         CCalEntry::TMethod aMethod,
       
  1518         CalCommon::TRecurrenceRange aRange )
       
  1519     {
       
  1520     FUNC_LOG;
       
  1521 
       
  1522     HBufC8* guid = aUid.AllocLC();
       
  1523     CCalEntry* entry = CCalEntry::NewL( aType, guid, aMethod, aRange );
       
  1524     CleanupStack::Pop( guid );
       
  1525 
       
  1526     return entry;
       
  1527     }
       
  1528 
       
  1529 // ----------------------------------------------------------------------------
       
  1530 // ESMRHelper::SetMeetingTimeL
       
  1531 // ----------------------------------------------------------------------------
       
  1532 //
       
  1533 void ESMRHelper::SetMeetingTimeL(
       
  1534         CCalEntry& aTargetEntry,
       
  1535         const CCalEntry& aSourceEntry )
       
  1536     {
       
  1537     FUNC_LOG;
       
  1538     TCalTime start;
       
  1539     TCalTime end;
       
  1540 
       
  1541     TDateTime tempStart;
       
  1542     TDateTime tempEnd;
       
  1543 
       
  1544     CCalEntry::TType type = aSourceEntry.EntryTypeL();
       
  1545 
       
  1546     switch ( type )
       
  1547         {
       
  1548         case CCalEntry::EAppt:
       
  1549             {
       
  1550             start.SetTimeLocalL( aSourceEntry.StartTimeL().TimeLocalL() );
       
  1551             end.SetTimeLocalL( aSourceEntry.EndTimeL().TimeLocalL() );
       
  1552             break;
       
  1553             }
       
  1554         case CCalEntry::ETodo:
       
  1555             {
       
  1556             // Todo has only due date => Adding date from that,
       
  1557             // Hour, minute and second as default values
       
  1558             tempStart = aSourceEntry.StartTimeL().TimeLocalL().DateTime();
       
  1559             tempStart.SetHour( KDefaultMeetingStartHour );
       
  1560             tempStart.SetMinute( 0 );
       
  1561             tempStart.SetSecond( 0 );
       
  1562 
       
  1563             tempEnd = aSourceEntry.StartTimeL().TimeLocalL().DateTime();
       
  1564             tempEnd.SetHour( KDefaultMeetingEndHour );
       
  1565             tempEnd.SetMinute( 0 );
       
  1566             tempEnd.SetSecond( 0 );
       
  1567 
       
  1568             start.SetTimeLocalL( tempStart );
       
  1569             end.SetTimeLocalL( tempEnd );
       
  1570             break;
       
  1571             }
       
  1572         case CCalEntry::EEvent: //Memo
       
  1573             {
       
  1574             // Memo is one day event with start time as 00:00 and end as 23:59
       
  1575             // Let's add start date from that, and set hour, minute and second
       
  1576             // as default values
       
  1577             tempStart = aSourceEntry.StartTimeL().TimeLocalL().DateTime();
       
  1578             tempStart.SetHour( KDefaultMeetingStartHour );
       
  1579             tempStart.SetMinute( 0 );
       
  1580             tempStart.SetSecond( 0 );
       
  1581 
       
  1582             tempEnd = aSourceEntry.StartTimeL().TimeLocalL().DateTime();
       
  1583             tempEnd.SetHour( KDefaultMeetingEndHour );
       
  1584             tempEnd.SetMinute( 0 );
       
  1585             tempEnd.SetSecond( 0 );
       
  1586 
       
  1587             start.SetTimeLocalL( tempStart );
       
  1588             end.SetTimeLocalL( tempEnd );
       
  1589 
       
  1590             break;
       
  1591             }
       
  1592         case CCalEntry::EAnniv:
       
  1593             {
       
  1594             // Anniversary has start date, which is taken as date of the meeting.
       
  1595             // Hour, minute and second are set as teh default values.
       
  1596             tempStart = aSourceEntry.StartTimeL().TimeLocalL().DateTime();
       
  1597             tempStart.SetHour( KDefaultMeetingStartHour );
       
  1598             tempStart.SetMinute( 0 );
       
  1599             tempStart.SetSecond( 0 );
       
  1600 
       
  1601             tempEnd = aSourceEntry.StartTimeL().TimeLocalL().DateTime();
       
  1602             tempEnd.SetHour( KDefaultMeetingEndHour );
       
  1603             tempEnd.SetMinute( 0 );
       
  1604             tempEnd.SetSecond( 0 );
       
  1605 
       
  1606             start.SetTimeLocalL( tempStart );
       
  1607             end.SetTimeLocalL( tempEnd );
       
  1608             break;
       
  1609             }
       
  1610 
       
  1611         default:
       
  1612             {
       
  1613             __ASSERT_DEBUG( EFalse, Panic( EInvalidEntryType ) );
       
  1614             }
       
  1615         }
       
  1616 
       
  1617     aTargetEntry.SetStartAndEndTimeL( start, end );
       
  1618     }
       
  1619 
       
  1620 // ----------------------------------------------------------------------------
       
  1621 // ESMRHelper::SetDefaultAlarmForMetingL
       
  1622 // ----------------------------------------------------------------------------
       
  1623 //
       
  1624 void ESMRHelper::SetDefaultAlarmForMeetingL(
       
  1625         CCalEntry& aTargetEntry )
       
  1626     {
       
  1627     FUNC_LOG;
       
  1628 
       
  1629     // Get default alarm time from central repository
       
  1630     TInt defaultAlarmTime;
       
  1631     CRepository* repository = CRepository::NewLC( KCRUidCalendar );
       
  1632     TInt err = repository->Get( KCalendarDefaultAlarmTime, defaultAlarmTime );
       
  1633     CleanupStack::PopAndDestroy( repository );
       
  1634 
       
  1635     if ( err != KErrNone )
       
  1636         {
       
  1637         defaultAlarmTime = KDefaultMeetingAlarmMinutes;
       
  1638         }
       
  1639 
       
  1640     // Getting current time
       
  1641     TTime currentTime;
       
  1642     currentTime.HomeTime();
       
  1643 
       
  1644     // Getting meeting start time
       
  1645     TTime start = aTargetEntry.StartTimeL().TimeLocalL();
       
  1646 
       
  1647     // Create default alarm
       
  1648     CCalAlarm* alarm = CCalAlarm::NewL();
       
  1649     CleanupStack::PushL( alarm );
       
  1650 
       
  1651     TTimeIntervalMinutes alarmOffset( defaultAlarmTime );
       
  1652 
       
  1653     // If alarm time is in past
       
  1654     if ( ( start - alarmOffset ) < currentTime )
       
  1655         {
       
  1656         // Setting alarm off
       
  1657         aTargetEntry.SetAlarmL( NULL );
       
  1658         }
       
  1659     else
       
  1660         {
       
  1661         // Set default alarm time
       
  1662         alarm->SetTimeOffset( alarmOffset );
       
  1663         aTargetEntry.SetAlarmL( alarm );
       
  1664         }
       
  1665     CleanupStack::PopAndDestroy( alarm );
       
  1666 
       
  1667     }
       
  1668 
       
  1669 // ---------------------------------------------------------------------------
       
  1670 // ESMRHelper::AddOrganizerL
       
  1671 // ---------------------------------------------------------------------------
       
  1672 //
       
  1673 void ESMRHelper::AddOrganizerL( CCalEntry& aTargetEntry )
       
  1674     {
       
  1675     FUNC_LOG;
       
  1676     CMRMailboxUtils* mbUtils = CMRMailboxUtils::NewL( NULL );
       
  1677     CleanupStack::PushL( mbUtils );
       
  1678 
       
  1679     CMRMailboxUtils::TMailboxInfo defaultMailBox;
       
  1680     TInt err = mbUtils->GetDefaultMRMailBoxL( defaultMailBox );
       
  1681 
       
  1682     if ( KErrNone != err )
       
  1683         {
       
  1684         RArray<CMRMailboxUtils::TMailboxInfo> mailBoxes;
       
  1685         CleanupClosePushL( mailBoxes );
       
  1686 
       
  1687         SupportedMailboxesL( *mbUtils, mailBoxes );
       
  1688 
       
  1689         TInt selectedMailbox( PromptForDefaultMailboxL(mailBoxes) );
       
  1690 
       
  1691         if ( KErrCancel != selectedMailbox )
       
  1692             {
       
  1693             mbUtils->SetDefaultMRMailBoxL(
       
  1694                     mailBoxes[selectedMailbox].iEntryId ); // codescanner::accessArrayElementWithoutCheck2
       
  1695             mbUtils->GetDefaultMRMailBoxL(defaultMailBox);
       
  1696             }
       
  1697         CleanupStack::PopAndDestroy( &mailBoxes );
       
  1698 
       
  1699         // This will leave if user cancelled the mailbox selection
       
  1700         User::LeaveIfError( selectedMailbox );
       
  1701         }
       
  1702 
       
  1703     //Set the organizer from the selected mailbox
       
  1704     CCalUser* organizer = CCalUser::NewL( defaultMailBox.iEmailAddress );
       
  1705     CleanupStack::PushL( organizer );
       
  1706     aTargetEntry.SetOrganizerL( organizer );
       
  1707     CleanupStack::Pop( organizer ); // Ownership trasferred
       
  1708 
       
  1709     CleanupStack::PopAndDestroy( mbUtils );
       
  1710     }
       
  1711 
   526 // EOF
  1712 // EOF
       
  1713