Commit f2ff74c0 authored by Michael Natterer's avatar Michael Natterer 😴

plug-ins: cleanup in file-webp, mostly simplify the save dialog

parent a9c436ea
......@@ -30,17 +30,14 @@
#include "libgimp/stdplugins-intl.h"
void save_dialog_response (GtkWidget *widget,
gint response_id,
gpointer data);
GtkListStore * save_dialog_presets (void);
void save_dialog_set_preset (GtkWidget *widget,
gpointer data);
void save_dialog_toggle_scale (GtkWidget *widget,
static GtkListStore * save_dialog_presets (void);
static void save_dialog_preset_changed (GtkWidget *widget,
gchar **data);
static void save_dialog_toggle_scale (GtkWidget *widget,
gpointer data);
struct
static struct
{
const gchar *id;
const gchar *label;
......@@ -56,50 +53,34 @@ struct
};
void
save_dialog_response (GtkWidget *widget,
gint response_id,
gpointer data)
{
/* Store the response */
*(GtkResponseType *)data = response_id;
/* Close the dialog */
gtk_widget_destroy (widget);
}
GtkListStore *
static GtkListStore *
save_dialog_presets (void)
{
GtkListStore *list_store;
int i;
gint i;
/* Create the model */
list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
/* Insert the entries */
for (i = 0; presets[i].id; ++i)
{
gtk_list_store_insert_with_values (list_store,
NULL,
-1,
0, presets[i].id,
1, presets[i].label,
-1);
}
return list_store;
}
void
save_dialog_set_preset (GtkWidget *widget,
gpointer data)
static void
save_dialog_preset_changed (GtkWidget *widget,
gchar **data)
{
*(gchar **) data =
gimp_string_combo_box_get_active (GIMP_STRING_COMBO_BOX (widget));
g_free (*data);
*data = gimp_string_combo_box_get_active (GIMP_STRING_COMBO_BOX (widget));
}
void
static void
save_dialog_toggle_scale (GtkWidget *widget,
gpointer data)
{
......@@ -107,10 +88,10 @@ save_dialog_toggle_scale (GtkWidget *widget,
! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)));
}
GtkResponseType
gboolean
save_dialog (WebPSaveParams *params,
gint32 image_ID,
gint32 nLayers)
gint32 n_layers)
{
GtkWidget *dialog;
GtkWidget *vbox;
......@@ -124,26 +105,16 @@ save_dialog (WebPSaveParams *params,
GtkWidget *loop_anim_checkbox;
GtkObject *quality_scale;
GtkObject *alpha_quality_scale;
GtkResponseType response;
gboolean animation_supported = FALSE;
int slider1 , slider2;
gint slider1 , slider2;
gboolean run;
animation_supported = nLayers > 1;
animation_supported = n_layers > 1;
/* Create the dialog */
dialog = gimp_export_dialog_new (_("WebP"),BINARY_NAME,
SAVE_PROCEDURE);
/* Store the response when the dialog is closed */
g_signal_connect (dialog, "response",
G_CALLBACK (save_dialog_response),
&response);
/* Quit the main loop when the dialog is closed */
g_signal_connect (dialog, "destroy",
G_CALLBACK (gtk_main_quit),
NULL);
/* Create the vbox */
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
......@@ -165,9 +136,10 @@ save_dialog (WebPSaveParams *params,
/* Create the label for the selecting a preset */
preset_label = gtk_label_new (_("Preset:"));
gtk_misc_set_alignment (GTK_MISC (preset_label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), preset_label,
0, 1, 0, 1,
0, 0, 0, 0);
GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (preset_label);
/* Create the combobox containing the presets */
......@@ -183,7 +155,7 @@ save_dialog (WebPSaveParams *params,
gtk_widget_show (preset_combo);
g_signal_connect (preset_combo, "changed",
G_CALLBACK (save_dialog_set_preset),
G_CALLBACK (save_dialog_preset_changed),
&params->preset);
/* Create the lossless checkbox */
......@@ -279,9 +251,11 @@ save_dialog (WebPSaveParams *params,
G_CALLBACK (save_dialog_toggle_scale),
alpha_quality_scale);
/* Display the dialog and enter the main event loop */
gtk_widget_show (dialog);
gtk_main ();
return response;
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
gtk_widget_destroy (dialog);
return run;
}
......@@ -26,9 +26,9 @@
#include "file-webp-save.h"
GtkResponseType save_dialog (WebPSaveParams *params,
gboolean save_dialog (WebPSaveParams *params,
gint32 image_ID,
gint32 nLayers);
gint32 n_layers);
#endif /* __WEBP_DIALOG_H__ */
......@@ -123,8 +123,6 @@ load_image (const gchar *filename,
return -1;
}
gegl_init (NULL, NULL);
wp_data.bytes = indata;
wp_data.size = indatalen;
......
......@@ -574,8 +574,6 @@ save_image (const gchar *filename,
if (nLayers == 0)
return FALSE;
gegl_init (NULL, NULL);
g_printerr("Saving WebP file %s\n", filename);
if (nLayers == 1)
......
......@@ -143,16 +143,17 @@ run (const gchar *name,
gint32 drawable_ID;
GError *error = NULL;
/* Determine the current run mode */
INIT_I18N ();
gegl_init (NULL, NULL);
run_mode = param[0].data.d_int32;
/* Fill in the return values */
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
/* Determine which procedure is being invoked */
if (! strcmp (name, LOAD_PROCEDURE))
{
/* No need to determine whether the plugin is being invoked
......@@ -180,7 +181,7 @@ run (const gchar *name,
gint32 n_layers;
/* Initialize the parameters to their defaults */
params.preset = "default";
params.preset = g_strdup ("default");
params.lossless = FALSE;
params.animation = FALSE;
params.loop = TRUE;
......@@ -198,13 +199,11 @@ run (const gchar *name,
{
case GIMP_RUN_INTERACTIVE:
case GIMP_RUN_WITH_LAST_VALS:
gimp_ui_init (BINARY_NAME, FALSE);
/* Attempt to export the image */
export_ret = gimp_export_image (&image_ID,
&drawable_ID,
"WEBP",
export_ret = gimp_export_image (&image_ID, &drawable_ID,
"WebP",
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_ALPHA);
......@@ -216,16 +215,14 @@ run (const gchar *name,
}
/* Display the dialog */
if (save_dialog (&params, image_ID, n_layers) != GTK_RESPONSE_OK)
if (! save_dialog (&params, image_ID, n_layers))
{
values[0].data.d_status = GIMP_PDB_CANCEL;
return;
}
break;
case GIMP_RUN_NONINTERACTIVE:
/* Ensure the correct number of parameters were supplied */
if (nparams != 10)
{
......@@ -234,13 +231,13 @@ run (const gchar *name,
}
/* Load the parameters */
params.preset = param[5].data.d_string;
g_free (params.preset);
params.preset = g_strdup (param[5].data.d_string);
params.lossless = param[6].data.d_int32;
params.quality = param[7].data.d_float;
params.alpha_quality = param[8].data.d_float;
params.animation = param[9].data.d_int32;
params.loop = param[10].data.d_int32;
break;
}
......@@ -255,6 +252,7 @@ run (const gchar *name,
status = GIMP_PDB_EXECUTION_ERROR;
}
g_free (params.preset);
g_free (layers);
}
......
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