File indexing completed on 2024-06-23 05:18:27

0001 /*
0002    SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "composerviewinterface.h"
0008 #include "composerviewbase.h"
0009 #include "snippet/convertsnippetvariablesutil.h"
0010 #include <KIO/Global>
0011 #include <MessageComposer/AttachmentModel>
0012 using namespace MessageComposer;
0013 ComposerViewInterface::ComposerViewInterface(ComposerViewBase *composerView)
0014     : mComposerView(composerView)
0015 {
0016 }
0017 
0018 ComposerViewInterface::~ComposerViewInterface() = default;
0019 
0020 QString ComposerViewInterface::subject() const
0021 {
0022     if (mComposerView) {
0023         return mComposerView->subject();
0024     }
0025     return {};
0026 }
0027 
0028 QString ComposerViewInterface::to() const
0029 {
0030     if (mComposerView) {
0031         return mComposerView->to();
0032     }
0033     return {};
0034 }
0035 
0036 QString ComposerViewInterface::cc() const
0037 {
0038     if (mComposerView) {
0039         return mComposerView->cc();
0040     }
0041     return {};
0042 }
0043 
0044 QString ComposerViewInterface::bcc() const
0045 {
0046     if (mComposerView) {
0047         return mComposerView->bcc();
0048     }
0049     return {};
0050 }
0051 
0052 QString ComposerViewInterface::from() const
0053 {
0054     if (mComposerView) {
0055         return mComposerView->from();
0056     }
0057     return {};
0058 }
0059 
0060 QString ComposerViewInterface::replyTo() const
0061 {
0062     if (mComposerView) {
0063         return mComposerView->replyTo();
0064     }
0065     return {};
0066 }
0067 
0068 MessageComposer::ComposerAttachmentInterface ComposerViewInterface::attachments() const
0069 {
0070     MessageComposer::ComposerAttachmentInterface attachmentInterface;
0071     if (mComposerView) {
0072         const int countElement = mComposerView->attachmentModel()->attachments().count();
0073         attachmentInterface.setCount(countElement);
0074         QStringList fileNames;
0075         QStringList nameAndSize;
0076         QStringList names;
0077 
0078         fileNames.reserve(countElement);
0079         nameAndSize.reserve(countElement);
0080         names.reserve(countElement);
0081         const auto attachments = mComposerView->attachmentModel()->attachments();
0082         for (const MessageCore::AttachmentPart::Ptr &attachment : attachments) {
0083             fileNames.append(attachment->fileName());
0084             names.append(attachment->name());
0085             nameAndSize.append(QStringLiteral("%1 (%2)").arg(attachment->name(), KIO::convertSize(attachment->size())));
0086         }
0087         attachmentInterface.setNames(names);
0088         attachmentInterface.setNamesAndSize(nameAndSize);
0089         attachmentInterface.setFileNames(fileNames);
0090     }
0091     return attachmentInterface;
0092 }
0093 
0094 QString ComposerViewInterface::shortDate() const
0095 {
0096     return MessageComposer::ConvertSnippetVariablesUtil::shortDate();
0097 }
0098 
0099 QString ComposerViewInterface::longDate() const
0100 {
0101     return MessageComposer::ConvertSnippetVariablesUtil::longDate();
0102 }
0103 
0104 QString ComposerViewInterface::shortTime() const
0105 {
0106     return MessageComposer::ConvertSnippetVariablesUtil::shortTime();
0107 }
0108 
0109 QString ComposerViewInterface::longTime() const
0110 {
0111     return MessageComposer::ConvertSnippetVariablesUtil::longTime();
0112 }
0113 
0114 QString ComposerViewInterface::insertDayOfWeek() const
0115 {
0116     return MessageComposer::ConvertSnippetVariablesUtil::insertDayOfWeek();
0117 }