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()
52QDebug operator<<(
QDebug dbg,
const FileIndexerConfig::FolderConfig& entry)
55 dbg.
nospace() << entry.path <<
": "
56 << (entry.isIncluded ?
"included" :
"excluded");
62 const_cast<FileIndexerConfig*
>(
this)->buildFolderCache();
65 for (
const auto& entry : m_folderCache) {
66 if (entry.isIncluded) {
75 const_cast<FileIndexerConfig*
>(
this)->buildFolderCache();
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;
131 const_cast<FileIndexerConfig*
>(
this)->buildFolderCache();
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) {
175 for (
const auto &c : pathComponents) {
180 if (!indexHiddenFilesAndFolders() ||
197 return !m_excludeFilterRegExpCache.exactMatch(fileName);
202 return !m_excludeMimetypes.contains(mimeType);
207 const_cast<FileIndexerConfig*
>(
this)->buildFolderCache();
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();
351 m_folderCacheDirty =
true;
352 buildExcludeFilterRegExpCache();
353 buildMimeTypeCache();
355 m_indexHidden = m_settings->indexHiddenFolders();
356 m_onlyBasicIndexing = m_settings->onlyBasicIndexing();
361 return m_settings->dbVersion();
364void FileIndexerConfig::setDatabaseVersion(
int version)
366 m_settings->setDbVersion(version);
370bool FileIndexerConfig::indexingEnabled()
const
372 return m_settings->indexingEnabled();
377 return m_maxUncomittedFiles;
382#include "moc_fileindexerconfig.cpp"
QStringList excludeFolders() const
Folders that are excluded from indexing.
bool shouldMimeTypeBeIndexed(const QString &mimeType) const
Checks if mimeType should be indexed.
bool shouldFolderBeIndexed(const QString &path) const
Check if the folder at path should be indexed.
int databaseVersion() const
Returns the internal version number of the Baloo database.
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(),...
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...
bool shouldFileBeIndexed(const QString &fileName) const
Check fileName for all exclude filters.
uint maxUncomittedFiles() const
Returns batch size.
QStringList includeFolders() const
Folders to search for files to index and analyze.
bool canBeSearched(const QString &folder) const
Check if folder can be searched.
Q_SCRIPTABLE QString start(QString train="")
Implements storage for docIds without any associated data Instantiated for:
int defaultExcludeFilterListVersion()
QStringList defaultExcludeFilterList()
QString path(const QString &relativePath)
const QList< QKeySequence > & end()
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