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