8 #include "templatesconfiguration.h"
9 #include "globalsettings_templateparser.h"
10 #include "templatesconfiguration_kfg.h"
11 #include <TextCustomEditor/PlainTextEditor>
13 #include "templateparser_debug.h"
14 #include <KLocalizedString>
15 #include <KMessageBox>
19 using namespace TemplateParser;
20 class TemplateParser::TemplatesConfigurationPrivate
23 TemplatesConfigurationPrivate() =
default;
28 TemplatesConfiguration::TemplatesConfiguration(
QWidget *parent,
const QString &name)
30 , d(new TemplateParser::TemplatesConfigurationPrivate)
45 qOverload<const QString &, int>(&TemplateParser::TemplatesInsertCommandPushButton::insertCommand),
47 &TemplatesConfiguration::slotInsertCommand);
49 d->mHelpString =
i18n(
50 "<p>Here you can create and manage templates to use when "
51 "composing new messages, replies or forwarded messages.</p>"
52 "<p>The message templates support substitution commands, "
53 "either simply type them or select them from "
54 "the <i>Insert command</i> menu.</p>");
55 const QString templateConfigurationName(name);
56 if (templateConfigurationName ==
QLatin1String(
"folder-templates")) {
57 d->mHelpString +=
i18n(
58 "<p>Templates specified here are folder-specific. "
59 "They override both global templates and per-identity "
61 }
else if (templateConfigurationName ==
QLatin1String(
"identity-templates")) {
62 d->mHelpString +=
i18n(
63 "<p>Templates specified here are identity-specific. "
64 "They override global templates, but can be overridden by "
65 "per-folder templates if they are specified.</p>");
67 d->mHelpString +=
i18n(
68 "<p>These are global (default) templates. They can be overridden "
69 "by per-identity templates or per-folder templates "
70 "if they are specified.</p>");
73 mHelp->setText(
i18n(
"<a href=\"whatsthis\">How does this work?</a>"));
78 TemplatesConfiguration::~TemplatesConfiguration()
87 void TemplatesConfiguration::slotHelpLinkClicked(
const QString &)
92 void TemplatesConfiguration::slotTextChanged()
97 void TemplatesConfiguration::resetToDefault()
100 i18n(
"Do you want to reset current template or all templates to default?"),
101 i18nc(
"@title:window",
"Reset to default"),
106 if (choice == KMessageBox::Cancel) {
108 }
else if (choice == KMessageBox::ButtonCode::PrimaryAction) {
109 const int toolboxCurrentIndex(toolBox1->currentIndex());
110 if (toolBox1->widget(toolboxCurrentIndex) == page_new) {
111 textEdit_new->setPlainText(DefaultTemplates::defaultNewMessage());
112 }
else if (toolBox1->widget(toolboxCurrentIndex) == page_reply) {
113 textEdit_reply->setPlainText(DefaultTemplates::defaultReply());
114 }
else if (toolBox1->widget(toolboxCurrentIndex) == page_reply_all) {
115 textEdit_reply_all->setPlainText(DefaultTemplates::defaultReplyAll());
116 }
else if (toolBox1->widget(toolboxCurrentIndex) == page_forward) {
117 textEdit_forward->setPlainText(DefaultTemplates::defaultForward());
119 qCDebug(TEMPLATEPARSER_LOG) <<
"Unknown current page in TemplatesConfiguration!";
122 textEdit_new->setPlainText(DefaultTemplates::defaultNewMessage());
123 textEdit_reply->setPlainText(DefaultTemplates::defaultReply());
124 textEdit_reply_all->setPlainText(DefaultTemplates::defaultReplyAll());
125 textEdit_forward->setPlainText(DefaultTemplates::defaultForward());
127 lineEdit_quote->setText(DefaultTemplates::defaultQuoteString());
130 QLabel *TemplatesConfiguration::helpLabel()
const
135 void TemplatesConfiguration::loadFromGlobal()
138 str = TemplateParserSettings::self()->templateNewMessage();
140 textEdit_new->setPlainText(DefaultTemplates::defaultNewMessage());
142 textEdit_new->setPlainText(str);
144 str = TemplateParserSettings::self()->templateReply();
146 textEdit_reply->setPlainText(DefaultTemplates::defaultReply());
148 textEdit_reply->setPlainText(str);
150 str = TemplateParserSettings::self()->templateReplyAll();
152 textEdit_reply_all->setPlainText(DefaultTemplates::defaultReplyAll());
154 textEdit_reply_all->setPlainText(str);
156 str = TemplateParserSettings::self()->templateForward();
158 textEdit_forward->setPlainText(DefaultTemplates::defaultForward());
160 textEdit_forward->setPlainText(str);
162 str = TemplateParserSettings::self()->quoteString();
164 lineEdit_quote->setText(DefaultTemplates::defaultQuoteString());
166 lineEdit_quote->setText(str);
170 void TemplatesConfiguration::saveToGlobal()
172 TemplateParserSettings::self()->setTemplateNewMessage(strOrBlank(textEdit_new->toPlainText()));
173 TemplateParserSettings::self()->setTemplateReply(strOrBlank(textEdit_reply->toPlainText()));
174 TemplateParserSettings::self()->setTemplateReplyAll(strOrBlank(textEdit_reply_all->toPlainText()));
175 TemplateParserSettings::self()->setTemplateForward(strOrBlank(textEdit_forward->toPlainText()));
176 TemplateParserSettings::self()->setQuoteString(lineEdit_quote->text());
177 TemplateParserSettings::self()->save();
180 void TemplatesConfiguration::loadFromIdentity(uint
id)
186 str = t.templateNewMessage();
188 str = TemplateParserSettings::self()->templateNewMessage();
191 str = DefaultTemplates::defaultNewMessage();
193 textEdit_new->setPlainText(str);
195 str = t.templateReply();
197 str = TemplateParserSettings::self()->templateReply();
200 str = DefaultTemplates::defaultReply();
202 textEdit_reply->setPlainText(str);
204 str = t.templateReplyAll();
206 str = TemplateParserSettings::self()->templateReplyAll();
209 str = DefaultTemplates::defaultReplyAll();
211 textEdit_reply_all->setPlainText(str);
213 str = t.templateForward();
215 str = TemplateParserSettings::self()->templateForward();
218 str = DefaultTemplates::defaultForward();
220 textEdit_forward->setPlainText(str);
222 str = t.quoteString();
224 str = TemplateParserSettings::self()->quoteString();
227 str = DefaultTemplates::defaultQuoteString();
229 lineEdit_quote->setText(str);
232 void TemplatesConfiguration::saveToIdentity(uint
id)
235 t.setTemplateNewMessage(strOrBlank(textEdit_new->toPlainText()));
236 t.setTemplateReply(strOrBlank(textEdit_reply->toPlainText()));
237 t.setTemplateReplyAll(strOrBlank(textEdit_reply_all->toPlainText()));
238 t.setTemplateForward(strOrBlank(textEdit_forward->toPlainText()));
239 t.setQuoteString(lineEdit_quote->text());
243 void TemplatesConfiguration::loadFromFolder(
const QString &
id, uint identity)
246 Templates *tid =
nullptr;
254 str = t.templateNewMessage();
256 str = tid->templateNewMessage();
259 str = TemplateParserSettings::self()->templateNewMessage();
261 str = DefaultTemplates::defaultNewMessage();
264 textEdit_new->setPlainText(str);
266 str = t.templateReply();
268 str = tid->templateReply();
271 str = TemplateParserSettings::self()->templateReply();
273 str = DefaultTemplates::defaultReply();
276 textEdit_reply->setPlainText(str);
278 str = t.templateReplyAll();
280 str = tid->templateReplyAll();
282 str = TemplateParserSettings::self()->templateReplyAll();
286 str = DefaultTemplates::defaultReplyAll();
288 textEdit_reply_all->setPlainText(str);
290 str = t.templateForward();
292 str = tid->templateForward();
294 str = TemplateParserSettings::self()->templateForward();
298 str = DefaultTemplates::defaultForward();
300 textEdit_forward->setPlainText(str);
302 str = t.quoteString();
304 str = tid->quoteString();
307 str = TemplateParserSettings::self()->quoteString();
309 str = DefaultTemplates::defaultQuoteString();
312 lineEdit_quote->setText(str);
317 void TemplatesConfiguration::saveToFolder(
const QString &
id)
321 t.setTemplateNewMessage(strOrBlank(textEdit_new->toPlainText()));
322 t.setTemplateReply(strOrBlank(textEdit_reply->toPlainText()));
323 t.setTemplateReplyAll(strOrBlank(textEdit_reply_all->toPlainText()));
324 t.setTemplateForward(strOrBlank(textEdit_forward->toPlainText()));
325 t.setQuoteString(lineEdit_quote->text());
333 const int toolboxCurrentIndex(toolBox1->currentIndex());
334 if (toolBox1->widget(toolboxCurrentIndex) == page_new) {
335 edit = textEdit_new->editor();
336 }
else if (toolBox1->widget(toolboxCurrentIndex) == page_reply) {
337 edit = textEdit_reply->editor();
338 }
else if (toolBox1->widget(toolboxCurrentIndex) == page_reply_all) {
339 edit = textEdit_reply_all->editor();
340 }
else if (toolBox1->widget(toolboxCurrentIndex) == page_forward) {
341 edit = textEdit_forward->editor();
343 qCDebug(TEMPLATEPARSER_LOG) <<
"Unknown current page in TemplatesConfiguration!";
349 void TemplatesConfiguration::slotInsertCommand(
const QString &cmd,
int adjustCursor)
361 i18n(
"Use of \"Reply using plain text\" and \"Reply using HTML text\" in pairs"
362 " is not correct. Use only one of the aforementioned commands with \" Reply as"
363 " Quoted Message command\" as per your need\n"
364 "(a)Reply using plain text for quotes to be strictly in plain text\n"
365 "(b)Reply using HTML text for quotes being in HTML format if present"));
378 return QStringLiteral(
"%BLANK");
385 return QStringLiteral(
"IDENTITY_%1").
arg(
id);
388 #include "moc_templatesconfiguration.cpp"