7#include "customtemplatesmenu.h"
8#include "customtemplates.h"
9#include "customtemplates_kfg.h"
10#include "globalsettings_templateparser.h"
12#include <KActionCollection>
14#include <KLocalizedString>
19using namespace TemplateParser;
20class TemplateParser::CustomTemplatesMenuPrivate
23 CustomTemplatesMenuPrivate() =
default;
25 ~CustomTemplatesMenuPrivate()
27 delete mCustomReplyActionMenu;
28 delete mCustomReplyAllActionMenu;
29 delete mCustomForwardActionMenu;
44 : d(new TemplateParser::CustomTemplatesMenuPrivate)
46 d->mOwnerActionCollection = ac;
49 d->mOwnerActionCollection->addAction(QStringLiteral(
"custom_forward"), d->mCustomForwardActionMenu);
52 d->mOwnerActionCollection->addAction(QStringLiteral(
"custom_reply"), d->mCustomReplyActionMenu);
54 d->mCustomReplyAllActionMenu =
new KActionMenu(
QIcon::fromTheme(QStringLiteral(
"mail-reply-all-custom")),
i18n(
"Reply to All With Custom Template"), owner);
55 d->mOwnerActionCollection->addAction(QStringLiteral(
"custom_reply_all"), d->mCustomReplyAllActionMenu);
60CustomTemplatesMenu::~CustomTemplatesMenu()
65KActionMenu *CustomTemplatesMenu::replyActionMenu()
const
67 return d->mCustomReplyActionMenu;
70KActionMenu *CustomTemplatesMenu::replyAllActionMenu()
const
72 return d->mCustomReplyAllActionMenu;
75KActionMenu *CustomTemplatesMenu::forwardActionMenu()
const
77 return d->mCustomForwardActionMenu;
80void CustomTemplatesMenu::clear()
82 qDeleteAll(d->mCustomTemplateActions);
83 d->mCustomTemplateActions.clear();
85 d->mCustomReplyActionMenu->menu()->clear();
86 d->mCustomReplyAllActionMenu->menu()->clear();
87 d->mCustomForwardActionMenu->menu()->clear();
88 d->mCustomTemplates.clear();
91void CustomTemplatesMenu::update()
95 const QStringList list = TemplateParserSettings::self()->customTemplates();
102 for (; it !=
end; ++it) {
104 d->mCustomTemplates.append(*it);
106 nameAction.replace(
QLatin1Char(
'&'), QStringLiteral(
"&&"));
112 case CustomTemplates::TReply:
113 action =
new QAction(nameAction, d->mOwnerActionCollection);
114 d->mOwnerActionCollection->setDefaultShortcut(action, t.shortcut());
115 d->mOwnerActionCollection->addAction(nameActionName, action);
117 slotReplySelected(idx);
119 d->mCustomReplyActionMenu->addAction(action);
120 d->mCustomTemplateActions.append(action);
124 case CustomTemplates::TReplyAll:
125 action =
new QAction(nameAction, d->mOwnerActionCollection);
126 d->mOwnerActionCollection->setDefaultShortcut(action, t.shortcut());
127 d->mOwnerActionCollection->addAction(nameActionName, action);
129 slotReplyAllSelected(idx);
131 d->mCustomReplyAllActionMenu->addAction(action);
132 d->mCustomTemplateActions.append(action);
136 case CustomTemplates::TForward:
137 action =
new QAction(nameAction, d->mOwnerActionCollection);
138 d->mOwnerActionCollection->addAction(nameActionName, action);
139 d->mOwnerActionCollection->setDefaultShortcut(action, t.shortcut());
141 slotForwardSelected(idx);
143 d->mCustomForwardActionMenu->addAction(action);
144 d->mCustomTemplateActions.append(action);
148 case CustomTemplates::TUniversal:
149 action =
new QAction(nameAction, d->mOwnerActionCollection);
150 d->mOwnerActionCollection->addAction(nameActionName, action);
153 slotReplySelected(idx);
155 d->mCustomReplyActionMenu->addAction(action);
156 d->mCustomTemplateActions.append(action);
158 action =
new QAction(nameAction, d->mOwnerActionCollection);
160 slotReplyAllSelected(idx);
162 d->mCustomReplyAllActionMenu->addAction(action);
163 d->mCustomTemplateActions.append(action);
165 action =
new QAction(nameAction, d->mOwnerActionCollection);
167 slotForwardSelected(idx);
169 d->mCustomForwardActionMenu->addAction(action);
170 d->mCustomTemplateActions.append(action);
179 QAction *noAction = d->mCustomReplyActionMenu->menu()->addAction(
i18n(
"(no custom templates)"));
181 d->mCustomReplyActionMenu->setEnabled(
false);
184 QAction *noAction = d->mCustomReplyAllActionMenu->menu()->addAction(
i18n(
"(no custom templates)"));
186 d->mCustomReplyAllActionMenu->setEnabled(
false);
189 QAction *noAction = d->mCustomForwardActionMenu->menu()->addAction(
i18n(
"(no custom templates)"));
191 d->mCustomForwardActionMenu->setEnabled(
false);
195void CustomTemplatesMenu::slotReplySelected(
int idx)
197 Q_EMIT replyTemplateSelected(d->mCustomTemplates.at(idx));
200void CustomTemplatesMenu::slotReplyAllSelected(
int idx)
202 Q_EMIT replyAllTemplateSelected(d->mCustomTemplates.at(idx));
205void CustomTemplatesMenu::slotForwardSelected(
int idx)
207 Q_EMIT forwardTemplateSelected(d->mCustomTemplates.at(idx));
210#include "moc_customtemplatesmenu.cpp"
QString i18n(const char *text, const TYPE &arg...)
void update(Part *part, const QByteArray &data, qint64 dataSize)
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
void triggered(bool checked)
QIcon fromTheme(const QString &name)
const_iterator constBegin() const const
const_iterator constEnd() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)