Commit a6601d56 authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

app: some GimpProgress cleanup

- change start() and set_text() to use "format" and "..." instead of
  "message", allowing to format progress messages in place
- s/cancelable/cancellable/
- move "cancellable" to be the second argument of start()
parent 33538157
......@@ -342,8 +342,8 @@ image_resize_to_layers_cmd_callback (GtkAction *action,
image = gimp_display_get_image (display);
progress = gimp_progress_start (GIMP_PROGRESS (display),
_("Resizing"), FALSE);
progress = gimp_progress_start (GIMP_PROGRESS (display), FALSE,
_("Resizing"));
gimp_image_resize_to_layers (image,
action_data_get_context (data),
......@@ -366,8 +366,8 @@ image_resize_to_selection_cmd_callback (GtkAction *action,
image = gimp_display_get_image (display);
progress = gimp_progress_start (GIMP_PROGRESS (display),
_("Resizing"), FALSE);
progress = gimp_progress_start (GIMP_PROGRESS (display), FALSE,
_("Resizing"));
gimp_image_resize_to_selection (image,
action_data_get_context (data),
......@@ -455,8 +455,8 @@ image_flip_cmd_callback (GtkAction *action,
image = gimp_display_get_image (display);
progress = gimp_progress_start (GIMP_PROGRESS (display),
_("Flipping"), FALSE);
progress = gimp_progress_start (GIMP_PROGRESS (display), FALSE,
_("Flipping"));
gimp_image_flip (image, action_data_get_context (data),
(GimpOrientationType) value, progress);
......@@ -479,8 +479,8 @@ image_rotate_cmd_callback (GtkAction *action,
image = gimp_display_get_image (display);
progress = gimp_progress_start (GIMP_PROGRESS (display),
_("Rotating"), FALSE);
progress = gimp_progress_start (GIMP_PROGRESS (display), FALSE,
_("Rotating"));
gimp_image_rotate (image, action_data_get_context (data),
(GimpRotationType) value, progress);
......@@ -698,8 +698,8 @@ image_resize_callback (GtkWidget *dialog,
height == gimp_image_get_height (image))
return;
progress = gimp_progress_start (GIMP_PROGRESS (display),
_("Resizing"), FALSE);
progress = gimp_progress_start (GIMP_PROGRESS (display), FALSE,
_("Resizing"));
gimp_image_resize_with_layers (image,
context,
......@@ -798,8 +798,8 @@ image_scale_callback (GtkWidget *dialog,
{
GimpProgress *progress;
progress = gimp_progress_start (GIMP_PROGRESS (user_data),
_("Scaling"), FALSE);
progress = gimp_progress_start (GIMP_PROGRESS (user_data), FALSE,
_("Scaling"));
gimp_image_scale (image, width, height, interpolation, progress);
......
......@@ -1178,7 +1178,7 @@ layers_scale_layer_callback (GtkWidget *dialog,
progress = GIMP_PROGRESS (progress_dialog);
}
progress = gimp_progress_start (progress, _("Scaling"), FALSE);
progress = gimp_progress_start (progress, FALSE, _("Scaling"));
gimp_item_scale_by_origin (item,
width, height, interpolation,
......
......@@ -88,7 +88,7 @@ gimp_drawable_merge_filter (GimpDrawable *drawable,
GimpFilter *filter,
GimpProgress *progress,
const gchar *undo_desc,
gboolean cancelable)
gboolean cancellable)
{
GeglRectangle rect;
gboolean success = TRUE;
......@@ -167,7 +167,7 @@ gimp_drawable_merge_filter (GimpDrawable *drawable,
gimp_drawable_get_buffer (drawable),
&rect,
cache, rects, n_rects,
cancelable))
cancellable))
{
/* finished successfully */
......
......@@ -35,7 +35,7 @@ gboolean gimp_drawable_merge_filter (GimpDrawable *drawable,
GimpFilter *filter,
GimpProgress *progress,
const gchar *undo_desc,
gboolean cancelable);
gboolean cancellable);
#endif /* __GIMP_DRAWABLE_FILTER_H__ */
......@@ -61,9 +61,8 @@ gimp_drawable_foreground_extract (GimpDrawable *drawable,
g_return_val_if_fail (GEGL_IS_BUFFER (trimap), NULL);
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
progress = gimp_progress_start (progress,
_("Computing alpha of unknown pixels"),
FALSE);
progress = gimp_progress_start (progress, FALSE,
_("Computing alpha of unknown pixels"));
drawable_buffer = gimp_drawable_get_buffer (drawable);
......
......@@ -104,7 +104,7 @@ gimp_image_convert_precision (GimpImage *image,
}
if (progress)
gimp_progress_start (progress, undo_desc, FALSE);
gimp_progress_start (progress, FALSE, "%s", undo_desc);
g_object_freeze_notify (G_OBJECT (image));
......
......@@ -400,7 +400,7 @@ gimp_image_map_apply (GimpImageMap *image_map,
gboolean
gimp_image_map_commit (GimpImageMap *image_map,
GimpProgress *progress,
gboolean cancelable)
gboolean cancellable)
{
gboolean success = TRUE;
......@@ -413,7 +413,7 @@ gimp_image_map_commit (GimpImageMap *image_map,
image_map->filter,
progress,
image_map->undo_desc,
cancelable);
cancellable);
gimp_image_map_remove_filter (image_map);
......
......@@ -68,7 +68,7 @@ void gimp_image_map_apply (GimpImageMap *image_map,
gboolean gimp_image_map_commit (GimpImageMap *image_map,
GimpProgress *progress,
gboolean cancelable);
gboolean cancellable);
void gimp_image_map_abort (GimpImageMap *image_map);
......
......@@ -64,8 +64,8 @@ static void gimp_pdb_progress_set_property (GObject *object,
GParamSpec *pspec);
static GimpProgress * gimp_pdb_progress_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable);
gboolean cancellable,
const gchar *message);
static void gimp_pdb_progress_progress_end (GimpProgress *progress);
static gboolean gimp_pdb_progress_progress_is_active (GimpProgress *progress);
static void gimp_pdb_progress_progress_set_text (GimpProgress *progress,
......@@ -299,8 +299,8 @@ gimp_pdb_progress_run_callback (GimpPdbProgress *progress,
static GimpProgress *
gimp_pdb_progress_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable)
gboolean cancellable,
const gchar *message)
{
GimpPdbProgress *pdb_progress = GIMP_PDB_PROGRESS (progress);
......
......@@ -96,20 +96,33 @@ gimp_progress_iface_base_init (GimpProgressInterface *progress_iface)
GimpProgress *
gimp_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable)
gboolean cancellable,
const gchar *format,
...)
{
GimpProgressInterface *progress_iface;
g_return_val_if_fail (GIMP_IS_PROGRESS (progress), NULL);
if (! message)
message = _("Please wait");
g_return_val_if_fail (format != NULL, NULL);
progress_iface = GIMP_PROGRESS_GET_INTERFACE (progress);
if (progress_iface->start)
return progress_iface->start (progress, message, cancelable);
{
GimpProgress *ret;
va_list args;
gchar *text;
va_start (args, format);
text = g_strdup_vprintf (format, args);
va_end (args);
ret = progress_iface->start (progress, cancellable, text);
g_free (text);
return ret;
}
return NULL;
}
......@@ -144,19 +157,29 @@ gimp_progress_is_active (GimpProgress *progress)
void
gimp_progress_set_text (GimpProgress *progress,
const gchar *message)
const gchar *format,
...)
{
GimpProgressInterface *progress_iface;
g_return_if_fail (GIMP_IS_PROGRESS (progress));
if (! message || ! strlen (message))
message = _("Please wait");
g_return_if_fail (format != NULL);
progress_iface = GIMP_PROGRESS_GET_INTERFACE (progress);
if (progress_iface->set_text)
progress_iface->set_text (progress, message);
{
va_list args;
gchar *text;
va_start (args, format);
text = g_strdup_vprintf (format, args);
va_end (args);
progress_iface->set_text (progress, text);
g_free (text);
}
}
void
......
......@@ -36,8 +36,8 @@ struct _GimpProgressInterface
/* virtual functions */
GimpProgress * (* start) (GimpProgress *progress,
const gchar *message,
gboolean cancelable);
gboolean cancellable,
const gchar *message);
void (* end) (GimpProgress *progress);
gboolean (* is_active) (GimpProgress *progress);
......@@ -64,13 +64,15 @@ struct _GimpProgressInterface
GType gimp_progress_interface_get_type (void) G_GNUC_CONST;
GimpProgress * gimp_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable);
gboolean cancellable,
const gchar *format,
...) G_GNUC_PRINTF (3, 4);
void gimp_progress_end (GimpProgress *progress);
gboolean gimp_progress_is_active (GimpProgress *progress);
void gimp_progress_set_text (GimpProgress *progress,
const gchar *message);
const gchar *message,
...) G_GNUC_PRINTF (2, 3);
void gimp_progress_set_value (GimpProgress *progress,
gdouble percentage);
gdouble gimp_progress_get_value (GimpProgress *progress);
......
......@@ -30,8 +30,8 @@ static void gimp_sub_progress_iface_init (GimpProgressInterface *if
static void gimp_sub_progress_finalize (GObject *object);
static GimpProgress * gimp_sub_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable);
gboolean cancellable,
const gchar *message);
static void gimp_sub_progress_end (GimpProgress *progress);
static gboolean gimp_sub_progress_is_active (GimpProgress *progress);
static void gimp_sub_progress_set_text (GimpProgress *progress,
......@@ -101,8 +101,8 @@ gimp_sub_progress_iface_init (GimpProgressInterface *iface)
static GimpProgress *
gimp_sub_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable)
gboolean cancellable,
const gchar *message)
{
/* does nothing */
return NULL;
......
......@@ -258,8 +258,8 @@ convert_precision_dialog_response (GtkWidget *widget,
{
GimpProgress *progress;
progress = gimp_progress_start (dialog->progress,
_("Converting to lower bit depth"), FALSE);
progress = gimp_progress_start (dialog->progress, FALSE,
_("Converting to lower bit depth"));
gimp_image_convert_precision (dialog->image,
dialog->precision,
......
......@@ -305,8 +305,8 @@ convert_dialog_response (GtkWidget *widget,
GimpProgress *progress;
GError *error = NULL;
progress = gimp_progress_start (dialog->progress,
_("Converting to indexed colors"), FALSE);
progress = gimp_progress_start (dialog->progress, FALSE,
_("Converting to indexed colors"));
/* Convert the image to indexed color */
if (! gimp_image_convert_type (dialog->image,
......
......@@ -88,8 +88,8 @@ static cairo_region_t * gimp_canvas_progress_get_extents (GimpCanvasItem *ite
gdouble y);
static GimpProgress * gimp_canvas_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable);
gboolean cancellable,
const gchar *message);
static void gimp_canvas_progress_end (GimpProgress *progress);
static gboolean gimp_canvas_progress_is_active (GimpProgress *progress);
static void gimp_canvas_progress_set_text (GimpProgress *progress,
......@@ -346,8 +346,8 @@ gimp_canvas_progress_hit (GimpCanvasItem *item,
static GimpProgress *
gimp_canvas_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable)
gboolean cancellable,
const gchar *message)
{
gimp_canvas_progress_set_text (progress, message);
......
......@@ -99,8 +99,8 @@ static void gimp_display_get_property (GObject *object
GParamSpec *pspec);
static GimpProgress * gimp_display_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable);
gboolean cancellable,
const gchar *message);
static void gimp_display_progress_end (GimpProgress *progress);
static gboolean gimp_display_progress_is_active (GimpProgress *progress);
static void gimp_display_progress_set_text (GimpProgress *progress,
......@@ -267,15 +267,15 @@ gimp_display_get_property (GObject *object,
static GimpProgress *
gimp_display_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable)
gboolean cancellable,
const gchar *message)
{
GimpDisplay *display = GIMP_DISPLAY (progress);
GimpDisplayPrivate *private = GIMP_DISPLAY_GET_PRIVATE (display);
if (private->shell)
return gimp_progress_start (GIMP_PROGRESS (private->shell),
message, cancelable);
return gimp_progress_start (GIMP_PROGRESS (private->shell), cancellable,
"%s", message);
return NULL;
}
......@@ -310,7 +310,7 @@ gimp_display_progress_set_text (GimpProgress *progress,
GimpDisplayPrivate *private = GIMP_DISPLAY_GET_PRIVATE (display);
if (private->shell)
gimp_progress_set_text (GIMP_PROGRESS (private->shell), message);
gimp_progress_set_text (GIMP_PROGRESS (private->shell), "%s", message);
}
static void
......
......@@ -33,13 +33,14 @@
static GimpProgress *
gimp_display_shell_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable)
gboolean cancellable,
const gchar *message)
{
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (progress);
GimpStatusbar *statusbar = gimp_display_shell_get_statusbar (shell);
return gimp_progress_start (GIMP_PROGRESS (statusbar), message, cancelable);
return gimp_progress_start (GIMP_PROGRESS (statusbar), cancellable,
"%s", message);
}
static void
......@@ -67,7 +68,7 @@ gimp_display_shell_progress_set_text (GimpProgress *progress,
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (progress);
GimpStatusbar *statusbar = gimp_display_shell_get_statusbar (shell);
gimp_progress_set_text (GIMP_PROGRESS (statusbar), message);
gimp_progress_set_text (GIMP_PROGRESS (statusbar), "%s", message);
}
static void
......
......@@ -84,8 +84,8 @@ static void gimp_statusbar_hbox_size_request (GtkWidget *widget,
static GimpProgress *
gimp_statusbar_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable);
gboolean cancellable,
const gchar *message);
static void gimp_statusbar_progress_end (GimpProgress *progress);
static gboolean gimp_statusbar_progress_is_active (GimpProgress *progress);
static void gimp_statusbar_progress_set_text (GimpProgress *progress,
......@@ -400,8 +400,8 @@ gimp_statusbar_hbox_size_request (GtkWidget *widget,
static GimpProgress *
gimp_statusbar_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable)
gboolean cancellable,
const gchar *message)
{
GimpStatusbar *statusbar = GIMP_STATUSBAR (progress);
......@@ -414,9 +414,9 @@ gimp_statusbar_progress_start (GimpProgress *progress,
gimp_statusbar_push (statusbar, "progress", NULL, "%s", message);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (bar), 0.0);
gtk_widget_set_sensitive (statusbar->cancel_button, cancelable);
gtk_widget_set_sensitive (statusbar->cancel_button, cancellable);
if (cancelable)
if (cancellable)
{
if (message)
{
......
......@@ -246,7 +246,7 @@ file_remote_copy_file (Gimp *gimp,
{
remote_progress.cancellable = g_cancellable_new ();
gimp_progress_start (progress, _("Connecting to server"), TRUE);
gimp_progress_start (progress, TRUE, _("Connecting to server"));
g_signal_connect (progress, "cancel",
G_CALLBACK (file_remote_copy_file_cancel),
......@@ -342,7 +342,6 @@ file_remote_progress_callback (goffset current_num_bytes,
const gchar *format;
gchar *done = g_format_size (current_num_bytes);
gchar *total = g_format_size (total_num_bytes);
gchar *text;
switch (progress->mode)
{
......@@ -358,13 +357,10 @@ file_remote_progress_callback (goffset current_num_bytes,
g_assert_not_reached ();
}
text = g_strdup_printf (format, done, total);
gimp_progress_set_text (progress->progress, format, done, total);
g_free (total);
g_free (done);
gimp_progress_set_text (progress->progress, text);
g_free (text);
gimp_progress_set_value (progress->progress,
(gdouble) current_num_bytes /
(gdouble) total_num_bytes);
......@@ -373,7 +369,6 @@ file_remote_progress_callback (goffset current_num_bytes,
{
const gchar *format;
gchar *done = g_format_size (current_num_bytes);
gchar *text;
switch (progress->mode)
{
......@@ -389,16 +384,12 @@ file_remote_progress_callback (goffset current_num_bytes,
g_assert_not_reached ();
}
text = g_strdup_printf (format, done);
gimp_progress_set_text (progress->progress, format, done);
g_free (done);
gimp_progress_set_text (progress->progress, text);
g_free (text);
gimp_progress_pulse (progress->progress);
}
while (! progress->cancel && g_main_context_pending (NULL))
g_main_context_iteration (NULL, FALSE);
}
......@@ -69,7 +69,7 @@ gimp_gegl_apply_cached_operation (GeglBuffer *src_buffer,
GeglBuffer *cache,
const GeglRectangle *valid_rects,
gint n_valid_rects,
gboolean cancelable)
gboolean cancellable)
{
GeglNode *gegl;
GeglNode *dest_node;
......@@ -140,16 +140,16 @@ gimp_gegl_apply_cached_operation (GeglBuffer *src_buffer,
if (gimp_progress_is_active (progress))
{
if (undo_desc)
gimp_progress_set_text (progress, undo_desc);
gimp_progress_set_text (progress, "%s", undo_desc);
progress_started = FALSE;
cancelable = FALSE;
cancellable = FALSE;
}
else
{
gimp_progress_start (progress, undo_desc, cancelable);
gimp_progress_start (progress, cancellable, "%s", undo_desc);
if (cancelable)
if (cancellable)
g_signal_connect (progress, "cancel",
G_CALLBACK (gimp_gegl_apply_operation_cancel),
&cancel);
......@@ -215,7 +215,7 @@ gimp_gegl_apply_cached_operation (GeglBuffer *src_buffer,
value * rect_pixels) /
(gdouble) all_pixels);
if (cancelable)
if (cancellable)
while (! cancel && g_main_context_pending (NULL))
g_main_context_iteration (NULL, FALSE);
}
......@@ -239,7 +239,7 @@ gimp_gegl_apply_cached_operation (GeglBuffer *src_buffer,
{
gimp_progress_set_value (progress, value);
if (cancelable)
if (cancellable)
while (! cancel && g_main_context_pending (NULL))
g_main_context_iteration (NULL, FALSE);
}
......@@ -260,7 +260,7 @@ gimp_gegl_apply_cached_operation (GeglBuffer *src_buffer,
{
gimp_progress_end (progress);
if (cancelable)
if (cancellable)
g_signal_handlers_disconnect_by_func (progress,
gimp_gegl_apply_operation_cancel,
&cancel);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment