Libksieve

sievescriptdebuggerwidget.cpp
1 /*
2  Copyright (C) 2015-2020 Laurent Montel <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "sievescriptdebuggerwidget.h"
21 #include "sievescriptdebuggerfrontendwidget.h"
22 
23 #include <KLocalizedString>
24 
25 #include <QStackedWidget>
26 #include <QHBoxLayout>
27 #include <QLabel>
28 #include <QStandardPaths>
29 #include <QTimer>
30 
31 using namespace KSieveUi;
32 SieveScriptDebuggerWidget::SieveScriptDebuggerWidget(QWidget *parent)
33  : QWidget(parent)
34 {
35  QHBoxLayout *mainLayout = new QHBoxLayout(this);
36  mainLayout->setContentsMargins(0, 0, 0, 0);
37  mStackedWidget = new QStackedWidget(this);
38  mStackedWidget->setObjectName(QStringLiteral("stackedwidget"));
39  mainLayout->addWidget(mStackedWidget);
40 
41  mSieveScriptFrontEnd = new SieveScriptDebuggerFrontEndWidget;
42  mSieveScriptFrontEnd->setObjectName(QStringLiteral("sievescriptfrontend"));
43  mStackedWidget->addWidget(mSieveScriptFrontEnd);
44  connect(mSieveScriptFrontEnd, &SieveScriptDebuggerFrontEndWidget::scriptTextChanged, this, &SieveScriptDebuggerWidget::scriptTextChanged);
45  connect(mSieveScriptFrontEnd, &SieveScriptDebuggerFrontEndWidget::debugButtonEnabled, this, &SieveScriptDebuggerWidget::debugButtonEnabled);
46  connect(this, &SieveScriptDebuggerWidget::debugScriptButtonClicked, mSieveScriptFrontEnd, &SieveScriptDebuggerFrontEndWidget::debugScriptButtonClicked);
47 
48  mSieveNoExistingFrontEnd = new QLabel(i18n("\"sieve-test\" was not found on system. Please install it. (See in Dovecot package)"));
49  mSieveNoExistingFrontEnd->setAlignment(Qt::AlignHCenter);
50  QFont f = mSieveNoExistingFrontEnd->font();
51  f.setBold(true);
52  mSieveNoExistingFrontEnd->setFont(f);
53  mSieveNoExistingFrontEnd->setObjectName(QStringLiteral("sievenoexistingfrontend"));
54  mStackedWidget->addWidget(mSieveNoExistingFrontEnd);
55 
56  QTimer::singleShot(0, this, &SieveScriptDebuggerWidget::checkSieveTestApplication);
57 }
58 
59 SieveScriptDebuggerWidget::~SieveScriptDebuggerWidget()
60 {
61 }
62 
63 QList<int> SieveScriptDebuggerWidget::splitterSizes() const
64 {
65  return mSieveScriptFrontEnd->splitterSizes();
66 }
67 
68 void SieveScriptDebuggerWidget::setSplitterSizes(const QList<int> &sizes)
69 {
70  mSieveScriptFrontEnd->setSplitterSizes(sizes);
71 }
72 
73 bool SieveScriptDebuggerWidget::canAccept() const
74 {
75  return mSieveScriptFrontEnd->canAccept();
76 }
77 
78 void SieveScriptDebuggerWidget::setScript(const QString &script)
79 {
80  if (mStackedWidget->currentWidget() == mSieveScriptFrontEnd) {
81  mSieveScriptFrontEnd->setScript(script);
82  }
83 }
84 
85 QString SieveScriptDebuggerWidget::script() const
86 {
87  if (mStackedWidget->currentWidget() == mSieveScriptFrontEnd) {
88  return mSieveScriptFrontEnd->script();
89  } else {
90  return QString();
91  }
92 }
93 
94 void SieveScriptDebuggerWidget::checkSieveTestApplication()
95 {
96  if (QStandardPaths::findExecutable(QStringLiteral("sieve-test")).isEmpty()) {
97  mHaveDebugApps = false;
98  mStackedWidget->setCurrentWidget(mSieveNoExistingFrontEnd);
99  Q_EMIT sieveTestNotFound();
100  } else {
101  mHaveDebugApps = true;
102  mStackedWidget->setCurrentWidget(mSieveScriptFrontEnd);
103  }
104 }
105 
106 bool SieveScriptDebuggerWidget::haveDebugApps() const
107 {
108  return mHaveDebugApps;
109 }
void setContentsMargins(int left, int top, int right, int bottom)
QString findExecutable(const QString &executableName, const QStringList &paths)
AlignHCenter
void setBold(bool enable)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
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-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:07:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.