?? esimgroupview.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 + -