javaextensions/pim/agnadapter/src.s60/cpimagnitemadapter.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:  Base class for the Agenda Model event and todo item adapters
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // CLASS HEADER
       
    20 #include "cpimagnitemadapter.h"
       
    21 #include "logger.h"
       
    22 
       
    23 // EXTERNAL INCLUDES
       
    24 #include <caltime.h>
       
    25 #include <CalenInterimUtils2.h>
       
    26 #include <tzconverter.h>
       
    27 #include <calentry.h>
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // destructor
       
    32 CPIMAgnItemAdapter::~CPIMAgnItemAdapter()
       
    33 {
       
    34     JELOG2(EPim);
       
    35     CallMethod(this, &CPIMAgnItemAdapter::DoClose, iFuncServer);
       
    36 }
       
    37 
       
    38 void CPIMAgnItemAdapter::DoClose()
       
    39 {
       
    40     JELOG2(EPim);
       
    41     delete iCalenInterimUtils;
       
    42     iCalenInterimUtils = NULL;
       
    43     iTzServer.Close();
       
    44 }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CPIMAgnItemAdapter::ConstructL
       
    48 // Symbian 2nd phase constructor can leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 void CPIMAgnItemAdapter::ConstructL()
       
    52 {
       
    53     JELOG2(EPim);
       
    54     User::LeaveIfError(iTzServer.Connect());
       
    55     iCalenInterimUtils = CCalenInterimUtils2::NewL();
       
    56 }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CPIMAgnItemAdapter::IsDateInValidAgendaRange
       
    60 // Checks the date is acceptable within the agenda model's valid date range
       
    61 // (from 1st January 1980 to 31st December 2100).
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 TBool CPIMAgnItemAdapter::IsDateInValidAgendaRange(TPIMDate aDate) const
       
    65 {
       
    66     JELOG2(EPim);
       
    67     if (aDate < TCalTime::MinTime() || aDate > TCalTime::MaxTime())
       
    68     {
       
    69         return EFalse;
       
    70     }
       
    71     return ETrue;
       
    72 }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CPIMAgnItemAdapter::StartOfDay
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 TPIMDate CPIMAgnItemAdapter::StartOfDay(const TPIMDate& aTime) const
       
    79 {
       
    80     JELOG2(EPim);
       
    81     TTime zero(0);
       
    82     return (zero + aTime.DaysFrom(zero));
       
    83 }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CPIMAgnItemAdapter::ConvertTimeL
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CPIMAgnItemAdapter::ConvertTimeL(TPIMDate& aTime,
       
    90                                       const TPIMDateFormat aRequestedFormat)
       
    91 {
       
    92     JELOG2(EPim);
       
    93     TTime temp(aTime);
       
    94     // Create converter here because some other client  might have changed the
       
    95     // time zone during the run time of PIM API. We do not listen time changes
       
    96     CTzConverter* converter = CTzConverter::NewL(iTzServer);
       
    97     CleanupStack::PushL(converter);
       
    98 
       
    99     // Convert time to requested format
       
   100     if (aRequestedFormat == EPIMDateUTC)
       
   101     {
       
   102         User::LeaveIfError(converter->ConvertToUniversalTime(temp));
       
   103     }
       
   104     else if (aRequestedFormat == EPIMDateLocal)
       
   105     {
       
   106         User::LeaveIfError(converter->ConvertToLocalTime(temp));
       
   107     }
       
   108     // Do not modify if some other time format was requested...
       
   109     CleanupStack::PopAndDestroy(converter);
       
   110     aTime = temp;
       
   111 }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CPIMAgnItemAdapter::CreateCalendarEntryLC
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 CCalEntry* CPIMAgnItemAdapter::CreateCalendarEntryLC(const TInt aType)
       
   118 {
       
   119     JELOG2(EPim);
       
   120     // Create global unique identifier
       
   121     HBufC8* guid = iCalenInterimUtils->GlobalUidL();
       
   122     CleanupStack::PushL(guid);
       
   123 
       
   124     // Create a native calendar entry. aType specifies the type
       
   125     // of the entry (meeting, memo, anniversary or todo)
       
   126     CCalEntry* entry = CCalEntry::NewL(static_cast<CCalEntry::TType>(aType),
       
   127                                        guid, CCalEntry::EMethodNone, 0); // sequence number
       
   128 
       
   129     CleanupStack::Pop(guid);
       
   130     CleanupStack::PushL(entry);
       
   131     return entry;
       
   132 }
       
   133 
       
   134 CPIMAgnItemAdapter::CPIMAgnItemAdapter(java::util::FunctionServer* aFuncServer) :
       
   135         iFuncServer(aFuncServer)
       
   136 {
       
   137     JELOG2(EPim);
       
   138 }
       
   139 
       
   140 // End of file