📄 sman.cpp
字号:
int CSMan2AppView::saveSnapShot(void)
{
RFile outStream;
int retVal;
retVal = 1;
if (outStream.Replace(iEikonEnv->Static()->FsSession(), snapshotFileName, EFileRead) == KErrNone)
{
TFileText snapshotFile;
snapshotFile.Set(outStream);
for (int i = 0; i < snapshotTasks->Count(); i++)
{
snapshotFile.Write(snapshotTasks->At(i));
}
retVal = 0;
outStream.Close();
}
return retVal;
}
int CSMan2AppView::loadConfig(void)
{
RFile inStream;
TInt retVal;
retVal = 1;
if (inStream.Open(iEikonEnv->Static()->FsSession(), configFileName, EFileRead) == KErrNone)
{
TInt fileSize;
inStream.Size(fileSize);
if (fileSize >= (TInt)sizeof(verData))
{
CVerInfo verData;
// Check config version. If correct, load it else ignore it
TPckg<CVerInfo> pkgVerData(verData);
inStream.Read(pkgVerData);
if ((verData.majorVersion == VER_MAJOR) && (verData.minorVersion == VER_MINOR))
{
TPckg<CConfig> pkgConfigData(configData);
inStream.Read(pkgConfigData);
retVal = 0;
}
}
inStream.Close();
}
return retVal;
}
int CSMan2AppView::saveConfig(void)
{
RFile outStream;
TInt retVal;
retVal = 1;
if (outStream.Replace(iEikonEnv->Static()->FsSession(), configFileName, EFileRead) == KErrNone)
{
verData.majorVersion = VER_MAJOR;
verData.minorVersion = VER_MINOR;
TPckg<CVerInfo> pkgVerData(verData);
outStream.Write(pkgVerData);
TPckg<CConfig> pkgConfigData(configData);
outStream.Write(pkgConfigData);
retVal = 0;
outStream.Close();
}
return retVal;
}
TKeyResponse CSMan2AppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
if (aType == EEventKey)
{
if (aKeyEvent.iCode == EQuartzKeyConfirm)
{
refreshTaskList(TODO_FOCUS);
return EKeyWasConsumed;
} else if (aKeyEvent.iCode == EQuartzKeyTwoWayDown)
{
cTaskListBox->View()->MoveCursorL(CListBoxView::ECursorNextItem, CListBoxView::ENoSelection);
cTaskListBox->UpdateScrollBarsL();
return EKeyWasConsumed;
} else if (aKeyEvent.iCode == EQuartzKeyTwoWayUp)
{
cTaskListBox->View()->MoveCursorL(CListBoxView::ECursorPreviousItem, CListBoxView::ENoSelection);
cTaskListBox->UpdateScrollBarsL();
return EKeyWasConsumed;
}
}
return cTaskListBox->OfferKeyEventL(aKeyEvent, aType);
}
int CSMan2AppView::CountComponentControls() const
{
return 2;
}
CCoeControl* CSMan2AppView::ComponentControl(int aIndex) const
{
if (aIndex == 0)
{
return cTaskListBox;
}
else if (aIndex == 1)
{
return memStatus;
}
else
return NULL;
}
void CSMan2AppView::ConstructL(const TRect& aRect)
{
TPoint p;
TSize sz;
CreateWindowL();
SetRect(aRect);
snapshotTasks = new (ELeave) CArrayFixFlat<TApaAppCaption>(3);
snapshotFileName.Copy(CEikonEnv::Static()->EikAppUi()->Application()->AppFullName());
snapshotFileName.SetLength(snapshotFileName.Length() - 3);
configFileName.Copy(snapshotFileName);
snapshotFileName.Append(_L("snp"));
configFileName.Append(_L("cfg"));
if (loadSnapShot() == 1)
{
iEikonEnv->InfoMsgWithAlignment(TGulAlignment(EHRightVCenter), R_TBUF_NOPREVSNAPSHOT);
}
else iEikonEnv->InfoMsgWithAlignment(TGulAlignment(EHRightVCenter), R_TBUF_SNAPSHOTLOADED);
// Initialize listbox
cTaskListBox = new(ELeave) CEikColumnListBox;
cTaskListBox->ConstructL(this, CEikColumnListBox::EMultipleSelection);
CColumnListBoxData* listBoxColumns = ((CColumnListBoxItemDrawer*)cTaskListBox->ItemDrawer())->ColumnData();
listBoxColumns->SetColumnWidthPixelL(0, int(Size().iWidth * 0.55));
listBoxColumns->SetColumnWidthPixelL(1, int(Size().iWidth * 0.30));
listBoxColumns->SetColumnAlignmentL(0, CGraphicsContext::ELeft);
listBoxColumns->SetColumnAlignmentL(1, CGraphicsContext::ERight);
cTaskListBox->CreateScrollBarFrameL();
cTaskListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto);
p.iX = 0;
p.iY = 0;
sz.iWidth = 208;
sz.iHeight = 240; // max 255
cTaskListBox->SetExtent(p, sz);
// Initialize label
memStatus = new(ELeave) CEikLabel;
memStatusText.Format(_L(" SMan - Free RAM: 0KB"));
memStatus->SetTextL(memStatusText);
memStatus->SetContainerWindowL(*this);
p.iY = 241;
sz.iHeight = 14;
memStatus->SetExtent(p, sz);
memStatus->ActivateL();
// Initialize shortcut arrays. This array gets reset by loadConfig() if there is
// a valid config file to load. So it must be initialised prior to loadConfig()
for (int i = 0; i < NUM_SHORTCUTS; i++)
{
configData.shortCutUid[i] = KNullUid;
}
// Load config and initialize vars based on config
loadConfig();
ToggleHotKey();
qFilemanUID.iUid = QFILEMAN_UID;
cPanelUID.iUid = CONTROLPANEL_UID;
refreshTaskList(TODO_REFRESH);
ActivateL();
}
void CSMan2AppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
if (aPointerEvent.iType == TPointerEvent::EButton1Down)
{
TPoint penXY = aPointerEvent.iPosition;
int yMod = (int)(((penXY.iY - 6) / cTaskListBox->ItemHeight()) + cTaskListBox->View()->TopItemIndex());
if (yMod < 0)
yMod = 0;
if ((yMod <= cTaskListBox->View()->BottomItemIndex()) && (yMod < 236))
{
if (penXY.iX > 21)
{
cTaskListBox->ClearSelection();
cTaskListBox->SetCurrentItemIndex(yMod);
refreshTaskList(TODO_FOCUS);
}
else
{
cTaskListBox->View()->VerticalMoveToItemL(yMod, CListBoxView::EDisjointSelection);
cTaskListBox->UpdateScrollBarsL();
}
}
}
}
void CSMan2AppView::refreshTaskList(int intTodo)
{
RWsSession oWindowSession;
RApaLsSession oApaSession;
CApaWindowGroupName* oWindowGroupName;
int j,i, dump;
bool taskRemoved;
CArrayFixFlat<TInt>* windowGroupList;
CArrayFixFlat<TApaAppCaption>* markedArray;
TPtrC currentCaptionText, temp;
TApaAppCaption selectedItemText, tempText;
TThreadId ntid;
TKeyArrayFix keyArray = TKeyArrayFix(0, ECmpNormal);
RThread oThread;
iArray = ((CDesCArray *) cTaskListBox->Model()->ItemTextArray());
// Build the marked array
markedArray = new CArrayFixFlat<TApaAppCaption>(3);
for (i = 0; i < cTaskListBox->SelectionIndexes()->Count(); i++)
{
temp.Set(cTaskListBox->Model()->ItemText(cTaskListBox->SelectionIndexes()->At(i)));
TextUtils::ColumnText(currentCaptionText, 0, &temp);
markedArray->AppendL(currentCaptionText);
}
i = cTaskListBox->CurrentItemIndex();
cTaskListBox->SetCurrentItemIndexAndDraw(0);
cTaskListBox->ClearSelection();
if ((i >= 0) && (i <= iArray->Count()))
{
temp.Set(cTaskListBox->Model()->ItemText(i));
TextUtils::ColumnText(currentCaptionText, 0, &temp);
selectedItemText.Copy(currentCaptionText);
}
else
{
// U3 spell :)
selectedItemText = _L("zxkuqyb");
}
iArray->Reset();
oWindowSession.Connect();
oApaSession.Connect();
oWindowGroupName = CApaWindowGroupName::NewL(oWindowSession);
windowGroupList = new CArrayFixFlat<TInt>(5);
oWindowSession.WindowGroupList(windowGroupList);
for (j = 0; j < windowGroupList->Count(); j++)
{
oWindowGroupName->ConstructFromWgIdL(windowGroupList->At(j));
// Do not show captionless, system or hidden threads
if ((oWindowGroupName->Caption().Length() == 0) || (oWindowGroupName->IsSystem()) || (oWindowGroupName->Hidden()))
continue;
// Do not show threads that don't have an app icon
CApaMaskedBitmap *b = CApaMaskedBitmap::NewLC();
if (oApaSession.GetAppIcon(oWindowGroupName->AppUid(),TSize(128,128),*b) != KErrNone)
{
CleanupStack::PopAndDestroy();
continue;
}
CleanupStack::PopAndDestroy(); // CApaMaskedBitmap
oWindowSession.GetWindowGroupClientThreadId(windowGroupList->At(j), ntid);
oThread.Open(ntid);
// Do not show protected threads
if (oThread.Protected())
continue;
currentCaptionText.Set(oWindowGroupName->Caption());
taskRemoved = FALSE;
if (intTodo == TODO_FOCUS)
{
if (currentCaptionText.Compare(selectedItemText) == 0)
{
User::InfoPrint(currentCaptionText);
oWindowSession.SetWindowGroupOrdinalPosition(windowGroupList->At(j), 0);
intTodo = TODO_NOTHING;
}
}
else if (intTodo == TODO_TERMINATE)
{
// In the unlikely event u launch an app more than once, this routine will
// kill all instances with the same name even though you only check marked
// one item to kill. The solution is to remove it from markedarray once it
// is killed. Use the Delete method
if (markedArray->Find(currentCaptionText, keyArray, dump) == 0)
{
markedArray->Delete(dump);
oThread.Kill(0);
oThread.Close();
taskRemoved = TRUE;
}
}
else if (intTodo == TODO_SNAPSHOT)
{
snapshotTasks->AppendL(oWindowGroupName->Caption());
}
else if (intTodo == TODO_FLUSH)
{
// Search for the task in the snapshot. If the task wasn't found, kill it
if (snapshotTasks->Find(currentCaptionText,keyArray,dump) != 0)
{
// Kill the task
//oThread.Open(ntid);
oThread.Kill(0);
oThread.Close();
taskRemoved = TRUE;
}
}
if (!taskRemoved)
{
// Weird problem here. I couldn't call GetMemoryInfo for an RProcess. Kept
// getting KErrNotSupported errors. Calling the deprecated GetRamSizes gives
// me a panic. Only GetRamSizes for an RThread works. So I have to walk
// through all the threads and see which process id it belongs to and add
// up the RAM utilization based on the pid that I want. What is SE doing....
RProcess targetProcess, currentProcess;
TFullName procName;
RThread currentThread;
TInt iRamSize;
TBuf<10> procSizeInText;
oThread.Open(ntid);
oThread.Process(targetProcess);
iRamSize = 0;
TFindThread findThread;
while(findThread.Next(procName) == KErrNone)
{
currentThread.Open(findThread);
currentThread.Process(currentProcess);
if (currentProcess.Id() == targetProcess.Id())
{
TInt a, b;
currentThread.GetRamSizes(a, b);
iRamSize = iRamSize + a + b;
}
currentProcess.Close();
currentThread.Close();
}
oThread.Close();
iRamSize = iRamSize / 1024;
tempText = oWindowGroupName->Caption();
tempText.Append(KColumnListSeparator);
procSizeInText.Num(iRamSize);
tempText.Append(procSizeInText);
tempText.Append(_L("k"));
iArray->AppendL(tempText);
}
oThread.Close();
}
delete oWindowGroupName;
delete windowGroupList;
oWindowSession.Close();
oApaSession.Close();
// Remark the remaining tasks that are still alive as the selected list was reset
if (intTodo != TODO_TERMINATE)
{
CArrayFixFlat<TInt>* markedIndexArray = new CArrayFixFlat<TInt>(5);
for (j = 0; j < markedArray->Count(); j++)
{
if (iArray->Find(markedArray->At(j), dump, ECmpNormal) == 0)
{
markedIndexArray->AppendL(dump);
}
}
cTaskListBox->SetSelectionIndexesL(markedIndexArray);
delete markedIndexArray;
}
delete markedArray;
cTaskListBox->HandleItemAdditionL();
// Update amount of free memory in system
int freeRAM;
HAL::Get(HALData::EMemoryRAMFree, freeRAM);
memStatusText.Format(_L(" SMan - Free RAM: %dKB"), freeRAM / 1024);
memStatus->MakeVisible(EFalse);
memStatus->SetTextL(memStatusText);
memStatus->MakeVisible(ETrue);
if (i > (((CDesCArray *) cTaskListBox->Model()->ItemTextArray())->Count() - 1))
{
i = ((CDesCArray *) cTaskListBox->Model()->ItemTextArray())->Count() - 1;
} else if (i < 0)
{
i = 0;
}
if ((i < 12) && (cTaskListBox->TopItemIndex() > 0))
{
cTaskListBox->View()->VScrollTo(0);
}
cTaskListBox->SetCurrentItemIndexAndDraw(i);
cTaskListBox->UpdateScrollBarsL();
cTaskListBox->SetFocus(ETrue, EDrawNow);
}
void CSMan2AppView::HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType)
{
HandleControlEventL(aControl, aEventType);
}
CSMan2AppView::~CSMan2AppView()
{
}
void CSMan2AppView::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear(aRect);
}
/*************************************************************
*
* External interface
*
**************************************************************/
TUid CSMan2Application::AppDllUid() const
{
return KUidSMan2App;
}
GLDEF_C TInt E32Dll(TDllReason)
{
return KErrNone;
}
EXPORT_C CApaApplication* NewApplication()
{
return new CSMan2Application;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -