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

📄 esimgroupview.cpp

📁 基于SIP协议的即时消息聊天功能设计,Symbian平台下实现
💻 CPP
字号:
/*
============================================================================
 Name        : ESIMGroupView.cpp
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : ESIMGroupView.cpp - source file
============================================================================
*/

#include  <aknviewappui.h>
#include  <avkon.hrh>

#include <ESIMItemEngine.h>
#include "ESIMGroupView.h"
#include "ESIMGroupContainer.h"
#include "ESIMUserItem.h"
#include "ESIMGroupItem.h"

#include "ESIMAppui.h"

#include "ESIM.hrh" 
#include "ESIM.rsg" 
#include <eikmobs.h>
#include <eikmenup.h>
#include <stringloader.h> 
#include <aknlists.h> 
#include <aknpopup.h> 
#include <aknquerydialog.h>
#include <utf.h>

#include <string.h>
// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CESIMGroupView::ConstructL(const TRect& aRect)
// EPOC two-phased constructor
// ---------------------------------------------------------
//
void CESIMGroupView::ConstructL()
    {
    BaseConstructL( R_ESIM_GROUP_VIEW );
    }

// ---------------------------------------------------------
// CESIMGroupView::~CESIMGroupView()
// destructor
// ---------------------------------------------------------
//
CESIMGroupView::~CESIMGroupView()
    {
    if ( iContainer )
        {
        AppUi()->RemoveFromViewStack( *this, iContainer );
        }

    delete iContainer;
    }

// ---------------------------------------------------------
// TUid CESIMGroupView::Id()
// 
// ---------------------------------------------------------
//
TUid CESIMGroupView::Id() const
    {
    return KGroupViewId;
    }

// ---------------------------------------------------------
// CESIMGroupView::HandleCommandL(TInt aCommand)
// takes care of view command handling
// ---------------------------------------------------------
//
void CESIMGroupView::HandleCommandL(TInt aCommand)
    {   
    switch (aCommand)
		{
		case EAknSoftkeyBack:
			{
				AppUi()->HandleCommandL(EEikCmdExit);
				break;
			}
		case EESIMGroupCmdNew:
			{
				iEngine->CreateGroupL();
				iContainer->RefreshListL();
				break;
			}
		case EESIMGroupCmdDelete:
			{
				iEngine->RemoveGroupItem(iContainer->GetCurrentItemIndex());
				iContainer->RefreshListL();
				break;
			}
		case EESIMGroupCmdEdit:
			{
				iContainer->SetCurrentGroupName( );
				iEngine->SetCurrentGroupIndex(iContainer->ListBox()->CurrentItemIndex());//通知groupUser要打开的是第几个组
				AppUi()->HandleCommandL(EESIMCmdActiveGroupUserView);
				break;
			}
		case EESIMCmdActiveConversationView:
			{
				CAknViewAppUi* aAknViewAppUi = AppUi();
				CESIMAppUi* aESIMAppUi = reinterpret_cast<CESIMAppUi*>(aAknViewAppUi);

				aESIMAppUi->iStatus = KGroupViewId;

				AppUi()->HandleCommandL(EESIMCmdActiveConversationView);
			}
		case EESIMGroupCmdSendMessage:
			{
				CESIMGroupItem* pGroups = 
					iEngine->GroupItem(iContainer->ListBox()->CurrentItemIndex());
				RPointerArray<CESIMUserItem>& users = pGroups->ItemList();
				if (users.Count() == 0)
				{
					CEikonEnv::Static()->InfoWinL(_L("Warning"),
						_L("No user in this group, please add some"));
					break;
				}



				TInt KMaxMessageLength = 60;
				TInt KMaxMessageSizeDesc16 = KMaxMessageLength * 2;
				HBufC* iMessage;
				iMessage = HBufC::NewL(KMaxMessageLength);
				TPtr message = iMessage->Des();

				HBufC* titleBuf = StringLoader::LoadLC(R_CHAT_TITLE);
				CAknTextQueryDialog* messageDialog = new (ELeave) CAknTextQueryDialog(message, 
					*titleBuf, CAknTextQueryDialog::ENoTone);
				CleanupStack::PopAndDestroy(titleBuf);
				messageDialog->SetMaxLength(KMaxMessageLength);

				// 组织消息体
				if (messageDialog->ExecuteLD(R_ESIM_CHAT_MESSAGE_DIALOG))
				{
					CAknViewAppUi* aAknViewAppUi = AppUi();
					CESIMAppUi* aESIMAppUi = reinterpret_cast<CESIMAppUi*>(aAknViewAppUi);

					HBufC8* from;
					from = HBufC8::NewL(100);
					from->Des().Format(_L8("sip:%s"), aESIMAppUi->iLocalAddress.Ptr());

					HBufC8* to;
					to = HBufC8::NewL(100);
					to->Des().Format(_L8("sip:msgas@%s"), aESIMAppUi->iRemoteAddress.Ptr());

					TBuf8<100> msg;
					msg.Copy(message);
					//CnvUtfConverter::ConvertFromUnicodeToUtf8(msg, message);

					// 取组里的成员的地址

					// 手动构造XML
					char* buf = new char[1000];
					memset(buf, '\0', 1000);
					size_t strLength;
					strcat(buf, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\" xmlns:cp=\"urn:ietf:params:xml:ns:capacity\" xmlns:xsi=\"ttp://www.w3.org/2001/XMLSchema-instance\">\n<list>\n");


						for(TInt i = 0;  i < users.Count(); i++)
						{
							(users[i]->SipAddress())->Des();
							TBuf8<50> tmp;
							TBuf8<100> to;
							CnvUtfConverter::ConvertFromUnicodeToUtf8(tmp, users[i]->SipAddress()->Des());
							to.Format(_L8("sip:%s"), tmp.PtrZ());
							strcat(buf, "<entry uri=\"");
							strcat(buf, (char*)(to.PtrZ()));
							strcat(buf, "\" cp:capacity=\"to\"/>\n");
						}

						strcat(buf, "</list>\n</resource-lists>\r\n");

						//aESIMAppUi->SIPEngine()->sip_group_message((char*)msg.PtrZ(), 
						//	(char*)to->Des().PtrZ(), 
      //                      (char*)from->Des().PtrZ(), buf);

						delete buf;

						delete to;
						to = NULL;

						delete from;
						from = NULL;

				}

				delete iMessage;
				iMessage = NULL;

				break;
			}
		default:
			AppUi()->HandleCommandL(aCommand);
			break;		
		}
    }

// ---------------------------------------------------------
// CESIMGroupView::HandleClientRectChange()
// ---------------------------------------------------------
//
void CESIMGroupView::HandleClientRectChange()
    {
    if ( iContainer )
        {
        iContainer->SetRect( ClientRect() );
        }
    }

// ---------------------------------------------------------
// CESIMGroupView::DoActivateL(...)
// 
// ---------------------------------------------------------
//
void CESIMGroupView::DoActivateL(
   const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
   const TDesC8& /*aCustomMessage*/)
    {
    if (!iContainer)
        {
        iContainer = new (ELeave) CESIMGroupContainer(iEngine);
        iContainer->SetMopParent(this);
        iContainer->ConstructL( ClientRect(), this);
        AppUi()->AddToStackL( *this, iContainer );
        }
   }

// ---------------------------------------------------------
// CESIMGroupView::DoDeactivate()
// 
// ---------------------------------------------------------
//
void CESIMGroupView::DoDeactivate()
    {
    if ( iContainer )
        {
        AppUi()->RemoveFromViewStack( *this, iContainer );
        }
    
    delete iContainer;
    iContainer = NULL;
    }
//*****************

void CESIMGroupView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane){
	if(aResourceId == R_ESIM_GROUP_VIEW_MENU) 
	{
		aMenuPane->SetItemDimmed(EESIMGroupCmdDelete,DimBluethooth());
		aMenuPane->SetItemDimmed(EESIMGroupCmdEdit,DimBluethooth());
	}
}

TBool CESIMGroupView::DimBluethooth()
{
	if (iContainer->ListCount()==0)
	return  ETrue;
	else
	return  EFalse;
}

/**
* Creates vertical scrollbars for the list, which appear automatically when required.
*
*/
void CESIMGroupView::SetupScrollBarsL(CEikListBox& aListBox)
{
	aListBox.CreateScrollBarFrameL(ETrue);
	aListBox.ScrollBarFrame()->SetScrollBarVisibilityL(
		CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
}

void CESIMGroupView::AddUserToGroup()
{
	// First phase construction of menu list
	CAknSinglePopupMenuStyleListBox* savedGameMenuList =
		new (ELeave) CAknSinglePopupMenuStyleListBox;
	CleanupStack::PushL(savedGameMenuList);

	// Create a popuplist to show the menu list in
	CAknPopupList* popupList = CAknPopupList::NewL(
		savedGameMenuList, 
		R_AVKON_SOFTKEYS_OK_BACK);

	CleanupStack::PushL(popupList);

	// Second phase construction of menulist
	savedGameMenuList->ConstructL(popupList,EAknListBoxMenuList);
	// Set up scroll bars
	SetupScrollBarsL (*savedGameMenuList);

	// Set up menu items
	CTextListBoxModel* model = savedGameMenuList->Model();  // not taking ownership
	model->SetOwnershipType (ELbmOwnsItemArray);
	CDesCArray* savedGameMenuListArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());

	//CDesCArray *groups = iEngine->GetContactGroupsL();
	_LIT (KStringHeader, "%S");
	TBuf <16> aString;
	for (TInt i = 0; i< iEngine->UserItemCount(); i++)
	{
		TPtrC ptr = ((iEngine->UserItem(i))->Name())->Des();
		aString.Format(KStringHeader(), &ptr);
		savedGameMenuListArray->AppendL (aString);
	}

	// Set title
	HBufC* title;
	title = StringLoader::LoadLC(R_SAVED_GAME_MENU_LIST_TITLE);	// Pushes title onto the Cleanup Stack.
	popupList->SetTitleL(*title);
	CleanupStack::PopAndDestroy(title);

	// Show the menu in the popup list
	TInt popupOk = popupList->ExecuteLD();

	CleanupStack::Pop(popupList);

	// if the user selected a level to play, play the game at that level
	if (popupOk)
	{
		//TDesC level = (*savedGameMenuListArray)[savedGameMenuList->CurrentItemIndex()];
		TInt userIndex = savedGameMenuList->CurrentItemIndex();
		//TDesC level = (*savedGameMenuListArray)[index];


		/*iEngine->GetSelectedContactL(iContainer->ListBox());
		iEngine->GetSelectedContactGroupL(groupIndex);*/

		TInt t = iContainer->ListBox()->CurrentItemIndex();

		iEngine->AddUserToGroupL(userIndex, iContainer->ListBox()->CurrentItemIndex());

		CleanupStack::PopAndDestroy(savedGameMenuList);
		//PlayGame (aSavedGameName, level);
	}
	// otherwise return to the saved game list
	else
		CleanupStack::PopAndDestroy(savedGameMenuList);	
}
// End of File

⌨️ 快捷键说明

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