www.pudn.com > FileList_v1_0.zip > Filelistengine.cpp


/* 
* ============================================================================ 
*  Name     : CFileListEngine from FileListEngine.h 
*  Part of  : FileList 
*  Created  : 18.12.2002 by Forum Nokia 
*  Implementation notes: 
*     Engine for constructing filelist. 
*     Initial content was generated by Nokia Series 60 AppWizard. 
*  Version  : 1.0 
*  Copyright: Nokia Corporation 
* ============================================================================ 
*/ 
 
// INCLUDE FILES 
#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\\"); 
 
 
// ================= MEMBER FUNCTIONS ======================= 
 
// --------------------------------------------------------- 
// CFileListEngine::ConstructL(const TRect& aRect) 
// Symbian two phased constructor 
// --------------------------------------------------------- 
// 
void CFileListEngine::ConstructL() 
    { 
    } 
 
// Destructor 
CFileListEngine::~CFileListEngine() 
    { 
    // Delete directory list 
    delete iDirList; 
    } 
 
// --------------------------------------------------------- 
// CFileListEngine::StartFileList() 
// This Method reads the appropriate directory list. 
// --------------------------------------------------------- 
// 
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; 
 
    } 
 
// --------------------------------------------------------- 
// CFileListEngine::GetFileListItems(CDesCArray* aItems) 
// This Method constructs the listbox items with directory  
// information 
// --------------------------------------------------------- 
// 
void CFileListEngine::GetFileListItems(CDesCArray* aItems) 
    { 
    if(!iDirList) 
        return; 
                        
    for (TInt i=0;iCount();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); 
        } 
         
    } 
 
// --------------------------------------------------------- 
// 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::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 
    }; 
 
// --------------------------------------------------------- 
// CFileListEngine::RemoveItems(CDesCArray* aItems) 
// This Method removes all listbox items when a new list  
// needs to be shown. 
// --------------------------------------------------------- 
// 
TBool CFileListEngine::RemoveItems(CDesCArray* aItems) 
    { 
    if(iDirList) 
        {         
        if (iDirList->Count()) 
            { 
            aItems->Delete(0,(iDirList->Count())); 
            return ETrue; 
            } 
        }     
    return EFalse; 
    }; 
 
// --------------------------------------------------------- 
// 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(); 
    };