Skip to main content

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