gtk4/auto/
filter_list_model.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
5#[cfg(feature = "v4_12")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
7use crate::SectionModel;
8use crate::{ffi, Filter};
9use glib::{
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
12    translate::*,
13};
14use std::boxed::Box as Box_;
15
16#[cfg(feature = "v4_12")]
17#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
18glib::wrapper! {
19    #[doc(alias = "GtkFilterListModel")]
20    pub struct FilterListModel(Object<ffi::GtkFilterListModel, ffi::GtkFilterListModelClass>) @implements gio::ListModel, SectionModel;
21
22    match fn {
23        type_ => || ffi::gtk_filter_list_model_get_type(),
24    }
25}
26
27#[cfg(not(any(feature = "v4_12")))]
28glib::wrapper! {
29    #[doc(alias = "GtkFilterListModel")]
30    pub struct FilterListModel(Object<ffi::GtkFilterListModel, ffi::GtkFilterListModelClass>) @implements gio::ListModel;
31
32    match fn {
33        type_ => || ffi::gtk_filter_list_model_get_type(),
34    }
35}
36
37impl FilterListModel {
38    #[doc(alias = "gtk_filter_list_model_new")]
39    pub fn new(
40        model: Option<impl IsA<gio::ListModel>>,
41        filter: Option<impl IsA<Filter>>,
42    ) -> FilterListModel {
43        assert_initialized_main_thread!();
44        unsafe {
45            from_glib_full(ffi::gtk_filter_list_model_new(
46                model.map(|p| p.upcast()).into_glib_ptr(),
47                filter.map(|p| p.upcast()).into_glib_ptr(),
48            ))
49        }
50    }
51
52    // rustdoc-stripper-ignore-next
53    /// Creates a new builder-pattern struct instance to construct [`FilterListModel`] objects.
54    ///
55    /// This method returns an instance of [`FilterListModelBuilder`](crate::builders::FilterListModelBuilder) which can be used to create [`FilterListModel`] objects.
56    pub fn builder() -> FilterListModelBuilder {
57        FilterListModelBuilder::new()
58    }
59
60    #[doc(alias = "gtk_filter_list_model_get_filter")]
61    #[doc(alias = "get_filter")]
62    pub fn filter(&self) -> Option<Filter> {
63        unsafe { from_glib_none(ffi::gtk_filter_list_model_get_filter(self.to_glib_none().0)) }
64    }
65
66    #[doc(alias = "gtk_filter_list_model_get_incremental")]
67    #[doc(alias = "get_incremental")]
68    #[doc(alias = "incremental")]
69    pub fn is_incremental(&self) -> bool {
70        unsafe {
71            from_glib(ffi::gtk_filter_list_model_get_incremental(
72                self.to_glib_none().0,
73            ))
74        }
75    }
76
77    #[doc(alias = "gtk_filter_list_model_get_model")]
78    #[doc(alias = "get_model")]
79    pub fn model(&self) -> Option<gio::ListModel> {
80        unsafe { from_glib_none(ffi::gtk_filter_list_model_get_model(self.to_glib_none().0)) }
81    }
82
83    #[doc(alias = "gtk_filter_list_model_get_pending")]
84    #[doc(alias = "get_pending")]
85    pub fn pending(&self) -> u32 {
86        unsafe { ffi::gtk_filter_list_model_get_pending(self.to_glib_none().0) }
87    }
88
89    #[cfg(feature = "v4_20")]
90    #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
91    #[doc(alias = "gtk_filter_list_model_get_watch_items")]
92    #[doc(alias = "get_watch_items")]
93    #[doc(alias = "watch-items")]
94    pub fn is_watch_items(&self) -> bool {
95        unsafe {
96            from_glib(ffi::gtk_filter_list_model_get_watch_items(
97                self.to_glib_none().0,
98            ))
99        }
100    }
101
102    #[doc(alias = "gtk_filter_list_model_set_filter")]
103    #[doc(alias = "filter")]
104    pub fn set_filter(&self, filter: Option<&impl IsA<Filter>>) {
105        unsafe {
106            ffi::gtk_filter_list_model_set_filter(
107                self.to_glib_none().0,
108                filter.map(|p| p.as_ref()).to_glib_none().0,
109            );
110        }
111    }
112
113    #[doc(alias = "gtk_filter_list_model_set_incremental")]
114    #[doc(alias = "incremental")]
115    pub fn set_incremental(&self, incremental: bool) {
116        unsafe {
117            ffi::gtk_filter_list_model_set_incremental(
118                self.to_glib_none().0,
119                incremental.into_glib(),
120            );
121        }
122    }
123
124    #[doc(alias = "gtk_filter_list_model_set_model")]
125    #[doc(alias = "model")]
126    pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
127        unsafe {
128            ffi::gtk_filter_list_model_set_model(
129                self.to_glib_none().0,
130                model.map(|p| p.as_ref()).to_glib_none().0,
131            );
132        }
133    }
134
135    #[cfg(feature = "v4_20")]
136    #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
137    #[doc(alias = "gtk_filter_list_model_set_watch_items")]
138    #[doc(alias = "watch-items")]
139    pub fn set_watch_items(&self, watch_items: bool) {
140        unsafe {
141            ffi::gtk_filter_list_model_set_watch_items(
142                self.to_glib_none().0,
143                watch_items.into_glib(),
144            );
145        }
146    }
147
148    #[doc(alias = "filter")]
149    pub fn connect_filter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
150        unsafe extern "C" fn notify_filter_trampoline<F: Fn(&FilterListModel) + 'static>(
151            this: *mut ffi::GtkFilterListModel,
152            _param_spec: glib::ffi::gpointer,
153            f: glib::ffi::gpointer,
154        ) {
155            let f: &F = &*(f as *const F);
156            f(&from_glib_borrow(this))
157        }
158        unsafe {
159            let f: Box_<F> = Box_::new(f);
160            connect_raw(
161                self.as_ptr() as *mut _,
162                c"notify::filter".as_ptr() as *const _,
163                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
164                    notify_filter_trampoline::<F> as *const (),
165                )),
166                Box_::into_raw(f),
167            )
168        }
169    }
170
171    #[doc(alias = "incremental")]
172    pub fn connect_incremental_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
173        unsafe extern "C" fn notify_incremental_trampoline<F: Fn(&FilterListModel) + 'static>(
174            this: *mut ffi::GtkFilterListModel,
175            _param_spec: glib::ffi::gpointer,
176            f: glib::ffi::gpointer,
177        ) {
178            let f: &F = &*(f as *const F);
179            f(&from_glib_borrow(this))
180        }
181        unsafe {
182            let f: Box_<F> = Box_::new(f);
183            connect_raw(
184                self.as_ptr() as *mut _,
185                c"notify::incremental".as_ptr() as *const _,
186                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
187                    notify_incremental_trampoline::<F> as *const (),
188                )),
189                Box_::into_raw(f),
190            )
191        }
192    }
193
194    #[doc(alias = "model")]
195    pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
196        unsafe extern "C" fn notify_model_trampoline<F: Fn(&FilterListModel) + 'static>(
197            this: *mut ffi::GtkFilterListModel,
198            _param_spec: glib::ffi::gpointer,
199            f: glib::ffi::gpointer,
200        ) {
201            let f: &F = &*(f as *const F);
202            f(&from_glib_borrow(this))
203        }
204        unsafe {
205            let f: Box_<F> = Box_::new(f);
206            connect_raw(
207                self.as_ptr() as *mut _,
208                c"notify::model".as_ptr() as *const _,
209                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
210                    notify_model_trampoline::<F> as *const (),
211                )),
212                Box_::into_raw(f),
213            )
214        }
215    }
216
217    #[doc(alias = "pending")]
218    pub fn connect_pending_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
219        unsafe extern "C" fn notify_pending_trampoline<F: Fn(&FilterListModel) + 'static>(
220            this: *mut ffi::GtkFilterListModel,
221            _param_spec: glib::ffi::gpointer,
222            f: glib::ffi::gpointer,
223        ) {
224            let f: &F = &*(f as *const F);
225            f(&from_glib_borrow(this))
226        }
227        unsafe {
228            let f: Box_<F> = Box_::new(f);
229            connect_raw(
230                self.as_ptr() as *mut _,
231                c"notify::pending".as_ptr() as *const _,
232                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
233                    notify_pending_trampoline::<F> as *const (),
234                )),
235                Box_::into_raw(f),
236            )
237        }
238    }
239
240    #[cfg(feature = "v4_20")]
241    #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
242    #[doc(alias = "watch-items")]
243    pub fn connect_watch_items_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
244        unsafe extern "C" fn notify_watch_items_trampoline<F: Fn(&FilterListModel) + 'static>(
245            this: *mut ffi::GtkFilterListModel,
246            _param_spec: glib::ffi::gpointer,
247            f: glib::ffi::gpointer,
248        ) {
249            let f: &F = &*(f as *const F);
250            f(&from_glib_borrow(this))
251        }
252        unsafe {
253            let f: Box_<F> = Box_::new(f);
254            connect_raw(
255                self.as_ptr() as *mut _,
256                c"notify::watch-items".as_ptr() as *const _,
257                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
258                    notify_watch_items_trampoline::<F> as *const (),
259                )),
260                Box_::into_raw(f),
261            )
262        }
263    }
264}
265
266impl Default for FilterListModel {
267    fn default() -> Self {
268        glib::object::Object::new::<Self>()
269    }
270}
271
272// rustdoc-stripper-ignore-next
273/// A [builder-pattern] type to construct [`FilterListModel`] objects.
274///
275/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
276#[must_use = "The builder must be built to be used"]
277pub struct FilterListModelBuilder {
278    builder: glib::object::ObjectBuilder<'static, FilterListModel>,
279}
280
281impl FilterListModelBuilder {
282    fn new() -> Self {
283        Self {
284            builder: glib::object::Object::builder(),
285        }
286    }
287
288    pub fn filter(self, filter: &impl IsA<Filter>) -> Self {
289        Self {
290            builder: self.builder.property("filter", filter.clone().upcast()),
291        }
292    }
293
294    pub fn incremental(self, incremental: bool) -> Self {
295        Self {
296            builder: self.builder.property("incremental", incremental),
297        }
298    }
299
300    pub fn model(self, model: &impl IsA<gio::ListModel>) -> Self {
301        Self {
302            builder: self.builder.property("model", model.clone().upcast()),
303        }
304    }
305
306    #[cfg(feature = "v4_20")]
307    #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
308    pub fn watch_items(self, watch_items: bool) -> Self {
309        Self {
310            builder: self.builder.property("watch-items", watch_items),
311        }
312    }
313
314    // rustdoc-stripper-ignore-next
315    /// Build the [`FilterListModel`].
316    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
317    pub fn build(self) -> FilterListModel {
318        assert_initialized_main_thread!();
319        self.builder.build()
320    }
321}