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

kio/kio

  • kio
  • kio
kfilefilter.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 <kfileitem.h>
24 #include <kglobal.h>
25 
26 #include "kfilefilter.h"
27 
28 KSimpleFileFilter::KSimpleFileFilter()
29  : m_filterDotFiles( true ),
30  m_filterSpecials( true ),
31  m_modeFilter( 0 )
32 {
33  m_nameFilters.setAutoDelete( true );
34 }
35 
36 KSimpleFileFilter::~KSimpleFileFilter()
37 {
38 }
39 
40 void KSimpleFileFilter::setFilterDotFiles( bool filter )
41 {
42  m_filterDotFiles = filter;
43 }
44 
45 void KSimpleFileFilter::setFilterSpecials( bool filter )
46 {
47  m_filterSpecials = filter;
48 }
49 
50 void KSimpleFileFilter::setNameFilters( const TQString& nameFilters )
51 {
52  // KDE 3.0 defaults
53  setNameFilters( nameFilters, false, ' ' );
54 }
55 
56 void 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 
70 void KSimpleFileFilter::setMimeFilters( const TQStringList& mimeFilters )
71 {
72  m_mimeFilters = mimeFilters;
73 }
74 
75 void KSimpleFileFilter::setModeFilter( mode_t mode )
76 {
77  m_modeFilter = mode;
78 }
79 
80 bool KSimpleFileFilter::passesFilter( const KFileItem *item ) const
81 {
82  static const TQString& dot = KGlobal::staticQString(".");
83  static const TQString& dotdot = KGlobal::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 
129 void KFileFilter::virtual_hook( int, void* )
130 { /*BASE::virtual_hook( id, data );*/ }
131 
132 void KSimpleFileFilter::virtual_hook( int id, void* data )
133 { KFileFilter::virtual_hook( id, data ); }
134 

kio/kio

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

kio/kio

Skip menu "kio/kio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kio by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |