File indexing completed on 2024-03-24 03:54:33
0001 /* 0002 SPDX-FileCopyrightText: 2008-2009 Sebastian Trueg <trueg@kde.org> 0003 SPDX-FileCopyrightText: 2012-2014 Vishesh Handa <me@vhanda.in> 0004 SPDX-FileCopyrightText: 2020 Benjamin Port <benjamin.port@enioka.com> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef BALOO_FILEINDEXER_CONFIG_H_ 0010 #define BALOO_FILEINDEXER_CONFIG_H_ 0011 0012 #include <QObject> 0013 #include <QList> 0014 #include <QSet> 0015 #include <QDebug> 0016 0017 #include "regexpcache.h" 0018 0019 class BalooSettings; 0020 0021 namespace Baloo 0022 { 0023 0024 class StorageDevices; 0025 0026 /** 0027 * Active config class which emits signals if the config 0028 * was changed, for example if the KCM saved the config file. 0029 */ 0030 class FileIndexerConfig : public QObject 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 0036 explicit FileIndexerConfig(QObject* parent = nullptr); 0037 ~FileIndexerConfig() override; 0038 0039 /** 0040 * Folders to search for files to index and analyze. 0041 * \return list of paths. 0042 */ 0043 QStringList includeFolders() const; 0044 0045 /** 0046 * Folders that are excluded from indexing. 0047 * (Descendant folders of an excluded folder can be added 0048 * and they will be indexed.) 0049 * \return list of paths. 0050 */ 0051 QStringList excludeFolders() const; 0052 0053 QStringList excludeFilters() const; 0054 0055 QStringList excludeMimetypes() const; 0056 0057 bool indexHiddenFilesAndFolders() const; 0058 0059 bool onlyBasicIndexing() const; 0060 0061 /** 0062 * Check if \p folder can be searched. 0063 * \p folder can be searched if itself or one of its descendants is indexed. 0064 * 0065 * Example: 0066 * if ~/foo is not indexed and ~/foo/bar is indexed 0067 * then ~/foo can be searched. 0068 * 0069 * \return \c true if the \p folder can be searched. 0070 */ 0071 bool canBeSearched(const QString& folder) const; 0072 0073 /** 0074 * Check if file or folder \p path should be indexed taking into account 0075 * the includeFolders(), the excludeFolders(), and the excludeFilters(). 0076 * Inclusion takes precedence. 0077 * 0078 * Be aware that this method does not check if parent dirs 0079 * match any of the exclude filters. Only the path of the 0080 * dir itself it checked. 0081 * 0082 * \return \c true if the file or folder at \p path should 0083 * be indexed according to the configuration. 0084 */ 0085 bool shouldBeIndexed(const QString& path) const; 0086 0087 /** 0088 * Check if the folder at \p path should be indexed. 0089 * 0090 * Be aware that this method does not check if parent dirs 0091 * match any of the exclude filters. Only the name of the 0092 * dir itself it checked. 0093 * 0094 * \return \c true if the folder at \p path should 0095 * be indexed according to the configuration. 0096 */ 0097 bool shouldFolderBeIndexed(const QString& path) const; 0098 0099 /** 0100 * Check \p fileName for all exclude filters. This does 0101 * not take file paths into account. 0102 * 0103 * \return \c true if a file with name \p filename should 0104 * be indexed according to the configuration. 0105 */ 0106 bool shouldFileBeIndexed(const QString& fileName) const; 0107 0108 /** 0109 * Checks if \p mimeType should be indexed 0110 * 0111 * \return \c true if the mimetype should be indexed according 0112 * to the configuration 0113 */ 0114 bool shouldMimeTypeBeIndexed(const QString& mimeType) const; 0115 0116 /** 0117 * Check if \p path is in the list of folders to be indexed taking 0118 * include and exclude folders into account. 0119 * \p folder is set to the folder which was the reason for the decision. 0120 */ 0121 bool folderInFolderList(const QString& path, QString& folder) const; 0122 0123 /** 0124 * Returns the internal version number of the Baloo database 0125 */ 0126 int databaseVersion() const; 0127 void setDatabaseVersion(int version); 0128 0129 bool indexingEnabled() const; 0130 0131 /** 0132 * Returns batch size 0133 */ 0134 uint maxUncomittedFiles() const; 0135 0136 public Q_SLOTS: 0137 /** 0138 * Reread the config from disk and update the configuration cache. 0139 * This is only required for testing as normally the config updates 0140 * itself whenever the config file on disk changes. 0141 * 0142 * \return \c true if the config has actually changed 0143 */ 0144 void forceConfigUpdate(); 0145 0146 private: 0147 0148 void buildFolderCache(); 0149 void buildExcludeFilterRegExpCache(); 0150 void buildMimeTypeCache(); 0151 0152 BalooSettings *m_settings; 0153 0154 struct FolderConfig 0155 { 0156 QString path; 0157 bool isIncluded; 0158 0159 /// Sort by path length, and on ties lexicographically. 0160 /// Longest path first 0161 bool operator<(const FolderConfig& other) const; 0162 }; 0163 0164 class FolderCache : public std::vector<FolderConfig> 0165 { 0166 public: 0167 void cleanup(); 0168 0169 bool addFolderConfig(const FolderConfig&); 0170 }; 0171 friend QDebug operator<<(QDebug dbg, const FolderConfig& config); 0172 0173 /// Caching cleaned up list (no duplicates, no non-default entries, etc.) 0174 FolderCache m_folderCache; 0175 /// Whether the folder cache needs to be rebuilt the next time it is used 0176 bool m_folderCacheDirty; 0177 0178 /// cache of regexp objects for all exclude filters 0179 /// to prevent regexp parsing over and over 0180 RegExpCache m_excludeFilterRegExpCache; 0181 0182 /// A set of mimetypes which should never be indexed 0183 QSet<QString> m_excludeMimetypes; 0184 0185 bool m_indexHidden; 0186 bool m_onlyBasicIndexing; 0187 0188 StorageDevices* m_devices; 0189 0190 const uint m_maxUncomittedFiles; 0191 }; 0192 0193 QDebug operator<<(QDebug dbg, const FileIndexerConfig::FolderCache::value_type&); 0194 0195 } 0196 0197 #endif