#ifndef TDESTRINGMATCHER_H #define TDESTRINGMATCHER_H #include #include #include "tdeglobal.h" /************ * * Generic string matcher class. */ class TDECORE_EXPORT TDEStringMatcher { public: TDEStringMatcher(); ~TDEStringMatcher(); /** Perform string matching based on the match-controlling @properties described below. */ bool match( const TQString& ); /** @return value of @property Criteria described below. */ TQString getCriteria(); /** Process @param newCriteria to initialize / update the @property patternsDivider described below. */ bool setCriteria(TQString newCriteria); /** Present dialog that allows user to view/update current match- controlling @properties described below. @return one of the values of @enum UpdateResult listed below. @param dialogTitle can be used to describe the application/ the software component that is using the TDEStringMatcher. Examples: "Hidden File Definitionfor Konqueror Listview" "Global Default Hidden File Definition" */ int getMatchPropertiesFromUser( TQString dialogTitle = TQString("Define String Matching Criteria") ); enum class Status : int { reloadCriteria = -1, // Criteria was not changed, request reloading default criteriaUnchanged = 0, // Criteria was not changed criteriaApplied = 1, // New criteria applied, should not be saved saveCriteria = 2 // New criteria applied, request saving as default }; #define ReloadCriteria -1 #define CriteriaUnchanged 0 #define CriteriaApplied 1 #define SaveCriteria 2 /** Process @param newPatternsDivider to initialize / update the match-controlling @properties that are described below. */ void setPatternsDivider(TQChar newPatternsDivider); protected: /** Derive value of @property Criteria from the current values of the match-controlling @properties described below */ void generateCriteria(); /** Match-controlling properties: @property patternList is a list of zero or more string patterns each of which will be used as a wildcard or regex to match a string. If the list is empty, then no strings will match. @property isCaseInsensitive determines whether or not matching will be done in "case insensitive" fashion. @property isRegex determines whether or not the matching will be regex-based (versus wildcard/globbing-based). */ bool isCaseInsensitive = FALSE; bool isRegex = FALSE; TQStringList patternList; // FIXME: Use STL? /** @property patternsDivider is a character used to separate multiple match patterns in @property Criteria described below. This should be a character that will not be used in a match pattern. */ TQChar patternsDivider; /** @property Criteria is a string which encodes the match-controlling @properties described above. It has the format ^([wWrR])(.+). The leading character's case determines @property isCaseInsensitive and its value determines @property isRegex (rR: TRUE, wW: FALSE). Remainder of string is a @property patternsDivider separated list of match patterns that determines the content of @property patternList. */ TQString Criteria; private: static constexpr const char patternsDividerDefault = ','; static constexpr const char * criteriaMatchNothing = "w"; }; /************ * * Hidden file matcher class. */ class TDECORE_EXPORT TDEHiddenFileMatcher : public TDEStringMatcher { friend class TDEGlobal; // for initInstance() public: TDEHiddenFileMatcher(); ~TDEHiddenFileMatcher(); private: TQString getGlobalCriteria(); void setGlobalCriteria(); /** @property patternsDivider4fileNames specifies a reasonable default for separating multiple file name match patterns. */ static constexpr const char patternsDivider4fileNames = '/'; /** @property criteriaMatchDotfiles encodes the traditional unix-style hidden file matching of so-called dotfiles. It is default value of @property Criteria unless overridden. */ static constexpr const char * criteriaMatchDotfiles = "w.*"; // Default Criteria setting location in kdeglobals static constexpr const char * globalSettingsGroup = "General"; static constexpr const char * globalSettingsKey = "globalHiddenFileSpec"; }; #endif