2
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
4
* The GIMP Help plug-in
5
* Copyright (C) 1999-2004 Sven Neumann <sven@gimp.org>
5
* Copyright (C) 1999-2008 Sven Neumann <sven@gimp.org>
6
6
* Michael Natterer <mitch@gimp.org>
7
7
* Henrik Brix Andersen <brix@gimp.org>
45
46
/* local function prototypes */
47
static gboolean domain_locale_parse (GimpHelpDomain *domain,
48
GimpHelpLocale *locale,
51
static gchar * domain_filename_from_uri (const gchar *uri);
48
static gboolean domain_locale_parse (GimpHelpDomain *domain,
49
GimpHelpLocale *locale,
50
GimpHelpProgress *progress,
54
54
/* public functions */
57
57
gimp_help_domain_new (const gchar *domain_name,
58
const gchar *domain_uri,
59
const gchar *domain_root)
58
const gchar *domain_uri)
61
60
GimpHelpDomain *domain = g_slice_new0 (GimpHelpDomain);
63
62
domain->help_domain = g_strdup (domain_name);
64
63
domain->help_uri = g_strdup (domain_uri);
65
domain->help_root = g_strdup (domain_root);
85
83
g_free (domain->help_domain);
86
84
g_free (domain->help_uri);
87
g_free (domain->help_root);
89
86
g_slice_free (GimpHelpDomain, domain);
93
gimp_help_domain_lookup_locale (GimpHelpDomain *domain,
94
const gchar *locale_id)
90
gimp_help_domain_lookup_locale (GimpHelpDomain *domain,
91
const gchar *locale_id,
92
GimpHelpProgress *progress)
96
94
GimpHelpLocale *locale = NULL;
109
107
locale = gimp_help_locale_new (locale_id);
110
108
g_hash_table_insert (domain->help_locales, g_strdup (locale_id), locale);
112
domain_locale_parse (domain, locale, NULL);
110
domain_locale_parse (domain, locale, progress, NULL);
118
gimp_help_domain_map (GimpHelpDomain *domain,
120
const gchar *help_id,
121
GimpHelpLocale **ret_locale,
122
gboolean *fatal_error)
116
gimp_help_domain_map (GimpHelpDomain *domain,
118
const gchar *help_id,
119
GimpHelpProgress *progress,
120
GimpHelpLocale **ret_locale,
121
gboolean *fatal_error)
124
123
GimpHelpLocale *locale = NULL;
125
124
const gchar *ref = NULL;
136
135
for (list = help_locales; list && !ref; list = list->next)
138
137
locale = gimp_help_domain_lookup_locale (domain,
139
(const gchar *) list->data);
138
(const gchar *) list->data,
140
140
ref = gimp_help_locale_map (locale, help_id);
144
144
for (list = help_locales; list && !ref; list = list->next)
146
146
locale = gimp_help_domain_lookup_locale (domain,
147
(const gchar *) list->data);
147
(const gchar *) list->data,
148
149
ref = locale->help_missing;
170
171
locale = gimp_help_domain_lookup_locale (domain,
171
GIMP_HELP_DEFAULT_LOCALE);
172
GIMP_HELP_DEFAULT_LOCALE, NULL);
173
if (! domain_locale_parse (domain, locale, &error))
174
if (! domain_locale_parse (domain, locale, NULL, &error))
175
if (error->code == G_FILE_ERROR_NOENT)
178
case G_IO_ERROR_NOT_FOUND:
179
if (domain->help_domain)
181
g_message (_("The help pages for '%s' are not available."),
182
domain->help_domain);
186
g_message ("%s\n\n%s",
187
_("The GIMP user manual is not available."),
188
_("Please install the additional help package "
189
"or use the online user manual at "
190
"http://docs.gimp.org/."));
194
case G_IO_ERROR_NOT_SUPPORTED:
177
195
g_message ("%s\n\n%s",
178
_("The GIMP help files are not found."),
179
_("Please install the additional help package or use "
180
"the online user manual at http://docs.gimp.org/."));
184
g_message ("%s\n\n%s\n\n%s",
185
_("There is a problem with the GIMP help files."),
187
_("Please check your installation."));
197
_("Perhaps you are missing GIO backends and need "
198
"to install GVFS?"));
201
case G_IO_ERROR_CANCELLED:
205
g_message (error->message);
190
209
g_error_free (error);
205
224
/* private functions */
208
domain_locale_parse (GimpHelpDomain *domain,
209
GimpHelpLocale *locale,
227
domain_locale_parse (GimpHelpDomain *domain,
228
GimpHelpLocale *locale,
229
GimpHelpProgress *progress,
213
233
gboolean success;
215
235
g_return_val_if_fail (domain != NULL, FALSE);
216
236
g_return_val_if_fail (locale != NULL, FALSE);
217
237
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
219
if (! domain->help_root)
220
domain->help_root = domain_filename_from_uri (domain->help_uri);
222
if (! domain->help_root)
224
g_set_error (error, 0, 0,
225
"Cannot determine location of gimp-help.xml from '%s'",
230
filename = g_build_filename (domain->help_root,
235
success = gimp_help_locale_parse (locale,
239
uri = g_strdup_printf ("%s/%s/gimp-help.xml",
240
domain->help_uri, locale->locale_id);
242
success = gimp_help_locale_parse (locale, uri, domain->help_domain,
246
domain_filename_from_uri (const gchar *uri)
251
g_return_val_if_fail (uri != NULL, NULL);
253
filename = g_filename_from_uri (uri, &hostname, NULL);
260
/* we have a file: URI with a hostname */
262
/* on Win32, create a valid UNC path and use it as the filename */
264
gchar *tmp = g_build_filename ("//", hostname, filename, NULL);
269
/* otherwise return NULL, caller should use URI then */