[go: up one dir, main page]

gtk4/auto/
sort_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, Sorter};
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 = "GtkSortListModel")]
20    pub struct SortListModel(Object<ffi::GtkSortListModel, ffi::GtkSortListModelClass>) @implements gio::ListModel, SectionModel;
21
22    match fn {
23        type_ => || ffi::gtk_sort_list_model_get_type(),
24    }
25}
26
27#[cfg(not(any(feature = "v4_12")))]
28glib::wrapper! {
29    #[doc(alias = "GtkSortListModel")]
30    pub struct SortListModel(Object<ffi::GtkSortListModel, ffi::GtkSortListModelClass>) @implements gio::ListModel;
31
32    match fn {
33        type_ => || ffi::gtk_sort_list_model_get_type(),
34    }
35}
36
37impl SortListModel {
38    #[doc(alias = "gtk_sort_list_model_new")]
39    pub fn new(
40        model: Option<impl IsA<gio::ListModel>>,
41        sorter: Option<impl IsA<Sorter>>,
42    ) -> SortListModel {
43        assert_initialized_main_thread!();
44        unsafe {
45            from_glib_full(ffi::gtk_sort_list_model_new(
46                model.map(|p| p.upcast()).into_glib_ptr(),
47                sorter.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 [`SortListModel`] objects.
54    ///
55    /// This method returns an instance of [`SortListModelBuilder`](crate::builders::SortListModelBuilder) which can be used to create [`SortListModel`] objects.
56    pub fn builder() -> SortListModelBuilder {
57        SortListModelBuilder::new()
58    }
59
60    #[doc(alias = "gtk_sort_list_model_get_incremental")]
61    #[doc(alias = "get_incremental")]
62    #[doc(alias = "incremental")]
63    pub fn is_incremental(&self) -> bool {
64        unsafe {
65            from_glib(ffi::gtk_sort_list_model_get_incremental(
66                self.to_glib_none().0,
67            ))
68        }
69    }
70
71    #[doc(alias = "gtk_sort_list_model_get_model")]
72    #[doc(alias = "get_model")]
73    pub fn model(&self) -> Option<gio::ListModel> {
74        unsafe { from_glib_none(ffi::gtk_sort_list_model_get_model(self.to_glib_none().0)) }
75    }
76
77    #[doc(alias = "gtk_sort_list_model_get_pending")]
78    #[doc(alias = "get_pending")]
79    pub fn pending(&self) -> u32 {
80        unsafe { ffi::gtk_sort_list_model_get_pending(self.to_glib_none().0) }
81    }
82
83    #[cfg(feature = "v4_12")]
84    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
85    #[doc(alias = "gtk_sort_list_model_get_section_sorter")]
86    #[doc(alias = "get_section_sorter")]
87    #[doc(alias = "section-sorter")]
88    pub fn section_sorter(&self) -> Option<Sorter> {
89        unsafe {
90            from_glib_none(ffi::gtk_sort_list_model_get_section_sorter(
91                self.to_glib_none().0,
92            ))
93        }
94    }
95
96    #[doc(alias = "gtk_sort_list_model_get_sorter")]
97    #[doc(alias = "get_sorter")]
98    pub fn sorter(&self) -> Option<Sorter> {
99        unsafe { from_glib_none(ffi::gtk_sort_list_model_get_sorter(self.to_glib_none().0)) }
100    }
101
102    #[doc(alias = "gtk_sort_list_model_set_incremental")]
103    #[doc(alias = "incremental")]
104    pub fn set_incremental(&self, incremental: bool) {
105        unsafe {
106            ffi::gtk_sort_list_model_set_incremental(
107                self.to_glib_none().0,
108                incremental.into_glib(),
109            );
110        }
111    }
112
113    #[doc(alias = "gtk_sort_list_model_set_model")]
114    #[doc(alias = "model")]
115    pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
116        unsafe {
117            ffi::gtk_sort_list_model_set_model(
118                self.to_glib_none().0,
119                model.map(|p| p.as_ref()).to_glib_none().0,
120            );
121        }
122    }
123
124    #[cfg(feature = "v4_12")]
125    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
126    #[doc(alias = "gtk_sort_list_model_set_section_sorter")]
127    #[doc(alias = "section-sorter")]
128    pub fn set_section_sorter(&self, sorter: Option<&impl IsA<Sorter>>) {
129        unsafe {
130            ffi::gtk_sort_list_model_set_section_sorter(
131                self.to_glib_none().0,
132                sorter.map(|p| p.as_ref()).to_glib_none().0,
133            );
134        }
135    }
136
137    #[doc(alias = "gtk_sort_list_model_set_sorter")]
138    #[doc(alias = "sorter")]
139    pub fn set_sorter(&self, sorter: Option<&impl IsA<Sorter>>) {
140        unsafe {
141            ffi::gtk_sort_list_model_set_sorter(
142                self.to_glib_none().0,
143                sorter.map(|p| p.as_ref()).to_glib_none().0,
144            );
145        }
146    }
147
148    #[doc(alias = "incremental")]
149    pub fn connect_incremental_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
150        unsafe extern "C" fn notify_incremental_trampoline<F: Fn(&SortListModel) + 'static>(
151            this: *mut ffi::GtkSortListModel,
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::incremental".as_ptr() as *const _,
163                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
164                    notify_incremental_trampoline::<F> as *const (),
165                )),
166                Box_::into_raw(f),
167            )
168        }
169    }
170
171    #[doc(alias = "model")]
172    pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
173        unsafe extern "C" fn notify_model_trampoline<F: Fn(&SortListModel) + 'static>(
174            this: *mut ffi::GtkSortListModel,
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::model".as_ptr() as *const _,
186                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
187                    notify_model_trampoline::<F> as *const (),
188                )),
189                Box_::into_raw(f),
190            )
191        }
192    }
193
194    #[doc(alias = "pending")]
195    pub fn connect_pending_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
196        unsafe extern "C" fn notify_pending_trampoline<F: Fn(&SortListModel) + 'static>(
197            this: *mut ffi::GtkSortListModel,
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::pending".as_ptr() as *const _,
209                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
210                    notify_pending_trampoline::<F> as *const (),
211                )),
212                Box_::into_raw(f),
213            )
214        }
215    }
216
217    #[cfg(feature = "v4_12")]
218    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
219    #[doc(alias = "section-sorter")]
220    pub fn connect_section_sorter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
221        unsafe extern "C" fn notify_section_sorter_trampoline<F: Fn(&SortListModel) + 'static>(
222            this: *mut ffi::GtkSortListModel,
223            _param_spec: glib::ffi::gpointer,
224            f: glib::ffi::gpointer,
225        ) {
226            let f: &F = &*(f as *const F);
227            f(&from_glib_borrow(this))
228        }
229        unsafe {
230            let f: Box_<F> = Box_::new(f);
231            connect_raw(
232                self.as_ptr() as *mut _,
233                c"notify::section-sorter".as_ptr() as *const _,
234                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
235                    notify_section_sorter_trampoline::<F> as *const (),
236                )),
237                Box_::into_raw(f),
238            )
239        }
240    }
241
242    #[doc(alias = "sorter")]
243    pub fn connect_sorter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
244        unsafe extern "C" fn notify_sorter_trampoline<F: Fn(&SortListModel) + 'static>(
245            this: *mut ffi::GtkSortListModel,
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::sorter".as_ptr() as *const _,
257                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
258                    notify_sorter_trampoline::<F> as *const (),
259                )),
260                Box_::into_raw(f),
261            )
262        }
263    }
264}
265
266impl Default for SortListModel {
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 [`SortListModel`] 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 SortListModelBuilder {
278    builder: glib::object::ObjectBuilder<'static, SortListModel>,
279}
280
281impl SortListModelBuilder {
282    fn new() -> Self {
283        Self {
284            builder: glib::object::Object::builder(),
285        }
286    }
287
288    pub fn incremental(self, incremental: bool) -> Self {
289        Self {
290            builder: self.builder.property("incremental", incremental),
291        }
292    }
293
294    pub fn model(self, model: &impl IsA<gio::ListModel>) -> Self {
295        Self {
296            builder: self.builder.property("model", model.clone().upcast()),
297        }
298    }
299
300    #[cfg(feature = "v4_12")]
301    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
302    pub fn section_sorter(self, section_sorter: &impl IsA<Sorter>) -> Self {
303        Self {
304            builder: self
305                .builder
306                .property("section-sorter", section_sorter.clone().upcast()),
307        }
308    }
309
310    pub fn sorter(self, sorter: &impl IsA<Sorter>) -> Self {
311        Self {
312            builder: self.builder.property("sorter", sorter.clone().upcast()),
313        }
314    }
315
316    // rustdoc-stripper-ignore-next
317    /// Build the [`SortListModel`].
318    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
319    pub fn build(self) -> SortListModel {
320        assert_initialized_main_thread!();
321        self.builder.build()
322    }
323}