File indexing completed on 2024-05-12 05:35:38
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2007-2010 Sebastian Trueg <trueg@kde.org> 0004 SPDX-FileCopyrightText: 2012-2014 Vishesh Handa <me@vhanda.in> 0005 SPDX-FileCopyrightText: 2020 Benjamin Port <benjamin.port@enioka.com> 0006 0007 SPDX-License-Identifier: LGPL-2.0-only 0008 */ 0009 0010 #include "kcm.h" 0011 #include "fileexcludefilters.h" 0012 0013 #include <KFormat> 0014 #include <KLocalizedString> 0015 #include <KPluginFactory> 0016 #include <QStandardPaths> 0017 0018 #include <QDBusConnection> 0019 #include <QDBusMessage> 0020 #include <QDBusPendingCall> 0021 #include <QDir> 0022 #include <QProcess> 0023 #include <QPushButton> 0024 0025 #include <Baloo/IndexerConfig> 0026 #include <baloo/baloosettings.h> 0027 #include <baloodata.h> 0028 0029 K_PLUGIN_FACTORY_WITH_JSON(KCMColorsFactory, "kcm_baloofile.json", registerPlugin<Baloo::ServerConfigModule>(); registerPlugin<BalooData>();) 0030 0031 static QString balooDatabaseLocation() 0032 { 0033 // First consult the environment variable, in case the index has been 0034 // relocated manually 0035 QString location = QString::fromLocal8Bit(qgetenv("BALOO_DB_PATH")); 0036 if (location.isEmpty()) { 0037 location = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/baloo/index"); 0038 } else { 0039 location.append(QLatin1String("/index")); 0040 } 0041 return location; 0042 } 0043 0044 using namespace Baloo; 0045 0046 ServerConfigModule::ServerConfigModule(QObject *parent, const KPluginMetaData &metaData) 0047 : KQuickManagedConfigModule(parent, metaData) 0048 , m_data(new BalooData(this)) 0049 , m_filteredFolderModel(new FilteredFolderModel(m_data->settings(), this)) 0050 { 0051 qmlRegisterAnonymousType<FilteredFolderModel>("org.kde.plasma.baloo.kcm", 0); 0052 qmlRegisterAnonymousType<BalooSettings>("org.kde.plasma.baloo.kcm", 0); 0053 0054 setButtons(Help | Apply | Default); 0055 0056 connect(balooSettings(), &BalooSettings::excludedFoldersChanged, m_filteredFolderModel, &FilteredFolderModel::updateDirectoryList); 0057 connect(balooSettings(), &BalooSettings::foldersChanged, m_filteredFolderModel, &FilteredFolderModel::updateDirectoryList); 0058 m_filteredFolderModel->updateDirectoryList(); 0059 } 0060 0061 ServerConfigModule::~ServerConfigModule() 0062 { 0063 } 0064 0065 void ServerConfigModule::load() 0066 { 0067 KQuickManagedConfigModule::load(); 0068 } 0069 0070 void ServerConfigModule::save() 0071 { 0072 KQuickManagedConfigModule::save(); 0073 0074 // Update Baloo config or start Baloo 0075 if (balooSettings()->indexingEnabled()) { 0076 // Update the baloo_file's config cache - if it not yet running, 0077 // the DBus call goes nowhere 0078 Baloo::IndexerConfig config; 0079 config.refresh(); 0080 0081 // Trying to start baloo when it is already running is fine 0082 const QString exe = QStandardPaths::findExecutable(QStringLiteral("baloo_file")); 0083 QProcess::startDetached(exe, QStringList()); 0084 } else { 0085 QDBusMessage message = 0086 QDBusMessage::createMethodCall(QStringLiteral("org.kde.baloo"), QStringLiteral("/"), QStringLiteral("org.kde.baloo.main"), QStringLiteral("quit")); 0087 0088 QDBusConnection::sessionBus().asyncCall(message); 0089 } 0090 0091 // enable baloo runner if we have indexing enabled, otherwise disable it 0092 KConfig cfg(QStringLiteral("krunnerrc")); 0093 KConfigGroup grp = cfg.group(QStringLiteral("Plugins")); 0094 grp.writeEntry("baloosearchEnabled", balooSettings()->indexingEnabled(), KConfig::Notify); 0095 } 0096 0097 FilteredFolderModel *ServerConfigModule::filteredModel() const 0098 { 0099 return m_filteredFolderModel; 0100 } 0101 0102 BalooSettings *ServerConfigModule::balooSettings() const 0103 { 0104 return m_data->settings(); 0105 } 0106 0107 void ServerConfigModule::deleteIndex() 0108 { 0109 QFile(balooDatabaseLocation()).remove(); 0110 } 0111 0112 int ServerConfigModule::rawIndexFileSize() 0113 { 0114 return QFile(balooDatabaseLocation()).size(); 0115 } 0116 0117 QString ServerConfigModule::prettyIndexFileSize() 0118 { 0119 return KFormat().formatByteSize(rawIndexFileSize()); 0120 } 0121 0122 #include "kcm.moc" 0123 #include "moc_kcm.cpp"