Libksieve

autocreatescriptdialog.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 "autocreatescriptdialog.h"
8 #include "sieveactionwidgetlister.h"
9 #include "sieveconditionwidgetlister.h"
10 #include "sieveeditorgraphicalmodewidget.h"
11 #include "sievescriptlistbox.h"
12 
13 #include <KConfigGroup>
14 #include <KLocalizedString>
15 #include <KSharedConfig>
16 #include <QDialogButtonBox>
17 #include <QKeyEvent>
18 #include <QPushButton>
19 #include <QVBoxLayout>
20 
21 using namespace KSieveUi;
22 
23 AutoCreateScriptDialog::AutoCreateScriptDialog(QWidget *parent)
24  : QDialog(parent)
25  , mEditor(new SieveEditorGraphicalModeWidget(this))
26 {
27  setWindowTitle(i18nc("@title:window", "Create Sieve Filter"));
28  auto mainLayout = new QVBoxLayout(this);
30  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
31  okButton->setDefault(true);
32  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
35  okButton->setFocus();
36  mainLayout->addWidget(mEditor);
37  mainLayout->addWidget(buttonBox);
38  readConfig();
39 }
40 
41 AutoCreateScriptDialog::~AutoCreateScriptDialog()
42 {
43  writeConfig();
44 }
45 
46 void AutoCreateScriptDialog::loadScript(const QString &doc, QString &error)
47 {
48  mEditor->loadScript(doc, error);
49 }
50 
51 void AutoCreateScriptDialog::setSieveImapAccountSettings(const SieveImapAccountSettings &sieveImapAccountSettings)
52 {
53  mEditor->setSieveImapAccountSettings(sieveImapAccountSettings);
54 }
55 
56 void AutoCreateScriptDialog::setSieveCapabilities(const QStringList &capabilities)
57 {
58  mEditor->setSieveCapabilities(capabilities);
59 }
60 
61 void AutoCreateScriptDialog::setListOfIncludeFile(const QStringList &listOfIncludeFile)
62 {
63  mEditor->setListOfIncludeFile(listOfIncludeFile);
64 }
65 
66 QString AutoCreateScriptDialog::script(QStringList &required) const
67 {
68  return mEditor->script(required);
69 }
70 
71 void AutoCreateScriptDialog::readConfig()
72 {
73  KConfigGroup group(KSharedConfig::openStateConfig(), "AutoCreateScriptDialog");
74  const QSize sizeDialog = group.readEntry("Size", QSize(800, 600));
75  if (sizeDialog.isValid()) {
76  resize(sizeDialog);
77  }
78 }
79 
80 void AutoCreateScriptDialog::writeConfig()
81 {
82  KConfigGroup group(KSharedConfig::openStateConfig(), "AutoCreateScriptDialog");
83  group.writeEntry("Size", size());
84 }
85 
86 bool AutoCreateScriptDialog::event(QEvent *e)
87 {
88  const bool shortCutOverride = (e->type() == QEvent::ShortcutOverride);
89  if (shortCutOverride || e->type() == QEvent::KeyPress) {
90  auto kev = static_cast<QKeyEvent *>(e);
91  if (kev->key() == Qt::Key_Escape) {
92  e->ignore();
93  return true;
94  }
95  }
96  return QDialog::event(e);
97 }
void resize(int w, int h)
bool isValid() const const
ShortcutOverride
QEvent::Type type() const const
virtual void reject()
QSize size() const const
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
void ignore()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setFocus()
void setShortcut(const QKeySequence &key)
virtual void accept()
void readConfig()
void setWindowTitle(const QString &)
The SieveImapAccountSettings class.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setDefault(bool)
virtual bool event(QEvent *event) override
Key_Return
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 23:09:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.