1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module peas.Engine; 26 27 private import glib.ConstructionException; 28 private import glib.ListG; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import peas.PluginInfo; 33 private import peas.c.functions; 34 public import peas.c.types; 35 private import std.algorithm; 36 37 38 /** 39 * The #PeasEngine structure contains only private data and should only be 40 * accessed using the provided API. 41 */ 42 public class Engine : ObjectG 43 { 44 /** the main Gtk struct */ 45 protected PeasEngine* peasEngine; 46 47 /** Get the main Gtk struct */ 48 public PeasEngine* getEngineStruct(bool transferOwnership = false) 49 { 50 if (transferOwnership) 51 ownedRef = false; 52 return peasEngine; 53 } 54 55 /** the main Gtk struct as a void* */ 56 protected override void* getStruct() 57 { 58 return cast(void*)peasEngine; 59 } 60 61 /** 62 * Sets our main struct and passes it to the parent class. 63 */ 64 public this (PeasEngine* peasEngine, bool ownedRef = false) 65 { 66 this.peasEngine = peasEngine; 67 super(cast(GObject*)peasEngine, ownedRef); 68 } 69 70 /** 71 * Return a new instance of Engine. 72 * If no default Engine has been instantiated yet, 73 * the first call of this function will set the default 74 * engine as the new instance of Engine. 75 * 76 * Params: 77 * global = Weather to return a global plugin loader 78 * 79 * Return: a new instance of Engine. 80 * 81 * Throws: ConstructionException GTK+ fails to create the object. 82 */ 83 public this(bool global = true) 84 { 85 PeasEngine* p; 86 87 if (global) 88 p = peas_engine_new(); 89 else 90 p = peas_engine_new_with_nonglobal_loaders(); 91 92 if(p is null) 93 { 94 throw new ConstructionException("null returned by new"); 95 } 96 97 this(p, true); 98 } 99 100 /** 101 */ 102 103 /** */ 104 public static GType getType() 105 { 106 return peas_engine_get_type(); 107 } 108 109 /** 110 * Return the existing instance of #PeasEngine or a subclass of it. 111 * If no #PeasEngine subclass has been instantiated yet, the first call 112 * of this function will return a new instance of #PeasEngine. 113 * 114 * Note: this function should never be used when multiple threads are 115 * using libpeas API as it is not thread-safe. 116 * 117 * Returns: the existing instance of #PeasEngine. 118 */ 119 public static Engine getDefault() 120 { 121 auto p = peas_engine_get_default(); 122 123 if(p is null) 124 { 125 return null; 126 } 127 128 return ObjectG.getDObject!(Engine)(cast(PeasEngine*) p); 129 } 130 131 /** 132 * This function appends a search path to the list of paths where to 133 * look for plugins. 134 * 135 * A so-called "search path" actually consists of both a 136 * module directory (where the shared libraries or language modules 137 * lie) and a data directory (where the plugin data is). 138 * 139 * The plugin will be able to use a correct data dir depending on 140 * where it is installed, hence allowing to keep the plugin agnostic 141 * when it comes to installation location: the same plugin can be 142 * installed either in the system path or in the user's home directory, 143 * without taking other special care than using 144 * peas_plugin_info_get_data_dir() when looking for its data files. 145 * 146 * If @data_dir is %NULL, then it is set to the same value as 147 * @module_dir. 148 * 149 * Params: 150 * moduleDir = the plugin module directory. 151 * dataDir = the plugin data directory. 152 */ 153 public void addSearchPath(string moduleDir, string dataDir) 154 { 155 peas_engine_add_search_path(peasEngine, Str.toStringz(moduleDir), Str.toStringz(dataDir)); 156 } 157 158 /** 159 * If the plugin identified by @info implements the @extension_type, 160 * then this function will return a new instance of this implementation, 161 * wrapped in a new #PeasExtension instance. Otherwise, it will return %NULL. 162 * 163 * Since libpeas 1.22, @extension_type can be an Abstract #GType 164 * and not just an Interface #GType. 165 * 166 * See peas_engine_create_extension() for more information. 167 * 168 * Params: 169 * info = A loaded #PeasPluginInfo. 170 * extensionType = The implemented extension #GType. 171 * firstProperty = the name of the first property. 172 * varArgs = the value of the first property, followed optionally by more 173 * name/value pairs, followed by %NULL. 174 * 175 * Returns: a new instance of #PeasExtension wrapping 176 * the @extension_type instance, or %NULL. 177 */ 178 public PeasExtension* createExtensionValist(PluginInfo info, GType extensionType, string firstProperty, void* varArgs) 179 { 180 return peas_engine_create_extension_valist(peasEngine, (info is null) ? null : info.getPluginInfoStruct(), extensionType, Str.toStringz(firstProperty), varArgs); 181 } 182 183 /** 184 * If the plugin identified by @info implements the @extension_type, 185 * then this function will return a new instance of this implementation, 186 * wrapped in a new #PeasExtension instance. Otherwise, it will return %NULL. 187 * 188 * Since libpeas 1.22, @extension_type can be an Abstract #GType 189 * and not just an Interface #GType. 190 * 191 * See peas_engine_create_extension() for more information. 192 * 193 * Params: 194 * info = A loaded #PeasPluginInfo. 195 * extensionType = The implemented extension #GType. 196 * parameters = an array of #GParameter. 197 * 198 * Returns: a new instance of #PeasExtension wrapping 199 * the @extension_type instance, or %NULL. 200 */ 201 public PeasExtension* createExtensionv(PluginInfo info, GType extensionType, GParameter[] parameters) 202 { 203 return peas_engine_create_extensionv(peasEngine, (info is null) ? null : info.getPluginInfoStruct(), extensionType, cast(uint)parameters.length, parameters.ptr); 204 } 205 206 /** 207 * Enable a loader, enables a loader for plugins. 208 * The C plugin loader is always enabled. The other plugin 209 * loaders are: lua5.1, python and python3. 210 * 211 * For instance, the following code will enable Python 2 plugins 212 * to be loaded: 213 * |[ 214 * peas_engine_enable_loader (engine, "python"); 215 * ]| 216 * 217 * Note: plugin loaders used to be shared across #PeasEngines so enabling 218 * a loader on one #PeasEngine would enable it on all #PeasEngines. 219 * This behavior has been kept to avoid breaking applications, 220 * however a warning has been added to help applications transition. 221 * 222 * Params: 223 * loaderName = The name of the loader to enable. 224 */ 225 public void enableLoader(string loaderName) 226 { 227 peas_engine_enable_loader(peasEngine, Str.toStringz(loaderName)); 228 } 229 230 /** 231 * This function triggers garbage collection on all the loaders currently 232 * owned by the #PeasEngine. This can be used to force the loaders to destroy 233 * managed objects that still hold references to objects that are about to 234 * disappear. 235 */ 236 public void garbageCollect() 237 { 238 peas_engine_garbage_collect(peasEngine); 239 } 240 241 /** 242 * Returns the list of the names of all the loaded plugins, or an array 243 * containing a single %NULL element if there is no plugin currently loaded. 244 * 245 * Please note that the returned array is a newly allocated one: you will need 246 * to free it using g_strfreev(). 247 * 248 * Returns: A newly-allocated 249 * %NULL-terminated array of strings. 250 */ 251 public string[] getLoadedPlugins() 252 { 253 auto retStr = peas_engine_get_loaded_plugins(peasEngine); 254 255 scope(exit) Str.freeStringArray(retStr); 256 return Str.toStringArray(retStr); 257 } 258 259 /** 260 * Gets the #PeasPluginInfo corresponding with @plugin_name, 261 * or %NULL if @plugin_name was not found. 262 * 263 * Params: 264 * pluginName = A plugin name. 265 * 266 * Returns: the #PeasPluginInfo corresponding with 267 * a given plugin module name. 268 */ 269 public PluginInfo getPluginInfo(string pluginName) 270 { 271 auto p = peas_engine_get_plugin_info(peasEngine, Str.toStringz(pluginName)); 272 273 if(p is null) 274 { 275 return null; 276 } 277 278 return ObjectG.getDObject!(PluginInfo)(cast(PeasPluginInfo*) p); 279 } 280 281 /** 282 * Returns the list of #PeasPluginInfo known to the engine. 283 * 284 * Returns: a #GList of 285 * #PeasPluginInfo. Note that the list belongs to the engine and should 286 * not be freed. 287 */ 288 public ListG getPluginList() 289 { 290 auto p = peas_engine_get_plugin_list(peasEngine); 291 292 if(p is null) 293 { 294 return null; 295 } 296 297 return new ListG(cast(GList*) p); 298 } 299 300 /** 301 * Loads the plugin corresponding to @info if it's not currently loaded. 302 * Emits the "load-plugin" signal; loading the plugin 303 * actually occurs in the default signal handler. 304 * 305 * Params: 306 * info = A #PeasPluginInfo. 307 * 308 * Returns: whether the plugin has been successfully loaded. 309 */ 310 public bool loadPlugin(PluginInfo info) 311 { 312 return peas_engine_load_plugin(peasEngine, (info is null) ? null : info.getPluginInfoStruct()) != 0; 313 } 314 315 /** 316 * This function prepends a search path to the list of paths where to 317 * look for plugins. 318 * 319 * See Also: peas_engine_add_search_path() 320 * 321 * Params: 322 * moduleDir = the plugin module directory. 323 * dataDir = the plugin data directory. 324 * 325 * Since: 1.6 326 */ 327 public void prependSearchPath(string moduleDir, string dataDir) 328 { 329 peas_engine_prepend_search_path(peasEngine, Str.toStringz(moduleDir), Str.toStringz(dataDir)); 330 } 331 332 /** 333 * Returns if @info provides an extension for @extension_type. 334 * If the @info is not loaded than %FALSE will always be returned. 335 * 336 * Since libpeas 1.22, @extension_type can be an Abstract #GType 337 * and not just an Interface #GType. 338 * 339 * Params: 340 * info = A #PeasPluginInfo. 341 * extensionType = The extension #GType. 342 * 343 * Returns: if @info provides an extension for @extension_type. 344 */ 345 public bool providesExtension(PluginInfo info, GType extensionType) 346 { 347 return peas_engine_provides_extension(peasEngine, (info is null) ? null : info.getPluginInfoStruct(), extensionType) != 0; 348 } 349 350 /** 351 * Rescan all the registered directories to find new or updated plugins. 352 * 353 * Calling this function will make the newly installed plugin infos 354 * be loaded by the engine, so the new plugins can be used without 355 * restarting the application. 356 */ 357 public void rescanPlugins() 358 { 359 peas_engine_rescan_plugins(peasEngine); 360 } 361 362 /** 363 * Sets the list of loaded plugins for @engine. When this function is called, 364 * the #PeasEngine will load all the plugins whose names are in @plugin_names, 365 * and ensures all other active plugins are unloaded. 366 * 367 * If @plugin_names is %NULL, all plugins will be unloaded. 368 * 369 * Params: 370 * pluginNames = A %NULL-terminated 371 * array of plugin names, or %NULL. 372 */ 373 public void setLoadedPlugins(string[] pluginNames) 374 { 375 peas_engine_set_loaded_plugins(peasEngine, Str.toStringzArray(pluginNames)); 376 } 377 378 /** 379 * Unloads the plugin corresponding to @info. 380 * Emits the "unload-plugin" signal; unloading the plugin 381 * actually occurs in the default signal handler. 382 * 383 * Params: 384 * info = A #PeasPluginInfo. 385 * 386 * Returns: whether the plugin has been successfully unloaded. 387 */ 388 public bool unloadPlugin(PluginInfo info) 389 { 390 return peas_engine_unload_plugin(peasEngine, (info is null) ? null : info.getPluginInfoStruct()) != 0; 391 } 392 393 /** 394 * The load-plugin signal is emitted when a plugin is being loaded. 395 * 396 * The plugin is being loaded in the default handler. Hence, if you want to 397 * perform some action before the plugin is loaded, you should use 398 * g_signal_connect(), but if you want to perform some action *after* the 399 * plugin is loaded (the most common case), you should use 400 * g_signal_connect_after(). 401 * 402 * Params: 403 * info = A #PeasPluginInfo. 404 */ 405 gulong addOnLoadPlugin(void delegate(PluginInfo, Engine) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 406 { 407 return Signals.connect(this, "load-plugin", dlg, connectFlags ^ ConnectFlags.SWAPPED); 408 } 409 410 /** 411 * The unload-plugin signal is emitted when a plugin is being unloaded. 412 * 413 * The plugin is being unloaded in the default handler. Hence, if you want 414 * to perform some action before the plugin is unloaded (the most common 415 * case), you should use g_signal_connect(), but if you want to perform some 416 * action after the plugin is unloaded (the most common case), you should 417 * use g_signal_connect_after(). 418 * 419 * Params: 420 * info = A #PeasPluginInfo. 421 */ 422 gulong addOnUnloadPlugin(void delegate(PluginInfo, Engine) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 423 { 424 return Signals.connect(this, "unload-plugin", dlg, connectFlags ^ ConnectFlags.SWAPPED); 425 } 426 }