Libksieve

sievescriptdebuggerwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2021 Laurent Montel <[email protected]>
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 
18 using namespace KSieveUi;
19 SieveScriptDebuggerWidget::SieveScriptDebuggerWidget(QWidget *parent)
20  : QWidget(parent)
21 {
22  auto mainLayout = new QHBoxLayout(this);
23  mainLayout->setContentsMargins({});
24  mStackedWidget = new QStackedWidget(this);
25  mStackedWidget->setObjectName(QStringLiteral("stackedwidget"));
26  mainLayout->addWidget(mStackedWidget);
27 
28  mSieveScriptFrontEnd = new SieveScriptDebuggerFrontEndWidget;
29  mSieveScriptFrontEnd->setObjectName(QStringLiteral("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(i18n("\"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(QStringLiteral("sievenoexistingfrontend"));
41  mStackedWidget->addWidget(mSieveNoExistingFrontEnd);
42 
43  QTimer::singleShot(0, this, &SieveScriptDebuggerWidget::checkSieveTestApplication);
44 }
45 
46 SieveScriptDebuggerWidget::~SieveScriptDebuggerWidget()
47 {
48 }
49 
50 QList<int> SieveScriptDebuggerWidget::splitterSizes() const
51 {
52  return mSieveScriptFrontEnd->splitterSizes();
53 }
54 
55 void SieveScriptDebuggerWidget::setSplitterSizes(const QList<int> &sizes)
56 {
57  mSieveScriptFrontEnd->setSplitterSizes(sizes);
58 }
59 
60 bool SieveScriptDebuggerWidget::canAccept() const
61 {
62  return mSieveScriptFrontEnd->canAccept();
63 }
64 
65 void SieveScriptDebuggerWidget::setScript(const QString &script)
66 {
67  if (mStackedWidget->currentWidget() == mSieveScriptFrontEnd) {
68  mSieveScriptFrontEnd->setScript(script);
69  }
70 }
71 
72 QString SieveScriptDebuggerWidget::script() const
73 {
74  if (mStackedWidget->currentWidget() == mSieveScriptFrontEnd) {
75  return mSieveScriptFrontEnd->script();
76  } else {
77  return QString();
78  }
79 }
80 
81 void SieveScriptDebuggerWidget::checkSieveTestApplication()
82 {
83  if (QStandardPaths::findExecutable(QStringLiteral("sieve-test")).isEmpty()) {
84  mHaveDebugApps = false;
85  mStackedWidget->setCurrentWidget(mSieveNoExistingFrontEnd);
86  Q_EMIT sieveTestNotFound();
87  } else {
88  mHaveDebugApps = true;
89  mStackedWidget->setCurrentWidget(mSieveScriptFrontEnd);
90  }
91 }
92 
93 bool SieveScriptDebuggerWidget::haveDebugApps() const
94 {
95  return mHaveDebugApps;
96 }
QString findExecutable(const QString &executableName, const QStringList &paths)
AlignHCenter
void setBold(bool enable)
QString i18n(const char *text, const TYPE &arg...)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Apr 17 2021 23:09:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.