Libksieve

sievescriptparsingerrordialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "sievescriptparsingerrordialog.h"
8 #include <KPIMTextEdit/RichTextEditorWidget>
9 #include <PimCommon/PimUtil>
10 
11 #include <KLocalizedString>
12 #include <KSharedConfig>
13 
14 #include <KConfigGroup>
15 #include <QDialogButtonBox>
16 #include <QPushButton>
17 #include <QVBoxLayout>
18 #include <cerrno>
19 using namespace KSieveUi;
20 SieveScriptParsingErrorDialog::SieveScriptParsingErrorDialog(QWidget *parent)
21  : QDialog(parent)
22 {
23  setWindowTitle(i18nc("@title:window", "Sieve Parsing Error"));
24  auto mainLayout = new QVBoxLayout(this);
25 
26  mTextEdit = new KPIMTextEdit::RichTextEditorWidget(this);
27  mTextEdit->setReadOnly(true);
28 
29  auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
30  auto user1Button = new QPushButton(this);
31  buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
32  connect(buttonBox, &QDialogButtonBox::rejected, this, &SieveScriptParsingErrorDialog::reject);
33  user1Button->setText(i18n("Save As..."));
34  readConfig();
35  connect(user1Button, &QPushButton::clicked, this, &SieveScriptParsingErrorDialog::slotSaveAs);
36  mainLayout->addWidget(mTextEdit);
37  mainLayout->addWidget(buttonBox);
38 }
39 
40 SieveScriptParsingErrorDialog::~SieveScriptParsingErrorDialog()
41 {
42  writeConfig();
43 }
44 
45 void SieveScriptParsingErrorDialog::setError(QString script, QString error)
46 {
47  QString str;
48  str = QLatin1String("<b>") + i18n("Sieve script:") + QLatin1String("</b><br>");
49  str += script.replace(QLatin1Char('\n'), QStringLiteral("<br>")) + QLatin1String("<br><br>");
50  str += QLatin1String("<b>") + i18n("Errors reported:") + QLatin1String("</b><br>");
51  str += error.replace(QLatin1Char('\n'), QStringLiteral("<br>")) + QLatin1String("<br>");
52  mTextEdit->setHtml(str);
53 }
54 
55 void SieveScriptParsingErrorDialog::readConfig()
56 {
57  KConfigGroup group(KSharedConfig::openStateConfig(), "SieveScriptParsingErrorDialog");
58  const QSize sizeDialog = group.readEntry("Size", QSize(800, 600));
59  if (sizeDialog.isValid()) {
60  resize(sizeDialog);
61  }
62 }
63 
64 void SieveScriptParsingErrorDialog::writeConfig()
65 {
66  KConfigGroup group(KSharedConfig::openStateConfig(), "SieveScriptParsingErrorDialog");
67  group.writeEntry("Size", size());
68 }
69 
70 void SieveScriptParsingErrorDialog::slotSaveAs()
71 {
72  const QString filter = i18n("All Files (*)");
73  PimCommon::Util::saveTextAs(mTextEdit->toPlainText(), filter, this, QUrl(), i18nc("@title:window", "Save Log To File"));
74 }
void resize(int w, int h)
bool isValid() const const
QSize size() const const
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void clicked(bool checked)
QFuture< void > filter(Sequence &sequence, KeepFunctor filterFunction)
QString i18n(const char *text, const TYPE &arg...)
QString & replace(int position, int n, QChar after)
void readConfig()
void setWindowTitle(const QString &)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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.