1#[cfg(feature = "v4_12")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
7use crate::SectionModel;
8use crate::{Filter, ffi};
9use glib::{
10 prelude::*,
11 signal::{SignalHandlerId, connect_raw},
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(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 unsafe {
308 let f: &F = &*(f as *const F);
309 f(&from_glib_borrow(this))
310 }
311 }
312 unsafe {
313 let f: Box_<F> = Box_::new(f);
314 connect_raw(
315 self.as_ptr() as *mut _,
316 c"notify::filter".as_ptr(),
317 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
318 notify_filter_trampoline::<F> as *const (),
319 )),
320 Box_::into_raw(f),
321 )
322 }
323 }
324
325 #[doc(alias = "incremental")]
326 pub fn connect_incremental_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
327 unsafe extern "C" fn notify_incremental_trampoline<F: Fn(&FilterListModel) + 'static>(
328 this: *mut ffi::GtkFilterListModel,
329 _param_spec: glib::ffi::gpointer,
330 f: glib::ffi::gpointer,
331 ) {
332 unsafe {
333 let f: &F = &*(f as *const F);
334 f(&from_glib_borrow(this))
335 }
336 }
337 unsafe {
338 let f: Box_<F> = Box_::new(f);
339 connect_raw(
340 self.as_ptr() as *mut _,
341 c"notify::incremental".as_ptr(),
342 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
343 notify_incremental_trampoline::<F> as *const (),
344 )),
345 Box_::into_raw(f),
346 )
347 }
348 }
349
350 #[doc(alias = "model")]
351 pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
352 unsafe extern "C" fn notify_model_trampoline<F: Fn(&FilterListModel) + 'static>(
353 this: *mut ffi::GtkFilterListModel,
354 _param_spec: glib::ffi::gpointer,
355 f: glib::ffi::gpointer,
356 ) {
357 unsafe {
358 let f: &F = &*(f as *const F);
359 f(&from_glib_borrow(this))
360 }
361 }
362 unsafe {
363 let f: Box_<F> = Box_::new(f);
364 connect_raw(
365 self.as_ptr() as *mut _,
366 c"notify::model".as_ptr(),
367 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
368 notify_model_trampoline::<F> as *const (),
369 )),
370 Box_::into_raw(f),
371 )
372 }
373 }
374
375 #[doc(alias = "pending")]
376 pub fn connect_pending_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
377 unsafe extern "C" fn notify_pending_trampoline<F: Fn(&FilterListModel) + 'static>(
378 this: *mut ffi::GtkFilterListModel,
379 _param_spec: glib::ffi::gpointer,
380 f: glib::ffi::gpointer,
381 ) {
382 unsafe {
383 let f: &F = &*(f as *const F);
384 f(&from_glib_borrow(this))
385 }
386 }
387 unsafe {
388 let f: Box_<F> = Box_::new(f);
389 connect_raw(
390 self.as_ptr() as *mut _,
391 c"notify::pending".as_ptr(),
392 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
393 notify_pending_trampoline::<F> as *const (),
394 )),
395 Box_::into_raw(f),
396 )
397 }
398 }
399
400 #[cfg(feature = "v4_20")]
401 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
402 #[doc(alias = "watch-items")]
403 pub fn connect_watch_items_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
404 unsafe extern "C" fn notify_watch_items_trampoline<F: Fn(&FilterListModel) + 'static>(
405 this: *mut ffi::GtkFilterListModel,
406 _param_spec: glib::ffi::gpointer,
407 f: glib::ffi::gpointer,
408 ) {
409 unsafe {
410 let f: &F = &*(f as *const F);
411 f(&from_glib_borrow(this))
412 }
413 }
414 unsafe {
415 let f: Box_<F> = Box_::new(f);
416 connect_raw(
417 self.as_ptr() as *mut _,
418 c"notify::watch-items".as_ptr(),
419 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
420 notify_watch_items_trampoline::<F> as *const (),
421 )),
422 Box_::into_raw(f),
423 )
424 }
425 }
426}
427
428impl Default for FilterListModel {
429 fn default() -> Self {
430 glib::object::Object::new::<Self>()
431 }
432}
433
434#[must_use = "The builder must be built to be used"]
439pub struct FilterListModelBuilder {
440 builder: glib::object::ObjectBuilder<'static, FilterListModel>,
441}
442
443impl FilterListModelBuilder {
444 fn new() -> Self {
445 Self {
446 builder: glib::object::Object::builder(),
447 }
448 }
449
450 pub fn filter(self, filter: &impl IsA<Filter>) -> Self {
452 Self {
453 builder: self.builder.property("filter", filter.clone().upcast()),
454 }
455 }
456
457 pub fn incremental(self, incremental: bool) -> Self {
459 Self {
460 builder: self.builder.property("incremental", incremental),
461 }
462 }
463
464 pub fn model(self, model: &impl IsA<gio::ListModel>) -> Self {
466 Self {
467 builder: self.builder.property("model", model.clone().upcast()),
468 }
469 }
470
471 #[cfg(feature = "v4_20")]
473 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
474 pub fn watch_items(self, watch_items: bool) -> Self {
475 Self {
476 builder: self.builder.property("watch-items", watch_items),
477 }
478 }
479
480 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
483 pub fn build(self) -> FilterListModel {
484 assert_initialized_main_thread!();
485 self.builder.build()
486 }
487}