calendarui/regionalplugins/calenregionalutil/src/calenextrarowformatter.cpp
changeset 49 5de72ea7a065
parent 23 fd30d51f876b
child 50 579cc610882e
equal deleted inserted replaced
37:360d55486d7f 49:5de72ea7a065
    13 *
    13 *
    14 * Description:   Calendar Lunar Plugin 
    14 * Description:   Calendar Lunar Plugin 
    15  *
    15  *
    16 */
    16 */
    17 
    17 
    18 
    18 #include <qstringlist.h>
    19 
    19 #include <hbglobal.h>
    20 #include <calenregionalutil.rsg>
    20 
    21 #include <badesca.h> 
    21 #include <badesca.h> 
    22 #include <eikenv.h>
    22 #include <eikenv.h>
    23 #include <StringLoader.h>
       
    24 
    23 
    25 #include "calendarui_debug.h"
    24 #include "calendarui_debug.h"
    26 #include "CalenExtraRowFormatter.h"
    25 #include "CalenExtraRowFormatter.h"
    27 
    26 
    28 // -----------------------------------------------------------------------------
    27 // -----------------------------------------------------------------------------
   157 // -----------------------------------------------------------------------------
   156 // -----------------------------------------------------------------------------
   158 //
   157 //
   159 EXPORT_C TPtrC CCalenExtraRowFormatter::FormatExtraRowInformationL( 
   158 EXPORT_C TPtrC CCalenExtraRowFormatter::FormatExtraRowInformationL( 
   160     CCalenLunarLocalizedInfo& aLocInfo, 
   159     CCalenLunarLocalizedInfo& aLocInfo, 
   161     RArray<CCalenLunarLocalizedInfo::TField>& aPrioritizedFields )
   160     RArray<CCalenLunarLocalizedInfo::TField>& aPrioritizedFields )
   162     {
   161 {
   163     TRACE_ENTRY_POINT;
   162 	TRACE_ENTRY_POINT;
   164     
   163 
   165     
   164 
   166     if ( aPrioritizedFields.Count() == 0)
   165 	if ( aPrioritizedFields.Count() == 0)
   167         {
   166 	{
   168         iText = KNullDesC;
   167 		iText = KNullDesC;
   169         
   168 
   170         TRACE_EXIT_POINT;
   169 		TRACE_EXIT_POINT;
   171         return iText;
   170 		return iText;
   172         }
   171 	}
   173 
   172 
   174     // Initialize substring labels
   173 	// Initialize substring labels
   175     RArray<CCalenLunarLocalizedInfo::TField> subLabels;
   174 	RArray<CCalenLunarLocalizedInfo::TField> subLabels;
   176     CleanupClosePushL( subLabels );
   175 	CleanupClosePushL( subLabels );
   177     subLabels.AppendL( CCalenLunarLocalizedInfo::EAnimalYear );
   176 	subLabels.AppendL( CCalenLunarLocalizedInfo::EAnimalYear );
   178     subLabels.AppendL( CCalenLunarLocalizedInfo::ELunarYear );
   177 	subLabels.AppendL( CCalenLunarLocalizedInfo::ELunarYear );
   179     subLabels.AppendL( CCalenLunarLocalizedInfo::ELunarMonthAndDay );
   178 	subLabels.AppendL( CCalenLunarLocalizedInfo::ELunarMonthAndDay );
   180     subLabels.AppendL( CCalenLunarLocalizedInfo::EFestival );
   179 	subLabels.AppendL( CCalenLunarLocalizedInfo::EFestival );
   181     subLabels.AppendL( CCalenLunarLocalizedInfo::ESolarTerm );
   180 	subLabels.AppendL( CCalenLunarLocalizedInfo::ESolarTerm );
   182     
   181 
   183     // ASSERT that all prioritized fields can be found from subLabels
   182 	// ASSERT that all prioritized fields can be found from subLabels
   184     for ( TInt i=0; i < aPrioritizedFields.Count(); i++)
   183 	for ( TInt i=0; i < aPrioritizedFields.Count(); i++)
   185         {
   184 	{
   186         ASSERT( subLabels.Find( aPrioritizedFields[i] ) >= 0 ); 
   185 		ASSERT( subLabels.Find( aPrioritizedFields[i] ) >= 0 ); 
   187         }
   186 	}
   188 
   187 
   189 	// Initialize substring array 
   188 	// Initialize substring array 
   190 	CPtrCArray* subs = new (ELeave) CPtrCArray(10);
   189 	CPtrCArray* subs = new (ELeave) CPtrCArray(10);
   191 	CleanupStack::PushL( subs );
   190 	CleanupStack::PushL( subs );
   192 	for ( TInt i = 0; i < subLabels.Count(); i++) 
   191 	for ( TInt i = 0; i < subLabels.Count(); i++) 
   193 		{
   192 	{
   194 		subs->AppendL( TPtrC( KNullDesC ) );
   193 		subs->AppendL( TPtrC( KNullDesC ) );
   195 		}
   194 	}
   196 	// subs->InsertL( 0, TPtrC( KNullDesC ), 5 );
   195 
   197 	
       
   198 	// Set wanted fields to substring array
   196 	// Set wanted fields to substring array
   199 	for ( TInt i = 0; i < aPrioritizedFields.Count(); i++)
   197 	for ( TInt i = 0; i < aPrioritizedFields.Count(); i++)
   200 		{
   198 	{
   201 		CCalenLunarLocalizedInfo::TField field = aPrioritizedFields[i];
   199 		CCalenLunarLocalizedInfo::TField field = aPrioritizedFields[i];
   202 		TInt subIx = subLabels.Find( field );
   200 		TInt subIx = subLabels.Find( field );
   203 		// Replace 
   201 		// Replace 
   204 		subs->Delete(subIx);
   202 		subs->Delete(subIx);
   205 		RDebug::Print( _L("A sub count  %d"), subs->Count() );
   203 		RDebug::Print( _L("A sub count  %d"), subs->Count() );
   206 		subs->InsertL(subIx, TPtrC( aLocInfo.GetField( field ) ) );
   204 		subs->InsertL(subIx, TPtrC( aLocInfo.GetField( field ) ) );
   207 		RDebug::Print( _L("B sub count %d"), subs->Count() );
   205 		RDebug::Print( _L("B sub count %d"), subs->Count() );
   208 		RDebug::Print( _L("B field %S"), &(subs->At(subIx)) );
   206 		RDebug::Print( _L("B field %S"), &(subs->At(subIx)) );
   209 		
   207 
   210 		}
   208 	}
   211 	
   209 	TBuf<100> textBuf;
   212 	// Format all fields to extra row     
   210 	QStringList textDataStringList;
   213 	HBufC* extraRowFmt = StringLoader::LoadLC( R_CALE_EXTRA_ROW_LUNAR );
   211 	for (TInt i=0; i < subLabels.Count(); i++) {
   214 	
   212 		textBuf = subs->At( i );
   215 	RDebug::RawPrint( *extraRowFmt );
   213 		textDataStringList.append(
   216 	
   214 							QString((QChar*)textBuf.Ptr(),textBuf.Length()));
   217 	TBuf<1000> fmt = *extraRowFmt;
   215 	}
   218 	for (TInt i=0; i < subLabels.Count(); i++)
   216 	// Get the locale specific separator
   219 		{
   217 	QString separator = hbTrId("txt_calendar_preview_title_cale_separator");
   220 		RDebug::Print( _L("Before Format") );
   218 	
   221 		RDebug::RawPrint( fmt );
   219 	// Format all fields to single row 
   222 		StringLoader::Format( iText, 
   220 	QString textDataString;
   223 							  fmt,
   221 	textDataString = hbTrId(
   224 							  i + 1, // %0U is a separator 
   222 						"txt_calendar_preview_title_123242526").arg(
   225 							  subs->At( i ) );
   223 							textDataStringList.at(0)).arg(
   226 		fmt = iText;
   224 								separator).arg(
   227 		RDebug::Print( _L("After Format") );
   225 									textDataStringList.at(1)).arg(
   228 		RDebug::RawPrint( fmt );
   226 										textDataStringList.at(2)).arg(
   229 		}
   227 											textDataStringList.at(3)).arg(
   230 	
   228 												textDataStringList.at(4));
   231 	// Now we have something like "Year of Dog%0U%0U6/11%0U%0U" 
   229 
   232 	// First We need to remove multiple occurences of %0U
   230 	iText = static_cast<const TUint16*> (
   233 	_LIT(KSeparatorFmt, "%0U");
   231 							textDataString.utf16()), textDataString.length();
   234 	
   232 
   235 	CollapseDuplicatesL( iText, 0, KSeparatorFmt );
   233 	// Now we have something like "Year of Dog%2GengYin%2%2"
   236 	RDebug::Print( _L("After collapse") );
   234 	// where %2 is the separator txt_calendar_preview_title_cale_separator
   237 	RDebug::RawPrint( iText );
   235 	// First We need to remove multiple occurences of separator
   238 
   236 	textBuf = static_cast<const TUint16*> (
   239 	// Remove leading and trailing %0U
   237 										separator.utf16()), separator.length();
   240 	// By now, we are sure that there is max 1 %0U in the beginning
   238 	CollapseDuplicatesL( iText, 0, textBuf);
   241 	// and in the end of string.
   239 	
   242 	RemoveLeadingAndTrailingL( iText, KSeparatorFmt );
   240 	// Remove leading and trailing separators
   243 	RDebug::Print( _L("After leading and trailing removal") );
   241 	// Leading separator won't be there but trailing one is there for sure
   244 	RDebug::RawPrint( iText );
   242 	RemoveLeadingAndTrailingL( iText, textBuf );
   245 	
   243 	
   246 
   244 	// CleanUp
   247 	// If there are now separators anymore, then do not fill them
       
   248 	TBool hasSeparators = iText.Find( KSeparatorFmt ) >= 0;
       
   249 	
       
   250 	if ( hasSeparators ) 
       
   251 		{
       
   252 	
       
   253 		// fill in separators
       
   254 		HBufC* separator = StringLoader::LoadLC( R_CALE_LUNAR_SEPARATOR );
       
   255 		fmt = iText;
       
   256 		StringLoader::Format( iText, 
       
   257 							  fmt,
       
   258 							  0, // %0U is a separator 
       
   259 							  *separator );
       
   260 	
       
   261 		RDebug::Print( _L("After separator insert") );
       
   262 		RDebug::RawPrint( iText );
       
   263 		CleanupStack::PopAndDestroy( separator );
       
   264 		}
       
   265 
       
   266 
       
   267 	CleanupStack::PopAndDestroy( extraRowFmt );
       
   268 	CleanupStack::PopAndDestroy( subs );
   245 	CleanupStack::PopAndDestroy( subs );
   269     CleanupStack::PopAndDestroy( &subLabels );
   246 	CleanupStack::PopAndDestroy( &subLabels );
   270     
   247 	TRACE_EXIT_POINT;
   271     TRACE_EXIT_POINT;
   248 	
   272     return iText;
   249 	return iText;
   273     }
   250 }
   274 
   251 
   275 //EOF
   252 //EOF
   276 
   253