chxavfolderpopuplist.cpp
来自「著名的 helix realplayer 基于手机 symbian 系统的 播放」· C++ 代码 · 共 359 行
CPP
359 行
/************************************************************************
* chxCHXCHXAvFolderPopupList.cpp
* ------------------------
*
* Synopsis:
*
* (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
*
************************************************************************/
#include "avkon.mbg"
// Include from this project...
#include "chxavmisc.h"
#include "chxavcallback.h"
#include "chxavcleanstring.h"
#include "chxavfolderdisplayinfo.h"
#include "chxavfolderpopuplist.h"
#include "realplayer.hrh"
#include "realplayer.mbg"
#include "chxavcleanupstack.h"
#include "hxsym_debug.h"
namespace
{
//
// standard folder icon info
//
enum
{
k_idxFolderIcon = 0
};
const CHXAvMisc::ImageInfo folderIconInfo[] =
{
{ EMbmAvkonQgn_prop_folder_small, EMbmAvkonQgn_prop_folder_small_mask }
};
//
// root icon info
//
enum
{
k_idxPhoneIcon = 0,
k_idxMmcIcon,
k_idxMmcLockedIcon,
k_idxMmcAbsentIcon
};
static const CHXAvMisc::ImageInfo rootIconInfo[] =
{
{EMbmRealplayerQgn_prop_phone_small, EMbmRealplayerQgn_prop_phone_small_mask },
{EMbmRealplayerQgn_prop_mmc_small, EMbmRealplayerQgn_prop_mmc_small_mask },
{EMbmRealplayerQgn_prop_mmc_locked_small, EMbmRealplayerQgn_prop_mmc_locked_small_mask },
{EMbmRealplayerQgn_prop_mmc_non_small, EMbmRealplayerQgn_prop_mmc_non_small_mask },
};
} // local
CHXAvFolderPopupList::CHXAvFolderPopupList(TInt& idxSelected,
TInt& idExitCmd)
: m_idxSelected(idxSelected)
, m_idExitCmd(idExitCmd)
, m_wpBasePath(0)
{
}
CHXAvFolderPopupList::~CHXAvFolderPopupList()
{
}
////////////////////////////////////////////////
// construct helper
void CHXAvFolderPopupList::DoBeginConstructL(TInt resIdPrompt,
TInt resIdCba,
TInt resIdSelectButtonText,
const TDesC* pCurrentPath)
{
// create actual listbox
m_spListBox = new (ELeave) CAknSingleGraphicPopupMenuStyleListBox;
CAknPopupList::ConstructL(m_spListBox.Ptr(), resIdCba,
AknPopupLayouts::EMenuGraphicWindow);
m_wpBasePath = pCurrentPath;
m_spListBox->ConstructL(this, CEikListBox::ELeftDownInViewRect);
m_spListBox->CreateScrollBarFrameL(ETrue);
m_spListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
if( resIdSelectButtonText != -1 )
{
// set left button text
CEikButtonGroupContainer* pCba = ButtonGroupContainer();
pCba->SetCommandL(0, EAknSoftkeySelect, CHXAvCleanString(resIdSelectButtonText)());
}
m_spSelectButton = new (ELeave) CHXAvCallback();
m_spSelectButton->ConstructL(
MakeCommand(this, &CHXAvFolderPopupList::ForwardCommandL, TInt(EAknSoftkeySelect)));
SetTitleL(CHXAvCleanString(resIdPrompt)());
m_spListBox->SetListBoxObserver(this);
}
////////////////////////////////////////////////
// construct regular folder list
//
void CHXAvFolderPopupList::ConstructL(TInt resIdPrompt, TInt resIdSelectButtonText,
const CDesCArrayFlat* pFolders, const TDesC* pCurrentPath,
TInt idxCurrentItem)
{
// child folder list gets 'back'
DoBeginConstructL(resIdPrompt, R_AVP_CBA_MOVE_BACK, resIdSelectButtonText, pCurrentPath);
SetFolderListItemsL(pFolders);
m_spListBox->ClearSelection();
m_spListBox->SetCurrentItemIndex(idxCurrentItem);
m_spListBox->HandleItemAdditionL();
}
////////////////////////////////////////////////
// construct top-level root media store selection list
void CHXAvFolderPopupList::ConstructL(TInt resIdPrompt, TInt resIdSelectButtonText,
const CHXAvVector<CHXAvMediaFolderInfoPtr>& mediaFolderInfo,
const TDesC* pCurrentPath,
TInt idxCurrentItem)
{
// top level list gets 'cancel'
DoBeginConstructL(resIdPrompt, R_AVP_CBA_MOVE_CANCEL, resIdSelectButtonText, pCurrentPath);
SetRootFolderListItemsL(mediaFolderInfo);
m_spListBox->ClearSelection();
m_spListBox->SetCurrentItemIndex(idxCurrentItem);
m_spListBox->HandleItemAdditionL();
}
//////////////////////////////
//
void
CHXAvFolderPopupList::AttemptExitL(TBool aAccept)
{
DPRINTF(SYMP_INFO, ("CHXAvFolderPopupList::AttemptExitL() accept = %ld\n", aAccept));
if( aAccept && m_idExitCmd != EOpenFolder)
{
DPRINTF(SYMP_INFO, ("CHXAvFolderPopupList::AttemptExitL() command: 'select folder'\n"));
// must have pressed the softkey
m_idExitCmd = EMoveToFolder;
}
// 'open' the selected folder
m_idxSelected = m_spListBox->CurrentItemIndex();
CAknPopupList::AttemptExitL(aAccept);
}
//////////////////////////////
// create and set icon array for list items
//
void
CHXAvFolderPopupList::CreateAndSetRootIconsL()
{
// create icon array for list items
CAknIconArray* pIcons = CHXAvMisc::AllocIconsL(rootIconInfo, ARRAY_COUNT(rootIconInfo));
AUTO_PUSH_POP(pIcons);
// transfer icon array ownership to list box
m_spListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL(pIcons);
}
//////////////////////////////
//
void CHXAvFolderPopupList::CreateAndSetFolderIconsL()
{
CAknIconArray* pIcons = CHXAvMisc::AllocIconsL(
folderIconInfo, ARRAY_COUNT(folderIconInfo), CHXAvMisc::KAVPAvkonImagePath);
AUTO_PUSH_POP(pIcons);
// transfer icon array ownership to list box
m_spListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL(pIcons);
}
//////////////////////////////
// set list box contents to list of folders
//
void CHXAvFolderPopupList::SetFolderListItemsL(const CDesCArrayFlat* pFolders)
{
HX_ASSERT(m_spListBox);
HX_ASSERT(pFolders->Count() > 0);
m_wpFolders = pFolders;
// create folder display info traits
CHXAvFolderDisplayInfo displayInfo;
// create folder icons
CreateAndSetFolderIconsL();
// create list item entries based on folder list
CDesCArrayFlat* pItems = new (ELeave) CDesCArrayFlat(20 /*granularity*/);
AUTO_PUSH_POP(pItems);
TInt count = pFolders->Count();
for( TInt idx = 0; idx < count; ++idx )
{
const TDesC& name = (*pFolders)[idx];
if( name.Length() > 0)
{
TFileName* pPath = CHXAvFile::AllocFileNameL(*m_wpBasePath, name, CHXAvFile::ntFolder);
AUTO_PUSH_POP_DEL(pPath);
displayInfo.SetFolderPathL(*pPath);
HBufC* pText = CHXAvMisc::AllocGrListItemL(displayInfo.GetDisplayText(), k_idxFolderIcon);
AUTO_PUSH_POP_DEL(pText);
pItems->AppendL(*pText); // copied
}
}
// transfer list ownership to listbox
CTextListBoxModel* pModel = m_spListBox->Model();
pModel->SetItemTextArray(pItems);
pModel->SetOwnershipType(ELbmOwnsItemArray);
}
//////////////////////////////
// set list box contents to list of root media store folders
//
void
CHXAvFolderPopupList::SetRootFolderListItemsL(const CHXAvVector<CHXAvMediaFolderInfoPtr>& mediaFolderInfo)
{
HX_ASSERT(m_spListBox);
HX_ASSERT(mediaFolderInfo.Nelements() > 0);
CreateAndSetRootIconsL();
CDesCArrayFlat* pItems = new (ELeave) CDesCArrayFlat( CHXAvMisc::k_defaultArrayGranularity );
AUTO_PUSH_POP(pItems);
// XXXLCM if you have media folders on the same drive, they will end up with the same name
for(TInt idx = 0; idx < mediaFolderInfo.Nelements(); ++idx)
{
CHXAvMediaFolderInfoPtr spInfo = mediaFolderInfo[idx];
spInfo->UpdateDriveInfo();
const CHXAvFile::DriveInfo& info = spInfo->GetDriveInfo();
// get display text
HBufC* pbuffDesc = spInfo->AllocListDescriptionL();
AUTO_PUSH_POP_DEL(pbuffDesc);
// get icon
TInt idxIcon (k_idxPhoneIcon);
if( spInfo->IsMmcFolder() )
{
switch(info.state)
{
case CHXAvFile::dsAccessible:
idxIcon = k_idxMmcIcon;
break;
case CHXAvFile::dsLocked:
idxIcon = k_idxMmcLockedIcon;
break;
default:
idxIcon = k_idxMmcAbsentIcon;
break;
}
}
HBufC* pLine = CHXAvMisc::AllocGrListItemL(*pbuffDesc, idxIcon);
AUTO_PUSH_POP_DEL(pLine);
pItems->AppendL(*pLine);
}
// transfer list ownership to listbox
CTextListBoxModel* pModel = m_spListBox->Model();
pModel->SetItemTextArray(pItems);
pModel->SetOwnershipType(ELbmOwnsItemArray);
}
////////////////////////////////////////////
//
bool CHXAvFolderPopupList::FolderHasChildren(TInt idxFolder)
{
bool bHasChildren = true;
// XXXLCM for root media store selection list we assume there are children
if( m_wpBasePath && m_wpFolders)
{
// need to check
//CTextListBoxModel* pModel = m_spListBox->Model();
//TPtrC text = CHXAvMisc::TextChunk(pModel->ItemText(idxFolder), 1);
TPtrC text = (*m_wpFolders)[idxFolder];
// alloc qualified folder path
TFileName* pPath = CHXAvFile::AllocFileNameL(*m_wpBasePath, text, CHXAvFile::ntFolder);
AUTO_PUSH_POP_DEL(pPath);
const bool bIncludeFolders = true;
TInt childCount = 0;
CHXAvFile::GetFolderChildCount(*pPath, childCount,
bIncludeFolders, CHXAvFile::FilterIncludeNoFiles);
bHasChildren = (childCount > 0);
}
return bHasChildren;
}
////////////////////////////////////////////
//
void CHXAvFolderPopupList::ForwardCommandL(TInt idCommand)
{
DPRINTF(SYMP_INFO, ("CHXAvFolderPopupList::ForwardCommandL() cmd = %ld\n", idCommand));
// get this popup list to exit; this object is deleted during this call
ProcessCommandL(idCommand);
}
////////////////////////////////////////////
// MEikListBoxObserver
void CHXAvFolderPopupList::HandleListBoxEventL(CEikListBox* aListBox,TListBoxEvent aEventType)
{
DPRINTF(SYMP_INFO, ("CHXAvFolderPopupList::HandleListBoxEventL() type = %ld\n", aEventType));
if( aEventType == MEikListBoxObserver::EEventEnterKeyPressed ||
aEventType == MEikListBoxObserver::EEventItemClicked )
{
if( FolderHasChildren(m_spListBox->CurrentItemIndex()) )
{
DPRINTF(SYMP_INFO, ("CHXAvFolderPopupList::HandleListBoxEventL() command: 'open folder'\n"));
// 'open' the selected folder
m_idExitCmd = EOpenFolder;
if(m_spSelectButton)
{
//HX_ASSERT(m_spSelectButton.GetRefCount() >= 2); // us and class client
m_spSelectButton->Set(10);
}
//ProcessCommandL(EAknSoftkeySelect); // this is unsafe; self-destruct may occur
}
}
else
{
CAknPopupList::HandleListBoxEventL(aListBox, aEventType);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?