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

« back to all changes in this revision

Viewing changes to app/plug-in/gimpplugin-cleanup.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 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimpplugin-cleanup.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 "glib-object.h"
 
24
 
 
25
#include "plug-in-types.h"
 
26
 
 
27
#include "core/gimp.h"
 
28
#include "core/gimpcontainer.h"
 
29
#include "core/gimpimage.h"
 
30
#include "core/gimpimage-undo.h"
 
31
#include "core/gimpdrawable.h"
 
32
#include "core/gimpundostack.h"
 
33
 
 
34
#include "gimpplugin.h"
 
35
#include "gimpplugin-cleanup.h"
 
36
#include "gimppluginmanager.h"
 
37
#include "gimppluginprocedure.h"
 
38
 
 
39
 
 
40
typedef struct _GimpPlugInCleanupImage GimpPlugInCleanupImage;
 
41
 
 
42
struct _GimpPlugInCleanupImage
 
43
{
 
44
  GimpImage *image;
 
45
  gint       undo_group_count;
 
46
};
 
47
 
 
48
 
 
49
/*  local function prototypes  */
 
50
 
 
51
static GimpPlugInCleanupImage *
 
52
         gimp_plug_in_cleanup_get_image (GimpPlugInProcFrame *proc_frame,
 
53
                                         GimpImage           *image);
 
54
 
 
55
 
 
56
/*  public functions  */
 
57
 
 
58
gboolean
 
59
gimp_plug_in_cleanup_undo_group_start (GimpPlugIn *plug_in,
 
60
                                       GimpImage  *image)
 
61
{
 
62
  GimpPlugInProcFrame    *proc_frame;
 
63
  GimpPlugInCleanupImage *cleanup;
 
64
 
 
65
  g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
 
66
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
 
67
 
 
68
  proc_frame = gimp_plug_in_get_proc_frame (plug_in);
 
69
  cleanup    = gimp_plug_in_cleanup_get_image (proc_frame, image);
 
70
 
 
71
  g_printerr ("\n%s: procedure %s starts undo group on "
 
72
              "image with group count %d\n",
 
73
              G_STRFUNC, GIMP_OBJECT (proc_frame->procedure)->name,
 
74
              image->group_count);
 
75
 
 
76
  if (! cleanup)
 
77
    {
 
78
      g_printerr ("%s: creating new cleanup entry => SUCCESS\n", G_STRFUNC);
 
79
 
 
80
      cleanup = g_new0 (GimpPlugInCleanupImage, 1);
 
81
 
 
82
      cleanup->image            = image;
 
83
      cleanup->undo_group_count = image->group_count;
 
84
 
 
85
      proc_frame->cleanups = g_list_prepend (proc_frame->cleanups, cleanup);
 
86
    }
 
87
  else
 
88
    {
 
89
      g_printerr ("%s: using existing cleanup entry => SUCCESS\n", G_STRFUNC);
 
90
    }
 
91
 
 
92
  return TRUE;
 
93
}
 
94
 
 
95
gboolean
 
96
gimp_plug_in_cleanup_undo_group_end (GimpPlugIn *plug_in,
 
97
                                     GimpImage  *image)
 
98
{
 
99
  GimpPlugInProcFrame    *proc_frame;
 
100
  GimpPlugInCleanupImage *cleanup;
 
101
 
 
102
  g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
 
103
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
 
104
 
 
105
  proc_frame = gimp_plug_in_get_proc_frame (plug_in);
 
106
  cleanup    = gimp_plug_in_cleanup_get_image (proc_frame, image);
 
107
 
 
108
  g_printerr ("\n%s: procedure %s ends undo group on "
 
109
              "image with group count %d\n",
 
110
              G_STRFUNC, GIMP_OBJECT (proc_frame->procedure)->name,
 
111
              image->group_count);
 
112
 
 
113
  if (! cleanup)
 
114
    {
 
115
      g_printerr ("%s: no cleanup entry found => FAILURE\n", G_STRFUNC);
 
116
      return FALSE;
 
117
    }
 
118
 
 
119
  if (cleanup->undo_group_count == image->group_count - 1)
 
120
    {
 
121
      g_printerr ("%s: group count balanced, deleting cleanup entry => SUCCESS\n",
 
122
                  G_STRFUNC);
 
123
 
 
124
      proc_frame->cleanups = g_list_remove (proc_frame->cleanups, cleanup);
 
125
      g_free (cleanup);
 
126
    }
 
127
  else
 
128
    {
 
129
      g_printerr ("%s: undo groups still open, keeping cleanup entry => SUCCESS\n",
 
130
                  G_STRFUNC);
 
131
    }
 
132
 
 
133
  return TRUE;
 
134
}
 
135
 
 
136
void
 
137
gimp_plug_in_cleanup (GimpPlugIn          *plug_in,
 
138
                      GimpPlugInProcFrame *proc_frame)
 
139
{
 
140
  GList *list;
 
141
 
 
142
  g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
 
143
  g_return_if_fail (proc_frame != NULL);
 
144
 
 
145
  for (list = proc_frame->cleanups; list; list = g_list_next (list))
 
146
    {
 
147
      GimpPlugInCleanupImage *cleanup = list->data;
 
148
      GimpImage              *image   = cleanup->image;
 
149
 
 
150
      if (! gimp_container_have (plug_in->manager->gimp->images,
 
151
                                 (GimpObject *) image))
 
152
        continue;
 
153
 
 
154
      if (image->pushing_undo_group == GIMP_UNDO_GROUP_NONE)
 
155
        continue;
 
156
 
 
157
      g_printerr ("\n%s: checking image with group count %d\n",
 
158
                  G_STRFUNC, image->group_count);
 
159
 
 
160
      if (cleanup->undo_group_count != image->group_count)
 
161
        {
 
162
          GimpProcedure *proc = proc_frame->procedure;
 
163
 
 
164
          g_message ("Plug-In '%s' left image undo in inconsistent state, "
 
165
                     "closing open undo groups.",
 
166
                     gimp_plug_in_procedure_get_label (GIMP_PLUG_IN_PROCEDURE (proc)));
 
167
 
 
168
          while (image->pushing_undo_group != GIMP_UNDO_GROUP_NONE &&
 
169
                 cleanup->undo_group_count < image->group_count)
 
170
            {
 
171
              if (! gimp_image_undo_group_end (image))
 
172
                break;
 
173
            }
 
174
        }
 
175
 
 
176
      g_free (cleanup);
 
177
    }
 
178
 
 
179
  g_list_free (proc_frame->cleanups);
 
180
  proc_frame->cleanups = NULL;
 
181
}
 
182
 
 
183
 
 
184
/*  private functions  */
 
185
 
 
186
static GimpPlugInCleanupImage *
 
187
gimp_plug_in_cleanup_get_image (GimpPlugInProcFrame *proc_frame,
 
188
                                GimpImage           *image)
 
189
{
 
190
  GList *list;
 
191
 
 
192
  for (list = proc_frame->cleanups; list; list = g_list_next (list))
 
193
    {
 
194
      GimpPlugInCleanupImage *cleanup = list->data;
 
195
 
 
196
      if (cleanup->image == image)
 
197
        return cleanup;
 
198
    }
 
199
 
 
200
  return NULL;
 
201
}