Fixes NB#106346, added a missing fix
[modest] / src / hildon2 / modest-msg-edit-window.c
index 484f153..6e5aed5 100644 (file)
@@ -485,6 +485,10 @@ scroll_drag_timeout (gpointer userdata)
        ModestMsgEditWindow *win = (ModestMsgEditWindow *) userdata;
        ModestMsgEditWindowPrivate *priv;
 
+       /* It could happen that the window was already closed */
+       if (!GTK_WIDGET_VISIBLE (win))
+               return FALSE;
+
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(win);
 
        correct_scroll_without_drag_check (win, TRUE);
@@ -505,6 +509,10 @@ correct_scroll_without_drag_check_idle (gpointer userdata)
        GtkTextMark *insert;
        GtkAdjustment *vadj;
 
+       /* It could happen that the window was already closed */
+       if (!GTK_WIDGET_VISIBLE (w))
+               return FALSE;
+
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(w);
 
        insert = gtk_text_buffer_get_insert (priv->text_buffer);
@@ -538,8 +546,10 @@ correct_scroll_without_drag_check (ModestMsgEditWindow *w, gboolean only_if_focu
                return;
        }
 
-       priv->correct_scroll_idle = g_idle_add ((GSourceFunc) correct_scroll_without_drag_check_idle,
-                                               (gpointer) w);
+       priv->correct_scroll_idle = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+                                                    (GSourceFunc) correct_scroll_without_drag_check_idle,
+                                                    g_object_ref (w),
+                                                    g_object_unref);
 }
 
 static void
@@ -550,8 +560,11 @@ correct_scroll (ModestMsgEditWindow *w)
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(w);
        if (gtk_grab_get_current () == priv->msg_body) {
                if (priv->scroll_drag_timeout_id == 0) {
-                       priv->scroll_drag_timeout_id = g_timeout_add (500, (GSourceFunc) scroll_drag_timeout,
-                                                                     (gpointer) w);
+                       priv->scroll_drag_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT,
+                                                                          500,
+                                                                          (GSourceFunc) scroll_drag_timeout,
+                                                                          g_object_ref (w),
+                                                                          g_object_unref);
                }
                return;
        }
@@ -972,6 +985,27 @@ modest_msg_edit_window_finalize (GObject *obj)
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
+static void
+pixbuf_size_prepared (GdkPixbufLoader *loader,
+                     gint width,
+                     gint height,
+                     ModestMsgEditWindow *self)
+{
+       gint new_height, new_width;
+       gboolean set_size;
+       
+       new_height = height;
+       new_width = width;
+       set_size = FALSE;
+
+       if (width > IMAGE_MAX_WIDTH) {
+               new_height = height * IMAGE_MAX_WIDTH / width;
+               new_width = IMAGE_MAX_WIDTH;
+       }
+
+       gdk_pixbuf_loader_set_size (loader, new_width, new_height);
+}
+
 static GdkPixbuf *
 pixbuf_from_stream (TnyStream *stream,
                    const gchar *mime_type,
@@ -992,6 +1026,7 @@ pixbuf_from_stream (TnyStream *stream,
                        *stream_size = 0;
                return NULL;
        }
+       g_signal_connect (G_OBJECT (loader), "size-prepared", G_CALLBACK (pixbuf_size_prepared), self);
 
        hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
 
@@ -1749,9 +1784,11 @@ modest_msg_edit_window_get_format_state (ModestMsgEditWindow *self)
 {
        ModestMsgEditFormatState *format_state = NULL;
        ModestMsgEditWindowPrivate *priv;
-       WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
+       WPTextBufferFormat *buffer_format;
 
        g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self), NULL);
+
+       buffer_format = g_new0 (WPTextBufferFormat, 1);
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
 
        wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, TRUE);
@@ -1775,11 +1812,15 @@ modest_msg_edit_window_set_format_state (ModestMsgEditWindow *self,
                                         const ModestMsgEditFormatState *format_state)
 {
        ModestMsgEditWindowPrivate *priv;
-       WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
-       WPTextBufferFormat *current_format = g_new0 (WPTextBufferFormat, 1);
+       WPTextBufferFormat *buffer_format;
+       WPTextBufferFormat *current_format;
+
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
        g_return_if_fail (format_state != NULL);
 
+       buffer_format = g_new0 (WPTextBufferFormat, 1);
+       current_format = g_new0 (WPTextBufferFormat, 1);
+
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
        gtk_widget_grab_focus (priv->msg_body);
        buffer_format->bold = (format_state->bold != FALSE);
@@ -2177,7 +2218,7 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
 
                                modest_platform_information_banner (NULL, NULL, 
                                                                    _FM("sfil_ib_opening_not_allowed"));
-
+                               g_free (filename);
                                g_object_unref (mime_part);
                                gnome_vfs_file_info_unref (info);
                                continue;
@@ -2201,7 +2242,8 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
                                priv->images_count ++;
                                insert_mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (priv->text_buffer));
                                gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (priv->text_buffer), &position, insert_mark);
-                               wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, g_strdup (tny_mime_part_get_content_id (mime_part)), pixbuf);
+                               wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, 
+                                                            tny_mime_part_get_content_id (mime_part), pixbuf);
                                g_object_unref (pixbuf);
 
                                tny_list_prepend (priv->images, (GObject *) mime_part);
@@ -2351,6 +2393,7 @@ modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window,
                        if (size > allowed_size) {
                                modest_platform_information_banner (NULL, NULL, 
                                                                    _FM("sfil_ib_opening_not_allowed"));
+                               g_free (filename);
                                return 0;
                        }
                } else
@@ -2363,6 +2406,7 @@ modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window,
                        modest_platform_information_banner (NULL, NULL, _FM("sfil_ib_opening_not_allowed"));
 
                        g_object_unref (mime_part);
+                       g_free (filename);
                        gnome_vfs_file_info_unref (info);
                        return 0;
                }
@@ -3205,6 +3249,8 @@ modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        GtkClipboard *selection_clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
        gchar *text = NULL;
+
+       /* It could happen that the window was already closed */
        if (!GTK_WIDGET_VISIBLE (window))
                return;
 
@@ -3216,9 +3262,8 @@ modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
        }
        priv->clipboard_text = text;
 
-       if (GTK_WIDGET_VISIBLE (window)) {
-               modest_window_check_dimming_rules_group (MODEST_WINDOW (window), MODEST_DIMMING_RULES_CLIPBOARD);
-       }
+       modest_window_check_dimming_rules_group (MODEST_WINDOW (window), MODEST_DIMMING_RULES_CLIPBOARD);
+
        g_object_unref (window);
 }
 
@@ -3243,7 +3288,10 @@ modest_msg_edit_window_clipboard_owner_handle_change_in_idle (ModestMsgEditWindo
 {
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        if (priv->clipboard_owner_idle == 0) {
-               priv->clipboard_owner_idle = g_idle_add (clipboard_owner_change_idle, window);
+               priv->clipboard_owner_idle = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+                                                             clipboard_owner_change_idle, 
+                                                             g_object_ref (window),
+                                                             g_object_unref);
        }
 }
 
@@ -3254,6 +3302,7 @@ subject_field_move_cursor (GtkEntry *entry,
                           gboolean a2,
                           gpointer window)
 {
+       /* It could happen that the window was already closed */
        if (!GTK_WIDGET_VISIBLE (window))
                return;