2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-08-28 18:49:11 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2004-03-09 01:45:21 +00:00
|
|
|
* The GIMP Help plug-in
|
2008-05-16 16:56:33 +00:00
|
|
|
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
|
2003-08-28 18:49:11 +00:00
|
|
|
* Michael Natterer <mitch@gimp.org>
|
2004-03-09 01:45:21 +00:00
|
|
|
* Henrik Brix Andersen <brix@gimp.org>
|
2003-08-28 18:49:11 +00:00
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-08-28 18:49:11 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-08-28 18:49:11 +00: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-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-08-28 18:49:11 +00:00
|
|
|
*/
|
|
|
|
|
2004-08-14 15:47:22 +00:00
|
|
|
/* This code is written so that it can also be compiled standalone.
|
|
|
|
* It shouldn't depend on libgimp.
|
|
|
|
*/
|
|
|
|
|
2003-08-28 18:49:11 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
#include <glib-object.h>
|
2008-05-16 16:56:33 +00:00
|
|
|
#include <gio/gio.h>
|
2004-01-19 03:06:04 +00:00
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
|
|
|
#include "gimphelp.h"
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2004-08-14 15:47:22 +00:00
|
|
|
#ifdef DISABLE_NLS
|
|
|
|
#define _(String) (String)
|
|
|
|
#else
|
2004-01-15 20:07:51 +00:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
2004-08-14 15:47:22 +00:00
|
|
|
#endif
|
2004-01-15 20:07:51 +00:00
|
|
|
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2025-02-20 17:54:08 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gboolean *success;
|
2025-03-06 13:53:13 -05:00
|
|
|
gboolean *done;
|
2025-02-20 17:54:08 +01:00
|
|
|
|
|
|
|
GimpHelpLocale *locale;
|
|
|
|
const gchar *uri;
|
|
|
|
const gchar *domain;
|
|
|
|
GimpHelpProgress *progress;
|
|
|
|
GCancellable *cancellable;
|
|
|
|
GError **error;
|
|
|
|
} HelpThreadData;
|
|
|
|
|
2003-08-28 18:49:11 +00:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2025-02-20 17:54:08 +01:00
|
|
|
static gboolean parse_thread_func (HelpThreadData *data);
|
2008-05-16 16:56:33 +00:00
|
|
|
static gboolean domain_locale_parse (GimpHelpDomain *domain,
|
|
|
|
GimpHelpLocale *locale,
|
|
|
|
GimpHelpProgress *progress,
|
|
|
|
GError **error);
|
2004-03-18 02:45:52 +00:00
|
|
|
|
2005-02-07 18:06:17 +00:00
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
/* public functions */
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
GimpHelpDomain *
|
|
|
|
gimp_help_domain_new (const gchar *domain_name,
|
2008-04-02 10:30:58 +00:00
|
|
|
const gchar *domain_uri)
|
2006-11-20 21:46:21 +00:00
|
|
|
{
|
2007-05-23 13:59:51 +00:00
|
|
|
GimpHelpDomain *domain = g_slice_new0 (GimpHelpDomain);
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
domain->help_domain = g_strdup (domain_name);
|
|
|
|
domain->help_uri = g_strdup (domain_uri);
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
if (domain_uri)
|
|
|
|
{
|
|
|
|
/* strip trailing slash */
|
|
|
|
if (g_str_has_suffix (domain->help_uri, "/"))
|
|
|
|
domain->help_uri[strlen (domain->help_uri) - 1] = '\0';
|
|
|
|
}
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
return domain;
|
|
|
|
}
|
2003-08-28 18:49:11 +00:00
|
|
|
|
|
|
|
void
|
2006-11-20 21:46:21 +00:00
|
|
|
gimp_help_domain_free (GimpHelpDomain *domain)
|
2003-08-28 18:49:11 +00:00
|
|
|
{
|
2006-11-20 21:46:21 +00:00
|
|
|
g_return_if_fail (domain != NULL);
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
if (domain->help_locales)
|
|
|
|
g_hash_table_destroy (domain->help_locales);
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
g_free (domain->help_domain);
|
|
|
|
g_free (domain->help_uri);
|
2007-05-23 13:59:51 +00:00
|
|
|
|
|
|
|
g_slice_free (GimpHelpDomain, domain);
|
2003-08-28 18:49:11 +00:00
|
|
|
}
|
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
GimpHelpLocale *
|
2008-05-16 16:56:33 +00:00
|
|
|
gimp_help_domain_lookup_locale (GimpHelpDomain *domain,
|
|
|
|
const gchar *locale_id,
|
|
|
|
GimpHelpProgress *progress)
|
2003-08-28 18:49:11 +00:00
|
|
|
{
|
2006-11-20 21:46:21 +00:00
|
|
|
GimpHelpLocale *locale = NULL;
|
|
|
|
|
|
|
|
if (domain->help_locales)
|
|
|
|
locale = g_hash_table_lookup (domain->help_locales, locale_id);
|
|
|
|
else
|
|
|
|
domain->help_locales =
|
|
|
|
g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
g_free,
|
|
|
|
(GDestroyNotify) gimp_help_locale_free);
|
|
|
|
|
|
|
|
if (locale)
|
|
|
|
return locale;
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
locale = gimp_help_locale_new (locale_id);
|
|
|
|
|
2025-02-21 16:23:49 +01:00
|
|
|
if (! domain_locale_parse (domain, locale, progress, NULL))
|
|
|
|
g_clear_pointer (&locale, gimp_help_locale_free);
|
|
|
|
else
|
|
|
|
g_hash_table_insert (domain->help_locales, g_strdup (locale_id), locale);
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
return locale;
|
2003-08-28 18:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
2008-05-16 16:56:33 +00:00
|
|
|
gimp_help_domain_map (GimpHelpDomain *domain,
|
|
|
|
GList *help_locales,
|
|
|
|
const gchar *help_id,
|
|
|
|
GimpHelpProgress *progress,
|
|
|
|
GimpHelpLocale **ret_locale,
|
|
|
|
gboolean *fatal_error)
|
2003-08-28 18:49:11 +00:00
|
|
|
{
|
2006-11-20 21:46:21 +00:00
|
|
|
GimpHelpLocale *locale = NULL;
|
|
|
|
const gchar *ref = NULL;
|
|
|
|
GList *list;
|
2003-08-28 18:49:11 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (domain != NULL, NULL);
|
2004-03-18 00:11:03 +00:00
|
|
|
g_return_val_if_fail (help_locales != NULL, NULL);
|
2003-08-28 18:49:11 +00:00
|
|
|
g_return_val_if_fail (help_id != NULL, NULL);
|
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
if (fatal_error)
|
|
|
|
*fatal_error = FALSE;
|
|
|
|
|
2025-03-06 13:46:51 -05:00
|
|
|
/* Look for a reference matching the help_id */
|
2004-03-18 02:45:52 +00:00
|
|
|
for (list = help_locales; list && !ref; list = list->next)
|
2003-08-28 18:49:11 +00:00
|
|
|
{
|
2006-11-20 21:46:21 +00:00
|
|
|
locale = gimp_help_domain_lookup_locale (domain,
|
2008-05-16 16:56:33 +00:00
|
|
|
(const gchar *) list->data,
|
|
|
|
progress);
|
2025-03-06 13:46:51 -05:00
|
|
|
if (locale)
|
|
|
|
{
|
|
|
|
ref = gimp_help_locale_map (locale, help_id);
|
|
|
|
/* It doesn't make sense to keep looking since all available locales
|
|
|
|
* have the same pages available. If the first locale present
|
|
|
|
* doesn't have it, the others won't have it either. */
|
|
|
|
if (! ref)
|
|
|
|
ref = locale->help_missing;
|
|
|
|
}
|
2004-03-18 12:18:12 +00:00
|
|
|
}
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2025-03-06 13:46:51 -05:00
|
|
|
if (ret_locale && locale)
|
2006-11-23 20:36:17 +00:00
|
|
|
*ret_locale = locale;
|
|
|
|
|
2004-03-18 12:18:12 +00:00
|
|
|
if (ref)
|
|
|
|
{
|
|
|
|
return g_strconcat (domain->help_uri, "/",
|
|
|
|
locale->locale_id, "/",
|
|
|
|
ref,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else /* try to assemble a useful error message */
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2004-03-18 02:45:52 +00:00
|
|
|
|
2004-03-18 12:18:12 +00:00
|
|
|
#ifdef GIMP_HELP_DEBUG
|
|
|
|
g_printerr ("help: help_id lookup and all fallbacks failed for '%s'\n",
|
|
|
|
help_id);
|
2004-03-18 02:45:52 +00:00
|
|
|
#endif
|
2004-03-18 00:11:03 +00:00
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
locale = gimp_help_domain_lookup_locale (domain,
|
2008-05-16 16:56:33 +00:00
|
|
|
GIMP_HELP_DEFAULT_LOCALE, NULL);
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2025-03-06 13:46:51 -05:00
|
|
|
if (locale && ! domain_locale_parse (domain, locale, NULL, &error))
|
2004-03-18 12:18:12 +00:00
|
|
|
{
|
2008-05-16 16:56:33 +00:00
|
|
|
switch (error->code)
|
2005-10-05 22:27:50 +00:00
|
|
|
{
|
2008-05-16 16:56:33 +00:00
|
|
|
case G_IO_ERROR_NOT_FOUND:
|
2008-07-06 09:45:35 +00:00
|
|
|
if (domain->help_domain)
|
|
|
|
{
|
|
|
|
g_message (_("The help pages for '%s' are not available."),
|
|
|
|
domain->help_domain);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_message ("%s\n\n%s",
|
|
|
|
_("The GIMP user manual is not available."),
|
2016-02-26 17:15:14 +01:00
|
|
|
/* TRANSLATORS: do not end the URL with a dot,
|
|
|
|
* it would be in the link. Because of
|
|
|
|
* technical limitations, make sure the URL
|
|
|
|
* ends with a space, a newline or is end of text.
|
|
|
|
* Cf. bug 762282.
|
|
|
|
*/
|
2008-07-06 09:45:35 +00:00
|
|
|
_("Please install the additional help package "
|
2016-02-25 16:32:44 +01:00
|
|
|
"or use the online user manual at: "
|
2018-07-14 14:13:22 +02:00
|
|
|
"https://docs.gimp.org/"));
|
2008-07-06 09:45:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_IO_ERROR_NOT_SUPPORTED:
|
2005-10-05 22:27:50 +00:00
|
|
|
g_message ("%s\n\n%s",
|
2008-07-06 09:45:35 +00:00
|
|
|
error->message,
|
|
|
|
_("Perhaps you are missing GIO backends and need "
|
|
|
|
"to install GVFS?"));
|
2008-05-16 16:56:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case G_IO_ERROR_CANCELLED:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-11-04 14:05:24 +00:00
|
|
|
g_message ("%s", error->message);
|
2008-05-16 16:56:33 +00:00
|
|
|
break;
|
2005-10-05 22:27:50 +00:00
|
|
|
}
|
2004-03-18 02:45:52 +00:00
|
|
|
|
2004-03-18 12:18:12 +00:00
|
|
|
g_error_free (error);
|
2004-12-05 19:50:37 +00:00
|
|
|
|
2006-11-20 21:46:21 +00:00
|
|
|
if (fatal_error)
|
|
|
|
*fatal_error = TRUE;
|
2004-03-18 12:18:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_message (_("Help ID '%s' unknown"), help_id);
|
|
|
|
}
|
2004-03-18 02:45:52 +00:00
|
|
|
|
2004-03-18 12:18:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-03-18 02:45:52 +00:00
|
|
|
|
2003-08-28 18:49:11 +00:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2025-03-06 13:53:13 -05:00
|
|
|
G_LOCK_DEFINE (done);
|
2025-02-20 17:54:08 +01:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
parse_thread_func (HelpThreadData *data)
|
|
|
|
{
|
|
|
|
|
2025-03-06 13:53:13 -05:00
|
|
|
*data->success = gimp_help_locale_parse (data->locale, data->uri, data->domain,
|
|
|
|
data->progress, data->cancellable, data->error);
|
|
|
|
G_LOCK (done);
|
|
|
|
*data->done = TRUE;
|
|
|
|
G_UNLOCK (done);
|
2025-02-20 17:54:08 +01:00
|
|
|
|
2025-03-06 13:53:13 -05:00
|
|
|
return *data->success;
|
2025-02-20 17:54:08 +01:00
|
|
|
}
|
|
|
|
|
2004-03-18 00:11:03 +00:00
|
|
|
static gboolean
|
2008-05-16 16:56:33 +00:00
|
|
|
domain_locale_parse (GimpHelpDomain *domain,
|
|
|
|
GimpHelpLocale *locale,
|
|
|
|
GimpHelpProgress *progress,
|
|
|
|
GError **error)
|
2003-08-28 18:49:11 +00:00
|
|
|
{
|
2025-02-20 17:54:08 +01:00
|
|
|
GCancellable *cancellable;
|
|
|
|
gchar *uri;
|
|
|
|
GThread *thread;
|
|
|
|
GTimer *timer;
|
|
|
|
gboolean success = FALSE;
|
2025-03-06 13:53:13 -05:00
|
|
|
gboolean done = FALSE;
|
2025-02-20 17:54:08 +01:00
|
|
|
HelpThreadData data;
|
2003-08-28 18:49:11 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (domain != NULL, FALSE);
|
2004-03-18 02:45:52 +00:00
|
|
|
g_return_val_if_fail (locale != NULL, FALSE);
|
2004-03-18 00:11:03 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2008-04-02 10:30:58 +00:00
|
|
|
uri = g_strdup_printf ("%s/%s/gimp-help.xml",
|
|
|
|
domain->help_uri, locale->locale_id);
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2025-02-20 17:54:08 +01:00
|
|
|
timer = g_timer_new ();
|
|
|
|
cancellable = g_cancellable_new ();
|
2025-03-06 13:53:13 -05:00
|
|
|
data.done = &done;
|
2025-02-20 17:54:08 +01:00
|
|
|
data.success = &success;
|
|
|
|
data.locale = locale;
|
|
|
|
data.uri = uri;
|
|
|
|
data.domain = domain->help_domain;
|
|
|
|
data.progress = progress;
|
|
|
|
data.cancellable = cancellable;
|
|
|
|
data.error = error;
|
|
|
|
thread = g_thread_new (NULL, (GThreadFunc) parse_thread_func, &data);
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
gboolean exit;
|
|
|
|
|
2025-03-06 13:53:13 -05:00
|
|
|
G_LOCK (done);
|
|
|
|
exit = *data.done;
|
|
|
|
G_UNLOCK (done);
|
2025-02-20 17:54:08 +01:00
|
|
|
|
|
|
|
if (! exit && g_timer_elapsed (timer, NULL) > 10.0)
|
|
|
|
{
|
|
|
|
g_cancellable_cancel (cancellable);
|
|
|
|
exit = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exit)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_thread_join (thread);
|
2004-03-18 12:18:12 +00:00
|
|
|
|
2008-04-02 10:30:58 +00:00
|
|
|
g_free (uri);
|
2025-02-20 17:54:08 +01:00
|
|
|
g_timer_destroy (timer);
|
|
|
|
g_object_unref (cancellable);
|
2003-08-28 18:49:11 +00:00
|
|
|
|
2004-03-18 12:18:12 +00:00
|
|
|
return success;
|
2003-08-28 18:49:11 +00:00
|
|
|
}
|