File indexing completed on 2025-01-05 04:49:46
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "viewerplugincreateeventinterface.h" 0008 #include "createeventjob.h" 0009 #include "eventedit.h" 0010 #include <KLocalizedString> 0011 0012 #include <KActionCollection> 0013 #include <QAction> 0014 #include <QIcon> 0015 #include <QLayout> 0016 0017 using namespace MessageViewer; 0018 0019 ViewerPluginCreateEventInterface::ViewerPluginCreateEventInterface(KActionCollection *ac, QWidget *parent) 0020 : ViewerPluginInterface(parent) 0021 { 0022 createAction(ac); 0023 } 0024 0025 ViewerPluginCreateEventInterface::~ViewerPluginCreateEventInterface() = default; 0026 0027 ViewerPluginInterface::SpecificFeatureTypes ViewerPluginCreateEventInterface::featureTypes() const 0028 { 0029 return ViewerPluginInterface::NeedMessage; 0030 } 0031 0032 void ViewerPluginCreateEventInterface::setText(const QString &text) 0033 { 0034 Q_UNUSED(text) 0035 // Nothing 0036 } 0037 0038 QList<QAction *> ViewerPluginCreateEventInterface::actions() const 0039 { 0040 return mAction; 0041 } 0042 0043 void ViewerPluginCreateEventInterface::setMessage(const KMime::Message::Ptr &value) 0044 { 0045 widget()->setMessage(value); 0046 } 0047 0048 void ViewerPluginCreateEventInterface::closePlugin() 0049 { 0050 if (mEventEdit) { 0051 mEventEdit->slotCloseWidget(); 0052 } 0053 } 0054 0055 void ViewerPluginCreateEventInterface::showWidget() 0056 { 0057 widget()->showEventEdit(); 0058 } 0059 0060 void ViewerPluginCreateEventInterface::setMessageItem(const Akonadi::Item &item) 0061 { 0062 mMessageItem = item; 0063 } 0064 0065 void ViewerPluginCreateEventInterface::createAction(KActionCollection *ac) 0066 { 0067 if (ac) { 0068 auto act = new QAction(QIcon::fromTheme(QStringLiteral("appointment-new")), i18n("Create Event..."), this); 0069 act->setIconText(i18n("Create Event")); 0070 addHelpTextAction(act, i18n("Allows you to create a calendar Event")); 0071 ac->addAction(QStringLiteral("create_event"), act); 0072 ac->setDefaultShortcut(act, QKeySequence(Qt::CTRL | Qt::Key_E)); 0073 connect(act, &QAction::triggered, this, &ViewerPluginCreateEventInterface::slotActivatePlugin); 0074 mAction.append(act); 0075 } 0076 } 0077 0078 EventEdit *ViewerPluginCreateEventInterface::widget() 0079 { 0080 if (!mEventEdit) { 0081 auto parentWidget = static_cast<QWidget *>(parent()); 0082 mEventEdit = new EventEdit(parentWidget); 0083 connect(mEventEdit, &EventEdit::createEvent, this, &ViewerPluginCreateEventInterface::slotCreateEvent); 0084 mEventEdit->setObjectName(QLatin1StringView("eventedit")); 0085 parentWidget->layout()->addWidget(mEventEdit); 0086 mEventEdit->hide(); 0087 } 0088 return mEventEdit; 0089 } 0090 0091 void ViewerPluginCreateEventInterface::slotCreateEvent(const KCalendarCore::Event::Ptr &eventPtr, const Akonadi::Collection &collection) 0092 { 0093 auto createJob = new CreateEventJob(eventPtr, collection, mMessageItem, this); 0094 createJob->start(); 0095 } 0096 0097 #include "moc_viewerplugincreateeventinterface.cpp"