Mailcommon

snippetselectattachmentwidget.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 "snippetselectattachmentwidget.h"
8#include "snippetcustomfileattachmentnamedialog.h"
9#include <KLocalizedString>
10#include <QFileDialog>
11#include <QPointer>
12#include <QVBoxLayout>
13
14using namespace MailCommon;
15SnippetSelectAttachmentWidget::SnippetSelectAttachmentWidget(QWidget *parent)
16 : QWidget(parent)
17 , mEditor(new SnippetSelectorWidget(this))
18{
19 auto mainLayout = new QVBoxLayout(this);
20 mainLayout->setObjectName(QLatin1StringView("mainLayout"));
21 mainLayout->setContentsMargins({});
22
23 mEditor->setObjectName(QLatin1StringView("editor"));
24 mainLayout->addWidget(mEditor);
25}
26
27SnippetSelectAttachmentWidget::~SnippetSelectAttachmentWidget() = default;
28
29void SnippetSelectAttachmentWidget::setAttachments(const QStringList &lst)
30{
31 mEditor->setStringList(lst);
32}
33
34QStringList SnippetSelectAttachmentWidget::attachments() const
35{
36 return mEditor->stringList();
37}
38
39SnippetSelectorWidget::SnippetSelectorWidget(QWidget *parent)
40 : PimCommon::SimpleStringListEditor(parent,
41 static_cast<PimCommon::SimpleStringListEditor::ButtonCode>(PimCommon::SimpleStringListEditor::Add
42 | PimCommon::SimpleStringListEditor::Remove
43 | PimCommon::SimpleStringListEditor::Custom))
44{
45 setRemoveDialogLabel(i18n("Do you want to delete selected attachment?"));
46}
47
48SnippetSelectorWidget::~SnippetSelectorWidget() = default;
49
50void SnippetSelectorWidget::addNewEntry()
51{
52 const QStringList lst = QFileDialog::getOpenFileNames(this, i18nc("@title:window", "Select Attachments"));
53 if (!lst.isEmpty()) {
55 }
56}
57
58QString SnippetSelectorWidget::customEntry(const QString &text)
59{
60 QPointer<SnippetCustomFileAttachmentNameDialog> dlg = new SnippetCustomFileAttachmentNameDialog(this);
61 dlg->setText(text);
62 QString result;
63 if (dlg->exec()) {
64 result = dlg->result();
65 }
66 delete dlg;
67 return result;
68}
69
70#include "moc_snippetselectattachmentwidget.cpp"
void setStringList(const QStringList &strings)
void appendStringList(const QStringList &strings)
QStringList stringList() const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
The filter dialog.
QStringList getOpenFileNames(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.