File indexing completed on 2024-05-12 05:14:53

0001 /*
0002  *  pluginbase.h  -  base class for plugin to provide features requiring Akonadi
0003  *  Program:  kalarm
0004  *  SPDX-FileCopyrightText: 2022 David Jarvie <djarvie@kde.org>
0005  *
0006  *  SPDX-License-Identifier: LGPL-2.0-or-later
0007  */
0008 
0009 #pragma once
0010 
0011 #include "kalarmcalendar/kacalendar.h"
0012 #include "kalarmpluginlib_export.h"
0013 
0014 #include <KMime/Message>
0015 
0016 #include <QObject>
0017 
0018 class QUrl;
0019 class QColor;
0020 namespace KMime { class Content; }
0021 namespace KCalendarCore { class Person; }
0022 namespace KIdentityManagementCore { class Identity; }
0023 namespace KAlarmCal { class KAEvent; }
0024 namespace MailSend { struct JobData; }
0025 class QSortFilterProxyModel;
0026 
0027 class KALARMPLUGINLIB_EXPORT PluginBase : public QObject
0028 {
0029     Q_OBJECT
0030 public:
0031     explicit PluginBase(QObject* parent = nullptr, const QList<QVariant>& = {});
0032     ~PluginBase() override;
0033 
0034     QString name() const  { return mName; }
0035 
0036     /** Create birthday model instances. */
0037     virtual QSortFilterProxyModel* createBirthdayModels(QWidget* messageParent, QObject* parent = nullptr) = 0;
0038 
0039     /** Set a new prefix and suffix, and the corresponding selection list. */
0040     virtual void setPrefixSuffix(QSortFilterProxyModel* birthdaySortModel, const QString& prefix, const QString& suffix, const QStringList& alarmMessageList) = 0;
0041 
0042     enum class BirthdayModelValue { NameColumn, DateColumn, DateRole };
0043     /** Return BirthdayModel enum values. */
0044     virtual int birthdayModelEnum(BirthdayModelValue) const = 0;
0045 
0046     /** Send an email using PIM libraries.
0047      *  @return  empty string if sending initiated successfully, else error message.
0048      */
0049     virtual QString sendMail(KMime::Message::Ptr message, const KIdentityManagementCore::Identity& identity,
0050                              const QString& normalizedFrom, bool keepSentMail, MailSend::JobData& jobdata) = 0;
0051 
0052     /** Extract dragged and dropped Akonadi RFC822 message data. */
0053     virtual KMime::Message::Ptr fetchAkonadiEmail(const QUrl&, qint64& emailId) = 0;
0054 
0055     /** Get a single selection from the address book. */
0056     virtual bool getAddressBookSelection(KCalendarCore::Person&, QWidget* parent = nullptr) = 0;
0057 
0058     /** Get the Akonadi Collection ID which contains a given email ID. */
0059     virtual qint64 getCollectionId(qint64 emailId) = 0;
0060 
0061     /** Delete a KOrganizer event. */
0062     virtual void deleteEvent(const QString& mimeType, const QString& gid = {}, const QString& uid = {}) = 0;
0063 
0064     /** Initiate Akonadi resource migration. */
0065     virtual void initiateAkonadiResourceMigration() = 0;
0066 
0067     /** Delete a named Akonadi resource.
0068      *  This should be called after the resource has been migrated.
0069      */
0070     virtual void deleteAkonadiResource(const QString& resourceName) = 0;
0071 
0072 Q_SIGNALS:
0073     /** Emitted when the birthday contacts model's data has changed. */
0074     void birthdayModelDataChanged();
0075 
0076     /** Emitted when an error has occurred sending an email. */
0077     void emailSent(const MailSend::JobData&, const QStringList& errmsgs, bool sendError);
0078 
0079     /** Emitted when an error has occurred sending an email. */
0080     void emailQueued(const KAlarmCal::KAEvent&);
0081 
0082     /** Emitted when Akonadi resource migration has completed.
0083      *  @param migrated  true if Akonadi migration was required.
0084      */
0085     void akonadiMigrationComplete(bool migrated);
0086 
0087     /** Emitted when a file resource needs to be migrated. */
0088     void migrateFileResource(const QString& resourceName, const QUrl& location, KAlarmCal::CalEvent::Types alarmTypes,
0089                              const QString& displayName, const QColor& backgroundColour,
0090                              KAlarmCal::CalEvent::Types enabledTypes, KAlarmCal::CalEvent::Types standardTypes,
0091                              bool readOnly);
0092 
0093     /** Emitted when a directory resource needs to be migrated. */
0094     void migrateDirResource(const QString& resourceName, const QString& path, KAlarmCal::CalEvent::Types alarmTypes,
0095                             const QString& displayName, const QColor& backgroundColour,
0096                             KAlarmCal::CalEvent::Types enabledTypes, KAlarmCal::CalEvent::Types standardTypes,
0097                             bool readOnly);
0098 
0099 
0100 protected:
0101     void setName(const QString& pluginName)  { mName = pluginName; }
0102 
0103 private:
0104     QString mName;
0105 };
0106 
0107 // vim: et sw=4: