symbian4appui.cpp

来自「S60 3版 音乐播放器及进度条实现 功能:前后倒放歌曲及暂停等功能」· C++ 代码 · 共 231 行

CPP
231
字号
/*
============================================================================
Name        : CSymbian4AppUi from Symbian3Appui.cpp
Author      : 
Version     :
Copyright   : Your copyright notice
Description : CSymbian4AppUi implementation
============================================================================
*/

// INCLUDE FILES
#include  <aknviewappui.h>
#include "Symbian4Appui.h"
#include "Symbian4View.h"
#include "Symbian4View2.h"
#include <Symbian4.rsg>
#include "Symbian4.hrh"

#include <avkon.hrh>
#include <flogger.h> //日志文件
// ================= MEMBER FUNCTIONS =======================
//
// ----------------------------------------------------------
// CSymbian4AppUi::ConstructL()
// 
// ----------------------------------------------------------
//
CSymbian4AppUi::CSymbian4AppUi()
{
	iCurrent = 0;
	iPlayListArray=NULL;
	iDecoratedTabGroup=NULL;
}
void CSymbian4AppUi::ConstructL()
{
	BaseConstructL(EAknEnableSkin);

  //  iLog.Connect(); 

	// Show tabs for main views from resources
	CEikStatusPane* sp = StatusPane();

	// Fetch pointer to the default navi pane control
	iNaviPane = (CAknNavigationControlContainer*)sp->ControlL( 
		TUid::Uid(EEikStatusPaneUidNavi));

	// Tabgroup has been read from resource and it were pushed to the navi pane. 
	// Get pointer to the navigation decorator with the ResourceDecorator() function. 
	// Application owns the decorator and it has responsibility to delete the object.
	iDecoratedTabGroup = iNaviPane->ResourceDecorator();
	if (iDecoratedTabGroup)
	{
		iTabGroup = (CAknTabGroup*) iDecoratedTabGroup->DecoratedControl();
		iTabGroup->SetObserver( this );
	}

	iPlayListArray = new (ELeave) CDesCArrayFlat(10);

	CSymbian4View* view1 = new (ELeave) CSymbian4View;

	CleanupStack::PushL( view1 );
	view1->ConstructL();
	AddViewL( view1 );      // transfer ownership to CAknViewAppUi
	CleanupStack::Pop();    // view1

	CSymbian4View2* view2 = new (ELeave) CSymbian4View2;

	CleanupStack::PushL( view2 );
	view2->ConstructL();
	AddViewL( view2 );      // transfer ownership to CAknViewAppUi
	CleanupStack::Pop();    // view2


	GetPlayList(); 

	SetDefaultViewL(*view2);


}

// ----------------------------------------------------
// CSymbian4AppUi::~CSymbian4AppUi()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
CSymbian4AppUi::~CSymbian4AppUi()
{
	delete iDecoratedTabGroup;
	delete iPlayListArray;
	iPlayListArray=NULL;

//	iLog.CloseLog(); 
//	iLog.Close();
}

// ------------------------------------------------------------------------------
// CSymbian4AppUi::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
//  This function is called by the EIKON framework just before it displays
//  a menu pane. Its default implementation is empty, and by overriding it,
//  the application can set the state of menu items dynamically according
//  to the state of application data.
// ------------------------------------------------------------------------------
//
void CSymbian4AppUi::DynInitMenuPaneL(
									  TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/)
{
}

// ----------------------------------------------------
// CSymbian4AppUi::HandleKeyEventL(
//     const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
// takes care of key event handling
// ----------------------------------------------------
//
TKeyResponse CSymbian4AppUi::HandleKeyEventL(
	const TKeyEvent& aKeyEvent,TEventCode aType)
{
	if ( iTabGroup == NULL )
	{
		return EKeyWasNotConsumed;
	}

//	if ( aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow )
//	{
//		return iTabGroup->OfferKeyEventL( aKeyEvent, aType );
//	}
	else
	{
		return EKeyWasNotConsumed;
	}
}

// ----------------------------------------------------
// CSymbian4AppUi::HandleCommandL(TInt aCommand)
// takes care of command handling
// ----------------------------------------------------
//
void CSymbian4AppUi::HandleCommandL(TInt aCommand)
{
	switch ( aCommand )
	{
	case EEikCmdExit:
		{
			Exit();
			break;
		}
	case ESymbian4CmdAppTest:
		{
			iEikonEnv->InfoMsg(_L("test"));
			break;
		}
		// TODO: Add Your command handling code here
	default:
		break;      
	}
}

// ----------------------------------------------------
// CSymbian4AppUi::TabChangedL(TInt aIndex)
// This method gets called when CAknTabGroup active 
// tab has changed.
// ----------------------------------------------------
//
void CSymbian4AppUi::TabChangedL(TInt aIndex)
{
	ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(aIndex)));
}

void CSymbian4AppUi::GetPlayList()
{
	_LIT(iFileDir,"C:\\Data\\Sounds\\");
	TBuf<64> sBuf;
	TInt index = 0;
	CDirScan* ds = CDirScan::NewLC(iCoeEnv->FsSession()); 
	TRAPD(err,ds->SetScanDataL(iFileDir,KEntryAttNormal,ESortByName|EAscending,CDirScan::EScanDownTree));
	if (err != KErrNone)
	{
		CleanupStack::PopAndDestroy(ds);
		return;
	}

	CDir* c = NULL;
	TFileName fullname;
	while (1)
	{
		ds->NextL(c);
		if (!c)
			break;
		for (TInt i = 0; i < c->Count(); i++)
		{

			const TEntry e = (*c)[i];
			fullname.Copy(ds->FullPath());
			fullname.Append(e.iName);
			TParsePtrC p(fullname); 
			if( (!p.Ext().Compare(_L(".mp3")))||!p.Ext().Compare(_L(".aac"))) 
			{
				sBuf.Zero(); 
				sBuf.AppendNum(++index);

				sBuf.Append(_L("\t"));
				sBuf.Append(p.NameAndExt());
				iPlayListArray->AppendL(sBuf);
			}
		}
		delete c;
		c = NULL;
	}
	CleanupStack::PopAndDestroy(ds);
}

TInt CSymbian4AppUi::GetCurrent()
{
	return iCurrent;
}

CDesCArrayFlat*  CSymbian4AppUi::GetPlayListPoint()
{
	return iPlayListArray;
}

void CSymbian4AppUi::SetCurrent(TInt aCurrent)
{
	if (aCurrent > iPlayListArray->Count()-1 )
		aCurrent = iPlayListArray->Count()-1;
	if (aCurrent < 0)
		aCurrent = 0;
	iCurrent = aCurrent;
}

⌨️ 快捷键说明

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