Akonadi Search

akonadisearchdebugsearchjob.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "akonadisearchdebugsearchjob.h"
8
9#include <QProcess>
10#include <QStandardPaths>
11
12using namespace Akonadi::Search;
13AkonadiSearchDebugSearchJob::AkonadiSearchDebugSearchJob(QObject *parent)
14 : QObject(parent)
15{
16}
17
18AkonadiSearchDebugSearchJob::~AkonadiSearchDebugSearchJob() = default;
19
20void AkonadiSearchDebugSearchJob::start()
21{
22 // "delve" is also a name of Go debugger, some distros prefer xapian-delve
23 // for that reason, so try that first and fallback to "delve"
24 QString delvePath = QStandardPaths::findExecutable(QStringLiteral("xapian-delve"));
25 if (delvePath.isEmpty()) {
26 delvePath = QStandardPaths::findExecutable(QStringLiteral("delve"));
27 }
28 if (delvePath.isEmpty()) {
29 // Don't translate it. Just debug
30 Q_EMIT error(QStringLiteral("\"delve\" not installed on computer."));
32 return;
33 } else {
34 mProcess = new QProcess(this);
35 connect(mProcess, &QProcess::readyReadStandardOutput, this, &AkonadiSearchDebugSearchJob::slotReadStandard);
36 connect(mProcess, &QProcess::readyReadStandardError, this, &AkonadiSearchDebugSearchJob::slotReadError);
37 mProcess->setWorkingDirectory(mPath);
38 QStringList arguments;
39 arguments << QStringLiteral("-r") << mAkonadiId;
40 arguments << mPath;
41 mProcess->start(delvePath, arguments);
42 }
43}
44
45void AkonadiSearchDebugSearchJob::slotReadStandard()
46{
47 const QByteArray stdStrg = mProcess->readAllStandardOutput();
48 Q_EMIT result(QString::fromUtf8(stdStrg));
49 mProcess->close();
50 mProcess->deleteLater();
51 mProcess = nullptr;
53}
54
55void AkonadiSearchDebugSearchJob::slotReadError()
56{
57 const QByteArray errorStrg = mProcess->readAllStandardOutput();
58 Q_EMIT error(QString::fromUtf8(errorStrg));
59 mProcess->close();
60 mProcess->deleteLater();
61 mProcess = nullptr;
63}
64
65void AkonadiSearchDebugSearchJob::setAkonadiId(const QString &id)
66{
67 mAkonadiId = id;
68}
69
70void AkonadiSearchDebugSearchJob::setArguments(const QStringList &args)
71{
72 mArguments = args;
73}
74
75void AkonadiSearchDebugSearchJob::setSearchPath(const QString &path)
76{
77 mPath = path;
78}
79
80#include "moc_akonadisearchdebugsearchjob.cpp"
Akonadi search infrastructure.
Definition core/query.h:21
QString path(const QString &relativePath)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
virtual void close() override
QByteArray readAllStandardOutput()
void readyReadStandardError()
void readyReadStandardOutput()
void setWorkingDirectory(const QString &dir)
void start(OpenMode mode)
QString findExecutable(const QString &executableName, const QStringList &paths)
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:56:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.