1/*
2 SPDX-FileCopyrightText: 2012-2015 Vishesh Handa <me@vhanda.in>
3
4 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5*/
6
7#include <QFile>
8
9#include <KLocalizedString>
10#include <QFileInfo>
11#include <QTextStream>
12
13#include "command.h"
14#include "database.h"
15#include "global.h"
16#include "transaction.h"
17
18#include "indexcommand.h"
19#include "indexentry.h"
20
21using namespace Baloo;
22
23QString IndexCommand::command()
24{
25 return QStringLiteral("index");
26}
27
28QString IndexCommand::description()
29{
30 return i18n("Immediately index files");
31}
32
33// IndexCommand::exec
34// Sets up stdout textstream and calls indexFileNow for each of the arguments
35
36int IndexCommand::exec(const QCommandLineParser &parser)
37{
38 QTextStream out(stdout);
39
40 if (parser.positionalArguments().size() < 2) {
41 out << "Enter a filename to index\n";
42 return 1;
43 }
44
45 Database *db = globalDatabaseInstance();
46 if (db->open(mode: Database::ReadWriteDatabase) != Database::OpenResult::Success) {
47 out << "Baloo Index could not be opened\n";
48 return 1;
49 }
50
51 IndexEntry collection(db, out);
52
53 for (int i = 1; i < parser.positionalArguments().size(); ++i) {
54 collection.indexFileNow(fileName: parser.positionalArguments().at(i));
55 }
56
57 collection.commit();
58 out << "File(s) indexed\n";
59 return 0;
60}
61

source code of baloo/src/tools/balooctl/indexcommand.cpp