gtk4/auto/
bookmark_list.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
5use crate::ffi;
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// [`BookmarkList`][crate::BookmarkList] is a list model that wraps `GBookmarkFile`.
15    ///
16    /// It presents a `GListModel` and fills it asynchronously with the
17    /// `GFileInfo`s returned from that function.
18    ///
19    /// The `GFileInfo`s in the list have some attributes in the recent
20    /// namespace added: `recent::private` (boolean) and `recent:applications`
21    /// (stringv).
22    ///
23    /// ## Properties
24    ///
25    ///
26    /// #### `attributes`
27    ///  The attributes to query.
28    ///
29    /// Readable | Writeable
30    ///
31    ///
32    /// #### `filename`
33    ///  The bookmark file to load.
34    ///
35    /// Readable | Writeable | Construct Only
36    ///
37    ///
38    /// #### `io-priority`
39    ///  Priority used when loading.
40    ///
41    /// Readable | Writeable
42    ///
43    ///
44    /// #### `item-type`
45    ///  The type of items. See [`ListModelExtManual::item_type()`][crate::gio::prelude::ListModelExtManual::item_type()].
46    ///
47    /// Readable
48    ///
49    ///
50    /// #### `loading`
51    ///  [`true`] if files are being loaded.
52    ///
53    /// Readable
54    ///
55    ///
56    /// #### `n-items`
57    ///  The number of items. See [`ListModelExtManual::n_items()`][crate::gio::prelude::ListModelExtManual::n_items()].
58    ///
59    /// Readable
60    ///
61    /// # Implements
62    ///
63    /// [`trait@glib::ObjectExt`], [`trait@gio::prelude::ListModelExt`]
64    #[doc(alias = "GtkBookmarkList")]
65    pub struct BookmarkList(Object<ffi::GtkBookmarkList, ffi::GtkBookmarkListClass>) @implements gio::ListModel;
66
67    match fn {
68        type_ => || ffi::gtk_bookmark_list_get_type(),
69    }
70}
71
72impl BookmarkList {
73    /// Creates a new [`BookmarkList`][crate::BookmarkList] with the given @attributes.
74    /// ## `filename`
75    /// The bookmark file to load
76    /// ## `attributes`
77    /// The attributes to query
78    ///
79    /// # Returns
80    ///
81    /// a new [`BookmarkList`][crate::BookmarkList]
82    #[doc(alias = "gtk_bookmark_list_new")]
83    pub fn new(
84        filename: Option<impl AsRef<std::path::Path>>,
85        attributes: Option<&str>,
86    ) -> BookmarkList {
87        assert_initialized_main_thread!();
88        unsafe {
89            from_glib_full(ffi::gtk_bookmark_list_new(
90                filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
91                attributes.to_glib_none().0,
92            ))
93        }
94    }
95
96    /// Gets the attributes queried on the children.
97    ///
98    /// # Returns
99    ///
100    /// The queried attributes
101    #[doc(alias = "gtk_bookmark_list_get_attributes")]
102    #[doc(alias = "get_attributes")]
103    pub fn attributes(&self) -> Option<glib::GString> {
104        unsafe { from_glib_none(ffi::gtk_bookmark_list_get_attributes(self.to_glib_none().0)) }
105    }
106
107    /// Returns the filename of the bookmark file that
108    /// this list is loading.
109    ///
110    /// # Returns
111    ///
112    /// the filename of the .xbel file
113    #[doc(alias = "gtk_bookmark_list_get_filename")]
114    #[doc(alias = "get_filename")]
115    pub fn filename(&self) -> std::path::PathBuf {
116        unsafe { from_glib_none(ffi::gtk_bookmark_list_get_filename(self.to_glib_none().0)) }
117    }
118
119    /// Returns [`true`] if the files are currently being loaded.
120    ///
121    /// Files will be added to @self from time to time while loading is
122    /// going on. The order in which are added is undefined and may change
123    /// in between runs.
124    ///
125    /// # Returns
126    ///
127    /// [`true`] if @self is loading
128    #[doc(alias = "gtk_bookmark_list_is_loading")]
129    #[doc(alias = "loading")]
130    pub fn is_loading(&self) -> bool {
131        unsafe { from_glib(ffi::gtk_bookmark_list_is_loading(self.to_glib_none().0)) }
132    }
133
134    /// Sets the @attributes to be enumerated and starts the enumeration.
135    ///
136    /// If @attributes is [`None`], no attributes will be queried, but a list
137    /// of `GFileInfo`s will still be created.
138    /// ## `attributes`
139    /// the attributes to enumerate
140    #[doc(alias = "gtk_bookmark_list_set_attributes")]
141    #[doc(alias = "attributes")]
142    pub fn set_attributes(&self, attributes: Option<&str>) {
143        unsafe {
144            ffi::gtk_bookmark_list_set_attributes(
145                self.to_glib_none().0,
146                attributes.to_glib_none().0,
147            );
148        }
149    }
150
151    #[doc(alias = "attributes")]
152    pub fn connect_attributes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
153        unsafe extern "C" fn notify_attributes_trampoline<F: Fn(&BookmarkList) + 'static>(
154            this: *mut ffi::GtkBookmarkList,
155            _param_spec: glib::ffi::gpointer,
156            f: glib::ffi::gpointer,
157        ) {
158            let f: &F = &*(f as *const F);
159            f(&from_glib_borrow(this))
160        }
161        unsafe {
162            let f: Box_<F> = Box_::new(f);
163            connect_raw(
164                self.as_ptr() as *mut _,
165                b"notify::attributes\0".as_ptr() as *const _,
166                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
167                    notify_attributes_trampoline::<F> as *const (),
168                )),
169                Box_::into_raw(f),
170            )
171        }
172    }
173
174    #[doc(alias = "io-priority")]
175    pub fn connect_io_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
176        unsafe extern "C" fn notify_io_priority_trampoline<F: Fn(&BookmarkList) + 'static>(
177            this: *mut ffi::GtkBookmarkList,
178            _param_spec: glib::ffi::gpointer,
179            f: glib::ffi::gpointer,
180        ) {
181            let f: &F = &*(f as *const F);
182            f(&from_glib_borrow(this))
183        }
184        unsafe {
185            let f: Box_<F> = Box_::new(f);
186            connect_raw(
187                self.as_ptr() as *mut _,
188                b"notify::io-priority\0".as_ptr() as *const _,
189                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
190                    notify_io_priority_trampoline::<F> as *const (),
191                )),
192                Box_::into_raw(f),
193            )
194        }
195    }
196
197    #[doc(alias = "loading")]
198    pub fn connect_loading_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
199        unsafe extern "C" fn notify_loading_trampoline<F: Fn(&BookmarkList) + 'static>(
200            this: *mut ffi::GtkBookmarkList,
201            _param_spec: glib::ffi::gpointer,
202            f: glib::ffi::gpointer,
203        ) {
204            let f: &F = &*(f as *const F);
205            f(&from_glib_borrow(this))
206        }
207        unsafe {
208            let f: Box_<F> = Box_::new(f);
209            connect_raw(
210                self.as_ptr() as *mut _,
211                b"notify::loading\0".as_ptr() as *const _,
212                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
213                    notify_loading_trampoline::<F> as *const (),
214                )),
215                Box_::into_raw(f),
216            )
217        }
218    }
219}