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 /// Signals that command line processing is completed.
142 ///
143 /// For remote invocation, it causes the invoking process to terminate.
144 ///
145 /// For local invocation, it does nothing.
146 ///
147 /// This method should be called in the [`command-line`][struct@crate::Application#command-line]
148 /// handler, after the exit status is set and all messages are printed.
149 ///
150 /// After this call, g_application_command_line_set_exit_status() has no effect.
151 /// Subsequent calls to this method are no-ops.
152 ///
153 /// This method is automatically called when the #GApplicationCommandLine
154 /// object is disposed — so you can omit the call in non-garbage collected
155 /// languages.
156 #[cfg(feature = "v2_80")]
157 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
158 #[doc(alias = "g_application_command_line_done")]
159 fn done(&self) {
160 unsafe {
161 ffi::g_application_command_line_done(self.as_ref().to_glib_none().0);
162 }
163 }
164
165 /// Gets the list of arguments that was passed on the command line.
166 ///
167 /// The strings in the array may contain non-UTF-8 data on UNIX (such as
168 /// filenames or arguments given in the system locale) but are always in
169 /// UTF-8 on Windows.
170 ///
171 /// If you wish to use the return value with #GOptionContext, you must
172 /// use g_option_context_parse_strv().
173 ///
174 /// The return value is [`None`]-terminated and should be freed using
175 /// g_strfreev().
176 ///
177 /// # Returns
178 ///
179 ///
180 /// the string array containing the arguments (the argv)
181 #[doc(alias = "g_application_command_line_get_arguments")]
182 #[doc(alias = "get_arguments")]
183 fn arguments(&self) -> Vec<std::ffi::OsString> {
184 unsafe {
185 let mut argc = std::mem::MaybeUninit::uninit();
186 let ret = FromGlibContainer::from_glib_full_num(
187 ffi::g_application_command_line_get_arguments(
188 self.as_ref().to_glib_none().0,
189 argc.as_mut_ptr(),
190 ),
191 argc.assume_init() as _,
192 );
193 ret
194 }
195 }
196
197 /// Gets the working directory of the command line invocation.
198 /// The string may contain non-utf8 data.
199 ///
200 /// It is possible that the remote application did not send a working
201 /// directory, so this may be [`None`].
202 ///
203 /// The return value should not be modified or freed and is valid for as
204 /// long as @self exists.
205 ///
206 /// # Returns
207 ///
208 /// the current directory, or [`None`]
209 #[doc(alias = "g_application_command_line_get_cwd")]
210 #[doc(alias = "get_cwd")]
211 fn cwd(&self) -> Option<std::path::PathBuf> {
212 unsafe {
213 from_glib_none(ffi::g_application_command_line_get_cwd(
214 self.as_ref().to_glib_none().0,
215 ))
216 }
217 }
218
219 /// Gets the contents of the 'environ' variable of the command line
220 /// invocation, as would be returned by g_get_environ(), ie as a
221 /// [`None`]-terminated list of strings in the form 'NAME=VALUE'.
222 /// The strings may contain non-utf8 data.
223 ///
224 /// The remote application usually does not send an environment. Use
225 /// [`ApplicationFlags::SEND_ENVIRONMENT`][crate::ApplicationFlags::SEND_ENVIRONMENT] to affect that. Even with this flag
226 /// set it is possible that the environment is still not available (due
227 /// to invocation messages from other applications).
228 ///
229 /// The return value should not be modified or freed and is valid for as
230 /// long as @self exists.
231 ///
232 /// See g_application_command_line_getenv() if you are only interested
233 /// in the value of a single environment variable.
234 ///
235 /// # Returns
236 ///
237 ///
238 /// the environment strings, or [`None`] if they were not sent
239 #[doc(alias = "g_application_command_line_get_environ")]
240 #[doc(alias = "get_environ")]
241 fn environ(&self) -> Vec<std::ffi::OsString> {
242 unsafe {
243 FromGlibPtrContainer::from_glib_none(ffi::g_application_command_line_get_environ(
244 self.as_ref().to_glib_none().0,
245 ))
246 }
247 }
248
249 /// Determines if @self represents a remote invocation.
250 ///
251 /// # Returns
252 ///
253 /// [`true`] if the invocation was remote
254 #[doc(alias = "g_application_command_line_get_is_remote")]
255 #[doc(alias = "get_is_remote")]
256 #[doc(alias = "is-remote")]
257 fn is_remote(&self) -> bool {
258 unsafe {
259 from_glib(ffi::g_application_command_line_get_is_remote(
260 self.as_ref().to_glib_none().0,
261 ))
262 }
263 }
264
265 /// Gets the options that were passed to g_application_command_line().
266 ///
267 /// If you did not override local_command_line() then these are the same
268 /// options that were parsed according to the #GOptionEntrys added to the
269 /// application with g_application_add_main_option_entries() and possibly
270 /// modified from your GApplication::handle-local-options handler.
271 ///
272 /// If no options were sent then an empty dictionary is returned so that
273 /// you don't need to check for [`None`].
274 ///
275 /// The data has been passed via an untrusted external process, so the types of
276 /// all values must be checked before being used.
277 ///
278 /// # Returns
279 ///
280 /// a #GVariantDict with the options
281 #[doc(alias = "g_application_command_line_get_options_dict")]
282 #[doc(alias = "get_options_dict")]
283 fn options_dict(&self) -> glib::VariantDict {
284 unsafe {
285 from_glib_none(ffi::g_application_command_line_get_options_dict(
286 self.as_ref().to_glib_none().0,
287 ))
288 }
289 }
290
291 /// Gets the platform data associated with the invocation of @self.
292 ///
293 /// This is a #GVariant dictionary containing information about the
294 /// context in which the invocation occurred. It typically contains
295 /// information like the current working directory and the startup
296 /// notification ID.
297 ///
298 /// It comes from an untrusted external process and hence the types of all
299 /// values must be validated before being used.
300 ///
301 /// For local invocation, it will be [`None`].
302 ///
303 /// # Returns
304 ///
305 /// the platform data, or [`None`]
306 #[doc(alias = "g_application_command_line_get_platform_data")]
307 #[doc(alias = "get_platform_data")]
308 fn platform_data(&self) -> Option<glib::Variant> {
309 unsafe {
310 from_glib_full(ffi::g_application_command_line_get_platform_data(
311 self.as_ref().to_glib_none().0,
312 ))
313 }
314 }
315
316 /// Gets the stdin of the invoking process.
317 ///
318 /// The #GInputStream can be used to read data passed to the standard
319 /// input of the invoking process.
320 /// This doesn't work on all platforms. Presently, it is only available
321 /// on UNIX when using a D-Bus daemon capable of passing file descriptors.
322 /// If stdin is not available then [`None`] will be returned. In the
323 /// future, support may be expanded to other platforms.
324 ///
325 /// You must only call this function once per commandline invocation.
326 ///
327 /// # Returns
328 ///
329 /// a #GInputStream for stdin
330 #[doc(alias = "g_application_command_line_get_stdin")]
331 #[doc(alias = "get_stdin")]
332 fn stdin(&self) -> Option<InputStream> {
333 unsafe {
334 from_glib_full(ffi::g_application_command_line_get_stdin(
335 self.as_ref().to_glib_none().0,
336 ))
337 }
338 }
339
340 /// Gets the value of a particular environment variable of the command
341 /// line invocation, as would be returned by g_getenv(). The strings may
342 /// contain non-utf8 data.
343 ///
344 /// The remote application usually does not send an environment. Use
345 /// [`ApplicationFlags::SEND_ENVIRONMENT`][crate::ApplicationFlags::SEND_ENVIRONMENT] to affect that. Even with this flag
346 /// set it is possible that the environment is still not available (due
347 /// to invocation messages from other applications).
348 ///
349 /// The return value should not be modified or freed and is valid for as
350 /// long as @self exists.
351 /// ## `name`
352 /// the environment variable to get
353 ///
354 /// # Returns
355 ///
356 /// the value of the variable, or [`None`] if unset or unsent
357 #[doc(alias = "g_application_command_line_getenv")]
358 fn getenv(&self, name: impl AsRef<std::ffi::OsStr>) -> Option<glib::GString> {
359 unsafe {
360 from_glib_none(ffi::g_application_command_line_getenv(
361 self.as_ref().to_glib_none().0,
362 name.as_ref().to_glib_none().0,
363 ))
364 }
365 }
366
367 //#[doc(alias = "g_application_command_line_print")]
368 //fn print(&self, format: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
369 // unsafe { TODO: call ffi:g_application_command_line_print() }
370 //}
371
372 /// Prints a message using the stdout print handler in the invoking process.
373 ///
374 /// Unlike g_application_command_line_print(), @message is not a `printf()`-style
375 /// format string. Use this function if @message contains text you don't have
376 /// control over, that could include `printf()` escape sequences.
377 /// ## `message`
378 /// the message
379 #[cfg(feature = "v2_80")]
380 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
381 #[doc(alias = "g_application_command_line_print_literal")]
382 fn print_literal(&self, message: &str) {
383 unsafe {
384 ffi::g_application_command_line_print_literal(
385 self.as_ref().to_glib_none().0,
386 message.to_glib_none().0,
387 );
388 }
389 }
390
391 //#[doc(alias = "g_application_command_line_printerr")]
392 //fn printerr(&self, format: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
393 // unsafe { TODO: call ffi:g_application_command_line_printerr() }
394 //}
395
396 /// Prints a message using the stderr print handler in the invoking process.
397 ///
398 /// Unlike g_application_command_line_printerr(), @message is not
399 /// a `printf()`-style format string. Use this function if @message contains text
400 /// you don't have control over, that could include `printf()` escape sequences.
401 /// ## `message`
402 /// the message
403 #[cfg(feature = "v2_80")]
404 #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
405 #[doc(alias = "g_application_command_line_printerr_literal")]
406 fn printerr_literal(&self, message: &str) {
407 unsafe {
408 ffi::g_application_command_line_printerr_literal(
409 self.as_ref().to_glib_none().0,
410 message.to_glib_none().0,
411 );
412 }
413 }
414
415 #[doc(alias = "is-remote")]
416 fn connect_is_remote_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
417 unsafe extern "C" fn notify_is_remote_trampoline<
418 P: IsA<ApplicationCommandLine>,
419 F: Fn(&P) + 'static,
420 >(
421 this: *mut ffi::GApplicationCommandLine,
422 _param_spec: glib::ffi::gpointer,
423 f: glib::ffi::gpointer,
424 ) {
425 unsafe {
426 let f: &F = &*(f as *const F);
427 f(ApplicationCommandLine::from_glib_borrow(this).unsafe_cast_ref())
428 }
429 }
430 unsafe {
431 let f: Box_<F> = Box_::new(f);
432 connect_raw(
433 self.as_ptr() as *mut _,
434 c"notify::is-remote".as_ptr(),
435 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
436 notify_is_remote_trampoline::<Self, F> as *const (),
437 )),
438 Box_::into_raw(f),
439 )
440 }
441 }
442}
443
444impl<O: IsA<ApplicationCommandLine>> ApplicationCommandLineExt for O {}