1#[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")]
78 pub struct FilterListModel(Object<ffi::GtkFilterListModel, ffi::GtkFilterListModelClass>) @implements gio::ListModel, SectionModel;
79
80 match fn {
81 type_ => || ffi::gtk_filter_list_model_get_type(),
82 }
83}
84
85#[cfg(not(any(feature = "v4_12")))]
86glib::wrapper! {
87 #[doc(alias = "GtkFilterListModel")]
88 pub struct FilterListModel(Object<ffi::GtkFilterListModel, ffi::GtkFilterListModelClass>) @implements gio::ListModel;
89
90 match fn {
91 type_ => || ffi::gtk_filter_list_model_get_type(),
92 }
93}
94
95impl FilterListModel {
96 #[doc(alias = "gtk_filter_list_model_new")]
107 pub fn new(
108 model: Option<impl IsA<gio::ListModel>>,
109 filter: Option<impl IsA<Filter>>,
110 ) -> FilterListModel {
111 assert_initialized_main_thread!();
112 unsafe {
113 from_glib_full(ffi::gtk_filter_list_model_new(
114 model.map(|p| p.upcast()).into_glib_ptr(),
115 filter.map(|p| p.upcast()).into_glib_ptr(),
116 ))
117 }
118 }
119
120 pub fn builder() -> FilterListModelBuilder {
125 FilterListModelBuilder::new()
126 }
127
128 #[doc(alias = "gtk_filter_list_model_get_filter")]
134 #[doc(alias = "get_filter")]
135 pub fn filter(&self) -> Option<Filter> {
136 unsafe { from_glib_none(ffi::gtk_filter_list_model_get_filter(self.to_glib_none().0)) }
137 }
138
139 #[doc(alias = "gtk_filter_list_model_get_incremental")]
147 #[doc(alias = "get_incremental")]
148 #[doc(alias = "incremental")]
149 pub fn is_incremental(&self) -> bool {
150 unsafe {
151 from_glib(ffi::gtk_filter_list_model_get_incremental(
152 self.to_glib_none().0,
153 ))
154 }
155 }
156
157 #[doc(alias = "gtk_filter_list_model_get_model")]
163 #[doc(alias = "get_model")]
164 pub fn model(&self) -> Option<gio::ListModel> {
165 unsafe { from_glib_none(ffi::gtk_filter_list_model_get_model(self.to_glib_none().0)) }
166 }
167
168 #[doc(alias = "gtk_filter_list_model_get_pending")]
191 #[doc(alias = "get_pending")]
192 pub fn pending(&self) -> u32 {
193 unsafe { ffi::gtk_filter_list_model_get_pending(self.to_glib_none().0) }
194 }
195
196 #[cfg(feature = "v4_20")]
204 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
205 #[doc(alias = "gtk_filter_list_model_get_watch_items")]
206 #[doc(alias = "get_watch_items")]
207 #[doc(alias = "watch-items")]
208 pub fn is_watch_items(&self) -> bool {
209 unsafe {
210 from_glib(ffi::gtk_filter_list_model_get_watch_items(
211 self.to_glib_none().0,
212 ))
213 }
214 }
215
216 #[doc(alias = "gtk_filter_list_model_set_filter")]
220 #[doc(alias = "filter")]
221 pub fn set_filter(&self, filter: Option<&impl IsA<Filter>>) {
222 unsafe {
223 ffi::gtk_filter_list_model_set_filter(
224 self.to_glib_none().0,
225 filter.map(|p| p.as_ref()).to_glib_none().0,
226 );
227 }
228 }
229
230 #[doc(alias = "gtk_filter_list_model_set_incremental")]
249 #[doc(alias = "incremental")]
250 pub fn set_incremental(&self, incremental: bool) {
251 unsafe {
252 ffi::gtk_filter_list_model_set_incremental(
253 self.to_glib_none().0,
254 incremental.into_glib(),
255 );
256 }
257 }
258
259 #[doc(alias = "gtk_filter_list_model_set_model")]
268 #[doc(alias = "model")]
269 pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
270 unsafe {
271 ffi::gtk_filter_list_model_set_model(
272 self.to_glib_none().0,
273 model.map(|p| p.as_ref()).to_glib_none().0,
274 );
275 }
276 }
277
278 #[cfg(feature = "v4_20")]
288 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
289 #[doc(alias = "gtk_filter_list_model_set_watch_items")]
290 #[doc(alias = "watch-items")]
291 pub fn set_watch_items(&self, watch_items: bool) {
292 unsafe {
293 ffi::gtk_filter_list_model_set_watch_items(
294 self.to_glib_none().0,
295 watch_items.into_glib(),
296 );
297 }
298 }
299
300 #[doc(alias = "filter")]
301 pub fn connect_filter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
302 unsafe extern "C" fn notify_filter_trampoline<F: Fn(&FilterListModel) + 'static>(
303 this: *mut ffi::GtkFilterListModel,
304 _param_spec: glib::ffi::gpointer,
305 f: glib::ffi::gpointer,
306 ) {
307 let f: &F = &*(f as *const F);
308 f(&from_glib_borrow(this))
309 }
310 unsafe {
311 let f: Box_<F> = Box_::new(f);
312 connect_raw(
313 self.as_ptr() as *mut _,
314 c"notify::filter".as_ptr() as *const _,
315 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
316 notify_filter_trampoline::<F> as *const (),
317 )),
318 Box_::into_raw(f),
319 )
320 }
321 }
322
323 #[doc(alias = "incremental")]
324 pub fn connect_incremental_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
325 unsafe extern "C" fn notify_incremental_trampoline<F: Fn(&FilterListModel) + 'static>(
326 this: *mut ffi::GtkFilterListModel,
327 _param_spec: glib::ffi::gpointer,
328 f: glib::ffi::gpointer,
329 ) {
330 let f: &F = &*(f as *const F);
331 f(&from_glib_borrow(this))
332 }
333 unsafe {
334 let f: Box_<F> = Box_::new(f);
335 connect_raw(
336 self.as_ptr() as *mut _,
337 c"notify::incremental".as_ptr() as *const _,
338 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
339 notify_incremental_trampoline::<F> as *const (),
340 )),
341 Box_::into_raw(f),
342 )
343 }
344 }
345
346 #[doc(alias = "model")]
347 pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
348 unsafe extern "C" fn notify_model_trampoline<F: Fn(&FilterListModel) + 'static>(
349 this: *mut ffi::GtkFilterListModel,
350 _param_spec: glib::ffi::gpointer,
351 f: glib::ffi::gpointer,
352 ) {
353 let f: &F = &*(f as *const F);
354 f(&from_glib_borrow(this))
355 }
356 unsafe {
357 let f: Box_<F> = Box_::new(f);
358 connect_raw(
359 self.as_ptr() as *mut _,
360 c"notify::model".as_ptr() as *const _,
361 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
362 notify_model_trampoline::<F> as *const (),
363 )),
364 Box_::into_raw(f),
365 )
366 }
367 }
368
369 #[doc(alias = "pending")]
370 pub fn connect_pending_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
371 unsafe extern "C" fn notify_pending_trampoline<F: Fn(&FilterListModel) + 'static>(
372 this: *mut ffi::GtkFilterListModel,
373 _param_spec: glib::ffi::gpointer,
374 f: glib::ffi::gpointer,
375 ) {
376 let f: &F = &*(f as *const F);
377 f(&from_glib_borrow(this))
378 }
379 unsafe {
380 let f: Box_<F> = Box_::new(f);
381 connect_raw(
382 self.as_ptr() as *mut _,
383 c"notify::pending".as_ptr() as *const _,
384 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
385 notify_pending_trampoline::<F> as *const (),
386 )),
387 Box_::into_raw(f),
388 )
389 }
390 }
391
392 #[cfg(feature = "v4_20")]
393 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
394 #[doc(alias = "watch-items")]
395 pub fn connect_watch_items_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
396 unsafe extern "C" fn notify_watch_items_trampoline<F: Fn(&FilterListModel) + 'static>(
397 this: *mut ffi::GtkFilterListModel,
398 _param_spec: glib::ffi::gpointer,
399 f: glib::ffi::gpointer,
400 ) {
401 let f: &F = &*(f as *const F);
402 f(&from_glib_borrow(this))
403 }
404 unsafe {
405 let f: Box_<F> = Box_::new(f);
406 connect_raw(
407 self.as_ptr() as *mut _,
408 c"notify::watch-items".as_ptr() as *const _,
409 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
410 notify_watch_items_trampoline::<F> as *const (),
411 )),
412 Box_::into_raw(f),
413 )
414 }
415 }
416}
417
418impl Default for FilterListModel {
419 fn default() -> Self {
420 glib::object::Object::new::<Self>()
421 }
422}
423
424#[must_use = "The builder must be built to be used"]
429pub struct FilterListModelBuilder {
430 builder: glib::object::ObjectBuilder<'static, FilterListModel>,
431}
432
433impl FilterListModelBuilder {
434 fn new() -> Self {
435 Self {
436 builder: glib::object::Object::builder(),
437 }
438 }
439
440 pub fn filter(self, filter: &impl IsA<Filter>) -> Self {
442 Self {
443 builder: self.builder.property("filter", filter.clone().upcast()),
444 }
445 }
446
447 pub fn incremental(self, incremental: bool) -> Self {
449 Self {
450 builder: self.builder.property("incremental", incremental),
451 }
452 }
453
454 pub fn model(self, model: &impl IsA<gio::ListModel>) -> Self {
456 Self {
457 builder: self.builder.property("model", model.clone().upcast()),
458 }
459 }
460
461 #[cfg(feature = "v4_20")]
463 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
464 pub fn watch_items(self, watch_items: bool) -> Self {
465 Self {
466 builder: self.builder.property("watch-items", watch_items),
467 }
468 }
469
470 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
473 pub fn build(self) -> FilterListModel {
474 assert_initialized_main_thread!();
475 self.builder.build()
476 }
477}