Warning, file /pim/mailcommon/src/snippets/snippetcustomfileattachmentnamedialog.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-or-later
0005 */
0006 
0007 #include "snippetcustomfileattachmentnamedialog.h"
0008 #include "snippetcustomfileattachmentnamewidget.h"
0009 
0010 #include <KConfigGroup>
0011 #include <QDialogButtonBox>
0012 #include <QPushButton>
0013 #include <QVBoxLayout>
0014 
0015 #include <KLocalizedString>
0016 #include <KSharedConfig>
0017 #include <KWindowConfig>
0018 #include <QWindow>
0019 namespace
0020 {
0021 static const char mySnippetCustomFileAttachmentNameDialogGroupName[] = "SnippetCustomFileAttachmentNameDialog";
0022 }
0023 using namespace MailCommon;
0024 SnippetCustomFileAttachmentNameDialog::SnippetCustomFileAttachmentNameDialog(QWidget *parent)
0025     : QDialog(parent)
0026     , mCustomWidget(new SnippetCustomFileAttachmentNameWidget(this))
0027 {
0028     setWindowTitle(i18nc("@title:window", "Customize File Name Attachment"));
0029     auto mainLayout = new QVBoxLayout(this);
0030     mainLayout->setObjectName(QLatin1StringView("mainLayout"));
0031 
0032     mCustomWidget->setObjectName(QLatin1StringView("mCustomWidget"));
0033     mainLayout->addWidget(mCustomWidget);
0034 
0035     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0036     buttonBox->setObjectName(QLatin1StringView("button"));
0037     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0038     okButton->setDefault(true);
0039     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0040     connect(buttonBox, &QDialogButtonBox::accepted, this, &SnippetCustomFileAttachmentNameDialog::accept);
0041     connect(buttonBox, &QDialogButtonBox::rejected, this, &SnippetCustomFileAttachmentNameDialog::reject);
0042 
0043     mainLayout->addWidget(buttonBox);
0044 
0045     readConfig();
0046 }
0047 
0048 SnippetCustomFileAttachmentNameDialog::~SnippetCustomFileAttachmentNameDialog()
0049 {
0050     writeConfig();
0051 }
0052 
0053 void SnippetCustomFileAttachmentNameDialog::readConfig()
0054 {
0055     create(); // ensure a window is created
0056     windowHandle()->resize(QSize(500, 150));
0057     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySnippetCustomFileAttachmentNameDialogGroupName));
0058     KWindowConfig::restoreWindowSize(windowHandle(), group);
0059     resize(windowHandle()->size()); // workaround for QTBUG-40584
0060 }
0061 
0062 void SnippetCustomFileAttachmentNameDialog::writeConfig()
0063 {
0064     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySnippetCustomFileAttachmentNameDialogGroupName));
0065     KWindowConfig::saveWindowSize(windowHandle(), group);
0066     group.sync();
0067 }
0068 
0069 QString SnippetCustomFileAttachmentNameDialog::result() const
0070 {
0071     return mCustomWidget->result();
0072 }
0073 
0074 void SnippetCustomFileAttachmentNameDialog::setText(const QString &str)
0075 {
0076     mCustomWidget->setText(str);
0077 }
0078 
0079 #include "moc_snippetcustomfileattachmentnamedialog.cpp"