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