Commit 3531b40e authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Remove duplicate code

parent 2b5e2084
Pipeline #26453 passed with stage
in 36 minutes and 54 seconds
......@@ -6,6 +6,7 @@
#include "composerviewinterface.h"
#include "composerviewbase.h"
#include "snippet/convertsnippetvariablesutil.h"
#include <MessageComposer/AttachmentModel>
#include <KFormat>
using namespace MessageComposer;
......@@ -78,31 +79,25 @@ MessageComposer::ComposerAttachmentInterface ComposerViewInterface::attachments(
QString ComposerViewInterface::shortDate() const
{
QLocale locale;
return locale.toString(QDate::currentDate(), QLocale::ShortFormat);
return MessageComposer::ConvertSnippetVariablesUtil::shortDate();
}
QString ComposerViewInterface::longDate() const
{
QLocale locale;
return locale.toString(QDate::currentDate(), QLocale::LongFormat);
return MessageComposer::ConvertSnippetVariablesUtil::longDate();
}
QString ComposerViewInterface::shortTime() const
{
QLocale locale;
return locale.toString(QTime::currentTime(), QLocale::ShortFormat);
return MessageComposer::ConvertSnippetVariablesUtil::shortTime();
}
QString ComposerViewInterface::longTime() const
{
QLocale locale;
return locale.toString(QTime::currentTime(), QLocale::LongFormat);
return MessageComposer::ConvertSnippetVariablesUtil::longTime();
}
QString ComposerViewInterface::insertDayOfWeek() const
{
const QDateTime date = QDateTime::currentDateTime().toLocalTime();
const QString str = QLocale().dayName(date.date().dayOfWeek(), QLocale::LongFormat);
return str;
return MessageComposer::ConvertSnippetVariablesUtil::insertDayOfWeek();
}
......@@ -93,17 +93,16 @@ void ConvertSnippetVariableMenu::initializeMenu(bool onlyMenuForCustomizeAttachm
dateTimeMenuVariable->addAction(i18n("Day Of Week"), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::Dow);
});
QLocale locale;
dateTimeMenuVariable->addAction(i18n("Date (%1)", locale.toString(QDate::currentDate(), QLocale::ShortFormat)), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Date (%1)", MessageComposer::ConvertSnippetVariablesUtil::shortDate()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::ShortDate);
});
dateTimeMenuVariable->addAction(i18n("Date (%1)", locale.toString(QDate::currentDate(), QLocale::LongFormat)), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Date (%1)", MessageComposer::ConvertSnippetVariablesUtil::longDate()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::Date);
});
dateTimeMenuVariable->addAction(i18n("Time (%1)", locale.toString(QTime::currentTime(), QLocale::ShortFormat)), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Time (%1)", MessageComposer::ConvertSnippetVariablesUtil::shortTime()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::Time);
});
dateTimeMenuVariable->addAction(i18n("Time (%1)", locale.toString(QTime::currentTime(), QLocale::LongFormat)), this, [this]() {
dateTimeMenuVariable->addAction(i18n("Time (%1)", MessageComposer::ConvertSnippetVariablesUtil::longTime()), this, [this]() {
Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::TimeLong);
});
dateTimeMenuVariable->addAction(i18n("Year"), this, [this]() {
......
......@@ -6,6 +6,9 @@
#include "convertsnippetvariablesutil.h"
#include <QDateTime>
#include <QLocale>
QString MessageComposer::ConvertSnippetVariablesUtil::snippetVariableFromEnum(MessageComposer::ConvertSnippetVariablesUtil::VariableType type)
{
switch (type) {
......@@ -80,3 +83,35 @@ QString MessageComposer::ConvertSnippetVariablesUtil::snippetVariableFromEnum(Me
}
return {};
}
QString MessageComposer::ConvertSnippetVariablesUtil::shortDate()
{
QLocale locale;
return locale.toString(QDate::currentDate(), QLocale::ShortFormat);
}
QString MessageComposer::ConvertSnippetVariablesUtil::longDate()
{
QLocale locale;
return locale.toString(QDate::currentDate(), QLocale::LongFormat);
}
QString MessageComposer::ConvertSnippetVariablesUtil::shortTime()
{
QLocale locale;
return locale.toString(QTime::currentTime(), QLocale::ShortFormat);
}
QString MessageComposer::ConvertSnippetVariablesUtil::longTime()
{
QLocale locale;
return locale.toString(QTime::currentTime(), QLocale::LongFormat);
}
QString MessageComposer::ConvertSnippetVariablesUtil::insertDayOfWeek()
{
const QDateTime date = QDateTime::currentDateTime().toLocalTime();
const QString str = QLocale().dayName(date.date().dayOfWeek(), QLocale::LongFormat);
return str;
}
......@@ -49,6 +49,13 @@ enum VariableType {
};
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString snippetVariableFromEnum(MessageComposer::ConvertSnippetVariablesUtil::VariableType type);
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QString shortDate();
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();
}
}
#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