Messagelib

composerviewinterface.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "composerviewinterface.h"
8 #include "composerviewbase.h"
9 #include "snippet/convertsnippetvariablesutil.h"
10 #include <KFormat>
11 #include <MessageComposer/AttachmentModel>
12 using namespace MessageComposer;
13 ComposerViewInterface::ComposerViewInterface(ComposerViewBase *composerView)
14  : mComposerView(composerView)
15 {
16 }
17 
18 ComposerViewInterface::~ComposerViewInterface() = default;
19 
20 QString ComposerViewInterface::subject() const
21 {
22  if (mComposerView) {
23  return mComposerView->subject();
24  }
25  return {};
26 }
27 
28 QString ComposerViewInterface::to() const
29 {
30  if (mComposerView) {
31  return mComposerView->to();
32  }
33  return {};
34 }
35 
36 QString ComposerViewInterface::cc() const
37 {
38  if (mComposerView) {
39  return mComposerView->cc();
40  }
41  return {};
42 }
43 
44 QString ComposerViewInterface::bcc() const
45 {
46  if (mComposerView) {
47  return mComposerView->bcc();
48  }
49  return {};
50 }
51 
52 QString ComposerViewInterface::from() const
53 {
54  if (mComposerView) {
55  return mComposerView->from();
56  }
57  return {};
58 }
59 
60 QString ComposerViewInterface::replyTo() const
61 {
62  if (mComposerView) {
63  return mComposerView->replyTo();
64  }
65  return {};
66 }
67 
68 MessageComposer::ComposerAttachmentInterface ComposerViewInterface::attachments() const
69 {
71  if (mComposerView) {
72  const int countElement = mComposerView->attachmentModel()->attachments().count();
73  attachmentInterface.setCount(countElement);
74  QStringList fileNames;
75  QStringList nameAndSize;
76  QStringList names;
77 
78  fileNames.reserve(countElement);
79  nameAndSize.reserve(countElement);
80  names.reserve(countElement);
81  const auto attachments = mComposerView->attachmentModel()->attachments();
82  for (const MessageCore::AttachmentPart::Ptr &attachment : attachments) {
83  fileNames.append(attachment->fileName());
84  names.append(attachment->name());
85  nameAndSize.append(QStringLiteral("%1 (%2)").arg(attachment->name(), KFormat().formatByteSize(attachment->size())));
86  }
87  attachmentInterface.setNames(names);
88  attachmentInterface.setNamesAndSize(nameAndSize);
89  attachmentInterface.setFileNames(fileNames);
90  }
91  return attachmentInterface;
92 }
93 
94 QString ComposerViewInterface::shortDate() const
95 {
96  return MessageComposer::ConvertSnippetVariablesUtil::shortDate();
97 }
98 
99 QString ComposerViewInterface::longDate() const
100 {
101  return MessageComposer::ConvertSnippetVariablesUtil::longDate();
102 }
103 
104 QString ComposerViewInterface::shortTime() const
105 {
106  return MessageComposer::ConvertSnippetVariablesUtil::shortTime();
107 }
108 
109 QString ComposerViewInterface::longTime() const
110 {
111  return MessageComposer::ConvertSnippetVariablesUtil::longTime();
112 }
113 
114 QString ComposerViewInterface::insertDayOfWeek() const
115 {
116  return MessageComposer::ConvertSnippetVariablesUtil::insertDayOfWeek();
117 }
void reserve(int alloc)
The ComposerAttachmentInterface class.
void append(const T &value)
The ComposerViewBase class.
QString formatByteSize(double size, int precision=1, KFormat::BinaryUnitDialect dialect=KFormat::DefaultBinaryDialect, KFormat::BinarySizeUnits units=KFormat::DefaultBinaryUnits) const
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Dec 4 2021 23:12:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.