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

📄 testmtmsappview.cpp

📁 本例是SYMBIAN C++一个创建短信的例子
💻 CPP
字号:
/*
 ============================================================================
 Name		: TestMtmsAppView.cpp
 Author	  : Tomken
 Copyright   : (C) 2008-2009
 Description : Application view implementation
 ============================================================================
 */

// INCLUDE FILES
#include <coemain.h>
#include "TestMtmsAppView.h"
#include "TestMtms.hrh"

#include <avkon.mbg>
#include <akniconutils.h> 
#include <aknlists.h> 
#include <GULICON.H>
#include <akniconarray.h> 
#include <aknnotewrappers.h> 
#include <npdapi.h>
#include <utf.h>

#include "CallStack.h"

CTestMtmsAppView* CTestMtmsAppView::NewL(const TRect& aRect)
{
	CTestMtmsAppView* self = CTestMtmsAppView::NewLC(aRect);
	CleanupStack::Pop(self);
	return self;
}

CTestMtmsAppView* CTestMtmsAppView::NewLC(const TRect& aRect)
{
	CTestMtmsAppView* self = new ( ELeave ) CTestMtmsAppView;
	CleanupStack::PushL(self);
	self->ConstructL(aRect);
	return self;
}

void CTestMtmsAppView::ConstructL(const TRect& aRect)
{
	// Create a window for this application view
	CreateWindowL();
	
	CreateDoubleListL();
	iMtmsEngine = CNqMtmsEngine::NewL(*this);

	// Set the windows size
	SetRect(aRect);
	
	
	// Activate the window, which makes it ready to be drawn
	ActivateL();

}

CTestMtmsAppView::CTestMtmsAppView()
{
}

CTestMtmsAppView::~CTestMtmsAppView()
{
	delete iDoubleGraphicListBox;
	
	if(iMsvArray)
	{
		iMsvArray->Reset();
		delete iMsvArray;
		iMsvArray = NULL;
	}
	
	delete iMtmsEngine;
}

void CTestMtmsAppView::Draw(const TRect& /*aRect*/) const
{
	// Get the standard graphics context
	CWindowGc& gc = SystemGc();
	
	// Gets the control's extent
	TRect drawRect(Rect());
	
	// Clears the screen
	gc.Clear(drawRect);
	

}

void CTestMtmsAppView::SizeChanged()
{
	TRect rect = Rect();
	iDoubleGraphicListBox->SetRect(rect);
}

void CTestMtmsAppView::CreateDoubleListL()
{
	iDoubleGraphicListBox = new (ELeave) CAknDoubleStyleListBox;
	iDoubleGraphicListBox->ConstructL(this, 0);
	iDoubleGraphicListBox->SetContainerWindowL(*this);
	iDoubleGraphicListBox->SetListBoxObserver(this);
	
	iDoubleGraphicListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);

    iDoubleGraphicListBox->ActivateL();
    iDoubleGraphicListBox->CreateScrollBarFrameL(EFalse);
    iDoubleGraphicListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);

	// CArrayPtr<CGulIcon>* icons = CreateListIcons();
//	CArrayPtr<CGulIcon>* icons = CreateListIcons_Dm();

//	iDoubleGraphicListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
//	CleanupStack::Pop(icons);

	iDoubleGraphicListBox->MakeVisible(ETrue);
}

CArrayPtr<CGulIcon>* CTestMtmsAppView::CreateListIcons_Dm()
{
	CArrayPtr<CGulIcon>* icons = new ( ELeave ) CAknIconArray( 1 );
	CleanupStack::PushL( icons );
	CFbsBitmap* icon = NULL;
	CFbsBitmap* icon_m = NULL;
	
//	CSmsMasterAppUi::CreateIconL(KSvgIconsPath, icon, icon_m, EMbmCm2svgiconsIconselected, EMbmCm2svgiconsIconselected_mask);
//	KResizeIcon(13,13);
	icons->AppendL( CGulIcon::NewL(icon, icon_m) );
	
	// 拒接来电
//	CSmsMasterAppUi::CreateIconL(KSvgIconsPath, icon, icon_m, EMbmCm2svgiconsIconsdenycall,EMbmCm2svgiconsIconsdenycall_mask);
//	KResizeIcon(13,13);
	icons->AppendL( CGulIcon::NewL(icon, icon_m) );
	
	return icons;
}

void CTestMtmsAppView::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
{
	if(aEventType == MEikListBoxObserver::EEventEnterKeyPressed)
	{
	}
}

TInt CTestMtmsAppView::CountComponentControls() const
{
	return 1;
}

CCoeControl* CTestMtmsAppView::ComponentControl(TInt aIndex) const
{
	switch ( aIndex )
	{
		case 0:
			return iDoubleGraphicListBox;
		default:
			return NULL;
	}
}

TKeyResponse CTestMtmsAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
	TKeyResponse res = EKeyWasNotConsumed;
	res = iDoubleGraphicListBox->OfferKeyEventL(aKeyEvent, aType);
	return res;
}

void CTestMtmsAppView::HandleMtmsEngineInitialized()
{
	// InitInboxList();
}

void CTestMtmsAppView::HandleMtmsEngineSessionEventL(MMsvSessionObserver::TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3)
{

}

void CTestMtmsAppView::HandleMtmsEngineError(TInt aError)
{
}

void CTestMtmsAppView::InitInboxList()
{
	CALLSTACKITEM_N(_L8("CTestMtmsAppView"), _L8("InitInboxList"));
	
	_LIT(KListItemFormat, "\t%S\t%S\t");
	CTextListBoxModel* model = iDoubleGraphicListBox->Model ();
	CDesCArray* textArray = static_cast <CDesCArray*>( model->ItemTextArray() );
	textArray->Reset();
	
	if(iMsvArray)
	{
		iMsvArray->Reset();
		delete iMsvArray;
		iMsvArray = NULL;
	}
	iMtmsEngine->GetFolderMessageInfo(KNqFolderInbox, iMsvArray);
	TBuf<128> info;

	TInt count = iMsvArray->Count();
	for(TInt x=0; x<count; x++)
	{
		if(x == 138)
		{
			TInt d = 0;
		}
		TMsvId id = (*iMsvArray)[x];
		TBuf<16> name;
		iMtmsEngine->GetMessageAddressAliasL(id, name);
		if(name.Length() == 0)
		{
			iMtmsEngine->GetMessageFromAddressL(id, name);
		}
		
		
		TBuf<32> desc;
		iMtmsEngine->GetMessageIndexBodyTextL(id, desc);
		
		info.Format(KListItemFormat, &name, &desc);
		textArray->AppendL(info);
	}
	
	iDoubleGraphicListBox->HandleItemAdditionL();
	iDoubleGraphicListBox->SetCurrentItemIndex( 0 );
}


void CTestMtmsAppView::InitOutboxList()
{
	CALLSTACKITEM_N(_L8("CTestMtmsAppView"), _L8("InitInboxList"));
	
	_LIT(KListItemFormat, "\t%S\t%S\t");
	CTextListBoxModel* model = iDoubleGraphicListBox->Model ();
	CDesCArray* textArray = static_cast <CDesCArray*>( model->ItemTextArray() );
	textArray->Reset();
	
	if(iMsvArray)
	{
		iMsvArray->Reset();
		delete iMsvArray;
		iMsvArray = NULL;
	}
	iMtmsEngine->GetFolderMessageInfo(KNqFolderUnsend, iMsvArray);
	TBuf<128> info;

	TInt count = iMsvArray->Count();
	for(TInt x=0; x<count; x++)
	{
		if(x == 138)
		{
			TInt d = 0;
		}
		TMsvId id = (*iMsvArray)[x];
		TBuf<16> name;
		iMtmsEngine->GetMessageAddressAliasL(id, name);
		if(name.Length() == 0)
		{
			iMtmsEngine->GetMessageFromAddressL(id, name);
		}
		
		
		TBuf<32> desc;
		iMtmsEngine->GetMessageIndexBodyTextL(id, desc);
		
		info.Format(KListItemFormat, &name, &desc);
		textArray->AppendL(info);
	}
	
	iDoubleGraphicListBox->HandleItemAdditionL();
	iDoubleGraphicListBox->SetCurrentItemIndex( 0 );
}

void CTestMtmsAppView::HandleCommandL(TInt aCommand)
{
	if(aCommand == ECmdInitInbox)
	{
		InitInboxList();
	}
	else if(aCommand == ECmdInitOutbox)
	{
		InitOutboxList();
	}
	else if(aCommand == ECmdUnreadIt)
	{
		TInt idx = iDoubleGraphicListBox->CurrentItemIndex();
		if(idx >= 0 && idx <iMsvArray->Count())
		{
			TMsvId id = (*iMsvArray)[idx];
			iMtmsEngine->SetUnread(id, ETrue);
		}
	}
	else if(aCommand == ECmdSimulateSendSms)
	{
		TInt idx = iDoubleGraphicListBox->CurrentItemIndex();
		if(idx >= 0 && idx <iMsvArray->Count())
		{
			TMsvId id = (*iMsvArray)[idx];
			iMtmsEngine->ResendSmsL(id);
		}
	}
	else if(aCommand == ECmdSendState)
	{
		_LIT8(KUtf8Header, "\xef\xbb\xbf");
		RFs fs;
		fs.Connect();
		CleanupClosePushL(fs);
		
		RFile file;
		TInt err = file.Open(fs, _L("c:\\sms.txt"), EFileRead);
	
		if(err == KErrNone)
		{
			CleanupClosePushL(file);
			TInt size = 0;
			file.Size(size);
			
			HBufC8* data8 = HBufC8::NewLC(size);
			TPtr8 ptr8 = data8->Des();
			file.Read(ptr8);
			
			if(ptr8.Left(3).Compare(KUtf8Header) == 0)
				ptr8.Delete(0, 3);
			
			HBufC* data = HBufC::NewLC(size);
			TPtr ptr = data->Des();
			
			CnvUtfConverter::ConvertToUnicodeFromUtf8(ptr, ptr8);
			
			TPtrC ccPtr = data->Des();
			TInt brIdx = ccPtr.Locate('\n');
			while(brIdx != KErrNotFound)
			{
				TPtrC linePtr = ccPtr.Left(brIdx);
				
				TInt spIdx = linePtr.Locate('#');
				if(spIdx != KErrNotFound)
					iMtmsEngine->CreateSMSMessageL(KMsvGlobalInBoxIndexEntryId, linePtr.Left(spIdx), linePtr.Left(spIdx), linePtr.Mid(spIdx+1));
				else
					iMtmsEngine->CreateSMSMessageL(KMsvGlobalInBoxIndexEntryId, _L("10661088748"), _L("10661088748"), linePtr);
					
				ccPtr.Set(ccPtr.Mid(brIdx+1));
				
				brIdx =  ccPtr.Locate('\n');
			}
			
			
			CleanupStack::PopAndDestroy(); // data 
			CleanupStack::PopAndDestroy(); // data8 
			CleanupStack::PopAndDestroy(); // Close file 
		}
		
		CleanupStack::PopAndDestroy(); // Close fs 
	}
	else if(aCommand == ECmdNotepadTest)
	{
		TestNotepad();
	}
	else if(aCommand == ECmdCreateToInbox)
	{
		TInt rt;
		// HBufC* text = CNotepadApi::ExecTextEditorL(rt, _L(""), _L("Total"));
		//if(KErrNone == rt)
		{
			iMtmsEngine->CreateSMSMessageL(KMsvGlobalInBoxIndexEntryId, _L("15010972062"), _L("15010972062"), _L("xxx"));
		//	delete text;
		}
	}
	else if(aCommand == ECmdCreateToSend)
	{
		TInt rt;
		HBufC* text = CNotepadApi::ExecTextEditorL(rt);
		if(KErrNone == rt)
		{
			iMtmsEngine->CreateSMSMessageL(KMsvSentEntryId, _L("Abcde"), _L("13871239999"), *text);
			delete text;
		}
	}
}

void CTestMtmsAppView::TestNotepad()
{
	
	HBufC* buf = CNotepadApi::FetchTemplateL();
	
	buf = CNotepadApi::FetchMemoL();
	
#if 0
	CNotepadModel* module = CNotepadModel::NewL(iCoeEnv->FsSession(), 0x46272004);
	module->OpenL();
	TInt count = module->MdcaCount();
	for(TInt i =0; i<count; i++)
	{
		const TPtrC16 ptr = module->MdcaPoint(i);
	}
	
	module->Close();
	delete module;
#endif

//	CNotepadApi* npd = CNotepadApi::NewL();
	
#if 0
	CNotepadModel* module = npd->Model();
	TInt count = module->MdcaCount();
	for(TInt i =0; i<count; i++)
	{
		const TPtrC16 ptr = module->MdcaPoint(i);
	}
#endif
//	delete npd;
}

// End of File

⌨️ 快捷键说明

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