configurefiltersdialog.cpp 1.65 KB
Newer Older
1
2
3
4
5
6
7
/*
  SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>

  SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "configurefiltersdialog.h"
#include "configurefilterswidget.h"
Laurent Montel's avatar
Laurent Montel committed
8
9
#include <KConfigGroup>
#include <KSharedConfig>
10
11
12
13
#include <QDialogButtonBox>
#include <QVBoxLayout>

using namespace MessageList::Core;
Laurent Montel's avatar
Laurent Montel committed
14
15
16
17
18
namespace
{
static const char myConfigureFiltersDialogConfigGroupName[] = "ConfigureFiltersDialog";
}

19
20
21
22
ConfigureFiltersDialog::ConfigureFiltersDialog(QWidget *parent)
    : QDialog(parent)
    , mConfigureFiltersWidget(new ConfigureFiltersWidget(this))
{
Laurent Montel's avatar
Laurent Montel committed
23
24
25
26
27
28
29
30
31
32
    auto mainLayout = new QVBoxLayout(this);
    mainLayout->setObjectName(QStringLiteral("mainLayout"));

    mConfigureFiltersWidget->setObjectName(QStringLiteral("mConfigureFiltersWidget"));
    mainLayout->addWidget(mConfigureFiltersWidget);

    auto button = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
    mainLayout->addWidget(button);
    connect(button, &QDialogButtonBox::accepted, this, &ConfigureFiltersDialog::accept);
    connect(button, &QDialogButtonBox::rejected, this, &ConfigureFiltersDialog::reject);
Laurent Montel's avatar
Laurent Montel committed
33
    readConfig();
34
35
36
37
}

ConfigureFiltersDialog::~ConfigureFiltersDialog()
{
Laurent Montel's avatar
Laurent Montel committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    writeConfig();
}

void ConfigureFiltersDialog::readConfig()
{
    KConfigGroup group(KSharedConfig::openStateConfig(), myConfigureFiltersDialogConfigGroupName);
    const QSize size = group.readEntry("Size", QSize(600, 400));
    if (size.isValid()) {
        resize(size);
    }
}

void ConfigureFiltersDialog::writeConfig()
{
    KConfigGroup group(KSharedConfig::openStateConfig(), myConfigureFiltersDialogConfigGroupName);
    group.writeEntry("Size", size());
    group.sync();
55
}