Changeset View
Changeset View
Standalone View
Standalone View
src/file/fileindexerconfig.cpp
1 | /* This file is part of the KDE Project | 1 | /* This file is part of the KDE Project | ||
---|---|---|---|---|---|
2 | Copyright (c) 2008-2010 Sebastian Trueg <trueg@kde.org> | 2 | Copyright (c) 2008-2010 Sebastian Trueg <trueg@kde.org> | ||
3 | Copyright (c) 2013-2014 Vishesh Handa <me@vhanda.in> | 3 | Copyright (c) 2013-2014 Vishesh Handa <me@vhanda.in> | ||
4 | Copyright (c) 2020 Benjamin Port <benjamin.port@enioka.com> | ||||
4 | 5 | | |||
5 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public | ||
7 | License version 2 as published by the Free Software Foundation. | 8 | License version 2 as published by the Free Software Foundation. | ||
8 | 9 | | |||
9 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Show All 9 Lines | |||||
21 | #include "fileexcludefilters.h" | 22 | #include "fileexcludefilters.h" | ||
22 | #include "storagedevices.h" | 23 | #include "storagedevices.h" | ||
23 | 24 | | |||
24 | #include <QStringList> | 25 | #include <QStringList> | ||
25 | #include <QDir> | 26 | #include <QDir> | ||
26 | 27 | | |||
27 | #include <QStandardPaths> | 28 | #include <QStandardPaths> | ||
28 | #include <KConfigGroup> | 29 | #include <KConfigGroup> | ||
29 | 30 | #include "baloosettings.h" | |||
30 | 31 | | |||
31 | namespace | 32 | namespace | ||
32 | { | 33 | { | ||
33 | /// recursively check if a folder is hidden | 34 | /// recursively check if a folder is hidden | ||
34 | bool isDirHidden(const QDir& dir) | 35 | bool isDirHidden(const QDir& dir) | ||
35 | { | 36 | { | ||
36 | #ifdef __unix__ | 37 | #ifdef __unix__ | ||
37 | return dir.absolutePath().contains(QLatin1String("/.")); | 38 | return dir.absolutePath().contains(QLatin1String("/.")); | ||
Show All 18 Lines | |||||
56 | } | 57 | } | ||
57 | 58 | | |||
58 | } | 59 | } | ||
59 | 60 | | |||
60 | using namespace Baloo; | 61 | using namespace Baloo; | ||
61 | 62 | | |||
62 | FileIndexerConfig::FileIndexerConfig(QObject* parent) | 63 | FileIndexerConfig::FileIndexerConfig(QObject* parent) | ||
63 | : QObject(parent) | 64 | : QObject(parent) | ||
64 | , m_config(QStringLiteral("baloofilerc")) | 65 | , m_settings(new BalooSettings(this)) | ||
65 | , m_folderCacheDirty(true) | 66 | , m_folderCacheDirty(true) | ||
66 | , m_indexHidden(false) | 67 | , m_indexHidden(false) | ||
67 | , m_devices(nullptr) | 68 | , m_devices(nullptr) | ||
68 | , m_maxUncomittedFiles(40) | 69 | , m_maxUncomittedFiles(40) | ||
69 | { | 70 | { | ||
70 | forceConfigUpdate(); | 71 | forceConfigUpdate(); | ||
71 | } | 72 | } | ||
72 | 73 | | |||
Show All 26 Lines | 99 | if (!m_folderCache[i].second) | |||
99 | fl << m_folderCache[i].first; | 100 | fl << m_folderCache[i].first; | ||
100 | } | 101 | } | ||
101 | return fl; | 102 | return fl; | ||
102 | } | 103 | } | ||
103 | 104 | | |||
104 | 105 | | |||
105 | QStringList FileIndexerConfig::excludeFilters() const | 106 | QStringList FileIndexerConfig::excludeFilters() const | ||
106 | { | 107 | { | ||
107 | KConfigGroup cfg = m_config.group("General"); | | |||
108 | | ||||
109 | // read configured exclude filters | 108 | // read configured exclude filters | ||
110 | QStringList filters = cfg.readEntry("exclude filters", defaultExcludeFilterList()); | 109 | QStringList filters = m_settings->excludedFilters(); | ||
111 | 110 | | |||
112 | // make sure we always keep the latest default exclude filters | 111 | // make sure we always keep the latest default exclude filters | ||
113 | // TODO: there is one problem here. What if the user removed some of the default filters? | 112 | // TODO: there is one problem here. What if the user removed some of the default filters? | ||
114 | if (cfg.readEntry("exclude filters version", 0) < defaultExcludeFilterListVersion()) { | 113 | if (m_settings->excludedFiltersVersion() < defaultExcludeFilterListVersion()) { | ||
115 | filters += defaultExcludeFilterList(); | 114 | filters += defaultExcludeFilterList(); | ||
116 | // in case the cfg entry was empty and filters == defaultExcludeFilterList() | 115 | // in case the cfg entry was empty and filters == defaultExcludeFilterList() | ||
117 | filters.removeDuplicates(); | 116 | filters.removeDuplicates(); | ||
118 | 117 | | |||
119 | // write the config directly since the KCM does not have support for the version yet | 118 | // write the config directly since the KCM does not have support for the version yet | ||
120 | // TODO: make this class public and use it in the KCM | 119 | m_settings->setExcludedFilters(filters); | ||
ervin: I guess this TODO comment can go with your change. | |||||
121 | KConfig config(m_config.name()); | 120 | m_settings->setExcludedFiltersVersion(defaultExcludeFilterListVersion()); | ||
122 | KConfigGroup cfg = config.group("General"); | | |||
123 | cfg.writeEntry("exclude filters", filters); | | |||
124 | cfg.writeEntry("exclude filters version", defaultExcludeFilterListVersion()); | | |||
125 | } | 121 | } | ||
126 | 122 | | |||
127 | return filters; | 123 | return filters; | ||
128 | } | 124 | } | ||
129 | 125 | | |||
130 | QStringList FileIndexerConfig::excludeMimetypes() const | 126 | QStringList FileIndexerConfig::excludeMimetypes() const | ||
131 | { | 127 | { | ||
132 | #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) | 128 | #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) | ||
Show All 10 Lines | |||||
143 | 139 | | |||
144 | bool FileIndexerConfig::onlyBasicIndexing() const | 140 | bool FileIndexerConfig::onlyBasicIndexing() const | ||
145 | { | 141 | { | ||
146 | return m_onlyBasicIndexing; | 142 | return m_onlyBasicIndexing; | ||
147 | } | 143 | } | ||
148 | 144 | | |||
149 | bool FileIndexerConfig::isInitialRun() const | 145 | bool FileIndexerConfig::isInitialRun() const | ||
150 | { | 146 | { | ||
151 | return m_config.group("General").readEntry("first run", true); | 147 | KConfig config(QStringLiteral("baloofilerc")); | ||
148 | return config.group("General").readEntry("first run", true); | ||||
152 | } | 149 | } | ||
153 | 150 | | |||
154 | 151 | | |||
155 | bool FileIndexerConfig::canBeSearched(const QString& folder) const | 152 | bool FileIndexerConfig::canBeSearched(const QString& folder) const | ||
156 | { | 153 | { | ||
157 | QFileInfo fi(folder); | 154 | QFileInfo fi(folder); | ||
158 | QString path = fi.absolutePath(); | 155 | QString path = fi.absolutePath(); | ||
159 | if (!fi.isDir()) { | 156 | if (!fi.isDir()) { | ||
▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Line(s) | 312 | { | |||
316 | if (!m_folderCacheDirty) { | 313 | if (!m_folderCacheDirty) { | ||
317 | return; | 314 | return; | ||
318 | } | 315 | } | ||
319 | 316 | | |||
320 | if (!m_devices) { | 317 | if (!m_devices) { | ||
321 | m_devices = new StorageDevices(this); | 318 | m_devices = new StorageDevices(this); | ||
322 | } | 319 | } | ||
323 | 320 | | |||
324 | KConfigGroup group = m_config.group("General"); | 321 | QStringList includeFoldersPlain = m_settings->folders(); | ||
325 | QStringList includeFoldersPlain = group.readPathEntry("folders", QStringList() << QDir::homePath()); | 322 | QStringList excludeFoldersPlain = m_settings->excludedFolders(); | ||
326 | QStringList excludeFoldersPlain = group.readPathEntry("exclude folders", QStringList()); | | |||
327 | | ||||
328 | // Add all removable media and network shares as ignored unless they have | 323 | // Add all removable media and network shares as ignored unless they have | ||
329 | // been explicitly added in the include list | 324 | // been explicitly added in the include list | ||
330 | const auto allMedia = m_devices->allMedia(); | 325 | const auto allMedia = m_devices->allMedia(); | ||
331 | for (const auto& device: allMedia) { | 326 | for (const auto& device: allMedia) { | ||
332 | const QString mountPath = device.mountPath(); | 327 | const QString mountPath = device.mountPath(); | ||
333 | if (!device.isUsable() && !mountPath.isEmpty()) { | 328 | if (!device.isUsable() && !mountPath.isEmpty()) { | ||
334 | if (!includeFoldersPlain.contains(mountPath)) { | 329 | if (!includeFoldersPlain.contains(mountPath)) { | ||
335 | excludeFoldersPlain << mountPath; | 330 | excludeFoldersPlain << mountPath; | ||
Show All 14 Lines | |||||
350 | void FileIndexerConfig::buildExcludeFilterRegExpCache() | 345 | void FileIndexerConfig::buildExcludeFilterRegExpCache() | ||
351 | { | 346 | { | ||
352 | QStringList newFilters = excludeFilters(); | 347 | QStringList newFilters = excludeFilters(); | ||
353 | m_excludeFilterRegExpCache.rebuildCacheFromFilterList(newFilters); | 348 | m_excludeFilterRegExpCache.rebuildCacheFromFilterList(newFilters); | ||
354 | } | 349 | } | ||
355 | 350 | | |||
356 | void FileIndexerConfig::buildMimeTypeCache() | 351 | void FileIndexerConfig::buildMimeTypeCache() | ||
357 | { | 352 | { | ||
358 | const QStringList excludedTypes = m_config.group("General").readPathEntry("exclude mimetypes", defaultExcludeMimetypes()); | 353 | const QStringList excludedTypes = m_settings->excludedMimetypes(); | ||
359 | #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) | 354 | #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) | ||
360 | m_excludeMimetypes = excludedTypes.toSet(); | 355 | m_excludeMimetypes = excludedTypes.toSet(); | ||
361 | #else | 356 | #else | ||
362 | m_excludeMimetypes = QSet<QString>(excludedTypes.begin(), excludedTypes.end()); | 357 | m_excludeMimetypes = QSet<QString>(excludedTypes.begin(), excludedTypes.end()); | ||
363 | #endif | 358 | #endif | ||
364 | } | 359 | } | ||
365 | 360 | | |||
366 | void FileIndexerConfig::forceConfigUpdate() | 361 | void FileIndexerConfig::forceConfigUpdate() | ||
367 | { | 362 | { | ||
368 | m_config.reparseConfiguration(); | 363 | m_settings->load(); | ||
369 | 364 | | |||
370 | m_folderCacheDirty = true; | 365 | m_folderCacheDirty = true; | ||
371 | buildExcludeFilterRegExpCache(); | 366 | buildExcludeFilterRegExpCache(); | ||
372 | buildMimeTypeCache(); | 367 | buildMimeTypeCache(); | ||
373 | 368 | | |||
374 | m_indexHidden = m_config.group("General").readEntry("index hidden folders", false); | 369 | m_indexHidden = m_settings->indexHiddenFolders(); | ||
375 | m_onlyBasicIndexing = m_config.group("General").readEntry("only basic indexing", false); | 370 | m_onlyBasicIndexing = m_settings->onlyBasicIndexing(); | ||
376 | } | 371 | } | ||
377 | 372 | | |||
378 | void FileIndexerConfig::setInitialRun(bool isInitialRun) | 373 | void FileIndexerConfig::setInitialRun(bool isInitialRun) | ||
379 | { | 374 | { | ||
380 | m_config.group("General").writeEntry("first run", isInitialRun); | 375 | // Don't use kcfg, it will break KCM default state | ||
381 | m_config.sync(); | 376 | KConfig config(QStringLiteral("baloofilerc")); | ||
377 | config.group("General").writeEntry("first run", isInitialRun); | ||||
378 | config.sync(); | ||||
382 | } | 379 | } | ||
383 | 380 | | |||
384 | bool FileIndexerConfig::initialUpdateDisabled() const | 381 | bool FileIndexerConfig::initialUpdateDisabled() const | ||
385 | { | 382 | { | ||
386 | return m_config.group("General").readEntry("disable initial update", true); | 383 | return m_settings->disableInitialUpdate(); | ||
387 | } | 384 | } | ||
388 | 385 | | |||
389 | int FileIndexerConfig::databaseVersion() const | 386 | int FileIndexerConfig::databaseVersion() const | ||
390 | { | 387 | { | ||
391 | return m_config.group("General").readEntry("dbVersion", 0); | 388 | return m_settings->dbVersion(); | ||
392 | } | 389 | } | ||
393 | 390 | | |||
394 | void FileIndexerConfig::setDatabaseVersion(int version) | 391 | void FileIndexerConfig::setDatabaseVersion(int version) | ||
395 | { | 392 | { | ||
396 | m_config.group("General").writeEntry("dbVersion", version); | 393 | m_settings->setDbVersion(version); | ||
397 | m_config.sync(); | 394 | m_settings->save(); | ||
398 | } | 395 | } | ||
399 | 396 | | |||
400 | bool FileIndexerConfig::indexingEnabled() const | 397 | bool FileIndexerConfig::indexingEnabled() const | ||
401 | { | 398 | { | ||
402 | return m_config.group("Basic Settings").readEntry("Indexing-Enabled", true); | 399 | return m_settings->indexingEnabled(); | ||
403 | } | 400 | } | ||
404 | 401 | | |||
405 | uint FileIndexerConfig::maxUncomittedFiles() const | 402 | uint FileIndexerConfig::maxUncomittedFiles() const | ||
406 | { | 403 | { | ||
407 | return m_maxUncomittedFiles; | 404 | return m_maxUncomittedFiles; | ||
408 | } | 405 | } | ||
409 | |
I guess this TODO comment can go with your change.