📄 filelistengine.cpp
字号:
/*
* ============================================================================
* Name : CFileListEngine from FileListEngine.h
* Part of : FileList
* Created : 04.11.2006 by Forum Nokia
* Implementation notes:
* Engine for constructing filelist.
* Initial content was generated by Nokia Series 60 AppWizard.
* Version : 2.0
* Copyright: Nokia Corporation
* ============================================================================
*/
// INCLUDE FILES
#include "FileListEngine.h"
#include "Filelist.hrh" // enumerations
#include <documenthandler.h>// for launching
#include "FileList.pan"
#include <bautils.h>
#ifndef __HARDCODED_PATHS__
#include <PathInfo.h>
#endif
// ================= Constants =======================
// 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");
#ifndef __HARDCODED_PATHS__
#define KDirSounds PathInfo::DigitalSoundsPath()
#define KDirPictures PathInfo::ImagesPath()
#define KDirVideos PathInfo::VideosPath()
#else
// Directory for Sounds
_LIT(KDirSounds,"c:\\Nokia\\Sounds\\Digital\\");
// Directory for Pictures
_LIT(KDirPictures,"c:\\Nokia\\Images\\");
// Directory for Videos
_LIT(KDirVideos,"c:\\Nokia\\Videos\\");
#endif
_LIT(KSlash, "\\");
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CFileListEngine::ConstructL(const TRect& aRect)
// Symbian two phased constructor
// ---------------------------------------------------------
//
void CFileListEngine::ConstructL(CEikProcess* aProcess /*= NULL*/)
{
#ifdef __SERIES60_3X__
aProcess = NULL;
iDocHandler = CDocumentHandler::NewL();
#else
iDocHandler = CDocumentHandler::NewL(aProcess);
#endif
}
// Destructor
CFileListEngine::~CFileListEngine()
{
delete iDocHandler;
iFileList.Close();
iDirList.Close();
}
// ---------------------------------------------------------
// CFileListEngine::StartFileList()
// This Method gets the specific directory.
// In the 1st edition use harcoded paths and the S60 2nd and 3rd edition
// get the specific path using PathInfo.
// ---------------------------------------------------------
//
TInt CFileListEngine::StartFileList()
{
iFileList.Reset();
iDirList.Reset();
// Connect to fileserver
TInt error = iFsSession.Connect();
if(error!=KErrNone)
{
return error;
}
#ifndef __HARDCODED_PATHS__
TFileName path1 = PathInfo::PhoneMemoryRootPath();
TFileName path2 = PathInfo::MemoryCardRootPath();
switch (iDirectory)
{
case EFileListPictures:
path1.Append(KDirPictures);
path2.Append(KDirPictures);
break;
case EFileListVideos:
path1.Append(KDirVideos);
path2.Append(KDirPictures);
break;
case EFileListSounds:
default:
path1.Append(KDirSounds);
path2.Append(KDirPictures);
break;
}
TRAPD( err, GetResourceFilesL( path1 ));
TRAPD( err2, GetResourceFilesL( path2 ));
return err;
#else
TFileName path;
switch (iDirectory)
{
case EFileListPictures:
path.Append(KDirPictures);
break;
case EFileListVideos:
path.Append(KDirVideos);
break;
case EFileListSounds:
default:
path.Append(KDirSounds);
break;
}
TRAPD( err, GetResourceFilesL( path ));
return err;
#endif
}
// ---------------------------------------------------------
// CFileListEngine::GetResourceFilesL ( TFileName &aBasePath )
// The method get all files including files into subfolders.
// ---------------------------------------------------------
//
void CFileListEngine::GetResourceFilesL ( TFileName &aBasePath )
{
CDir* dirs = 0;
CDir* files = 0;
if(! BaflUtils::PathExists(iFsSession, aBasePath))
{
return;
}
// Get dir. KEntryAttNormal means that no hidden files or directories are included
User::LeaveIfError(iFsSession.GetDir(aBasePath,KEntryAttNormal,ESortByName,files, dirs));
CleanupStack::PushL(dirs);
CleanupStack::PushL(files);
//get files in base path
for( TInt i=0; i<files->Count(); i++ )
{
iFileList.Append( (*files)[i] );
iDirList.Append( aBasePath );
}
//get subfolders
for( TInt i=0; i<dirs->Count(); i++ )
{
// Exclude directories beginning with '_' as they can
// contain system-generated thumbnails etc.
if( (*dirs)[i].iName[0] != '_')
{
TFileName nextDir = aBasePath;
nextDir.Append( (*dirs)[i].iName );
nextDir.Append( KSlash );
GetResourceFilesL( nextDir );
}
}
CleanupStack::PopAndDestroy( 2 );
}
// ---------------------------------------------------------
// CFileListEngine::GetFileListItems(CDesCArray* aItems)
// This Method constructs the listbox items with directory
// information
// ---------------------------------------------------------
//
void CFileListEngine::GetFileListItemsL(CDesCArray* aItems)
{
for (TInt i=0;i<iFileList.Count();i++)
{
TFileName filename(KNullDesC);
if(iSizeDate==EFileListSize)
{
// Show file size
filename.Format(KStringSize,i+1,&iFileList[i].iName,iFileList[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");
iFileList[i].iModified.FormatL(dateString,KDateString);
// Show date modified
filename.Format(KStringDate,i+1,&iFileList[i].iName,&dateString);
}
aItems->AppendL(filename);
}
}
// ---------------------------------------------------------
// CFileListEngine::SetDirectory(TInt aDirectory)
// This Method sets which directory to list.
// ---------------------------------------------------------
//
void CFileListEngine::SetDirectory(TInt aDirectory)
{
if (aDirectory!=EFileListDirNoChange)
iDirectory=aDirectory;
}
// ---------------------------------------------------------
// CFileListEngine::LaunchCurrent(TInt aPosition)
// This Method launches selected item with DocumentHandler.
// DocumentHandler will launch correct application depending
// on the file type.
// Note that all the extensions do not work on emulator.
// ---------------------------------------------------------
//
void CFileListEngine::LaunchCurrentL(TInt aPosition)
{
TFileName descr = iDirList[aPosition];
if(aPosition <= iFileList.Count())
{
// Add filename to be launched
descr.Append(iFileList[aPosition].iName);
}
else
{
Panic(EFileListIvalidIndex);
}
// Create nullType. This makes the DocumentHandler to figure out the posfix for us.
TDataType nullType;
// Launch the appropriate application for this file
iDocHandler->OpenFileEmbeddedL(descr,nullType);
iDocHandler->SetExitObserver(this);
iDocEmbedded = ETrue;
};
// ---------------------------------------------------------
// CFileListEngine::RemoveItems(CDesCArray* aItems)
// This Method removes all listbox items when a new list
// needs to be shown.
// ---------------------------------------------------------
//
TBool CFileListEngine::RemoveItems(CDesCArray* aItems)
{
if (iFileList.Count())
{
aItems->Delete(0,(iFileList.Count()));
return ETrue;
}
return EFalse;
};
// ---------------------------------------------------------
// CFileListEngine::IsDirListEmpty()
// ---------------------------------------------------------
//
TBool CFileListEngine::IsDirListEmpty()
{
if(iFileList.Count())
{
return EFalse;
}
return ETrue;
};
// ---------------------------------------------------------
// CFileListEngine::SetSizeDate(TInt aSizeDate)
// This Method sets whether modification date or file size
// is shown. There is also option for toggling the status.
// ---------------------------------------------------------
//
void CFileListEngine::SetSizeDate(TInt aSizeDate)
{
if (aSizeDate==EFileListToggle)
if (iSizeDate==EFileListSize)
iSizeDate=EFileListDate;
else
iSizeDate=EFileListSize;
else
if (aSizeDate!=EFileListSizeDateNoChange)
iSizeDate=aSizeDate;
};
// ---------------------------------------------------------
// CFileListEngine::EndFileList()
// This Method ends the FileList session
// ---------------------------------------------------------
//
void CFileListEngine::EndFileList()
{
// Close the file server session
iFsSession.Close();
};
#ifdef __SERIES60_3X__
void CFileListEngine::HandleServerAppExit(TInt aReason)
{
iDocEmbedded = EFalse;
MAknServerAppExitObserver::HandleServerAppExit(aReason);
}
#else
void CFileListEngine::NotifyExit(TExitMode /*aMode*/)
{
iDocEmbedded = EFalse;
}
#endif
//EOF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -