Baloo
10 #include "fileindexerconfig.h"
11 #include "fileexcludefilters.h"
12 #include "storagedevices.h"
13 #include "baloodebug.h"
15 #include <QStringList>
18 #include <QStandardPaths>
19 #include "baloosettings.h"
37 FileIndexerConfig::FileIndexerConfig(
QObject* parent)
39 , m_settings(new BalooSettings(this))
40 , m_folderCacheDirty(true)
41 , m_indexHidden(false)
43 , m_maxUncomittedFiles(40)
48 FileIndexerConfig::~FileIndexerConfig()
55 dbg.
nospace() << entry.path <<
": "
56 << (entry.isIncluded ?
"included" :
"excluded");
65 for (
const auto& entry : m_folderCache) {
66 if (entry.isIncluded) {
78 for (
const auto& entry : m_folderCache) {
79 if (!entry.isIncluded) {
86 QStringList FileIndexerConfig::excludeFilters()
const
89 QStringList filters = m_settings->excludedFilters();
99 m_settings->setExcludedFilters(filters);
106 QStringList FileIndexerConfig::excludeMimetypes()
const
111 bool FileIndexerConfig::indexHiddenFilesAndFolders()
const
113 return m_indexHidden;
116 bool FileIndexerConfig::onlyBasicIndexing()
const
118 return m_onlyBasicIndexing;
134 for (
const auto& entry : m_folderCache) {
135 if (entry.isIncluded && entry.path.startsWith(path)) {
150 (!fi.
isHidden() || indexHiddenFilesAndFolders()) &&
158 auto normalizedPath = normalizeTrailingSlashes(
QString(path));
163 if (folder == normalizedPath) {
173 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
176 const auto trailingPath = normalizedPath.midRef(folder.
size());
179 for (
const auto &c : pathComponents) {
184 if (!indexHiddenFilesAndFolders() ||
201 return !m_excludeFilterRegExpCache.exactMatch(fileName);
206 return !m_excludeMimetypes.
contains(mimeType);
215 for (
const auto& entry : m_folderCache) {
219 return entry.isIncluded;
227 void FileIndexerConfig::FolderCache::cleanup()
235 bool keepAllIncluded =
true;
237 auto entry = begin();
238 while (entry != end()) {
239 if ((*entry).isIncluded && keepAllIncluded) {
244 const QString entryPath = (*entry).path;
246 auto parent = std::find_if(
start, end(),
247 [&entryPath](
const FolderConfig& _parent) {
251 if (parent !=
end()) {
252 if ((*entry).isIncluded == (*parent).isIncluded) {
254 entry = erase(entry);
259 if (!(*entry).isIncluded) {
261 entry = erase(entry);
269 bool FileIndexerConfig::FolderConfig::operator<(
const FolderConfig& other)
const
271 return path.
size() > other.path.size() ||
272 (
path.
size() == other.path.size() &&
path < other.path);
275 bool FileIndexerConfig::FolderCache::addFolderConfig(
const FolderConfig& config)
277 if (
config.path.isEmpty()) {
278 qCDebug(BALOO) <<
"Trying to add folder config entry with empty path";
284 auto it = std::lower_bound(cbegin(), cend(), newConfig);
285 if (it != cend() && (*it).path == newConfig.path) {
286 qCDebug(BALOO) <<
"Folder config entry for" << newConfig.path <<
"already exists";
290 it =
insert(it, newConfig);
294 void FileIndexerConfig::buildFolderCache()
296 if (!m_folderCacheDirty) {
301 m_devices =
new StorageDevices(
this);
308 if (!cache.addFolderConfig({folder, true})) {
309 qCWarning(BALOO) <<
"Failed to add include folder config entry for" << folder;
315 if (!cache.addFolderConfig({folder, false})) {
316 qCWarning(BALOO) <<
"Failed to add exclude folder config entry for" << folder;
322 const auto allMedia = m_devices->allMedia();
323 for (
const auto& device: allMedia) {
324 const QString mountPath = device.mountPath();
325 if (!device.isUsable() && !mountPath.
isEmpty()) {
327 cache.addFolderConfig({mountPath,
false});
333 qCDebug(BALOO) <<
"Folder cache:" << cache;
334 m_folderCache = cache;
336 m_folderCacheDirty =
false;
339 void FileIndexerConfig::buildExcludeFilterRegExpCache()
342 m_excludeFilterRegExpCache.rebuildCacheFromFilterList(newFilters);
345 void FileIndexerConfig::buildMimeTypeCache()
347 const QStringList excludedTypes = m_settings->excludedMimetypes();
355 m_folderCacheDirty =
true;
356 buildExcludeFilterRegExpCache();
357 buildMimeTypeCache();
359 m_indexHidden = m_settings->indexHiddenFolders();
360 m_onlyBasicIndexing = m_settings->onlyBasicIndexing();
365 return m_settings->dbVersion();
368 void FileIndexerConfig::setDatabaseVersion(
int version)
370 m_settings->setDbVersion(version);
374 bool FileIndexerConfig::indexingEnabled()
const
376 return m_settings->indexingEnabled();
381 return m_maxUncomittedFiles;
386 #include "moc_fileindexerconfig.cpp"
int databaseVersion() const
Returns the internal version number of the Baloo database.
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
QStringList includeFolders() const
Folders to search for files to index and analyze.
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
uint maxUncomittedFiles() const
Returns batch size.
QStringView mid(qsizetype start) const const
Q_SCRIPTABLE Q_NOREPLY void start()
bool insert(Part *part, qint64 *insertId=nullptr)
QStringList defaultExcludeFilterList()
int defaultExcludeFilterListVersion()
void forceConfigUpdate()
Reread the config from disk and update the configuration cache.
bool shouldBeIndexed(const QString &path) const
Check if file or folder path should be indexed taking into account the includeFolders(),...
Implements storage for docIds without any associated data Instantiated for:
bool isEmpty() const const
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
KSharedConfigPtr config()
QString fileName() const const
QString path() const const
bool contains(const T &value) const const
QString absolutePath() const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
bool isHidden() const const
QString cleanPath(const QString &path)
bool folderInFolderList(const QString &path, QString &folder) const
Check if path is in the list of folders to be indexed taking include and exclude folders into account...
QString path(const QString &relativePath)
bool shouldFileBeIndexed(const QString &fileName) const
Check fileName for all exclude filters.
bool shouldMimeTypeBeIndexed(const QString &mimeType) const
Checks if mimeType should be indexed.
bool canBeSearched(const QString &folder) const
Check if folder can be searched.
QStringList excludeFolders() const
Folders that are excluded from indexing.
bool cd(const QString &dirName)
const QList< QKeySequence > & end()
bool shouldFolderBeIndexed(const QString &path) const
Check if the folder at path should be indexed.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:56:26 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.