1#![allow(deprecated)]
5
6use crate::{ffi, Buildable, Filter};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GtkFileFilter")]
16 pub struct FileFilter(Object<ffi::GtkFileFilter>) @extends Filter, @implements Buildable;
17
18 match fn {
19 type_ => || ffi::gtk_file_filter_get_type(),
20 }
21}
22
23impl FileFilter {
24 #[doc(alias = "gtk_file_filter_new")]
25 pub fn new() -> FileFilter {
26 assert_initialized_main_thread!();
27 unsafe { from_glib_full(ffi::gtk_file_filter_new()) }
28 }
29
30 #[doc(alias = "gtk_file_filter_new_from_gvariant")]
31 #[doc(alias = "new_from_gvariant")]
32 pub fn from_gvariant(variant: &glib::Variant) -> FileFilter {
33 assert_initialized_main_thread!();
34 unsafe {
35 from_glib_full(ffi::gtk_file_filter_new_from_gvariant(
36 variant.to_glib_none().0,
37 ))
38 }
39 }
40
41 #[doc(alias = "gtk_file_filter_add_mime_type")]
42 pub fn add_mime_type(&self, mime_type: &str) {
43 unsafe {
44 ffi::gtk_file_filter_add_mime_type(self.to_glib_none().0, mime_type.to_glib_none().0);
45 }
46 }
47
48 #[doc(alias = "gtk_file_filter_add_pattern")]
49 pub fn add_pattern(&self, pattern: &str) {
50 unsafe {
51 ffi::gtk_file_filter_add_pattern(self.to_glib_none().0, pattern.to_glib_none().0);
52 }
53 }
54
55 #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
56 #[allow(deprecated)]
57 #[doc(alias = "gtk_file_filter_add_pixbuf_formats")]
58 pub fn add_pixbuf_formats(&self) {
59 unsafe {
60 ffi::gtk_file_filter_add_pixbuf_formats(self.to_glib_none().0);
61 }
62 }
63
64 #[cfg(feature = "v4_4")]
65 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
66 #[doc(alias = "gtk_file_filter_add_suffix")]
67 pub fn add_suffix(&self, suffix: &str) {
68 unsafe {
69 ffi::gtk_file_filter_add_suffix(self.to_glib_none().0, suffix.to_glib_none().0);
70 }
71 }
72
73 #[doc(alias = "gtk_file_filter_get_attributes")]
74 #[doc(alias = "get_attributes")]
75 pub fn attributes(&self) -> Vec<glib::GString> {
76 unsafe {
77 FromGlibPtrContainer::from_glib_none(ffi::gtk_file_filter_get_attributes(
78 self.to_glib_none().0,
79 ))
80 }
81 }
82
83 #[doc(alias = "gtk_file_filter_get_name")]
84 #[doc(alias = "get_name")]
85 pub fn name(&self) -> Option<glib::GString> {
86 unsafe { from_glib_none(ffi::gtk_file_filter_get_name(self.to_glib_none().0)) }
87 }
88
89 #[doc(alias = "gtk_file_filter_set_name")]
90 #[doc(alias = "name")]
91 pub fn set_name(&self, name: Option<&str>) {
92 unsafe {
93 ffi::gtk_file_filter_set_name(self.to_glib_none().0, name.to_glib_none().0);
94 }
95 }
96
97 #[doc(alias = "gtk_file_filter_to_gvariant")]
98 pub fn to_gvariant(&self) -> glib::Variant {
99 unsafe { from_glib_none(ffi::gtk_file_filter_to_gvariant(self.to_glib_none().0)) }
100 }
101
102 #[doc(alias = "name")]
103 pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
104 unsafe extern "C" fn notify_name_trampoline<F: Fn(&FileFilter) + 'static>(
105 this: *mut ffi::GtkFileFilter,
106 _param_spec: glib::ffi::gpointer,
107 f: glib::ffi::gpointer,
108 ) {
109 let f: &F = &*(f as *const F);
110 f(&from_glib_borrow(this))
111 }
112 unsafe {
113 let f: Box_<F> = Box_::new(f);
114 connect_raw(
115 self.as_ptr() as *mut _,
116 c"notify::name".as_ptr() as *const _,
117 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
118 notify_name_trampoline::<F> as *const (),
119 )),
120 Box_::into_raw(f),
121 )
122 }
123 }
124}
125
126impl Default for FileFilter {
127 fn default() -> Self {
128 Self::new()
129 }
130}