diff --git a/src/file/CMakeLists.txt b/src/file/CMakeLists.txt --- a/src/file/CMakeLists.txt +++ b/src/file/CMakeLists.txt @@ -48,6 +48,7 @@ ecm_qt_declare_logging_category(file_static_lib_SRCS HEADER baloodebug.h IDENTIFIER BALOO CATEGORY_NAME org.kde.baloo) qt5_add_dbus_interface(file_static_lib_SRCS org.kde.BalooWatcherApplication.xml baloowatcherapplication_interface) +kconfig_add_kcfg_files(file_static_lib_SRCS ../lib/baloosettings.kcfgc GENERATE_MOC) add_library(baloofilecommon STATIC ${file_static_lib_SRCS}) target_link_libraries(baloofilecommon diff --git a/src/file/baloosettings.kcfgc b/src/file/baloosettings.kcfgc new file mode 100644 --- /dev/null +++ b/src/file/baloosettings.kcfgc @@ -0,0 +1,6 @@ +File=../lib/baloosettings.kcfg +ClassName=BalooSettings +Inherits=KCoreConfigSkeleton +Mutators=true +DefaultValueGetters=true +ParentInConstructor=true diff --git a/src/file/extractor/CMakeLists.txt b/src/file/extractor/CMakeLists.txt --- a/src/file/extractor/CMakeLists.txt +++ b/src/file/extractor/CMakeLists.txt @@ -16,6 +16,7 @@ ) ecm_qt_declare_logging_category(EXTRACTOR_SRCS HEADER baloodebug.h IDENTIFIER BALOO CATEGORY_NAME org.kde.baloo) +kconfig_add_kcfg_files(EXTRACTOR_SRCS ../baloosettings.kcfgc GENERATE_MOC) add_executable(baloo_file_extractor ${EXTRACTOR_SRCS}) ecm_mark_nongui_executable(baloo_file_extractor) diff --git a/src/file/fileindexerconfig.h b/src/file/fileindexerconfig.h --- a/src/file/fileindexerconfig.h +++ b/src/file/fileindexerconfig.h @@ -1,6 +1,7 @@ /* Copyright (c) 2008-2009 Sebastian Trueg Copyright (c) 2012-2014 Vishesh Handa + Copyright (c) 2020 Benjamin Port This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -24,10 +25,10 @@ #include #include -#include - #include "regexpcache.h" +class BalooSettings; + namespace Baloo { @@ -186,7 +187,7 @@ void buildExcludeFilterRegExpCache(); void buildMimeTypeCache(); - KConfig m_config; + BalooSettings *m_settings; /// Caching cleaned up list (no duplicates, no useless entries, etc.) QList > m_folderCache; diff --git a/src/file/fileindexerconfig.cpp b/src/file/fileindexerconfig.cpp --- a/src/file/fileindexerconfig.cpp +++ b/src/file/fileindexerconfig.cpp @@ -1,6 +1,7 @@ /* This file is part of the KDE Project Copyright (c) 2008-2010 Sebastian Trueg Copyright (c) 2013-2014 Vishesh Handa + Copyright (c) 2020 Benjamin Port This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -26,7 +27,7 @@ #include #include - +#include "baloosettings.h" namespace { @@ -61,7 +62,7 @@ FileIndexerConfig::FileIndexerConfig(QObject* parent) : QObject(parent) - , m_config(QStringLiteral("baloofilerc")) + , m_settings(new BalooSettings(this)) , m_folderCacheDirty(true) , m_indexHidden(false) , m_devices(nullptr) @@ -104,24 +105,19 @@ QStringList FileIndexerConfig::excludeFilters() const { - KConfigGroup cfg = m_config.group("General"); - // read configured exclude filters - QStringList filters = cfg.readEntry("exclude filters", defaultExcludeFilterList()); + QStringList filters = m_settings->excludedFilters(); // make sure we always keep the latest default exclude filters // TODO: there is one problem here. What if the user removed some of the default filters? - if (cfg.readEntry("exclude filters version", 0) < defaultExcludeFilterListVersion()) { + if (m_settings->excludedFiltersVersion() < defaultExcludeFilterListVersion()) { filters += defaultExcludeFilterList(); // in case the cfg entry was empty and filters == defaultExcludeFilterList() filters.removeDuplicates(); // write the config directly since the KCM does not have support for the version yet - // TODO: make this class public and use it in the KCM - KConfig config(m_config.name()); - KConfigGroup cfg = config.group("General"); - cfg.writeEntry("exclude filters", filters); - cfg.writeEntry("exclude filters version", defaultExcludeFilterListVersion()); + m_settings->setExcludedFilters(filters); + m_settings->setExcludedFiltersVersion(defaultExcludeFilterListVersion()); } return filters; @@ -148,7 +144,8 @@ bool FileIndexerConfig::isInitialRun() const { - return m_config.group("General").readEntry("first run", true); + KConfig config(QStringLiteral("baloofilerc")); + return config.group("General").readEntry("first run", true); } @@ -321,10 +318,8 @@ m_devices = new StorageDevices(this); } - KConfigGroup group = m_config.group("General"); - QStringList includeFoldersPlain = group.readPathEntry("folders", QStringList() << QDir::homePath()); - QStringList excludeFoldersPlain = group.readPathEntry("exclude folders", QStringList()); - + QStringList includeFoldersPlain = m_settings->folders(); + QStringList excludeFoldersPlain = m_settings->excludedFolders(); // Add all removable media and network shares as ignored unless they have // been explicitly added in the include list const auto allMedia = m_devices->allMedia(); @@ -355,7 +350,7 @@ void FileIndexerConfig::buildMimeTypeCache() { - const QStringList excludedTypes = m_config.group("General").readPathEntry("exclude mimetypes", defaultExcludeMimetypes()); + const QStringList excludedTypes = m_settings->excludedMimetypes(); #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) m_excludeMimetypes = excludedTypes.toSet(); #else @@ -365,45 +360,46 @@ void FileIndexerConfig::forceConfigUpdate() { - m_config.reparseConfiguration(); + m_settings->load(); m_folderCacheDirty = true; buildExcludeFilterRegExpCache(); buildMimeTypeCache(); - m_indexHidden = m_config.group("General").readEntry("index hidden folders", false); - m_onlyBasicIndexing = m_config.group("General").readEntry("only basic indexing", false); + m_indexHidden = m_settings->indexHiddenFolders(); + m_onlyBasicIndexing = m_settings->onlyBasicIndexing(); } void FileIndexerConfig::setInitialRun(bool isInitialRun) { - m_config.group("General").writeEntry("first run", isInitialRun); - m_config.sync(); + // Don't use kcfg, it will break KCM default state + KConfig config(QStringLiteral("baloofilerc")); + config.group("General").writeEntry("first run", isInitialRun); + config.sync(); } bool FileIndexerConfig::initialUpdateDisabled() const { - return m_config.group("General").readEntry("disable initial update", true); + return m_settings->disableInitialUpdate(); } int FileIndexerConfig::databaseVersion() const { - return m_config.group("General").readEntry("dbVersion", 0); + return m_settings->dbVersion(); } void FileIndexerConfig::setDatabaseVersion(int version) { - m_config.group("General").writeEntry("dbVersion", version); - m_config.sync(); + m_settings->setDbVersion(version); + m_settings->save(); } bool FileIndexerConfig::indexingEnabled() const { - return m_config.group("Basic Settings").readEntry("Indexing-Enabled", true); + return m_settings->indexingEnabled(); } uint FileIndexerConfig::maxUncomittedFiles() const { return m_maxUncomittedFiles; } - diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -30,6 +30,7 @@ ) ecm_qt_declare_logging_category(BALOO_LIB_SRCS HEADER baloodebug.h IDENTIFIER BALOO CATEGORY_NAME org.kde.baloo) +kconfig_add_kcfg_files(BALOO_LIB_SRCS baloosettings.kcfgc GENERATE_MOC) add_library(KF5Baloo ${BALOO_LIB_SRCS}) add_dependencies(KF5Baloo BalooDBusInterfaces) @@ -84,6 +85,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/core_export.h + ${CMAKE_CURRENT_BINARY_DIR}/baloosettings.h ${KF5Baloo_HEADERS} DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/Baloo/baloo COMPONENT Devel diff --git a/src/lib/baloosettings.kcfg b/src/lib/baloosettings.kcfg new file mode 100644 --- /dev/null +++ b/src/lib/baloosettings.kcfg @@ -0,0 +1,53 @@ + + + QDir + fileexcludefilters.h + + + + + true + + + + + + false + + + + 0 + + + + false + + + + true + + + + QStringList() + + + + QStringList() << QDir::homePath() + + + + Baloo::defaultExcludeMimetypes() + + + + Baloo::defaultExcludeFilterList() + + + + 0 + + + diff --git a/src/lib/baloosettings.kcfgc b/src/lib/baloosettings.kcfgc new file mode 100644 --- /dev/null +++ b/src/lib/baloosettings.kcfgc @@ -0,0 +1,9 @@ +File=baloosettings.kcfg +ClassName=BalooSettings +Inherits=KCoreConfigSkeleton +Mutators=true +DefaultValueGetters=true +GenerateProperties=true +ParentInConstructor=true +Visibility=BALOO_CORE_EXPORT +IncludeFiles=\"core_export.h\" diff --git a/src/lib/indexerconfig.cpp b/src/lib/indexerconfig.cpp --- a/src/lib/indexerconfig.cpp +++ b/src/lib/indexerconfig.cpp @@ -1,6 +1,7 @@ /* * This file is part of the KDE Baloo Project * Copyright (C) 2014 Vishesh Handa + * Copyright (C) 2020 Benjamin Port * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -23,17 +24,16 @@ #include "../file/fileexcludefilters.h" #include "../file/regexpcache.h" -#include -#include - #include #include "maininterface.h" +#include "baloosettings.h" using namespace Baloo; class IndexerConfig::Private { public: FileIndexerConfig m_config; + BalooSettings m_settings; }; IndexerConfig::IndexerConfig() @@ -48,15 +48,13 @@ bool IndexerConfig::fileIndexingEnabled() const { - return d->m_config.indexingEnabled(); + return d->m_settings.indexingEnabled(); } void IndexerConfig::setFileIndexingEnabled(bool enabled) const { - KConfig config(QStringLiteral("baloofilerc")); - KConfigGroup basicSettings = config.group("Basic Settings"); - basicSettings.writeEntry("Indexing-Enabled", enabled); + d->m_settings.setIndexingEnabled(enabled); } bool IndexerConfig::shouldBeIndexed(const QString& path) const @@ -92,26 +90,22 @@ void IndexerConfig::setExcludeFolders(const QStringList& excludeFolders) { - KConfig config(QStringLiteral("baloofilerc")); - config.group("General").writePathEntry("exclude folders", excludeFolders); + d->m_settings.setExcludedFolders(excludeFolders); } void IndexerConfig::setIncludeFolders(const QStringList& includeFolders) { - KConfig config(QStringLiteral("baloofilerc")); - config.group("General").writePathEntry("folders", includeFolders); + d->m_settings.setFolders(includeFolders); } void IndexerConfig::setExcludeFilters(const QStringList& excludeFilters) { - KConfig config(QStringLiteral("baloofilerc")); - config.group("General").writeEntry("exclude filters", excludeFilters); + d->m_settings.setExcludedFilters(excludeFilters); } void IndexerConfig::setExcludeMimetypes(const QStringList& excludeMimetypes) { - KConfig config(QStringLiteral("baloofilerc")); - config.group("General").writeEntry("exclude mimetypes", excludeMimetypes); + d->m_settings.setExcludedMimetypes(excludeMimetypes); } bool IndexerConfig::firstRun() const @@ -126,26 +120,22 @@ bool IndexerConfig::indexHidden() const { - KConfig config(QStringLiteral("baloofilerc")); - return config.group("General").readEntry("index hidden folders", false); + return d->m_settings.indexHiddenFolders(); } void IndexerConfig::setIndexHidden(bool value) const { - KConfig config(QStringLiteral("baloofilerc")); - config.group("General").writeEntry("index hidden folders", value); + d->m_settings.setIndexHiddenFolders(value); } bool IndexerConfig::onlyBasicIndexing() const { - KConfig config(QStringLiteral("baloofilerc")); - return config.group("General").readEntry("only basic indexing", false); + return d->m_settings.onlyBasicIndexing(); } void IndexerConfig::setOnlyBasicIndexing(bool value) { - KConfig config(QStringLiteral("baloofilerc")); - config.group("General").writeEntry("only basic indexing", value); + d->m_settings.setOnlyBasicIndexing(value); } void IndexerConfig::refresh() const diff --git a/src/tools/balooctl/main.cpp b/src/tools/balooctl/main.cpp --- a/src/tools/balooctl/main.cpp +++ b/src/tools/balooctl/main.cpp @@ -23,7 +23,6 @@ #include #include -#include #include #include #include