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 public class AppChooserWidget : Box, AppChooserIF
63 {
64 	/** the main Gtk struct */
65 	protected GtkAppChooserWidget* gtkAppChooserWidget;
66 
67 	/** Get the main Gtk struct */
68 	public GtkAppChooserWidget* getAppChooserWidgetStruct()
69 	{
70 		return gtkAppChooserWidget;
71 	}
72 
73 	/** the main Gtk struct as a void* */
74 	protected override void* getStruct()
75 	{
76 		return cast(void*)gtkAppChooserWidget;
77 	}
78 
79 	protected override void setStruct(GObject* obj)
80 	{
81 		gtkAppChooserWidget = cast(GtkAppChooserWidget*)obj;
82 		super.setStruct(obj);
83 	}
84 
85 	/**
86 	 * Sets our main struct and passes it to the parent class.
87 	 */
88 	public this (GtkAppChooserWidget* gtkAppChooserWidget, bool ownedRef = false)
89 	{
90 		this.gtkAppChooserWidget = gtkAppChooserWidget;
91 		super(cast(GtkBox*)gtkAppChooserWidget, ownedRef);
92 	}
93 
94 	// add the AppChooser capabilities
95 	mixin AppChooserT!(GtkAppChooserWidget);
96 
97 
98 	/** */
99 	public static GType getType()
100 	{
101 		return gtk_app_chooser_widget_get_type();
102 	}
103 
104 	/**
105 	 * Creates a new #GtkAppChooserWidget for applications
106 	 * that can handle content of the given type.
107 	 *
108 	 * Params:
109 	 *     contentType = the content type to show applications for
110 	 *
111 	 * Return: a newly created #GtkAppChooserWidget
112 	 *
113 	 * Since: 3.0
114 	 *
115 	 * Throws: ConstructionException GTK+ fails to create the object.
116 	 */
117 	public this(string contentType)
118 	{
119 		auto p = gtk_app_chooser_widget_new(Str.toStringz(contentType));
120 		
121 		if(p is null)
122 		{
123 			throw new ConstructionException("null returned by new");
124 		}
125 		
126 		this(cast(GtkAppChooserWidget*) p);
127 	}
128 
129 	/**
130 	 * Returns the text that is shown if there are not applications
131 	 * that can handle the content type.
132 	 *
133 	 * Return: the value of #GtkAppChooserWidget:default-text
134 	 *
135 	 * Since: 3.0
136 	 */
137 	public string getDefaultText()
138 	{
139 		return Str.toString(gtk_app_chooser_widget_get_default_text(gtkAppChooserWidget));
140 	}
141 
142 	/**
143 	 * Returns the current value of the #GtkAppChooserWidget:show-all
144 	 * property.
145 	 *
146 	 * Return: the value of #GtkAppChooserWidget:show-all
147 	 *
148 	 * Since: 3.0
149 	 */
150 	public bool getShowAll()
151 	{
152 		return gtk_app_chooser_widget_get_show_all(gtkAppChooserWidget) != 0;
153 	}
154 
155 	/**
156 	 * Returns the current value of the #GtkAppChooserWidget:show-default
157 	 * property.
158 	 *
159 	 * Return: the value of #GtkAppChooserWidget:show-default
160 	 *
161 	 * Since: 3.0
162 	 */
163 	public bool getShowDefault()
164 	{
165 		return gtk_app_chooser_widget_get_show_default(gtkAppChooserWidget) != 0;
166 	}
167 
168 	/**
169 	 * Returns the current value of the #GtkAppChooserWidget:show-fallback
170 	 * property.
171 	 *
172 	 * Return: the value of #GtkAppChooserWidget:show-fallback
173 	 *
174 	 * Since: 3.0
175 	 */
176 	public bool getShowFallback()
177 	{
178 		return gtk_app_chooser_widget_get_show_fallback(gtkAppChooserWidget) != 0;
179 	}
180 
181 	/**
182 	 * Returns the current value of the #GtkAppChooserWidget:show-other
183 	 * property.
184 	 *
185 	 * Return: the value of #GtkAppChooserWidget:show-other
186 	 *
187 	 * Since: 3.0
188 	 */
189 	public bool getShowOther()
190 	{
191 		return gtk_app_chooser_widget_get_show_other(gtkAppChooserWidget) != 0;
192 	}
193 
194 	/**
195 	 * Returns the current value of the #GtkAppChooserWidget:show-recommended
196 	 * property.
197 	 *
198 	 * Return: the value of #GtkAppChooserWidget:show-recommended
199 	 *
200 	 * Since: 3.0
201 	 */
202 	public bool getShowRecommended()
203 	{
204 		return gtk_app_chooser_widget_get_show_recommended(gtkAppChooserWidget) != 0;
205 	}
206 
207 	/**
208 	 * Sets the text that is shown if there are not applications
209 	 * that can handle the content type.
210 	 *
211 	 * Params:
212 	 *     text = the new value for #GtkAppChooserWidget:default-text
213 	 */
214 	public void setDefaultText(string text)
215 	{
216 		gtk_app_chooser_widget_set_default_text(gtkAppChooserWidget, Str.toStringz(text));
217 	}
218 
219 	/**
220 	 * Sets whether the app chooser should show all applications
221 	 * in a flat list.
222 	 *
223 	 * Params:
224 	 *     setting = the new value for #GtkAppChooserWidget:show-all
225 	 *
226 	 * Since: 3.0
227 	 */
228 	public void setShowAll(bool setting)
229 	{
230 		gtk_app_chooser_widget_set_show_all(gtkAppChooserWidget, setting);
231 	}
232 
233 	/**
234 	 * Sets whether the app chooser should show the default handler
235 	 * for the content type in a separate section.
236 	 *
237 	 * Params:
238 	 *     setting = the new value for #GtkAppChooserWidget:show-default
239 	 *
240 	 * Since: 3.0
241 	 */
242 	public void setShowDefault(bool setting)
243 	{
244 		gtk_app_chooser_widget_set_show_default(gtkAppChooserWidget, setting);
245 	}
246 
247 	/**
248 	 * Sets whether the app chooser should show related applications
249 	 * for the content type in a separate section.
250 	 *
251 	 * Params:
252 	 *     setting = the new value for #GtkAppChooserWidget:show-fallback
253 	 *
254 	 * Since: 3.0
255 	 */
256 	public void setShowFallback(bool setting)
257 	{
258 		gtk_app_chooser_widget_set_show_fallback(gtkAppChooserWidget, setting);
259 	}
260 
261 	/**
262 	 * Sets whether the app chooser should show applications
263 	 * which are unrelated to the content type.
264 	 *
265 	 * Params:
266 	 *     setting = the new value for #GtkAppChooserWidget:show-other
267 	 *
268 	 * Since: 3.0
269 	 */
270 	public void setShowOther(bool setting)
271 	{
272 		gtk_app_chooser_widget_set_show_other(gtkAppChooserWidget, setting);
273 	}
274 
275 	/**
276 	 * Sets whether the app chooser should show recommended applications
277 	 * for the content type in a separate section.
278 	 *
279 	 * Params:
280 	 *     setting = the new value for #GtkAppChooserWidget:show-recommended
281 	 *
282 	 * Since: 3.0
283 	 */
284 	public void setShowRecommended(bool setting)
285 	{
286 		gtk_app_chooser_widget_set_show_recommended(gtkAppChooserWidget, setting);
287 	}
288 
289 	int[string] connectedSignals;
290 
291 	void delegate(AppInfoIF, AppChooserWidget)[] onApplicationActivatedListeners;
292 	/**
293 	 * Emitted when an application item is activated from the widget's list.
294 	 *
295 	 * This usually happens when the user double clicks an item, or an item
296 	 * is selected and the user presses one of the keys Space, Shift+Space,
297 	 * Return or Enter.
298 	 *
299 	 * Params:
300 	 *     application = the activated #GAppInfo
301 	 */
302 	void addOnApplicationActivated(void delegate(AppInfoIF, AppChooserWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
303 	{
304 		if ( "application-activated" !in connectedSignals )
305 		{
306 			Signals.connectData(
307 				this,
308 				"application-activated",
309 				cast(GCallback)&callBackApplicationActivated,
310 				cast(void*)this,
311 				null,
312 				connectFlags);
313 			connectedSignals["application-activated"] = 1;
314 		}
315 		onApplicationActivatedListeners ~= dlg;
316 	}
317 	extern(C) static void callBackApplicationActivated(GtkAppChooserWidget* appchooserwidgetStruct, GAppInfo* application, AppChooserWidget _appchooserwidget)
318 	{
319 		foreach ( void delegate(AppInfoIF, AppChooserWidget) dlg; _appchooserwidget.onApplicationActivatedListeners )
320 		{
321 			dlg(ObjectG.getDObject!(AppInfo, AppInfoIF)(application), _appchooserwidget);
322 		}
323 	}
324 
325 	void delegate(AppInfoIF, AppChooserWidget)[] onApplicationSelectedListeners;
326 	/**
327 	 * Emitted when an application item is selected from the widget's list.
328 	 *
329 	 * Params:
330 	 *     application = the selected #GAppInfo
331 	 */
332 	void addOnApplicationSelected(void delegate(AppInfoIF, AppChooserWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
333 	{
334 		if ( "application-selected" !in connectedSignals )
335 		{
336 			Signals.connectData(
337 				this,
338 				"application-selected",
339 				cast(GCallback)&callBackApplicationSelected,
340 				cast(void*)this,
341 				null,
342 				connectFlags);
343 			connectedSignals["application-selected"] = 1;
344 		}
345 		onApplicationSelectedListeners ~= dlg;
346 	}
347 	extern(C) static void callBackApplicationSelected(GtkAppChooserWidget* appchooserwidgetStruct, GAppInfo* application, AppChooserWidget _appchooserwidget)
348 	{
349 		foreach ( void delegate(AppInfoIF, AppChooserWidget) dlg; _appchooserwidget.onApplicationSelectedListeners )
350 		{
351 			dlg(ObjectG.getDObject!(AppInfo, AppInfoIF)(application), _appchooserwidget);
352 		}
353 	}
354 
355 	void delegate(Menu, AppInfoIF, AppChooserWidget)[] onPopulatePopupListeners;
356 	/**
357 	 * Emitted when a context menu is about to popup over an application item.
358 	 * Clients can insert menu items into the provided #GtkMenu object in the
359 	 * callback of this signal; the context menu will be shown over the item
360 	 * if at least one item has been added to the menu.
361 	 *
362 	 * Params:
363 	 *     menu = the #GtkMenu to populate
364 	 *     application = the current #GAppInfo
365 	 */
366 	void addOnPopulatePopup(void delegate(Menu, AppInfoIF, AppChooserWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
367 	{
368 		if ( "populate-popup" !in connectedSignals )
369 		{
370 			Signals.connectData(
371 				this,
372 				"populate-popup",
373 				cast(GCallback)&callBackPopulatePopup,
374 				cast(void*)this,
375 				null,
376 				connectFlags);
377 			connectedSignals["populate-popup"] = 1;
378 		}
379 		onPopulatePopupListeners ~= dlg;
380 	}
381 	extern(C) static void callBackPopulatePopup(GtkAppChooserWidget* appchooserwidgetStruct, GtkMenu* menu, GAppInfo* application, AppChooserWidget _appchooserwidget)
382 	{
383 		foreach ( void delegate(Menu, AppInfoIF, AppChooserWidget) dlg; _appchooserwidget.onPopulatePopupListeners )
384 		{
385 			dlg(ObjectG.getDObject!(Menu)(menu), ObjectG.getDObject!(AppInfo, AppInfoIF)(application), _appchooserwidget);
386 		}
387 	}
388 }