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;
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 });
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
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 });
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("Short Time (%1)", MessageComposer::ConvertSnippetVariablesUtil::shortTime()), this, [this]() {
114 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::Time);
115 });
116 dateTimeMenuVariable->addAction(i18n("Time (%1)", MessageComposer::ConvertSnippetVariablesUtil::longTime()), this, [this]() {
117 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::TimeLong);
118 });
119 dateTimeMenuVariable->addAction(i18n("Year (%1)", MessageComposer::ConvertSnippetVariablesUtil::year()), this, [this]() {
120 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::Year);
121 });
122 } else {
123 dateTimeMenuVariable = new QMenu(i18n("Date/Time"), mParentWidget);
124 mMenu = dateTimeMenuVariable;
125 }
126
127 dateTimeMenuVariable->addAction(i18n("Last Year (%1)", MessageComposer::ConvertSnippetVariablesUtil::lastYear()), this, [this]() {
128 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::LastYear);
129 });
130 dateTimeMenuVariable->addAction(i18n("Next Year (%1)", MessageComposer::ConvertSnippetVariablesUtil::nextYear()), this, [this]() {
131 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::NextYear);
132 });
133 dateTimeMenuVariable->addAction(i18n("Month Number (%1)", MessageComposer::ConvertSnippetVariablesUtil::monthNumber()), this, [this]() {
134 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::MonthNumber);
135 });
136 dateTimeMenuVariable->addAction(i18n("Day Of Month (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfMonth()), this, [this]() {
137 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayOfMonth);
138 });
139 dateTimeMenuVariable->addAction(i18n("Week Number (%1)", MessageComposer::ConvertSnippetVariablesUtil::weekNumber()), this, [this]() {
140 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::WeekNumber);
141 });
142 dateTimeMenuVariable->addAction(i18n("Month Name Short (%1)", MessageComposer::ConvertSnippetVariablesUtil::monthNameShort()), this, [this]() {
143 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::MonthNameShort);
144 });
145 dateTimeMenuVariable->addAction(i18n("Month Name Long (%1)", MessageComposer::ConvertSnippetVariablesUtil::monthNameLong()), this, [this]() {
146 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::MonthNameLong);
147 });
148 dateTimeMenuVariable->addAction(i18n("Last Month Name Long (%1)", MessageComposer::ConvertSnippetVariablesUtil::lastMonthNameLong()), this, [this]() {
149 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::LastMonthNameLong);
150 });
151 dateTimeMenuVariable->addAction(i18n("Day Of Week (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfWeek()), this, [this]() {
152 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayOfWeek);
153 });
154 dateTimeMenuVariable->addAction(i18n("Day Of Week Name Short (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameShort()), this, [this]() {
155 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayOfWeekNameShort);
156 });
157 dateTimeMenuVariable->addAction(i18n("Day Of Week Name Long (%1)", MessageComposer::ConvertSnippetVariablesUtil::dayOfWeekNameLong()), this, [this]() {
158 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::DayOfWeekNameLong);
159 });
160 dateTimeMenuVariable->addAction(i18n("Year Last Month (%1)", MessageComposer::ConvertSnippetVariablesUtil::yearLastMonth()), this, [this]() {
161 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::YearLastMonth);
162 });
165 auto miscVariable = new QMenu(i18n("Misc"), mMenu);
166 miscVariable->addAction(i18n("Subject"), this, [this]() {
167 Q_EMIT insertVariable(MessageComposer::ConvertSnippetVariablesUtil::FullSubject);
168 });
169 // Add more variables!
170 mMenu->addMenu(miscVariable);
171 }
172}
173
174QMenu *ConvertSnippetVariableMenu::menu() const
175{
176 return mMenu;
177}
178
179#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 * addMenu(QMenu *menu)
Q_EMITQ_EMIT
T qobject_cast(QObject *object)
void setFocusPolicy(Qt::FocusPolicy policy)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:37:31 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.