Warning, file /pim/mailcommon/src/snippets/snippetselectattachmentwidget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "snippetselectattachmentwidget.h" 0008 #include "snippetcustomfileattachmentnamedialog.h" 0009 #include <KLocalizedString> 0010 #include <QFileDialog> 0011 #include <QPointer> 0012 #include <QVBoxLayout> 0013 0014 using namespace MailCommon; 0015 SnippetSelectAttachmentWidget::SnippetSelectAttachmentWidget(QWidget *parent) 0016 : QWidget(parent) 0017 , mEditor(new SnippetSelectorWidget(this)) 0018 { 0019 auto mainLayout = new QVBoxLayout(this); 0020 mainLayout->setObjectName(QLatin1StringView("mainLayout")); 0021 mainLayout->setContentsMargins({}); 0022 0023 mEditor->setObjectName(QLatin1StringView("editor")); 0024 mainLayout->addWidget(mEditor); 0025 } 0026 0027 SnippetSelectAttachmentWidget::~SnippetSelectAttachmentWidget() = default; 0028 0029 void SnippetSelectAttachmentWidget::setAttachments(const QStringList &lst) 0030 { 0031 mEditor->setStringList(lst); 0032 } 0033 0034 QStringList SnippetSelectAttachmentWidget::attachments() const 0035 { 0036 return mEditor->stringList(); 0037 } 0038 0039 SnippetSelectorWidget::SnippetSelectorWidget(QWidget *parent) 0040 : PimCommon::SimpleStringListEditor(parent, 0041 static_cast<PimCommon::SimpleStringListEditor::ButtonCode>(PimCommon::SimpleStringListEditor::Add 0042 | PimCommon::SimpleStringListEditor::Remove 0043 | PimCommon::SimpleStringListEditor::Custom)) 0044 { 0045 setRemoveDialogLabel(i18n("Do you want to delete selected attachment?")); 0046 } 0047 0048 SnippetSelectorWidget::~SnippetSelectorWidget() = default; 0049 0050 void SnippetSelectorWidget::addNewEntry() 0051 { 0052 const QStringList lst = QFileDialog::getOpenFileNames(this, i18n("Select Attachments")); 0053 if (!lst.isEmpty()) { 0054 appendStringList(lst); 0055 } 0056 } 0057 0058 QString SnippetSelectorWidget::customEntry(const QString &text) 0059 { 0060 QPointer<SnippetCustomFileAttachmentNameDialog> dlg = new SnippetCustomFileAttachmentNameDialog(this); 0061 dlg->setText(text); 0062 QString result; 0063 if (dlg->exec()) { 0064 result = dlg->result(); 0065 } 0066 delete dlg; 0067 return result; 0068 } 0069 0070 #include "moc_snippetselectattachmentwidget.cpp"