File indexing completed on 2024-11-24 04:43:06

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include "confirmbeforedeletingdialog.h"
0007 #include "confirmbeforedeletingwidget.h"
0008 
0009 #include <KConfigGroup>
0010 #include <KLocalizedString>
0011 #include <KSharedConfig>
0012 #include <KWindowConfig>
0013 #include <QDialogButtonBox>
0014 #include <QVBoxLayout>
0015 #include <QWindow>
0016 
0017 namespace
0018 {
0019 static const char myConfirmBeforeDeletingConfigGroupName[] = "ConfirmBeforeDeletingDialog";
0020 }
0021 ConfirmBeforeDeletingDialog::ConfirmBeforeDeletingDialog(QWidget *parent)
0022     : QDialog(parent)
0023     , mConfirmBeforeDeletingWidget(new ConfirmBeforeDeletingWidget(this))
0024 {
0025     setWindowTitle(i18nc("@title:window", "Configure Before Deleting Mail"));
0026     auto mainLayout = new QVBoxLayout(this);
0027     mainLayout->setObjectName(QLatin1StringView("mainlayout"));
0028 
0029     mConfirmBeforeDeletingWidget->setObjectName(QLatin1StringView("mConfirmBeforeDeletingWidget"));
0030     mainLayout->addWidget(mConfirmBeforeDeletingWidget);
0031 
0032     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0033     buttonBox->setObjectName(QLatin1StringView("buttonBox"));
0034     mainLayout->addWidget(buttonBox);
0035     connect(buttonBox, &QDialogButtonBox::accepted, this, &ConfirmBeforeDeletingDialog::slotSave);
0036     connect(buttonBox, &QDialogButtonBox::rejected, this, &ConfirmBeforeDeletingDialog::reject);
0037     readConfig();
0038 }
0039 
0040 ConfirmBeforeDeletingDialog::~ConfirmBeforeDeletingDialog()
0041 {
0042     writeConfig();
0043 }
0044 
0045 void ConfirmBeforeDeletingDialog::slotSave()
0046 {
0047     mConfirmBeforeDeletingWidget->save();
0048     accept();
0049 }
0050 
0051 void ConfirmBeforeDeletingDialog::writeConfig()
0052 {
0053     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfirmBeforeDeletingConfigGroupName));
0054     KWindowConfig::saveWindowSize(windowHandle(), group);
0055     group.sync();
0056 }
0057 
0058 void ConfirmBeforeDeletingDialog::readConfig()
0059 {
0060     create(); // ensure a window is created
0061     windowHandle()->resize(QSize(500, 300));
0062     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfirmBeforeDeletingConfigGroupName));
0063     KWindowConfig::restoreWindowSize(windowHandle(), group);
0064     resize(windowHandle()->size()); // workaround for QTBUG-40584
0065 }
0066 
0067 #include "moc_confirmbeforedeletingdialog.cpp"