Libksieve

parsingresultdialog.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 "parsingresultdialog.h"
8 #include <KPIMTextEdit/PlainTextEditor>
9 #include <KPIMTextEdit/PlainTextEditorWidget>
10 #include <PimCommon/PimUtil>
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 <QDialogButtonBox>
20 #include <QPushButton>
21 #include <QVBoxLayout>
22 
23 using namespace KSieveUi;
24 
25 ParsingResultDialog::ParsingResultDialog(QWidget *parent)
26  : QDialog(parent)
27 {
28  setWindowTitle(i18nc("@title:window", "Sieve Parsing"));
29  auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
30 
31  auto mainLayout = new QVBoxLayout(this);
32  auto user1Button = new QPushButton(this);
33  buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
34  connect(buttonBox, &QDialogButtonBox::rejected, this, &ParsingResultDialog::reject);
35  user1Button->setText(i18n("Save As..."));
36 
37  mTextEdit = new KPIMTextEdit::PlainTextEditorWidget(this);
38  auto highlighter = new KSyntaxHighlighting::SyntaxHighlighter(mTextEdit->editor()->document());
39  highlighter->setDefinition(mSyntaxRepo.definitionForName(QStringLiteral("XML")));
40  highlighter->setTheme((palette().color(QPalette::Base).lightness() < 128) ? mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme)
41  : mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::LightTheme));
42  mTextEdit->setReadOnly(true);
43  mainLayout->addWidget(mTextEdit);
44  mainLayout->addWidget(buttonBox);
45 
46  connect(user1Button, &QPushButton::clicked, this, &ParsingResultDialog::slotSaveAs);
47  readConfig();
48 }
49 
50 ParsingResultDialog::~ParsingResultDialog()
51 {
52  writeConfig();
53 }
54 
55 void ParsingResultDialog::setResultParsing(const QString &result)
56 {
57  mTextEdit->setPlainText(result);
58 }
59 
60 void ParsingResultDialog::readConfig()
61 {
62  KConfigGroup group(KSharedConfig::openStateConfig(), "ParsingResultDialog");
63  const QSize sizeDialog = group.readEntry("Size", QSize(800, 600));
64  if (sizeDialog.isValid()) {
65  resize(sizeDialog);
66  }
67 }
68 
69 void ParsingResultDialog::writeConfig()
70 {
71  KConfigGroup group(KSharedConfig::openStateConfig(), "ParsingResultDialog");
72  group.writeEntry("Size", size());
73 }
74 
75 void ParsingResultDialog::slotSaveAs()
76 {
77  const QString filter = i18n("XML Files (*.xml);;All Files (*)");
78  PimCommon::Util::saveTextAs(mTextEdit->toPlainText(), filter, this);
79 }
void setDefinition(const Definition &def) override
bool isValid() 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...)
void readConfig()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Apr 11 2021 23:09:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.