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 
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 	 * Return: 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 	 * Return: 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 	 * Return: 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 	 * Return: 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 	 * Return: 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 	 * Return: 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 	 * Return: 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 	int[string] connectedSignals;
294 
295 	void delegate(AppInfoIF, AppChooserWidget)[] onApplicationActivatedListeners;
296 	/**
297 	 * Emitted when an application item is activated from the widget's list.
298 	 *
299 	 * This usually happens when the user double clicks an item, or an item
300 	 * is selected and the user presses one of the keys Space, Shift+Space,
301 	 * Return or Enter.
302 	 *
303 	 * Params:
304 	 *     application = the activated #GAppInfo
305 	 */
306 	void addOnApplicationActivated(void delegate(AppInfoIF, AppChooserWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
307 	{
308 		if ( "application-activated" !in connectedSignals )
309 		{
310 			Signals.connectData(
311 				this,
312 				"application-activated",
313 				cast(GCallback)&callBackApplicationActivated,
314 				cast(void*)this,
315 				null,
316 				connectFlags);
317 			connectedSignals["application-activated"] = 1;
318 		}
319 		onApplicationActivatedListeners ~= dlg;
320 	}
321 	extern(C) static void callBackApplicationActivated(GtkAppChooserWidget* appchooserwidgetStruct, GAppInfo* application, AppChooserWidget _appchooserwidget)
322 	{
323 		foreach ( void delegate(AppInfoIF, AppChooserWidget) dlg; _appchooserwidget.onApplicationActivatedListeners )
324 		{
325 			dlg(ObjectG.getDObject!(AppInfo, AppInfoIF)(application), _appchooserwidget);
326 		}
327 	}
328 
329 	void delegate(AppInfoIF, AppChooserWidget)[] onApplicationSelectedListeners;
330 	/**
331 	 * Emitted when an application item is selected from the widget's list.
332 	 *
333 	 * Params:
334 	 *     application = the selected #GAppInfo
335 	 */
336 	void addOnApplicationSelected(void delegate(AppInfoIF, AppChooserWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
337 	{
338 		if ( "application-selected" !in connectedSignals )
339 		{
340 			Signals.connectData(
341 				this,
342 				"application-selected",
343 				cast(GCallback)&callBackApplicationSelected,
344 				cast(void*)this,
345 				null,
346 				connectFlags);
347 			connectedSignals["application-selected"] = 1;
348 		}
349 		onApplicationSelectedListeners ~= dlg;
350 	}
351 	extern(C) static void callBackApplicationSelected(GtkAppChooserWidget* appchooserwidgetStruct, GAppInfo* application, AppChooserWidget _appchooserwidget)
352 	{
353 		foreach ( void delegate(AppInfoIF, AppChooserWidget) dlg; _appchooserwidget.onApplicationSelectedListeners )
354 		{
355 			dlg(ObjectG.getDObject!(AppInfo, AppInfoIF)(application), _appchooserwidget);
356 		}
357 	}
358 
359 	void delegate(Menu, AppInfoIF, AppChooserWidget)[] onPopulatePopupListeners;
360 	/**
361 	 * Emitted when a context menu is about to popup over an application item.
362 	 * Clients can insert menu items into the provided #GtkMenu object in the
363 	 * callback of this signal; the context menu will be shown over the item
364 	 * if at least one item has been added to the menu.
365 	 *
366 	 * Params:
367 	 *     menu = the #GtkMenu to populate
368 	 *     application = the current #GAppInfo
369 	 */
370 	void addOnPopulatePopup(void delegate(Menu, AppInfoIF, AppChooserWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
371 	{
372 		if ( "populate-popup" !in connectedSignals )
373 		{
374 			Signals.connectData(
375 				this,
376 				"populate-popup",
377 				cast(GCallback)&callBackPopulatePopup,
378 				cast(void*)this,
379 				null,
380 				connectFlags);
381 			connectedSignals["populate-popup"] = 1;
382 		}
383 		onPopulatePopupListeners ~= dlg;
384 	}
385 	extern(C) static void callBackPopulatePopup(GtkAppChooserWidget* appchooserwidgetStruct, GtkMenu* menu, GAppInfo* application, AppChooserWidget _appchooserwidget)
386 	{
387 		foreach ( void delegate(Menu, AppInfoIF, AppChooserWidget) dlg; _appchooserwidget.onPopulatePopupListeners )
388 		{
389 			dlg(ObjectG.getDObject!(Menu)(menu), ObjectG.getDObject!(AppInfo, AppInfoIF)(application), _appchooserwidget);
390 		}
391 	}
392 }