gtk/auto/
recent_chooser.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{RecentFilter, RecentInfo, RecentSortType};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem, mem::transmute, ptr};
12
13glib::wrapper! {
14    #[doc(alias = "GtkRecentChooser")]
15    pub struct RecentChooser(Interface<ffi::GtkRecentChooser, ffi::GtkRecentChooserIface>);
16
17    match fn {
18        type_ => || ffi::gtk_recent_chooser_get_type(),
19    }
20}
21
22impl RecentChooser {
23    pub const NONE: Option<&'static RecentChooser> = None;
24}
25
26mod sealed {
27    pub trait Sealed {}
28    impl<T: super::IsA<super::RecentChooser>> Sealed for T {}
29}
30
31pub trait RecentChooserExt: IsA<RecentChooser> + sealed::Sealed + 'static {
32    #[doc(alias = "gtk_recent_chooser_add_filter")]
33    fn add_filter(&self, filter: &RecentFilter) {
34        unsafe {
35            ffi::gtk_recent_chooser_add_filter(
36                self.as_ref().to_glib_none().0,
37                filter.to_glib_none().0,
38            );
39        }
40    }
41
42    #[doc(alias = "gtk_recent_chooser_get_current_item")]
43    #[doc(alias = "get_current_item")]
44    fn current_item(&self) -> Option<RecentInfo> {
45        unsafe {
46            from_glib_full(ffi::gtk_recent_chooser_get_current_item(
47                self.as_ref().to_glib_none().0,
48            ))
49        }
50    }
51
52    #[doc(alias = "gtk_recent_chooser_get_current_uri")]
53    #[doc(alias = "get_current_uri")]
54    fn current_uri(&self) -> Option<glib::GString> {
55        unsafe {
56            from_glib_full(ffi::gtk_recent_chooser_get_current_uri(
57                self.as_ref().to_glib_none().0,
58            ))
59        }
60    }
61
62    #[doc(alias = "gtk_recent_chooser_get_filter")]
63    #[doc(alias = "get_filter")]
64    fn filter(&self) -> Option<RecentFilter> {
65        unsafe {
66            from_glib_none(ffi::gtk_recent_chooser_get_filter(
67                self.as_ref().to_glib_none().0,
68            ))
69        }
70    }
71
72    #[doc(alias = "gtk_recent_chooser_get_items")]
73    #[doc(alias = "get_items")]
74    fn items(&self) -> Vec<RecentInfo> {
75        unsafe {
76            FromGlibPtrContainer::from_glib_full(ffi::gtk_recent_chooser_get_items(
77                self.as_ref().to_glib_none().0,
78            ))
79        }
80    }
81
82    #[doc(alias = "gtk_recent_chooser_get_limit")]
83    #[doc(alias = "get_limit")]
84    fn limit(&self) -> i32 {
85        unsafe { ffi::gtk_recent_chooser_get_limit(self.as_ref().to_glib_none().0) }
86    }
87
88    #[doc(alias = "gtk_recent_chooser_get_local_only")]
89    #[doc(alias = "get_local_only")]
90    fn is_local_only(&self) -> bool {
91        unsafe {
92            from_glib(ffi::gtk_recent_chooser_get_local_only(
93                self.as_ref().to_glib_none().0,
94            ))
95        }
96    }
97
98    #[doc(alias = "gtk_recent_chooser_get_select_multiple")]
99    #[doc(alias = "get_select_multiple")]
100    fn selects_multiple(&self) -> bool {
101        unsafe {
102            from_glib(ffi::gtk_recent_chooser_get_select_multiple(
103                self.as_ref().to_glib_none().0,
104            ))
105        }
106    }
107
108    #[doc(alias = "gtk_recent_chooser_get_show_icons")]
109    #[doc(alias = "get_show_icons")]
110    fn shows_icons(&self) -> bool {
111        unsafe {
112            from_glib(ffi::gtk_recent_chooser_get_show_icons(
113                self.as_ref().to_glib_none().0,
114            ))
115        }
116    }
117
118    #[doc(alias = "gtk_recent_chooser_get_show_not_found")]
119    #[doc(alias = "get_show_not_found")]
120    fn shows_not_found(&self) -> bool {
121        unsafe {
122            from_glib(ffi::gtk_recent_chooser_get_show_not_found(
123                self.as_ref().to_glib_none().0,
124            ))
125        }
126    }
127
128    #[doc(alias = "gtk_recent_chooser_get_show_private")]
129    #[doc(alias = "get_show_private")]
130    fn shows_private(&self) -> bool {
131        unsafe {
132            from_glib(ffi::gtk_recent_chooser_get_show_private(
133                self.as_ref().to_glib_none().0,
134            ))
135        }
136    }
137
138    #[doc(alias = "gtk_recent_chooser_get_show_tips")]
139    #[doc(alias = "get_show_tips")]
140    fn shows_tips(&self) -> bool {
141        unsafe {
142            from_glib(ffi::gtk_recent_chooser_get_show_tips(
143                self.as_ref().to_glib_none().0,
144            ))
145        }
146    }
147
148    #[doc(alias = "gtk_recent_chooser_get_sort_type")]
149    #[doc(alias = "get_sort_type")]
150    fn sort_type(&self) -> RecentSortType {
151        unsafe {
152            from_glib(ffi::gtk_recent_chooser_get_sort_type(
153                self.as_ref().to_glib_none().0,
154            ))
155        }
156    }
157
158    #[doc(alias = "gtk_recent_chooser_get_uris")]
159    #[doc(alias = "get_uris")]
160    fn uris(&self) -> Vec<glib::GString> {
161        unsafe {
162            let mut length = mem::MaybeUninit::uninit();
163            let ret = FromGlibContainer::from_glib_full_num(
164                ffi::gtk_recent_chooser_get_uris(
165                    self.as_ref().to_glib_none().0,
166                    length.as_mut_ptr(),
167                ),
168                length.assume_init() as _,
169            );
170            ret
171        }
172    }
173
174    #[doc(alias = "gtk_recent_chooser_list_filters")]
175    fn list_filters(&self) -> Vec<RecentFilter> {
176        unsafe {
177            FromGlibPtrContainer::from_glib_container(ffi::gtk_recent_chooser_list_filters(
178                self.as_ref().to_glib_none().0,
179            ))
180        }
181    }
182
183    #[doc(alias = "gtk_recent_chooser_remove_filter")]
184    fn remove_filter(&self, filter: &RecentFilter) {
185        unsafe {
186            ffi::gtk_recent_chooser_remove_filter(
187                self.as_ref().to_glib_none().0,
188                filter.to_glib_none().0,
189            );
190        }
191    }
192
193    #[doc(alias = "gtk_recent_chooser_select_all")]
194    fn select_all(&self) {
195        unsafe {
196            ffi::gtk_recent_chooser_select_all(self.as_ref().to_glib_none().0);
197        }
198    }
199
200    #[doc(alias = "gtk_recent_chooser_select_uri")]
201    fn select_uri(&self, uri: &str) -> Result<(), glib::Error> {
202        unsafe {
203            let mut error = ptr::null_mut();
204            let is_ok = ffi::gtk_recent_chooser_select_uri(
205                self.as_ref().to_glib_none().0,
206                uri.to_glib_none().0,
207                &mut error,
208            );
209            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
210            if error.is_null() {
211                Ok(())
212            } else {
213                Err(from_glib_full(error))
214            }
215        }
216    }
217
218    #[doc(alias = "gtk_recent_chooser_set_current_uri")]
219    fn set_current_uri(&self, uri: &str) -> Result<(), glib::Error> {
220        unsafe {
221            let mut error = ptr::null_mut();
222            let is_ok = ffi::gtk_recent_chooser_set_current_uri(
223                self.as_ref().to_glib_none().0,
224                uri.to_glib_none().0,
225                &mut error,
226            );
227            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
228            if error.is_null() {
229                Ok(())
230            } else {
231                Err(from_glib_full(error))
232            }
233        }
234    }
235
236    #[doc(alias = "gtk_recent_chooser_set_filter")]
237    fn set_filter(&self, filter: Option<&RecentFilter>) {
238        unsafe {
239            ffi::gtk_recent_chooser_set_filter(
240                self.as_ref().to_glib_none().0,
241                filter.to_glib_none().0,
242            );
243        }
244    }
245
246    #[doc(alias = "gtk_recent_chooser_set_limit")]
247    fn set_limit(&self, limit: i32) {
248        unsafe {
249            ffi::gtk_recent_chooser_set_limit(self.as_ref().to_glib_none().0, limit);
250        }
251    }
252
253    #[doc(alias = "gtk_recent_chooser_set_local_only")]
254    fn set_local_only(&self, local_only: bool) {
255        unsafe {
256            ffi::gtk_recent_chooser_set_local_only(
257                self.as_ref().to_glib_none().0,
258                local_only.into_glib(),
259            );
260        }
261    }
262
263    #[doc(alias = "gtk_recent_chooser_set_select_multiple")]
264    fn set_select_multiple(&self, select_multiple: bool) {
265        unsafe {
266            ffi::gtk_recent_chooser_set_select_multiple(
267                self.as_ref().to_glib_none().0,
268                select_multiple.into_glib(),
269            );
270        }
271    }
272
273    #[doc(alias = "gtk_recent_chooser_set_show_icons")]
274    fn set_show_icons(&self, show_icons: bool) {
275        unsafe {
276            ffi::gtk_recent_chooser_set_show_icons(
277                self.as_ref().to_glib_none().0,
278                show_icons.into_glib(),
279            );
280        }
281    }
282
283    #[doc(alias = "gtk_recent_chooser_set_show_not_found")]
284    fn set_show_not_found(&self, show_not_found: bool) {
285        unsafe {
286            ffi::gtk_recent_chooser_set_show_not_found(
287                self.as_ref().to_glib_none().0,
288                show_not_found.into_glib(),
289            );
290        }
291    }
292
293    #[doc(alias = "gtk_recent_chooser_set_show_private")]
294    fn set_show_private(&self, show_private: bool) {
295        unsafe {
296            ffi::gtk_recent_chooser_set_show_private(
297                self.as_ref().to_glib_none().0,
298                show_private.into_glib(),
299            );
300        }
301    }
302
303    #[doc(alias = "gtk_recent_chooser_set_show_tips")]
304    fn set_show_tips(&self, show_tips: bool) {
305        unsafe {
306            ffi::gtk_recent_chooser_set_show_tips(
307                self.as_ref().to_glib_none().0,
308                show_tips.into_glib(),
309            );
310        }
311    }
312
313    #[doc(alias = "gtk_recent_chooser_set_sort_func")]
314    fn set_sort_func<P: Fn(&RecentInfo, &RecentInfo) -> i32 + 'static>(&self, sort_func: P) {
315        let sort_func_data: Box_<P> = Box_::new(sort_func);
316        unsafe extern "C" fn sort_func_func<P: Fn(&RecentInfo, &RecentInfo) -> i32 + 'static>(
317            a: *mut ffi::GtkRecentInfo,
318            b: *mut ffi::GtkRecentInfo,
319            user_data: glib::ffi::gpointer,
320        ) -> libc::c_int {
321            let a = from_glib_borrow(a);
322            let b = from_glib_borrow(b);
323            let callback: &P = &*(user_data as *mut _);
324            (*callback)(&a, &b)
325        }
326        let sort_func = Some(sort_func_func::<P> as _);
327        unsafe extern "C" fn data_destroy_func<P: Fn(&RecentInfo, &RecentInfo) -> i32 + 'static>(
328            data: glib::ffi::gpointer,
329        ) {
330            let _callback: Box_<P> = Box_::from_raw(data as *mut _);
331        }
332        let destroy_call3 = Some(data_destroy_func::<P> as _);
333        let super_callback0: Box_<P> = sort_func_data;
334        unsafe {
335            ffi::gtk_recent_chooser_set_sort_func(
336                self.as_ref().to_glib_none().0,
337                sort_func,
338                Box_::into_raw(super_callback0) as *mut _,
339                destroy_call3,
340            );
341        }
342    }
343
344    #[doc(alias = "gtk_recent_chooser_set_sort_type")]
345    fn set_sort_type(&self, sort_type: RecentSortType) {
346        unsafe {
347            ffi::gtk_recent_chooser_set_sort_type(
348                self.as_ref().to_glib_none().0,
349                sort_type.into_glib(),
350            );
351        }
352    }
353
354    #[doc(alias = "gtk_recent_chooser_unselect_all")]
355    fn unselect_all(&self) {
356        unsafe {
357            ffi::gtk_recent_chooser_unselect_all(self.as_ref().to_glib_none().0);
358        }
359    }
360
361    #[doc(alias = "gtk_recent_chooser_unselect_uri")]
362    fn unselect_uri(&self, uri: &str) {
363        unsafe {
364            ffi::gtk_recent_chooser_unselect_uri(
365                self.as_ref().to_glib_none().0,
366                uri.to_glib_none().0,
367            );
368        }
369    }
370
371    #[doc(alias = "item-activated")]
372    fn connect_item_activated<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
373        unsafe extern "C" fn item_activated_trampoline<
374            P: IsA<RecentChooser>,
375            F: Fn(&P) + 'static,
376        >(
377            this: *mut ffi::GtkRecentChooser,
378            f: glib::ffi::gpointer,
379        ) {
380            let f: &F = &*(f as *const F);
381            f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
382        }
383        unsafe {
384            let f: Box_<F> = Box_::new(f);
385            connect_raw(
386                self.as_ptr() as *mut _,
387                b"item-activated\0".as_ptr() as *const _,
388                Some(transmute::<_, unsafe extern "C" fn()>(
389                    item_activated_trampoline::<Self, F> as *const (),
390                )),
391                Box_::into_raw(f),
392            )
393        }
394    }
395
396    #[doc(alias = "selection-changed")]
397    fn connect_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
398        unsafe extern "C" fn selection_changed_trampoline<
399            P: IsA<RecentChooser>,
400            F: Fn(&P) + 'static,
401        >(
402            this: *mut ffi::GtkRecentChooser,
403            f: glib::ffi::gpointer,
404        ) {
405            let f: &F = &*(f as *const F);
406            f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
407        }
408        unsafe {
409            let f: Box_<F> = Box_::new(f);
410            connect_raw(
411                self.as_ptr() as *mut _,
412                b"selection-changed\0".as_ptr() as *const _,
413                Some(transmute::<_, unsafe extern "C" fn()>(
414                    selection_changed_trampoline::<Self, F> as *const (),
415                )),
416                Box_::into_raw(f),
417            )
418        }
419    }
420
421    #[doc(alias = "filter")]
422    fn connect_filter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
423        unsafe extern "C" fn notify_filter_trampoline<
424            P: IsA<RecentChooser>,
425            F: Fn(&P) + 'static,
426        >(
427            this: *mut ffi::GtkRecentChooser,
428            _param_spec: glib::ffi::gpointer,
429            f: glib::ffi::gpointer,
430        ) {
431            let f: &F = &*(f as *const F);
432            f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
433        }
434        unsafe {
435            let f: Box_<F> = Box_::new(f);
436            connect_raw(
437                self.as_ptr() as *mut _,
438                b"notify::filter\0".as_ptr() as *const _,
439                Some(transmute::<_, unsafe extern "C" fn()>(
440                    notify_filter_trampoline::<Self, F> as *const (),
441                )),
442                Box_::into_raw(f),
443            )
444        }
445    }
446
447    #[doc(alias = "limit")]
448    fn connect_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
449        unsafe extern "C" fn notify_limit_trampoline<P: IsA<RecentChooser>, F: Fn(&P) + 'static>(
450            this: *mut ffi::GtkRecentChooser,
451            _param_spec: glib::ffi::gpointer,
452            f: glib::ffi::gpointer,
453        ) {
454            let f: &F = &*(f as *const F);
455            f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
456        }
457        unsafe {
458            let f: Box_<F> = Box_::new(f);
459            connect_raw(
460                self.as_ptr() as *mut _,
461                b"notify::limit\0".as_ptr() as *const _,
462                Some(transmute::<_, unsafe extern "C" fn()>(
463                    notify_limit_trampoline::<Self, F> as *const (),
464                )),
465                Box_::into_raw(f),
466            )
467        }
468    }
469
470    #[doc(alias = "local-only")]
471    fn connect_local_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
472        unsafe extern "C" fn notify_local_only_trampoline<
473            P: IsA<RecentChooser>,
474            F: Fn(&P) + 'static,
475        >(
476            this: *mut ffi::GtkRecentChooser,
477            _param_spec: glib::ffi::gpointer,
478            f: glib::ffi::gpointer,
479        ) {
480            let f: &F = &*(f as *const F);
481            f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
482        }
483        unsafe {
484            let f: Box_<F> = Box_::new(f);
485            connect_raw(
486                self.as_ptr() as *mut _,
487                b"notify::local-only\0".as_ptr() as *const _,
488                Some(transmute::<_, unsafe extern "C" fn()>(
489                    notify_local_only_trampoline::<Self, F> as *const (),
490                )),
491                Box_::into_raw(f),
492            )
493        }
494    }
495
496    #[doc(alias = "select-multiple")]
497    fn connect_select_multiple_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
498        unsafe extern "C" fn notify_select_multiple_trampoline<
499            P: IsA<RecentChooser>,
500            F: Fn(&P) + 'static,
501        >(
502            this: *mut ffi::GtkRecentChooser,
503            _param_spec: glib::ffi::gpointer,
504            f: glib::ffi::gpointer,
505        ) {
506            let f: &F = &*(f as *const F);
507            f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
508        }
509        unsafe {
510            let f: Box_<F> = Box_::new(f);
511            connect_raw(
512                self.as_ptr() as *mut _,
513                b"notify::select-multiple\0".as_ptr() as *const _,
514                Some(transmute::<_, unsafe extern "C" fn()>(
515                    notify_select_multiple_trampoline::<Self, F> as *const (),
516                )),
517                Box_::into_raw(f),
518            )
519        }
520    }
521
522    #[doc(alias = "show-icons")]
523    fn connect_show_icons_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
524        unsafe extern "C" fn notify_show_icons_trampoline<
525            P: IsA<RecentChooser>,
526            F: Fn(&P) + 'static,
527        >(
528            this: *mut ffi::GtkRecentChooser,
529            _param_spec: glib::ffi::gpointer,
530            f: glib::ffi::gpointer,
531        ) {
532            let f: &F = &*(f as *const F);
533            f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
534        }
535        unsafe {
536            let f: Box_<F> = Box_::new(f);
537            connect_raw(
538                self.as_ptr() as *mut _,
539                b"notify::show-icons\0".as_ptr() as *const _,
540                Some(transmute::<_, unsafe extern "C" fn()>(
541                    notify_show_icons_trampoline::<Self, F> as *const (),
542                )),
543                Box_::into_raw(f),
544            )
545        }
546    }
547
548    #[doc(alias = "show-not-found")]
549    fn connect_show_not_found_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
550        unsafe extern "C" fn notify_show_not_found_trampoline<
551            P: IsA<RecentChooser>,
552            F: Fn(&P) + 'static,
553        >(
554            this: *mut ffi::GtkRecentChooser,
555            _param_spec: glib::ffi::gpointer,
556            f: glib::ffi::gpointer,
557        ) {
558            let f: &F = &*(f as *const F);
559            f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
560        }
561        unsafe {
562            let f: Box_<F> = Box_::new(f);
563            connect_raw(
564                self.as_ptr() as *mut _,
565                b"notify::show-not-found\0".as_ptr() as *const _,
566                Some(transmute::<_, unsafe extern "C" fn()>(
567                    notify_show_not_found_trampoline::<Self, F> as *const (),
568                )),
569                Box_::into_raw(f),
570            )
571        }
572    }
573
574    #[doc(alias = "show-private")]
575    fn connect_show_private_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
576        unsafe extern "C" fn notify_show_private_trampoline<
577            P: IsA<RecentChooser>,
578            F: Fn(&P) + 'static,
579        >(
580            this: *mut ffi::GtkRecentChooser,
581            _param_spec: glib::ffi::gpointer,
582            f: glib::ffi::gpointer,
583        ) {
584            let f: &F = &*(f as *const F);
585            f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
586        }
587        unsafe {
588            let f: Box_<F> = Box_::new(f);
589            connect_raw(
590                self.as_ptr() as *mut _,
591                b"notify::show-private\0".as_ptr() as *const _,
592                Some(transmute::<_, unsafe extern "C" fn()>(
593                    notify_show_private_trampoline::<Self, F> as *const (),
594                )),
595                Box_::into_raw(f),
596            )
597        }
598    }
599
600    #[doc(alias = "show-tips")]
601    fn connect_show_tips_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
602        unsafe extern "C" fn notify_show_tips_trampoline<
603            P: IsA<RecentChooser>,
604            F: Fn(&P) + 'static,
605        >(
606            this: *mut ffi::GtkRecentChooser,
607            _param_spec: glib::ffi::gpointer,
608            f: glib::ffi::gpointer,
609        ) {
610            let f: &F = &*(f as *const F);
611            f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
612        }
613        unsafe {
614            let f: Box_<F> = Box_::new(f);
615            connect_raw(
616                self.as_ptr() as *mut _,
617                b"notify::show-tips\0".as_ptr() as *const _,
618                Some(transmute::<_, unsafe extern "C" fn()>(
619                    notify_show_tips_trampoline::<Self, F> as *const (),
620                )),
621                Box_::into_raw(f),
622            )
623        }
624    }
625
626    #[doc(alias = "sort-type")]
627    fn connect_sort_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
628        unsafe extern "C" fn notify_sort_type_trampoline<
629            P: IsA<RecentChooser>,
630            F: Fn(&P) + 'static,
631        >(
632            this: *mut ffi::GtkRecentChooser,
633            _param_spec: glib::ffi::gpointer,
634            f: glib::ffi::gpointer,
635        ) {
636            let f: &F = &*(f as *const F);
637            f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
638        }
639        unsafe {
640            let f: Box_<F> = Box_::new(f);
641            connect_raw(
642                self.as_ptr() as *mut _,
643                b"notify::sort-type\0".as_ptr() as *const _,
644                Some(transmute::<_, unsafe extern "C" fn()>(
645                    notify_sort_type_trampoline::<Self, F> as *const (),
646                )),
647                Box_::into_raw(f),
648            )
649        }
650    }
651}
652
653impl<O: IsA<RecentChooser>> RecentChooserExt for O {}
654
655impl fmt::Display for RecentChooser {
656    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
657        f.write_str("RecentChooser")
658    }
659}