Mailcommon

snippetselectattachmentdialog.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
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>
17namespace
18{
19static const char mySnippetSelectAttachmentDialogGroupName[] = "SnippetSelectAttachmentDialog";
20}
21using namespace MailCommon;
22SnippetSelectAttachmentDialog::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(QLatin1StringView("mainLayout"));
29
30 mAttachmentWidget->setObjectName(QLatin1StringView("attachmentwidget"));
31 mainLayout->addWidget(mAttachmentWidget);
32
34 buttonBox->setObjectName(QLatin1StringView("button"));
35 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
36 okButton->setDefault(true);
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
46SnippetSelectAttachmentDialog::~SnippetSelectAttachmentDialog()
47{
48 writeConfig();
49}
50
51void SnippetSelectAttachmentDialog::setAttachments(const QStringList &lst)
52{
53 mAttachmentWidget->setAttachments(lst);
54}
55
56QStringList SnippetSelectAttachmentDialog::attachments() const
57{
58 return mAttachmentWidget->attachments();
59}
60
61void SnippetSelectAttachmentDialog::readConfig()
62{
63 create(); // ensure a window is created
64 windowHandle()->resize(QSize(300, 350));
65 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySnippetSelectAttachmentDialogGroupName));
67 resize(windowHandle()->size()); // workaround for QTBUG-40584
68}
69
70void SnippetSelectAttachmentDialog::writeConfig()
71{
72 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySnippetSelectAttachmentDialogGroupName));
74 group.sync();
75}
76
77#include "moc_snippetselectattachmentdialog.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 Tue Mar 26 2024 11:14:01 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.