Mailcommon

snippetselectattachmentdialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2023 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 #include "snippetselectattachmentdialog.h"
8 #include "snippetselectattachmentwidget.h"
9 #include <KConfigGroup>
10 #include <KLocalizedString>
11 #include <KSharedConfig>
12 #include <KWindowConfig>
13 #include <QDialogButtonBox>
14 #include <QPushButton>
15 #include <QVBoxLayout>
16 #include <QWindow>
17 namespace
18 {
19 static const char mySnippetSelectAttachmentDialogGroupName[] = "SnippetSelectAttachmentDialog";
20 }
21 using namespace MailCommon;
22 SnippetSelectAttachmentDialog::SnippetSelectAttachmentDialog(QWidget *parent)
23  : QDialog(parent)
24  , mAttachmentWidget(new SnippetSelectAttachmentWidget(this))
25 {
26  setWindowTitle(i18nc("@title:window", "Select Attachments"));
27  auto mainLayout = new QVBoxLayout(this);
28  mainLayout->setObjectName(QStringLiteral("mainLayout"));
29 
30  mAttachmentWidget->setObjectName(QStringLiteral("attachmentwidget"));
31  mainLayout->addWidget(mAttachmentWidget);
32 
34  buttonBox->setObjectName(QStringLiteral("button"));
35  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
36  okButton->setDefault(true);
37  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
38  connect(buttonBox, &QDialogButtonBox::accepted, this, &SnippetSelectAttachmentDialog::accept);
39  connect(buttonBox, &QDialogButtonBox::rejected, this, &SnippetSelectAttachmentDialog::reject);
40 
41  mainLayout->addWidget(buttonBox);
42 
43  readConfig();
44 }
45 
46 SnippetSelectAttachmentDialog::~SnippetSelectAttachmentDialog()
47 {
48  writeConfig();
49 }
50 
51 void SnippetSelectAttachmentDialog::setAttachments(const QStringList &lst)
52 {
53  mAttachmentWidget->setAttachments(lst);
54 }
55 
56 QStringList SnippetSelectAttachmentDialog::attachments() const
57 {
58  return mAttachmentWidget->attachments();
59 }
60 
61 void SnippetSelectAttachmentDialog::readConfig()
62 {
63  create(); // ensure a window is created
64  windowHandle()->resize(QSize(300, 350));
65  KConfigGroup group(KSharedConfig::openStateConfig(), mySnippetSelectAttachmentDialogGroupName);
66  KWindowConfig::restoreWindowSize(windowHandle(), group);
67  resize(windowHandle()->size()); // workaround for QTBUG-40584
68 }
69 
70 void SnippetSelectAttachmentDialog::writeConfig()
71 {
72  KConfigGroup group(KSharedConfig::openStateConfig(), mySnippetSelectAttachmentDialogGroupName);
73  KWindowConfig::saveWindowSize(windowHandle(), group);
74  group.sync();
75 }
76 
77 #include "moc_snippetselectattachmentdialog.cpp"
void setShortcut(const QKeySequence &key)
void readConfig()
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QAction * create(StandardGameAction id, const QObject *recvr, const char *slot, QObject *parent)
Key_Return
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setDefault(bool)
The filter dialog.
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 03:56:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.