Warning, file /pim/mailcommon/src/snippets/snippetattachmentwidget.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 "snippetattachmentwidget.h"
0008 #include "snippetselectattachmentdialog.h"
0009 #include <KLocalizedString>
0010 #include <QHBoxLayout>
0011 #include <QLineEdit>
0012 #include <QPointer>
0013 #include <QToolButton>
0014 
0015 using namespace MailCommon;
0016 
0017 SnippetAttachmentWidget::SnippetAttachmentWidget(QWidget *parent)
0018     : QWidget(parent)
0019     , mLineEdit(new QLineEdit(this))
0020 {
0021     auto layout = new QHBoxLayout(this);
0022     layout->setObjectName(QLatin1StringView("layout"));
0023     layout->setContentsMargins({});
0024 
0025     mLineEdit->setObjectName(QLatin1StringView("lineedit"));
0026     mLineEdit->setPlaceholderText(i18n("Click on button for selecting attachment file"));
0027     layout->addWidget(mLineEdit);
0028     mLineEdit->setReadOnly(true);
0029 
0030     auto button = new QToolButton(this);
0031     button->setObjectName(QLatin1StringView("button"));
0032     button->setToolTip(i18n("Select Attachments"));
0033     button->setText(i18n("..."));
0034     layout->addWidget(button);
0035     connect(button, &QToolButton::clicked, this, &SnippetAttachmentWidget::slotSelectAttachment);
0036 }
0037 
0038 SnippetAttachmentWidget::~SnippetAttachmentWidget() = default;
0039 
0040 void SnippetAttachmentWidget::setText(const QString &str)
0041 {
0042     mLineEdit->setText(str);
0043 }
0044 
0045 QString SnippetAttachmentWidget::text() const
0046 {
0047     return mLineEdit->text();
0048 }
0049 
0050 void SnippetAttachmentWidget::clear()
0051 {
0052     mLineEdit->clear();
0053 }
0054 
0055 void SnippetAttachmentWidget::slotSelectAttachment()
0056 {
0057     QPointer<MailCommon::SnippetSelectAttachmentDialog> dlg = new MailCommon::SnippetSelectAttachmentDialog(this);
0058     dlg->setAttachments(mLineEdit->text().split(QLatin1Char(','), Qt::SkipEmptyParts));
0059     if (dlg->exec()) {
0060         mLineEdit->setText(dlg->attachments().join(QLatin1Char(',')));
0061         Q_EMIT wasChanged();
0062     }
0063     delete dlg;
0064 }
0065 
0066 #include "moc_snippetattachmentwidget.cpp"