File tree Expand file tree Collapse file tree 5 files changed +46
-21
lines changed Expand file tree Collapse file tree 5 files changed +46
-21
lines changed Original file line number Diff line number Diff line change @@ -249,9 +249,9 @@ status = "generate"
249249 ignore = true
250250 [[object .function ]]
251251 name = " content_type_guess"
252- [[ object . function . parameter ]]
253- name = " filename "
254- string_type = " filename "
252+ # implemented manually until gir generates nullable array parameters
253+ # https://github.com/gtk-rs/gir/issues/1133
254+ manual = true
255255
256256[[object ]]
257257name = " Gio.ActionGroup"
Original file line number Diff line number Diff line change @@ -178,24 +178,6 @@ pub fn content_type_get_symbolic_icon(type_: &str) -> Icon {
178178 }
179179}
180180
181- #[ doc( alias = "g_content_type_guess" ) ]
182- pub fn content_type_guess (
183- filename : Option < impl AsRef < std:: path:: Path > > ,
184- data : & [ u8 ] ,
185- ) -> ( glib:: GString , bool ) {
186- let data_size = data. len ( ) as _ ;
187- unsafe {
188- let mut result_uncertain = std:: mem:: MaybeUninit :: uninit ( ) ;
189- let ret = from_glib_full ( ffi:: g_content_type_guess (
190- filename. as_ref ( ) . map ( |p| p. as_ref ( ) ) . to_glib_none ( ) . 0 ,
191- data. to_glib_none ( ) . 0 ,
192- data_size,
193- result_uncertain. as_mut_ptr ( ) ,
194- ) ) ;
195- ( ret, from_glib ( result_uncertain. assume_init ( ) ) )
196- }
197- }
198-
199181#[ doc( alias = "g_content_type_guess_for_tree" ) ]
200182pub fn content_type_guess_for_tree ( root : & impl IsA < File > ) -> Vec < glib:: GString > {
201183 unsafe {
Original file line number Diff line number Diff line change 1+ // Take a look at the license at the top of the repository in the LICENSE file.
2+
3+ use std:: ptr;
4+
5+ use glib:: translate:: * ;
6+
7+ use crate :: ffi;
8+
9+ #[ doc( alias = "g_content_type_guess" ) ]
10+ pub fn content_type_guess < ' a > (
11+ filename : Option < impl AsRef < std:: path:: Path > > ,
12+ data : impl Into < Option < & ' a [ u8 ] > > ,
13+ ) -> ( glib:: GString , bool ) {
14+ let data = data. into ( ) ;
15+ let data_size = data. map_or ( 0 , |d| d. len ( ) ) ;
16+ unsafe {
17+ let mut result_uncertain = std:: mem:: MaybeUninit :: uninit ( ) ;
18+ let ret = from_glib_full ( ffi:: g_content_type_guess (
19+ filename. as_ref ( ) . map ( |p| p. as_ref ( ) ) . to_glib_none ( ) . 0 ,
20+ data. map_or ( ptr:: null ( ) , |d| d. to_glib_none ( ) . 0 ) ,
21+ data_size,
22+ result_uncertain. as_mut_ptr ( ) ,
23+ ) ) ;
24+ ( ret, from_glib ( result_uncertain. assume_init ( ) ) )
25+ }
26+ }
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ mod cancellable;
2222pub use cancellable:: CancelledHandlerId ;
2323mod cancellable_future;
2424pub use crate :: cancellable_future:: { CancellableFuture , Cancelled } ;
25+ mod content_type;
2526mod converter;
2627mod credentials;
2728mod data_input_stream;
@@ -116,6 +117,7 @@ pub mod builders {
116117
117118pub mod functions {
118119 pub use super :: auto:: functions:: * ;
120+ pub use super :: content_type:: content_type_guess;
119121}
120122
121123pub use crate :: auto:: * ;
Original file line number Diff line number Diff line change 1+ // Take a look at the license at the top of the repository in the LICENSE file.
2+
3+ #[ cfg( unix) ]
4+ #[ test]
5+ fn test_content_type_guess ( ) {
6+ // We only test for directory and file without extension here as we can't guarantee the
7+ // CI runners will have any mimetypes installed.
8+ let ret: ( glib:: GString , bool ) =
9+ gio:: functions:: content_type_guess ( Some ( std:: path:: Path :: new ( "test/" ) ) , None ) ;
10+ assert_eq ! ( ret. 0 , "inode/directory" ) ;
11+
12+ let ret: ( glib:: GString , bool ) =
13+ gio:: functions:: content_type_guess ( Some ( std:: path:: Path :: new ( "test" ) ) , None ) ;
14+ assert_eq ! ( ret. 0 , "application/octet-stream" ) ;
15+ }
You can’t perform that action at this time.
0 commit comments