1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
5
* (C) 1999 Austin Donnelly <austin@gimp.org>
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.
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.
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.
24
#include <glib-object.h>
26
#include "libgimpbase/gimpbase.h"
27
#include "libgimpmodule/gimpmodule.h"
29
#include "core-types.h"
31
#include "config/gimpconfig-path.h"
32
#include "config/gimpconfigwriter.h"
33
#include "config/gimpcoreconfig.h"
34
#include "config/gimpscanner.h"
37
#include "gimp-modules.h"
39
#include "gimp-intl.h"
43
gimp_modules_init (Gimp *gimp)
45
g_return_if_fail (GIMP_IS_GIMP (gimp));
47
if (! gimp->no_interface)
49
gimp->module_db = gimp_module_db_new (gimp->be_verbose);
50
gimp->write_modulerc = FALSE;
55
gimp_modules_exit (Gimp *gimp)
57
g_return_if_fail (GIMP_IS_GIMP (gimp));
61
g_object_unref (gimp->module_db);
62
gimp->module_db = NULL;
67
gimp_modules_load (Gimp *gimp)
72
gchar *module_load_inhibit = NULL;
74
g_return_if_fail (GIMP_IS_GIMP (gimp));
76
if (gimp->no_interface)
79
filename = gimp_personal_rc_file ("modulerc");
80
scanner = gimp_scanner_new_file (filename, NULL);
88
#define MODULE_LOAD_INHIBIT 1
90
g_scanner_scope_add_symbol (scanner, 0, "module-load-inhibit",
91
GINT_TO_POINTER (MODULE_LOAD_INHIBIT));
93
token = G_TOKEN_LEFT_PAREN;
95
while (g_scanner_peek_next_token (scanner) == token)
97
token = g_scanner_get_next_token (scanner);
101
case G_TOKEN_LEFT_PAREN:
102
token = G_TOKEN_SYMBOL;
106
if (scanner->value.v_symbol == GINT_TO_POINTER (MODULE_LOAD_INHIBIT))
108
token = G_TOKEN_STRING;
110
if (! gimp_scanner_parse_string_no_validate (scanner,
111
&module_load_inhibit))
114
token = G_TOKEN_RIGHT_PAREN;
117
case G_TOKEN_RIGHT_PAREN:
118
token = G_TOKEN_LEFT_PAREN;
121
default: /* do nothing */
126
#undef MODULE_LOAD_INHIBIT
128
if (token != G_TOKEN_LEFT_PAREN)
130
g_scanner_get_next_token (scanner);
131
g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
132
_("fatal parse error"), TRUE);
139
g_message (error->message);
140
g_clear_error (&error);
143
gimp_scanner_destroy (scanner);
146
if (module_load_inhibit)
148
gimp_module_db_set_load_inhibit (gimp->module_db, module_load_inhibit);
149
g_free (module_load_inhibit);
152
path = gimp_config_path_expand (gimp->config->module_path, TRUE, NULL);
153
gimp_module_db_load (gimp->module_db, path);
158
add_to_inhibit_string (gpointer data,
161
GimpModule *module = data;
162
GString *str = user_data;
164
if (module->load_inhibit)
166
str = g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
167
str = g_string_append (str, module->filename);
172
gimp_modules_unload (Gimp *gimp)
174
g_return_if_fail (GIMP_IS_GIMP (gimp));
176
if (! gimp->no_interface && gimp->write_modulerc)
178
GimpConfigWriter *writer;
182
GError *error = NULL;
184
str = g_string_new (NULL);
185
g_list_foreach (gimp->module_db->modules, add_to_inhibit_string, str);
191
filename = gimp_personal_rc_file ("modulerc");
192
writer = gimp_config_writer_new_file (filename, TRUE,
193
"GIMP modulerc", &error);
198
gimp_config_writer_open (writer, "module-load-inhibit");
199
gimp_config_writer_printf (writer, "\"%s\"", p);
200
gimp_config_writer_close (writer);
202
gimp_config_writer_finish (writer, "end of modulerc", &error);
204
gimp->write_modulerc = FALSE;
207
g_string_free (str, TRUE);
211
g_message (error->message);
212
g_clear_error (&error);
218
gimp_modules_refresh (Gimp *gimp)
220
g_return_if_fail (GIMP_IS_GIMP (gimp));
222
if (! gimp->no_interface)
226
path = gimp_config_path_expand (gimp->config->module_path, TRUE, NULL);
227
gimp_module_db_refresh (gimp->module_db, path);