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

📄 esimusercontainer.cpp

📁 基于SIP协议的即时消息聊天功能设计,Symbian平台下实现
💻 CPP
字号:
/*
============================================================================
 Name        : CESIMUserContainer from CESIMUserContainer.h
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : 点对点和组群消息选择界面
============================================================================
*/

// INCLUDE FILES
#include "ESIMUserContainer.h"

#include <eiklabel.h>  // for example label control
#include <barsread.h> // TResource Reader
#include <eikclbd.h> // CColumnListBoxData
#include <eiktxlbx.h> 
#include <aknlists.h> //CAknSingleGraphicHeadingStyleListBox
#include <stringloader.h> 
#include <akniconarray.h> 
#include <ESIM.rsg>
#include "ESIM.hrh"
#include "ESIM.mbg"

#include "ESIMUserItem.h"
#include "ESIMItemEngine.h" //for CESIMItemEngine
#include "ESIMUserView.h"
#include <AknQueryDialog.h>//CAknQueryDialog


#define KListPosition TPoint(0,0) 
const TInt KNumberOfIcons(3);
const TInt KNumberOfNames(20);

static TInt m = 0; // To test UI refresh

// ================= MEMBER FUNCTIONS =======================


// ---------------------------------------------------------
// CESIMUserContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CESIMUserContainer::ConstructL(const TRect& aRect,CESIMUserView* aView)
    {
	CTimer::ConstructL(); // Must be called before create any local Timer

	iTimer.CreateLocal(); // Create a local timer

	CActiveScheduler::Add(this); // Add active object to the scheduler

	CreateWindowL();

	iView = aView;

	// Create the list
	CreateListL();	

	// Observe the list
	iUserListBox->SetListBoxObserver(this);

    SetRect(aRect);
    ActivateL();

    }

// Destructor
CESIMUserContainer::~CESIMUserContainer()
    {
		Cancel();

		delete iUserListBox;

		iTimer.Close();
    }

// ---------------------------------------------------------
// CESIMUserContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CESIMUserContainer::SizeChanged()
    {
    // TODO: Add here control resize code etc.
    iUserListBox->SetExtent (KListPosition, iUserListBox->MinimumSize());
	//iUserListBox->SetExtent (KListPosition, TSize(100,100));
    }

// ---------------------------------------------------------
// CESIMUserContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CESIMUserContainer::CountComponentControls() const
    {
    return 1; // return nbr of controls inside this container
    }

// ---------------------------------------------------------
// CESIMUserContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CESIMUserContainer::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
        case 0:
            return iUserListBox;
        default:
            return NULL;
        }
    }

// ---------------------------------------------------------
// CESIMUserContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CESIMUserContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    // TODO: Add your drawing code here
    // example code...
/*   gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
*/
	gc.Clear(aRect);
    }

// ---------------------------------------------------------
// CESIMUserContainer::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CESIMUserContainer::HandleControlEventL(
    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    // TODO: Add your control event handler code here
    }

//CHUZX ADD
	/**
* Constructs the iSavedGamesList, setting its window.
*/
void CESIMUserContainer::CreateListL()
	{
	// First phase construction
	iUserListBox = new (ELeave) CAknSingleGraphicStyleListBox;
	iUserListBox->SetContainerWindowL(*this);
	
	// Second Phase Construction
	TResourceReader reader;
	iEikonEnv->CreateResourceReaderLC(reader, R_ESIM_USER_LISTBOX);
	iUserListBox->ConstructFromResourceL(reader);
	CleanupStack::PopAndDestroy(); // reader

	SetupListItemsL();
	SetupListIconsL();

	//create scroll bar
    iUserListBox->CreateScrollBarFrameL( ETrue );
    iUserListBox->ScrollBarFrame()->SetScrollBarVisibilityL( 
            CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
	}

/**
* Populates the list model's item array with a list of saved games
*/
void CESIMUserContainer::SetupListItemsL()
{
// 	//CDesCArray *contacts = iEngine->GetContactsL();
// 	CTextListBoxModel* model = iUserListBox->Model();  // not taking ownership
// 	CDesCArray* items = STATIC_CAST(CDesCArray*, model->ItemTextArray());
// 	// Strings will be of the format "2\tSaved Game i", where i is a number from 1 to 10
// 	
// 	//TInt n = 0;
// 	if(3 == m)
// 		m = 0;
// 	
// 	TBuf <40> aString;
// 
// 	for (TInt i = 0; i< iEngine->UserItemCount(); i++)
// 	{
// 		TPtrC ptr = ((iEngine->UserItem(i))->Name())->Des() ;
// 	//	aString.Format(KStringHeader0, &ptr);
// 	//	items->AppendL (aString);
// 		
// 		if(0 == m)
// 		{
// 			_LIT (KStringHeader0, "0\t%S");
// 		//	m++;
// 			aString.Format(KStringHeader0, &ptr);
// 			items->AppendL (aString);
// 		}
// 
// 		if(1 == m)
// 		{
// 			_LIT (KStringHeader1, "1\t%S");
// 		//	m++;
// 			aString.Format(KStringHeader1, &ptr);
// 			items->AppendL (aString);
// 		}
// 
// 		if(2 == m)
// 		{
// 			_LIT (KStringHeader2, "2\t%S");
// 		//	m = n;
// 			aString.Format(KStringHeader2, &ptr);
// 			items->AppendL (aString);
// 		}
// 
// 		//Start();// Issue the 2sec delay
// 		//if(m == 3)
// 		//	m = n;
// 	}
	//CDesCArray *contacts = iEngine->GetContactsL();
	CTextListBoxModel* model = iUserListBox->Model();  // not taking ownership
	CDesCArray* items = STATIC_CAST(CDesCArray*, model->ItemTextArray());
	// Strings will be of the format "2\tSaved Game i", where i is a number from 1 to 10

	TInt n = 0;
	if(3 == m)
		m = 0;

	TBuf <40> aString;

	for (TInt i = 0; i< iEngine->UserItemCount(); i++)
	{
		TPtrC pName = ((iEngine->UserItem(i))->Name())->Des();

		_LIT (KStringHeader0, "0\t%S");

		aString.Format(KStringHeader0, &pName);
		items->AppendL (aString);


		// 取得User的Flag,根据其状态刷新屏幕
		// 由收到的sip MSG 根据sipaddress设置相应的Flag为ETRUE
		// 当在UI中现实了该条消息后,置相应Flag位EFALSE
		for (TInt i = 0; i< iEngine->UserItemCount(); i++)
		{
			iEngine->UserItem(0)->SetFlagsL(ETrue); // test

			TUint pFlag = ((iEngine->UserItem(i))->Flags()) ;


			if (pFlag)
			{
				TPtrC pName2 = ((iEngine->UserItem(i))->Name())->Des() ; //需改为根据sipaddr判断

				if (!(pName.Compare(pName2))) //若相同,则显示对应的用户图标
				{

					items->Delete(i);

					if(0 == m)
					{
						_LIT (KStringHeader0, "0\t%S");

						aString.Format(KStringHeader0, &pName);
						items->AppendL (aString);
					}

					if(1 == m)
					{

						_LIT (KStringHeader1, "1\t%S");					
						aString.Format(KStringHeader1, &pName);
						items->AppendL (aString);
					}

					if(2 == m)
					{
						_LIT (KStringHeader2, "2\t%S");

						aString.Format(KStringHeader2, &pName);
						items->AppendL (aString);
					}

					// Start();// Issue the  delay
				}
			}
		}
	}
}

void CESIMUserContainer::SetupListIconsL()
	{
	// Get the name of the file containing the icons	
	HBufC* iconFileName;
	iconFileName = StringLoader::LoadLC(R_ICON_FILE_NAME);	// Pushes iconFileName onto the Cleanup Stack.

	// Create an array of icons, reading them from the file
	CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(KNumberOfIcons);
	CleanupStack::PushL(icons);
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, 
					EMbmEsimMarked_add, EMbmEsimMarked_addm));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, 
					EMbmEsimNon_check, EMbmEsimNon_checkm));
    icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, 
					EMbmEsim1player, EMbmEsim1player_mask));
	
	iUserListBox->ItemDrawer()->ColumnData()->SetIconArray(icons); // 传递icon的所有权
	
	CleanupStack::Pop(icons);
	CleanupStack::PopAndDestroy(iconFileName);

	//CleanupStack::PopAndDestroy(2);

//	Start(); // Issue the 2sec delay

	}

/**
* Called by the framework whenever a key event occurs.	
* Passes the key event to the saved games list if it is not null, otherwise returns
* EKeyWasNotConsumed
* @param aKeyEvent the Key event which occured, e.g. select key pressed
* @param aType the type of Key event which occurred, e.g. key up, key down
* @return TKeyResponse EKeyWasNotConsumed if the key was not processed, EKeyWasConsumed if it was
*/
TKeyResponse CESIMUserContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
	{
// 	if (aKeyEvent.iScanCode == 16 || aKeyEvent.iScanCode == 17)
// 	{
// 		return iUserListBox->OfferKeyEventL (aKeyEvent, aType);
// 	}
// 
// 	if (aKeyEvent.iScanCode == 167)
// 	{
// 		iEngine->EditUserFormL(iUserListBox->CurrentItemIndex());
// 		RefreshListL();
// 	}
// 	return EKeyWasNotConsumed;
		TInt currentItemIndex(iUserListBox->CurrentItemIndex());
		iEngine->SetCurrentUserIndex(currentItemIndex);
		
	if (iUserListBox&&aKeyEvent.iCode != EKeyLeftArrow && aKeyEvent.iCode != EKeyRightArrow)
		return iUserListBox->OfferKeyEventL (aKeyEvent, aType);
	else
		return EKeyWasNotConsumed;
	}

/**
* Called by the framework whenever a list event occurs for which this container
* is an observer.
* @param aListBoxEvent The type of event which occured
*
*/
void CESIMUserContainer::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aListBoxEvent)
	{
		TInt currentItemIndex(aListBox->CurrentItemIndex());
		iEngine->SetCurrentUserIndex(currentItemIndex);
	// if the Select Key has been pressed CEikColumnListBox 
	if (aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) 
		{
// 		iView->HandleCommandL(EESIMCmdActiveConversationView);
 		iView->HandleCommandL(EESIMCmdSendMessage);
// 		iEngine->EditUserFormL(iUserListBox->CurrentItemIndex());
// 		RefreshListL();

		}
	}
  
/**
* Deletes all currently marked games
*/
/**/
void CESIMUserContainer::DeleteSelectedL()
	{
	//create a confirmation query
	CAknQueryDialog* DeleteSelectQuery = CAknQueryDialog::NewL();	
	if (DeleteSelectQuery->ExecuteLD(R_ESIM_CONFIRMATION_QUERY))
		{
			iEngine->RemoveUserItem(iUserListBox->CurrentItemIndex());	    
		}
	}
/**/
CEikColumnListBox* CESIMUserContainer::ListBox() const
	{
	return iUserListBox;
	}
/**/
TBool CESIMUserContainer::IsItemOnListBox()
	{
    TInt listboxcount(0);
	listboxcount = iUserListBox->Model()->NumberOfItems();
	if (0 == listboxcount)
	    return ETrue;
	else
	    return EFalse;
	}
/**/
void CESIMUserContainer::RefreshListL()
{
	//清空列表
	CTextListBoxModel* model = iUserListBox->Model();  // not taking ownership
	CDesCArray* items = STATIC_CAST(CDesCArray*, model->ItemTextArray());
	items->Delete(0, items->Count());

	//再将新的列表全部加入
	SetupListItemsL();
    iUserListBox->HandleItemAdditionL();
	iUserListBox->SetCurrentItemIndexAndDraw( 0 );
    SizeChanged();
    DrawNow();
}

// Implementation  of an active object methods

void CESIMUserContainer::Start()
{
	if(IsActive())
		return;

	iTimer.After(iStatus,5000000); // Issue a  delay

	SetActive(); // Set the active object Active

}

void CESIMUserContainer::RunL()
{
	++m;


	RefreshListL();


}


void CESIMUserContainer::Cancel()
{
	DoCancel();

}

void CESIMUserContainer::DoCancel()
{
	CTimer::Cancel();

}
// End of File

⌨️ 快捷键说明

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