gkdbus: Fix underflow and unreachable code bug
[platform/upstream/glib.git] / gio / gicon.h
1 /* GIO - GLib Input, Output and Streaming Library
2  *
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
5  * SPDX-License-Identifier: LGPL-2.1-or-later
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General
18  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #ifndef __G_ICON_H__
24 #define __G_ICON_H__
25
26 #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
27 #error "Only <gio/gio.h> can be included directly."
28 #endif
29
30 #include <gio/giotypes.h>
31
32 G_BEGIN_DECLS
33
34 #define G_TYPE_ICON            (g_icon_get_type ())
35 #define G_ICON(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_ICON, GIcon))
36 #define G_IS_ICON(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_ICON))
37 #define G_ICON_GET_IFACE(obj)  (G_TYPE_INSTANCE_GET_INTERFACE ((obj), G_TYPE_ICON, GIconIface))
38
39 /**
40  * GIcon:
41  *
42  * An abstract type that specifies an icon.
43  **/
44 typedef struct _GIconIface GIconIface;
45
46 /**
47  * GIconIface:
48  * @g_iface: The parent interface.
49  * @hash: A hash for a given #GIcon.
50  * @equal: Checks if two #GIcons are equal.
51  * @to_tokens: Serializes a #GIcon into tokens. The tokens must not
52  * contain any whitespace. Don't implement if the #GIcon can't be
53  * serialized (Since 2.20).
54  * @from_tokens: Constructs a #GIcon from tokens. Set the #GError if
55  * the tokens are malformed. Don't implement if the #GIcon can't be
56  * serialized (Since 2.20).
57  * @serialize: Serializes a #GIcon into a #GVariant. Since: 2.38
58  *
59  * GIconIface is used to implement GIcon types for various
60  * different systems. See #GThemedIcon and #GLoadableIcon for
61  * examples of how to implement this interface.
62  */
63 struct _GIconIface
64 {
65   GTypeInterface g_iface;
66
67   /* Virtual Table */
68
69   guint       (* hash)        (GIcon   *icon);
70   gboolean    (* equal)       (GIcon   *icon1,
71                                GIcon   *icon2);
72
73   /**
74    * GIconIface::to_tokens:
75    * @icon: The #GIcon
76    * @tokens: (element-type utf8) (out caller-allocates):
77    *   The array to fill with tokens
78    * @out_version: (out): version of serialized tokens
79    *
80    * Serializes the @icon into string tokens.
81    * This is can be invoked when g_icon_new_for_string() is called.
82    *
83    * Returns: %TRUE if serialization took place, %FALSE otherwise
84    *
85    * Since: 2.20
86    */
87   gboolean    (* to_tokens)   (GIcon   *icon,
88                                GPtrArray *tokens,
89                                gint    *out_version);
90
91   /**
92    * GIconIface::from_tokens:
93    * @tokens: (array length=num_tokens): An array of tokens
94    * @num_tokens: The number of tokens in @tokens
95    * @version: Version of the serialized tokens
96    * @error: Return location for errors, or %NULL to ignore
97    *
98    * Constructs a #GIcon from a list of @tokens.
99    *
100    * Returns: (nullable) (transfer full): the #GIcon or %NULL on error
101    *
102    * Since: 2.20
103    */
104   GIcon *     (* from_tokens) (gchar  **tokens,
105                                gint     num_tokens,
106                                gint     version,
107                                GError **error);
108
109   GVariant *  (* serialize)   (GIcon   *icon);
110 };
111
112 GIO_AVAILABLE_IN_ALL
113 GType    g_icon_get_type  (void) G_GNUC_CONST;
114
115 GIO_AVAILABLE_IN_ALL
116 guint    g_icon_hash            (gconstpointer  icon);
117 GIO_AVAILABLE_IN_ALL
118 gboolean g_icon_equal           (GIcon         *icon1,
119                                  GIcon         *icon2);
120 GIO_AVAILABLE_IN_ALL
121 gchar   *g_icon_to_string       (GIcon         *icon);
122 GIO_AVAILABLE_IN_ALL
123 GIcon   *g_icon_new_for_string  (const gchar   *str,
124                                  GError       **error);
125
126 GIO_AVAILABLE_IN_2_38
127 GVariant * g_icon_serialize     (GIcon         *icon);
128 GIO_AVAILABLE_IN_2_38
129 GIcon *    g_icon_deserialize   (GVariant      *value);
130
131 G_END_DECLS
132
133 #endif /* __G_ICON_H__ */