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"
43 const QString exe = QStringLiteral(KDE_INSTALL_FULL_LIBEXECDIR_KF
"/baloo_file");
47int main(
int argc,
char* argv[])
51 KAboutData aboutData(QStringLiteral(
"baloo"),
i18n(
"balooctl"), QStringLiteral(PROJECT_VERSION));
52 aboutData.addAuthor(
i18n(
"Vishesh Handa"),
QString(), QStringLiteral(
"vhanda@kde.org"));
73 QString statusFormatDescription =
i18nc(
"Format to use for status command, %1|%2|%3 are option values, %4 is a CLI command",
74 "Output format <%1|%2|%3>.\nThe default format is \"%1\".\nOnly applies to \"%4\"",
75 QStringLiteral(
"multiline"),
76 QStringLiteral(
"json"),
77 QStringLiteral(
"simple"),
78 QStringLiteral(
"balooctl status <file>"));
79 parser.
addOption({{QStringLiteral(
"f"), QStringLiteral(
"format")},
80 statusFormatDescription,
i18n(
"format"), QStringLiteral(
"multiline")});
94 org::kde::baloo::main mainInterface(QStringLiteral(
"org.kde.baloo"),
98 org::kde::baloo::scheduler schedulerinterface(QStringLiteral(
"org.kde.baloo"),
99 QStringLiteral(
"/scheduler"),
103 ConfigCommand command;
104 return command.exec(parser);
108 StatusCommand commandStatus;
109 return commandStatus.exec(parser);
113 bool isEnabled =
false;
122 cfg.setFileIndexingEnabled(isEnabled);
125 bool running = mainInterface.isValid();
127 out <<
"File Indexer already running\n";
129 out <<
"Enabling and starting the File Indexer\n";
133 out <<
"Disabling and stopping the File Indexer\n";
135 mainInterface.quit();
142 bool running = mainInterface.isValid();
145 mainInterface.quit();
146 out <<
"Stopping the File Indexer ...";
147 for (
int i = 5 * 60; i; --i) {
149 if (!mainInterface.isValid()) {
155 if (!mainInterface.isValid()) {
158 out <<
" - failed to stop!\n";
163 const QString path = fileIndexDbPath() + QStringLiteral(
"/index");
165 out <<
"Deleted the index database\n";
169 out <<
"Restarting the File Indexer\n";
176 schedulerinterface.suspend();
177 out <<
"File Indexer suspended\n";
182 schedulerinterface.resume();
183 out <<
"File Indexer resumed\n";
188 schedulerinterface.checkUnindexedFiles();
189 out <<
"Started search for unindexed files\n";
195 out <<
"Please enter a filename to index\n";
199 Database *db = globalDatabaseInstance();
200 if (!db->open(Database::ReadWriteDatabase)) {
201 out <<
"Baloo Index could not be opened\n";
205 Transaction tr(db, Transaction::ReadWrite);
211 out <<
"Could not stat file: " << url <<
'\n';
214 if (tr.inPhaseOne(
id)) {
215 out <<
"Skipping: " << url <<
" Reason: Already scheduled for indexing\n";
218 if (!tr.documentData(
id).isEmpty()) {
219 out <<
"Skipping: " << url <<
" Reason: Already indexed\n";
222 Indexer indexer(url, &tr);
223 out <<
"Indexing " << url <<
'\n';
227 out <<
"File(s) indexed\n";
234 out <<
"Please enter a filename to index\n";
238 Database *db = globalDatabaseInstance();
239 if (!db->open(Database::ReadWriteDatabase)) {
240 out <<
"Baloo Index could not be opened\n";
244 Transaction tr(db, Transaction::ReadWrite);
252 out <<
"File not found on filesystem or in DB: " << url <<
'\n';
255 out <<
"File has been deleted, clearing from DB: " << url <<
'\n';
258 out <<
"Clearing " << url <<
'\n';
261 tr.removeDocument(
id);
264 out <<
"File(s) cleared\n";
270 Database *db = globalDatabaseInstance();
271 if (!db->open(Database::ReadOnlyDatabase)) {
272 out <<
"Baloo Index could not be opened\n";
276 Transaction tr(db, Transaction::ReadOnly);
278 const quint64 limit = 128;
281 out <<
"All Files were indexed successfully\n";
285 out <<
"The following files could not be indexed:\n";
286 for (
auto id : failedIds) {
287 out << tr.documentUrl(
id) <<
'\n';
289 if (failedIds.size() == limit) {
290 out <<
"... list truncated\n";
296 Database *db = globalDatabaseInstance();
297 if (!db->open(Database::ReadOnlyDatabase)) {
298 out <<
"Baloo Index could not be opened\n";
304 Transaction tr(db, Transaction::ReadOnly);
307 uint totalDataSize = size.expectedSize;
310 auto prFunc = [&](
const QString&
name, uint size) {
311 out.setFieldWidth(20);
313 out.setFieldWidth(0);
315 out.setFieldWidth(15);
316 out << format.formatByteSize(size, 2);
317 out.setFieldWidth(10);
319 out.setFieldWidth(0);
323 out <<
"File Size: " << format.formatByteSize(size.actualSize, 2) <<
"\n";
324 out <<
"Used: " << format.formatByteSize(totalDataSize, 2) <<
"\n\n";
325 prFunc(QStringLiteral(
"PostingDB"), size.postingDb);
326 prFunc(QStringLiteral(
"PositionDB"), size.positionDb);
327 prFunc(QStringLiteral(
"DocTerms"), size.docTerms);
328 prFunc(QStringLiteral(
"DocFilenameTerms"), size.docFilenameTerms);
329 prFunc(QStringLiteral(
"DocXattrTerms"), size.docXattrTerms);
330 prFunc(QStringLiteral(
"IdTree"), size.idTree);
331 prFunc(QStringLiteral(
"IdFileName"), size.idFilename);
332 prFunc(QStringLiteral(
"DocTime"), size.docTime);
333 prFunc(QStringLiteral(
"DocData"), size.docData);
334 prFunc(QStringLiteral(
"ContentIndexingDB"), size.contentIndexingIds);
335 prFunc(QStringLiteral(
"FailedIdsDB"), size.failedIds);
336 prFunc(QStringLiteral(
"MTimeDB"), size.mtimeDb);
343 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()
QByteArray encodeName(const QString &fileName)
QString absoluteFilePath() const const
const_reference at(qsizetype i) const const
bool isEmpty() const const
qsizetype size() 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)