7#include <QCoreApplication>
8#include <QCommandLineParser>
12#include <KLocalizedString>
19#include <QDBusConnection>
20#include <QDBusConnectionInterface>
24#include "transaction.h"
25#include "databasesize.h"
29#include "indexerconfig.h"
31#include "fileindexerconfig.h"
32#include "monitorcommand.h"
33#include "schedulerinterface.h"
34#include "maininterface.h"
35#include "indexerstate.h"
36#include "configcommand.h"
37#include "statuscommand.h"
39#include "clearcommand.h"
40#include "indexcommand.h"
46 const QString exe = QStringLiteral(KDE_INSTALL_FULL_LIBEXECDIR_KF
"/baloo_file");
50int main(
int argc,
char* argv[])
54 KAboutData aboutData(QStringLiteral(
"baloo"),
i18n(
"balooctl"), QStringLiteral(PROJECT_VERSION));
55 aboutData.addAuthor(
i18n(
"Vishesh Handa"),
QString(), QStringLiteral(
"vhanda@kde.org"));
76 QString statusFormatDescription =
i18nc(
"Format to use for status command, %1|%2|%3 are option values, %4 is a CLI command",
77 "Output format <%1|%2|%3>.\nThe default format is \"%1\".\nOnly applies to \"%4\"",
78 QStringLiteral(
"multiline"),
79 QStringLiteral(
"json"),
80 QStringLiteral(
"simple"),
81 QStringLiteral(
"balooctl status <file>"));
83 parser.
addOption({{QStringLiteral(
"f"), QStringLiteral(
"format")}, statusFormatDescription,
i18n(
"format"), QStringLiteral(
"multiline")});
97 org::kde::baloo::main mainInterface(QStringLiteral(
"org.kde.baloo"),
101 org::kde::baloo::scheduler schedulerinterface(QStringLiteral(
"org.kde.baloo"),
102 QStringLiteral(
"/scheduler"),
108 ConfigCommand command;
109 return command.exec(parser);
113 StatusCommand commandStatus;
114 return commandStatus.exec(parser);
118 bool isEnabled =
false;
127 cfg.setFileIndexingEnabled(isEnabled);
130 bool running = mainInterface.isValid();
132 out <<
"File Indexer already running\n";
134 out <<
"Enabling and starting the File Indexer\n";
138 out <<
"Disabling and stopping the File Indexer\n";
140 mainInterface.quit();
147 bool running = mainInterface.isValid();
150 mainInterface.quit();
151 out <<
"Stopping the File Indexer ...";
152 for (
int i = 5 * 60; i; --i) {
154 if (!mainInterface.isValid()) {
160 if (!mainInterface.isValid()) {
163 out <<
" - failed to stop!\n";
168 const QString path = fileIndexDbPath() + QStringLiteral(
"/index");
170 out <<
"Deleted the index database\n";
174 out <<
"Restarting the File Indexer\n";
181 schedulerinterface.suspend();
182 out <<
"File Indexer suspended\n";
187 schedulerinterface.resume();
188 out <<
"File Indexer resumed\n";
193 schedulerinterface.checkUnindexedFiles();
194 out <<
"Started search for unindexed files\n";
199 IndexCommand commandIndex;
200 return commandIndex.exec(parser);
204 ClearCommand commandClear;
205 return commandClear.exec(parser);
209 Database *db = globalDatabaseInstance();
210 if (!db->open(Database::ReadOnlyDatabase)) {
211 out <<
"Baloo Index could not be opened\n";
215 Transaction tr(db, Transaction::ReadOnly);
217 const quint64 limit = 128;
220 out <<
"All Files were indexed successfully\n";
224 out <<
"The following files could not be indexed:\n";
225 for (
auto id : failedIds) {
226 out << tr.documentUrl(
id) <<
'\n';
228 if (failedIds.size() == limit) {
229 out <<
"... list truncated\n";
235 Database *db = globalDatabaseInstance();
236 if (!db->open(Database::ReadOnlyDatabase)) {
237 out <<
"Baloo Index could not be opened\n";
243 Transaction tr(db, Transaction::ReadOnly);
246 uint totalDataSize = size.expectedSize;
249 auto prFunc = [&](
const QString&
name, uint size) {
250 out.setFieldWidth(20);
252 out.setFieldWidth(0);
254 out.setFieldWidth(15);
255 out << format.formatByteSize(size, 2);
256 out.setFieldWidth(10);
258 out.setFieldWidth(0);
262 out <<
"File Size: " << format.formatByteSize(size.actualSize, 2) <<
"\n";
263 out <<
"Used: " << format.formatByteSize(totalDataSize, 2) <<
"\n\n";
264 prFunc(QStringLiteral(
"PostingDB"), size.postingDb);
265 prFunc(QStringLiteral(
"PositionDB"), size.positionDb);
266 prFunc(QStringLiteral(
"DocTerms"), size.docTerms);
267 prFunc(QStringLiteral(
"DocFilenameTerms"), size.docFilenameTerms);
268 prFunc(QStringLiteral(
"DocXattrTerms"), size.docXattrTerms);
269 prFunc(QStringLiteral(
"IdTree"), size.idTree);
270 prFunc(QStringLiteral(
"IdFileName"), size.idFilename);
271 prFunc(QStringLiteral(
"DocTime"), size.docTime);
272 prFunc(QStringLiteral(
"DocData"), size.docData);
273 prFunc(QStringLiteral(
"ContentIndexingDB"), size.contentIndexingIds);
274 prFunc(QStringLiteral(
"FailedIdsDB"), size.failedIds);
275 prFunc(QStringLiteral(
"MTimeDB"), size.mtimeDb);
282 return mon.exec(parser);
This class allows it to access the current config, to read and modify it.
static void setApplicationData(const KAboutData &aboutData)
Q_SCRIPTABLE QString start(QString train="")
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Implements storage for docIds without any associated data Instantiated for:
QString path(const QString &relativePath)
QString name(StandardAction id)
QCommandLineOption addHelpOption()
bool addOption(const QCommandLineOption &option)
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax)
QCommandLineOption addVersionOption()
QStringList positionalArguments() const const
void process(const QCoreApplication &app)
void showHelp(int exitCode)
void processEvents(QEventLoop::ProcessEventsFlags flags)
QDBusConnection sessionBus()
bool isEmpty() const const
bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid)
QString number(double n, char format, int precision)
QTextStream & flush(QTextStream &stream)
void msleep(unsigned long msecs)