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