1/***************************************************************************
2 * Copyright (C) 2011 by Janardhan Reddy *
3 * <annapareddyjanardhanreddy@gmail.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21#ifndef KFILEITEMMODELFILTER_H
22#define KFILEITEMMODELFILTER_H
23
24#include <libdolphin_export.h>
25#include <QStringList>
26
27class KFileItem;
28class QRegExp;
29
30/**
31 * @brief Allows to check whether an item of the KFileItemModel
32 * matches with a set filter-string.
33 *
34 * Currently the filter is only checked for the KFileItem::text()
35 * property of the KFileItem, but this might get extended in
36 * future.
37 */
38class LIBDOLPHINPRIVATE_EXPORT KFileItemModelFilter
39{
40
41public:
42 KFileItemModelFilter();
43 virtual ~KFileItemModelFilter();
44
45 /**
46 * Sets the pattern that is used for a comparison with the item
47 * in KFileItemModelFilter::matches(). Per default the pattern
48 * defines a sub-string. As soon as the pattern contains at least
49 * a '*', '?' or '[' the pattern represents a regular expression.
50 */
51 void setPattern(const QString& pattern);
52 QString pattern() const;
53
54 /**
55 * Set the list of mimetypes that are used for comparison with the
56 * item in KFileItemModelFilter::matchesMimeType.
57 */
58 void setMimeTypes(const QStringList& types);
59 QStringList mimeTypes() const;
60
61 /**
62 * @return True if either the pattern or mimetype filters has been set.
63 */
64 bool hasSetFilters() const;
65
66 /**
67 * @return True if the item matches with the pattern defined by
68 * @ref setPattern() or @ref setMimeTypes
69 */
70 bool matches(const KFileItem& item) const;
71
72private:
73 /**
74 * @return True if item matches pattern set by @ref setPattern.
75 */
76 bool matchesPattern(const KFileItem& item) const;
77
78 /**
79 * @return True if item matches mimetypes set by @ref setMimeTypes.
80 */
81 bool matchesType(const KFileItem& item) const;
82
83 bool m_useRegExp; // If true, m_regExp is used for filtering,
84 // otherwise m_lowerCaseFilter is used.
85 QRegExp* m_regExp;
86 QString m_lowerCasePattern; // Lowercase version of m_filter for
87 // faster comparison in matches().
88 QString m_pattern; // Property set by setPattern().
89 QStringList m_mimeTypes; // Property set by setMimeTypes()
90};
91#endif
92
93
94