libappstream/auto/validator.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
// 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, IssueSeverity, ValidatorIssue};
use glib::{prelude::*, translate::*};
glib::wrapper! {
///
///
/// # Implements
///
/// [`ValidatorExt`][trait@crate::prelude::ValidatorExt]
#[doc(alias = "AsValidator")]
pub struct Validator(Object<ffi::AsValidator, ffi::AsValidatorClass>);
match fn {
type_ => || ffi::as_validator_get_type(),
}
}
impl Validator {
pub const NONE: Option<&'static Validator> = None;
/// Creates a new [`Validator`][crate::Validator].
///
/// # Returns
///
/// an [`Validator`][crate::Validator]
#[doc(alias = "as_validator_new")]
pub fn new() -> Validator {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::as_validator_new()) }
}
}
impl Default for Validator {
fn default() -> Self {
Self::new()
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::Validator>> Sealed for T {}
}
/// Trait containing all [`struct@Validator`] methods.
///
/// # Implementors
///
/// [`Validator`][struct@crate::Validator]
pub trait ValidatorExt: IsA<Validator> + sealed::Sealed + 'static {
/// Override the severity of a selected tag. For most tags, the severity
/// can not be lowered to a value that makes a validation
/// that would otherwise fail pass (so e.g. an ERROR can not become an INFO).
/// Some tags are explicitly allowed to have their severity lowered to enable
/// validation of e.g. incomplete metadata during development.
/// Increasing the severity of any tag is always allowed.
/// ## `tag`
/// the issue tag to override, e.g. "release-time-missing"
/// ## `severity_override`
/// the new severity for the tag.
#[doc(alias = "as_validator_add_override")]
fn add_override(&self, tag: &str, severity_override: IssueSeverity) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::as_validator_add_override(
self.as_ref().to_glib_none().0,
tag.to_glib_none().0,
severity_override.into_glib(),
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Add release metadata explicitly from bytes.
/// ## `release_fname`
/// File basename of the release metadata file to add.
/// ## `release_metadata`
/// Data of the release metadata file.
#[doc(alias = "as_validator_add_release_bytes")]
fn add_release_bytes(
&self,
release_fname: &str,
release_metadata: &glib::Bytes,
) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::as_validator_add_release_bytes(
self.as_ref().to_glib_none().0,
release_fname.to_glib_none().0,
release_metadata.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))
}
}
}
/// Add a release metadata file to the validation process.
/// ## `release_file`
/// Release metadata file to add.
#[doc(alias = "as_validator_add_release_file")]
fn add_release_file(&self, release_file: &impl IsA<gio::File>) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::as_validator_add_release_file(
self.as_ref().to_glib_none().0,
release_file.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))
}
}
}
/// Check the current registered values again and return [`true`]
/// if no issues were found that would make the previously validated
/// files fail validation.
///
/// Usually you do not need to call this function explicitly, as
/// the as_validator_validate_* functions will already return whether
/// data was valid as return value.
///
/// # Returns
///
/// [`true`] if previously validated files were valid.
#[doc(alias = "as_validator_check_success")]
fn check_success(&self) -> bool {
unsafe {
from_glib(ffi::as_validator_check_success(
self.as_ref().to_glib_none().0,
))
}
}
/// Clear all release information that was explicitly added to the
/// validation process.
#[doc(alias = "as_validator_clear_release_data")]
fn clear_release_data(&self) {
unsafe {
ffi::as_validator_clear_release_data(self.as_ref().to_glib_none().0);
}
}
///
/// # Returns
///
/// [`true`] in case we allow network access.
#[doc(alias = "as_validator_get_allow_net")]
#[doc(alias = "get_allow_net")]
fn allows_net(&self) -> bool {
unsafe {
from_glib(ffi::as_validator_get_allow_net(
self.as_ref().to_glib_none().0,
))
}
}
/// Get the number of files for which issues have been found.
///
/// # Returns
///
/// The number of files that have issues.
#[doc(alias = "as_validator_get_issue_files_count")]
#[doc(alias = "get_issue_files_count")]
fn issue_files_count(&self) -> u32 {
unsafe { ffi::as_validator_get_issue_files_count(self.as_ref().to_glib_none().0) }
}
/// Get a list of found metadata format issues.
///
/// # Returns
///
/// a list of [`ValidatorIssue`][crate::ValidatorIssue] instances, free with `g_list_free()`
#[doc(alias = "as_validator_get_issues")]
#[doc(alias = "get_issues")]
fn issues(&self) -> Vec<ValidatorIssue> {
unsafe {
FromGlibPtrContainer::from_glib_container(ffi::as_validator_get_issues(
self.as_ref().to_glib_none().0,
))
}
}
//#[doc(alias = "as_validator_get_issues_per_file")]
//#[doc(alias = "get_issues_per_file")]
//fn issues_per_file(&self) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 606 } {
// unsafe { TODO: call ffi:as_validator_get_issues_per_file() }
//}
#[doc(alias = "as_validator_get_report_yaml")]
#[doc(alias = "get_report_yaml")]
fn report_yaml(&self) -> Result<glib::GString, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::as_validator_get_report_yaml(self.as_ref().to_glib_none().0, &mut error);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
///
/// # Returns
///
/// [`true`] in case we are in strict mode and consider any issues as fatal.
#[doc(alias = "as_validator_get_strict")]
#[doc(alias = "get_strict")]
fn is_strict(&self) -> bool {
unsafe { from_glib(ffi::as_validator_get_strict(self.as_ref().to_glib_none().0)) }
}
/// Get the explanatory text for a given issue tag.
///
/// # Returns
///
/// Explanation text.
#[doc(alias = "as_validator_get_tag_explanation")]
#[doc(alias = "get_tag_explanation")]
fn tag_explanation(&self, tag: &str) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::as_validator_get_tag_explanation(
self.as_ref().to_glib_none().0,
tag.to_glib_none().0,
))
}
}
/// Get the severity for a given issue tag.
///
/// # Returns
///
/// The [`IssueSeverity`][crate::IssueSeverity]
#[doc(alias = "as_validator_get_tag_severity")]
#[doc(alias = "get_tag_severity")]
fn tag_severity(&self, tag: &str) -> IssueSeverity {
unsafe {
from_glib(ffi::as_validator_get_tag_severity(
self.as_ref().to_glib_none().0,
tag.to_glib_none().0,
))
}
}
/// Get an array of all tags known to the validator.
///
/// # Returns
///
/// A string array of tags
#[doc(alias = "as_validator_get_tags")]
#[doc(alias = "get_tags")]
fn tags(&self) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::as_validator_get_tags(
self.as_ref().to_glib_none().0,
))
}
}
/// If set to [`true`], the validator will be allowed to connect
/// to the internet to e.g. check URLs for validity.
/// ## `value`
/// [`true`] if remote URLs should be checked for availability.
#[doc(alias = "as_validator_set_allow_net")]
fn set_allow_net(&self, value: bool) {
unsafe {
ffi::as_validator_set_allow_net(self.as_ref().to_glib_none().0, value.into_glib());
}
}
/// Enable or disable strict mode. In strict mode, any found issue will result
/// in a failed validation (except for issues of "pedantic" severity).
/// Otherwise, only a "warning" or "error" will cause the validation to fail.
/// ## `is_strict`
/// [`true`] to enable strict mode.
#[doc(alias = "as_validator_set_strict")]
fn set_strict(&self, is_strict: bool) {
unsafe {
ffi::as_validator_set_strict(self.as_ref().to_glib_none().0, is_strict.into_glib());
}
}
/// Validate AppStream XML data from a byte array.
/// Remember to run `as_validator_clear_issues` if you do not want previous
/// validation runs to affect the outcome of this validation.
/// ## `metadata`
/// XML metadata as [`glib::Bytes`][crate::glib::Bytes].
///
/// # Returns
///
/// [`true`] if bytes validated successfully.
#[doc(alias = "as_validator_validate_bytes")]
fn validate_bytes(&self, metadata: &glib::Bytes) -> bool {
unsafe {
from_glib(ffi::as_validator_validate_bytes(
self.as_ref().to_glib_none().0,
metadata.to_glib_none().0,
))
}
}
/// Validate AppStream XML data.
/// ## `metadata`
/// XML metadata.
///
/// # Returns
///
/// [`true`] if data validated successfully.
#[doc(alias = "as_validator_validate_data")]
fn validate_data(&self, metadata: &str) -> bool {
unsafe {
from_glib(ffi::as_validator_validate_data(
self.as_ref().to_glib_none().0,
metadata.to_glib_none().0,
))
}
}
/// Validate an AppStream XML file.
/// ## `metadata_file`
/// An AppStream XML file.
///
/// # Returns
///
/// [`true`] if file validated successfully.
#[doc(alias = "as_validator_validate_file")]
fn validate_file(&self, metadata_file: &impl IsA<gio::File>) -> bool {
unsafe {
from_glib(ffi::as_validator_validate_file(
self.as_ref().to_glib_none().0,
metadata_file.as_ref().to_glib_none().0,
))
}
}
/// Validate a full directory tree for issues in AppStream metadata.
/// ## `root_dir`
/// The root directory of the filesystem tree that should be validated.
///
/// # Returns
///
/// [`true`] if file validated successfully.
#[doc(alias = "as_validator_validate_tree")]
fn validate_tree(&self, root_dir: &str) -> bool {
unsafe {
from_glib(ffi::as_validator_validate_tree(
self.as_ref().to_glib_none().0,
root_dir.to_glib_none().0,
))
}
}
}
impl<O: IsA<Validator>> ValidatorExt for O {}