⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filelistengine.cpp

📁 NOKIA S60手机3gp视频播放器源代码.
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CFileListEngine from FileListEngine.h
*  Part of  : FileList
*  Created  : 18.12.2002 by Forum Nokia
*  Implementation notes:
*     Engine for constructing filelist.
*  Version  : 1.0
*  Copyright: Nokia Corporation
* ============================================================================
*/

#include "FileListEngine.h"
#include "Filelist.hrh"     // enumerations

// ================= 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"); 
// 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\\");


/*
-----------------------------------------------------------------------------

	void CFileListEngine::ConstructL()

	Description: Symbian two phased 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;
    }

/*
-----------------------------------------------------------------------------

	TInt CFileListEngine::StartFileList()

	Description: This Method reads the appropriate directory list.
	Comments   :

    Return values: return error code

-----------------------------------------------------------------------------
*/
TInt CFileListEngine::StartFileList()
    {
    if (iDirList)
        {        
        delete iDirList;
        iDirList = 0;
        }    
        
    TInt error = KErrNone;

    // Connect to fileserver
    User::LeaveIfError(iFsSession.Connect()); 

    switch (iDirectory)
        {
        // Get dir. KEntryAttNormal means that no hidden files or directories are included
        case EFileListSounds:
            error = iFsSession.GetDir(KDirSounds,KEntryAttNormal,ESortByName,iDirList);
            break;
        case EFileListPictures:
            error = iFsSession.GetDir(KDirPictures,KEntryAttNormal,ESortByName,iDirList);
            break;
        case EFileListVideos:
            error = iFsSession.GetDir(KDirVideos,KEntryAttNormal,ESortByName,iDirList);
            break;
        default:
            error = iFsSession.GetDir(KDirSounds,KEntryAttNormal,ESortByName,iDirList);
            break;
        }

    return error;

    }

/*
-----------------------------------------------------------------------------

	TInt CFileListEngine::StartFileList()

	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: 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;
    // Use appropriate directory path for launching file
    switch (iDirectory)
        {   
        case EFileListSounds:
            descr.Append(KDirSounds);
            break;
        case EFileListPictures:
            descr.Append(KDirPictures);
            break;
        case EFileListVideos:
            descr.Append(KDirVideos);
            break;
        default:
            descr.Append(KDirSounds);
            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: 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: sets whether modification date or file size 
				 is shown. There is also 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: ends the FileList session
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CFileListEngine::EndFileList()
    {
    // Close the file server session
    iFsSession.Close();
    };

/*
-----------------------------------------------------------------------------

	void CFileListEngine::GetVideoFilePathAndNameAtPositon(TInt aPosition, 
	                      TDes &aName )

	Description: Gets the video file name at the listbox poistion
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CFileListEngine::GetVideoFilePathAndNameAtPositon(TInt aPosition, TDes &aName )
	{
    if(!iDirList)
        return;

    // Use appropriate directory path for launching file
    switch (iDirectory)
        {   
        case EFileListSounds:
            aName.Append(KDirSounds);
            break;
        case EFileListPictures:
            aName.Append(KDirPictures);
            break;
        case EFileListVideos:
            aName.Append(KDirVideos);
            break;
        default:
            aName.Append(KDirSounds);
            break;
        }
    // Add filename to be launched
    aName.Append((*iDirList)[aPosition].iName);
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -