⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rosteritem.cpp

📁 Simple Jabber Client for Symbian Platform
💻 CPP
字号:
/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *  Jabber
 *  Copyright (C) 2004 Xie Tian Lu  http://sabber.jabberstudio.org/
 */

#include "RosterItem.h"
#include <string.h>
#include "osaux.h"
#include "iconset.h"
#include "roster.h"
#include "listboxicon.h"

CRosterItem* CRosterItem::CreateRosterItem( char* aJid, char* aNick, char* aGroup, TInt aType )
{
	CRosterItem* inst = 0;

	switch ( aType ) {
	case EJabberUser:
		inst = new CRosterJabberUserItem( aJid, aNick, aGroup );
	break;

	case EGroup:
		inst = new CRosterGroupItem( aNick );
	break;
	}

	return inst;
}

CRosterItem::CRosterItem( char* aNick ) 
: iSelected( EFalse ), iIconSet( 0 )
{
	strcpy( iNick, aNick );
}

CRosterItem::~CRosterItem()
{
}

void CRosterItem::ItemDraw( CWindowGc* gc, const TRect& aBox, TInt aItemHeight )
{
	TBuf<128> buf;

	CUtil::UTF82Unicode( buf, iNick );
	TInt y = aBox.iTl.iY + 15;
	TInt l = aBox.iTl.iX + 24;
	gc->DrawText( buf, TPoint( l, y ) );
	//gc->DrawText(buf,TRect(TPoint(aBox.iTl.iX + 54,aBox.iTl.iY + 3 ),TPoint(aBox.iBr.iX-2,aBox.iBr.iY-3)),12);
}

void CRosterItem::ItemDraw( CWindowGc* gc, const TRect& aBox, TInt aItemHeight, CFont* aFont )
{
	TBuf<128> buf;

	gc->UseFont(aFont);
	CUtil::UTF82Unicode( buf, iNick );
	TInt y = aBox.iTl.iY + 15;
	TInt l = aBox.iTl.iX + 24;
	gc->DrawText( buf, TPoint( l, y ) );

	//gc->DrawText(buf,TRect(TPoint(aBox.iTl.iX + 54,aBox.iTl.iY + 3 ),TPoint(aBox.iBr.iX-2,aBox.iBr.iY-3)),12);
}

TInt CRosterItem::LineNum()
{
	return 1;
}

TInt CRosterItem::ViewLineNum()
{
	return 0;
}

TInt CRosterItem::Presence( char* jid, char* show, char* status, int on )
{
	return -1;
}

void CRosterItem::SetIconSet( CIconSet* aSet )
{
	iIconSet = aSet;
}


/////////////////////////////////////////////////////////////////////////////////////////

/**
 * class CRosterJabberUserItem
 */

CRosterJabberUserItem::CRosterJabberUserItem( char* aJid, char* aNick, char* aGroup )
: CRosterItem( aNick ), iState( EOffline )
{
	strcpy( iNick, aNick );
	strcpy( iJid, aJid );
	strcpy( iGroup, aGroup );
}

CRosterJabberUserItem::~CRosterJabberUserItem()
{
}

void CRosterJabberUserItem::ItemDraw( CWindowGc* gc, const TRect& aBox, TInt aItemHeight )
{
	//CFont* font = CUtil::GetChineseFont();

	TBuf< 128 > buf;
	CUtil::UTF82Unicode( buf, iNick );
	gc->DrawText( buf,
				  TRect( TPoint( aBox.iTl.iX + 54, aBox.iTl.iY + 5 ),
				  	     TPoint( aBox.iBr.iX - 2,  aBox.iBr.iY - 1 ) ),
				  12 );
}

void CRosterJabberUserItem::ItemDraw( CWindowGc* gc, const TRect& aBox, TInt aItemHeight, CFont* aFont )
{
	TBuf< 128 > buf;
	CUtil::UTF82Unicode( buf, iNick );
	gc->UseFont( aFont );
	//gc->DrawText( buf,
	//			  TRect( TPoint( aBox.iTl.iX + 32, aBox.iTl.iY + 5 ),
	//			  	     TPoint( aBox.iBr.iX - 2,  aBox.iBr.iY - 1 ) ),
	//			  12 );

	TInt y = aBox.iTl.iY + 15;
	TInt l = aBox.iTl.iX + 36;
	gc->DrawText( buf, TPoint( l, y ) );

	if ( !iIconSet )
		return;

	TInt x = aBox.iTl.iX + 8;
	y = aBox.iTl.iY; 

	switch ( iState ) {
	case EOffline:
		iIconSet->DrawIcon( *gc, EJabOffline, x, y );
		break;

	case EOnline:
		iIconSet->DrawIcon( *gc, EJabOnline, x, y );
		break;

	case EChat:
		iIconSet->DrawIcon( *gc, EJabChat, x, y );
		break;

	case EAway:
		iIconSet->DrawIcon( *gc, EJabAway, x, y );
		break;

	case EDND:
		iIconSet->DrawIcon( *gc, EJabDND, x, y );
		break;

	case EXA:
		iIconSet->DrawIcon( *gc, EJabXA, x, y );
		break;
	}
}

TInt CRosterJabberUserItem::Presence( char* jid, char* show, char* status, int on )
{
	if ( !EqualTo( jid ) )
		return -1;

	if ( !on ) 
		return EOffline;

	if ( show != NULL ) {
		if ( strcmp( show, STR_SHOW_AWAY ) == 0 )
			iState = EAway;
		else if ( strcmp( show, STR_SHOW_DND ) == 0 )
			iState = EDND;
		else if ( strcmp( show, STR_SHOW_XA ) == 0 ) 
			iState = EXA;
		else if ( strcmp( show, STR_SHOW_CHAT ) == 0 )
			iState = EChat;
		else 
			iState = EOnline;
	//} else if ( status != NULL ) {
	//	if ( strcmp( status, STR_CS_STAYOUT ) == 0 )
	//		iState = ELeaveWhile;
	//	else if ( strcmp( status, STR_CS_BUSY ) == 0 )
	//		iState = EBusy;
	//	else if ( strcmp( status, STR_CS_MEETING ) == 0 )
	//		iState = EConference;
	//	else
	//		iState = EOnline;
	} else {
		iState = EOnline;
	}

	strcpy( iJid, jid );
	return iState;
}

void CRosterJabberUserItem::Load( RFile& aFile )
{
}

void CRosterJabberUserItem::Save( RFile& aFile )
{
}

TBool CRosterJabberUserItem::EqualTo( char* jid ) 
{
	char	m[ 128 ];
	char	h[ 128 ];
	char*	t;

	strcpy( m, iJid );
	strcpy( h, jid );
	if ( t = strstr( m, "/" ) )
		*t = 0;
	if ( t = strstr( h, "/" ) )
		*t = 0;

	if ( strcmp( m, h ) == 0 )
		return ETrue;

	return EFalse;
}

void CRosterJabberUserItem::GetJid( char* jid )
{
	strcpy( jid, iJid );
}

/////////////////////////////////////////////////////////////////////////////////////////

/**
 * class CRosterGroupItem
 */

CRosterGroupItem::CRosterGroupItem( char* aNick ) : CRosterItem( aNick )
{
}

CRosterGroupItem::~CRosterGroupItem() 
{
}

void CRosterGroupItem::ItemDraw( CWindowGc* gc, const TRect& aBox, TInt aItemHeight )
{
}

void CRosterGroupItem::ItemDraw( CWindowGc* gc, const TRect& aBox, TInt aItemHeight, CFont* aFont )
{
}

void CRosterGroupItem::Load( RFile& aFile )
{
}

void CRosterGroupItem::Save( RFile& aFile )
{
}

TBool CRosterGroupItem::EqualTo( char* aNick )
{
	return ( strcmp( iNick, aNick ) == 0 );
}

void CRosterGroupItem::AddItem( CRosterJabberUserItem* aItem )
{
}

void CRosterGroupItem::DelItem( CRosterJabberUserItem* aItem )
{
}

void CRosterGroupItem::GetJid( char* jid )
{
	strcpy( jid, "" );
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -