libappstream 0.4.0

Rust bindings for appstream
Documentation
// 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::{
    ffi, BundleKind, Category, Component, ComponentScope, DataIdMatchFlags, MarkupKind,
    MetadataLocation, RelationCompare, VercmpFlags,
};
use glib::translate::*;

#[doc(alias = "as_get_current_distro_component_id")]
#[doc(alias = "get_current_distro_component_id")]
pub fn current_distro_component_id() -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe { from_glib_full(ffi::as_get_current_distro_component_id()) }
}

#[doc(alias = "as_get_default_categories")]
#[doc(alias = "get_default_categories")]
pub fn default_categories(with_special: bool) -> Vec<Category> {
    assert_initialized_main_thread!();
    unsafe {
        FromGlibPtrContainer::from_glib_container(ffi::as_get_default_categories(
            with_special.into_glib(),
        ))
    }
}

#[doc(alias = "as_get_default_categories_gi")]
#[doc(alias = "get_default_categories_gi")]
pub fn default_categories_gi(with_special: bool) -> Vec<Category> {
    assert_initialized_main_thread!();
    unsafe {
        FromGlibPtrContainer::from_glib_full(ffi::as_get_default_categories_gi(
            with_special.into_glib(),
        ))
    }
}

#[doc(alias = "as_get_license_name")]
#[doc(alias = "get_license_name")]
pub fn license_name(license: &str) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe { from_glib_full(ffi::as_get_license_name(license.to_glib_none().0)) }
}

#[doc(alias = "as_get_license_url")]
#[doc(alias = "get_license_url")]
pub fn license_url(license: &str) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe { from_glib_full(ffi::as_get_license_url(license.to_glib_none().0)) }
}

#[doc(alias = "as_is_spdx_license_exception_id")]
pub fn is_spdx_license_exception_id(exception_id: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::as_is_spdx_license_exception_id(
            exception_id.to_glib_none().0,
        ))
    }
}

#[doc(alias = "as_is_spdx_license_expression")]
pub fn is_spdx_license_expression(license: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::as_is_spdx_license_expression(license.to_glib_none().0)) }
}

#[doc(alias = "as_is_spdx_license_id")]
pub fn is_spdx_license_id(license_id: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::as_is_spdx_license_id(license_id.to_glib_none().0)) }
}

#[doc(alias = "as_license_is_free_license")]
pub fn license_is_free_license(license: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::as_license_is_free_license(license.to_glib_none().0)) }
}

#[doc(alias = "as_license_is_metadata_license")]
pub fn license_is_metadata_license(license: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::as_license_is_metadata_license(
            license.to_glib_none().0,
        ))
    }
}

#[doc(alias = "as_license_is_metadata_license_id")]
pub fn license_is_metadata_license_id(license_id: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::as_license_is_metadata_license_id(
            license_id.to_glib_none().0,
        ))
    }
}

#[doc(alias = "as_license_to_spdx_id")]
pub fn license_to_spdx_id(license: &str) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe { from_glib_full(ffi::as_license_to_spdx_id(license.to_glib_none().0)) }
}

#[doc(alias = "as_markup_convert")]
pub fn markup_convert(markup: &str, to_kind: MarkupKind) -> Result<glib::GString, glib::Error> {
    assert_initialized_main_thread!();
    unsafe {
        let mut error = std::ptr::null_mut();
        let ret = ffi::as_markup_convert(markup.to_glib_none().0, to_kind.into_glib(), &mut error);
        if error.is_null() {
            Ok(from_glib_full(ret))
        } else {
            Err(from_glib_full(error))
        }
    }
}

#[doc(alias = "as_markup_strsplit_words")]
pub fn markup_strsplit_words(text: &str) -> Vec<glib::GString> {
    assert_initialized_main_thread!();
    let line_len = text.len() as _;
    unsafe {
        FromGlibPtrContainer::from_glib_full(ffi::as_markup_strsplit_words(
            text.to_glib_none().0,
            line_len,
        ))
    }
}

#[doc(alias = "as_spdx_license_tokenize")]
pub fn spdx_license_tokenize(license: &str) -> Vec<glib::GString> {
    assert_initialized_main_thread!();
    unsafe {
        FromGlibPtrContainer::from_glib_full(ffi::as_spdx_license_tokenize(
            license.to_glib_none().0,
        ))
    }
}

#[doc(alias = "as_utils_build_data_id")]
pub fn utils_build_data_id(
    scope: ComponentScope,
    bundle_kind: BundleKind,
    origin: &str,
    cid: &str,
    branch: &str,
) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_full(ffi::as_utils_build_data_id(
            scope.into_glib(),
            bundle_kind.into_glib(),
            origin.to_glib_none().0,
            cid.to_glib_none().0,
            branch.to_glib_none().0,
        ))
    }
}

#[doc(alias = "as_utils_data_id_equal")]
pub fn utils_data_id_equal(data_id1: &str, data_id2: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::as_utils_data_id_equal(
            data_id1.to_glib_none().0,
            data_id2.to_glib_none().0,
        ))
    }
}

#[doc(alias = "as_utils_data_id_get_cid")]
pub fn utils_data_id_get_cid(data_id: &str) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe { from_glib_full(ffi::as_utils_data_id_get_cid(data_id.to_glib_none().0)) }
}

#[doc(alias = "as_utils_data_id_hash")]
pub fn utils_data_id_hash(data_id: &str) -> u32 {
    assert_initialized_main_thread!();
    unsafe { ffi::as_utils_data_id_hash(data_id.to_glib_none().0) }
}

#[doc(alias = "as_utils_data_id_match")]
pub fn utils_data_id_match(data_id1: &str, data_id2: &str, match_flags: DataIdMatchFlags) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::as_utils_data_id_match(
            data_id1.to_glib_none().0,
            data_id2.to_glib_none().0,
            match_flags.into_glib(),
        ))
    }
}

#[doc(alias = "as_utils_data_id_valid")]
pub fn utils_data_id_valid(data_id: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::as_utils_data_id_valid(data_id.to_glib_none().0)) }
}

#[doc(alias = "as_utils_get_desktop_environment_name")]
pub fn utils_get_desktop_environment_name(de_id: &str) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_none(ffi::as_utils_get_desktop_environment_name(
            de_id.to_glib_none().0,
        ))
    }
}

#[doc(alias = "as_utils_get_gui_environment_style_name")]
pub fn utils_get_gui_environment_style_name(env_style: &str) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_none(ffi::as_utils_get_gui_environment_style_name(
            env_style.to_glib_none().0,
        ))
    }
}

#[doc(alias = "as_utils_get_tag_search_weight")]
pub fn utils_get_tag_search_weight(tag_name: &str) -> u16 {
    assert_initialized_main_thread!();
    unsafe { ffi::as_utils_get_tag_search_weight(tag_name.to_glib_none().0) }
}

#[doc(alias = "as_utils_guess_scope_from_path")]
pub fn utils_guess_scope_from_path(path: &str) -> ComponentScope {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::as_utils_guess_scope_from_path(path.to_glib_none().0)) }
}

#[doc(alias = "as_utils_install_metadata_file")]
pub fn utils_install_metadata_file(
    location: MetadataLocation,
    filename: &str,
    origin: &str,
    destdir: &str,
) -> Result<(), glib::Error> {
    assert_initialized_main_thread!();
    unsafe {
        let mut error = std::ptr::null_mut();
        let is_ok = ffi::as_utils_install_metadata_file(
            location.into_glib(),
            filename.to_glib_none().0,
            origin.to_glib_none().0,
            destdir.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 = "as_utils_is_category_name")]
pub fn utils_is_category_name(category_name: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::as_utils_is_category_name(
            category_name.to_glib_none().0,
        ))
    }
}

#[doc(alias = "as_utils_is_desktop_environment")]
pub fn utils_is_desktop_environment(de_id: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::as_utils_is_desktop_environment(de_id.to_glib_none().0)) }
}

#[doc(alias = "as_utils_is_gui_environment_style")]
pub fn utils_is_gui_environment_style(env_style: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::as_utils_is_gui_environment_style(
            env_style.to_glib_none().0,
        ))
    }
}

#[doc(alias = "as_utils_is_platform_triplet")]
pub fn utils_is_platform_triplet(triplet: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::as_utils_is_platform_triplet(triplet.to_glib_none().0)) }
}

#[doc(alias = "as_utils_is_tld")]
pub fn utils_is_tld(tld: &str) -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::as_utils_is_tld(tld.to_glib_none().0)) }
}

#[doc(alias = "as_utils_locale_is_compatible")]
pub fn utils_locale_is_compatible(locale1: Option<&str>, locale2: Option<&str>) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::as_utils_locale_is_compatible(
            locale1.to_glib_none().0,
            locale2.to_glib_none().0,
        ))
    }
}

#[doc(alias = "as_utils_posix_locale_to_bcp47")]
pub fn utils_posix_locale_to_bcp47(locale: &str) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe { from_glib_full(ffi::as_utils_posix_locale_to_bcp47(locale.to_glib_none().0)) }
}

#[doc(alias = "as_utils_sort_components_into_categories")]
pub fn utils_sort_components_into_categories(
    cpts: &[Component],
    categories: &[Category],
    check_duplicates: bool,
) {
    assert_initialized_main_thread!();
    unsafe {
        ffi::as_utils_sort_components_into_categories(
            cpts.to_glib_none().0,
            categories.to_glib_none().0,
            check_duplicates.into_glib(),
        );
    }
}

#[doc(alias = "as_vercmp")]
pub fn vercmp(a: &str, b: &str, flags: VercmpFlags) -> i32 {
    assert_initialized_main_thread!();
    unsafe { ffi::as_vercmp(a.to_glib_none().0, b.to_glib_none().0, flags.into_glib()) }
}

#[doc(alias = "as_vercmp_simple")]
pub fn vercmp_simple(a: &str, b: &str) -> i32 {
    assert_initialized_main_thread!();
    unsafe { ffi::as_vercmp_simple(a.to_glib_none().0, b.to_glib_none().0) }
}

#[doc(alias = "as_vercmp_test_match")]
pub fn vercmp_test_match(
    ver1: &str,
    compare: RelationCompare,
    ver2: &str,
    flags: VercmpFlags,
) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::as_vercmp_test_match(
            ver1.to_glib_none().0,
            compare.into_glib(),
            ver2.to_glib_none().0,
            flags.into_glib(),
        ))
    }
}

#[doc(alias = "as_version_string")]
pub fn version_string() -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe { from_glib_none(ffi::as_version_string()) }
}