Fixed several TnyIterator leaks
[modest] / src / maemo / modest-msg-edit-window.c
index d438ddf..0f127a3 100644 (file)
@@ -272,6 +272,7 @@ struct _ModestMsgEditWindowPrivate {
 
        GtkWidget   *scroll;
        guint        scroll_drag_timeout_id;
+       gdouble      last_upper;
 
        gint last_cid;
        TnyList *attachments;
@@ -437,6 +438,7 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
        priv->sent = FALSE;
 
        priv->scroll_drag_timeout_id = 0;
+       priv->last_upper = 0.0;
 
        modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
                                            GTK_WINDOW(obj),"applications_email_editor");
@@ -526,6 +528,9 @@ correct_scroll_without_drag_check (ModestMsgEditWindow *w)
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(w);
 
+       if (!gtk_widget_is_focus (priv->msg_body))
+               return;
+
        insert = gtk_text_buffer_get_insert (priv->text_buffer);
        gtk_text_buffer_get_iter_at_mark (priv->text_buffer, &iter, insert);
 
@@ -601,7 +606,14 @@ text_buffer_mark_set (GtkTextBuffer *buffer,
 void vadj_changed (GtkAdjustment *adj,
                   ModestMsgEditWindow *window)
 {
-       correct_scroll (window);
+       ModestMsgEditWindowPrivate *priv;
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+       if (priv->last_upper != adj->upper) {
+               priv->last_upper = adj->upper;
+               correct_scroll (window);
+       }
 }
 
 static void
@@ -996,6 +1008,7 @@ replace_with_images (ModestMsgEditWindow *self, TnyList *attachments)
                }
                g_object_unref (part);
        }
+       g_object_unref (iter);
 }
 
 static void
@@ -1073,6 +1086,7 @@ update_last_cid (ModestMsgEditWindow *self, TnyList *attachments)
                }
                g_object_unref (part);
        }
+       g_object_unref (iter);
 }
 
 static void
@@ -1616,6 +1630,7 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window)
                g_object_unref (part);
                tny_iterator_next (att_iter);
        }
+       g_object_unref (att_iter);
        
        data->priority_flags = priv->priority_flags;
 
@@ -2091,7 +2106,7 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
                result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
                if (result == GNOME_VFS_OK) {
                        GdkPixbuf *pixbuf;
-                       GnomeVFSFileInfo info;
+                       GnomeVFSFileInfo *info;
                        gchar *filename, *basename, *escaped_filename;
                        TnyMimePart *mime_part;
                        gchar *content_id;
@@ -2105,11 +2120,12 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
                        filename = gnome_vfs_unescape_string_for_display (escaped_filename);
                        g_free (escaped_filename);
                        gnome_vfs_uri_unref (vfs_uri);
+                       info = gnome_vfs_file_info_new ();
 
-                       if (gnome_vfs_get_file_info (uri, &info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE
+                       if (gnome_vfs_get_file_info (uri, info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE
                                                     | GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE) 
                            == GNOME_VFS_OK)
-                               mime_type = gnome_vfs_file_info_get_mime_type (&info);
+                               mime_type = gnome_vfs_file_info_get_mime_type (info);
 
                        mime_part = tny_platform_factory_new_mime_part
                                (modest_runtime_get_platform_factory ());
@@ -2140,6 +2156,7 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
                        gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
                        g_free (filename);
                        g_object_unref (mime_part);
+                       gnome_vfs_file_info_unref (info);
 
                }
        }
@@ -2198,7 +2215,7 @@ modest_msg_edit_window_attach_file_one (
                gchar *escaped_filename;
                gchar *filename;
                gchar *content_id;
-               GnomeVFSFileInfo info;
+               GnomeVFSFileInfo *info;
                GnomeVFSURI *vfs_uri;
 
                vfs_uri = gnome_vfs_uri_new (uri);
@@ -2208,12 +2225,14 @@ modest_msg_edit_window_attach_file_one (
                filename = gnome_vfs_unescape_string_for_display (escaped_filename);
                g_free (escaped_filename);
                gnome_vfs_uri_unref (vfs_uri);
+
+               info = gnome_vfs_file_info_new ();
                
                if (gnome_vfs_get_file_info (uri, 
-                                            &info, 
+                                            info, 
                                             GNOME_VFS_FILE_INFO_GET_MIME_TYPE)
                    == GNOME_VFS_OK)
-                       mime_type = gnome_vfs_file_info_get_mime_type (&info);
+                       mime_type = gnome_vfs_file_info_get_mime_type (info);
                mime_part = tny_platform_factory_new_mime_part
                        (modest_runtime_get_platform_factory ());
                stream = TNY_STREAM (tny_vfs_stream_new (handle));
@@ -2234,12 +2253,13 @@ modest_msg_edit_window_attach_file_one (
                tny_list_prepend (priv->attachments, (GObject *) mime_part);
                modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
                                                        mime_part,
-                                                       info.size == 0, info.size);
+                                                       info->size == 0, info->size);
                gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
                gtk_widget_show_all (priv->attachments_caption);
                gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
                g_free (filename);
                g_object_unref (mime_part);
+               gnome_vfs_file_info_unref (info);
        }
 }
 
@@ -2319,6 +2339,7 @@ modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window,
                        gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
                        g_object_unref (mime_part);
                }
+               g_object_unref (iter);
        }
 
        g_object_unref (att_list);