📄 filelistengine.cpp
字号:
/*
* ============================================================================
* Name : CFileListEngine from FileListEngine.cpp
* Part of : FileList
* Created : 04/11/2006 by Forum Nokia
* Description:
* Implementation of the engine for constructing the FileList.
* Version : 2.1.0
* ============================================================================
*/
// INCLUDE FILES
#include "FileListEngine.h"
#include "Myxmlparse.hrh" // enumerations
#include <documenthandler.h>// for launching
#include "FileList.pan"
#include <bautils.h>
#include <PathInfo.h>
#include <eikmsg.h>
#include <e32cons.h>
#include <f32file.h>
#include <EIKDEF.H>
#include <EIKENV.H>
#include <AknQueryDialog.h> //弹出对话框
#include <f32file.h >//文件
#include <aknnotewrappers.h>//非阻塞对话框
// ================= Constants =======================
_LIT(KString,"%d\t%S\t");
_LIT(KSlash, "\\");
_LIT(KXml, ".xml");
/*const TInt KDateLength( 30 );*/
// ================= 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 by using PathInfo.
// ---------------------------------------------------------
//
TInt CFileListEngine::StartFileList()
{
iFileList.Reset();
iDirList.Reset();
// Connect to fileserver
TInt error = iFsSession.Connect();
if(error!=KErrNone)
{
return error;
}
TFileName path1 = PathInfo::PhoneMemoryRootPath();
TFileName path2 = PathInfo::MemoryCardRootPath();
switch (iDirectory)
{
case EFileListDefaults:
break;
default:
break;
}
// switch (iDirectory)
// {
// case EFileListPictures:
// path1.Append(KDirPictures);
// path2.Append(KDirPictures);
// break;
// case EFileListVideos:
// path1.Append(KDirVideos);
// path2.Append(KDirVideos);
// break;
// case EFileListSounds:
// default:
// path1.Append(KDirSounds);
// path2.Append(KDirSounds);
// break;
// }
TRAPD( err, GetResourceFilesL( path1 ));
TRAPD( err2, GetResourceFilesL( path2 ));
return err;
}
// ---------------------------------------------------------
// 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;
}
else
{
iNowPath=aBasePath;
}
// 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
// if(files->Count()<=0)
// {
// TBuf<32> ibuf;
// ibuf.Copy(_L("No file is exsit!"));
// CAknInformationNote* iInfoNote = new (ELeave) CAknInformationNote;
// iInfoNote->ExecuteLD(ibuf);
// //break;
// }
// else
// {
for( TInt i=0; i<files->Count(); i++ )
{
iFileList.Append( (*files)[i] );
iDirList.Append( aBasePath );
}
// }
//get subfolders
// for( TInt j=0; j<dirs->Count(); j++ )
// {
// // Exclude directories beginning with '_' as they can
// // contain system-generated thumbnails etc.
// if( (*dirs)[j].iName[0] != '_')
// {
// TFileName nextDir = aBasePath;
// nextDir.Append( (*dirs)[j].iName );
// nextDir.Append( KSlash );
// GetResourceFilesL( nextDir );
// }
// }
// Number 2 cannot be considered a "magic number" in this case,
// and PopAndDestroy does get a parameter. Thus, the CSIs.
CleanupStack::PopAndDestroy( 2, dirs ); // CSI: 47,12 #
}
// ---------------------------------------------------------
// 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);
filename.Format(KString,i+1,&iFileList[i].iName);
//if(filename.Right(3).Compare(_L("txt")))///选择xml类型的文件
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::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
void CFileListEngine::CreateFile(TFileName aFileName)
{
RFs fs;
RFile file;
TFileName iFile=GetNowPath(); //获取当前文件夹的路径
iFile.Append(aFileName);
iFile.Append(KXml);
User::LeaveIfError(fs.Connect()); //连接文件服务器
TInt err=file.Open(fs,iFile,EFileStreamText|EFileWrite|EFileShareAny);
if (err==KErrNotFound) // 若文件不存在 则创建文件
{
err=file.Create(fs,iFile,EFileStreamText|EFileWrite|EFileShareAny);
}
else //若存在文件 则弹出提示对话框
{
TBuf<32> buf;
buf.Copy(_L("file is exsit!"));
CAknInformationNote* iInfoNote = new (ELeave) CAknInformationNote;
iInfoNote->ExecuteLD(buf);
}
file.Close();
fs.Close();
}
//返回当前文件夹路径
TFileName CFileListEngine::GetNowPath()
{
return iNowPath;
}
//TFileName CFileListEngine::GetFileName(TInt i)
//{
// TFileName descr=iDirList[i];
// if(i<=iFileList.Count())
// {
// descr.Append(iFileList[i].iName);
// return descr;
// }
//}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -