Messagelib

convertsnippetvariablesutil.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2022 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "convertsnippetvariablesutil.h"
8 
9 #include <QDateTime>
10 #include <QLocale>
11 
12 QString MessageComposer::ConvertSnippetVariablesUtil::snippetVariableFromEnum(MessageComposer::ConvertSnippetVariablesUtil::VariableType type)
13 {
14  switch (type) {
15  case CcAddr:
16  return QStringLiteral("%CCADDR");
17  case CcLname:
18  return QStringLiteral("%CCLNAME");
19  case CcFname:
20  return QStringLiteral("%CCFNAME");
21  case CcName:
22  return QStringLiteral("%CCNAME");
23  case BccAddr:
24  return QStringLiteral("%BCCADDR");
25  case BccLname:
26  return QStringLiteral("%BCCLNAME");
27  case BccFname:
28  return QStringLiteral("%BCCFNAME");
29  case BccName:
30  return QStringLiteral("%BCCNAME");
31  case FullSubject:
32  return QStringLiteral("%FULLSUBJECT");
33  case ToAddr:
34  return QStringLiteral("%TOADDR");
35  case ToFname:
36  return QStringLiteral("%TOFNAME");
37  case ToLname:
38  return QStringLiteral("%TOLNAME");
39  case ToName:
40  return QStringLiteral("%TONAME");
41  case FromAddr:
42  return QStringLiteral("%FROMADDR");
43  case FromLname:
44  return QStringLiteral("%FROMLNAME");
45  case FromFname:
46  return QStringLiteral("%FROMFNAME");
47  case FromName:
48  return QStringLiteral("%FROMNAME");
49  case Dow:
50  return QStringLiteral("%DOW");
51  case Date:
52  return QStringLiteral("%DATE");
53  case ShortDate:
54  return QStringLiteral("%SHORTDATE");
55  case Time:
56  return QStringLiteral("%TIME");
57  case TimeLong:
58  return QStringLiteral("%TIMELONG");
59  case AttachmentCount:
60  return QStringLiteral("%ATTACHMENTCOUNT");
61  case AttachmentName:
62  return QStringLiteral("%ATTACHMENTNAMES");
63  case AttachmentFilenames:
64  return QStringLiteral("%ATTACHMENTFILENAMES");
65  case AttachmentNamesAndSizes:
66  return QStringLiteral("%ATTACHMENTNAMESANDSIZES");
67  case Year:
68  return QStringLiteral("%YEAR");
69  case LastYear:
70  return QStringLiteral("%LASTYEAR");
71  case NextYear:
72  return QStringLiteral("%NEXTYEAR");
73  case MonthNumber:
74  return QStringLiteral("%MONTHNUMBER"); // 1-12
75  case DayOfMonth:
76  return QStringLiteral("%DAYOFMONTH"); // 1-31
77  case WeekNumber:
78  return QStringLiteral("%WEEKNUMBER"); // 1-52
79  case MonthNameShort:
80  return QStringLiteral("%MONTHNAMESHORT"); //(Jan-Dec)
81  case MonthNameLong:
82  return QStringLiteral("%MONTHNAMELONG"); //(January-December)
83  case DayOfWeek:
84  return QStringLiteral("%DAYOFWEEK"); //(1-7)
85  case DayOfWeekNameShort:
86  return QStringLiteral("%DAYOFWEEKNAMESHORT"); //(Mon-Sun)
87  case DayOfWeekNameLong:
88  return QStringLiteral("%DAYOFWEEKNAMELONG"); //(Monday-Sunday)
89  case YearLastMonth:
90  return QStringLiteral("%YEARLASTMONTH"); // january 2020 will how 2019-12
91  case LastMonthNameLong:
92  return QStringLiteral("%LASTMONTHNAMELONG");
93  }
94  return {};
95 }
96 
97 QString MessageComposer::ConvertSnippetVariablesUtil::shortDate()
98 {
100  return locale.toString(QDate::currentDate(), QLocale::ShortFormat);
101 }
102 
103 QString MessageComposer::ConvertSnippetVariablesUtil::longDate()
104 {
105  QLocale locale;
106  return locale.toString(QDate::currentDate(), QLocale::LongFormat);
107 }
108 
109 QString MessageComposer::ConvertSnippetVariablesUtil::shortTime()
110 {
111  QLocale locale;
112  return locale.toString(QTime::currentTime(), QLocale::ShortFormat);
113 }
114 
115 QString MessageComposer::ConvertSnippetVariablesUtil::longTime()
116 {
117  QLocale locale;
118  return locale.toString(QTime::currentTime(), QLocale::LongFormat);
119 }
120 
121 QString MessageComposer::ConvertSnippetVariablesUtil::insertDayOfWeek()
122 {
124  const QString str = QLocale().dayName(date.date().dayOfWeek(), QLocale::LongFormat);
125  return str;
126 }
127 
128 QString MessageComposer::ConvertSnippetVariablesUtil::lastYear()
129 {
130  const QDate date = QDate::currentDate();
131  return QString::number(date.year() - 1);
132 }
133 
134 QString MessageComposer::ConvertSnippetVariablesUtil::nextYear()
135 {
136  const QDate date = QDate::currentDate();
137  return QString::number(date.year() + 1);
138 }
139 
140 QString MessageComposer::ConvertSnippetVariablesUtil::monthNumber()
141 {
142  const QDate date = QDate::currentDate();
143  return QString::number(date.month());
144 }
145 
146 QString MessageComposer::ConvertSnippetVariablesUtil::dayOfMonth()
147 {
148  const QDate date = QDate::currentDate();
149  return QString::number(date.daysInMonth());
150 }
151 
152 QString MessageComposer::ConvertSnippetVariablesUtil::weekNumber()
153 {
154  const QDate date = QDate::currentDate();
155  return QString::number(date.weekNumber());
156 }
157 
158 QString MessageComposer::ConvertSnippetVariablesUtil::monthNameShort()
159 {
160  const QDate date = QDate::currentDate();
161  return date.toString(QStringLiteral("MMM"));
162 }
163 
164 QString MessageComposer::ConvertSnippetVariablesUtil::monthNameLong()
165 {
166  const QDate date = QDate::currentDate();
167  return date.toString(QStringLiteral("MMMM"));
168 }
169 
170 QString MessageComposer::ConvertSnippetVariablesUtil::lastMonthNameLong()
171 {
172  const QDate date = QDate::currentDate().addMonths(-1);
173  return date.toString(QStringLiteral("MMMM"));
174 }
175 
176 QString MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameShort()
177 {
178  const QDate date = QDate::currentDate();
179  return date.toString(QStringLiteral("ddd"));
180 }
181 
182 QString MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameLong()
183 {
184  const QDate date = QDate::currentDate();
185  return date.toString(QStringLiteral("dddd"));
186 }
187 
188 QString MessageComposer::ConvertSnippetVariablesUtil::yearLastMonth()
189 {
190  const QDate date = QDate::currentDate();
191  return date.toString(date.toString(QStringLiteral("yyyy-MMM")));
192 }
193 
194 QString MessageComposer::ConvertSnippetVariablesUtil::year()
195 {
196  const QDate date = QDate::currentDate();
197  return date.toString(QString::number(date.year()));
198 }
199 
200 QString MessageComposer::ConvertSnippetVariablesUtil::dayOfWeek()
201 {
202  const QDate date = QDate::currentDate();
203  return date.toString(QString::number(date.dayOfWeek()));
204 }
int month() const const
QString number(int n, int base)
QDateTime currentDateTime()
int year() const const
int weekNumber(int *yearNumber) const const
QTime currentTime()
QDate addMonths(int nmonths) const const
QString dayName(int day, QLocale::FormatType type) const const
QDate currentDate()
QDateTime toLocalTime() const const
LocaleWrapper locale()
int daysInMonth() const const
QDate date() const const
QString toString(Qt::DateFormat format) const const
DayOfWeek
int dayOfWeek() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue May 24 2022 04:08:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.