11// Take a look at the license at the top of the repository in the LICENSE file.
22
3- use std:: { boxed:: Box as Box_ , mem:: transmute} ;
3+ use std:: { boxed:: Box as Box_ , mem:: transmute, ops :: ControlFlow } ;
44
55use glib:: {
66 prelude:: * ,
@@ -9,22 +9,25 @@ use glib::{
99 ExitCode , GString ,
1010} ;
1111
12- use crate :: { ffi, Application , File } ;
12+ use crate :: { ffi, Application , ApplicationCommandLine , File } ;
1313
1414pub trait ApplicationExtManual : IsA < Application > {
1515 #[ doc( alias = "g_application_run" ) ]
1616 fn run ( & self ) -> ExitCode {
1717 self . run_with_args ( & std:: env:: args ( ) . collect :: < Vec < _ > > ( ) )
1818 }
19+
1920 #[ doc( alias = "g_application_run" ) ]
2021 fn run_with_args < S : AsRef < str > > ( & self , args : & [ S ] ) -> ExitCode {
2122 let argv: Vec < & str > = args. iter ( ) . map ( |a| a. as_ref ( ) ) . collect ( ) ;
2223 let argc = argv. len ( ) as i32 ;
2324 let exit_code = unsafe {
2425 ffi:: g_application_run ( self . as_ref ( ) . to_glib_none ( ) . 0 , argc, argv. to_glib_none ( ) . 0 )
2526 } ;
26- ExitCode :: from ( exit_code)
27+ ExitCode :: try_from ( exit_code) . unwrap ( )
2728 }
29+
30+ #[ doc( alias = "open" ) ]
2831 fn connect_open < F : Fn ( & Self , & [ File ] , & str ) + ' static > ( & self , f : F ) -> SignalHandlerId {
2932 unsafe extern "C" fn open_trampoline < P , F : Fn ( & P , & [ File ] , & str ) + ' static > (
3033 this : * mut ffi:: GApplication ,
@@ -56,6 +59,76 @@ pub trait ApplicationExtManual: IsA<Application> {
5659 }
5760 }
5861
62+ #[ doc( alias = "command-line" ) ]
63+ fn connect_command_line < F : Fn ( & Self , & ApplicationCommandLine ) -> ExitCode + ' static > (
64+ & self ,
65+ f : F ,
66+ ) -> SignalHandlerId {
67+ unsafe extern "C" fn command_line_trampoline <
68+ P : IsA < Application > ,
69+ F : Fn ( & P , & ApplicationCommandLine ) -> ExitCode + ' static ,
70+ > (
71+ this : * mut ffi:: GApplication ,
72+ command_line : * mut ffi:: GApplicationCommandLine ,
73+ f : glib:: ffi:: gpointer ,
74+ ) -> std:: ffi:: c_int {
75+ let f: & F = & * ( f as * const F ) ;
76+ f (
77+ Application :: from_glib_borrow ( this) . unsafe_cast_ref ( ) ,
78+ & from_glib_borrow ( command_line) ,
79+ )
80+ . into ( )
81+ }
82+ unsafe {
83+ let f: Box_ < F > = Box_ :: new ( f) ;
84+ connect_raw (
85+ self . as_ptr ( ) as * mut _ ,
86+ c"command-line" . as_ptr ( ) as * const _ ,
87+ Some ( std:: mem:: transmute :: < * const ( ) , unsafe extern "C" fn ( ) > (
88+ command_line_trampoline :: < Self , F > as * const ( ) ,
89+ ) ) ,
90+ Box_ :: into_raw ( f) ,
91+ )
92+ }
93+ }
94+
95+ #[ doc( alias = "handle-local-options" ) ]
96+ fn connect_handle_local_options <
97+ F : Fn ( & Self , & glib:: VariantDict ) -> ControlFlow < ExitCode > + ' static ,
98+ > (
99+ & self ,
100+ f : F ,
101+ ) -> SignalHandlerId {
102+ unsafe extern "C" fn handle_local_options_trampoline <
103+ P : IsA < Application > ,
104+ F : Fn ( & P , & glib:: VariantDict ) -> ControlFlow < ExitCode > + ' static ,
105+ > (
106+ this : * mut ffi:: GApplication ,
107+ options : * mut glib:: ffi:: GVariantDict ,
108+ f : glib:: ffi:: gpointer ,
109+ ) -> std:: ffi:: c_int {
110+ let f: & F = & * ( f as * const F ) ;
111+ f (
112+ Application :: from_glib_borrow ( this) . unsafe_cast_ref ( ) ,
113+ & from_glib_borrow ( options) ,
114+ )
115+ . break_value ( )
116+ . map ( i32:: from)
117+ . unwrap_or ( -1 )
118+ }
119+ unsafe {
120+ let f: Box_ < F > = Box_ :: new ( f) ;
121+ connect_raw (
122+ self . as_ptr ( ) as * mut _ ,
123+ c"handle-local-options" . as_ptr ( ) as * const _ ,
124+ Some ( std:: mem:: transmute :: < * const ( ) , unsafe extern "C" fn ( ) > (
125+ handle_local_options_trampoline :: < Self , F > as * const ( ) ,
126+ ) ) ,
127+ Box_ :: into_raw ( f) ,
128+ )
129+ }
130+ }
131+
59132 #[ doc( alias = "g_application_hold" ) ]
60133 fn hold ( & self ) -> ApplicationHoldGuard {
61134 unsafe {
0 commit comments