~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/help/gimphelpdomain.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: james.westby@ubuntu.com-20081006133041-3panbkcanaymfsmp
Tags: upstream-2.6.0
ImportĀ upstreamĀ versionĀ 2.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
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>
8
8
 *
30
30
#include <string.h>
31
31
 
32
32
#include <glib-object.h>
 
33
#include <gio/gio.h>
33
34
 
34
35
#include "libgimpbase/gimpbase.h"
35
36
 
44
45
 
45
46
/*  local function prototypes  */
46
47
 
47
 
static gboolean   domain_locale_parse      (GimpHelpDomain  *domain,
48
 
                                            GimpHelpLocale  *locale,
49
 
                                            GError         **error);
50
 
 
51
 
static gchar    * domain_filename_from_uri (const gchar     *uri);
 
48
static gboolean   domain_locale_parse (GimpHelpDomain    *domain,
 
49
                                       GimpHelpLocale    *locale,
 
50
                                       GimpHelpProgress  *progress,
 
51
                                       GError           **error);
52
52
 
53
53
 
54
54
/*  public functions  */
55
55
 
56
56
GimpHelpDomain *
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)
60
59
{
61
60
  GimpHelpDomain *domain = g_slice_new0 (GimpHelpDomain);
62
61
 
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);
66
64
 
67
65
  if (domain_uri)
68
66
    {
84
82
 
85
83
  g_free (domain->help_domain);
86
84
  g_free (domain->help_uri);
87
 
  g_free (domain->help_root);
88
85
 
89
86
  g_slice_free (GimpHelpDomain, domain);
90
87
}
91
88
 
92
89
GimpHelpLocale *
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)
95
93
{
96
94
  GimpHelpLocale *locale = NULL;
97
95
 
109
107
  locale = gimp_help_locale_new (locale_id);
110
108
  g_hash_table_insert (domain->help_locales, g_strdup (locale_id), locale);
111
109
 
112
 
  domain_locale_parse (domain, locale, NULL);
 
110
  domain_locale_parse (domain, locale, progress, NULL);
113
111
 
114
112
  return locale;
115
113
}
116
114
 
117
115
gchar *
118
 
gimp_help_domain_map (GimpHelpDomain  *domain,
119
 
                      GList           *help_locales,
120
 
                      const gchar     *help_id,
121
 
                      GimpHelpLocale **ret_locale,
122
 
                      gboolean        *fatal_error)
 
116
gimp_help_domain_map (GimpHelpDomain    *domain,
 
117
                      GList             *help_locales,
 
118
                      const gchar       *help_id,
 
119
                      GimpHelpProgress  *progress,
 
120
                      GimpHelpLocale   **ret_locale,
 
121
                      gboolean          *fatal_error)
123
122
{
124
123
  GimpHelpLocale *locale = NULL;
125
124
  const gchar    *ref    = NULL;
136
135
  for (list = help_locales; list && !ref; list = list->next)
137
136
    {
138
137
      locale = gimp_help_domain_lookup_locale (domain,
139
 
                                               (const gchar *) list->data);
 
138
                                               (const gchar *) list->data,
 
139
                                               progress);
140
140
      ref = gimp_help_locale_map (locale, help_id);
141
141
    }
142
142
 
144
144
  for (list = help_locales; list && !ref; list = list->next)
145
145
    {
146
146
      locale = gimp_help_domain_lookup_locale (domain,
147
 
                                               (const gchar *) list->data);
 
147
                                               (const gchar *) list->data,
 
148
                                               progress);
148
149
      ref = locale->help_missing;
149
150
    }
150
151
 
168
169
#endif
169
170
 
170
171
      locale = gimp_help_domain_lookup_locale (domain,
171
 
                                               GIMP_HELP_DEFAULT_LOCALE);
 
172
                                               GIMP_HELP_DEFAULT_LOCALE, NULL);
172
173
 
173
 
      if (! domain_locale_parse (domain, locale, &error))
 
174
      if (! domain_locale_parse (domain, locale, NULL, &error))
174
175
        {
175
 
          if (error->code == G_FILE_ERROR_NOENT)
 
176
          switch (error->code)
176
177
            {
 
178
            case G_IO_ERROR_NOT_FOUND:
 
179
              if (domain->help_domain)
 
180
                {
 
181
                  g_message (_("The help pages for '%s' are not available."),
 
182
                             domain->help_domain);
 
183
                }
 
184
              else
 
185
                {
 
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/."));
 
191
                }
 
192
              break;
 
193
 
 
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/."));
181
 
            }
182
 
          else
183
 
            {
184
 
              g_message ("%s\n\n%s\n\n%s",
185
 
                         _("There is a problem with the GIMP help files."),
186
196
                         error->message,
187
 
                         _("Please check your installation."));
 
197
                         _("Perhaps you are missing GIO backends and need "
 
198
                           "to install GVFS?"));
 
199
              break;
 
200
 
 
201
            case G_IO_ERROR_CANCELLED:
 
202
              break;
 
203
 
 
204
            default:
 
205
              g_message (error->message);
 
206
              break;
188
207
            }
189
208
 
190
209
          g_error_free (error);
205
224
/*  private functions  */
206
225
 
207
226
static gboolean
208
 
domain_locale_parse (GimpHelpDomain  *domain,
209
 
                     GimpHelpLocale  *locale,
210
 
                     GError         **error)
 
227
domain_locale_parse (GimpHelpDomain    *domain,
 
228
                     GimpHelpLocale    *locale,
 
229
                     GimpHelpProgress  *progress,
 
230
                     GError           **error)
211
231
{
212
 
  gchar    *filename;
 
232
  gchar    *uri;
213
233
  gboolean  success;
214
234
 
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);
218
238
 
219
 
  if (! domain->help_root)
220
 
    domain->help_root = domain_filename_from_uri (domain->help_uri);
221
 
 
222
 
  if (! domain->help_root)
223
 
    {
224
 
      g_set_error (error, 0, 0,
225
 
                   "Cannot determine location of gimp-help.xml from '%s'",
226
 
                   domain->help_uri);
227
 
      return FALSE;
228
 
    }
229
 
 
230
 
  filename = g_build_filename (domain->help_root,
231
 
                               locale->locale_id,
232
 
                               "gimp-help.xml",
233
 
                               NULL);
234
 
 
235
 
  success = gimp_help_locale_parse (locale,
236
 
                                    filename,
237
 
                                    domain->help_domain,
238
 
                                    error);
239
 
 
240
 
  g_free (filename);
 
239
  uri = g_strdup_printf ("%s/%s/gimp-help.xml",
 
240
                         domain->help_uri, locale->locale_id);
 
241
 
 
242
  success = gimp_help_locale_parse (locale, uri, domain->help_domain,
 
243
                                    progress, error);
 
244
 
 
245
  g_free (uri);
241
246
 
242
247
  return success;
243
248
}
244
 
 
245
 
static gchar *
246
 
domain_filename_from_uri (const gchar *uri)
247
 
{
248
 
  gchar *filename;
249
 
  gchar *hostname;
250
 
 
251
 
  g_return_val_if_fail (uri != NULL, NULL);
252
 
 
253
 
  filename = g_filename_from_uri (uri, &hostname, NULL);
254
 
 
255
 
  if (!filename)
256
 
    return NULL;
257
 
 
258
 
  if (hostname)
259
 
    {
260
 
      /*  we have a file: URI with a hostname                           */
261
 
#ifdef G_OS_WIN32
262
 
      /*  on Win32, create a valid UNC path and use it as the filename  */
263
 
 
264
 
      gchar *tmp = g_build_filename ("//", hostname, filename, NULL);
265
 
 
266
 
      g_free (filename);
267
 
      filename = tmp;
268
 
#else
269
 
      /*  otherwise return NULL, caller should use URI then             */
270
 
      g_free (filename);
271
 
      filename = NULL;
272
 
#endif
273
 
 
274
 
      g_free (hostname);
275
 
    }
276
 
 
277
 
  return filename;
278
 
}