libpanel/auto/
session_item.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files.git)
4// DO NOT EDIT
5
6use crate::{ffi, Position};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "PanelSessionItem")]
16    pub struct SessionItem(Object<ffi::PanelSessionItem, ffi::PanelSessionItemClass>);
17
18    match fn {
19        type_ => || ffi::panel_session_item_get_type(),
20    }
21}
22
23impl SessionItem {
24    #[doc(alias = "panel_session_item_new")]
25    pub fn new() -> SessionItem {
26        assert_initialized_main_thread!();
27        unsafe { from_glib_full(ffi::panel_session_item_new()) }
28    }
29
30    // rustdoc-stripper-ignore-next
31    /// Creates a new builder-pattern struct instance to construct [`SessionItem`] objects.
32    ///
33    /// This method returns an instance of [`SessionItemBuilder`](crate::builders::SessionItemBuilder) which can be used to create [`SessionItem`] objects.
34    pub fn builder() -> SessionItemBuilder {
35        SessionItemBuilder::new()
36    }
37
38    #[doc(alias = "panel_session_item_get_id")]
39    #[doc(alias = "get_id")]
40    pub fn id(&self) -> Option<glib::GString> {
41        unsafe { from_glib_none(ffi::panel_session_item_get_id(self.to_glib_none().0)) }
42    }
43
44    #[doc(alias = "panel_session_item_get_metadata_value")]
45    #[doc(alias = "get_metadata_value")]
46    pub fn metadata_value(
47        &self,
48        key: &str,
49        expected_type: Option<&glib::VariantTy>,
50    ) -> Option<glib::Variant> {
51        unsafe {
52            from_glib_full(ffi::panel_session_item_get_metadata_value(
53                self.to_glib_none().0,
54                key.to_glib_none().0,
55                expected_type.to_glib_none().0,
56            ))
57        }
58    }
59
60    #[doc(alias = "panel_session_item_get_module_name")]
61    #[doc(alias = "get_module_name")]
62    #[doc(alias = "module-name")]
63    pub fn module_name(&self) -> Option<glib::GString> {
64        unsafe {
65            from_glib_none(ffi::panel_session_item_get_module_name(
66                self.to_glib_none().0,
67            ))
68        }
69    }
70
71    #[doc(alias = "panel_session_item_get_position")]
72    #[doc(alias = "get_position")]
73    pub fn position(&self) -> Option<Position> {
74        unsafe { from_glib_none(ffi::panel_session_item_get_position(self.to_glib_none().0)) }
75    }
76
77    #[doc(alias = "panel_session_item_get_type_hint")]
78    #[doc(alias = "get_type_hint")]
79    #[doc(alias = "type-hint")]
80    pub fn type_hint(&self) -> Option<glib::GString> {
81        unsafe { from_glib_none(ffi::panel_session_item_get_type_hint(self.to_glib_none().0)) }
82    }
83
84    #[doc(alias = "panel_session_item_get_workspace")]
85    #[doc(alias = "get_workspace")]
86    pub fn workspace(&self) -> Option<glib::GString> {
87        unsafe { from_glib_none(ffi::panel_session_item_get_workspace(self.to_glib_none().0)) }
88    }
89
90    #[doc(alias = "panel_session_item_has_metadata_with_type")]
91    pub fn has_metadata_with_type(&self, key: &str, expected_type: &glib::VariantTy) -> bool {
92        unsafe {
93            from_glib(ffi::panel_session_item_has_metadata_with_type(
94                self.to_glib_none().0,
95                key.to_glib_none().0,
96                expected_type.to_glib_none().0,
97            ))
98        }
99    }
100
101    #[doc(alias = "panel_session_item_set_id")]
102    #[doc(alias = "id")]
103    pub fn set_id(&self, id: Option<&str>) {
104        unsafe {
105            ffi::panel_session_item_set_id(self.to_glib_none().0, id.to_glib_none().0);
106        }
107    }
108
109    #[doc(alias = "panel_session_item_set_metadata_value")]
110    pub fn set_metadata_value(&self, key: &str, value: Option<&glib::Variant>) {
111        unsafe {
112            ffi::panel_session_item_set_metadata_value(
113                self.to_glib_none().0,
114                key.to_glib_none().0,
115                value.to_glib_none().0,
116            );
117        }
118    }
119
120    #[doc(alias = "panel_session_item_set_module_name")]
121    #[doc(alias = "module-name")]
122    pub fn set_module_name(&self, module_name: Option<&str>) {
123        unsafe {
124            ffi::panel_session_item_set_module_name(
125                self.to_glib_none().0,
126                module_name.to_glib_none().0,
127            );
128        }
129    }
130
131    #[doc(alias = "panel_session_item_set_position")]
132    #[doc(alias = "position")]
133    pub fn set_position(&self, position: Option<&Position>) {
134        unsafe {
135            ffi::panel_session_item_set_position(self.to_glib_none().0, position.to_glib_none().0);
136        }
137    }
138
139    #[doc(alias = "panel_session_item_set_type_hint")]
140    #[doc(alias = "type-hint")]
141    pub fn set_type_hint(&self, type_hint: Option<&str>) {
142        unsafe {
143            ffi::panel_session_item_set_type_hint(
144                self.to_glib_none().0,
145                type_hint.to_glib_none().0,
146            );
147        }
148    }
149
150    #[doc(alias = "panel_session_item_set_workspace")]
151    #[doc(alias = "workspace")]
152    pub fn set_workspace(&self, workspace: Option<&str>) {
153        unsafe {
154            ffi::panel_session_item_set_workspace(
155                self.to_glib_none().0,
156                workspace.to_glib_none().0,
157            );
158        }
159    }
160
161    #[doc(alias = "id")]
162    pub fn connect_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
163        unsafe extern "C" fn notify_id_trampoline<F: Fn(&SessionItem) + 'static>(
164            this: *mut ffi::PanelSessionItem,
165            _param_spec: glib::ffi::gpointer,
166            f: glib::ffi::gpointer,
167        ) {
168            let f: &F = &*(f as *const F);
169            f(&from_glib_borrow(this))
170        }
171        unsafe {
172            let f: Box_<F> = Box_::new(f);
173            connect_raw(
174                self.as_ptr() as *mut _,
175                c"notify::id".as_ptr() as *const _,
176                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
177                    notify_id_trampoline::<F> as *const (),
178                )),
179                Box_::into_raw(f),
180            )
181        }
182    }
183
184    #[doc(alias = "module-name")]
185    pub fn connect_module_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
186        unsafe extern "C" fn notify_module_name_trampoline<F: Fn(&SessionItem) + 'static>(
187            this: *mut ffi::PanelSessionItem,
188            _param_spec: glib::ffi::gpointer,
189            f: glib::ffi::gpointer,
190        ) {
191            let f: &F = &*(f as *const F);
192            f(&from_glib_borrow(this))
193        }
194        unsafe {
195            let f: Box_<F> = Box_::new(f);
196            connect_raw(
197                self.as_ptr() as *mut _,
198                c"notify::module-name".as_ptr() as *const _,
199                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
200                    notify_module_name_trampoline::<F> as *const (),
201                )),
202                Box_::into_raw(f),
203            )
204        }
205    }
206
207    #[doc(alias = "position")]
208    pub fn connect_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
209        unsafe extern "C" fn notify_position_trampoline<F: Fn(&SessionItem) + 'static>(
210            this: *mut ffi::PanelSessionItem,
211            _param_spec: glib::ffi::gpointer,
212            f: glib::ffi::gpointer,
213        ) {
214            let f: &F = &*(f as *const F);
215            f(&from_glib_borrow(this))
216        }
217        unsafe {
218            let f: Box_<F> = Box_::new(f);
219            connect_raw(
220                self.as_ptr() as *mut _,
221                c"notify::position".as_ptr() as *const _,
222                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
223                    notify_position_trampoline::<F> as *const (),
224                )),
225                Box_::into_raw(f),
226            )
227        }
228    }
229
230    #[doc(alias = "type-hint")]
231    pub fn connect_type_hint_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
232        unsafe extern "C" fn notify_type_hint_trampoline<F: Fn(&SessionItem) + 'static>(
233            this: *mut ffi::PanelSessionItem,
234            _param_spec: glib::ffi::gpointer,
235            f: glib::ffi::gpointer,
236        ) {
237            let f: &F = &*(f as *const F);
238            f(&from_glib_borrow(this))
239        }
240        unsafe {
241            let f: Box_<F> = Box_::new(f);
242            connect_raw(
243                self.as_ptr() as *mut _,
244                c"notify::type-hint".as_ptr() as *const _,
245                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
246                    notify_type_hint_trampoline::<F> as *const (),
247                )),
248                Box_::into_raw(f),
249            )
250        }
251    }
252
253    #[doc(alias = "workspace")]
254    pub fn connect_workspace_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
255        unsafe extern "C" fn notify_workspace_trampoline<F: Fn(&SessionItem) + 'static>(
256            this: *mut ffi::PanelSessionItem,
257            _param_spec: glib::ffi::gpointer,
258            f: glib::ffi::gpointer,
259        ) {
260            let f: &F = &*(f as *const F);
261            f(&from_glib_borrow(this))
262        }
263        unsafe {
264            let f: Box_<F> = Box_::new(f);
265            connect_raw(
266                self.as_ptr() as *mut _,
267                c"notify::workspace".as_ptr() as *const _,
268                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
269                    notify_workspace_trampoline::<F> as *const (),
270                )),
271                Box_::into_raw(f),
272            )
273        }
274    }
275}
276
277impl Default for SessionItem {
278    fn default() -> Self {
279        Self::new()
280    }
281}
282
283// rustdoc-stripper-ignore-next
284/// A [builder-pattern] type to construct [`SessionItem`] objects.
285///
286/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
287#[must_use = "The builder must be built to be used"]
288pub struct SessionItemBuilder {
289    builder: glib::object::ObjectBuilder<'static, SessionItem>,
290}
291
292impl SessionItemBuilder {
293    fn new() -> Self {
294        Self {
295            builder: glib::object::Object::builder(),
296        }
297    }
298
299    pub fn id(self, id: impl Into<glib::GString>) -> Self {
300        Self {
301            builder: self.builder.property("id", id.into()),
302        }
303    }
304
305    pub fn module_name(self, module_name: impl Into<glib::GString>) -> Self {
306        Self {
307            builder: self.builder.property("module-name", module_name.into()),
308        }
309    }
310
311    pub fn position(self, position: &Position) -> Self {
312        Self {
313            builder: self.builder.property("position", position.clone()),
314        }
315    }
316
317    pub fn type_hint(self, type_hint: impl Into<glib::GString>) -> Self {
318        Self {
319            builder: self.builder.property("type-hint", type_hint.into()),
320        }
321    }
322
323    pub fn workspace(self, workspace: impl Into<glib::GString>) -> Self {
324        Self {
325            builder: self.builder.property("workspace", workspace.into()),
326        }
327    }
328
329    // rustdoc-stripper-ignore-next
330    /// Build the [`SessionItem`].
331    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
332    pub fn build(self) -> SessionItem {
333        assert_initialized_main_thread!();
334        self.builder.build()
335    }
336}