gio/auto/application_command_line.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 crate::{File, InputStream, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 /// local_command_line = test_local_cmdline;
15 ///
16 /// ...
17 /// }
18 /// ```text
19 ///
20 /// In this example of split commandline handling, options that start
21 /// with `--local-` are handled locally, all other options are passed
22 /// to the [signal@Gio.Application::command-line] handler which runs in the primary
23 /// instance.
24 ///
25 /// The complete example can be found here:
26 /// [gapplication-example-cmdline2.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-cmdline2.c)
27 ///
28 /// If handling the commandline requires a lot of work, it may be better to defer it.
29 ///
30 /// ```c
31 /// static gboolean
32 /// my_cmdline_handler (gpointer data)
33 /// {
34 /// GApplicationCommandLine *cmdline = data;
35 ///
36 /// // do the heavy lifting in an idle
37 ///
38 /// g_application_command_line_set_exit_status (cmdline, 0);
39 /// g_object_unref (cmdline); // this releases the application
40 ///
41 /// return G_SOURCE_REMOVE;
42 /// }
43 ///
44 /// static int
45 /// command_line (GApplication *application,
46 /// GApplicationCommandLine *cmdline)
47 /// {
48 /// // keep the application running until we are done with this commandline
49 /// g_application_hold (application);
50 ///
51 /// g_object_set_data_full (G_OBJECT (cmdline),
52 /// "application", application,
53 /// (GDestroyNotify)g_application_release);
54 ///
55 /// g_object_ref (cmdline);
56 /// g_idle_add (my_cmdline_handler, cmdline);
57 ///
58 /// return 0;
59 /// }
60 /// ```text
61 ///
62 /// In this example the commandline is not completely handled before
63 /// the [`command-line`][struct@crate::Application#command-line] handler returns. Instead, we keep
64 /// a reference to the `GApplicationCommandLine` object and handle it
65 /// later (in this example, in an idle). Note that it is necessary to
66 /// hold the application until you are done with the commandline.
67 ///
68 /// The complete example can be found here:
69 /// [gapplication-example-cmdline3.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-cmdline3.c)
70 ///
71 /// ## Properties
72 ///
73 ///
74 /// #### `arguments`
75 /// The commandline that caused this [`command-line`][struct@crate::Application#command-line]
76 /// signal emission.
77 ///
78 /// Writable | Construct Only
79 ///
80 ///
81 /// #### `is-remote`
82 /// Whether this is a remote commandline.
83 ///
84 /// Readable
85 ///
86 ///
87 /// #### `options`
88 /// The options sent along with the commandline.
89 ///
90 /// Writable | Construct Only
91 ///
92 ///
93 /// #### `platform-data`
94 /// Platform-specific data for the commandline.
95 ///
96 /// Writable | Construct Only
97 ///
98 /// # Implements
99 ///
100 /// [`ApplicationCommandLineExt`][trait@crate::prelude::ApplicationCommandLineExt], [`trait@glib::ObjectExt`], [`ApplicationCommandLineExtManual`][trait@crate::prelude::ApplicationCommandLineExtManual]
101 #[doc(alias = "GApplicationCommandLine")]
102 pub struct ApplicationCommandLine(Object<ffi::GApplicationCommandLine, ffi::GApplicationCommandLineClass>);
103
104 match fn {
105 type_ => || ffi::g_application_command_line_get_type(),
106 }
107}
108
109impl ApplicationCommandLine {
110 pub const NONE: Option<&'static ApplicationCommandLine> = None;
111}
112
113/// Trait containing all [`struct@ApplicationCommandLine`] methods.
114///
115/// # Implementors
116///
117/// [`ApplicationCommandLine`][struct@crate::ApplicationCommandLine]
118pub trait ApplicationCommandLineExt: IsA<ApplicationCommandLine> + 'static {
119 /// Creates a #GFile corresponding to a filename that was given as part
120 /// of the invocation of @self.
121 ///
122 /// This differs from g_file_new_for_commandline_arg() in that it
123 /// resolves relative pathnames using the current working directory of
124 /// the invoking process rather than the local process.
125 /// ## `arg`
126 /// an argument from @self
127 ///
128 /// # Returns
129 ///
130 /// a new #GFile
131 #[doc(alias = "g_application_command_line_create_file_for_arg")]
132 fn create_file_for_arg(&self, arg: impl AsRef<std::ffi::OsStr>) -> File {
133 unsafe {
134 from_glib_full(ffi::g_application_command_line_create_file_for_arg(
135 self.as_ref().to_glib_none().0,
136 arg.as_ref().to_glib_none().0,
137 ))
138 }
139 }
140
141 /// so you can omit the call in non-garbage collected
142 /// languages.
143 #[cfg(feature = "v2_80")]
144 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
145 #[doc(alias = "g_application_command_line_done")]
146 fn done(&self) {
147 unsafe {
148 ffi::g_application_command_line_done(self.as_ref().to_glib_none().0);
149 }
150 }
151
152 /// Gets the list of arguments that was passed on the command line.
153 ///
154 /// The strings in the array may contain non-UTF-8 data on UNIX (such as
155 /// filenames or arguments given in the system locale) but are always in
156 /// UTF-8 on Windows.
157 ///
158 /// If you wish to use the return value with #GOptionContext, you must
159 /// use g_option_context_parse_strv().
160 ///
161 /// The return value is [`None`]-terminated and should be freed using
162 /// g_strfreev().
163 ///
164 /// # Returns
165 ///
166 ///
167 /// the string array containing the arguments (the argv)
168 #[doc(alias = "g_application_command_line_get_arguments")]
169 #[doc(alias = "get_arguments")]
170 fn arguments(&self) -> Vec<std::ffi::OsString> {
171 unsafe {
172 let mut argc = std::mem::MaybeUninit::uninit();
173 let ret = FromGlibContainer::from_glib_full_num(
174 ffi::g_application_command_line_get_arguments(
175 self.as_ref().to_glib_none().0,
176 argc.as_mut_ptr(),
177 ),
178 argc.assume_init() as _,
179 );
180 ret
181 }
182 }
183
184 /// Gets the working directory of the command line invocation.
185 /// The string may contain non-utf8 data.
186 ///
187 /// It is possible that the remote application did not send a working
188 /// directory, so this may be [`None`].
189 ///
190 /// The return value should not be modified or freed and is valid for as
191 /// long as @self exists.
192 ///
193 /// # Returns
194 ///
195 /// the current directory, or [`None`]
196 #[doc(alias = "g_application_command_line_get_cwd")]
197 #[doc(alias = "get_cwd")]
198 fn cwd(&self) -> Option<std::path::PathBuf> {
199 unsafe {
200 from_glib_none(ffi::g_application_command_line_get_cwd(
201 self.as_ref().to_glib_none().0,
202 ))
203 }
204 }
205
206 /// Gets the contents of the 'environ' variable of the command line
207 /// invocation, as would be returned by g_get_environ(), ie as a
208 /// [`None`]-terminated list of strings in the form 'NAME=VALUE'.
209 /// The strings may contain non-utf8 data.
210 ///
211 /// The remote application usually does not send an environment. Use
212 /// [`ApplicationFlags::SEND_ENVIRONMENT`][crate::ApplicationFlags::SEND_ENVIRONMENT] to affect that. Even with this flag
213 /// set it is possible that the environment is still not available (due
214 /// to invocation messages from other applications).
215 ///
216 /// The return value should not be modified or freed and is valid for as
217 /// long as @self exists.
218 ///
219 /// See g_application_command_line_getenv() if you are only interested
220 /// in the value of a single environment variable.
221 ///
222 /// # Returns
223 ///
224 ///
225 /// the environment strings, or [`None`] if they were not sent
226 #[doc(alias = "g_application_command_line_get_environ")]
227 #[doc(alias = "get_environ")]
228 fn environ(&self) -> Vec<std::ffi::OsString> {
229 unsafe {
230 FromGlibPtrContainer::from_glib_none(ffi::g_application_command_line_get_environ(
231 self.as_ref().to_glib_none().0,
232 ))
233 }
234 }
235
236 /// Determines if @self represents a remote invocation.
237 ///
238 /// # Returns
239 ///
240 /// [`true`] if the invocation was remote
241 #[doc(alias = "g_application_command_line_get_is_remote")]
242 #[doc(alias = "get_is_remote")]
243 #[doc(alias = "is-remote")]
244 fn is_remote(&self) -> bool {
245 unsafe {
246 from_glib(ffi::g_application_command_line_get_is_remote(
247 self.as_ref().to_glib_none().0,
248 ))
249 }
250 }
251
252 /// Gets the options that were passed to g_application_command_line().
253 ///
254 /// If you did not override local_command_line() then these are the same
255 /// options that were parsed according to the #GOptionEntrys added to the
256 /// application with g_application_add_main_option_entries() and possibly
257 /// modified from your GApplication::handle-local-options handler.
258 ///
259 /// If no options were sent then an empty dictionary is returned so that
260 /// you don't need to check for [`None`].
261 ///
262 /// The data has been passed via an untrusted external process, so the types of
263 /// all values must be checked before being used.
264 ///
265 /// # Returns
266 ///
267 /// a #GVariantDict with the options
268 #[doc(alias = "g_application_command_line_get_options_dict")]
269 #[doc(alias = "get_options_dict")]
270 fn options_dict(&self) -> glib::VariantDict {
271 unsafe {
272 from_glib_none(ffi::g_application_command_line_get_options_dict(
273 self.as_ref().to_glib_none().0,
274 ))
275 }
276 }
277
278 /// Gets the platform data associated with the invocation of @self.
279 ///
280 /// This is a #GVariant dictionary containing information about the
281 /// context in which the invocation occurred. It typically contains
282 /// information like the current working directory and the startup
283 /// notification ID.
284 ///
285 /// It comes from an untrusted external process and hence the types of all
286 /// values must be validated before being used.
287 ///
288 /// For local invocation, it will be [`None`].
289 ///
290 /// # Returns
291 ///
292 /// the platform data, or [`None`]
293 #[doc(alias = "g_application_command_line_get_platform_data")]
294 #[doc(alias = "get_platform_data")]
295 fn platform_data(&self) -> Option<glib::Variant> {
296 unsafe {
297 from_glib_full(ffi::g_application_command_line_get_platform_data(
298 self.as_ref().to_glib_none().0,
299 ))
300 }
301 }
302
303 /// Gets the stdin of the invoking process.
304 ///
305 /// The #GInputStream can be used to read data passed to the standard
306 /// input of the invoking process.
307 /// This doesn't work on all platforms. Presently, it is only available
308 /// on UNIX when using a D-Bus daemon capable of passing file descriptors.
309 /// If stdin is not available then [`None`] will be returned. In the
310 /// future, support may be expanded to other platforms.
311 ///
312 /// You must only call this function once per commandline invocation.
313 ///
314 /// # Returns
315 ///
316 /// a #GInputStream for stdin
317 #[doc(alias = "g_application_command_line_get_stdin")]
318 #[doc(alias = "get_stdin")]
319 fn stdin(&self) -> Option<InputStream> {
320 unsafe {
321 from_glib_full(ffi::g_application_command_line_get_stdin(
322 self.as_ref().to_glib_none().0,
323 ))
324 }
325 }
326
327 /// Gets the value of a particular environment variable of the command
328 /// line invocation, as would be returned by g_getenv(). The strings may
329 /// contain non-utf8 data.
330 ///
331 /// The remote application usually does not send an environment. Use
332 /// [`ApplicationFlags::SEND_ENVIRONMENT`][crate::ApplicationFlags::SEND_ENVIRONMENT] to affect that. Even with this flag
333 /// set it is possible that the environment is still not available (due
334 /// to invocation messages from other applications).
335 ///
336 /// The return value should not be modified or freed and is valid for as
337 /// long as @self exists.
338 /// ## `name`
339 /// the environment variable to get
340 ///
341 /// # Returns
342 ///
343 /// the value of the variable, or [`None`] if unset or unsent
344 #[doc(alias = "g_application_command_line_getenv")]
345 fn getenv(&self, name: impl AsRef<std::ffi::OsStr>) -> Option<glib::GString> {
346 unsafe {
347 from_glib_none(ffi::g_application_command_line_getenv(
348 self.as_ref().to_glib_none().0,
349 name.as_ref().to_glib_none().0,
350 ))
351 }
352 }
353
354 //#[doc(alias = "g_application_command_line_print")]
355 //fn print(&self, format: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
356 // unsafe { TODO: call ffi:g_application_command_line_print() }
357 //}
358
359 /// Prints a message using the stdout print handler in the invoking process.
360 ///
361 /// Unlike g_application_command_line_print(), @message is not a `printf()`-style
362 /// format string. Use this function if @message contains text you don't have
363 /// control over, that could include `printf()` escape sequences.
364 /// ## `message`
365 /// the message
366 #[cfg(feature = "v2_80")]
367 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
368 #[doc(alias = "g_application_command_line_print_literal")]
369 fn print_literal(&self, message: &str) {
370 unsafe {
371 ffi::g_application_command_line_print_literal(
372 self.as_ref().to_glib_none().0,
373 message.to_glib_none().0,
374 );
375 }
376 }
377
378 //#[doc(alias = "g_application_command_line_printerr")]
379 //fn printerr(&self, format: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
380 // unsafe { TODO: call ffi:g_application_command_line_printerr() }
381 //}
382
383 /// Prints a message using the stderr print handler in the invoking process.
384 ///
385 /// Unlike g_application_command_line_printerr(), @message is not
386 /// a `printf()`-style format string. Use this function if @message contains text
387 /// you don't have control over, that could include `printf()` escape sequences.
388 /// ## `message`
389 /// the message
390 #[cfg(feature = "v2_80")]
391 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
392 #[doc(alias = "g_application_command_line_printerr_literal")]
393 fn printerr_literal(&self, message: &str) {
394 unsafe {
395 ffi::g_application_command_line_printerr_literal(
396 self.as_ref().to_glib_none().0,
397 message.to_glib_none().0,
398 );
399 }
400 }
401
402 #[doc(alias = "is-remote")]
403 fn connect_is_remote_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
404 unsafe extern "C" fn notify_is_remote_trampoline<
405 P: IsA<ApplicationCommandLine>,
406 F: Fn(&P) + 'static,
407 >(
408 this: *mut ffi::GApplicationCommandLine,
409 _param_spec: glib::ffi::gpointer,
410 f: glib::ffi::gpointer,
411 ) {
412 unsafe {
413 let f: &F = &*(f as *const F);
414 f(ApplicationCommandLine::from_glib_borrow(this).unsafe_cast_ref())
415 }
416 }
417 unsafe {
418 let f: Box_<F> = Box_::new(f);
419 connect_raw(
420 self.as_ptr() as *mut _,
421 c"notify::is-remote".as_ptr(),
422 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
423 notify_is_remote_trampoline::<Self, F> as *const (),
424 )),
425 Box_::into_raw(f),
426 )
427 }
428 }
429}
430
431impl<O: IsA<ApplicationCommandLine>> ApplicationCommandLineExt for O {}