Mailcommon

filteractionmissingtemplatedialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2016-2022 Laurent Montel <[email protected]>
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 <QDialogButtonBox>
16 #include <QLabel>
17 #include <QPushButton>
18 #include <QVBoxLayout>
19 
20 using namespace MailCommon;
21 
22 FilterActionMissingTemplateDialog::FilterActionMissingTemplateDialog(const QStringList &templateList, const QString &filtername, QWidget *parent)
23  : QDialog(parent)
24  , mComboBoxTemplate(new QComboBox(this))
25 {
26  setModal(true);
27  setWindowTitle(i18nc("@title:window", "Select Template"));
28  auto mainLayout = new QVBoxLayout(this);
29 
30  auto label = new QLabel(this);
31  label->setObjectName(QStringLiteral("label"));
32  label->setText(
33  i18n("Filter template is missing. "
34  "Please select a template to use with filter \"%1\"",
35  filtername));
36  label->setWordWrap(true);
37  mainLayout->addWidget(label);
38  mComboBoxTemplate->setObjectName(QStringLiteral("comboboxtemplate"));
39  mComboBoxTemplate->addItems(templateList);
40  mainLayout->addWidget(mComboBoxTemplate);
41 
43  buttonBox->setObjectName(QStringLiteral("buttonbox"));
44  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
45  okButton->setDefault(true);
46  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
47  connect(buttonBox, &QDialogButtonBox::accepted, this, &FilterActionMissingTemplateDialog::accept);
48  connect(buttonBox, &QDialogButtonBox::rejected, this, &FilterActionMissingTemplateDialog::reject);
49  mainLayout->addWidget(buttonBox);
50  readConfig();
51 }
52 
53 FilterActionMissingTemplateDialog::~FilterActionMissingTemplateDialog()
54 {
55  writeConfig();
56 }
57 
58 void FilterActionMissingTemplateDialog::readConfig()
59 {
60  KConfigGroup group(KSharedConfig::openStateConfig(), "FilterActionMissingTemplateDialog");
61 
62  const QSize size = group.readEntry("Size", QSize(500, 300));
63  if (size.isValid()) {
64  resize(size);
65  }
66 }
67 
68 void FilterActionMissingTemplateDialog::writeConfig()
69 {
70  KConfigGroup group(KSharedConfig::openStateConfig(), "FilterActionMissingTemplateDialog");
71  group.writeEntry("Size", size());
72 }
73 
74 QString FilterActionMissingTemplateDialog::selectedTemplate() const
75 {
76  if (mComboBoxTemplate->currentIndex() == 0) {
77  return {};
78  } else {
79  return mComboBoxTemplate->currentText();
80  }
81 }
bool isValid() const const
void setShortcut(const QKeySequence &key)
void readConfig()
QString i18n(const char *text, const TYPE &arg...)
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
Key_Return
QString label(StandardShortcut id)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setDefault(bool)
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.