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.RecentChooserT;
26 
27 public  import glib.ErrorG;
28 public  import glib.GException;
29 public  import glib.ListG;
30 public  import glib.ListSG;
31 public  import glib.Str;
32 public  import gobject.ObjectG;
33 public  import gobject.Signals;
34 public  import gtk.RecentFilter;
35 public  import gtk.RecentInfo;
36 public  import gtkc.gdktypes;
37 public  import gtkc.gtk;
38 public  import gtkc.gtktypes;
39 
40 
41 /**
42  * #GtkRecentChooser is an interface that can be implemented by widgets
43  * displaying the list of recently used files.  In GTK+, the main objects
44  * that implement this interface are #GtkRecentChooserWidget,
45  * #GtkRecentChooserDialog and #GtkRecentChooserMenu.
46  * 
47  * Recently used files are supported since GTK+ 2.10.
48  */
49 public template RecentChooserT(TStruct)
50 {
51 	/** Get the main Gtk struct */
52 	public GtkRecentChooser* getRecentChooserStruct()
53 	{
54 		return cast(GtkRecentChooser*)getStruct();
55 	}
56 
57 	/**
58 	 */
59 
60 	/**
61 	 * Adds @filter to the list of #GtkRecentFilter objects held by @chooser.
62 	 *
63 	 * If no previous filter objects were defined, this function will call
64 	 * gtk_recent_chooser_set_filter().
65 	 *
66 	 * Params:
67 	 *     filter = a #GtkRecentFilter
68 	 *
69 	 * Since: 2.10
70 	 */
71 	public void addFilter(RecentFilter filter)
72 	{
73 		gtk_recent_chooser_add_filter(getRecentChooserStruct(), (filter is null) ? null : filter.getRecentFilterStruct());
74 	}
75 
76 	/**
77 	 * Gets the #GtkRecentInfo currently selected by @chooser.
78 	 *
79 	 * Return: a #GtkRecentInfo.  Use gtk_recent_info_unref() when
80 	 *     when you have finished using it.
81 	 *
82 	 * Since: 2.10
83 	 */
84 	public RecentInfo getCurrentItem()
85 	{
86 		auto p = gtk_recent_chooser_get_current_item(getRecentChooserStruct());
87 		
88 		if(p is null)
89 		{
90 			return null;
91 		}
92 		
93 		return ObjectG.getDObject!(RecentInfo)(cast(GtkRecentInfo*) p);
94 	}
95 
96 	/**
97 	 * Gets the URI currently selected by @chooser.
98 	 *
99 	 * Return: a newly allocated string holding a URI.
100 	 *
101 	 * Since: 2.10
102 	 */
103 	public string getCurrentUri()
104 	{
105 		return Str.toString(gtk_recent_chooser_get_current_uri(getRecentChooserStruct()));
106 	}
107 
108 	/**
109 	 * Gets the #GtkRecentFilter object currently used by @chooser to affect
110 	 * the display of the recently used resources.
111 	 *
112 	 * Return: a #GtkRecentFilter object.
113 	 *
114 	 * Since: 2.10
115 	 */
116 	public RecentFilter getFilter()
117 	{
118 		auto p = gtk_recent_chooser_get_filter(getRecentChooserStruct());
119 		
120 		if(p is null)
121 		{
122 			return null;
123 		}
124 		
125 		return ObjectG.getDObject!(RecentFilter)(cast(GtkRecentFilter*) p);
126 	}
127 
128 	/**
129 	 * Gets the list of recently used resources in form of #GtkRecentInfo objects.
130 	 *
131 	 * The return value of this function is affected by the “sort-type” and
132 	 * “limit” properties of @chooser.
133 	 *
134 	 * Return: A newly allocated
135 	 *     list of #GtkRecentInfo objects.  You should
136 	 *     use gtk_recent_info_unref() on every item of the list, and then free
137 	 *     the list itself using g_list_free().
138 	 *
139 	 * Since: 2.10
140 	 */
141 	public ListG getItems()
142 	{
143 		auto p = gtk_recent_chooser_get_items(getRecentChooserStruct());
144 		
145 		if(p is null)
146 		{
147 			return null;
148 		}
149 		
150 		return new ListG(cast(GList*) p);
151 	}
152 
153 	/**
154 	 * Gets the number of items returned by gtk_recent_chooser_get_items()
155 	 * and gtk_recent_chooser_get_uris().
156 	 *
157 	 * Return: A positive integer, or -1 meaning that all items are
158 	 *     returned.
159 	 *
160 	 * Since: 2.10
161 	 */
162 	public int getLimit()
163 	{
164 		return gtk_recent_chooser_get_limit(getRecentChooserStruct());
165 	}
166 
167 	/**
168 	 * Gets whether only local resources should be shown in the recently used
169 	 * resources selector.  See gtk_recent_chooser_set_local_only()
170 	 *
171 	 * Return: %TRUE if only local resources should be shown.
172 	 *
173 	 * Since: 2.10
174 	 */
175 	public bool getLocalOnly()
176 	{
177 		return gtk_recent_chooser_get_local_only(getRecentChooserStruct()) != 0;
178 	}
179 
180 	/**
181 	 * Gets whether @chooser can select multiple items.
182 	 *
183 	 * Return: %TRUE if @chooser can select more than one item.
184 	 *
185 	 * Since: 2.10
186 	 */
187 	public bool getSelectMultiple()
188 	{
189 		return gtk_recent_chooser_get_select_multiple(getRecentChooserStruct()) != 0;
190 	}
191 
192 	/**
193 	 * Retrieves whether @chooser should show an icon near the resource.
194 	 *
195 	 * Return: %TRUE if the icons should be displayed, %FALSE otherwise.
196 	 *
197 	 * Since: 2.10
198 	 */
199 	public bool getShowIcons()
200 	{
201 		return gtk_recent_chooser_get_show_icons(getRecentChooserStruct()) != 0;
202 	}
203 
204 	/**
205 	 * Retrieves whether @chooser should show the recently used resources that
206 	 * were not found.
207 	 *
208 	 * Return: %TRUE if the resources not found should be displayed, and
209 	 *     %FALSE otheriwse.
210 	 *
211 	 * Since: 2.10
212 	 */
213 	public bool getShowNotFound()
214 	{
215 		return gtk_recent_chooser_get_show_not_found(getRecentChooserStruct()) != 0;
216 	}
217 
218 	/**
219 	 * Returns whether @chooser should display recently used resources
220 	 * registered as private.
221 	 *
222 	 * Return: %TRUE if the recent chooser should show private items,
223 	 *     %FALSE otherwise.
224 	 *
225 	 * Since: 2.10
226 	 */
227 	public bool getShowPrivate()
228 	{
229 		return gtk_recent_chooser_get_show_private(getRecentChooserStruct()) != 0;
230 	}
231 
232 	/**
233 	 * Gets whether @chooser should display tooltips containing the full path
234 	 * of a recently user resource.
235 	 *
236 	 * Return: %TRUE if the recent chooser should show tooltips,
237 	 *     %FALSE otherwise.
238 	 *
239 	 * Since: 2.10
240 	 */
241 	public bool getShowTips()
242 	{
243 		return gtk_recent_chooser_get_show_tips(getRecentChooserStruct()) != 0;
244 	}
245 
246 	/**
247 	 * Gets the value set by gtk_recent_chooser_set_sort_type().
248 	 *
249 	 * Return: the sorting order of the @chooser.
250 	 *
251 	 * Since: 2.10
252 	 */
253 	public GtkRecentSortType getSortType()
254 	{
255 		return gtk_recent_chooser_get_sort_type(getRecentChooserStruct());
256 	}
257 
258 	/**
259 	 * Gets the URI of the recently used resources.
260 	 *
261 	 * The return value of this function is affected by the “sort-type” and “limit”
262 	 * properties of @chooser.
263 	 *
264 	 * Since the returned array is %NULL terminated, @length may be %NULL.
265 	 *
266 	 * Return: A newly allocated, %NULL-terminated array of strings. Use
267 	 *     g_strfreev() to free it.
268 	 *
269 	 * Since: 2.10
270 	 */
271 	public string[] getUris()
272 	{
273 		size_t length;
274 		
275 		return Str.toStringArray(gtk_recent_chooser_get_uris(getRecentChooserStruct(), &length));
276 	}
277 
278 	/**
279 	 * Gets the #GtkRecentFilter objects held by @chooser.
280 	 *
281 	 * Return: A singly linked list
282 	 *     of #GtkRecentFilter objects.  You
283 	 *     should just free the returned list using g_slist_free().
284 	 *
285 	 * Since: 2.10
286 	 */
287 	public ListSG listFilters()
288 	{
289 		auto p = gtk_recent_chooser_list_filters(getRecentChooserStruct());
290 		
291 		if(p is null)
292 		{
293 			return null;
294 		}
295 		
296 		return new ListSG(cast(GSList*) p);
297 	}
298 
299 	/**
300 	 * Removes @filter from the list of #GtkRecentFilter objects held by @chooser.
301 	 *
302 	 * Params:
303 	 *     filter = a #GtkRecentFilter
304 	 *
305 	 * Since: 2.10
306 	 */
307 	public void removeFilter(RecentFilter filter)
308 	{
309 		gtk_recent_chooser_remove_filter(getRecentChooserStruct(), (filter is null) ? null : filter.getRecentFilterStruct());
310 	}
311 
312 	/**
313 	 * Selects all the items inside @chooser, if the @chooser supports
314 	 * multiple selection.
315 	 *
316 	 * Since: 2.10
317 	 */
318 	public void selectAll()
319 	{
320 		gtk_recent_chooser_select_all(getRecentChooserStruct());
321 	}
322 
323 	/**
324 	 * Selects @uri inside @chooser.
325 	 *
326 	 * Params:
327 	 *     uri = a URI
328 	 *
329 	 * Return: %TRUE if @uri was found.
330 	 *
331 	 * Since: 2.10
332 	 *
333 	 * Throws: GException on failure.
334 	 */
335 	public bool selectUri(string uri)
336 	{
337 		GError* err = null;
338 		
339 		auto p = gtk_recent_chooser_select_uri(getRecentChooserStruct(), Str.toStringz(uri), &err) != 0;
340 		
341 		if (err !is null)
342 		{
343 			throw new GException( new ErrorG(err) );
344 		}
345 		
346 		return p;
347 	}
348 
349 	/**
350 	 * Sets @uri as the current URI for @chooser.
351 	 *
352 	 * Params:
353 	 *     uri = a URI
354 	 *
355 	 * Return: %TRUE if the URI was found.
356 	 *
357 	 * Since: 2.10
358 	 *
359 	 * Throws: GException on failure.
360 	 */
361 	public bool setCurrentUri(string uri)
362 	{
363 		GError* err = null;
364 		
365 		auto p = gtk_recent_chooser_set_current_uri(getRecentChooserStruct(), Str.toStringz(uri), &err) != 0;
366 		
367 		if (err !is null)
368 		{
369 			throw new GException( new ErrorG(err) );
370 		}
371 		
372 		return p;
373 	}
374 
375 	/**
376 	 * Sets @filter as the current #GtkRecentFilter object used by @chooser
377 	 * to affect the displayed recently used resources.
378 	 *
379 	 * Params:
380 	 *     filter = a #GtkRecentFilter
381 	 *
382 	 * Since: 2.10
383 	 */
384 	public void setFilter(RecentFilter filter)
385 	{
386 		gtk_recent_chooser_set_filter(getRecentChooserStruct(), (filter is null) ? null : filter.getRecentFilterStruct());
387 	}
388 
389 	/**
390 	 * Sets the number of items that should be returned by
391 	 * gtk_recent_chooser_get_items() and gtk_recent_chooser_get_uris().
392 	 *
393 	 * Params:
394 	 *     limit = a positive integer, or -1 for all items
395 	 *
396 	 * Since: 2.10
397 	 */
398 	public void setLimit(int limit)
399 	{
400 		gtk_recent_chooser_set_limit(getRecentChooserStruct(), limit);
401 	}
402 
403 	/**
404 	 * Sets whether only local resources, that is resources using the file:// URI
405 	 * scheme, should be shown in the recently used resources selector.  If
406 	 * @local_only is %TRUE (the default) then the shown resources are guaranteed
407 	 * to be accessible through the operating system native file system.
408 	 *
409 	 * Params:
410 	 *     localOnly = %TRUE if only local files can be shown
411 	 *
412 	 * Since: 2.10
413 	 */
414 	public void setLocalOnly(bool localOnly)
415 	{
416 		gtk_recent_chooser_set_local_only(getRecentChooserStruct(), localOnly);
417 	}
418 
419 	/**
420 	 * Sets whether @chooser can select multiple items.
421 	 *
422 	 * Params:
423 	 *     selectMultiple = %TRUE if @chooser can select more than one item
424 	 *
425 	 * Since: 2.10
426 	 */
427 	public void setSelectMultiple(bool selectMultiple)
428 	{
429 		gtk_recent_chooser_set_select_multiple(getRecentChooserStruct(), selectMultiple);
430 	}
431 
432 	/**
433 	 * Sets whether @chooser should show an icon near the resource when
434 	 * displaying it.
435 	 *
436 	 * Params:
437 	 *     showIcons = whether to show an icon near the resource
438 	 *
439 	 * Since: 2.10
440 	 */
441 	public void setShowIcons(bool showIcons)
442 	{
443 		gtk_recent_chooser_set_show_icons(getRecentChooserStruct(), showIcons);
444 	}
445 
446 	/**
447 	 * Sets whether @chooser should display the recently used resources that
448 	 * it didn’t find.  This only applies to local resources.
449 	 *
450 	 * Params:
451 	 *     showNotFound = whether to show the local items we didn’t find
452 	 *
453 	 * Since: 2.10
454 	 */
455 	public void setShowNotFound(bool showNotFound)
456 	{
457 		gtk_recent_chooser_set_show_not_found(getRecentChooserStruct(), showNotFound);
458 	}
459 
460 	/**
461 	 * Whether to show recently used resources marked registered as private.
462 	 *
463 	 * Params:
464 	 *     showPrivate = %TRUE to show private items, %FALSE otherwise
465 	 *
466 	 * Since: 2.10
467 	 */
468 	public void setShowPrivate(bool showPrivate)
469 	{
470 		gtk_recent_chooser_set_show_private(getRecentChooserStruct(), showPrivate);
471 	}
472 
473 	/**
474 	 * Sets whether to show a tooltips containing the full path of each
475 	 * recently used resource in a #GtkRecentChooser widget.
476 	 *
477 	 * Params:
478 	 *     showTips = %TRUE if tooltips should be shown
479 	 *
480 	 * Since: 2.10
481 	 */
482 	public void setShowTips(bool showTips)
483 	{
484 		gtk_recent_chooser_set_show_tips(getRecentChooserStruct(), showTips);
485 	}
486 
487 	/**
488 	 * Sets the comparison function used when sorting to be @sort_func.  If
489 	 * the @chooser has the sort type set to #GTK_RECENT_SORT_CUSTOM then
490 	 * the chooser will sort using this function.
491 	 *
492 	 * To the comparison function will be passed two #GtkRecentInfo structs and
493 	 * @sort_data;  @sort_func should return a positive integer if the first
494 	 * item comes before the second, zero if the two items are equal and
495 	 * a negative integer if the first item comes after the second.
496 	 *
497 	 * Params:
498 	 *     sortFunc = the comparison function
499 	 *     sortData = user data to pass to @sort_func, or %NULL
500 	 *     dataDestroy = destroy notifier for @sort_data, or %NULL
501 	 *
502 	 * Since: 2.10
503 	 */
504 	public void setSortFunc(GtkRecentSortFunc sortFunc, void* sortData, GDestroyNotify dataDestroy)
505 	{
506 		gtk_recent_chooser_set_sort_func(getRecentChooserStruct(), sortFunc, sortData, dataDestroy);
507 	}
508 
509 	/**
510 	 * Changes the sorting order of the recently used resources list displayed by
511 	 * @chooser.
512 	 *
513 	 * Params:
514 	 *     sortType = sort order that the chooser should use
515 	 *
516 	 * Since: 2.10
517 	 */
518 	public void setSortType(GtkRecentSortType sortType)
519 	{
520 		gtk_recent_chooser_set_sort_type(getRecentChooserStruct(), sortType);
521 	}
522 
523 	/**
524 	 * Unselects all the items inside @chooser.
525 	 *
526 	 * Since: 2.10
527 	 */
528 	public void unselectAll()
529 	{
530 		gtk_recent_chooser_unselect_all(getRecentChooserStruct());
531 	}
532 
533 	/**
534 	 * Unselects @uri inside @chooser.
535 	 *
536 	 * Params:
537 	 *     uri = a URI
538 	 *
539 	 * Since: 2.10
540 	 */
541 	public void unselectUri(string uri)
542 	{
543 		gtk_recent_chooser_unselect_uri(getRecentChooserStruct(), Str.toStringz(uri));
544 	}
545 
546 	int[string] connectedSignals;
547 
548 	void delegate(RecentChooserIF)[] _onItemActivatedListeners;
549 	@property void delegate(RecentChooserIF)[] onItemActivatedListeners()
550 	{
551 		return _onItemActivatedListeners;
552 	}
553 	/**
554 	 * This signal is emitted when the user "activates" a recent item
555 	 * in the recent chooser.  This can happen by double-clicking on an item
556 	 * in the recently used resources list, or by pressing
557 	 * `Enter`.
558 	 *
559 	 * Since: 2.10
560 	 */
561 	void addOnItemActivated(void delegate(RecentChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
562 	{
563 		if ( "item-activated" !in connectedSignals )
564 		{
565 			Signals.connectData(
566 				this,
567 				"item-activated",
568 				cast(GCallback)&callBackItemActivated,
569 				cast(void*)cast(RecentChooserIF)this,
570 				null,
571 				connectFlags);
572 			connectedSignals["item-activated"] = 1;
573 		}
574 		_onItemActivatedListeners ~= dlg;
575 	}
576 	extern(C) static void callBackItemActivated(GtkRecentChooser* recentchooserStruct, RecentChooserIF _recentchooser)
577 	{
578 		foreach ( void delegate(RecentChooserIF) dlg; _recentchooser.onItemActivatedListeners )
579 		{
580 			dlg(_recentchooser);
581 		}
582 	}
583 
584 	void delegate(RecentChooserIF)[] _onSelectionChangedListeners;
585 	@property void delegate(RecentChooserIF)[] onSelectionChangedListeners()
586 	{
587 		return _onSelectionChangedListeners;
588 	}
589 	/**
590 	 * This signal is emitted when there is a change in the set of
591 	 * selected recently used resources.  This can happen when a user
592 	 * modifies the selection with the mouse or the keyboard, or when
593 	 * explicitly calling functions to change the selection.
594 	 *
595 	 * Since: 2.10
596 	 */
597 	void addOnSelectionChanged(void delegate(RecentChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
598 	{
599 		if ( "selection-changed" !in connectedSignals )
600 		{
601 			Signals.connectData(
602 				this,
603 				"selection-changed",
604 				cast(GCallback)&callBackSelectionChanged,
605 				cast(void*)cast(RecentChooserIF)this,
606 				null,
607 				connectFlags);
608 			connectedSignals["selection-changed"] = 1;
609 		}
610 		_onSelectionChangedListeners ~= dlg;
611 	}
612 	extern(C) static void callBackSelectionChanged(GtkRecentChooser* recentchooserStruct, RecentChooserIF _recentchooser)
613 	{
614 		foreach ( void delegate(RecentChooserIF) dlg; _recentchooser.onSelectionChangedListeners )
615 		{
616 			dlg(_recentchooser);
617 		}
618 	}
619 }