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 
5 use gio_sys;
6 use glib;
7 use glib::object::Cast;
8 use glib::object::IsA;
9 use glib::signal::connect_raw;
10 use glib::signal::SignalHandlerId;
11 use glib::translate::*;
12 use glib::GString;
13 use glib_sys;
14 use libc;
15 use std;
16 use std::boxed::Box as Box_;
17 use std::fmt;
18 use std::mem::transmute;
19 use AppInfo;
20 use File;
21 
22 glib_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 
30 impl AppLaunchContext {
new() -> AppLaunchContext31     pub fn new() -> AppLaunchContext {
32         unsafe { from_glib_full(gio_sys::g_app_launch_context_new()) }
33     }
34 }
35 
36 impl Default for AppLaunchContext {
default() -> Self37     fn default() -> Self {
38         Self::new()
39     }
40 }
41 
42 pub const NONE_APP_LAUNCH_CONTEXT: Option<&AppLaunchContext> = None;
43 
44 pub trait AppLaunchContextExt: 'static {
get_display<P: IsA<AppInfo>>(&self, info: &P, files: &[File]) -> Option<GString>45     fn get_display<P: IsA<AppInfo>>(&self, info: &P, files: &[File]) -> Option<GString>;
46 
get_environment(&self) -> Vec<std::ffi::OsString>47     fn get_environment(&self) -> Vec<std::ffi::OsString>;
48 
get_startup_notify_id<P: IsA<AppInfo>>(&self, info: &P, files: &[File]) -> Option<GString>49     fn get_startup_notify_id<P: IsA<AppInfo>>(&self, info: &P, files: &[File]) -> Option<GString>;
50 
launch_failed(&self, startup_notify_id: &str)51     fn launch_failed(&self, startup_notify_id: &str);
52 
setenv<P: AsRef<std::ffi::OsStr>, Q: AsRef<std::ffi::OsStr>>(&self, variable: P, value: Q)53     fn setenv<P: AsRef<std::ffi::OsStr>, Q: AsRef<std::ffi::OsStr>>(&self, variable: P, value: Q);
54 
unsetenv<P: AsRef<std::ffi::OsStr>>(&self, variable: P)55     fn unsetenv<P: AsRef<std::ffi::OsStr>>(&self, variable: P);
56 
connect_launch_failed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId57     fn connect_launch_failed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId;
58 
connect_launched<F: Fn(&Self, &AppInfo, &glib::Variant) + 'static>( &self, f: F, ) -> SignalHandlerId59     fn connect_launched<F: Fn(&Self, &AppInfo, &glib::Variant) + 'static>(
60         &self,
61         f: F,
62     ) -> SignalHandlerId;
63 }
64 
65 impl<O: IsA<AppLaunchContext>> AppLaunchContextExt for O {
get_display<P: IsA<AppInfo>>(&self, info: &P, files: &[File]) -> Option<GString>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 
get_environment(&self) -> Vec<std::ffi::OsString>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 
get_startup_notify_id<P: IsA<AppInfo>>(&self, info: &P, files: &[File]) -> Option<GString>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 
launch_failed(&self, startup_notify_id: &str)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 
setenv<P: AsRef<std::ffi::OsStr>, Q: AsRef<std::ffi::OsStr>>(&self, variable: P, value: Q)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 
unsetenv<P: AsRef<std::ffi::OsStr>>(&self, variable: P)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 
connect_launch_failed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId122     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 
connect_launched<F: Fn(&Self, &AppInfo, &glib::Variant) + 'static>( &self, f: F, ) -> SignalHandlerId147     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 
178 impl fmt::Display for AppLaunchContext {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result179     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
180         write!(f, "AppLaunchContext")
181     }
182 }
183