1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::AsyncResult;
use crate::BusType;
use crate::Cancellable;
use crate::DBusConnection;
use crate::File;
use crate::IOErrorEnum;
use crate::IOStream;
use crate::Icon;
use crate::InputStream;
use crate::Resource;
use crate::ResourceLookupFlags;
use crate::SettingsBackend;
use glib::object::IsA;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::mem;
use std::pin::Pin;
use std::ptr;

/// Asynchronously connects to the message bus specified by `bus_type`.
///
/// When the operation is finished, `callback` will be invoked. You can
/// then call `g_bus_get_finish()` to get the result of the operation.
///
/// This is an asynchronous failable function. See [`bus_get_sync()`][crate::bus_get_sync()] for
/// the synchronous version.
/// ## `bus_type`
/// a [`BusType`][crate::BusType]
/// ## `cancellable`
/// a [`Cancellable`][crate::Cancellable] or [`None`]
/// ## `callback`
/// a `GAsyncReadyCallback` to call when the request is satisfied
#[doc(alias = "g_bus_get")]
pub fn bus_get<
    P: IsA<Cancellable>,
    Q: FnOnce(Result<DBusConnection, glib::Error>) + Send + 'static,
>(
    bus_type: BusType,
    cancellable: Option<&P>,
    callback: Q,
) {
    let user_data: Box_<Q> = Box_::new(callback);
    unsafe extern "C" fn bus_get_trampoline<
        Q: FnOnce(Result<DBusConnection, glib::Error>) + Send + 'static,
    >(
        _source_object: *mut glib::gobject_ffi::GObject,
        res: *mut crate::ffi::GAsyncResult,
        user_data: glib::ffi::gpointer,
    ) {
        let mut error = ptr::null_mut();
        let ret = ffi::g_bus_get_finish(res, &mut error);
        let result = if error.is_null() {
            Ok(from_glib_full(ret))
        } else {
            Err(from_glib_full(error))
        };
        let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
        callback(result);
    }
    let callback = bus_get_trampoline::<Q>;
    unsafe {
        ffi::g_bus_get(
            bus_type.into_glib(),
            cancellable.map(|p| p.as_ref()).to_glib_none().0,
            Some(callback),
            Box_::into_raw(user_data) as *mut _,
        );
    }
}

pub fn bus_get_future(
    bus_type: BusType,
) -> Pin<Box_<dyn std::future::Future<Output = Result<DBusConnection, glib::Error>> + 'static>> {
    Box_::pin(crate::GioFuture::new(
        &(),
        move |_obj, cancellable, send| {
            bus_get(bus_type, Some(cancellable), move |res| {
                send.resolve(res);
            });
        },
    ))
}

/// Synchronously connects to the message bus specified by `bus_type`.
/// Note that the returned object may shared with other callers,
/// e.g. if two separate parts of a process calls this function with
/// the same `bus_type`, they will share the same object.
///
/// This is a synchronous failable function. See [`bus_get()`][crate::bus_get()] and
/// `g_bus_get_finish()` for the asynchronous version.
///
/// The returned object is a singleton, that is, shared with other
/// callers of [`bus_get()`][crate::bus_get()] and [`bus_get_sync()`][crate::bus_get_sync()] for `bus_type`. In the
/// event that you need a private message bus connection, use
/// [`dbus_address_get_for_bus_sync()`][crate::dbus_address_get_for_bus_sync()] and
/// [`DBusConnection::for_address()`][crate::DBusConnection::for_address()].
///
/// Note that the returned [`DBusConnection`][crate::DBusConnection] object will (usually) have
/// the `property::DBusConnection::exit-on-close` property set to [`true`].
/// ## `bus_type`
/// a [`BusType`][crate::BusType]
/// ## `cancellable`
/// a [`Cancellable`][crate::Cancellable] or [`None`]
///
/// # Returns
///
/// a [`DBusConnection`][crate::DBusConnection] or [`None`] if `error` is set.
///  Free with `g_object_unref()`.
#[doc(alias = "g_bus_get_sync")]
pub fn bus_get_sync<P: IsA<Cancellable>>(
    bus_type: BusType,
    cancellable: Option<&P>,
) -> Result<DBusConnection, glib::Error> {
    unsafe {
        let mut error = ptr::null_mut();
        let ret = ffi::g_bus_get_sync(
            bus_type.into_glib(),
            cancellable.map(|p| p.as_ref()).to_glib_none().0,
            &mut error,
        );
        if error.is_null() {
            Ok(from_glib_full(ret))
        } else {
            Err(from_glib_full(error))
        }
    }
}

//#[doc(alias = "g_bus_own_name")]
//pub fn bus_own_name(bus_type: BusType, name: &str, flags: BusNameOwnerFlags, bus_acquired_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>, name_acquired_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>, name_lost_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>) -> u32 {
//    unsafe { TODO: call ffi:g_bus_own_name() }
//}

//#[doc(alias = "g_bus_own_name_on_connection")]
//pub fn bus_own_name_on_connection(connection: &DBusConnection, name: &str, flags: BusNameOwnerFlags, name_acquired_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>, name_lost_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>) -> u32 {
//    unsafe { TODO: call ffi:g_bus_own_name_on_connection() }
//}

//#[doc(alias = "g_bus_watch_name")]
//pub fn bus_watch_name(bus_type: BusType, name: &str, flags: BusNameWatcherFlags, name_appeared_handler: Option<Box_<dyn Fn(&DBusConnection, &str, &str) + 'static>>, name_vanished_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>) -> u32 {
//    unsafe { TODO: call ffi:g_bus_watch_name() }
//}

//#[doc(alias = "g_bus_watch_name_on_connection")]
//pub fn bus_watch_name_on_connection(connection: &DBusConnection, name: &str, flags: BusNameWatcherFlags, name_appeared_handler: Option<Box_<dyn Fn(&DBusConnection, &str, &str) + 'static>>, name_vanished_handler: Option<Box_<dyn Fn(&DBusConnection, &str) + 'static>>) -> u32 {
//    unsafe { TODO: call ffi:g_bus_watch_name_on_connection() }
//}

/// Checks if a content type can be executable. Note that for instance
/// things like text files can be executables (i.e. scripts and batch files).
/// ## `type_`
/// a content type string
///
/// # Returns
///
/// [`true`] if the file type corresponds to a type that
///  can be executable, [`false`] otherwise.
#[doc(alias = "g_content_type_can_be_executable")]
pub fn content_type_can_be_executable(type_: &str) -> bool {
    unsafe {
        from_glib(ffi::g_content_type_can_be_executable(
            type_.to_glib_none().0,
        ))
    }
}

/// Compares two content types for equality.
/// ## `type1`
/// a content type string
/// ## `type2`
/// a content type string
///
/// # Returns
///
/// [`true`] if the two strings are identical or equivalent,
///  [`false`] otherwise.
#[doc(alias = "g_content_type_equals")]
pub fn content_type_equals(type1: &str, type2: &str) -> bool {
    unsafe {
        from_glib(ffi::g_content_type_equals(
            type1.to_glib_none().0,
            type2.to_glib_none().0,
        ))
    }
}

/// Tries to find a content type based on the mime type name.
/// ## `mime_type`
/// a mime type string
///
/// # Returns
///
/// Newly allocated string with content type or
///  [`None`]. Free with `g_free()`
#[doc(alias = "g_content_type_from_mime_type")]
pub fn content_type_from_mime_type(mime_type: &str) -> Option<glib::GString> {
    unsafe {
        from_glib_full(ffi::g_content_type_from_mime_type(
            mime_type.to_glib_none().0,
        ))
    }
}

/// Gets the human readable description of the content type.
/// ## `type_`
/// a content type string
///
/// # Returns
///
/// a short description of the content type `type_`. Free the
///  returned string with `g_free()`
#[doc(alias = "g_content_type_get_description")]
pub fn content_type_get_description(type_: &str) -> glib::GString {
    unsafe { from_glib_full(ffi::g_content_type_get_description(type_.to_glib_none().0)) }
}

/// Gets the generic icon name for a content type.
///
/// See the
/// [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
/// specification for more on the generic icon name.
/// ## `type_`
/// a content type string
///
/// # Returns
///
/// the registered generic icon name for the given `type_`,
///  or [`None`] if unknown. Free with `g_free()`
#[doc(alias = "g_content_type_get_generic_icon_name")]
pub fn content_type_get_generic_icon_name(type_: &str) -> Option<glib::GString> {
    unsafe {
        from_glib_full(ffi::g_content_type_get_generic_icon_name(
            type_.to_glib_none().0,
        ))
    }
}

/// Gets the icon for a content type.
/// ## `type_`
/// a content type string
///
/// # Returns
///
/// [`Icon`][crate::Icon] corresponding to the content type. Free the returned
///  object with `g_object_unref()`
#[doc(alias = "g_content_type_get_icon")]
pub fn content_type_get_icon(type_: &str) -> Icon {
    unsafe { from_glib_full(ffi::g_content_type_get_icon(type_.to_glib_none().0)) }
}

/// Get the list of directories which MIME data is loaded from. See
/// [`content_type_set_mime_dirs()`][crate::content_type_set_mime_dirs()] for details.
///
/// # Returns
///
/// [`None`]-terminated list of
///  directories to load MIME data from, including any `mime/` subdirectory,
///  and with the first directory to try listed first
#[cfg(any(feature = "v2_60", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
#[doc(alias = "g_content_type_get_mime_dirs")]
pub fn content_type_get_mime_dirs() -> Vec<glib::GString> {
    unsafe { FromGlibPtrContainer::from_glib_none(ffi::g_content_type_get_mime_dirs()) }
}

/// Gets the mime type for the content type, if one is registered.
/// ## `type_`
/// a content type string
///
/// # Returns
///
/// the registered mime type for the
///  given `type_`, or [`None`] if unknown; free with `g_free()`.
#[doc(alias = "g_content_type_get_mime_type")]
pub fn content_type_get_mime_type(type_: &str) -> Option<glib::GString> {
    unsafe { from_glib_full(ffi::g_content_type_get_mime_type(type_.to_glib_none().0)) }
}

/// Gets the symbolic icon for a content type.
/// ## `type_`
/// a content type string
///
/// # Returns
///
/// symbolic [`Icon`][crate::Icon] corresponding to the content type.
///  Free the returned object with `g_object_unref()`
#[doc(alias = "g_content_type_get_symbolic_icon")]
pub fn content_type_get_symbolic_icon(type_: &str) -> Icon {
    unsafe {
        from_glib_full(ffi::g_content_type_get_symbolic_icon(
            type_.to_glib_none().0,
        ))
    }
}

/// Guesses the content type based on example data. If the function is
/// uncertain, `result_uncertain` will be set to [`true`]. Either `filename`
/// or `data` may be [`None`], in which case the guess will be based solely
/// on the other argument.
/// ## `filename`
/// a string, or [`None`]
/// ## `data`
/// a stream of data, or [`None`]
///
/// # Returns
///
/// a string indicating a guessed content type for the
///  given data. Free with `g_free()`
///
/// ## `result_uncertain`
/// return location for the certainty
///  of the result, or [`None`]
#[doc(alias = "g_content_type_guess")]
pub fn content_type_guess(filename: Option<&str>, data: &[u8]) -> (glib::GString, bool) {
    let data_size = data.len() as usize;
    unsafe {
        let mut result_uncertain = mem::MaybeUninit::uninit();
        let ret = from_glib_full(ffi::g_content_type_guess(
            filename.to_glib_none().0,
            data.to_glib_none().0,
            data_size,
            result_uncertain.as_mut_ptr(),
        ));
        let result_uncertain = result_uncertain.assume_init();
        (ret, from_glib(result_uncertain))
    }
}

/// Tries to guess the type of the tree with root `root`, by
/// looking at the files it contains. The result is an array
/// of content types, with the best guess coming first.
///
/// The types returned all have the form x-content/foo, e.g.
/// x-content/audio-cdda (for audio CDs) or x-content/image-dcf
/// (for a camera memory card). See the
/// [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
/// specification for more on x-content types.
///
/// This function is useful in the implementation of
/// [`MountExt::guess_content_type()`][crate::prelude::MountExt::guess_content_type()].
/// ## `root`
/// the root of the tree to guess a type for
///
/// # Returns
///
/// an [`None`]-terminated
///  array of zero or more content types. Free with `g_strfreev()`
#[doc(alias = "g_content_type_guess_for_tree")]
pub fn content_type_guess_for_tree<P: IsA<File>>(root: &P) -> Vec<glib::GString> {
    unsafe {
        FromGlibPtrContainer::from_glib_full(ffi::g_content_type_guess_for_tree(
            root.as_ref().to_glib_none().0,
        ))
    }
}

/// Determines if `type_` is a subset of `supertype`.
/// ## `type_`
/// a content type string
/// ## `supertype`
/// a content type string
///
/// # Returns
///
/// [`true`] if `type_` is a kind of `supertype`,
///  [`false`] otherwise.
#[doc(alias = "g_content_type_is_a")]
pub fn content_type_is_a(type_: &str, supertype: &str) -> bool {
    unsafe {
        from_glib(ffi::g_content_type_is_a(
            type_.to_glib_none().0,
            supertype.to_glib_none().0,
        ))
    }
}

/// Determines if `type_` is a subset of `mime_type`.
/// Convenience wrapper around [`content_type_is_a()`][crate::content_type_is_a()].
/// ## `type_`
/// a content type string
/// ## `mime_type`
/// a mime type string
///
/// # Returns
///
/// [`true`] if `type_` is a kind of `mime_type`,
///  [`false`] otherwise.
#[cfg(any(feature = "v2_52", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_52")))]
#[doc(alias = "g_content_type_is_mime_type")]
pub fn content_type_is_mime_type(type_: &str, mime_type: &str) -> bool {
    unsafe {
        from_glib(ffi::g_content_type_is_mime_type(
            type_.to_glib_none().0,
            mime_type.to_glib_none().0,
        ))
    }
}

/// Checks if the content type is the generic "unknown" type.
/// On UNIX this is the "application/octet-stream" mimetype,
/// while on win32 it is "*" and on OSX it is a dynamic type
/// or octet-stream.
/// ## `type_`
/// a content type string
///
/// # Returns
///
/// [`true`] if the type is the unknown type.
#[doc(alias = "g_content_type_is_unknown")]
pub fn content_type_is_unknown(type_: &str) -> bool {
    unsafe { from_glib(ffi::g_content_type_is_unknown(type_.to_glib_none().0)) }
}

/// Set the list of directories used by GIO to load the MIME database.
/// If `dirs` is [`None`], the directories used are the default:
///
///  - the `mime` subdirectory of the directory in `$XDG_DATA_HOME`
///  - the `mime` subdirectory of every directory in `$XDG_DATA_DIRS`
///
/// This function is intended to be used when writing tests that depend on
/// information stored in the MIME database, in order to control the data.
///
/// Typically, in case your tests use `G_TEST_OPTION_ISOLATE_DIRS`, but they
/// depend on the system’s MIME database, you should call this function
/// with `dirs` set to [`None`] before calling `g_test_init()`, for instance:
///
///
///
/// **⚠️ The following code is in C ⚠️**
///
/// ```C
///   // Load MIME data from the system
///   g_content_type_set_mime_dirs (NULL);
///   // Isolate the environment
///   g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
///
///   …
///
///   return g_test_run ();
/// ```
/// ## `dirs`
/// [`None`]-terminated list of
///  directories to load MIME data from, including any `mime/` subdirectory,
///  and with the first directory to try listed first
#[cfg(any(feature = "v2_60", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
#[doc(alias = "g_content_type_set_mime_dirs")]
pub fn content_type_set_mime_dirs(dirs: &[&str]) {
    unsafe {
        ffi::g_content_type_set_mime_dirs(dirs.to_glib_none().0);
    }
}

/// Gets a list of strings containing all the registered content types
/// known to the system. The list and its data should be freed using
/// `g_list_free_full (list, g_free)`.
///
/// # Returns
///
/// list of the registered
///  content types
#[doc(alias = "g_content_types_get_registered")]
pub fn content_types_get_registered() -> Vec<glib::GString> {
    unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_content_types_get_registered()) }
}

/// Escape `string` so it can appear in a D-Bus address as the value
/// part of a key-value pair.
///
/// For instance, if `string` is `/run/bus-for-:0`,
/// this function would return `/run/bus-for-`3A0``,
/// which could be used in a D-Bus address like
/// `unix:nonce-tcp:host=127.0.0.1,port=42,noncefile=/run/bus-for-`3A0``.
/// ## `string`
/// an unescaped string to be included in a D-Bus address
///  as the value in a key-value pair
///
/// # Returns
///
/// a copy of `string` with all
///  non-optionally-escaped bytes escaped
#[doc(alias = "g_dbus_address_escape_value")]
pub fn dbus_address_escape_value(string: &str) -> glib::GString {
    unsafe { from_glib_full(ffi::g_dbus_address_escape_value(string.to_glib_none().0)) }
}

/// Synchronously looks up the D-Bus address for the well-known message
/// bus instance specified by `bus_type`. This may involve using various
/// platform specific mechanisms.
///
/// The returned address will be in the
/// [D-Bus address format](https://dbus.freedesktop.org/doc/dbus-specification.html`addresses`).
/// ## `bus_type`
/// a [`BusType`][crate::BusType]
/// ## `cancellable`
/// a [`Cancellable`][crate::Cancellable] or [`None`]
///
/// # Returns
///
/// a valid D-Bus address string for `bus_type` or
///  [`None`] if `error` is set
#[doc(alias = "g_dbus_address_get_for_bus_sync")]
pub fn dbus_address_get_for_bus_sync<P: IsA<Cancellable>>(
    bus_type: BusType,
    cancellable: Option<&P>,
) -> Result<glib::GString, glib::Error> {
    unsafe {
        let mut error = ptr::null_mut();
        let ret = ffi::g_dbus_address_get_for_bus_sync(
            bus_type.into_glib(),
            cancellable.map(|p| p.as_ref()).to_glib_none().0,
            &mut error,
        );
        if error.is_null() {
            Ok(from_glib_full(ret))
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Asynchronously connects to an endpoint specified by `address` and
/// sets up the connection so it is in a state to run the client-side
/// of the D-Bus authentication conversation. `address` must be in the
/// [D-Bus address format](https://dbus.freedesktop.org/doc/dbus-specification.html`addresses`).
///
/// When the operation is finished, `callback` will be invoked. You can
/// then call `g_dbus_address_get_stream_finish()` to get the result of
/// the operation.
///
/// This is an asynchronous failable function. See
/// [`dbus_address_get_stream_sync()`][crate::dbus_address_get_stream_sync()] for the synchronous version.
/// ## `address`
/// A valid D-Bus address.
/// ## `cancellable`
/// A [`Cancellable`][crate::Cancellable] or [`None`].
/// ## `callback`
/// A `GAsyncReadyCallback` to call when the request is satisfied.
#[doc(alias = "g_dbus_address_get_stream")]
pub fn dbus_address_get_stream<
    P: IsA<Cancellable>,
    Q: FnOnce(Result<(IOStream, Option<glib::GString>), glib::Error>) + Send + 'static,
>(
    address: &str,
    cancellable: Option<&P>,
    callback: Q,
) {
    let user_data: Box_<Q> = Box_::new(callback);
    unsafe extern "C" fn dbus_address_get_stream_trampoline<
        Q: FnOnce(Result<(IOStream, Option<glib::GString>), glib::Error>) + Send + 'static,
    >(
        _source_object: *mut glib::gobject_ffi::GObject,
        res: *mut crate::ffi::GAsyncResult,
        user_data: glib::ffi::gpointer,
    ) {
        let mut error = ptr::null_mut();
        let mut out_guid = ptr::null_mut();
        let ret = ffi::g_dbus_address_get_stream_finish(res, &mut out_guid, &mut error);
        let result = if error.is_null() {
            Ok((from_glib_full(ret), from_glib_full(out_guid)))
        } else {
            Err(from_glib_full(error))
        };
        let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
        callback(result);
    }
    let callback = dbus_address_get_stream_trampoline::<Q>;
    unsafe {
        ffi::g_dbus_address_get_stream(
            address.to_glib_none().0,
            cancellable.map(|p| p.as_ref()).to_glib_none().0,
            Some(callback),
            Box_::into_raw(user_data) as *mut _,
        );
    }
}

pub fn dbus_address_get_stream_future(
    address: &str,
) -> Pin<
    Box_<
        dyn std::future::Future<Output = Result<(IOStream, Option<glib::GString>), glib::Error>>
            + 'static,
    >,
> {
    let address = String::from(address);
    Box_::pin(crate::GioFuture::new(
        &(),
        move |_obj, cancellable, send| {
            dbus_address_get_stream(&address, Some(cancellable), move |res| {
                send.resolve(res);
            });
        },
    ))
}

/// Synchronously connects to an endpoint specified by `address` and
/// sets up the connection so it is in a state to run the client-side
/// of the D-Bus authentication conversation. `address` must be in the
/// [D-Bus address format](https://dbus.freedesktop.org/doc/dbus-specification.html`addresses`).
///
/// A server is not required to set a GUID, so `out_guid` may be set to [`None`]
/// even on success.
///
/// This is a synchronous failable function. See
/// [`dbus_address_get_stream()`][crate::dbus_address_get_stream()] for the asynchronous version.
/// ## `address`
/// A valid D-Bus address.
/// ## `cancellable`
/// A [`Cancellable`][crate::Cancellable] or [`None`].
///
/// # Returns
///
/// A [`IOStream`][crate::IOStream] or [`None`] if `error` is set.
///
/// ## `out_guid`
/// [`None`] or return location to store the GUID extracted from `address`, if any.
#[doc(alias = "g_dbus_address_get_stream_sync")]
pub fn dbus_address_get_stream_sync<P: IsA<Cancellable>>(
    address: &str,
    cancellable: Option<&P>,
) -> Result<(IOStream, Option<glib::GString>), glib::Error> {
    unsafe {
        let mut out_guid = ptr::null_mut();
        let mut error = ptr::null_mut();
        let ret = ffi::g_dbus_address_get_stream_sync(
            address.to_glib_none().0,
            &mut out_guid,
            cancellable.map(|p| p.as_ref()).to_glib_none().0,
            &mut error,
        );
        if error.is_null() {
            Ok((from_glib_full(ret), from_glib_full(out_guid)))
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Generate a D-Bus GUID that can be used with
/// e.g. [`DBusConnection::new()`][crate::DBusConnection::new()].
///
/// See the D-Bus specification regarding what strings are valid D-Bus
/// GUID (for example, D-Bus GUIDs are not RFC-4122 compliant).
///
/// # Returns
///
/// A valid D-Bus GUID. Free with `g_free()`.
#[doc(alias = "g_dbus_generate_guid")]
pub fn dbus_generate_guid() -> glib::GString {
    unsafe { from_glib_full(ffi::g_dbus_generate_guid()) }
}

/// Converts a [`glib::Value`][crate::glib::Value] to a [`glib::Variant`][crate::glib::Variant] of the type indicated by the `type_`
/// parameter.
///
/// The conversion is using the following rules:
///
/// - `G_TYPE_STRING`: 's', 'o', 'g' or 'ay'
/// - `G_TYPE_STRV`: 'as', 'ao' or 'aay'
/// - `G_TYPE_BOOLEAN`: 'b'
/// - `G_TYPE_UCHAR`: 'y'
/// - `G_TYPE_INT`: 'i', 'n'
/// - `G_TYPE_UINT`: 'u', 'q'
/// - `G_TYPE_INT64` 'x'
/// - `G_TYPE_UINT64`: 't'
/// - `G_TYPE_DOUBLE`: 'd'
/// - `G_TYPE_VARIANT`: Any [`glib::VariantType`][crate::glib::VariantType]
///
/// This can fail if e.g. `gvalue` is of type `G_TYPE_STRING` and `type_`
/// is ['i'][G-VARIANT-TYPE-INT32:CAPS]. It will also fail for any `GType`
/// (including e.g. `G_TYPE_OBJECT` and `G_TYPE_BOXED` derived-types) not
/// in the table above.
///
/// Note that if `gvalue` is of type `G_TYPE_VARIANT` and its value is
/// [`None`], the empty [`glib::Variant`][crate::glib::Variant] instance (never [`None`]) for `type_` is
/// returned (e.g. 0 for scalar types, the empty string for string types,
/// '/' for object path types, the empty array for any array type and so on).
///
/// See the [`dbus_gvariant_to_gvalue()`][crate::dbus_gvariant_to_gvalue()] function for how to convert a
/// [`glib::Variant`][crate::glib::Variant] to a [`glib::Value`][crate::glib::Value].
/// ## `gvalue`
/// A [`glib::Value`][crate::glib::Value] to convert to a [`glib::Variant`][crate::glib::Variant]
/// ## `type_`
/// A [`glib::VariantType`][crate::glib::VariantType]
///
/// # Returns
///
/// A [`glib::Variant`][crate::glib::Variant] (never floating) of
///  [`glib::VariantType`][crate::glib::VariantType] `type_` holding the data from `gvalue` or an empty [`glib::Variant`][crate::glib::Variant]
///  in case of failure. Free with `g_variant_unref()`.
#[doc(alias = "g_dbus_gvalue_to_gvariant")]
pub fn dbus_gvalue_to_gvariant(gvalue: &glib::Value, type_: &glib::VariantTy) -> glib::Variant {
    unsafe {
        from_glib_full(ffi::g_dbus_gvalue_to_gvariant(
            gvalue.to_glib_none().0,
            type_.to_glib_none().0,
        ))
    }
}

/// Converts a [`glib::Variant`][crate::glib::Variant] to a [`glib::Value`][crate::glib::Value]. If `value` is floating, it is consumed.
///
/// The rules specified in the [`dbus_gvalue_to_gvariant()`][crate::dbus_gvalue_to_gvariant()] function are
/// used - this function is essentially its reverse form. So, a [`glib::Variant`][crate::glib::Variant]
/// containing any basic or string array type will be converted to a [`glib::Value`][crate::glib::Value]
/// containing a basic value or string array. Any other [`glib::Variant`][crate::glib::Variant] (handle,
/// variant, tuple, dict entry) will be converted to a [`glib::Value`][crate::glib::Value] containing that
/// [`glib::Variant`][crate::glib::Variant].
///
/// The conversion never fails - a valid [`glib::Value`][crate::glib::Value] is always returned in
/// `out_gvalue`.
/// ## `value`
/// A [`glib::Variant`][crate::glib::Variant].
///
/// # Returns
///
///
/// ## `out_gvalue`
/// Return location pointing to a zero-filled (uninitialized) [`glib::Value`][crate::glib::Value].
#[doc(alias = "g_dbus_gvariant_to_gvalue")]
pub fn dbus_gvariant_to_gvalue(value: &glib::Variant) -> glib::Value {
    unsafe {
        let mut out_gvalue = glib::Value::uninitialized();
        ffi::g_dbus_gvariant_to_gvalue(value.to_glib_none().0, out_gvalue.to_glib_none_mut().0);
        out_gvalue
    }
}

/// Checks if `string` is a
/// [D-Bus address](https://dbus.freedesktop.org/doc/dbus-specification.html`addresses`).
///
/// This doesn't check if `string` is actually supported by [`DBusServer`][crate::DBusServer]
/// or [`DBusConnection`][crate::DBusConnection] - use [`dbus_is_supported_address()`][crate::dbus_is_supported_address()] to do more
/// checks.
/// ## `string`
/// A string.
///
/// # Returns
///
/// [`true`] if `string` is a valid D-Bus address, [`false`] otherwise.
#[doc(alias = "g_dbus_is_address")]
pub fn dbus_is_address(string: &str) -> bool {
    unsafe { from_glib(ffi::g_dbus_is_address(string.to_glib_none().0)) }
}

/// Checks if `string` is a D-Bus GUID.
///
/// See the D-Bus specification regarding what strings are valid D-Bus
/// GUID (for example, D-Bus GUIDs are not RFC-4122 compliant).
/// ## `string`
/// The string to check.
///
/// # Returns
///
/// [`true`] if `string` is a guid, [`false`] otherwise.
#[doc(alias = "g_dbus_is_guid")]
pub fn dbus_is_guid(string: &str) -> bool {
    unsafe { from_glib(ffi::g_dbus_is_guid(string.to_glib_none().0)) }
}

/// Checks if `string` is a valid D-Bus interface name.
/// ## `string`
/// The string to check.
///
/// # Returns
///
/// [`true`] if valid, [`false`] otherwise.
#[doc(alias = "g_dbus_is_interface_name")]
pub fn dbus_is_interface_name(string: &str) -> bool {
    unsafe { from_glib(ffi::g_dbus_is_interface_name(string.to_glib_none().0)) }
}

/// Checks if `string` is a valid D-Bus member (e.g. signal or method) name.
/// ## `string`
/// The string to check.
///
/// # Returns
///
/// [`true`] if valid, [`false`] otherwise.
#[doc(alias = "g_dbus_is_member_name")]
pub fn dbus_is_member_name(string: &str) -> bool {
    unsafe { from_glib(ffi::g_dbus_is_member_name(string.to_glib_none().0)) }
}

/// Checks if `string` is a valid D-Bus bus name (either unique or well-known).
/// ## `string`
/// The string to check.
///
/// # Returns
///
/// [`true`] if valid, [`false`] otherwise.
#[doc(alias = "g_dbus_is_name")]
pub fn dbus_is_name(string: &str) -> bool {
    unsafe { from_glib(ffi::g_dbus_is_name(string.to_glib_none().0)) }
}

/// Like [`dbus_is_address()`][crate::dbus_is_address()] but also checks if the library supports the
/// transports in `string` and that key/value pairs for each transport
/// are valid. See the specification of the
/// [D-Bus address format](https://dbus.freedesktop.org/doc/dbus-specification.html`addresses`).
/// ## `string`
/// A string.
///
/// # Returns
///
/// [`true`] if `string` is a valid D-Bus address that is
/// supported by this library, [`false`] if `error` is set.
#[doc(alias = "g_dbus_is_supported_address")]
pub fn dbus_is_supported_address(string: &str) -> Result<(), glib::Error> {
    unsafe {
        let mut error = ptr::null_mut();
        let _ = ffi::g_dbus_is_supported_address(string.to_glib_none().0, &mut error);
        if error.is_null() {
            Ok(())
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Checks if `string` is a valid D-Bus unique bus name.
/// ## `string`
/// The string to check.
///
/// # Returns
///
/// [`true`] if valid, [`false`] otherwise.
#[doc(alias = "g_dbus_is_unique_name")]
pub fn dbus_is_unique_name(string: &str) -> bool {
    unsafe { from_glib(ffi::g_dbus_is_unique_name(string.to_glib_none().0)) }
}

/// Converts errno.h error codes into GIO error codes. The fallback
/// value [`IOErrorEnum::Failed`][crate::IOErrorEnum::Failed] is returned for error codes not currently
/// handled (but note that future GLib releases may return a more
/// specific value instead).
///
/// As `errno` is global and may be modified by intermediate function
/// calls, you should save its value as soon as the call which sets it
/// ## `err_no`
/// Error number as defined in errno.h.
///
/// # Returns
///
/// [`IOErrorEnum`][crate::IOErrorEnum] value for the given errno.h error number.
#[doc(alias = "g_io_error_from_errno")]
pub fn io_error_from_errno(err_no: i32) -> IOErrorEnum {
    unsafe { from_glib(ffi::g_io_error_from_errno(err_no)) }
}

//#[doc(alias = "g_io_modules_load_all_in_directory")]
//pub fn io_modules_load_all_in_directory<P: AsRef<std::path::Path>>(dirname: P) -> /*Ignored*/Vec<IOModule> {
//    unsafe { TODO: call ffi:g_io_modules_load_all_in_directory() }
//}

//#[doc(alias = "g_io_modules_load_all_in_directory_with_scope")]
//pub fn io_modules_load_all_in_directory_with_scope<P: AsRef<std::path::Path>>(dirname: P, scope: /*Ignored*/&mut IOModuleScope) -> /*Ignored*/Vec<IOModule> {
//    unsafe { TODO: call ffi:g_io_modules_load_all_in_directory_with_scope() }
//}

/// Scans all the modules in the specified directory, ensuring that
/// any extension point implemented by a module is registered.
///
/// This may not actually load and initialize all the types in each
/// module, some modules may be lazily loaded and initialized when
/// an extension point it implements is used with e.g.
/// `g_io_extension_point_get_extensions()` or
/// `g_io_extension_point_get_extension_by_name()`.
///
/// If you need to guarantee that all types are loaded in all the modules,
/// use `g_io_modules_load_all_in_directory()`.
/// ## `dirname`
/// pathname for a directory containing modules
///  to scan.
#[doc(alias = "g_io_modules_scan_all_in_directory")]
pub fn io_modules_scan_all_in_directory<P: AsRef<std::path::Path>>(dirname: P) {
    unsafe {
        ffi::g_io_modules_scan_all_in_directory(dirname.as_ref().to_glib_none().0);
    }
}

//#[doc(alias = "g_io_modules_scan_all_in_directory_with_scope")]
//pub fn io_modules_scan_all_in_directory_with_scope<P: AsRef<std::path::Path>>(dirname: P, scope: /*Ignored*/&mut IOModuleScope) {
//    unsafe { TODO: call ffi:g_io_modules_scan_all_in_directory_with_scope() }
//}

/// Cancels all cancellable I/O jobs.
///
/// A job is cancellable if a [`Cancellable`][crate::Cancellable] was passed into
/// `g_io_scheduler_push_job()`.
///
/// # Deprecated
///
/// You should never call this function, since you don't
/// know how other libraries in your program might be making use of
/// gioscheduler.
#[doc(alias = "g_io_scheduler_cancel_all_jobs")]
pub fn io_scheduler_cancel_all_jobs() {
    unsafe {
        ffi::g_io_scheduler_cancel_all_jobs();
    }
}

//#[doc(alias = "g_io_scheduler_push_job")]
//pub fn io_scheduler_push_job<P: IsA<Cancellable>>(job_func: /*Unimplemented*/Fn(/*Ignored*/IOSchedulerJob, Option<&Cancellable>) -> bool, user_data: /*Unimplemented*/Option<Fundamental: Pointer>, io_priority: i32, cancellable: Option<&P>) {
//    unsafe { TODO: call ffi:g_io_scheduler_push_job() }
//}

/// Creates a keyfile-backed [`SettingsBackend`][crate::SettingsBackend].
///
/// The filename of the keyfile to use is given by `filename`.
///
/// All settings read to or written from the backend must fall under the
/// path given in `root_path` (which must start and end with a slash and
/// not contain two consecutive slashes). `root_path` may be "/".
///
/// If `root_group` is non-[`None`] then it specifies the name of the keyfile
/// group used for keys that are written directly below `root_path`. For
/// example, if `root_path` is "/apps/example/" and `root_group` is
/// "toplevel", then settings the key "/apps/example/enabled" to a value
/// of [`true`] will cause the following to appear in the keyfile:
///
///
/// ```text
///   [toplevel]
///   enabled=true
/// ```
///
/// If `root_group` is [`None`] then it is not permitted to store keys
/// directly below the `root_path`.
///
/// For keys not stored directly below `root_path` (ie: in a sub-path),
/// the name of the subpath (with the final slash stripped) is used as
/// the name of the keyfile group. To continue the example, if
/// "/apps/example/profiles/default/font-size" were set to
/// 12 then the following would appear in the keyfile:
///
///
/// ```text
///   [profiles/default]
///   font-size=12
/// ```
///
/// The backend will refuse writes (and return writability as being
/// [`false`]) for keys outside of `root_path` and, in the event that
/// `root_group` is [`None`], also for keys directly under `root_path`.
/// Writes will also be refused if the backend detects that it has the
/// inability to rewrite the keyfile (ie: the containing directory is not
/// writable).
///
/// There is no checking done for your key namespace clashing with the
/// syntax of the key file format. For example, if you have '[' or ']'
/// characters in your path names or '=' in your key names you may be in
/// trouble.
///
/// The backend reads default values from a keyfile called `defaults` in
/// the directory specified by the `GKeyfileSettingsBackend:defaults-dir` property,
/// and a list of locked keys from a text file with the name `locks` in
/// the same location.
/// ## `filename`
/// the filename of the keyfile
/// ## `root_path`
/// the path under which all settings keys appear
/// ## `root_group`
/// the group name corresponding to
///  `root_path`, or [`None`]
///
/// # Returns
///
/// a keyfile-backed [`SettingsBackend`][crate::SettingsBackend]
#[doc(alias = "g_keyfile_settings_backend_new")]
pub fn keyfile_settings_backend_new(
    filename: &str,
    root_path: &str,
    root_group: Option<&str>,
) -> SettingsBackend {
    unsafe {
        from_glib_full(ffi::g_keyfile_settings_backend_new(
            filename.to_glib_none().0,
            root_path.to_glib_none().0,
            root_group.to_glib_none().0,
        ))
    }
}

/// Creates a memory-backed [`SettingsBackend`][crate::SettingsBackend].
///
/// This backend allows changes to settings, but does not write them
/// to any backing storage, so the next time you run your application,
/// the memory backend will start out with the default values again.
///
/// # Returns
///
/// a newly created [`SettingsBackend`][crate::SettingsBackend]
#[doc(alias = "g_memory_settings_backend_new")]
pub fn memory_settings_backend_new() -> SettingsBackend {
    unsafe { from_glib_full(ffi::g_memory_settings_backend_new()) }
}

/// Initializes the platform networking libraries (eg, on Windows, this
/// calls WSAStartup()). GLib will call this itself if it is needed, so
/// you only need to call it if you directly call system networking
/// functions (without calling any GLib networking functions first).
#[doc(alias = "g_networking_init")]
pub fn networking_init() {
    unsafe {
        ffi::g_networking_init();
    }
}

/// Creates a readonly [`SettingsBackend`][crate::SettingsBackend].
///
/// This backend does not allow changes to settings, so all settings
/// will always have their default values.
///
/// # Returns
///
/// a newly created [`SettingsBackend`][crate::SettingsBackend]
#[doc(alias = "g_null_settings_backend_new")]
pub fn null_settings_backend_new() -> SettingsBackend {
    unsafe { from_glib_full(ffi::g_null_settings_backend_new()) }
}

/// Returns all the names of children at the specified `path` in the set of
/// globally registered resources.
/// The return result is a [`None`] terminated list of strings which should
/// be released with `g_strfreev()`.
///
/// `lookup_flags` controls the behaviour of the lookup.
/// ## `path`
/// A pathname inside the resource
/// ## `lookup_flags`
/// A [`ResourceLookupFlags`][crate::ResourceLookupFlags]
///
/// # Returns
///
/// an array of constant strings
#[doc(alias = "g_resources_enumerate_children")]
pub fn resources_enumerate_children(
    path: &str,
    lookup_flags: ResourceLookupFlags,
) -> Result<Vec<glib::GString>, glib::Error> {
    unsafe {
        let mut error = ptr::null_mut();
        let ret = ffi::g_resources_enumerate_children(
            path.to_glib_none().0,
            lookup_flags.into_glib(),
            &mut error,
        );
        if error.is_null() {
            Ok(FromGlibPtrContainer::from_glib_full(ret))
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Looks for a file at the specified `path` in the set of
/// globally registered resources and if found returns information about it.
///
/// `lookup_flags` controls the behaviour of the lookup.
/// ## `path`
/// A pathname inside the resource
/// ## `lookup_flags`
/// A [`ResourceLookupFlags`][crate::ResourceLookupFlags]
///
/// # Returns
///
/// [`true`] if the file was found. [`false`] if there were errors
///
/// ## `size`
/// a location to place the length of the contents of the file,
///  or [`None`] if the length is not needed
///
/// ## `flags`
/// a location to place the `GResourceFlags` about the file,
///  or [`None`] if the flags are not needed
#[doc(alias = "g_resources_get_info")]
pub fn resources_get_info(
    path: &str,
    lookup_flags: ResourceLookupFlags,
) -> Result<(usize, u32), glib::Error> {
    unsafe {
        let mut size = mem::MaybeUninit::uninit();
        let mut flags = mem::MaybeUninit::uninit();
        let mut error = ptr::null_mut();
        let _ = ffi::g_resources_get_info(
            path.to_glib_none().0,
            lookup_flags.into_glib(),
            size.as_mut_ptr(),
            flags.as_mut_ptr(),
            &mut error,
        );
        let size = size.assume_init();
        let flags = flags.assume_init();
        if error.is_null() {
            Ok((size, flags))
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Looks for a file at the specified `path` in the set of
/// globally registered resources and returns a [`glib::Bytes`][crate::glib::Bytes] that
/// lets you directly access the data in memory.
///
/// The data is always followed by a zero byte, so you
/// can safely use the data as a C string. However, that byte
/// is not included in the size of the GBytes.
///
/// For uncompressed resource files this is a pointer directly into
/// the resource bundle, which is typically in some readonly data section
/// in the program binary. For compressed files we allocate memory on
/// the heap and automatically uncompress the data.
///
/// `lookup_flags` controls the behaviour of the lookup.
/// ## `path`
/// A pathname inside the resource
/// ## `lookup_flags`
/// A [`ResourceLookupFlags`][crate::ResourceLookupFlags]
///
/// # Returns
///
/// [`glib::Bytes`][crate::glib::Bytes] or [`None`] on error.
///  Free the returned object with `g_bytes_unref()`
#[doc(alias = "g_resources_lookup_data")]
pub fn resources_lookup_data(
    path: &str,
    lookup_flags: ResourceLookupFlags,
) -> Result<glib::Bytes, glib::Error> {
    unsafe {
        let mut error = ptr::null_mut();
        let ret = ffi::g_resources_lookup_data(
            path.to_glib_none().0,
            lookup_flags.into_glib(),
            &mut error,
        );
        if error.is_null() {
            Ok(from_glib_full(ret))
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Looks for a file at the specified `path` in the set of
/// globally registered resources and returns a [`InputStream`][crate::InputStream]
/// that lets you read the data.
///
/// `lookup_flags` controls the behaviour of the lookup.
/// ## `path`
/// A pathname inside the resource
/// ## `lookup_flags`
/// A [`ResourceLookupFlags`][crate::ResourceLookupFlags]
///
/// # Returns
///
/// [`InputStream`][crate::InputStream] or [`None`] on error.
///  Free the returned object with `g_object_unref()`
#[doc(alias = "g_resources_open_stream")]
pub fn resources_open_stream(
    path: &str,
    lookup_flags: ResourceLookupFlags,
) -> Result<InputStream, glib::Error> {
    unsafe {
        let mut error = ptr::null_mut();
        let ret = ffi::g_resources_open_stream(
            path.to_glib_none().0,
            lookup_flags.into_glib(),
            &mut error,
        );
        if error.is_null() {
            Ok(from_glib_full(ret))
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Registers the resource with the process-global set of resources.
/// Once a resource is registered the files in it can be accessed
/// with the global resource lookup functions like [`resources_lookup_data()`][crate::resources_lookup_data()].
/// ## `resource`
/// A [`Resource`][crate::Resource]
#[doc(alias = "g_resources_register")]
pub fn resources_register(resource: &Resource) {
    unsafe {
        ffi::g_resources_register(resource.to_glib_none().0);
    }
}

/// Unregisters the resource from the process-global set of resources.
/// ## `resource`
/// A [`Resource`][crate::Resource]
#[doc(alias = "g_resources_unregister")]
pub fn resources_unregister(resource: &Resource) {
    unsafe {
        ffi::g_resources_unregister(resource.to_glib_none().0);
    }
}

/// Determines if `mount_path` is considered an implementation of the
/// OS. This is primarily used for hiding mountable and mounted volumes
/// that only are used in the OS and has little to no relevance to the
/// casual user.
/// ## `mount_path`
/// a mount path, e.g. `/media/disk` or `/usr`
///
/// # Returns
///
/// [`true`] if `mount_path` is considered an implementation detail
///  of the OS.
#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[doc(alias = "g_unix_is_mount_path_system_internal")]
pub fn unix_is_mount_path_system_internal<P: AsRef<std::path::Path>>(mount_path: P) -> bool {
    unsafe {
        from_glib(ffi::g_unix_is_mount_path_system_internal(
            mount_path.as_ref().to_glib_none().0,
        ))
    }
}

/// Determines if `device_path` is considered a block device path which is only
/// used in implementation of the OS. This is primarily used for hiding
/// mounted volumes that are intended as APIs for programs to read, and system
/// administrators at a shell; rather than something that should, for example,
/// appear in a GUI. For example, the Linux `/proc` filesystem.
///
/// The list of device paths considered ‘system’ ones may change over time.
/// ## `device_path`
/// a device path, e.g. `/dev/loop0` or `nfsd`
///
/// # Returns
///
/// [`true`] if `device_path` is considered an implementation detail of
///  the OS.
#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[cfg(any(feature = "v2_56", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_56")))]
#[doc(alias = "g_unix_is_system_device_path")]
pub fn unix_is_system_device_path<P: AsRef<std::path::Path>>(device_path: P) -> bool {
    unsafe {
        from_glib(ffi::g_unix_is_system_device_path(
            device_path.as_ref().to_glib_none().0,
        ))
    }
}

/// Determines if `fs_type` is considered a type of file system which is only
/// used in implementation of the OS. This is primarily used for hiding
/// mounted volumes that are intended as APIs for programs to read, and system
/// administrators at a shell; rather than something that should, for example,
/// appear in a GUI. For example, the Linux `/proc` filesystem.
///
/// The list of file system types considered ‘system’ ones may change over time.
/// ## `fs_type`
/// a file system type, e.g. `procfs` or `tmpfs`
///
/// # Returns
///
/// [`true`] if `fs_type` is considered an implementation detail of the OS.
#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[cfg(any(feature = "v2_56", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_56")))]
#[doc(alias = "g_unix_is_system_fs_type")]
pub fn unix_is_system_fs_type(fs_type: &str) -> bool {
    unsafe { from_glib(ffi::g_unix_is_system_fs_type(fs_type.to_glib_none().0)) }
}