use crate::{ffi, RemoteType};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "FlatpakRemote")]
pub struct Remote(Object<ffi::FlatpakRemote, ffi::FlatpakRemoteClass>);
match fn {
type_ => || ffi::flatpak_remote_get_type(),
}
}
impl Remote {
pub const NONE: Option<&'static Remote> = None;
#[doc(alias = "flatpak_remote_new")]
pub fn new(name: &str) -> Remote {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::flatpak_remote_new(name.to_glib_none().0)) }
}
#[cfg(feature = "v1_3_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_3_4")))]
#[doc(alias = "flatpak_remote_new_from_file")]
#[doc(alias = "new_from_file")]
pub fn from_file(name: &str, data: &glib::Bytes) -> Result<Remote, glib::Error> {
assert_initialized_main_thread!();
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::flatpak_remote_new_from_file(
name.to_glib_none().0,
data.to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
pub fn builder() -> RemoteBuilder {
RemoteBuilder::new()
}
}
impl Default for Remote {
fn default() -> Self {
glib::object::Object::new::<Self>()
}
}
#[must_use = "The builder must be built to be used"]
pub struct RemoteBuilder {
builder: glib::object::ObjectBuilder<'static, Remote>,
}
impl RemoteBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
pub fn name(self, name: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("name", name.into()),
}
}
pub fn type_(self, type_: RemoteType) -> Self {
Self {
builder: self.builder.property("type", type_),
}
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Remote {
assert_initialized_main_thread!();
self.builder.build()
}
}
pub trait RemoteExt: IsA<Remote> + 'static {
#[doc(alias = "flatpak_remote_get_appstream_dir")]
#[doc(alias = "get_appstream_dir")]
fn appstream_dir(&self, arch: Option<&str>) -> Option<gio::File> {
unsafe {
from_glib_full(ffi::flatpak_remote_get_appstream_dir(
self.as_ref().to_glib_none().0,
arch.to_glib_none().0,
))
}
}
#[doc(alias = "flatpak_remote_get_appstream_timestamp")]
#[doc(alias = "get_appstream_timestamp")]
fn appstream_timestamp(&self, arch: Option<&str>) -> Option<gio::File> {
unsafe {
from_glib_full(ffi::flatpak_remote_get_appstream_timestamp(
self.as_ref().to_glib_none().0,
arch.to_glib_none().0,
))
}
}
#[doc(alias = "flatpak_remote_get_collection_id")]
#[doc(alias = "get_collection_id")]
fn collection_id(&self) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::flatpak_remote_get_collection_id(
self.as_ref().to_glib_none().0,
))
}
}
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "flatpak_remote_get_comment")]
#[doc(alias = "get_comment")]
fn comment(&self) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::flatpak_remote_get_comment(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "flatpak_remote_get_default_branch")]
#[doc(alias = "get_default_branch")]
fn default_branch(&self) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::flatpak_remote_get_default_branch(
self.as_ref().to_glib_none().0,
))
}
}
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "flatpak_remote_get_description")]
#[doc(alias = "get_description")]
fn description(&self) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::flatpak_remote_get_description(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "flatpak_remote_get_disabled")]
#[doc(alias = "get_disabled")]
fn is_disabled(&self) -> bool {
unsafe {
from_glib(ffi::flatpak_remote_get_disabled(
self.as_ref().to_glib_none().0,
))
}
}
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "flatpak_remote_get_filter")]
#[doc(alias = "get_filter")]
fn filter(&self) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::flatpak_remote_get_filter(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "flatpak_remote_get_gpg_verify")]
#[doc(alias = "get_gpg_verify")]
fn is_gpg_verify(&self) -> bool {
unsafe {
from_glib(ffi::flatpak_remote_get_gpg_verify(
self.as_ref().to_glib_none().0,
))
}
}
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "flatpak_remote_get_homepage")]
#[doc(alias = "get_homepage")]
fn homepage(&self) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::flatpak_remote_get_homepage(
self.as_ref().to_glib_none().0,
))
}
}
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "flatpak_remote_get_icon")]
#[doc(alias = "get_icon")]
fn icon(&self) -> Option<glib::GString> {
unsafe { from_glib_full(ffi::flatpak_remote_get_icon(self.as_ref().to_glib_none().0)) }
}
#[cfg(feature = "v1_1_1")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_1_1")))]
#[doc(alias = "flatpak_remote_get_main_ref")]
#[doc(alias = "get_main_ref")]
fn main_ref(&self) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::flatpak_remote_get_main_ref(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "flatpak_remote_get_name")]
#[doc(alias = "get_name")]
fn name(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::flatpak_remote_get_name(self.as_ref().to_glib_none().0)) }
}
#[doc(alias = "flatpak_remote_get_nodeps")]
#[doc(alias = "get_nodeps")]
fn is_nodeps(&self) -> bool {
unsafe {
from_glib(ffi::flatpak_remote_get_nodeps(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "flatpak_remote_get_noenumerate")]
#[doc(alias = "get_noenumerate")]
fn is_noenumerate(&self) -> bool {
unsafe {
from_glib(ffi::flatpak_remote_get_noenumerate(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "flatpak_remote_get_prio")]
#[doc(alias = "get_prio")]
fn prio(&self) -> i32 {
unsafe { ffi::flatpak_remote_get_prio(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "flatpak_remote_get_remote_type")]
#[doc(alias = "get_remote_type")]
fn remote_type(&self) -> RemoteType {
unsafe {
from_glib(ffi::flatpak_remote_get_remote_type(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "flatpak_remote_get_title")]
#[doc(alias = "get_title")]
fn title(&self) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::flatpak_remote_get_title(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "flatpak_remote_get_url")]
#[doc(alias = "get_url")]
fn url(&self) -> Option<glib::GString> {
unsafe { from_glib_full(ffi::flatpak_remote_get_url(self.as_ref().to_glib_none().0)) }
}
#[doc(alias = "flatpak_remote_set_collection_id")]
fn set_collection_id(&self, collection_id: Option<&str>) {
unsafe {
ffi::flatpak_remote_set_collection_id(
self.as_ref().to_glib_none().0,
collection_id.to_glib_none().0,
);
}
}
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "flatpak_remote_set_comment")]
fn set_comment(&self, comment: &str) {
unsafe {
ffi::flatpak_remote_set_comment(
self.as_ref().to_glib_none().0,
comment.to_glib_none().0,
);
}
}
#[doc(alias = "flatpak_remote_set_default_branch")]
fn set_default_branch(&self, default_branch: &str) {
unsafe {
ffi::flatpak_remote_set_default_branch(
self.as_ref().to_glib_none().0,
default_branch.to_glib_none().0,
);
}
}
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "flatpak_remote_set_description")]
fn set_description(&self, description: &str) {
unsafe {
ffi::flatpak_remote_set_description(
self.as_ref().to_glib_none().0,
description.to_glib_none().0,
);
}
}
#[doc(alias = "flatpak_remote_set_disabled")]
fn set_disabled(&self, disabled: bool) {
unsafe {
ffi::flatpak_remote_set_disabled(self.as_ref().to_glib_none().0, disabled.into_glib());
}
}
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "flatpak_remote_set_filter")]
fn set_filter(&self, filter_path: &str) {
unsafe {
ffi::flatpak_remote_set_filter(
self.as_ref().to_glib_none().0,
filter_path.to_glib_none().0,
);
}
}
#[doc(alias = "flatpak_remote_set_gpg_key")]
fn set_gpg_key(&self, gpg_key: &glib::Bytes) {
unsafe {
ffi::flatpak_remote_set_gpg_key(
self.as_ref().to_glib_none().0,
gpg_key.to_glib_none().0,
);
}
}
#[doc(alias = "flatpak_remote_set_gpg_verify")]
fn set_gpg_verify(&self, gpg_verify: bool) {
unsafe {
ffi::flatpak_remote_set_gpg_verify(
self.as_ref().to_glib_none().0,
gpg_verify.into_glib(),
);
}
}
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "flatpak_remote_set_homepage")]
fn set_homepage(&self, homepage: &str) {
unsafe {
ffi::flatpak_remote_set_homepage(
self.as_ref().to_glib_none().0,
homepage.to_glib_none().0,
);
}
}
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "flatpak_remote_set_icon")]
fn set_icon(&self, icon: &str) {
unsafe {
ffi::flatpak_remote_set_icon(self.as_ref().to_glib_none().0, icon.to_glib_none().0);
}
}
#[cfg(feature = "v1_1_1")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_1_1")))]
#[doc(alias = "flatpak_remote_set_main_ref")]
fn set_main_ref(&self, main_ref: &str) {
unsafe {
ffi::flatpak_remote_set_main_ref(
self.as_ref().to_glib_none().0,
main_ref.to_glib_none().0,
);
}
}
#[doc(alias = "flatpak_remote_set_nodeps")]
fn set_nodeps(&self, nodeps: bool) {
unsafe {
ffi::flatpak_remote_set_nodeps(self.as_ref().to_glib_none().0, nodeps.into_glib());
}
}
#[doc(alias = "flatpak_remote_set_noenumerate")]
fn set_noenumerate(&self, noenumerate: bool) {
unsafe {
ffi::flatpak_remote_set_noenumerate(
self.as_ref().to_glib_none().0,
noenumerate.into_glib(),
);
}
}
#[doc(alias = "flatpak_remote_set_prio")]
fn set_prio(&self, prio: i32) {
unsafe {
ffi::flatpak_remote_set_prio(self.as_ref().to_glib_none().0, prio);
}
}
#[doc(alias = "flatpak_remote_set_title")]
fn set_title(&self, title: &str) {
unsafe {
ffi::flatpak_remote_set_title(self.as_ref().to_glib_none().0, title.to_glib_none().0);
}
}
#[doc(alias = "flatpak_remote_set_url")]
fn set_url(&self, url: &str) {
unsafe {
ffi::flatpak_remote_set_url(self.as_ref().to_glib_none().0, url.to_glib_none().0);
}
}
fn set_name(&self, name: Option<&str>) {
ObjectExt::set_property(self.as_ref(), "name", name)
}
#[doc(alias = "type")]
fn type_(&self) -> RemoteType {
ObjectExt::property(self.as_ref(), "type")
}
#[doc(alias = "name")]
fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_name_trampoline<P: IsA<Remote>, F: Fn(&P) + 'static>(
this: *mut ffi::FlatpakRemote,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Remote::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::name".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_name_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<Remote>> RemoteExt for O {}