libsecret/auto/item.rs
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
// 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
#[cfg(feature = "v0_19")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))]
use crate::Retrievable;
use crate::{ffi, ItemFlags, Service, Value};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::{boxed::Box as Box_, pin::Pin};
#[cfg(feature = "v0_19")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))]
glib::wrapper! {
/// A secret item
///
/// #SecretItem represents a secret item stored in the Secret Service.
///
/// Each item has a value, represented by a [`Value`][crate::Value], which can be
/// retrieved by [`ItemExt::secret()`][crate::prelude::ItemExt::secret()] or set by [`ItemExt::set_secret()`][crate::prelude::ItemExt::set_secret()].
/// The item is only available when the item is not locked.
///
/// Items can be locked or unlocked using the [`ServiceExtManual::lock()`][crate::prelude::ServiceExtManual::lock()] or
/// [`ServiceExtManual::unlock()`][crate::prelude::ServiceExtManual::unlock()] functions. The Secret Service may not be able to
/// unlock individual items, and may unlock an entire collection when a single
/// item is unlocked.
///
/// Each item has a set of attributes, which are used to locate the item later.
/// These are not stored or transferred in a secure manner. Each attribute has
/// a string name and a string value. Use [`ServiceExtManual::search()`][crate::prelude::ServiceExtManual::search()] to search for
/// items based on their attributes, and [`ItemExtManual::set_attributes()`][crate::prelude::ItemExtManual::set_attributes()] to change
/// the attributes associated with an item.
///
/// Items can be created with `create()` or [`ServiceExtManual::store()`][crate::prelude::ServiceExtManual::store()].
///
/// ## Properties
///
///
/// #### `flags`
/// A set of flags describing which parts of the secret item have
/// been initialized.
///
/// Readable | Writeable | Construct Only
///
///
/// #### `locked`
/// Whether the item is locked or not.
///
/// An item may not be independently lockable separate from other items in
/// its collection.
///
/// To lock or unlock a item use the [`ServiceExtManual::lock()`][crate::prelude::ServiceExtManual::lock()] or
/// [`ServiceExtManual::unlock()`][crate::prelude::ServiceExtManual::unlock()] functions.
///
/// Readable
///
///
/// #### `service`
/// The [`Service`][crate::Service] object that this item 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>
/// <details><summary><h4>Retrievable</h4></summary>
///
///
/// #### `attributes`
/// The attributes set on this item.
///
/// Attributes are used to locate an item. They are not guaranteed to be
/// stored or transferred securely.
///
/// Readable | Writeable
///
///
/// #### `created`
/// The date and time (in seconds since the UNIX epoch) that this
/// item was created.
///
/// Readable | Writeable
///
///
/// #### `label`
/// The human readable label for the item.
///
/// Readable | Writeable
///
///
/// #### `modified`
/// The date and time (in seconds since the UNIX epoch) that this
/// item was last modified.
///
/// Readable | Writeable
/// </details>
///
/// # Implements
///
/// [`ItemExt`][trait@crate::prelude::ItemExt], [`trait@gio::prelude::DBusProxyExt`], [`trait@gio::prelude::DBusInterfaceExt`], [`trait@gio::prelude::InitableExt`], [`RetrievableExt`][trait@crate::prelude::RetrievableExt], [`RetrievableExtManual`][trait@crate::prelude::RetrievableExtManual]
#[doc(alias = "SecretItem")]
pub struct Item(Object<ffi::SecretItem, ffi::SecretItemClass>) @extends gio::DBusProxy, @implements gio::DBusInterface, gio::Initable, Retrievable;
match fn {
type_ => || ffi::secret_item_get_type(),
}
}
#[cfg(not(any(feature = "v0_19")))]
glib::wrapper! {
#[doc(alias = "SecretItem")]
pub struct Item(Object<ffi::SecretItem, ffi::SecretItemClass>) @extends gio::DBusProxy, @implements gio::DBusInterface, gio::Initable;
match fn {
type_ => || ffi::secret_item_get_type(),
}
}
impl Item {
pub const NONE: Option<&'static Item> = None;
/// Get a new item proxy for a secret item 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
/// ## `item_path`
/// the D-Bus path of the item
/// ## `flags`
/// initialization flags for the new item
/// ## `cancellable`
/// optional cancellation object
///
/// # Returns
///
/// the new item, which should be unreferenced
/// with `GObject::Object::unref()`
#[doc(alias = "secret_item_new_for_dbus_path_sync")]
#[doc(alias = "new_for_dbus_path_sync")]
pub fn for_dbus_path_sync(
service: Option<&impl IsA<Service>>,
item_path: &str,
flags: ItemFlags,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<Item, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::secret_item_new_for_dbus_path_sync(
service.map(|p| p.as_ref()).to_glib_none().0,
item_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))
}
}
}
/// Get a new item proxy for a secret item 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
/// ## `item_path`
/// the D-Bus path of the collection
/// ## `flags`
/// initialization flags for the new item
/// ## `cancellable`
/// optional cancellation object
/// ## `callback`
/// called when the operation completes
#[doc(alias = "secret_item_new_for_dbus_path")]
pub fn new_for_dbus_path<P: FnOnce(Result<Item, glib::Error>) + 'static>(
service: Option<&impl IsA<Service>>,
item_path: &str,
flags: ItemFlags,
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<Item, 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_item_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_item_new_for_dbus_path(
service.map(|p| p.as_ref()).to_glib_none().0,
item_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)>,
item_path: &str,
flags: ItemFlags,
) -> Pin<Box_<dyn std::future::Future<Output = Result<Item, glib::Error>> + 'static>> {
let service = service.map(ToOwned::to_owned);
let item_path = String::from(item_path);
Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| {
Self::new_for_dbus_path(
service.as_ref().map(::std::borrow::Borrow::borrow),
&item_path,
flags,
Some(cancellable),
move |res| {
send.resolve(res);
},
);
}))
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::Item>> Sealed for T {}
}
/// Trait containing all [`struct@Item`] methods.
///
/// # Implementors
///
/// [`Item`][struct@crate::Item]
pub trait ItemExt: IsA<Item> + sealed::Sealed + 'static {
/// Delete this item.
///
/// 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_item_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_item_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_item_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 secret item.
///
/// 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 item was successfully deleted or not
#[doc(alias = "secret_item_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_item_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 item.
///
/// The return value is the number of seconds since the unix epoch, January 1st
/// 1970.
///
/// # Returns
///
/// the created date and time
#[cfg(not(feature = "v0_19"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "v0_19"))))]
#[doc(alias = "secret_item_get_created")]
#[doc(alias = "get_created")]
fn created(&self) -> u64 {
unsafe { ffi::secret_item_get_created(self.as_ref().to_glib_none().0) }
}
/// Get the flags representing what features of the #SecretItem proxy
/// have been initialized.
///
/// Use [`load_secret()`][Self::load_secret()] to initialize further features
/// and change the flags.
///
/// # Returns
///
/// the flags for features initialized
#[doc(alias = "secret_item_get_flags")]
#[doc(alias = "get_flags")]
fn flags(&self) -> ItemFlags {
unsafe { from_glib(ffi::secret_item_get_flags(self.as_ref().to_glib_none().0)) }
}
/// Get the label of this item.
///
/// # Returns
///
/// the label, which should be freed with `free()`
#[cfg(not(feature = "v0_19"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "v0_19"))))]
#[doc(alias = "secret_item_get_label")]
#[doc(alias = "get_label")]
fn label(&self) -> glib::GString {
unsafe { from_glib_full(ffi::secret_item_get_label(self.as_ref().to_glib_none().0)) }
}
/// Get whether the item is locked or not.
///
/// Depending on the secret service an item may not be able to be locked
/// independently from the collection that it is in.
///
/// # Returns
///
/// whether the item is locked or not
#[doc(alias = "secret_item_get_locked")]
#[doc(alias = "get_locked")]
#[doc(alias = "locked")]
fn is_locked(&self) -> bool {
unsafe { from_glib(ffi::secret_item_get_locked(self.as_ref().to_glib_none().0)) }
}
/// Get the modified date and time of the item.
///
/// The return value is the number of seconds since the unix epoch, January 1st
/// 1970.
///
/// # Returns
///
/// the modified date and time
#[cfg(not(feature = "v0_19"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "v0_19"))))]
#[doc(alias = "secret_item_get_modified")]
#[doc(alias = "get_modified")]
fn modified(&self) -> u64 {
unsafe { ffi::secret_item_get_modified(self.as_ref().to_glib_none().0) }
}
/// Gets the name of the schema that this item was stored with. This is also
/// available at the `xdg:schema` attribute.
///
/// # Returns
///
/// the schema name
#[doc(alias = "secret_item_get_schema_name")]
#[doc(alias = "get_schema_name")]
fn schema_name(&self) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::secret_item_get_schema_name(
self.as_ref().to_glib_none().0,
))
}
}
/// Get the secret value of this item.
///
/// If this item is locked or the secret has not yet been loaded then this will
/// return [`None`].
///
/// To load the secret call the [`load_secret()`][Self::load_secret()] method.
///
/// # Returns
///
/// the secret value which should be
/// released with `Value::unref()`, or [`None`]
#[doc(alias = "secret_item_get_secret")]
#[doc(alias = "get_secret")]
fn secret(&self) -> Option<Value> {
unsafe { from_glib_full(ffi::secret_item_get_secret(self.as_ref().to_glib_none().0)) }
}
/// Get the Secret Service object that this item was created with.
///
/// # Returns
///
/// the Secret Service object
#[doc(alias = "secret_item_get_service")]
#[doc(alias = "get_service")]
fn service(&self) -> Service {
unsafe { from_glib_none(ffi::secret_item_get_service(self.as_ref().to_glib_none().0)) }
}
/// Load the secret value of this item.
///
/// Each item has a single secret which might be a password or some
/// other secret binary value.
///
/// This function will fail if the secret item is locked.
///
/// This function returns immediately and completes asynchronously.
/// ## `cancellable`
/// optional cancellation object
/// ## `callback`
/// called when the operation completes
#[doc(alias = "secret_item_load_secret")]
fn load_secret<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_secret_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_item_load_secret_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_secret_trampoline::<P>;
unsafe {
ffi::secret_item_load_secret(
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_secret_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_secret(Some(cancellable), move |res| {
send.resolve(res);
});
}))
}
/// Load the secret value of this item.
///
/// Each item has a single secret which might be a password or some
/// other secret binary value.
///
/// This function may block indefinitely. Use the asynchronous version
/// in user interface threads.
/// ## `cancellable`
/// optional cancellation object
///
/// # Returns
///
/// whether the secret item successfully loaded or not
#[doc(alias = "secret_item_load_secret_sync")]
fn load_secret_sync(
&self,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::secret_item_load_secret_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 item.
///
/// 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_item_refresh")]
fn refresh(&self) {
unsafe {
ffi::secret_item_refresh(self.as_ref().to_glib_none().0);
}
}
/// Set the label of this item.
///
/// This function returns immediately and completes asynchronously.
/// ## `label`
/// a new label
/// ## `cancellable`
/// optional cancellation object
/// ## `callback`
/// called when the operation completes
#[doc(alias = "secret_item_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_item_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_item_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 item.
///
/// 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_item_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_item_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))
}
}
}
/// Set the secret value of this item.
///
/// Each item has a single secret which might be a password or some
/// other secret binary value.
///
/// This function returns immediately and completes asynchronously.
/// ## `value`
/// a new secret value
/// ## `cancellable`
/// optional cancellation object
/// ## `callback`
/// called when the operation completes
#[doc(alias = "secret_item_set_secret")]
fn set_secret<P: FnOnce(Result<(), glib::Error>) + 'static>(
&self,
value: &Value,
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_secret_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_item_set_secret_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_secret_trampoline::<P>;
unsafe {
ffi::secret_item_set_secret(
self.as_ref().to_glib_none().0,
value.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_secret_future(
&self,
value: &Value,
) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
let value = value.clone();
Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
obj.set_secret(&value, Some(cancellable), move |res| {
send.resolve(res);
});
}))
}
/// Set the secret value of this item.
///
/// Each item has a single secret which might be a password or some
/// other secret binary value.
///
/// This function may block indefinitely. Use the asynchronous version
/// in user interface threads.
/// ## `value`
/// a new secret value
/// ## `cancellable`
/// optional cancellation object
///
/// # Returns
///
/// whether the change was successful or not
#[doc(alias = "secret_item_set_secret_sync")]
fn set_secret_sync(
&self,
value: &Value,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::secret_item_set_secret_sync(
self.as_ref().to_glib_none().0,
value.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))
}
}
}
#[doc(alias = "locked")]
fn connect_locked_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_locked_trampoline<P: IsA<Item>, F: Fn(&P) + 'static>(
this: *mut ffi::SecretItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Item::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::<*const (), unsafe extern "C" fn()>(
notify_locked_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<Item>> ItemExt for O {}