1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 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.
23
#include <glib-object.h>
25
#include "plug-in-types.h"
27
#include "core/gimp.h"
28
#include "core/gimppdbprogress.h"
29
#include "core/gimpprogress.h"
31
#include "pdb/procedural_db.h"
34
#include "plug-in-progress.h"
37
/* local function prototypes */
39
static void plug_in_progress_cancel_callback (GimpProgress *progress,
43
/* public functions */
46
plug_in_progress_start (PlugIn *plug_in,
50
PlugInProcFrame *proc_frame;
52
g_return_if_fail (plug_in != NULL);
54
proc_frame = plug_in_get_proc_frame (plug_in);
57
message = plug_in->prog;
59
if (! proc_frame->progress)
61
proc_frame->progress = gimp_new_progress (plug_in->gimp, display_ID);
63
if (proc_frame->progress)
65
proc_frame->progress_created = TRUE;
67
g_object_ref (proc_frame->progress);
71
if (proc_frame->progress)
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),
79
if (gimp_progress_is_active (proc_frame->progress))
81
gimp_progress_set_text (proc_frame->progress, message);
82
gimp_progress_set_value (proc_frame->progress, 0.0);
86
gimp_progress_start (proc_frame->progress, message, TRUE);
92
plug_in_progress_update (PlugIn *plug_in,
95
PlugInProcFrame *proc_frame;
97
g_return_if_fail (plug_in != NULL);
99
proc_frame = plug_in_get_proc_frame (plug_in);
101
if (! proc_frame->progress ||
102
! gimp_progress_is_active (proc_frame->progress) ||
103
! proc_frame->progress_cancel_id)
105
plug_in_progress_start (plug_in, NULL, -1);
108
if (proc_frame->progress && gimp_progress_is_active (proc_frame->progress))
109
gimp_progress_set_value (proc_frame->progress, percentage);
113
plug_in_progress_end (PlugIn *plug_in)
115
PlugInProcFrame *proc_frame;
117
g_return_if_fail (plug_in != NULL);
119
proc_frame = plug_in_get_proc_frame (plug_in);
121
if (proc_frame->progress)
123
if (proc_frame->progress_cancel_id)
125
g_signal_handler_disconnect (proc_frame->progress,
126
proc_frame->progress_cancel_id);
127
proc_frame->progress_cancel_id = 0;
130
if (gimp_progress_is_active (proc_frame->progress))
131
gimp_progress_end (proc_frame->progress);
133
if (proc_frame->progress_created)
135
gimp_free_progress (plug_in->gimp, proc_frame->progress);
136
g_object_unref (proc_frame->progress);
137
proc_frame->progress = NULL;
143
plug_in_progress_install (PlugIn *plug_in,
144
const gchar *progress_callback)
146
PlugInProcFrame *proc_frame;
147
ProcRecord *proc_rec;
149
g_return_val_if_fail (plug_in != NULL, FALSE);
150
g_return_val_if_fail (progress_callback != NULL, FALSE);
152
proc_rec = procedural_db_lookup (plug_in->gimp, progress_callback);
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)
165
proc_frame = plug_in_get_proc_frame (plug_in);
167
if (proc_frame->progress)
169
plug_in_progress_end (plug_in);
171
if (proc_frame->progress)
173
g_object_unref (proc_frame->progress);
174
proc_frame->progress = NULL;
178
proc_frame->progress = g_object_new (GIMP_TYPE_PDB_PROGRESS,
179
"context", proc_frame->main_context,
180
"callback-name", progress_callback,
187
plug_in_progress_uninstall (PlugIn *plug_in,
188
const gchar *progress_callback)
190
PlugInProcFrame *proc_frame;
192
g_return_val_if_fail (plug_in != NULL, FALSE);
193
g_return_val_if_fail (progress_callback != NULL, FALSE);
195
proc_frame = plug_in_get_proc_frame (plug_in);
197
if (GIMP_IS_PDB_PROGRESS (proc_frame->progress))
199
plug_in_progress_end (plug_in);
200
g_object_unref (proc_frame->progress);
201
proc_frame->progress = NULL;
210
plug_in_progress_cancel (PlugIn *plug_in,
211
const gchar *progress_callback)
213
g_return_val_if_fail (plug_in != NULL, FALSE);
214
g_return_val_if_fail (progress_callback != NULL, FALSE);
220
plug_in_progress_message (PlugIn *plug_in,
221
const gchar *message)
223
PlugInProcFrame *proc_frame;
226
g_return_if_fail (plug_in != NULL);
227
g_return_if_fail (message != NULL);
229
proc_frame = plug_in_get_proc_frame (plug_in);
231
domain = plug_in_get_undo_desc (plug_in);
233
if (proc_frame->progress)
235
gimp_progress_message (proc_frame->progress,
236
plug_in->gimp, domain, message);
240
gimp_message (plug_in->gimp, domain, message);
247
/* private functions */
250
plug_in_progress_cancel_callback (GimpProgress *progress,
253
PlugInProcFrame *proc_frame = &plug_in->main_proc_frame;
256
if (proc_frame->main_loop)
258
proc_frame->return_vals = g_new (Argument, 1);
259
proc_frame->n_return_vals = 1;
261
proc_frame->return_vals->arg_type = GIMP_PDB_STATUS;
262
proc_frame->return_vals->value.pdb_int = GIMP_PDB_CANCEL;
265
for (list = plug_in->temp_proc_frames; list; list = g_list_next (list))
267
proc_frame = list->data;
269
if (proc_frame->main_loop)
271
proc_frame->return_vals = g_new (Argument, 1);
272
proc_frame->n_return_vals = 1;
274
proc_frame->return_vals->arg_type = GIMP_PDB_STATUS;
275
proc_frame->return_vals->value.pdb_int = GIMP_PDB_CANCEL;
279
plug_in_close (plug_in, TRUE);
280
plug_in_unref (plug_in);