Akonadi Search

akonadisearchdebugwidget.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 "akonadisearchdebugwidget.h"
8#include "akonadisearchsyntaxhighlighter.h"
9#include "job/akonadisearchdebugsearchjob.h"
10#include <KLineEdit>
11#include <QPushButton>
12
13#include <QLabel>
14#include <QVBoxLayout>
15
16#include <QPlainTextEdit>
17
18using namespace Akonadi::Search;
19
20AkonadiSearchDebugWidget::AkonadiSearchDebugWidget(QWidget *parent)
21 : QWidget(parent)
22 , mPlainTextEditor(new QPlainTextEdit(this))
23 , mSearchPathComboBox(new Akonadi::Search::AkonadiSearchDebugSearchPathComboBox(this))
24 , mLineEdit(new KLineEdit(this))
25 , mSearchButton(new QPushButton(QStringLiteral("Search"), this))
26{
27 auto mainLayout = new QVBoxLayout(this);
28
29 auto hbox = new QHBoxLayout;
30 mainLayout->addLayout(hbox);
31 auto lab = new QLabel(QStringLiteral("Item identifier:"), this);
32 hbox->addWidget(lab);
33 mLineEdit->setTrapReturnKey(true);
34 mLineEdit->setClearButtonEnabled(true);
35 mLineEdit->setObjectName(QLatin1StringView("lineedit"));
36 connect(mLineEdit, &KLineEdit::textChanged, this, &AkonadiSearchDebugWidget::slotSearchLineTextChanged);
37 hbox->addWidget(mLineEdit);
38
39 hbox->addWidget(mSearchPathComboBox);
40 mSearchPathComboBox->setObjectName(QLatin1StringView("searchpathcombo"));
41
42 mSearchButton->setObjectName(QLatin1StringView("searchbutton"));
43 connect(mSearchButton, &QPushButton::clicked, this, &AkonadiSearchDebugWidget::slotSearch);
44 hbox->addWidget(mSearchButton);
45 mSearchButton->setEnabled(false);
46
47 new AkonadiSearchSyntaxHighlighter(mPlainTextEditor->document());
48 mPlainTextEditor->setReadOnly(true);
49 mainLayout->addWidget(mPlainTextEditor);
50 mPlainTextEditor->setObjectName(QLatin1StringView("plaintexteditor"));
51
52 connect(mLineEdit, &KLineEdit::returnPressed, this, &AkonadiSearchDebugWidget::slotSearch);
53}
54
55AkonadiSearchDebugWidget::~AkonadiSearchDebugWidget() = default;
56
57void AkonadiSearchDebugWidget::slotSearchLineTextChanged(const QString &text)
58{
59 mSearchButton->setEnabled(!text.trimmed().isEmpty());
60}
61
62void AkonadiSearchDebugWidget::setAkonadiId(Akonadi::Item::Id akonadiId)
63{
65}
66
67void AkonadiSearchDebugWidget::setSearchType(AkonadiSearchDebugSearchPathComboBox::SearchType type)
68{
69 mSearchPathComboBox->setSearchType(type);
70}
71
72void AkonadiSearchDebugWidget::doSearch()
73{
74 slotSearch();
75}
76
77QString AkonadiSearchDebugWidget::plainText() const
78{
79 return QStringLiteral("Item: %1\n").arg(mLineEdit->text()) + mPlainTextEditor->toPlainText();
80}
81
82void AkonadiSearchDebugWidget::slotSearch()
83{
84 const QString searchId = mLineEdit->text();
85 if (searchId.isEmpty()) {
86 return;
87 }
88 auto job = new Akonadi::Search::AkonadiSearchDebugSearchJob(this);
89 job->setAkonadiId(searchId);
90 job->setSearchPath(mSearchPathComboBox->searchPath());
91 connect(job, &Akonadi::Search::AkonadiSearchDebugSearchJob::result, this, &AkonadiSearchDebugWidget::slotResult);
92 connect(job, &Akonadi::Search::AkonadiSearchDebugSearchJob::error, this, &AkonadiSearchDebugWidget::slotError);
93 job->start();
94}
95
96void AkonadiSearchDebugWidget::slotResult(const QString &result)
97{
98 mPlainTextEditor->setPlainText(result);
99}
100
101void AkonadiSearchDebugWidget::slotError(const QString &errorStr)
102{
103 mPlainTextEditor->setPlainText(QStringLiteral("Error found:\n") + errorStr);
104}
105
106#include "moc_akonadisearchdebugwidget.cpp"
virtual void setText(const QString &)
Akonadi search infrastructure.
Definition core/query.h:21
void clicked(bool checked)
void addLayout(QLayout *layout, int stretch)
void returnPressed()
void textChanged(const QString &text)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
void setPlainText(const QString &text)
QString toPlainText() const const
QString arg(Args &&... args) const const
bool isEmpty() const const
QString number(double n, char format, int precision)
QString trimmed() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:15:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.