calendarui/organizerplugin/aiagendaplugin2/src/aicalendarplugin2constantdata.cpp
changeset 0 f979ecb2b13e
child 5 42814f902fe6
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  
       
    15  *
       
    16 */
       
    17 
       
    18 #include "aicalendarplugin2constantdata.h"
       
    19 #include "aicalendarplugin2contentmodel.h"
       
    20 #include <aicalendarplugin2res.rsg>
       
    21 #include <avkon.rsg>
       
    22 #include <StringLoader.h>
       
    23 #include <aicontentmodel.h>
       
    24 #include <aiutility.h>
       
    25 #include <aipropertyextension.h>
       
    26 #include <AknUtils.h>
       
    27 
       
    28 // CONSTANTS
       
    29 #include "aicalendarplugin2constants.hrh"
       
    30 
       
    31 _LIT( KAI2CalShortDayName, "%*E" );
       
    32 
       
    33 template<class Array>
       
    34 void CleanupReset(TAny* aObj)
       
    35     {
       
    36     static_cast<Array*>(aObj)->Reset();
       
    37     delete aObj;
       
    38     }
       
    39 
       
    40 template<class Array>
       
    41 void CleanupResetPushL(Array& aPointerArray)
       
    42     {
       
    43     CleanupStack::PushL( TCleanupItem(&CleanupReset<Array>, &aPointerArray) );
       
    44     }
       
    45 // ============================ MEMBER FUNCTIONS ===============================
       
    46 
       
    47 CAICalendarPlugin2ConstantData* CAICalendarPlugin2ConstantData::NewL()
       
    48     {
       
    49     CAICalendarPlugin2ConstantData* self = new( ELeave )CAICalendarPlugin2ConstantData;
       
    50     CleanupStack::PushL( self );
       
    51     self->ConstructL();
       
    52     CleanupStack::Pop( self );
       
    53     return self;
       
    54     }
       
    55 
       
    56 CAICalendarPlugin2ConstantData::CAICalendarPlugin2ConstantData()
       
    57   : iDaysToHandleAsNotToday( KAIRangeTomorrowOnly ) // platform defaults to "tomorrow only"
       
    58     {
       
    59     }
       
    60 
       
    61 void CAICalendarPlugin2ConstantData::ConstructL()
       
    62     {
       
    63     // load time format strings
       
    64     iTimeFormatUsual = StringLoader::LoadL( R_QTN_TIME_USUAL );
       
    65     iDateFormatWithoutYearWithZero = StringLoader::LoadL( R_QTN_DATE_WITHOUT_YEAR_WITH_ZERO );
       
    66     iDateFormatShortWithZero = StringLoader::LoadL( R_QTN_DATE_SHORT_WITH_ZERO );    
       
    67     iContent = AiUtility::CreateContentItemArrayIteratorL( KAICalendarPlugin2Content );
       
    68     iResources = AiUtility::CreateContentItemArrayIteratorL( KAICalendarPlugin2Resources );
       
    69     iEvents = AiUtility::CreateContentItemArrayIteratorL( KAICalendarPlugin2Events );
       
    70     }
       
    71 
       
    72 CAICalendarPlugin2ConstantData::~CAICalendarPlugin2ConstantData()
       
    73     {
       
    74     Release( iEvents );
       
    75     Release( iResources );
       
    76     Release( iContent );    
       
    77     delete iDateFormatShortWithZero;
       
    78     delete iDateFormatWithoutYearWithZero;
       
    79     delete iTimeFormatUsual;
       
    80     delete iNextEventOnCombined;
       
    81     }
       
    82     
       
    83 const TDesC& CAICalendarPlugin2ConstantData::TimeFormatUsual()
       
    84     {
       
    85     return *iTimeFormatUsual;
       
    86     }
       
    87 
       
    88 const TDesC& CAICalendarPlugin2ConstantData::DateFormatWithoutYearWithZero()
       
    89     {
       
    90     return *iDateFormatWithoutYearWithZero;
       
    91     }
       
    92 
       
    93 const TDesC& CAICalendarPlugin2ConstantData::MakeEventOnL( const TTime& aTime )
       
    94     {
       
    95     delete iNextEventOnCombined;
       
    96     iNextEventOnCombined = NULL;
       
    97     
       
    98     CDesC16ArrayFlat* desArray = new(ELeave) CDesC16ArrayFlat( 2 );
       
    99     CleanupStack::PushL( desArray );
       
   100 
       
   101     
       
   102     // Format day name short (Mon, Tue etc.)
       
   103     HBufC* day = HBufC::NewLC( KAICal2SizeDayShort );
       
   104     TPtr bufPtr2 = day->Des();
       
   105     aTime.FormatL( bufPtr2, KAI2CalShortDayName );
       
   106     desArray->AppendL( *day );
       
   107     CleanupStack::PopAndDestroy( day );
       
   108     
       
   109     
       
   110     // Format date (8/11  31/1/08 etc)
       
   111     TTime today;
       
   112     today.HomeTime();
       
   113     TDateTime todayDate = today.DateTime();
       
   114     TDateTime time = aTime.DateTime();
       
   115     HBufC* date = HBufC::NewLC( KAICal2SizeDateShort );
       
   116     TPtr bufPtr = date->Des();
       
   117     if( todayDate.Year() == time.Year() )
       
   118         {
       
   119         aTime.FormatL( bufPtr, *iDateFormatWithoutYearWithZero );
       
   120         }
       
   121     else
       
   122         {
       
   123         aTime.FormatL( bufPtr, *iDateFormatShortWithZero );
       
   124         }
       
   125     AknTextUtils::LanguageSpecificNumberConversion( bufPtr );
       
   126     desArray->AppendL( *date );
       
   127     CleanupStack::PopAndDestroy( date );
       
   128     
       
   129     
       
   130     // Load the string with formatters
       
   131     iNextEventOnCombined = StringLoader::LoadL( R_QTN_AI_CALE_NEXT_LATER, *desArray );
       
   132 
       
   133     // Destroy the formatters
       
   134     CleanupStack::PopAndDestroy(); // desArray
       
   135     
       
   136     return *iNextEventOnCombined;
       
   137     }
       
   138 
       
   139 void CAICalendarPlugin2ConstantData::SetPropertyL( TInt aProperty, TAny* aValue )
       
   140     {
       
   141     if( aProperty == EAiPublisherInfo )
       
   142         {
       
   143         ASSERT( aValue );
       
   144         
       
   145         const TAiPublisherInfo* info( 
       
   146                 static_cast<const TAiPublisherInfo*>( aValue ) );
       
   147                 
       
   148         iInfo = *info;
       
   149         }        
       
   150     }
       
   151 
       
   152 TAny* CAICalendarPlugin2ConstantData::GetPropertyL( TInt aProperty )
       
   153     {
       
   154     switch( aProperty )
       
   155     {
       
   156     case EAiPublisherInfo:
       
   157         return &iInfo;
       
   158 
       
   159     case EAiPublisherContent:
       
   160         return iContent;
       
   161 
       
   162     case EAiPublisherResources:
       
   163         return iResources;
       
   164 
       
   165     case EAiPublisherEvents:
       
   166         return iEvents;
       
   167 
       
   168     case EAiPluginName:
       
   169         return StringLoader::LoadL( R_QTN_AI_CALE_PLUGIN_NAME );
       
   170     }
       
   171     return NULL;
       
   172     }
       
   173