Libksieve

autocreatescriptdialog.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 "autocreatescriptdialog.h"
8#include "sieveeditorgraphicalmodewidget.h"
9
10#include <KConfigGroup>
11#include <KLocalizedString>
12#include <KSharedConfig>
13#include <KWindowConfig>
14#include <QDialogButtonBox>
15#include <QKeyEvent>
16#include <QPushButton>
17#include <QVBoxLayout>
18#include <QWindow>
19
20using namespace KSieveUi;
21namespace
22{
23static const char myAutoCreateScriptDialogGroupName[] = "AutoCreateScriptDialog";
24}
25AutoCreateScriptDialog::AutoCreateScriptDialog(QWidget *parent)
26 : QDialog(parent)
27 , mEditor(new SieveEditorGraphicalModeWidget(this))
28{
29 setWindowTitle(i18nc("@title:window", "Create Sieve Filter"));
30 auto mainLayout = new QVBoxLayout(this);
32 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
33 okButton->setDefault(true);
35 connect(buttonBox, &QDialogButtonBox::accepted, this, &AutoCreateScriptDialog::accept);
36 connect(buttonBox, &QDialogButtonBox::rejected, this, &AutoCreateScriptDialog::reject);
37 okButton->setFocus();
38 mainLayout->addWidget(mEditor);
39 mainLayout->addWidget(buttonBox);
40 readConfig();
41}
42
43AutoCreateScriptDialog::~AutoCreateScriptDialog()
44{
45 writeConfig();
46}
47
48void AutoCreateScriptDialog::loadScript(const QString &doc, QString &error)
49{
50 mEditor->loadScript(doc, error);
51}
52
53void AutoCreateScriptDialog::setSieveImapAccountSettings(const KSieveCore::SieveImapAccountSettings &sieveImapAccountSettings)
54{
55 mEditor->setSieveImapAccountSettings(sieveImapAccountSettings);
56}
57
58void AutoCreateScriptDialog::setSieveCapabilities(const QStringList &capabilities)
59{
60 mEditor->setSieveCapabilities(capabilities);
61}
62
63void AutoCreateScriptDialog::setListOfIncludeFile(const QStringList &listOfIncludeFile)
64{
65 mEditor->setListOfIncludeFile(listOfIncludeFile);
66}
67
68QString AutoCreateScriptDialog::script(QStringList &required) const
69{
70 return mEditor->script(required);
71}
72
73void AutoCreateScriptDialog::readConfig()
74{
75 create(); // ensure a window is created
76 windowHandle()->resize(QSize(800, 600));
77 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myAutoCreateScriptDialogGroupName));
79 resize(windowHandle()->size()); // workaround for QTBUG-40584
80}
81
82void AutoCreateScriptDialog::writeConfig()
83{
84 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myAutoCreateScriptDialogGroupName));
86 group.sync();
87}
88
89bool AutoCreateScriptDialog::event(QEvent *e)
90{
91 const bool shortCutOverride = (e->type() == QEvent::ShortcutOverride);
92 if (shortCutOverride || e->type() == QEvent::KeyPress) {
93 auto kev = static_cast<QKeyEvent *>(e);
94 if (kev->key() == Qt::Key_Escape) {
95 e->ignore();
96 return true;
97 }
98 }
99 return QDialog::event(e);
100}
101
102#include "moc_autocreatescriptdialog.cpp"
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
The SieveImapAccountSettings class.
QString i18nc(const char *context, 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 setShortcut(const QKeySequence &key)
ShortcutOverride
void ignore()
Type type() const const
void setDefault(bool)
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void create(WId window, bool initializeWindow, bool destroyOldWindow)
virtual bool event(QEvent *event) override
void setFocus()
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 Mon Nov 18 2024 12:14:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.