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