Messagelib

dkimruledialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "dkimruledialog.h"
8 #include "dkimrulewidget.h"
9 
10 #include <KConfigGroup>
11 #include <KLocalizedString>
12 #include <KSharedConfig>
13 #include <QDialogButtonBox>
14 #include <QPushButton>
15 #include <QVBoxLayout>
16 
17 namespace
18 {
19 static const char myDKIMRuleDialogConfigGroupName[] = "DKIMRuleDialog";
20 }
21 using namespace MessageViewer;
22 DKIMRuleDialog::DKIMRuleDialog(QWidget *parent)
23  : QDialog(parent)
24  , mRuleWidget(new DKIMRuleWidget(this))
25 {
26  setWindowTitle(i18nc("@title:window", "Add Rule"));
27 
28  auto mainLayout = new QVBoxLayout(this);
29  mainLayout->setObjectName(QStringLiteral("mainlayout"));
30 
31  mRuleWidget->setObjectName(QStringLiteral("rulewidget"));
32  mainLayout->addWidget(mRuleWidget);
33 
35  buttonBox->setObjectName(QStringLiteral("buttonBox"));
36  mainLayout->addWidget(buttonBox);
37 
38  mOkButton = buttonBox->button(QDialogButtonBox::Ok);
39  mOkButton->setEnabled(false);
40 
41  connect(mRuleWidget, &DKIMRuleWidget::updateOkButtonRequested, this, [this](bool enabled) {
42  mOkButton->setEnabled(enabled);
43  });
44 
45  connect(buttonBox, &QDialogButtonBox::accepted, this, &DKIMRuleDialog::accept);
46  connect(buttonBox, &QDialogButtonBox::rejected, this, &DKIMRuleDialog::reject);
47  readConfig();
48 }
49 
50 DKIMRuleDialog::~DKIMRuleDialog()
51 {
52  writeConfig();
53 }
54 
55 void DKIMRuleDialog::readConfig()
56 {
57  KConfigGroup group(KSharedConfig::openStateConfig(), myDKIMRuleDialogConfigGroupName);
58  const QSize size = group.readEntry("Size", QSize(600, 400));
59  if (size.isValid()) {
60  resize(size);
61  }
62 }
63 
64 void DKIMRuleDialog::writeConfig()
65 {
66  KConfigGroup group(KSharedConfig::openStateConfig(), myDKIMRuleDialogConfigGroupName);
67  group.writeEntry("Size", size());
68  group.sync();
69 }
70 
71 void DKIMRuleDialog::loadRule(const MessageViewer::DKIMRule &rule)
72 {
73  setWindowTitle(i18nc("@title:window", "Modify Rule"));
74  mRuleWidget->loadRule(rule);
75 }
76 
77 MessageViewer::DKIMRule DKIMRuleDialog::rule() const
78 {
79  return mRuleWidget->rule();
80 }
bool isValid() const const
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void readConfig()
The DKIMRule class.
Definition: dkimrule.h:17
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Nov 26 2021 23:16:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.