File indexing completed on 2024-12-22 04:56:52

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