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 )
{
kdDebug(7003) << "+KDirLister" << endl;
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->delayedMimeTypes = _delayedMimeTypes;
setAutoUpdate( true );
setDirOnlyMode( false );
setShowingDotFiles( false );
setShowingHiddenFiles( false );
setAutoErrorHandlingEnabled( true, 0 );
}
@ -1931,6 +1935,7 @@ KDirLister::~KDirLister()
s_pCache->forgetDirs( this );
}
delete d->hiddenFileMatcher;
delete d;
}
@ -2015,18 +2020,28 @@ void KDirLister::setAutoUpdate( bool _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;
d->isShowingDotFiles = _showDotFiles;
d->changes ^= DOT_FILES;
d->isShowingHiddenFiles = _showHiddenFiles;
d->changes ^= HIDDEN_FILES;
}
bool KDirLister::showingDotFiles() const
{
return isShowingHiddenFiles();
}
void KDirLister::setShowingDotFiles( bool _showDotFiles )
{
setShowingHiddenFiles( _showDotFiles );
}
bool KDirLister::dirOnlyMode() const
@ -2114,10 +2129,11 @@ void KDirLister::emitChanges()
if ( (*kit)->isHidden() )
{
if ( d->changes & DOT_FILES )
if ( d->changes & HIDDEN_FILES )
{
// the lister switched to dot files mode
if ( d->isShowingDotFiles ) {
// the lister switched to hidden files mode
if ( d->isShowingHiddenFiles ) {
addNewItem( *kit );
}
else {
@ -2190,6 +2206,10 @@ KFileItem *KDirLister::find( const KURL& _url ) const
}
#endif
TDEStringMatcher *KDirLister::hiddenFileMatcher()
{
return d->hiddenFileMatcher;
}
// ================ public filter methods ================ //
@ -2280,7 +2300,7 @@ bool KDirLister::matchesFilter( const KFileItem *item ) const
if ( item->text() == dotdot )
return false;
if ( !d->isShowingDotFiles && item->isHidden() )
if ( !d->isShowingHiddenFiles && item->isHidden() )
return false;
if ( item->isDir() || d->lstFilters.isEmpty() )
@ -2371,6 +2391,10 @@ void KDirLister::addNewItem( const KFileItem *item )
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 ) ) {
return; // No reason to continue... bailing out here prevents a mimetype scan.
}

@ -159,23 +159,35 @@ public:
void setAutoErrorHandlingEnabled( bool enable, TQWidget *parent );
/**
* Checks whether hidden files (files beginning with a dot) will be
* shown.
* By default this option is disabled (hidden files will be not shown).
* @return true if dot files are shown, false otherwise
* @see setShowingDotFiles()
* 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 showingDotFiles() const;
bool isShowingHiddenFiles() const;
/**
* Changes the "is viewing dot files" setting.
* Changes the "is viewing hidden files" setting.
* 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
* @param show true to enable showing hidden files, false to
* disable
* @see isShowingHiddenFiles()
* @see also description of @property hiddenFileMatcher
*/
virtual void setShowingHiddenFiles( bool _showHiddenFiles );
/**
* @deprecated use isShowingHiddenFiles()
* @return true if dot files are shown, false otherwise
* @see setShowingDotFiles()
*/
bool showingDotFiles() const KDE_DEPRECATED;
/**
* @deprecated use setShowingHiddenFiles()
* @see showingDotFiles()
*/
virtual void setShowingDotFiles( bool _showDotFiles );
virtual void setShowingDotFiles( bool _showDotFiles ) KDE_DEPRECATED;
/**
* Checks whether the KDirLister only lists directories or all
@ -254,6 +266,17 @@ public:
KFileItem *find( const KURL& _url ) const;
#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.
* @param name the item name
@ -536,7 +559,7 @@ signals:
protected:
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