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
26 // Uses MFC C++ template containers
29 #include "UnicodeString.h"
32 struct FileFilterElement;
36 * @brief Return values for many filter functions.
40 FILTER_OK = 0, /**< Success */
41 FILTER_ERROR_FILEACCESS, /**< File could not be opened etc. */
42 FILTER_NOTFOUND, /**< Filter not found */
46 * @brief File filter manager for handling filefilters.
48 * The FileFilterMgr loads a collection of named file filters from disk,
49 * and provides lookup access by name, or array access by index, to these
50 * named filters. It also provides test functions for actually using the
53 * We are using PCRE for regular expressions. Nice thing in PCRE is it supports
54 * UTF-8 unicode, unlike many other libs. For ANSI builds we use just ansi
55 * strings, and for unicode we must first convert strings to UTF-8.
63 // Reload filter array from specified directory (passed to CFileFind)
64 void LoadFromDirectory(LPCTSTR szPattern, LPCTSTR szExt);
65 // Reload an edited filter
66 int ReloadFilterFromDisk(FileFilter * pfilter);
67 int ReloadFilterFromDisk(LPCTSTR szFullPath);
68 // Load a filter from a string
69 void LoadFilterString(LPCTSTR szFilterString);
70 int AddFilter(LPCTSTR szFilterFile);
71 void RemoveFilter(LPCTSTR szFilterFile);
73 // access to array of filters
74 int GetFilterCount() const { return m_filters.size(); }
75 String GetFilterName(int i) const;
76 String GetFilterName(const FileFilter *pFilter) const;
77 String GetFilterPath(int i) const;
78 String GetFilterDesc(int i) const;
79 String GetFilterDesc(const FileFilter *pFilter) const;
80 FileFilter * GetFilterByPath(LPCTSTR szFilterName);
81 String GetFullpath(FileFilter * pfilter) const;
83 // methods to actually use filter
84 BOOL TestFileNameAgainstFilter(const FileFilter * pFilter, LPCTSTR szFileName) const;
85 BOOL TestDirNameAgainstFilter(const FileFilter * pFilter, LPCTSTR szDirName) const;
87 void DeleteAllFilters();
89 // Implementation methods
91 // Clear the list of known filters
92 // Load a filter from a file (if syntax is valid)
93 FileFilter * LoadFilterFile(LPCTSTR szFilepath, int & errorcode);
95 // Implementation data
97 std::vector<FileFilter*> m_filters; /*< List of filters loaded */
101 BOOL TestAgainstRegList(const std::vector<FileFilterElement*> *filterList, LPCTSTR szTest);
102 void EmptyFilterList(std::vector<FileFilterElement*> *filterList);
105 #endif // FileFilterMgr_h_included