1 /* LIBGIMP - The GIMP Library
2 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
3 *
4 * gimpbasetypes.c
5 * Copyright (C) 2004 Sven Neumann <sven@gimp.org>
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 3 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 Public
18 * License along with this library. If not, see
19 * <https://www.gnu.org/licenses/>.
20 */
21
22 #include "config.h"
23
24 #include <glib-object.h>
25
26 #include "gimpbasetypes.h"
27
28
29 /**
30 * SECTION: gimpbasetypes
31 * @title: gimpbasetypes
32 * @short_description: Translation between gettext translation domain
33 * identifier and GType.
34 *
35 * Translation between gettext translation domain identifier and
36 * GType.
37 **/
38
39
40 static GQuark gimp_translation_domain_quark (void) G_GNUC_CONST;
41 static GQuark gimp_translation_context_quark (void) G_GNUC_CONST;
42 static GQuark gimp_value_descriptions_quark (void) G_GNUC_CONST;
43
44
45 /**
46 * gimp_type_set_translation_domain:
47 * @type: a #GType
48 * @domain: a constant string that identifies a translation domain or %NULL
49 *
50 * This function attaches a constant string as a gettext translation
51 * domain identifier to a #GType. The only purpose of this function is
52 * to use it when registering a #G_TYPE_ENUM with translatable value
53 * names.
54 *
55 * Since: 2.2
56 **/
57 void
gimp_type_set_translation_domain(GType type,const gchar * domain)58 gimp_type_set_translation_domain (GType type,
59 const gchar *domain)
60 {
61 g_type_set_qdata (type,
62 gimp_translation_domain_quark (), (gpointer) domain);
63 }
64
65 /**
66 * gimp_type_get_translation_domain:
67 * @type: a #GType
68 *
69 * Retrieves the gettext translation domain identifier that has been
70 * previously set using gimp_type_set_translation_domain(). You should
71 * not need to use this function directly, use gimp_enum_get_value()
72 * or gimp_enum_value_get_desc() instead.
73 *
74 * Return value: the translation domain associated with @type
75 * or %NULL if no domain was set
76 *
77 * Since: 2.2
78 **/
79 const gchar *
gimp_type_get_translation_domain(GType type)80 gimp_type_get_translation_domain (GType type)
81 {
82 return (const gchar *) g_type_get_qdata (type,
83 gimp_translation_domain_quark ());
84 }
85
86 /**
87 * gimp_type_set_translation_context:
88 * @type: a #GType
89 * @context: a constant string that identifies a translation context or %NULL
90 *
91 * This function attaches a constant string as a translation context
92 * to a #GType. The only purpose of this function is to use it when
93 * registering a #G_TYPE_ENUM with translatable value names.
94 *
95 * Since: 2.8
96 **/
97 void
gimp_type_set_translation_context(GType type,const gchar * context)98 gimp_type_set_translation_context (GType type,
99 const gchar *context)
100 {
101 g_type_set_qdata (type,
102 gimp_translation_context_quark (), (gpointer) context);
103 }
104
105 /**
106 * gimp_type_get_translation_context:
107 * @type: a #GType
108 *
109 * Retrieves the translation context that has been previously set
110 * using gimp_type_set_translation_context(). You should not need to
111 * use this function directly, use gimp_enum_get_value() or
112 * gimp_enum_value_get_desc() instead.
113 *
114 * Return value: the translation context associated with @type
115 * or %NULL if no context was set
116 *
117 * Since: 2.8
118 **/
119 const gchar *
gimp_type_get_translation_context(GType type)120 gimp_type_get_translation_context (GType type)
121 {
122 return (const gchar *) g_type_get_qdata (type,
123 gimp_translation_context_quark ());
124 }
125
126 /**
127 * gimp_enum_set_value_descriptions:
128 * @enum_type: a #GType
129 * @descriptions: a %NULL terminated constant static array of #GimpEnumDesc
130 *
131 * Sets the array of human readable and translatable descriptions
132 * and help texts for enum values.
133 *
134 * Since: 2.2
135 **/
136 void
gimp_enum_set_value_descriptions(GType enum_type,const GimpEnumDesc * descriptions)137 gimp_enum_set_value_descriptions (GType enum_type,
138 const GimpEnumDesc *descriptions)
139 {
140 g_return_if_fail (g_type_is_a (enum_type, G_TYPE_ENUM));
141 g_return_if_fail (descriptions != NULL);
142
143 g_type_set_qdata (enum_type,
144 gimp_value_descriptions_quark (),
145 (gpointer) descriptions);
146 }
147
148 /**
149 * gimp_enum_get_value_descriptions:
150 * @enum_type: a #GType
151 *
152 * Retreives the array of human readable and translatable descriptions
153 * and help texts for enum values.
154 *
155 * Returns: a %NULL terminated constant array of #GimpEnumDesc
156 *
157 * Since: 2.2
158 **/
159 const GimpEnumDesc *
gimp_enum_get_value_descriptions(GType enum_type)160 gimp_enum_get_value_descriptions (GType enum_type)
161 {
162 g_return_val_if_fail (g_type_is_a (enum_type, G_TYPE_ENUM), NULL);
163
164 return (const GimpEnumDesc *)
165 g_type_get_qdata (enum_type, gimp_value_descriptions_quark ());
166 }
167
168 /**
169 * gimp_flags_set_value_descriptions:
170 * @flags_type: a #GType
171 * @descriptions: a %NULL terminated constant static array of #GimpFlagsDesc
172 *
173 * Sets the array of human readable and translatable descriptions
174 * and help texts for flags values.
175 *
176 * Since: 2.2
177 **/
178 void
gimp_flags_set_value_descriptions(GType flags_type,const GimpFlagsDesc * descriptions)179 gimp_flags_set_value_descriptions (GType flags_type,
180 const GimpFlagsDesc *descriptions)
181 {
182 g_return_if_fail (g_type_is_a (flags_type, G_TYPE_FLAGS));
183 g_return_if_fail (descriptions != NULL);
184
185 g_type_set_qdata (flags_type,
186 gimp_value_descriptions_quark (),
187 (gpointer) descriptions);
188 }
189
190 /**
191 * gimp_flags_get_value_descriptions:
192 * @flags_type: a #GType
193 *
194 * Retreives the array of human readable and translatable descriptions
195 * and help texts for flags values.
196 *
197 * Returns: a %NULL terminated constant array of #GimpFlagsDesc
198 *
199 * Since: 2.2
200 **/
201 const GimpFlagsDesc *
gimp_flags_get_value_descriptions(GType flags_type)202 gimp_flags_get_value_descriptions (GType flags_type)
203 {
204 g_return_val_if_fail (g_type_is_a (flags_type, G_TYPE_FLAGS), NULL);
205
206 return (const GimpFlagsDesc *)
207 g_type_get_qdata (flags_type, gimp_value_descriptions_quark ());
208 }
209
210
211 /* private functions */
212
213 static GQuark
gimp_translation_domain_quark(void)214 gimp_translation_domain_quark (void)
215 {
216 static GQuark quark = 0;
217
218 if (! quark)
219 quark = g_quark_from_static_string ("gimp-translation-domain-quark");
220
221 return quark;
222 }
223
224 static GQuark
gimp_translation_context_quark(void)225 gimp_translation_context_quark (void)
226 {
227 static GQuark quark = 0;
228
229 if (! quark)
230 quark = g_quark_from_static_string ("gimp-translation-context-quark");
231
232 return quark;
233 }
234
235 static GQuark
gimp_value_descriptions_quark(void)236 gimp_value_descriptions_quark (void)
237 {
238 static GQuark quark = 0;
239
240 if (! quark)
241 quark = g_quark_from_static_string ("gimp-value-descriptions-quark");
242
243 return quark;
244 }
245