7#include "templatescommandmenu.h"
9#include "templateparser_debug.h"
11#include <KLazyLocalizedString>
12#include <KLocalizedString>
16using namespace TemplateParser;
20 const TemplatesCommandMenu::Command command;
22 [[nodiscard]]
QString getLocalizedDisplayName()
const
28static const InsertCommand originalCommands[] = {{kli18n(
"Quoted Message Text"), TemplatesCommandMenu::CQuote},
30 {kli18n(
"Message Text as Is"), TemplatesCommandMenu::CText},
32 {kli18n(
"Message Id"), TemplatesCommandMenu::COMsgId},
34 {kli18n(
"Date"), TemplatesCommandMenu::CODate},
36 {kli18n(
"Date in Short Format"), TemplatesCommandMenu::CODateShort},
38 {kli18n(
"Date in C Locale"), TemplatesCommandMenu::CODateEn},
40 {kli18n(
"Day of Week"), TemplatesCommandMenu::CODow},
42 {kli18n(
"Time"), TemplatesCommandMenu::COTime},
44 {kli18n(
"Time in Long Format"), TemplatesCommandMenu::COTimeLong},
46 {kli18n(
"Time in C Locale"), TemplatesCommandMenu::COTimeLongEn},
48 {kli18n(
"To Field Address"), TemplatesCommandMenu::COToAddr},
50 {kli18n(
"To Field Name"), TemplatesCommandMenu::COToName},
52 {kli18n(
"To Field First Name"), TemplatesCommandMenu::COToFName},
54 {kli18n(
"To Field Last Name"), TemplatesCommandMenu::COToLName},
56 {kli18n(
"CC Field Address"), TemplatesCommandMenu::COCCAddr},
58 {kli18n(
"CC Field Name"), TemplatesCommandMenu::COCCName},
60 {kli18n(
"CC Field First Name"), TemplatesCommandMenu::COCCFName},
62 {kli18n(
"CC Field Last Name"), TemplatesCommandMenu::COCCLName},
64 {kli18n(
"From Field Address"), TemplatesCommandMenu::COFromAddr},
66 {kli18n(
"From Field Name"), TemplatesCommandMenu::COFromName},
68 {kli18n(
"From Field First Name"), TemplatesCommandMenu::COFromFName},
70 {kli18n(
"From Field Last Name"), TemplatesCommandMenu::COFromLName},
72 {kli18n(
"Addresses of all recipients"), TemplatesCommandMenu::COAddresseesAddr},
74 {kli18nc(
"Template value for subject of the message",
"Subject"), TemplatesCommandMenu::COFullSubject},
76 {kli18n(
"Quoted Headers"), TemplatesCommandMenu::CQHeaders},
78 {kli18n(
"Headers as Is"), TemplatesCommandMenu::CHeaders},
80 {kli18n(
"Header Content"), TemplatesCommandMenu::COHeader},
82 {kli18n(
"Reply as Quoted Plain Text"), TemplatesCommandMenu::CQuotePlain},
84 {kli18n(
"Reply as Quoted HTML Text"), TemplatesCommandMenu::CQuoteHtml}};
85static const int originalCommandsCount =
sizeof(originalCommands) /
sizeof(*originalCommands);
87static const InsertCommand currentCommands[] = {{kli18n(
"Date"), TemplatesCommandMenu::CDate},
89 {kli18n(
"Date in Short Format"), TemplatesCommandMenu::CDateShort},
91 {kli18n(
"Date in C Locale"), TemplatesCommandMenu::CDateEn},
93 {kli18n(
"Day of Week"), TemplatesCommandMenu::CDow},
95 {kli18n(
"Time"), TemplatesCommandMenu::CTime},
97 {kli18n(
"Time in Long Format"), TemplatesCommandMenu::CTimeLong},
99 {kli18n(
"Time in C Locale"), TemplatesCommandMenu::CTimeLongEn},
100 {kli18n(
"To Field Address"), TemplatesCommandMenu::CToAddr},
102 {kli18n(
"To Field Name"), TemplatesCommandMenu::CToName},
104 {kli18n(
"To Field First Name"), TemplatesCommandMenu::CToFName},
106 {kli18n(
"To Field Last Name"), TemplatesCommandMenu::CToLName},
108 {kli18n(
"CC Field Address"), TemplatesCommandMenu::CCCAddr},
110 {kli18n(
"CC Field Name"), TemplatesCommandMenu::CCCName},
112 {kli18n(
"CC Field First Name"), TemplatesCommandMenu::CCCFName},
114 {kli18n(
"CC Field Last Name"), TemplatesCommandMenu::CCCLName},
116 {kli18n(
"From Field Address"), TemplatesCommandMenu::CFromAddr},
118 {kli18n(
"From field Name"), TemplatesCommandMenu::CFromName},
120 {kli18n(
"From Field First Name"), TemplatesCommandMenu::CFromFName},
122 {kli18n(
"From Field Last Name"), TemplatesCommandMenu::CFromLName},
124 {kli18nc(
"Template subject command.",
"Subject"), TemplatesCommandMenu::CFullSubject},
126 {kli18n(
"Header Content"), TemplatesCommandMenu::CHeader}};
127static const int currentCommandsCount =
sizeof(currentCommands) /
sizeof(*currentCommands);
129static const InsertCommand extCommands[] = {{kli18n(
"Pipe Original Message Body and Insert Result as Quoted Text"), TemplatesCommandMenu::CQuotePipe},
131 {kli18n(
"Pipe Original Message Body and Insert Result as Is"), TemplatesCommandMenu::CTextPipe},
133 {kli18n(
"Pipe Original Message with Headers and Insert Result as Is"), TemplatesCommandMenu::CMsgPipe},
135 {kli18n(
"Pipe Current Message Body and Insert Result as Is"), TemplatesCommandMenu::CBodyPipe},
137 {kli18n(
"Pipe Current Message Body and Replace with Result"), TemplatesCommandMenu::CClearPipe}};
139static const int extCommandsCount =
sizeof(extCommands) /
sizeof(*extCommands);
141static const InsertCommand miscCommands[] = {
142 {kli18nc(
"Inserts user signature, also known as footer, into message",
"Signature"), TemplatesCommandMenu::CSignature},
144 {kli18n(
"Insert File Content"), TemplatesCommandMenu::CInsert},
146 {kli18nc(
"All characters, up to and including the next newline, "
147 "are discarded without performing any macro expansion",
148 "Discard to Next Line"),
149 TemplatesCommandMenu::CDnl},
151 {kli18n(
"Template Comment"), TemplatesCommandMenu::CRem},
153 {kli18n(
"No Operation"), TemplatesCommandMenu::CNop},
155 {kli18n(
"Clear Generated Message"), TemplatesCommandMenu::CClear},
156 {kli18n(
"Cursor position"), TemplatesCommandMenu::CCursor},
158 {kli18n(
"Blank text"), TemplatesCommandMenu::CBlank},
160 {kli18n(
"Dictionary Language"), TemplatesCommandMenu::CDictionaryLanguage},
161 {kli18n(
"Language"), TemplatesCommandMenu::CLanguage},
164static const int miscCommandsCount =
sizeof(miscCommands) /
sizeof(*miscCommands);
166static const InsertCommand debugCommands[] = {{kli18n(
"Turn Debug On"), TemplatesCommandMenu::CDebug},
168 {kli18n(
"Turn Debug Off"), TemplatesCommandMenu::CDebugOff}};
169static const int debugCommandsCount =
sizeof(debugCommands) /
sizeof(*debugCommands);
177 auto action =
new QAction(it.key(), menu);
178 const TemplatesCommandMenu::Command cmd = it.value();
180 slotInsertCommand(cmd);
187TemplatesCommandMenu::TemplatesCommandMenu(
QObject *parent)
192TemplatesCommandMenu::~TemplatesCommandMenu() =
default;
194QMenu *TemplatesCommandMenu::menu()
const
196 return mMenu->
menu();
199void TemplatesCommandMenu::fillMenu()
204void TemplatesCommandMenu::fillSubMenus()
206 if (mWasInitialized) {
209 mWasInitialized =
true;
213 if (mType & ReplyForwardMessage) {
218 for (
int i = 0; i < originalCommandsCount; ++i) {
219 commandMap.
insert(originalCommands[i].getLocalizedDisplayName(), originalCommands[i].command);
222 fillMenuFromActionMap(commandMap, menu);
227 if (mType & CurrentMessage) {
231 for (
int i = 0; i < currentCommandsCount; ++i) {
232 commandMap.
insert(currentCommands[i].getLocalizedDisplayName(), currentCommands[i].command);
235 fillMenuFromActionMap(commandMap, menu);
240 if (mType & External) {
244 for (
int i = 0; i < extCommandsCount; ++i) {
245 commandMap.
insert(extCommands[i].getLocalizedDisplayName(), extCommands[i].command);
248 fillMenuFromActionMap(commandMap, menu);
254 menu =
new KActionMenu(
i18nc(
"Miscellaneous template commands menu",
"Miscellaneous"), mMenu);
257 for (
int i = 0; i < miscCommandsCount; ++i) {
258 commandMap.
insert(miscCommands[i].getLocalizedDisplayName(), miscCommands[i].command);
261 fillMenuFromActionMap(commandMap, menu);
266 if (!qEnvironmentVariableIsEmpty(
"KDEPIM_DEBUGGING")) {
268 menu =
new KActionMenu(
i18nc(
"Debug template commands menu",
"Debug"), mMenu);
271 for (
int i = 0; i < debugCommandsCount; ++i) {
272 commandMap.
insert(debugCommands[i].getLocalizedDisplayName(), debugCommands[i].command);
275 fillMenuFromActionMap(commandMap, menu);
285void TemplatesCommandMenu::setType(MenuTypes type)
289 mWasInitialized =
false;
294void TemplatesCommandMenu::slotInsertCommand(TemplatesCommandMenu::Command cmd)
296 Q_EMIT insertCommand(cmd);
299 case TemplatesCommandMenu::CBlank:
300 Q_EMIT insertCommand(QStringLiteral(
"%BLANK"));
302 case TemplatesCommandMenu::CQuote:
303 Q_EMIT insertCommand(QStringLiteral(
"%QUOTE"));
305 case TemplatesCommandMenu::CText:
306 Q_EMIT insertCommand(QStringLiteral(
"%TEXT"));
308 case TemplatesCommandMenu::COMsgId:
309 Q_EMIT insertCommand(QStringLiteral(
"%OMSGID"));
311 case TemplatesCommandMenu::CODate:
312 Q_EMIT insertCommand(QStringLiteral(
"%ODATE"));
314 case TemplatesCommandMenu::CODateShort:
315 Q_EMIT insertCommand(QStringLiteral(
"%ODATESHORT"));
317 case TemplatesCommandMenu::CODateEn:
318 Q_EMIT insertCommand(QStringLiteral(
"%ODATEEN"));
320 case TemplatesCommandMenu::CODow:
321 Q_EMIT insertCommand(QStringLiteral(
"%ODOW"));
323 case TemplatesCommandMenu::COTime:
324 Q_EMIT insertCommand(QStringLiteral(
"%OTIME"));
326 case TemplatesCommandMenu::COTimeLong:
327 Q_EMIT insertCommand(QStringLiteral(
"%OTIMELONG"));
329 case TemplatesCommandMenu::COTimeLongEn:
330 Q_EMIT insertCommand(QStringLiteral(
"%OTIMELONGEN"));
332 case TemplatesCommandMenu::COToAddr:
333 Q_EMIT insertCommand(QStringLiteral(
"%OTOADDR"));
335 case TemplatesCommandMenu::COToName:
336 Q_EMIT insertCommand(QStringLiteral(
"%OTONAME"));
338 case TemplatesCommandMenu::COToFName:
339 Q_EMIT insertCommand(QStringLiteral(
"%OTOFNAME"));
341 case TemplatesCommandMenu::COToLName:
342 Q_EMIT insertCommand(QStringLiteral(
"%OTOLNAME"));
344 case TemplatesCommandMenu::COCCAddr:
345 Q_EMIT insertCommand(QStringLiteral(
"%OCCADDR"));
347 case TemplatesCommandMenu::COCCName:
348 Q_EMIT insertCommand(QStringLiteral(
"%OCCNAME"));
350 case TemplatesCommandMenu::COCCFName:
351 Q_EMIT insertCommand(QStringLiteral(
"%OCCFNAME"));
353 case TemplatesCommandMenu::COCCLName:
354 Q_EMIT insertCommand(QStringLiteral(
"%OCCLNAME"));
356 case TemplatesCommandMenu::COFromAddr:
357 Q_EMIT insertCommand(QStringLiteral(
"%OFROMADDR"));
359 case TemplatesCommandMenu::COFromName:
360 Q_EMIT insertCommand(QStringLiteral(
"%OFROMNAME"));
362 case TemplatesCommandMenu::COFromFName:
363 Q_EMIT insertCommand(QStringLiteral(
"%OFROMFNAME"));
365 case TemplatesCommandMenu::COFromLName:
366 Q_EMIT insertCommand(QStringLiteral(
"%OFROMLNAME"));
368 case TemplatesCommandMenu::COFullSubject:
369 Q_EMIT insertCommand(QStringLiteral(
"%OFULLSUBJECT"));
371 case TemplatesCommandMenu::CQHeaders:
372 Q_EMIT insertCommand(QStringLiteral(
"%QHEADERS"));
374 case TemplatesCommandMenu::CHeaders:
375 Q_EMIT insertCommand(QStringLiteral(
"%HEADERS"));
377 case TemplatesCommandMenu::COHeader:
378 Q_EMIT insertCommand(QStringLiteral(
"%OHEADER=\"\""), -1);
380 case TemplatesCommandMenu::CMsgId:
381 Q_EMIT insertCommand(QStringLiteral(
"%MSGID"));
383 case TemplatesCommandMenu::CDate:
384 Q_EMIT insertCommand(QStringLiteral(
"%DATE"));
386 case TemplatesCommandMenu::CDateShort:
387 Q_EMIT insertCommand(QStringLiteral(
"%DATESHORT"));
389 case TemplatesCommandMenu::CDateEn:
390 Q_EMIT insertCommand(QStringLiteral(
"%DATEEN"));
392 case TemplatesCommandMenu::CDow:
393 Q_EMIT insertCommand(QStringLiteral(
"%DOW"));
395 case TemplatesCommandMenu::CTime:
396 Q_EMIT insertCommand(QStringLiteral(
"%TIME"));
398 case TemplatesCommandMenu::CTimeLong:
399 Q_EMIT insertCommand(QStringLiteral(
"%TIMELONG"));
401 case TemplatesCommandMenu::CTimeLongEn:
402 Q_EMIT insertCommand(QStringLiteral(
"%TIMELONGEN"));
404 case TemplatesCommandMenu::COAddresseesAddr:
405 Q_EMIT insertCommand(QStringLiteral(
"%OADDRESSEESADDR"));
407 case TemplatesCommandMenu::CToAddr:
408 Q_EMIT insertCommand(QStringLiteral(
"%TOADDR"));
410 case TemplatesCommandMenu::CToName:
411 Q_EMIT insertCommand(QStringLiteral(
"%TONAME"));
413 case TemplatesCommandMenu::CToFName:
414 Q_EMIT insertCommand(QStringLiteral(
"%TOFNAME"));
416 case TemplatesCommandMenu::CToLName:
417 Q_EMIT insertCommand(QStringLiteral(
"%TOLNAME"));
419 case TemplatesCommandMenu::CCCAddr:
420 Q_EMIT insertCommand(QStringLiteral(
"%CCADDR"));
422 case TemplatesCommandMenu::CCCName:
423 Q_EMIT insertCommand(QStringLiteral(
"%CCNAME"));
425 case TemplatesCommandMenu::CCCFName:
426 Q_EMIT insertCommand(QStringLiteral(
"%CCFNAME"));
428 case TemplatesCommandMenu::CCCLName:
429 Q_EMIT insertCommand(QStringLiteral(
"%CCLNAME"));
431 case TemplatesCommandMenu::CFromAddr:
432 Q_EMIT insertCommand(QStringLiteral(
"%FROMADDR"));
434 case TemplatesCommandMenu::CFromName:
435 Q_EMIT insertCommand(QStringLiteral(
"%FROMNAME"));
437 case TemplatesCommandMenu::CFromFName:
438 Q_EMIT insertCommand(QStringLiteral(
"%FROMFNAME"));
440 case TemplatesCommandMenu::CFromLName:
441 Q_EMIT insertCommand(QStringLiteral(
"%FROMLNAME"));
443 case TemplatesCommandMenu::CFullSubject:
444 Q_EMIT insertCommand(QStringLiteral(
"%FULLSUBJECT"));
446 case TemplatesCommandMenu::CHeader:
447 Q_EMIT insertCommand(QStringLiteral(
"%HEADER=\"\""), -1);
449 case TemplatesCommandMenu::CSystem:
450 Q_EMIT insertCommand(QStringLiteral(
"%SYSTEM=\"\""), -1);
452 case TemplatesCommandMenu::CQuotePipe:
453 Q_EMIT insertCommand(QStringLiteral(
"%QUOTEPIPE=\"\""), -1);
455 case TemplatesCommandMenu::CTextPipe:
456 Q_EMIT insertCommand(QStringLiteral(
"%TEXTPIPE=\"\""), -1);
458 case TemplatesCommandMenu::CMsgPipe:
459 Q_EMIT insertCommand(QStringLiteral(
"%MSGPIPE=\"\""), -1);
461 case TemplatesCommandMenu::CBodyPipe:
462 Q_EMIT insertCommand(QStringLiteral(
"%BODYPIPE=\"\""), -1);
464 case TemplatesCommandMenu::CClearPipe:
465 Q_EMIT insertCommand(QStringLiteral(
"%CLEARPIPE=\"\""), -1);
467 case TemplatesCommandMenu::CCursor:
468 Q_EMIT insertCommand(QStringLiteral(
"%CURSOR"));
470 case TemplatesCommandMenu::CSignature:
471 Q_EMIT insertCommand(QStringLiteral(
"%SIGNATURE"));
473 case TemplatesCommandMenu::CInsert:
474 Q_EMIT insertCommand(QStringLiteral(
"%INSERT=\"\""), -1);
476 case TemplatesCommandMenu::CDnl:
477 Q_EMIT insertCommand(QStringLiteral(
"%-"));
479 case TemplatesCommandMenu::CRem:
480 Q_EMIT insertCommand(QStringLiteral(
"%REM=\"\""), -1);
482 case TemplatesCommandMenu::CNop:
483 Q_EMIT insertCommand(QStringLiteral(
"%NOP"));
485 case TemplatesCommandMenu::CClear:
486 Q_EMIT insertCommand(QStringLiteral(
"%CLEAR"));
488 case TemplatesCommandMenu::CDebug:
489 Q_EMIT insertCommand(QStringLiteral(
"%DEBUG"));
491 case TemplatesCommandMenu::CDebugOff:
492 Q_EMIT insertCommand(QStringLiteral(
"%DEBUGOFF"));
494 case TemplatesCommandMenu::CQuotePlain:
495 Q_EMIT insertCommand(QStringLiteral(
"%FORCEDPLAIN"));
497 case TemplatesCommandMenu::CQuoteHtml:
498 Q_EMIT insertCommand(QStringLiteral(
"%FORCEDHTML"));
500 case TemplatesCommandMenu::CDictionaryLanguage:
501 Q_EMIT insertCommand(QStringLiteral(
"%DICTIONARYLANGUAGE=\"\""), -1);
503 case TemplatesCommandMenu::CLanguage:
504 Q_EMIT insertCommand(QStringLiteral(
"%LANGUAGE=\"\""), -1);
507 qCDebug(TEMPLATEPARSER_LOG) <<
"Unknown template command index:" << cmd;
510#include "moc_templatescommandmenu.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
void triggered(bool checked)
iterator insert(const Key &key, const T &value)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)