1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * @file FileFilterMgr.h
5 * @brief Declaration file for FileFilterMgr
10 #include "UnicodeString.h"
11 #include "FileFilter.h"
14 * @brief Return values for many filter functions.
18 FILTER_OK = 0, /**< Success */
19 FILTER_ERROR_FILEACCESS, /**< File could not be opened etc. */
20 FILTER_NOTFOUND, /**< Filter not found */
24 * @brief File filter manager for handling filefilters.
26 * The FileFilterMgr loads a collection of named file filters from disk,
27 * and provides lookup access by name, or array access by index, to these
28 * named filters. It also provides test functions for actually using the
31 * We are using PCRE for regular expressions. Nice thing in PCRE is it supports
32 * UTF-8 unicode, unlike many other libs. For ANSI builds we use just ansi
33 * strings, and for unicode we must first convert strings to UTF-8.
41 // Reload filter array from specified directory (passed to CFileFind)
42 void LoadFromDirectory(const String& dir, const String& szPattern, const String& szExt);
43 // Reload an edited filter
44 int ReloadFilterFromDisk(FileFilter * pfilter);
45 int ReloadFilterFromDisk(const String& szFullPath);
46 // Load a filter from a string
47 void LoadFilterString(const String& szFilterString);
48 int AddFilter(const String& szFilterFile);
49 void RemoveFilter(const String& szFilterFile);
51 // access to array of filters
52 int GetFilterCount() const { return (int) m_filters.size(); }
53 String GetFilterName(int i) const;
54 String GetFilterName(const FileFilter *pFilter) const;
55 String GetFilterPath(int i) const;
56 String GetFilterDesc(int i) const;
57 String GetFilterDesc(const FileFilter *pFilter) const;
58 FileFilter * GetFilterByPath(const String& szFilterName);
59 FileFilter * GetFilterByIndex(int i);
60 String GetFullpath(FileFilter * pfilter) const;
62 // methods to actually use filter
63 bool TestFileNameAgainstFilter(const FileFilter * pFilter, const String& szFileName) const;
64 bool TestDirNameAgainstFilter(const FileFilter * pFilter, const String& szDirName) const;
66 void DeleteAllFilters();
67 void CloneFrom(const FileFilterMgr* fileFilterMgr);
69 // Implementation methods
71 // Clear the list of known filters
72 // Load a filter from a file (if syntax is valid)
73 FileFilter * LoadFilterFile(const String& szFilepath, int & errorcode);
75 // Implementation data
77 std::vector<FileFilterPtr> m_filters; /*< List of filters loaded */
81 bool TestAgainstRegList(const std::vector<FileFilterElementPtr> *filterList, const String& szTest);
82 void EmptyFilterList(std::vector<FileFilterElementPtr> *filterList);
85 * @brief Return name of filter.
87 * @param [in] i Index of filter.
88 * @return Name of filter in given index.
90 inline String FileFilterMgr::GetFilterName(int i) const
92 return m_filters[i]->name;
96 * @brief Return name of filter.
97 * @param [in] pFilter Filter to get name for.
98 * @return Given filter's name.
100 inline String FileFilterMgr::GetFilterName(const FileFilter *pFilter) const
102 return pFilter->name;
106 * @brief Return description of filter.
108 * @param [in] i Index of filter.
109 * @return Description of filter in given index.
111 inline String FileFilterMgr::GetFilterDesc(int i) const
113 return m_filters[i]->description;
117 * @brief Return description of filter.
118 * @param [in] pFilter Filter to get description for.
119 * @return Given filter's description.
121 inline String FileFilterMgr::GetFilterDesc(const FileFilter *pFilter) const
123 return pFilter->description;
127 * @brief Return full path to filter.
129 * @param [in] i Index of filter.
130 * @return Full path of filter in given index.
132 inline String FileFilterMgr::GetFilterPath(int i) const
134 return m_filters[i]->fullpath;
138 * @brief Return full path to filter.
140 * @param [in] pFilter Pointer to filter.
141 * @return Full path of filter.
143 inline String FileFilterMgr::GetFullpath(FileFilter * pfilter) const
145 return pfilter->fullpath;