Libksieve

sieveeditorparsingmissingfeaturewarning.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#include "sieveeditorparsingmissingfeaturewarning.h"
7#include "autocreatescripts/sievescriptparsingerrordialog.h"
8
9#include <KLocalizedString>
10#include <QAction>
11
12using namespace KSieveUi;
13
14SieveEditorParsingMissingFeatureWarning::SieveEditorParsingMissingFeatureWarning(TextEditorType type, QWidget *parent)
15 : KMessageWidget(parent)
16{
17 setVisible(false);
18 setCloseButtonVisible(false);
19 setMessageType(Error);
20 setText(i18n("Some errors were found during parsing. <a href=\"sieveerrordetails\">(Details…)</a>"));
21 connect(this, &SieveEditorParsingMissingFeatureWarning::linkActivated, this, &SieveEditorParsingMissingFeatureWarning::slotShowDetails);
22
23 switch (type) {
24 case TextEditor: {
25 auto action = new QAction(i18nc("@action", "Switch to Graphical Mode"), this);
26 connect(action, &QAction::triggered, this, &SieveEditorParsingMissingFeatureWarning::slotSwitchInGraphicalMode);
27 addAction(action);
28
29 action = new QAction(i18nc("@action", "Stay in Text Mode"), this);
30 connect(action, &QAction::triggered, this, &SieveEditorParsingMissingFeatureWarning::slotInActualMode);
31 addAction(action);
32 break;
33 }
34 case GraphicEditor: {
35 auto action = new QAction(i18nc("@action", "Switch to Text Mode"), this);
36 connect(action, &QAction::triggered, this, &SieveEditorParsingMissingFeatureWarning::slotSwitchInTextMode);
37 addAction(action);
38
39 action = new QAction(i18nc("@action", "Stay in Graphical Mode"), this);
40 connect(action, &QAction::triggered, this, &SieveEditorParsingMissingFeatureWarning::slotInActualMode);
41 addAction(action);
42 break;
43 }
44 }
45
46 setWordWrap(true);
47}
48
49SieveEditorParsingMissingFeatureWarning::~SieveEditorParsingMissingFeatureWarning() = default;
50
51QString SieveEditorParsingMissingFeatureWarning::initialScript() const
52{
53 return mScript;
54}
55
56void SieveEditorParsingMissingFeatureWarning::slotShowDetails(const QString &content)
57{
58 if (content == QLatin1StringView("sieveerrordetails")) {
59 SieveScriptParsingErrorDialog dlg(this);
60 dlg.setError(mScript, mErrors);
61 dlg.exec();
62 }
63}
64
65void SieveEditorParsingMissingFeatureWarning::setErrors(const QString &initialScript, const QString &errors)
66{
67 mErrors = errors;
68 mScript = initialScript;
69}
70
71void SieveEditorParsingMissingFeatureWarning::slotSwitchInTextMode()
72{
73 Q_EMIT switchToTextMode();
74 setVisible(false);
75}
76
77void SieveEditorParsingMissingFeatureWarning::slotSwitchInGraphicalMode()
78{
79 Q_EMIT switchToGraphicalMode();
80 setVisible(false);
81}
82
83void SieveEditorParsingMissingFeatureWarning::slotInActualMode()
84{
85 setVisible(false);
86}
87
88#include "moc_sieveeditorparsingmissingfeaturewarning.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void triggered(bool checked)
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
virtual void setVisible(bool visible)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.