Mailcommon

snippetcustomfileattachmentnamedialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2022 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "snippetcustomfileattachmentnamedialog.h"
8 #include "snippetcustomfileattachmentnamewidget.h"
9 
10 #include <KConfigGroup>
11 #include <QDialogButtonBox>
12 #include <QPushButton>
13 #include <QVBoxLayout>
14 
15 #include <KLocalizedString>
16 #include <KSharedConfig>
17 namespace
18 {
19 static const char mySnippetCustomFileAttachmentNameDialogGroupName[] = "SnippetCustomFileAttachmentNameDialog";
20 }
21 using namespace MailCommon;
22 SnippetCustomFileAttachmentNameDialog::SnippetCustomFileAttachmentNameDialog(QWidget *parent)
23  : QDialog(parent)
24  , mCustomWidget(new SnippetCustomFileAttachmentNameWidget(this))
25 {
26  setWindowTitle(i18nc("@title:window", "Customize File Name Attachment"));
27  auto mainLayout = new QVBoxLayout(this);
28  mainLayout->setObjectName(QStringLiteral("mainLayout"));
29 
30  mCustomWidget->setObjectName(QStringLiteral("mCustomWidget"));
31  mainLayout->addWidget(mCustomWidget);
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, &SnippetCustomFileAttachmentNameDialog::accept);
39  connect(buttonBox, &QDialogButtonBox::rejected, this, &SnippetCustomFileAttachmentNameDialog::reject);
40 
41  mainLayout->addWidget(buttonBox);
42 
43  readConfig();
44 }
45 
46 SnippetCustomFileAttachmentNameDialog::~SnippetCustomFileAttachmentNameDialog()
47 {
48  writeConfig();
49 }
50 
51 void SnippetCustomFileAttachmentNameDialog::readConfig()
52 {
53  KConfigGroup group(KSharedConfig::openStateConfig(), mySnippetCustomFileAttachmentNameDialogGroupName);
54 
55  const QSize size = group.readEntry("Size", QSize(500, 150));
56  if (size.isValid()) {
57  resize(size);
58  }
59 }
60 
61 void SnippetCustomFileAttachmentNameDialog::writeConfig()
62 {
63  KConfigGroup group(KSharedConfig::openStateConfig(), mySnippetCustomFileAttachmentNameDialogGroupName);
64  group.writeEntry("Size", size());
65 }
66 
67 QString SnippetCustomFileAttachmentNameDialog::result() const
68 {
69  return mCustomWidget->result();
70 }
71 
72 void SnippetCustomFileAttachmentNameDialog::setText(const QString &str)
73 {
74  mCustomWidget->setText(str);
75 }
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.