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

use crate::Icon;
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::{boxed::Box as Box_, fmt, mem::transmute};

glib::wrapper! {
    /// [`ThemedIcon`][crate::ThemedIcon] is an implementation of [`Icon`][crate::Icon] that supports icon themes.
    /// [`ThemedIcon`][crate::ThemedIcon] contains a list of all of the icons present in an icon
    /// theme, so that icons can be looked up quickly. [`ThemedIcon`][crate::ThemedIcon] does
    /// not provide actual pixmaps for icons, just the icon names.
    /// Ideally something like `gtk_icon_theme_choose_icon()` should be used to
    /// resolve the list of names so that fallback icons work nicely with
    /// themes that inherit other themes.
    ///
    /// ## Properties
    ///
    ///
    /// #### `name`
    ///  The icon name.
    ///
    /// Writeable | Construct Only
    ///
    ///
    /// #### `names`
    ///  A [`None`]-terminated array of icon names.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `use-default-fallbacks`
    ///  Whether to use the default fallbacks found by shortening the icon name
    /// at '-' characters. If the "names" array has more than one element,
    /// ignores any past the first.
    ///
    /// For example, if the icon name was "gnome-dev-cdrom-audio", the array
    /// would become
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    /// {
    ///   "gnome-dev-cdrom-audio",
    ///   "gnome-dev-cdrom",
    ///   "gnome-dev",
    ///   "gnome",
    ///   NULL
    /// };
    /// ```
    ///
    /// Readable | Writeable | Construct Only
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`], [`IconExt`][trait@crate::prelude::IconExt]
    #[doc(alias = "GThemedIcon")]
    pub struct ThemedIcon(Object<ffi::GThemedIcon, ffi::GThemedIconClass>) @implements Icon;

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

impl ThemedIcon {
    /// Creates a new themed icon for `iconname`.
    /// ## `iconname`
    /// a string containing an icon name.
    ///
    /// # Returns
    ///
    /// a new [`ThemedIcon`][crate::ThemedIcon].
    #[doc(alias = "g_themed_icon_new")]
    pub fn new(iconname: &str) -> ThemedIcon {
        unsafe { from_glib_full(ffi::g_themed_icon_new(iconname.to_glib_none().0)) }
    }

    /// Creates a new themed icon for `iconnames`.
    /// ## `iconnames`
    /// an array of strings containing icon names.
    ///
    /// # Returns
    ///
    /// a new [`ThemedIcon`][crate::ThemedIcon]
    #[doc(alias = "g_themed_icon_new_from_names")]
    #[doc(alias = "new_from_names")]
    pub fn from_names(iconnames: &[&str]) -> ThemedIcon {
        let len = iconnames.len() as _;
        unsafe {
            from_glib_full(ffi::g_themed_icon_new_from_names(
                iconnames.to_glib_none().0,
                len,
            ))
        }
    }

    /// Creates a new themed icon for `iconname`, and all the names
    /// that can be created by shortening `iconname` at '-' characters.
    ///
    /// In the following example, `icon1` and `icon2` are equivalent:
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    /// const char *names[] = {
    ///   "gnome-dev-cdrom-audio",
    ///   "gnome-dev-cdrom",
    ///   "gnome-dev",
    ///   "gnome"
    /// };
    ///
    /// icon1 = g_themed_icon_new_from_names (names, 4);
    /// icon2 = g_themed_icon_new_with_default_fallbacks ("gnome-dev-cdrom-audio");
    /// ```
    /// ## `iconname`
    /// a string containing an icon name
    ///
    /// # Returns
    ///
    /// a new [`ThemedIcon`][crate::ThemedIcon].
    #[doc(alias = "g_themed_icon_new_with_default_fallbacks")]
    #[doc(alias = "new_with_default_fallbacks")]
    pub fn with_default_fallbacks(iconname: &str) -> ThemedIcon {
        unsafe {
            from_glib_full(ffi::g_themed_icon_new_with_default_fallbacks(
                iconname.to_glib_none().0,
            ))
        }
    }

    /// Append a name to the list of icons from within `self`.
    ///
    /// Note that doing so invalidates the hash computed by prior calls
    /// to `g_icon_hash()`.
    /// ## `iconname`
    /// name of icon to append to list of icons from within `self`.
    #[doc(alias = "g_themed_icon_append_name")]
    pub fn append_name(&self, iconname: &str) {
        unsafe {
            ffi::g_themed_icon_append_name(self.to_glib_none().0, iconname.to_glib_none().0);
        }
    }

    /// Gets the names of icons from within `self`.
    ///
    /// # Returns
    ///
    /// a list of icon names.
    #[doc(alias = "g_themed_icon_get_names")]
    #[doc(alias = "get_names")]
    pub fn names(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(ffi::g_themed_icon_get_names(
                self.to_glib_none().0,
            ))
        }
    }

    /// Prepend a name to the list of icons from within `self`.
    ///
    /// Note that doing so invalidates the hash computed by prior calls
    /// to `g_icon_hash()`.
    /// ## `iconname`
    /// name of icon to prepend to list of icons from within `self`.
    #[doc(alias = "g_themed_icon_prepend_name")]
    pub fn prepend_name(&self, iconname: &str) {
        unsafe {
            ffi::g_themed_icon_prepend_name(self.to_glib_none().0, iconname.to_glib_none().0);
        }
    }

    /// Whether to use the default fallbacks found by shortening the icon name
    /// at '-' characters. If the "names" array has more than one element,
    /// ignores any past the first.
    ///
    /// For example, if the icon name was "gnome-dev-cdrom-audio", the array
    /// would become
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    /// {
    ///   "gnome-dev-cdrom-audio",
    ///   "gnome-dev-cdrom",
    ///   "gnome-dev",
    ///   "gnome",
    ///   NULL
    /// };
    /// ```
    #[doc(alias = "use-default-fallbacks")]
    pub fn uses_default_fallbacks(&self) -> bool {
        ObjectExt::property(self, "use-default-fallbacks")
    }

    #[doc(alias = "names")]
    pub fn connect_names_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_names_trampoline<F: Fn(&ThemedIcon) + 'static>(
            this: *mut ffi::GThemedIcon,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::names\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_names_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for ThemedIcon {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("ThemedIcon")
    }
}