Mailcommon

filteractionmissingtemplatedialog.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "filteractionmissingtemplatedialog.h"
8
9#include <KSharedConfig>
10
11#include <KConfigGroup>
12#include <KLocalizedString>
13#include <QComboBox>
14
15#include <KWindowConfig>
16#include <QDialogButtonBox>
17#include <QLabel>
18#include <QPushButton>
19#include <QVBoxLayout>
20#include <QWindow>
21
22using namespace MailCommon;
23namespace
24{
25static const char myFilterActionMissingTemplateDialogGroupName[] = "FilterActionMissingTemplateDialog";
26}
27FilterActionMissingTemplateDialog::FilterActionMissingTemplateDialog(const QStringList &templateList, const QString &filtername, QWidget *parent)
28 : QDialog(parent)
29 , mComboBoxTemplate(new QComboBox(this))
30{
31 setModal(true);
32 setWindowTitle(i18nc("@title:window", "Select Template"));
33 auto mainLayout = new QVBoxLayout(this);
34
35 auto label = new QLabel(this);
36 label->setObjectName(QLatin1StringView("label"));
37 label->setText(
38 i18n("Filter template is missing. "
39 "Please select a template to use with filter \"%1\"",
40 filtername));
41 label->setWordWrap(true);
42 mainLayout->addWidget(label);
43 mComboBoxTemplate->setObjectName(QLatin1StringView("comboboxtemplate"));
44 mComboBoxTemplate->addItems(templateList);
45 mainLayout->addWidget(mComboBoxTemplate);
46
48 buttonBox->setObjectName(QLatin1StringView("buttonbox"));
49 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
50 okButton->setDefault(true);
52 connect(buttonBox, &QDialogButtonBox::accepted, this, &FilterActionMissingTemplateDialog::accept);
53 connect(buttonBox, &QDialogButtonBox::rejected, this, &FilterActionMissingTemplateDialog::reject);
54 mainLayout->addWidget(buttonBox);
55 readConfig();
56}
57
58FilterActionMissingTemplateDialog::~FilterActionMissingTemplateDialog()
59{
60 writeConfig();
61}
62
63void FilterActionMissingTemplateDialog::readConfig()
64{
65 create(); // ensure a window is created
66 windowHandle()->resize(QSize(500, 300));
67 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingTemplateDialogGroupName));
69 resize(windowHandle()->size()); // workaround for QTBUG-40584
70}
71
72void FilterActionMissingTemplateDialog::writeConfig()
73{
74 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingTemplateDialogGroupName));
76 group.sync();
77}
78
79QString FilterActionMissingTemplateDialog::selectedTemplate() const
80{
81 if (mComboBoxTemplate->currentIndex() == 0) {
82 return {};
83 } else {
84 return mComboBoxTemplate->currentText();
85 }
86}
87
88#include "moc_filteractionmissingtemplatedialog.cpp"
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
The filter dialog.
void setShortcut(const QKeySequence &key)
void setDefault(bool)
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void create(WId window, bool initializeWindow, bool destroyOldWindow)
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 Fri Dec 13 2024 11:49:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.