gio/auto/
icon.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
// 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::ffi;
use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// `GIcon` is a very minimal interface for icons. It provides functions
    /// for checking the equality of two icons, hashing of icons and
    /// serializing an icon to and from strings.
    ///
    /// `GIcon` does not provide the actual pixmap for the icon as this is out
    /// of GIO's scope, however implementations of `GIcon` may contain the name
    /// of an icon (see [`ThemedIcon`][crate::ThemedIcon]), or the path to an icon
    /// (see [`LoadableIcon`][crate::LoadableIcon]).
    ///
    /// To obtain a hash of a `GIcon`, see `Gio::Icon::hash()`.
    ///
    /// To check if two `GIcon`s are equal, see `Gio::Icon::equal()`.
    ///
    /// For serializing a `GIcon`, use [`IconExt::serialize()`][crate::prelude::IconExt::serialize()] and
    /// [`deserialize()`][Self::deserialize()].
    ///
    /// If you want to consume `GIcon` (for example, in a toolkit) you must
    /// be prepared to handle at least the three following cases:
    /// [`LoadableIcon`][crate::LoadableIcon], [`ThemedIcon`][crate::ThemedIcon] and [`EmblemedIcon`][crate::EmblemedIcon].
    /// It may also make sense to have fast-paths for other cases (like handling
    /// [`GdkPixbuf`](https://docs.gtk.org/gdk-pixbuf/class.Pixbuf.html) directly,
    /// for example) but all compliant `GIcon` implementations outside of GIO must
    /// implement [`LoadableIcon`][crate::LoadableIcon].
    ///
    /// If your application or library provides one or more `GIcon`
    /// implementations you need to ensure that your new implementation also
    /// implements [`LoadableIcon`][crate::LoadableIcon].  Additionally, you must provide an
    /// implementation of [`IconExt::serialize()`][crate::prelude::IconExt::serialize()] that gives a result that is
    /// understood by [`deserialize()`][Self::deserialize()], yielding one of the built-in
    /// icon types.
    ///
    /// # Implements
    ///
    /// [`IconExt`][trait@crate::prelude::IconExt]
    #[doc(alias = "GIcon")]
    pub struct Icon(Interface<ffi::GIcon, ffi::GIconIface>);

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

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

    /// Deserializes a #GIcon previously serialized using g_icon_serialize().
    /// ## `value`
    /// a #GVariant created with g_icon_serialize()
    ///
    /// # Returns
    ///
    /// a #GIcon, or [`None`] when deserialization fails.
    #[doc(alias = "g_icon_deserialize")]
    pub fn deserialize(value: &glib::Variant) -> Option<Icon> {
        unsafe { from_glib_full(ffi::g_icon_deserialize(value.to_glib_none().0)) }
    }

    /// Generate a #GIcon instance from @str. This function can fail if
    /// @str is not valid - see g_icon_to_string() for discussion.
    ///
    /// If your application or library provides one or more #GIcon
    /// implementations you need to ensure that each #GType is registered
    /// with the type system prior to calling g_icon_new_for_string().
    /// ## `str`
    /// A string obtained via g_icon_to_string().
    ///
    /// # Returns
    ///
    /// An object implementing the #GIcon
    ///          interface or [`None`] if @error is set.
    #[doc(alias = "g_icon_new_for_string")]
    #[doc(alias = "new_for_string")]
    pub fn for_string(str: &str) -> Result<Icon, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_icon_new_for_string(str.to_glib_none().0, &mut error);
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }
}

/// Trait containing all [`struct@Icon`] methods.
///
/// # Implementors
///
/// [`BytesIcon`][struct@crate::BytesIcon], [`Emblem`][struct@crate::Emblem], [`EmblemedIcon`][struct@crate::EmblemedIcon], [`FileIcon`][struct@crate::FileIcon], [`Icon`][struct@crate::Icon], [`LoadableIcon`][struct@crate::LoadableIcon], [`ThemedIcon`][struct@crate::ThemedIcon]
pub trait IconExt: IsA<Icon> + 'static {
    #[doc(alias = "g_icon_equal")]
    fn equal(&self, icon2: Option<&impl IsA<Icon>>) -> bool {
        unsafe {
            from_glib(ffi::g_icon_equal(
                self.as_ref().to_glib_none().0,
                icon2.map(|p| p.as_ref()).to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_icon_hash")]
    fn hash(&self) -> u32 {
        unsafe {
            ffi::g_icon_hash(
                ToGlibPtr::<*mut ffi::GIcon>::to_glib_none(self.as_ref()).0
                    as glib::ffi::gconstpointer,
            )
        }
    }

    /// Serializes a #GIcon into a #GVariant. An equivalent #GIcon can be retrieved
    /// back by calling g_icon_deserialize() on the returned value.
    /// As serialization will avoid using raw icon data when possible, it only
    /// makes sense to transfer the #GVariant between processes on the same machine,
    /// (as opposed to over the network), and within the same file system namespace.
    ///
    /// # Returns
    ///
    /// a #GVariant, or [`None`] when serialization fails. The #GVariant will not be floating.
    #[doc(alias = "g_icon_serialize")]
    fn serialize(&self) -> Option<glib::Variant> {
        unsafe { from_glib_full(ffi::g_icon_serialize(self.as_ref().to_glib_none().0)) }
    }

    /// Generates a textual representation of @self that can be used for
    /// serialization such as when passing @self to a different process or
    /// saving it to persistent storage. Use g_icon_new_for_string() to
    /// get @self back from the returned string.
    ///
    /// The encoding of the returned string is proprietary to #GIcon except
    /// in the following two cases
    ///
    /// - If @self is a #GFileIcon, the returned string is a native path
    ///   (such as `/path/to/my icon.png`) without escaping
    ///   if the #GFile for @self is a native file.  If the file is not
    ///   native, the returned string is the result of g_file_get_uri()
    ///   (such as `sftp://path/to/my`20icon``).
    ///
    /// - If @self is a #GThemedIcon with exactly one name and no fallbacks,
    ///   the encoding is simply the name (such as `network-server`).
    ///
    /// # Returns
    ///
    /// An allocated NUL-terminated UTF8 string or
    /// [`None`] if @self can't be serialized. Use g_free() to free.
    #[doc(alias = "g_icon_to_string")]
    fn to_string(&self) -> Option<glib::GString> {
        unsafe { from_glib_full(ffi::g_icon_to_string(self.as_ref().to_glib_none().0)) }
    }
}

impl<O: IsA<Icon>> IconExt for O {}