10#include "fileindexerconfig.h"
11#include "fileexcludefilters.h"
12#include "storagedevices.h"
13#include "baloodebug.h"
18#include <QStandardPaths>
19#include "baloosettings.h"
37FileIndexerConfig::FileIndexerConfig(
QObject* parent)
39 , m_settings(new BalooSettings(this))
40 , m_folderCacheDirty(true)
41 , m_indexHidden(false)
43 , m_maxUncomittedFiles(40)
48FileIndexerConfig::~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) {
86QStringList FileIndexerConfig::excludeFilters()
const
89 QStringList filters = m_settings->excludedFilters();
99 m_settings->setExcludedFilters(filters);
106QStringList FileIndexerConfig::excludeMimetypes()
const
108 return QList<QString>(m_excludeMimetypes.begin(), m_excludeMimetypes.end());
111bool FileIndexerConfig::indexHiddenFilesAndFolders()
const
113 return m_indexHidden;
116bool FileIndexerConfig::onlyBasicIndexing()
const
118 return m_onlyBasicIndexing;
121bool FileIndexerConfig::canBeSearched(
const QString& folder)
const
127 }
else if (shouldFolderBeIndexed(path)) {
134 for (
const auto& entry : m_folderCache) {
135 if (entry.isIncluded && entry.path.startsWith(path)) {
143bool FileIndexerConfig::shouldBeIndexed(
const QString& path)
const
147 return shouldFolderBeIndexed(path);
150 (!fi.
isHidden() || indexHiddenFilesAndFolders()) &&
151 shouldFileBeIndexed(fi.
fileName()));
155bool FileIndexerConfig::shouldFolderBeIndexed(
const QString& path)
const
158 auto normalizedPath = normalizeTrailingSlashes(
QString(path));
160 if (folderInFolderList(normalizedPath, folder)) {
163 if (folder == normalizedPath) {
175 for (
const auto &c : pathComponents) {
176 if (!shouldFileBeIndexed(c.toString())) {
180 if (!indexHiddenFilesAndFolders() ||
192bool FileIndexerConfig::shouldFileBeIndexed(
const QString& fileName)
const
197 return !m_excludeFilterRegExpCache.exactMatch(fileName);
200bool FileIndexerConfig::shouldMimeTypeBeIndexed(
const QString& mimeType)
const
202 return !m_excludeMimetypes.contains(mimeType);
205bool FileIndexerConfig::folderInFolderList(
const QString& path,
QString& folder)
const
211 for (
const auto& entry : m_folderCache) {
215 return entry.isIncluded;
223void FileIndexerConfig::FolderCache::cleanup()
231 bool keepAllIncluded =
true;
233 auto entry = begin();
234 while (entry != end()) {
235 if ((*entry).isIncluded && keepAllIncluded) {
240 const QString entryPath = (*entry).path;
242 auto parent = std::find_if(
start, end(),
243 [&entryPath](
const FolderConfig& _parent) {
247 if (parent !=
end()) {
248 if ((*entry).isIncluded == (*parent).isIncluded) {
250 entry = erase(entry);
255 if (!(*entry).isIncluded) {
257 entry = erase(entry);
265bool FileIndexerConfig::FolderConfig::operator<(
const FolderConfig& other)
const
267 return path.
size() > other.path.size() ||
268 (
path.
size() == other.path.size() && path < other.path);
271bool FileIndexerConfig::FolderCache::addFolderConfig(
const FolderConfig& config)
273 if (config.path.isEmpty()) {
274 qCDebug(BALOO) <<
"Trying to add folder config entry with empty path";
277 auto newConfig{config};
280 auto it = std::lower_bound(cbegin(), cend(), newConfig);
281 if (it != cend() && (*it).path == newConfig.path) {
282 qCDebug(BALOO) <<
"Folder config entry for" << newConfig.path <<
"already exists";
286 it =
insert(it, newConfig);
290void FileIndexerConfig::buildFolderCache()
292 if (!m_folderCacheDirty) {
297 m_devices =
new StorageDevices(
this);
302 const QStringList includeFolders = m_settings->folders();
303 for (
const auto& folder : includeFolders) {
304 if (!cache.addFolderConfig({folder, true})) {
305 qCWarning(BALOO) <<
"Failed to add include folder config entry for" << folder;
309 const QStringList excludeFolders = m_settings->excludedFolders();
310 for (
const auto& folder : excludeFolders) {
311 if (!cache.addFolderConfig({folder, false})) {
312 qCWarning(BALOO) <<
"Failed to add exclude folder config entry for" << folder;
318 const auto allMedia = m_devices->allMedia();
319 for (
const auto& device: allMedia) {
320 const QString mountPath = device.mountPath();
321 if (!device.isUsable() && !mountPath.
isEmpty()) {
322 if (!includeFolders.contains(mountPath)) {
323 cache.addFolderConfig({mountPath,
false});
329 qCDebug(BALOO) <<
"Folder cache:" << cache;
330 m_folderCache = cache;
332 m_folderCacheDirty =
false;
335void FileIndexerConfig::buildExcludeFilterRegExpCache()
338 m_excludeFilterRegExpCache.rebuildCacheFromFilterList(newFilters);
341void FileIndexerConfig::buildMimeTypeCache()
343 const QStringList excludedTypes = m_settings->excludedMimetypes();
347void FileIndexerConfig::forceConfigUpdate()
351 m_folderCacheDirty =
true;
352 buildExcludeFilterRegExpCache();
353 buildMimeTypeCache();
355 m_indexHidden = m_settings->indexHiddenFolders();
356 m_onlyBasicIndexing = m_settings->onlyBasicIndexing();
359int FileIndexerConfig::databaseVersion()
const
361 return m_settings->dbVersion();
364void FileIndexerConfig::setDatabaseVersion(
int version)
366 m_settings->setDbVersion(version);
370bool FileIndexerConfig::indexingEnabled()
const
372 return m_settings->indexingEnabled();
375uint FileIndexerConfig::maxUncomittedFiles()
const
377 return m_maxUncomittedFiles;
382#include "moc_fileindexerconfig.cpp"
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
Q_SCRIPTABLE Q_NOREPLY void start()
Implements storage for docIds without any associated data Instantiated for:
int defaultExcludeFilterListVersion()
QStringList defaultExcludeFilterList()
QString path(const QString &relativePath)
const QList< QKeySequence > & end()
QDebug operator<<(QDebug dbg, const PerceptualColor::MultiSpinBoxSection &value)
bool cd(const QString &dirName)
QString cleanPath(const QString &path)
QString path() const const
QString absolutePath() const const
QString fileName() const const
bool isHidden() const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype size() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
qsizetype removeDuplicates()
QStringView mid(qsizetype start, qsizetype length) const const
QList< QStringView > split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const