]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kfileitemmodelfilter.h
f9f588aba2a024bdd3f6d9cbd6bfe52b2bc55d1a
[dolphin.git] / src / kitemviews / private / kfileitemmodelfilter.h
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 "dolphin_export.h"
25
26 #include <QStringList>
27
28 class KFileItem;
29 class QRegExp;
30
31 /**
32 * @brief Allows to check whether an item of the KFileItemModel
33 * matches with a set filter-string.
34 *
35 * Currently the filter is only checked for the KFileItem::text()
36 * property of the KFileItem, but this might get extended in
37 * future.
38 */
39 class DOLPHIN_EXPORT KFileItemModelFilter
40 {
41
42 public:
43 KFileItemModelFilter();
44 virtual ~KFileItemModelFilter();
45
46 /**
47 * Sets the pattern that is used for a comparison with the item
48 * in KFileItemModelFilter::matches(). Per default the pattern
49 * defines a sub-string. As soon as the pattern contains at least
50 * a '*', '?' or '[' the pattern represents a regular expression.
51 */
52 void setPattern(const QString& pattern);
53 QString pattern() const;
54
55 /**
56 * Set the list of mimetypes that are used for comparison with the
57 * item in KFileItemModelFilter::matchesMimeType.
58 */
59 void setMimeTypes(const QStringList& types);
60 QStringList mimeTypes() const;
61
62 /**
63 * @return True if either the pattern or mimetype filters has been set.
64 */
65 bool hasSetFilters() const;
66
67 /**
68 * @return True if the item matches with the pattern defined by
69 * @ref setPattern() or @ref setMimeTypes
70 */
71 bool matches(const KFileItem& item) const;
72
73 private:
74 /**
75 * @return True if item matches pattern set by @ref setPattern.
76 */
77 bool matchesPattern(const KFileItem& item) const;
78
79 /**
80 * @return True if item matches mimetypes set by @ref setMimeTypes.
81 */
82 bool matchesType(const KFileItem& item) const;
83
84 bool m_useRegExp; // If true, m_regExp is used for filtering,
85 // otherwise m_lowerCaseFilter is used.
86 QRegExp* m_regExp;
87 QString m_lowerCasePattern; // Lowercase version of m_filter for
88 // faster comparison in matches().
89 QString m_pattern; // Property set by setPattern().
90 QStringList m_mimeTypes; // Property set by setMimeTypes()
91 };
92 #endif
93
94