chxavmisc.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:24k
- /*****************************************************************************
- * chxavmisc.cpp
- * -------------
- *
- * Synopsis:
- * Misc helpers for s60 player only
- *
- *
- *
- * Target:
- * Symbian OS
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- *****************************************************************************/
- // Symbian includes...
- #include <coeutils.h>
- #include <aknenv.h>
- #include <limits.h>
- #include <apgwgnam.h>
- #include <apsettingshandlerui.h>
- #include <akntabgrp.h>
- #include <akniconarray.h>
- #include <aputils.h>
- #include <apgcli.h>
- #include <commdb.h>
- #include <avkon.rsg>
- // Helix includes...
- #include "hxassert.h"
- #include "hxstring.h"
- // Includes from this project...
- #include "chxavutil.h"
- #include "chxavmisc.h"
- #include "chxavfileutil.h"
- #include "chxavinfolist.h"
- #include "chxavmessagedialog.h"
- #include "chxavcleanstring.h"
- #include "chxavcleanupstack.h"
- #include "chxavnamedisplaytrait.h"
- #include "chxavurllist.h"
- #include "realplayer.rsg"
- #include "realplayer.hrh"
- #include "comptr.h"
- #include "ihxpckts.h"
- #include "chxavplayer.h"
- #include "hxdebug_hxapi.h"
- #include "hxsym_leaveutil.h"
- #include "hxapihelp.h"
- namespace
- {
- ////////////////////////////////////////
- // icon indexes:
- //
- // local media (.rm, .ra, etc.)
- // remote media (url)
- // list (.ram)
- // broken local file
- //
- enum ClipTypeIconIndex
- {
- IconLocal,
- IconRemote,
- IconList,
- IconLocalBroken
- };
- ClipTypeIconIndex GetIconIndex(const TDesC& path, bool bPathIsLocal)
- {
- ClipTypeIconIndex idxIcon = ClipTypeIconIndex(-1);
- if( bPathIsLocal )
- {
- CHXAvFile::FileType type = CHXAvFile::GetFileType(path);
- if (CHXAvFile::ftRam == type)
- {
- idxIcon = IconList;
- }
- else
- {
- // for now, use local icon for everything else
- idxIcon = IconLocal;
- }
- if (!ConeUtils::FileExists(path))
- {
- // file no longer exists
- idxIcon = IconLocalBroken;
- }
- }
- else
- {
- idxIcon = IconRemote;
- }
- return idxIcon;
- }
- } // end locals
- namespace CHXAvMisc
- {
- ////////////////////////////////////////////////////////////
- // allocate descriptive filesize text, e.g., "4.9 kbytes"
- HBufC* AllocFileSizeDescL(TUint cbFile)
- {
- HBufC* pbuff = 0;
- if( cbFile < CHXAvUtil::k_bytesPerKilobyte )
- {
- CHXAvCleanString text(R_FILEVIEW_BYTES_FORMAT, TInt(cbFile));
- pbuff = text().AllocL();
- }
- else
- {
- HX_ASSERT((cbFile / k_bytesPerKilobyte) <= INT_MAX); // next cast
- CHXAvCleanString text(R_FILEVIEW_KB_FORMAT, TInt(cbFile / k_bytesPerKilobyte));
- pbuff = text().AllocL();
- }
- return pbuff;
- }
- //
- // graphic list item text format is:
- //
- // [{icon index}]t{main text}[t{subtext}][t{idxIconD}]
- //
- HBufC* AllocGrListItemL(const TDesC& mainText, const TDesC& subText, TInt idxIcon)
- {
- HX_ASSERT(mainText.Length() > 0);
- const TUint cchExtraSpace = 10; // enough for t and icon indexes
- TUint cchItemText = cchExtraSpace + mainText.Length() + subText.Length();
-
- HBufC* pBuf = HBufC::NewL(cchItemText);
- AUTO_PUSH_POP(pBuf); // out
- TPtr ptr = pBuf->Des();
- // -1 means "no icon"
- if( idxIcon != -1 )
- {
- ptr.AppendNum(idxIcon);
- }
- // main text
- ptr.Append(KListColumnDelimiter);
- HBufC* pFixedMainText = CHXAvMisc::AllocDisplayFriendlyStringL(mainText);
- AUTO_PUSH_POP_DEL(pFixedMainText);
- ptr.Append(*pFixedMainText);
- // sub text
- if( subText.Length() > 0 )
- {
- ptr.Append(KListColumnDelimiter);
- HBufC* pFixedSubText = CHXAvMisc::AllocDisplayFriendlyStringL(subText);
- AUTO_PUSH_POP_DEL(pFixedSubText);
- ptr.Append(*pFixedSubText);
- }
-
- return pBuf;
- }
- ////////////////////////////////////////
- //
- // graphic list item text must be:
- //
- // [icon index]tmain text[t subtext][tidxIconD][tidxIconD]
- //
- HBufC* AllocGrListItemL(ListType type,
- TInt idxIcon,
- const TDesC& mainText,
- const TDesC& subText)
- {
- _LIT(KSingle, "%dt%S");
- _LIT(KSingleNoIcon, "%dt%S");
- _LIT(KDouble, "%dt%St%S");
- _LIT(KDoubleNoIcon, "t%St%S");
- HX_ASSERT(mainText.Length() > 0);
- const TUint cchIndexSpace = 20;
- TUint cchItemText = cchIndexSpace + mainText.Length() + subText.Length();
-
- HBufC* pBuf = HBufC::NewL(cchItemText);
- TPtr ptr = pBuf->Des();
- switch (type)
- {
- case Double:
- ptr.Format(KDouble, idxIcon, &mainText, &subText);
- break;
- case DoubleNoIcon:
- ptr.Format(KDoubleNoIcon, &mainText, &subText);
- break;
- case Single:
- ptr.Format(KSingle, idxIcon, &mainText);
- break;
- case SingleNoIcon:
- ptr.Format(KSingleNoIcon, &mainText);
- break;
- default:
- HX_ASSERT(false);
- break;
- }
- return pBuf;
- }
- ////////////////////////////////////////////
- // show the access point settings page
- //
- // wapApId = id of item that should be selected by
- // default (i.e., the currently set access point)
- //
- TInt RunAccessPointSettingPageL(TInt wapApId)
- {
- const bool bStartWithSel = true; // if false (edit only), other params ignored
- const TSelectionListType listType = EApSettingsSelListIsPopUp;
- const TSelectionMenuType menuType = EApSettingsSelMenuSelectNormal;
- const TInt ispFilter = KEApIspTypeInternetOnly | KEApIspTypeInternetAndWAP;
- const TInt bearerType = EApBearerTypeAll;
- const TInt sortType = KEApSortNameAscending;
- // access point settings ui handler; displays setting page ui
- CApSettingsHandler* pSettings
- = CApSettingsHandler::NewLC(bStartWithSel, listType, menuType,
- ispFilter, bearerType, sortType);
- AUTO_POP_DEL(pSettings);
- TUint32 idSelected = 0;
- pSettings->RunSettingsL(wapApId, idSelected);
- return idSelected;
- }
- ///////////////////////////////////////
- // extract text chunk from delimited text (e.g., "thellotthere")
- TPtrC
- TextChunk(const TDesC& text, TInt idxChunk, TChar chDelimit)
- {
- TPtrC titleOut(KNullDesC);
- TPtrC temp = text;
- TInt idxDelimit = 0;
- // skip to chunk
- while(idxChunk--)
- {
- // skip past tab delimiter
- idxDelimit = temp.Locate(chDelimit);
- if( KErrNotFound == idxDelimit )
- {
- break;
- }
- temp.Set(temp.Mid(idxDelimit + 1));
- }
- if( idxDelimit != KErrNotFound )
- {
- idxDelimit = 0;
- TInt idxDelimit = temp.Locate(chDelimit);
- if( idxDelimit == KErrNotFound )
- {
- // ok, no ending tab
- idxDelimit = temp.Length();
- }
- // collect to next delimiter or end
- titleOut.Set(temp.Left(idxDelimit));
- }
-
- return titleOut;
- }
- ////////////////////////////////////
- //
- TInt LaunchAppL(RFs& fsSession, const TDesC& appPath, const TDesC& doc)
- {
- // get absolute path to the app
- TFileName fullPathApp;
- TInt err = CHXAvFile::GetFullPath(fsSession, appPath, fullPathApp);
- if( KErrNone == err )
- {
- // set up the command line
- CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
- cmdLine->SetLibraryNameL(fullPathApp);
- cmdLine->SetDocumentNameL(doc);
- cmdLine->SetCommandL(EApaCommandOpen);
- // run the command line
- RApaLsSession ls;
- HXSYM_LEAVE_IF_ERR(ls.Connect());
- CleanupClosePushL(ls);
- HXSYM_LEAVE_IF_ERR(ls.StartApp(*cmdLine));
- CleanupStack::PopAndDestroy(2); // ls and cmdLine
-
- }
- return err;
- }
- ////////////////////////////////////////////////
- // iterate all app instances with the given uid
- // and either end or kill
- //
- // note: this will not find embedded instances!
- //
- void ForEachAppInstanceL(TUid uid, ForEachAppInstanceCommand command)
- {
- RWsSession& ws = CEikonEnv::Static()->WsSession();
-
- TInt wgId = 0;
- CApaWindowGroupName::FindByAppUid(uid, ws, wgId);
- while( wgId != KErrNotFound )
- {
- DPRINTF(SYMP_INFO, ("ForEachAppInstanceL(): found task wgid = %ld", wgId));
- TApaTask task(ws);
- task.SetWgId(wgId);
- // end this task if it is not our own (identified by thread id)
- if( task.ThreadId() != RThread().Id() )
- {
- if( command == KillApp )
- {
- DPRINTF(SYMP_INFO, ("ForEachAppInstanceL(): killing task (wgid = %ld)", wgId));
- task.KillTask();
- }
- else
- {
- DPRINTF(SYMP_INFO, ("ForEachAppInstanceL(): ending task (wgid = %ld)", wgId));
- task.EndTask();
- }
- }
- CApaWindowGroupName::FindByAppUid(uid, ws, wgId);
- }
- }
- ////////////////////////////////////////////////
- //
- void LaunchAppL(TInt uid, const TDesC& arg)
- {
-
- TUid uidApp = TUid::Uid(uid);
- TApaTaskList taskList(CEikonEnv::Static()->WsSession());
- TApaTask task = taskList.FindApp(uidApp);
- if (task.Exists())
- {
- // convert to 8-bit message (note that copy, append convert)
- HBufC8* pBuf = HBufC8::NewL(arg.Length());
- AUTO_PUSH_POP_DEL(pBuf);
- TPtr8 ptr = pBuf->Des();
- ptr.Copy(arg);
- // send message to the task; uid is not used
- task.SendMessage(TUid::Uid( 0 ), *pBuf);
-
- //HXSYM_LEAVE_IF_ERR(task.SwitchOpenFile(aFileName));
- //task.BringToForeground();
- }
- else
- {
- // launch the webbrowser app
- RApaLsSession session;
- HXSYM_LEAVE_IF_ERR(session.Connect());
- TThreadId tidNewAppInstance = 0; // ignored
- session.StartDocument( arg, uidApp, tidNewAppInstance );
- session.Close();
- }
- }
- ////////////////////////////////////////////
- // form our app-specific message for BroadcastWsEventL()
- HBufC8* MakeHXPlayerPrivateMessageL(const TDesC8& name)
- {
- const TUint k_cbForRest = 50;
- HBufC8* pbuff = HBufC8::NewL(name.Length() + k_cbForRest);
-
- // name:tid
- _LIT8(KFormatText, "%S:0x%x");
- TThreadId tid = RThread().Id();
- TPtr8 des = pbuff->Des();
- des.AppendFormat(KFormatText, &name, tid);
- return pbuff;
- }
- //////////////////////////////////////////////////////
- // send TWsEvent to all window groups except ours
- void BroadcastWsEventL(TUint type, const HBufC8* pMsg)
- {
- TWsEvent event;
-
- event.SetType(type);
- HXSYM_LEAVE_IF_FALSE(pMsg->Length() <= TWsEvent::EWsEventDataSize);
- Mem::Copy(event.EventData(), pMsg->Ptr(), pMsg->Length());
- RWsSession& ws = CEikonEnv::Static()->WsSession();
- TInt wgidThisInstance = GetThisWgId();
- CArrayFixFlat<TInt>* pWindowList = new (ELeave) CArrayFixFlat<TInt>(4);
- AUTO_PUSH_POP_DEL(pWindowList);
- HXSYM_LEAVE_IF_ERR(ws.WindowGroupList(pWindowList));
- for (TInt idx = 0; idx < pWindowList->Count(); ++idx)
- {
- TInt wgid = (*pWindowList)[idx];
- if(wgid != wgidThisInstance)
- {
- ws.SendEventToWindowGroup(wgid, event);
- }
- }
- }
- TInt GetThisWgId()
- {
- RWindowGroup& win = CCoeEnv::Static()->RootWin();
- return win.Identifier();
- }
- TUid GetAppUidFromWgId(TInt wgid)
- {
- RWsSession& ws = CEikonEnv::Static()->WsSession();
- CApaWindowGroupName* pName = CApaWindowGroupName::NewL(ws);
- AUTO_PUSH_POP_DEL(pName);
- pName->ConstructFromWgIdL(wgid);
- return pName->AppUid();
- }
- ////////////////////////////////////////
- // create array of list items based on URL list
- //
- CDesCArrayFlat*
- AllocGrPopupListItemsL(CHXAvURLList *list, const CHXAvNameDisplayTrait* pDisplayTrait)
- {
- TInt itemCount = list->NumURLs();
- CDesCArrayFlat* pItems = new (ELeave) CDesCArrayFlat(itemCount);
- AUTO_PUSH_POP(pItems); // out
- for(TInt idx = 0; idx < itemCount; ++idx)
- {
- CHXAvURLInfo* pInfo = list->GetURL(idx);
- // use unescaped path-only portion of URL (e.g., realnetworksrootfoo.rm)
- HBufC* pPath = CHXAvUtil::AllocStdPathFromPlayerUrlL(pInfo->URL());
- AUTO_PUSH_POP_DEL(pPath);
- bool bIsLocal = CHXAvUtil::IsLocal(pInfo->URL());
- TInt idxIcon = GetIconIndex(*pPath, bIsLocal);
- TPtrC name(pInfo->Title());
- if( name.Length() == 0 )
- {
- // no tile; use url
- TPtrC urlName = CHXAvFile::GetNakedPathNode(*pPath);
- if(pDisplayTrait)
- {
- // fix up the display name (e.g., hide extension)
- NameExt info = pDisplayTrait->GetDisplayText(urlName);
- name.Set(info.first);
- }
- else
- {
- name.Set(urlName);
- }
- }
- if( name.Length() > 0 )
- {
- HBufC* pItemText = AllocGrListItemL(name, idxIcon);
- AUTO_PUSH_POP_DEL(pItemText);
- pItems->AppendL(*pItemText);
- }
- }
- return pItems;
- }
- //////////////////////////////////////////
- // sync the scrollbar associated with the list box
- //
- void UpdateScrollBar(CEikListBox* pListBox)
- {
- if(pListBox)
- {
- // this apparantly does not handle below
- pListBox->UpdateScrollBarsL();
- TInt pos = pListBox->CurrentItemIndex();
- if( pos < 0 ) // -1 = empty
- {
- pos = 0;
- }
-
- CEikScrollBarFrame* pFrame = pListBox->ScrollBarFrame();
- if( pFrame != 0 )
- {
- pFrame->MoveVertThumbTo(pos);
- }
- }
- }
- ////////////////////////////////////////////////////////
- // alloc string with special characters replaced by spaces; this
- // can be used in ui displays so that boxes are not seen in place
- // of these characters
- //
- void MakeDisplayFriendly(TDes& des, const TDesC& replaceChars)
- {
- // replace with spaces
- ReplaceCharacters(
- des,
- replaceChars, ' ');
- }
- ////////////////////////////////////////////////////////
- // see MakeDisplayFriendly()
- HBufC* AllocDisplayFriendlyStringL(const TDesC& text, const TDesC& replaceChars)
- {
- HBufC* pbuff = text.AllocL();
- AUTO_PUSH_POP(pbuff);
- TPtr ptr = pbuff->Des();
- MakeDisplayFriendly(ptr, replaceChars);
- return pbuff;
- }
- //////////////////////////
- // for each character in text, replace with chWith if character is in replaceChars
- //
- void ReplaceCharacters(TDes& text, const TDesC& replaceChars, TChar chWith)
- {
- TInt cchText = text.Length();
- for (TInt idx = 0; idx < cchText; ++idx)
- {
- if( KErrNotFound != replaceChars.Locate(text[idx]) )
- {
- // this character matches one of replaceChars; replace
- text[idx] = chWith;
- }
- }
- }
- ////////////////////////////////////////////////////////////
- //helper
- void AddTabL(CAknTabGroup* pGroup, const TDesC& imageFilePath, TInt idTab, TInt idxImage, TInt idxMask)
- {
- CFbsBitmap* pImage = new (ELeave) CFbsBitmap();
- AUTO_PUSH_POP(pImage);
- HXSYM_LEAVE_IF_ERR(pImage->Load(imageFilePath, idxImage, ETrue));
-
- CFbsBitmap* pMask = new (ELeave) CFbsBitmap();
- AUTO_PUSH_POP(pMask);
- HXSYM_LEAVE_IF_ERR(pMask->Load(imageFilePath, idxMask, ETrue));
-
- // tab group assumes ownership of bitmap
- pGroup->AddTabL(idTab, pImage, pMask);
-
- }
- ////////////////////////////////////////////////////////////
- //
- // The mbmPath may or may not have drive letter. If empty, we assume default app mbm file.
- //
- void AddIconHelperL(const TDesC& mbmPath, ImageInfo const info[], TInt count, CAknIconArray*& pIcons)
- {
- TFileName* pFullImagePath = 0;
- if( mbmPath.Length() == 0 )
- {
- pFullImagePath = CHXAvFile::AllocAppFolderPathL(CHXAvUtil::KImagesMBMName);
- }
- else
- {
- pFullImagePath = new (ELeave) TFileName;
- AUTO_PUSH_POP(pFullImagePath);
- RFs& fs = CCoeEnv::Static()->FsSession();
-
- // ensure path is full path (with drive) //XXXLCM does CreateIconL do this resolution for us?
- HXSYM_LEAVE_IF_ERR( CHXAvFile::GetFullPath(fs, mbmPath, *pFullImagePath) );
- }
- AUTO_PUSH_POP_DEL(pFullImagePath);
-
- for( TInt idx = 0; idx < count; ++idx )
- {
- CEikonEnv* pEnv = CEikonEnv::Static();
- CGulIcon* pIcon = pEnv->CreateIconL(*pFullImagePath, info[idx].idxImg, info[idx].idxImgMask);
- AUTO_PUSH_POP(pIcon); // transfer ownership
- pIcons->AppendL(pIcon);
- }
- }
- ////////////////////////////////////////////////////////
- // allocate an array of icons from image file
- CAknIconArray* AllocIconsL(const ImageInfo vec[], TInt imageCount, const TDesC& imageFilePath)
- {
- CAknIconArray* pIcons = new (ELeave) CAknIconArray(10/*granularity*/); //XXXLCM
- AUTO_PUSH_POP(pIcons); // out
- AddIconHelperL(imageFilePath, vec, imageCount, pIcons);
- return pIcons;
- }
- ////////////////////////////////////////
- // count valid media folder root
- /*TUint GetValidRootCountL(const utVector<avMediaFolderInfoPtr>& mediaFolderInfo)
- {
- TUint validRootCount = 0;
-
- for(TInt idx = 0; idx < mediaFolderInfo.Nelements(); ++idx)
- {
- avMediaFolderInfoPtr spInfo = mediaFolderInfo[idx];
- if( CHXAvFile::PathExists(spInfo->GetRoot()) )
- {
- ++validRootCount;
- }
- }
- HX_ASSERT(validRootCount > 0);
-
- return validRootCount;
- }*/
- ////////////////////////////////////////
- //
- HBufC* AllocTimerTextL(TUint ms)
- {
- HBufC* pText = HBufC::NewL(CHXAvUtil::k_cchMaxTimerText);
- TPtr ptr = pText->Des();
- FormatTimerText(ms, ptr);
- return pText;
- }
- /////////////////////////////////////////////////////////////////
- void FormatTimerText(TUint ms, TDes& des)
- {
- HX_ASSERT(des.MaxLength() >= k_cchMaxTimerText);
- TLocale locale;
- CHXString fmt;
- TUint totalSecs = ms / 1000;
- TUint hours = totalSecs / k_secsPerHour;
- TUint mins = ((totalSecs % k_secsPerHour) / k_secsPerMin);
- TUint secs = ((totalSecs % k_secsPerHour) % k_secsPerMin);
- TBuf<16> dhrs;
- TBuf<2> dmins;
- TBuf<2> dsecs;
- dhrs.AppendNum(hours);
- dmins.AppendNum(mins);
- dsecs.AppendNum(secs);
-
- if (hours != 0)
- {
- des.Append(dhrs);
- des.Append(locale.TimeSeparator(1));
- if (mins < 10)
- des.Append(_L("0"));
- }
- des.Append(dmins);
- des.Append(locale.TimeSeparator(2));
- if (secs < 10) {
- des.AppendNum(0);
- }
- des.Append(dsecs);
- }
- ////////////////////////////////////////////////////////////
- // init/add items that go in all options menus in all views
- void InitDebugMenuItemsL(CEikMenuPane* pPane)
- {
- #if defined(TEST_MENU)
- // add test item to menu
- CEikMenuPaneItem::SData extraItem;
- extraItem.iCommandId = EDoTest;
- extraItem.iCascadeId = 0;
- extraItem.iFlags = 0;
- extraItem.iText.Copy(_L("Test"));
- pPane->AddMenuItemL(extraItem);
- #endif
- }
- /////////
- ///////////////////////////////////////////////////
- // add menu item
- void AddMenuItemL(CEikMenuPane* pPane, TInt idCmd, TInt resIdText)
- {
- CEikMenuPaneItem::SData extraItem;
- extraItem.iCommandId = idCmd;
- extraItem.iCascadeId = 0;
- extraItem.iFlags = 0;
- extraItem.iText.Copy(CHXAvCleanString(resIdText)());
- pPane->AddMenuItemL(extraItem);
- }
- void InitHelpMenuItem(CEikMenuPane* pPane)
- {
- // look for something like "z:\System\Apps\CsHelp\CsHelp.app"
- _LIT(KHelpAppPath, "z:\System\Apps\CsHelp\CsHelp.app"); //XXXLCM once hlplnch.h is available
- bool bExists = CHXAvFile::PathExists(KHelpAppPath);
- pPane->SetItemDimmed(EAknCmdHelp, !bExists);
- }
- ////////////////////////////////////////////
- // true if we know for sure file is an app/program
- bool IsAppFileL(const TDesC& file)
- {
- RApaLsSession ls;
- HXSYM_LEAVE_IF_ERR(ls.Connect());
- CleanupClosePushL(ls);
- TBool bIsAnApp = EFalse;
- TInt err = ls.IsProgram(file, bIsAnApp);
-
- CleanupStack::PopAndDestroy(); // ls
- return bIsAnApp;
- }
- ////////////////////////////////////////////////////////
- //
- // return title for display in title bar or recent clips
- //
- // title is taken from file header; if that is missing, it is
- // formed based on play url; if that is missing, it is
- // formed based on main url (ram or playlist if play url is empty)
- //
- HBufC* AllocTitleL(CHXAvPlayer* pPlayer)
- {
- HX_ASSERT(pPlayer);
- comptr<IHXValues> header(pPlayer->GetClipInfo().GetFileHeader(0));
- // header may be missing, e.g., clip not played yet or fails to open
- CHXString strTitle;
- if( header )
- {
- val::GetString(header, "Title", strTitle, val::buffer);
- }
-
- HBufC* pTitleText = 0;
- if( strTitle.GetLength() > 0)
- {
- CHXAvCleanString text(strTitle);
- pTitleText = CHXAvMisc::AllocDisplayFriendlyStringL(text());
- }
- else
- {
- // no title in header; create one from clip url
- CHXString strUrl = pPlayer->GetPlayURL();
- if( strUrl.IsEmpty() )
- {
- strUrl = pPlayer->GetMainURL();
- }
-
- if( !strUrl.IsEmpty() )
- {
- CHXAvCleanString text(strUrl);
- pTitleText = CHXAvUtil::AllocDisplayTextForPlayerUrlL(text());
- }
- }
- return pTitleText;
- }
- #if(0) /////////////////////////////////////////////////////////////////////////////////
- void EnsureProcessNotRunningL(const TDesC& name)
- {
- // the full process name is something like '{process name}[{appuid}]{4 digit number}'
-
- // form name plus wildcard
- _LIT(KSearchNameFormat, "%S*");
- HBufC* pSearchName = HBufC::NewL(name.Length() + 1); // plus space for asterisk
- AUTO_PUSH_POP_DEL(pSearchName);
- pSearchName->Des().Format(KSearchNameFormat, &name);
- // find process
- TFindProcess finder(*pSearchName);
- DPRINTF(SYMP_INFO, ("EnsureProcessNotRunningL(): searching for process '%s'n", dbg::CharPtr(*pSearchName)()));
- TFullName fullName;
- TInt res = finder.Next(fullName);
- while( KErrNone == res )
- {
- // server exists; server should not exist before we call start
- DPRINTF(SYMP_INFO, ("EnsureProcessNotRunningL(): '%s' foundn", dbg::CharPtr(fullName)()));
- RProcess proc;
- res = proc.Open(finder);
- if( KErrNone == res )
- {
- // kill this if it is not the current process
- if( proc.Id() != RProcess().Id() )
- {
- DPRINTF(SYMP_INFO, ("EnsureProcessNotRunningL(): killing process!n"));
- proc.Kill(KErrNone);
- proc.Close();
- }
- }
- res = finder.Next(fullName);
- }
- }
- void DumpWindowGroupInfoL()
- {
- RWsSession& ws = CEikonEnv::Static()->WsSession();
- TThreadId tidThis = RThread().Id();
- // get list of window groups
- CArrayFixFlat<TInt>* pWindowList = new (ELeave) CArrayFixFlat<TInt>(4);
- AUTO_PUSH_POP_DEL(pWindowList);
- HXSYM_LEAVE_IF_ERR(ws.WindowGroupList(pWindowList));
- // iterate over window groups
- TBuf<200> winName;
- for (TInt idx = 0; idx < pWindowList->Count(); ++idx)
- {
- // get window group name
- TInt wgid = (*pWindowList)[idx];
- ws.GetWindowGroupNameFromIdentifier(wgid, winName );
- RDebug::Print(_L("win group %d name: %S"), wgid, &winName);
- winName.Zero();
- CApaWindowGroupName* pWgn = CApaWindowGroupName::NewL(ws);
- AUTO_PUSH_POP_DEL(pWgn);
- pWgn->ConstructFromWgIdL(wgid);
- // now get info
- RDebug::Print(_L("win group info:"));
- RDebug::Print(_L("caption: %S"), &(pWgn->Caption()));
- RDebug::Print(_L("doc: %S"), &(pWgn->DocName()));
- RDebug::Print(_L("hidden = %d; system = %d"), pWgn->Hidden(), pWgn->IsSystem());
- RDebug::Print(_L("app uid: 0x%x"), pWgn->AppUid());
-
- // get thread info associated with window group
- TThreadId threadId = 0;
- TInt err = ws.GetWindowGroupClientThreadId(wgid, threadId);
- if( err == KErrNone)
- {
- RThread thread;
- err = thread.Open(threadId);
- if( err == KErrNone)
- {
- RDebug::Print(_L("thread name: %S"), &(thread.Name()));
- thread.Close();
- }
- }
- }
- }
- #endif /////////////////////////////////////////////////////////////////
- } // avMisc