Libksieve

sievescriptparsingerrordialog.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "sievescriptparsingerrordialog.h"
8#include <PimCommon/PimUtil>
9#include <TextCustomEditor/RichTextEditorWidget>
10
11#include <KLocalizedString>
12#include <KSharedConfig>
13
14#include <KConfigGroup>
15#include <KWindowConfig>
16#include <QDialogButtonBox>
17#include <QPushButton>
18#include <QVBoxLayout>
19#include <QWindow>
20#include <cerrno>
21using namespace KSieveUi;
22namespace
23{
24static const char mySieveScriptParsingErrorDialogGroupName[] = "SieveScriptParsingErrorDialog";
25}
26SieveScriptParsingErrorDialog::SieveScriptParsingErrorDialog(QWidget *parent)
27 : QDialog(parent)
28 , mTextEdit(new TextCustomEditor::RichTextEditorWidget(this))
29{
30 setWindowTitle(i18nc("@title:window", "Sieve Parsing Error"));
31 auto mainLayout = new QVBoxLayout(this);
32
33 mTextEdit->setReadOnly(true);
34
35 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
36 auto user1Button = new QPushButton(this);
37 buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
38 connect(buttonBox, &QDialogButtonBox::rejected, this, &SieveScriptParsingErrorDialog::reject);
39 user1Button->setText(i18n("Save As…"));
40 readConfig();
41 connect(user1Button, &QPushButton::clicked, this, &SieveScriptParsingErrorDialog::slotSaveAs);
42 mainLayout->addWidget(mTextEdit);
43 mainLayout->addWidget(buttonBox);
44}
45
46SieveScriptParsingErrorDialog::~SieveScriptParsingErrorDialog()
47{
48 writeConfig();
49}
50
51void SieveScriptParsingErrorDialog::setError(QString script, QString error)
52{
53 QString str;
54 str = QLatin1StringView("<b>") + i18n("Sieve script:") + QLatin1StringView("</b><br>");
55 str += script.replace(QLatin1Char('\n'), QStringLiteral("<br>")) + QLatin1StringView("<br><br>");
56 str += QLatin1StringView("<b>") + i18n("Errors reported:") + QLatin1StringView("</b><br>");
57 str += error.replace(QLatin1Char('\n'), QStringLiteral("<br>")) + QLatin1StringView("<br>");
58 mTextEdit->setHtml(str);
59}
60
61void SieveScriptParsingErrorDialog::readConfig()
62{
63 create(); // ensure a window is created
64 windowHandle()->resize(QSize(800, 600));
65 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySieveScriptParsingErrorDialogGroupName));
67 resize(windowHandle()->size()); // workaround for QTBUG-40584
68}
69
70void SieveScriptParsingErrorDialog::writeConfig()
71{
72 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySieveScriptParsingErrorDialogGroupName));
74 group.sync();
75}
76
77void SieveScriptParsingErrorDialog::slotSaveAs()
78{
79 const QString filter = i18n("All Files (*)");
80 PimCommon::Util::saveTextAs(mTextEdit->toPlainText(), filter, this, QUrl(), i18nc("@title:window", "Save Log To File"));
81}
82
83#include "moc_sievescriptparsingerrordialog.cpp"
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
void clicked(bool checked)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void create(WId window, bool initializeWindow, bool destroyOldWindow)
void resize(const QSize &)
QWindow * windowHandle() const const
void resize(const QSize &newSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.