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 public import gtkc.gdktypes; 32 private import peas.Engine; 33 private import peas.PluginInfo; 34 private import peasc.peas; 35 public import peasc.peastypes; 36 private import std.algorithm; 37 38 39 /** 40 * The #PeasExtensionSet structure contains only private data and should only 41 * be accessed using the provided API. 42 */ 43 public class ExtensionSet : ObjectG 44 { 45 /** the main Gtk struct */ 46 protected PeasExtensionSet* peasExtensionSet; 47 48 /** Get the main Gtk struct */ 49 public PeasExtensionSet* getExtensionSetStruct() 50 { 51 return peasExtensionSet; 52 } 53 54 /** the main Gtk struct as a void* */ 55 protected override void* getStruct() 56 { 57 return cast(void*)peasExtensionSet; 58 } 59 60 protected override void setStruct(GObject* obj) 61 { 62 peasExtensionSet = cast(PeasExtensionSet*)obj; 63 super.setStruct(obj); 64 } 65 66 /** 67 * Sets our main struct and passes it to the parent class. 68 */ 69 public this (PeasExtensionSet* peasExtensionSet, bool ownedRef = false) 70 { 71 this.peasExtensionSet = peasExtensionSet; 72 super(cast(GObject*)peasExtensionSet, ownedRef); 73 } 74 75 76 /** */ 77 public static GType getType() 78 { 79 return peas_extension_set_get_type(); 80 } 81 82 /** 83 * Create a new #PeasExtensionSet for the @exten_type extension type. 84 * 85 * If @engine is %NULL, then the default engine will be used. 86 * 87 * See peas_extension_set_new() for more information. 88 * 89 * Params: 90 * engine = A #PeasEngine, or %NULL. 91 * extenType = the extension #GType. 92 * firstProperty = the name of the first property. 93 * varArgs = the value of the first property, followed optionally by more 94 * name/value pairs, followed by %NULL. 95 * 96 * Return: a new instance of #PeasExtensionSet. 97 * 98 * Throws: ConstructionException GTK+ fails to create the object. 99 */ 100 public this(Engine engine, GType extenType, string firstProperty, void* varArgs) 101 { 102 auto p = peas_extension_set_new_valist((engine is null) ? null : engine.getEngineStruct(), extenType, Str.toStringz(firstProperty), varArgs); 103 104 if(p is null) 105 { 106 throw new ConstructionException("null returned by new_valist"); 107 } 108 109 this(cast(PeasExtensionSet*) p, true); 110 } 111 112 /** 113 * Create a new #PeasExtensionSet for the @exten_type extension type. 114 * 115 * If @engine is %NULL, then the default engine will be used. 116 * 117 * See peas_extension_set_new() for more information. 118 * 119 * Params: 120 * engine = A #PeasEngine, or %NULL. 121 * extenType = the extension #GType. 122 * nParameters = the length of the @parameters array. 123 * parameters = an array of #GParameter. 124 * 125 * Return: 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 * Return: 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 ConnectFlags flags; 174 this(void delegate(PluginInfo, ObjectG, ExtensionSet) dlg, gulong handlerId, ConnectFlags flags) 175 { 176 this.dlg = dlg; 177 this.handlerId = handlerId; 178 this.flags = flags; 179 } 180 } 181 protected OnExtensionAddedDelegateWrapper[] onExtensionAddedListeners; 182 183 /** 184 * The extension-added signal is emitted when a new extension has been 185 * added to the #PeasExtensionSet. It happens when a new plugin implementing 186 * the extension set's extension type is loaded. 187 * 188 * You should connect to this signal in order to set up the extensions when 189 * they are loaded. Note that this signal is not fired for extensions coming 190 * from plugins that were already loaded when the #PeasExtensionSet instance 191 * was created. You should set those up by yourself. 192 * 193 * Params: 194 * info = A #PeasPluginInfo. 195 * exten = A #PeasExtension. 196 */ 197 gulong addOnExtensionAdded(void delegate(PluginInfo, ObjectG, ExtensionSet) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 198 { 199 onExtensionAddedListeners ~= new OnExtensionAddedDelegateWrapper(dlg, 0, connectFlags); 200 onExtensionAddedListeners[onExtensionAddedListeners.length - 1].handlerId = Signals.connectData( 201 this, 202 "extension-added", 203 cast(GCallback)&callBackExtensionAdded, 204 cast(void*)onExtensionAddedListeners[onExtensionAddedListeners.length - 1], 205 cast(GClosureNotify)&callBackExtensionAddedDestroy, 206 connectFlags); 207 return onExtensionAddedListeners[onExtensionAddedListeners.length - 1].handlerId; 208 } 209 210 extern(C) static void callBackExtensionAdded(PeasExtensionSet* extensionsetStruct, PeasPluginInfo* info, GObject* exten,OnExtensionAddedDelegateWrapper wrapper) 211 { 212 wrapper.dlg(ObjectG.getDObject!(PluginInfo)(info), ObjectG.getDObject!(ObjectG)(exten), wrapper.outer); 213 } 214 215 extern(C) static void callBackExtensionAddedDestroy(OnExtensionAddedDelegateWrapper wrapper, GClosure* closure) 216 { 217 wrapper.outer.internalRemoveOnExtensionAdded(wrapper); 218 } 219 220 protected void internalRemoveOnExtensionAdded(OnExtensionAddedDelegateWrapper source) 221 { 222 foreach(index, wrapper; onExtensionAddedListeners) 223 { 224 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 225 { 226 onExtensionAddedListeners[index] = null; 227 onExtensionAddedListeners = std.algorithm.remove(onExtensionAddedListeners, index); 228 break; 229 } 230 } 231 } 232 233 234 protected class OnExtensionRemovedDelegateWrapper 235 { 236 void delegate(PluginInfo, ObjectG, ExtensionSet) dlg; 237 gulong handlerId; 238 ConnectFlags flags; 239 this(void delegate(PluginInfo, ObjectG, ExtensionSet) dlg, gulong handlerId, ConnectFlags flags) 240 { 241 this.dlg = dlg; 242 this.handlerId = handlerId; 243 this.flags = flags; 244 } 245 } 246 protected OnExtensionRemovedDelegateWrapper[] onExtensionRemovedListeners; 247 248 /** 249 * The extension-removed signal is emitted when a new extension is about to be 250 * removed from the #PeasExtensionSet. It happens when a plugin implementing 251 * the extension set's extension type is unloaded, or when the 252 * #PeasExtensionSet itself is destroyed. 253 * 254 * You should connect to this signal in order to clean up the extensions 255 * when their plugin is unload. Note that this signal is not fired for the 256 * #PeasExtension instances still available when the #PeasExtensionSet 257 * instance is destroyed. You should clean those up by yourself. 258 * 259 * Params: 260 * info = A #PeasPluginInfo. 261 * exten = A #PeasExtension. 262 */ 263 gulong addOnExtensionRemoved(void delegate(PluginInfo, ObjectG, ExtensionSet) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 264 { 265 onExtensionRemovedListeners ~= new OnExtensionRemovedDelegateWrapper(dlg, 0, connectFlags); 266 onExtensionRemovedListeners[onExtensionRemovedListeners.length - 1].handlerId = Signals.connectData( 267 this, 268 "extension-removed", 269 cast(GCallback)&callBackExtensionRemoved, 270 cast(void*)onExtensionRemovedListeners[onExtensionRemovedListeners.length - 1], 271 cast(GClosureNotify)&callBackExtensionRemovedDestroy, 272 connectFlags); 273 return onExtensionRemovedListeners[onExtensionRemovedListeners.length - 1].handlerId; 274 } 275 276 extern(C) static void callBackExtensionRemoved(PeasExtensionSet* extensionsetStruct, PeasPluginInfo* info, GObject* exten,OnExtensionRemovedDelegateWrapper wrapper) 277 { 278 wrapper.dlg(ObjectG.getDObject!(PluginInfo)(info), ObjectG.getDObject!(ObjectG)(exten), wrapper.outer); 279 } 280 281 extern(C) static void callBackExtensionRemovedDestroy(OnExtensionRemovedDelegateWrapper wrapper, GClosure* closure) 282 { 283 wrapper.outer.internalRemoveOnExtensionRemoved(wrapper); 284 } 285 286 protected void internalRemoveOnExtensionRemoved(OnExtensionRemovedDelegateWrapper source) 287 { 288 foreach(index, wrapper; onExtensionRemovedListeners) 289 { 290 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 291 { 292 onExtensionRemovedListeners[index] = null; 293 onExtensionRemovedListeners = std.algorithm.remove(onExtensionRemovedListeners, index); 294 break; 295 } 296 } 297 } 298 299 }