]> git.lyx.org Git - lyx.git/blob - src/support/filefilterlist.h
make "make distcheck" work
[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 <string>
16 #include <vector>
17
18 namespace lyx {
19 namespace support {
20
21 /** \c FileFilterList parses a Qt-style list of available file filters
22  *  to generate the corresponding vector.
23  *  For example "TeX documents (*.tex);;LyX Documents (*.lyx)"
24  *  will be parsed to fill a vector of size 2, whilst "*.{p[bgp]m} *.pdf"
25  *  will result in a vector of size 1 in which the description field is empty.
26  */
27 class FileFilterList {
28 public:
29         class Filter {
30                 std::string desc_;
31                 std::vector<std::string> globs_;
32         public:
33                 /* \param description text describing the filters.
34                  * \param one or more wildcard patterns, separated by
35                  * whitespace.
36                  */
37                 Filter(std::string const & description,
38                        std::string const & globs);
39
40                 std::string const & description() const { return desc_; }
41
42                 typedef std::vector<std::string>::const_iterator glob_iterator;
43                 glob_iterator begin() const { return globs_.begin(); }
44                 glob_iterator end() const { return globs_.end(); }
45         };
46
47         /** \param qt_style_filter a list of available file filters.
48          *  Eg. "TeX documents (*.tex);;LyX Documents (*.lyx)".
49          *  The "All files (*)" filter is always added to the list.
50          */
51         explicit FileFilterList(std::string const & qt_style_filter =
52                                 std::string());
53
54         typedef std::vector<Filter>::size_type size_type;
55
56         bool empty() const { return filters_.empty(); }
57         size_type size() const { return filters_.size(); }
58         Filter & operator[](size_type i) { return filters_[i]; }
59         Filter const & operator[](size_type i) const { return filters_[i]; }
60
61         /** \returns the equivalent of the string passed to the c-tor
62          *  although any brace expressions are expanded.
63          *  (E.g. "*.{png,jpg}" -> "*.png *.jpg")
64          */
65         std::string const as_string() const;
66
67 private:
68         void parse_filter(std::string const & filter);
69         std::vector<Filter> filters_;
70 };
71
72 } // namespace support
73 } // namespace lyx
74
75 #endif // NOT FILE_FILTER_LIST_H