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
// This file was generated by gir (https://github.com/gtk-rs/gir @ fe7a6ff+)
// from gir-files (https://github.com/gtk-rs/gir-files @ b215ee8)
// DO NOT EDIT

use FormatOptions;
use ParamList;
use ParserOptions;
use ffi;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// A data structure representing a Content-Type.
    ///
    /// # Implements
    ///
    /// [`ContentTypeExt`](trait.ContentTypeExt.html)
    pub struct ContentType(Object<ffi::GMimeContentType, ffi::GMimeContentTypeClass>);

    match fn {
        get_type => || ffi::g_mime_content_type_get_type(),
    }
}

impl ContentType {
    /// Creates a Content-Type object with type `type_` and subtype `subtype`.
    /// ## `type_`
    /// the MIME type or `None` for the default value
    /// ## `subtype`
    /// the MIME subtype or `None` for the default value
    ///
    /// # Returns
    ///
    /// a new `ContentType` object.
    pub fn new(type_: &str, subtype: &str) -> ContentType {
        unsafe {
            from_glib_full(ffi::g_mime_content_type_new(type_.to_glib_none().0, subtype.to_glib_none().0))
        }
    }

    /// Parses the input string into a `ContentType` object.
    /// ## `options`
    /// a `ParserOptions` or `None`
    /// ## `str`
    /// input string containing a content-type (and params)
    ///
    /// # Returns
    ///
    /// a new `ContentType` object.
    pub fn parse<'a, P: Into<Option<&'a ParserOptions>>>(options: P, str: &str) -> Option<ContentType> {
        let options = options.into();
        unsafe {
            from_glib_full(ffi::g_mime_content_type_parse(mut_override(options.to_glib_none().0), str.to_glib_none().0))
        }
    }
}

/// Trait containing all `ContentType` methods.
///
/// # Implementors
///
/// [`ContentType`](struct.ContentType.html)
pub trait ContentTypeExt {
    /// Encodes the Content-Disposition header.
    /// ## `options`
    /// a `FormatOptions` or `None`
    ///
    /// # Returns
    ///
    /// a new string containing the encoded header value.
    fn encode<'a, P: Into<Option<&'a FormatOptions>>>(&self, options: P) -> Option<String>;

    /// Gets the Content-Type's media sub-type.
    ///
    /// # Returns
    ///
    /// the Content-Type's media sub-type.
    fn get_media_subtype(&self) -> Option<String>;

    /// Gets the Content-Type's media type.
    ///
    /// # Returns
    ///
    /// the Content-Type's media type.
    fn get_media_type(&self) -> Option<String>;

    /// Allocates a string buffer containing the type and subtype defined
    /// by the `self`.
    ///
    /// # Returns
    ///
    /// an allocated string containing the type and subtype of the
    /// content-type in the format: type/subtype.
    fn get_mime_type(&self) -> Option<String>;

    /// Gets the parameter value specified by `name` if it's available.
    /// ## `name`
    /// parameter name (aka attribute)
    ///
    /// # Returns
    ///
    /// the value of the requested parameter or `None` if the
    /// parameter is not set. If the parameter is set, the returned string
    /// will be in UTF-8.
    fn get_parameter(&self, name: &str) -> Option<String>;

    /// Gets the Content-Type's parameter list.
    ///
    /// # Returns
    ///
    /// the Content-Type's parameter list.
    fn get_parameters(&self) -> Option<ParamList>;

    /// Compares the given type and subtype with that of the given mime
    /// type object.
    /// ## `type_`
    /// MIME type to compare against
    /// ## `subtype`
    /// MIME subtype to compare against
    ///
    /// # Returns
    ///
    /// `true` if the MIME types match or `false` otherwise. You may
    /// use "*" in place of `type_` and/or `subtype` as a wilcard.
    fn is_type(&self, type_: &str, subtype: &str) -> bool;

    /// Sets the Content-Type's media subtype.
    /// ## `subtype`
    /// media subtype
    fn set_media_subtype(&self, subtype: &str);

    /// Sets the Content-Type's media type.
    /// ## `type_`
    /// media type
    fn set_media_type(&self, type_: &str);

    /// Sets a parameter on the Content-Type.
    ///
    /// Note: The `name` should be in US-ASCII while the `value` should be in
    /// UTF-8.
    /// ## `name`
    /// parameter name (aka attribute)
    /// ## `value`
    /// parameter value
    fn set_parameter(&self, name: &str, value: &str);
}

impl<O: IsA<ContentType>> ContentTypeExt for O {
    fn encode<'a, P: Into<Option<&'a FormatOptions>>>(&self, options: P) -> Option<String> {
        let options = options.into();
        unsafe {
            from_glib_full(ffi::g_mime_content_type_encode(self.to_glib_none().0, mut_override(options.to_glib_none().0)))
        }
    }

    fn get_media_subtype(&self) -> Option<String> {
        unsafe {
            from_glib_none(ffi::g_mime_content_type_get_media_subtype(self.to_glib_none().0))
        }
    }

    fn get_media_type(&self) -> Option<String> {
        unsafe {
            from_glib_none(ffi::g_mime_content_type_get_media_type(self.to_glib_none().0))
        }
    }

    fn get_mime_type(&self) -> Option<String> {
        unsafe {
            from_glib_full(ffi::g_mime_content_type_get_mime_type(self.to_glib_none().0))
        }
    }

    fn get_parameter(&self, name: &str) -> Option<String> {
        unsafe {
            from_glib_none(ffi::g_mime_content_type_get_parameter(self.to_glib_none().0, name.to_glib_none().0))
        }
    }

    fn get_parameters(&self) -> Option<ParamList> {
        unsafe {
            from_glib_none(ffi::g_mime_content_type_get_parameters(self.to_glib_none().0))
        }
    }

    fn is_type(&self, type_: &str, subtype: &str) -> bool {
        unsafe {
            from_glib(ffi::g_mime_content_type_is_type(self.to_glib_none().0, type_.to_glib_none().0, subtype.to_glib_none().0))
        }
    }

    fn set_media_subtype(&self, subtype: &str) {
        unsafe {
            ffi::g_mime_content_type_set_media_subtype(self.to_glib_none().0, subtype.to_glib_none().0);
        }
    }

    fn set_media_type(&self, type_: &str) {
        unsafe {
            ffi::g_mime_content_type_set_media_type(self.to_glib_none().0, type_.to_glib_none().0);
        }
    }

    fn set_parameter(&self, name: &str, value: &str) {
        unsafe {
            ffi::g_mime_content_type_set_parameter(self.to_glib_none().0, name.to_glib_none().0, value.to_glib_none().0);
        }
    }
}