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(
"DAYNUMBER");
78 result.
append(MessageComposer::ConvertSnippetVariablesUtil::dayNumber());
80 i += strlen(
"CUSTOMDATE");
81 result.
append(MessageComposer::ConvertSnippetVariablesUtil::customDate());
83 i += strlen(
"DAYOFMONTH");
84 result.
append(MessageComposer::ConvertSnippetVariablesUtil::dayOfMonth());
86 i += strlen(
"WEEKNUMBER");
87 result.
append(MessageComposer::ConvertSnippetVariablesUtil::weekNumber());
89 i += strlen(
"MONTHNAMESHORT");
90 result.
append(MessageComposer::ConvertSnippetVariablesUtil::monthNameShort());
92 i += strlen(
"MONTHNAMELONG");
93 result.
append(MessageComposer::ConvertSnippetVariablesUtil::monthNameLong());
95 i += strlen(
"DAYOFWEEKNAMESHORT");
96 result.
append(MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameShort());
98 i += strlen(
"DAYOFWEEKNAMELONG");
99 result.
append(MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameLong());
101 i += strlen(
"YEARLASTMONTH");
102 result.
append(MessageComposer::ConvertSnippetVariablesUtil::yearLastMonth());
105 result.
append(MessageComposer::ConvertSnippetVariablesUtil::year());
107 i += strlen(
"DAYOFWEEK");
108 result.
append(MessageComposer::ConvertSnippetVariablesUtil::dayOfWeek());
110 i += strlen(
"LASTMONTHNAMELONG");
111 result.
append(MessageComposer::ConvertSnippetVariablesUtil::lastMonthNameLong());
121 const int tmpl_len = text.length();
122 for (
int i = 0; i < tmpl_len; ++i) {
123 const QChar c = text[i];
125 const QString cmd = text.mid(i + 1);
128 i += strlen(
"CCADDR");
129 const QString str = composerView->cc();
132 i += strlen(
"CCFNAME");
133 const QString str = getFirstNameFromEmail(composerView->cc());
136 i += strlen(
"CCLNAME");
137 const QString str = getLastNameFromEmail(composerView->cc());
140 i += strlen(
"CCNAME");
141 const QString str = getNameFromEmail(composerView->cc());
144 i += strlen(
"BCCADDR");
145 const QString str = composerView->bcc();
148 i += strlen(
"BCCFNAME");
149 const QString str = getFirstNameFromEmail(composerView->bcc());
152 i += strlen(
"BCCLNAME");
153 const QString str = getLastNameFromEmail(composerView->bcc());
156 i += strlen(
"BCCNAME");
157 const QString str = getNameFromEmail(composerView->bcc());
160 i += strlen(
"FULLSUBJECT");
161 const QString str = composerView->subject();
164 i += strlen(
"TOADDR");
165 const QString str = composerView->to();
168 i += strlen(
"TOFNAME");
169 const QString str = getFirstNameFromEmail(composerView->to());
172 i += strlen(
"TOLNAME");
173 const QString str = getLastNameFromEmail(composerView->to());
176 i += strlen(
"TONAME");
177 const QString str = getNameFromEmail(composerView->to());
180 i += strlen(
"FROMADDR");
181 const QString str = composerView->from();
184 i += strlen(
"FROMFNAME");
185 const QString str = getFirstNameFromEmail(composerView->from());
188 i += strlen(
"FROMLNAME");
189 const QString str = getLastNameFromEmail(composerView->from());
192 i += strlen(
"FROMNAME");
193 const QString str = getNameFromEmail(composerView->from());
197 const QString str = composerView->insertDayOfWeek();
201 const QString str = composerView->longDate();
204 i += strlen(
"SHORTDATE");
205 const QString str = composerView->shortDate();
209 const QString str = composerView->shortTime();
212 i += strlen(
"TIMELONG");
213 const QString str = composerView->longTime();
216 i += strlen(
"ATTACHMENTCOUNT");
220 i += strlen(
"ATTACHMENTNAMES");
224 i += strlen(
"ATTACHMENTFILENAMES");
228 i += strlen(
"ATTACHMENTNAMESANDSIZES");
232 result.
append(convertVariables(cmd, i, c));
235 result.
append(convertVariables(cmd, i, c));
244QString ConvertSnippetVariablesJob::getNameFromEmail(
const QString &address)
248 for (
const QString &str : lst) {
253 resultName << firstName;
261QString ConvertSnippetVariablesJob::getFirstNameFromEmail(
const QString &address)
265 for (
const QString &str : lst) {
268 const QString firstName = TemplateParser::Util::getFirstNameFromEmail(mailBoxAddress.
name());
270 resultName << firstName;
278QString ConvertSnippetVariablesJob::getLastNameFromEmail(
const QString &address)
282 for (
const QString &str : lst) {
286 const QString lastName = TemplateParser::Util::getLastNameFromEmail(newAddress.
name());
288 resultName << lastName;
296#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