]> git.lyx.org Git - lyx.git/blob - src/support/filefilterlist.h
Give FileFilterList its own .[Ch] files.
[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::string globs_;
32         public:
33                 Filter(std::string const & d, std::string const & g)
34                         : desc_(d), globs_(g) {}
35                 std::string const & description() const { return desc_; }
36                 std::string const & globs() const { return globs_; }
37         };
38
39         /** \param qt_style_filter a list of available file filters.
40          *  Eg. "TeX documents (*.tex);;LyX Documents (*.lyx)".
41          *  The "All files (*)" filter is always added to the list.
42          */
43         explicit FileFilterList(std::string const & qt_style_filter = std::string());
44         std::vector<Filter> const & filters() const { return filters_; }
45
46         /** \param expand pass each glob through \c convert_brace_glob.
47          *  \returns the equivalent of the string passed to the c-tor.
48          */
49         std::string const str(bool expand) const;
50
51 private:
52         void parse_filter(std::string const & filter);
53         std::vector<Filter> filters_;
54 };
55
56 } // namespace support
57 } // namespace lyx
58
59 #endif // NOT FILE_FILTER_LIST_H