Filelistengine.cpp
上传用户:xinrui0099
上传日期:2010-03-05
资源大小:48k
文件大小:9k
源码类别:

Symbian

开发平台:

C/C++

  1. /*
  2. * ============================================================================
  3. *  Name     : CFileListEngine from FileListEngine.h
  4. *  Part of  : FileList
  5. *  Created  : 18.12.2002 by Forum Nokia
  6. *  Implementation notes:
  7. *     Engine for constructing filelist.
  8. *  Version  : 1.0
  9. *  Copyright: Nokia Corporation
  10. * ============================================================================
  11. */
  12. #include "FileListEngine.h"
  13. #include "Filelist.hrh"     // enumerations
  14. // ================= Constants =======================
  15. // Number, name and file size
  16. _LIT(KStringSize,"%dt%St%d bytes");
  17. // Number, name and date modified
  18. _LIT(KStringDate,"%dt%St%S"); 
  19. // Directory for Sounds
  20. _LIT(KDirSounds,"c:\Nokia\Sounds\Digital\");
  21. // Directory for Pictures
  22. _LIT(KDirPictures,"c:\Nokia\Images\");
  23. // Directory for Videos
  24. _LIT(KDirVideos,"c:\Nokia\Videos\");
  25. /*
  26. -----------------------------------------------------------------------------
  27. void CFileListEngine::ConstructL()
  28. Description: Symbian two phased constructor
  29. Comments   :
  30.     Return values: N/A
  31. -----------------------------------------------------------------------------
  32. */
  33. void CFileListEngine::ConstructL()
  34.     {
  35.     }
  36. /*
  37. -----------------------------------------------------------------------------
  38. CFileListEngine::~CFileListEngine()
  39. Description: destructor
  40. Comments   :
  41.     Return values: N/A
  42. -----------------------------------------------------------------------------
  43. */
  44. CFileListEngine::~CFileListEngine()
  45.     {
  46.     // Delete directory list
  47.     delete iDirList;
  48.     }
  49. /*
  50. -----------------------------------------------------------------------------
  51. TInt CFileListEngine::StartFileList()
  52. Description: This Method reads the appropriate directory list.
  53. Comments   :
  54.     Return values: return error code
  55. -----------------------------------------------------------------------------
  56. */
  57. TInt CFileListEngine::StartFileList()
  58.     {
  59.     if (iDirList)
  60.         {        
  61.         delete iDirList;
  62.         iDirList = 0;
  63.         }    
  64.         
  65.     TInt error = KErrNone;
  66.     // Connect to fileserver
  67.     User::LeaveIfError(iFsSession.Connect()); 
  68.     switch (iDirectory)
  69.         {
  70.         // Get dir. KEntryAttNormal means that no hidden files or directories are included
  71.         case EFileListSounds:
  72.             error = iFsSession.GetDir(KDirSounds,KEntryAttNormal,ESortByName,iDirList);
  73.             break;
  74.         case EFileListPictures:
  75.             error = iFsSession.GetDir(KDirPictures,KEntryAttNormal,ESortByName,iDirList);
  76.             break;
  77.         case EFileListVideos:
  78.             error = iFsSession.GetDir(KDirVideos,KEntryAttNormal,ESortByName,iDirList);
  79.             break;
  80.         default:
  81.             error = iFsSession.GetDir(KDirSounds,KEntryAttNormal,ESortByName,iDirList);
  82.             break;
  83.         }
  84.     return error;
  85.     }
  86. /*
  87. -----------------------------------------------------------------------------
  88. TInt CFileListEngine::StartFileList()
  89. Description: This Method constructs the listbox items with directory 
  90.      information
  91. Comments   :
  92.     Return values: N/A
  93. -----------------------------------------------------------------------------
  94. */
  95. void CFileListEngine::GetFileListItems(CDesCArray* aItems)
  96.     {
  97.     if(!iDirList)
  98.         return;
  99.                        
  100.     for (TInt i=0;i<iDirList->Count();i++)
  101.         {
  102.         TFileName filename = NULL;
  103.         if(iSizeDate==EFileListSize)
  104.             {
  105.             // Show file size
  106.             filename.Format(KStringSize,i+1,&(*iDirList)[i].iName,(*iDirList)[i].iSize);
  107.             }
  108.         else
  109.             {
  110.             // Fix the date and time string of last modification
  111.             TBuf<30> dateString; 
  112.             _LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B");
  113.             (*iDirList)[i].iModified.FormatL(dateString,KDateString); 
  114.             // Show date modified
  115.             filename.Format(KStringDate,i+1,&(*iDirList)[i].iName,&dateString);
  116.             }
  117.         aItems->AppendL(filename);
  118.         }
  119.         
  120.     }
  121. /*
  122. -----------------------------------------------------------------------------
  123. void CFileListEngine::SetDirectory(TInt aDirectory)
  124. Description: This Method sets which directory to list.
  125. Comments   :
  126.     Return values: N/A
  127. -----------------------------------------------------------------------------
  128. */
  129. void CFileListEngine::SetDirectory(TInt aDirectory)
  130.     {
  131.     if (aDirectory!=EFileListDirNoChange)
  132.         iDirectory=aDirectory;
  133.     }
  134. /*
  135. -----------------------------------------------------------------------------
  136. void CFileListEngine::LaunchCurrent(TInt aPosition)
  137. Description: launches selected item with DocumentHandler.
  138.  DocumentHandler will launch correct application depending 
  139.  on the file type.
  140. Comments   : Note that all the extensions do not work on emulator.
  141.     Return values: N/A
  142. -----------------------------------------------------------------------------
  143. */
  144. void CFileListEngine::LaunchCurrent(TInt aPosition)
  145.     {
  146.     if(!iDirList)
  147.         return;
  148.      //Launch current item in the list
  149.  
  150.     CDocumentHandler* handler = CDocumentHandler::NewL(NULL);
  151.     CleanupStack::PushL(handler);
  152.     TFileName descr;
  153.     // Use appropriate directory path for launching file
  154.     switch (iDirectory)
  155.         {   
  156.         case EFileListSounds:
  157.             descr.Append(KDirSounds);
  158.             break;
  159.         case EFileListPictures:
  160.             descr.Append(KDirPictures);
  161.             break;
  162.         case EFileListVideos:
  163.             descr.Append(KDirVideos);
  164.             break;
  165.         default:
  166.             descr.Append(KDirSounds);
  167.             break;
  168.         }
  169.     // Add filename to be launched
  170.     descr.Append((*iDirList)[aPosition].iName);
  171.     // Create nullType. This makes the DocumentHandler to figure out the posfix for us.
  172.     TDataType nullType;
  173.     // Launch the appropriate application for this file
  174.     handler->OpenFileL(descr,nullType);
  175.     CleanupStack::PopAndDestroy(); // handler
  176.     };
  177. /*
  178. -----------------------------------------------------------------------------
  179. TBool CFileListEngine::RemoveItems(CDesCArray* aItems)
  180. Description: removes all listbox items when a new list 
  181.      needs to be shown.
  182. Comments   :
  183.     Return values: true if removed, false if not removed
  184. -----------------------------------------------------------------------------
  185. */
  186. TBool CFileListEngine::RemoveItems(CDesCArray* aItems)
  187.     {
  188.     if(iDirList)
  189.         {        
  190.         if (iDirList->Count())
  191.             {
  192.             aItems->Delete(0,(iDirList->Count()));
  193.             return ETrue;
  194.             }
  195.         }    
  196.     return EFalse;
  197.     };
  198. /*
  199. -----------------------------------------------------------------------------
  200. void CFileListEngine::SetSizeDate(TInt aSizeDate)
  201. Description: sets whether modification date or file size 
  202.  is shown. There is also option for toggling the status.
  203. Comments   :
  204.     Return values: N/A
  205. -----------------------------------------------------------------------------
  206. */
  207. void CFileListEngine::SetSizeDate(TInt aSizeDate)
  208.     {
  209.     if (aSizeDate==EFileListToggle)
  210.         if (iSizeDate==EFileListSize)
  211.             iSizeDate=EFileListDate;
  212.         else
  213.             iSizeDate=EFileListSize;
  214.     else
  215.         if (aSizeDate!=EFileListSizeDateNoChange)
  216.             iSizeDate=aSizeDate;
  217.     };
  218. /*
  219. -----------------------------------------------------------------------------
  220. void CFileListEngine::EndFileList()
  221. Description: ends the FileList session
  222. Comments   :
  223.     Return values: N/A
  224. -----------------------------------------------------------------------------
  225. */
  226. void CFileListEngine::EndFileList()
  227.     {
  228.     // Close the file server session
  229.     iFsSession.Close();
  230.     };
  231. /*
  232. -----------------------------------------------------------------------------
  233. void CFileListEngine::GetVideoFilePathAndNameAtPositon(TInt aPosition, 
  234.                       TDes &aName )
  235. Description: Gets the video file name at the listbox poistion
  236. Comments   :
  237.     Return values: N/A
  238. -----------------------------------------------------------------------------
  239. */
  240. void CFileListEngine::GetVideoFilePathAndNameAtPositon(TInt aPosition, TDes &aName )
  241. {
  242.     if(!iDirList)
  243.         return;
  244.     // Use appropriate directory path for launching file
  245.     switch (iDirectory)
  246.         {   
  247.         case EFileListSounds:
  248.             aName.Append(KDirSounds);
  249.             break;
  250.         case EFileListPictures:
  251.             aName.Append(KDirPictures);
  252.             break;
  253.         case EFileListVideos:
  254.             aName.Append(KDirVideos);
  255.             break;
  256.         default:
  257.             aName.Append(KDirSounds);
  258.             break;
  259.         }
  260.     // Add filename to be launched
  261.     aName.Append((*iDirList)[aPosition].iName);
  262. }