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
// 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 Param;
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 list of Content-Type or Content-Disposition parameters.
    ///
    /// # Implements
    ///
    /// [`ParamListExt`](trait.ParamListExt.html)
    pub struct ParamList(Object<ffi::GMimeParamList, ffi::GMimeParamListClass>);

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

impl ParamList {
    /// Creates a new Content-Type or Content-Disposition parameter list.
    ///
    /// # Returns
    ///
    /// a new `ParamList`.
    pub fn new() -> ParamList {
        unsafe {
            from_glib_full(ffi::g_mime_param_list_new())
        }
    }

    /// Parses the input string into a parameter list.
    /// ## `options`
    /// a `ParserOptions` or `None`
    /// ## `str`
    /// a string to parse
    ///
    /// # Returns
    ///
    /// a new `ParamList`.
    pub fn parse(options: &mut ParserOptions, str: &str) -> Option<ParamList> {
        unsafe {
            from_glib_full(ffi::g_mime_param_list_parse(options.to_glib_none_mut().0, str.to_glib_none().0))
        }
    }
}

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

/// Trait containing all `ParamList` methods.
///
/// # Implementors
///
/// [`ParamList`](struct.ParamList.html)
pub trait ParamListExt {
    /// Clears the list of parameters.
    fn clear(&self);

    //fn encode(&self, options: &mut FormatOptions, fold: bool, str: /*Ignored*/&mut glib::String);

    /// Gets the `Param` with the given `name`.
    /// ## `name`
    /// the name of the parameter
    ///
    /// # Returns
    ///
    /// the requested `Param`.
    fn get_parameter(&self, name: &str) -> Option<Param>;

    /// Gets the `Param` at the specified `index`.
    /// ## `index`
    /// the index of the requested parameter
    ///
    /// # Returns
    ///
    /// the `Param` at the specified index.
    fn get_parameter_at(&self, index: i32) -> Option<Param>;

    /// Gets the length of the list.
    ///
    /// # Returns
    ///
    /// the number of `Param` items in the list.
    fn length(&self) -> i32;

    /// Removes a parameter from the `ParamList`.
    /// ## `name`
    /// the name of the parameter
    ///
    /// # Returns
    ///
    /// `true` if the specified parameter was removed or `false` otherwise.
    fn remove(&self, name: &str) -> bool;

    /// Removes a `Param` from the `ParamList` at the specified index.
    /// ## `index`
    /// index of the param to remove
    ///
    /// # Returns
    ///
    /// `true` if a `Param` was removed or `false` otherwise.
    fn remove_at(&self, index: i32) -> bool;

    /// Sets the specified parameter to `value`.
    /// ## `name`
    /// The name of the parameter
    /// ## `value`
    /// The parameter value
    fn set_parameter(&self, name: &str, value: &str);
}

impl<O: IsA<ParamList>> ParamListExt for O {
    fn clear(&self) {
        unsafe {
            ffi::g_mime_param_list_clear(self.to_glib_none().0);
        }
    }

    //fn encode(&self, options: &mut FormatOptions, fold: bool, str: /*Ignored*/&mut glib::String) {
    //    unsafe { TODO: call ffi::g_mime_param_list_encode() }
    //}

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

    fn get_parameter_at(&self, index: i32) -> Option<Param> {
        unsafe {
            from_glib_none(ffi::g_mime_param_list_get_parameter_at(self.to_glib_none().0, index))
        }
    }

    fn length(&self) -> i32 {
        unsafe {
            ffi::g_mime_param_list_length(self.to_glib_none().0)
        }
    }

    fn remove(&self, name: &str) -> bool {
        unsafe {
            from_glib(ffi::g_mime_param_list_remove(self.to_glib_none().0, name.to_glib_none().0))
        }
    }

    fn remove_at(&self, index: i32) -> bool {
        unsafe {
            from_glib(ffi::g_mime_param_list_remove_at(self.to_glib_none().0, index))
        }
    }

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