Mailcommon

snippetselectattachmentwidget.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 "snippetselectattachmentwidget.h"
8 #include "snippetcustomfileattachmentnamedialog.h"
9 #include <KLocalizedString>
10 #include <QFileDialog>
11 #include <QPointer>
12 #include <QVBoxLayout>
13 
14 using namespace MailCommon;
15 SnippetSelectAttachmentWidget::SnippetSelectAttachmentWidget(QWidget *parent)
16  : QWidget(parent)
17  , mEditor(new SnippetSelectorWidget(this))
18 {
19  auto mainLayout = new QVBoxLayout(this);
20  mainLayout->setObjectName(QStringLiteral("mainLayout"));
21  mainLayout->setContentsMargins({});
22 
23  mEditor->setObjectName(QStringLiteral("editor"));
24  mainLayout->addWidget(mEditor);
25 }
26 
27 SnippetSelectAttachmentWidget::~SnippetSelectAttachmentWidget() = default;
28 
29 void SnippetSelectAttachmentWidget::setAttachments(const QStringList &lst)
30 {
31  mEditor->setStringList(lst);
32 }
33 
34 QStringList SnippetSelectAttachmentWidget::attachments() const
35 {
36  return mEditor->stringList();
37 }
38 
39 SnippetSelectorWidget::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 
48 SnippetSelectorWidget::~SnippetSelectorWidget() = default;
49 
50 void SnippetSelectorWidget::addNewEntry()
51 {
52  const QStringList lst = QFileDialog::getOpenFileNames(this, i18n("Select Attachments"));
53  if (!lst.isEmpty()) {
54  appendStringList(lst);
55  }
56 }
57 
58 QString 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 }
QStringList getOpenFileNames(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
QString i18n(const char *text, const TYPE &arg...)
bool isEmpty() const const
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Oct 1 2022 04:00:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.