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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::{CollectionCreateFlags, CollectionFlags, Item, Service};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::{boxed::Box as Box_, pin::Pin};

glib::wrapper! {
    /// A proxy object representing a collection of secrets in the Secret Service.
    ///
    /// #SecretCollection represents a collection of secret items stored in the
    /// Secret Service.
    ///
    /// A collection can be in a locked or unlocked state. Use
    /// `SecretService::lock()` or `SecretService::unlock()` to lock or
    /// unlock the collection.
    ///
    /// Use the [`items`][struct@crate::SecretCollection#items] property or
    /// `SecretCollection::get_items()` to lookup the items in the collection.
    /// There may not be any items exposed when the collection is locked.
    ///
    /// ## Properties
    ///
    ///
    /// #### `created`
    ///  The date and time (in seconds since the UNIX epoch) that this
    /// collection was created.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `flags`
    ///  A set of flags describing which parts of the secret collection have
    /// been initialized.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `label`
    ///  The human readable label for the collection.
    ///
    /// Setting this property will result in the label of the collection being
    /// set asynchronously. To properly track the changing of the label use the
    /// [`CollectionExt::set_label()`][crate::prelude::CollectionExt::set_label()] function.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `locked`
    ///  Whether the collection is locked or not.
    ///
    /// To lock or unlock a collection use the [`ServiceExtManual::lock()`][crate::prelude::ServiceExtManual::lock()] or
    /// [`ServiceExtManual::unlock()`][crate::prelude::ServiceExtManual::unlock()] functions.
    ///
    /// Readable
    ///
    ///
    /// #### `modified`
    ///  The date and time (in seconds since the UNIX epoch) that this
    /// collection was last modified.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `service`
    ///  The [`Service`][crate::Service] object that this collection is associated with and
    /// uses to interact with the actual D-Bus Secret Service.
    ///
    /// Readable | Writeable | Construct Only
    /// <details><summary><h4>DBusProxy</h4></summary>
    ///
    ///
    /// #### `g-bus-type`
    ///  If this property is not `G_BUS_TYPE_NONE`, then
    /// #GDBusProxy:g-connection must be [`None`] and will be set to the
    /// #GDBusConnection obtained by calling g_bus_get() with the value
    /// of this property.
    ///
    /// Writeable | Construct Only
    ///
    ///
    /// #### `g-connection`
    ///  The #GDBusConnection the proxy is for.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `g-default-timeout`
    ///  The timeout to use if -1 (specifying default timeout) is passed
    /// as @timeout_msec in the g_dbus_proxy_call() and
    /// g_dbus_proxy_call_sync() functions.
    ///
    /// This allows applications to set a proxy-wide timeout for all
    /// remote method invocations on the proxy. If this property is -1,
    /// the default timeout (typically 25 seconds) is used. If set to
    /// `G_MAXINT`, then no timeout is used.
    ///
    /// Readable | Writeable | Construct
    ///
    ///
    /// #### `g-flags`
    ///  Flags from the #GDBusProxyFlags enumeration.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `g-interface-info`
    ///  Ensure that interactions with this proxy conform to the given
    /// interface. This is mainly to ensure that malformed data received
    /// from the other peer is ignored. The given #GDBusInterfaceInfo is
    /// said to be the "expected interface".
    ///
    /// The checks performed are:
    /// - When completing a method call, if the type signature of
    ///   the reply message isn't what's expected, the reply is
    ///   discarded and the #GError is set to `G_IO_ERROR_INVALID_ARGUMENT`.
    ///
    /// - Received signals that have a type signature mismatch are dropped and
    ///   a warning is logged via g_warning().
    ///
    /// - Properties received via the initial `GetAll()` call or via the
    ///   `::PropertiesChanged` signal (on the
    ///   [org.freedesktop.DBus.Properties](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties)
    ///   interface) or set using g_dbus_proxy_set_cached_property()
    ///   with a type signature mismatch are ignored and a warning is
    ///   logged via g_warning().
    ///
    /// Note that these checks are never done on methods, signals and
    /// properties that are not referenced in the given
    /// #GDBusInterfaceInfo, since extending a D-Bus interface on the
    /// service-side is not considered an ABI break.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `g-interface-name`
    ///  The D-Bus interface name the proxy is for.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `g-name`
    ///  The well-known or unique name that the proxy is for.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `g-name-owner`
    ///  The unique name that owns #GDBusProxy:g-name or [`None`] if no-one
    /// currently owns that name. You may connect to #GObject::notify signal to
    /// track changes to this property.
    ///
    /// Readable
    ///
    ///
    /// #### `g-object-path`
    ///  The object path the proxy is for.
    ///
    /// Readable | Writeable | Construct Only
    /// </details>
    ///
    /// # Implements
    ///
    /// [`CollectionExt`][trait@crate::prelude::CollectionExt], [`trait@gio::prelude::DBusProxyExt`], [`trait@gio::prelude::DBusInterfaceExt`], [`trait@gio::prelude::InitableExt`], [`CollectionExtManual`][trait@crate::prelude::CollectionExtManual]
    #[doc(alias = "SecretCollection")]
    pub struct Collection(Object<ffi::SecretCollection, ffi::SecretCollectionClass>) @extends gio::DBusProxy, @implements gio::DBusInterface, gio::Initable;

    match fn {
        type_ => || ffi::secret_collection_get_type(),
    }
}

impl Collection {
    pub const NONE: Option<&'static Collection> = None;

    /// Get a new collection proxy for a collection in the secret service.
    ///
    /// If @service is [`None`], then `get_sync()` will be called to get
    /// the default [`Service`][crate::Service] proxy.
    ///
    /// This method may block indefinitely and should not be used in user interface
    /// threads.
    /// ## `service`
    /// a secret service object
    /// ## `collection_path`
    /// the D-Bus path of the collection
    /// ## `flags`
    /// options for the collection initialization
    /// ## `cancellable`
    /// optional cancellation object
    ///
    /// # Returns
    ///
    /// the new collection, which should be unreferenced
    ///   with `GObject::Object::unref()`
    #[doc(alias = "secret_collection_new_for_dbus_path_sync")]
    #[doc(alias = "new_for_dbus_path_sync")]
    pub fn for_dbus_path_sync(
        service: Option<&impl IsA<Service>>,
        collection_path: &str,
        flags: CollectionFlags,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
    ) -> Result<Collection, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::secret_collection_new_for_dbus_path_sync(
                service.map(|p| p.as_ref()).to_glib_none().0,
                collection_path.to_glib_none().0,
                flags.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))
            }
        }
    }

    /// Create a new collection in the secret service.
    ///
    /// This method returns immediately and completes asynchronously. The secret
    /// service may prompt the user. [`ServiceExt::prompt()`][crate::prelude::ServiceExt::prompt()] will be used to handle
    /// any prompts that are required.
    ///
    /// An @alias is a well-known tag for a collection, such as 'default' (ie: the
    /// default collection to store items in). This allows other applications to
    /// easily identify and share a collection. If you specify an @alias, and a
    /// collection with that alias already exists, then a new collection will not
    /// be created. The previous one will be returned instead.
    ///
    /// If @service is [`None`], then `get()` will be called to get the
    /// default [`Service`][crate::Service] proxy.
    /// ## `service`
    /// a secret service object
    /// ## `label`
    /// label for the new collection
    /// ## `alias`
    /// alias to assign to the collection
    /// ## `flags`
    /// currently unused
    /// ## `cancellable`
    /// optional cancellation object
    /// ## `callback`
    /// called when the operation completes
    #[doc(alias = "secret_collection_create")]
    pub fn create<P: FnOnce(Result<Collection, glib::Error>) + 'static>(
        service: Option<&impl IsA<Service>>,
        label: &str,
        alias: Option<&str>,
        flags: CollectionCreateFlags,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
        callback: P,
    ) {
        let main_context = glib::MainContext::ref_thread_default();
        let is_main_context_owner = main_context.is_owner();
        let has_acquired_main_context = (!is_main_context_owner)
            .then(|| main_context.acquire().ok())
            .flatten();
        assert!(
            is_main_context_owner || has_acquired_main_context.is_some(),
            "Async operations only allowed if the thread is owning the MainContext"
        );

        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
        unsafe extern "C" fn create_trampoline<
            P: FnOnce(Result<Collection, glib::Error>) + 'static,
        >(
            _source_object: *mut glib::gobject_ffi::GObject,
            res: *mut gio::ffi::GAsyncResult,
            user_data: glib::ffi::gpointer,
        ) {
            let mut error = std::ptr::null_mut();
            let ret = ffi::secret_collection_create_finish(res, &mut error);
            let result = if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
                Box_::from_raw(user_data as *mut _);
            let callback: P = callback.into_inner();
            callback(result);
        }
        let callback = create_trampoline::<P>;
        unsafe {
            ffi::secret_collection_create(
                service.map(|p| p.as_ref()).to_glib_none().0,
                label.to_glib_none().0,
                alias.to_glib_none().0,
                flags.into_glib(),
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    pub fn create_future(
        service: Option<&(impl IsA<Service> + Clone + 'static)>,
        label: &str,
        alias: Option<&str>,
        flags: CollectionCreateFlags,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<Collection, glib::Error>> + 'static>>
    {
        let service = service.map(ToOwned::to_owned);
        let label = String::from(label);
        let alias = alias.map(ToOwned::to_owned);
        Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| {
            Self::create(
                service.as_ref().map(::std::borrow::Borrow::borrow),
                &label,
                alias.as_ref().map(::std::borrow::Borrow::borrow),
                flags,
                Some(cancellable),
                move |res| {
                    send.resolve(res);
                },
            );
        }))
    }

    /// Create a new collection in the secret service.
    ///
    /// This method may block indefinitely and should not be used in user interface
    /// threads. The secret service may prompt the user. [`ServiceExt::prompt()`][crate::prelude::ServiceExt::prompt()]
    /// will be used to handle any prompts that are required.
    ///
    /// An @alias is a well-known tag for a collection, such as `default` (ie: the
    /// default collection to store items in). This allows other applications to
    /// easily identify and share a collection. If you specify an @alias, and a
    /// collection with that alias already exists, then a new collection will not
    /// be created. The previous one will be returned instead.
    ///
    /// If @service is [`None`], then `get_sync()` will be called to get the
    /// default [`Service`][crate::Service] proxy.
    /// ## `service`
    /// a secret service object
    /// ## `label`
    /// label for the new collection
    /// ## `alias`
    /// alias to assign to the collection
    /// ## `flags`
    /// currently unused
    /// ## `cancellable`
    /// optional cancellation object
    ///
    /// # Returns
    ///
    /// the new collection, which should be unreferenced
    ///   with `GObject::Object::unref()`
    #[doc(alias = "secret_collection_create_sync")]
    pub fn create_sync(
        service: Option<&impl IsA<Service>>,
        label: &str,
        alias: Option<&str>,
        flags: CollectionCreateFlags,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
    ) -> Result<Collection, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::secret_collection_create_sync(
                service.map(|p| p.as_ref()).to_glib_none().0,
                label.to_glib_none().0,
                alias.to_glib_none().0,
                flags.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))
            }
        }
    }

    /// Lookup which collection is assigned to this alias. Aliases help determine
    /// well known collections, such as 'default'.
    ///
    /// If @service is [`None`], then `get()` will be called to get the
    /// default [`Service`][crate::Service] proxy.
    ///
    /// This method will return immediately and complete asynchronously.
    /// ## `service`
    /// a secret service object
    /// ## `alias`
    /// the alias to lookup
    /// ## `flags`
    /// options for the collection initialization
    /// ## `cancellable`
    /// optional cancellation object
    /// ## `callback`
    /// called when the operation completes
    #[doc(alias = "secret_collection_for_alias")]
    pub fn for_alias<P: FnOnce(Result<Option<Collection>, glib::Error>) + 'static>(
        service: Option<&impl IsA<Service>>,
        alias: &str,
        flags: CollectionFlags,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
        callback: P,
    ) {
        let main_context = glib::MainContext::ref_thread_default();
        let is_main_context_owner = main_context.is_owner();
        let has_acquired_main_context = (!is_main_context_owner)
            .then(|| main_context.acquire().ok())
            .flatten();
        assert!(
            is_main_context_owner || has_acquired_main_context.is_some(),
            "Async operations only allowed if the thread is owning the MainContext"
        );

        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
        unsafe extern "C" fn for_alias_trampoline<
            P: FnOnce(Result<Option<Collection>, glib::Error>) + 'static,
        >(
            _source_object: *mut glib::gobject_ffi::GObject,
            res: *mut gio::ffi::GAsyncResult,
            user_data: glib::ffi::gpointer,
        ) {
            let mut error = std::ptr::null_mut();
            let ret = ffi::secret_collection_for_alias_finish(res, &mut error);
            let result = if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
                Box_::from_raw(user_data as *mut _);
            let callback: P = callback.into_inner();
            callback(result);
        }
        let callback = for_alias_trampoline::<P>;
        unsafe {
            ffi::secret_collection_for_alias(
                service.map(|p| p.as_ref()).to_glib_none().0,
                alias.to_glib_none().0,
                flags.into_glib(),
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    pub fn for_alias_future(
        service: Option<&(impl IsA<Service> + Clone + 'static)>,
        alias: &str,
        flags: CollectionFlags,
    ) -> Pin<
        Box_<dyn std::future::Future<Output = Result<Option<Collection>, glib::Error>> + 'static>,
    > {
        let service = service.map(ToOwned::to_owned);
        let alias = String::from(alias);
        Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| {
            Self::for_alias(
                service.as_ref().map(::std::borrow::Borrow::borrow),
                &alias,
                flags,
                Some(cancellable),
                move |res| {
                    send.resolve(res);
                },
            );
        }))
    }

    /// Lookup which collection is assigned to this alias. Aliases help determine
    /// well known collections, such as `default`.
    ///
    /// If @service is [`None`], then `get_sync()` will be called to get the
    /// default [`Service`][crate::Service] proxy.
    ///
    /// This method may block and should not be used in user interface threads.
    /// ## `service`
    /// a secret service object
    /// ## `alias`
    /// the alias to lookup
    /// ## `flags`
    /// options for the collection initialization
    /// ## `cancellable`
    /// optional cancellation object
    ///
    /// # Returns
    ///
    /// the collection, or [`None`] if none assigned to the alias
    #[doc(alias = "secret_collection_for_alias_sync")]
    pub fn for_alias_sync(
        service: Option<&impl IsA<Service>>,
        alias: &str,
        flags: CollectionFlags,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
    ) -> Result<Option<Collection>, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::secret_collection_for_alias_sync(
                service.map(|p| p.as_ref()).to_glib_none().0,
                alias.to_glib_none().0,
                flags.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))
            }
        }
    }

    /// Get a new collection proxy for a collection in the secret service.
    ///
    /// If @service is [`None`], then `get()` will be called to get
    /// the default [`Service`][crate::Service] proxy.
    ///
    /// This method will return immediately and complete asynchronously.
    /// ## `service`
    /// a secret service object
    /// ## `collection_path`
    /// the D-Bus path of the collection
    /// ## `flags`
    /// options for the collection initialization
    /// ## `cancellable`
    /// optional cancellation object
    /// ## `callback`
    /// called when the operation completes
    #[doc(alias = "secret_collection_new_for_dbus_path")]
    pub fn new_for_dbus_path<P: FnOnce(Result<Collection, glib::Error>) + 'static>(
        service: Option<&impl IsA<Service>>,
        collection_path: &str,
        flags: CollectionFlags,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
        callback: P,
    ) {
        let main_context = glib::MainContext::ref_thread_default();
        let is_main_context_owner = main_context.is_owner();
        let has_acquired_main_context = (!is_main_context_owner)
            .then(|| main_context.acquire().ok())
            .flatten();
        assert!(
            is_main_context_owner || has_acquired_main_context.is_some(),
            "Async operations only allowed if the thread is owning the MainContext"
        );

        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
        unsafe extern "C" fn new_for_dbus_path_trampoline<
            P: FnOnce(Result<Collection, glib::Error>) + 'static,
        >(
            _source_object: *mut glib::gobject_ffi::GObject,
            res: *mut gio::ffi::GAsyncResult,
            user_data: glib::ffi::gpointer,
        ) {
            let mut error = std::ptr::null_mut();
            let ret = ffi::secret_collection_new_for_dbus_path_finish(res, &mut error);
            let result = if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
                Box_::from_raw(user_data as *mut _);
            let callback: P = callback.into_inner();
            callback(result);
        }
        let callback = new_for_dbus_path_trampoline::<P>;
        unsafe {
            ffi::secret_collection_new_for_dbus_path(
                service.map(|p| p.as_ref()).to_glib_none().0,
                collection_path.to_glib_none().0,
                flags.into_glib(),
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    pub fn new_for_dbus_path_future(
        service: Option<&(impl IsA<Service> + Clone + 'static)>,
        collection_path: &str,
        flags: CollectionFlags,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<Collection, glib::Error>> + 'static>>
    {
        let service = service.map(ToOwned::to_owned);
        let collection_path = String::from(collection_path);
        Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| {
            Self::new_for_dbus_path(
                service.as_ref().map(::std::borrow::Borrow::borrow),
                &collection_path,
                flags,
                Some(cancellable),
                move |res| {
                    send.resolve(res);
                },
            );
        }))
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Collection>> Sealed for T {}
}

/// Trait containing all [`struct@Collection`] methods.
///
/// # Implementors
///
/// [`Collection`][struct@crate::Collection]
pub trait CollectionExt: IsA<Collection> + sealed::Sealed + 'static {
    /// Delete this collection.
    ///
    /// This method returns immediately and completes asynchronously. The secret
    /// service may prompt the user. [`ServiceExt::prompt()`][crate::prelude::ServiceExt::prompt()] will be used to handle
    /// any prompts that show up.
    /// ## `cancellable`
    /// optional cancellation object
    /// ## `callback`
    /// called when the operation completes
    #[doc(alias = "secret_collection_delete")]
    fn delete<P: FnOnce(Result<(), glib::Error>) + 'static>(
        &self,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
        callback: P,
    ) {
        let main_context = glib::MainContext::ref_thread_default();
        let is_main_context_owner = main_context.is_owner();
        let has_acquired_main_context = (!is_main_context_owner)
            .then(|| main_context.acquire().ok())
            .flatten();
        assert!(
            is_main_context_owner || has_acquired_main_context.is_some(),
            "Async operations only allowed if the thread is owning the MainContext"
        );

        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
        unsafe extern "C" fn delete_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(
            _source_object: *mut glib::gobject_ffi::GObject,
            res: *mut gio::ffi::GAsyncResult,
            user_data: glib::ffi::gpointer,
        ) {
            let mut error = std::ptr::null_mut();
            let _ = ffi::secret_collection_delete_finish(_source_object as *mut _, res, &mut error);
            let result = if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
                Box_::from_raw(user_data as *mut _);
            let callback: P = callback.into_inner();
            callback(result);
        }
        let callback = delete_trampoline::<P>;
        unsafe {
            ffi::secret_collection_delete(
                self.as_ref().to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    fn delete_future(
        &self,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
            obj.delete(Some(cancellable), move |res| {
                send.resolve(res);
            });
        }))
    }

    /// Delete this collection.
    ///
    /// This method may block indefinitely and should not be used in user interface
    /// threads. The secret service may prompt the user. [`ServiceExt::prompt()`][crate::prelude::ServiceExt::prompt()] will
    /// be used to handle any prompts that show up.
    /// ## `cancellable`
    /// optional cancellation object
    ///
    /// # Returns
    ///
    /// whether the collection was successfully deleted or not
    #[doc(alias = "secret_collection_delete_sync")]
    fn delete_sync(
        &self,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
    ) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::secret_collection_delete_sync(
                self.as_ref().to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Get the created date and time of the collection.
    ///
    /// The return value is the number of seconds since the unix epoch, January 1st
    /// 1970.
    ///
    /// # Returns
    ///
    /// the created date and time
    #[doc(alias = "secret_collection_get_created")]
    #[doc(alias = "get_created")]
    fn created(&self) -> u64 {
        unsafe { ffi::secret_collection_get_created(self.as_ref().to_glib_none().0) }
    }

    /// Get the flags representing what features of the #SecretCollection proxy
    /// have been initialized.
    ///
    /// Use [`load_items()`][Self::load_items()] to initialize further features and change
    /// the flags.
    ///
    /// # Returns
    ///
    /// the flags for features initialized
    #[doc(alias = "secret_collection_get_flags")]
    #[doc(alias = "get_flags")]
    fn flags(&self) -> CollectionFlags {
        unsafe {
            from_glib(ffi::secret_collection_get_flags(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Get the list of items in this collection.
    ///
    /// # Returns
    ///
    /// a list of items, when
    ///   done, the list should be freed with `GLib::List::free()`, and each item
    ///   should be released with `GObject::Object::unref()`
    #[doc(alias = "secret_collection_get_items")]
    #[doc(alias = "get_items")]
    fn items(&self) -> Vec<Item> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::secret_collection_get_items(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Get the label of this collection.
    ///
    /// # Returns
    ///
    /// the label, which should be freed with
    ///   `free()`
    #[doc(alias = "secret_collection_get_label")]
    #[doc(alias = "get_label")]
    fn label(&self) -> glib::GString {
        unsafe {
            from_glib_full(ffi::secret_collection_get_label(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Get whether the collection is locked or not.
    ///
    /// Use [`ServiceExtManual::lock()`][crate::prelude::ServiceExtManual::lock()] or [`ServiceExtManual::unlock()`][crate::prelude::ServiceExtManual::unlock()] to lock or unlock the
    /// collection.
    ///
    /// # Returns
    ///
    /// whether the collection is locked or not
    #[doc(alias = "secret_collection_get_locked")]
    #[doc(alias = "get_locked")]
    fn is_locked(&self) -> bool {
        unsafe {
            from_glib(ffi::secret_collection_get_locked(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Get the modified date and time of the collection.
    ///
    /// The return value is the number of seconds since the unix epoch, January 1st
    /// 1970.
    ///
    /// # Returns
    ///
    /// the modified date and time
    #[doc(alias = "secret_collection_get_modified")]
    #[doc(alias = "get_modified")]
    fn modified(&self) -> u64 {
        unsafe { ffi::secret_collection_get_modified(self.as_ref().to_glib_none().0) }
    }

    /// Get the Secret Service object that this collection was created with.
    ///
    /// # Returns
    ///
    /// the Secret Service object
    #[doc(alias = "secret_collection_get_service")]
    #[doc(alias = "get_service")]
    fn service(&self) -> Service {
        unsafe {
            from_glib_none(ffi::secret_collection_get_service(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Ensure that the #SecretCollection proxy has loaded all the items present
    /// in the Secret Service.
    ///
    /// This affects the result of [`items()`][Self::items()].
    ///
    /// For collections returned from [`ServiceExt::collections()`][crate::prelude::ServiceExt::collections()] the items will
    /// have already been loaded.
    ///
    /// This method will return immediately and complete asynchronously.
    /// ## `cancellable`
    /// optional cancellation object
    /// ## `callback`
    /// called when the operation completes
    #[doc(alias = "secret_collection_load_items")]
    fn load_items<P: FnOnce(Result<(), glib::Error>) + 'static>(
        &self,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
        callback: P,
    ) {
        let main_context = glib::MainContext::ref_thread_default();
        let is_main_context_owner = main_context.is_owner();
        let has_acquired_main_context = (!is_main_context_owner)
            .then(|| main_context.acquire().ok())
            .flatten();
        assert!(
            is_main_context_owner || has_acquired_main_context.is_some(),
            "Async operations only allowed if the thread is owning the MainContext"
        );

        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
        unsafe extern "C" fn load_items_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(
            _source_object: *mut glib::gobject_ffi::GObject,
            res: *mut gio::ffi::GAsyncResult,
            user_data: glib::ffi::gpointer,
        ) {
            let mut error = std::ptr::null_mut();
            let _ =
                ffi::secret_collection_load_items_finish(_source_object as *mut _, res, &mut error);
            let result = if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
                Box_::from_raw(user_data as *mut _);
            let callback: P = callback.into_inner();
            callback(result);
        }
        let callback = load_items_trampoline::<P>;
        unsafe {
            ffi::secret_collection_load_items(
                self.as_ref().to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    fn load_items_future(
        &self,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
            obj.load_items(Some(cancellable), move |res| {
                send.resolve(res);
            });
        }))
    }

    /// Ensure that the #SecretCollection proxy has loaded all the items present
    /// in the Secret Service. This affects the result of
    /// [`items()`][Self::items()].
    ///
    /// For collections returned from [`ServiceExt::collections()`][crate::prelude::ServiceExt::collections()] the items
    /// will have already been loaded.
    ///
    /// This method may block indefinitely and should not be used in user interface
    /// threads.
    /// ## `cancellable`
    /// optional cancellation object
    ///
    /// # Returns
    ///
    /// whether the load was successful or not
    #[doc(alias = "secret_collection_load_items_sync")]
    fn load_items_sync(
        &self,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
    ) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::secret_collection_load_items_sync(
                self.as_ref().to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Refresh the properties on this collection. This fires off a request to
    /// refresh, and the properties will be updated later.
    ///
    /// Calling this method is not normally necessary, as the secret service
    /// will notify the client when properties change.
    #[doc(alias = "secret_collection_refresh")]
    fn refresh(&self) {
        unsafe {
            ffi::secret_collection_refresh(self.as_ref().to_glib_none().0);
        }
    }

    /// Set the label of this collection.
    ///
    /// This function returns immediately and completes asynchronously.
    /// ## `label`
    /// a new label
    /// ## `cancellable`
    /// optional cancellation object
    /// ## `callback`
    /// called when the operation completes
    #[doc(alias = "secret_collection_set_label")]
    fn set_label<P: FnOnce(Result<(), glib::Error>) + 'static>(
        &self,
        label: &str,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
        callback: P,
    ) {
        let main_context = glib::MainContext::ref_thread_default();
        let is_main_context_owner = main_context.is_owner();
        let has_acquired_main_context = (!is_main_context_owner)
            .then(|| main_context.acquire().ok())
            .flatten();
        assert!(
            is_main_context_owner || has_acquired_main_context.is_some(),
            "Async operations only allowed if the thread is owning the MainContext"
        );

        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
        unsafe extern "C" fn set_label_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(
            _source_object: *mut glib::gobject_ffi::GObject,
            res: *mut gio::ffi::GAsyncResult,
            user_data: glib::ffi::gpointer,
        ) {
            let mut error = std::ptr::null_mut();
            let _ =
                ffi::secret_collection_set_label_finish(_source_object as *mut _, res, &mut error);
            let result = if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
                Box_::from_raw(user_data as *mut _);
            let callback: P = callback.into_inner();
            callback(result);
        }
        let callback = set_label_trampoline::<P>;
        unsafe {
            ffi::secret_collection_set_label(
                self.as_ref().to_glib_none().0,
                label.to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    fn set_label_future(
        &self,
        label: &str,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
        let label = String::from(label);
        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
            obj.set_label(&label, Some(cancellable), move |res| {
                send.resolve(res);
            });
        }))
    }

    /// Set the label of this collection.
    ///
    /// This function may block indefinitely. Use the asynchronous version
    /// in user interface threads.
    /// ## `label`
    /// a new label
    /// ## `cancellable`
    /// optional cancellation object
    ///
    /// # Returns
    ///
    /// whether the change was successful or not
    #[doc(alias = "secret_collection_set_label_sync")]
    fn set_label_sync(
        &self,
        label: &str,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
    ) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::secret_collection_set_label_sync(
                self.as_ref().to_glib_none().0,
                label.to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// The date and time (in seconds since the UNIX epoch) that this
    /// collection was created.
    fn set_created(&self, created: u64) {
        ObjectExt::set_property(self.as_ref(), "created", created)
    }

    /// The date and time (in seconds since the UNIX epoch) that this
    /// collection was last modified.
    fn set_modified(&self, modified: u64) {
        ObjectExt::set_property(self.as_ref(), "modified", modified)
    }

    #[doc(alias = "created")]
    fn connect_created_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_created_trampoline<P: IsA<Collection>, F: Fn(&P) + 'static>(
            this: *mut ffi::SecretCollection,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Collection::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::created\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_created_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "label")]
    fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_label_trampoline<P: IsA<Collection>, F: Fn(&P) + 'static>(
            this: *mut ffi::SecretCollection,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Collection::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::label\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_label_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "locked")]
    fn connect_locked_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_locked_trampoline<P: IsA<Collection>, F: Fn(&P) + 'static>(
            this: *mut ffi::SecretCollection,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Collection::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::locked\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_locked_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "modified")]
    fn connect_modified_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_modified_trampoline<P: IsA<Collection>, F: Fn(&P) + 'static>(
            this: *mut ffi::SecretCollection,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Collection::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::modified\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_modified_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<Collection>> CollectionExt for O {}