summaryrefslogtreecommitdiffstats
path: root/kio/kio/kfilefilter.h
blob: b17d2fe74d0859314af8a71e9e759fa275503735 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* This file is part of the KDE libraries

   Copyright (c) 2001,2002 Carsten Pfeiffer <pfeiffer@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License (LGPL) as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef KFILEFILTER_H
#define KFILEFILTER_H

#include <tqptrlist.h>
#include <tqstringlist.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include <tdelibs_export.h>

class TQRegExp;
class KFileItem;

/**
 * A KFileFilter is a simple base class for file filters. Just
 * reimplement passesFilter().
 * @short Base class for file filters.
 */
class KIO_EXPORT KFileFilter
{
public:
    /**
     * Checks the given @p item.
     * @param item the item to filter
     * @return true if the @p item passes the filter, false otherwise
     */
    virtual bool passesFilter( const KFileItem *item ) const = 0;
protected:
    virtual void virtual_hook( int id, void* data );
};

/**
 * A simple file filter that can filter hidden dot files, by name, 
 * by mime type and by mode.
 * @short A simple file filter.
 */
class KIO_EXPORT KSimpleFileFilter : public KFileFilter
{
public:
    /**
     * Creates a new filter. By default, it filters only hidden dot files
     * and "." and "..".
     */
    KSimpleFileFilter();
    virtual ~KSimpleFileFilter();

    /**
     * Enable or disable filtering hidden dot files.
     * This option is enabled by default.
     * @param filter true to enable filtering dot files, false to 
     *        disable
     * @see filterDotFiles
     */
    virtual void setFilterDotFiles( bool filter );
    /**
     * Checks whether filtering dot files is enabled.
     * This option is enabled by default.
     * @return true if filtering is enabled, false otherwise
     * @see setFilterDotFiles
     */
    bool filterDotFiles() const { return m_filterDotFiles; }

    /**
     * Filters "." and "..", default is true.
     * @param filter true to enable, false otherwise
     */
    virtual void setFilterSpecials( bool filter );
    /**
     * Checks whether it filters "." and "..", default is true.
     * @return true if enabled, false otherwise
     */
    bool filterSpecials() const { return m_filterSpecials; }

    // ### KDE4 make virtual and bool caseSensitive = false
    /**
     * Sets a list of regular expressions to filter by name.
     * The file will only pass if its name matches one of the regular
     * expressions.
     * @param nameFilters a list of regular expressions, separated by
     *                    the character @p separator
     * @param caseSensitive if true, matches case sensitive. False 
     *                      otherwise
     * @param separator the separator in the @p nameFilter
     * @since 3.1
     */
    void setNameFilters( const TQString& nameFilters, bool caseSensitive,
                         const TQChar& separator = ' ' );
    /**
     * Sets a list of regular expressions to filter by name.
     * The file will only pass if its name matches one of the regular
     * expressions.
     * @param nameFilters a list of regular expressions, separated by
     *                    space (' ')
     */
    virtual void setNameFilters( const TQString& nameFilters );

    /**
     * Sets a list of mime filters. A file can only pass if its
     * mime type is contained in this list.
     * @param mimeFilters the list of mime types
     * @see setMimeFilter
     */
    virtual void setMimeFilters( const TQStringList& mimeFilters );
    /**
     * Returns the list of mime types.
     * @return the list of mime types
     * @see mimeFilter
     */
    TQStringList mimeFilters() const { return m_mimeFilters; }

    /**
     * Sets the mode filter. If the @p mode is 0, the filter is
     * disabled. 
     * When enabled, a file will only pass if the files mode
     * ANDed with @p mode is not zero.
     * @param mode the new mode. 0 to disable
     * @see modeFilter
     */
    virtual void setModeFilter( mode_t mode );
    /**
     * Returns the mode filter, as set by setModeFilter().
     * @return the mode filter, 0 if disabled
     * @see setModeFilter
     */
    mode_t modeFilter() const { return m_modeFilter; }

    /**
     * Checks the given @p item.
     * @param item the item to filter
     * @return true if the @p item passes the filter, false otherwise
     */
    virtual bool passesFilter( const KFileItem *item ) const;

protected:
    TQPtrList<TQRegExp>   m_nameFilters;

private:
    TQStringList         m_mimeFilters;
    bool                m_filterDotFiles :1;
    bool                m_filterSpecials :1;
    mode_t              m_modeFilter;
protected:
    virtual void virtual_hook( int id, void* data );
private:
    class KSimpleFileFilterPrivate* d;
};

#endif // KFILEFILTER_H