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

📄 taskmgrappview.cpp

📁 基于Symbian s60 2nd 下的任务管理器程序。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) 2003, Nokia. All rights reserved */

#include <e32def.h>
#include <coemain.h>
#include <apaid.h>
#include <apgcli.h>
#include <badesca.h>
#include <gdi.h>
#include <w32std.h>
#include <eikclbd.h>
#include <eikfrlb.h>
#include <aknquerydialog.h>
#include <aknnotewrappers.h>
#include <eikdll.h>
#include <taskmgr.rsg>
#include <hal.h>
#include <hal_data.h>
#include <pathinfo.h>
#include <aknmessagequerydialog.h>
#include <AknCommonDialogs.h>
#include <akntitle.h>

#include <plpvariant.h>
#include <plpvar.h>

#include "taskmgrAppView.h"

const TUid KUidtaskmgrApp = {0x10005B60};

TKeyResponse CtaskmgrAppView::OfferKeyEventL(
                                       const TKeyEvent& aKeyEvent,
                                       TEventCode aType )
{
    if ( aType != EEventKey ){
        return EKeyWasNotConsumed;
    }

    switch ( aKeyEvent.iCode ){
        // Up & Down arrow key's event transfer to list box
        case EKeyUpArrow:
        case EKeyDownArrow:
            if ( iListBox ){
                return iListBox->OfferKeyEventL( aKeyEvent, aType );
            }
            break;
        default:
            break;
     }
   return EKeyWasNotConsumed;
	
}



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

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

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

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

CtaskmgrAppView::CtaskmgrAppView()
{
	// No implementation required
}

CtaskmgrAppView::~CtaskmgrAppView()
{
   	delete iListBox;
   	if(iAppList){
    	iAppList->Reset();
   		delete iAppList;
   		iAppList = NULL;
   	}
   	if(iProcList){
   		iProcList->Reset();
    	delete iProcList;
    	iProcList = NULL;
    }
	// No implementation required
}

void CtaskmgrAppView::CreateListBoxL(const TRect&/* aRect*/)
{
	//Delete the list box if already exists.
	if ( iListBox ){
		delete iListBox;
		iListBox = NULL;
	}
	
	iListBox = new (ELeave ) CAknDoubleStyleListBox();
	iListBox->ConstructL(this, EAknListBoxSelectionList );
	iListBox->SetContainerWindowL(*this);

	//add scroll bar to the list
	iListBox->CreateScrollBarFrameL(ETrue);
	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn,
														CEikScrollBarFrame::EAuto);
	
	const TPoint aPoint(0,0);
	const TSize aSize(180,150);
	
	//most important line , else the lst box simply disappears
	iListBox->SetExtent(aPoint,aSize);
	//Fill list box with the data
	InitTaskList();
	
	iListBox->HandleItemAdditionL();
	iListBox->ActivateL();
	iListBox->DrawNow();
}

void CtaskmgrAppView::HandleListBoxEventL(CEikListBox* /*aListBox*/,TListBoxEvent /*aEventType*/ )
{

}



//This fucntion will get the present task list and 
//add it to the UI list
void CtaskmgrAppView::InitTaskList()
{
	CEikStatusPane* sp=iEikonEnv->AppUiFactory()->StatusPane();
	CAknTitlePane* tp=(CAknTitlePane*)sp->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
	tp->SetTextL(_L("Task List")); // Set the text string.

	if(iProcList){
		iProcList->Reset();
		delete iProcList;
		iProcList = NULL;
	}
	_LIT(KItemFormatString,"\t%S\t%S\t");
	RApaLsSession RSession;
	TInt AAppCount = 0;//get the number of applications
	
	RSession.Connect();	
	RSession.AppCount(AAppCount);
	iAppCount = AAppCount;
	
	iAppList = new (ELeave) CDesCArrayFlat(iAppCount);
	RSession.GetAllApps();
	
	iListBox->Reset();
	
	if(AAppCount > 0){
		CDesCArray *itemList  = new (ELeave) CDesCArrayFlat(AAppCount);
		TBuf<200> Item;
		TApaAppInfo AppInfo;
		TApaTaskList aList(CEikonEnv::Static()->WsSession());
		TInt ListCount = 0;
		
		for(TInt i=0;i<AAppCount;i++){
			RSession.GetNextApp(AppInfo);
			TApaTask ATask3 = aList.FindApp(AppInfo.iUid);
			if(ATask3.Exists())
			{
				if(AppInfo.iFullName.Find(_L("Phone.app"))!=KErrNotFound)
				{
					iPhoneIndex = ListCount;
				}
			
				Item.Format(KItemFormatString,&AppInfo.iCaption,&AppInfo.iFullName);
				itemList->AppendL(Item);
				UidArray[ListCount++] = AppInfo.iUid;
			}
		}
		
		//set items and ownership
		iListBox->Model()->SetItemTextArray(itemList);
		iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);	

	}
	else{
		iEikonEnv->InfoMsg(_L("No tasks!!"));
	}
	iListBox->SetCurrentItemIndex(0);
	iListBox->SetFocus(ETrue); 
	RSession.Close();
}

void CtaskmgrAppView::ConstructL(const TRect& aRect)
{
    CreateWindowL();
	CreateListBoxL(aRect);
    SetRect(aRect);
    ActivateL();
}

// Draw this application's view to the screen
void CtaskmgrAppView::Draw(const TRect& /*aRect*/) const
{
/*    // Get the standard graphics context 
    CWindowGc& gc = SystemGc();
    // Gets the control's extent
    TRect rect = Rect();
    // Clears the screen
    gc.Clear(rect);
*/
}

void CtaskmgrAppView::RefreshList()
{
	if(iAppState == ETaskListState){
		InitTaskList();
	}else if (iAppState == EProcessListState){
		InitProcessList();	
	}
	iListBox->HandleItemAdditionL();
	iListBox->ActivateL();
	iListBox->DrawNow();
}

void CtaskmgrAppView::KillApp()
{
	TInt ItemSelected;	
	
	ItemSelected = iListBox->CurrentItemIndex();
	
	TUid KillThisUid = UidArray[ItemSelected];
	TApaTaskList aList(CEikonEnv::Static()->WsSession());
	TApaTask ATask3 = aList.FindApp(KillThisUid);
	
	if(ATask3.Exists())
		ATask3.KillTask();

	RefreshList();
}

void CtaskmgrAppView::NewApp()
{
	CAknTextQueryDialog* dlg;
	TBuf<512> aText;
  	dlg = new(ELeave)CAknTextQueryDialog(aText, CAknQueryDialog::ENoTone);
  	dlg->SetMaxLength(512);
  	TBool answer( dlg->ExecuteLD( R_AKNEXQUERY_ONELINE_DATA_QUERY ) );
  	if(answer){
	  	//now check if thing is app or exe and then 
	  	//launch it accordingly
	  	_LIT(KExe,".exe");
	  	_LIT(KApp,".app");
	  	if(aText.Find(KExe)!=KErrNotFound){
	  		EikDll::StartExeL(aText);
	  	}
	  	else if(aText.Find(KApp)!=KErrNotFound){
		  	CApaCommandLine* commandLine = CApaCommandLine::NewLC();
    	    commandLine->SetLibraryNameL( aText );
        	commandLine->SetCommandL( EApaCommandRun );
	  		EikDll::StartAppL(*commandLine);
	  		CleanupStack::PopAndDestroy(); // commandLine
	  	}
  	}
}

void CtaskmgrAppView::TaskInfo()
{
	/*buf = "
	//ThreadId : %d\n 
	 WindowGroup Id : %d\n
	 Heap Size : %d kb\n
	 Stack Size : %d kb\n
	 Protected : %S\n
	 CPU usage : %d\n mcrsecs";
	 */
	if(iAppState == ETaskListState){
		TInt ItemSelected = iListBox->CurrentItemIndex();
	
		TUid SelectedAppUid = UidArray[ItemSelected];
		TApaTaskList aList(CEikonEnv::Static()->WsSession());
		TApaTask ATask3 = aList.FindApp(SelectedAppUid);
		TInt WinGrpId = ATask3.WgId();
		
		TThreadId AppThreadId = ATask3.ThreadId();
		//now get this thread related info
		RThread AppThread;
		AppThread.Open(AppThreadId);
		TInt HeapSize,StackSize;
		
		AppThread.GetRamSizes(HeapSize,StackSize);
		
		TTimeIntervalMicroSeconds CpuTime;
		AppThread.GetCpuTime(CpuTime);
		
		HBufC *aText = iEikonEnv->AllocReadResourceLC( R_TASK_INFO); 
		HBufC *aText1 = HBufC::NewLC(650);
		
		TBuf<10> IfProtected;
		IfProtected.Copy(AppThread.Protected()?_L("YES"):_L("NO"));
		aText1->Des().Format(aText->Des(),AppThreadId,
						     WinGrpId,
						     (HeapSize/1024),
						     (StackSize/1024),
						     &IfProtected,
						     CpuTime);
		
		ShowInfoDialog(R_TASK_TITLE,*aText1);
	
		CleanupStack::PopAndDestroy( aText1 ); 	
		CleanupStack::PopAndDestroy( aText ); 

⌨️ 快捷键说明

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