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