javaextensions/pim/agnadapter/src.s60/cpimagnmemoadapter.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14: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 PIM Event items and native calendar day notes
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // CLASS HEADER
       
    20 #include "cpimagnmemoadapter.h"
       
    21 
       
    22 // INTERNAL INCLUDES
       
    23 #include "pimpanics.h"
       
    24 #include "agneventsupport.h"
       
    25 #include "mpimeventitem.h"
       
    26 #include "mpimitemdata.h"
       
    27 #include "logger.h"
       
    28 
       
    29 // EXTERNAL INCLUDES
       
    30 #include <calentry.h>
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CPIMAgnMemoAdapter::NewL
       
    36 // Two-phased constructor.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CPIMAgnMemoAdapter* CPIMAgnMemoAdapter::NewL(
       
    40     java::util::FunctionServer* aFuncServer)
       
    41 {
       
    42     JELOG2(EPim);
       
    43     CPIMAgnMemoAdapter* self = new(ELeave) CPIMAgnMemoAdapter(aFuncServer);
       
    44     CleanupStack::PushL(self);
       
    45     CallMethodL(self, &CPIMAgnMemoAdapter::ConstructL, self->iFuncServer);
       
    46     CleanupStack::Pop(self);
       
    47     return self;
       
    48 }
       
    49 
       
    50 // destructor
       
    51 CPIMAgnMemoAdapter::~CPIMAgnMemoAdapter()
       
    52 {
       
    53 }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CPIMAgnMemoAdapter::CreateItemToAgnL
       
    57 // Creates a new Agenda Model Event item from a PIM item data.
       
    58 // Returns: A Event item based on PIM item data.
       
    59 //          The ownership of the Event item is transferred to the caller.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CCalEntry* CPIMAgnMemoAdapter::CreateItemToAgnL(const MPIMEventItem& aItem)
       
    63 {
       
    64     JELOG2(EPim);
       
    65     // Create new calendar entry
       
    66     CCalEntry* entry = CreateCalendarEntryLC(CCalEntry::EEvent);
       
    67     // Add default values to the item. The default values are used
       
    68     // by the native calendar application and therefore needed to be added
       
    69     AddDefaultValuesToEntryL(aItem, *entry);
       
    70     // Convert fields from Java side to the native side
       
    71     ConvertFieldsToAgnL(aItem, *entry);
       
    72     CleanupStack::Pop(entry);
       
    73     return entry;
       
    74 }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CPIMAgnMemoAdapter::ReadAgnToItemL
       
    78 // Reads an Agenda Model Event item and converts it to a framework PIM item.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CPIMAgnMemoAdapter::ReadAgnToItemL(MPIMEventItem& aItem, CCalEntry& aEntry)
       
    82 {
       
    83     JELOG2(EPim);
       
    84     ReadFieldsFromAgnL(aItem, aEntry, KPIMSupportedMemoFields,
       
    85                        KPIMSupportedMemoFieldsCount);
       
    86 }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CPIMAgnMemoAdapter::UpdateItemToAgnL
       
    90 // Reads an Agenda Model Event item and updates it based on the PIM item data.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CPIMAgnMemoAdapter::UpdateItemToAgnL(const MPIMEventItem& aItem,
       
    94         CCalEntry& aEntry)
       
    95 {
       
    96     JELOG2(EPim);
       
    97     // Before updating values, empty the fields or set default values for the
       
    98     // fields that PIM api supports
       
    99     ClearPIMFieldsL(aEntry, KPIMSupportedMemoFields,
       
   100                     KPIMSupportedMemoFieldsCount);
       
   101 
       
   102     // Convert fields from Java side to the native side
       
   103     ConvertFieldsToAgnL(aItem, aEntry);
       
   104 }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CPIMAgnMemoAdapter::CPIMAgnMemoAdapter
       
   108 // C++ constructor can NOT contain any code, that
       
   109 // might leave.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 CPIMAgnMemoAdapter::CPIMAgnMemoAdapter(java::util::FunctionServer* aFuncServer) :
       
   113         CPIMAgnEventAdapter(aFuncServer)
       
   114 {
       
   115     JELOG2(EPim);
       
   116 }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CPIMAgnMemoAdapter::ReadStartFromAgnL
       
   120 // Reads Agenda entry's start field and converts it into PIM Item field.
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CPIMAgnMemoAdapter::ReadStartFromAgnL(MPIMEventItem& aItem,
       
   124         CCalEntry& aEntry)
       
   125 {
       
   126     JELOG2(EPim);
       
   127     TTime agnStartTime(aEntry.StartTimeL().TimeUtcL());
       
   128 
       
   129     if (agnStartTime != Time::NullTTime())
       
   130     {
       
   131         // TTime start date, as a TTime but without a time component.
       
   132         TPIMFieldData fieldData(EPIMEventStart, KPIMAttrNone, agnStartTime);
       
   133         aItem.ItemData().AddValueL(fieldData);
       
   134     }
       
   135 }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CPIMAgnMemoAdapter::ReadEndFromAgnL
       
   139 // Reads Agenda entry's end field and converts it into PIM Item field.
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 void CPIMAgnMemoAdapter::ReadEndFromAgnL(MPIMEventItem& aItem,
       
   143         CCalEntry& aEntry)
       
   144 {
       
   145     JELOG2(EPim);
       
   146     TTime agnEndDate(aEntry.EndTimeL().TimeUtcL());
       
   147 
       
   148     if (agnEndDate != Time::NullTTime())
       
   149     {
       
   150         // TTime end date, as a TTime but without a time component.
       
   151         TPIMFieldData fieldData(EPIMEventEnd, KPIMAttrNone, agnEndDate);
       
   152         aItem.ItemData().AddValueL(fieldData);
       
   153     }
       
   154 }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CPIMAgnMemoAdapter::AddDefaultValuesToEntryL
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CPIMAgnMemoAdapter::AddDefaultValuesToEntryL(const MPIMEventItem& aItem,
       
   161         CCalEntry& aEntry) const
       
   162 {
       
   163     JELOG2(EPim);
       
   164     // Add common event default values to the native entry
       
   165     CPIMAgnEventAdapter::AddDefaultValuesToEntryL(aItem, aEntry);
       
   166     const MPIMItemData& data = aItem.ItemData();
       
   167 
       
   168     // Set default start and end time if these are not present in the Java item
       
   169     if (data.CountValues(EPIMEventStart) == 0 && data.CountValues(EPIMEventEnd)
       
   170             == 0)
       
   171     {
       
   172         TCalTime defaultTime;
       
   173         TTime currentTime;
       
   174         // Get current time in universal time
       
   175         currentTime.UniversalTime();
       
   176         defaultTime.SetTimeUtcL(currentTime);
       
   177         aEntry.SetStartAndEndTimeL(defaultTime, defaultTime);
       
   178     }
       
   179 }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CPIMAgnApptAdapter::ConstructL
       
   183 // Symbian 2nd phase constructor can leave.
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 void CPIMAgnMemoAdapter::ConstructL()
       
   187 {
       
   188     JELOG2(EPim);
       
   189     CPIMAgnEventAdapter::ConstructL();
       
   190 }
       
   191 
       
   192 // End of file