File indexing completed on 2024-05-12 16:59:20
0001 /* 0002 * SPDX-FileCopyrightText: 2011-2016 Ivan Cukic <ivan.cukic@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #ifndef PLUGIN_H 0008 #define PLUGIN_H 0009 0010 #include "kactivitymanagerd_plugin_export.h" 0011 0012 // Qt 0013 #include <QMetaObject> 0014 #include <QObject> 0015 0016 // KDE 0017 #include <kconfiggroup.h> 0018 #include <kpluginfactory.h> 0019 0020 // Utils 0021 #include <utils/d_ptr.h> 0022 0023 // Local 0024 #include "Event.h" 0025 #include "Module.h" 0026 0027 /** 0028 * 0029 */ 0030 class KACTIVITYMANAGERD_PLUGIN_EXPORT Plugin : public Module 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 explicit Plugin(QObject *parent); 0036 ~Plugin() override; 0037 0038 /** 0039 * Initializes the plugin. 0040 * @arg modules Activities, Resources and Features manager objects 0041 * @returns the plugin needs to return whether it has 0042 * successfully been initialized 0043 */ 0044 virtual bool init(QHash<QString, QObject *> &modules) = 0; 0045 0046 /** 0047 * Returns the config group for the plugin. 0048 * In order to use it, you need to set the plugin name. 0049 */ 0050 KConfigGroup config() const; 0051 QString name() const; 0052 0053 /** 0054 * Convenience meta-method to provide prettier invocation of QMetaObject::invokeMethod 0055 */ 0056 // template <typename ReturnType> 0057 // inline static ReturnType retrieve(QObject *object, const char *method, 0058 // const char *returnTypeName) 0059 // { 0060 // ReturnType result; 0061 // 0062 // QMetaObject::invokeMethod( 0063 // object, method, Qt::DirectConnection, 0064 // QReturnArgument<ReturnType>(returnTypeName, result)); 0065 // 0066 // return result; 0067 // } 0068 0069 template<typename ReturnType, typename... Args> 0070 inline static ReturnType retrieve(QObject *object, const char *method, const char *returnTypeName, Args... args) 0071 { 0072 ReturnType result; 0073 0074 QMetaObject::invokeMethod(object, method, Qt::DirectConnection, QReturnArgument<ReturnType>(returnTypeName, result), args...); 0075 0076 return result; 0077 } 0078 0079 /** 0080 * Convenience meta-method to provide prettier invocation of QMetaObject::invokeMethod 0081 */ 0082 // template <Qt::ConnectionType connection = Qt::QueuedConnection> 0083 // inline static void invoke(QObject *object, const char *method, 0084 // const char *returnTypeName) 0085 // { 0086 // Q_UNUSED(returnTypeName); 0087 // QMetaObject::invokeMethod(object, method, connection); 0088 // } 0089 0090 template<Qt::ConnectionType connection, typename... Args> 0091 inline static void invoke(QObject *object, const char *method, Args... args) 0092 { 0093 QMetaObject::invokeMethod(object, method, connection, args...); 0094 } 0095 0096 protected: 0097 void setName(const QString &name); 0098 0099 private: 0100 D_PTR; 0101 }; 0102 0103 #endif // PLUGIN_H