~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

Viewing changes to app/core/gimp-modules.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimpmodules.c
 
5
 * (C) 1999 Austin Donnelly <austin@gimp.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <glib-object.h>
 
25
 
 
26
#include "libgimpbase/gimpbase.h"
 
27
#include "libgimpmodule/gimpmodule.h"
 
28
 
 
29
#include "core-types.h"
 
30
 
 
31
#include "config/gimpconfig-path.h"
 
32
#include "config/gimpconfigwriter.h"
 
33
#include "config/gimpcoreconfig.h"
 
34
#include "config/gimpscanner.h"
 
35
 
 
36
#include "gimp.h"
 
37
#include "gimp-modules.h"
 
38
 
 
39
#include "gimp-intl.h"
 
40
 
 
41
 
 
42
void
 
43
gimp_modules_init (Gimp *gimp)
 
44
{
 
45
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
46
 
 
47
  if (! gimp->no_interface)
 
48
    {
 
49
      gimp->module_db = gimp_module_db_new (gimp->be_verbose);
 
50
      gimp->write_modulerc = FALSE;
 
51
    }
 
52
}
 
53
 
 
54
void
 
55
gimp_modules_exit (Gimp *gimp)
 
56
{
 
57
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
58
 
 
59
  if (gimp->module_db)
 
60
    {
 
61
      g_object_unref (gimp->module_db);
 
62
      gimp->module_db = NULL;
 
63
    }
 
64
}
 
65
 
 
66
void
 
67
gimp_modules_load (Gimp *gimp)
 
68
{
 
69
  gchar    *filename;
 
70
  gchar    *path;
 
71
  GScanner *scanner;
 
72
  gchar    *module_load_inhibit = NULL;
 
73
 
 
74
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
75
 
 
76
  if (gimp->no_interface)
 
77
    return;
 
78
 
 
79
  filename = gimp_personal_rc_file ("modulerc");
 
80
  scanner = gimp_scanner_new_file (filename, NULL);
 
81
  g_free (filename);
 
82
 
 
83
  if (scanner)
 
84
    {
 
85
      GTokenType  token;
 
86
      GError     *error = NULL;
 
87
 
 
88
#define MODULE_LOAD_INHIBIT 1
 
89
 
 
90
      g_scanner_scope_add_symbol (scanner, 0, "module-load-inhibit",
 
91
                                  GINT_TO_POINTER (MODULE_LOAD_INHIBIT));
 
92
 
 
93
      token = G_TOKEN_LEFT_PAREN;
 
94
 
 
95
      while (g_scanner_peek_next_token (scanner) == token)
 
96
        {
 
97
          token = g_scanner_get_next_token (scanner);
 
98
 
 
99
          switch (token)
 
100
            {
 
101
            case G_TOKEN_LEFT_PAREN:
 
102
              token = G_TOKEN_SYMBOL;
 
103
              break;
 
104
 
 
105
            case G_TOKEN_SYMBOL:
 
106
              if (scanner->value.v_symbol == GINT_TO_POINTER (MODULE_LOAD_INHIBIT))
 
107
                {
 
108
                  token = G_TOKEN_STRING;
 
109
 
 
110
                  if (! gimp_scanner_parse_string_no_validate (scanner,
 
111
                                                               &module_load_inhibit))
 
112
                    goto error;
 
113
                }
 
114
              token = G_TOKEN_RIGHT_PAREN;
 
115
              break;
 
116
 
 
117
            case G_TOKEN_RIGHT_PAREN:
 
118
              token = G_TOKEN_LEFT_PAREN;
 
119
              break;
 
120
 
 
121
            default: /* do nothing */
 
122
              break;
 
123
            }
 
124
        }
 
125
 
 
126
#undef MODULE_LOAD_INHIBIT
 
127
 
 
128
      if (token != G_TOKEN_LEFT_PAREN)
 
129
        {
 
130
          g_scanner_get_next_token (scanner);
 
131
          g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
 
132
                                 _("fatal parse error"), TRUE);
 
133
        }
 
134
 
 
135
    error:
 
136
 
 
137
      if (error)
 
138
        {
 
139
          g_message (error->message);
 
140
          g_clear_error (&error);
 
141
        }
 
142
 
 
143
      gimp_scanner_destroy (scanner);
 
144
    }
 
145
 
 
146
  if (module_load_inhibit)
 
147
    {
 
148
      gimp_module_db_set_load_inhibit (gimp->module_db, module_load_inhibit);
 
149
      g_free (module_load_inhibit);
 
150
    }
 
151
 
 
152
  path = gimp_config_path_expand (gimp->config->module_path, TRUE, NULL);
 
153
  gimp_module_db_load (gimp->module_db, path);
 
154
  g_free (path);
 
155
}
 
156
 
 
157
static void
 
158
add_to_inhibit_string (gpointer data,
 
159
                       gpointer user_data)
 
160
{
 
161
  GimpModule *module = data;
 
162
  GString    *str    = user_data;
 
163
 
 
164
  if (module->load_inhibit)
 
165
    {
 
166
      str = g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
 
167
      str = g_string_append (str, module->filename);
 
168
    }
 
169
}
 
170
 
 
171
void
 
172
gimp_modules_unload (Gimp *gimp)
 
173
{
 
174
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
175
 
 
176
  if (! gimp->no_interface && gimp->write_modulerc)
 
177
    {
 
178
      GimpConfigWriter *writer;
 
179
      GString          *str;
 
180
      gchar            *p;
 
181
      gchar            *filename;
 
182
      GError           *error = NULL;
 
183
 
 
184
      str = g_string_new (NULL);
 
185
      g_list_foreach (gimp->module_db->modules, add_to_inhibit_string, str);
 
186
      if (str->len > 0)
 
187
        p = str->str + 1;
 
188
      else
 
189
        p = "";
 
190
 
 
191
      filename = gimp_personal_rc_file ("modulerc");
 
192
      writer = gimp_config_writer_new_file (filename, TRUE,
 
193
                                            "GIMP modulerc", &error);
 
194
      g_free (filename);
 
195
 
 
196
      if (writer)
 
197
        {
 
198
          gimp_config_writer_open (writer, "module-load-inhibit");
 
199
          gimp_config_writer_printf (writer, "\"%s\"", p);
 
200
          gimp_config_writer_close (writer);
 
201
 
 
202
          gimp_config_writer_finish (writer, "end of modulerc", &error);
 
203
 
 
204
          gimp->write_modulerc = FALSE;
 
205
        }
 
206
 
 
207
      g_string_free (str, TRUE);
 
208
 
 
209
      if (error)
 
210
        {
 
211
          g_message (error->message);
 
212
          g_clear_error (&error);
 
213
        }
 
214
    }
 
215
}
 
216
 
 
217
void
 
218
gimp_modules_refresh (Gimp *gimp)
 
219
{
 
220
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
221
 
 
222
  if (! gimp->no_interface)
 
223
    {
 
224
      gchar *path;
 
225
 
 
226
      path = gimp_config_path_expand (gimp->config->module_path, TRUE, NULL);
 
227
      gimp_module_db_refresh (gimp->module_db, path);
 
228
      g_free (path);
 
229
    }
 
230
}