Changeset View
Changeset View
Standalone View
Standalone View
kcms/baloo/kcm.cpp
1 | /* This file is part of the KDE Project | 1 | /* This file is part of the KDE Project | ||
---|---|---|---|---|---|
2 | Copyright (c) 2007-2010 Sebastian Trueg <trueg@kde.org> | 2 | Copyright (c) 2007-2010 Sebastian Trueg <trueg@kde.org> | ||
3 | Copyright (c) 2012-2014 Vishesh Handa <me@vhanda.in> | 3 | Copyright (c) 2012-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 | ||
12 | Library General Public License for more details. | 13 | Library General Public License for more details. | ||
13 | 14 | | |||
14 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. | ||
18 | */ | 19 | */ | ||
19 | 20 | | |||
20 | #include "kcm.h" | 21 | #include "kcm.h" | ||
21 | #include "fileexcludefilters.h" | 22 | #include "fileexcludefilters.h" | ||
22 | 23 | | |||
23 | #include <KPluginFactory> | 24 | #include <KPluginFactory> | ||
24 | #include <KPluginLoader> | 25 | #include <KPluginLoader> | ||
25 | #include <KAboutData> | 26 | #include <KAboutData> | ||
26 | #include <QDebug> | | |||
27 | #include <QStandardPaths> | 27 | #include <QStandardPaths> | ||
28 | #include <KLocalizedString> | 28 | #include <KLocalizedString> | ||
29 | 29 | | |||
30 | #include <QPushButton> | 30 | #include <QPushButton> | ||
31 | #include <QDir> | 31 | #include <QDir> | ||
32 | #include <QProcess> | 32 | #include <QProcess> | ||
33 | #include <QDBusConnection> | 33 | #include <QDBusConnection> | ||
34 | #include <QDBusMessage> | 34 | #include <QDBusMessage> | ||
35 | #include <QDBusPendingCall> | 35 | #include <QDBusPendingCall> | ||
36 | #include <QStorageInfo> | 36 | #include <QStorageInfo> | ||
37 | 37 | | |||
38 | #include <Baloo/IndexerConfig> | 38 | #include <Baloo/IndexerConfig> | ||
39 | #include <baloo/baloosettings.h> | ||||
39 | 40 | | |||
40 | K_PLUGIN_FACTORY_WITH_JSON(KCMColorsFactory, "kcm_baloofile.json", registerPlugin<Baloo::ServerConfigModule>();) | 41 | K_PLUGIN_FACTORY_WITH_JSON(KCMColorsFactory, "kcm_baloofile.json", registerPlugin<Baloo::ServerConfigModule>();) | ||
41 | 42 | | |||
42 | namespace | | |||
43 | { | | |||
44 | QStringList defaultFolders() | | |||
45 | { | | |||
46 | return { QDir::homePath() }; | | |||
47 | } | | |||
48 | } // namespace | | |||
49 | | ||||
50 | using namespace Baloo; | 43 | using namespace Baloo; | ||
51 | 44 | | |||
52 | ServerConfigModule::ServerConfigModule(QObject* parent, const QVariantList& args) | 45 | ServerConfigModule::ServerConfigModule(QObject* parent, const QVariantList& args) | ||
53 | : KQuickAddons::ConfigModule(parent, args) | 46 | : KQuickAddons::ManagedConfigModule(parent, args) | ||
54 | , m_filteredFolderModel(new FilteredFolderModel(this)) | 47 | , m_settings(new BalooSettings(this)) | ||
55 | , m_indexing(false) | 48 | , m_filteredFolderModel(new FilteredFolderModel(m_settings, this)) | ||
56 | , m_fileContents(false) | | |||
57 | { | 49 | { | ||
58 | qmlRegisterType<FilteredFolderModel>(); | 50 | qmlRegisterType<FilteredFolderModel>(); | ||
51 | qmlRegisterType<BalooSettings>(); | ||||
59 | 52 | | |||
60 | KAboutData* about = new KAboutData( | 53 | KAboutData* about = new KAboutData( | ||
61 | QStringLiteral("kcm_baloofile"), i18n("File Search"), | 54 | QStringLiteral("kcm_baloofile"), i18n("File Search"), | ||
62 | QStringLiteral("0.1"), QString(), KAboutLicense::GPL, | 55 | QStringLiteral("0.1"), QString(), KAboutLicense::GPL, | ||
63 | i18n("Copyright 2007-2010 Sebastian Trüg")); | 56 | i18n("Copyright 2007-2010 Sebastian Trüg")); | ||
64 | 57 | | |||
65 | about->addAuthor(i18n("Sebastian Trüg"), QString(), QStringLiteral("trueg@kde.org")); | 58 | about->addAuthor(i18n("Sebastian Trüg"), QString(), QStringLiteral("trueg@kde.org")); | ||
66 | about->addAuthor(i18n("Vishesh Handa"), QString(), QStringLiteral("vhanda@kde.org")); | 59 | about->addAuthor(i18n("Vishesh Handa"), QString(), QStringLiteral("vhanda@kde.org")); | ||
67 | about->addAuthor(i18n("Tomaz Canabrava"), QString(), QStringLiteral("tcnaabrava@kde.org")); | 60 | about->addAuthor(i18n("Tomaz Canabrava"), QString(), QStringLiteral("tcnaabrava@kde.org")); | ||
68 | 61 | | |||
69 | setAboutData(about); | 62 | setAboutData(about); | ||
70 | setButtons(Help | Apply | Default); | 63 | setButtons(Help | Apply | Default); | ||
71 | 64 | | |||
72 | connect(m_filteredFolderModel, &FilteredFolderModel::folderAdded, this, [this]{ setNeedsSave(true); }); | 65 | connect(m_settings, &BalooSettings::excludedFoldersChanged, m_filteredFolderModel, &FilteredFolderModel::updateDirectoryList); | ||
73 | connect(m_filteredFolderModel, &FilteredFolderModel::folderRemoved, this, [this]{ setNeedsSave(true); }); | 66 | connect(m_settings, &BalooSettings::foldersChanged, m_filteredFolderModel, &FilteredFolderModel::updateDirectoryList); | ||
67 | m_filteredFolderModel->updateDirectoryList(); | ||||
74 | } | 68 | } | ||
75 | 69 | | |||
76 | ServerConfigModule::~ServerConfigModule() | 70 | ServerConfigModule::~ServerConfigModule() | ||
77 | { | 71 | { | ||
78 | } | 72 | } | ||
79 | 73 | | |||
80 | void ServerConfigModule::load() | 74 | void ServerConfigModule::load() | ||
81 | { | 75 | { | ||
82 | Baloo::IndexerConfig config; | 76 | ManagedConfigModule::load(); | ||
83 | m_indexing = config.fileIndexingEnabled(); | 77 | m_previouslyEnabled = m_settings->indexingEnabled(); | ||
84 | m_previouslyEnabled = m_indexing; | | |||
85 | m_fileContents = !config.onlyBasicIndexing(); | | |||
86 | | ||||
87 | m_filteredFolderModel->setDirectoryList(config.includeFolders(), config.excludeFolders()); | | |||
88 | | ||||
89 | emit indexingChanged(m_indexing); | | |||
90 | emit fileContentsChanged(m_fileContents); | | |||
91 | } | 78 | } | ||
92 | 79 | | |||
93 | void ServerConfigModule::save() | 80 | void ServerConfigModule::save() | ||
94 | { | 81 | { | ||
95 | bool enabled = m_indexing && !allMountPointsExcluded(); | 82 | ManagedConfigModule::save(); | ||
96 | 83 | | |||
97 | Baloo::IndexerConfig config; | 84 | Baloo::IndexerConfig config; | ||
98 | config.setFileIndexingEnabled(enabled); | 85 | config.setFirstRun(m_previouslyEnabled != m_settings->indexingEnabled()); | ||
99 | config.setIncludeFolders(m_filteredFolderModel->includeFolders()); | | |||
100 | config.setExcludeFolders(m_filteredFolderModel->excludeFolders()); | | |||
101 | config.setOnlyBasicIndexing(!m_fileContents); | | |||
102 | config.setFirstRun(false); | | |||
103 | 86 | | |||
104 | if (m_previouslyEnabled != enabled) { | 87 | m_previouslyEnabled = m_settings->indexingEnabled(); | ||
105 | config.setFirstRun(true); | | |||
106 | } | | |||
107 | 88 | | |||
108 | // Start Baloo | 89 | // Start Baloo | ||
109 | if (enabled) { | 90 | if (m_settings->indexingEnabled() && !allMountPointsExcluded()) { | ||
110 | const QString exe = QStandardPaths::findExecutable(QStringLiteral("baloo_file")); | 91 | const QString exe = QStandardPaths::findExecutable(QStringLiteral("baloo_file")); | ||
111 | QProcess::startDetached(exe, QStringList()); | 92 | QProcess::startDetached(exe, QStringList()); | ||
112 | } | 93 | } | ||
113 | else { | 94 | else { | ||
114 | QDBusMessage message = QDBusMessage::createMethodCall( | 95 | QDBusMessage message = QDBusMessage::createMethodCall( | ||
115 | QStringLiteral("org.kde.baloo"), | 96 | QStringLiteral("org.kde.baloo"), | ||
116 | QStringLiteral("/"), | 97 | QStringLiteral("/"), | ||
117 | QStringLiteral("org.kde.baloo.main"), | 98 | QStringLiteral("org.kde.baloo.main"), | ||
118 | QStringLiteral("quit") | 99 | QStringLiteral("quit") | ||
119 | ); | 100 | ); | ||
120 | 101 | | |||
121 | QDBusConnection::sessionBus().asyncCall(message); | 102 | QDBusConnection::sessionBus().asyncCall(message); | ||
122 | } | 103 | } | ||
123 | 104 | | |||
124 | // Start cleaner | 105 | // Start cleaner | ||
125 | const QString exe = QStandardPaths::findExecutable(QStringLiteral("baloo_file_cleaner")); | 106 | const QString exe = QStandardPaths::findExecutable(QStringLiteral("baloo_file_cleaner")); | ||
126 | QProcess::startDetached(exe, QStringList()); | 107 | QProcess::startDetached(exe, QStringList()); | ||
127 | 108 | | |||
128 | // Update the baloo_file's config cache | 109 | // Update the baloo_file's config cache | ||
129 | config.refresh(); | 110 | config.refresh(); | ||
130 | } | 111 | } | ||
131 | 112 | | |||
132 | void ServerConfigModule::defaults() | 113 | FilteredFolderModel *ServerConfigModule::filteredModel() const | ||
133 | { | | |||
134 | m_filteredFolderModel->setDirectoryList(defaultFolders(), QStringList()); | | |||
135 | } | | |||
136 | | ||||
137 | bool ServerConfigModule::indexing() const | | |||
138 | { | | |||
139 | return m_indexing; | | |||
140 | } | | |||
141 | | ||||
142 | bool ServerConfigModule::fileContents() const | | |||
143 | { | 114 | { | ||
144 | return m_fileContents; | | |||
145 | } | | |||
146 | | ||||
147 | FilteredFolderModel *ServerConfigModule::filteredModel() const { | | |||
148 | return m_filteredFolderModel; | 115 | return m_filteredFolderModel; | ||
149 | } | 116 | } | ||
150 | 117 | | |||
151 | void ServerConfigModule::setIndexing(bool indexing) | | |||
152 | { | | |||
153 | if (m_indexing != indexing) { | | |||
154 | m_indexing = indexing; | | |||
155 | Q_EMIT indexingChanged(indexing); | | |||
156 | setNeedsSave(true); | | |||
157 | } | | |||
158 | } | | |||
159 | | ||||
160 | void ServerConfigModule::setFileContents(bool fileContents) | | |||
161 | { | | |||
162 | if (m_fileContents != fileContents) { | | |||
163 | m_fileContents = fileContents; | | |||
164 | Q_EMIT fileContentsChanged(fileContents); | | |||
165 | setNeedsSave(true); | | |||
166 | } | | |||
167 | } | | |||
168 | | ||||
169 | bool ServerConfigModule::allMountPointsExcluded() | 118 | bool ServerConfigModule::allMountPointsExcluded() | ||
170 | { | 119 | { | ||
171 | QStringList mountPoints; | 120 | QStringList mountPoints; | ||
172 | for (const QStorageInfo &si : QStorageInfo::mountedVolumes()) { | 121 | for (const QStorageInfo &si : QStorageInfo::mountedVolumes()) { | ||
173 | mountPoints.append(si.rootPath()); | 122 | mountPoints.append(si.rootPath()); | ||
174 | } | 123 | } | ||
175 | 124 | | |||
176 | return m_filteredFolderModel->excludeFolders().toSet() == mountPoints.toSet(); | 125 | return m_settings->excludedFolders().toSet() == mountPoints.toSet(); | ||
126 | } | ||||
127 | | ||||
128 | BalooSettings *ServerConfigModule::balooSettings() const | ||||
129 | { | ||||
130 | return m_settings; | ||||
177 | } | 131 | } | ||
178 | 132 | | |||
179 | #include "kcm.moc" | 133 | #include "kcm.moc" |