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 gio_sys;
6use glib;
7use glib::object::Cast;
8use glib::object::IsA;
9use glib::signal::connect_raw;
10use glib::signal::SignalHandlerId;
11use glib::translate::*;
12use glib::GString;
13use glib_sys;
14use libc;
15use std;
16use std::boxed::Box as Box_;
17use std::fmt;
18use std::mem::transmute;
19use AppInfo;
20use File;
21
22glib_wrapper! {
23    pub struct AppLaunchContext(Object<gio_sys::GAppLaunchContext, gio_sys::GAppLaunchContextClass, AppLaunchContextClass>);
24
25    match fn {
26        get_type => || gio_sys::g_app_launch_context_get_type(),
27    }
28}
29
30impl AppLaunchContext {
31    pub fn new() -> AppLaunchContext {
32        unsafe { from_glib_full(gio_sys::g_app_launch_context_new()) }
33    }
34}
35
36impl Default for AppLaunchContext {
37    fn default() -> Self {
38        Self::new()
39    }
40}
41
42pub const NONE_APP_LAUNCH_CONTEXT: Option<&AppLaunchContext> = None;
43
44pub trait AppLaunchContextExt: 'static {
45    fn get_display<P: IsA<AppInfo>>(&self, info: &P, files: &[File]) -> Option<GString>;
46
47    fn get_environment(&self) -> Vec<std::ffi::OsString>;
48
49    fn get_startup_notify_id<P: IsA<AppInfo>>(&self, info: &P, files: &[File]) -> Option<GString>;
50
51    fn launch_failed(&self, startup_notify_id: &str);
52
53    fn setenv<P: AsRef<std::ffi::OsStr>, Q: AsRef<std::ffi::OsStr>>(&self, variable: P, value: Q);
54
55    fn unsetenv<P: AsRef<std::ffi::OsStr>>(&self, variable: P);
56
57    fn connect_launch_failed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId;
58
59    fn connect_launched<F: Fn(&Self, &AppInfo, &glib::Variant) + 'static>(
60        &self,
61        f: F,
62    ) -> SignalHandlerId;
63}
64
65impl<O: IsA<AppLaunchContext>> AppLaunchContextExt for O {
66    fn get_display<P: IsA<AppInfo>>(&self, info: &P, files: &[File]) -> Option<GString> {
67        unsafe {
68            from_glib_full(gio_sys::g_app_launch_context_get_display(
69                self.as_ref().to_glib_none().0,
70                info.as_ref().to_glib_none().0,
71                files.to_glib_none().0,
72            ))
73        }
74    }
75
76    fn get_environment(&self) -> Vec<std::ffi::OsString> {
77        unsafe {
78            FromGlibPtrContainer::from_glib_full(gio_sys::g_app_launch_context_get_environment(
79                self.as_ref().to_glib_none().0,
80            ))
81        }
82    }
83
84    fn get_startup_notify_id<P: IsA<AppInfo>>(&self, info: &P, files: &[File]) -> Option<GString> {
85        unsafe {
86            from_glib_full(gio_sys::g_app_launch_context_get_startup_notify_id(
87                self.as_ref().to_glib_none().0,
88                info.as_ref().to_glib_none().0,
89                files.to_glib_none().0,
90            ))
91        }
92    }
93
94    fn launch_failed(&self, startup_notify_id: &str) {
95        unsafe {
96            gio_sys::g_app_launch_context_launch_failed(
97                self.as_ref().to_glib_none().0,
98                startup_notify_id.to_glib_none().0,
99            );
100        }
101    }
102
103    fn setenv<P: AsRef<std::ffi::OsStr>, Q: AsRef<std::ffi::OsStr>>(&self, variable: P, value: Q) {
104        unsafe {
105            gio_sys::g_app_launch_context_setenv(
106                self.as_ref().to_glib_none().0,
107                variable.as_ref().to_glib_none().0,
108                value.as_ref().to_glib_none().0,
109            );
110        }
111    }
112
113    fn unsetenv<P: AsRef<std::ffi::OsStr>>(&self, variable: P) {
114        unsafe {
115            gio_sys::g_app_launch_context_unsetenv(
116                self.as_ref().to_glib_none().0,
117                variable.as_ref().to_glib_none().0,
118            );
119        }
120    }
121
122    fn connect_launch_failed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
123        unsafe extern "C" fn launch_failed_trampoline<P, F: Fn(&P, &str) + 'static>(
124            this: *mut gio_sys::GAppLaunchContext,
125            startup_notify_id: *mut libc::c_char,
126            f: glib_sys::gpointer,
127        ) where
128            P: IsA<AppLaunchContext>,
129        {
130            let f: &F = &*(f as *const F);
131            f(
132                &AppLaunchContext::from_glib_borrow(this).unsafe_cast(),
133                &GString::from_glib_borrow(startup_notify_id),
134            )
135        }
136        unsafe {
137            let f: Box_<F> = Box_::new(f);
138            connect_raw(
139                self.as_ptr() as *mut _,
140                b"launch-failed\0".as_ptr() as *const _,
141                Some(transmute(launch_failed_trampoline::<Self, F> as usize)),
142                Box_::into_raw(f),
143            )
144        }
145    }
146
147    fn connect_launched<F: Fn(&Self, &AppInfo, &glib::Variant) + 'static>(
148        &self,
149        f: F,
150    ) -> SignalHandlerId {
151        unsafe extern "C" fn launched_trampoline<P, F: Fn(&P, &AppInfo, &glib::Variant) + 'static>(
152            this: *mut gio_sys::GAppLaunchContext,
153            info: *mut gio_sys::GAppInfo,
154            platform_data: *mut glib_sys::GVariant,
155            f: glib_sys::gpointer,
156        ) where
157            P: IsA<AppLaunchContext>,
158        {
159            let f: &F = &*(f as *const F);
160            f(
161                &AppLaunchContext::from_glib_borrow(this).unsafe_cast(),
162                &from_glib_borrow(info),
163                &from_glib_borrow(platform_data),
164            )
165        }
166        unsafe {
167            let f: Box_<F> = Box_::new(f);
168            connect_raw(
169                self.as_ptr() as *mut _,
170                b"launched\0".as_ptr() as *const _,
171                Some(transmute(launched_trampoline::<Self, F> as usize)),
172                Box_::into_raw(f),
173            )
174        }
175    }
176}
177
178impl fmt::Display for AppLaunchContext {
179    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
180        write!(f, "AppLaunchContext")
181    }
182}