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

tdeio/tdeio

tdefilefilter.cpp

00001 /* This file is part of the KDE libraries
00002 
00003    Copyright (c) 2001,2002 Carsten Pfeiffer <pfeiffer@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License (LGPL) as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <tqregexp.h>
00022 
00023 #include <tdefileitem.h>
00024 #include <tdeglobal.h>
00025 
00026 #include "tdefilefilter.h"
00027 
00028 KSimpleFileFilter::KSimpleFileFilter()
00029     : m_filterDotFiles( true ),
00030       m_filterSpecials( true ),
00031       m_modeFilter( 0 )
00032 {
00033     m_nameFilters.setAutoDelete( true );
00034 }
00035 
00036 KSimpleFileFilter::~KSimpleFileFilter()
00037 {
00038 }
00039 
00040 void KSimpleFileFilter::setFilterDotFiles( bool filter )
00041 {
00042     m_filterDotFiles = filter;
00043 }
00044 
00045 void KSimpleFileFilter::setFilterSpecials( bool filter )
00046 {
00047     m_filterSpecials = filter;
00048 }
00049 
00050 void KSimpleFileFilter::setNameFilters( const TQString& nameFilters )
00051 {
00052     // KDE 3.0 defaults
00053     setNameFilters( nameFilters, false, ' ' );
00054 }
00055 
00056 void KSimpleFileFilter::setNameFilters( const TQString& nameFilters,
00057                                         bool caseSensitive, 
00058                                         const TQChar& separator )
00059 {
00060     m_nameFilters.clear();
00061 
00062     // Split on white space
00063     TQStringList list = TQStringList::split(separator, nameFilters);
00064 
00065     TQStringList::ConstIterator it = list.begin();
00066     for ( ; it != list.end(); ++it )
00067         m_nameFilters.append(new TQRegExp(*it, caseSensitive, true ));
00068 }
00069 
00070 void KSimpleFileFilter::setMimeFilters( const TQStringList& mimeFilters )
00071 {
00072     m_mimeFilters = mimeFilters;
00073 }
00074 
00075 void KSimpleFileFilter::setModeFilter( mode_t mode )
00076 {
00077     m_modeFilter = mode;
00078 }
00079 
00080 bool KSimpleFileFilter::passesFilter( const KFileItem *item ) const
00081 {
00082     static const TQString& dot    = TDEGlobal::staticQString(".");
00083     static const TQString& dotdot = TDEGlobal::staticQString("..");
00084 
00085     const TQString& name = item->name();
00086 
00087     if ( m_filterDotFiles && item->isHidden() )
00088         return false;
00089 
00090     if ( m_filterSpecials && (name == dot || name == dotdot) )
00091         return false;
00092 
00093     if ( m_modeFilter && !(m_modeFilter & item->mode()) )
00094         return false;
00095 
00096     if ( !m_mimeFilters.isEmpty() ) {
00097         // correct or guessed mimetype -- we don't mind
00098         KMimeType::Ptr mime = item->mimeTypePtr();
00099         bool ok = false;
00100 
00101         TQStringList::ConstIterator it = m_mimeFilters.begin();
00102         for ( ; it != m_mimeFilters.end(); ++it ) {
00103             if ( mime->is(*it) ) { // match!
00104                 ok = true;
00105                 break;
00106             }
00107         }
00108         if ( !ok )
00109             return false;
00110     }
00111 
00112     if ( !m_nameFilters.isEmpty() ) {
00113         bool ok = false;
00114 
00115         TQPtrListIterator<TQRegExp> it( m_nameFilters );
00116         for ( ; it.current(); ++it ) {
00117             if ( it.current()->exactMatch( name ) ) { // match!
00118                 ok = true;
00119                 break;
00120             }
00121         }
00122         if ( !ok )
00123             return false;
00124     }
00125 
00126     return true; // passes the filter!
00127 }
00128 
00129 void KFileFilter::virtual_hook( int, void* )
00130 { /*BASE::virtual_hook( id, data );*/ }
00131 
00132 void KSimpleFileFilter::virtual_hook( int id, void* data )
00133 { KFileFilter::virtual_hook( id, data ); }
00134 

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.6.3
This website is maintained by Timothy Pearson.