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 gtk.AppChooserWidget;
26 
27 private import gio.AppInfo;
28 private import gio.AppInfoIF;
29 private import glib.ConstructionException;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gobject.Signals;
33 private import gtk.AppChooserIF;
34 private import gtk.AppChooserT;
35 private import gtk.Box;
36 private import gtk.Menu;
37 private import gtk.Widget;
38 public  import gtkc.gdktypes;
39 private import gtkc.gtk;
40 public  import gtkc.gtktypes;
41 private import std.algorithm;
42 
43 
44 /**
45  * #GtkAppChooserWidget is a widget for selecting applications.
46  * It is the main building block for #GtkAppChooserDialog. Most
47  * applications only need to use the latter; but you can use
48  * this widget as part of a larger widget if you have special needs.
49  * 
50  * #GtkAppChooserWidget offers detailed control over what applications
51  * are shown, using the
52  * #GtkAppChooserWidget:show-default,
53  * #GtkAppChooserWidget:show-recommended,
54  * #GtkAppChooserWidget:show-fallback,
55  * #GtkAppChooserWidget:show-other and
56  * #GtkAppChooserWidget:show-all
57  * properties. See the #GtkAppChooser documentation for more information
58  * about these groups of applications.
59  * 
60  * To keep track of the selected application, use the
61  * #GtkAppChooserWidget::application-selected and #GtkAppChooserWidget::application-activated signals.
62  * 
63  * # CSS nodes
64  * 
65  * GtkAppChooserWidget has a single CSS node with name appchooser.
66  */
67 public class AppChooserWidget : Box, AppChooserIF
68 {
69 	/** the main Gtk struct */
70 	protected GtkAppChooserWidget* gtkAppChooserWidget;
71 
72 	/** Get the main Gtk struct */
73 	public GtkAppChooserWidget* getAppChooserWidgetStruct()
74 	{
75 		return gtkAppChooserWidget;
76 	}
77 
78 	/** the main Gtk struct as a void* */
79 	protected override void* getStruct()
80 	{
81 		return cast(void*)gtkAppChooserWidget;
82 	}
83 
84 	protected override void setStruct(GObject* obj)
85 	{
86 		gtkAppChooserWidget = cast(GtkAppChooserWidget*)obj;
87 		super.setStruct(obj);
88 	}
89 
90 	/**
91 	 * Sets our main struct and passes it to the parent class.
92 	 */
93 	public this (GtkAppChooserWidget* gtkAppChooserWidget, bool ownedRef = false)
94 	{
95 		this.gtkAppChooserWidget = gtkAppChooserWidget;
96 		super(cast(GtkBox*)gtkAppChooserWidget, ownedRef);
97 	}
98 
99 	// add the AppChooser capabilities
100 	mixin AppChooserT!(GtkAppChooserWidget);
101 
102 
103 	/** */
104 	public static GType getType()
105 	{
106 		return gtk_app_chooser_widget_get_type();
107 	}
108 
109 	/**
110 	 * Creates a new #GtkAppChooserWidget for applications
111 	 * that can handle content of the given type.
112 	 *
113 	 * Params:
114 	 *     contentType = the content type to show applications for
115 	 *
116 	 * Return: a newly created #GtkAppChooserWidget
117 	 *
118 	 * Since: 3.0
119 	 *
120 	 * Throws: ConstructionException GTK+ fails to create the object.
121 	 */
122 	public this(string contentType)
123 	{
124 		auto p = gtk_app_chooser_widget_new(Str.toStringz(contentType));
125 		
126 		if(p is null)
127 		{
128 			throw new ConstructionException("null returned by new");
129 		}
130 		
131 		this(cast(GtkAppChooserWidget*) p);
132 	}
133 
134 	/**
135 	 * Returns the text that is shown if there are not applications
136 	 * that can handle the content type.
137 	 *
138 	 * Return: the value of #GtkAppChooserWidget:default-text
139 	 *
140 	 * Since: 3.0
141 	 */
142 	public string getDefaultText()
143 	{
144 		return Str.toString(gtk_app_chooser_widget_get_default_text(gtkAppChooserWidget));
145 	}
146 
147 	/**
148 	 * Returns the current value of the #GtkAppChooserWidget:show-all
149 	 * property.
150 	 *
151 	 * Return: the value of #GtkAppChooserWidget:show-all
152 	 *
153 	 * Since: 3.0
154 	 */
155 	public bool getShowAll()
156 	{
157 		return gtk_app_chooser_widget_get_show_all(gtkAppChooserWidget) != 0;
158 	}
159 
160 	/**
161 	 * Returns the current value of the #GtkAppChooserWidget:show-default
162 	 * property.
163 	 *
164 	 * Return: the value of #GtkAppChooserWidget:show-default
165 	 *
166 	 * Since: 3.0
167 	 */
168 	public bool getShowDefault()
169 	{
170 		return gtk_app_chooser_widget_get_show_default(gtkAppChooserWidget) != 0;
171 	}
172 
173 	/**
174 	 * Returns the current value of the #GtkAppChooserWidget:show-fallback
175 	 * property.
176 	 *
177 	 * Return: the value of #GtkAppChooserWidget:show-fallback
178 	 *
179 	 * Since: 3.0
180 	 */
181 	public bool getShowFallback()
182 	{
183 		return gtk_app_chooser_widget_get_show_fallback(gtkAppChooserWidget) != 0;
184 	}
185 
186 	/**
187 	 * Returns the current value of the #GtkAppChooserWidget:show-other
188 	 * property.
189 	 *
190 	 * Return: the value of #GtkAppChooserWidget:show-other
191 	 *
192 	 * Since: 3.0
193 	 */
194 	public bool getShowOther()
195 	{
196 		return gtk_app_chooser_widget_get_show_other(gtkAppChooserWidget) != 0;
197 	}
198 
199 	/**
200 	 * Returns the current value of the #GtkAppChooserWidget:show-recommended
201 	 * property.
202 	 *
203 	 * Return: the value of #GtkAppChooserWidget:show-recommended
204 	 *
205 	 * Since: 3.0
206 	 */
207 	public bool getShowRecommended()
208 	{
209 		return gtk_app_chooser_widget_get_show_recommended(gtkAppChooserWidget) != 0;
210 	}
211 
212 	/**
213 	 * Sets the text that is shown if there are not applications
214 	 * that can handle the content type.
215 	 *
216 	 * Params:
217 	 *     text = the new value for #GtkAppChooserWidget:default-text
218 	 */
219 	public void setDefaultText(string text)
220 	{
221 		gtk_app_chooser_widget_set_default_text(gtkAppChooserWidget, Str.toStringz(text));
222 	}
223 
224 	/**
225 	 * Sets whether the app chooser should show all applications
226 	 * in a flat list.
227 	 *
228 	 * Params:
229 	 *     setting = the new value for #GtkAppChooserWidget:show-all
230 	 *
231 	 * Since: 3.0
232 	 */
233 	public void setShowAll(bool setting)
234 	{
235 		gtk_app_chooser_widget_set_show_all(gtkAppChooserWidget, setting);
236 	}
237 
238 	/**
239 	 * Sets whether the app chooser should show the default handler
240 	 * for the content type in a separate section.
241 	 *
242 	 * Params:
243 	 *     setting = the new value for #GtkAppChooserWidget:show-default
244 	 *
245 	 * Since: 3.0
246 	 */
247 	public void setShowDefault(bool setting)
248 	{
249 		gtk_app_chooser_widget_set_show_default(gtkAppChooserWidget, setting);
250 	}
251 
252 	/**
253 	 * Sets whether the app chooser should show related applications
254 	 * for the content type in a separate section.
255 	 *
256 	 * Params:
257 	 *     setting = the new value for #GtkAppChooserWidget:show-fallback
258 	 *
259 	 * Since: 3.0
260 	 */
261 	public void setShowFallback(bool setting)
262 	{
263 		gtk_app_chooser_widget_set_show_fallback(gtkAppChooserWidget, setting);
264 	}
265 
266 	/**
267 	 * Sets whether the app chooser should show applications
268 	 * which are unrelated to the content type.
269 	 *
270 	 * Params:
271 	 *     setting = the new value for #GtkAppChooserWidget:show-other
272 	 *
273 	 * Since: 3.0
274 	 */
275 	public void setShowOther(bool setting)
276 	{
277 		gtk_app_chooser_widget_set_show_other(gtkAppChooserWidget, setting);
278 	}
279 
280 	/**
281 	 * Sets whether the app chooser should show recommended applications
282 	 * for the content type in a separate section.
283 	 *
284 	 * Params:
285 	 *     setting = the new value for #GtkAppChooserWidget:show-recommended
286 	 *
287 	 * Since: 3.0
288 	 */
289 	public void setShowRecommended(bool setting)
290 	{
291 		gtk_app_chooser_widget_set_show_recommended(gtkAppChooserWidget, setting);
292 	}
293 
294 	protected class OnApplicationActivatedDelegateWrapper
295 	{
296 		void delegate(AppInfoIF, AppChooserWidget) dlg;
297 		gulong handlerId;
298 		ConnectFlags flags;
299 		this(void delegate(AppInfoIF, AppChooserWidget) dlg, gulong handlerId, ConnectFlags flags)
300 		{
301 			this.dlg = dlg;
302 			this.handlerId = handlerId;
303 			this.flags = flags;
304 		}
305 	}
306 	protected OnApplicationActivatedDelegateWrapper[] onApplicationActivatedListeners;
307 
308 	/**
309 	 * Emitted when an application item is activated from the widget's list.
310 	 *
311 	 * This usually happens when the user double clicks an item, or an item
312 	 * is selected and the user presses one of the keys Space, Shift+Space,
313 	 * Return or Enter.
314 	 *
315 	 * Params:
316 	 *     application = the activated #GAppInfo
317 	 */
318 	gulong addOnApplicationActivated(void delegate(AppInfoIF, AppChooserWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
319 	{
320 		onApplicationActivatedListeners ~= new OnApplicationActivatedDelegateWrapper(dlg, 0, connectFlags);
321 		onApplicationActivatedListeners[onApplicationActivatedListeners.length - 1].handlerId = Signals.connectData(
322 			this,
323 			"application-activated",
324 			cast(GCallback)&callBackApplicationActivated,
325 			cast(void*)onApplicationActivatedListeners[onApplicationActivatedListeners.length - 1],
326 			cast(GClosureNotify)&callBackApplicationActivatedDestroy,
327 			connectFlags);
328 		return onApplicationActivatedListeners[onApplicationActivatedListeners.length - 1].handlerId;
329 	}
330 	
331 	extern(C) static void callBackApplicationActivated(GtkAppChooserWidget* appchooserwidgetStruct, GAppInfo* application,OnApplicationActivatedDelegateWrapper wrapper)
332 	{
333 		wrapper.dlg(ObjectG.getDObject!(AppInfo, AppInfoIF)(application), wrapper.outer);
334 	}
335 	
336 	extern(C) static void callBackApplicationActivatedDestroy(OnApplicationActivatedDelegateWrapper wrapper, GClosure* closure)
337 	{
338 		wrapper.outer.internalRemoveOnApplicationActivated(wrapper);
339 	}
340 
341 	protected void internalRemoveOnApplicationActivated(OnApplicationActivatedDelegateWrapper source)
342 	{
343 		foreach(index, wrapper; onApplicationActivatedListeners)
344 		{
345 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
346 			{
347 				onApplicationActivatedListeners[index] = null;
348 				onApplicationActivatedListeners = std.algorithm.remove(onApplicationActivatedListeners, index);
349 				break;
350 			}
351 		}
352 	}
353 	
354 
355 	protected class OnApplicationSelectedDelegateWrapper
356 	{
357 		void delegate(AppInfoIF, AppChooserWidget) dlg;
358 		gulong handlerId;
359 		ConnectFlags flags;
360 		this(void delegate(AppInfoIF, AppChooserWidget) dlg, gulong handlerId, ConnectFlags flags)
361 		{
362 			this.dlg = dlg;
363 			this.handlerId = handlerId;
364 			this.flags = flags;
365 		}
366 	}
367 	protected OnApplicationSelectedDelegateWrapper[] onApplicationSelectedListeners;
368 
369 	/**
370 	 * Emitted when an application item is selected from the widget's list.
371 	 *
372 	 * Params:
373 	 *     application = the selected #GAppInfo
374 	 */
375 	gulong addOnApplicationSelected(void delegate(AppInfoIF, AppChooserWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
376 	{
377 		onApplicationSelectedListeners ~= new OnApplicationSelectedDelegateWrapper(dlg, 0, connectFlags);
378 		onApplicationSelectedListeners[onApplicationSelectedListeners.length - 1].handlerId = Signals.connectData(
379 			this,
380 			"application-selected",
381 			cast(GCallback)&callBackApplicationSelected,
382 			cast(void*)onApplicationSelectedListeners[onApplicationSelectedListeners.length - 1],
383 			cast(GClosureNotify)&callBackApplicationSelectedDestroy,
384 			connectFlags);
385 		return onApplicationSelectedListeners[onApplicationSelectedListeners.length - 1].handlerId;
386 	}
387 	
388 	extern(C) static void callBackApplicationSelected(GtkAppChooserWidget* appchooserwidgetStruct, GAppInfo* application,OnApplicationSelectedDelegateWrapper wrapper)
389 	{
390 		wrapper.dlg(ObjectG.getDObject!(AppInfo, AppInfoIF)(application), wrapper.outer);
391 	}
392 	
393 	extern(C) static void callBackApplicationSelectedDestroy(OnApplicationSelectedDelegateWrapper wrapper, GClosure* closure)
394 	{
395 		wrapper.outer.internalRemoveOnApplicationSelected(wrapper);
396 	}
397 
398 	protected void internalRemoveOnApplicationSelected(OnApplicationSelectedDelegateWrapper source)
399 	{
400 		foreach(index, wrapper; onApplicationSelectedListeners)
401 		{
402 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
403 			{
404 				onApplicationSelectedListeners[index] = null;
405 				onApplicationSelectedListeners = std.algorithm.remove(onApplicationSelectedListeners, index);
406 				break;
407 			}
408 		}
409 	}
410 	
411 
412 	protected class OnPopulatePopupDelegateWrapper
413 	{
414 		void delegate(Menu, AppInfoIF, AppChooserWidget) dlg;
415 		gulong handlerId;
416 		ConnectFlags flags;
417 		this(void delegate(Menu, AppInfoIF, AppChooserWidget) dlg, gulong handlerId, ConnectFlags flags)
418 		{
419 			this.dlg = dlg;
420 			this.handlerId = handlerId;
421 			this.flags = flags;
422 		}
423 	}
424 	protected OnPopulatePopupDelegateWrapper[] onPopulatePopupListeners;
425 
426 	/**
427 	 * Emitted when a context menu is about to popup over an application item.
428 	 * Clients can insert menu items into the provided #GtkMenu object in the
429 	 * callback of this signal; the context menu will be shown over the item
430 	 * if at least one item has been added to the menu.
431 	 *
432 	 * Params:
433 	 *     menu = the #GtkMenu to populate
434 	 *     application = the current #GAppInfo
435 	 */
436 	gulong addOnPopulatePopup(void delegate(Menu, AppInfoIF, AppChooserWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
437 	{
438 		onPopulatePopupListeners ~= new OnPopulatePopupDelegateWrapper(dlg, 0, connectFlags);
439 		onPopulatePopupListeners[onPopulatePopupListeners.length - 1].handlerId = Signals.connectData(
440 			this,
441 			"populate-popup",
442 			cast(GCallback)&callBackPopulatePopup,
443 			cast(void*)onPopulatePopupListeners[onPopulatePopupListeners.length - 1],
444 			cast(GClosureNotify)&callBackPopulatePopupDestroy,
445 			connectFlags);
446 		return onPopulatePopupListeners[onPopulatePopupListeners.length - 1].handlerId;
447 	}
448 	
449 	extern(C) static void callBackPopulatePopup(GtkAppChooserWidget* appchooserwidgetStruct, GtkMenu* menu, GAppInfo* application,OnPopulatePopupDelegateWrapper wrapper)
450 	{
451 		wrapper.dlg(ObjectG.getDObject!(Menu)(menu), ObjectG.getDObject!(AppInfo, AppInfoIF)(application), wrapper.outer);
452 	}
453 	
454 	extern(C) static void callBackPopulatePopupDestroy(OnPopulatePopupDelegateWrapper wrapper, GClosure* closure)
455 	{
456 		wrapper.outer.internalRemoveOnPopulatePopup(wrapper);
457 	}
458 
459 	protected void internalRemoveOnPopulatePopup(OnPopulatePopupDelegateWrapper source)
460 	{
461 		foreach(index, wrapper; onPopulatePopupListeners)
462 		{
463 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
464 			{
465 				onPopulatePopupListeners[index] = null;
466 				onPopulatePopupListeners = std.algorithm.remove(onPopulatePopupListeners, index);
467 				break;
468 			}
469 		}
470 	}
471 	
472 }