Warning, file /pim/mailcommon/src/snippets/snippetselectattachmentdialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "snippetselectattachmentdialog.h" 0008 #include "snippetselectattachmentwidget.h" 0009 #include <KConfigGroup> 0010 #include <KLocalizedString> 0011 #include <KSharedConfig> 0012 #include <KWindowConfig> 0013 #include <QDialogButtonBox> 0014 #include <QPushButton> 0015 #include <QVBoxLayout> 0016 #include <QWindow> 0017 namespace 0018 { 0019 static const char mySnippetSelectAttachmentDialogGroupName[] = "SnippetSelectAttachmentDialog"; 0020 } 0021 using namespace MailCommon; 0022 SnippetSelectAttachmentDialog::SnippetSelectAttachmentDialog(QWidget *parent) 0023 : QDialog(parent) 0024 , mAttachmentWidget(new SnippetSelectAttachmentWidget(this)) 0025 { 0026 setWindowTitle(i18nc("@title:window", "Select Attachments")); 0027 auto mainLayout = new QVBoxLayout(this); 0028 mainLayout->setObjectName(QLatin1StringView("mainLayout")); 0029 0030 mAttachmentWidget->setObjectName(QLatin1StringView("attachmentwidget")); 0031 mainLayout->addWidget(mAttachmentWidget); 0032 0033 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0034 buttonBox->setObjectName(QLatin1StringView("button")); 0035 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0036 okButton->setDefault(true); 0037 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0038 connect(buttonBox, &QDialogButtonBox::accepted, this, &SnippetSelectAttachmentDialog::accept); 0039 connect(buttonBox, &QDialogButtonBox::rejected, this, &SnippetSelectAttachmentDialog::reject); 0040 0041 mainLayout->addWidget(buttonBox); 0042 0043 readConfig(); 0044 } 0045 0046 SnippetSelectAttachmentDialog::~SnippetSelectAttachmentDialog() 0047 { 0048 writeConfig(); 0049 } 0050 0051 void SnippetSelectAttachmentDialog::setAttachments(const QStringList &lst) 0052 { 0053 mAttachmentWidget->setAttachments(lst); 0054 } 0055 0056 QStringList SnippetSelectAttachmentDialog::attachments() const 0057 { 0058 return mAttachmentWidget->attachments(); 0059 } 0060 0061 void SnippetSelectAttachmentDialog::readConfig() 0062 { 0063 create(); // ensure a window is created 0064 windowHandle()->resize(QSize(300, 350)); 0065 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySnippetSelectAttachmentDialogGroupName)); 0066 KWindowConfig::restoreWindowSize(windowHandle(), group); 0067 resize(windowHandle()->size()); // workaround for QTBUG-40584 0068 } 0069 0070 void SnippetSelectAttachmentDialog::writeConfig() 0071 { 0072 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySnippetSelectAttachmentDialogGroupName)); 0073 KWindowConfig::saveWindowSize(windowHandle(), group); 0074 group.sync(); 0075 } 0076 0077 #include "moc_snippetselectattachmentdialog.cpp"