1 /* 2 * plugin: A plugin class managing loading the shared object as well as 3 * initializing and setting up extensions to this application 4 * 5 * Copyright 2012-2020 Stephan Haller <nomad@froevel.de> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 20 * MA 02110-1301, USA. 21 * 22 * 23 */ 24 25 #ifndef __LIBXFDASHBOARD_PLUGIN__ 26 #define __LIBXFDASHBOARD_PLUGIN__ 27 28 #if !defined(__LIBXFDASHBOARD_H_INSIDE__) && !defined(LIBXFDASHBOARD_COMPILATION) 29 #error "Only <libxfdashboard/libxfdashboard.h> can be included directly." 30 #endif 31 32 #include <glib-object.h> 33 #include <gmodule.h> 34 35 G_BEGIN_DECLS 36 37 /* Public definitions */ 38 /** 39 * XfdashboardPluginFlag: 40 * @XFDASHBOARD_PLUGIN_FLAG_NONE: Plugin does not request anything special. 41 * @XFDASHBOARD_PLUGIN_FLAG_EARLY_INITIALIZATION: Plugin requests to get enabled before the stage is initialized 42 * 43 * Flags defining behaviour of this XfdashboardPlugin. 44 */ 45 typedef enum /*< flags,prefix=XFDASHBOARD_PLUGIN_FLAG >*/ 46 { 47 XFDASHBOARD_PLUGIN_FLAG_NONE=0, 48 49 XFDASHBOARD_PLUGIN_FLAG_EARLY_INITIALIZATION=1 << 0, 50 } XfdashboardPluginFlag; 51 52 53 /* Helper macros to declare, define and register GObject types in plugins */ 54 #define XFDASHBOARD_DECLARE_PLUGIN_TYPE(inFunctionNamePrefix) \ 55 void inFunctionNamePrefix##_register_plugin_type(XfdashboardPlugin *inPlugin); 56 57 #define XFDASHBOARD_DEFINE_PLUGIN_TYPE(inFunctionNamePrefix) \ 58 void inFunctionNamePrefix##_register_plugin_type(XfdashboardPlugin *inPlugin) \ 59 { \ 60 inFunctionNamePrefix##_register_type(G_TYPE_MODULE(inPlugin)); \ 61 } 62 63 #define XFDASHBOARD_REGISTER_PLUGIN_TYPE(self, inFunctionNamePrefix) \ 64 inFunctionNamePrefix##_register_plugin_type(XFDASHBOARD_PLUGIN(self)); 65 66 67 /* Object declaration */ 68 #define XFDASHBOARD_TYPE_PLUGIN (xfdashboard_plugin_get_type()) 69 #define XFDASHBOARD_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XFDASHBOARD_TYPE_PLUGIN, XfdashboardPlugin)) 70 #define XFDASHBOARD_IS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XFDASHBOARD_TYPE_PLUGIN)) 71 #define XFDASHBOARD_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XFDASHBOARD_TYPE_PLUGIN, XfdashboardPluginClass)) 72 #define XFDASHBOARD_IS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), XFDASHBOARD_TYPE_PLUGIN)) 73 #define XFDASHBOARD_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XFDASHBOARD_TYPE_PLUGIN, XfdashboardPluginClass)) 74 75 typedef struct _XfdashboardPlugin XfdashboardPlugin; 76 typedef struct _XfdashboardPluginClass XfdashboardPluginClass; 77 typedef struct _XfdashboardPluginPrivate XfdashboardPluginPrivate; 78 79 struct _XfdashboardPlugin 80 { 81 /*< private >*/ 82 /* Parent instance */ 83 GTypeModule parent_instance; 84 85 /* Private structure */ 86 XfdashboardPluginPrivate *priv; 87 }; 88 89 struct _XfdashboardPluginClass 90 { 91 /*< private >*/ 92 /* Parent class */ 93 GTypeModuleClass parent_class; 94 95 /*< public >*/ 96 /* Virtual functions */ 97 void (*enable)(XfdashboardPlugin *self); 98 void (*disable)(XfdashboardPlugin *self); 99 100 GObject* (*configure)(XfdashboardPlugin *self); 101 }; 102 103 /* Error */ 104 #define XFDASHBOARD_PLUGIN_ERROR (xfdashboard_plugin_error_quark()) 105 106 GQuark xfdashboard_plugin_error_quark(void); 107 108 typedef enum /*< prefix=XFDASHBOARD_PLUGIN_ERROR >*/ 109 { 110 XFDASHBOARD_PLUGIN_ERROR_NONE, 111 XFDASHBOARD_PLUGIN_ERROR_ERROR, 112 } XfdashboardPluginErrorEnum; 113 114 /* Public API */ 115 GType xfdashboard_plugin_get_type(void) G_GNUC_CONST; 116 117 XfdashboardPlugin* xfdashboard_plugin_new(const gchar *inPluginFilename, GError **outError); 118 119 const gchar* xfdashboard_plugin_get_id(XfdashboardPlugin *self); 120 XfdashboardPluginFlag xfdashboard_plugin_get_flags(XfdashboardPlugin *self); 121 122 void xfdashboard_plugin_set_info(XfdashboardPlugin *self, 123 const gchar *inFirstPropertyName, ...) 124 G_GNUC_NULL_TERMINATED; 125 126 gboolean xfdashboard_plugin_is_enabled(XfdashboardPlugin *self); 127 void xfdashboard_plugin_enable(XfdashboardPlugin *self); 128 void xfdashboard_plugin_disable(XfdashboardPlugin *self); 129 130 const gchar* xfdashboard_plugin_get_config_path(XfdashboardPlugin *self); 131 const gchar* xfdashboard_plugin_get_cache_path(XfdashboardPlugin *self); 132 const gchar* xfdashboard_plugin_get_data_path(XfdashboardPlugin *self); 133 134 G_END_DECLS 135 136 #endif /* __LIBXFDASHBOARD_PLUGIN__ */ 137