1 /***************************************************************************
2 * Copyright (C) 2011 by Janardhan Reddy *
3 * <annapareddyjanardhanreddy@gmail.com> *
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. *
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. *
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 ***************************************************************************/
21 #ifndef KFILEITEMMODELFILTER_H
22 #define KFILEITEMMODELFILTER_H
24 #include <libdolphin_export.h>
25 #include <QStringList>
31 * @brief Allows to check whether an item of the KFileItemModel
32 * matches with a set filter-string.
34 * Currently the filter is only checked for the KFileItem::text()
35 * property of the KFileItem, but this might get extended in
38 class LIBDOLPHINPRIVATE_EXPORT KFileItemModelFilter
42 KFileItemModelFilter();
43 virtual ~KFileItemModelFilter();
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.
51 void setPattern(const QString
& pattern
);
52 QString
pattern() const;
55 * Set the list of mimetypes that are used for comparison with the
56 * item in KFileItemModelFilter::matchesMimeType.
58 void setMimeTypes(const QStringList
& types
);
59 QStringList
mimeTypes() const;
62 * @return True if either the pattern or mimetype filters has been set.
64 bool hasSetFilters() const;
67 * @return True if the item matches with the pattern defined by
68 * @ref setPattern() or @ref setMimeTypes
70 bool matches(const KFileItem
& item
) const;
74 * @return True if item matches pattern set by @ref setPattern.
76 bool matchesPattern(const KFileItem
& item
) const;
79 * @return True if item matches mimetypes set by @ref setMimeTypes.
81 bool matchesType(const KFileItem
& item
) const;
83 bool m_useRegExp
; // If true, m_regExp is used for filtering,
84 // otherwise m_lowerCaseFilter is used.
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()