1 /* 2 * This file is a part of the Cairo-Dock project 3 * 4 * Copyright : (C) see the 'copyright' file. 5 * E-mail : see the 'copyright' file. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 3 10 * of the License, or (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 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef __GLDI_MODULES_MANAGER__ 21 #define __GLDI_MODULES_MANAGER__ 22 23 #include "cairo-dock-struct.h" 24 #include "cairo-dock-desklet-factory.h" // CairoDeskletAttribute 25 #include "cairo-dock-manager.h" 26 G_BEGIN_DECLS 27 28 /** 29 * @file cairo-dock-module-manager.h This class manages the external modules of Cairo-Dock. 30 * 31 * A module has an interface and a visit card : 32 * - the visit card allows it to define itself (name, category, default icon, etc) 33 * - the interface defines the entry points for init, stop, reload, read config, and reset data. 34 * 35 * Modules can be instanciated several times; each time they are, an instance \ref _GldiModuleInstance is created. 36 * Each instance holds a set of data: the icon and its container, the config structure and its conf file, the data structure and a slot to plug datas into containers and icons. All these data are optionnal; a module that has an icon is also called an applet. 37 */ 38 39 // manager 40 typedef struct _GldiModulesParam GldiModulesParam; 41 typedef struct _GldiModuleAttr GldiModuleAttr; 42 43 #ifndef _MANAGER_DEF_ 44 extern GldiModulesParam myModulesParam; 45 extern GldiManager myModulesMgr; 46 extern GldiObjectManager myModuleObjectMgr; 47 #endif 48 49 50 struct _GldiModuleAttr { 51 GldiVisitCard *pVisitCard; 52 GldiModuleInterface *pInterface; 53 }; 54 55 // params 56 struct _GldiModulesParam { 57 gchar **cActiveModuleList; 58 }; 59 60 // signals 61 typedef enum { 62 NOTIFICATION_MODULE_REGISTERED = NB_NOTIFICATIONS_OBJECT, 63 NOTIFICATION_MODULE_ACTIVATED, 64 NOTIFICATION_LOGOUT, 65 NB_NOTIFICATIONS_MODULES 66 } GldiModuleNotifications; 67 68 69 /// Categories a module can be in. 70 typedef enum { 71 CAIRO_DOCK_CATEGORY_BEHAVIOR=0, 72 CAIRO_DOCK_CATEGORY_THEME, 73 CAIRO_DOCK_CATEGORY_APPLET_FILES, 74 CAIRO_DOCK_CATEGORY_APPLET_INTERNET, 75 CAIRO_DOCK_CATEGORY_APPLET_DESKTOP, 76 CAIRO_DOCK_CATEGORY_APPLET_ACCESSORY, 77 CAIRO_DOCK_CATEGORY_APPLET_SYSTEM, 78 CAIRO_DOCK_CATEGORY_APPLET_FUN, 79 CAIRO_DOCK_NB_CATEGORY 80 } GldiModuleCategory; 81 82 typedef enum { 83 CAIRO_DOCK_MODULE_IS_PLUGIN = 0, 84 CAIRO_DOCK_MODULE_CAN_DOCK = 1<<0, 85 CAIRO_DOCK_MODULE_CAN_DESKLET = 1<<1, 86 CAIRO_DOCK_MODULE_CAN_OTHERS = 1<<2 87 } GldiModuleContainerType; 88 89 /// Definition of the visit card of a module. Contains everything that is statically defined for a module. 90 struct _GldiVisitCard { 91 // nom du module qui servira a l'identifier. 92 const gchar *cModuleName; 93 // numero de version majeure de cairo-dock necessaire au bon fonctionnement du module. 94 gint iMajorVersionNeeded; 95 // numero de version mineure de cairo-dock necessaire au bon fonctionnement du module. 96 gint iMinorVersionNeeded; 97 // numero de version micro de cairo-dock necessaire au bon fonctionnement du module. 98 gint iMicroVersionNeeded; 99 // chemin d'une image de previsualisation. 100 const gchar *cPreviewFilePath; 101 // Nom du domaine pour la traduction du module par 'gettext'. 102 const gchar *cGettextDomain; 103 // Version du dock pour laquelle a ete compilee le module. 104 const gchar *cDockVersionOnCompilation; 105 // version courante du module. 106 const gchar *cModuleVersion; 107 // repertoire du plug-in cote utilisateur. 108 const gchar *cUserDataDir; 109 // repertoire d'installation du plug-in. 110 const gchar *cShareDataDir; 111 // nom de son fichier de conf. 112 const gchar *cConfFileName; 113 // categorie de l'applet. 114 GldiModuleCategory iCategory; 115 // chemin d'une image pour l'icone du module dans le panneau de conf du dock. 116 const gchar *cIconFilePath; 117 // taille de la structure contenant la config du module. 118 gint iSizeOfConfig; 119 // taille de la structure contenant les donnees du module. 120 gint iSizeOfData; 121 // VRAI ssi le plug-in peut etre instancie plusiers fois. 122 gboolean bMultiInstance; 123 // description et mode d'emploi succint. 124 const gchar *cDescription; 125 // auteur/pseudo 126 const gchar *cAuthor; 127 // nom d'un module interne auquel ce module se rattache, ou NULL si aucun. 128 const gchar *cInternalModule; 129 // nom du module tel qu'affiche a l'utilisateur. 130 const gchar *cTitle; 131 GldiModuleContainerType iContainerType; 132 gboolean bStaticDeskletSize; 133 // whether to display the applet's name on the icon's label if it's NULL or not. 134 gboolean bAllowEmptyTitle; 135 // if TRUE and the applet inhibites a class, then appli icons will be placed after the applet icon. 136 gboolean bActAsLauncher; 137 gpointer reserved[2]; 138 }; 139 140 /// Definition of the interface of a module. 141 struct _GldiModuleInterface { 142 void (* initModule) (GldiModuleInstance *pInstance, GKeyFile *pKeyFile); 143 void (* stopModule) (GldiModuleInstance *pInstance); 144 gboolean (* reloadModule) (GldiModuleInstance *pInstance, GldiContainer *pOldContainer, GKeyFile *pKeyFile); 145 gboolean (* read_conf_file) (GldiModuleInstance *pInstance, GKeyFile *pKeyFile); 146 void (* reset_config) (GldiModuleInstance *pInstance); 147 void (* reset_data) (GldiModuleInstance *pInstance); 148 void (* load_custom_widget) (GldiModuleInstance *pInstance, GKeyFile *pKeyFile, GSList *pWidgetList); 149 void (* save_custom_widget) (GldiModuleInstance *pInstance, GKeyFile *pKeyFile, GSList *pWidgetList); 150 }; 151 152 /// Pre-init function of a module. Fills the visit card and the interface of a module. 153 typedef gboolean (* GldiModulePreInit) (GldiVisitCard *pVisitCard, GldiModuleInterface *pInterface); 154 155 /// Definition of an external module. 156 struct _GldiModule { 157 /// object 158 GldiObject object; 159 /// interface of the module. 160 GldiModuleInterface *pInterface; 161 /// visit card of the module. 162 GldiVisitCard *pVisitCard; 163 /// conf file of the module. 164 gchar *cConfFilePath; 165 /// if the module interface is provided by a dynamic library, handle to this library. 166 gpointer handle; 167 /// list of instances of the module. 168 GList *pInstancesList; 169 gpointer reserved[2]; 170 }; 171 172 struct _CairoDockMinimalAppletConfig { 173 gint iDesiredIconWidth; 174 gint iDesiredIconHeight; 175 gchar *cLabel; 176 gchar *cIconFileName; 177 gdouble fOrder; 178 gchar *cDockName; 179 gboolean bAlwaysVisible; 180 GldiColor *pHiddenBgColor; 181 CairoDeskletAttr deskletAttribute; 182 gboolean bIsDetached; 183 }; 184 185 /** Say if an object is a Module. 186 *@param obj the object. 187 *@return TRUE if the object is a Module. 188 */ 189 #define GLDI_OBJECT_IS_MODULE(obj) gldi_object_is_manager_child (GLDI_OBJECT(obj), &myModuleObjectMgr) 190 191 /////////////////// 192 // MODULE LOADER // 193 /////////////////// 194 195 #define gldi_module_is_auto_loaded(pModule) (pModule->pInterface->initModule == NULL || pModule->pInterface->stopModule == NULL || pModule->pVisitCard->cInternalModule != NULL) 196 197 /** Create a new module. The module takes ownership of the 2 arguments, unless an error occured. 198 * @param pVisitCard the visit card of the module 199 * @param pInterface the interface of the module 200 * @return the new module, or NULL if the visit card is invalid. 201 */ 202 GldiModule *gldi_module_new (GldiVisitCard *pVisitCard, GldiModuleInterface *pInterface); 203 204 /** Create a new module from a .so file. 205 * @param cSoFilePath path to the .so file 206 * @return the new module, or NULL if an error occured. 207 */ 208 GldiModule *gldi_module_new_from_so_file (const gchar *cSoFilePath); 209 210 /** Create new modules from all the .so files contained in the given folder. 211 * @param cModuleDirPath path to the folder 212 * @param erreur an error 213 * @return the new module, or NULL if an error occured. 214 */ 215 void gldi_modules_new_from_directory (const gchar *cModuleDirPath, GError **erreur); 216 217 /** Get the path to the folder containing the config files of a module (one file per instance). The folder is created if needed. 218 * If the module is not configurable, or if the folder couldn't be created, NULL is returned. 219 * @param pModule the module 220 * @return the path to the folder (free it after use). 221 */ 222 gchar *gldi_module_get_config_dir (GldiModule *pModule); 223 224 void cairo_dock_free_visit_card (GldiVisitCard *pVisitCard); 225 226 227 ///////////// 228 // MANAGER // 229 ///////////// 230 231 /** Get the module which has a given name. 232 *@param cModuleName the unique name of the module. 233 *@return the module, or NULL if not found. 234 */ 235 GldiModule *gldi_module_get (const gchar *cModuleName); 236 237 GldiModule *gldi_module_foreach (GHRFunc pCallback, gpointer user_data); 238 239 GldiModule *gldi_module_foreach_in_alphabetical_order (GCompareFunc pCallback, gpointer user_data); 240 241 int gldi_module_get_nb (void); 242 #define cairo_dock_get_nb_modules gldi_module_get_nb 243 244 void gldi_modules_write_active (void); 245 246 247 /////////////////////// 248 // MODULES HIGH LEVEL// 249 /////////////////////// 250 251 /** Create and initialize all the instances of a module. 252 *@param module the module to activate. 253 */ 254 void gldi_module_activate (GldiModule *module); 255 256 /** Stop and destroy all the instances of a module. 257 *@param module the module to deactivate 258 */ 259 void gldi_module_deactivate (GldiModule *module); 260 261 void gldi_modules_activate_from_list (gchar **cActiveModuleList); 262 263 void gldi_modules_deactivate_all (void); 264 265 // cp file 266 gchar *gldi_module_add_conf_file (GldiModule *pModule); /// should maybe be in the module-instance too... 267 // cp file + instanciate_module 268 void gldi_module_add_instance (GldiModule *pModule); 269 270 271 void gldi_register_modules_manager (void); 272 273 G_END_DECLS 274 #endif 275