📄 tasklistview.cpp
字号:
}
else
markedArrayText = NULL;
// Get the currently highlighted item. Used for focusing to a task
if (intTodo == TODO_FOCUS)
{
temp.Set(cTaskListBox->Model()->ItemText(currentItemIndex));
TextUtils::ColumnText(currentTaskCaption, 1, &temp);
highlightedTask.Copy(currentTaskCaption);
}
// Cycle through the list of tasks and rebuild the elements in the listbox
itemArray->Reset();
cTaskListBox->HandleItemRemovalL();
windowGroupList = new CArrayFixFlat<TInt>(5);
iEikonEnv->WsSession().WindowGroupList(windowGroupList);
oWindowGroupName = CApaWindowGroupName::NewL(iEikonEnv->WsSession());
oApaLsSession.Connect();
for (int posIndex = 0; posIndex < windowGroupList->Count(); posIndex++)
{
// Check whether this is a task we should display
oWindowGroupName->ConstructFromWgIdL(windowGroupList->At(posIndex));
// If we are doing a snapshot the behaviour is:
// - if hidden tasks is turned off, assume all hidden tasks are checked by default
// - if hidden tasks is turned on, explicitly follow what the user checked
// else just follow the hidden task flag as normal
tempCaption.Copy(oWindowGroupName->Caption());
if ((tempCaption.Length() == 0) && (!oWindowGroupName->IsSystem()))
{
TThreadId iThread;
TFullName aResult;
RThread theThread;
if (iEikonEnv->WsSession().GetWindowGroupClientThreadId(windowGroupList->At(posIndex), iThread) == KErrNone)
{
TFindThread findThread;
while (findThread.Next(aResult) == KErrNone)
{
theThread.Open(findThread);
if (iThread == theThread.Id())
{
RProcess ownerProcess;
theThread.Process(ownerProcess);
if (ownerProcess.LoadedFromRam())
{
// Keep copying until you find a '[' or you reach the end of the string
TInt x = aResult.Find(_L("["));
if (x != KErrNotFound)
tempCaption.Copy(aResult.Left(x));
else
tempCaption.Copy(aResult);
}
ownerProcess.Close();
theThread.Close();
break;
}
theThread.Close();
}
}
}
if ((!configData->showHiddenTasks) && (intTodo != TODO_SNAPSHOT))
{
//if ((oWindowGroupName->Caption().Length() == 0) || (oWindowGroupName->IsSystem()) || (oWindowGroupName->Hidden()))
if ((tempCaption.Length() == 0) || (oWindowGroupName->IsSystem()) || (oWindowGroupName->Hidden()))
continue;
}
else
{
//if (oWindowGroupName->Caption().Length() == 0)
if (tempCaption.Length() == 0)
continue;
}
if (iEikonEnv->WsSession().GetWindowGroupClientThreadId(windowGroupList->At(posIndex), threadId) != KErrNone)
continue;
currentTaskThread.Open(threadId);
if (currentTaskThread.Protected())
{
currentTaskThread.Close();
continue;
}
currentTaskThread.Close();
// Now we can do what we were called for
taskRemoved = EFalse;
currentTaskCaption.Set(tempCaption);
CApaMaskedBitmap *tempBitmap = CApaMaskedBitmap::NewLC();
if (oApaLsSession.GetAppIcon(oWindowGroupName->AppUid(),TSize(20,16),*tempBitmap) == KErrNone)
{
CApaMaskedBitmap *appBitmap = CApaMaskedBitmap::NewL(tempBitmap);
iconArray->AppendL(CGulIcon::NewL(appBitmap, NULL));
}
else
{
TFileName bitmapFile;
bitmapFile.Copy(appPathNoExt);
bitmapFile.Append(_L("MBM"));
CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
User::LeaveIfError(bitmap->Load(bitmapFile, EMbmMyHeaderBlankappicon));
iconArray->AppendL(CGulIcon::NewL(bitmap, NULL)); // empty bitmap
}
CleanupStack::PopAndDestroy(); // tempBitmap
if (intTodo == TODO_FOCUS)
{
if (currentTaskCaption.Compare(highlightedTask) == 0)
{
User::InfoPrint(currentTaskCaption);
//static_cast<CSMan2AppUi*>(CEikonEnv::Static()->EikAppUi())->SetAppPosition(EFalse);
// Due to some strange java problem, this line of code creates an issue with SMan (and i think any
// other app). When i set the ordinal position of the java window to 0, SMan still thinks it has focus.
// Normally this isn't a problem but because of the way SMan reacts to the hotkey, it is. Sending SMan
// to the background doesn't always work since the java window may already be in the foreground.
// The solution lies in maintaining a TBool flag (appInForeground) that is modified in the HandleForegroundEventL()
// member. This flag is checked in the hotkey handler and the appropriate action is then taken.
// ----------------------------------------------
// This problem was first discovered with Malcolm Bryant's jCompile utility.
iEikonEnv->WsSession().SetWindowGroupOrdinalPosition(windowGroupList->At(posIndex), 0);
intTodo = TODO_NOTHING;
}
}
else if ((intTodo == TODO_TERMINATE) && (oWindowGroupName->AppUid() != KUidSMan2App) && (currentTaskCaption.Compare(_L("EiksrvBackdrop")) != 0))
{
TKeyArrayFix keyArray = TKeyArrayFix(0, ECmpNormal);
int foundIndex;
if (markedArrayText->Find(currentTaskCaption, keyArray, foundIndex) == 0)
{
if (!configData->forceEndTask)
gentleEndTask(currentTaskCaption);
else
{
currentTaskThread.Open(threadId);
RProcess ownerProcess;
currentTaskThread.Process(ownerProcess);
currentTaskThread.Close();
ownerProcess.Kill(0);
ownerProcess.Close();
taskRemoved = ETrue;
markedArrayText->Delete(foundIndex);
}
}
}
else if (intTodo == TODO_SNAPSHOT)
{
snapshotTasks->AppendL(currentTaskCaption);
if (!configData->showHiddenTasks)
{
if (oWindowGroupName->IsSystem() || oWindowGroupName->Hidden())
taskRemoved = ETrue;
}
}
else if ((intTodo == TODO_FLUSH) && (oWindowGroupName->AppUid() != KUidSMan2App))
{
TKeyArrayFix keyArray = TKeyArrayFix(0, ECmpNormal);
int foundIndex;
// Search for the task in the snapshot. If the task wasn't found, kill it
if (snapshotTasks->Find(currentTaskCaption, keyArray, foundIndex) != 0)
{
if (!configData->forceEndTask)
gentleEndTask(currentTaskCaption);
else
{
currentTaskThread.Open(threadId);
RProcess ownerProcess;
currentTaskThread.Process(ownerProcess);
currentTaskThread.Close();
ownerProcess.Kill(0);
ownerProcess.Close();
taskRemoved = ETrue;
}
}
}
// Done! Now, if the task was still alive we calculate the amount of RAM it
// is consuming.
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.
RProcess targetProcess, currentProcess;
TFullName procName;
RThread currentThread;
TInt iRamSize = 0;
TBuf<10> procSizeInText;
TBuf<10> iconIndex;
TApaAppCaption tempText;
currentTaskThread.Open(threadId);
currentTaskThread.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();
}
targetProcess.Close();
currentTaskThread.Close();
iRamSize = iRamSize / 1024;
iconIndex.Num(iconArray->Count() - 1);
tempText.Copy(iconIndex);
tempText.Append(KColumnListSeparator);
tempText.Append(currentTaskCaption);
tempText.Append(KColumnListSeparator);
procSizeInText.Num(iRamSize);
tempText.Append(procSizeInText);
tempText.Append(_L("k"));
itemArray->AppendL(tempText);
}
}
oApaLsSession.Close();
delete windowGroupList;
delete oWindowGroupName;
if (markedArrayText != NULL)
delete markedArrayText;
// 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);
// Do some sorting...
itemArray = ((CDesCArray *) cTaskListBox->Model()->ItemTextArray());
// Move the highlight back to the item that it was originally at but only if this is
// a sane value
// Grab this pointer again because I'm not sure if HandleItemAdditionL() may have
// moved the address of the array
if (currentItemIndex > (itemArray->MdcaCount() - 1))
currentItemIndex = itemArray->MdcaCount() - 1;
// This may be -1 if there were no items in the list box (i.e. we just started up this
// program)
if (currentItemIndex < 0)
currentItemIndex = 0;
cTaskListBox->SetCurrentItemIndex(currentItemIndex);
cTaskListBox->HandleItemAdditionL();
cTaskListBox->UpdateScrollBarsL();
cTaskListBox->SetFocus(ETrue, ENoDrawNow);
cTaskListBox->DrawDeferred();
if (configData->forceEndTask == EFalse)
{
if ((intTodo == TODO_TERMINATE) || (intTodo == TODO_FLUSH))
{
if (taskRefresher->IsActive())
taskRefresher->Cancel();
taskRefresher->startRefresh(REFRESH_DELAY_IF_NOT_FORCE_ENDTASK);
}
else if (intTodo == TODO_REFRESH)
{
if (taskRefresher->IsActive())
taskRefresher->Cancel();
}
}
}
void CSMan2TaskListView::gentleEndTask(TPtrC currentCaptionText)
{
TApaTaskList taskList(iEikonEnv->WsSession());
TApaTask oneTask = taskList.FindApp(currentCaptionText);
if (oneTask.Exists())
oneTask.EndTask();
}
void CSMan2TaskListView::HandleControlEventL(CCoeControl* aControl, TCoeEvent /*aEventType*/)
{
if (Index(aControl) == 1)
iEikonEnv->EikAppUi()->HandleCommandL(cmdFlushOut);
else if (Index(aControl) == 2)
iEikonEnv->EikAppUi()->HandleCommandL(cmdEndTask);
else if (Index(aControl) == 3)
iEikonEnv->EikAppUi()->HandleCommandL(cmdRefresh);
else if (Index(aControl) == 4)
iEikonEnv->EikAppUi()->HandleCommandL(cmdSnapshot);
else if (Index(aControl) == 5)
iEikonEnv->EikAppUi()->HandleCommandL(cmdCompressHeap);
}
/*
void CSMan2TaskListView::Draw(const TRect& aRect) const
{
TFileName mbmName;
mbmName.Copy(appPathNoExt);
mbmName.Append(_L("MBM"));
CWindowGc& gc = SystemGc();
CFbsBitmap* iAppBitmap = new (ELeave) CFbsBitmap();
//User::LeaveIfError(iAppBitmap->Load(mbmName, EMbmMyheaderFlushout));
TInt err = iAppBitmap->Load(mbmName, EMbmMyheaderFlushout);
gc.UseBrushPattern(iAppBitmap);
gc.SetBrushStyle(CGraphicsContext::EPatternedBrush);
gc.DrawRect(aRect);
delete iAppBitmap;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -