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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimp-contexts.c
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <errno.h>
 
24
 
 
25
#ifdef HAVE_UNISTD_H
 
26
#include <unistd.h>
 
27
#endif
 
28
 
 
29
#include <glib/gstdio.h>
 
30
#include <glib-object.h>
 
31
 
 
32
#include "libgimpbase/gimpbase.h"
 
33
#include "libgimpconfig/gimpconfig.h"
 
34
 
 
35
#include "core-types.h"
 
36
 
 
37
#include "gimp.h"
 
38
#include "gimp-contexts.h"
 
39
#include "gimpcontext.h"
 
40
 
 
41
#include "config/gimpconfig-file.h"
 
42
 
 
43
#include "gimp-intl.h"
 
44
 
 
45
 
 
46
void
 
47
gimp_contexts_init (Gimp *gimp)
 
48
{
 
49
  GimpContext *context;
 
50
 
 
51
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
52
 
 
53
  /*  the default context contains the user's saved preferences
 
54
   *
 
55
   *  TODO: load from disk
 
56
   */
 
57
  context = gimp_context_new (gimp, "Default", NULL);
 
58
  gimp_set_default_context (gimp, context);
 
59
  g_object_unref (context);
 
60
 
 
61
  /*  the initial user_context is a straight copy of the default context
 
62
   */
 
63
  context = gimp_context_new (gimp, "User", context);
 
64
  gimp_set_user_context (gimp, context);
 
65
  g_object_unref (context);
 
66
}
 
67
 
 
68
void
 
69
gimp_contexts_exit (Gimp *gimp)
 
70
{
 
71
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
72
 
 
73
  gimp_set_user_context (gimp, NULL);
 
74
  gimp_set_default_context (gimp, NULL);
 
75
}
 
76
 
 
77
void
 
78
gimp_contexts_load (Gimp *gimp)
 
79
{
 
80
  gchar  *filename;
 
81
  GError *error = NULL;
 
82
 
 
83
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
84
 
 
85
  filename = gimp_personal_rc_file ("contextrc");
 
86
 
 
87
  if (gimp->be_verbose)
 
88
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
 
89
 
 
90
  if (! gimp_config_deserialize_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
 
91
                                      filename,
 
92
                                      NULL, &error))
 
93
    {
 
94
      if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
 
95
        gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
 
96
      g_error_free (error);
 
97
    }
 
98
 
 
99
  g_free (filename);
 
100
}
 
101
 
 
102
void
 
103
gimp_contexts_save (Gimp *gimp)
 
104
{
 
105
  gchar  *filename;
 
106
  GError *error = NULL;
 
107
 
 
108
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
109
 
 
110
  filename = gimp_personal_rc_file ("contextrc");
 
111
 
 
112
  if (gimp->be_verbose)
 
113
    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
 
114
 
 
115
  if (! gimp_config_serialize_to_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
 
116
                                       filename,
 
117
                                       "GIMP user context",
 
118
                                       "end of user context",
 
119
                                       NULL, &error))
 
120
    {
 
121
      gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
 
122
      g_error_free (error);
 
123
    }
 
124
 
 
125
  g_free (filename);
 
126
}
 
127
 
 
128
gboolean
 
129
gimp_contexts_clear (Gimp    *gimp,
 
130
                     GError **error)
 
131
{
 
132
  gchar    *filename;
 
133
  gboolean  success = TRUE;
 
134
 
 
135
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
 
136
 
 
137
  filename = gimp_personal_rc_file ("contextrc");
 
138
 
 
139
  if (g_unlink (filename) != 0 && errno != ENOENT)
 
140
    {
 
141
      g_set_error (error, 0, 0, _("Deleting \"%s\" failed: %s"),
 
142
                   gimp_filename_to_utf8 (filename), g_strerror (errno));
 
143
      success = FALSE;
 
144
    }
 
145
 
 
146
  g_free (filename);
 
147
 
 
148
  return success;
 
149
}