Skip to main content

gtk/
recent_data.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::ffi;
4use glib::translate::*;
5use libc::c_char;
6
7/// Meta-data to be passed to [`RecentManagerExt::add_full()`][crate::prelude::RecentManagerExt::add_full()] when
8/// registering a recently used resource.
9pub struct RecentData {
10    pub display_name: Option<String>,
11    pub description: Option<String>,
12    pub mime_type: String,
13    pub app_name: String,
14    pub app_exec: String,
15    pub groups: Vec<String>,
16    pub is_private: bool,
17}
18
19#[doc(hidden)]
20impl<'a> ToGlibPtr<'a, *mut ffi::GtkRecentData> for RecentData {
21    type Storage = (
22        Box<ffi::GtkRecentData>,
23        [Stash<'a, *mut c_char, Option<String>>; 2],
24        [Stash<'a, *mut c_char, String>; 3],
25        Stash<'a, *mut *mut c_char, [String]>,
26    );
27
28    fn to_glib_none(&'a self) -> Stash<'a, *mut ffi::GtkRecentData, Self> {
29        let display_name = self.display_name.to_glib_none();
30        let description = self.description.to_glib_none();
31        let mime_type = self.mime_type.to_glib_none();
32        let app_name = self.app_name.to_glib_none();
33        let app_exec = self.app_exec.to_glib_none();
34        let groups = self.groups.to_glib_none();
35
36        let mut data = Box::new(ffi::GtkRecentData {
37            display_name: display_name.0,
38            description: description.0,
39            mime_type: mime_type.0,
40            app_name: app_name.0,
41            app_exec: app_exec.0,
42            groups: groups.0,
43            is_private: self.is_private.into_glib(),
44        });
45
46        Stash(
47            &mut *data,
48            (
49                data,
50                [display_name, description],
51                [mime_type, app_name, app_exec],
52                groups,
53            ),
54        )
55    }
56}