File indexing completed on 2024-10-27 04:50:59

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "attachmentaddedfromexternalwarning.h"
0008 
0009 #include <QUrl>
0010 
0011 #include <KLocalizedString>
0012 
0013 AttachmentAddedFromExternalWarning::AttachmentAddedFromExternalWarning(QWidget *parent)
0014     : KMessageWidget(parent)
0015 {
0016     setPosition(KMessageWidget::Header);
0017     setVisible(false);
0018     setCloseButtonVisible(true);
0019     setMessageType(Information);
0020     setWordWrap(true);
0021 }
0022 
0023 AttachmentAddedFromExternalWarning::~AttachmentAddedFromExternalWarning() = default;
0024 
0025 void AttachmentAddedFromExternalWarning::setAttachmentNames(const QStringList &lst)
0026 {
0027     QStringList attachments;
0028 
0029     for (const QString &item : lst) {
0030         const QUrl url(item);
0031 
0032         if (url.isLocalFile()) {
0033             attachments << url.toLocalFile();
0034         } else {
0035             attachments << item;
0036         }
0037     }
0038 
0039     if (attachments.count() == 1) {
0040         setText(i18n("This attachment: <ul><li>%1</li></ul> was added externally. Remove it if it's an error.", attachments.at(0)));
0041     } else {
0042         setText(i18n("These attachments: <ul><li>%1</li></ul> were added externally. Remove them if it's an error.",
0043                      attachments.join(QLatin1StringView("</li><li>"))));
0044     }
0045 }
0046 
0047 #include "moc_attachmentaddedfromexternalwarning.cpp"