[go: up one dir, main page]

gtk4/auto/
recent_manager.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, RecentData, RecentInfo};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GtkRecentManager")]
16    pub struct RecentManager(Object<ffi::GtkRecentManager, ffi::GtkRecentManagerClass>);
17
18    match fn {
19        type_ => || ffi::gtk_recent_manager_get_type(),
20    }
21}
22
23impl RecentManager {
24    pub const NONE: Option<&'static RecentManager> = None;
25
26    #[doc(alias = "gtk_recent_manager_new")]
27    pub fn new() -> RecentManager {
28        assert_initialized_main_thread!();
29        unsafe { from_glib_full(ffi::gtk_recent_manager_new()) }
30    }
31
32    #[doc(alias = "gtk_recent_manager_get_default")]
33    #[doc(alias = "get_default")]
34    #[allow(clippy::should_implement_trait)]
35    pub fn default() -> RecentManager {
36        assert_initialized_main_thread!();
37        unsafe { from_glib_none(ffi::gtk_recent_manager_get_default()) }
38    }
39}
40
41impl Default for RecentManager {
42    fn default() -> Self {
43        Self::new()
44    }
45}
46
47pub trait RecentManagerExt: IsA<RecentManager> + 'static {
48    #[doc(alias = "gtk_recent_manager_add_full")]
49    fn add_full(&self, uri: &str, recent_data: &RecentData) -> bool {
50        unsafe {
51            from_glib(ffi::gtk_recent_manager_add_full(
52                self.as_ref().to_glib_none().0,
53                uri.to_glib_none().0,
54                recent_data.to_glib_none().0,
55            ))
56        }
57    }
58
59    #[doc(alias = "gtk_recent_manager_add_item")]
60    fn add_item(&self, uri: &str) -> bool {
61        unsafe {
62            from_glib(ffi::gtk_recent_manager_add_item(
63                self.as_ref().to_glib_none().0,
64                uri.to_glib_none().0,
65            ))
66        }
67    }
68
69    #[doc(alias = "gtk_recent_manager_get_items")]
70    #[doc(alias = "get_items")]
71    fn items(&self) -> Vec<RecentInfo> {
72        unsafe {
73            FromGlibPtrContainer::from_glib_full(ffi::gtk_recent_manager_get_items(
74                self.as_ref().to_glib_none().0,
75            ))
76        }
77    }
78
79    #[doc(alias = "gtk_recent_manager_has_item")]
80    fn has_item(&self, uri: &str) -> bool {
81        unsafe {
82            from_glib(ffi::gtk_recent_manager_has_item(
83                self.as_ref().to_glib_none().0,
84                uri.to_glib_none().0,
85            ))
86        }
87    }
88
89    #[doc(alias = "gtk_recent_manager_lookup_item")]
90    fn lookup_item(&self, uri: &str) -> Result<Option<RecentInfo>, glib::Error> {
91        unsafe {
92            let mut error = std::ptr::null_mut();
93            let ret = ffi::gtk_recent_manager_lookup_item(
94                self.as_ref().to_glib_none().0,
95                uri.to_glib_none().0,
96                &mut error,
97            );
98            if error.is_null() {
99                Ok(from_glib_full(ret))
100            } else {
101                Err(from_glib_full(error))
102            }
103        }
104    }
105
106    #[doc(alias = "gtk_recent_manager_move_item")]
107    fn move_item(&self, uri: &str, new_uri: Option<&str>) -> Result<(), glib::Error> {
108        unsafe {
109            let mut error = std::ptr::null_mut();
110            let is_ok = ffi::gtk_recent_manager_move_item(
111                self.as_ref().to_glib_none().0,
112                uri.to_glib_none().0,
113                new_uri.to_glib_none().0,
114                &mut error,
115            );
116            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
117            if error.is_null() {
118                Ok(())
119            } else {
120                Err(from_glib_full(error))
121            }
122        }
123    }
124
125    #[doc(alias = "gtk_recent_manager_purge_items")]
126    fn purge_items(&self) -> Result<i32, glib::Error> {
127        unsafe {
128            let mut error = std::ptr::null_mut();
129            let ret =
130                ffi::gtk_recent_manager_purge_items(self.as_ref().to_glib_none().0, &mut error);
131            if error.is_null() {
132                Ok(ret)
133            } else {
134                Err(from_glib_full(error))
135            }
136        }
137    }
138
139    #[doc(alias = "gtk_recent_manager_remove_item")]
140    fn remove_item(&self, uri: &str) -> Result<(), glib::Error> {
141        unsafe {
142            let mut error = std::ptr::null_mut();
143            let is_ok = ffi::gtk_recent_manager_remove_item(
144                self.as_ref().to_glib_none().0,
145                uri.to_glib_none().0,
146                &mut error,
147            );
148            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
149            if error.is_null() {
150                Ok(())
151            } else {
152                Err(from_glib_full(error))
153            }
154        }
155    }
156
157    fn filename(&self) -> Option<glib::GString> {
158        ObjectExt::property(self.as_ref(), "filename")
159    }
160
161    fn size(&self) -> i32 {
162        ObjectExt::property(self.as_ref(), "size")
163    }
164
165    #[doc(alias = "changed")]
166    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
167        unsafe extern "C" fn changed_trampoline<P: IsA<RecentManager>, F: Fn(&P) + 'static>(
168            this: *mut ffi::GtkRecentManager,
169            f: glib::ffi::gpointer,
170        ) {
171            let f: &F = &*(f as *const F);
172            f(RecentManager::from_glib_borrow(this).unsafe_cast_ref())
173        }
174        unsafe {
175            let f: Box_<F> = Box_::new(f);
176            connect_raw(
177                self.as_ptr() as *mut _,
178                c"changed".as_ptr() as *const _,
179                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
180                    changed_trampoline::<Self, F> as *const (),
181                )),
182                Box_::into_raw(f),
183            )
184        }
185    }
186
187    #[doc(alias = "size")]
188    fn connect_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
189        unsafe extern "C" fn notify_size_trampoline<P: IsA<RecentManager>, F: Fn(&P) + 'static>(
190            this: *mut ffi::GtkRecentManager,
191            _param_spec: glib::ffi::gpointer,
192            f: glib::ffi::gpointer,
193        ) {
194            let f: &F = &*(f as *const F);
195            f(RecentManager::from_glib_borrow(this).unsafe_cast_ref())
196        }
197        unsafe {
198            let f: Box_<F> = Box_::new(f);
199            connect_raw(
200                self.as_ptr() as *mut _,
201                c"notify::size".as_ptr() as *const _,
202                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
203                    notify_size_trampoline::<Self, F> as *const (),
204                )),
205                Box_::into_raw(f),
206            )
207        }
208    }
209}
210
211impl<O: IsA<RecentManager>> RecentManagerExt for O {}