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

« back to all changes in this revision

Viewing changes to app/plug-in/plug-in-progress.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
 
/* The GIMP -- an image manipulation program
2
 
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
 
 *
4
 
 * plug-in-progress.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/gimppdbprogress.h"
29
 
#include "core/gimpprogress.h"
30
 
 
31
 
#include "pdb/procedural_db.h"
32
 
 
33
 
#include "plug-in.h"
34
 
#include "plug-in-progress.h"
35
 
 
36
 
 
37
 
/*  local function prototypes  */
38
 
 
39
 
static void   plug_in_progress_cancel_callback (GimpProgress *progress,
40
 
                                                PlugIn       *plug_in);
41
 
 
42
 
 
43
 
/*  public functions  */
44
 
 
45
 
void
46
 
plug_in_progress_start (PlugIn      *plug_in,
47
 
                        const gchar *message,
48
 
                        gint         display_ID)
49
 
{
50
 
  PlugInProcFrame *proc_frame;
51
 
 
52
 
  g_return_if_fail (plug_in != NULL);
53
 
 
54
 
  proc_frame = plug_in_get_proc_frame (plug_in);
55
 
 
56
 
  if (! message)
57
 
    message = plug_in->prog;
58
 
 
59
 
  if (! proc_frame->progress)
60
 
    {
61
 
      proc_frame->progress = gimp_new_progress (plug_in->gimp, display_ID);
62
 
 
63
 
      if (proc_frame->progress)
64
 
        {
65
 
          proc_frame->progress_created = TRUE;
66
 
 
67
 
          g_object_ref (proc_frame->progress);
68
 
        }
69
 
    }
70
 
 
71
 
  if (proc_frame->progress)
72
 
    {
73
 
      if (! proc_frame->progress_cancel_id)
74
 
        proc_frame->progress_cancel_id =
75
 
          g_signal_connect (proc_frame->progress, "cancel",
76
 
                            G_CALLBACK (plug_in_progress_cancel_callback),
77
 
                            plug_in);
78
 
 
79
 
      if (gimp_progress_is_active (proc_frame->progress))
80
 
        {
81
 
          gimp_progress_set_text (proc_frame->progress, message);
82
 
          gimp_progress_set_value (proc_frame->progress, 0.0);
83
 
        }
84
 
      else
85
 
        {
86
 
          gimp_progress_start (proc_frame->progress, message, TRUE);
87
 
        }
88
 
    }
89
 
}
90
 
 
91
 
void
92
 
plug_in_progress_update (PlugIn  *plug_in,
93
 
                         gdouble  percentage)
94
 
{
95
 
  PlugInProcFrame *proc_frame;
96
 
 
97
 
  g_return_if_fail (plug_in != NULL);
98
 
 
99
 
  proc_frame = plug_in_get_proc_frame (plug_in);
100
 
 
101
 
  if (! proc_frame->progress                           ||
102
 
      ! gimp_progress_is_active (proc_frame->progress) ||
103
 
      ! proc_frame->progress_cancel_id)
104
 
    {
105
 
      plug_in_progress_start (plug_in, NULL, -1);
106
 
    }
107
 
 
108
 
  if (proc_frame->progress && gimp_progress_is_active (proc_frame->progress))
109
 
    gimp_progress_set_value (proc_frame->progress, percentage);
110
 
}
111
 
 
112
 
void
113
 
plug_in_progress_end (PlugIn *plug_in)
114
 
{
115
 
  PlugInProcFrame *proc_frame;
116
 
 
117
 
  g_return_if_fail (plug_in != NULL);
118
 
 
119
 
  proc_frame = plug_in_get_proc_frame (plug_in);
120
 
 
121
 
  if (proc_frame->progress)
122
 
    {
123
 
      if (proc_frame->progress_cancel_id)
124
 
        {
125
 
          g_signal_handler_disconnect (proc_frame->progress,
126
 
                                       proc_frame->progress_cancel_id);
127
 
          proc_frame->progress_cancel_id = 0;
128
 
        }
129
 
 
130
 
      if (gimp_progress_is_active (proc_frame->progress))
131
 
        gimp_progress_end (proc_frame->progress);
132
 
 
133
 
      if (proc_frame->progress_created)
134
 
        {
135
 
          gimp_free_progress (plug_in->gimp, proc_frame->progress);
136
 
          g_object_unref (proc_frame->progress);
137
 
          proc_frame->progress = NULL;
138
 
        }
139
 
    }
140
 
}
141
 
 
142
 
gboolean
143
 
plug_in_progress_install (PlugIn      *plug_in,
144
 
                          const gchar *progress_callback)
145
 
{
146
 
  PlugInProcFrame *proc_frame;
147
 
  ProcRecord      *proc_rec;
148
 
 
149
 
  g_return_val_if_fail (plug_in != NULL, FALSE);
150
 
  g_return_val_if_fail (progress_callback != NULL, FALSE);
151
 
 
152
 
  proc_rec = procedural_db_lookup (plug_in->gimp, progress_callback);
153
 
 
154
 
  if (! proc_rec                                    ||
155
 
      proc_rec->num_args != 3                       ||
156
 
      proc_rec->args[0].arg_type != GIMP_PDB_INT32  ||
157
 
      proc_rec->args[1].arg_type != GIMP_PDB_STRING ||
158
 
      proc_rec->args[2].arg_type != GIMP_PDB_FLOAT  ||
159
 
      proc_rec->proc_type        != GIMP_TEMPORARY  ||
160
 
      proc_rec->exec_method.temporary.plug_in != plug_in)
161
 
    {
162
 
      return FALSE;
163
 
    }
164
 
 
165
 
  proc_frame = plug_in_get_proc_frame (plug_in);
166
 
 
167
 
  if (proc_frame->progress)
168
 
    {
169
 
      plug_in_progress_end (plug_in);
170
 
 
171
 
      if (proc_frame->progress)
172
 
        {
173
 
          g_object_unref (proc_frame->progress);
174
 
          proc_frame->progress = NULL;
175
 
        }
176
 
    }
177
 
 
178
 
  proc_frame->progress = g_object_new (GIMP_TYPE_PDB_PROGRESS,
179
 
                                       "context",       proc_frame->main_context,
180
 
                                       "callback-name", progress_callback,
181
 
                                       NULL);
182
 
 
183
 
  return TRUE;
184
 
}
185
 
 
186
 
gboolean
187
 
plug_in_progress_uninstall (PlugIn      *plug_in,
188
 
                            const gchar *progress_callback)
189
 
{
190
 
  PlugInProcFrame *proc_frame;
191
 
 
192
 
  g_return_val_if_fail (plug_in != NULL, FALSE);
193
 
  g_return_val_if_fail (progress_callback != NULL, FALSE);
194
 
 
195
 
  proc_frame = plug_in_get_proc_frame (plug_in);
196
 
 
197
 
  if (GIMP_IS_PDB_PROGRESS (proc_frame->progress))
198
 
    {
199
 
      plug_in_progress_end (plug_in);
200
 
      g_object_unref (proc_frame->progress);
201
 
      proc_frame->progress = NULL;
202
 
 
203
 
      return TRUE;
204
 
    }
205
 
 
206
 
  return FALSE;
207
 
}
208
 
 
209
 
gboolean
210
 
plug_in_progress_cancel (PlugIn      *plug_in,
211
 
                         const gchar *progress_callback)
212
 
{
213
 
  g_return_val_if_fail (plug_in != NULL, FALSE);
214
 
  g_return_val_if_fail (progress_callback != NULL, FALSE);
215
 
 
216
 
  return FALSE;
217
 
}
218
 
 
219
 
void
220
 
plug_in_progress_message (PlugIn      *plug_in,
221
 
                          const gchar *message)
222
 
{
223
 
  PlugInProcFrame *proc_frame;
224
 
  gchar           *domain;
225
 
 
226
 
  g_return_if_fail (plug_in != NULL);
227
 
  g_return_if_fail (message != NULL);
228
 
 
229
 
  proc_frame = plug_in_get_proc_frame (plug_in);
230
 
 
231
 
  domain = plug_in_get_undo_desc (plug_in);
232
 
 
233
 
  if (proc_frame->progress)
234
 
    {
235
 
      gimp_progress_message (proc_frame->progress,
236
 
                             plug_in->gimp, domain, message);
237
 
    }
238
 
  else
239
 
    {
240
 
      gimp_message (plug_in->gimp, domain, message);
241
 
    }
242
 
 
243
 
  g_free (domain);
244
 
}
245
 
 
246
 
 
247
 
/*  private functions  */
248
 
 
249
 
static void
250
 
plug_in_progress_cancel_callback (GimpProgress *progress,
251
 
                                  PlugIn       *plug_in)
252
 
{
253
 
  PlugInProcFrame *proc_frame = &plug_in->main_proc_frame;
254
 
  GList           *list;
255
 
 
256
 
  if (proc_frame->main_loop)
257
 
    {
258
 
      proc_frame->return_vals   = g_new (Argument, 1);
259
 
      proc_frame->n_return_vals = 1;
260
 
 
261
 
      proc_frame->return_vals->arg_type      = GIMP_PDB_STATUS;
262
 
      proc_frame->return_vals->value.pdb_int = GIMP_PDB_CANCEL;
263
 
    }
264
 
 
265
 
  for (list = plug_in->temp_proc_frames; list; list = g_list_next (list))
266
 
    {
267
 
      proc_frame = list->data;
268
 
 
269
 
      if (proc_frame->main_loop)
270
 
        {
271
 
          proc_frame->return_vals   = g_new (Argument, 1);
272
 
          proc_frame->n_return_vals = 1;
273
 
 
274
 
          proc_frame->return_vals->arg_type      = GIMP_PDB_STATUS;
275
 
          proc_frame->return_vals->value.pdb_int = GIMP_PDB_CANCEL;
276
 
        }
277
 
    }
278
 
 
279
 
  plug_in_close (plug_in, TRUE);
280
 
  plug_in_unref (plug_in);
281
 
}