You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
3.4 KiB
C++
129 lines
3.4 KiB
C++
#include "tdestringmatcher.h"
|
|
#include "tdestringmatcher-dialog.h"
|
|
|
|
#include <tqregexp.h>
|
|
#include "tdeconfig.h"
|
|
#include "kdebug.h"
|
|
|
|
TDEStringMatcher::TDEStringMatcher()
|
|
{
|
|
patternsDivider = patternsDividerDefault;
|
|
setCriteria( criteriaMatchNothing );
|
|
}
|
|
|
|
TDEStringMatcher::~TDEStringMatcher()
|
|
{
|
|
}
|
|
|
|
bool TDEStringMatcher::match( const TQString& filename )
|
|
{
|
|
TQRegExp rxMatcher;
|
|
if ( filename.isEmpty() )
|
|
return FALSE;
|
|
rxMatcher.setWildcard( ! isRegex );
|
|
rxMatcher.setCaseSensitive( ! isCaseInsensitive );
|
|
for ( TQStringList::iterator it = patternList.begin(); it != patternList.end() ; ++it )
|
|
{
|
|
rxMatcher.setPattern( *it );
|
|
if ( rxMatcher.exactMatch( filename ) ) {
|
|
return( TRUE ) ;
|
|
}
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
TQString TDEStringMatcher::getCriteria()
|
|
{
|
|
return Criteria;
|
|
}
|
|
|
|
void TDEStringMatcher::generateCriteria()
|
|
{
|
|
TQString newCriteria = patternList.join( TQString ( patternsDivider ) ) ;
|
|
TQChar leadingChar;
|
|
if ( isRegex )
|
|
leadingChar = 'r';
|
|
else
|
|
leadingChar = 'w' ;
|
|
if ( isCaseInsensitive )
|
|
leadingChar = leadingChar.upper();
|
|
newCriteria.prepend( leadingChar );
|
|
Criteria = newCriteria;
|
|
}
|
|
|
|
bool TDEStringMatcher::setCriteria( TQString newCriteria )
|
|
{
|
|
if ( newCriteria.length() == 0 ) {
|
|
return TRUE; // We always succeed when asked to do nothing!
|
|
}
|
|
|
|
TQChar optionsChar = newCriteria[0];
|
|
switch( optionsChar ) {
|
|
case 'w': isRegex = FALSE; isCaseInsensitive = FALSE; break;
|
|
case 'W': isRegex = FALSE; isCaseInsensitive = TRUE; break;
|
|
case 'r': isRegex = TRUE; isCaseInsensitive = FALSE; break;
|
|
case 'R': isRegex = TRUE; isCaseInsensitive = TRUE; break;
|
|
default :
|
|
kdWarning(7077)
|
|
<< "TDEStringMatcher::setCriteria: invalid leading character in criteria string: '"
|
|
<< newCriteria << "'" << endl;
|
|
return FALSE;
|
|
};
|
|
|
|
patternList.clear();
|
|
patternList = TQStringList::split( patternsDivider, newCriteria.mid(1), TRUE );
|
|
Criteria = newCriteria;
|
|
return TRUE;
|
|
}
|
|
|
|
int TDEStringMatcher::getMatchPropertiesFromUser( TQString dialogTitle )
|
|
{
|
|
Customize_TDEStringMatcher_Dialog defineHiddenUI =
|
|
Customize_TDEStringMatcher_Dialog( patternList, isRegex, isCaseInsensitive, dialogTitle );
|
|
|
|
defineHiddenUI.exec();
|
|
if ( defineHiddenUI.result() > CriteriaUnchanged ) {
|
|
patternList = defineHiddenUI.getPatternList();
|
|
isRegex = defineHiddenUI.isPatternRegex();
|
|
isCaseInsensitive = defineHiddenUI.isPatternCaseInsensitive();
|
|
generateCriteria();
|
|
kdDebug(7077)
|
|
<< "TDEStringMatcher::getMatchPropertiesFromUser: updated criteria string: '"
|
|
<< Criteria << "'" << endl;
|
|
}
|
|
return defineHiddenUI.result();
|
|
}
|
|
|
|
void TDEStringMatcher::setPatternsDivider( TQChar newPatternsDivider )
|
|
{
|
|
patternsDivider = newPatternsDivider;
|
|
}
|
|
|
|
|
|
|
|
TDEHiddenFileMatcher::TDEHiddenFileMatcher()
|
|
{
|
|
setPatternsDivider( patternsDivider4fileNames );
|
|
setCriteria( getGlobalCriteria() );
|
|
}
|
|
|
|
TDEHiddenFileMatcher::~TDEHiddenFileMatcher()
|
|
{
|
|
}
|
|
|
|
TQString TDEHiddenFileMatcher::getGlobalCriteria()
|
|
{
|
|
TDEConfig *config = TDEGlobal::config();
|
|
TDEConfigGroupSaver saver( config, globalSettingsGroup );
|
|
TQString defaultCriteria = config->readEntry( globalSettingsKey, criteriaMatchDotfiles );
|
|
return defaultCriteria;
|
|
}
|
|
|
|
void TDEHiddenFileMatcher::setGlobalCriteria()
|
|
{
|
|
TDEConfig *config = TDEGlobal::config();
|
|
TDEConfigGroupSaver saver( config, globalSettingsGroup );
|
|
config->writeEntry( globalSettingsKey, Criteria );
|
|
}
|
|
|