Libksieve

parsingresultdialog.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 
20 #include "parsingresultdialog.h"
21 #include <PimCommon/PimUtil>
22 #include <KPIMTextEdit/PlainTextEditorWidget>
23 #include <KPIMTextEdit/PlainTextEditor>
24 
25 #include <KLocalizedString>
26 #include <KSharedConfig>
27 #include <KConfigGroup>
28 #include <KSyntaxHighlighting/Definition>
29 #include <KSyntaxHighlighting/SyntaxHighlighter>
30 #include <KSyntaxHighlighting/Theme>
31 
32 #include <QDialogButtonBox>
33 #include <QPushButton>
34 #include <QVBoxLayout>
35 
36 using namespace KSieveUi;
37 
38 ParsingResultDialog::ParsingResultDialog(QWidget *parent)
39  : QDialog(parent)
40 {
41  setWindowTitle(i18nc("@title:window", "Sieve Parsing"));
42  QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
43 
44  QVBoxLayout *mainLayout = new QVBoxLayout(this);
45  QPushButton *user1Button = new QPushButton(this);
46  buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
47  connect(buttonBox, &QDialogButtonBox::rejected, this, &ParsingResultDialog::reject);
48  user1Button->setText(i18n("Save As..."));
49 
50  mTextEdit = new KPIMTextEdit::PlainTextEditorWidget(this);
51  auto highlighter = new KSyntaxHighlighting::SyntaxHighlighter(mTextEdit->editor()->document());
52  highlighter->setDefinition(mSyntaxRepo.definitionForName(QStringLiteral("XML")));
53  highlighter->setTheme((palette().color(QPalette::Base).lightness() < 128)
54  ? mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme)
55  : mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::LightTheme));
56  mTextEdit->setReadOnly(true);
57  mainLayout->addWidget(mTextEdit);
58  mainLayout->addWidget(buttonBox);
59 
60  connect(user1Button, &QPushButton::clicked, this, &ParsingResultDialog::slotSaveAs);
61  readConfig();
62 }
63 
64 ParsingResultDialog::~ParsingResultDialog()
65 {
66  writeConfig();
67 }
68 
69 void ParsingResultDialog::setResultParsing(const QString &result)
70 {
71  mTextEdit->setPlainText(result);
72 }
73 
74 void ParsingResultDialog::readConfig()
75 {
76  KConfigGroup group(KSharedConfig::openConfig(), "ParsingResultDialog");
77  const QSize sizeDialog = group.readEntry("Size", QSize(800, 600));
78  if (sizeDialog.isValid()) {
79  resize(sizeDialog);
80  }
81 }
82 
83 void ParsingResultDialog::writeConfig()
84 {
85  KConfigGroup group(KSharedConfig::openConfig(), "ParsingResultDialog");
86  group.writeEntry("Size", size());
87 }
88 
89 void ParsingResultDialog::slotSaveAs()
90 {
91  const QString filter = i18n("XML Files (*.xml);;All Files (*)");
92  PimCommon::Util::saveTextAs(mTextEdit->toPlainText(), filter, this);
93 }
void setDefinition(const Definition &def) override
bool isValid() const const
void addButton(QAbstractButton *button, QDialogButtonBox::ButtonRole role)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void clicked(bool checked)
QFuture< void > filter(Sequence &sequence, KeepFunctor filterFunction)
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
QString i18n(const char *text, const TYPE &arg...)
void readConfig()
void setText(const QString &text)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 1 2020 23:08:20 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.