gio/auto/
app_launch_context.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, AppInfo, File};
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 = "GAppLaunchContext")]
16    pub struct AppLaunchContext(Object<ffi::GAppLaunchContext, ffi::GAppLaunchContextClass>);
17
18    match fn {
19        type_ => || ffi::g_app_launch_context_get_type(),
20    }
21}
22
23impl AppLaunchContext {
24    pub const NONE: Option<&'static AppLaunchContext> = None;
25
26    #[doc(alias = "g_app_launch_context_new")]
27    pub fn new() -> AppLaunchContext {
28        unsafe { from_glib_full(ffi::g_app_launch_context_new()) }
29    }
30}
31
32impl Default for AppLaunchContext {
33    fn default() -> Self {
34        Self::new()
35    }
36}
37
38pub trait AppLaunchContextExt: IsA<AppLaunchContext> + 'static {
39    #[doc(alias = "g_app_launch_context_get_display")]
40    #[doc(alias = "get_display")]
41    fn display(&self, info: &impl IsA<AppInfo>, files: &[File]) -> Option<glib::GString> {
42        unsafe {
43            from_glib_full(ffi::g_app_launch_context_get_display(
44                self.as_ref().to_glib_none().0,
45                info.as_ref().to_glib_none().0,
46                files.to_glib_none().0,
47            ))
48        }
49    }
50
51    #[doc(alias = "g_app_launch_context_get_environment")]
52    #[doc(alias = "get_environment")]
53    fn environment(&self) -> Vec<std::ffi::OsString> {
54        unsafe {
55            FromGlibPtrContainer::from_glib_full(ffi::g_app_launch_context_get_environment(
56                self.as_ref().to_glib_none().0,
57            ))
58        }
59    }
60
61    #[doc(alias = "g_app_launch_context_get_startup_notify_id")]
62    #[doc(alias = "get_startup_notify_id")]
63    fn startup_notify_id(
64        &self,
65        info: Option<&impl IsA<AppInfo>>,
66        files: &[File],
67    ) -> Option<glib::GString> {
68        unsafe {
69            from_glib_full(ffi::g_app_launch_context_get_startup_notify_id(
70                self.as_ref().to_glib_none().0,
71                info.map(|p| p.as_ref()).to_glib_none().0,
72                files.to_glib_none().0,
73            ))
74        }
75    }
76
77    #[doc(alias = "g_app_launch_context_launch_failed")]
78    fn launch_failed(&self, startup_notify_id: &str) {
79        unsafe {
80            ffi::g_app_launch_context_launch_failed(
81                self.as_ref().to_glib_none().0,
82                startup_notify_id.to_glib_none().0,
83            );
84        }
85    }
86
87    #[doc(alias = "g_app_launch_context_setenv")]
88    fn setenv(&self, variable: impl AsRef<std::ffi::OsStr>, value: impl AsRef<std::ffi::OsStr>) {
89        unsafe {
90            ffi::g_app_launch_context_setenv(
91                self.as_ref().to_glib_none().0,
92                variable.as_ref().to_glib_none().0,
93                value.as_ref().to_glib_none().0,
94            );
95        }
96    }
97
98    #[doc(alias = "g_app_launch_context_unsetenv")]
99    fn unsetenv(&self, variable: impl AsRef<std::ffi::OsStr>) {
100        unsafe {
101            ffi::g_app_launch_context_unsetenv(
102                self.as_ref().to_glib_none().0,
103                variable.as_ref().to_glib_none().0,
104            );
105        }
106    }
107
108    #[doc(alias = "launch-failed")]
109    fn connect_launch_failed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
110        unsafe extern "C" fn launch_failed_trampoline<
111            P: IsA<AppLaunchContext>,
112            F: Fn(&P, &str) + 'static,
113        >(
114            this: *mut ffi::GAppLaunchContext,
115            startup_notify_id: *mut std::ffi::c_char,
116            f: glib::ffi::gpointer,
117        ) {
118            let f: &F = &*(f as *const F);
119            f(
120                AppLaunchContext::from_glib_borrow(this).unsafe_cast_ref(),
121                &glib::GString::from_glib_borrow(startup_notify_id),
122            )
123        }
124        unsafe {
125            let f: Box_<F> = Box_::new(f);
126            connect_raw(
127                self.as_ptr() as *mut _,
128                c"launch-failed".as_ptr() as *const _,
129                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
130                    launch_failed_trampoline::<Self, F> as *const (),
131                )),
132                Box_::into_raw(f),
133            )
134        }
135    }
136
137    #[cfg(feature = "v2_72")]
138    #[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
139    #[doc(alias = "launch-started")]
140    fn connect_launch_started<F: Fn(&Self, &AppInfo, Option<&glib::Variant>) + 'static>(
141        &self,
142        f: F,
143    ) -> SignalHandlerId {
144        unsafe extern "C" fn launch_started_trampoline<
145            P: IsA<AppLaunchContext>,
146            F: Fn(&P, &AppInfo, Option<&glib::Variant>) + 'static,
147        >(
148            this: *mut ffi::GAppLaunchContext,
149            info: *mut ffi::GAppInfo,
150            platform_data: *mut glib::ffi::GVariant,
151            f: glib::ffi::gpointer,
152        ) {
153            let f: &F = &*(f as *const F);
154            f(
155                AppLaunchContext::from_glib_borrow(this).unsafe_cast_ref(),
156                &from_glib_borrow(info),
157                Option::<glib::Variant>::from_glib_borrow(platform_data)
158                    .as_ref()
159                    .as_ref(),
160            )
161        }
162        unsafe {
163            let f: Box_<F> = Box_::new(f);
164            connect_raw(
165                self.as_ptr() as *mut _,
166                c"launch-started".as_ptr() as *const _,
167                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
168                    launch_started_trampoline::<Self, F> as *const (),
169                )),
170                Box_::into_raw(f),
171            )
172        }
173    }
174
175    #[doc(alias = "launched")]
176    fn connect_launched<F: Fn(&Self, &AppInfo, &glib::Variant) + 'static>(
177        &self,
178        f: F,
179    ) -> SignalHandlerId {
180        unsafe extern "C" fn launched_trampoline<
181            P: IsA<AppLaunchContext>,
182            F: Fn(&P, &AppInfo, &glib::Variant) + 'static,
183        >(
184            this: *mut ffi::GAppLaunchContext,
185            info: *mut ffi::GAppInfo,
186            platform_data: *mut glib::ffi::GVariant,
187            f: glib::ffi::gpointer,
188        ) {
189            let f: &F = &*(f as *const F);
190            f(
191                AppLaunchContext::from_glib_borrow(this).unsafe_cast_ref(),
192                &from_glib_borrow(info),
193                &from_glib_borrow(platform_data),
194            )
195        }
196        unsafe {
197            let f: Box_<F> = Box_::new(f);
198            connect_raw(
199                self.as_ptr() as *mut _,
200                c"launched".as_ptr() as *const _,
201                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
202                    launched_trampoline::<Self, F> as *const (),
203                )),
204                Box_::into_raw(f),
205            )
206        }
207    }
208}
209
210impl<O: IsA<AppLaunchContext>> AppLaunchContextExt for O {}