1 /////////////////////////////////////////////////////////////////////////////
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 // This program is distributed in the hope that it will be useful, but
8 // WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // General Public License for more details.
11 // You should have received a copy of the GNU General Public License
12 // along with this program; if not, write to the Free Software
13 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
14 /////////////////////////////////////////////////////////////////////////////
16 * @file FileFilterMgr.h
18 * @brief Declaration file for FileFilterMgr
20 // ID line follows -- this is updated by SVN
23 #ifndef FileFilterMgr_h_included
24 #define FileFilterMgr_h_included
27 #include "UnicodeString.h"
30 struct FileFilterElement;
34 * @brief Return values for many filter functions.
38 FILTER_OK = 0, /**< Success */
39 FILTER_ERROR_FILEACCESS, /**< File could not be opened etc. */
40 FILTER_NOTFOUND, /**< Filter not found */
44 * @brief File filter manager for handling filefilters.
46 * The FileFilterMgr loads a collection of named file filters from disk,
47 * and provides lookup access by name, or array access by index, to these
48 * named filters. It also provides test functions for actually using the
51 * We are using PCRE for regular expressions. Nice thing in PCRE is it supports
52 * UTF-8 unicode, unlike many other libs. For ANSI builds we use just ansi
53 * strings, and for unicode we must first convert strings to UTF-8.
61 // Reload filter array from specified directory (passed to CFileFind)
62 void LoadFromDirectory(LPCTSTR dir, LPCTSTR szPattern, LPCTSTR szExt);
63 // Reload an edited filter
64 int ReloadFilterFromDisk(FileFilter * pfilter);
65 int ReloadFilterFromDisk(LPCTSTR szFullPath);
66 // Load a filter from a string
67 void LoadFilterString(LPCTSTR szFilterString);
68 int AddFilter(LPCTSTR szFilterFile);
69 void RemoveFilter(LPCTSTR szFilterFile);
71 // access to array of filters
72 int GetFilterCount() const { return (int) m_filters.size(); }
73 String GetFilterName(int i) const;
74 String GetFilterName(const FileFilter *pFilter) const;
75 String GetFilterPath(int i) const;
76 String GetFilterDesc(int i) const;
77 String GetFilterDesc(const FileFilter *pFilter) const;
78 FileFilter * GetFilterByPath(LPCTSTR szFilterName);
79 String GetFullpath(FileFilter * pfilter) const;
81 // methods to actually use filter
82 BOOL TestFileNameAgainstFilter(const FileFilter * pFilter, LPCTSTR szFileName) const;
83 BOOL TestDirNameAgainstFilter(const FileFilter * pFilter, LPCTSTR szDirName) const;
85 void DeleteAllFilters();
87 // Implementation methods
89 // Clear the list of known filters
90 // Load a filter from a file (if syntax is valid)
91 FileFilter * LoadFilterFile(LPCTSTR szFilepath, int & errorcode);
93 // Implementation data
95 std::vector<FileFilter*> m_filters; /*< List of filters loaded */
99 BOOL TestAgainstRegList(const std::vector<FileFilterElement*> *filterList, LPCTSTR szTest);
100 void EmptyFilterList(std::vector<FileFilterElement*> *filterList);
103 #endif // FileFilterMgr_h_included