File indexing completed on 2024-12-01 04:36:54
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "notificationhistorydialog.h" 0008 #include "notificationhistorywidget.h" 0009 0010 #include <KConfigGroup> 0011 #include <KLocalizedString> 0012 #include <KSharedConfig> 0013 #include <KWindowConfig> 0014 #include <QDialogButtonBox> 0015 #include <QVBoxLayout> 0016 #include <QWindow> 0017 0018 namespace 0019 { 0020 const char myNotificationHistoryDialogConfigGroupName[] = "NotificationHistoryDialog"; 0021 } 0022 0023 NotificationHistoryDialog::NotificationHistoryDialog(QWidget *parent) 0024 : QDialog(parent) 0025 , mNotificationHistoryWidget(new NotificationHistoryWidget(this)) 0026 { 0027 setWindowTitle(i18nc("@title:window", "Notification")); 0028 auto mainLayout = new QVBoxLayout(this); 0029 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0030 0031 mNotificationHistoryWidget->setObjectName(QStringLiteral("mNotificationHistoryWidget")); 0032 mainLayout->addWidget(mNotificationHistoryWidget); 0033 connect(mNotificationHistoryWidget, &NotificationHistoryWidget::showNotifyMessage, this, &NotificationHistoryDialog::showNotifyMessage); 0034 0035 auto button = new QDialogButtonBox(QDialogButtonBox::Close, this); 0036 button->setObjectName(QStringLiteral("button")); 0037 mainLayout->addWidget(button); 0038 connect(button, &QDialogButtonBox::rejected, this, &NotificationHistoryDialog::reject); 0039 connect(button, &QDialogButtonBox::accepted, this, &NotificationHistoryDialog::accept); 0040 readConfig(); 0041 } 0042 0043 NotificationHistoryDialog::~NotificationHistoryDialog() 0044 { 0045 writeConfig(); 0046 } 0047 0048 void NotificationHistoryDialog::readConfig() 0049 { 0050 create(); // ensure a window is created 0051 windowHandle()->resize(QSize(400, 300)); 0052 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myNotificationHistoryDialogConfigGroupName)); 0053 KWindowConfig::restoreWindowSize(windowHandle(), group); 0054 resize(windowHandle()->size()); // workaround for QTBUG-40584 0055 } 0056 0057 void NotificationHistoryDialog::writeConfig() 0058 { 0059 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myNotificationHistoryDialogConfigGroupName)); 0060 KWindowConfig::saveWindowSize(windowHandle(), group); 0061 } 0062 0063 void NotificationHistoryDialog::addServerList(const QStringList &serverNames) 0064 { 0065 mNotificationHistoryWidget->addServerList(serverNames); 0066 } 0067 0068 #include "moc_notificationhistorydialog.cpp"