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"
8using namespace Qt::Literals::StringLiterals;
9
10#include "akonadisearchsyntaxhighlighter.h"
11#include "job/akonadisearchdebugsearchjob.h"
12#include <KLineEdit>
13#include <QPushButton>
14
15#include <QLabel>
16#include <QVBoxLayout>
17
18#include <QPlainTextEdit>
19
20using namespace Akonadi::Search;
21
22AkonadiSearchDebugWidget::AkonadiSearchDebugWidget(QWidget *parent)
23 : QWidget(parent)
24 , mPlainTextEditor(new QPlainTextEdit(this))
25 , mSearchPathComboBox(new Akonadi::Search::AkonadiSearchDebugSearchPathComboBox(this))
26 , mLineEdit(new KLineEdit(this))
27 , mSearchButton(new QPushButton(QStringLiteral("Search"), this))
28{
29 auto mainLayout = new QVBoxLayout(this);
30
31 auto hbox = new QHBoxLayout;
32 mainLayout->addLayout(hbox);
33 auto lab = new QLabel(QStringLiteral("Item identifier:"), this);
34 hbox->addWidget(lab);
35 mLineEdit->setTrapReturnKey(true);
36 mLineEdit->setClearButtonEnabled(true);
37 mLineEdit->setObjectName("lineedit"_L1);
38 connect(mLineEdit, &KLineEdit::textChanged, this, &AkonadiSearchDebugWidget::slotSearchLineTextChanged);
39 hbox->addWidget(mLineEdit);
40
41 hbox->addWidget(mSearchPathComboBox);
42 mSearchPathComboBox->setObjectName("searchpathcombo"_L1);
43
44 mSearchButton->setObjectName("searchbutton"_L1);
45 connect(mSearchButton, &QPushButton::clicked, this, &AkonadiSearchDebugWidget::slotSearch);
46 hbox->addWidget(mSearchButton);
47 mSearchButton->setEnabled(false);
48
49 new AkonadiSearchSyntaxHighlighter(mPlainTextEditor->document());
50 mPlainTextEditor->setReadOnly(true);
51 mainLayout->addWidget(mPlainTextEditor);
52 mPlainTextEditor->setObjectName("plaintexteditor"_L1);
53
54 connect(mLineEdit, &KLineEdit::returnPressed, this, &AkonadiSearchDebugWidget::slotSearch);
55}
56
57AkonadiSearchDebugWidget::~AkonadiSearchDebugWidget() = default;
58
59void AkonadiSearchDebugWidget::slotSearchLineTextChanged(const QString &text)
60{
61 mSearchButton->setEnabled(!text.trimmed().isEmpty());
62}
63
64void AkonadiSearchDebugWidget::setAkonadiId(Akonadi::Item::Id akonadiId)
65{
66 mLineEdit->setText(QString::number(akonadiId));
67}
68
69void AkonadiSearchDebugWidget::setSearchType(AkonadiSearchDebugSearchPathComboBox::SearchType type)
70{
71 mSearchPathComboBox->setSearchType(type);
72}
73
74void AkonadiSearchDebugWidget::doSearch()
75{
76 slotSearch();
77}
78
79QString AkonadiSearchDebugWidget::plainText() const
80{
81 return QStringLiteral("Item: %1\n").arg(mLineEdit->text()) + mPlainTextEditor->toPlainText();
82}
83
84void AkonadiSearchDebugWidget::slotSearch()
85{
86 const QString searchId = mLineEdit->text();
87 if (searchId.isEmpty()) {
88 return;
89 }
90 auto job = new Akonadi::Search::AkonadiSearchDebugSearchJob(this);
91 job->setAkonadiId(searchId);
92 job->setSearchPath(mSearchPathComboBox->searchPath());
93 connect(job, &Akonadi::Search::AkonadiSearchDebugSearchJob::result, this, &AkonadiSearchDebugWidget::slotResult);
94 connect(job, &Akonadi::Search::AkonadiSearchDebugSearchJob::error, this, &AkonadiSearchDebugWidget::slotError);
95 job->start();
96}
97
98void AkonadiSearchDebugWidget::slotResult(const QString &result)
99{
100 mPlainTextEditor->setPlainText(result);
101}
102
103void AkonadiSearchDebugWidget::slotError(const QString &errorStr)
104{
105 mPlainTextEditor->setPlainText(QStringLiteral("Error found:\n") + errorStr);
106}
107
108#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)
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 Fri Dec 6 2024 12:04:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.