2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-08-29 02:49:11 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2004-03-09 09:45:21 +08:00
|
|
|
* The GIMP Help plug-in
|
2008-05-17 00:56:33 +08:00
|
|
|
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
2003-08-29 02:49:11 +08:00
|
|
|
* Michael Natterer <mitch@gimp.org>
|
2004-03-09 09:45:21 +08:00
|
|
|
* Henrik Brix Andersen <brix@gimp.org>
|
2003-08-29 02:49:11 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-08-29 02:49:11 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-08-29 02:49:11 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-08-29 02:49:11 +08:00
|
|
|
*/
|
|
|
|
|
2004-08-14 23:47:22 +08:00
|
|
|
/* This code is written so that it can also be compiled standalone.
|
|
|
|
* It shouldn't depend on libgimp.
|
|
|
|
*/
|
|
|
|
|
2003-08-29 02:49:11 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-04-02 18:30:58 +08:00
|
|
|
#include <glib-object.h>
|
|
|
|
#include <gio/gio.h>
|
2004-01-19 11:06:04 +08:00
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
#include "gimphelp.h"
|
2008-05-17 00:56:33 +08:00
|
|
|
#include "gimphelpprogress-private.h"
|
2003-08-29 02:49:11 +08:00
|
|
|
|
2004-08-14 23:47:22 +08:00
|
|
|
#ifdef DISABLE_NLS
|
|
|
|
#define _(String) (String)
|
|
|
|
#else
|
2004-01-16 04:07:51 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
2004-08-14 23:47:22 +08:00
|
|
|
#endif
|
2004-01-16 04:07:51 +08:00
|
|
|
|
2022-12-27 23:49:25 +08:00
|
|
|
#ifdef PLATFORM_OSX
|
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
#endif
|
2003-08-29 02:49:11 +08:00
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
static void locale_set_error (GError **error,
|
|
|
|
const gchar *format,
|
2008-04-02 18:30:58 +08:00
|
|
|
GFile *file);
|
2003-08-29 02:49:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
GimpHelpLocale *
|
|
|
|
gimp_help_locale_new (const gchar *locale_id)
|
2004-03-18 10:45:52 +08:00
|
|
|
{
|
2007-05-23 21:59:51 +08:00
|
|
|
GimpHelpLocale *locale = g_slice_new0 (GimpHelpLocale);
|
2004-03-18 10:45:52 +08:00
|
|
|
|
|
|
|
locale->locale_id = g_strdup (locale_id);
|
|
|
|
|
|
|
|
return locale;
|
|
|
|
}
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
void
|
|
|
|
gimp_help_locale_free (GimpHelpLocale *locale)
|
2004-03-18 10:45:52 +08:00
|
|
|
{
|
2008-06-10 22:48:10 +08:00
|
|
|
g_return_if_fail (locale != NULL);
|
|
|
|
|
2004-03-18 10:45:52 +08:00
|
|
|
if (locale->help_id_mapping)
|
|
|
|
g_hash_table_destroy (locale->help_id_mapping);
|
|
|
|
|
|
|
|
g_free (locale->locale_id);
|
|
|
|
g_free (locale->help_missing);
|
|
|
|
|
2006-11-24 05:04:41 +08:00
|
|
|
g_list_free (locale->toplevel_items);
|
|
|
|
|
2007-05-23 21:59:51 +08:00
|
|
|
g_slice_free (GimpHelpLocale, locale);
|
2004-03-18 10:45:52 +08:00
|
|
|
}
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_help_locale_map (GimpHelpLocale *locale,
|
|
|
|
const gchar *help_id)
|
2004-03-18 20:18:12 +08:00
|
|
|
{
|
2008-06-10 22:48:10 +08:00
|
|
|
g_return_val_if_fail (locale != NULL, NULL);
|
|
|
|
g_return_val_if_fail (help_id != NULL, NULL);
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
if (locale->help_id_mapping)
|
|
|
|
{
|
|
|
|
GimpHelpItem *item = g_hash_table_lookup (locale->help_id_mapping,
|
|
|
|
help_id);
|
|
|
|
|
|
|
|
if (item)
|
|
|
|
return item->ref;
|
|
|
|
}
|
2004-03-18 20:18:12 +08:00
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
return NULL;
|
2004-03-18 20:18:12 +08:00
|
|
|
}
|
|
|
|
|
2004-03-18 10:45:52 +08:00
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
/* the locale mapping parser */
|
2003-08-29 02:49:11 +08:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
LOCALE_START,
|
|
|
|
LOCALE_IN_HELP,
|
|
|
|
LOCALE_IN_ITEM,
|
|
|
|
LOCALE_IN_MISSING,
|
|
|
|
LOCALE_IN_UNKNOWN
|
|
|
|
} LocaleParserState;
|
2003-08-29 02:49:11 +08:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2008-04-02 18:30:58 +08:00
|
|
|
GFile *file;
|
2006-11-21 05:46:21 +08:00
|
|
|
LocaleParserState state;
|
|
|
|
LocaleParserState last_known_state;
|
2003-08-29 02:49:11 +08:00
|
|
|
gint markup_depth;
|
|
|
|
gint unknown_depth;
|
|
|
|
GString *value;
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
GimpHelpLocale *locale;
|
|
|
|
const gchar *help_domain;
|
2003-08-29 02:49:11 +08:00
|
|
|
gchar *id_attr_name;
|
2006-11-21 05:46:21 +08:00
|
|
|
} LocaleParser;
|
2003-08-29 02:49:11 +08:00
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
static gboolean locale_parser_parse (GMarkupParseContext *context,
|
2008-05-17 00:56:33 +08:00
|
|
|
GimpHelpProgress *progress,
|
2008-04-02 18:30:58 +08:00
|
|
|
GInputStream *stream,
|
2008-05-17 00:56:33 +08:00
|
|
|
goffset size,
|
|
|
|
GCancellable *cancellable,
|
2004-03-18 08:11:03 +08:00
|
|
|
GError **error);
|
2006-11-21 05:46:21 +08:00
|
|
|
static void locale_parser_start_element (GMarkupParseContext *context,
|
2003-08-29 02:49:11 +08:00
|
|
|
const gchar *element_name,
|
|
|
|
const gchar **attribute_names,
|
|
|
|
const gchar **attribute_values,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error);
|
2006-11-21 05:46:21 +08:00
|
|
|
static void locale_parser_end_element (GMarkupParseContext *context,
|
2003-08-29 02:49:11 +08:00
|
|
|
const gchar *element_name,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error);
|
2006-11-21 05:46:21 +08:00
|
|
|
static void locale_parser_error (GMarkupParseContext *context,
|
2003-08-29 02:49:11 +08:00
|
|
|
GError *error,
|
|
|
|
gpointer user_data);
|
2006-11-21 05:46:21 +08:00
|
|
|
static void locale_parser_start_unknown (LocaleParser *parser);
|
|
|
|
static void locale_parser_end_unknown (LocaleParser *parser);
|
|
|
|
static void locale_parser_parse_namespace (LocaleParser *parser,
|
2003-08-29 02:49:11 +08:00
|
|
|
const gchar **names,
|
|
|
|
const gchar **values);
|
2006-11-21 05:46:21 +08:00
|
|
|
static void locale_parser_parse_item (LocaleParser *parser,
|
|
|
|
const gchar **names,
|
|
|
|
const gchar **values);
|
|
|
|
static void locale_parser_parse_missing (LocaleParser *parser,
|
2004-03-18 08:11:03 +08:00
|
|
|
const gchar **names,
|
|
|
|
const gchar **values);
|
2003-08-29 02:49:11 +08:00
|
|
|
|
|
|
|
static const GMarkupParser markup_parser =
|
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_start_element,
|
|
|
|
locale_parser_end_element,
|
2003-08-29 02:49:11 +08:00
|
|
|
NULL, /* characters */
|
|
|
|
NULL, /* passthrough */
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_error
|
2003-08-29 02:49:11 +08:00
|
|
|
};
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
gboolean
|
2008-05-17 00:56:33 +08:00
|
|
|
gimp_help_locale_parse (GimpHelpLocale *locale,
|
|
|
|
const gchar *uri,
|
|
|
|
const gchar *help_domain,
|
|
|
|
GimpHelpProgress *progress,
|
|
|
|
GError **error)
|
2003-08-29 02:49:11 +08:00
|
|
|
{
|
|
|
|
GMarkupParseContext *context;
|
2022-12-27 23:49:25 +08:00
|
|
|
GFile *file = NULL;
|
2008-05-17 00:56:33 +08:00
|
|
|
GCancellable *cancellable = NULL;
|
|
|
|
LocaleParser parser = { NULL, };
|
2022-12-27 23:49:25 +08:00
|
|
|
#ifdef PLATFORM_OSX
|
|
|
|
NSURL *fileURL;
|
|
|
|
NSString *nsUri;
|
|
|
|
NSData *data;
|
|
|
|
const gchar *str;
|
|
|
|
#else
|
|
|
|
GFileInputStream *stream;
|
2008-05-17 00:56:33 +08:00
|
|
|
goffset size = 0;
|
2022-12-27 23:49:25 +08:00
|
|
|
#endif
|
2004-03-18 20:18:12 +08:00
|
|
|
gboolean success;
|
2003-08-29 02:49:11 +08:00
|
|
|
|
2004-03-18 10:45:52 +08:00
|
|
|
g_return_val_if_fail (locale != NULL, FALSE);
|
2008-04-02 18:30:58 +08:00
|
|
|
g_return_val_if_fail (uri != NULL, FALSE);
|
2004-03-18 08:11:03 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2003-08-29 02:49:11 +08:00
|
|
|
|
2004-03-18 20:18:12 +08:00
|
|
|
if (locale->help_id_mapping)
|
|
|
|
{
|
|
|
|
g_hash_table_destroy (locale->help_id_mapping);
|
|
|
|
locale->help_id_mapping = NULL;
|
|
|
|
}
|
2006-11-21 05:46:21 +08:00
|
|
|
|
2004-03-18 20:18:12 +08:00
|
|
|
if (locale->help_missing)
|
|
|
|
{
|
|
|
|
g_free (locale->help_missing);
|
|
|
|
locale->help_missing = NULL;
|
|
|
|
}
|
|
|
|
|
2004-08-12 08:01:05 +08:00
|
|
|
#ifdef GIMP_HELP_DEBUG
|
2008-07-24 22:48:28 +08:00
|
|
|
g_printerr ("help (%s): parsing '%s' for \"%s\"\n",
|
2008-04-02 18:30:58 +08:00
|
|
|
locale->locale_id, uri, help_domain);
|
2004-08-12 08:01:05 +08:00
|
|
|
#endif
|
|
|
|
|
2008-04-02 18:30:58 +08:00
|
|
|
file = g_file_new_for_uri (uri);
|
|
|
|
|
2008-05-17 00:56:33 +08:00
|
|
|
if (progress)
|
|
|
|
{
|
|
|
|
gchar *name = g_file_get_parse_name (file);
|
|
|
|
|
|
|
|
cancellable = g_cancellable_new ();
|
|
|
|
_gimp_help_progress_start (progress, cancellable,
|
|
|
|
_("Loading index from '%s'"), name);
|
|
|
|
|
2022-12-27 23:49:25 +08:00
|
|
|
g_clear_object (&cancellable);
|
2008-05-17 00:56:33 +08:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
2022-12-27 23:49:25 +08:00
|
|
|
#ifdef PLATFORM_OSX
|
|
|
|
nsUri = [NSString stringWithUTF8String: uri];
|
|
|
|
fileURL = [NSURL URLWithString: nsUri];
|
|
|
|
[nsUri release];
|
|
|
|
|
|
|
|
if (progress)
|
|
|
|
_gimp_help_progress_pulse (progress);
|
|
|
|
|
|
|
|
/* Load the data from the remote URL into the NSData object */
|
|
|
|
data = [NSData dataWithContentsOfURL:fileURL];
|
|
|
|
[fileURL release];
|
|
|
|
|
|
|
|
if (! data)
|
|
|
|
{
|
|
|
|
locale_set_error (error,
|
|
|
|
_("Could not load data from '%s': %s"), file);
|
|
|
|
g_object_unref (file);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (progress)
|
|
|
|
_gimp_help_progress_pulse (progress);
|
|
|
|
#else /* PLATFORM_OSX */
|
2008-05-17 00:56:33 +08:00
|
|
|
if (progress)
|
|
|
|
{
|
|
|
|
GFileInfo *info = g_file_query_info (file,
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_SIZE, 0,
|
|
|
|
cancellable, error);
|
2008-08-14 04:42:34 +08:00
|
|
|
if (! info)
|
2008-05-17 00:56:33 +08:00
|
|
|
{
|
2008-08-14 04:42:34 +08:00
|
|
|
locale_set_error (error,
|
|
|
|
_("Could not open '%s' for reading: %s"), file);
|
|
|
|
g_object_unref (file);
|
|
|
|
|
|
|
|
return FALSE;
|
2008-05-17 00:56:33 +08:00
|
|
|
}
|
2008-08-14 04:42:34 +08:00
|
|
|
|
2023-09-19 20:38:42 +08:00
|
|
|
size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
|
2008-08-14 04:42:34 +08:00
|
|
|
|
|
|
|
g_object_unref (info);
|
2008-05-17 00:56:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
stream = g_file_read (file, cancellable, error);
|
2008-04-02 18:30:58 +08:00
|
|
|
|
|
|
|
if (! stream)
|
2004-03-18 20:18:12 +08:00
|
|
|
{
|
2008-08-14 03:19:50 +08:00
|
|
|
locale_set_error (error,
|
2008-07-24 22:48:28 +08:00
|
|
|
_("Could not open '%s' for reading: %s"), file);
|
2008-04-02 18:30:58 +08:00
|
|
|
g_object_unref (file);
|
|
|
|
|
2004-03-18 20:18:12 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2022-12-27 23:49:25 +08:00
|
|
|
#endif /* ! PLATFORM_OSX */
|
2003-08-29 02:49:11 +08:00
|
|
|
|
2008-04-02 18:30:58 +08:00
|
|
|
parser.file = file;
|
2007-05-23 21:59:51 +08:00
|
|
|
parser.value = g_string_new (NULL);
|
|
|
|
parser.locale = locale;
|
|
|
|
parser.help_domain = help_domain;
|
|
|
|
parser.id_attr_name = g_strdup ("id");
|
2004-03-18 20:18:12 +08:00
|
|
|
|
2007-05-23 21:59:51 +08:00
|
|
|
context = g_markup_parse_context_new (&markup_parser, 0, &parser, NULL);
|
2003-08-29 02:49:11 +08:00
|
|
|
|
2022-12-27 23:49:25 +08:00
|
|
|
#ifdef PLATFORM_OSX
|
|
|
|
str = (const char *)[data bytes];
|
|
|
|
|
|
|
|
if (! g_markup_parse_context_parse (context, str, [data length], error))
|
|
|
|
success = FALSE;
|
|
|
|
else
|
|
|
|
success = g_markup_parse_context_end_parse (context, error);
|
|
|
|
|
|
|
|
[data release];
|
|
|
|
#else /* PLATFORM_OSX */
|
2008-05-17 00:56:33 +08:00
|
|
|
success = locale_parser_parse (context, progress,
|
|
|
|
G_INPUT_STREAM (stream), size,
|
|
|
|
cancellable, error);
|
|
|
|
|
2022-12-27 23:49:25 +08:00
|
|
|
g_object_unref (stream);
|
|
|
|
#endif /* ! PLATFORM_OSX */
|
2008-05-17 00:56:33 +08:00
|
|
|
if (progress)
|
|
|
|
_gimp_help_progress_finish (progress);
|
2003-08-29 02:49:11 +08:00
|
|
|
|
|
|
|
g_markup_parse_context_free (context);
|
|
|
|
|
2007-05-23 21:59:51 +08:00
|
|
|
g_string_free (parser.value, TRUE);
|
|
|
|
g_free (parser.id_attr_name);
|
2003-08-29 02:49:11 +08:00
|
|
|
|
2004-03-18 20:18:12 +08:00
|
|
|
if (! success)
|
2008-04-02 18:30:58 +08:00
|
|
|
locale_set_error (error, _("Parse error in '%s':\n%s"), file);
|
|
|
|
|
|
|
|
g_object_unref (file);
|
2003-08-29 02:49:11 +08:00
|
|
|
|
2004-03-18 20:18:12 +08:00
|
|
|
return success;
|
2003-08-29 02:49:11 +08:00
|
|
|
}
|
|
|
|
|
2004-03-18 08:11:03 +08:00
|
|
|
static gboolean
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_parse (GMarkupParseContext *context,
|
2008-05-17 00:56:33 +08:00
|
|
|
GimpHelpProgress *progress,
|
2008-04-02 18:30:58 +08:00
|
|
|
GInputStream *stream,
|
2008-05-17 00:56:33 +08:00
|
|
|
goffset size,
|
|
|
|
GCancellable *cancellable,
|
2004-03-18 08:11:03 +08:00
|
|
|
GError **error)
|
|
|
|
{
|
2008-05-17 00:56:33 +08:00
|
|
|
gssize len;
|
|
|
|
goffset done = 0;
|
|
|
|
gchar buffer[4096];
|
2004-03-18 08:11:03 +08:00
|
|
|
|
2008-04-02 18:30:58 +08:00
|
|
|
while ((len = g_input_stream_read (stream, buffer, sizeof (buffer),
|
2008-05-17 00:56:33 +08:00
|
|
|
cancellable, error)) != -1)
|
2004-03-18 08:11:03 +08:00
|
|
|
{
|
2008-04-02 18:30:58 +08:00
|
|
|
switch (len)
|
2004-03-18 08:11:03 +08:00
|
|
|
{
|
2008-04-02 18:30:58 +08:00
|
|
|
case 0:
|
2004-03-18 08:11:03 +08:00
|
|
|
return g_markup_parse_context_end_parse (context, error);
|
2008-04-02 18:30:58 +08:00
|
|
|
|
|
|
|
default:
|
2008-05-17 00:56:33 +08:00
|
|
|
done += len;
|
|
|
|
|
|
|
|
if (progress)
|
|
|
|
{
|
|
|
|
if (size > 0)
|
|
|
|
_gimp_help_progress_update (progress, (gdouble) done / size);
|
|
|
|
else
|
|
|
|
_gimp_help_progress_pulse (progress);
|
|
|
|
}
|
|
|
|
|
2004-03-18 20:18:12 +08:00
|
|
|
if (! g_markup_parse_context_parse (context, buffer, len, error))
|
|
|
|
return FALSE;
|
2004-03-18 08:11:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-02 18:30:58 +08:00
|
|
|
return FALSE;
|
2004-03-18 08:11:03 +08:00
|
|
|
}
|
|
|
|
|
2003-08-29 02:49:11 +08:00
|
|
|
static void
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_start_element (GMarkupParseContext *context,
|
2003-08-29 02:49:11 +08:00
|
|
|
const gchar *element_name,
|
|
|
|
const gchar **attribute_names,
|
|
|
|
const gchar **attribute_values,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
LocaleParser *parser = (LocaleParser *) user_data;
|
2003-08-29 02:49:11 +08:00
|
|
|
|
|
|
|
switch (parser->state)
|
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
case LOCALE_START:
|
2003-08-29 02:49:11 +08:00
|
|
|
if (strcmp (element_name, "gimp-help") == 0)
|
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
parser->state = LOCALE_IN_HELP;
|
|
|
|
locale_parser_parse_namespace (parser,
|
2004-03-18 08:11:03 +08:00
|
|
|
attribute_names, attribute_values);
|
2003-08-29 02:49:11 +08:00
|
|
|
}
|
|
|
|
else
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_start_unknown (parser);
|
2003-08-29 02:49:11 +08:00
|
|
|
break;
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
case LOCALE_IN_HELP:
|
2003-08-29 02:49:11 +08:00
|
|
|
if (strcmp (element_name, "help-item") == 0)
|
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
parser->state = LOCALE_IN_ITEM;
|
|
|
|
locale_parser_parse_item (parser,
|
2004-03-18 08:11:03 +08:00
|
|
|
attribute_names, attribute_values);
|
|
|
|
}
|
|
|
|
else if (strcmp (element_name, "help-missing") == 0)
|
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
parser->state = LOCALE_IN_MISSING;
|
|
|
|
locale_parser_parse_missing (parser,
|
2004-03-18 08:11:03 +08:00
|
|
|
attribute_names, attribute_values);
|
2003-08-29 02:49:11 +08:00
|
|
|
}
|
|
|
|
else
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_start_unknown (parser);
|
2003-08-29 02:49:11 +08:00
|
|
|
break;
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
case LOCALE_IN_ITEM:
|
|
|
|
case LOCALE_IN_MISSING:
|
|
|
|
case LOCALE_IN_UNKNOWN:
|
|
|
|
locale_parser_start_unknown (parser);
|
2003-08-29 02:49:11 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_end_element (GMarkupParseContext *context,
|
2003-08-29 02:49:11 +08:00
|
|
|
const gchar *element_name,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
LocaleParser *parser = (LocaleParser *) user_data;
|
2003-08-29 02:49:11 +08:00
|
|
|
|
|
|
|
switch (parser->state)
|
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
case LOCALE_START:
|
|
|
|
g_warning ("locale_parser: This shouldn't happen.");
|
2003-08-29 02:49:11 +08:00
|
|
|
break;
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
case LOCALE_IN_HELP:
|
|
|
|
parser->state = LOCALE_START;
|
2003-08-29 02:49:11 +08:00
|
|
|
break;
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
case LOCALE_IN_ITEM:
|
|
|
|
case LOCALE_IN_MISSING:
|
|
|
|
parser->state = LOCALE_IN_HELP;
|
2003-08-29 02:49:11 +08:00
|
|
|
break;
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
case LOCALE_IN_UNKNOWN:
|
|
|
|
locale_parser_end_unknown (parser);
|
2003-08-29 02:49:11 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_error (GMarkupParseContext *context,
|
2003-08-29 02:49:11 +08:00
|
|
|
GError *error,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
LocaleParser *parser = (LocaleParser *) user_data;
|
2008-04-02 18:30:58 +08:00
|
|
|
gchar *name = g_file_get_parse_name (parser->file);
|
|
|
|
|
|
|
|
g_printerr ("help (parsing %s): %s", name, error->message);
|
2003-08-29 02:49:11 +08:00
|
|
|
|
2008-04-02 18:30:58 +08:00
|
|
|
g_free (name);
|
2003-08-29 02:49:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_start_unknown (LocaleParser *parser)
|
2003-08-29 02:49:11 +08:00
|
|
|
{
|
|
|
|
if (parser->unknown_depth == 0)
|
|
|
|
parser->last_known_state = parser->state;
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
parser->state = LOCALE_IN_UNKNOWN;
|
2003-08-29 02:49:11 +08:00
|
|
|
parser->unknown_depth++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_end_unknown (LocaleParser *parser)
|
2003-08-29 02:49:11 +08:00
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
g_assert (parser->unknown_depth > 0 && parser->state == LOCALE_IN_UNKNOWN);
|
2003-08-29 02:49:11 +08:00
|
|
|
|
|
|
|
parser->unknown_depth--;
|
|
|
|
|
|
|
|
if (parser->unknown_depth == 0)
|
|
|
|
parser->state = parser->last_known_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_parse_namespace (LocaleParser *parser,
|
2003-08-29 02:49:11 +08:00
|
|
|
const gchar **names,
|
|
|
|
const gchar **values)
|
|
|
|
{
|
2004-03-18 08:11:03 +08:00
|
|
|
for (; *names && *values; names++, values++)
|
2003-08-29 02:49:11 +08:00
|
|
|
{
|
|
|
|
if (! strncmp (*names, "xmlns:", 6) &&
|
2006-11-21 05:46:21 +08:00
|
|
|
! strcmp (*values, parser->help_domain))
|
2003-08-29 02:49:11 +08:00
|
|
|
{
|
|
|
|
g_free (parser->id_attr_name);
|
|
|
|
parser->id_attr_name = g_strdup_printf ("%s:id", *names + 6);
|
|
|
|
|
2004-03-18 08:11:03 +08:00
|
|
|
#ifdef GIMP_HELP_DEBUG
|
2004-03-18 10:45:52 +08:00
|
|
|
g_printerr ("help (%s): id attribute name for \"%s\" is \"%s\"\n",
|
|
|
|
parser->locale->locale_id,
|
2006-11-21 05:46:21 +08:00
|
|
|
parser->help_domain,
|
2004-03-18 10:45:52 +08:00
|
|
|
parser->id_attr_name);
|
2004-03-18 08:11:03 +08:00
|
|
|
#endif
|
2003-08-29 02:49:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_parse_item (LocaleParser *parser,
|
2003-08-29 02:49:11 +08:00
|
|
|
const gchar **names,
|
|
|
|
const gchar **values)
|
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
const gchar *id = NULL;
|
|
|
|
const gchar *ref = NULL;
|
|
|
|
const gchar *title = NULL;
|
2012-01-10 03:04:28 +08:00
|
|
|
const gchar *sort = NULL; /* optional sort key provided by doc team */
|
2006-11-21 05:46:21 +08:00
|
|
|
const gchar *parent = NULL;
|
2003-08-29 02:49:11 +08:00
|
|
|
|
2004-03-18 08:11:03 +08:00
|
|
|
for (; *names && *values; names++, values++)
|
2003-08-29 02:49:11 +08:00
|
|
|
{
|
|
|
|
if (! strcmp (*names, parser->id_attr_name))
|
|
|
|
id = *values;
|
|
|
|
|
|
|
|
if (! strcmp (*names, "ref"))
|
|
|
|
ref = *values;
|
2006-11-21 05:46:21 +08:00
|
|
|
|
|
|
|
if (! strcmp (*names, "title"))
|
|
|
|
title = *values;
|
|
|
|
|
2012-01-10 03:04:28 +08:00
|
|
|
if (! strcmp (*names, "sort"))
|
|
|
|
sort = *values;
|
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
if (! strcmp (*names, "parent"))
|
|
|
|
parent = *values;
|
2003-08-29 02:49:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (id && ref)
|
|
|
|
{
|
2004-03-18 10:45:52 +08:00
|
|
|
if (! parser->locale->help_id_mapping)
|
2006-11-21 05:46:21 +08:00
|
|
|
parser->locale->help_id_mapping =
|
|
|
|
g_hash_table_new_full (g_str_hash,
|
|
|
|
g_str_equal,
|
|
|
|
g_free,
|
|
|
|
(GDestroyNotify) gimp_help_item_free);
|
2003-08-29 02:49:11 +08:00
|
|
|
|
2004-03-18 10:45:52 +08:00
|
|
|
g_hash_table_insert (parser->locale->help_id_mapping,
|
2006-11-21 05:46:21 +08:00
|
|
|
g_strdup (id),
|
2012-01-10 03:04:28 +08:00
|
|
|
gimp_help_item_new (ref, title, sort, parent));
|
2003-08-29 02:49:11 +08:00
|
|
|
|
2004-03-18 08:11:03 +08:00
|
|
|
#ifdef GIMP_HELP_DEBUG
|
2004-03-18 10:45:52 +08:00
|
|
|
g_printerr ("help (%s): added mapping \"%s\" -> \"%s\"\n",
|
|
|
|
parser->locale->locale_id, id, ref);
|
2004-03-18 08:11:03 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_parser_parse_missing (LocaleParser *parser,
|
2004-03-18 08:11:03 +08:00
|
|
|
const gchar **names,
|
|
|
|
const gchar **values)
|
|
|
|
{
|
|
|
|
const gchar *ref = NULL;
|
|
|
|
|
|
|
|
for (; *names && *values; names++, values++)
|
|
|
|
{
|
|
|
|
if (! strcmp (*names, "ref"))
|
|
|
|
ref = *values;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ref &&
|
2004-03-18 10:45:52 +08:00
|
|
|
parser->locale->help_missing == NULL)
|
2004-03-18 08:11:03 +08:00
|
|
|
{
|
2004-03-18 10:45:52 +08:00
|
|
|
parser->locale->help_missing = g_strdup (ref);
|
2004-03-18 08:11:03 +08:00
|
|
|
|
|
|
|
#ifdef GIMP_HELP_DEBUG
|
2004-03-18 10:45:52 +08:00
|
|
|
g_printerr ("help (%s): added fallback for missing help -> \"%s\"\n",
|
|
|
|
parser->locale->locale_id, ref);
|
2004-03-18 08:11:03 +08:00
|
|
|
#endif
|
2003-08-29 02:49:11 +08:00
|
|
|
}
|
|
|
|
}
|
2004-08-14 23:47:22 +08:00
|
|
|
|
|
|
|
static void
|
2006-11-21 05:46:21 +08:00
|
|
|
locale_set_error (GError **error,
|
|
|
|
const gchar *format,
|
2008-04-02 18:30:58 +08:00
|
|
|
GFile *file)
|
2004-08-14 23:47:22 +08:00
|
|
|
{
|
|
|
|
if (error && *error)
|
|
|
|
{
|
2008-04-02 18:30:58 +08:00
|
|
|
gchar *name = g_file_get_parse_name (file);
|
|
|
|
gchar *msg;
|
2004-08-14 23:47:22 +08:00
|
|
|
|
2008-04-02 18:30:58 +08:00
|
|
|
msg = g_strdup_printf (format, name, (*error)->message);
|
2004-08-14 23:47:22 +08:00
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
g_free ((*error)->message);
|
|
|
|
(*error)->message = msg;
|
|
|
|
}
|
|
|
|
}
|