@@ -6,7 +6,9 @@ use glib::{prelude::*, translate::*};
6
6
7
7
#[ cfg( feature = "v2_74" ) ]
8
8
use crate :: FileIOStream ;
9
- use crate :: { ffi, Cancellable , File , FileCreateFlags , FileEnumerator , FileQueryInfoFlags } ;
9
+ use crate :: {
10
+ ffi, Cancellable , File , FileAttributeType , FileCreateFlags , FileEnumerator , FileQueryInfoFlags ,
11
+ } ;
10
12
11
13
impl File {
12
14
#[ cfg( feature = "v2_74" ) ]
@@ -1111,6 +1113,99 @@ pub trait FileExtManual: IsA<File> + Sized {
1111
1113
1112
1114
( fut, Box :: pin ( receiver) )
1113
1115
}
1116
+
1117
+ #[ doc( alias = "g_file_set_attribute" ) ]
1118
+ fn set_attribute < T > (
1119
+ & self ,
1120
+ attribute : & str ,
1121
+ type_ : FileAttributeType ,
1122
+ value : FileAttributeTypeValue < T > ,
1123
+ flags : FileQueryInfoFlags ,
1124
+ cancellable : Option < & impl IsA < Cancellable > > ,
1125
+ ) -> Result < ( ) , glib:: Error > {
1126
+ unsafe {
1127
+ let mut error = std:: ptr:: null_mut ( ) ;
1128
+ let is_ok = ffi:: g_file_set_attribute (
1129
+ self . as_ref ( ) . to_glib_none ( ) . 0 ,
1130
+ attribute. to_glib_none ( ) . 0 ,
1131
+ type_. into_glib ( ) ,
1132
+ value. 0 ,
1133
+ flags. into_glib ( ) ,
1134
+ cancellable. map ( |p| p. as_ref ( ) ) . to_glib_none ( ) . 0 ,
1135
+ & mut error,
1136
+ ) ;
1137
+ debug_assert_eq ! ( is_ok == glib:: ffi:: GFALSE , !error. is_null( ) ) ;
1138
+ if error. is_null ( ) {
1139
+ Ok ( ( ) )
1140
+ } else {
1141
+ Err ( from_glib_full ( error) )
1142
+ }
1143
+ }
1144
+ }
1114
1145
}
1115
1146
1116
1147
impl < O : IsA < File > > FileExtManual for O { }
1148
+
1149
+ // checker-ignore-item
1150
+ pub struct FileAttributeTypeValue < T > ( pub glib:: ffi:: gpointer , pub T ) ;
1151
+
1152
+ impl < T > From < * const T > for FileAttributeTypeValue < * const T > {
1153
+ fn from ( value : * const T ) -> Self {
1154
+ Self ( value as _ , value)
1155
+ }
1156
+ }
1157
+
1158
+ impl < T > From < * mut T > for FileAttributeTypeValue < * mut T > {
1159
+ fn from ( value : * mut T ) -> Self {
1160
+ Self ( value as _ , value)
1161
+ }
1162
+ }
1163
+
1164
+ impl < ' a > From < & ' a str >
1165
+ for FileAttributeTypeValue < <& ' a str as ToGlibPtr < ' a , * mut libc:: c_char > >:: Storage >
1166
+ {
1167
+ fn from ( value : & ' a str ) -> Self {
1168
+ let s = ToGlibPtr :: < * mut libc:: c_char > :: to_glib_none ( value) ;
1169
+ Self ( s. 0 as _ , s. 1 )
1170
+ }
1171
+ }
1172
+
1173
+ impl < T : Copy > From < & T > for FileAttributeTypeValue < T >
1174
+ where
1175
+ FileAttributeTypeValue < T > : From < T > ,
1176
+ {
1177
+ fn from ( value : & T ) -> Self {
1178
+ ( * value) . into ( )
1179
+ }
1180
+ }
1181
+
1182
+ impl From < bool > for FileAttributeTypeValue < glib:: ffi:: gboolean > {
1183
+ fn from ( value : bool ) -> Self {
1184
+ let b = value. into_glib ( ) ;
1185
+ Self ( & b as * const _ as _ , b)
1186
+ }
1187
+ }
1188
+
1189
+ impl From < u32 > for FileAttributeTypeValue < u32 > {
1190
+ fn from ( value : u32 ) -> Self {
1191
+ Self ( & value as * const _ as _ , value)
1192
+ }
1193
+ }
1194
+
1195
+ impl From < i32 > for FileAttributeTypeValue < i32 > {
1196
+ fn from ( value : i32 ) -> Self {
1197
+ Self ( & value as * const _ as _ , value)
1198
+ }
1199
+ }
1200
+
1201
+ impl From < u64 > for FileAttributeTypeValue < u64 > {
1202
+ fn from ( value : u64 ) -> Self {
1203
+ Self ( & value as * const _ as _ , value)
1204
+ }
1205
+ }
1206
+
1207
+ impl From < i64 > for FileAttributeTypeValue < i64 > {
1208
+ fn from ( value : i64 ) -> Self {
1209
+ Self ( & value as * const _ as _ , value)
1210
+ }
1211
+ }
0 commit comments