libappstream/auto/
content_rating.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
// 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, ContentRatingValue};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    ///
    ///
    /// # Implements
    ///
    /// [`ContentRatingExt`][trait@crate::prelude::ContentRatingExt]
    #[doc(alias = "AsContentRating")]
    pub struct ContentRating(Object<ffi::AsContentRating, ffi::AsContentRatingClass>);

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

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

    /// Creates a new [`ContentRating`][crate::ContentRating].
    ///
    /// # Returns
    ///
    /// a [`ContentRating`][crate::ContentRating]
    #[doc(alias = "as_content_rating_new")]
    pub fn new() -> ContentRating {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::as_content_rating_new()) }
    }

    /// Gets the highest [`ContentRatingValue`][crate::ContentRatingValue] which is allowed to be seen by the
    /// given Common Sense Media `age` for the given subsection `id`.
    ///
    /// For example, if the CSM age mappings for `violence-bloodshed` are:
    ///  * age ≥ 0 for [`ContentRatingValue::None`][crate::ContentRatingValue::None]
    ///  * age ≥ 9 for [`ContentRatingValue::Mild`][crate::ContentRatingValue::Mild]
    ///  * age ≥ 11 for [`ContentRatingValue::Moderate`][crate::ContentRatingValue::Moderate]
    ///  * age ≥ 18 for [`ContentRatingValue::Intense`][crate::ContentRatingValue::Intense]
    /// then calling this function with `violence-bloodshed` and `age` set to 17 would
    /// return [`ContentRatingValue::Moderate`][crate::ContentRatingValue::Moderate]. Calling it with age 18 would
    /// return [`ContentRatingValue::Intense`][crate::ContentRatingValue::Intense].
    /// ## `id`
    /// the subsection ID e.g. `violence-cartoon`
    /// ## `age`
    /// the CSM age
    ///
    /// # Returns
    ///
    /// the [`ContentRatingValue`][crate::ContentRatingValue], or [`ContentRatingValue::Unknown`][crate::ContentRatingValue::Unknown] if
    ///  unknown
    #[doc(alias = "as_content_rating_attribute_from_csm_age")]
    pub fn attribute_from_csm_age(id: &str, age: u32) -> ContentRatingValue {
        assert_initialized_main_thread!();
        unsafe {
            from_glib(ffi::as_content_rating_attribute_from_csm_age(
                id.to_glib_none().0,
                age,
            ))
        }
    }

    /// Get a human-readable description of what content would be expected to
    /// require the content rating attribute given by `id` and `value`.
    /// ## `id`
    /// the subsection ID e.g. `violence-cartoon`
    /// ## `value`
    /// the [`ContentRatingValue`][crate::ContentRatingValue], e.g. [`ContentRatingValue::Intense`][crate::ContentRatingValue::Intense]
    ///
    /// # Returns
    ///
    /// a human-readable description of `id` and `value`
    #[doc(alias = "as_content_rating_attribute_get_description")]
    pub fn attribute_get_description(id: &str, value: ContentRatingValue) -> Option<glib::GString> {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_none(ffi::as_content_rating_attribute_get_description(
                id.to_glib_none().0,
                value.into_glib(),
            ))
        }
    }

    /// Gets the Common Sense Media approved age for a specific rating level.
    /// ## `id`
    /// the subsection ID e.g. `violence-cartoon`
    /// ## `value`
    /// the [`ContentRatingValue`][crate::ContentRatingValue], e.g. [`ContentRatingValue::Intense`][crate::ContentRatingValue::Intense]
    ///
    /// # Returns
    ///
    /// The age in years, or 0 for no details.
    #[doc(alias = "as_content_rating_attribute_to_csm_age")]
    pub fn attribute_to_csm_age(id: &str, value: ContentRatingValue) -> u32 {
        assert_initialized_main_thread!();
        unsafe {
            ffi::as_content_rating_attribute_to_csm_age(id.to_glib_none().0, value.into_glib())
        }
    }

    /// Returns a list of all the valid OARS content rating attribute IDs as could
    /// be passed to [`ContentRatingExt::add_attribute()`][crate::prelude::ContentRatingExt::add_attribute()] or
    /// [`attribute_to_csm_age()`][Self::attribute_to_csm_age()].
    ///
    /// # Returns
    ///
    /// a [`None`]-terminated
    ///  array of IDs, to be freed with `g_free()` (the element values are owned by
    ///  libappstream and must not be freed)
    #[doc(alias = "as_content_rating_get_all_rating_ids")]
    #[doc(alias = "get_all_rating_ids")]
    pub fn all_rating_ids() -> Vec<glib::GString> {
        assert_initialized_main_thread!();
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::as_content_rating_get_all_rating_ids())
        }
    }
}

impl Default for ContentRating {
    fn default() -> Self {
        Self::new()
    }
}

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

/// Trait containing all [`struct@ContentRating`] methods.
///
/// # Implementors
///
/// [`ContentRating`][struct@crate::ContentRating]
pub trait ContentRatingExt: IsA<ContentRating> + sealed::Sealed + 'static {
    /// Adds an attribute value to the content rating.
    /// ## `id`
    /// a content rating ID, e.g. `money-gambling`.
    /// ## `value`
    /// a [`ContentRatingValue`][crate::ContentRatingValue], e.g. [`ContentRatingValue::Moderate`][crate::ContentRatingValue::Moderate].
    #[doc(alias = "as_content_rating_add_attribute")]
    fn add_attribute(&self, id: &str, value: ContentRatingValue) {
        unsafe {
            ffi::as_content_rating_add_attribute(
                self.as_ref().to_glib_none().0,
                id.to_glib_none().0,
                value.into_glib(),
            );
        }
    }

    /// Gets the content_rating kind.
    ///
    /// # Returns
    ///
    /// a string, e.g. "oars-1.0", or NULL
    #[doc(alias = "as_content_rating_get_kind")]
    #[doc(alias = "get_kind")]
    fn kind(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::as_content_rating_get_kind(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the lowest Common Sense Media approved age for the content_rating block.
    /// NOTE: these numbers are based on the data and descriptions available from
    /// https://www.commonsensemedia.org/about-us/our-mission/about-our-ratings and
    /// you may disagree with them.
    ///
    /// You're free to disagree with these, and of course you should use your own
    /// brain to work our if your child is able to cope with the concepts enumerated
    /// here. Some 13 year olds may be fine with the concept of mutilation of body
    /// parts; others may get nightmares.
    ///
    /// # Returns
    ///
    /// The age in years, 0 for no rating, or G_MAXUINT for no details.
    #[doc(alias = "as_content_rating_get_minimum_age")]
    #[doc(alias = "get_minimum_age")]
    fn minimum_age(&self) -> u32 {
        unsafe { ffi::as_content_rating_get_minimum_age(self.as_ref().to_glib_none().0) }
    }

    /// Gets the set of ratings IDs which are present in this `self`. An
    /// example of a ratings ID is `violence-bloodshed`.
    ///
    /// The IDs are returned in lexicographical order.
    ///
    /// # Returns
    ///
    /// [`None`]-terminated
    ///  array of ratings IDs; each ratings ID is owned by the [`ContentRating`][crate::ContentRating] and
    ///  must not be freed, but the container must be freed with `g_free()`
    #[doc(alias = "as_content_rating_get_rating_ids")]
    #[doc(alias = "get_rating_ids")]
    fn rating_ids(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::as_content_rating_get_rating_ids(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the value of a content rating key.
    /// ## `id`
    /// A ratings ID, e.g. `violence-bloodshed`.
    ///
    /// # Returns
    ///
    /// the [`ContentRatingValue`][crate::ContentRatingValue], or [`ContentRatingValue::Unknown`][crate::ContentRatingValue::Unknown]
    #[doc(alias = "as_content_rating_get_value")]
    #[doc(alias = "get_value")]
    fn value(&self, id: &str) -> ContentRatingValue {
        unsafe {
            from_glib(ffi::as_content_rating_get_value(
                self.as_ref().to_glib_none().0,
                id.to_glib_none().0,
            ))
        }
    }

    /// Sets the content rating kind.
    /// ## `kind`
    /// the rating kind, e.g. "oars-1.0"
    #[doc(alias = "as_content_rating_set_kind")]
    fn set_kind(&self, kind: &str) {
        unsafe {
            ffi::as_content_rating_set_kind(self.as_ref().to_glib_none().0, kind.to_glib_none().0);
        }
    }

    /// Sets the value of a content rating key.
    /// ## `id`
    /// A ratings ID, e.g. `violence-bloodshed`.
    /// ## `value`
    /// A [`ContentRatingValue`][crate::ContentRatingValue], e.g. [`ContentRatingValue::Intense`][crate::ContentRatingValue::Intense]
    #[doc(alias = "as_content_rating_set_value")]
    fn set_value(&self, id: &str, value: ContentRatingValue) {
        unsafe {
            ffi::as_content_rating_set_value(
                self.as_ref().to_glib_none().0,
                id.to_glib_none().0,
                value.into_glib(),
            );
        }
    }
}

impl<O: IsA<ContentRating>> ContentRatingExt for O {}