Messagelib

dkimruledialog.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
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
17namespace
18{
19static const char myDKIMRuleDialogConfigGroupName[] = "DKIMRuleDialog";
20}
21using namespace MessageViewer;
22DKIMRuleDialog::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(QLatin1StringView("mainlayout"));
30
31 mRuleWidget->setObjectName(QLatin1StringView("rulewidget"));
32 mainLayout->addWidget(mRuleWidget);
33
35 buttonBox->setObjectName(QLatin1StringView("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
50DKIMRuleDialog::~DKIMRuleDialog()
51{
52 writeConfig();
53}
54
55void DKIMRuleDialog::readConfig()
56{
57 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myDKIMRuleDialogConfigGroupName));
58 const QSize size = group.readEntry("Size", QSize(600, 400));
59 if (size.isValid()) {
60 resize(size);
61 }
62}
63
64void DKIMRuleDialog::writeConfig()
65{
66 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myDKIMRuleDialogConfigGroupName));
67 group.writeEntry("Size", size());
68 group.sync();
69}
70
71void DKIMRuleDialog::loadRule(const MessageViewer::DKIMRule &rule)
72{
73 setWindowTitle(i18nc("@title:window", "Modify Rule"));
74 mRuleWidget->loadRule(rule);
75}
76
77MessageViewer::DKIMRule DKIMRuleDialog::rule() const
78{
79 return mRuleWidget->rule();
80}
81
82#include "moc_dkimruledialog.cpp"
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
The DKIMRule class.
Definition dkimrule.h:18
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.