Libksieve

autocreatescriptdialog.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 "autocreatescriptdialog.h"
21 #include "sievescriptlistbox.h"
22 #include "sieveconditionwidgetlister.h"
23 #include "sieveactionwidgetlister.h"
24 #include "sieveeditorgraphicalmodewidget.h"
25 
26 #include <KLocalizedString>
27 #include <KSharedConfig>
28 #include <QKeyEvent>
29 #include <QDialogButtonBox>
30 #include <KConfigGroup>
31 #include <QPushButton>
32 #include <QVBoxLayout>
33 
34 using namespace KSieveUi;
35 
36 AutoCreateScriptDialog::AutoCreateScriptDialog(QWidget *parent)
37  : QDialog(parent)
38 {
39  setWindowTitle(i18nc("@title:window", "Create Sieve Filter"));
40  QVBoxLayout *mainLayout = new QVBoxLayout(this);
42  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
43  okButton->setDefault(true);
44  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
47  okButton->setFocus();
48  mEditor = new SieveEditorGraphicalModeWidget(this);
49  mainLayout->addWidget(mEditor);
50  mainLayout->addWidget(buttonBox);
51  readConfig();
52 }
53 
54 AutoCreateScriptDialog::~AutoCreateScriptDialog()
55 {
56  writeConfig();
57 }
58 
59 void AutoCreateScriptDialog::loadScript(const QString &doc, QString &error)
60 {
61  mEditor->loadScript(doc, error);
62 }
63 
64 void AutoCreateScriptDialog::setSieveImapAccountSettings(const SieveImapAccountSettings &sieveImapAccountSettings)
65 {
66  mEditor->setSieveImapAccountSettings(sieveImapAccountSettings);
67 }
68 
69 void AutoCreateScriptDialog::setSieveCapabilities(const QStringList &capabilities)
70 {
71  mEditor->setSieveCapabilities(capabilities);
72 }
73 
74 void AutoCreateScriptDialog::setListOfIncludeFile(const QStringList &listOfIncludeFile)
75 {
76  mEditor->setListOfIncludeFile(listOfIncludeFile);
77 }
78 
79 QString AutoCreateScriptDialog::script(QStringList &required) const
80 {
81  return mEditor->script(required);
82 }
83 
84 void AutoCreateScriptDialog::readConfig()
85 {
86  KConfigGroup group(KSharedConfig::openConfig(), "AutoCreateScriptDialog");
87  const QSize sizeDialog = group.readEntry("Size", QSize(800, 600));
88  if (sizeDialog.isValid()) {
89  resize(sizeDialog);
90  }
91 }
92 
93 void AutoCreateScriptDialog::writeConfig()
94 {
95  KConfigGroup group(KSharedConfig::openConfig(), "AutoCreateScriptDialog");
96  group.writeEntry("Size", size());
97 }
98 
99 bool AutoCreateScriptDialog::event(QEvent *e)
100 {
101  const bool shortCutOverride = (e->type() == QEvent::ShortcutOverride);
102  if (shortCutOverride || e->type() == QEvent::KeyPress) {
103  QKeyEvent *kev = static_cast<QKeyEvent * >(e);
104  if (kev->key() == Qt::Key_Escape) {
105  e->ignore();
106  return true;
107  }
108  }
109  return QDialog::event(e);
110 }
void resize(int w, int h)
bool isValid() const const
ShortcutOverride
QEvent::Type type() const const
virtual void reject()
QSize size() const const
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void ignore()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setFocus()
void setShortcut(const QKeySequence &key)
virtual void accept()
int key() const const
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
void readConfig()
void setWindowTitle(const QString &)
The SieveImapAccountSettings class.
QPushButton * button(QDialogButtonBox::StandardButton which) const const
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-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:07:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.