GList *
gimp_gradient_load_svg (GimpContext  *context,
                        const gchar  *filename,
                        GError      **error)
{
  GimpXmlParser *xml_parser;
  SvgParser      parser = { NULL, };
  gboolean       success;

  g_return_val_if_fail (filename != NULL, NULL);
  g_return_val_if_fail (g_path_is_absolute (filename), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  xml_parser = gimp_xml_parser_new (&markup_parser, &parser);

  success = gimp_xml_parser_parse_file (xml_parser, filename, error);

  gimp_xml_parser_free (xml_parser);

  if (success && ! parser.gradients)
    {
      g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                   _("No linear gradients found in '%s'"),
                   gimp_filename_to_utf8 (filename));
    }
  else
    {
      if (error && *error) /*  parser reported an error  */
        {
          gchar *msg = (*error)->message;

          (*error)->message =
            g_strdup_printf (_("Failed to import gradients from '%s': %s"),
                             gimp_filename_to_utf8 (filename), msg);

          g_free (msg);
        }
    }

  if (parser.gradient)
    g_object_unref (parser.gradient);

  if (parser.stops)
    {
      GList *list;

      for (list = parser.stops; list; list = list->next)
        g_slice_free (SvgStop, list->data);

      g_list_free (parser.stops);
    }

  return g_list_reverse (parser.gradients);
}
gboolean
gimp_language_store_parse_iso_codes (GimpLanguageStore  *store,
                                     GError            **error)
{
#ifdef HAVE_ISO_CODES
  static const GMarkupParser markup_parser =
    {
      iso_codes_parser_start_element,
      iso_codes_parser_end_element,
      NULL,  /*  characters   */
      NULL,  /*  passthrough  */
      NULL   /*  error        */
    };

  GimpXmlParser   *xml_parser;
  gchar           *filename;
  gboolean         success;
  IsoCodesParser   parser = { 0, };

  g_return_val_if_fail (GIMP_IS_LANGUAGE_STORE (store), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  iso_codes_parser_init ();

  parser.store = g_object_ref (store);

  xml_parser = gimp_xml_parser_new (&markup_parser, &parser);

#ifdef G_OS_WIN32
  filename = g_build_filename (gimp_data_directory (),
                               "..", "..", "xml", "iso-codes", "iso_639.xml",
                               NULL);
#else
  filename = g_build_filename (ISO_CODES_LOCATION, "iso_639.xml", NULL);
#endif

  success = gimp_xml_parser_parse_file (xml_parser, filename, error);

  g_free (filename);

  gimp_xml_parser_free (xml_parser);
  g_object_unref (parser.store);

  return success;
#endif

  return TRUE;
}
Esempio n. 3
0
/*
 * Parse the ISO-639 code list if available on this system, and fill
 * @base_lang_list with English names of all needed base codes.
 *
 * It will also fill the static @all_lang_list.
 */
static gboolean
parse_iso_codes (GHashTable  *base_lang_list,
                 GError     **error)
{
  gboolean         success = TRUE;
#ifdef HAVE_ISO_CODES
  static const GMarkupParser markup_parser =
    {
      iso_codes_parser_start_element,
      iso_codes_parser_end_element,
      NULL,  /*  characters   */
      NULL,  /*  passthrough  */
      NULL   /*  error        */
    };

  GimpXmlParser   *xml_parser;
  gchar           *filename;
  IsoCodesParser   parser = { 0, };

  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  iso_codes_parser_init ();

  parser.base_lang_list = g_hash_table_ref (base_lang_list);

  xml_parser = gimp_xml_parser_new (&markup_parser, &parser);

#ifdef G_OS_WIN32
  filename = g_build_filename (gimp_data_directory (),
                               "..", "..", "xml", "iso-codes", "iso_639.xml",
                               NULL);
#else
  filename = g_build_filename (ISO_CODES_LOCATION, "iso_639.xml", NULL);
#endif

  success = gimp_xml_parser_parse_file (xml_parser, filename, error);

  g_free (filename);

  gimp_xml_parser_free (xml_parser);
  g_hash_table_unref (parser.base_lang_list);

#endif

  return success;
}
Esempio n. 4
0
gboolean
gimp_tags_user_install (void)
{
  GFile             *file;
  GOutputStream     *output;
  GMarkupParser      markup_parser;
  GimpXmlParser     *xml_parser;
  const char        *tags_locale;
  GimpTagsInstaller  tags_installer = { 0, };
  GError            *error          = NULL;
  gboolean           result         = TRUE;

  /* This is a special string to specify the language identifier to
   * look for in the gimp-tags-default.xml file. Please translate the
   * C in it according to the name of the po file used for
   * gimp-tags-default.xml. E.g. lithuanian for the translation,
   * that would be "tags-locale:lt".
   */
  tags_locale = _("tags-locale:C");

  if (g_str_has_prefix (tags_locale, "tags-locale:"))
    {
      tags_locale += strlen ("tags-locale:");

      if (*tags_locale && *tags_locale != 'C')
        tags_installer.locale = tags_locale;
    }
  else
    {
      g_warning ("Wrong translation for 'tags-locale:', fix the translation!");
    }

  tags_installer.buf = g_string_new (NULL);

  g_string_append (tags_installer.buf, "<?xml version='1.0' encoding='UTF-8'?>\n");
  g_string_append (tags_installer.buf, "<tags>\n");

  markup_parser.start_element = gimp_tags_installer_load_start_element;
  markup_parser.end_element   = gimp_tags_installer_load_end_element;
  markup_parser.text          = gimp_tags_installer_load_text;
  markup_parser.passthrough   = NULL;
  markup_parser.error         = NULL;

  xml_parser = gimp_xml_parser_new (&markup_parser, &tags_installer);

  file = gimp_data_directory_file ("tags", "gimp-tags-default.xml", NULL);
  result = gimp_xml_parser_parse_gfile (xml_parser, file, &error);
  g_object_unref (file);

  gimp_xml_parser_free (xml_parser);

  if (! result)
    {
      g_string_free (tags_installer.buf, TRUE);
      return FALSE;
    }

  g_string_append (tags_installer.buf, "\n</tags>\n");

  file = gimp_directory_file (GIMP_TAGS_FILE, NULL);

  output = G_OUTPUT_STREAM (g_file_replace (file,
                                            NULL, FALSE, G_FILE_CREATE_NONE,
                                            NULL, &error));
  if (! output)
    {
      g_printerr ("%s\n", error->message);
      result = FALSE;
    }
  else if (! g_output_stream_write_all (output,
                                        tags_installer.buf->str,
                                        tags_installer.buf->len,
                                        NULL, NULL, &error))
    {
      GCancellable *cancellable = g_cancellable_new ();

      g_printerr (_("Error writing '%s': %s"),
                  gimp_file_get_utf8_name (file), error->message);
      result = FALSE;

      /* Cancel the overwrite initiated by g_file_replace(). */
      g_cancellable_cancel (cancellable);
      g_output_stream_close (output, cancellable, NULL);
      g_object_unref (cancellable);
    }
  else if (! g_output_stream_close (output, NULL, &error))
    {
      g_printerr (_("Error closing '%s': %s"),
                  gimp_file_get_utf8_name (file), error->message);
      result = FALSE;
    }

  if (output)
    g_object_unref (output);

  g_clear_error (&error);
  g_object_unref (file);
  g_string_free (tags_installer.buf, TRUE);

  return result;
}
Esempio n. 5
0
gboolean
gimp_tags_user_install (void)
{
  gchar             *filename;
  GMarkupParser      markup_parser;
  GimpXmlParser     *xml_parser;
  const char        *tags_locale;
  GimpTagsInstaller  tags_installer = { 0, };
  GError            *error          = NULL;
  gboolean           result         = TRUE;

  /* This is a special string to specify the language identifier to
   * look for in the gimp-tags-default.xml file. Please translate the
   * C in it according to the name of the po file used for
   * gimp-tags-default.xml. E.g. lithuanian for the translation,
   * that would be "tags-locale:lt".
   */
  tags_locale = _("tags-locale:C");

  if (g_str_has_prefix (tags_locale, "tags-locale:"))
    {
      tags_locale += strlen ("tags-locale:");

      if (*tags_locale && *tags_locale != 'C')
        tags_installer.locale = tags_locale;
    }
  else
    {
      g_warning ("Wrong translation for 'tags-locale:', fix the translation!");
    }

  tags_installer.buf = g_string_new (NULL);

  g_string_append (tags_installer.buf, "<?xml version='1.0' encoding='UTF-8'?>\n");
  g_string_append (tags_installer.buf, "<tags>\n");

  filename = g_build_filename (gimp_data_directory (), "tags",
                               "gimp-tags-default.xml", NULL);

  markup_parser.start_element = gimp_tags_installer_load_start_element;
  markup_parser.end_element   = gimp_tags_installer_load_end_element;
  markup_parser.text          = gimp_tags_installer_load_text;
  markup_parser.passthrough   = NULL;
  markup_parser.error         = NULL;

  xml_parser = gimp_xml_parser_new (&markup_parser, &tags_installer);

  result = gimp_xml_parser_parse_file (xml_parser, filename, &error);

  g_free (filename);
  gimp_xml_parser_free (xml_parser);

  if (! result)
    {
      g_string_free (tags_installer.buf, TRUE);
      return FALSE;
    }

  g_string_append (tags_installer.buf, "\n</tags>\n");

  filename = g_build_filename (gimp_directory (), GIMP_TAGS_FILE, NULL);

  result = g_file_set_contents (filename, tags_installer.buf->str,
                                tags_installer.buf->len, &error);

  g_free (filename);
  g_string_free (tags_installer.buf, TRUE);

  if (! result)
    {
      g_warning ("Error while creating tags.xml: %s\n", error->message);
      g_error_free (error);
      return FALSE;
    }

  return TRUE;
}