]> git.lyx.org Git - lyx.git/blob - src/support/FileFilterList.h
fix linking error in the frontend
[lyx.git] / src / support / FileFilterList.h
1 // -*- C++ -*-
2 /**
3  * \file FileFilterList.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef FILE_FILTER_LIST_H
13 #define FILE_FILTER_LIST_H
14
15 #include "support/docstring.h"
16
17 #include <string>
18 #include <vector>
19
20 namespace lyx {
21 namespace support {
22
23 /** \c FileFilterList parses a Qt-style list of available file filters
24  *  to generate the corresponding vector.
25  *  For example "TeX documents (*.tex);;LyX Documents (*.lyx)"
26  *  will be parsed to fill a vector of size 2, whilst "*.{p[bgp]m} *.pdf"
27  *  will result in a vector of size 1 in which the description field is empty.
28  */
29 class FileFilterList {
30 public:
31         // FIXME UNICODE: globs_ should be unicode...
32         class Filter {
33                 lyx::docstring desc_;
34                 std::vector<std::string> globs_;
35         public:
36                 /* \param description text describing the filters.
37                  * \param one or more wildcard patterns, separated by
38                  * whitespace.
39                  */
40                 Filter(lyx::docstring const & description,
41                        std::string const & globs);
42
43                 lyx::docstring const & description() const { return desc_; }
44
45                 typedef std::vector<std::string>::const_iterator glob_iterator;
46                 glob_iterator begin() const { return globs_.begin(); }
47                 glob_iterator end() const { return globs_.end(); }
48         };
49
50         /** \param qt_style_filter a list of available file filters.
51          *  Eg. "TeX documents (*.tex);;LyX Documents (*.lyx)".
52          *  The "All files (*)" filter is always added to the list.
53          */
54         explicit FileFilterList(lyx::docstring const & qt_style_filter =
55                                 lyx::docstring());
56
57         typedef std::vector<Filter>::size_type size_type;
58
59         bool empty() const { return filters_.empty(); }
60         size_type size() const { return filters_.size(); }
61         Filter & operator[](size_type i) { return filters_[i]; }
62         Filter const & operator[](size_type i) const { return filters_[i]; }
63
64         /** \returns the equivalent of the string passed to the c-tor
65          *  although any brace expressions are expanded.
66          *  (E.g. "*.{png,jpg}" -> "*.png *.jpg")
67          */
68         lyx::docstring const as_string() const;
69
70 private:
71         void parse_filter(std::string const & filter);
72         std::vector<Filter> filters_;
73 };
74
75 } // namespace support
76 } // namespace lyx
77
78 #endif // NOT FILE_FILTER_LIST_H