Enable KDirLister to utilize its own custom TDEHiddenFileMatcher

object instead of the global instance.

Signed-off-by: Vincent Reher <tde@4reher.org>
issue/270/tdelibs-V4
Vincent Reher 1 year ago
parent 5fe559d378
commit 2d9363f2bd

@ -1907,15 +1907,19 @@ void KDirListerCache::printDebug()
KDirLister::KDirLister( bool _delayedMimeTypes ) KDirLister::KDirLister( bool _delayedMimeTypes )
{ {
kdDebug(7003) << "+KDirLister" << endl; kdDebug(7003) << "+KDirLister" << endl;
d = new KDirListerPrivate; d = new KDirListerPrivate;
// Create a separate "copy" of the global hidden file matcher
TSMTRACE << "KDirLister::KDirLister: Allocating a hidden file matcher" << endl;
d->hiddenFileMatcher = new TDEStringMatcher;
d->hiddenFileMatcher->setMatchSpecs( TDEGlobal::hiddenFileMatcher()->getMatchSpecString() );
d->complete = true; d->complete = true;
d->delayedMimeTypes = _delayedMimeTypes; d->delayedMimeTypes = _delayedMimeTypes;
setAutoUpdate( true ); setAutoUpdate( true );
setDirOnlyMode( false ); setDirOnlyMode( false );
setShowingDotFiles( false ); setShowingHiddenFiles( false );
setAutoErrorHandlingEnabled( true, 0 ); setAutoErrorHandlingEnabled( true, 0 );
} }
@ -1931,6 +1935,7 @@ KDirLister::~KDirLister()
s_pCache->forgetDirs( this ); s_pCache->forgetDirs( this );
} }
delete d->hiddenFileMatcher;
delete d; delete d;
} }
@ -2015,18 +2020,28 @@ void KDirLister::setAutoUpdate( bool _enable )
s_pCache->setAutoUpdate( this, _enable ); s_pCache->setAutoUpdate( this, _enable );
} }
bool KDirLister::showingDotFiles() const bool KDirLister::isShowingHiddenFiles() const
{ {
return d->isShowingDotFiles; return d->isShowingHiddenFiles;
} }
void KDirLister::setShowingDotFiles( bool _showDotFiles ) void KDirLister::setShowingHiddenFiles( bool _showHiddenFiles )
{ {
if ( d->isShowingDotFiles == _showDotFiles ) if ( d->isShowingHiddenFiles == _showHiddenFiles )
return; return;
d->isShowingDotFiles = _showDotFiles; d->isShowingHiddenFiles = _showHiddenFiles;
d->changes ^= DOT_FILES; d->changes ^= HIDDEN_FILES;
}
bool KDirLister::showingDotFiles() const
{
return isShowingHiddenFiles();
}
void KDirLister::setShowingDotFiles( bool _showDotFiles )
{
setShowingHiddenFiles( _showDotFiles );
} }
bool KDirLister::dirOnlyMode() const bool KDirLister::dirOnlyMode() const
@ -2114,10 +2129,11 @@ void KDirLister::emitChanges()
if ( (*kit)->isHidden() ) if ( (*kit)->isHidden() )
{ {
if ( d->changes & DOT_FILES ) if ( d->changes & HIDDEN_FILES )
{ {
// the lister switched to dot files mode // the lister switched to hidden files mode
if ( d->isShowingDotFiles ) { if ( d->isShowingHiddenFiles ) {
addNewItem( *kit ); addNewItem( *kit );
} }
else { else {
@ -2190,6 +2206,10 @@ KFileItem *KDirLister::find( const KURL& _url ) const
} }
#endif #endif
TDEStringMatcher *KDirLister::hiddenFileMatcher()
{
return d->hiddenFileMatcher;
}
// ================ public filter methods ================ // // ================ public filter methods ================ //
@ -2280,7 +2300,7 @@ bool KDirLister::matchesFilter( const KFileItem *item ) const
if ( item->text() == dotdot ) if ( item->text() == dotdot )
return false; return false;
if ( !d->isShowingDotFiles && item->isHidden() ) if ( !d->isShowingHiddenFiles && item->isHidden() )
return false; return false;
if ( item->isDir() || d->lstFilters.isEmpty() ) if ( item->isDir() || d->lstFilters.isEmpty() )
@ -2371,6 +2391,10 @@ void KDirLister::addNewItem( const KFileItem *item )
const_cast<KFileItem*>(item)->setURL(newItemURL); const_cast<KFileItem*>(item)->setURL(newItemURL);
} }
// Replace KFileItem default hidden file matcher with our own.
//-Debug: TSMTRACE << "KDirLister::addNewItem() installing custom matcher for " << item->url().fileName() <<endl ;
const_cast<KFileItem*>(item)->setHiddenFileMatcher( d->hiddenFileMatcher );
if ( ( d->dirOnlyMode && !item->isDir() ) || !matchesFilter( item ) ) { if ( ( d->dirOnlyMode && !item->isDir() ) || !matchesFilter( item ) ) {
return; // No reason to continue... bailing out here prevents a mimetype scan. return; // No reason to continue... bailing out here prevents a mimetype scan.
} }

@ -158,24 +158,36 @@ public:
*/ */
void setAutoErrorHandlingEnabled( bool enable, TQWidget *parent ); void setAutoErrorHandlingEnabled( bool enable, TQWidget *parent );
/**
* Checks whether hidden files will be shown. By default this
* option is disabled (hidden files will be not shown).
* @return true if hidden files are shown, false otherwise
* @see setShowingHiddenFiles()
*/
bool isShowingHiddenFiles() const;
/**
* Changes the "is viewing hidden files" setting.
* Calls updateDirectory() if setting changed.
* @param show true to enable showing hidden files, false to
* disable
* @see isShowingHiddenFiles()
* @see also description of @property hiddenFileMatcher
*/
virtual void setShowingHiddenFiles( bool _showHiddenFiles );
/** /**
* Checks whether hidden files (files beginning with a dot) will be * @deprecated use isShowingHiddenFiles()
* shown.
* By default this option is disabled (hidden files will be not shown).
* @return true if dot files are shown, false otherwise * @return true if dot files are shown, false otherwise
* @see setShowingDotFiles() * @see setShowingDotFiles()
*/ */
bool showingDotFiles() const; bool showingDotFiles() const KDE_DEPRECATED;
/** /**
* Changes the "is viewing dot files" setting. * @deprecated use setShowingHiddenFiles()
* Calls updateDirectory() if setting changed.
* By default this option is disabled (hidden files will not be shown).
* @param _showDotFiles true to enable showing hidden files, false to
* disable
* @see showingDotFiles() * @see showingDotFiles()
*/ */
virtual void setShowingDotFiles( bool _showDotFiles ); virtual void setShowingDotFiles( bool _showDotFiles ) KDE_DEPRECATED;
/** /**
* Checks whether the KDirLister only lists directories or all * Checks whether the KDirLister only lists directories or all
@ -254,6 +266,17 @@ public:
KFileItem *find( const KURL& _url ) const; KFileItem *find( const KURL& _url ) const;
#endif #endif
/**
* @return the pointer
* to the object that encapsulates criteria for determining whether
* or not the filesystem objects managed by this KDirLister should
* be hidden based on characteristics of their names. This object is
* passed to KFileItem::setHiddenFileMatcher() for each associated
* filesystem entity so the determination of "hidden" can be made using
* KDirLister's own hiddenFileMatcher instead of KFileItem's default.
*/
TDEStringMatcher *hiddenFileMatcher();
/** /**
* Find an item by its name. * Find an item by its name.
* @param name the item name * @param name the item name
@ -536,7 +559,7 @@ signals:
protected: protected:
enum Changes { enum Changes {
NONE=0, NAME_FILTER=1, MIME_FILTER=2, DOT_FILES=4, DIR_ONLY_MODE=8 NONE=0, NAME_FILTER=1, MIME_FILTER=2, HIDDEN_FILES=4, DIR_ONLY_MODE=8
}; };
/** /**

Loading…
Cancel
Save