[goffice] Fixed behavior with unkown image format.
- From: Jean BrÃfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Fixed behavior with unkown image format.
- Date: Mon, 31 Oct 2011 16:23:05 +0000 (UTC)
commit 3900290e185d55b514c813435b08dff1dee064a3
Author: Jean Brefort <jean brefort normalesup org>
Date: Mon Oct 31 17:22:11 2011 +0100
Fixed behavior with unkown image format.
ChangeLog | 9 ++++++++
goffice/graph/gog-object.c | 48 ++++++++++++++++++++++++++++++++++++++-----
goffice/gtk/goffice-gtk.c | 34 ++++++++++++++++--------------
goffice/utils/go-image.c | 11 ++++++++-
4 files changed, 78 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1f5b45c..dbe5cf0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-10-31 Jean Brefort <jean brefort normalesup org>
+ * goffice/graph/gog-object.c (cb_size_changed),
+ (cb_manual_size_changed), (gog_object_populate_editor): made the manual
+ size UI consistent.
+ * goffice/gtk/goffice-gtk.c (go_gui_get_image_save_info): don't ask for
+ the extension when file type is unknown.
+ * goffice/utils/go-image.c (go_image_get_format_from_name),
+ (go_image_new_from_data): fixed behavior with unknown format.
+
2011-10-30 Jean Brefort <jean brefort normalesup org>
* goffice/canvas/goc-item.c (goc_item_set_operator),
diff --git a/goffice/graph/gog-object.c b/goffice/graph/gog-object.c
index 5c0ddff..f7a7e18 100644
--- a/goffice/graph/gog-object.c
+++ b/goffice/graph/gog-object.c
@@ -336,6 +336,20 @@ cb_position_changed (GtkWidget *spin, ObjectPrefState *state)
}
static void
+cb_size_changed (GtkWidget *spin, ObjectPrefState *state)
+{
+ GogViewAllocation pos;
+ double value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin)) / 100.0;
+
+ gog_object_get_manual_position (state->gobj, &pos);
+ if (spin == state->w_spin)
+ pos.w = value;
+ else if (spin == state->h_spin)
+ pos.h = value;
+ gog_object_set_manual_position (state->gobj, &pos);
+}
+
+static void
update_select_state (ObjectPrefState *state)
{
if (state->position_select_combo) {
@@ -395,7 +409,27 @@ static void
cb_manual_size_changed (GtkComboBox *combo, ObjectPrefState *state)
{
if (gtk_combo_box_get_active (combo) == 1) {
+ if (state->w_spin) {
+ gtk_widget_show (go_gtk_builder_get_widget (state->gui, "width_label"));
+ gtk_widget_show (go_gtk_builder_get_widget (state->gui, "width_spin"));
+ gtk_widget_show (go_gtk_builder_get_widget (state->gui, "width-pc-lbl"));
+ }
+ if (state->h_spin) {
+ gtk_widget_show (go_gtk_builder_get_widget (state->gui, "height_label"));
+ gtk_widget_show (go_gtk_builder_get_widget (state->gui, "height_spin"));
+ gtk_widget_show (go_gtk_builder_get_widget (state->gui, "height-pc-lbl"));
+ }
} else {
+ if (state->w_spin) {
+ gtk_widget_hide (go_gtk_builder_get_widget (state->gui, "width_label"));
+ gtk_widget_hide (go_gtk_builder_get_widget (state->gui, "width_spin"));
+ gtk_widget_hide (go_gtk_builder_get_widget (state->gui, "width-pc-lbl"));
+ }
+ if (state->h_spin) {
+ gtk_widget_hide (go_gtk_builder_get_widget (state->gui, "height_label"));
+ gtk_widget_hide (go_gtk_builder_get_widget (state->gui, "height_spin"));
+ gtk_widget_hide (go_gtk_builder_get_widget (state->gui, "height-pc-lbl"));
+ }
}
}
@@ -525,31 +559,33 @@ gog_object_populate_editor (GogObject *gobj,
manual_size? 1: 0);
g_signal_connect (G_OBJECT (w),
"changed", G_CALLBACK (cb_manual_size_changed), state);
- if (manual_size && size_mode & GOG_MANUAL_SIZE_WIDTH) {
+ if (size_mode & GOG_MANUAL_SIZE_WIDTH) {
w = go_gtk_builder_get_widget (gui, "width_label");
gtk_size_group_add_widget (label_size_group, w);
w = go_gtk_builder_get_widget (gui, "width_spin");
gtk_size_group_add_widget (widget_size_group, w);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), gobj->manual_position.w * 100.0);
g_signal_connect (G_OBJECT (w), "value-changed",
- G_CALLBACK (cb_position_changed), state);
+ G_CALLBACK (cb_size_changed), state);
state->w_spin = w;
- } else {
+ }
+ if (!manual_size) {
gtk_widget_hide (go_gtk_builder_get_widget (gui, "width_label"));
gtk_widget_hide (go_gtk_builder_get_widget (gui, "width_spin"));
gtk_widget_hide (go_gtk_builder_get_widget (gui, "width-pc-lbl"));
}
- if (manual_size && size_mode & GOG_MANUAL_SIZE_HEIGHT) {
+ if (size_mode & GOG_MANUAL_SIZE_HEIGHT) {
w = go_gtk_builder_get_widget (gui, "height_label");
gtk_size_group_add_widget (label_size_group, w);
w = go_gtk_builder_get_widget (gui, "height_spin");
gtk_size_group_add_widget (widget_size_group, w);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), gobj->manual_position.h * 100.0);
g_signal_connect (G_OBJECT (w), "value-changed",
- G_CALLBACK (cb_position_changed), state);
+ G_CALLBACK (cb_size_changed), state);
state->h_spin = w;
- } else {
+ }
+ if (!manual_size) {
gtk_widget_hide (go_gtk_builder_get_widget (gui, "height_label"));
gtk_widget_hide (go_gtk_builder_get_widget (gui, "height_spin"));
gtk_widget_hide (go_gtk_builder_get_widget (gui, "height-pc-lbl"));
diff --git a/goffice/gtk/goffice-gtk.c b/goffice/gtk/goffice-gtk.c
index 26139f1..957cf7e 100644
--- a/goffice/gtk/goffice-gtk.c
+++ b/goffice/gtk/goffice-gtk.c
@@ -913,24 +913,26 @@ go_gui_get_image_save_info (GtkWindow *toplevel, GSList *supported_formats,
uri = gtk_file_chooser_get_uri (fsel);
if (format_combo) {
char *new_uri = NULL;
-
- format = GPOINTER_TO_UINT (g_slist_nth_data
- (supported_formats,
- gtk_combo_box_get_active (format_combo)));
- format_info = go_image_get_format_info (format);
- if (!go_url_check_extension (uri, format_info->ext, &new_uri) &&
- !go_gtk_query_yes_no (GTK_WINDOW (fsel), TRUE,
- _("The given file extension does not match the"
- " chosen file type. Do you want to use this name"
- " anyway?"))) {
- g_free (new_uri);
- g_free (uri);
- uri = NULL;
- goto loop;
- } else {
+ int index = gtk_combo_box_get_active (format_combo);
+
+ if (index >= 0) {
+ format = GPOINTER_TO_UINT (g_slist_nth_data
+ (supported_formats, index));
+ format_info = go_image_get_format_info (format);
+ if (!go_url_check_extension (uri, format_info->ext, &new_uri) &&
+ !go_gtk_query_yes_no (GTK_WINDOW (fsel), TRUE,
+ _("The given file extension does not match the"
+ " chosen file type. Do you want to use this name"
+ " anyway?"))) {
+ g_free (new_uri);
+ g_free (uri);
+ uri = NULL;
+ goto loop;
+ }
g_free (uri);
uri = new_uri;
- }
+ } else
+ format = GO_IMAGE_FORMAT_UNKNOWN;
*ret_format = format;
}
if (!go_gtk_url_is_writeable (GTK_WINDOW (fsel), uri, TRUE)) {
diff --git a/goffice/utils/go-image.c b/goffice/utils/go-image.c
index 4cf1ded..1d211e6 100644
--- a/goffice/utils/go-image.c
+++ b/goffice/utils/go-image.c
@@ -201,11 +201,12 @@ go_image_build_pixbuf_format_infos (void)
GOImageFormatInfo const *
go_image_get_format_info (GOImageFormat format)
{
+ if (format == GO_IMAGE_FORMAT_UNKNOWN)
+ return NULL;
if (format > GO_IMAGE_FORMAT_UNKNOWN)
go_image_build_pixbuf_format_infos ();
g_return_val_if_fail (format >= 0 &&
- format != GO_IMAGE_FORMAT_UNKNOWN &&
format <= GO_IMAGE_FORMAT_UNKNOWN + pixbuf_format_nbr, NULL);
if (format < GO_IMAGE_FORMAT_UNKNOWN)
return &image_format_infos[format];
@@ -225,6 +226,9 @@ go_image_get_format_from_name (char const *name)
{
unsigned i;
+ if (name == NULL)
+ return GO_IMAGE_FORMAT_UNKNOWN;
+
go_image_build_pixbuf_format_infos ();
for (i = 0; i < GO_IMAGE_FORMAT_UNKNOWN; i++) {
@@ -458,7 +462,10 @@ go_image_new_from_data (char const *type, guint8 const *data, gsize length, char
g_free (mime_type);
type = real_type;
}
- g_return_val_if_fail (type != NULL, NULL);
+ if (type == NULL) {
+ g_warning ("unrecognized image format");
+ return NULL;
+ }
if (!strcmp (type, "svg")) {
image = go_svg_new_from_data (data, length, error);
} else if (!strcmp (type, "emf") || !strcmp (type, "wmf")) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]