Libksieve

sieveeditorparsingmissingfeaturewarning.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
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 
12 #include <QPointer>
13 
14 using namespace KSieveUi;
15 
16 SieveEditorParsingMissingFeatureWarning::SieveEditorParsingMissingFeatureWarning(TextEditorType type, QWidget *parent)
17  : KMessageWidget(parent)
18 {
19  setVisible(false);
20  setCloseButtonVisible(false);
21  setMessageType(Error);
22  setText(i18n("Some errors were found during parsing. <a href=\"sieveerrordetails\">(Details...)</a>"));
23  connect(this, &SieveEditorParsingMissingFeatureWarning::linkActivated, this, &SieveEditorParsingMissingFeatureWarning::slotShowDetails);
24 
25  switch (type) {
26  case TextEditor: {
27  auto action = new QAction(i18n("Switch to Graphical Mode"), this);
28  connect(action, &QAction::triggered, this, &SieveEditorParsingMissingFeatureWarning::slotSwitchInGraphicalMode);
29  addAction(action);
30 
31  action = new QAction(i18n("Stay in Text Mode"), this);
32  connect(action, &QAction::triggered, this, &SieveEditorParsingMissingFeatureWarning::slotInActualMode);
33  addAction(action);
34  break;
35  }
36  case GraphicEditor: {
37  auto action = new QAction(i18n("Switch to Text Mode"), this);
38  connect(action, &QAction::triggered, this, &SieveEditorParsingMissingFeatureWarning::slotSwitchInTextMode);
39  addAction(action);
40 
41  action = new QAction(i18n("Stay in Graphical Mode"), this);
42  connect(action, &QAction::triggered, this, &SieveEditorParsingMissingFeatureWarning::slotInActualMode);
43  addAction(action);
44  break;
45  }
46  }
47 
48  setWordWrap(true);
49 }
50 
51 SieveEditorParsingMissingFeatureWarning::~SieveEditorParsingMissingFeatureWarning()
52 {
53 }
54 
55 QString SieveEditorParsingMissingFeatureWarning::initialScript() const
56 {
57  return mScript;
58 }
59 
60 void SieveEditorParsingMissingFeatureWarning::slotShowDetails(const QString &content)
61 {
62  if (content == QLatin1String("sieveerrordetails")) {
63  QPointer<SieveScriptParsingErrorDialog> dlg = new SieveScriptParsingErrorDialog(this);
64  dlg->setError(mScript, mErrors);
65  dlg->exec();
66  delete dlg;
67  }
68 }
69 
70 void SieveEditorParsingMissingFeatureWarning::setErrors(const QString &initialScript, const QString &errors)
71 {
72  mErrors = errors;
73  mScript = initialScript;
74 }
75 
76 void SieveEditorParsingMissingFeatureWarning::slotSwitchInTextMode()
77 {
78  Q_EMIT switchToTextMode();
79  setVisible(false);
80 }
81 
82 void SieveEditorParsingMissingFeatureWarning::slotSwitchInGraphicalMode()
83 {
84  Q_EMIT switchToGraphicalMode();
85  setVisible(false);
86 }
87 
88 void SieveEditorParsingMissingFeatureWarning::slotInActualMode()
89 {
90  setVisible(false);
91 }
void triggered(bool checked)
void addAction(QAction *action)
virtual void setVisible(bool visible) override
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 Fri Apr 16 2021 23:09:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.