📄 filelistengine.cpp
字号:
/*
* ============================================================================
* Name : CFileListEngine from FileListEngine.h
* Part of : Video Recording Example (VRex)
* Created : 16.03.2004 by Nokia Forum
* Description: Declares file list engine
*
* Version :
* Copyright: Nokia Corporation
* ============================================================================
*/
#include "FileListEngine.h"
#include "Filelist.hrh" // enumerations
#include <PathInfo.h> // for PathInfo
// Number, name and file size
_LIT(KStringSize,"%d\t%S\t%d bytes");
// Number, name and date modified
_LIT(KStringDate,"%d\t%S\t%S");
/*
-----------------------------------------------------------------------------
void CFileListEngine::ConstructL()
Description: Second phase constructor.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CFileListEngine::ConstructL()
{
}
/*
-----------------------------------------------------------------------------
CFileListEngine::~CFileListEngine()
Description: Destructor.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
CFileListEngine::~CFileListEngine()
{
// Delete directory list
delete iDirList;
iDirList = NULL;
iFsSession.Close();
}
/*
-----------------------------------------------------------------------------
TInt CFileListEngine::StartFileList()
Description: This method reads the appropriate directory list.
Comments :
Return values: Error code
-----------------------------------------------------------------------------
*/
TInt CFileListEngine::StartFileList()
{
if (iDirList)
{
delete iDirList;
iDirList = 0;
}
TInt error = KErrNone;
// Root path in phone memory
TFileName rootPath = PathInfo::PhoneMemoryRootPath();
// Connect to file server
User::LeaveIfError(iFsSession.Connect());
switch (iDirectory)
{
// Get dir. KEntryAttNormal means that no hidden files or directories are included
case EFileListSounds:
rootPath.Append(PathInfo::SoundsPath());
error = iFsSession.GetDir(rootPath,KEntryAttNormal,ESortByName,iDirList);
break;
case EFileListPictures:
rootPath.Append(PathInfo::GmsPicturesPath());
error = iFsSession.GetDir(rootPath,KEntryAttNormal,ESortByName,iDirList);
break;
case EFileListVideos:
rootPath.Append(PathInfo::VideosPath());
error = iFsSession.GetDir(rootPath,KEntryAttNormal,ESortByName,iDirList);
break;
default:
rootPath.Append(PathInfo::GmsPicturesPath());
error = iFsSession.GetDir(rootPath,KEntryAttNormal,ESortByName,iDirList);
break;
}
return error;
}
/*
-----------------------------------------------------------------------------
void CFileListEngine::GetFileListItems(CDesCArray* aItems)
Description: This method constructs the listbox items with directory
information.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CFileListEngine::GetFileListItems(CDesCArray* aItems)
{
if(!iDirList)
return;
for (TInt i=0;i<iDirList->Count();i++)
{
TFileName filename = NULL;
if(iSizeDate==EFileListSize)
{
// Show file size
filename.Format(KStringSize,i+1,&(*iDirList)[i].iName,(*iDirList)[i].iSize);
}
else
{
// Fix the date and time string of last modification
TBuf<30> dateString;
_LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B");
(*iDirList)[i].iModified.FormatL(dateString,KDateString);
// Show date modified
filename.Format(KStringDate,i+1,&(*iDirList)[i].iName,&dateString);
}
aItems->AppendL(filename);
}
}
/*
-----------------------------------------------------------------------------
void CFileListEngine::SetDirectory(TInt aDirectory)
Description: This method sets which directory to list.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CFileListEngine::SetDirectory(TInt aDirectory)
{
if (aDirectory!=EFileListDirNoChange)
iDirectory=aDirectory;
}
/*
-----------------------------------------------------------------------------
void CFileListEngine::LaunchCurrent(TInt aPosition)
Description: This method launches selected item with DocumentHandler.
DocumentHandler will launch correct application depending
on the file type.
Comments : Note that all the extensions do not work on emulator.
Return values: N/A
-----------------------------------------------------------------------------
*/
void CFileListEngine::LaunchCurrent(TInt aPosition)
{
if(!iDirList)
return;
//Launch current item in the list
CDocumentHandler* handler = CDocumentHandler::NewL(NULL);
CleanupStack::PushL(handler);
TFileName descr = PathInfo::PhoneMemoryRootPath();
// Use appropriate directory path for launching file
switch (iDirectory)
{
case EFileListSounds:
descr.Append(PathInfo::SoundsPath());
break;
case EFileListPictures:
descr.Append(PathInfo::GmsPicturesPath());
break;
case EFileListVideos:
descr.Append(PathInfo::VideosPath());
break;
default:
descr.Append(PathInfo::SoundsPath());
break;
}
// Add filename to be launched
descr.Append((*iDirList)[aPosition].iName);
// Create nullType. This makes the DocumentHandler to figure out the posfix for us.
TDataType nullType;
// Launch the appropriate application for this file
handler->OpenFileL(descr,nullType);
CleanupStack::PopAndDestroy(); // handler
}
/*
-----------------------------------------------------------------------------
TBool CFileListEngine::RemoveItems(CDesCArray* aItems)
Description: This method removes all listbox items when a new list
needs to be shown.
Comments :
Return values: true if removed, false if not removed
-----------------------------------------------------------------------------
*/
TBool CFileListEngine::RemoveItems(CDesCArray* aItems)
{
if(iDirList)
{
if (iDirList->Count())
{
aItems->Delete(0,(iDirList->Count()));
return ETrue;
}
}
return EFalse;
}
/*
-----------------------------------------------------------------------------
void CFileListEngine::SetSizeDate(TInt aSizeDate)
Description: This method sets whether modification date or file size
is shown. There is also an option for toggling the status.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CFileListEngine::SetSizeDate(TInt aSizeDate)
{
if (aSizeDate==EFileListToggle)
if (iSizeDate==EFileListSize)
iSizeDate=EFileListDate;
else
iSizeDate=EFileListSize;
else
if (aSizeDate!=EFileListSizeDateNoChange)
iSizeDate=aSizeDate;
}
/*
-----------------------------------------------------------------------------
void CFileListEngine::EndFileList()
Description: This method ends the file server session.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CFileListEngine::EndFileList()
{
// Close the file server session
iFsSession.Close();
}
/*
-----------------------------------------------------------------------------
void CFileListEngine::GetVideoFilePathAndNameAtPositon(TInt aPosition,
TDes &aName)
Description: This method gets the video file name at the listbox position.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CFileListEngine::GetVideoFilePathAndNameAtPositon(TInt aPosition, TDes &aName)
{
if(!iDirList)
return;
aName.Append(PathInfo::PhoneMemoryRootPath());
// Use appropriate directory path for launching file
switch (iDirectory)
{
case EFileListSounds:
aName.Append(PathInfo::SoundsPath());
break;
case EFileListPictures:
aName.Append(PathInfo::GmsPicturesPath());
break;
case EFileListVideos:
aName.Append(PathInfo::VideosPath());
break;
default:
aName.Append(PathInfo::SoundsPath());
break;
}
// Add filename to be launched
aName.Append((*iDirList)[aPosition].iName);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -