[gimp] plug-ins: cleanup in file-webp, mostly simplify the save dialog
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: cleanup in file-webp, mostly simplify the save dialog
- Date: Wed, 10 Aug 2016 19:50:39 +0000 (UTC)
commit f2ff74c08ca73c9f75bddbbb4c0fe45f081e8b72
Author: Michael Natterer <mitch gimp org>
Date: Wed Aug 10 21:48:27 2016 +0200
plug-ins: cleanup in file-webp, mostly simplify the save dialog
plug-ins/file-webp/file-webp-dialog.c | 128 +++++++++++++--------------------
plug-ins/file-webp/file-webp-dialog.h | 6 +-
plug-ins/file-webp/file-webp-load.c | 2 -
plug-ins/file-webp/file-webp-save.c | 2 -
plug-ins/file-webp/file-webp-save.h | 12 ++--
plug-ins/file-webp/file-webp.c | 24 +++----
6 files changed, 71 insertions(+), 103 deletions(-)
---
diff --git a/plug-ins/file-webp/file-webp-dialog.c b/plug-ins/file-webp/file-webp-dialog.c
index 96150a1..678a45f 100644
--- a/plug-ins/file-webp/file-webp-dialog.c
+++ b/plug-ins/file-webp/file-webp-dialog.c
@@ -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,
- gpointer data);
+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;
@@ -48,58 +45,42 @@ struct
{
{ "default", "Default" },
{ "picture", "Picture" },
- { "photo", "Photo" },
+ { "photo", "Photo" },
{ "drawing", "Drawing" },
- { "icon", "Icon" },
- { "text", "Text" },
+ { "icon", "Icon" },
+ { "text", "Text" },
{ 0 }
};
-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);
- }
+ 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,43 +88,33 @@ 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;
- GtkWidget *label;
- GtkWidget *table;
- GtkWidget *preset_label;
- GtkListStore *preset_list;
- GtkWidget *preset_combo;
- GtkWidget *lossless_checkbox;
- GtkWidget *animation_checkbox;
- GtkWidget *loop_anim_checkbox;
- GtkObject *quality_scale;
- GtkObject *alpha_quality_scale;
- GtkResponseType response;
- gboolean animation_supported = FALSE;
- int slider1 , slider2;
-
- animation_supported = nLayers > 1;
+ GtkWidget *dialog;
+ GtkWidget *vbox;
+ GtkWidget *label;
+ GtkWidget *table;
+ GtkWidget *preset_label;
+ GtkListStore *preset_list;
+ GtkWidget *preset_combo;
+ GtkWidget *lossless_checkbox;
+ GtkWidget *animation_checkbox;
+ GtkWidget *loop_anim_checkbox;
+ GtkObject *quality_scale;
+ GtkObject *alpha_quality_scale;
+ gboolean animation_supported = FALSE;
+ gint slider1 , slider2;
+ gboolean run;
+
+ 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),
¶ms->preset);
/* Create the lossless checkbox */
@@ -192,7 +164,7 @@ save_dialog (WebPSaveParams *params,
params->lossless);
gtk_table_attach (GTK_TABLE (table), lossless_checkbox,
1, 3, 1, 2,
- GTK_FILL, GTK_FILL, 0, 0);
+ GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (lossless_checkbox);
g_signal_connect (lossless_checkbox, "toggled",
@@ -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;
}
diff --git a/plug-ins/file-webp/file-webp-dialog.h b/plug-ins/file-webp/file-webp-dialog.h
index e0bec97..97cd3e3 100644
--- a/plug-ins/file-webp/file-webp-dialog.h
+++ b/plug-ins/file-webp/file-webp-dialog.h
@@ -26,9 +26,9 @@
#include "file-webp-save.h"
-GtkResponseType save_dialog (WebPSaveParams *params,
- gint32 image_ID,
- gint32 nLayers);
+gboolean save_dialog (WebPSaveParams *params,
+ gint32 image_ID,
+ gint32 n_layers);
#endif /* __WEBP_DIALOG_H__ */
diff --git a/plug-ins/file-webp/file-webp-load.c b/plug-ins/file-webp/file-webp-load.c
index 4c40490..ffdf098 100644
--- a/plug-ins/file-webp/file-webp-load.c
+++ b/plug-ins/file-webp/file-webp-load.c
@@ -123,8 +123,6 @@ load_image (const gchar *filename,
return -1;
}
- gegl_init (NULL, NULL);
-
wp_data.bytes = indata;
wp_data.size = indatalen;
diff --git a/plug-ins/file-webp/file-webp-save.c b/plug-ins/file-webp/file-webp-save.c
index efc0b1f..f3d3b52 100644
--- a/plug-ins/file-webp/file-webp-save.c
+++ b/plug-ins/file-webp/file-webp-save.c
@@ -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)
diff --git a/plug-ins/file-webp/file-webp-save.h b/plug-ins/file-webp/file-webp-save.h
index 23c55e6..643ccf8 100644
--- a/plug-ins/file-webp/file-webp-save.h
+++ b/plug-ins/file-webp/file-webp-save.h
@@ -25,12 +25,12 @@
typedef struct
{
- gchar *preset;
- gboolean lossless;
- gboolean animation;
- gboolean loop;
- gfloat quality;
- gfloat alpha_quality;
+ gchar *preset;
+ gboolean lossless;
+ gboolean animation;
+ gboolean loop;
+ gfloat quality;
+ gfloat alpha_quality;
} WebPSaveParams;
diff --git a/plug-ins/file-webp/file-webp.c b/plug-ins/file-webp/file-webp.c
index 451e80d..b845525 100644
--- a/plug-ins/file-webp/file-webp.c
+++ b/plug-ins/file-webp/file-webp.c
@@ -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 (¶ms, image_ID, n_layers) != GTK_RESPONSE_OK)
+ if (! save_dialog (¶ms, 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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]