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