• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
tdefilefilter.cpp
1/* This file is part of the KDE libraries
2
3 Copyright (c) 2001,2002 Carsten Pfeiffer <pfeiffer@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License (LGPL) as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library 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 GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include <tqregexp.h>
22
23#include <tdefileitem.h>
24#include <tdeglobal.h>
25
26#include "tdefilefilter.h"
27
28KSimpleFileFilter::KSimpleFileFilter()
29 : m_filterDotFiles( true ),
30 m_filterSpecials( true ),
31 m_modeFilter( 0 )
32{
33 m_nameFilters.setAutoDelete( true );
34}
35
36KSimpleFileFilter::~KSimpleFileFilter()
37{
38}
39
40void KSimpleFileFilter::setFilterDotFiles( bool filter )
41{
42 m_filterDotFiles = filter;
43}
44
45void KSimpleFileFilter::setFilterSpecials( bool filter )
46{
47 m_filterSpecials = filter;
48}
49
50void KSimpleFileFilter::setNameFilters( const TQString& nameFilters )
51{
52 // KDE 3.0 defaults
53 setNameFilters( nameFilters, false, ' ' );
54}
55
56void KSimpleFileFilter::setNameFilters( const TQString& nameFilters,
57 bool caseSensitive,
58 const TQChar& separator )
59{
60 m_nameFilters.clear();
61
62 // Split on white space
63 TQStringList list = TQStringList::split(separator, nameFilters);
64
65 TQStringList::ConstIterator it = list.begin();
66 for ( ; it != list.end(); ++it )
67 m_nameFilters.append(new TQRegExp(*it, caseSensitive, true ));
68}
69
70void KSimpleFileFilter::setMimeFilters( const TQStringList& mimeFilters )
71{
72 m_mimeFilters = mimeFilters;
73}
74
75void KSimpleFileFilter::setModeFilter( mode_t mode )
76{
77 m_modeFilter = mode;
78}
79
80bool KSimpleFileFilter::passesFilter( const KFileItem *item ) const
81{
82 static const TQString& dot = TDEGlobal::staticQString(".");
83 static const TQString& dotdot = TDEGlobal::staticQString("..");
84
85 const TQString& name = item->name();
86
87 if ( m_filterDotFiles && item->isHidden() )
88 return false;
89
90 if ( m_filterSpecials && (name == dot || name == dotdot) )
91 return false;
92
93 if ( m_modeFilter && !(m_modeFilter & item->mode()) )
94 return false;
95
96 if ( !m_mimeFilters.isEmpty() ) {
97 // correct or guessed mimetype -- we don't mind
98 KMimeType::Ptr mime = item->mimeTypePtr();
99 bool ok = false;
100
101 TQStringList::ConstIterator it = m_mimeFilters.begin();
102 for ( ; it != m_mimeFilters.end(); ++it ) {
103 if ( mime->is(*it) ) { // match!
104 ok = true;
105 break;
106 }
107 }
108 if ( !ok )
109 return false;
110 }
111
112 if ( !m_nameFilters.isEmpty() ) {
113 bool ok = false;
114
115 TQPtrListIterator<TQRegExp> it( m_nameFilters );
116 for ( ; it.current(); ++it ) {
117 if ( it.current()->exactMatch( name ) ) { // match!
118 ok = true;
119 break;
120 }
121 }
122 if ( !ok )
123 return false;
124 }
125
126 return true; // passes the filter!
127}
128
129void KFileFilter::virtual_hook( int, void* )
130{ /*BASE::virtual_hook( id, data );*/ }
131
132void KSimpleFileFilter::virtual_hook( int id, void* data )
133{ KFileFilter::virtual_hook( id, data ); }
134
KFileItem
A KFileItem is a generic class to handle a file, local or remote.
Definition: tdefileitem.h:42
KFileItem::mimeTypePtr
KMimeType::Ptr mimeTypePtr() const
Returns the currently known mimetype of the file item.
Definition: tdefileitem.h:358
KFileItem::mode
mode_t mode() const
Returns the file type (stat.st_mode containing only S_IFDIR, S_IFLNK, ...).
Definition: tdefileitem.h:181
KFileItem::name
const TQString & name(bool lowerCase=false) const
Return the name of the file item (without a path).
Definition: tdefileitem.h:312
KFileItem::isHidden
bool isHidden() const
Checks whether the file is hidden.
Definition: tdefileitem.cpp:833
KSimpleFileFilter::setFilterSpecials
virtual void setFilterSpecials(bool filter)
Filters "." and "..", default is true.
Definition: tdefilefilter.cpp:45
KSimpleFileFilter::setMimeFilters
virtual void setMimeFilters(const TQStringList &mimeFilters)
Sets a list of mime filters.
Definition: tdefilefilter.cpp:70
KSimpleFileFilter::passesFilter
virtual bool passesFilter(const KFileItem *item) const
Checks the given item.
Definition: tdefilefilter.cpp:80
KSimpleFileFilter::setModeFilter
virtual void setModeFilter(mode_t mode)
Sets the mode filter.
Definition: tdefilefilter.cpp:75
KSimpleFileFilter::KSimpleFileFilter
KSimpleFileFilter()
Creates a new filter.
Definition: tdefilefilter.cpp:28
KSimpleFileFilter::mimeFilters
TQStringList mimeFilters() const
Returns the list of mime types.
Definition: tdefilefilter.h:131
KSimpleFileFilter::setNameFilters
void setNameFilters(const TQString &nameFilters, bool caseSensitive, const TQChar &separator=' ')
Sets a list of regular expressions to filter by name.
Definition: tdefilefilter.cpp:56
KSimpleFileFilter::setFilterDotFiles
virtual void setFilterDotFiles(bool filter)
Enable or disable filtering hidden dot files.
Definition: tdefilefilter.cpp:40

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.4
This website is maintained by Timothy Pearson.