Messagelib

convertsnippetvariablesutil.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "convertsnippetvariablesutil.h"
8
9#include <QDateTime>
10#include <QLocale>
11
12QString 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 DayNumber:
76 return QStringLiteral("%DAYNUMBER"); // 1-28 to 31
77 case CustomDate:
78 return QStringLiteral("%CUSTOMDATE"); // dd MMM yyyy
79 case DayOfMonth:
80 return QStringLiteral("%DAYOFMONTH"); // 1-31
81 case WeekNumber:
82 return QStringLiteral("%WEEKNUMBER"); // 1-52
83 case MonthNameShort:
84 return QStringLiteral("%MONTHNAMESHORT"); //(Jan-Dec)
85 case MonthNameLong:
86 return QStringLiteral("%MONTHNAMELONG"); //(January-December)
87 case DayOfWeek:
88 return QStringLiteral("%DAYOFWEEK"); //(1-7)
89 case DayOfWeekNameShort:
90 return QStringLiteral("%DAYOFWEEKNAMESHORT"); //(Mon-Sun)
91 case DayOfWeekNameLong:
92 return QStringLiteral("%DAYOFWEEKNAMELONG"); //(Monday-Sunday)
93 case YearLastMonth:
94 return QStringLiteral("%YEARLASTMONTH"); // january 2020 will how 2019-12
95 case LastMonthNameLong:
96 return QStringLiteral("%LASTMONTHNAMELONG");
97 }
98 return {};
99}
100
101QString MessageComposer::ConvertSnippetVariablesUtil::shortDate()
102{
103 QLocale locale;
105}
106
107QString MessageComposer::ConvertSnippetVariablesUtil::longDate()
108{
109 QLocale locale;
111}
112
113QString MessageComposer::ConvertSnippetVariablesUtil::customDate()
114{
115 QLocale locale;
116 return locale.toString(QDate::currentDate(), QStringLiteral("dd MMM yyyy"));
117}
118
119QString MessageComposer::ConvertSnippetVariablesUtil::shortTime()
120{
121 QLocale locale;
123}
124
125QString MessageComposer::ConvertSnippetVariablesUtil::longTime()
126{
127 QLocale locale;
129}
130
131QString MessageComposer::ConvertSnippetVariablesUtil::insertDayOfWeek()
132{
134 const QString str = QLocale().dayName(date.date().dayOfWeek(), QLocale::LongFormat);
135 return str;
136}
137
138QString MessageComposer::ConvertSnippetVariablesUtil::lastYear()
139{
140 const QDate date = QDate::currentDate();
141 return QString::number(date.year() - 1);
142}
143
144QString MessageComposer::ConvertSnippetVariablesUtil::nextYear()
145{
146 const QDate date = QDate::currentDate();
147 return QString::number(date.year() + 1);
148}
149
150QString MessageComposer::ConvertSnippetVariablesUtil::dayNumber()
151{
152 const QDate date = QDate::currentDate();
153 return QString::number(date.day());
154}
155
156QString MessageComposer::ConvertSnippetVariablesUtil::monthNumber()
157{
158 const QDate date = QDate::currentDate();
159 return QString::number(date.month());
160}
161
162QString MessageComposer::ConvertSnippetVariablesUtil::dayOfMonth()
163{
164 const QDate date = QDate::currentDate();
165 return QString::number(date.daysInMonth());
166}
167
168QString MessageComposer::ConvertSnippetVariablesUtil::weekNumber()
169{
170 const QDate date = QDate::currentDate();
171 return QString::number(date.weekNumber());
172}
173
174QString MessageComposer::ConvertSnippetVariablesUtil::monthNameShort()
175{
176 const QDate date = QDate::currentDate();
177 return date.toString(QStringLiteral("MMM"));
178}
179
180QString MessageComposer::ConvertSnippetVariablesUtil::monthNameLong()
181{
182 const QDate date = QDate::currentDate();
183 return date.toString(QStringLiteral("MMMM"));
184}
185
186QString MessageComposer::ConvertSnippetVariablesUtil::lastMonthNameLong()
187{
188 const QDate date = QDate::currentDate().addMonths(-1);
189 return date.toString(QStringLiteral("MMMM"));
190}
191
192QString MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameShort()
193{
194 const QDate date = QDate::currentDate();
195 return date.toString(QStringLiteral("ddd"));
196}
197
198QString MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameLong()
199{
200 const QDate date = QDate::currentDate();
201 return date.toString(QStringLiteral("dddd"));
202}
203
204QString MessageComposer::ConvertSnippetVariablesUtil::yearLastMonth()
205{
206 const QDate date = QDate::currentDate();
207 return date.toString(date.toString(QStringLiteral("yyyy-MMM")));
208}
209
210QString MessageComposer::ConvertSnippetVariablesUtil::year()
211{
212 const QDate date = QDate::currentDate();
213 return date.toString(QString::number(date.year()));
214}
215
216QString MessageComposer::ConvertSnippetVariablesUtil::dayOfWeek()
217{
218 const QDate date = QDate::currentDate();
219 return date.toString(QString::number(date.dayOfWeek()));
220}
QDate addMonths(int nmonths) const const
QDate currentDate()
int day() const const
int dayOfWeek() const const
int daysInMonth() const const
int month() const const
QString toString(QStringView format, QCalendar cal) const const
int weekNumber(int *yearNumber) const const
int year() const const
QDateTime currentDateTime()
QDate date() const const
QDateTime toLocalTime() const const
QString dayName(int day, FormatType type) const const
QString toString(QDate date, FormatType format) const const
QString number(double n, char format, int precision)
DayOfWeek
QTime currentTime()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 11:53:54 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.