chxavmisc.cpp
来自「著名的 helix realplayer 基于手机 symbian 系统的 播放」· C++ 代码 · 共 903 行 · 第 1/2 页
CPP
903 行
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., \realnetworks\root\foo.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' found\n", 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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?