1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
#include <glib/gstdio.h>
30
#include <glib-object.h>
32
#include "libgimpbase/gimpbase.h"
33
#include "libgimpconfig/gimpconfig.h"
35
#include "core-types.h"
38
#include "gimp-contexts.h"
39
#include "gimpcontext.h"
41
#include "config/gimpconfig-file.h"
43
#include "gimp-intl.h"
47
gimp_contexts_init (Gimp *gimp)
51
g_return_if_fail (GIMP_IS_GIMP (gimp));
53
/* the default context contains the user's saved preferences
55
* TODO: load from disk
57
context = gimp_context_new (gimp, "Default", NULL);
58
gimp_set_default_context (gimp, context);
59
g_object_unref (context);
61
/* the initial user_context is a straight copy of the default context
63
context = gimp_context_new (gimp, "User", context);
64
gimp_set_user_context (gimp, context);
65
g_object_unref (context);
69
gimp_contexts_exit (Gimp *gimp)
71
g_return_if_fail (GIMP_IS_GIMP (gimp));
73
gimp_set_user_context (gimp, NULL);
74
gimp_set_default_context (gimp, NULL);
78
gimp_contexts_load (Gimp *gimp)
83
g_return_if_fail (GIMP_IS_GIMP (gimp));
85
filename = gimp_personal_rc_file ("contextrc");
88
g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
90
if (! gimp_config_deserialize_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
94
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
95
gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
103
gimp_contexts_save (Gimp *gimp)
106
GError *error = NULL;
108
g_return_if_fail (GIMP_IS_GIMP (gimp));
110
filename = gimp_personal_rc_file ("contextrc");
112
if (gimp->be_verbose)
113
g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
115
if (! gimp_config_serialize_to_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
118
"end of user context",
121
gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
122
g_error_free (error);
129
gimp_contexts_clear (Gimp *gimp,
133
gboolean success = TRUE;
135
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
137
filename = gimp_personal_rc_file ("contextrc");
139
if (g_unlink (filename) != 0 && errno != ENOENT)
141
g_set_error (error, 0, 0, _("Deleting \"%s\" failed: %s"),
142
gimp_filename_to_utf8 (filename), g_strerror (errno));