meetingui/meetingrequestviewers/src/CMRStringFormatter.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2005 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: Implementation for meeting request string formatter  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CMRStringFormatter.h"
       
    23 #include "MRViewersPanic.h"
       
    24 #include <coemain.h> 	            // CCoeEnv
       
    25 #include <stringloader.h>           // StringLoader
       
    26 #include <avkon.rsg>                // resouce identifiers
       
    27 #include <meetingrequestviewersuires.rsg>
       
    28 #include <calentry.h>				// Calendar entry API V2
       
    29 #include <caltime.h>
       
    30 
       
    31 // CONSTANTS
       
    32 /// Unnamed namespace for local definitions
       
    33 namespace {
       
    34 
       
    35 const TInt KMaxDateTimeTextLength = 100;
       
    36 
       
    37 _LIT( KPanicMsg, "~CMRStringFormatter" );
       
    38 
       
    39 void Panic( TPanicCode aReason )
       
    40     {
       
    41     User::Panic( KPanicMsg, aReason );
       
    42     }
       
    43 
       
    44 }  // namespace
       
    45 
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 CMRStringFormatter* CMRStringFormatter::NewL( CCoeEnv& aCoeEnv )
       
    50     {
       
    51     CMRStringFormatter* self = new( ELeave ) CMRStringFormatter( aCoeEnv );
       
    52 
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop();
       
    56 
       
    57     return self;
       
    58     }
       
    59 
       
    60 CMRStringFormatter::~CMRStringFormatter()
       
    61     {
       
    62     delete iDateFormat;
       
    63     delete iTimeFormat;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CMRStringFormatter::CMRStringFormatter
       
    68 // C++ default constructor can NOT contain any code, that
       
    69 // might leave.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CMRStringFormatter::CMRStringFormatter( CCoeEnv& aCoeEnv ) : iCoeEnv( aCoeEnv )
       
    73     {
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CMRStringFormatter::ConstructL
       
    78 // Symbian 2nd phase constructor can leave.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CMRStringFormatter::ConstructL()
       
    82     {
       
    83     iDateFormat = StringLoader::LoadL( R_QTN_DATE_USUAL_WITH_ZERO, &iCoeEnv );
       
    84 	iTimeFormat = StringLoader::LoadL( R_QTN_TIME_USUAL, &iCoeEnv );
       
    85     }
       
    86 
       
    87 HBufC* CMRStringFormatter::DateStringLC( const TCalTime& aTime ) const
       
    88     {    
       
    89     return DateStringLC( aTime.TimeLocalL() );
       
    90     }
       
    91 
       
    92 HBufC* CMRStringFormatter::DateStringLC( const TTime& aTime ) const
       
    93     {
       
    94     TBuf<KMaxDateTimeTextLength> tmpString;
       
    95     aTime.FormatL( tmpString, *iDateFormat );
       
    96     return tmpString.AllocLC();    
       
    97     }
       
    98 	
       
    99 HBufC* CMRStringFormatter::TimeStringLC( const TCalTime& aTime ) const
       
   100     {
       
   101     return TimeStringLC( aTime.TimeLocalL() );
       
   102     }
       
   103 	
       
   104 HBufC* CMRStringFormatter::TimeStringLC( const TTime& aTime ) const
       
   105     {
       
   106     TBuf<KMaxDateTimeTextLength> tmpString;
       
   107     aTime.FormatL( tmpString, *iTimeFormat );
       
   108     return tmpString.AllocLC();
       
   109     }
       
   110 	
       
   111 HBufC* CMRStringFormatter::WhenStringLC(
       
   112     const TCalTime& aStartTime,
       
   113     const TCalTime& aEndTime ) const
       
   114     {
       
   115 	TBuf<KMaxDateTimeTextLength> tmpWhenStartDate;
       
   116 	TBuf<KMaxDateTimeTextLength> tmpWhenStartTime;
       
   117 	TBuf<KMaxDateTimeTextLength> tmpWhendEndTime;
       
   118 	
       
   119 	// use local time in ui
       
   120 	TTime whenStartTime = aStartTime.TimeLocalL();
       
   121 	TTime whenEndTime = aEndTime.TimeLocalL();
       
   122 	
       
   123 	whenStartTime.FormatL( tmpWhenStartDate, *iDateFormat );
       
   124 	whenStartTime.FormatL( tmpWhenStartTime, *iTimeFormat );
       
   125 	whenEndTime.FormatL( tmpWhendEndTime, *iTimeFormat );
       
   126 	
       
   127 	CDesCArrayFlat* timeStrings = new( ELeave ) CDesCArrayFlat( 3 );
       
   128 	CleanupStack::PushL( timeStrings );
       
   129 	
       
   130 	timeStrings->AppendL( tmpWhenStartDate );
       
   131 	timeStrings->AppendL( tmpWhenStartTime );
       
   132 	timeStrings->AppendL( tmpWhendEndTime );
       
   133 	HBufC* string = StringLoader::LoadL( R_QTN_MAIL_MTG_TIME_DATA,
       
   134 	                                      *timeStrings,
       
   135 	                                      &iCoeEnv );	
       
   136 	CleanupStack::PopAndDestroy( timeStrings );
       
   137 	CleanupStack::PushL( string );
       
   138 	return string;
       
   139 	}
       
   140 
       
   141 //  End of File
       
   142