7#include "convertsnippetvariablesjob.h"
8#include "composer/composerviewinterface.h"
9#include "snippet/convertsnippetvariablesutil.h"
10#include <KEmailAddress>
13#include <TemplateParser/TemplatesUtil>
15ConvertSnippetVariablesJob::ConvertSnippetVariablesJob(
QObject *parent)
20ConvertSnippetVariablesJob::~ConvertSnippetVariablesJob()
22 delete mComposerViewInterface;
25void ConvertSnippetVariablesJob::setText(
const QString &str)
30bool ConvertSnippetVariablesJob::canStart()
const
32 if (mText.
isEmpty() || !mComposerViewInterface) {
38void ConvertSnippetVariablesJob::start()
45 Q_EMIT textConverted(convertVariables(mComposerViewInterface, mText));
49QString ConvertSnippetVariablesJob::text()
const
56 return mComposerViewInterface;
61 mComposerViewInterface = composerViewInterface;
68 i += strlen(
"LASTYEAR");
69 result.
append(MessageComposer::ConvertSnippetVariablesUtil::lastYear());
71 i += strlen(
"NEXTYEAR");
72 result.
append(MessageComposer::ConvertSnippetVariablesUtil::nextYear());
74 i += strlen(
"MONTHNUMBER");
75 result.
append(MessageComposer::ConvertSnippetVariablesUtil::monthNumber());
77 i += strlen(
"DAYOFMONTH");
78 result.
append(MessageComposer::ConvertSnippetVariablesUtil::dayOfMonth());
80 i += strlen(
"WEEKNUMBER");
81 result.
append(MessageComposer::ConvertSnippetVariablesUtil::weekNumber());
83 i += strlen(
"MONTHNAMESHORT");
84 result.
append(MessageComposer::ConvertSnippetVariablesUtil::monthNameShort());
86 i += strlen(
"MONTHNAMELONG");
87 result.
append(MessageComposer::ConvertSnippetVariablesUtil::monthNameLong());
89 i += strlen(
"DAYOFWEEKNAMESHORT");
90 result.
append(MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameShort());
92 i += strlen(
"DAYOFWEEKNAMELONG");
93 result.
append(MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameLong());
95 i += strlen(
"YEARLASTMONTH");
96 result.
append(MessageComposer::ConvertSnippetVariablesUtil::yearLastMonth());
99 result.
append(MessageComposer::ConvertSnippetVariablesUtil::year());
101 i += strlen(
"DAYOFWEEK");
102 result.
append(MessageComposer::ConvertSnippetVariablesUtil::dayOfWeek());
104 i += strlen(
"LASTMONTHNAMELONG");
105 result.
append(MessageComposer::ConvertSnippetVariablesUtil::lastMonthNameLong());
115 const int tmpl_len = text.length();
116 for (
int i = 0; i < tmpl_len; ++i) {
117 const QChar c = text[i];
119 const QString cmd = text.mid(i + 1);
122 i += strlen(
"CCADDR");
123 const QString str = composerView->cc();
126 i += strlen(
"CCFNAME");
127 const QString str = getFirstNameFromEmail(composerView->cc());
130 i += strlen(
"CCLNAME");
131 const QString str = getLastNameFromEmail(composerView->cc());
134 i += strlen(
"CCNAME");
135 const QString str = getNameFromEmail(composerView->cc());
138 i += strlen(
"BCCADDR");
139 const QString str = composerView->bcc();
142 i += strlen(
"BCCFNAME");
143 const QString str = getFirstNameFromEmail(composerView->bcc());
146 i += strlen(
"BCCLNAME");
147 const QString str = getLastNameFromEmail(composerView->bcc());
150 i += strlen(
"BCCNAME");
151 const QString str = getNameFromEmail(composerView->bcc());
154 i += strlen(
"FULLSUBJECT");
155 const QString str = composerView->subject();
158 i += strlen(
"TOADDR");
159 const QString str = composerView->to();
162 i += strlen(
"TOFNAME");
163 const QString str = getFirstNameFromEmail(composerView->to());
166 i += strlen(
"TOLNAME");
167 const QString str = getLastNameFromEmail(composerView->to());
170 i += strlen(
"TONAME");
171 const QString str = getNameFromEmail(composerView->to());
174 i += strlen(
"FROMADDR");
175 const QString str = composerView->from();
178 i += strlen(
"FROMFNAME");
179 const QString str = getFirstNameFromEmail(composerView->from());
182 i += strlen(
"FROMLNAME");
183 const QString str = getLastNameFromEmail(composerView->from());
186 i += strlen(
"FROMNAME");
187 const QString str = getNameFromEmail(composerView->from());
191 const QString str = composerView->insertDayOfWeek();
195 const QString str = composerView->longDate();
198 i += strlen(
"SHORTDATE");
199 const QString str = composerView->shortDate();
203 const QString str = composerView->shortTime();
206 i += strlen(
"TIMELONG");
207 const QString str = composerView->longTime();
210 i += strlen(
"ATTACHMENTCOUNT");
214 i += strlen(
"ATTACHMENTNAMES");
218 i += strlen(
"ATTACHMENTFILENAMES");
222 i += strlen(
"ATTACHMENTNAMESANDSIZES");
226 result.
append(convertVariables(cmd, i, c));
229 result.
append(convertVariables(cmd, i, c));
238QString ConvertSnippetVariablesJob::getNameFromEmail(
const QString &address)
242 for (
const QString &str : lst) {
247 resultName << firstName;
255QString ConvertSnippetVariablesJob::getFirstNameFromEmail(
const QString &address)
259 for (
const QString &str : lst) {
262 const QString firstName = TemplateParser::Util::getFirstNameFromEmail(mailBoxAddress.
name());
264 resultName << firstName;
272QString ConvertSnippetVariablesJob::getLastNameFromEmail(
const QString &address)
276 for (
const QString &str : lst) {
279 qDebug() <<
"newAddress.name() " << newAddress.
name();
280 const QString lastName = TemplateParser::Util::getLastNameFromEmail(newAddress.
name());
282 resultName << lastName;
290#include "moc_convertsnippetvariablesjob.cpp"
void fromUnicodeString(QStringView s)
The ComposerViewInterface class.
KCODECS_EXPORT QString normalizeAddressesAndEncodeIdn(const QString &str)
KCODECS_EXPORT QStringList splitAddressList(const QString &aStr)
PostalAddress address(const QVariant &location)
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
bool isEmpty() const const
QString & append(QChar ch)
bool isEmpty() const const
QString number(double n, char format, int precision)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QString join(QChar separator) const const