libappstream/auto/
context.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
// 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, FormatStyle, FormatVersion, ValueFlags};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    ///
    ///
    /// # Implements
    ///
    /// [`ContextExt`][trait@crate::prelude::ContextExt]
    #[doc(alias = "AsContext")]
    pub struct Context(Object<ffi::AsContext, ffi::AsContextClass>);

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

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

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

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

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

/// Trait containing all [`struct@Context`] methods.
///
/// # Implementors
///
/// [`Context`][struct@crate::Context]
pub trait ContextExt: IsA<Context> + sealed::Sealed + 'static {
    ///
    /// # Returns
    ///
    /// The name of the file the data originates from.
    #[doc(alias = "as_context_get_filename")]
    #[doc(alias = "get_filename")]
    fn filename(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::as_context_get_filename(self.as_ref().to_glib_none().0)) }
    }

    ///
    /// # Returns
    ///
    /// The AppStream format version.
    #[doc(alias = "as_context_get_format_version")]
    #[doc(alias = "get_format_version")]
    fn format_version(&self) -> FormatVersion {
        unsafe {
            from_glib(ffi::as_context_get_format_version(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// The active locale in BCP47 format.
    #[doc(alias = "as_context_get_locale")]
    #[doc(alias = "get_locale")]
    fn locale(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::as_context_get_locale(self.as_ref().to_glib_none().0)) }
    }

    ///
    /// # Returns
    ///
    /// [`true`] if all locale should be parsed.
    #[doc(alias = "as_context_get_locale_use_all")]
    #[doc(alias = "get_locale_use_all")]
    fn is_locale_use_all(&self) -> bool {
        unsafe {
            from_glib(ffi::as_context_get_locale_use_all(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// The media base URL.
    #[doc(alias = "as_context_get_media_baseurl")]
    #[doc(alias = "get_media_baseurl")]
    fn media_baseurl(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::as_context_get_media_baseurl(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// The data origin.
    #[doc(alias = "as_context_get_origin")]
    #[doc(alias = "get_origin")]
    fn origin(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::as_context_get_origin(self.as_ref().to_glib_none().0)) }
    }

    ///
    /// # Returns
    ///
    /// The data priority.
    #[doc(alias = "as_context_get_priority")]
    #[doc(alias = "get_priority")]
    fn priority(&self) -> i32 {
        unsafe { ffi::as_context_get_priority(self.as_ref().to_glib_none().0) }
    }

    ///
    /// # Returns
    ///
    /// The document style.
    #[doc(alias = "as_context_get_style")]
    #[doc(alias = "get_style")]
    fn style(&self) -> FormatStyle {
        unsafe { from_glib(ffi::as_context_get_style(self.as_ref().to_glib_none().0)) }
    }

    ///
    /// # Returns
    ///
    /// The [`ValueFlags`][crate::ValueFlags] that are set on `cpt`.
    #[doc(alias = "as_context_get_value_flags")]
    #[doc(alias = "get_value_flags")]
    fn value_flags(&self) -> ValueFlags {
        unsafe {
            from_glib(ffi::as_context_get_value_flags(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// [`true`] if a media base URL is set.
    #[doc(alias = "as_context_has_media_baseurl")]
    fn has_media_baseurl(&self) -> bool {
        unsafe {
            from_glib(ffi::as_context_has_media_baseurl(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Sets the file name we are loading data from.
    /// ## `fname`
    /// the new file name.
    #[doc(alias = "as_context_set_filename")]
    fn set_filename(&self, fname: &str) {
        unsafe {
            ffi::as_context_set_filename(self.as_ref().to_glib_none().0, fname.to_glib_none().0);
        }
    }

    /// Sets the AppStream format version.
    /// ## `ver`
    /// the new format version.
    #[doc(alias = "as_context_set_format_version")]
    fn set_format_version(&self, ver: FormatVersion) {
        unsafe {
            ffi::as_context_set_format_version(self.as_ref().to_glib_none().0, ver.into_glib());
        }
    }

    /// Sets the active locale.
    /// If the magic value "ALL" is used, the current system locale will be used
    /// for data reading, but when writing data all locale will be written.
    /// ## `locale`
    /// a POSIX or BCP47 locale, or [`None`]. e.g. "en_GB"
    #[doc(alias = "as_context_set_locale")]
    fn set_locale(&self, locale: Option<&str>) {
        unsafe {
            ffi::as_context_set_locale(self.as_ref().to_glib_none().0, locale.to_glib_none().0);
        }
    }

    /// Sets the media base URL.
    /// ## `value`
    /// the new value.
    #[doc(alias = "as_context_set_media_baseurl")]
    fn set_media_baseurl(&self, value: &str) {
        unsafe {
            ffi::as_context_set_media_baseurl(
                self.as_ref().to_glib_none().0,
                value.to_glib_none().0,
            );
        }
    }

    /// Sets the data origin.
    /// ## `value`
    /// the new value.
    #[doc(alias = "as_context_set_origin")]
    fn set_origin(&self, value: &str) {
        unsafe {
            ffi::as_context_set_origin(self.as_ref().to_glib_none().0, value.to_glib_none().0);
        }
    }

    /// Sets the data priority.
    /// ## `priority`
    /// the new priority.
    #[doc(alias = "as_context_set_priority")]
    fn set_priority(&self, priority: i32) {
        unsafe {
            ffi::as_context_set_priority(self.as_ref().to_glib_none().0, priority);
        }
    }

    /// Sets the AppStream document style.
    /// ## `style`
    /// the new document style.
    #[doc(alias = "as_context_set_style")]
    fn set_style(&self, style: FormatStyle) {
        unsafe {
            ffi::as_context_set_style(self.as_ref().to_glib_none().0, style.into_glib());
        }
    }

    /// ## `flags`
    /// [`ValueFlags`][crate::ValueFlags] to set on `cpt`.
    #[doc(alias = "as_context_set_value_flags")]
    fn set_value_flags(&self, flags: ValueFlags) {
        unsafe {
            ffi::as_context_set_value_flags(self.as_ref().to_glib_none().0, flags.into_glib());
        }
    }
}

impl<O: IsA<Context>> ContextExt for O {}