gimpbasetypes.c 6.64 KB
Newer Older
Sven Neumann's avatar
Sven Neumann committed
1 2 3 4 5 6
/* LIBGIMP - The GIMP Library
 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
 *
 * gimpbasetypes.c
 * Copyright (C) 2004 Sven Neumann <sven@gimp.org>
 *
7
 * This library is free software: you can redistribute it and/or
Sven Neumann's avatar
Sven Neumann committed
8 9
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
10
 * version 3 of the License, or (at your option) any later version.
Sven Neumann's avatar
Sven Neumann committed
11 12 13 14 15 16 17
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
18 19
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
Sven Neumann's avatar
Sven Neumann committed
20 21 22 23 24 25 26 27 28
 */

#include "config.h"

#include <glib-object.h>

#include "gimpbasetypes.h"


29 30 31 32 33 34 35 36 37 38 39
/**
 * SECTION: gimpbasetypes
 * @title: gimpbasetypes
 * @short_description: Translation between gettext translation domain
 *                     identifier and GType.
 *
 * Translation between gettext translation domain identifier and
 * GType.
 **/


40 41 42
static GQuark  gimp_translation_domain_quark  (void) G_GNUC_CONST;
static GQuark  gimp_translation_context_quark (void) G_GNUC_CONST;
static GQuark  gimp_value_descriptions_quark  (void) G_GNUC_CONST;
Sven Neumann's avatar
Sven Neumann committed
43 44 45 46 47 48 49 50 51


/**
 * gimp_type_set_translation_domain:
 * @type:   a #GType
 * @domain: a constant string that identifies a translation domain or %NULL
 *
 * This function attaches a constant string as a gettext translation
 * 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
Sven Neumann's avatar
Sven Neumann committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
 * names.
 *
 * Since: GIMP 2.2
 **/
void
gimp_type_set_translation_domain (GType        type,
                                  const gchar *domain)
{
  g_type_set_qdata (type,
                    gimp_translation_domain_quark (), (gpointer) domain);
}

/**
 * gimp_type_get_translation_domain:
 * @type: a #GType
 *
 * Retrieves the gettext translation domain identifier that has been
 * previously set using gimp_type_set_translation_domain(). You should
 * not need to use this function directly, use gimp_enum_get_value()
72
 * or gimp_enum_value_get_desc() instead.
Sven Neumann's avatar
Sven Neumann committed
73 74 75 76 77 78 79 80 81 82 83 84 85
 *
 * Return value: the translation domain associated with @type
 *               or %NULL if no domain was set
 *
 * Since: GIMP 2.2
 **/
const gchar *
gimp_type_get_translation_domain (GType type)
{
  return (const gchar *) g_type_get_qdata (type,
                                           gimp_translation_domain_quark ());
}

86 87
/**
 * gimp_type_set_translation_context:
88 89
 * @type:    a #GType
 * @context: a constant string that identifies a translation context or %NULL
90 91 92
 *
 * This function attaches a constant string as a translation context
 * 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
 *
 * Since: GIMP 2.8
 **/
void
gimp_type_set_translation_context (GType        type,
                                   const gchar *context)
{
  g_type_set_qdata (type,
                    gimp_translation_context_quark (), (gpointer) context);
}

/**
 * gimp_type_get_translation_context:
 * @type: a #GType
 *
 * Retrieves the translation context that has been previously set
 * using gimp_type_set_translation_context(). You should not need to
 * use this function directly, use gimp_enum_get_value() or
112
 * gimp_enum_value_get_desc() instead.
113 114 115 116 117 118 119 120 121 122 123 124 125
 *
 * Return value: the translation context associated with @type
 *               or %NULL if no context was set
 *
 * Since: GIMP 2.8
 **/
const gchar *
gimp_type_get_translation_context (GType type)
{
  return (const gchar *) g_type_get_qdata (type,
                                           gimp_translation_context_quark ());
}

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
/**
 * gimp_enum_set_value_descriptions:
 * @enum_type:    a #GType
 * @descriptions: a %NULL terminated constant static array of #GimpEnumDesc
 *
 * Sets the array of human readable and translatable descriptions
 * and help texts for enum values.
 *
 * Since: GIMP 2.2
 **/
void
gimp_enum_set_value_descriptions (GType               enum_type,
                                  const GimpEnumDesc *descriptions)
{
  g_return_if_fail (g_type_is_a (enum_type, G_TYPE_ENUM));
  g_return_if_fail (descriptions != NULL);

  g_type_set_qdata (enum_type,
                    gimp_value_descriptions_quark (),
                    (gpointer) descriptions);
}

/**
 * gimp_enum_get_value_descriptions:
 * @enum_type: a #GType
 *
 * Retreives the array of human readable and translatable descriptions
 * and help texts for enum values.
 *
 * Returns: a %NULL terminated constant array of #GimpEnumDesc
 *
 * Since: GIMP 2.2
 **/
const GimpEnumDesc *
gimp_enum_get_value_descriptions (GType enum_type)
{
  g_return_val_if_fail (g_type_is_a (enum_type, G_TYPE_ENUM), NULL);

  return (const GimpEnumDesc *)
    g_type_get_qdata (enum_type, gimp_value_descriptions_quark ());
}

/**
 * gimp_flags_set_value_descriptions:
 * @flags_type:   a #GType
 * @descriptions: a %NULL terminated constant static array of #GimpFlagsDesc
 *
 * Sets the array of human readable and translatable descriptions
 * and help texts for flags values.
 *
 * Since: GIMP 2.2
 **/
void
gimp_flags_set_value_descriptions (GType                flags_type,
                                   const GimpFlagsDesc *descriptions)
{
  g_return_if_fail (g_type_is_a (flags_type, G_TYPE_FLAGS));
  g_return_if_fail (descriptions != NULL);

  g_type_set_qdata (flags_type,
                    gimp_value_descriptions_quark (),
                    (gpointer) descriptions);
}

/**
 * gimp_flags_get_value_descriptions:
 * @flags_type: a #GType
 *
 * Retreives the array of human readable and translatable descriptions
 * and help texts for flags values.
 *
 * Returns: a %NULL terminated constant array of #GimpFlagsDesc
 *
 * Since: GIMP 2.2
 **/
const GimpFlagsDesc *
gimp_flags_get_value_descriptions (GType flags_type)
{
  g_return_val_if_fail (g_type_is_a (flags_type, G_TYPE_FLAGS), NULL);

  return (const GimpFlagsDesc *)
    g_type_get_qdata (flags_type, gimp_value_descriptions_quark ());
}


/*  private functions  */

Sven Neumann's avatar
Sven Neumann committed
213 214 215 216 217 218 219 220 221 222
static GQuark
gimp_translation_domain_quark (void)
{
  static GQuark quark = 0;

  if (! quark)
    quark = g_quark_from_static_string ("gimp-translation-domain-quark");

  return quark;
}
223

224 225 226 227 228 229 230 231 232 233 234
static GQuark
gimp_translation_context_quark (void)
{
  static GQuark quark = 0;

  if (! quark)
    quark = g_quark_from_static_string ("gimp-translation-context-quark");

  return quark;
}

235 236 237 238 239 240 241 242 243 244
static GQuark
gimp_value_descriptions_quark (void)
{
  static GQuark quark = 0;

  if (! quark)
    quark = g_quark_from_static_string ("gimp-value-descriptions-quark");

  return quark;
}