Messagelib

convertsnippetvariablemenu.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "convertsnippetvariablemenu.h"
8#include <KLocalizedString>
9#include <QMenu>
10using namespace MessageComposer;
11ConvertSnippetVariableMenu::ConvertSnippetVariableMenu(bool onlyMenuForCustomizeAttachmentFileName, QWidget *parentWidget, QObject *parent)
12 : QObject(parent)
13 , mParentWidget(parentWidget)
14{
15 initializeMenu(onlyMenuForCustomizeAttachmentFileName);
16}
17
18ConvertSnippetVariableMenu::~ConvertSnippetVariableMenu() = default;
19
20void ConvertSnippetVariableMenu::initializeMenu(bool onlyMenuForCustomizeAttachmentFileName)
21{
22 QMenu *dateTimeMenuVariable = nullptr;
23 if (!onlyMenuForCustomizeAttachmentFileName) {
24 mMenu = new QMenu(mParentWidget);
26
27 auto toMenuVariable = new QMenu(i18n("To"), mMenu);
28 toMenuVariable->addAction(i18n("To Field Address"), this, [this]() {
29 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::ToAddr);
30 });
31 toMenuVariable->addAction(i18n("To Field Last Name"), this, [this]() {
32 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::ToLname);
33 });
34 toMenuVariable->addAction(i18n("To Field First Name"), this, [this]() {
35 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::ToFname);
36 });
37 toMenuVariable->addAction(i18n("To Field Name"), this, [this]() {
38 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::ToName);
39 });
40 mMenu->addMenu(toMenuVariable);
41
42 auto fromMenuVariable = new QMenu(i18n("From"), mMenu);
43 fromMenuVariable->addAction(i18n("From Field Address"), this, [this]() {
44 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::FromAddr);
45 });
46 fromMenuVariable->addAction(i18n("From Field Last Name"), this, [this]() {
47 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::FromLname);
48 });
49 fromMenuVariable->addAction(i18n("From Field First Name"), this, [this]() {
50 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::FromFname);
51 });
52 fromMenuVariable->addAction(i18n("From Field Name"), this, [this]() {
53 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::FromName);
54 });
55 mMenu->addMenu(fromMenuVariable);
56
57 auto ccMenuVariable = new QMenu(i18n("CC"), mMenu);
58 ccMenuVariable->addAction(i18n("CC Field Address"), this, [this]() {
59 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::CcAddr);
60 });
61 ccMenuVariable->addAction(i18n("CC Field Last Name"), this, [this]() {
62 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::CcLname);
63 });
64 ccMenuVariable->addAction(i18n("CC Field First Name"), this, [this]() {
65 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::CcFname);
66 });
67 ccMenuVariable->addAction(i18n("CC Field Name"), this, [this]() {
68 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::CcName);
69 });
70
71 mMenu->addMenu(ccMenuVariable);
72
73 auto bccMenuVariable = new QMenu(i18n("Bcc"), mMenu);
74 bccMenuVariable->addAction(i18n("BCC Field Address"), this, [this]() {
75 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::BccAddr);
76 });
77 bccMenuVariable->addAction(i18n("BCC Field Last Name"), this, [this]() {
78 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::BccLname);
79 });
80 bccMenuVariable->addAction(i18n("BCC Field First Name"), this, [this]() {
81 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::BccFname);
82 });
83 bccMenuVariable->addAction(i18n("BCC Field Name"), this, [this]() {
84 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::BccName);
85 });
86
87 mMenu->addMenu(bccMenuVariable);
88
89 auto attachmentMenuVariable = new QMenu(i18n("Attachment"), mMenu);
90 attachmentMenuVariable->addAction(i18n("Number Of Attachments"), this, [this]() {
91 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::AttachmentCount);
92 });
93 attachmentMenuVariable->addAction(i18n("Names"), this, [this]() {
94 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::AttachmentName);
95 });
96 attachmentMenuVariable->addAction(i18n("Filenames"), this, [this]() {
97 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::AttachmentFilenames);
98 });
99 attachmentMenuVariable->addAction(i18n("Names and Sizes"), this, [this]() {
100 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::AttachmentNamesAndSizes);
101 });
102 mMenu->addMenu(attachmentMenuVariable);
103 dateTimeMenuVariable = new QMenu(i18n("Date/Time"), mMenu);
104 dateTimeMenuVariable->addAction(i18n("Day Of Week (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfWeek()), this, [this]() {
105 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::Dow);
106 });
107 dateTimeMenuVariable->addAction(i18n("Date (%1)", MessageComposer::ConvertSnippetVariablesUtil::shortDate()), this, [this]() {
108 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::ShortDate);
109 });
110 dateTimeMenuVariable->addAction(i18n("Long Date (%1)", MessageComposer::ConvertSnippetVariablesUtil::longDate()), this, [this]() {
111 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::Date);
112 });
113 dateTimeMenuVariable->addAction(i18n("Custom Date (%1)", MessageComposer::ConvertSnippetVariablesUtil::customDate()), this, [this]() {
114 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::CustomDate);
115 });
116 dateTimeMenuVariable->addAction(i18n("Short Time (%1)", MessageComposer::ConvertSnippetVariablesUtil::shortTime()), this, [this]() {
117 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::Time);
118 });
119 dateTimeMenuVariable->addAction(i18n("Time (%1)", MessageComposer::ConvertSnippetVariablesUtil::longTime()), this, [this]() {
120 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::TimeLong);
121 });
122 dateTimeMenuVariable->addAction(i18n("Year (%1)", MessageComposer::ConvertSnippetVariablesUtil::year()), this, [this]() {
123 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::Year);
124 });
125 } else {
126 dateTimeMenuVariable = new QMenu(i18n("Date/Time"), mParentWidget);
127 mMenu = dateTimeMenuVariable;
128 }
129
130 dateTimeMenuVariable->addAction(i18n("Last Year (%1)", MessageComposer::ConvertSnippetVariablesUtil::lastYear()), this, [this]() {
131 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::LastYear);
132 });
133 dateTimeMenuVariable->addAction(i18n("Next Year (%1)", MessageComposer::ConvertSnippetVariablesUtil::nextYear()), this, [this]() {
134 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::NextYear);
135 });
136 dateTimeMenuVariable->addAction(i18n("Month Number (%1)", MessageComposer::ConvertSnippetVariablesUtil::monthNumber()), this, [this]() {
137 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::MonthNumber);
138 });
139 dateTimeMenuVariable->addAction(i18n("Day Number (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayNumber()), this, [this]() {
140 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayNumber);
141 });
142 dateTimeMenuVariable->addAction(i18n("Day Of Month (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfMonth()), this, [this]() {
143 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayOfMonth);
144 });
145 dateTimeMenuVariable->addAction(i18n("Week Number (%1)", MessageComposer::ConvertSnippetVariablesUtil::weekNumber()), this, [this]() {
146 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::WeekNumber);
147 });
148 dateTimeMenuVariable->addAction(i18n("Month Name Short (%1)", MessageComposer::ConvertSnippetVariablesUtil::monthNameShort()), this, [this]() {
149 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::MonthNameShort);
150 });
151 dateTimeMenuVariable->addAction(i18n("Month Name Long (%1)", MessageComposer::ConvertSnippetVariablesUtil::monthNameLong()), this, [this]() {
152 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::MonthNameLong);
153 });
154 dateTimeMenuVariable->addAction(i18n("Last Month Name Long (%1)", MessageComposer::ConvertSnippetVariablesUtil::lastMonthNameLong()), this, [this]() {
155 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::LastMonthNameLong);
156 });
157 dateTimeMenuVariable->addAction(i18n("Day Of Week (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfWeek()), this, [this]() {
158 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayOfWeek);
159 });
160 dateTimeMenuVariable->addAction(i18n("Day Of Week Name Short (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameShort()), this, [this]() {
161 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayOfWeekNameShort);
162 });
163 dateTimeMenuVariable->addAction(i18n("Day Of Week Name Long (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameLong()), this, [this]() {
164 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayOfWeekNameLong);
165 });
166 dateTimeMenuVariable->addAction(i18n("Year Last Month (%1)", MessageComposer::ConvertSnippetVariablesUtil::yearLastMonth()), this, [this]() {
167 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::YearLastMonth);
168 });
169 if (!onlyMenuForCustomizeAttachmentFileName) {
170 mMenu->addMenu(dateTimeMenuVariable);
171 auto miscVariable = new QMenu(i18n("Misc"), mMenu);
172 miscVariable->addAction(i18n("Subject"), this, [this]() {
173 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::FullSubject);
174 });
175 // Add more variables!
176 mMenu->addMenu(miscVariable);
177 }
178}
179
180QMenu *ConvertSnippetVariableMenu::menu() const
181{
182 return mMenu;
183}
184
185#include "moc_convertsnippetvariablemenu.cpp"
QString i18n(const char *text, const TYPE &arg...)
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
QAction * addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut)
QAction * addMenu(QMenu *menu)
Q_EMITQ_EMIT
void setFocusPolicy(Qt::FocusPolicy policy)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.