File indexing completed on 2022-11-29 20:24:01

0001 /*
0002     SPDX-FileCopyrightText: 2020-2022 Laurent Montel <montel@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 */
0007 
0008 #include "groupmanagementdialog.h"
0009 #include "groupmanagementwidget.h"
0010 
0011 #include <KConfigGroup>
0012 #include <KLocalizedString>
0013 #include <KSharedConfig>
0014 #include <KWindowConfig>
0015 #include <QDialogButtonBox>
0016 #include <QVBoxLayout>
0017 #include <QWindow>
0018 
0019 namespace
0020 {
0021 static const char myGroupManagementDialogGroupName[] = "GroupManagementDialog";
0022 }
0023 
0024 GroupManagementDialog::GroupManagementDialog(QWidget *parent)
0025     : QDialog(parent)
0026     , mGroupManagementWidget(new GroupManagementWidget(this))
0027 {
0028     setWindowTitle(i18nc("@title:window", "Manage Group"));
0029     mGroupManagementWidget->setObjectName(QStringLiteral("mGroupManagementWidget"));
0030     auto mainLayout = new QVBoxLayout(this);
0031     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0032     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
0033     buttonBox->setObjectName(QStringLiteral("buttonBox"));
0034     connect(buttonBox, &QDialogButtonBox::rejected, this, &GroupManagementDialog::reject);
0035     mainLayout->addWidget(mGroupManagementWidget);
0036     mainLayout->addWidget(buttonBox);
0037     readConfig();
0038     connect(mGroupManagementWidget, &GroupManagementWidget::groupsChanged, this, &GroupManagementDialog::groupsChanged);
0039 }
0040 
0041 GroupManagementDialog::~GroupManagementDialog()
0042 {
0043     writeConfig();
0044 }
0045 
0046 void GroupManagementDialog::readConfig()
0047 {
0048     create(); // ensure a window is created
0049     windowHandle()->resize(QSize(400, 300));
0050     KConfigGroup group(KSharedConfig::openStateConfig(), myGroupManagementDialogGroupName);
0051     KWindowConfig::restoreWindowSize(windowHandle(), group);
0052     resize(windowHandle()->size()); // workaround for QTBUG-40584
0053 }
0054 
0055 void GroupManagementDialog::writeConfig()
0056 {
0057     KConfigGroup group(KSharedConfig::openStateConfig(), myGroupManagementDialogGroupName);
0058     KWindowConfig::saveWindowSize(windowHandle(), group);
0059 }