chxavfileviewwindow.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:52k
- /************************************************************************
- * chxCHXAvFileViewWindow.cpp
- * -----------------------
- *
- * Synopsis:
- * Contains the implementation of the CHXAvFileViewWindow. This is the class
- * that implements the object that is controlled by the CHXAvFileView
- * object. This class creates and manages the actual controls of the file
- * view.
- *
- * Target:
- * Symbian OS
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- ************************************************************************/
- // Standard includes...
- #include <eiklbo.h>
- #include <aknlists.h>
- #include <coemain.h>
- #include <coeutils.h>
- #include <akntabgrp.h>
- #include <akntabgrp.h>
- #include <aknnavide.h>
- #include <akntitle.h>
- #include <aknsfld.h>
- #include <aknutils.h>
- #include <akniconarray.h>
- #include <aknselectionlist.h>
- #include <eikfutil.h>
- #include <f32file.h> // TSwitch, CFileMan
- #include <barsread.h> //TResourceReader
- #include <SenduiMtmUids.h>
- #include <sendui.h>
- #include <SendNorm.rsg>
- // Helix includes...
- #include "hxassert.h"
- #include "ihxpckts.h"
- #include "hxstring.h"
- #include "hxurl.h"
- // Includes from this project...
- #include "chxavcleanupstack.h"
- #include "chxavfileviewwindow.h"
- #include "chxavnamedisplaytrait.h"
- #include "chxavfileview.h"
- #include "chxavramparser.h"
- #include "hxsym_debug.h"
- #include "hxsym_leaveutil.h"
- #include "hxsym_mmc_utils.h"
- #include "chxavcleanstring.h"
- #include "chxavurlrep.h"
- #include "chxavfolderdisplayinfo.h"
- #include "chxavmediafolderinfo.h"
- #include "chxavplayerui.h"
- #include "chxavfileutil.h"
- #include "chxavplayer.h"
- #include "chxavplaylist.h"
- #include "realplayer.hrh"
- #include "realplayer.rsg"
- #include "player_uids.h"
- #include "chxavurlrep.h"
- #include "realplayer.mbg"
- #include "r1p.hlp.hrh"
- namespace
- {
- // Order is important! must match TFileViewIconImageIds
- CHXAvMisc::ImageInfo const theirListBoxIcons[] =
- {
- // mark icon must be first
- { EMbmAvkonQgn_indi_marked_grid_add, EMbmAvkonQgn_indi_marked_grid_add_mask }, // EMarkIcon
- { EMbmAvkonQgn_prop_folder_large, EMbmAvkonQgn_prop_folder_large_mask }, // EFolderIcon
- { EMbmAvkonQgn_prop_group_large, EMbmAvkonQgn_prop_group_large_mask } // EVideosFolderIcon
- };
- CHXAvMisc::ImageInfo const ourListBoxIcons[] =
- {
- { EMbmRealplayerQgn_prop_media_sub, EMbmRealplayerQgn_prop_media_sub_mask }, // EMediaIcon
- { EMbmRealplayerQgn_prop_network_sub, EMbmRealplayerQgn_prop_network_sub_mask } // EPlaylistIcon
- };
- // these must match order of icons above; localized folder ids specified in .rss (not here)
- TInt ToImageIndex(CHXAvFile::FileType type)
- {
- HX_ASSERT(type != CHXAvFile::ftUnknown);
- switch(type)
- {
- case CHXAvFile::ftRam:
- // playlist icon
- return EPlaylistIcon;
- case CHXAvFile::ftLink:
- // link icon
- return EPlaylistIcon;
- case CHXAvFile::ftFolder:
- // folder icon
- return EFolderIcon;
- default:
- // media icon for everything else
- return EMediaIcon;
- }
- }
- } // local
- /*
- * CHXAvFileViewWindow
- * -------------------
- * constructor
- *
- */
- CHXAvFileViewWindow::CHXAvFileViewWindow()
- : CHXAvNameDisplayTrait(true)
- , m_pListBox(0)
- , m_pFileView(0)
- , m_playerUI(0)
- , m_wpNaviPane(0)
- , m_wpTabGroup(0)
- , m_bHideTabs(false)
- , m_shiftMarkState(smNotMarking)
- {
- }
- /*
- * ~CHXAvFileViewWindow
- * --------------------
- * Dtor.
- *
- */
- CHXAvFileViewWindow::~CHXAvFileViewWindow()
- {
- HX_DELETE(m_pListBox);
- CleanUpTabs();
- }
- /*
- * CleanUpTabs
- * -----------
- *
- */
- void CHXAvFileViewWindow::CleanUpTabs()
- {
- if(m_wpNaviPane)
- {
- if(m_spDecoratedTabGroup)
- {
- // restore navipane
- m_wpNaviPane->Pop(m_spDecoratedTabGroup.Ptr());
- }
- m_wpNaviPane = 0;
- }
- m_spDecoratedTabGroup = 0;
- m_wpTabGroup = 0;
- }
- /*
- * CreateTabsL
- * -----------
- *
- */
- void
- CHXAvFileViewWindow::CreateTabsL(TInt idxInitTab)
- {
- if(0 == m_wpNaviPane)
- {
- // get handle to the navi pane control
- CEikStatusPane* pStatusPane = iEikonEnv->AppUiFactory()->StatusPane();
- m_wpNaviPane
- = static_cast<CAknNavigationControlContainer*>(
- pStatusPane->ControlL(TUid::Uid(EEikStatusPaneUidNavi)) );
- }
- // create tab group control to decorate navi pane
- m_spDecoratedTabGroup = m_wpNaviPane->CreateTabGroupL();
- m_wpTabGroup
- = static_cast<CAknTabGroup*>(m_spDecoratedTabGroup->DecoratedControl());
- // two tabs
- const TInt tabWidthFlag = EAknTabWidthWithTwoTabs;
- m_wpTabGroup->SetTabFixedWidthL(tabWidthFlag);
- // create tabs for tab control
- TInt count = m_spPageInfo->Nelements();
- for(TInt idx = 0; idx < count; ++idx)
- {
- CHXAvFileViewPageInfoPtr pInfo = (*m_spPageInfo)[idx];
- CHXAvMisc::ImageInfo imgInfo = pInfo->GetTabInfo();
- CHXAvMisc::AddTabL(m_wpTabGroup, pInfo->GetTabImageFilePath(), idx, imgInfo.idxImg, imgInfo.idxImgMask);
- }
- // activate the default tab
- m_wpTabGroup->SetActiveTabByIndex(idxInitTab);
-
- }
- ////////////////////////////////////////////////////////////////////
- //
- void CHXAvFileViewWindow::UpdateTopAndBottomL()
- {
- UpdateNaviPaneL();
- CHXAvMisc::UpdateScrollBar(m_pListBox);
- }
- ////////////////////////////////////////////////////////////////////
- //
- void CHXAvFileViewWindow::UpdateNaviPaneL()
- {
- DPRINTF(SYMP_INFO, ("CHXAvFileViewWindow::UpdateNaviPaneL()n"));
- if(m_wpNaviPane)
- {
- if(m_spDecoratedTabGroup && !m_bHideTabs)
- {
- m_wpNaviPane->PushL(*m_spDecoratedTabGroup);
- }
- else
- {
- m_wpNaviPane->PushDefaultL();
- }
- }
- }
- ////////////////////////////////////////////////////////////
- // called when drive state changed (or may have changed)
- void CHXAvFileViewWindow::ReloadCurrentPageL()
- {
- LoadPageL(m_wpTabGroup->ActiveTabIndex());
- }
- ////////////////////////////////////////////////////////////
- // called when drive goes away or current folder goes aways
- void CHXAvFileViewWindow::ResetCurrentPageInfoToRootL()
- {
- m_spCurrentPage->Indexes().RemoveAll();
- m_spCurrentPage->SetCurrentIndex(0);
- m_spCurrentPage->FolderInfo()->SetCurrentPathL(KNullDesC);
- }
- ////////////////////////////////////////////////////////////
- //
- // update drive state and reset page related data that may be
- // invalidated by the change
- //
- // return 'true' if page needs to be rebuilt (because state has changed)
- //
- bool CHXAvFileViewWindow::DoUpdateAndCheckDriveStateL()
- {
- // query drive for current state info
- CHXAvMediaFolderInfo* pFolderInfo = m_spCurrentPage->FolderInfo();
- TUint32 flags = pFolderInfo->UpdateDriveInfoCheckState();
- if( flags & CHXAvMediaFolderInfo::VOLID_CHANGED )
- {
- // volume id has changed since we last looked at this drive
- // reset current path and folder index stack - they apply
- // to a different drive volume
- ResetCurrentPageInfoToRootL();
- }
- return flags != 0;
- }
- ////////////////////////////////////////////////////////////
- //
- // set current page and re-build view to reflect contents of the page
- //
- void CHXAvFileViewWindow::LoadPageL(TInt idxPage)
- {
- HX_ASSERT(idxPage >= 0);
- HX_ASSERT(idxPage < m_spPageInfo->Nelements());
- m_spCurrentPage = (*m_spPageInfo)[idxPage];
- // make sure drive info is up-to-date (handle case of removable drive)
- DoUpdateAndCheckDriveStateL();
- // handle case where saved current path info becomes invalid
- // since we last displayed it (external delete/rename); invalid
- // root handled by file store init
- if(!m_spCurrentPage->FolderInfo()->IsCurrentPathValid())
- {
- ResetCurrentPageInfoToRootL();
- }
- // set text to show if view is empty
- InitEmptyListTextL();
- // init file store model and ui helpers
- InitFileStoreL();
- // init listbox contents
- TInt idxCurrent = m_spCurrentPage->GetSelectedItemIndex();
- RefreshListBoxL(idxCurrent);
-
- // title, navipane, etc.
- m_pFileView->UpdateViewStateL();
- DrawNow();
-
- }
- ////////////////////////////////////////////////////////////
- // LoadPageL() helper
- //
- // re-init file store (and related file ui)
- //
- // assumes drive info is up-to-date
- //
- void CHXAvFileViewWindow::InitFileStoreL()
- {
- m_spStore = 0;
- m_spFileUI = 0;
- CHXAvMediaFolderInfo* pFolderInfo = m_spCurrentPage->FolderInfo();
- const CHXAvFile::DriveInfo info = pFolderInfo->GetDriveInfo();
- // only create a file store if drive is accessible
- if( CHXAvFile::dsAccessible == info.state )
- {
- //
- // re-create file store (for underlying access to associated
- // media folder) and ui handler
- //
- m_spStore = new (ELeave) CHXAvFileStore();
- // trap in case path/drive is bad somehow
- TRAPD(err,
- m_spStore->ConstructL(
- pFolderInfo->GetRoot(),
- pFolderInfo->GetCurrentPath(),
- m_spCurrentPage->IsAutoCreateRoot()) );
- if(KErrNone == err)
- {
- m_spFileUI = new (ELeave) CHXAvFileUI();
- m_spFileUI->ConstructL(m_playerUI, m_spStore);
- // stop watching for drive events (store will watch for us)
- m_fsWatcher.StopWatching();
- // request file system events from file store
- CHXAvCompositeCommand& handler = m_spStore->GetEventHandler();
- CHXAvCommand& cmd = MakeCommand(this, &CHXAvFileViewWindow::OnFileSystemEvent);
- handler.AppendL(cmd);
- }
- else
- {
- // abandon these
- m_spStore = 0;
- m_spFileUI = 0;
- // don't leave; default to inaccessible media store state
- CHXAvMessageDialog::DoAlertInfoL(CHXAvCleanString(R_ERR_OPEN_FOLDER_FAILED)());
- }
- }
- if( !m_spStore )
- {
- // normally store watches for us; in this case we want to detect
- BeginWatchingForDriveEventsL();
- }
-
- }
- ////////////////////////////////////////////////////////////
- // LoadPageL() helper
- //
- // set text to display when page is empty (empty folder or invalid drive)
- //
- // assumes drive info is up-to-date
- //
- void CHXAvFileViewWindow::InitEmptyListTextL()
- {
- DPRINTF(SYMP_INFO, ("CHXAvFileViewWindow::InitEmptyListTextL()n"));
- TInt idEmptyList = R_AVP_FILE_FOLDER_EMPTY_TEXT;
- CHXAvMediaFolderInfo* pFolderInfo = m_spCurrentPage->FolderInfo();
- const CHXAvFile::DriveInfo info = pFolderInfo->GetDriveInfo();
- if( pFolderInfo->IsMmcFolder() )
- {
- // non-accessible text only applies to mmc (unexpected for flash)
- switch( info.state )
- {
- case CHXAvFile::dsAccessible:
- idEmptyList = R_AVP_FILE_FOLDER_EMPTY_TEXT;
- break;
- case CHXAvFile::dsCorrupted:
- idEmptyList = R_AVP_MMC_CORRUPT;
- break;
- case CHXAvFile::dsLocked:
- idEmptyList = R_AVP_MMC_LOCKED;
- break;
- default:
- idEmptyList = R_AVP_MMC_NOT_INSERTED;
- break;
- }
- }
- m_pListBox->View()->SetListEmptyTextL(CHXAvCleanString(idEmptyList)());
- }
- ////////////////////////////////////////////////////////////
- // called when no store for current page
- void CHXAvFileViewWindow::BeginWatchingForDriveEventsL()
- {
- HX_ASSERT(!m_spStore);
- // watch all drives; we can't specify an actual drive
- m_fsWatcher.SetWatchPathL(KNullDesC);
- m_fsWatcher.SetNotifyType(ENotifyAll);
-
- // delay notifications to minimize potential for receiving flood of events
- m_fsWatcher.SetNotificationDelay(2000);
- m_fsWatcher.StartWatching();
- }
- /*
- * ConstructL
- * ----------
- *
- */
- void CHXAvFileViewWindow::ConstructL(const TRect& rc, CHXAvPlayerUI* pPlayerUi, CHXAvFileView* pFileView,
- const refptr<CHXAvFileViewPageInfoVector>& spPageInfo,
- TInt idxCurrentPage)
- {
- HX_ASSERT(pPlayerUi);
- HX_ASSERT(pFileView);
- HX_ASSERT(spPageInfo);
- HX_ASSERT(spPageInfo->Nelements() > 0);
- HX_ASSERT(idxCurrentPage < spPageInfo->Nelements());
- m_playerUI = pPlayerUi;
- m_pFileView = pFileView;
- m_spPageInfo = spPageInfo;
- // callback to rebuild current page after drive goes away
- const CHXAvCommand& cmd =
- MakeCommand(this, &CHXAvFileViewWindow::ReloadCurrentPageL);
- m_cbReloadPage.ConstructL(cmd);
- // for watching for mount events (when no store for current drive)
- m_fsWatcher.ConstructL();
- m_fsWatcher.SetEventActionL(MakeCommand(this, &CHXAvFileViewWindow::OnFileSystemEvent));
- // create main view window and listbox
- CreateWindowL();
- CreateFileViewListBoxL();
- SetRect(rc);
- // only create tabs if there is more than one storage location
- if(m_spPageInfo->Nelements() > 1)
- {
- CreateTabsL(idxCurrentPage);
- }
- // build and show initial page
- LoadPageL(idxCurrentPage);
- ActivateL();
- }
- ////////////////////////////////////////////////////////////
- // called when we receive notification that something has
- // changed on the file system (and we know it isn't for an
- // mmc drive swap); since filesystem event notification does
- // not specify exactly what changed, we act as through current
- // directory view must be updated
- //
- void CHXAvFileViewWindow::HandlePossibleCurrentFolderChangeL()
- {
- HX_ASSERT(m_spStore);
- // check possibility that current store path (current folder in view)
- // has been deleted or renamed
- if(CHXAvFile::PathExists(m_spStore->GetFullPath()))
- {
- // assume current folder needs updating (hard to tell for sure)
- TInt idxHilight = m_pListBox->CurrentItemIndex();
- if( idxHilight >= 0 ) // -1 == empty
- {
- //
- // get name of last item hilighted; we want to keep it
- // hilighted (if possible) as contents of directory change
- // from external fs events; we need to copy it
- // since RefreshListBoxL() updates the entry list
- //
- const CHXAvFileStore::Entries& entries = m_spStore->GetEntries();
- HX_ASSERT(idxHilight < entries.Nelements());
- const TEntry& entry = entries[idxHilight].m_entry;
- HBufC* pSearchName = entry.iName.AllocL();
- AUTO_PUSH_POP_DEL(pSearchName);
- RefreshListBoxL(idxHilight, *pSearchName);
- }
- else
- {
- // nothing was previously hilighted
- RefreshListBoxL();
- }
- }
- else
- {
- // reload current page; we could be smarter and try to go up to parent
- ResetCurrentPageInfoToRootL();
- m_cbReloadPage.Set(1);
- }
- }
- ////////////////////////////////////////////////////////////
- // usually called when store detects an generated event; when
- // store does not exist (because drive/path not present), we
- // watch for possible drive mount/unmount events via our own
- // filesystem watcher (and may receive events that way)
- //
- void CHXAvFileViewWindow::OnFileSystemEvent()
- {
- DPRINTF(SYMP_FILE, ("CHXAvFileViewWindow::OnFileSystemEvent(): something changed...n"));
- TRAPD(err, HandleFileSystemEventL());
- DPRINTF(SYMP_FILE, ("CHXAvFileViewWindow::OnFileSystemEvent(): handler err = %ldn", err));
- }
- // OnFileSystemEvent helper
- void CHXAvFileViewWindow::HandleFileSystemEventL()
- {
- bool bStateChanged = DoUpdateAndCheckDriveStateL();
- if( !m_spStore )
- {
- DPRINTF(SYMP_INFO, ("OnFileSystemEvent(): no store; drive added?"));
-
- // previously unavailable drive possibly mounted
- if( bStateChanged )
- {
- // drive state for current page has changed; rebuild everything
- ReloadCurrentPageL();
- }
- }
- else
- {
- if(bStateChanged)
- {
- // current drive state has changed (possibly unmounted);since
- // we handle this by possibly destroying the (now invalid) current
- // store, which is calling us here, we handle this in a separate callback
- m_cbReloadPage.Set(1);
- }
- else
- {
- // update contents (if current drive is accessible)
- CHXAvMediaFolderInfo* pFolderInfo = m_spCurrentPage->FolderInfo();
- const CHXAvFile::DriveInfo info = pFolderInfo->GetDriveInfo();
- if( CHXAvFile::dsAccessible == info.state )
- {
- // we don't know for sure that this event affects our view (we assume it does)
- HandlePossibleCurrentFolderChangeL();
- }
- }
- }
- }
- ////////////////////////////////////////////////////
- //
- bool CHXAvFileViewWindow::HilightItemIsPlaylist() const
- {
- TInt idxItem = m_pListBox->CurrentItemIndex();
- const CHXAvFile::FileInfo& info = GetFileInfoL(idxItem);
- bool bIsPlaylist = (info.m_type == CHXAvFile::ftRam || info.m_type == CHXAvFile::ftLink);
- if(bIsPlaylist)
- {
- // verify that playlist is well-formed by attempting to parse it
- CHXAvPlaylistPtr spList = CreatePlaylist(info.m_entry);
- if( !spList || 0 == spList->Length() )
- {
- // corrupt or otherwise not-editable
- bIsPlaylist = false;
- }
- }
- return bIsPlaylist;
- }
- ////////////////////////////////////////////////////
- // true if current item corresponds to a file
- bool CHXAvFileViewWindow::HilightItemIsFile() const
- {
- TInt idxItem = m_pListBox->CurrentItemIndex();
- const CHXAvFile::FileInfo& info = GetFileInfoL(idxItem);
- return !info.m_entry.IsDir();
- }
- ////////////////////////////////////////////////////
- // return true if hilighted item is in the mark list
- bool CHXAvFileViewWindow::HilightItemIsMarked() const
- {
- const CArrayFix<TInt>* pSelectedItems =
- m_pListBox->SelectionIndexes();
- TInt idxItem = m_pListBox->CurrentItemIndex();
- HX_ASSERT(idxItem != -1); // call HasHilightItem() first
- for(TInt idx = 0; idx < pSelectedItems->Count(); ++idx)
- {
- if (idxItem == (*pSelectedItems)[idx])
- {
- // index was in the list and therefore marked
- return true;
- }
- }
- return false;
- }
- ////////////////////////////////////////////////////////////
- // get an in-range index closest to idxWanted
- //
- // return:
- //
- // -1 if list is empty
- // idx of last item if wanted index is beyond the last item
- // idxWanted if it is in range
- //
- TInt CHXAvFileViewWindow::GetBestIndex(TInt idxWanted) const
- {
- HX_ASSERT(idxWanted >= 0);
- // make sure best index is valid; just in case
- TInt idxBest = (idxWanted >= 0) ? idxWanted : 0;
- TInt itemCount = m_pListBox->Model()->NumberOfItems();
- if( idxBest >= itemCount )
- {
- // wanted index is invalid (beyond last item)
- if( itemCount > 0)
- {
- // next best is last item
- idxBest = itemCount - 1;
- }
- else
- {
- // empty list
- idxBest = -1;
- }
- }
- return idxBest;
- }
- //
- // args:
- //
- // currentItemName - if not empty, we try to set current index to item that matches this name
- // if specified, must be provided in full significant name format, e.g. "foo.rm"
- //
- // idxLastCurrentItem - preserve index at last or closest to last current item if preferred name
- // not mathched or specified
- //
- void
- CHXAvFileViewWindow::SetListBoxSelectionAndDrawL(TInt idxLastCurrentItem,
- const TDesC& currentItemName)
- {
- HX_ASSERT(m_pListBox);
- HX_ASSERT(m_spStore);
- m_pListBox->Reset();
- m_pListBox->ClearSelection();
-
- // ensure zero (not -1) if no current item
- idxLastCurrentItem = max(idxLastCurrentItem, 0);
- // determine current hilight item
- TInt idxCurrent = -1;
- if(currentItemName.Length() > 0)
- {
- // trim possible folder suffix (entries don't keep suffix in name)
- TPtrC ptrName = CHXAvFile::GetEnsureNoFolderSuffix(currentItemName);
-
- // see if we can find a match for the given name
- const CHXAvFileStore::Entries& entries = m_spStore->GetEntries();
- for(TInt idx = 0; idx < entries.Nelements(); ++idx)
- {
- const TEntry& entry = entries[idx].m_entry;
- if (0 == entry.iName.CompareF(ptrName))
- {
- // found it
- idxCurrent = idx;
- break;
- }
- }
- }
- if( idxCurrent == -1 )
- {
- idxCurrent = GetBestIndex(idxLastCurrentItem);
- }
- // check again...
- if( idxCurrent >= 0 ) // -1 = empty
- {
- HX_ASSERT(idxCurrent < m_pListBox->Model()->NumberOfItems());
- m_pListBox->SetCurrentItemIndex(idxCurrent);
- }
-
- CHXAvMisc::UpdateScrollBar(m_pListBox);
- m_pListBox->DrawNow();
- }
- ////////////////////////////////////////////////////////////
- // rebuild and redraw listbox contents
- //
- void
- CHXAvFileViewWindow::RefreshListBoxL(TInt idxLastCurrentItem,
- const TDesC& currentItemName)
- {
- HX_ASSERT(m_spStore);
-
- // create new list of items and transfer ownership to the listbox
- CDesCArrayFlat* pItems = CreateListItemsL();
- AUTO_PUSH_POP(pItems);
- CTextListBoxModel* pModel = m_pListBox->Model();
- pModel->SetItemTextArray(pItems);
- pModel->SetOwnershipType(ELbmOwnsItemArray);
-
- SetListBoxSelectionAndDrawL(idxLastCurrentItem, currentItemName);
- }
- ////////////////////////////////////////////////////
- // allocate list box item text for given folder entry
- //
- //
- // main text: folder name
- // sub text : count of contents
- //
- HBufC*
- CHXAvFileViewWindow::AllocFolderItemTextL(const TEntry& entry) const
- {
- HX_ASSERT(entry.IsDir());
-
- // create full path to this folder
- TParse parse;
- parse.Set(m_spStore->GetFullPath(), 0, 0);
- parse.AddDir(entry.iName); // iName relative to base path (does not start with '/')
- // find folder child count (nanoplayer files + child folders)
- TInt childCount = 0;
- const bool bIncludeFolders = true;
- HXSYM_LEAVE_IF_ERR(
- CHXAvFile::GetFolderChildCount(parse.FullName(), childCount,
- bIncludeFolders, CHXAvFile::FilterIncludeNanoPlayerFiles));
-
- _LIT(KSubTextFormat, "%d");
- TBuf<40> bufSubText;
- bufSubText.Format(KSubTextFormat, childCount);
- // this handles localized dirs that may be on mmc
- CHXAvFolderDisplayInfo displayInfo;
- displayInfo.SetFolderPathL(parse.FullName());
- HBufC* pItemText = CHXAvMisc::AllocGrListItemL(displayInfo.GetDisplayText(), bufSubText, ToImageIndex(CHXAvFile::ftFolder));
-
- return pItemText;
- }
- ////////////////////////////////////////////////
- // try to create playlist object for given file entry
- CHXAvPlaylistPtr
- CHXAvFileViewWindow::CreatePlaylist(const TEntry& entry) const
- {
- HX_ASSERT(!entry.IsDir());
- // get full path to this file
- TFileName* pPath = CHXAvFile::AllocFileNameL(m_spStore->GetFullPath(), entry.iName);
- AUTO_PUSH_POP_DEL(pPath);
- CHXString strPath;
- CHXAvStringUtils::DesToString(*pPath, strPath);
- // try to parse it as a ram file
- return CHXAvRAMParser::Parse(strPath);
- }
- ////////////////////////////////////////////////
- //
- HBufC*
- CHXAvFileViewWindow::AllocPlayListDescriptionL(const CHXAvFile::FileInfo& info) const
- {
- HX_ASSERT(info.m_type == CHXAvFile::ftRam || info.m_type == CHXAvFile::ftLink);
- HBufC* pListText = 0;
- TInt count = 0;
- CHXAvPlaylistPtr spPlaylist = CreatePlaylist(info.m_entry);
- if( spPlaylist)
- {
- // this is a ram file (or a convincing imposter)
- count = spPlaylist->Length();
-
- if (count == 1)
- {
- CHXAvPlaylistItr iter(*spPlaylist);
-
- // set display text to first and only playlist item
- const CHXAvURLRep& url = iter.Current();
- if( url.Host().GetLength() > 0 )
- {
- CHXAvCleanString text(url.Host());
- pListText = text().AllocL();
- }
- }
- }
-
- if(!pListText)
- {
- // set display text to count of items in playlist
- CHXAvCleanString text(R_AVP_LINK_COUNT, count);
- pListText = text().AllocL();
- }
- return pListText;
- }
- ////////////////////////////////////////////////////
- // allocate list box item text for given file entry
- //
- //
- // main text: file name
- // sub text : size in bytes if file/ url if ram link
- //
- HBufC*
- CHXAvFileViewWindow::AllocFileItemTextL(const CHXAvFile::FileInfo& info) const
- {
- const TEntry& entry = info.m_entry;
- HX_ASSERT(!entry.IsDir());
- TFileName* pPath = CHXAvFile::AllocFileNameL(GetFullPath(),
- entry.iName);
- AUTO_PUSH_POP_DEL(pPath);
- HBufC* pInfoText = 0;
- if( (CHXAvFile::ftRam == info.m_type) || (CHXAvFile::ftLink == info.m_type) )
- {
- // show playlist description
- pInfoText = AllocPlayListDescriptionL(info);
- }
- else
- {
- // not a playlist file; show size
- pInfoText = CHXAvMisc::AllocFileSizeDescL(entry.iSize);
- }
- AUTO_PUSH_POP_DEL(pInfoText);
- NameExt pair = GetDisplayText(entry.iName);
- HBufC* pListText = CHXAvMisc::AllocGrListItemL(pair.first, *pInfoText, ToImageIndex(info.m_type));
- return pListText;
- }
- ////////////////////////////////////////////////////////////
- // allocate formatted list box items for current dircectory
- //
- void
- CHXAvFileViewWindow::AddListItemsForCurrentPathL(CDesCArrayFlat*& pItems) const
- {
- HX_ASSERT(m_spStore);
- // re-build local disk directory entry table
- const CHXAvFileStore::Entries& entries = m_spStore->UpdateEntriesL();
- TInt count = entries.Nelements();
- for(TInt idx = 0; idx < count; ++idx)
- {
- const CHXAvFile::FileInfo& info = GetFileInfoL(idx);
- const TEntry& entry = info.m_entry;
- // skip system/hidden files
- if(! CHXAvUtil::ShouldHideFromUser(entry) )
- {
- HBufC* pItemText = 0;
- // show only folders and files that we can play
- if (info.m_type == CHXAvFile::ftFolder)
- {
- pItemText = AllocFolderItemTextL(entry);
- }
- else if (CHXAvFile::IsNanoPlayerFileType(info.m_type))
- {
- pItemText = AllocFileItemTextL(info);
- }
-
- if (pItemText)
- {
- AUTO_PUSH_POP_DEL(pItemText);
- pItems->AppendL(*pItemText); // this copies buffer
- }
- }
- }
- }
- ////////////////////////////////////////////////////////////
- //
- // create array of listbox items (in list-box item format)
- // from current entry info
- //
- // list-box item format for double item large graphic listbox
- // is:
- //
- // [icon idx]t{item text}t{sub-text}
- //
- CDesCArrayFlat*
- CHXAvFileViewWindow::CreateListItemsL() const
- {
- CDesCArrayFlat* pItems = new (ELeave) CDesCArrayFlat(20 /*granularity*/);
- AUTO_PUSH_POP(pItems); // out
- if( m_spStore )
- {
- AddListItemsForCurrentPathL(pItems);
- }
-
- return pItems;
- }
- ////////////////////////////////////////////////////////////
- // 42 X 29 (their folder = 42 x 36; mark icon = 13 x 13) for large icons
- void CHXAvFileViewWindow::CreateAndAddIconsL()
- {
- CAknIconArray* pIcons = new (ELeave) CAknIconArray(3);
- AUTO_PUSH_POP(pIcons);
- // order is important!
- CHXAvMisc::AddIconHelperL(CHXAvMisc::KAVPAvkonImagePath, theirListBoxIcons, ARRAY_COUNT(theirListBoxIcons), pIcons);
- CHXAvMisc::AddIconHelperL(m_playerUI->GetAppImageFilePath(), ourListBoxIcons, ARRAY_COUNT(ourListBoxIcons), pIcons);
- // transfer icon array ownership to list box (CEikColumnListBox uses ColumnData())
- m_pListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL(pIcons);
- }
- ////////////////////////////////////////////////////////////
- // return full path to current folder
- const TDesC&
- CHXAvFileViewWindow::GetFullPath() const
- {
- if( m_spStore )
- {
- return m_spStore->GetFullPath();
- }
- return m_spCurrentPage->FolderInfo()->GetRoot();
- }
- /*
- * SyncToCurrentPageL
- * ------------------
- *
- */
- void
- CHXAvFileViewWindow::SyncToCurrentPageL()
- {
- m_spStore = 0;
- m_spFileUI = 0;
- TInt idEmptyList = R_AVP_FILE_FOLDER_EMPTY_TEXT;
- CHXAvMediaFolderInfo* pFolderInfo = m_spCurrentPage->FolderInfo();
- bool bIsMmc = pFolderInfo->IsMmcFolder();
- const CHXAvFile::DriveInfo info = pFolderInfo->GetDriveInfo();
- switch( info.state )
- {
- case CHXAvFile::dsAccessible:
- // normal case: accessible drive
- InitFileStoreL();
- idEmptyList = R_AVP_FILE_FOLDER_EMPTY_TEXT;
- break;
- case CHXAvFile::dsCorrupted:
- idEmptyList = bIsMmc ? R_AVP_MMC_CORRUPT : R_AVP_FILE_FOLDER_EMPTY_TEXT;
- break;
- case CHXAvFile::dsLocked:
- idEmptyList = bIsMmc ? R_AVP_MMC_LOCKED : R_AVP_FILE_FOLDER_EMPTY_TEXT;
- break;
- default:
- idEmptyList = bIsMmc ? R_AVP_MMC_NOT_INSERTED : R_AVP_FILE_FOLDER_EMPTY_TEXT;
- break;
- }
- m_pListBox->View()->SetListEmptyTextL(CHXAvCleanString(idEmptyList)());
- }
- ////////////////////////////////////////////
- // CCoeControl
- void CHXAvFileViewWindow::GetHelpContext(TCoeHelpContext& aContext) const
- {
- aContext = TCoeHelpContext( CHXAvMisc::KHelpUID, KRP_HLP_LIST );
- }
- /*
- * ComponentControl
- * ----------------
- * Return a pointer to the ith component of this control.
- *
- */
- CCoeControl *
- CHXAvFileViewWindow::ComponentControl(TInt aIndex) const
- {
- HX_ASSERT(0 == aIndex);
- return m_pListBox;
- }
- /*
- * CountComponentControls
- * ----------------------
- * Return the number of subcontrols in this control.
- *
- */
- TInt CHXAvFileViewWindow::CountComponentControls() const
- {
- return 1;
- }
- /*
- * SizeChanged
- * -----------
- * The size of this control has changed so adjust the child controls.
- *
- */
- void CHXAvFileViewWindow::SizeChanged()
- {
- TRect rc = Rect();
- if (m_pListBox)
- {
- m_pListBox->SetRect(rc);
- }
- }
- //////////////////////////////////////
- //
- // assumes we are using listbox with scrolling
- // loop (wrapping) behavior specified
- //
- TKeyResponse CHXAvFileViewWindow::HandleShiftMarkKeyL(TInt keyCode)
- {
- // default: consume arrow key so current item does not change
- TKeyResponse response = EKeyWasConsumed;
- const CHXAvFileStore::Entries& entries = m_spStore->GetEntries();
- TInt idxThis = m_pListBox->CurrentItemIndex();
- if( !entries[idxThis].m_entry.IsDir() )
- {
- TInt idxEnd = m_pListBox->Model()->NumberOfItems();
-
- TInt idxNext = idxThis + 1;
- if( idxNext >= idxEnd )
- {
- idxNext = 0;
- }
- TInt idxPrev = idxThis - 1;
- if( idxPrev < 0 )
- {
- idxPrev = idxEnd - 1;
- }
- TInt idxNextToSelect = (EKeyUpArrow == keyCode ? idxPrev : idxNext);
-
- if (!entries[idxNextToSelect].m_entry.IsDir())
- {
- // allow arrow key to pass to listbox so it changes current item
- response = EKeyWasNotConsumed;
- // mark current item
- if( m_shiftMarkState == smShiftMark )
- {
- m_pListBox->View()->SelectItemL(idxThis);
- }
- else
- {
- m_pListBox->View()->DeselectItem(idxThis);
- }
-
- // mark next item
- if( m_shiftMarkState == smShiftMark )
- {
- m_pListBox->View()->SelectItemL(idxNextToSelect);
- }
- else
- {
- m_pListBox->View()->DeselectItem(idxNextToSelect);
- }
- }
- }
- return response;
- }
- //////////////////////////////////////
- //
- TKeyResponse CHXAvFileViewWindow::HandleEventKeyEventL(const TKeyEvent& event)
- {
- TKeyResponse response = EKeyWasNotConsumed;
- DPRINTF(SYMP_WSEVENTS, ("CHXAvFileViewWindow::HandleEventKeyEventL(): event key: code = %dn", event.iCode));
- if( event.iModifiers & EModifierShift)
- {
- //
- // shift + key
- //
- switch( event.iCode )
- {
- case EKeyOK: // selection key
- case EKeyEnter: // 'enter' on keyboard
- DPRINTF(SYMP_WSEVENTS, ("CHXAvFileViewWindow::HandleEventKeyEventL(): shift + ok (or enter)n"));
- if( HasHilightItem() && HilightItemIsFile() )
- {
- TInt cmd = (HilightItemIsMarked() ? EAknCmdUnmark : EAknCmdMark);
- UserMarkL(cmd);
- response = EKeyWasConsumed;
- }
- break;
- case EKeyUpArrow:
- case EKeyDownArrow:
- DPRINTF(SYMP_WSEVENTS, ("CHXAvFileViewWindow::HandleEventKeyEventL(): shift + arrown"));
- response = HandleShiftMarkKeyL(event.iCode);
- break;
- default:
- break;
- }
- }
- else
- {
- //
- // key alone
- //
- switch( event.iCode )
- {
- case EKeyOK:
- case EKeyEnter:
- DPRINTF(SYMP_WSEVENTS, ("CHXAvFileViewWindow::HandleEventKeyEventL(): ok button clickn"));
- if(IsDriveLocked())
- {
- // do 'unlock drive' ui if current drive is locked
- UserUnlockDriveL();
- response = EKeyWasConsumed;
- } // else, see HandleListBoxEventL()
- break;
- case EKeyBackspace: // 0x0d ('c')
- case EKeyDelete: // 0x7f (keyboard delete)
- UserDeleteSelectedItemsL();
- response = EKeyWasConsumed;
- break;
- case EKeyLeftArrow:
- case EKeyRightArrow:
- //
- // these go to tab control
- //
- if( m_wpTabGroup )
- {
- if( EKeyWasConsumed == m_wpTabGroup->OfferKeyEventL(event, EEventKey) )
- {
- TInt idxTab = m_wpTabGroup->ActiveTabIndex();
- // save current folder in view and hilighted item before switching
- SaveCurrentPageInfoL();
- LoadPageL(idxTab);
- response = EKeyWasConsumed;
- }
- }
- break;
- default:
- break;
- }
- }
- //
- // give list box next crack (only for EEventKey, since
- // listbox always returns EKeyWasConsumed and we want
- // ignored keys to be forwarded to parent control
- //
- if( (EKeyWasNotConsumed == response) && m_pListBox )
- {
- response = m_pListBox->OfferKeyEventL(event, EEventKey);
- }
- return response;
- }
- /*
- * OfferKeyEventL
- * --------------
- * A key event is occurring.
- *
- */
- TKeyResponse CHXAvFileViewWindow::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
- {
- TKeyResponse response = EKeyWasNotConsumed;
- DPRINTF(SYMP_WSEVENTS, ("CHXAvFileViewWindow::OfferKeyEventL(): code = %d; sc = %dn", aKeyEvent.iCode, aKeyEvent.iScanCode));
- switch(aType)
- {
- case EEventKey:
- // see aKeyEvent.iCode
- response = HandleEventKeyEventL(aKeyEvent);
- break;
- case EEventKeyUp:
- // see aKeyEvent.iScanCode
- response = HandleKeyUpEventL(aKeyEvent);
- break;
- case EEventKeyDown:
- // see aKeyEvent.iScanCode
- response = HandleKeyDownEventL(aKeyEvent);
- break;
- default:
- /* do nothing */
- break;
- }
- return response;
- }
- /*
- * CreateFileViewListBoxL
- * ----------------------
- * Create the file view list box.
- *
- */
- void CHXAvFileViewWindow::CreateFileViewListBoxL()
- {
- HX_DELETE(m_pListBox);
-
- //
- // list entries for 'CAknDoubleLargeStyleListBox' should look like:
- //
- // {idxIcon}t{top text}t{bottom text}
- //
- // CEikColumnListBox derived
- m_pListBox = new (ELeave) CAknDoubleLargeStyleListBox();
- TInt flags = EAknGenericListBoxFlags | EAknListBoxMultipleSelection | EAknListBoxLoopScrolling;
- m_pListBox->ConstructL(this, flags);
- m_pListBox->SetMopParent(this);
- CreateAndAddIconsL();
- m_pListBox->CreateScrollBarFrameL( ETrue );
- m_pListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);
- m_pListBox->SetListBoxObserver(this);
- // set default message that is displayed when a folder is empty
- m_pListBox->View()->SetListEmptyTextL(CHXAvCleanString(R_AVP_FILE_FOLDER_EMPTY_TEXT)());
- m_pListBox->ActivateL();
- }
- ////////////////////////////////////////////
- // MEikListBoxObserver
- void CHXAvFileViewWindow::HandleListBoxEventL(CEikListBox* /*aListBox*/,TListBoxEvent aEventType)
- {
- DPRINTF(SYMP_INFO, ("CHXAvFileViewWindow::HandleListBoxEventL(): type = %dn", aEventType));
- if( aEventType == MEikListBoxObserver::EEventEnterKeyPressed ||
- aEventType == MEikListBoxObserver::EEventItemClicked )
- {
- // selection button was clicked; this is only called if an item is selected
-
- if(GetMarkedItemCount() == 0)
- {
- // open the hilighted item
- UserOpenCurrentItemL();
- }
- else
- {
- m_pFileView->HandleCommandL(EShowDefaultMenu);
- }
- }
- }
- ////////////////////////////////////////////////////////////
- // show contents of child folder
- //
- TInt CHXAvFileViewWindow::SwitchToChildFolderAndRefreshL(const TDesC& folder)
- {
- HX_ASSERT(m_spStore);
- TInt idxItem = m_pListBox->CurrentItemIndex();
- HX_ASSERT(idxItem != -1);
- TRAPD(err, m_spStore->SwitchToChildFolderL(folder));
- if(KErrNone == err)
- {
- //
- // remember the current index so we can re-set
- // to it in case user opts to return back to this
- // parent folder
- //
- HX_ASSERT(m_spCurrentPage);
- m_spCurrentPage->Indexes().Push((void *)idxItem);
- RefreshListBoxL();
- m_pFileView->UpdateViewStateL();
- }
- return err;
- }
- /*
- * UserOpenCurrentItemL
- * --------------------
- * Called by the user when they hit Play command in the file view.
- * We either open up the directory or play the file that is currently selected.
- *
- */
- void
- CHXAvFileViewWindow::UserOpenCurrentItemL()
- {
- HX_ASSERT(GetMarkedItemCount() == 0); // can't open when items are in selection list!
- TInt idxItem = m_pListBox->CurrentItemIndex();
- const TEntry& entry = GetFileInfoL(idxItem).m_entry;
- if( entry.IsDir())
- {
- // "open folder"
- TInt err = SwitchToChildFolderAndRefreshL(entry.iName);
- if(err != KErrNone)
- {
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_ERR_OPEN_FOLDER_FAILED)());
- // refresh current folder; perhaps view is out of sync with file system
- RefreshListBoxL(idxItem);
- }
- }
- else
- {
- // "open file"
- TFileName* pPath = CHXAvFile::AllocFileNameL(GetFullPath(), entry.iName);
- AUTO_PUSH_POP_DEL(pPath);
- HBufC* pUrl = CHXAvFile::AllocFileUrlL(*pPath);
- AUTO_PUSH_POP_DEL(pUrl);
- m_playerUI->ActivatePlayViewL(*pUrl);
- }
- }
- /*
- * GetFileInfoL
- * ------------
- * get file entry info for current item, with debug checks
- *
- */
- const CHXAvFile::FileInfo&
- CHXAvFileViewWindow::GetFileInfoL(TInt idx) const
- {
- HX_ASSERT(m_spStore);
- const CHXAvFileStore::Entries& entries = m_spStore->GetEntries();
- HX_ASSERT(idx >= 0);
- HX_ASSERT(idx < entries.Nelements());
- return entries[idx];
- }
- ////////////////////////////////////////////////////////////
- //
- void CHXAvFileViewWindow::UserSwitchToParentFolderAndRefreshL()
- {
- HX_ASSERT(m_spStore);
- HX_ASSERT(m_spCurrentPage);
- bool bAtRoot = m_spStore->IsAtRoot();
- HX_ASSERT(!bAtRoot);
-
- m_spStore->SwitchToParentFolderL();
- // get last index
- TInt idx = (TInt)(m_spCurrentPage->Indexes().TopOfStack());
- m_spCurrentPage->Indexes().Pop();
- RefreshListBoxL(idx);
- m_pFileView->UpdateViewStateL();
-
- }
- ////////////////////////////////////////////////////////////
- // prompt for a new folder and create it (relative to current path)
- //
- void CHXAvFileViewWindow::UserNewFolderL()
- {
- TInt err = m_spFileUI->DoNewFolderL(R_PROMPT_NEW_FOLDER_NAME);
- if(KErrNone == err)
- {
- // set focus to new folder item
- TPtrC ptrName = m_spFileUI->GetLastNewItemName();
- if( err != KErrNone )
- {
- ptrName.Set(KNullDesC);
- }
- TInt idxCurrent = m_pListBox->CurrentItemIndex();
- RefreshListBoxL(idxCurrent, ptrName);
- }
- }
- ////////////////////////////////////////////////////////////
- //
- // delete selected items, or delete current hilighted item
- //
- void CHXAvFileViewWindow::UserDeleteSelectedItemsL()
- {
- TInt idxHilightItem = m_pListBox->CurrentItemIndex();
- const CArrayFix<TInt>* pSelectedItems = m_pListBox->SelectionIndexes();
- //utVector<TInt> removeIndexes;
- TInt selectedCount = pSelectedItems->Count();
- TInt err = KErrCancel;
- if( selectedCount > 0)
- {
- // delete marked items
- err = m_spFileUI->DoDeleteItemsL(*pSelectedItems);
- }
- else if(idxHilightItem >= 0) // -1 == empty view
- {
- // no mark list; delete hilight item
- err = m_spFileUI->DoDeleteItemL(idxHilightItem);
- }
- #if(0)
- if(removeIndexes.Nelements() > 0)
- {
- RefreshListBoxL(removeIndexes, idxHilightItem);
- }
- #endif
- }
- ////////////////////////////////////////////////////
- // rename the currently hilighted file or folder
- //
- void CHXAvFileViewWindow::UserRenameCurrentItemL()
- {
- HX_ASSERT(GetMarkedItemCount() == 0); // can't rename when selection list exists!
- TInt idxItem = m_pListBox->CurrentItemIndex();
- HX_ASSERT(idxItem >= 0);
- TInt err = m_spFileUI->DoRenameL(idxItem, R_PROMPT_ENTER_NEW_NAME);
- if(KErrNone == err)
- {
- // set focus to newly renamed item
- TPtrC ptrName = m_spFileUI->GetLastNewItemName();
- if( err != KErrNone )
- {
- ptrName.Set(KNullDesC);
- }
- // update selection to new name
- TInt idxCurrent = m_pListBox->CurrentItemIndex();
- RefreshListBoxL(idxCurrent, ptrName);
- }
- }
- ////////////////////////////////////////////////////////////
- // move selected items, or move current hilighted item, to
- // user-specified folder (relative to root)
- //
- void CHXAvFileViewWindow::UserCopySelectedItemsL()
- {
- TInt idxHilightItem = m_pListBox->CurrentItemIndex();
- const CArrayFix<TInt>* pSelectedItems = m_pListBox->SelectionIndexes();
- TInt err = KErrNone;
- if( pSelectedItems->Count() > 0)
- {
- //XXXLCM implement
- //err = m_spFileUI->DoCopyItemsL(*pSelectedItems, R_PROMPT_COPY_TO);
- }
- else
- {
- HX_ASSERT(idxHilightItem >= 0);
- //err = m_spFileUI->DoCopyItemL(idxHilightItem, R_PROMPT_COPY_TO);
- }
- }
- ////////////////////////////////////////////////////////////
- // move selected items, or move current hilighted item, to
- // user-specified folder (relative to root)
- //
- void CHXAvFileViewWindow::UserMoveSelectedItemsL()
- {
- TInt idxHilightItem = m_pListBox->CurrentItemIndex();
- const CArrayFix<TInt>* pSelectedItems = m_pListBox->SelectionIndexes();
- TInt err = KErrNone;
- if( pSelectedItems->Count() > 0)
- {
- err = m_spFileUI->DoMoveItemsL(*pSelectedItems, R_PROMPT_MOVE_TO);
- }
- else
- {
- HX_ASSERT(idxHilightItem >= 0);
- err = m_spFileUI->DoMoveItemL(idxHilightItem, R_PROMPT_MOVE_TO);
- }
- }
- ////////////////////////////////////////////////////////////
- // send selected items as attachments via the selected mtm
- //
- void CHXAvFileViewWindow::UserSendSelectedItemsL(TInt command,
- CSendAppUi* pSendAppUi)
- {
- TSendingCapabilities caps(0, 1024,
- TSendingCapabilities::ESupportsAttachments);
- if (pSendAppUi->CommandIsValidL(command, caps, NULL ))
- {
- CDesCArray* pSelectedNames = new (ELeave) CDesCArrayFlat(4);
- AUTO_PUSH_POP_DEL(pSelectedNames);
- const CArrayFix<TInt>* pSelectedItems = m_pListBox->SelectionIndexes();
- if (pSelectedItems->Count() > 0)
- {
- for (TInt i = 0; i < pSelectedItems->Count(); ++i)
- {
- TFileName* pName = m_spStore->AllocFullPathL((*pSelectedItems)[i]);
- AUTO_PUSH_POP_DEL(pName);
- pSelectedNames->AppendL(*pName);
- }
- }
- else
- {
- TFileName* pName =
- m_spStore->AllocFullPathL(m_pListBox->CurrentItemIndex());
- AUTO_PUSH_POP_DEL(pName);
- pSelectedNames->AppendL(*pName);
- }
- pSendAppUi->CreateAndSendMessageL(command, NULL, pSelectedNames);
- }
- }
- ////////////////////////////////////////////////////////////////////
- //
- void CHXAvFileViewWindow::UserMarkL(TInt command)
- {
- HX_ASSERT(m_spStore);
- HX_ASSERT(m_pListBox != 0);
- if(command == EAknMarkAll)
- {
- //
- // handle this ourselves since we don't want to mark folders
- //
- CArrayFixFlat<TInt>* pSelections = new (ELeave) CArrayFixFlat<TInt>(20);
- AUTO_PUSH_POP_DEL(pSelections);
- const CHXAvFileStore::Entries& entries = m_spStore->GetEntries();
- TInt count = entries.Nelements();
- for(TInt idx = 0; idx < count; ++idx)
- {
- if( !entries[idx].m_entry.IsDir() )
- {
- // add index to file
- pSelections->AppendL(idx);
- }
- }
- m_pListBox->SetSelectionIndexesL(pSelections);
- m_pListBox->DrawNow();
- }
- else
- {
- AknSelectionService::HandleMarkableListProcessCommandL(command, m_pListBox);
- }
- }
- ////////////////////////////////////////////////////
- // get number of items (files) in view that are not
- // in the selection list
- TInt CHXAvFileViewWindow::GetUnmarkedItemCount() const
- {
- HX_ASSERT(m_spStore);
- TInt totalCount = m_spStore->GetCurrentFolderFileCount();
- TInt markedCount = GetMarkedItemCount();
- HX_ASSERT(totalCount >= markedCount);
- return totalCount - markedCount;
- }
- //////////////////////////////////////
- //
- bool CHXAvFileViewWindow::IsDriveLocked() const
- {
- bool bIsLocked = false;
- CHXAvMediaFolderInfo* pFolderInfo = m_spCurrentPage->FolderInfo();
- if(pFolderInfo)
- {
- TInt idx = CHXAvFile::GetDriveIndex(pFolderInfo->GetRoot());
- bIsLocked = CHXAvFile::IsDriveLocked(idx);
- }
- return bIsLocked;
- }
- ////////////////////////////////////////////////////////////
- //
- void CHXAvFileViewWindow::OnCompleteUnlockAttempt(TInt err)
- {
- if( KErrNone == err )
- {
- // drive was unlocked
- ReloadCurrentPageL();
- }
- }
- ////////////////////////////////////////////////////////////
- // attempt to unlock drive for current store
- void CHXAvFileViewWindow::UserUnlockDriveL()
- {
- // m_memCardUnlock.DoUiL();
- TInt idx = CHXAvFile::GetDriveIndex(GetFullPath());
- TInt err = util::DoUnlockDriveUi(idx);
- OnCompleteUnlockAttempt(err);
- }
- ////////////////////////////////////////////////////////////////////
- // called when page is deactivating/going away
- //
- // save state (current path and index) for current page so we can restore
- // state in case user returns back to page later on
- //
- void CHXAvFileViewWindow::SaveCurrentPageInfoL()
- {
- if(m_spStore && m_spCurrentPage)
- {
- HX_ASSERT(m_pListBox != 0);
- m_spCurrentPage->FolderInfo()->SetCurrentPathL(m_spStore->GetCurrentPath());
- m_spCurrentPage->SetCurrentIndex(m_pListBox->CurrentItemIndex());
- }
- }
- ////////////////////////////////////////////////////////////
- //
- void CHXAvFileViewWindow::UserEditCurrentItemL()
- {
- HX_ASSERT(GetMarkedItemCount() == 0); // can't open when items are in selection list!
- TInt idxItem = m_pListBox->CurrentItemIndex();
- const CHXAvFile::FileInfo& info = GetFileInfoL(idxItem);
- const TEntry& entry = info.m_entry;
- HX_ASSERT(CHXAvFile::ftRam == info.m_type);
- HX_ASSERT(!entry.IsDir());
- TFileName* pPath = CHXAvFile::AllocFileNameL(GetFullPath(), entry.iName);
- AUTO_PUSH_POP_DEL(pPath);
- // hide tabs while dialog is up
- m_bHideTabs = true; // in case switch away, then activate
- UpdateNaviPaneL();
- m_playerUI->DoEditPlaylistL(*pPath);
-
- // make sure ram file is still valid
- CHXAvFile::FileType fileType = CHXAvFile::GetFileType(*pPath);
- if(!CHXAvFile::IsNanoPlayerFileType(fileType))
- {
- // user made unusable file; delete it since it will no longer be recognized and show in our view
- m_spStore->DeleteFileL(*pPath);
- }
- // show tabs again
- m_bHideTabs = false;
- UpdateNaviPaneL();
- // after edit, refresh list box to reflect possible changes (e.g. in file size, link count)
- TInt idxCurrent = m_pListBox->CurrentItemIndex();
- RefreshListBoxL(idxCurrent);
- }
- //////////////////////////////////////
- //
- TKeyResponse CHXAvFileViewWindow::HandleKeyDownEventL(const TKeyEvent& event)
- {
- if(EStdKeyLeftShift == event.iScanCode)
- {
- DPRINTF(SYMP_WSEVENTS, ("CHXAvFileViewWindow::HandleKeyDownEventL(): shift downn"));
- //HX_ASSERT(smNotMarking == m_shiftMarkState);
- // note: we do not always get key up
- if(HasHilightItem() && HilightItemIsFile())
- {
- m_shiftMarkState = (HilightItemIsMarked() ? smShiftUnMark : smShiftMark);
- }
- }
- return EKeyWasNotConsumed;
- }
- //////////////////////////////////////
- //
- TKeyResponse CHXAvFileViewWindow::HandleKeyUpEventL(const TKeyEvent& event)
- {
- if(EStdKeyLeftShift == event.iScanCode)
- {
- DPRINTF(SYMP_INFO, ("CHXAvFileViewWindow::HandleKeyUpEventL(): shift upn"));
- m_shiftMarkState = smNotMarking;
- }
- #if defined(SYMBIANPLAYER_INCLUDE_LOCK_DRIVE_UI)
- else if( event.iScanCode == EStdKeyHash)
- {
- if( !CHXAvFile::IsDriveLocked(CHXAvMisc::KIdxMmcDrive))
- {
- util::DoLockDriveUiL();
- }
- }
- #endif
- return EKeyWasNotConsumed;
- }
- /*
- * GetCurrentPageIndex
- * -------------------
- * Return the index of the current page.
- *
- */
- TInt
- CHXAvFileViewWindow::GetCurrentPageIndex() const
- {
- TInt idx = 0;
- if( m_wpTabGroup )
- {
- idx = m_wpTabGroup->ActiveTabIndex();
- }
- return idx;
- }
- #if(0)
- //////////////////////////////////////
- // optimized version of refreshlistbox
- //
- // update list info and listbox model after actual folder
- // items corresponding to given indexes have been removed
- //
- // called after move or delete
- //
- // idHilightItem is the index for the last known current item
- // (i.e., just before the move or delete took place)
- //
- void CHXAvFileViewWindow::RefreshListBoxL(const Vector<TInt>& removeIndexes,
- TInt idxHilightItem)
- {
- CDesCArray* pTextItems = GetModelTextArray();
- HX_ASSERT(pTextItems);
- if(m_spStore)
- {
- //
- // update model text
- //
- // the fact that descriptor array deletion causes indexes
- // to change necessitates this weird way of deleting model
- // items
- //
- TInt idxItem = 0;
- TInt idxNextRemoveIndex = 0;
-
- TInt count = pTextItems->Count();
- for( TInt idxDelete = 0; idxDelete < count; ++idxDelete)
- {
- if( idxNextRemoveIndex >= removeIndexes.Nelements() )
- {
- // all items have been removed
- break;
- }
- if( idxDelete == removeIndexes[idxNextRemoveIndex] )
- {
- ++idxNextRemoveIndex;
- pTextItems->Delete(idxItem);
- continue;
- }
- // only update this index if an item not deleted
- ++idxItem;
- }
- // scrunch up the list box model
- pTextItems->Compress();
- //
- // update list info items
- //
- m_spStore->RemoveEntries(removeIndexes);
- // update the listbox UI and redraw
- m_pListBox->HandleItemRemovalL();
- if(m_pListBox->CurrentItemIndex() == -1)
- {
- // hilight item was deleted; set hilight to next best index
- idxHilightItem = GetBestIndex(idxHilightItem);
- HX_ASSERT(idxHilightItem < pTextItems->Count());
- m_pListBox->SetCurrentItemIndex(idxHilightItem);
- }
-
- }
- else
- {
- pTextItems->Reset();
- }
- CHXAvMisc:UpdateScrollBar(m_pListBox);
- m_pListBox->DrawNow();
- }
- #endif