Mailcommon

snippetselectattachmentdialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2022 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 <QDialogButtonBox>
13 #include <QPushButton>
14 #include <QVBoxLayout>
15 namespace
16 {
17 static const char mySnippetSelectAttachmentDialogGroupName[] = "SnippetSelectAttachmentDialog";
18 }
19 using namespace MailCommon;
20 SnippetSelectAttachmentDialog::SnippetSelectAttachmentDialog(QWidget *parent)
21  : QDialog(parent)
22  , mAttachmentWidget(new SnippetSelectAttachmentWidget(this))
23 {
24  setWindowTitle(i18nc("@title:window", "Select Attachments"));
25  auto mainLayout = new QVBoxLayout(this);
26  mainLayout->setObjectName(QStringLiteral("mainLayout"));
27 
28  mAttachmentWidget->setObjectName(QStringLiteral("attachmentwidget"));
29  mainLayout->addWidget(mAttachmentWidget);
30 
32  buttonBox->setObjectName(QStringLiteral("button"));
33  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
34  okButton->setDefault(true);
35  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
36  connect(buttonBox, &QDialogButtonBox::accepted, this, &SnippetSelectAttachmentDialog::accept);
37  connect(buttonBox, &QDialogButtonBox::rejected, this, &SnippetSelectAttachmentDialog::reject);
38 
39  mainLayout->addWidget(buttonBox);
40 
41  readConfig();
42 }
43 
44 SnippetSelectAttachmentDialog::~SnippetSelectAttachmentDialog()
45 {
46  writeConfig();
47 }
48 
49 void SnippetSelectAttachmentDialog::setAttachments(const QStringList &lst)
50 {
51  mAttachmentWidget->setAttachments(lst);
52 }
53 
54 QStringList SnippetSelectAttachmentDialog::attachments() const
55 {
56  return mAttachmentWidget->attachments();
57 }
58 
59 void SnippetSelectAttachmentDialog::writeConfig()
60 {
61  KConfigGroup group(KSharedConfig::openStateConfig(), mySnippetSelectAttachmentDialogGroupName);
62  group.writeEntry("Size", size());
63 }
64 
65 void SnippetSelectAttachmentDialog::readConfig()
66 {
67  KConfigGroup group(KSharedConfig::openStateConfig(), mySnippetSelectAttachmentDialogGroupName);
68  const QSize sizeDialog = group.readEntry("Size", QSize(300, 350));
69  if (sizeDialog.isValid()) {
70  resize(sizeDialog);
71  }
72 }
bool isValid() const const
void setShortcut(const QKeySequence &key)
void readConfig()
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
Key_Return
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setDefault(bool)
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.