chxavfolderpopuplist.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:11k
源码类别:

Symbian

开发平台:

C/C++

  1. /************************************************************************
  2.  * chxCHXCHXAvFolderPopupList.cpp
  3.  * ------------------------
  4.  *
  5.  * Synopsis:
  6.  *
  7.  * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
  8.  *
  9.  ************************************************************************/
  10. #include "avkon.mbg"
  11. // Include from this project...
  12. #include "chxavmisc.h"
  13. #include "chxavcallback.h"
  14. #include "chxavcleanstring.h"
  15. #include "chxavfolderdisplayinfo.h"
  16. #include "chxavfolderpopuplist.h"
  17. #include "realplayer.hrh"
  18. #include "realplayer.mbg"
  19. #include "chxavcleanupstack.h"
  20. #include "hxsym_debug.h"
  21. namespace
  22. {
  23.    
  24.     //
  25.     // standard folder icon info
  26.     //
  27.     enum
  28.     {
  29.         k_idxFolderIcon = 0
  30.     };
  31.     const CHXAvMisc::ImageInfo folderIconInfo[] = 
  32.     {
  33.         { EMbmAvkonQgn_prop_folder_small, EMbmAvkonQgn_prop_folder_small_mask }
  34.     };
  35.     //
  36.     // root icon info
  37.     //
  38.     enum
  39.     {
  40.         k_idxPhoneIcon = 0,
  41.         k_idxMmcIcon,
  42.         k_idxMmcLockedIcon,
  43.         k_idxMmcAbsentIcon
  44.     };
  45.     static const CHXAvMisc::ImageInfo rootIconInfo[] =
  46.     { 
  47.         {EMbmRealplayerQgn_prop_phone_small,        EMbmRealplayerQgn_prop_phone_small_mask }, 
  48.         {EMbmRealplayerQgn_prop_mmc_small,          EMbmRealplayerQgn_prop_mmc_small_mask   }, 
  49.         {EMbmRealplayerQgn_prop_mmc_locked_small,   EMbmRealplayerQgn_prop_mmc_locked_small_mask   }, 
  50.         {EMbmRealplayerQgn_prop_mmc_non_small,      EMbmRealplayerQgn_prop_mmc_non_small_mask   }, 
  51.     };
  52. } // local
  53. CHXAvFolderPopupList::CHXAvFolderPopupList(TInt& idxSelected, 
  54.                                      TInt& idExitCmd)
  55. : m_idxSelected(idxSelected)
  56. , m_idExitCmd(idExitCmd)
  57. , m_wpBasePath(0)
  58. {
  59. }
  60. CHXAvFolderPopupList::~CHXAvFolderPopupList()
  61. {
  62. }
  63. ////////////////////////////////////////////////
  64. // construct helper
  65. void CHXAvFolderPopupList::DoBeginConstructL(TInt resIdPrompt, 
  66.                                           TInt resIdCba, 
  67.                                           TInt resIdSelectButtonText,
  68.                                           const TDesC* pCurrentPath)
  69. {
  70.     // create actual listbox
  71.     m_spListBox = new (ELeave) CAknSingleGraphicPopupMenuStyleListBox;
  72.     CAknPopupList::ConstructL(m_spListBox.Ptr(), resIdCba,
  73. AknPopupLayouts::EMenuGraphicWindow);
  74.     m_wpBasePath = pCurrentPath;
  75.     
  76.     m_spListBox->ConstructL(this, CEikListBox::ELeftDownInViewRect);
  77.     m_spListBox->CreateScrollBarFrameL(ETrue);
  78.     m_spListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
  79. CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
  80.     if( resIdSelectButtonText != -1 )
  81.     {
  82.         // set left button text
  83.         CEikButtonGroupContainer* pCba = ButtonGroupContainer();
  84.         pCba->SetCommandL(0, EAknSoftkeySelect, CHXAvCleanString(resIdSelectButtonText)());
  85.     }
  86.     m_spSelectButton = new (ELeave) CHXAvCallback();
  87.     m_spSelectButton->ConstructL(
  88.         MakeCommand(this, &CHXAvFolderPopupList::ForwardCommandL, TInt(EAknSoftkeySelect)));
  89.     SetTitleL(CHXAvCleanString(resIdPrompt)());
  90.     m_spListBox->SetListBoxObserver(this);
  91. }
  92. ////////////////////////////////////////////////
  93. // construct regular folder list
  94. //
  95. void CHXAvFolderPopupList::ConstructL(TInt resIdPrompt, TInt resIdSelectButtonText,
  96.                                    const CDesCArrayFlat* pFolders, const TDesC* pCurrentPath,
  97.                                    TInt idxCurrentItem)
  98. {
  99.     // child folder list gets 'back'
  100.     DoBeginConstructL(resIdPrompt, R_AVP_CBA_MOVE_BACK, resIdSelectButtonText, pCurrentPath);
  101.     SetFolderListItemsL(pFolders);
  102.     m_spListBox->ClearSelection();
  103.     m_spListBox->SetCurrentItemIndex(idxCurrentItem);
  104.     m_spListBox->HandleItemAdditionL();
  105. }
  106. ////////////////////////////////////////////////
  107. // construct top-level root media store selection list
  108. void CHXAvFolderPopupList::ConstructL(TInt resIdPrompt, TInt resIdSelectButtonText,
  109.                                    const CHXAvVector<CHXAvMediaFolderInfoPtr>& mediaFolderInfo,
  110.                                    const TDesC* pCurrentPath,
  111.                                    TInt idxCurrentItem)
  112. {
  113.     // top level list gets 'cancel'
  114.     DoBeginConstructL(resIdPrompt, R_AVP_CBA_MOVE_CANCEL, resIdSelectButtonText, pCurrentPath);
  115.     SetRootFolderListItemsL(mediaFolderInfo);
  116.     m_spListBox->ClearSelection();
  117.     m_spListBox->SetCurrentItemIndex(idxCurrentItem);
  118.     m_spListBox->HandleItemAdditionL();
  119. }
  120. //////////////////////////////
  121. //
  122. void
  123. CHXAvFolderPopupList::AttemptExitL(TBool aAccept)
  124. {
  125.     DPRINTF(SYMP_INFO, ("CHXAvFolderPopupList::AttemptExitL() accept = %ldn", aAccept));
  126.     if( aAccept && m_idExitCmd != EOpenFolder)
  127.     {
  128.         DPRINTF(SYMP_INFO, ("CHXAvFolderPopupList::AttemptExitL() command: 'select folder'n"));
  129.         // must have pressed the softkey
  130.         m_idExitCmd = EMoveToFolder;
  131.     }
  132.         
  133.         // 'open' the selected folder
  134.     m_idxSelected = m_spListBox->CurrentItemIndex();
  135.     CAknPopupList::AttemptExitL(aAccept);
  136. }
  137. //////////////////////////////
  138. // create and set icon array for list items
  139. //
  140. void
  141. CHXAvFolderPopupList::CreateAndSetRootIconsL()
  142. {
  143.     // create icon array for list items
  144.     CAknIconArray* pIcons = CHXAvMisc::AllocIconsL(rootIconInfo, ARRAY_COUNT(rootIconInfo));
  145.     AUTO_PUSH_POP(pIcons);
  146.     // transfer icon array ownership to list box
  147.     m_spListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL(pIcons);
  148. }
  149. //////////////////////////////
  150. //
  151. void CHXAvFolderPopupList::CreateAndSetFolderIconsL()
  152. {
  153.     CAknIconArray* pIcons =  CHXAvMisc::AllocIconsL(
  154.         folderIconInfo, ARRAY_COUNT(folderIconInfo),  CHXAvMisc::KAVPAvkonImagePath);
  155.     AUTO_PUSH_POP(pIcons);
  156.     // transfer icon array ownership to list box
  157.     m_spListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL(pIcons);
  158.     
  159. }
  160. //////////////////////////////
  161. // set list box contents to list of folders
  162. //
  163. void CHXAvFolderPopupList::SetFolderListItemsL(const CDesCArrayFlat* pFolders)
  164. {
  165.     HX_ASSERT(m_spListBox);
  166.     HX_ASSERT(pFolders->Count() > 0);
  167.     m_wpFolders = pFolders;
  168.     // create folder display info traits
  169.     CHXAvFolderDisplayInfo displayInfo;
  170.     // create folder icons
  171.     CreateAndSetFolderIconsL();
  172.     
  173.     // create list item entries based on folder list
  174.     CDesCArrayFlat* pItems = new (ELeave) CDesCArrayFlat(20 /*granularity*/);
  175.     AUTO_PUSH_POP(pItems);
  176.     TInt count = pFolders->Count();
  177.     for( TInt idx = 0; idx < count; ++idx )
  178.     {
  179. const TDesC& name = (*pFolders)[idx];
  180. if( name.Length() > 0)
  181. {
  182.             
  183.             TFileName* pPath = CHXAvFile::AllocFileNameL(*m_wpBasePath, name, CHXAvFile::ntFolder);
  184.             AUTO_PUSH_POP_DEL(pPath);
  185.             displayInfo.SetFolderPathL(*pPath);
  186.          
  187.             HBufC* pText = CHXAvMisc::AllocGrListItemL(displayInfo.GetDisplayText(), k_idxFolderIcon);
  188.             AUTO_PUSH_POP_DEL(pText);
  189.             pItems->AppendL(*pText); // copied
  190. }
  191.     }
  192.     // transfer list ownership to listbox
  193.     CTextListBoxModel* pModel = m_spListBox->Model();
  194.     pModel->SetItemTextArray(pItems);
  195.     pModel->SetOwnershipType(ELbmOwnsItemArray);
  196. }
  197. //////////////////////////////
  198. // set list box contents to list of root media store folders
  199. //
  200. void
  201. CHXAvFolderPopupList::SetRootFolderListItemsL(const CHXAvVector<CHXAvMediaFolderInfoPtr>& mediaFolderInfo)
  202. {
  203.     HX_ASSERT(m_spListBox);
  204.     HX_ASSERT(mediaFolderInfo.Nelements() > 0);
  205.     CreateAndSetRootIconsL();
  206.     CDesCArrayFlat* pItems = new (ELeave) CDesCArrayFlat( CHXAvMisc::k_defaultArrayGranularity );
  207.     AUTO_PUSH_POP(pItems);
  208.     // XXXLCM if you have media folders on the same drive, they will end up with the same name
  209.     for(TInt idx = 0; idx < mediaFolderInfo.Nelements(); ++idx)
  210.     {
  211.         CHXAvMediaFolderInfoPtr spInfo = mediaFolderInfo[idx];
  212.         spInfo->UpdateDriveInfo();
  213.         const CHXAvFile::DriveInfo& info = spInfo->GetDriveInfo();
  214.         // get display text
  215.         HBufC* pbuffDesc = spInfo->AllocListDescriptionL();
  216.         AUTO_PUSH_POP_DEL(pbuffDesc);
  217.         // get icon
  218.         TInt idxIcon (k_idxPhoneIcon);
  219.         if( spInfo->IsMmcFolder() )
  220.         {
  221.             switch(info.state)
  222.             {
  223.             case CHXAvFile::dsAccessible:
  224.                 idxIcon = k_idxMmcIcon;
  225.                 break;
  226.             case CHXAvFile::dsLocked:
  227.                 idxIcon = k_idxMmcLockedIcon;
  228.                 break;
  229.             default:
  230.                 idxIcon = k_idxMmcAbsentIcon;
  231.                 break;
  232.             }
  233.         }
  234.         HBufC* pLine = CHXAvMisc::AllocGrListItemL(*pbuffDesc, idxIcon);
  235.         AUTO_PUSH_POP_DEL(pLine);
  236.         pItems->AppendL(*pLine);
  237.     }
  238.    
  239.     // transfer list ownership to listbox
  240.     CTextListBoxModel* pModel = m_spListBox->Model();
  241.     pModel->SetItemTextArray(pItems);
  242.     pModel->SetOwnershipType(ELbmOwnsItemArray);
  243. }
  244. ////////////////////////////////////////////
  245. //
  246. bool CHXAvFolderPopupList::FolderHasChildren(TInt idxFolder)
  247. {
  248.     bool bHasChildren = true;
  249.     // XXXLCM for root media store selection list we assume there are children
  250.     
  251.     if( m_wpBasePath && m_wpFolders)
  252.     {
  253.         // need to check
  254.         
  255.         //CTextListBoxModel* pModel = m_spListBox->Model();
  256.         //TPtrC text = CHXAvMisc::TextChunk(pModel->ItemText(idxFolder), 1);
  257.         TPtrC text = (*m_wpFolders)[idxFolder];
  258.         // alloc qualified folder path
  259.         TFileName* pPath = CHXAvFile::AllocFileNameL(*m_wpBasePath, text, CHXAvFile::ntFolder);
  260.         AUTO_PUSH_POP_DEL(pPath);
  261.   
  262.         const bool bIncludeFolders = true;
  263.         TInt childCount = 0;
  264.         CHXAvFile::GetFolderChildCount(*pPath, childCount, 
  265.                                                 bIncludeFolders, CHXAvFile::FilterIncludeNoFiles);
  266.         bHasChildren = (childCount > 0);
  267.     }
  268.     return bHasChildren;
  269. }
  270. ////////////////////////////////////////////
  271. //
  272. void CHXAvFolderPopupList::ForwardCommandL(TInt idCommand)
  273. {
  274.     DPRINTF(SYMP_INFO, ("CHXAvFolderPopupList::ForwardCommandL() cmd = %ldn", idCommand));
  275.     // get this popup list to exit; this object is deleted during this call
  276.     ProcessCommandL(idCommand);
  277. }
  278. ////////////////////////////////////////////
  279. // MEikListBoxObserver
  280. void CHXAvFolderPopupList::HandleListBoxEventL(CEikListBox* aListBox,TListBoxEvent aEventType)
  281. {
  282.     DPRINTF(SYMP_INFO, ("CHXAvFolderPopupList::HandleListBoxEventL() type = %ldn", aEventType));
  283.     if( aEventType == MEikListBoxObserver::EEventEnterKeyPressed ||
  284. aEventType == MEikListBoxObserver::EEventItemClicked )
  285.     {
  286.         if( FolderHasChildren(m_spListBox->CurrentItemIndex()) )
  287.         {
  288.     DPRINTF(SYMP_INFO, ("CHXAvFolderPopupList::HandleListBoxEventL() command: 'open folder'n"));
  289.         
  290.             // 'open' the selected folder
  291.             m_idExitCmd = EOpenFolder;
  292.             if(m_spSelectButton)
  293.             {
  294.                 //HX_ASSERT(m_spSelectButton.GetRefCount() >= 2); // us and class client
  295.                 m_spSelectButton->Set(10); 
  296.             }
  297.             //ProcessCommandL(EAknSoftkeySelect); // this is unsafe; self-destruct may occur
  298.         }  
  299.         
  300.     }
  301.     else
  302.     {
  303.         CAknPopupList::HandleListBoxEventL(aListBox, aEventType);
  304.     }
  305. }