Baloo

indexcommand.cpp
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(Database::ReadWriteDatabase)) {
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(parser.positionalArguments().at(i));
55 }
56
57 collection.commit();
58 out << "File(s) indexed\n";
59 return 0;
60}
QString i18n(const char *text, const TYPE &arg...)
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
QStringList positionalArguments() const const
const_reference at(qsizetype i) const const
qsizetype size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.