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.ExtensionSet; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import peas.Engine; 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 #PeasExtensionSet structure contains only private data and should only 40 * be accessed using the provided API. 41 */ 42 public class ExtensionSet : ObjectG 43 { 44 /** the main Gtk struct */ 45 protected PeasExtensionSet* peasExtensionSet; 46 47 /** Get the main Gtk struct */ 48 public PeasExtensionSet* getExtensionSetStruct(bool transferOwnership = false) 49 { 50 if (transferOwnership) 51 ownedRef = false; 52 return peasExtensionSet; 53 } 54 55 /** the main Gtk struct as a void* */ 56 protected override void* getStruct() 57 { 58 return cast(void*)peasExtensionSet; 59 } 60 61 /** 62 * Sets our main struct and passes it to the parent class. 63 */ 64 public this (PeasExtensionSet* peasExtensionSet, bool ownedRef = false) 65 { 66 this.peasExtensionSet = peasExtensionSet; 67 super(cast(GObject*)peasExtensionSet, ownedRef); 68 } 69 70 71 /** */ 72 public static GType getType() 73 { 74 return peas_extension_set_get_type(); 75 } 76 77 /** 78 * Create a new #PeasExtensionSet for the @exten_type extension type. 79 * 80 * If @engine is %NULL, then the default engine will be used. 81 * 82 * Since libpeas 1.22, @exten_type can be an Abstract #GType 83 * and not just an Interface #GType. 84 * 85 * See peas_extension_set_new() for more information. 86 * 87 * Params: 88 * engine = A #PeasEngine, or %NULL. 89 * extenType = the extension #GType. 90 * firstProperty = the name of the first property. 91 * varArgs = the value of the first property, followed optionally by more 92 * name/value pairs, followed by %NULL. 93 * 94 * Returns: a new instance of #PeasExtensionSet. 95 * 96 * Throws: ConstructionException GTK+ fails to create the object. 97 */ 98 public this(Engine engine, GType extenType, string firstProperty, void* varArgs) 99 { 100 auto p = peas_extension_set_new_valist((engine is null) ? null : engine.getEngineStruct(), extenType, Str.toStringz(firstProperty), varArgs); 101 102 if(p is null) 103 { 104 throw new ConstructionException("null returned by new_valist"); 105 } 106 107 this(cast(PeasExtensionSet*) p, true); 108 } 109 110 /** 111 * Create a new #PeasExtensionSet for the @exten_type extension type. 112 * 113 * If @engine is %NULL, then the default engine will be used. 114 * 115 * Since libpeas 1.22, @exten_type can be an Abstract #GType 116 * and not just an Interface #GType. 117 * 118 * See peas_extension_set_new() for more information. 119 * 120 * Params: 121 * engine = A #PeasEngine, or %NULL. 122 * extenType = the extension #GType. 123 * parameters = an array of #GParameter. 124 * 125 * Returns: a new instance of #PeasExtensionSet. 126 * 127 * Throws: ConstructionException GTK+ fails to create the object. 128 */ 129 public this(Engine engine, GType extenType, GParameter[] parameters) 130 { 131 auto p = peas_extension_set_newv((engine is null) ? null : engine.getEngineStruct(), extenType, cast(uint)parameters.length, parameters.ptr); 132 133 if(p is null) 134 { 135 throw new ConstructionException("null returned by newv"); 136 } 137 138 this(cast(PeasExtensionSet*) p, true); 139 } 140 141 /** 142 * Calls @func for each #PeasExtension. 143 * 144 * Params: 145 * func = A function call for each extension. 146 * data = Optional data to be passed to the function or %NULL. 147 * 148 * Since: 1.2 149 */ 150 public void foreac(PeasExtensionSetForeachFunc func, void* data) 151 { 152 peas_extension_set_foreach(peasExtensionSet, func, data); 153 } 154 155 /** 156 * Returns the #PeasExtension object corresponding to @info, or %NULL 157 * if the plugin doesn't provide such an extension. 158 * 159 * Params: 160 * info = a #PeasPluginInfo 161 * 162 * Returns: a reference to a #PeasExtension or %NULL 163 */ 164 public PeasExtension* getExtension(PluginInfo info) 165 { 166 return peas_extension_set_get_extension(peasExtensionSet, (info is null) ? null : info.getPluginInfoStruct()); 167 } 168 169 protected class OnExtensionAddedDelegateWrapper 170 { 171 void delegate(PluginInfo, ObjectG, ExtensionSet) dlg; 172 gulong handlerId; 173 174 this(void delegate(PluginInfo, ObjectG, ExtensionSet) dlg) 175 { 176 this.dlg = dlg; 177 onExtensionAddedListeners ~= this; 178 } 179 180 void remove(OnExtensionAddedDelegateWrapper source) 181 { 182 foreach(index, wrapper; onExtensionAddedListeners) 183 { 184 if (wrapper.handlerId == source.handlerId) 185 { 186 onExtensionAddedListeners[index] = null; 187 onExtensionAddedListeners = std.algorithm.remove(onExtensionAddedListeners, index); 188 break; 189 } 190 } 191 } 192 } 193 OnExtensionAddedDelegateWrapper[] onExtensionAddedListeners; 194 195 /** 196 * The extension-added signal is emitted when a new extension has been 197 * added to the #PeasExtensionSet. It happens when a new plugin implementing 198 * the extension set's extension type is loaded. 199 * 200 * You should connect to this signal in order to set up the extensions when 201 * they are loaded. Note that this signal is not fired for extensions coming 202 * from plugins that were already loaded when the #PeasExtensionSet instance 203 * was created. You should set those up by yourself. 204 * 205 * Params: 206 * info = A #PeasPluginInfo. 207 * exten = A #PeasExtension. 208 */ 209 gulong addOnExtensionAdded(void delegate(PluginInfo, ObjectG, ExtensionSet) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 210 { 211 auto wrapper = new OnExtensionAddedDelegateWrapper(dlg); 212 wrapper.handlerId = Signals.connectData( 213 this, 214 "extension-added", 215 cast(GCallback)&callBackExtensionAdded, 216 cast(void*)wrapper, 217 cast(GClosureNotify)&callBackExtensionAddedDestroy, 218 connectFlags); 219 return wrapper.handlerId; 220 } 221 222 extern(C) static void callBackExtensionAdded(PeasExtensionSet* extensionsetStruct, PeasPluginInfo* info, GObject* exten, OnExtensionAddedDelegateWrapper wrapper) 223 { 224 wrapper.dlg(ObjectG.getDObject!(PluginInfo)(info), ObjectG.getDObject!(ObjectG)(exten), wrapper.outer); 225 } 226 227 extern(C) static void callBackExtensionAddedDestroy(OnExtensionAddedDelegateWrapper wrapper, GClosure* closure) 228 { 229 wrapper.remove(wrapper); 230 } 231 232 protected class OnExtensionRemovedDelegateWrapper 233 { 234 void delegate(PluginInfo, ObjectG, ExtensionSet) dlg; 235 gulong handlerId; 236 237 this(void delegate(PluginInfo, ObjectG, ExtensionSet) dlg) 238 { 239 this.dlg = dlg; 240 onExtensionRemovedListeners ~= this; 241 } 242 243 void remove(OnExtensionRemovedDelegateWrapper source) 244 { 245 foreach(index, wrapper; onExtensionRemovedListeners) 246 { 247 if (wrapper.handlerId == source.handlerId) 248 { 249 onExtensionRemovedListeners[index] = null; 250 onExtensionRemovedListeners = std.algorithm.remove(onExtensionRemovedListeners, index); 251 break; 252 } 253 } 254 } 255 } 256 OnExtensionRemovedDelegateWrapper[] onExtensionRemovedListeners; 257 258 /** 259 * The extension-removed signal is emitted when a new extension is about to be 260 * removed from the #PeasExtensionSet. It happens when a plugin implementing 261 * the extension set's extension type is unloaded, or when the 262 * #PeasExtensionSet itself is destroyed. 263 * 264 * You should connect to this signal in order to clean up the extensions 265 * when their plugin is unload. Note that this signal is not fired for the 266 * #PeasExtension instances still available when the #PeasExtensionSet 267 * instance is destroyed. You should clean those up by yourself. 268 * 269 * Params: 270 * info = A #PeasPluginInfo. 271 * exten = A #PeasExtension. 272 */ 273 gulong addOnExtensionRemoved(void delegate(PluginInfo, ObjectG, ExtensionSet) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 274 { 275 auto wrapper = new OnExtensionRemovedDelegateWrapper(dlg); 276 wrapper.handlerId = Signals.connectData( 277 this, 278 "extension-removed", 279 cast(GCallback)&callBackExtensionRemoved, 280 cast(void*)wrapper, 281 cast(GClosureNotify)&callBackExtensionRemovedDestroy, 282 connectFlags); 283 return wrapper.handlerId; 284 } 285 286 extern(C) static void callBackExtensionRemoved(PeasExtensionSet* extensionsetStruct, PeasPluginInfo* info, GObject* exten, OnExtensionRemovedDelegateWrapper wrapper) 287 { 288 wrapper.dlg(ObjectG.getDObject!(PluginInfo)(info), ObjectG.getDObject!(ObjectG)(exten), wrapper.outer); 289 } 290 291 extern(C) static void callBackExtensionRemovedDestroy(OnExtensionRemovedDelegateWrapper wrapper, GClosure* closure) 292 { 293 wrapper.remove(wrapper); 294 } 295 }