1use 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")]
113 pub struct RecentChooser(Interface<ffi::GtkRecentChooser, ffi::GtkRecentChooserIface>);
114
115 match fn {
116 type_ => || ffi::gtk_recent_chooser_get_type(),
117 }
118}
119
120impl RecentChooser {
121 pub const NONE: Option<&'static RecentChooser> = None;
122}
123
124mod sealed {
125 pub trait Sealed {}
126 impl<T: super::IsA<super::RecentChooser>> Sealed for T {}
127}
128
129pub trait RecentChooserExt: IsA<RecentChooser> + sealed::Sealed + 'static {
135 #[doc(alias = "gtk_recent_chooser_add_filter")]
142 fn add_filter(&self, filter: &RecentFilter) {
143 unsafe {
144 ffi::gtk_recent_chooser_add_filter(
145 self.as_ref().to_glib_none().0,
146 filter.to_glib_none().0,
147 );
148 }
149 }
150
151 #[doc(alias = "gtk_recent_chooser_get_current_item")]
158 #[doc(alias = "get_current_item")]
159 fn current_item(&self) -> Option<RecentInfo> {
160 unsafe {
161 from_glib_full(ffi::gtk_recent_chooser_get_current_item(
162 self.as_ref().to_glib_none().0,
163 ))
164 }
165 }
166
167 #[doc(alias = "gtk_recent_chooser_get_current_uri")]
173 #[doc(alias = "get_current_uri")]
174 fn current_uri(&self) -> Option<glib::GString> {
175 unsafe {
176 from_glib_full(ffi::gtk_recent_chooser_get_current_uri(
177 self.as_ref().to_glib_none().0,
178 ))
179 }
180 }
181
182 #[doc(alias = "gtk_recent_chooser_get_filter")]
189 #[doc(alias = "get_filter")]
190 fn filter(&self) -> Option<RecentFilter> {
191 unsafe {
192 from_glib_none(ffi::gtk_recent_chooser_get_filter(
193 self.as_ref().to_glib_none().0,
194 ))
195 }
196 }
197
198 #[doc(alias = "gtk_recent_chooser_get_items")]
210 #[doc(alias = "get_items")]
211 fn items(&self) -> Vec<RecentInfo> {
212 unsafe {
213 FromGlibPtrContainer::from_glib_full(ffi::gtk_recent_chooser_get_items(
214 self.as_ref().to_glib_none().0,
215 ))
216 }
217 }
218
219 #[doc(alias = "gtk_recent_chooser_get_limit")]
227 #[doc(alias = "get_limit")]
228 fn limit(&self) -> i32 {
229 unsafe { ffi::gtk_recent_chooser_get_limit(self.as_ref().to_glib_none().0) }
230 }
231
232 #[doc(alias = "gtk_recent_chooser_get_local_only")]
239 #[doc(alias = "get_local_only")]
240 fn is_local_only(&self) -> bool {
241 unsafe {
242 from_glib(ffi::gtk_recent_chooser_get_local_only(
243 self.as_ref().to_glib_none().0,
244 ))
245 }
246 }
247
248 #[doc(alias = "gtk_recent_chooser_get_select_multiple")]
254 #[doc(alias = "get_select_multiple")]
255 fn selects_multiple(&self) -> bool {
256 unsafe {
257 from_glib(ffi::gtk_recent_chooser_get_select_multiple(
258 self.as_ref().to_glib_none().0,
259 ))
260 }
261 }
262
263 #[doc(alias = "gtk_recent_chooser_get_show_icons")]
269 #[doc(alias = "get_show_icons")]
270 fn shows_icons(&self) -> bool {
271 unsafe {
272 from_glib(ffi::gtk_recent_chooser_get_show_icons(
273 self.as_ref().to_glib_none().0,
274 ))
275 }
276 }
277
278 #[doc(alias = "gtk_recent_chooser_get_show_not_found")]
286 #[doc(alias = "get_show_not_found")]
287 fn shows_not_found(&self) -> bool {
288 unsafe {
289 from_glib(ffi::gtk_recent_chooser_get_show_not_found(
290 self.as_ref().to_glib_none().0,
291 ))
292 }
293 }
294
295 #[doc(alias = "gtk_recent_chooser_get_show_private")]
303 #[doc(alias = "get_show_private")]
304 fn shows_private(&self) -> bool {
305 unsafe {
306 from_glib(ffi::gtk_recent_chooser_get_show_private(
307 self.as_ref().to_glib_none().0,
308 ))
309 }
310 }
311
312 #[doc(alias = "gtk_recent_chooser_get_show_tips")]
320 #[doc(alias = "get_show_tips")]
321 fn shows_tips(&self) -> bool {
322 unsafe {
323 from_glib(ffi::gtk_recent_chooser_get_show_tips(
324 self.as_ref().to_glib_none().0,
325 ))
326 }
327 }
328
329 #[doc(alias = "gtk_recent_chooser_get_sort_type")]
335 #[doc(alias = "get_sort_type")]
336 fn sort_type(&self) -> RecentSortType {
337 unsafe {
338 from_glib(ffi::gtk_recent_chooser_get_sort_type(
339 self.as_ref().to_glib_none().0,
340 ))
341 }
342 }
343
344 #[doc(alias = "gtk_recent_chooser_get_uris")]
357 #[doc(alias = "get_uris")]
358 fn uris(&self) -> Vec<glib::GString> {
359 unsafe {
360 let mut length = mem::MaybeUninit::uninit();
361 let ret = FromGlibContainer::from_glib_full_num(
362 ffi::gtk_recent_chooser_get_uris(
363 self.as_ref().to_glib_none().0,
364 length.as_mut_ptr(),
365 ),
366 length.assume_init() as _,
367 );
368 ret
369 }
370 }
371
372 #[doc(alias = "gtk_recent_chooser_list_filters")]
380 fn list_filters(&self) -> Vec<RecentFilter> {
381 unsafe {
382 FromGlibPtrContainer::from_glib_container(ffi::gtk_recent_chooser_list_filters(
383 self.as_ref().to_glib_none().0,
384 ))
385 }
386 }
387
388 #[doc(alias = "gtk_recent_chooser_remove_filter")]
392 fn remove_filter(&self, filter: &RecentFilter) {
393 unsafe {
394 ffi::gtk_recent_chooser_remove_filter(
395 self.as_ref().to_glib_none().0,
396 filter.to_glib_none().0,
397 );
398 }
399 }
400
401 #[doc(alias = "gtk_recent_chooser_select_all")]
404 fn select_all(&self) {
405 unsafe {
406 ffi::gtk_recent_chooser_select_all(self.as_ref().to_glib_none().0);
407 }
408 }
409
410 #[doc(alias = "gtk_recent_chooser_select_uri")]
418 fn select_uri(&self, uri: &str) -> Result<(), glib::Error> {
419 unsafe {
420 let mut error = ptr::null_mut();
421 let is_ok = ffi::gtk_recent_chooser_select_uri(
422 self.as_ref().to_glib_none().0,
423 uri.to_glib_none().0,
424 &mut error,
425 );
426 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
427 if error.is_null() {
428 Ok(())
429 } else {
430 Err(from_glib_full(error))
431 }
432 }
433 }
434
435 #[doc(alias = "gtk_recent_chooser_set_current_uri")]
443 fn set_current_uri(&self, uri: &str) -> Result<(), glib::Error> {
444 unsafe {
445 let mut error = ptr::null_mut();
446 let is_ok = ffi::gtk_recent_chooser_set_current_uri(
447 self.as_ref().to_glib_none().0,
448 uri.to_glib_none().0,
449 &mut error,
450 );
451 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
452 if error.is_null() {
453 Ok(())
454 } else {
455 Err(from_glib_full(error))
456 }
457 }
458 }
459
460 #[doc(alias = "gtk_recent_chooser_set_filter")]
465 fn set_filter(&self, filter: Option<&RecentFilter>) {
466 unsafe {
467 ffi::gtk_recent_chooser_set_filter(
468 self.as_ref().to_glib_none().0,
469 filter.to_glib_none().0,
470 );
471 }
472 }
473
474 #[doc(alias = "gtk_recent_chooser_set_limit")]
479 fn set_limit(&self, limit: i32) {
480 unsafe {
481 ffi::gtk_recent_chooser_set_limit(self.as_ref().to_glib_none().0, limit);
482 }
483 }
484
485 #[doc(alias = "gtk_recent_chooser_set_local_only")]
492 fn set_local_only(&self, local_only: bool) {
493 unsafe {
494 ffi::gtk_recent_chooser_set_local_only(
495 self.as_ref().to_glib_none().0,
496 local_only.into_glib(),
497 );
498 }
499 }
500
501 #[doc(alias = "gtk_recent_chooser_set_select_multiple")]
505 fn set_select_multiple(&self, select_multiple: bool) {
506 unsafe {
507 ffi::gtk_recent_chooser_set_select_multiple(
508 self.as_ref().to_glib_none().0,
509 select_multiple.into_glib(),
510 );
511 }
512 }
513
514 #[doc(alias = "gtk_recent_chooser_set_show_icons")]
519 fn set_show_icons(&self, show_icons: bool) {
520 unsafe {
521 ffi::gtk_recent_chooser_set_show_icons(
522 self.as_ref().to_glib_none().0,
523 show_icons.into_glib(),
524 );
525 }
526 }
527
528 #[doc(alias = "gtk_recent_chooser_set_show_not_found")]
533 fn set_show_not_found(&self, show_not_found: bool) {
534 unsafe {
535 ffi::gtk_recent_chooser_set_show_not_found(
536 self.as_ref().to_glib_none().0,
537 show_not_found.into_glib(),
538 );
539 }
540 }
541
542 #[doc(alias = "gtk_recent_chooser_set_show_private")]
546 fn set_show_private(&self, show_private: bool) {
547 unsafe {
548 ffi::gtk_recent_chooser_set_show_private(
549 self.as_ref().to_glib_none().0,
550 show_private.into_glib(),
551 );
552 }
553 }
554
555 #[doc(alias = "gtk_recent_chooser_set_show_tips")]
560 fn set_show_tips(&self, show_tips: bool) {
561 unsafe {
562 ffi::gtk_recent_chooser_set_show_tips(
563 self.as_ref().to_glib_none().0,
564 show_tips.into_glib(),
565 );
566 }
567 }
568
569 #[doc(alias = "gtk_recent_chooser_set_sort_func")]
584 fn set_sort_func<P: Fn(&RecentInfo, &RecentInfo) -> i32 + 'static>(&self, sort_func: P) {
585 let sort_func_data: Box_<P> = Box_::new(sort_func);
586 unsafe extern "C" fn sort_func_func<P: Fn(&RecentInfo, &RecentInfo) -> i32 + 'static>(
587 a: *mut ffi::GtkRecentInfo,
588 b: *mut ffi::GtkRecentInfo,
589 user_data: glib::ffi::gpointer,
590 ) -> libc::c_int {
591 let a = from_glib_borrow(a);
592 let b = from_glib_borrow(b);
593 let callback: &P = &*(user_data as *mut _);
594 (*callback)(&a, &b)
595 }
596 let sort_func = Some(sort_func_func::<P> as _);
597 unsafe extern "C" fn data_destroy_func<P: Fn(&RecentInfo, &RecentInfo) -> i32 + 'static>(
598 data: glib::ffi::gpointer,
599 ) {
600 let _callback: Box_<P> = Box_::from_raw(data as *mut _);
601 }
602 let destroy_call3 = Some(data_destroy_func::<P> as _);
603 let super_callback0: Box_<P> = sort_func_data;
604 unsafe {
605 ffi::gtk_recent_chooser_set_sort_func(
606 self.as_ref().to_glib_none().0,
607 sort_func,
608 Box_::into_raw(super_callback0) as *mut _,
609 destroy_call3,
610 );
611 }
612 }
613
614 #[doc(alias = "gtk_recent_chooser_set_sort_type")]
619 fn set_sort_type(&self, sort_type: RecentSortType) {
620 unsafe {
621 ffi::gtk_recent_chooser_set_sort_type(
622 self.as_ref().to_glib_none().0,
623 sort_type.into_glib(),
624 );
625 }
626 }
627
628 #[doc(alias = "gtk_recent_chooser_unselect_all")]
630 fn unselect_all(&self) {
631 unsafe {
632 ffi::gtk_recent_chooser_unselect_all(self.as_ref().to_glib_none().0);
633 }
634 }
635
636 #[doc(alias = "gtk_recent_chooser_unselect_uri")]
640 fn unselect_uri(&self, uri: &str) {
641 unsafe {
642 ffi::gtk_recent_chooser_unselect_uri(
643 self.as_ref().to_glib_none().0,
644 uri.to_glib_none().0,
645 );
646 }
647 }
648
649 #[doc(alias = "item-activated")]
654 fn connect_item_activated<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
655 unsafe extern "C" fn item_activated_trampoline<
656 P: IsA<RecentChooser>,
657 F: Fn(&P) + 'static,
658 >(
659 this: *mut ffi::GtkRecentChooser,
660 f: glib::ffi::gpointer,
661 ) {
662 let f: &F = &*(f as *const F);
663 f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
664 }
665 unsafe {
666 let f: Box_<F> = Box_::new(f);
667 connect_raw(
668 self.as_ptr() as *mut _,
669 b"item-activated\0".as_ptr() as *const _,
670 Some(transmute::<_, unsafe extern "C" fn()>(
671 item_activated_trampoline::<Self, F> as *const (),
672 )),
673 Box_::into_raw(f),
674 )
675 }
676 }
677
678 #[doc(alias = "selection-changed")]
683 fn connect_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
684 unsafe extern "C" fn selection_changed_trampoline<
685 P: IsA<RecentChooser>,
686 F: Fn(&P) + 'static,
687 >(
688 this: *mut ffi::GtkRecentChooser,
689 f: glib::ffi::gpointer,
690 ) {
691 let f: &F = &*(f as *const F);
692 f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
693 }
694 unsafe {
695 let f: Box_<F> = Box_::new(f);
696 connect_raw(
697 self.as_ptr() as *mut _,
698 b"selection-changed\0".as_ptr() as *const _,
699 Some(transmute::<_, unsafe extern "C" fn()>(
700 selection_changed_trampoline::<Self, F> as *const (),
701 )),
702 Box_::into_raw(f),
703 )
704 }
705 }
706
707 #[doc(alias = "filter")]
708 fn connect_filter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
709 unsafe extern "C" fn notify_filter_trampoline<
710 P: IsA<RecentChooser>,
711 F: Fn(&P) + 'static,
712 >(
713 this: *mut ffi::GtkRecentChooser,
714 _param_spec: glib::ffi::gpointer,
715 f: glib::ffi::gpointer,
716 ) {
717 let f: &F = &*(f as *const F);
718 f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
719 }
720 unsafe {
721 let f: Box_<F> = Box_::new(f);
722 connect_raw(
723 self.as_ptr() as *mut _,
724 b"notify::filter\0".as_ptr() as *const _,
725 Some(transmute::<_, unsafe extern "C" fn()>(
726 notify_filter_trampoline::<Self, F> as *const (),
727 )),
728 Box_::into_raw(f),
729 )
730 }
731 }
732
733 #[doc(alias = "limit")]
734 fn connect_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
735 unsafe extern "C" fn notify_limit_trampoline<P: IsA<RecentChooser>, F: Fn(&P) + 'static>(
736 this: *mut ffi::GtkRecentChooser,
737 _param_spec: glib::ffi::gpointer,
738 f: glib::ffi::gpointer,
739 ) {
740 let f: &F = &*(f as *const F);
741 f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
742 }
743 unsafe {
744 let f: Box_<F> = Box_::new(f);
745 connect_raw(
746 self.as_ptr() as *mut _,
747 b"notify::limit\0".as_ptr() as *const _,
748 Some(transmute::<_, unsafe extern "C" fn()>(
749 notify_limit_trampoline::<Self, F> as *const (),
750 )),
751 Box_::into_raw(f),
752 )
753 }
754 }
755
756 #[doc(alias = "local-only")]
757 fn connect_local_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
758 unsafe extern "C" fn notify_local_only_trampoline<
759 P: IsA<RecentChooser>,
760 F: Fn(&P) + 'static,
761 >(
762 this: *mut ffi::GtkRecentChooser,
763 _param_spec: glib::ffi::gpointer,
764 f: glib::ffi::gpointer,
765 ) {
766 let f: &F = &*(f as *const F);
767 f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
768 }
769 unsafe {
770 let f: Box_<F> = Box_::new(f);
771 connect_raw(
772 self.as_ptr() as *mut _,
773 b"notify::local-only\0".as_ptr() as *const _,
774 Some(transmute::<_, unsafe extern "C" fn()>(
775 notify_local_only_trampoline::<Self, F> as *const (),
776 )),
777 Box_::into_raw(f),
778 )
779 }
780 }
781
782 #[doc(alias = "select-multiple")]
783 fn connect_select_multiple_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
784 unsafe extern "C" fn notify_select_multiple_trampoline<
785 P: IsA<RecentChooser>,
786 F: Fn(&P) + 'static,
787 >(
788 this: *mut ffi::GtkRecentChooser,
789 _param_spec: glib::ffi::gpointer,
790 f: glib::ffi::gpointer,
791 ) {
792 let f: &F = &*(f as *const F);
793 f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
794 }
795 unsafe {
796 let f: Box_<F> = Box_::new(f);
797 connect_raw(
798 self.as_ptr() as *mut _,
799 b"notify::select-multiple\0".as_ptr() as *const _,
800 Some(transmute::<_, unsafe extern "C" fn()>(
801 notify_select_multiple_trampoline::<Self, F> as *const (),
802 )),
803 Box_::into_raw(f),
804 )
805 }
806 }
807
808 #[doc(alias = "show-icons")]
809 fn connect_show_icons_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
810 unsafe extern "C" fn notify_show_icons_trampoline<
811 P: IsA<RecentChooser>,
812 F: Fn(&P) + 'static,
813 >(
814 this: *mut ffi::GtkRecentChooser,
815 _param_spec: glib::ffi::gpointer,
816 f: glib::ffi::gpointer,
817 ) {
818 let f: &F = &*(f as *const F);
819 f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
820 }
821 unsafe {
822 let f: Box_<F> = Box_::new(f);
823 connect_raw(
824 self.as_ptr() as *mut _,
825 b"notify::show-icons\0".as_ptr() as *const _,
826 Some(transmute::<_, unsafe extern "C" fn()>(
827 notify_show_icons_trampoline::<Self, F> as *const (),
828 )),
829 Box_::into_raw(f),
830 )
831 }
832 }
833
834 #[doc(alias = "show-not-found")]
835 fn connect_show_not_found_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
836 unsafe extern "C" fn notify_show_not_found_trampoline<
837 P: IsA<RecentChooser>,
838 F: Fn(&P) + 'static,
839 >(
840 this: *mut ffi::GtkRecentChooser,
841 _param_spec: glib::ffi::gpointer,
842 f: glib::ffi::gpointer,
843 ) {
844 let f: &F = &*(f as *const F);
845 f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
846 }
847 unsafe {
848 let f: Box_<F> = Box_::new(f);
849 connect_raw(
850 self.as_ptr() as *mut _,
851 b"notify::show-not-found\0".as_ptr() as *const _,
852 Some(transmute::<_, unsafe extern "C" fn()>(
853 notify_show_not_found_trampoline::<Self, F> as *const (),
854 )),
855 Box_::into_raw(f),
856 )
857 }
858 }
859
860 #[doc(alias = "show-private")]
861 fn connect_show_private_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
862 unsafe extern "C" fn notify_show_private_trampoline<
863 P: IsA<RecentChooser>,
864 F: Fn(&P) + 'static,
865 >(
866 this: *mut ffi::GtkRecentChooser,
867 _param_spec: glib::ffi::gpointer,
868 f: glib::ffi::gpointer,
869 ) {
870 let f: &F = &*(f as *const F);
871 f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
872 }
873 unsafe {
874 let f: Box_<F> = Box_::new(f);
875 connect_raw(
876 self.as_ptr() as *mut _,
877 b"notify::show-private\0".as_ptr() as *const _,
878 Some(transmute::<_, unsafe extern "C" fn()>(
879 notify_show_private_trampoline::<Self, F> as *const (),
880 )),
881 Box_::into_raw(f),
882 )
883 }
884 }
885
886 #[doc(alias = "show-tips")]
887 fn connect_show_tips_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
888 unsafe extern "C" fn notify_show_tips_trampoline<
889 P: IsA<RecentChooser>,
890 F: Fn(&P) + 'static,
891 >(
892 this: *mut ffi::GtkRecentChooser,
893 _param_spec: glib::ffi::gpointer,
894 f: glib::ffi::gpointer,
895 ) {
896 let f: &F = &*(f as *const F);
897 f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
898 }
899 unsafe {
900 let f: Box_<F> = Box_::new(f);
901 connect_raw(
902 self.as_ptr() as *mut _,
903 b"notify::show-tips\0".as_ptr() as *const _,
904 Some(transmute::<_, unsafe extern "C" fn()>(
905 notify_show_tips_trampoline::<Self, F> as *const (),
906 )),
907 Box_::into_raw(f),
908 )
909 }
910 }
911
912 #[doc(alias = "sort-type")]
913 fn connect_sort_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
914 unsafe extern "C" fn notify_sort_type_trampoline<
915 P: IsA<RecentChooser>,
916 F: Fn(&P) + 'static,
917 >(
918 this: *mut ffi::GtkRecentChooser,
919 _param_spec: glib::ffi::gpointer,
920 f: glib::ffi::gpointer,
921 ) {
922 let f: &F = &*(f as *const F);
923 f(RecentChooser::from_glib_borrow(this).unsafe_cast_ref())
924 }
925 unsafe {
926 let f: Box_<F> = Box_::new(f);
927 connect_raw(
928 self.as_ptr() as *mut _,
929 b"notify::sort-type\0".as_ptr() as *const _,
930 Some(transmute::<_, unsafe extern "C" fn()>(
931 notify_sort_type_trampoline::<Self, F> as *const (),
932 )),
933 Box_::into_raw(f),
934 )
935 }
936 }
937}
938
939impl<O: IsA<RecentChooser>> RecentChooserExt for O {}
940
941impl fmt::Display for RecentChooser {
942 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
943 f.write_str("RecentChooser")
944 }
945}