File indexing completed on 2024-05-12 17:07:08
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, const QVariantList &args) 0047 : KQuickAddons::ManagedConfigModule(parent, metaData, args) 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 ManagedConfigModule::load(); 0068 } 0069 0070 void ServerConfigModule::save() 0071 { 0072 ManagedConfigModule::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 Q_EMIT indexingSettingsChanged(); 0085 } else { 0086 QDBusMessage message = 0087 QDBusMessage::createMethodCall(QStringLiteral("org.kde.baloo"), QStringLiteral("/"), QStringLiteral("org.kde.baloo.main"), QStringLiteral("quit")); 0088 0089 QDBusConnection::sessionBus().asyncCall(message); 0090 } 0091 0092 // enable baloo runner if we have indexing enabled, otherwise disable it 0093 KConfig cfg(QStringLiteral("krunnerrc")); 0094 KConfigGroup grp = cfg.group("Plugins"); 0095 grp.writeEntry("baloosearchEnabled", balooSettings()->indexingEnabled(), KConfig::Notify); 0096 } 0097 0098 FilteredFolderModel *ServerConfigModule::filteredModel() const 0099 { 0100 return m_filteredFolderModel; 0101 } 0102 0103 BalooSettings *ServerConfigModule::balooSettings() const 0104 { 0105 return m_data->settings(); 0106 } 0107 0108 void ServerConfigModule::deleteIndex() 0109 { 0110 QFile(balooDatabaseLocation()).remove(); 0111 } 0112 0113 int ServerConfigModule::rawIndexFileSize() 0114 { 0115 return QFile(balooDatabaseLocation()).size(); 0116 } 0117 0118 QString ServerConfigModule::prettyIndexFileSize() 0119 { 0120 return KFormat().formatByteSize(rawIndexFileSize()); 0121 } 0122 0123 void ServerConfigModule::requestReboot() 0124 { 0125 QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.LogoutPrompt"), 0126 QStringLiteral("/LogoutPrompt"), 0127 QStringLiteral("org.kde.LogoutPrompt"), 0128 QStringLiteral("promptReboot")); 0129 QDBusConnection::sessionBus().asyncCall(msg); 0130 } 0131 0132 #include "kcm.moc" 0133 #include "moc_kcm.cpp"