Skip to content

Commit e039b1e

Browse files
pjungkampsdroege
authored andcommitted
gio: Add exit_code methods to ApplicationCommandLine
1 parent 6145da9 commit e039b1e

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

gio/Gir.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ generate_builder = true
346346
[[object]]
347347
name = "Gio.ApplicationCommandLine"
348348
status = "generate"
349+
manual_traits = ["ApplicationCommandLineExtManual"]
349350
[[object.function]]
350351
name = "create_file_for_arg"
351352
[[object.function.parameter]]
@@ -364,6 +365,16 @@ status = "generate"
364365
[[object.function.parameter]]
365366
name = "name"
366367
string_type = "os_string"
368+
[[object.function]]
369+
name = "set_exit_status"
370+
# Uses glib::ExitCode for consitency with gio::Application interfaces
371+
manual = true
372+
doc_trait_name = "ApplicationCommandLineExtManual"
373+
[[object.function]]
374+
name = "get_exit_status"
375+
# Uses glib::ExitCode for consitency with gio::Application interfaces
376+
manual = true
377+
doc_trait_name = "ApplicationCommandLineExtManual"
367378

368379
[[object]]
369380
name = "Gio.ApplicationFlags"

gio/src/application_command_line.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Take a look at the license at the top of the repository in the LICENSE file.
2+
3+
use std::{boxed::Box as Box_, mem::transmute, ops::ControlFlow};
4+
5+
use glib::{
6+
prelude::*,
7+
signal::{connect_raw, SignalHandlerId},
8+
translate::*,
9+
ExitCode, GString,
10+
};
11+
12+
use crate::{ffi, Application, ApplicationCommandLine, ExitCode, File};
13+
14+
pub trait ApplicationCommandLineExtManual: IsA<Application> {
15+
#[doc(alias = "g_application_command_line_get_exit_status")]
16+
#[doc(alias = "get_exit_status")]
17+
fn exit_code(&self) -> ExitCode {
18+
let status = unsafe {
19+
ffi::g_application_command_line_get_exit_status(self.as_ref().to_glib_none().0)
20+
};
21+
22+
ExitCode::try_from(status).unwrap()
23+
}
24+
25+
#[doc(alias = "g_application_command_line_set_exit_status")]
26+
#[doc(alias = "set_exit_status")]
27+
fn set_exit_code(&self, exit_code: ExitCode) {
28+
let status = i32::from(exit_code.get());
29+
30+
unsafe {
31+
ffi::g_application_command_line_set_exit_status(self.as_ref().to_glib_none().0, status);
32+
}
33+
}
34+
}
35+
36+
impl<O: IsA<Application>> ApplicationExtManual for O {}

0 commit comments

Comments
 (0)