gio/auto/
application_command_line.rs1use crate::{ffi, File, InputStream};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GApplicationCommandLine")]
15 pub struct ApplicationCommandLine(Object<ffi::GApplicationCommandLine, ffi::GApplicationCommandLineClass>);
16
17 match fn {
18 type_ => || ffi::g_application_command_line_get_type(),
19 }
20}
21
22impl ApplicationCommandLine {
23 pub const NONE: Option<&'static ApplicationCommandLine> = None;
24}
25
26pub trait ApplicationCommandLineExt: IsA<ApplicationCommandLine> + 'static {
27 #[doc(alias = "g_application_command_line_create_file_for_arg")]
28 fn create_file_for_arg(&self, arg: impl AsRef<std::ffi::OsStr>) -> File {
29 unsafe {
30 from_glib_full(ffi::g_application_command_line_create_file_for_arg(
31 self.as_ref().to_glib_none().0,
32 arg.as_ref().to_glib_none().0,
33 ))
34 }
35 }
36
37 #[cfg(feature = "v2_80")]
38 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
39 #[doc(alias = "g_application_command_line_done")]
40 fn done(&self) {
41 unsafe {
42 ffi::g_application_command_line_done(self.as_ref().to_glib_none().0);
43 }
44 }
45
46 #[doc(alias = "g_application_command_line_get_arguments")]
47 #[doc(alias = "get_arguments")]
48 fn arguments(&self) -> Vec<std::ffi::OsString> {
49 unsafe {
50 let mut argc = std::mem::MaybeUninit::uninit();
51 let ret = FromGlibContainer::from_glib_full_num(
52 ffi::g_application_command_line_get_arguments(
53 self.as_ref().to_glib_none().0,
54 argc.as_mut_ptr(),
55 ),
56 argc.assume_init() as _,
57 );
58 ret
59 }
60 }
61
62 #[doc(alias = "g_application_command_line_get_cwd")]
63 #[doc(alias = "get_cwd")]
64 fn cwd(&self) -> Option<std::path::PathBuf> {
65 unsafe {
66 from_glib_none(ffi::g_application_command_line_get_cwd(
67 self.as_ref().to_glib_none().0,
68 ))
69 }
70 }
71
72 #[doc(alias = "g_application_command_line_get_environ")]
73 #[doc(alias = "get_environ")]
74 fn environ(&self) -> Vec<std::ffi::OsString> {
75 unsafe {
76 FromGlibPtrContainer::from_glib_none(ffi::g_application_command_line_get_environ(
77 self.as_ref().to_glib_none().0,
78 ))
79 }
80 }
81
82 #[doc(alias = "g_application_command_line_get_exit_status")]
83 #[doc(alias = "get_exit_status")]
84 fn exit_status(&self) -> i32 {
85 unsafe { ffi::g_application_command_line_get_exit_status(self.as_ref().to_glib_none().0) }
86 }
87
88 #[doc(alias = "g_application_command_line_get_is_remote")]
89 #[doc(alias = "get_is_remote")]
90 #[doc(alias = "is-remote")]
91 fn is_remote(&self) -> bool {
92 unsafe {
93 from_glib(ffi::g_application_command_line_get_is_remote(
94 self.as_ref().to_glib_none().0,
95 ))
96 }
97 }
98
99 #[doc(alias = "g_application_command_line_get_options_dict")]
100 #[doc(alias = "get_options_dict")]
101 fn options_dict(&self) -> glib::VariantDict {
102 unsafe {
103 from_glib_none(ffi::g_application_command_line_get_options_dict(
104 self.as_ref().to_glib_none().0,
105 ))
106 }
107 }
108
109 #[doc(alias = "g_application_command_line_get_platform_data")]
110 #[doc(alias = "get_platform_data")]
111 fn platform_data(&self) -> Option<glib::Variant> {
112 unsafe {
113 from_glib_full(ffi::g_application_command_line_get_platform_data(
114 self.as_ref().to_glib_none().0,
115 ))
116 }
117 }
118
119 #[doc(alias = "g_application_command_line_get_stdin")]
120 #[doc(alias = "get_stdin")]
121 fn stdin(&self) -> Option<InputStream> {
122 unsafe {
123 from_glib_full(ffi::g_application_command_line_get_stdin(
124 self.as_ref().to_glib_none().0,
125 ))
126 }
127 }
128
129 #[doc(alias = "g_application_command_line_getenv")]
130 fn getenv(&self, name: impl AsRef<std::ffi::OsStr>) -> Option<glib::GString> {
131 unsafe {
132 from_glib_none(ffi::g_application_command_line_getenv(
133 self.as_ref().to_glib_none().0,
134 name.as_ref().to_glib_none().0,
135 ))
136 }
137 }
138
139 #[cfg(feature = "v2_80")]
145 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
146 #[doc(alias = "g_application_command_line_print_literal")]
147 fn print_literal(&self, message: &str) {
148 unsafe {
149 ffi::g_application_command_line_print_literal(
150 self.as_ref().to_glib_none().0,
151 message.to_glib_none().0,
152 );
153 }
154 }
155
156 #[cfg(feature = "v2_80")]
162 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
163 #[doc(alias = "g_application_command_line_printerr_literal")]
164 fn printerr_literal(&self, message: &str) {
165 unsafe {
166 ffi::g_application_command_line_printerr_literal(
167 self.as_ref().to_glib_none().0,
168 message.to_glib_none().0,
169 );
170 }
171 }
172
173 #[doc(alias = "g_application_command_line_set_exit_status")]
174 fn set_exit_status(&self, exit_status: i32) {
175 unsafe {
176 ffi::g_application_command_line_set_exit_status(
177 self.as_ref().to_glib_none().0,
178 exit_status,
179 );
180 }
181 }
182
183 #[doc(alias = "is-remote")]
184 fn connect_is_remote_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
185 unsafe extern "C" fn notify_is_remote_trampoline<
186 P: IsA<ApplicationCommandLine>,
187 F: Fn(&P) + 'static,
188 >(
189 this: *mut ffi::GApplicationCommandLine,
190 _param_spec: glib::ffi::gpointer,
191 f: glib::ffi::gpointer,
192 ) {
193 let f: &F = &*(f as *const F);
194 f(ApplicationCommandLine::from_glib_borrow(this).unsafe_cast_ref())
195 }
196 unsafe {
197 let f: Box_<F> = Box_::new(f);
198 connect_raw(
199 self.as_ptr() as *mut _,
200 c"notify::is-remote".as_ptr() as *const _,
201 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
202 notify_is_remote_trampoline::<Self, F> as *const (),
203 )),
204 Box_::into_raw(f),
205 )
206 }
207 }
208}
209
210impl<O: IsA<ApplicationCommandLine>> ApplicationCommandLineExt for O {}