Libksieve

parsingresultdialog.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 "parsingresultdialog.h"
8#include <PimCommon/PimUtil>
9#include <TextCustomEditor/PlainTextEditor>
10#include <TextCustomEditor/PlainTextEditorWidget>
11
12#include <KConfigGroup>
13#include <KLocalizedString>
14#include <KSharedConfig>
15#include <KSyntaxHighlighting/Definition>
16#include <KSyntaxHighlighting/SyntaxHighlighter>
17#include <KSyntaxHighlighting/Theme>
18
19#include <KWindowConfig>
20#include <QDialogButtonBox>
21#include <QPushButton>
22#include <QVBoxLayout>
23#include <QWindow>
24
25using namespace KSieveUi;
26namespace
27{
28static const char myParsingResultDialogGroupName[] = "ParsingResultDialog";
29}
30ParsingResultDialog::ParsingResultDialog(QWidget *parent)
31 : QDialog(parent)
32{
33 setWindowTitle(i18nc("@title:window", "Sieve Parsing"));
34 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
35
36 auto mainLayout = new QVBoxLayout(this);
37 auto user1Button = new QPushButton(this);
38 buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
39 connect(buttonBox, &QDialogButtonBox::rejected, this, &ParsingResultDialog::reject);
40 user1Button->setText(i18n("Save As…"));
41
42 mTextEdit = new TextCustomEditor::PlainTextEditorWidget(this);
43 auto highlighter = new KSyntaxHighlighting::SyntaxHighlighter(mTextEdit->editor()->document());
44 highlighter->setDefinition(mSyntaxRepo.definitionForName(QStringLiteral("XML")));
45 highlighter->setTheme((palette().color(QPalette::Base).lightness() < 128) ? mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme)
46 : mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::LightTheme));
47 mTextEdit->setReadOnly(true);
48 mainLayout->addWidget(mTextEdit);
49 mainLayout->addWidget(buttonBox);
50
51 connect(user1Button, &QPushButton::clicked, this, &ParsingResultDialog::slotSaveAs);
52 readConfig();
53}
54
55ParsingResultDialog::~ParsingResultDialog()
56{
57 writeConfig();
58}
59
60void ParsingResultDialog::setResultParsing(const QString &result)
61{
62 mTextEdit->setPlainText(result);
63}
64
65void ParsingResultDialog::readConfig()
66{
67 create(); // ensure a window is created
68 windowHandle()->resize(QSize(800, 600));
69 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myParsingResultDialogGroupName));
71 resize(windowHandle()->size()); // workaround for QTBUG-40584
72}
73
74void ParsingResultDialog::writeConfig()
75{
76 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myParsingResultDialogGroupName));
78 group.sync();
79}
80
81void ParsingResultDialog::slotSaveAs()
82{
83 const QString filter = i18n("XML Files (*.xml);;All Files (*)");
84 PimCommon::Util::saveTextAs(mTextEdit->toPlainText(), filter, this);
85}
86
87#include "moc_parsingresultdialog.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...)
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)
int result() const const
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 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.