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 "viewerplugincreatetodointerface.h" 0008 #include "createtodojob.h" 0009 #include "todoedit.h" 0010 0011 #include <KLocalizedString> 0012 0013 #include <KActionCollection> 0014 #include <QAction> 0015 #include <QLayout> 0016 0017 using namespace MessageViewer; 0018 0019 ViewerPluginCreateTodoInterface::ViewerPluginCreateTodoInterface(KActionCollection *ac, QWidget *parent) 0020 : ViewerPluginInterface(parent) 0021 { 0022 createAction(ac); 0023 } 0024 0025 ViewerPluginCreateTodoInterface::~ViewerPluginCreateTodoInterface() = default; 0026 0027 void ViewerPluginCreateTodoInterface::setText(const QString &text) 0028 { 0029 Q_UNUSED(text) 0030 // Nothing 0031 } 0032 0033 QList<QAction *> ViewerPluginCreateTodoInterface::actions() const 0034 { 0035 return mAction; 0036 } 0037 0038 void ViewerPluginCreateTodoInterface::setMessage(const KMime::Message::Ptr &value) 0039 { 0040 widget()->setMessage(value); 0041 } 0042 0043 void ViewerPluginCreateTodoInterface::closePlugin() 0044 { 0045 if (mTodoEdit) { 0046 mTodoEdit->slotCloseWidget(); 0047 } 0048 } 0049 0050 void ViewerPluginCreateTodoInterface::showWidget() 0051 { 0052 widget()->showToDoWidget(); 0053 } 0054 0055 void ViewerPluginCreateTodoInterface::setMessageItem(const Akonadi::Item &item) 0056 { 0057 mMessageItem = item; 0058 } 0059 0060 ViewerPluginInterface::SpecificFeatureTypes ViewerPluginCreateTodoInterface::featureTypes() const 0061 { 0062 return ViewerPluginInterface::NeedMessage; 0063 } 0064 0065 void ViewerPluginCreateTodoInterface::createAction(KActionCollection *ac) 0066 { 0067 if (ac) { 0068 auto act = new QAction(QIcon::fromTheme(QStringLiteral("task-new")), i18n("Create To-do"), this); 0069 act->setIconText(i18n("Create To-do")); 0070 addHelpTextAction(act, i18n("Allows you to create a calendar to-do or reminder from this message")); 0071 act->setWhatsThis( 0072 i18n("This option starts the KOrganizer to-do editor with initial values taken from the currently selected message. Then you can edit the to-do to " 0073 "your liking before saving it to your calendar.")); 0074 ac->addAction(QStringLiteral("create_todo"), act); 0075 ac->setDefaultShortcut(act, QKeySequence(Qt::CTRL | Qt::Key_T)); 0076 connect(act, &QAction::triggered, this, &ViewerPluginCreateTodoInterface::slotActivatePlugin); 0077 mAction.append(act); 0078 } 0079 } 0080 0081 void ViewerPluginCreateTodoInterface::slotCreateTodo(const KCalendarCore::Todo::Ptr &todoPtr, const Akonadi::Collection &collection) 0082 { 0083 auto createJob = new CreateTodoJob(todoPtr, collection, mMessageItem, this); 0084 createJob->start(); 0085 } 0086 0087 TodoEdit *ViewerPluginCreateTodoInterface::widget() 0088 { 0089 if (!mTodoEdit) { 0090 auto parentWidget = static_cast<QWidget *>(parent()); 0091 mTodoEdit = new TodoEdit(parentWidget); 0092 connect(mTodoEdit, &TodoEdit::createTodo, this, &ViewerPluginCreateTodoInterface::slotCreateTodo); 0093 mTodoEdit->setObjectName(QLatin1StringView("todoedit")); 0094 parentWidget->layout()->addWidget(mTodoEdit); 0095 mTodoEdit->hide(); 0096 } 0097 return mTodoEdit; 0098 } 0099 0100 void MessageViewer::ViewerPluginCreateTodoInterface::setCurrentCollection(const Akonadi::Collection &col) 0101 { 0102 widget()->setCurrentCollection(col); 0103 } 0104 0105 #include "moc_viewerplugincreatetodointerface.cpp"