javaextensions/pim/versit/src.s60/cpimtodopropertyconverter.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     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 properties vTodo <-> PIM API*
       
    15 */
       
    16 
       
    17 
       
    18 // CLASS HEADER
       
    19 #include "cpimtodopropertyconverter.h"
       
    20 
       
    21 // INTERNAL INCLUDES
       
    22 #include "pimcommon.h" // tpimfield
       
    23 #include "pimpanics.h"
       
    24 #include "pimversit.h"
       
    25 #include "cpimitem.h"
       
    26 #include "cpimtodoitem.h"
       
    27 #include "cpimparserproperty.h"
       
    28 #include "logger.h"
       
    29 
       
    30 // EXTERNAL INCLUDES
       
    31 #include <vcal.h>
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CPIMToDoPropertyConverter::NewL
       
    37 // Two-phased constructor.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CPIMToDoPropertyConverter* CPIMToDoPropertyConverter::NewL()
       
    41 {
       
    42     JELOG2(EPim);
       
    43     CPIMToDoPropertyConverter* self = new(ELeave) CPIMToDoPropertyConverter();
       
    44     return self;
       
    45 }
       
    46 
       
    47 // Destructor
       
    48 CPIMToDoPropertyConverter::~CPIMToDoPropertyConverter()
       
    49 {
       
    50     JELOG2(EPim);
       
    51 }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CPIMToDoPropertyConverter::ConvertPropertyL
       
    55 // Inserts a proprety from a vTodo to a PIM ToDo Item as a field
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void CPIMToDoPropertyConverter::ConvertPropertyL(
       
    59     const CParserProperty& aProperty, // property to convert
       
    60     CPIMToDoItem& aItem, // item to insert the field to
       
    61     TPIMDate& aAlarm)
       
    62 {
       
    63     JELOG2(EPim);
       
    64     TUid valueTypeUid = aProperty.Uid();
       
    65     TInt valueType = valueTypeUid.iUid;
       
    66 
       
    67     // The following, rather ugly, cast makes it possible for us to access
       
    68     // the protected iArrayOfParams field.
       
    69     const CPIMParserProperty& property =
       
    70         static_cast<const CPIMParserProperty&>(aProperty);
       
    71 
       
    72     if (aProperty.Name().CompareF(KVersitTokenCLASS) == 0)
       
    73     {
       
    74         ConvertClassPropertyL(property, aItem);
       
    75     }
       
    76     else
       
    77     {
       
    78         switch (valueType)
       
    79         {
       
    80         case KVersitPropertyDateTimeUid:
       
    81         {
       
    82             // due, completed
       
    83             ConvertDatePropertyL(property, aItem);
       
    84             break;
       
    85         }
       
    86         case KVersitPropertyHBufCUid:
       
    87         {
       
    88             // summary
       
    89             ConvertStringPropertyL(property, aItem);
       
    90             break;
       
    91         }
       
    92         case KVersitPropertyIntUid:
       
    93         {
       
    94             // priority
       
    95             ConvertPriorityPropertyL(property, aItem);
       
    96             break;
       
    97         }
       
    98         case KVCalPropertyAlarmUid:
       
    99         {
       
   100             ConvertAlarmPropertyL(property, aAlarm);
       
   101             break;
       
   102         }
       
   103         default:
       
   104         {
       
   105             // don't support, don't care
       
   106         }
       
   107         }
       
   108     }
       
   109 }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CPIMToDoPropertyConverter::ConvertToDoFieldL
       
   113 // Inserts a Field from a PIM ToDo Item to CParserVCard as a property.
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CPIMToDoPropertyConverter::ConvertToDoFieldL(const CPIMItem& aItem, // item to read the field from
       
   117         CParserVCalEntity& aParser, // parser to insert the property to.
       
   118         TPIMToDoField aField) // field to convert
       
   119 {
       
   120     JELOG2(EPim);
       
   121     TInt valueCount = aItem.CountValuesL(aField);
       
   122     for (TInt i = 0; i < valueCount; i++)
       
   123     {
       
   124         switch (aField)
       
   125         {
       
   126         case EPIMToDoDue:
       
   127         case EPIMToDoCompletionDate:
       
   128         case EPIMToDoRevision:
       
   129         {
       
   130             ConvertDateFieldL(aItem, aParser, aField, i);
       
   131             break;
       
   132         }
       
   133         case EPIMToDoSummary:
       
   134         case EPIMToDoNote:
       
   135             // UID is required by VFX. Do not fix even though this is wrong
       
   136         case EPIMToDoUid:
       
   137         {
       
   138             ConvertStringFieldL(aItem, aParser, aField, i);
       
   139             break;
       
   140         }
       
   141         case EPIMToDoPriority:
       
   142         {
       
   143             ConvertIntFieldL(aItem, aParser, aField, i);
       
   144             break;
       
   145         }
       
   146         case EPIMToDoCompleted:
       
   147         {
       
   148             ConvertCompletedFieldL(aItem, aParser, aField, i);
       
   149             break;
       
   150         }
       
   151         case EPIMToDoClass:
       
   152         {
       
   153             ConvertClassFieldL(aItem, aParser, aField, i);
       
   154             break;
       
   155         }
       
   156         case EPIMToDoExtAlarm:
       
   157         {
       
   158             ConvertAlarmFieldL(aItem, aParser, aField, i);
       
   159             break;
       
   160         }
       
   161         default:
       
   162         {
       
   163             __ASSERT_DEBUG(EFalse, User::Panic(KPIMPanicCategory,
       
   164                                                EPIMPanicUnsupportedField));
       
   165             return;
       
   166         }
       
   167         }
       
   168     }
       
   169 }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CPIMCalendarConverter::CPIMCalendarConverter
       
   173 // C++ default constructor can NOT contain any code, that
       
   174 // might leave.
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 CPIMToDoPropertyConverter::CPIMToDoPropertyConverter()
       
   178 {
       
   179     JELOG2(EPim);
       
   180 }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CPIMToDoPropertyConverter::ConvertDatePropertyL
       
   184 // Converts a date field from a vCard to a PIM ToDo Item
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CPIMToDoPropertyConverter::ConvertDatePropertyL(
       
   188     const CPIMParserProperty& aProperty, // property to convert
       
   189     CPIMToDoItem& aItem) // item to convert to
       
   190 {
       
   191     JELOG2(EPim);
       
   192     TPIMField field = aProperty.MatchToDoField();
       
   193     // Do not convert unrecognized fields
       
   194     if (field == -1)
       
   195     {
       
   196         return;
       
   197     }
       
   198 
       
   199     CParserPropertyValueDate* propertyValue =
       
   200         static_cast<CParserPropertyValueDate*>(aProperty.Value());
       
   201     const TVersitDateTime* value = propertyValue->Value();
       
   202 
       
   203     TPIMDate date(value->iDateTime);
       
   204     if (aItem.CountValuesL(field) > 0)
       
   205     {
       
   206         aItem.SetDateL(field, 0, KPIMAttrNone, date);
       
   207     }
       
   208     else
       
   209     {
       
   210         aItem.AddDateL(field, KPIMAttrNone, date);
       
   211     }
       
   212 }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CPIMToDoPropertyConverter::ConvertStringPropertyL
       
   216 // Converts a string property from a vTodo to a PIM ToDo Item
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 void CPIMToDoPropertyConverter::ConvertStringPropertyL(
       
   220     const CPIMParserProperty& aProperty, // property to convert
       
   221     CPIMToDoItem& aItem) // item to insert the field to
       
   222 {
       
   223     JELOG2(EPim);
       
   224     TPIMField field = aProperty.MatchToDoField();
       
   225     // Do not convert unrecognized fields
       
   226     if (field == -1)
       
   227     {
       
   228         return;
       
   229     }
       
   230 
       
   231     CParserPropertyValueHBufC* propertyValue =
       
   232         static_cast<CParserPropertyValueHBufC*>(aProperty.Value());
       
   233     // ToDo completed is a boolean field
       
   234     if (field == EPIMToDoCompleted)
       
   235     {
       
   236         TPtrC completed = propertyValue->Value();
       
   237         if (completed.CompareF(KPIMStatusCompleted) == 0)
       
   238         {
       
   239             aItem.AddBooleanL(EPIMToDoCompleted, KPIMAttrNone, ETrue);
       
   240         }
       
   241         else if (completed.CompareF(KPIMStatusUncompleted) == 0)
       
   242         {
       
   243             aItem.AddBooleanL(EPIMToDoCompleted, KPIMAttrNone, EFalse);
       
   244         }
       
   245         return;
       
   246     }
       
   247     HBufC* value = propertyValue->TakeValueOwnership();
       
   248     CleanupStack::PushL(value);
       
   249     aItem.AddStringL(field, KPIMAttrNone, value);
       
   250     CleanupStack::Pop(value); // owned by aItem
       
   251 }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CPIMToDoPropertyConverter::ConvertPriorityPropertyL
       
   255 // Converts a priority property from a vTodo to a PIM ToDo Item
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void CPIMToDoPropertyConverter::ConvertPriorityPropertyL(
       
   259     const CPIMParserProperty& aProperty, // property to convert
       
   260     CPIMToDoItem& aItem) // item to insert the field to
       
   261 {
       
   262     JELOG2(EPim);
       
   263     TPIMField field = aProperty.MatchToDoField();
       
   264     // Do not convert unrecognized fields
       
   265     if (field != EPIMToDoPriority)
       
   266     {
       
   267         return;
       
   268     }
       
   269 
       
   270     CParserPropertyValueInt* propertyValue =
       
   271         static_cast<CParserPropertyValueInt*>(aProperty.Value());
       
   272     TInt value = propertyValue->Value();
       
   273     TPIMAttribute attributes = KPIMAttrNone;
       
   274     if (aItem.CountValuesL(field) > 0)
       
   275     {
       
   276         aItem.SetIntL(field, 0, attributes, value);
       
   277     }
       
   278     else
       
   279     {
       
   280         aItem.addInt(field, attributes, value);
       
   281     }
       
   282 }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CPIMToDoPropertyConverter::ConvertDateFieldL
       
   286 // Converts a date field from a PIM ToDo Item to a CParserVCard.
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 void CPIMToDoPropertyConverter::ConvertDateFieldL(const CPIMItem& aItem, // item to convert from
       
   290         CParserVCalEntity& aParser, // parser to insert the property to.
       
   291         TPIMToDoField aField, // field to convert
       
   292         TInt aIndex) // index to the field
       
   293 {
       
   294     JELOG2(EPim);
       
   295     // Panic on debug builds if the field is incorrect
       
   296     __ASSERT_DEBUG(aField == EPIMToDoDue || aField == EPIMToDoCompletionDate
       
   297                    || aField == EPIMToDoRevision, User::Invariant());
       
   298 
       
   299     // Generate date
       
   300     const TPIMDate date = aItem.GetDateL(aField, aIndex);
       
   301     TDateTime dateTime = date.DateTime();
       
   302     TVersitDateTime* versitDateTime =
       
   303         new(ELeave) TVersitDateTime(dateTime, TVersitDateTime::EIsUTC);
       
   304     CleanupDeletePushL(versitDateTime);
       
   305 
       
   306     CParserPropertyValue* propertyValue =
       
   307         new(ELeave) CParserPropertyValueDateTime(versitDateTime);
       
   308     CleanupStack::Pop(versitDateTime); // versitDateTime is now owned by propertyValue
       
   309     TPtrC8 propertyName;
       
   310 
       
   311     if (aField == EPIMToDoDue)
       
   312     {
       
   313         propertyName.Set(KVersitTokenDUE);
       
   314     }
       
   315     else if (aField == EPIMToDoCompletionDate)
       
   316     {
       
   317         propertyName.Set(KVersitTokenCOMPLETED);
       
   318     }
       
   319     else if (aField == EPIMToDoRevision)
       
   320     {
       
   321         propertyName.Set(KVersitTokenLASTMODIFIED);
       
   322     }
       
   323     AddPropertyToParserL(propertyValue, propertyName, aParser);
       
   324     // Needed cleanup stack items are pushed and popped within the function
       
   325 }
       
   326 // -----------------------------------------------------------------------------
       
   327 // CPIMToDoPropertyConverter::ConvertStringFieldL
       
   328 // Converts a string field from a PIM ToDo Item to vCard
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 void CPIMToDoPropertyConverter::ConvertStringFieldL(const CPIMItem& aItem, // item to convert from
       
   332         CParserVCalEntity& aParser, // parser to write to
       
   333         TPIMToDoField aField, // field to convert
       
   334         TInt aIndex) // index to the field
       
   335 {
       
   336     JELOG2(EPim);
       
   337     // Panic on debug builds if the field is incorrect
       
   338     __ASSERT_DEBUG(aField == EPIMToDoSummary || aField == EPIMToDoNote
       
   339                    || aField == EPIMToDoUid, User::Invariant());
       
   340     const TDesC& string = aItem.GetStringL(aField, aIndex);
       
   341     CParserPropertyValue* propertyValue = CParserPropertyValueHBufC::NewL(
       
   342                                               string);
       
   343 
       
   344     TPtrC8 propertyName;
       
   345     if (aField == EPIMToDoSummary)
       
   346     {
       
   347         propertyName.Set(KVersitTokenSUMMARY);
       
   348     }
       
   349     else if (aField == EPIMToDoNote)
       
   350     {
       
   351         propertyName.Set(KVersitTokenDESCRIPTION);
       
   352     }
       
   353     else if (aField == EPIMToDoUid)
       
   354     {
       
   355         propertyName.Set(KVersitTokenUID);
       
   356     }
       
   357     AddPropertyToParserL(propertyValue, propertyName, aParser);
       
   358     // Needed cleanup stack items are pushed and popped within the function
       
   359 }
       
   360 // -----------------------------------------------------------------------------
       
   361 // CPIMToDoPropertyConverter::ConvertIntFieldL
       
   362 // Converts a string field from a PIM ToDo Item to vCard
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 void CPIMToDoPropertyConverter::ConvertIntFieldL(const CPIMItem& aItem, // item to convert from
       
   366         CParserVCalEntity& aParser, // parser to write to
       
   367         TPIMToDoField aField, // field to convert
       
   368         TInt aIndex) // index to the field
       
   369 {
       
   370     JELOG2(EPim);
       
   371     __ASSERT_DEBUG(EPIMToDoPriority == aField, User::Panic(KPIMPanicCategory,
       
   372                    EPIMPanicUnsupportedIntField));
       
   373     TInt priority = aItem.getInt(aField, aIndex);
       
   374     // Requirement specification 4.1.7, table 8 defines the following
       
   375     // mapping
       
   376     if (priority == EPIMToDoPriorityMinValue) // 0
       
   377     {
       
   378         return;
       
   379     }
       
   380     else if ((EPIMToDoPriorityHigh <= priority) && (priority
       
   381              < EPIMToDoPriorityMedium))
       
   382     {
       
   383         priority = EPIMToDoPriorityHigh;
       
   384     }
       
   385     else if ((EPIMToDoPriorityMedium <= priority) && (priority
       
   386              < EPIMToDoPriorityLow))
       
   387     {
       
   388         priority = EPIMToDoPriorityMedium;
       
   389     }
       
   390     else if ((EPIMToDoPriorityLow <= priority) && (priority
       
   391              <= EPIMToDoPriorityMaxValue))
       
   392     {
       
   393         priority = EPIMToDoPriorityLow;
       
   394     }
       
   395     else
       
   396     {
       
   397         User::Leave(KErrTooBig);
       
   398     }
       
   399 
       
   400     CParserPropertyValue* propertyValue =
       
   401         new(ELeave) CParserPropertyValueInt(priority);
       
   402     AddPropertyToParserL(propertyValue, KVersitTokenPRIORITY(), aParser);
       
   403     // Needed cleanup stack items are pushed and popped within the function
       
   404 }
       
   405 
       
   406 // -----------------------------------------------------------------------------
       
   407 // CPIMToDoPropertyConverter::ConvertCompletedFieldL
       
   408 // Converts a completed field from a PIM ToDo Item to a CParserVCard.
       
   409 // -----------------------------------------------------------------------------
       
   410 //
       
   411 void CPIMToDoPropertyConverter::ConvertCompletedFieldL(const CPIMItem& aItem, // item to convert from
       
   412         CParserVCalEntity& aParser, // parser to insert the property to.
       
   413         TPIMToDoField aField, // field to convert
       
   414         TInt aIndex) // index to the field
       
   415 {
       
   416     JELOG2(EPim);
       
   417     __ASSERT_DEBUG(aField == EPIMToDoCompleted, User::Panic(KPIMPanicCategory,
       
   418                    EPIMPanicUnsupportedField));
       
   419     TBool completed = aItem.GetBooleanL(aField, aIndex);
       
   420     TPtrC statusString(KPIMStatusUncompleted);
       
   421     // Completed should be converted as STATUS field in the vCalendar
       
   422     // false = STATUS:NEEDS ACTION, true = STATUS:COMPLETED. see vCalendar
       
   423     // standard specification
       
   424     if (completed)
       
   425     {
       
   426         statusString.Set(KPIMStatusCompleted);
       
   427     }
       
   428 
       
   429     CParserPropertyValue* propertyValue = CParserPropertyValueHBufC::NewL(
       
   430                                               statusString);
       
   431     AddPropertyToParserL(propertyValue, KVersitTokenSTATUS(), aParser);
       
   432     // Needed cleanup stack items are pushed and popped within the function
       
   433 }
       
   434 
       
   435 // -----------------------------------------------------------------------------
       
   436 // CPIMEventPropertyConverter::ConvertClassPropertyL
       
   437 // Converts CLASS property to a PIM ToDo item.
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 void CPIMToDoPropertyConverter::ConvertClassPropertyL(
       
   441     const CPIMParserProperty& aProperty, CPIMToDoItem& aItem)
       
   442 {
       
   443     JELOG2(EPim);
       
   444     CParserPropertyValueHBufC* propertyValue =
       
   445         static_cast<CParserPropertyValueHBufC*>(aProperty.Value());
       
   446 
       
   447     const TPtrC classStringPtr = propertyValue->Value();
       
   448     TInt classInt = KErrCorrupt;
       
   449 
       
   450     if (classStringPtr.CompareF(KPIMClassStringPublic) == 0)
       
   451     {
       
   452         classInt = EPIMToDoClassPublic;
       
   453     }
       
   454     else if (classStringPtr.CompareF(KPIMClassStringPrivate) == 0)
       
   455     {
       
   456         classInt = EPIMToDoClassPrivate;
       
   457     }
       
   458     else if (classStringPtr.CompareF(KPIMClassStringConfidential) == 0)
       
   459     {
       
   460         classInt = EPIMToDoClassConfidential;
       
   461     }
       
   462     // else the class value in the originating vCalendar is flawed - ignore
       
   463 
       
   464     if (classInt != KErrCorrupt)
       
   465     {
       
   466         aItem.AddIntL(EPIMToDoClass, KPIMAttrNone, classInt);
       
   467     }
       
   468 }
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // CPIMToDoPropertyConverter::ConvertClassFieldL
       
   472 // Converts ToDo.CLASS field to a vCalendar.
       
   473 // -----------------------------------------------------------------------------
       
   474 //
       
   475 void CPIMToDoPropertyConverter::ConvertClassFieldL(const CPIMItem& aItem,
       
   476         CParserVCalEntity& aParser, TPIMToDoField aField, TInt aIndex)
       
   477 {
       
   478     JELOG2(EPim);
       
   479     const TInt classVal = aItem.getInt(aField, aIndex);
       
   480     TPtrC classString(KPIMClassStringConfidential);
       
   481 
       
   482     switch (classVal)
       
   483     {
       
   484     case EPIMToDoClassConfidential:
       
   485     {
       
   486         classString.Set(KPIMClassStringConfidential);
       
   487         break;
       
   488     }
       
   489     case EPIMToDoClassPrivate:
       
   490     {
       
   491         classString.Set(KPIMClassStringPrivate);
       
   492         break;
       
   493     }
       
   494     case EPIMToDoClassPublic:
       
   495     {
       
   496         classString.Set(KPIMClassStringPublic);
       
   497         break;
       
   498     }
       
   499     default:
       
   500     {
       
   501         __ASSERT_DEBUG(EFalse, User::Invariant());
       
   502         break;
       
   503     }
       
   504     }
       
   505 
       
   506     CParserPropertyValue* propertyValue = CParserPropertyValueHBufC::NewL(
       
   507                                               classString);
       
   508     AddPropertyToParserL(propertyValue, KVersitTokenCLASS(), aParser);
       
   509     // Needed cleanup stack items are pushed and popped within the function
       
   510 }
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // CPIMToDoPropertyConverter::ConvertAlarmFieldL
       
   514 // Converts an alarm field from a PIM ToDo Item to a CParserVCard.
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 void CPIMToDoPropertyConverter::ConvertAlarmFieldL(const CPIMItem& aItem, // item to convert from
       
   518         CParserVCalEntity& aParser, // parser to insert the property to.
       
   519         TPIMToDoField aField, // field to convert
       
   520         TInt aIndex) // index to the field
       
   521 {
       
   522     JELOG2(EPim);
       
   523     // Calculate the alarm date and time
       
   524     const TInt alarmOffset = aItem.getInt(aField, aIndex);
       
   525 
       
   526     // If ToDo.DUE is not present there is no way to calculate alarm
       
   527     // so it has to be ignored
       
   528     if (aItem.CountValuesL(EPIMToDoDue) == 0)
       
   529     {
       
   530         return;
       
   531     }
       
   532     // There is ToDo.DUE present, so conversion can be made
       
   533     const TPIMDate dueDate = aItem.GetDateL(EPIMToDoDue, aIndex);
       
   534     TTime alarmTime(dueDate.Int64());
       
   535     // Count alarm time
       
   536     alarmTime -= TTimeIntervalSeconds(alarmOffset);
       
   537 
       
   538     TVersitDateTime
       
   539     * versitDateTime =
       
   540         new(ELeave) TVersitDateTime(alarmTime.DateTime(), TVersitDateTime::EIsUTC);
       
   541     CleanupDeletePushL(versitDateTime);
       
   542 
       
   543     CVersitAlarm* versitAlarm = CVersitAlarm::NewL(versitDateTime, NULL, 0,
       
   544                                 KNullDesC, KNullDesC);
       
   545     // versitDateTime is now owned by versitAlarm
       
   546     CleanupStack::Pop(versitDateTime);
       
   547     CleanupStack::PushL(versitAlarm);
       
   548     CParserPropertyValue* propertyValue =
       
   549         new(ELeave) CParserPropertyValueAlarm(versitAlarm);
       
   550     // versitAlarm is now owned by propertyValue
       
   551     CleanupStack::Pop(versitAlarm);
       
   552     AddPropertyToParserL(propertyValue, KVersitTokenDALARM(), aParser);
       
   553     // Needed cleanup stack items are pushed and popped within the function
       
   554 }
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // CPIMEventPropertyConverter::ConvertAlarmPropertyL
       
   558 // Converts an alarm property to a PIM ToDo item.
       
   559 // -----------------------------------------------------------------------------
       
   560 //
       
   561 void CPIMToDoPropertyConverter::ConvertAlarmPropertyL(
       
   562     const CPIMParserProperty& aProperty, TPIMDate& aAlarm)
       
   563 {
       
   564     JELOG2(EPim);
       
   565     // Do not convert unrecognized fields
       
   566     if (aProperty.MatchToDoField() != EPIMToDoExtAlarm)
       
   567     {
       
   568         return;
       
   569     }
       
   570 
       
   571     CParserPropertyValueAlarm* propertyValue =
       
   572         static_cast<CParserPropertyValueAlarm*>(aProperty.Value());
       
   573     const CVersitAlarm* value = propertyValue->Value();
       
   574     const TVersitDateTime* versitDT = value->iRunTime;
       
   575 
       
   576     TPIMDate date(versitDT->iDateTime);
       
   577     aAlarm = date;
       
   578 }
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 // CPIMToDoPropertyConverter::AddPropertyToParserL
       
   582 // adds a new property value to the parser. NOTE that the property value can be
       
   583 // of any type and it is taken to ownership within this function.
       
   584 // -----------------------------------------------------------------------------
       
   585 //
       
   586 void CPIMToDoPropertyConverter::AddPropertyToParserL(
       
   587     CParserPropertyValue* aPropertyValue, const TDesC8& aPropertyName,
       
   588     CParserVCalEntity& aParser)
       
   589 {
       
   590     JELOG2(EPim);
       
   591     // Add property value to the cleanup stack. It should not be added
       
   592     // before this call. This function is an exception and reduces much code
       
   593     CleanupStack::PushL(aPropertyValue);
       
   594     // Create a new parser property from the property value, its name and
       
   595     // array of parameters. If there are no parameters, the aArrayOfParams
       
   596     // should be NULL and the parser property will be generated without params
       
   597     CParserProperty* property = CParserProperty::NewL(*aPropertyValue,
       
   598                                 aPropertyName, NULL);
       
   599     // property takes ownership of the property value
       
   600     CleanupStack::Pop(aPropertyValue);
       
   601     // NOTE: property MUST not be pushed to the cleanup stack since the
       
   602     // AddPropertyL pushes it right away to the cleanup stack. So, we must not
       
   603     // push it here to avoid duplicate stack pointers
       
   604     aParser.AddPropertyL(property);
       
   605     // Property is now owned by the parser but we do not have to pop it
       
   606 }
       
   607 
       
   608 // End of File