gio/auto/
application_command_line.rs1use 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 std;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem;
18use std::mem::transmute;
19use File;
20use InputStream;
21
22glib_wrapper! {
23 pub struct ApplicationCommandLine(Object<gio_sys::GApplicationCommandLine, gio_sys::GApplicationCommandLineClass, ApplicationCommandLineClass>);
24
25 match fn {
26 get_type => || gio_sys::g_application_command_line_get_type(),
27 }
28}
29
30pub const NONE_APPLICATION_COMMAND_LINE: Option<&ApplicationCommandLine> = None;
31
32pub trait ApplicationCommandLineExt: 'static {
33 fn create_file_for_arg<P: AsRef<std::ffi::OsStr>>(&self, arg: P) -> Option<File>;
34
35 fn get_arguments(&self) -> Vec<std::ffi::OsString>;
36
37 fn get_cwd(&self) -> Option<std::path::PathBuf>;
38
39 fn get_environ(&self) -> Vec<std::ffi::OsString>;
40
41 fn get_exit_status(&self) -> i32;
42
43 fn get_is_remote(&self) -> bool;
44
45 fn get_platform_data(&self) -> Option<glib::Variant>;
48
49 fn get_stdin(&self) -> Option<InputStream>;
50
51 fn getenv<P: AsRef<std::ffi::OsStr>>(&self, name: P) -> Option<GString>;
52
53 fn set_exit_status(&self, exit_status: i32);
58
59 fn connect_property_is_remote_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
60}
61
62impl<O: IsA<ApplicationCommandLine>> ApplicationCommandLineExt for O {
63 fn create_file_for_arg<P: AsRef<std::ffi::OsStr>>(&self, arg: P) -> Option<File> {
64 unsafe {
65 from_glib_full(gio_sys::g_application_command_line_create_file_for_arg(
66 self.as_ref().to_glib_none().0,
67 arg.as_ref().to_glib_none().0,
68 ))
69 }
70 }
71
72 fn get_arguments(&self) -> Vec<std::ffi::OsString> {
73 unsafe {
74 let mut argc = mem::uninitialized();
75 let ret = FromGlibContainer::from_glib_full_num(
76 gio_sys::g_application_command_line_get_arguments(
77 self.as_ref().to_glib_none().0,
78 &mut argc,
79 ),
80 argc as usize,
81 );
82 ret
83 }
84 }
85
86 fn get_cwd(&self) -> Option<std::path::PathBuf> {
87 unsafe {
88 from_glib_none(gio_sys::g_application_command_line_get_cwd(
89 self.as_ref().to_glib_none().0,
90 ))
91 }
92 }
93
94 fn get_environ(&self) -> Vec<std::ffi::OsString> {
95 unsafe {
96 FromGlibPtrContainer::from_glib_none(gio_sys::g_application_command_line_get_environ(
97 self.as_ref().to_glib_none().0,
98 ))
99 }
100 }
101
102 fn get_exit_status(&self) -> i32 {
103 unsafe {
104 gio_sys::g_application_command_line_get_exit_status(self.as_ref().to_glib_none().0)
105 }
106 }
107
108 fn get_is_remote(&self) -> bool {
109 unsafe {
110 from_glib(gio_sys::g_application_command_line_get_is_remote(
111 self.as_ref().to_glib_none().0,
112 ))
113 }
114 }
115
116 fn get_platform_data(&self) -> Option<glib::Variant> {
121 unsafe {
122 from_glib_full(gio_sys::g_application_command_line_get_platform_data(
123 self.as_ref().to_glib_none().0,
124 ))
125 }
126 }
127
128 fn get_stdin(&self) -> Option<InputStream> {
129 unsafe {
130 from_glib_full(gio_sys::g_application_command_line_get_stdin(
131 self.as_ref().to_glib_none().0,
132 ))
133 }
134 }
135
136 fn getenv<P: AsRef<std::ffi::OsStr>>(&self, name: P) -> Option<GString> {
137 unsafe {
138 from_glib_none(gio_sys::g_application_command_line_getenv(
139 self.as_ref().to_glib_none().0,
140 name.as_ref().to_glib_none().0,
141 ))
142 }
143 }
144
145 fn set_exit_status(&self, exit_status: i32) {
154 unsafe {
155 gio_sys::g_application_command_line_set_exit_status(
156 self.as_ref().to_glib_none().0,
157 exit_status,
158 );
159 }
160 }
161
162 fn connect_property_is_remote_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
163 unsafe extern "C" fn notify_is_remote_trampoline<P, F: Fn(&P) + 'static>(
164 this: *mut gio_sys::GApplicationCommandLine,
165 _param_spec: glib_sys::gpointer,
166 f: glib_sys::gpointer,
167 ) where
168 P: IsA<ApplicationCommandLine>,
169 {
170 let f: &F = &*(f as *const F);
171 f(&ApplicationCommandLine::from_glib_borrow(this).unsafe_cast())
172 }
173 unsafe {
174 let f: Box_<F> = Box_::new(f);
175 connect_raw(
176 self.as_ptr() as *mut _,
177 b"notify::is-remote\0".as_ptr() as *const _,
178 Some(transmute(notify_is_remote_trampoline::<Self, F> as usize)),
179 Box_::into_raw(f),
180 )
181 }
182 }
183}
184
185impl fmt::Display for ApplicationCommandLine {
186 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
187 write!(f, "ApplicationCommandLine")
188 }
189}