1use crate::{AppInfo, File, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
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 unsafe {
119 let f: &F = &*(f as *const F);
120 f(
121 AppLaunchContext::from_glib_borrow(this).unsafe_cast_ref(),
122 &glib::GString::from_glib_borrow(startup_notify_id),
123 )
124 }
125 }
126 unsafe {
127 let f: Box_<F> = Box_::new(f);
128 connect_raw(
129 self.as_ptr() as *mut _,
130 c"launch-failed".as_ptr(),
131 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
132 launch_failed_trampoline::<Self, F> as *const (),
133 )),
134 Box_::into_raw(f),
135 )
136 }
137 }
138
139 #[cfg(feature = "v2_72")]
140 #[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
141 #[doc(alias = "launch-started")]
142 fn connect_launch_started<F: Fn(&Self, &AppInfo, Option<&glib::Variant>) + 'static>(
143 &self,
144 f: F,
145 ) -> SignalHandlerId {
146 unsafe extern "C" fn launch_started_trampoline<
147 P: IsA<AppLaunchContext>,
148 F: Fn(&P, &AppInfo, Option<&glib::Variant>) + 'static,
149 >(
150 this: *mut ffi::GAppLaunchContext,
151 info: *mut ffi::GAppInfo,
152 platform_data: *mut glib::ffi::GVariant,
153 f: glib::ffi::gpointer,
154 ) {
155 unsafe {
156 let f: &F = &*(f as *const F);
157 f(
158 AppLaunchContext::from_glib_borrow(this).unsafe_cast_ref(),
159 &from_glib_borrow(info),
160 Option::<glib::Variant>::from_glib_borrow(platform_data)
161 .as_ref()
162 .as_ref(),
163 )
164 }
165 }
166 unsafe {
167 let f: Box_<F> = Box_::new(f);
168 connect_raw(
169 self.as_ptr() as *mut _,
170 c"launch-started".as_ptr(),
171 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
172 launch_started_trampoline::<Self, F> as *const (),
173 )),
174 Box_::into_raw(f),
175 )
176 }
177 }
178
179 #[doc(alias = "launched")]
180 fn connect_launched<F: Fn(&Self, &AppInfo, &glib::Variant) + 'static>(
181 &self,
182 f: F,
183 ) -> SignalHandlerId {
184 unsafe extern "C" fn launched_trampoline<
185 P: IsA<AppLaunchContext>,
186 F: Fn(&P, &AppInfo, &glib::Variant) + 'static,
187 >(
188 this: *mut ffi::GAppLaunchContext,
189 info: *mut ffi::GAppInfo,
190 platform_data: *mut glib::ffi::GVariant,
191 f: glib::ffi::gpointer,
192 ) {
193 unsafe {
194 let f: &F = &*(f as *const F);
195 f(
196 AppLaunchContext::from_glib_borrow(this).unsafe_cast_ref(),
197 &from_glib_borrow(info),
198 &from_glib_borrow(platform_data),
199 )
200 }
201 }
202 unsafe {
203 let f: Box_<F> = Box_::new(f);
204 connect_raw(
205 self.as_ptr() as *mut _,
206 c"launched".as_ptr(),
207 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
208 launched_trampoline::<Self, F> as *const (),
209 )),
210 Box_::into_raw(f),
211 )
212 }
213 }
214}
215
216impl<O: IsA<AppLaunchContext>> AppLaunchContextExt for O {}