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