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)) | ||||
58 | { | 55 | { | ||
56 | qmlRegisterType<FilteredFolderModel>(); | ||||
57 | | ||||
59 | KAboutData* about = new KAboutData( | 58 | KAboutData* about = new KAboutData( | ||
60 | QStringLiteral("kcm_baloofile"), i18n("Configure File Search"), | 59 | QStringLiteral("kcm_baloofile"), i18n("Configure File Search"), | ||
ngraham: Make this match the name shown in the list ("File Search") | |||||
61 | QStringLiteral("0.1"), QString(), KAboutLicense::GPL, | 60 | QStringLiteral("0.1"), QString(), KAboutLicense::GPL, | ||
62 | i18n("Copyright 2007-2010 Sebastian Trüg")); | 61 | i18n("Copyright 2007-2010 Sebastian Trüg")); | ||
62 | | ||||
63 | about->addAuthor(i18n("Sebastian Trüg"), QString(), QStringLiteral("trueg@kde.org")); | 63 | about->addAuthor(i18n("Sebastian Trüg"), QString(), QStringLiteral("trueg@kde.org")); | ||
64 | about->addAuthor(i18n("Vishesh Handa"), QString(), QStringLiteral("vhanda@kde.org")); | 64 | about->addAuthor(i18n("Vishesh Handa"), QString(), QStringLiteral("vhanda@kde.org")); | ||
65 | about->addAuthor(i18n("Tomaz Canabrava"), QString(), QStringLiteral("tcnaabrava@kde.org")); | ||||
66 | | ||||
65 | setAboutData(about); | 67 | setAboutData(about); | ||
66 | setButtons(Help | Apply | Default); | 68 | setButtons(Help | Apply | Default); | ||
67 | 69 | | |||
68 | setupUi(this); | 70 | connect(m_filteredFolderModel, &QAbstractListModel::rowsRemoved, this, [this]{ setNeedsSave(true); }); | ||
69 | 71 | connect(m_filteredFolderModel, &QAbstractListModel::rowsInserted, 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 | } | 72 | } | ||
81 | 73 | | |||
82 | | ||||
83 | ServerConfigModule::~ServerConfigModule() | 74 | ServerConfigModule::~ServerConfigModule() | ||
84 | { | 75 | { | ||
85 | } | 76 | } | ||
86 | 77 | | |||
87 | | ||||
88 | void ServerConfigModule::load() | 78 | void ServerConfigModule::load() | ||
89 | { | 79 | { | ||
90 | Baloo::IndexerConfig config; | 80 | Baloo::IndexerConfig config; | ||
91 | 81 | setIndexing(config.fileIndexingEnabled()); | |||
92 | m_previouslyEnabled = config.fileIndexingEnabled(); | 82 | setFileContents(!config.onlyBasicIndexing()); | ||
93 | m_enableCheckbox->setChecked(m_previouslyEnabled); | 83 | m_filteredFolderModel->setDirectoryList(config.includeFolders(), config.excludeFolders()); | ||
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 | | ||||
102 | // All values loaded -> no changes | | |||
103 | Q_EMIT changed(false); | | |||
104 | } | 84 | } | ||
105 | 85 | | |||
106 | | ||||
107 | void ServerConfigModule::save() | 86 | void ServerConfigModule::save() | ||
108 | { | 87 | { | ||
109 | QStringList includeFolders = m_excludeFolders_FSW->includeFolders(); | 88 | qDebug() << "Saving!"; | ||
110 | QStringList excludeFolders = m_excludeFolders_FSW->excludeFolders(); | 89 | bool enabled = m_indexing && !allMountPointsExcluded(); | ||
111 | | ||||
112 | bool mountPointsEx = allMountPointsExcluded(); | | |||
113 | | ||||
114 | bool enabled = m_enableCheckbox->isChecked(); | | |||
115 | if (mountPointsEx) | | |||
116 | enabled = false; | | |||
117 | 90 | | |||
118 | Baloo::IndexerConfig config; | 91 | Baloo::IndexerConfig config; | ||
119 | config.setFileIndexingEnabled(enabled); | 92 | config.setFileIndexingEnabled(enabled); | ||
120 | config.setIncludeFolders(includeFolders); | 93 | config.setIncludeFolders(m_filteredFolderModel->includeFolders()); | ||
121 | config.setExcludeFolders(excludeFolders); | 94 | config.setExcludeFolders(m_filteredFolderModel->excludeFolders()); | ||
122 | config.setOnlyBasicIndexing(!m_enableContentIndexing->isChecked()); | 95 | config.setOnlyBasicIndexing(!m_fileContents); | ||
123 | 96 | | |||
124 | if (m_previouslyEnabled != enabled) { | 97 | if (m_previouslyEnabled != enabled) { | ||
125 | config.setFirstRun(true); | 98 | config.setFirstRun(true); | ||
126 | } | 99 | } | ||
127 | 100 | | |||
128 | // Start Baloo | 101 | // Start Baloo | ||
129 | if (enabled) { | 102 | if (enabled) { | ||
130 | const QString exe = QStandardPaths::findExecutable(QStringLiteral("baloo_file")); | 103 | const QString exe = QStandardPaths::findExecutable(QStringLiteral("baloo_file")); | ||
131 | QProcess::startDetached(exe, QStringList()); | 104 | QProcess::startDetached(exe, QStringList()); | ||
132 | } | 105 | } | ||
133 | else { | 106 | else { | ||
134 | QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.baloo"), | 107 | QDBusMessage message = QDBusMessage::createMethodCall( | ||
108 | QStringLiteral("org.kde.baloo"), | ||||
135 | QStringLiteral("/"), | 109 | QStringLiteral("/"), | ||
136 | QStringLiteral("org.kde.baloo.main"), | 110 | QStringLiteral("org.kde.baloo.main"), | ||
137 | QStringLiteral("quit")); | 111 | QStringLiteral("quit") | ||
112 | ); | ||||
138 | 113 | | |||
139 | QDBusConnection::sessionBus().asyncCall(message); | 114 | QDBusConnection::sessionBus().asyncCall(message); | ||
140 | } | 115 | } | ||
141 | 116 | | |||
142 | // Start cleaner | 117 | // Start cleaner | ||
143 | const QString exe = QStandardPaths::findExecutable(QStringLiteral("baloo_file_cleaner")); | 118 | const QString exe = QStandardPaths::findExecutable(QStringLiteral("baloo_file_cleaner")); | ||
144 | QProcess::startDetached(exe, QStringList()); | 119 | QProcess::startDetached(exe, QStringList()); | ||
145 | 120 | | |||
146 | // Update the baloo_file's config cache | 121 | // Update the baloo_file's config cache | ||
147 | config.refresh(); | 122 | config.refresh(); | ||
148 | | ||||
149 | // all values saved -> no changes | | |||
150 | Q_EMIT changed(false); | | |||
151 | } | 123 | } | ||
152 | 124 | | |||
153 | | ||||
154 | void ServerConfigModule::defaults() | 125 | void ServerConfigModule::defaults() | ||
155 | { | 126 | { | ||
156 | m_excludeFolders_FSW->setDirectoryList(defaultFolders(), QStringList()); | 127 | m_filteredFolderModel->setDirectoryList(defaultFolders(), QStringList()); | ||
157 | } | 128 | } | ||
158 | 129 | | |||
159 | void ServerConfigModule::indexingEnabledChanged() | 130 | bool ServerConfigModule::indexing() const | ||
160 | { | 131 | { | ||
161 | m_enableContentIndexing->setEnabled(m_enableCheckbox->isChecked()); | 132 | return m_indexing; | ||
162 | } | 133 | } | ||
163 | 134 | | |||
164 | void ServerConfigModule::onDirectoryListChanged() | 135 | bool ServerConfigModule::fileContents() const | ||
165 | { | 136 | { | ||
166 | m_enableCheckbox->setChecked(!allMountPointsExcluded()); | 137 | return m_fileContents; | ||
167 | } | 138 | } | ||
168 | 139 | | |||
169 | bool ServerConfigModule::allMountPointsExcluded() | 140 | FilteredFolderModel *ServerConfigModule::filteredModel() const { | ||
141 | return m_filteredFolderModel; | ||||
142 | } | ||||
143 | | ||||
144 | void ServerConfigModule::setIndexing(bool indexing) | ||||
170 | { | 145 | { | ||
171 | QStringList mountPoints; | 146 | if (m_indexing != indexing) { | ||
172 | Q_FOREACH (const QStorageInfo &si, QStorageInfo::mountedVolumes()) { | 147 | m_indexing = indexing; | ||
173 | mountPoints << si.rootPath(); | 148 | Q_EMIT indexingChanged(indexing); | ||
149 | setNeedsSave(true); | ||||
150 | } | ||||
174 | } | 151 | } | ||
175 | 152 | | |||
176 | const QStringList excluded = m_excludeFolders_FSW->excludeFolders(); | 153 | void ServerConfigModule::setFileContents(bool fileContents) | ||
154 | { | ||||
155 | if (m_fileContents != fileContents) { | ||||
156 | m_fileContents = fileContents; | ||||
157 | Q_EMIT fileContentsChanged(fileContents); | ||||
158 | setNeedsSave(true); | ||||
159 | } | ||||
160 | } | ||||
177 | 161 | | |||
178 | if (excluded.toSet() == mountPoints.toSet()) { | 162 | bool ServerConfigModule::allMountPointsExcluded() | ||
179 | return true; | 163 | { | ||
164 | QStringList mountPoints; | ||||
165 | for (const QStorageInfo &si : QStorageInfo::mountedVolumes()) { | ||||
166 | mountPoints.append(si.rootPath()); | ||||
180 | } | 167 | } | ||
181 | 168 | | |||
182 | return false; | 169 | return m_filteredFolderModel->excludeFolders().toSet() == mountPoints.toSet(); | ||
183 | } | 170 | } | ||
184 | 171 | | |||
185 | #include "kcm.moc" | 172 | #include "kcm.moc" |
Make this match the name shown in the list ("File Search")