Libksieve

sievescriptdebuggerwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "sievescriptdebuggerwidget.h"
8#include "sievescriptdebuggerfrontendwidget.h"
9
10#include <KLocalizedString>
11
12#include <QHBoxLayout>
13#include <QLabel>
14#include <QStackedWidget>
15#include <QStandardPaths>
16#include <QTimer>
17
18using namespace KSieveUi;
19SieveScriptDebuggerWidget::SieveScriptDebuggerWidget(QWidget *parent)
20 : QWidget(parent)
21{
22 auto mainLayout = new QHBoxLayout(this);
23 mainLayout->setContentsMargins({});
24 mStackedWidget = new QStackedWidget(this);
25 mStackedWidget->setObjectName(QLatin1StringView("stackedwidget"));
26 mainLayout->addWidget(mStackedWidget);
27
28 mSieveScriptFrontEnd = new SieveScriptDebuggerFrontEndWidget;
29 mSieveScriptFrontEnd->setObjectName(QLatin1StringView("sievescriptfrontend"));
30 mStackedWidget->addWidget(mSieveScriptFrontEnd);
31 connect(mSieveScriptFrontEnd, &SieveScriptDebuggerFrontEndWidget::scriptTextChanged, this, &SieveScriptDebuggerWidget::scriptTextChanged);
32 connect(mSieveScriptFrontEnd, &SieveScriptDebuggerFrontEndWidget::debugButtonEnabled, this, &SieveScriptDebuggerWidget::debugButtonEnabled);
33 connect(this, &SieveScriptDebuggerWidget::debugScriptButtonClicked, mSieveScriptFrontEnd, &SieveScriptDebuggerFrontEndWidget::debugScriptButtonClicked);
34
35 mSieveNoExistingFrontEnd = new QLabel(i18nc("@label:textbox", "\"sieve-test\" was not found on system. Please install it. (See in Dovecot package)"));
36 mSieveNoExistingFrontEnd->setAlignment(Qt::AlignHCenter);
37 QFont f = mSieveNoExistingFrontEnd->font();
38 f.setBold(true);
39 mSieveNoExistingFrontEnd->setFont(f);
40 mSieveNoExistingFrontEnd->setObjectName(QLatin1StringView("sievenoexistingfrontend"));
41 mStackedWidget->addWidget(mSieveNoExistingFrontEnd);
42
43 QTimer::singleShot(0, this, &SieveScriptDebuggerWidget::checkSieveTestApplication);
44}
45
46SieveScriptDebuggerWidget::~SieveScriptDebuggerWidget() = default;
47
48QList<int> SieveScriptDebuggerWidget::splitterSizes() const
49{
50 return mSieveScriptFrontEnd->splitterSizes();
51}
52
53void SieveScriptDebuggerWidget::setSplitterSizes(const QList<int> &sizes)
54{
55 mSieveScriptFrontEnd->setSplitterSizes(sizes);
56}
57
58bool SieveScriptDebuggerWidget::canAccept() const
59{
60 return mSieveScriptFrontEnd->canAccept();
61}
62
63void SieveScriptDebuggerWidget::setScript(const QString &script)
64{
65 if (mStackedWidget->currentWidget() == mSieveScriptFrontEnd) {
66 mSieveScriptFrontEnd->setScript(script);
67 }
68}
69
70QString SieveScriptDebuggerWidget::script() const
71{
72 if (mStackedWidget->currentWidget() == mSieveScriptFrontEnd) {
73 return mSieveScriptFrontEnd->script();
74 } else {
75 return {};
76 }
77}
78
79void SieveScriptDebuggerWidget::checkSieveTestApplication()
80{
81 if (QStandardPaths::findExecutable(QStringLiteral("sieve-test")).isEmpty()) {
82 mHaveDebugApps = false;
83 mStackedWidget->setCurrentWidget(mSieveNoExistingFrontEnd);
84 Q_EMIT sieveTestNotFound();
85 } else {
86 mHaveDebugApps = true;
87 mStackedWidget->setCurrentWidget(mSieveScriptFrontEnd);
88 }
89}
90
91bool SieveScriptDebuggerWidget::haveDebugApps() const
92{
93 return mHaveDebugApps;
94}
95
96#include "moc_sievescriptdebuggerwidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setBold(bool enable)
Q_EMITQ_EMIT
QWidget * currentWidget() const const
void setCurrentWidget(QWidget *widget)
QString findExecutable(const QString &executableName, const QStringList &paths)
AlignHCenter
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.