javaextensions/pim/versit/src.s60/cpimeventpropertyconverter.cpp
branchRCL_3
changeset 19 04becd199f91
child 23 98ccebc37403
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Converts event properties PIM API <-> versit
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // CLASS HEADER
       
    20 #include "cpimeventpropertyconverter.h"
       
    21 
       
    22 // INTERNAL INCLUDES
       
    23 #include "pimcommon.h" // tpimfield
       
    24 #include "pimpanics.h"
       
    25 #include "pimversit.h"
       
    26 #include "cpimparserproperty.h"
       
    27 #include "cpimitem.h"
       
    28 #include "cpimeventitem.h"
       
    29 #include "mpimrepeatruledata.h"
       
    30 #include "cleanupresetanddestroy.h"
       
    31 #include "logger.h"
       
    32 
       
    33 // EXTERNAL INCLUDES
       
    34 #include <vcal.h>
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CPIMEventPropertyConverter::NewL
       
    40 // Two-phased constructor.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CPIMEventPropertyConverter* CPIMEventPropertyConverter::NewL()
       
    44 {
       
    45     JELOG2(EPim);
       
    46     CPIMEventPropertyConverter* self =
       
    47         new(ELeave) CPIMEventPropertyConverter();
       
    48     return self;
       
    49 }
       
    50 
       
    51 // Destructor
       
    52 CPIMEventPropertyConverter::~CPIMEventPropertyConverter()
       
    53 {
       
    54     JELOG2(EPim);
       
    55 }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CPIMCardConverter::ConvertPropertyL
       
    59 // Inserts a proprety from a vEvent to a PIM Event Item as a field
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CPIMEventPropertyConverter::ConvertPropertyL(
       
    63     const CParserProperty& aProperty, // property to convert
       
    64     CPIMEventItem& aItem, // item to insert the field to
       
    65     TPIMDate& aAlarm) // DALARM is stored here
       
    66 {
       
    67     JELOG2(EPim);
       
    68     TUid valueTypeUid = aProperty.Uid();
       
    69     TInt valueType = valueTypeUid.iUid;
       
    70 
       
    71     // The following, rather ugly, cast makes it possible for us to access
       
    72     // the protected iArrayOfParams field.
       
    73     const CPIMParserProperty& property =
       
    74         static_cast<const CPIMParserProperty&>(aProperty);
       
    75 
       
    76     if (aProperty.Name().CompareF(KVersitTokenCLASS) == 0)
       
    77     {
       
    78         ConvertClassPropertyL(property, aItem);
       
    79     }
       
    80     else
       
    81     {
       
    82         switch (valueType)
       
    83         {
       
    84         case KVersitPropertyDateTimeUid:
       
    85         {
       
    86             // Start, End, DALARM
       
    87             ConvertDatePropertyL(property, aItem);
       
    88             break;
       
    89         }
       
    90         case KVersitPropertyHBufCUid:
       
    91         {
       
    92             // summary, location
       
    93             ConvertStringPropertyL(property, aItem);
       
    94             break;
       
    95         }
       
    96         case KVersitPropertyMultiDateTimeUid:
       
    97         {
       
    98             // exdate
       
    99             ConvertExDatePropertyL(property, aItem);
       
   100             break;
       
   101         }
       
   102         case KVCalPropertyRecurrenceUid:
       
   103         {
       
   104             // repeat rule
       
   105             ConvertRepeatRulePropertyL(property, aItem);
       
   106             break;
       
   107         }
       
   108         case KVCalPropertyAlarmUid:
       
   109         {
       
   110             // DALARM
       
   111             ConvertAlarmPropertyL(property, aAlarm);
       
   112             break;
       
   113         }
       
   114         default:
       
   115         {
       
   116             // don't support, don't care
       
   117         }
       
   118         }
       
   119     }
       
   120 }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CPIMEventPropertyConverter::ConvertEventFieldL
       
   124 // Inserts a Field from a PIM Event Item to CParserVCard as a property.
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CPIMEventPropertyConverter::ConvertEventFieldL(const CPIMItem& aItem, // item to read the field from
       
   128         CParserVCalEntity& aParser, // parser to insert the property to.
       
   129         TPIMEventField aField) // field to convert
       
   130 {
       
   131     JELOG2(EPim);
       
   132     TInt valueCount = aItem.CountValuesL(aField);
       
   133     for (TInt i = 0; i < valueCount; i++)
       
   134     {
       
   135         switch (aField)
       
   136         {
       
   137         case EPIMEventAlarm:
       
   138         {
       
   139             ConvertAlarmFieldL(aItem, aParser, aField, i);
       
   140             break;
       
   141         }
       
   142         case EPIMEventStart:
       
   143         case EPIMEventEnd:
       
   144         case EPIMEventRevision:
       
   145         {
       
   146             ConvertDateFieldL(aItem, aParser, aField, i);
       
   147             break;
       
   148         }
       
   149         case EPIMEventSummary:
       
   150         case EPIMEventLocation:
       
   151         case EPIMEventNote:
       
   152             // UID is required by VFX. Do not fix even though this is wrong
       
   153         case EPIMEventUid:
       
   154         {
       
   155             ConvertStringFieldL(aItem, aParser, aField, i);
       
   156             break;
       
   157         }
       
   158         case EPIMEventClass:
       
   159         {
       
   160             ConvertClassFieldL(aItem, aParser, aField, i);
       
   161             break;
       
   162         }
       
   163         default:
       
   164         {
       
   165             __ASSERT_DEBUG(EFalse, User::Panic(KPIMPanicCategory,
       
   166                                                EPIMPanicUnsupportedField));
       
   167             return;
       
   168         }
       
   169         }
       
   170     }
       
   171 }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CPIMEventPropertyConverter::ConvertRepeatRuleL
       
   175 // Inserts a repeat rule to a parser.
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 void CPIMEventPropertyConverter::ConvertRepeatRuleL(
       
   179     const MPIMRepeatRuleData* aRepeat, CParserVCalEntity& aParser)
       
   180 {
       
   181     JELOG2(EPim);
       
   182     // First exception dates
       
   183     const CArrayFix<TPIMDate>& exceptionDates = aRepeat->GetExceptDatesL();
       
   184     ConvertExceptionDatesL(exceptionDates, aParser);
       
   185 
       
   186     // The interval is always set to 1 - only exception is every 2 weeks repeat
       
   187     TInt interval = 1;
       
   188     TInt frequency = 0;
       
   189     TVersitDateTime* versitEndDate = NULL;
       
   190 
       
   191     GetRepeatRuleFieldsL(aRepeat, &interval, &frequency, &versitEndDate);
       
   192     if (versitEndDate)
       
   193     {
       
   194         CleanupDeletePushL(versitEndDate);
       
   195     }
       
   196 
       
   197     CVersitRecurrence* recurrence = CreateRecurrenceL(frequency, interval,
       
   198                                     versitEndDate);
       
   199 
       
   200     if (versitEndDate)
       
   201     {
       
   202         CleanupStack::Pop(versitEndDate); // versitEndDate is owned by recurrence now
       
   203     }
       
   204     CleanupStack::PushL(recurrence);
       
   205 
       
   206     CParserPropertyValue* propertyValue =
       
   207         new(ELeave) CParserPropertyValueRecurrence(recurrence);
       
   208     // recurrence is now owned by propertyValue
       
   209     CleanupStack::Pop(recurrence);
       
   210     AddPropertyToParserL(propertyValue, KVersitTokenRRULE(), aParser);
       
   211     // Needed cleanup stack items are popped out in the AddPropretyToParserL
       
   212 }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CPIMEventPropertyConverter::CPIMEventPropertyConverter
       
   216 // C++ default constructor can NOT contain any code, that
       
   217 // might leave.
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 CPIMEventPropertyConverter::CPIMEventPropertyConverter()
       
   221 {
       
   222     JELOG2(EPim);
       
   223 }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CPIMEventPropertyConverter::ConvertDatePropertyL
       
   227 // Converts a date field from a vCard to a PIM Event Item
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CPIMEventPropertyConverter::ConvertDatePropertyL(
       
   231     const CPIMParserProperty& aProperty, // property to convert
       
   232     CPIMEventItem& aItem)
       
   233 {
       
   234     JELOG2(EPim);
       
   235     TPIMField field = aProperty.MatchEventField();
       
   236     // Do not match unrecognized fields
       
   237     if (field == -1)
       
   238     {
       
   239         return;
       
   240     }
       
   241 
       
   242     CParserPropertyValueDate* propertyValue =
       
   243         static_cast<CParserPropertyValueDate*>(aProperty.Value());
       
   244     const TVersitDateTime* value = propertyValue->Value();
       
   245 
       
   246     TPIMDate date(value->iDateTime);
       
   247     aItem.AddDateL(field, KPIMAttrNone, date);
       
   248 }
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CPIMEventPropertyConverter::ConvertAlarmPropertyL
       
   252 // Converts an alarm field from a vCard to a PIM Event Item
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 void CPIMEventPropertyConverter::ConvertAlarmPropertyL(
       
   256     const CPIMParserProperty& aProperty, // property to convert
       
   257     TPIMDate& aAlarm) // item to insert the field to
       
   258 {
       
   259     JELOG2(EPim);
       
   260     if (aProperty.MatchEventField() != EPIMEventAlarm)
       
   261     {
       
   262         return;
       
   263     }
       
   264 
       
   265     CParserPropertyValueAlarm* propertyValue =
       
   266         static_cast<CParserPropertyValueAlarm*>(aProperty.Value());
       
   267     const CVersitAlarm* value = propertyValue->Value();
       
   268 
       
   269     const TVersitDateTime* versitDT = value->iRunTime;
       
   270     TPIMDate date(versitDT->iDateTime);
       
   271 
       
   272     aAlarm = date;
       
   273 }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CPIMEventPropertyConverter::ConvertStringPropertyL
       
   277 // Converts a string property from a vCalendar to a PIM Event Item
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CPIMEventPropertyConverter::ConvertStringPropertyL(
       
   281     const CPIMParserProperty& aProperty, // property to convert
       
   282     CPIMEventItem& aItem) // item to insert the field to
       
   283 {
       
   284     JELOG2(EPim);
       
   285     TPIMField field = aProperty.MatchEventField();
       
   286     // Do not convert unrecognized fields
       
   287     if (field == -1)
       
   288     {
       
   289         return;
       
   290     }
       
   291 
       
   292     CParserPropertyValueHBufC* propertyValue =
       
   293         static_cast<CParserPropertyValueHBufC*>(aProperty.Value());
       
   294     HBufC* value = propertyValue->TakeValueOwnership();
       
   295     CleanupStack::PushL(value);
       
   296     aItem.AddStringL(field, KPIMAttrNone, value);
       
   297     CleanupStack::Pop(value); // owned by aItem
       
   298 }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CPIMEventPropertyConverter::ConvertRepeatRulePropertyL
       
   302 // Inserts RRULE proprety from a vEvent to a PIM Event Item as a repeat rule
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 void CPIMEventPropertyConverter::ConvertRepeatRulePropertyL(
       
   306     const CPIMParserProperty& aProperty, // property to convert
       
   307     CPIMEventItem& aItem) // item to insert the field to
       
   308 {
       
   309     JELOG2(EPim);
       
   310     if (aProperty.Name().CompareF(KVersitTokenRRULE) != 0)
       
   311     {
       
   312         // Some unsupported recurrence data (i.e. EXRULE)
       
   313         return;
       
   314     }
       
   315     MPIMRepeatRuleData* repeatRule = aItem.GetRepeat();
       
   316 
       
   317     CParserPropertyValueRecurrence* propertyValue =
       
   318         static_cast<CParserPropertyValueRecurrence*>(aProperty.Value());
       
   319     CVersitRecurrence* value = propertyValue->Value();
       
   320     switch (value->iRepeatType)
       
   321     {
       
   322     case CVersitRecurrence::EDaily:
       
   323     {
       
   324         repeatRule->SetIntL(EPIMRepeatRuleFrequency, EPIMRepeatRuleDaily);
       
   325         break;
       
   326     }
       
   327     case CVersitRecurrence::EWeekly:
       
   328     {
       
   329         repeatRule->SetIntL(EPIMRepeatRuleFrequency, EPIMRepeatRuleWeekly);
       
   330         repeatRule->SetIntL(EPIMRepeatRuleInterval, value->iInterval);
       
   331         break;
       
   332     }
       
   333     case CVersitRecurrence::EMonthlyByPos:
       
   334     case CVersitRecurrence::EMonthlyByDay:
       
   335     {
       
   336         repeatRule->SetIntL(EPIMRepeatRuleFrequency, EPIMRepeatRuleMonthly);
       
   337         break;
       
   338     }
       
   339     case CVersitRecurrence::EYearlyByMonth:
       
   340     case CVersitRecurrence::EYearlyByDay:
       
   341     {
       
   342         repeatRule->SetIntL(EPIMRepeatRuleFrequency, EPIMRepeatRuleYearly);
       
   343         break;
       
   344     }
       
   345     default:
       
   346     {
       
   347         // unknown frequency
       
   348         return;
       
   349     }
       
   350     }
       
   351 
       
   352     TVersitDateTime* versitEndDate = value->iEndDate;
       
   353     if (versitEndDate)
       
   354     {
       
   355         TPIMDate endDate(versitEndDate->iDateTime);
       
   356         repeatRule->SetDateL(EPIMRepeatRuleEnd, endDate);
       
   357     }
       
   358 
       
   359     aItem.SetRepeating(ETrue);
       
   360 }
       
   361 // -----------------------------------------------------------------------------
       
   362 // CPIMEventPropertyConverter::ConvertExDatePropertyL
       
   363 // Inserts EXDATE proprety from a vEvent to a PIM Event Item as a repeat rule
       
   364 // field
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 void CPIMEventPropertyConverter::ConvertExDatePropertyL(
       
   368     const CPIMParserProperty& aProperty, // property to convert
       
   369     CPIMEventItem& aItem) // item to insert the field to
       
   370 {
       
   371     JELOG2(EPim);
       
   372     if (aProperty.Name().CompareF(KVersitTokenEXDATE) != 0)
       
   373     {
       
   374         // some unsupported multidate
       
   375         return;
       
   376     }
       
   377     MPIMRepeatRuleData* repeatRule = aItem.GetRepeat();
       
   378 
       
   379     CParserPropertyValueMultiDateTime* propertyValue =
       
   380         static_cast<CParserPropertyValueMultiDateTime*>(aProperty.Value());
       
   381     CArrayPtr<TVersitDateTime>* value = propertyValue->Value();
       
   382     TInt valueCount = value->Count();
       
   383     for (TInt i = 0; i < valueCount; i++)
       
   384     {
       
   385         TPIMDate date(value->At(i)->iDateTime);
       
   386         repeatRule->AddExceptDateL(date);
       
   387     }
       
   388 }
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // CPIMEventPropertyConverter::ConvertClassPropertyL
       
   392 // Converts CLASS property to a PIM Event item.
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 void CPIMEventPropertyConverter::ConvertClassPropertyL(
       
   396     const CPIMParserProperty& aProperty, CPIMEventItem& aItem)
       
   397 {
       
   398     JELOG2(EPim);
       
   399     CParserPropertyValueHBufC* propertyValue =
       
   400         static_cast<CParserPropertyValueHBufC*>(aProperty.Value());
       
   401 
       
   402     const TPtrC classStringPtr = propertyValue->Value();
       
   403     TInt classInt = KErrCorrupt;
       
   404 
       
   405     if (classStringPtr.CompareF(KPIMClassStringPublic) == 0)
       
   406     {
       
   407         classInt = EPIMEventClassPublic;
       
   408     }
       
   409     else if (classStringPtr.CompareF(KPIMClassStringPrivate) == 0)
       
   410     {
       
   411         classInt = EPIMEventClassPrivate;
       
   412     }
       
   413     else if (classStringPtr.CompareF(KPIMClassStringConfidential) == 0)
       
   414     {
       
   415         classInt = EPIMEventClassConfidential;
       
   416     }
       
   417     // else the class value in the originating vCalendar is flawed - ignore
       
   418 
       
   419     if (classInt != KErrCorrupt)
       
   420     {
       
   421         aItem.addInt(EPIMEventClass, KPIMAttrNone, classInt);
       
   422     }
       
   423 }
       
   424 
       
   425 // -----------------------------------------------------------------------------
       
   426 // CPIMEventPropertyConverter::ConvertExceptionDatesL
       
   427 // Inserts exceptiondates to a parser.
       
   428 // -----------------------------------------------------------------------------
       
   429 //
       
   430 void CPIMEventPropertyConverter::ConvertExceptionDatesL(const CArrayFix<
       
   431         TPIMDate>& aDates, CParserVCalEntity& aParser)
       
   432 {
       
   433     JELOG2(EPim);
       
   434     TInt exDateCount = aDates.Count();
       
   435     if (exDateCount > 0)
       
   436     {
       
   437         CArrayPtrFlat<TVersitDateTime>* versitExDates =
       
   438             new(ELeave) CArrayPtrFlat<TVersitDateTime> (exDateCount);
       
   439         CleanupStack::PushL(versitExDates);
       
   440         CleanupResetAndDestroyPushL(*versitExDates);
       
   441         for (TInt i = 0; i < exDateCount; i++)
       
   442         {
       
   443             TVersitDateTime
       
   444             * versitDateTime =
       
   445                 new(ELeave) TVersitDateTime(aDates.At(i).DateTime(), TVersitDateTime::EIsUTC);
       
   446             CleanupDeletePushL(versitDateTime);
       
   447             versitExDates->AppendL(versitDateTime);
       
   448             CleanupStack::Pop(versitDateTime); // versitDateTime
       
   449         }
       
   450         CParserPropertyValue* propertyValue =
       
   451             new(ELeave) CParserPropertyValueMultiDateTime(versitExDates);
       
   452         CleanupStack::Pop(2); // versitExDates is now owned by propertyValue
       
   453         AddPropertyToParserL(propertyValue, KVersitTokenEXDATE(), aParser);
       
   454         // Needed cleanup stack items are popped out in the AddPropretyToParserL
       
   455     }
       
   456 }
       
   457 // -----------------------------------------------------------------------------
       
   458 // CPIMEventPropertyConverter::ConvertDateFieldL
       
   459 // Converts a date field from a PIM Event Item to a CParserVCard.
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 void CPIMEventPropertyConverter::ConvertDateFieldL(const CPIMItem& aItem, // item to convert from
       
   463         CParserVCalEntity& aParser, // parser to insert the property to.
       
   464         TPIMEventField aField, // field to convert
       
   465         TInt aIndex) // index to the field
       
   466 {
       
   467     JELOG2(EPim);
       
   468     const TPIMDate date = aItem.GetDateL(aField, aIndex);
       
   469     TDateTime dateTime = date.DateTime();
       
   470     TVersitDateTime* versitDateTime =
       
   471         new(ELeave) TVersitDateTime(dateTime, TVersitDateTime::EIsUTC);
       
   472     CleanupDeletePushL(versitDateTime);
       
   473 
       
   474     CParserPropertyValue* propertyValue =
       
   475         new(ELeave) CParserPropertyValueDateTime(versitDateTime);
       
   476     // versitDateTime is now owned by propertyValue
       
   477     CleanupStack::Pop(versitDateTime);
       
   478 
       
   479     switch (aField)
       
   480     {
       
   481     case EPIMEventStart:
       
   482     {
       
   483         AddPropertyToParserL(propertyValue, KVersitTokenDTSTART(), aParser);
       
   484         // Needed cleanup stack items are popped
       
   485         // out in the AddPropretyToParserL
       
   486         break;
       
   487     }
       
   488     case EPIMEventEnd:
       
   489     {
       
   490         AddPropertyToParserL(propertyValue, KVersitTokenDTEND(), aParser);
       
   491         // Needed cleanup stack items are popped
       
   492         // out in the AddPropretyToParserL
       
   493         break;
       
   494     }
       
   495     case EPIMEventRevision:
       
   496     {
       
   497         AddPropertyToParserL(propertyValue, KVersitTokenLASTMODIFIED(), aParser);
       
   498         // Needed cleanup stack items are popped
       
   499         // out in the AddPropretyToParserL
       
   500         break;
       
   501     }
       
   502     default:
       
   503     {
       
   504         __ASSERT_DEBUG(EFalse, User::Panic(KPIMPanicCategory,
       
   505                                            EPIMPanicUnsupportedDateField));
       
   506     }
       
   507     }
       
   508 }
       
   509 // -----------------------------------------------------------------------------
       
   510 // CPIMEventPropertyConverter::ConvertAlarmFieldL
       
   511 // Converts an alarm field from a PIM Event Item to a CParserVCard.
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 void CPIMEventPropertyConverter::ConvertAlarmFieldL(const CPIMItem& aItem, // item to convert from
       
   515         CParserVCalEntity& aParser, // parser to insert the property to.
       
   516         TPIMEventField aField, // field to convert
       
   517         TInt aIndex) // index to the field
       
   518 {
       
   519     JELOG2(EPim);
       
   520     const TInt KAlarmInterval = aItem.getInt(aField, aIndex);
       
   521     const TTimeIntervalSeconds KTimeInterval(KAlarmInterval);
       
   522 
       
   523     // Check that there exists start date. If item is not written to
       
   524     // database there might not be start date present
       
   525     if (aItem.CountValuesL(EPIMEventStart) == 0)
       
   526     {
       
   527         return;
       
   528     }
       
   529 
       
   530     // Start date present, so conversion can be made
       
   531     const TPIMDate KStartDate = aItem.GetDateL(EPIMEventStart, 0);
       
   532     TTime alarmTime(KStartDate);
       
   533     alarmTime -= KTimeInterval;
       
   534     TDateTime dateTime = alarmTime.DateTime();
       
   535     TVersitDateTime* versitDateTime =
       
   536         new(ELeave) TVersitDateTime(dateTime, TVersitDateTime::EIsUTC);
       
   537     CleanupDeletePushL(versitDateTime);
       
   538 
       
   539     CVersitAlarm* versitAlarm = CVersitAlarm::NewL(versitDateTime, NULL, 0,
       
   540                                 KNullDesC, KNullDesC);
       
   541     // versitDateTime is now owned by versitAlarm
       
   542     CleanupStack::Pop(versitDateTime);
       
   543     CleanupStack::PushL(versitAlarm);
       
   544     CParserPropertyValue* propertyValue =
       
   545         new(ELeave) CParserPropertyValueAlarm(versitAlarm);
       
   546     // versitAlarm is now owned by propertyValue
       
   547     CleanupStack::Pop(versitAlarm);
       
   548     AddPropertyToParserL(propertyValue, KVersitTokenDALARM(), aParser);
       
   549     // Needed cleanup stack items are popped out in the AddPropretyToParserL
       
   550 }
       
   551 // -----------------------------------------------------------------------------
       
   552 // CPIMEventPropertyConverter::ConvertStringFieldL
       
   553 // Converts a string field from a PIM Event Item to vCard
       
   554 // -----------------------------------------------------------------------------
       
   555 //
       
   556 void CPIMEventPropertyConverter::ConvertStringFieldL(const CPIMItem& aItem, // item to convert from
       
   557         CParserVCalEntity& aParser, // parser to write to
       
   558         TPIMEventField aField, // field to convert
       
   559         TInt aIndex) // index to the field
       
   560 {
       
   561     JELOG2(EPim);
       
   562     const TDesC& string = aItem.GetStringL(aField, aIndex);
       
   563     CParserPropertyValue* propertyValue = CParserPropertyValueHBufC::NewL(
       
   564                                               string);
       
   565 
       
   566     switch (aField)
       
   567     {
       
   568     case EPIMEventSummary:
       
   569     {
       
   570         AddPropertyToParserL(propertyValue, KVersitTokenSUMMARY(), aParser);
       
   571         // Needed cleanup stack items are popped
       
   572         // out in the AddPropretyToParserL
       
   573         break;
       
   574     }
       
   575     case EPIMEventLocation:
       
   576     {
       
   577         AddPropertyToParserL(propertyValue, KVersitTokenLOCATION(), aParser);
       
   578         // Needed cleanup stack items are popped
       
   579         // out in the AddPropretyToParserL
       
   580         break;
       
   581     }
       
   582     case EPIMEventNote:
       
   583     {
       
   584         AddPropertyToParserL(propertyValue, KVersitTokenDESCRIPTION(), aParser);
       
   585         // Needed cleanup stack items are popped
       
   586         // out in the AddPropretyToParserL
       
   587         break;
       
   588     }
       
   589     case EPIMEventUid:
       
   590     {
       
   591         AddPropertyToParserL(propertyValue, KVersitTokenUID(), aParser);
       
   592         // Needed cleanup stack items are popped
       
   593         // out in the AddPropretyToParserL
       
   594         break;
       
   595     }
       
   596     default:
       
   597     {
       
   598         __ASSERT_DEBUG(EFalse, User::Panic(KPIMPanicCategory,
       
   599                                            EPIMPanicUnsupportedStringField));
       
   600     }
       
   601     }
       
   602 }
       
   603 
       
   604 // -----------------------------------------------------------------------------
       
   605 // CPIMEventPropertyConverter::ConvertClassFieldL
       
   606 // Converts Event.CLASS field to a vCalendar.
       
   607 // -----------------------------------------------------------------------------
       
   608 //
       
   609 void CPIMEventPropertyConverter::ConvertClassFieldL(const CPIMItem& aItem,
       
   610         CParserVCalEntity& aParser, TPIMEventField aField, TInt aIndex)
       
   611 {
       
   612     JELOG2(EPim);
       
   613     const TInt classVal = aItem.getInt(aField, aIndex);
       
   614     TPtrC classString(KPIMClassStringConfidential);
       
   615 
       
   616     switch (classVal)
       
   617     {
       
   618     case EPIMEventClassConfidential:
       
   619     {
       
   620         classString.Set(KPIMClassStringConfidential);
       
   621         break;
       
   622     }
       
   623     case EPIMEventClassPrivate:
       
   624     {
       
   625         classString.Set(KPIMClassStringPrivate);
       
   626         break;
       
   627     }
       
   628     case EPIMEventClassPublic:
       
   629     {
       
   630         classString.Set(KPIMClassStringPublic);
       
   631         break;
       
   632     }
       
   633     default:
       
   634     {
       
   635         __ASSERT_DEBUG(EFalse, User::Invariant());
       
   636         break;
       
   637     }
       
   638     }
       
   639 
       
   640     CParserPropertyValue* propertyValue = CParserPropertyValueHBufC::NewL(
       
   641                                               classString);
       
   642     AddPropertyToParserL(propertyValue, KVersitTokenCLASS(), aParser);
       
   643     // Needed cleanup stack items are popped out in the AddPropretyToParserL
       
   644 }
       
   645 
       
   646 // -----------------------------------------------------------------------------
       
   647 // CPIMEventPropertyConverter::GetRepeatRuleFieldsL
       
   648 // Gets the fields from a repeat rule
       
   649 // -----------------------------------------------------------------------------
       
   650 //
       
   651 void CPIMEventPropertyConverter::GetRepeatRuleFieldsL(
       
   652     const MPIMRepeatRuleData* aRepeat, // Fields are read from this
       
   653     TInt* aInterval, // interval is stored here
       
   654     TInt* aFrequency, // frequency is stored here
       
   655     TVersitDateTime** aVersitEndDate) // end date is stored here
       
   656 {
       
   657     JELOG2(EPim);
       
   658     TBool endExists = EFalse;
       
   659     CArrayFix<TPIMField>* repeatFields = aRepeat->GetFieldsL();
       
   660     CleanupStack::PushL(repeatFields);
       
   661     TInt fieldCount = repeatFields->Count();
       
   662     for (TInt i = 0; i < fieldCount; i++)
       
   663     {
       
   664         switch (repeatFields->At(i))
       
   665         {
       
   666         case EPIMRepeatRuleFrequency:
       
   667         {
       
   668             *aFrequency = aRepeat->GetIntL(EPIMRepeatRuleFrequency);
       
   669             break;
       
   670         }
       
   671         case EPIMRepeatRuleInterval:
       
   672         {
       
   673             *aInterval = aRepeat->GetIntL(EPIMRepeatRuleInterval);
       
   674             break;
       
   675         }
       
   676         case EPIMRepeatRuleEnd:
       
   677         {
       
   678             endExists = ETrue;
       
   679             break;
       
   680         }
       
   681         default:
       
   682         {
       
   683             // We ignore other fields
       
   684         }
       
   685         }
       
   686     }
       
   687     CleanupStack::PopAndDestroy(repeatFields);
       
   688     if (endExists)
       
   689     {
       
   690         TPIMDate endDate = aRepeat->GetDateL(EPIMRepeatRuleEnd);
       
   691         *aVersitEndDate
       
   692         = new(ELeave) TVersitDateTime(endDate.DateTime(), TVersitDateTime::EIsUTC);
       
   693     }
       
   694 }
       
   695 // -----------------------------------------------------------------------------
       
   696 // CPIMEventPropertyConverter::CreateRecurrenceL
       
   697 // Makes a CVersitRecurrence according to parameters
       
   698 // -----------------------------------------------------------------------------
       
   699 //
       
   700 CVersitRecurrence* CPIMEventPropertyConverter::CreateRecurrenceL(
       
   701     TInt aFrequency, TInt aInterval, TVersitDateTime* aVersitEndDate)
       
   702 {
       
   703     JELOG2(EPim);
       
   704     CVersitRecurrence* recurrence = NULL;
       
   705     switch (aFrequency)
       
   706     {
       
   707     case EPIMRepeatRuleDaily:
       
   708     {
       
   709         recurrence
       
   710         = new(ELeave) CVersitRecurrenceDaily(aInterval, 0, aVersitEndDate);
       
   711         break;
       
   712     }
       
   713     case EPIMRepeatRuleWeekly:
       
   714     {
       
   715         recurrence
       
   716         = new(ELeave) CVersitRecurrenceWeekly(aInterval, 0, aVersitEndDate, NULL);
       
   717         break;
       
   718     }
       
   719     case EPIMRepeatRuleMonthly:
       
   720     {
       
   721         recurrence
       
   722         = new(ELeave) CVersitRecurrenceMonthlyByDay(
       
   723             aInterval, 0, aVersitEndDate, NULL, NULL, NULL);
       
   724         break;
       
   725     }
       
   726     case EPIMRepeatRuleYearly:
       
   727     {
       
   728         recurrence
       
   729         = new(ELeave) CVersitRecurrenceYearlyByDay(aInterval, 0, aVersitEndDate, NULL);
       
   730         break;
       
   731     }
       
   732     default:
       
   733     {
       
   734         User::Leave(KErrNotSupported);
       
   735     }
       
   736     }
       
   737     return recurrence;
       
   738 }
       
   739 
       
   740 // -----------------------------------------------------------------------------
       
   741 // CPIMEventPropertyConverter::AddPropertyToParserL
       
   742 // adds a new property value to the parser. NOTE that the property value can be
       
   743 // of any type and it is taken to ownership within this function.
       
   744 // -----------------------------------------------------------------------------
       
   745 //
       
   746 void CPIMEventPropertyConverter::AddPropertyToParserL(
       
   747     CParserPropertyValue* aPropertyValue, const TDesC8& aPropertyName,
       
   748     CParserVCalEntity& aParser)
       
   749 {
       
   750     JELOG2(EPim);
       
   751     // Add property value to the cleanup stack. It should not be added
       
   752     // before this call. This function is an exception and reduces much code
       
   753     CleanupStack::PushL(aPropertyValue);
       
   754     // Create a new parser property from the property value, its name and
       
   755     // array of parameters. If there are no parameters, the aArrayOfParams
       
   756     // should be NULL and the parser property will be generated without params
       
   757     CParserProperty* property = CParserProperty::NewL(*aPropertyValue,
       
   758                                 aPropertyName, NULL);
       
   759     // property takes ownership of the property value
       
   760     CleanupStack::Pop(aPropertyValue);
       
   761     // NOTE: property MUST not be pushed to the cleanup stack since the
       
   762     // AddPropertyL pushes it right away to the cleanup stack. So, we must not
       
   763     // push it here to avoid duplicate stack pointers
       
   764     aParser.AddPropertyL(property);
       
   765     // Property is now owned by the parser but we do not have to pop it
       
   766 }
       
   767 
       
   768 // End of file