gimp r25331 - in trunk: . plug-ins/help



Author: neo
Date: Wed Apr  2 11:30:58 2008
New Revision: 25331
URL: http://svn.gnome.org/viewvc/gimp?rev=25331&view=rev

Log:
2008-04-02  Sven Neumann  <sven gimp org>

	* plug-ins/help/Makefile.am
	* plug-ins/help/gimphelpdomain.[ch]
	* plug-ins/help/gimphelplocale.[ch]
	* plug-ins/help/gimphelp.[ch]
	* plug-ins/help/gimp-help-lookup.c: use GIO to access the help index.


Modified:
   trunk/ChangeLog
   trunk/plug-ins/help/Makefile.am
   trunk/plug-ins/help/gimp-help-lookup.c
   trunk/plug-ins/help/gimphelp.c
   trunk/plug-ins/help/gimphelp.h
   trunk/plug-ins/help/gimphelpdomain.c
   trunk/plug-ins/help/gimphelpdomain.h
   trunk/plug-ins/help/gimphelplocale.c
   trunk/plug-ins/help/gimphelplocale.h

Modified: trunk/plug-ins/help/Makefile.am
==============================================================================
--- trunk/plug-ins/help/Makefile.am	(original)
+++ trunk/plug-ins/help/Makefile.am	Wed Apr  2 11:30:58 2008
@@ -35,7 +35,7 @@
 
 INCLUDES = \
 	-I$(top_srcdir)	\
-	$(GLIB_CFLAGS)	\
+	$(GIO_CFLAGS)	\
 	-I$(includedir)
 
 LDADD = \
@@ -44,7 +44,7 @@
 	$(libgimpcolor)	\
 	$(libgimpbase)	\
 	$(libgimpmath)	\
-	$(GLIB_LIBS)	\
+	$(GIO_LIBS)	\
 	$(RT_LIBS)	\
 	$(INTLLIBS)
 
@@ -56,4 +56,4 @@
 gimp_help_lookup_LDADD = \
 	$(libgimphelp)	\
 	$(libgimpbase)	\
-	$(GLIB_LIBS)
+	$(GIO_LIBS)

Modified: trunk/plug-ins/help/gimp-help-lookup.c
==============================================================================
--- trunk/plug-ins/help/gimp-help-lookup.c	(original)
+++ trunk/plug-ins/help/gimp-help-lookup.c	Wed Apr  2 11:30:58 2008
@@ -80,7 +80,7 @@
   GError         *error = NULL;
 
   help_base = g_getenv (GIMP_HELP_ENV_URI);
-  help_root = g_build_path (G_DIR_SEPARATOR_S, gimp_data_directory (), GIMP_HELP_PREFIX, NULL);
+  help_root = g_build_filename (gimp_data_directory (), GIMP_HELP_PREFIX, NULL);
 
   context = g_option_context_new ("HELP-ID");
   g_option_context_add_main_entries (context, entries, NULL);
@@ -91,12 +91,14 @@
       return EXIT_FAILURE;
     }
 
+  g_type_init ();
+
   if (help_base)
     uri = g_strdup (help_base);
   else
     uri = g_filename_to_uri (help_root, NULL, NULL);
 
-  gimp_help_register_domain (GIMP_HELP_DEFAULT_DOMAIN, uri, help_root);
+  gimp_help_register_domain (GIMP_HELP_DEFAULT_DOMAIN, uri);
   g_free (uri);
 
   uri = lookup (GIMP_HELP_DEFAULT_DOMAIN,

Modified: trunk/plug-ins/help/gimphelp.c
==============================================================================
--- trunk/plug-ins/help/gimphelp.c	(original)
+++ trunk/plug-ins/help/gimphelp.c	Wed Apr  2 11:30:58 2008
@@ -84,13 +84,10 @@
       g_free (help_root);
     }
 
-  gimp_help_register_domain (GIMP_HELP_DEFAULT_DOMAIN,
-                             default_domain_uri, NULL);
+  gimp_help_register_domain (GIMP_HELP_DEFAULT_DOMAIN, default_domain_uri);
 
   for (i = 0; i < num_domain_names; i++)
-    {
-      gimp_help_register_domain (domain_names[i], domain_uris[i], NULL);
-    }
+    gimp_help_register_domain (domain_names[i], domain_uris[i]);
 
   g_free (default_domain_uri);
 
@@ -109,8 +106,7 @@
 
 void
 gimp_help_register_domain (const gchar *domain_name,
-                           const gchar *domain_uri,
-                           const gchar *domain_root)
+                           const gchar *domain_uri)
 {
   g_return_if_fail (domain_name != NULL);
   g_return_if_fail (domain_uri != NULL);
@@ -127,8 +123,7 @@
 
   g_hash_table_insert (domain_hash,
                        g_strdup (domain_name),
-                       gimp_help_domain_new (domain_name,
-                                             domain_uri, domain_root));
+                       gimp_help_domain_new (domain_name, domain_uri));
 }
 
 GimpHelpDomain *

Modified: trunk/plug-ins/help/gimphelp.h
==============================================================================
--- trunk/plug-ins/help/gimphelp.h	(original)
+++ trunk/plug-ins/help/gimphelp.h	Wed Apr  2 11:30:58 2008
@@ -49,8 +49,7 @@
 void             gimp_help_exit            (void);
 
 void             gimp_help_register_domain (const gchar    *domain_name,
-                                            const gchar    *domain_uri,
-                                            const gchar    *domain_root);
+                                            const gchar    *domain_uri);
 GimpHelpDomain * gimp_help_lookup_domain   (const gchar    *domain_name);
 
 GList          * gimp_help_parse_locales   (const gchar    *help_locales);

Modified: trunk/plug-ins/help/gimphelpdomain.c
==============================================================================
--- trunk/plug-ins/help/gimphelpdomain.c	(original)
+++ trunk/plug-ins/help/gimphelpdomain.c	Wed Apr  2 11:30:58 2008
@@ -44,25 +44,21 @@
 
 /*  local function prototypes  */
 
-static gboolean   domain_locale_parse      (GimpHelpDomain  *domain,
-                                            GimpHelpLocale  *locale,
-                                            GError         **error);
-
-static gchar    * domain_filename_from_uri (const gchar     *uri);
+static gboolean   domain_locale_parse (GimpHelpDomain  *domain,
+                                       GimpHelpLocale  *locale,
+                                       GError         **error);
 
 
 /*  public functions  */
 
 GimpHelpDomain *
 gimp_help_domain_new (const gchar *domain_name,
-                      const gchar *domain_uri,
-                      const gchar *domain_root)
+                      const gchar *domain_uri)
 {
   GimpHelpDomain *domain = g_slice_new0 (GimpHelpDomain);
 
   domain->help_domain = g_strdup (domain_name);
   domain->help_uri    = g_strdup (domain_uri);
-  domain->help_root   = g_strdup (domain_root);
 
   if (domain_uri)
     {
@@ -84,7 +80,6 @@
 
   g_free (domain->help_domain);
   g_free (domain->help_uri);
-  g_free (domain->help_root);
 
   g_slice_free (GimpHelpDomain, domain);
 }
@@ -209,70 +204,19 @@
                      GimpHelpLocale  *locale,
                      GError         **error)
 {
-  gchar    *filename;
+  gchar    *uri;
   gboolean  success;
 
   g_return_val_if_fail (domain != NULL, FALSE);
   g_return_val_if_fail (locale != NULL, FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  if (! domain->help_root)
-    domain->help_root = domain_filename_from_uri (domain->help_uri);
-
-  if (! domain->help_root)
-    {
-      g_set_error (error, 0, 0,
-                   "Cannot determine location of gimp-help.xml from '%s'",
-                   domain->help_uri);
-      return FALSE;
-    }
+  uri = g_strdup_printf ("%s/%s/gimp-help.xml",
+                         domain->help_uri, locale->locale_id);
 
-  filename = g_build_filename (domain->help_root,
-                               locale->locale_id,
-                               "gimp-help.xml",
-                               NULL);
-
-  success = gimp_help_locale_parse (locale,
-                                    filename,
-                                    domain->help_domain,
-                                    error);
+  success = gimp_help_locale_parse (locale, uri, domain->help_domain, error);
 
-  g_free (filename);
+  g_free (uri);
 
   return success;
 }
-
-static gchar *
-domain_filename_from_uri (const gchar *uri)
-{
-  gchar *filename;
-  gchar *hostname;
-
-  g_return_val_if_fail (uri != NULL, NULL);
-
-  filename = g_filename_from_uri (uri, &hostname, NULL);
-
-  if (!filename)
-    return NULL;
-
-  if (hostname)
-    {
-      /*  we have a file: URI with a hostname                           */
-#ifdef G_OS_WIN32
-      /*  on Win32, create a valid UNC path and use it as the filename  */
-
-      gchar *tmp = g_build_filename ("//", hostname, filename, NULL);
-
-      g_free (filename);
-      filename = tmp;
-#else
-      /*  otherwise return NULL, caller should use URI then             */
-      g_free (filename);
-      filename = NULL;
-#endif
-
-      g_free (hostname);
-    }
-
-  return filename;
-}

Modified: trunk/plug-ins/help/gimphelpdomain.h
==============================================================================
--- trunk/plug-ins/help/gimphelpdomain.h	(original)
+++ trunk/plug-ins/help/gimphelpdomain.h	Wed Apr  2 11:30:58 2008
@@ -29,14 +29,12 @@
 {
   gchar      *help_domain;
   gchar      *help_uri;
-  gchar      *help_root;
   GHashTable *help_locales;
 };
 
 
 GimpHelpDomain * gimp_help_domain_new           (const gchar     *domain_name,
-                                                 const gchar     *domain_uri,
-                                                 const gchar     *domain_root);
+                                                 const gchar     *domain_uri);
 void             gimp_help_domain_free          (GimpHelpDomain  *domain);
 
 GimpHelpLocale * gimp_help_domain_lookup_locale (GimpHelpDomain  *domain,

Modified: trunk/plug-ins/help/gimphelplocale.c
==============================================================================
--- trunk/plug-ins/help/gimphelplocale.c	(original)
+++ trunk/plug-ins/help/gimphelplocale.c	Wed Apr  2 11:30:58 2008
@@ -29,7 +29,8 @@
 
 #include <string.h>
 
-#include <glib.h>
+#include <glib-object.h>
+#include <gio/gio.h>
 
 #include "gimphelp.h"
 
@@ -44,7 +45,7 @@
 
 static void   locale_set_error (GError      **error,
                                 const gchar  *format,
-                                const gchar  *filename);
+                                GFile        *file);
 
 
 /*  public functions  */
@@ -103,7 +104,7 @@
 
 typedef struct
 {
-  const gchar       *filename;
+  GFile             *file;
   LocaleParserState  state;
   LocaleParserState  last_known_state;
   gint               markup_depth;
@@ -116,7 +117,7 @@
 } LocaleParser;
 
 static gboolean  locale_parser_parse       (GMarkupParseContext  *context,
-                                            GIOChannel           *io,
+                                            GInputStream         *stream,
                                             GError              **error);
 static void  locale_parser_start_element   (GMarkupParseContext  *context,
                                             const gchar          *element_name,
@@ -154,17 +155,18 @@
 
 gboolean
 gimp_help_locale_parse (GimpHelpLocale  *locale,
-                        const gchar     *filename,
+                        const gchar     *uri,
                         const gchar     *help_domain,
                         GError         **error)
 {
   GMarkupParseContext *context;
-  GIOChannel          *io;
+  GFile               *file;
+  GFileInputStream    *stream;
   LocaleParser         parser = { NULL, };
   gboolean             success;
 
   g_return_val_if_fail (locale != NULL, FALSE);
-  g_return_val_if_fail (filename != NULL, FALSE);
+  g_return_val_if_fail (uri != NULL, FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
   if (locale->help_id_mapping)
@@ -181,21 +183,22 @@
 
 #ifdef GIMP_HELP_DEBUG
   g_printerr ("help (%s): parsing '%s' for locale \"%s\"\n",
-              locale->locale_id,
-              filename,
-              help_domain);
+              locale->locale_id, uri, help_domain);
 #endif
 
-  io = g_io_channel_new_file (filename, "r", error);
-  if (! io)
+  file = g_file_new_for_uri (uri);
+
+  stream = g_file_read (file, NULL, error);
+
+  if (! stream)
     {
-      locale_set_error (error,
-                        _("Could not open '%s' for reading: %s"),
-                        filename);
+      locale_set_error (error, _("Could not open '%s' for reading: %s"), file);
+      g_object_unref (file);
+
       return FALSE;
     }
 
-  parser.filename     = filename;
+  parser.file         = file;
   parser.value        = g_string_new (NULL);
   parser.locale       = locale;
   parser.help_domain  = help_domain;
@@ -203,50 +206,45 @@
 
   context = g_markup_parse_context_new (&markup_parser, 0, &parser, NULL);
 
-  success = locale_parser_parse (context, io, error);
+  success = locale_parser_parse (context, G_INPUT_STREAM (stream), error);
 
   g_markup_parse_context_free (context);
-  g_io_channel_unref (io);
+  g_object_unref (stream);
 
   g_string_free (parser.value, TRUE);
   g_free (parser.id_attr_name);
 
   if (! success)
-    locale_set_error (error, _("Parse error in '%s':\n%s"), filename);
+    locale_set_error (error, _("Parse error in '%s':\n%s"), file);
+
+  g_object_unref (file);
 
   return success;
 }
 
 static gboolean
 locale_parser_parse (GMarkupParseContext  *context,
-                     GIOChannel           *io,
+                     GInputStream         *stream,
                      GError              **error)
 {
-  GIOStatus  status;
-  gsize      len;
-  gchar      buffer[4096];
+  gssize len;
+  gchar  buffer[4096];
 
-  while (TRUE)
+  while ((len = g_input_stream_read (stream, buffer, sizeof (buffer),
+                                     NULL, error)) != -1)
     {
-      status = g_io_channel_read_chars (io,
-                                        buffer, sizeof (buffer), &len, error);
-
-      switch (status)
+      switch (len)
         {
-        case G_IO_STATUS_ERROR:
-          return FALSE;
-        case G_IO_STATUS_EOF:
+        case 0:
           return g_markup_parse_context_end_parse (context, error);
-        case G_IO_STATUS_NORMAL:
+
+        default:
           if (! g_markup_parse_context_parse (context, buffer, len, error))
             return FALSE;
-          break;
-        case G_IO_STATUS_AGAIN:
-          break;
         }
     }
 
-  return TRUE;
+  return FALSE;
 }
 
 static void
@@ -332,8 +330,11 @@
                      gpointer             user_data)
 {
   LocaleParser *parser = (LocaleParser *) user_data;
+  gchar        *name   = g_file_get_parse_name (parser->file);
+
+  g_printerr ("help (parsing %s): %s", name, error->message);
 
-  g_printerr ("help (parsing %s): %s", parser->filename, error->message);
+  g_free (name);
 }
 
 static void
@@ -453,13 +454,14 @@
 static void
 locale_set_error (GError      **error,
                   const gchar  *format,
-                  const gchar  *filename)
+                  GFile        *file)
 {
   if (error && *error)
     {
-      gchar *name = g_filename_display_name (filename);
-      gchar *msg  = g_strdup_printf (format, name, (*error)->message);
+      gchar *name = g_file_get_parse_name (file);
+      gchar *msg;
 
+      msg = g_strdup_printf (format, name, (*error)->message);
       g_free (name);
 
       g_free ((*error)->message);

Modified: trunk/plug-ins/help/gimphelplocale.h
==============================================================================
--- trunk/plug-ins/help/gimphelplocale.h	(original)
+++ trunk/plug-ins/help/gimphelplocale.h	Wed Apr  2 11:30:58 2008
@@ -43,7 +43,7 @@
                                               const gchar     *help_id);
 
 gboolean         gimp_help_locale_parse      (GimpHelpLocale  *locale,
-                                              const gchar     *filename,
+                                              const gchar     *uri,
                                               const gchar     *help_domain,
                                               GError         **error);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]