File indexing completed on 2025-02-16 04:49:30

0001 /*
0002    SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #include "checkattachmentdialog.h"
0007 #include <KConfigGroup>
0008 #include <KLocalizedString>
0009 #include <KSharedConfig>
0010 #include <KWindowConfig>
0011 #include <QDialogButtonBox>
0012 #include <QLabel>
0013 #include <QListWidget>
0014 #include <QVBoxLayout>
0015 #include <QWindow>
0016 namespace
0017 {
0018 static const char myConfigCheckAttachmentDialog[] = "CheckAttachmentDialog";
0019 }
0020 CheckAttachmentDialog::CheckAttachmentDialog(QWidget *parent)
0021     : QDialog(parent)
0022     , mListWidget(new QListWidget(this))
0023 {
0024     setWindowTitle(i18nc("@title:window", "Check Attachment"));
0025     auto mainLayout = new QVBoxLayout(this);
0026 
0027     auto lab = new QLabel(i18n("Do you want to send some attachment?"), this);
0028     lab->setObjectName(QLatin1StringView("lab"));
0029     mainLayout->addWidget(lab);
0030 
0031     mListWidget->setObjectName(QLatin1StringView("listwidget"));
0032     mainLayout->addWidget(mListWidget);
0033 
0034     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0035     buttonBox->setObjectName(QLatin1StringView("buttonbox"));
0036     connect(buttonBox, &QDialogButtonBox::accepted, this, &CheckAttachmentDialog::accept);
0037     connect(buttonBox, &QDialogButtonBox::rejected, this, &CheckAttachmentDialog::reject);
0038     mainLayout->addWidget(buttonBox);
0039     readConfig();
0040 }
0041 
0042 CheckAttachmentDialog::~CheckAttachmentDialog()
0043 {
0044     writeConfig();
0045 }
0046 
0047 void CheckAttachmentDialog::setEmails(const QStringList &emails)
0048 {
0049     mListWidget->clear();
0050     mListWidget->addItems(emails);
0051 }
0052 
0053 void CheckAttachmentDialog::writeConfig()
0054 {
0055     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigCheckAttachmentDialog));
0056     KWindowConfig::saveWindowSize(windowHandle(), group);
0057 }
0058 
0059 void CheckAttachmentDialog::readConfig()
0060 {
0061     create(); // ensure a window is created
0062     windowHandle()->resize(QSize(500, 300));
0063     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigCheckAttachmentDialog));
0064     KWindowConfig::restoreWindowSize(windowHandle(), group);
0065     resize(windowHandle()->size()); // workaround for QTBUG-40584
0066 }
0067 
0068 #include "moc_checkattachmentdialog.cpp"