8#include "configcommand.h"
9#include "indexerconfig.h"
15#include <KLocalizedString>
40 return QStringLiteral(
"config");
43QString ConfigCommand::description()
45 return i18n(
"Manipulate the Baloo configuration");
48int ConfigCommand::exec(
const QCommandLineParser& parser)
53 QTextStream out(stdout);
55 auto printCommand = [&out](
const QString& command,
const QString& description) {
57 out.setFieldWidth(25);
62 out << description <<
'\n';
65 const QString command = args.
isEmpty() ? QStringLiteral(
"help") : args.takeFirst();
66 if (command == QLatin1String(
"help")) {
68 out <<
i18n(
"The config command can be used to manipulate the Baloo Configuration\n");
69 out <<
i18n(
"Usage: balooctl config <command>\n\n");
70 out <<
i18n(
"Possible Commands:\n");
72 printCommand(QStringLiteral(
"add"),
i18n(
"Add a value to config parameter"));
73 printCommand(QStringLiteral(
"rm | remove"),
i18n(
"Remove a value from a config parameter"));
74 printCommand(QStringLiteral(
"list | ls | show"),
i18n(
"Show the value of a config parameter"));
75 printCommand(QStringLiteral(
"set"),
i18n(
"Set the value of a config parameter"));
76 printCommand(QStringLiteral(
"help"),
i18n(
"Display this help menu"));
80 if (command == QLatin1String(
"list") || command == QLatin1String(
"ls") || command == QLatin1String(
"show")) {
82 out <<
i18n(
"The following configuration options may be listed:\n\n");
84 printCommand(QStringLiteral(
"hidden"),
i18n(
"Controls if Baloo indexes hidden files and folders"));
85 printCommand(QStringLiteral(
"contentIndexing"),
i18n(
"Controls if Baloo indexes file content"));
86 printCommand(QStringLiteral(
"includeFolders"),
i18n(
"The list of folders which Baloo indexes"));
87 printCommand(QStringLiteral(
"excludeFolders"),
i18n(
"The list of folders which Baloo will never index"));
88 printCommand(QStringLiteral(
"excludeFilters"),
i18n(
"The list of filters which are used to exclude files"));
89 printCommand(QStringLiteral(
"excludeMimetypes"),
i18n(
"The list of mimetypes which are used to exclude files"));
96 if (config.indexHidden()) {
106 if (config.onlyBasicIndexing()) {
115 auto printList = [&out](
const QStringList&
list) {
116 for (
const QString& item: list) {
132 printList(config.excludeFilters());
137 printList(config.excludeMimetypes());
141 out <<
i18n(
"Config parameter could not be found\n");
145 if (command == QLatin1String(
"rm") || command == QLatin1String(
"remove")) {
147 out <<
i18n(
"The following configuration options may be modified:\n\n");
149 printCommand(QStringLiteral(
"includeFolders"),
i18n(
"The list of folders which Baloo indexes"));
150 printCommand(QStringLiteral(
"excludeFolders"),
i18n(
"The list of folders which Baloo will never index"));
151 printCommand(QStringLiteral(
"excludeFilters"),
i18n(
"The list of filters which are used to exclude files"));
152 printCommand(QStringLiteral(
"excludeMimetypes"),
i18n(
"The list of mimetypes which are used to exclude files"));
156 IndexerConfig config;
160 out <<
i18n(
"A folder must be provided\n");
165 path = normalizeTrailingSlashes(std::move(path));
168 out <<
i18n(
"%1 is not in the list of include folders", path) <<
'\n';
173 config.setIncludeFolders(folders);
180 out <<
i18n(
"A folder must be provided\n");
185 path = normalizeTrailingSlashes(std::move(path));
188 out <<
i18n(
"%1 is not in the list of exclude folders", path) <<
'\n';
193 config.setExcludeFolders(folders);
200 out <<
i18n(
"A filter must be provided\n");
204 QStringList filters = config.excludeFilters();
206 out <<
i18n(
"%1 is not in list of exclude filters", args.
first()) <<
'\n';
211 config.setExcludeFilters(filters);
217 out <<
i18n(
"A mimetype must be provided\n");
221 QStringList mimetypes = config.excludeMimetypes();
223 out <<
i18n(
"%1 is not in list of exclude mimetypes", args.
first()) <<
'\n';
228 config.setExcludeMimetypes(mimetypes);
232 out <<
i18n(
"Config parameter could not be found\n");
236 if (command == QLatin1String(
"add")) {
238 out <<
i18n(
"The following configuration options may be modified:\n\n");
240 printCommand(QStringLiteral(
"includeFolders"),
i18n(
"The list of folders which Baloo indexes"));
241 printCommand(QStringLiteral(
"excludeFolders"),
i18n(
"The list of folders which Baloo will never index"));
242 printCommand(QStringLiteral(
"excludeFilters"),
i18n(
"The list of filters which are used to exclude files"));
243 printCommand(QStringLiteral(
"excludeMimetypes"),
i18n(
"The list of mimetypes which are used to exclude files"));
247 IndexerConfig config;
251 out <<
i18n(
"A folder must be provided\n");
255 auto fileInfo = QFileInfo(args.
takeFirst());
256 if (!fileInfo.exists()) {
257 out <<
i18n(
"Path does not exist\n");
261 if (!fileInfo.isDir()) {
262 out <<
i18n(
"Path is not a directory\n");
266 auto path = normalizeTrailingSlashes(fileInfo.absoluteFilePath());
269 out <<
i18n(
"%1 is already in the list of include folders", path) <<
'\n';
274 out <<
i18n(
"%1 is in the list of exclude folders", path) <<
'\n';
279 config.setIncludeFolders(folders);
286 out <<
i18n(
"A folder must be provided\n");
290 auto fileInfo = QFileInfo(args.
takeFirst());
291 if (!fileInfo.exists()) {
292 out <<
i18n(
"Path does not exist\n");
296 if (!fileInfo.isDir()) {
297 out <<
i18n(
"Path is not a directory\n");
301 auto path = normalizeTrailingSlashes(fileInfo.absoluteFilePath());
304 out <<
i18n(
"%1 is already in the list of exclude folders", path) <<
'\n';
309 out <<
i18n(
"%1 is in the list of exclude folders", path) <<
'\n';
314 config.setExcludeFolders(folders);
321 out <<
i18n(
"A filter must be provided\n");
325 QStringList filters = config.excludeFilters();
327 out <<
i18n(
"Exclude filter is already in the list\n");
332 config.setExcludeFilters(filters);
339 out <<
i18n(
"A mimetype must be provided\n");
343 QStringList mimetypes = config.excludeMimetypes();
345 out <<
i18n(
"Exclude mimetype is already in the list\n");
350 config.setExcludeMimetypes(mimetypes);
355 out <<
i18n(
"Config parameter could not be found\n");
359 if (command == QLatin1String(
"set")) {
361 out <<
i18n(
"The following configuration options may be modified:\n\n");
363 printCommand(QStringLiteral(
"hidden"),
i18n(
"Controls if Baloo indexes hidden files and folders"));
364 printCommand(QStringLiteral(
"contentIndexing"),
i18n(
"Controls if Baloo indexes file content"));
368 IndexerConfig config;
371 if (configParam == QLatin1String(
"hidden")) {
373 out <<
i18n(
"A value must be provided\n");
381 || value.
compare(QLatin1String(
"1")) == 0) {
382 config.setIndexHidden(
true);
389 || value.
compare(QLatin1String(
"0")) == 0) {
390 config.setIndexHidden(
false);
394 out <<
i18n(
"Invalid value\n");
400 out <<
i18n(
"A value must be provided\n");
408 || value.
compare(QLatin1String(
"1")) == 0) {
409 config.setOnlyBasicIndexing(
false);
416 || value.
compare(QLatin1String(
"0")) == 0) {
417 config.setOnlyBasicIndexing(
true);
421 out <<
i18n(
"Invalid value\n");
425 out <<
i18n(
"Config parameter could not be found\n");
QStringList includeFolders() const
Folders to search for files to index and analyze.
QStringList excludeFolders() const
Folders that are excluded from indexing.
QString i18n(const char *text, const TYPE &arg...)
Implements storage for docIds without any associated data Instantiated for:
QString path(const QString &relativePath)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QStringList positionalArguments() const const
void append(QList< T > &&value)
bool isEmpty() const const
qsizetype removeAll(const AT &t)
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const