Commit b92ac88a authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add example

parent 3531b40e
......@@ -90,7 +90,7 @@ void ConvertSnippetVariableMenu::initializeMenu(bool onlyMenuForCustomizeAttachm
});
mMenu->addMenu(attachmentMenuVariable);
dateTimeMenuVariable = new QMenu(i18n("Date/Time"), mMenu);
dateTimeMenuVariable->addAction(i18n("Day Of Week"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Day Of Week (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfWeek()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::Dow);
});
dateTimeMenuVariable->addAction(i18n("Date (%1)", MessageComposer::ConvertSnippetVariablesUtil::shortDate()), this, [this]() {
......@@ -105,7 +105,7 @@ void ConvertSnippetVariableMenu::initializeMenu(bool onlyMenuForCustomizeAttachm
dateTimeMenuVariable->addAction(i18n("Time (%1)", MessageComposer::ConvertSnippetVariablesUtil::longTime()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::TimeLong);
});
dateTimeMenuVariable->addAction(i18n("Year"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Year (%1)", MessageComposer::ConvertSnippetVariablesUtil::year()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::Year);
});
} else {
......@@ -113,37 +113,37 @@ void ConvertSnippetVariableMenu::initializeMenu(bool onlyMenuForCustomizeAttachm
mMenu = dateTimeMenuVariable;
}
dateTimeMenuVariable->addAction(i18n("Last Year"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Last Year (%1)", MessageComposer::ConvertSnippetVariablesUtil::lastYear()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::LastYear);
});
dateTimeMenuVariable->addAction(i18n("Next Year"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Next Year (%1)", MessageComposer::ConvertSnippetVariablesUtil::nextYear()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::NextYear);
});
dateTimeMenuVariable->addAction(i18n("Month Number"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Month Number (%1)", MessageComposer::ConvertSnippetVariablesUtil::monthNumber()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::MonthNumber);
});
dateTimeMenuVariable->addAction(i18n("Day Of Month"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Day Of Month (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfMonth()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayOfMonth);
});
dateTimeMenuVariable->addAction(i18n("Week Number"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Week Number (%1)", MessageComposer::ConvertSnippetVariablesUtil::weekNumber()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::WeekNumber);
});
dateTimeMenuVariable->addAction(i18n("Month Name Short"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Month Name Short (%1)", MessageComposer::ConvertSnippetVariablesUtil::monthNameShort()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::MonthNameShort);
});
dateTimeMenuVariable->addAction(i18n("Month Name Long"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Month Name Long (%1)", MessageComposer::ConvertSnippetVariablesUtil::monthNameLong()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::MonthNameLong);
});
dateTimeMenuVariable->addAction(i18n("Day Of Week"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Day Of Week (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfWeek()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayOfWeek);
});
dateTimeMenuVariable->addAction(i18n("Day Of Week Name Short"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Day Of Week Name Short (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameShort()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayOfWeekNameShort);
});
dateTimeMenuVariable->addAction(i18n("Day Of Week Name Long"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Day Of Week Name Long (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameLong()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayOfWeekNameLong);
});
dateTimeMenuVariable->addAction(i18n("Year Last Month"), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Year Last Month (%1)", MessageComposer::ConvertSnippetVariablesUtil::yearLastMonth()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::YearLastMonth);
});
if (!onlyMenuForCustomizeAttachmentFileName) {
......
......@@ -7,6 +7,7 @@
#include "convertsnippetvariablesjob.h"
#include "messagecomposer_debug.h"
#include "composer/composerviewinterface.h"
#include "snippet/convertsnippetvariablesutil.h"
#include <TemplateParser/TemplatesUtil>
#include <KEmailAddress>
#include <QDate>
......@@ -66,52 +67,40 @@ QString ConvertSnippetVariablesJob::convertVariables(const QString &cmd, int &i,
QString result;
if (cmd.startsWith(QLatin1String("LASTYEAR"))) {
i += strlen("LASTYEAR");
const QDate date = QDate::currentDate();
result.append(QString::number(date.year() - 1));
result.append(MessageComposer::ConvertSnippetVariablesUtil::lastYear());
} else if (cmd.startsWith(QLatin1String("NEXTYEAR"))) {
i += strlen("NEXTYEAR");
const QDate date = QDate::currentDate();
result.append(QString::number(date.year() - 2));
result.append(MessageComposer::ConvertSnippetVariablesUtil::nextYear());
} else if (cmd.startsWith(QLatin1String("MONTHNUMBER"))) {
i += strlen("MONTHNUMBER");
const QDate date = QDate::currentDate();
result.append(QString::number(date.month()));
result.append(MessageComposer::ConvertSnippetVariablesUtil::monthNumber());
} else if (cmd.startsWith(QLatin1String("DAYOFMONTH"))) {
i += strlen("DAYOFMONTH");
const QDate date = QDate::currentDate();
result.append(QString::number(date.daysInMonth()));
result.append(MessageComposer::ConvertSnippetVariablesUtil::dayOfMonth());
} else if (cmd.startsWith(QLatin1String("WEEKNUMBER"))) {
i += strlen("WEEKNUMBER");
const QDate date = QDate::currentDate();
result.append(QString::number(date.weekNumber()));
result.append(MessageComposer::ConvertSnippetVariablesUtil::weekNumber());
} else if (cmd.startsWith(QLatin1String("MONTHNAMESHORT"))) {
i += strlen("MONTHNAMESHORT");
const QDate date = QDate::currentDate();
result.append(date.toString(QStringLiteral("MMM")));
result.append(MessageComposer::ConvertSnippetVariablesUtil::monthNameShort());
} else if (cmd.startsWith(QLatin1String("MONTHNAMELONG"))) {
i += strlen("MONTHNAMELONG");
const QDate date = QDate::currentDate();
result.append(date.toString(QStringLiteral("MMMM")));
result.append(MessageComposer::ConvertSnippetVariablesUtil::monthNameLong());
} else if (cmd.startsWith(QLatin1String("DAYOFWEEKNAMESHORT"))) {
i += strlen("DAYOFWEEKNAMESHORT");
const QDate date = QDate::currentDate();
result.append(date.toString(QStringLiteral("ddd")));
result.append(MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameShort());
} else if (cmd.startsWith(QLatin1String("DAYOFWEEKNAMELONG"))) {
i += strlen("DAYOFWEEKNAMELONG");
const QDate date = QDate::currentDate();
result.append(date.toString(QStringLiteral("dddd")));
result.append(MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameLong());
} else if (cmd.startsWith(QLatin1String("YEARLASTMONTH"))) {
i += strlen("YEARLASTMONTH");
const QDate date = QDate::currentDate().addMonths(-1);
result.append(date.toString(QStringLiteral("yyyy-MMM")));
result.append(MessageComposer::ConvertSnippetVariablesUtil::yearLastMonth());
} else if (cmd.startsWith(QLatin1String("YEAR"))) {
i += strlen("YEAR");
const QDate date = QDate::currentDate();
result.append(QString::number(date.year()));
result.append(MessageComposer::ConvertSnippetVariablesUtil::year());
} else if (cmd.startsWith(QLatin1String("DAYOFWEEK"))) {
i += strlen("DAYOFWEEK");
const QDate date = QDate::currentDate();
result.append(QString::number(date.dayOfWeek()));
result.append(MessageComposer::ConvertSnippetVariablesUtil::dayOfWeek());
} else {
result.append(c);
}
......
......@@ -115,3 +115,74 @@ QString MessageComposer::ConvertSnippetVariablesUtil::insertDayOfWeek()
return str;
}
QString MessageComposer::ConvertSnippetVariablesUtil::lastYear()
{
const QDate date = QDate::currentDate();
return QString::number(date.year() - 1);
}
QString MessageComposer::ConvertSnippetVariablesUtil::nextYear()
{
const QDate date = QDate::currentDate();
return QString::number(date.year() - 2);
}
QString MessageComposer::ConvertSnippetVariablesUtil::monthNumber()
{
const QDate date = QDate::currentDate();
return QString::number(date.month());
}
QString MessageComposer::ConvertSnippetVariablesUtil::dayOfMonth()
{
const QDate date = QDate::currentDate();
return QString::number(date.daysInMonth());
}
QString MessageComposer::ConvertSnippetVariablesUtil::weekNumber()
{
const QDate date = QDate::currentDate();
return QString::number(date.weekNumber());
}
QString MessageComposer::ConvertSnippetVariablesUtil::monthNameShort()
{
const QDate date = QDate::currentDate();
return date.toString(QStringLiteral("MMM"));
}
QString MessageComposer::ConvertSnippetVariablesUtil::monthNameLong()
{
const QDate date = QDate::currentDate();
return date.toString(QStringLiteral("MMMM"));
}
QString MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameShort()
{
const QDate date = QDate::currentDate();
return date.toString(QStringLiteral("ddd"));
}
QString MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameLong()
{
const QDate date = QDate::currentDate();
return date.toString(QStringLiteral("dddd"));
}
QString MessageComposer::ConvertSnippetVariablesUtil::yearLastMonth()
{
const QDate date = QDate::currentDate();
return date.toString(date.toString(QStringLiteral("yyyy-MMM")));
}
QString MessageComposer::ConvertSnippetVariablesUtil::year()
{
const QDate date = QDate::currentDate();
return date.toString(QString::number(date.year()));
}
QString MessageComposer::ConvertSnippetVariablesUtil::dayOfWeek()
{
const QDate date = QDate::currentDate();
return date.toString(QString::number(date.dayOfWeek()));
}
......@@ -56,6 +56,18 @@ Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString longDate();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString shortTime();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString longTime();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString insertDayOfWeek();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString lastYear();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString nextYear();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString monthNumber();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString dayOfMonth();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString weekNumber();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString monthNameShort();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString monthNameLong();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString dayOfWeekNameShort();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString dayOfWeekNameLong();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString yearLastMonth();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString year();
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString dayOfWeek();
}
}
#endif // CONVERTSNIPPETVARIABLESUTIL_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment