Skip to main content

gtk4/auto/
recent_info.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::translate::*;
7
8glib::wrapper! {
9    /// Contains the metadata associated with an item in the
10    /// recently used files list.
11    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
12    pub struct RecentInfo(Shared<ffi::GtkRecentInfo>);
13
14    match fn {
15        ref => |ptr| ffi::gtk_recent_info_ref(ptr),
16        unref => |ptr| ffi::gtk_recent_info_unref(ptr),
17        type_ => || ffi::gtk_recent_info_get_type(),
18    }
19}
20
21impl RecentInfo {
22    /// Creates a `GAppInfo` for the specified [`RecentInfo`][crate::RecentInfo]
23    ///
24    /// In case of error, @error will be set either with a
25    /// `GTK_RECENT_MANAGER_ERROR` or a `G_IO_ERROR`
26    /// ## `app_name`
27    /// the name of the application that should
28    ///   be mapped to a `GAppInfo`; if [`None`] is used then the default
29    ///   application for the MIME type is used
30    ///
31    /// # Returns
32    ///
33    /// the newly created `GAppInfo`
34    #[doc(alias = "gtk_recent_info_create_app_info")]
35    pub fn create_app_info(
36        &self,
37        app_name: Option<&str>,
38    ) -> Result<Option<gio::AppInfo>, glib::Error> {
39        unsafe {
40            let mut error = std::ptr::null_mut();
41            let ret = ffi::gtk_recent_info_create_app_info(
42                self.to_glib_none().0,
43                app_name.to_glib_none().0,
44                &mut error,
45            );
46            if error.is_null() {
47                Ok(from_glib_full(ret))
48            } else {
49                Err(from_glib_full(error))
50            }
51        }
52    }
53
54    /// Checks whether the resource pointed by @self still exists.
55    /// At the moment this check is done only on resources pointing
56    /// to local files.
57    ///
58    /// # Returns
59    ///
60    /// [`true`] if the resource exists
61    #[doc(alias = "gtk_recent_info_exists")]
62    pub fn exists(&self) -> bool {
63        unsafe { from_glib(ffi::gtk_recent_info_exists(self.to_glib_none().0)) }
64    }
65
66    /// Gets the time when the resource
67    /// was added to the recently used resources list.
68    ///
69    /// # Returns
70    ///
71    /// a `GDateTime` for the time
72    ///    when the resource was added
73    #[doc(alias = "gtk_recent_info_get_added")]
74    #[doc(alias = "get_added")]
75    pub fn added(&self) -> glib::DateTime {
76        unsafe { from_glib_none(ffi::gtk_recent_info_get_added(self.to_glib_none().0)) }
77    }
78
79    /// Gets the number of days elapsed since the last update
80    /// of the resource pointed by @self.
81    ///
82    /// # Returns
83    ///
84    /// a positive integer containing the number of days
85    ///   elapsed since the time this resource was last modified
86    #[doc(alias = "gtk_recent_info_get_age")]
87    #[doc(alias = "get_age")]
88    pub fn age(&self) -> i32 {
89        unsafe { ffi::gtk_recent_info_get_age(self.to_glib_none().0) }
90    }
91
92    /// Gets the data regarding the application that has registered the resource
93    /// pointed by @self.
94    ///
95    /// If the command line contains any escape characters defined inside the
96    /// storage specification, they will be expanded.
97    /// ## `app_name`
98    /// the name of the application that has registered this item
99    ///
100    /// # Returns
101    ///
102    /// [`true`] if an application with @app_name has registered this
103    ///   resource inside the recently used list, or [`false`] otherwise. The
104    ///   @app_exec string is owned by the [`RecentInfo`][crate::RecentInfo] and should not be
105    ///   modified or freed
106    ///
107    /// ## `app_exec`
108    /// return location for the string containing
109    ///    the command line
110    ///
111    /// ## `count`
112    /// return location for the number of times this item was registered
113    ///
114    /// ## `stamp`
115    /// return location for the time this item was last
116    ///    registered for this application
117    #[doc(alias = "gtk_recent_info_get_application_info")]
118    #[doc(alias = "get_application_info")]
119    pub fn application_info(&self, app_name: &str) -> Option<(glib::GString, u32, glib::DateTime)> {
120        unsafe {
121            let mut app_exec = std::ptr::null();
122            let mut count = std::mem::MaybeUninit::uninit();
123            let mut stamp = std::ptr::null_mut();
124            let ret = from_glib(ffi::gtk_recent_info_get_application_info(
125                self.to_glib_none().0,
126                app_name.to_glib_none().0,
127                &mut app_exec,
128                count.as_mut_ptr(),
129                &mut stamp,
130            ));
131            if ret {
132                Some((
133                    from_glib_none(app_exec),
134                    count.assume_init(),
135                    from_glib_none(stamp),
136                ))
137            } else {
138                None
139            }
140        }
141    }
142
143    /// Retrieves the list of applications that have registered this resource.
144    ///
145    /// # Returns
146    ///
147    /// a newly
148    ///   allocated [`None`]-terminated array of strings. Use g_strfreev() to free it.
149    #[doc(alias = "gtk_recent_info_get_applications")]
150    #[doc(alias = "get_applications")]
151    pub fn applications(&self) -> Vec<glib::GString> {
152        unsafe {
153            let mut length = std::mem::MaybeUninit::uninit();
154            let ret = FromGlibContainer::from_glib_full_num(
155                ffi::gtk_recent_info_get_applications(self.to_glib_none().0, length.as_mut_ptr()),
156                length.assume_init() as _,
157            );
158            ret
159        }
160    }
161
162    /// Gets the (short) description of the resource.
163    ///
164    /// # Returns
165    ///
166    /// the description of the resource. The returned string
167    ///   is owned by the recent manager, and should not be freed.
168    #[doc(alias = "gtk_recent_info_get_description")]
169    #[doc(alias = "get_description")]
170    pub fn description(&self) -> glib::GString {
171        unsafe { from_glib_none(ffi::gtk_recent_info_get_description(self.to_glib_none().0)) }
172    }
173
174    /// Gets the name of the resource.
175    ///
176    /// If none has been defined, the basename
177    /// of the resource is obtained.
178    ///
179    /// # Returns
180    ///
181    /// the display name of the resource. The returned string
182    ///   is owned by the recent manager, and should not be freed.
183    #[doc(alias = "gtk_recent_info_get_display_name")]
184    #[doc(alias = "get_display_name")]
185    pub fn display_name(&self) -> glib::GString {
186        unsafe { from_glib_none(ffi::gtk_recent_info_get_display_name(self.to_glib_none().0)) }
187    }
188
189    /// Retrieves the icon associated to the resource MIME type.
190    ///
191    /// # Returns
192    ///
193    /// a `GIcon` containing the icon
194    #[doc(alias = "gtk_recent_info_get_gicon")]
195    #[doc(alias = "get_gicon")]
196    pub fn gicon(&self) -> Option<gio::Icon> {
197        unsafe { from_glib_full(ffi::gtk_recent_info_get_gicon(self.to_glib_none().0)) }
198    }
199
200    /// Returns all groups registered for the recently used item @self.
201    ///
202    /// The array of returned group names will be [`None`] terminated, so
203    /// length might optionally be [`None`].
204    ///
205    /// # Returns
206    ///
207    ///
208    ///   a newly allocated [`None`] terminated array of strings.
209    ///   Use g_strfreev() to free it.
210    #[doc(alias = "gtk_recent_info_get_groups")]
211    #[doc(alias = "get_groups")]
212    pub fn groups(&self) -> Vec<glib::GString> {
213        unsafe {
214            let mut length = std::mem::MaybeUninit::uninit();
215            let ret = FromGlibContainer::from_glib_full_num(
216                ffi::gtk_recent_info_get_groups(self.to_glib_none().0, length.as_mut_ptr()),
217                length.assume_init() as _,
218            );
219            ret
220        }
221    }
222
223    /// Gets the MIME type of the resource.
224    ///
225    /// # Returns
226    ///
227    /// the MIME type of the resource. The returned string
228    ///   is owned by the recent manager, and should not be freed.
229    #[doc(alias = "gtk_recent_info_get_mime_type")]
230    #[doc(alias = "get_mime_type")]
231    pub fn mime_type(&self) -> glib::GString {
232        unsafe { from_glib_none(ffi::gtk_recent_info_get_mime_type(self.to_glib_none().0)) }
233    }
234
235    /// Gets the time when the meta-data
236    /// for the resource was last modified.
237    ///
238    /// # Returns
239    ///
240    /// a `GDateTime` for the time
241    ///   when the resource was last modified
242    #[doc(alias = "gtk_recent_info_get_modified")]
243    #[doc(alias = "get_modified")]
244    pub fn modified(&self) -> glib::DateTime {
245        unsafe { from_glib_none(ffi::gtk_recent_info_get_modified(self.to_glib_none().0)) }
246    }
247
248    ///  flag.
249    ///
250    /// Resources in the recently used list that have this flag
251    /// set to [`true`] should only be displayed by the applications
252    /// that have registered them.
253    ///
254    /// # Returns
255    ///
256    /// [`true`] if the private flag was found, [`false`] otherwise
257    #[doc(alias = "gtk_recent_info_get_private_hint")]
258    #[doc(alias = "get_private_hint")]
259    pub fn is_private_hint(&self) -> bool {
260        unsafe { from_glib(ffi::gtk_recent_info_get_private_hint(self.to_glib_none().0)) }
261    }
262
263    /// .
264    ///
265    /// # Returns
266    ///
267    /// A newly-allocated string in UTF-8 encoding
268    ///   free it with g_free()
269    #[doc(alias = "gtk_recent_info_get_short_name")]
270    #[doc(alias = "get_short_name")]
271    pub fn short_name(&self) -> glib::GString {
272        unsafe { from_glib_full(ffi::gtk_recent_info_get_short_name(self.to_glib_none().0)) }
273    }
274
275    /// Gets the URI of the resource.
276    ///
277    /// # Returns
278    ///
279    /// the URI of the resource. The returned string is
280    ///   owned by the recent manager, and should not be freed.
281    #[doc(alias = "gtk_recent_info_get_uri")]
282    #[doc(alias = "get_uri")]
283    pub fn uri(&self) -> glib::GString {
284        unsafe { from_glib_none(ffi::gtk_recent_info_get_uri(self.to_glib_none().0)) }
285    }
286
287    /// s URI.
288    ///
289    /// If the resource is local, it returns a local path; if the
290    /// resource is not local, it returns the UTF-8 encoded content
291    /// of [`uri()`][Self::uri()].
292    ///
293    /// # Returns
294    ///
295    /// s URI or [`None`]. Use g_free() when done using it.
296    #[doc(alias = "gtk_recent_info_get_uri_display")]
297    #[doc(alias = "get_uri_display")]
298    pub fn uri_display(&self) -> Option<glib::GString> {
299        unsafe { from_glib_full(ffi::gtk_recent_info_get_uri_display(self.to_glib_none().0)) }
300    }
301
302    /// Gets the time when the meta-data
303    /// for the resource was last visited.
304    ///
305    /// # Returns
306    ///
307    /// a `GDateTime` for the time
308    ///    when the resource was last visited
309    #[doc(alias = "gtk_recent_info_get_visited")]
310    #[doc(alias = "get_visited")]
311    pub fn visited(&self) -> glib::DateTime {
312        unsafe { from_glib_none(ffi::gtk_recent_info_get_visited(self.to_glib_none().0)) }
313    }
314
315    /// Checks whether an application registered this resource using @app_name.
316    /// ## `app_name`
317    /// a string containing an application name
318    ///
319    /// # Returns
320    ///
321    /// [`true`] if an application with name @app_name was found,
322    ///   [`false`] otherwise
323    #[doc(alias = "gtk_recent_info_has_application")]
324    pub fn has_application(&self, app_name: &str) -> bool {
325        unsafe {
326            from_glib(ffi::gtk_recent_info_has_application(
327                self.to_glib_none().0,
328                app_name.to_glib_none().0,
329            ))
330        }
331    }
332
333    /// Checks whether @group_name appears inside the groups
334    /// registered for the recently used item @self.
335    /// ## `group_name`
336    /// name of a group
337    ///
338    /// # Returns
339    ///
340    /// [`true`] if the group was found
341    #[doc(alias = "gtk_recent_info_has_group")]
342    pub fn has_group(&self, group_name: &str) -> bool {
343        unsafe {
344            from_glib(ffi::gtk_recent_info_has_group(
345                self.to_glib_none().0,
346                group_name.to_glib_none().0,
347            ))
348        }
349    }
350
351    /// Checks whether the resource is local or not by looking at the
352    /// scheme of its URI.
353    ///
354    /// # Returns
355    ///
356    /// [`true`] if the resource is local
357    #[doc(alias = "gtk_recent_info_is_local")]
358    pub fn is_local(&self) -> bool {
359        unsafe { from_glib(ffi::gtk_recent_info_is_local(self.to_glib_none().0)) }
360    }
361
362    /// Gets the name of the last application that have registered the
363    /// recently used resource represented by @self.
364    ///
365    /// # Returns
366    ///
367    /// an application name. Use g_free() to free it.
368    #[doc(alias = "gtk_recent_info_last_application")]
369    pub fn last_application(&self) -> glib::GString {
370        unsafe { from_glib_full(ffi::gtk_recent_info_last_application(self.to_glib_none().0)) }
371    }
372
373    /// Checks whether two [`RecentInfo`][crate::RecentInfo] point to the same resource.
374    /// ## `info_b`
375    /// a [`RecentInfo`][crate::RecentInfo]
376    ///
377    /// # Returns
378    ///
379    /// [`true`] if both [`RecentInfo`][crate::RecentInfo] point to the same
380    ///   resource, [`false`] otherwise
381    #[doc(alias = "gtk_recent_info_match")]
382    #[doc(alias = "match")]
383    pub fn match_(&self, info_b: &RecentInfo) -> bool {
384        unsafe {
385            from_glib(ffi::gtk_recent_info_match(
386                self.to_glib_none().0,
387                info_b.to_glib_none().0,
388            ))
389        }
390    }
391}