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

Symbian

开发平台:

C/C++

  1. /************************************************************************
  2.  * chxavfileview.cpp
  3.  * -----------------
  4.  *
  5.  * Synopsis:
  6.  * Contains the implementation of the CHXAvFileView class.  This class 
  7.  * is derived from CHXAvViewBase which is derived from CAknView.  This
  8.  * object instantiates and own a control called the CHXAvFileViewWindow.
  9.  * This control owns two component controls, the list box and a find box.
  10.  *
  11.  * Target:
  12.  * Symbian OS
  13.  *
  14.  *
  15.  * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
  16.  *
  17.  ************************************************************************/
  18. // Symbian includes...
  19. #include <coeccntx.h>
  20. #include <eikenv.h>
  21. #include <eikappui.h>
  22. #include <eikapp.h>
  23. #include <eikdoc.h>
  24. #include <eikmenup.h>
  25. #include <eikon.hrh>
  26. #include <aknviewappui.h>
  27. #include <apchangeobserver.h>
  28. #include <akniconarray.h> 
  29. #include <aknselectionlist.h>
  30. #include <SenduiMtmUids.h>
  31. #include <sendui.h>
  32. #include <SendNorm.rsg>
  33. // Includes for this project...
  34. #include "hxsym_debug.h"
  35. #include "realplayer.rsg"
  36. #include "chxavfileviewwindow.h"
  37. #include "chxavviewbase.h"
  38. #include "chxavfileview.h"
  39. #include "realplayer.hrh"
  40. #include "chxavplayerui.h"
  41. #include "chxavfileviewpageinfo.h"
  42. #include "chxavfolderdisplayinfo.h"
  43. #include "realplayer.mbg"
  44. namespace 
  45. {
  46. inline
  47. bool IsViewAtRoot(CHXAvFileViewWindow* pWin)
  48. {
  49.     CHXAvFileStorePtr spStore = pWin->GetStore();
  50.     return !spStore || spStore->IsAtRoot();
  51. }
  52. }
  53. /* 
  54.  * CHXAvFileView
  55.  * -------------
  56.  * Constructor.
  57.  *
  58.  */
  59. CHXAvFileView::CHXAvFileView(TInt viewIndex, CHXAvPlayerUI *playerUI) 
  60. : CHXAvViewBase(viewIndex, playerUI)
  61. , m_idxInitPage(0)
  62. {
  63. }
  64. /*
  65.  * ~CHXAvFileView
  66.  * --------------
  67.  * Destructor.
  68.  *
  69.  */
  70. CHXAvFileView::~CHXAvFileView()
  71. {
  72. }
  73. /* 
  74.  * ConstructL
  75.  * ----------
  76.  * Construction of elements.
  77.  *
  78.  */
  79. void CHXAvFileView::ConstructL()
  80. {
  81.     BaseConstructL(R_AVP_FILE_VIEW_INFO);
  82.     m_spPageInfo = new (ELeave) CHXAvFileViewPageInfoVector();
  83.     AppendPageInfoL();
  84.     m_spSendAppUi = CSendAppUi::NewL(ECmdSendVia); 
  85. }
  86. /*
  87.  * CreatePageInfoL
  88.  * ---------------
  89.  * Create and add to the list all of the page info stuff.
  90.  *
  91.  */
  92. void 
  93. CHXAvFileView::AppendPageInfoL()
  94. {
  95.     // Get mmc and local folder information...
  96.     HX_ASSERT(m_playerUI != NULL);
  97.     const CHXAvVector<CHXAvMediaFolderInfoPtr>& spFolderInfo = m_playerUI->GetMediaStoreInfoL(true);
  98.     // Add local tab...
  99.     CHXAvFileViewPageInfoPtr spInfo1 = new (ELeave) CHXAvFileViewPageInfo();
  100.     spInfo1->ConstructL(spFolderInfo[0]->GetRoot(), true, EMbmRealplayerFileview_local_tab, EMbmRealplayerFileview_local_tab_mask);
  101.     CHXAvUtil::Append(*m_spPageInfo, spInfo1);
  102.     if( spFolderInfo.Nelements() > 1 )
  103.     {
  104.         // Add mmc tab
  105.         CHXAvFileViewPageInfoPtr EMbmRealplayer = new (ELeave) CHXAvFileViewPageInfo();
  106.         EMbmRealplayer->ConstructL(spFolderInfo[1]->GetRoot(), false, EMbmRealplayerFileview_mmc_tab, EMbmRealplayerFileview_mmc_tab_mask);
  107. CHXAvUtil::Append(*m_spPageInfo, EMbmRealplayer);
  108.     }
  109. }
  110. /*
  111.  * HandleCommandL
  112.  * --------------
  113.  * Handle commands passed to us by our control and directly.
  114.  *
  115.  */
  116. void CHXAvFileView::HandleCommandL(TInt command)
  117. {
  118.     bool bAtRoot = IsViewAtRoot(m_spWindow.raw_ptr());
  119.     switch(command)
  120.     {
  121.         case EAknSoftkeyOk:
  122.         case EOpenFolder:
  123.         case EPlay:
  124.             m_spWindow->UserOpenCurrentItemL();
  125.     break;
  126.         case EAknSoftkeyBack:
  127.   HX_ASSERT(!bAtRoot);
  128.           if( !bAtRoot )
  129.   {
  130.       // go back to root
  131.       m_spWindow->UserSwitchToParentFolderAndRefreshL();
  132.   }
  133.   break;
  134.       case EAknMarkAll:
  135.       case EAknUnmarkAll:
  136.       case EAknCmdUnmark:
  137.       case EAknCmdMark:
  138.   m_spWindow->UserMarkL(command);
  139.   break;
  140.       case EShowDefaultMenu:
  141.           ShowPopupMenuL(R_AVP_FILE_VIEW_MENU_BAR);
  142.           break;
  143.       case EEditPlaylist:
  144.   m_spWindow->UserEditCurrentItemL();
  145.   break;
  146.       case EDelete:
  147.   m_spWindow->UserDeleteSelectedItemsL();
  148.   break;
  149.       case EMoveToFolder:
  150.   m_spWindow->UserMoveSelectedItemsL();
  151.   break;
  152.       case ECopyToFolder:
  153.           m_spWindow->UserCopySelectedItemsL();
  154.           break;
  155.       case ENewFolder:
  156.   m_spWindow->UserNewFolderL();
  157.   break;
  158.       case ERename:
  159.   m_spWindow->UserRenameCurrentItemL();
  160.   break;
  161.   /*
  162.       case EAknCmdAddToPinboard:
  163.   m_spWindow->UserAddSelectedToPinboardL();
  164.   break;*/
  165.       case ECmdSendVia:
  166.       case ECmdSendCmd1:
  167.       case ECmdSendCmd2:
  168.       case ECmdSendCmd3:
  169.       case ECmdSendCmd4:
  170.       case ECmdSendCmd5:
  171.       case ECmdSendCmd6:
  172.   m_spWindow->UserSendSelectedItemsL(command, m_spSendAppUi.Ptr());
  173.   break;
  174.       case EUnlockDrive:
  175.         m_spWindow->UserUnlockDriveL();
  176.         break;
  177.     default:
  178.         m_playerUI->HandleCommandL(command);
  179. break;
  180.     }
  181. }
  182. /*
  183.  * UpdateViewStateL
  184.  * ----------------
  185.  *
  186.  */
  187. ////////////////////////////////////////////////////////
  188. // make sure view state (everything but window area) appropriately
  189. // reflects state of the file view window; updates menu bar commands
  190. // and title text
  191. void CHXAvFileView::UpdateViewStateL()
  192. {
  193.     if(IsViewAtRoot(m_spWindow.raw_ptr()))
  194.     {
  195. Cba()->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_EXIT);
  196.         // use long caption from caption resource; initially overridden app title is shown
  197.         SetDefaultAppTitleL();
  198.     }
  199.     else
  200.     {
  201. Cba()->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_BACK);
  202.         CHXAvFolderDisplayInfo info;
  203.         info.SetFolderPathL(m_spWindow->GetFullPath());
  204.         // in case folder name has weird control characters 
  205.         HBufC* pFixedText = CHXAvMisc::AllocDisplayFriendlyStringL(info.GetDisplayText());
  206.         AUTO_PUSH_POP_DEL(pFixedText);
  207.         m_titlePane->SetTextL(*pFixedText);
  208.     }
  209.     UpdateMenuBar();
  210.     Cba()->DrawNow();
  211.     m_spWindow->UpdateTopAndBottomL();
  212. }
  213. /////////////////////////////////////
  214. // set menu bar, depending on whether or not current window
  215. // view represents a valid (accessible) drive or not
  216. void CHXAvFileView::UpdateMenuBar()
  217. {
  218.     TInt idMenuBar = m_spWindow->GetStore() ? R_AVP_FILE_VIEW_MENU_BAR : R_AVP_FILE_VIEW_NODRIVE_MENU_BAR;
  219.     MenuBar()->SetMenuTitleResourceId(idMenuBar);
  220. }
  221. /*
  222.  * CreateViewWindowForActivatingViewL
  223.  * -------------------
  224.  * Construct view window needed for active view
  225.  *
  226.  */
  227. CCoeControl* CHXAvFileView::CreateViewWindowForActivatingViewL()
  228. {
  229.     DPRINTF(SYMP_INFO, ("CHXAvFileView::CreateViewWindowForActivatingViewL()n"));
  230.     if (!m_spWindow)
  231.     {
  232.         m_spWindow = new (ELeave) CHXAvFileViewWindow();
  233.         HX_ASSERT(m_spPageInfo);        
  234.         m_spWindow->ConstructL(ClientRect(), m_playerUI, this, m_spPageInfo, m_idxInitPage);
  235.     }
  236.     return m_spWindow.raw_ptr();
  237. }
  238. /*
  239.  * FinishViewDeactivateL
  240.  * ---------------------
  241.  *
  242.  */
  243. void CHXAvFileView::FinishViewDeactivateL()
  244. {
  245.     DPRINTF(SYMP_INFO, ("CHXAvFileView::FinishViewDeactivateL()n"));
  246.     if( m_spWindow )
  247.     {
  248.         // remember the index of the page that is currently visible
  249.         m_idxInitPage = m_spWindow->GetCurrentPageIndex();
  250.         HX_ASSERT(m_idxInitPage >= 0);
  251.         m_spWindow->SaveCurrentPageInfoL();
  252.         m_spWindow = 0; 
  253.     }
  254.  
  255. /* 
  256.  * DynInitMenuPaneL
  257.  * ----------------
  258.  * Called when a menu pane is about to be displayed.
  259.  *
  260.  */
  261. void
  262. CHXAvFileView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
  263. {
  264.     HX_ASSERT(m_spWindow);
  265.     switch (aResourceId)
  266.     {
  267. case R_AVP_FILE_VIEW_MENU_PANE:
  268.     InitMainMenuPaneL(aMenuPane);
  269.     break;
  270. case R_AVP_MARK_MENU_PANE:
  271.     InitMarkMenuPaneL(aMenuPane);
  272.     break;
  273.         case R_AVP_OPEN_MENU_PANE:
  274.             InitOpenMenuPaneL(aMenuPane);
  275.     break;
  276.         case R_SENDUI_MENU:
  277.     m_spSendAppUi->DisplaySendCascadeMenuL(*aMenuPane);
  278.     break;
  279.         case R_AVP_FILE_VIEW_NODRIVE_MENU_PANE:
  280.             aMenuPane->SetItemDimmed(EUnlockDrive, !m_spWindow->IsDriveLocked());
  281.             CHXAvMisc::InitDebugMenuItemsL(aMenuPane);
  282.             CHXAvMisc::InitHelpMenuItem(aMenuPane);
  283.             break;
  284.         default:
  285.             break;
  286.     }
  287. }
  288. /*
  289.  * InitMainMenuPaneL
  290.  * -----------------
  291.  * Main menu is set up here.
  292.  *
  293.  */
  294. void 
  295. CHXAvFileView::InitMainMenuPaneL(CEikMenuPane* pPane)
  296. {
  297.     HX_ASSERT(m_spSendAppUi);
  298.     //
  299.     // note:
  300.     //
  301.     // only files can be marked
  302.     // any items marked -> selection applies to marks
  303.     // no items marked -> selection applies to hilight item
  304.     //
  305.     bool bItemsAreMarked = m_spWindow->GetMarkedItemCount() > 0;
  306.     bool bAtLeastOneItemSelected = bItemsAreMarked || m_spWindow->HasHilightItem();
  307.     bool bSingleItemSelected = m_spWindow->HasHilightItem() && !bItemsAreMarked;
  308.     bool bSingleFileSelected = bSingleItemSelected && m_spWindow->HilightItemIsFile();
  309.     bool bSingleFolderSelected = bSingleItemSelected && !m_spWindow->HilightItemIsFile();
  310.     bool bOneOrMoreFilesSelected = bItemsAreMarked || bSingleFileSelected;
  311.     bool bAtLeastOneFileInView = !m_spWindow->IsEmpty() && (m_spWindow->GetUnmarkedItemCount() + m_spWindow->GetMarkedItemCount() > 0);
  312.     bool bPlaylistItemSelected = bSingleFileSelected && m_spWindow->HilightItemIsPlaylist();
  313.     
  314.     
  315.     pPane->SetItemDimmed(EPlay, !bSingleFileSelected);
  316.     pPane->SetItemDimmed(EOpenFolder, !bSingleFolderSelected);
  317.     pPane->SetItemDimmed(EDelete, !bAtLeastOneItemSelected);
  318.     pPane->SetItemDimmed(EMarkCascade, !bAtLeastOneFileInView);
  319.     pPane->SetItemDimmed(ERename, !bSingleItemSelected);
  320.     pPane->SetItemDimmed(EMoveToFolder, !bOneOrMoreFilesSelected);
  321.     pPane->SetItemDimmed(ECopyToFolder, true /*!bOneOrMoreFilesSelected*/); //XXXLCM
  322.     pPane->SetItemDimmed(EEditPlaylist, !bPlaylistItemSelected);
  323.     //pPane->SetItemDimmed(EViewInfo, !bSingleFileSelected);
  324.     // enable create folder item only if page allows it at current level
  325.     pPane->SetItemDimmed(ENewFolder, !m_spWindow->IsCreateChildFolderAllowed());
  326.     if (bOneOrMoreFilesSelected)
  327.     {
  328. // send
  329. TSendingCapabilities caps(0, 1024,
  330.   TSendingCapabilities::ESupportsAttachments );
  331. TInt pos = 0;
  332. pPane->ItemAndPos(EMarkCascade, pos);
  333. m_spSendAppUi->DisplaySendMenuItemL(*pPane, pos + 1, caps);
  334. // add to pinboard
  335. //m_playerUI->PinbModel().AddLinkMenuItemL(*pPane, ECmdSendVia);
  336.     }
  337.     CHXAvMisc::InitDebugMenuItemsL(pPane);
  338.     CHXAvMisc::InitHelpMenuItem(pPane);
  339.    
  340. }
  341. /*
  342.  * InitMarkMenuPaneL
  343.  * -----------------
  344.  * Marked items menu.
  345.  *
  346.  */ 
  347. void 
  348. CHXAvFileView::InitMarkMenuPaneL(CEikMenuPane* pPane)
  349. {
  350.     HX_ASSERT(!m_spWindow->IsEmpty());
  351.     // we can unmark the hilight item if it is marked
  352.     pPane->SetItemDimmed(EAknCmdUnmark, !m_spWindow->HilightItemIsMarked());
  353.     // we can mark the hilight item if it is a file (and unmarked)
  354.     TBool bMarkable = !m_spWindow->HilightItemIsMarked() &&
  355. m_spWindow->HilightItemIsFile();
  356.     pPane->SetItemDimmed(EAknCmdMark, !bMarkable);
  357.     TBool bHasMarkedItems = m_spWindow->GetMarkedItemCount() > 0;
  358.     TBool bHasUnMarkedMarkableItems = m_spWindow->GetUnmarkedItemCount() > 0;
  359.     pPane->SetItemDimmed(EAknMarkAll, !bHasUnMarkedMarkableItems);
  360.     pPane->SetItemDimmed(EAknUnmarkAll, !bHasMarkedItems);
  361. }
  362. /*
  363.  * InitOpenMenuPaneL
  364.  * -----------------
  365.  * Open menu items.
  366.  *
  367.  */
  368. void 
  369. CHXAvFileView::InitOpenMenuPaneL(CEikMenuPane* pPane)
  370. {
  371.     // see if the guide exists
  372.     const TDesC& guide = m_playerUI->GetGuideUrlL(true);
  373.     bool bGuideExists = (guide.Length() > 0);
  374.     // only show 'open guide' if guide home page exists
  375.     pPane->SetItemDimmed(EOpenGuide, !bGuideExists);
  376.     // only show 'open recent' if at least one recent clip exists
  377.     pPane->SetItemDimmed(EOpenRecentDialog, (m_playerUI->GetRecentClipCount() == 0));
  378. }