sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: // LOGCLISERVSHARED.CPP
sl@0: // 
sl@0: //
sl@0: 
sl@0: #include "LogCliServShared.h"
sl@0: 
sl@0: 
sl@0: 
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: // -----> TLogWindow (source)
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: 
sl@0: EXPORT_C TLogWindow::TLogWindow()
sl@0: 	{
sl@0: 	Reset();
sl@0: 	}
sl@0: 
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: 
sl@0: EXPORT_C TBool TLogWindow::Contains(TInt aPosition) const
sl@0: 	{
sl@0: 	return (aPosition >= iLower && aPosition <= iUpper);
sl@0: 	}
sl@0: 
sl@0: EXPORT_C TInt TLogWindow::Range() const
sl@0: 	{
sl@0: 	if	(iUpper < 0)
sl@0: 		return 0;
sl@0: 	return (iUpper - iLower) + 1;
sl@0: 	}
sl@0: 
sl@0: EXPORT_C TInt TLogWindow::WindowIndexFromCursorPosition(TInt aCursorPosition) const
sl@0: 	{
sl@0: 	const TInt mapped = aCursorPosition - iLower;
sl@0: 	return mapped;
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TLogWindow::Reset()
sl@0: 	{
sl@0: 	iLower = -1;
sl@0: 	iUpper = -1;
sl@0: 	}
sl@0: 
sl@0: void TLogWindow::Normalize()
sl@0: 	{
sl@0: 	if	(iLower > iUpper)
sl@0: 		iLower = iUpper;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: // -----> TLogWindowAndCursor (source)
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: 
sl@0: TLogWindowAndCursor::TLogWindowAndCursor()
sl@0: 	{
sl@0: 	Reset();
sl@0: 	}
sl@0: 
sl@0: TLogWindowAndCursor::TLogWindowAndCursor(const TLogWindow& aWindow, TInt aCursorPosition)
sl@0: :	TLogWindow(aWindow), iCursorPosition(aCursorPosition)
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: 
sl@0: TLogWindowAndCursor::TAffected TLogWindowAndCursor::AdjustForItemDeletion(TInt aItemIndex)
sl@0: 	{
sl@0: 	const TInt KDelta = -1;
sl@0: 	//
sl@0: 	TAffected changed = EWindowUnaffected;
sl@0: 	if	(aItemIndex <= iUpper)
sl@0: 		{
sl@0: 		changed = EWindowAffected;
sl@0: 
sl@0: 		if	(aItemIndex < iCursorPosition)
sl@0: 			--iCursorPosition;
sl@0: 		else if (aItemIndex == iCursorPosition && iCursorPosition == iUpper)
sl@0: 			--iCursorPosition;
sl@0: 
sl@0: 		iUpper += KDelta;
sl@0: 		if	(aItemIndex < iLower)
sl@0: 			iLower += KDelta;
sl@0: 		//
sl@0: 		TLogWindow::Normalize();
sl@0: 		}
sl@0: 	return changed;
sl@0: 	}
sl@0: 
sl@0: TLogWindowAndCursor::TAffected TLogWindowAndCursor::AdjustForItemAddition(TInt aItemIndex)
sl@0: 	{
sl@0: 	///////////////////////////////////////
sl@0: 	// USE CASE 1:
sl@0: 	///////////////////////////////////////
sl@0: 	// Cursor position:  *
sl@0: 	// Window:			 ---------
sl@0: 	// View Index:       0 1 2 3 4 5 6
sl@0: 	// View Contents:    A B C D E F G
sl@0: 	//
sl@0: 	// Then, item X is added => 
sl@0: 	// 
sl@0: 	// Cursor position:    *
sl@0: 	// Window:			   ---------
sl@0: 	// View Index:       0 1 2 3 4 5 6 7
sl@0: 	// View Contents:    X A B C D E F G
sl@0: 	// 
sl@0: 	///////////////////////////////////////
sl@0: 	// USE CASE 2:
sl@0: 	///////////////////////////////////////
sl@0: 	// Cursor position:    *
sl@0: 	// Window:			   ---------
sl@0: 	// View Index:       0 1 2 3 4 5 6
sl@0: 	// View Contents:    A B C D E F G
sl@0: 	//
sl@0: 	// Then, item X is added => 
sl@0: 	// 
sl@0: 	// Cursor position:      *
sl@0: 	// Window:			     ---------
sl@0: 	// View Index:       0 1 2 3 4 5 6 7
sl@0: 	// View Contents:    X A B C D E F G
sl@0: 	// 
sl@0: 	///////////////////////////////////////
sl@0: 	// USE CASE 3:
sl@0: 	///////////////////////////////////////
sl@0: 	// Cursor position:          *
sl@0: 	// Window:			 ---------
sl@0: 	// View Index:       0 1 2 3 4 5 6
sl@0: 	// View Contents:    A B C D E F G
sl@0: 	//
sl@0: 	// Then, item X is added => 
sl@0: 	// 
sl@0: 	// Cursor position:            *
sl@0: 	// Window:			 -----------
sl@0: 	// View Index:       0 1 2 3 4 5 6 7
sl@0: 	// View Contents:    A B C D X E F G
sl@0: 	// 
sl@0: 	///////////////////////////////////////
sl@0: 	// USE CASE 4:
sl@0: 	///////////////////////////////////////
sl@0: 	// Cursor position:        *  
sl@0: 	// Window:			 ---------
sl@0: 	// View Index:       0 1 2 3 4 5 6
sl@0: 	// View Contents:    A B C D E F G
sl@0: 	//
sl@0: 	// Then, item X is added => 
sl@0: 	// 
sl@0: 	// Cursor position:        *   
sl@0: 	// Window:			 ---------
sl@0: 	// View Index:       0 1 2 3 4 5 6 7
sl@0: 	// View Contents:    A B C D E X F G
sl@0: 	// 
sl@0: 	///////////////////////////////////////
sl@0: 	const TInt KDelta = 1;
sl@0: 	//
sl@0: 	TAffected changed = EWindowUnaffected;
sl@0: 	if	(aItemIndex <= iUpper) // UC4
sl@0: 		{
sl@0: 		changed = EWindowAffected;
sl@0: 
sl@0: 		if	(aItemIndex <= iCursorPosition) // UC1
sl@0: 			++iCursorPosition;
sl@0: 		//
sl@0: 		iUpper += KDelta; // UC1
sl@0: 		if	(aItemIndex <= iLower) // UC1
sl@0: 			iLower += KDelta;
sl@0: 		//
sl@0: 		TLogWindow::Normalize();
sl@0: 		}
sl@0: 	return changed;
sl@0: 	}
sl@0: 
sl@0: TInt TLogWindowAndCursor::WindowIndexFromCursorPosition() const
sl@0: 	{
sl@0: 	return TLogWindow::WindowIndexFromCursorPosition(iCursorPosition);
sl@0: 	}
sl@0: 
sl@0: void TLogWindowAndCursor::Reset()
sl@0: 	{
sl@0: 	TLogWindow::Reset();
sl@0: 	iCursorPosition = -1;
sl@0: 	iValid = EFalse;
sl@0: 	}
sl@0: 
sl@0: void TLogWindowAndCursor::NormalizeWindowAndCursor()
sl@0: 	{
sl@0: 	TLogWindow::Normalize();
sl@0: 	if	(iCursorPosition < iLower)
sl@0: 		iCursorPosition = iLower;
sl@0: 	if	(iCursorPosition > iUpper)
sl@0: 		iCursorPosition = iUpper;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: // -----> TLogTransferWindow (source)
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: 
sl@0: EXPORT_C TLogTransferWindow::TLogTransferWindow() :
sl@0: 	iBufferSize(0),
sl@0: 	iServerDataSize(0)
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TLogTransferWindow::Reset()
sl@0: 	{
sl@0: 	TLogWindow::Reset();
sl@0: 	iBufferSize = iServerDataSize = 0;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: // -----> LogUtils (source)
sl@0: /////////////////////////////////////////////////////////////////////////////////////////
sl@0: /**  Retrieves appropriate date format string for the current locale.
sl@0: 
sl@0: @return    Format string for this locale. */
sl@0: EXPORT_C const TDesC& LogUtils::DateFormatForLocale()
sl@0: 	{
sl@0:     _LIT(KSQLDateFormatColon,"%D%*M%Y%1 %2 %3 %H:%T:%S%.%C"); 
sl@0:     _LIT(KSQLDateFormatDot,"%D%*M%Y%1 %2 %3 %H.%T.%S%.%C");
sl@0: 
sl@0: 	TLocale current; 
sl@0: 	TBool dateSeparatorIsColon=EFalse;
sl@0: 	for (TInt i=0; i<4; i++)
sl@0: 		{
sl@0: 		TChar c = current.DateSeparator(i);
sl@0: 		if (c==':')
sl@0: 			{
sl@0: 			dateSeparatorIsColon=ETrue;
sl@0: 			break;
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	if (dateSeparatorIsColon)
sl@0: 		return KSQLDateFormatDot;
sl@0: 	return KSQLDateFormatColon;
sl@0: 	}
sl@0: 
sl@0: