Libksieve

sieveeditorparsingmissingfeaturewarning.cpp
1 /*
2  Copyright (C) 2013-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 #include "sieveeditorparsingmissingfeaturewarning.h"
20 #include "autocreatescripts/sievescriptparsingerrordialog.h"
21 
22 #include <KLocalizedString>
23 #include <QAction>
24 
25 #include <QPointer>
26 
27 using namespace KSieveUi;
28 
29 SieveEditorParsingMissingFeatureWarning::SieveEditorParsingMissingFeatureWarning(TextEditorType type, QWidget *parent)
30  : KMessageWidget(parent)
31 {
32  setVisible(false);
33  setCloseButtonVisible(false);
34  setMessageType(Error);
35  setText(i18n("Some errors were found during parsing. <a href=\"sieveerrordetails\">(Details...)</a>"));
36  connect(this, &SieveEditorParsingMissingFeatureWarning::linkActivated, this, &SieveEditorParsingMissingFeatureWarning::slotShowDetails);
37 
38  switch (type) {
39  case TextEditor:
40  {
41  QAction *action = new QAction(i18n("Switch to Graphical Mode"), this);
42  connect(action, &QAction::triggered, this, &SieveEditorParsingMissingFeatureWarning::slotSwitchInGraphicalMode);
43  addAction(action);
44 
45  action = new QAction(i18n("Stay in Text Mode"), this);
46  connect(action, &QAction::triggered, this, &SieveEditorParsingMissingFeatureWarning::slotInActualMode);
47  addAction(action);
48  break;
49  }
50  case GraphicEditor:
51  {
52  QAction *action = new QAction(i18n("Switch to Text Mode"), this);
53  connect(action, &QAction::triggered, this, &SieveEditorParsingMissingFeatureWarning::slotSwitchInTextMode);
54  addAction(action);
55 
56  action = new QAction(i18n("Stay in Graphical Mode"), this);
57  connect(action, &QAction::triggered, this, &SieveEditorParsingMissingFeatureWarning::slotInActualMode);
58  addAction(action);
59  break;
60  }
61  }
62 
63  setWordWrap(true);
64 }
65 
66 SieveEditorParsingMissingFeatureWarning::~SieveEditorParsingMissingFeatureWarning()
67 {
68 }
69 
70 QString SieveEditorParsingMissingFeatureWarning::initialScript() const
71 {
72  return mScript;
73 }
74 
75 void SieveEditorParsingMissingFeatureWarning::slotShowDetails(const QString &content)
76 {
77  if (content == QLatin1String("sieveerrordetails")) {
78  QPointer<SieveScriptParsingErrorDialog> dlg = new SieveScriptParsingErrorDialog(this);
79  dlg->setError(mScript, mErrors);
80  dlg->exec();
81  delete dlg;
82  }
83 }
84 
85 void SieveEditorParsingMissingFeatureWarning::setErrors(const QString &initialScript, const QString &errors)
86 {
87  mErrors = errors;
88  mScript = initialScript;
89 }
90 
91 void SieveEditorParsingMissingFeatureWarning::slotSwitchInTextMode()
92 {
93  Q_EMIT switchToTextMode();
94  setVisible(false);
95 }
96 
97 void SieveEditorParsingMissingFeatureWarning::slotSwitchInGraphicalMode()
98 {
99  Q_EMIT switchToGraphicalMode();
100  setVisible(false);
101 }
102 
103 void SieveEditorParsingMissingFeatureWarning::slotInActualMode()
104 {
105  setVisible(false);
106 }
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-2020 The KDE developers.
Generated on Mon Aug 10 2020 23:12:59 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.