Mailcommon

snippetcustomfileattachmentnamedialog.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
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#include <KWindowConfig>
18#include <QWindow>
19namespace
20{
21static const char mySnippetCustomFileAttachmentNameDialogGroupName[] = "SnippetCustomFileAttachmentNameDialog";
22}
23using namespace MailCommon;
24SnippetCustomFileAttachmentNameDialog::SnippetCustomFileAttachmentNameDialog(QWidget *parent)
25 : QDialog(parent)
26 , mCustomWidget(new SnippetCustomFileAttachmentNameWidget(this))
27{
28 setWindowTitle(i18nc("@title:window", "Customize File Name Attachment"));
29 auto mainLayout = new QVBoxLayout(this);
30 mainLayout->setObjectName(QLatin1StringView("mainLayout"));
31
32 mCustomWidget->setObjectName(QLatin1StringView("mCustomWidget"));
33 mainLayout->addWidget(mCustomWidget);
34
36 buttonBox->setObjectName(QLatin1StringView("button"));
37 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
38 okButton->setDefault(true);
40 connect(buttonBox, &QDialogButtonBox::accepted, this, &SnippetCustomFileAttachmentNameDialog::accept);
41 connect(buttonBox, &QDialogButtonBox::rejected, this, &SnippetCustomFileAttachmentNameDialog::reject);
42
43 mainLayout->addWidget(buttonBox);
44
45 readConfig();
46}
47
48SnippetCustomFileAttachmentNameDialog::~SnippetCustomFileAttachmentNameDialog()
49{
50 writeConfig();
51}
52
53void SnippetCustomFileAttachmentNameDialog::readConfig()
54{
55 create(); // ensure a window is created
56 windowHandle()->resize(QSize(500, 150));
57 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySnippetCustomFileAttachmentNameDialogGroupName));
59 resize(windowHandle()->size()); // workaround for QTBUG-40584
60}
61
62void SnippetCustomFileAttachmentNameDialog::writeConfig()
63{
64 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySnippetCustomFileAttachmentNameDialogGroupName));
66 group.sync();
67}
68
69QString SnippetCustomFileAttachmentNameDialog::result() const
70{
71 return mCustomWidget->result();
72}
73
74void SnippetCustomFileAttachmentNameDialog::setText(const QString &str)
75{
76 mCustomWidget->setText(str);
77}
78
79#include "moc_snippetcustomfileattachmentnamedialog.cpp"
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
The filter dialog.
void setShortcut(const QKeySequence &key)
void setDefault(bool)
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void create(WId window, bool initializeWindow, bool destroyOldWindow)
void resize(const QSize &)
QWindow * windowHandle() const const
void resize(const QSize &newSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.