juce_DirectoryContentsList.h

Go to the documentation of this file.
00001 /*
00002   ==============================================================================
00003 
00004    This file is part of the JUCE library - "Jules' Utility Class Extensions"
00005    Copyright 2004-7 by Raw Material Software ltd.
00006 
00007   ------------------------------------------------------------------------------
00008 
00009    JUCE can be redistributed and/or modified under the terms of the
00010    GNU General Public License, as published by the Free Software Foundation;
00011    either version 2 of the License, or (at your option) any later version.
00012 
00013    JUCE is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with JUCE; if not, visit www.gnu.org/licenses or write to the
00020    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00021    Boston, MA 02111-1307 USA
00022 
00023   ------------------------------------------------------------------------------
00024 
00025    If you'd like to release a closed-source product which uses JUCE, commercial
00026    licenses are also available: visit www.rawmaterialsoftware.com/juce for
00027    more information.
00028 
00029   ==============================================================================
00030 */
00031 
00032 #ifndef __JUCE_DIRECTORYCONTENTSLIST_JUCEHEADER__
00033 #define __JUCE_DIRECTORYCONTENTSLIST_JUCEHEADER__
00034 
00035 #include "juce_FileFilter.h"
00036 #include "../../../events/juce_ChangeBroadcaster.h"
00037 #include "../../../../juce_core/threads/juce_TimeSliceThread.h"
00038 #include "../../graphics/imaging/juce_Image.h"
00039 
00040 
00041 //==============================================================================
00051 class JUCE_API  DirectoryContentsList   : public ChangeBroadcaster,
00052                                           public TimeSliceClient
00053 {
00054 public:
00055     //==============================================================================
00075     DirectoryContentsList (const FileFilter* const fileFilter,
00076                            TimeSliceThread& threadToUse);
00077 
00079     ~DirectoryContentsList();
00080 
00081 
00082     //==============================================================================
00088     void setDirectory (const File& directory,
00089                        const bool includeDirectories,
00090                        const bool includeFiles);
00091 
00093     const File& getDirectory() const throw();
00094 
00096     void clear();
00097 
00099     void refresh();
00100 
00102     bool isStillLoading() const;
00103 
00108     void setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles);
00109 
00110     //==============================================================================
00113     struct FileInfo
00114     {
00115         //==============================================================================
00123         String filename;
00124 
00126         int64 fileSize;
00127 
00132         Time modificationTime;
00133 
00138         Time creationTime;
00139 
00141         bool isDirectory;
00142 
00144         bool isReadOnly;
00145     };
00146 
00147     //==============================================================================
00158     int getNumFiles() const;
00159 
00170     bool getFileInfo (const int index,
00171                       FileInfo& resultInfo) const;
00172 
00179     const File getFile (const int index) const;
00180 
00185     const FileFilter* getFilter() const throw()             { return fileFilter; }
00186 
00187     //==============================================================================
00189     bool useTimeSlice();
00191     TimeSliceThread& getTimeSliceThread() throw()           { return thread; }
00193     static int compareElements (const DirectoryContentsList::FileInfo* const first,
00194                                 const DirectoryContentsList::FileInfo* const second) throw();
00195 
00196     juce_UseDebuggingNewOperator
00197 
00198 private:
00199     File root;
00200     const FileFilter* fileFilter;
00201     TimeSliceThread& thread;
00202     bool includeDirectories, includeFiles, ignoreHiddenFiles;
00203 
00204     CriticalSection fileListLock;
00205     OwnedArray <FileInfo> files;
00206 
00207     void* volatile fileFindHandle;
00208     bool volatile shouldStop;
00209 
00210     void changed();
00211     bool checkNextFile (bool& hasChanged);
00212     bool addFile (const String& filename, const bool isDir, const bool isHidden,
00213                   const int64 fileSize, const Time& modTime,
00214                   const Time& creationTime, const bool isReadOnly);
00215 
00216     DirectoryContentsList (const DirectoryContentsList&);
00217     const DirectoryContentsList& operator= (const DirectoryContentsList&);
00218 };
00219 
00220 
00221 #endif   // __JUCE_DIRECTORYCONTENTSLIST_JUCEHEADER__