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    /// [`RecentInfo`][crate::RecentInfo] 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    /// Gets the value of the “private” 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    /// Computes a valid UTF-8 string that can be used as the
264    /// name of the item in a menu or list.
265    ///
266    /// For example, calling this function on an item that refers
267    /// to “file:///foo/bar.txt” will yield “bar.txt”.
268    ///
269    /// # Returns
270    ///
271    /// A newly-allocated string in UTF-8 encoding
272    ///   free it with g_free()
273    #[doc(alias = "gtk_recent_info_get_short_name")]
274    #[doc(alias = "get_short_name")]
275    pub fn short_name(&self) -> glib::GString {
276        unsafe { from_glib_full(ffi::gtk_recent_info_get_short_name(self.to_glib_none().0)) }
277    }
278
279    /// Gets the URI of the resource.
280    ///
281    /// # Returns
282    ///
283    /// the URI of the resource. The returned string is
284    ///   owned by the recent manager, and should not be freed.
285    #[doc(alias = "gtk_recent_info_get_uri")]
286    #[doc(alias = "get_uri")]
287    pub fn uri(&self) -> glib::GString {
288        unsafe { from_glib_none(ffi::gtk_recent_info_get_uri(self.to_glib_none().0)) }
289    }
290
291    /// Gets a displayable version of the resource’s URI.
292    ///
293    /// If the resource is local, it returns a local path; if the
294    /// resource is not local, it returns the UTF-8 encoded content
295    /// of [`uri()`][Self::uri()].
296    ///
297    /// # Returns
298    ///
299    /// a newly allocated UTF-8 string containing the
300    ///   resource’s URI or [`None`]. Use g_free() when done using it.
301    #[doc(alias = "gtk_recent_info_get_uri_display")]
302    #[doc(alias = "get_uri_display")]
303    pub fn uri_display(&self) -> Option<glib::GString> {
304        unsafe { from_glib_full(ffi::gtk_recent_info_get_uri_display(self.to_glib_none().0)) }
305    }
306
307    /// Gets the time when the meta-data
308    /// for the resource was last visited.
309    ///
310    /// # Returns
311    ///
312    /// a `GDateTime` for the time
313    ///    when the resource was last visited
314    #[doc(alias = "gtk_recent_info_get_visited")]
315    #[doc(alias = "get_visited")]
316    pub fn visited(&self) -> glib::DateTime {
317        unsafe { from_glib_none(ffi::gtk_recent_info_get_visited(self.to_glib_none().0)) }
318    }
319
320    /// Checks whether an application registered this resource using @app_name.
321    /// ## `app_name`
322    /// a string containing an application name
323    ///
324    /// # Returns
325    ///
326    /// [`true`] if an application with name @app_name was found,
327    ///   [`false`] otherwise
328    #[doc(alias = "gtk_recent_info_has_application")]
329    pub fn has_application(&self, app_name: &str) -> bool {
330        unsafe {
331            from_glib(ffi::gtk_recent_info_has_application(
332                self.to_glib_none().0,
333                app_name.to_glib_none().0,
334            ))
335        }
336    }
337
338    /// Checks whether @group_name appears inside the groups
339    /// registered for the recently used item @self.
340    /// ## `group_name`
341    /// name of a group
342    ///
343    /// # Returns
344    ///
345    /// [`true`] if the group was found
346    #[doc(alias = "gtk_recent_info_has_group")]
347    pub fn has_group(&self, group_name: &str) -> bool {
348        unsafe {
349            from_glib(ffi::gtk_recent_info_has_group(
350                self.to_glib_none().0,
351                group_name.to_glib_none().0,
352            ))
353        }
354    }
355
356    /// Checks whether the resource is local or not by looking at the
357    /// scheme of its URI.
358    ///
359    /// # Returns
360    ///
361    /// [`true`] if the resource is local
362    #[doc(alias = "gtk_recent_info_is_local")]
363    pub fn is_local(&self) -> bool {
364        unsafe { from_glib(ffi::gtk_recent_info_is_local(self.to_glib_none().0)) }
365    }
366
367    /// Gets the name of the last application that have registered the
368    /// recently used resource represented by @self.
369    ///
370    /// # Returns
371    ///
372    /// an application name. Use g_free() to free it.
373    #[doc(alias = "gtk_recent_info_last_application")]
374    pub fn last_application(&self) -> glib::GString {
375        unsafe { from_glib_full(ffi::gtk_recent_info_last_application(self.to_glib_none().0)) }
376    }
377
378    /// Checks whether two [`RecentInfo`][crate::RecentInfo] point to the same resource.
379    /// ## `info_b`
380    /// a [`RecentInfo`][crate::RecentInfo]
381    ///
382    /// # Returns
383    ///
384    /// [`true`] if both [`RecentInfo`][crate::RecentInfo] point to the same
385    ///   resource, [`false`] otherwise
386    #[doc(alias = "gtk_recent_info_match")]
387    #[doc(alias = "match")]
388    pub fn match_(&self, info_b: &RecentInfo) -> bool {
389        unsafe {
390            from_glib(ffi::gtk_recent_info_match(
391                self.to_glib_none().0,
392                info_b.to_glib_none().0,
393            ))
394        }
395    }
396}