1
1
// Take a look at the license at the top of the repository in the LICENSE file.
2
2
3
- use std:: { boxed:: Box as Box_ , mem:: transmute} ;
3
+ use std:: { boxed:: Box as Box_ , mem:: transmute, ops :: ControlFlow } ;
4
4
5
5
use glib:: {
6
6
prelude:: * ,
@@ -9,22 +9,25 @@ use glib::{
9
9
ExitCode , GString ,
10
10
} ;
11
11
12
- use crate :: { ffi, Application , File } ;
12
+ use crate :: { ffi, Application , ApplicationCommandLine , File } ;
13
13
14
14
pub trait ApplicationExtManual : IsA < Application > {
15
15
#[ doc( alias = "g_application_run" ) ]
16
16
fn run ( & self ) -> ExitCode {
17
17
self . run_with_args ( & std:: env:: args ( ) . collect :: < Vec < _ > > ( ) )
18
18
}
19
+
19
20
#[ doc( alias = "g_application_run" ) ]
20
21
fn run_with_args < S : AsRef < str > > ( & self , args : & [ S ] ) -> ExitCode {
21
22
let argv: Vec < & str > = args. iter ( ) . map ( |a| a. as_ref ( ) ) . collect ( ) ;
22
23
let argc = argv. len ( ) as i32 ;
23
24
let exit_code = unsafe {
24
25
ffi:: g_application_run ( self . as_ref ( ) . to_glib_none ( ) . 0 , argc, argv. to_glib_none ( ) . 0 )
25
26
} ;
26
- ExitCode :: from ( exit_code)
27
+ ExitCode :: try_from ( exit_code) . unwrap ( )
27
28
}
29
+
30
+ #[ doc( alias = "open" ) ]
28
31
fn connect_open < F : Fn ( & Self , & [ File ] , & str ) + ' static > ( & self , f : F ) -> SignalHandlerId {
29
32
unsafe extern "C" fn open_trampoline < P , F : Fn ( & P , & [ File ] , & str ) + ' static > (
30
33
this : * mut ffi:: GApplication ,
@@ -56,6 +59,76 @@ pub trait ApplicationExtManual: IsA<Application> {
56
59
}
57
60
}
58
61
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
+
59
132
#[ doc( alias = "g_application_hold" ) ]
60
133
fn hold ( & self ) -> ApplicationHoldGuard {
61
134
unsafe {
0 commit comments