📄 sman.cpp
字号:
#include "SMan.h"
#include <SMan.rsg>
/*************************************************************
*
* Application object
*
**************************************************************/
CApaDocument* CSMan2Application::CreateDocumentL()
{
CSMan2Document* doc = new (ELeave) CSMan2Document(*this);
CleanupStack::PushL(doc);
doc->ConstructL();
CleanupStack::Pop();
return doc;
}
/*************************************************************
*
* Document object
*
**************************************************************/
CSMan2Document::CSMan2Document(CEikApplication& aApp)
: CEikDocument(aApp)
{
}
CSMan2Document::~CSMan2Document()
{
}
void CSMan2Document::ConstructL()
{
}
CEikAppUi* CSMan2Document::CreateAppUiL()
{
return new(ELeave) CSMan2AppUi;
}
/*************************************************************
*
* AppUi object
*
**************************************************************/
CSMan2AppUi::~CSMan2AppUi()
{
RemoveFromStack(iAppView);
delete iAppView->snapshotTasks;
delete iAppView->memStatus;
delete iAppView->cTaskListBox;
delete iAppView;
}
void CSMan2AppUi::HandleForegroundEventL(TBool aForeground)
{
if (aForeground)
{
// Update the screen
iAppView->refreshTaskList(TODO_REFRESH);
}
CEikAppUi::HandleForegroundEventL(aForeground);
}
void CSMan2AppUi::ConstructL()
{
BaseConstructL();
iAppView=new(ELeave) CSMan2AppView;
iAppView->ConstructL(ClientRect());
AddToStackL(iAppView);
}
void CSMan2AppUi::HandleCommandL(TInt aCommand)
{
if (aCommand == cmdEndTask)
{
if (iAppView->cTaskListBox->SelectionIndexes()->Count() > 0)
{
iAppView->refreshTaskList(TODO_TERMINATE);
}
else
iEikonEnv->InfoMsgWithAlignment(TGulAlignment(EHRightVCenter), R_TBUF_NOMARKEDTASKS);
}
else if (aCommand == cmdFlushOut)
{
flushTasks();
}
else if (aCommand == cmdSnapshot)
{
CEikDialog* snapshotDialog = new(ELeave) CEikDialog;
if (snapshotDialog->ExecuteLD(R_DIALOG_SNAPSHOTCONFIRM) == EEikBidYes)
{
updateSnapShot();
}
}
else if (aCommand == cmdHotkey)
{
CEikDialog* dialog = new(ELeave) CHotkeyDialog(&(iAppView->configData.iHotkeyDialogResult));
if (dialog->ExecuteLD(R_DIALOG_HOTKEY) == EEikBidOk)
{
iAppView->ToggleHotKey();
if (iAppView->saveConfig() != 0)
{
iEikonEnv->InfoMsgWithAlignment(TGulAlignment(EHRightVCenter), R_TBUF_ERRSAVECONFIG);
}
}
}
else if ((aCommand == cmdQuit) || (aCommand == EEikCmdExit))
{
Exit();
}
else if (aCommand == cmdCompressHeap)
{
User::CompressAllHeaps();
User::Heap().Compress();
iAppView->refreshTaskList(TODO_REFRESH);
}
else if (aCommand == cmdRefresh)
{
iAppView->refreshTaskList(TODO_REFRESH);
}
else if (aCommand == cmdAbout)
{
CEikDialog* aboutDialog = new(ELeave) CEikDialog;
aboutDialog->ExecuteLD(R_DIALOG_ABOUT);
}
else if (aCommand == cmdQFileMan)
{
if (iAppView->qFilemanUID.iUid != 0)
{
LaunchApp(iAppView->qFilemanUID);
}
}
else if (aCommand == cmdControlPanel)
{
LaunchApp(iAppView->cPanelUID);
}
else if (aCommand == cmdShortcuts)
{
CArrayFixFlat<TUid> *tempUid;
tempUid = new (ELeave) CArrayFixFlat<TUid>(NUM_SHORTCUTS);
for (int i = 0; i < NUM_SHORTCUTS; i++)
{
tempUid->AppendL(iAppView->configData.shortCutUid[i]);
}
CEikDialog* shortcutDialog = new (ELeave) CShortcutDialog(tempUid);
if (shortcutDialog->ExecuteLD(R_DIALOG_SHORTCUT) == EEikBidOk)
{
for (int i = 0; i < NUM_SHORTCUTS; i++)
{
iAppView->configData.shortCutUid[i] = tempUid->At(i);
}
if (iAppView->saveConfig() != 0)
{
iEikonEnv->InfoMsgWithAlignment(TGulAlignment(EHRightVCenter), R_TBUF_ERRSAVECONFIG);
}
}
delete tempUid;
} else
{
for (int i = 0; i < NUM_SHORTCUTS; i++)
{
if (aCommand == (cmdShort1 + i))
{
LaunchApp(iAppView->configData.shortCutUid[i]);
break;
}
}
}
}
void CSMan2AppUi::LaunchApp(TUid appUid)
{
// Given a uid, launch the app if it is not already running. If it is already
// running, bring it to the foreground. The method used here is not fullproof. You
// are at the mercy of the .app file as to how it handles the "C:\" parameter (in
// the document name). For example, Audio does it ok but Viewer will show an error.
// On the other hand, passing an empty string causes Audio to crash. I have not found
// a better way yet. JNI docs shows a EXE - Z:\System\Programs\AppRun.exe. I couldn't
// find a way to make it work. Using EikDll:StartExeL just bombs with "Not found" or
// "Bad name" error - not sure if the error is from AppRun.exe or from Symbian.
// AppRun.exe is an EXE and not an APP (DLL). So by right, I can't
// use StartApp or StartDocument to launch the exe. Tried using StartApp though and
// it worked but I had the same problem as described above. Also tried using
// StartDocument by passing the name of the APP file as the doc name and hoping
// the OS will figure out a program to open it - didn't work. How does qfileman do
// it??
RApaLsSession mySession;
bool runOK = false;
TApaAppInfo aInfo;
// Don't launch if another copy is already running. This isn't necessary
// because using StartApp, the OS auto-focuses any existing instance of the app
TApaTaskList taskList(CEikonEnv::Static()->WsSession());
TApaTask theTask = taskList.FindApp(appUid);
if (theTask.Exists())
{
theTask.BringToForeground();
runOK = true;
}
else
{
if (FindApp(appUid, &aInfo) == 0)
{
CApaCommandLine *cmdLine = CApaCommandLine::NewLC();
cmdLine->SetLibraryNameL(aInfo.iFullName);
// What should I set for this???
//cmdLine->SetDocumentNameL(_L(""));
cmdLine->SetCommandL(EApaCommandRun);
if (mySession.Connect() == KErrNone)
{
if (mySession.StartApp(*cmdLine) == KErrNone)
runOK = true;
mySession.Close();
}
CleanupStack::PopAndDestroy();
}
}
if (!runOK)
{
iEikonEnv->InfoMsgWithAlignment(TGulAlignment(EHRightVCenter), R_TBUF_ERRLAUNCHAPP);
}
}
void CSMan2AppUi::AppToForeground(void)
{
RWsSession& oWindowSession = iEikonEnv->WsSession();
RWindowGroup& oWindowGroup = iEikonEnv->RootWin();
int windowID = oWindowGroup.Identifier();
TApaTask oTApaTask(oWindowSession);
oTApaTask.SetWgId(windowID);
oTApaTask.BringToForeground();
}
void CSMan2AppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination)
{
if ((aEvent.Type() == EEventKey) && (aEvent.Key()->iCode == sCaptureKeyCodes[iAppView->configData.iHotkeyDialogResult]))
{
if (CEikonEnv::Static()->ScreenDevice()->CurrentScreenMode() != 0)
{
TBuf<64> buffer;
CEikonEnv::Static()->ReadResource(buffer, R_TBUF_FLIPCLOSEDERR);
User::InfoPrint(buffer);
}
else
AppToForeground();
} else if ((aEvent.Type() == EEventScreenDeviceChanged) &&
(CEikonEnv::Static()->ScreenDevice()->CurrentScreenMode() == 0) && // 0 = flip open
(iAppView->configData.iHotkeyDialogResult == 3))
{
AppToForeground();
}
CEikAppUi::HandleWsEventL(aEvent, aDestination);
}
void CSMan2AppUi::flushTasks(void)
{
if (iAppView->snapshotTasks->Count() <= 0)
{
iEikonEnv->InfoMsgWithAlignment(TGulAlignment(EHRightVCenter), R_TBUF_NOSNAPSHOT);
}
else
{
iAppView->refreshTaskList(TODO_FLUSH);
iEikonEnv->InfoMsgWithAlignment(TGulAlignment(EHRightVCenter), R_TBUF_TASKSFLUSHED);
}
}
void CSMan2AppUi::updateSnapShot(void)
{
iAppView->snapshotTasks->Reset();
iAppView->refreshTaskList(TODO_SNAPSHOT);
if (iAppView->saveSnapShot() == 0)
{
iEikonEnv->InfoMsgWithAlignment(TGulAlignment(EHRightVCenter), R_TBUF_SNAPSHOTUPDATED);
}
else
{
iEikonEnv->InfoMsgWithAlignment(TGulAlignment(EHRightVCenter), R_TBUF_ERRSAVESNAPSHOT);
}
}
TInt CSMan2AppUi::FindApp(TUid appUid, TApaAppInfo *aInfo)
{
// Given an app UID, find if it is installed and get its app info
RApaLsSession mySession;
TApaAppInfo theAppInfo;
TApaAppCapabilityBuf aCapabilityBuf;
TInt errRes, iTimeout = 50;
TTimeIntervalMicroSeconds32 iDelay = 100;
// For some strange reason when I have just issued a command to write to the
// disk (via saving snapshot or saving shortcuts), the app server always returns
// an invalid application list (corrupted). I have to wait a while before the query
// runs correct again....?????
CEikonEnv::Static()->BusyMsgL(_L("Validating..."), TGulAlignment(EHRightVTop));
mySession.Connect();
mySession.GetAllApps();
errRes = 2;
while ((errRes != 0) & (iTimeout > 0))
{
while (mySession.GetNextApp(theAppInfo) == KErrNone)
{
errRes = 1;
if (mySession.GetAppCapability(aCapabilityBuf, theAppInfo.iUid) == KErrNone)
{
// Only scan applications that are not hidden
if (aCapabilityBuf().iAppIsHidden == EFalse)
{
if (theAppInfo.iUid == appUid)
{
aInfo->iUid = theAppInfo.iUid;
aInfo->iFullName = theAppInfo.iFullName;
aInfo->iCaption = theAppInfo.iCaption;
errRes = 0;
break;
}
}
}
}
User::After(iDelay);
iTimeout--;
}
mySession.Close();
CEikonEnv::Static()->BusyMsgCancel();
return errRes;
}
void CSMan2AppUi::DynInitMenuPaneL(TInt aMenuId, CEikMenuPane* aMenuPane)
{
if (aMenuId == R_SHORTCUTS_MENU)
{
TApaAppInfo aInfo;
if (FindApp(iAppView->qFilemanUID, &aInfo) == 0)
{
// We don't need to do a similar check for control panel - u can't uninstall
// control panel!!
aMenuPane->SetItemDimmed(cmdQFileMan, EFalse);
// This is faster than NUM_SHORTCUTS calls to FindApp() as long as NUM_SHORTCUTS is less
// than the number of apps u have installed. However, this is bulkier in code.
RApaLsSession mySession;
TApaAppInfo theAppInfo;
TApaAppCapabilityBuf aCapabilityBuf;
mySession.Connect();
mySession.GetAllApps();
while (mySession.GetNextApp(theAppInfo) == KErrNone)
{
if (mySession.GetAppCapability(aCapabilityBuf, theAppInfo.iUid) == KErrNone)
{
// Only scan applications that are not hidden
if (aCapabilityBuf().iAppIsHidden == EFalse)
{
for (int i = 0; i < NUM_SHORTCUTS; i++)
{
if (theAppInfo.iUid == iAppView->configData.shortCutUid[i])
{
aMenuPane->SetItemDimmed(cmdShort1 + i,EFalse);
aMenuPane->SetItemTextL(cmdShort1 + i, theAppInfo.iCaption);
}
}
}
}
}
mySession.Close();
}
/*
// This is the slower but more compact way of doing it
for (int i = 0; i < NUM_SHORTCUTS; i++)
{
if (FindAppFast(iAppView->configData.shortCutUid[i], &appName))
{
aMenuPane->SetItemDimmed(cmdShort1 + i,EFalse);
aMenuPane->SetItemTextL(cmdShort1 + i, appName);
}
}
*/
}
}
/*************************************************************
*
* AppView object
*
**************************************************************/
void CSMan2AppView::ToggleHotKey()
{
if (iCapturedHotkeyHandle != 0)
CEikonEnv::Static()->RootWin().CancelCaptureKey(iCapturedHotkeyHandle);
iCapturedHotkeyHandle = 0;
if ((configData.iHotkeyDialogResult != 0) && (configData.iHotkeyDialogResult != 3)) // 3 = flip open
{
iCapturedHotkeyHandle = CEikonEnv::Static()->RootWin().CaptureKey(sCaptureKeyCodes[configData.iHotkeyDialogResult],0,0,2);
}
}
int CSMan2AppView::loadSnapShot(void)
{
RFile inStream;
int retVal;
retVal = 1;
snapshotTasks->Reset();
if (inStream.Open(iEikonEnv->Static()->FsSession(), snapshotFileName, EFileRead) == KErrNone)
{
TInt fileSize;
inStream.Size(fileSize);
if (fileSize > 1)
{
TFileText snapshotFile;
TBuf<128> buffer;
snapshotFile.Set(inStream);
while (snapshotFile.Read(buffer) == KErrNone)
{
snapshotTasks->AppendL(buffer);
}
retVal = 0;
}
inStream.Close();
}
return retVal;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -