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