2007-07-25 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Wed, 25 Jul 2007 09:52:49 +0000 (09:52 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Wed, 25 Jul 2007 09:52:49 +0000 (09:52 +0000)
* src/widgets/modest-msg-edit-window.h:
* src/maemo/modest-msg-edit-window.c: (create_stream_for_uri):
Moved some code here to make it simpler.
(modest_msg_edit_window_attach_file_one): Renamed from
modest_msg_edit_window_attach_file_interactive().
(modest_msg_edit_window_offer_attach_file): Renamed from
modest_msg_edit_window_attach_file() and used
modest_msg_edit_window_attach_file_one() instead of
copy/pasting the code. The old code for one was not using
GnomeVFS. This allows use of smb:// URLs when using send-as
from external applications, fixing bug NB#63741.

(modest_msg_edit_window_insert_image),
(modest_msg_edit_window_add_attachment_clicked):
* src/modest-ui-actions.c: (modest_ui_actions_on_attach_file):
* src/dbus_api/modest-dbus-callbacks.c: (on_idle_compose_mail):
Adapted to the new function names.

pmo-trunk-r2789

ChangeLog2
src/dbus_api/modest-dbus-callbacks.c
src/maemo/modest-msg-edit-window.c
src/modest-ui-actions.c
src/widgets/modest-msg-edit-window.h

index 4f8afaa..8a9168d 100644 (file)
@@ -1,5 +1,25 @@
 2007-07-25  Murray Cumming  <murrayc@murrayc.com>
 
+       * src/widgets/modest-msg-edit-window.h:
+       * src/maemo/modest-msg-edit-window.c: (create_stream_for_uri):
+       Moved some code here to make it simpler.
+       (modest_msg_edit_window_attach_file_one): Renamed from 
+       modest_msg_edit_window_attach_file_interactive().
+       (modest_msg_edit_window_offer_attach_file): Renamed from 
+       modest_msg_edit_window_attach_file() and used 
+       modest_msg_edit_window_attach_file_one() instead of 
+       copy/pasting the code. The old code for one was not using 
+       GnomeVFS. This allows use of smb:// URLs when using send-as 
+       from external applications, fixing bug NB#63741.
+
+       (modest_msg_edit_window_insert_image),
+       (modest_msg_edit_window_add_attachment_clicked):
+       * src/modest-ui-actions.c: (modest_ui_actions_on_attach_file):
+       * src/dbus_api/modest-dbus-callbacks.c: (on_idle_compose_mail):
+       Adapted to the new function names.
+
+2007-07-25  Murray Cumming  <murrayc@murrayc.com>
+
        (modest_platform_set_update_interval): Set the alarm recurrence 
        fields so that auto-update does not just happen the first time.
        This should have fixed projects.maemo.org bug NB#63938.
index 2f39ffb..f913111 100644 (file)
@@ -378,7 +378,7 @@ on_idle_compose_mail(gpointer user_data)
 
                                        list = g_strsplit(idle_data->attachments, ",", 0);
                                        for (i=0; list[i] != NULL; i++) {
-                                               modest_msg_edit_window_attach_file_noninteractive(
+                                               modest_msg_edit_window_attach_file_one(
                                                                (ModestMsgEditWindow *)win, list[i]);
                                        }
                                        g_strfreev(list);
index 8e2bf7e..5835214 100644 (file)
@@ -1457,6 +1457,23 @@ modest_msg_edit_window_select_background_color (ModestMsgEditWindow *window)
 
 }
 
+static TnyStream* create_stream_for_uri (const gchar* uri)
+{
+       if (!uri)
+               return NULL;
+               
+       TnyStream *result = NULL;
+
+       GnomeVFSHandle *handle = NULL;
+       GnomeVFSResult test = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
+       if (test == GNOME_VFS_OK) {
+               /* Create the tinymail stream: */
+               /* Presumably tinymai will call gnome_vfs_close (handle) later. */
+               result = TNY_STREAM (tny_vfs_stream_new (handle));
+       }
+       
+       return result;
+}
 
 void
 modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
@@ -1501,7 +1518,6 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
                        GnomeVFSFileInfo info;
                        gchar *filename, *basename, *escaped_filename;
                        TnyMimePart *mime_part;
-                       TnyStream *stream;
                        gchar *content_id;
                        const gchar *mime_type = NULL;
                        GnomeVFSURI *vfs_uri;
@@ -1520,8 +1536,8 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
 
                        mime_part = tny_platform_factory_new_mime_part
                                (modest_runtime_get_platform_factory ());
-                       stream = TNY_STREAM (tny_vfs_stream_new (handle));
-                       
+                               
+                       TnyStream *stream = create_stream_for_uri (uri);
                        tny_mime_part_construct_from_stream (mime_part, stream, mime_type);
                        
                        content_id = g_strdup_printf ("%d", priv->last_cid);
@@ -1578,7 +1594,7 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
 }
 
 void
-modest_msg_edit_window_attach_file (ModestMsgEditWindow *window)
+modest_msg_edit_window_offer_attach_file (ModestMsgEditWindow *window)
 {
        
        ModestMsgEditWindowPrivate *priv;
@@ -1604,124 +1620,72 @@ modest_msg_edit_window_attach_file (ModestMsgEditWindow *window)
        gtk_widget_destroy (dialog);
 
        for (uri_node = uris; uri_node != NULL; uri_node = g_slist_next (uri_node)) {
-               const gchar *uri;
-               GnomeVFSHandle *handle = NULL;
-               GnomeVFSResult result;
-
-               uri = (const gchar *) uri_node->data;
-               result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
-               if (result == GNOME_VFS_OK) {
-                       TnyMimePart *mime_part;
-                       TnyStream *stream;
-                       const gchar *mime_type = NULL;
-                       gchar *basename;
-                       gchar *escaped_filename;
-                       gchar *filename;
-                       gchar *content_id;
-                       GnomeVFSFileInfo info;
-                       GnomeVFSURI *vfs_uri;
-
-                       vfs_uri = gnome_vfs_uri_new (uri);
-                       
-
-                       escaped_filename = g_path_get_basename (gnome_vfs_uri_get_path (vfs_uri));
-                       filename = gnome_vfs_unescape_string_for_display (escaped_filename);
-                       g_free (escaped_filename);
-                       gnome_vfs_uri_unref (vfs_uri);
-                       
-                       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_part = tny_platform_factory_new_mime_part
-                               (modest_runtime_get_platform_factory ());
-                       stream = TNY_STREAM (tny_vfs_stream_new (handle));
-                       
-                       tny_mime_part_construct_from_stream (mime_part, stream, mime_type);
-                       
-                       content_id = g_strdup_printf ("%d", priv->last_cid);
-                       tny_mime_part_set_content_id (mime_part, content_id);
-                       g_free (content_id);
-                       priv->last_cid++;
-                       
-                       basename = g_path_get_basename (filename);
-                       tny_mime_part_set_filename (mime_part, basename);
-                       g_free (basename);
-                       
-                       priv->attachments = g_list_prepend (priv->attachments, mime_part);
-                       modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
-                                                               mime_part);
-                       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);
-
-               } 
+               const gchar *uri = (const gchar *) uri_node->data;
+               modest_msg_edit_window_attach_file_one (window, uri);
        }
        g_slist_foreach (uris, (GFunc) g_free, NULL);
        g_slist_free (uris);
 }
 
 void
-modest_msg_edit_window_attach_file_noninteractive (
+modest_msg_edit_window_attach_file_one (
                ModestMsgEditWindow *window,
-               const gchar *file_uri)
+               const gchar *uri)
 {
+       g_return_if_fail (window);
+       g_return_if_fail (uri);
+               
+       ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        
-       ModestMsgEditWindowPrivate *priv;
        
-       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
-
-       if (file_uri && strlen(file_uri)) {
-               gint file_id = 0;
+       GnomeVFSHandle *handle = NULL;
+       GnomeVFSResult result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
+       if (result == GNOME_VFS_OK) {
+               TnyMimePart *mime_part;
+               TnyStream *stream;
+               const gchar *mime_type = NULL;
+               gchar *basename;
+               gchar *escaped_filename;
+               gchar *filename;
+               gchar *content_id;
+               GnomeVFSFileInfo info;
+               GnomeVFSURI *vfs_uri;
+
+               vfs_uri = gnome_vfs_uri_new (uri);
                
-               /* TODO: We should probably try to use only the URI,
-                * instead of using a filename.
-                */
-               gchar* filename = g_filename_from_uri (file_uri, NULL, NULL);
-               if (!filename) {
-                       g_warning("%s: g_filename_from_uri('%s') failed.\n", __FUNCTION__, file_uri);
-               }
-
-               file_id = g_open (filename, O_RDONLY, 0);
-               if (file_id != -1) {
-                       TnyMimePart *mime_part;
-                       TnyStream *stream;
-                       const gchar *mime_type;
-                       gchar *basename;
-                       gchar *content_id;
-#ifdef MODEST_HAVE_HILDON0_WIDGETS
-                       mime_type = gnome_vfs_get_mime_type(filename);
-#else
-                       mime_type = gnome_vfs_get_file_mime_type_fast (filename, NULL);
-#endif
-                       mime_part = tny_platform_factory_new_mime_part
-                               (modest_runtime_get_platform_factory ());
-                       stream = TNY_STREAM (tny_fs_stream_new (file_id));
-                       
-                       tny_mime_part_construct_from_stream (mime_part, stream, mime_type);
-                       
-                       content_id = g_strdup_printf ("%d", priv->last_cid);
-                       tny_mime_part_set_content_id (mime_part, content_id);
-                       g_free (content_id);
-                       priv->last_cid++;
-                       
-                       basename = g_path_get_basename (filename);
-                       tny_mime_part_set_filename (mime_part, basename);
-                       g_free (basename);
-                       
-                       priv->attachments = g_list_prepend (priv->attachments, mime_part);
-                       modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
-                                                               mime_part);
-                       gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
-                       gtk_widget_show_all (priv->attachments_caption);
-               } else if (file_id == -1) {
-                       close (file_id);
-                       g_warning("file to be attached does not exist: %s", filename);
-               }
 
+               escaped_filename = g_path_get_basename (gnome_vfs_uri_get_path (vfs_uri));
+               filename = gnome_vfs_unescape_string_for_display (escaped_filename);
+               g_free (escaped_filename);
+               gnome_vfs_uri_unref (vfs_uri);
+               
+               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_part = tny_platform_factory_new_mime_part
+                       (modest_runtime_get_platform_factory ());
+               stream = TNY_STREAM (tny_vfs_stream_new (handle));
+               
+               tny_mime_part_construct_from_stream (mime_part, stream, mime_type);
+               
+               content_id = g_strdup_printf ("%d", priv->last_cid);
+               tny_mime_part_set_content_id (mime_part, content_id);
+               g_free (content_id);
+               priv->last_cid++;
+               
+               basename = g_path_get_basename (filename);
+               tny_mime_part_set_filename (mime_part, basename);
+               g_free (basename);
+               
+               priv->attachments = g_list_prepend (priv->attachments, mime_part);
+               modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
+                                                       mime_part);
+               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);
        }
 }
@@ -2646,7 +2610,7 @@ static void
 modest_msg_edit_window_add_attachment_clicked (GtkButton *button,
                                               ModestMsgEditWindow *window)
 {
-       modest_msg_edit_window_attach_file (window);
+       modest_msg_edit_window_offer_attach_file (window);
 }
 
 static void
index c41c64b..f06d3e9 100644 (file)
@@ -2136,7 +2136,7 @@ modest_ui_actions_on_attach_file (GtkAction *action,
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
        g_return_if_fail (GTK_IS_ACTION (action));
 
-       modest_msg_edit_window_attach_file (window);
+       modest_msg_edit_window_offer_attach_file (window);
 }
 
 void 
index 4cb6e21..c82bf14 100644 (file)
@@ -203,22 +203,22 @@ void                    modest_msg_edit_window_select_background_color
 void                    modest_msg_edit_window_insert_image          (ModestMsgEditWindow *window);
 
 /**
- * modest_msg_edit_window_attach_file:
+ * modest_msg_edit_window_offer_attach_file:
  * @self: a #ModestMsgEditWindow
  *
  * show a file selection dialog to attach a file
  */
-void                    modest_msg_edit_window_attach_file           (ModestMsgEditWindow *window);
+void                    modest_msg_edit_window_offer_attach_file           (ModestMsgEditWindow *window);
 
 /**
- * modest_msg_edit_window_attach_file_noninteractive:
+ * modest_msg_edit_window_attach_file_one:
  * @self: a #ModestMsgEditWindow
  * @file_uri: The URI of a file to attach to the email message.
  *
  * attach a file to a MsgEditWindow non interactively, 
  * without file dialog. This is needed by dbus callbacks.
  */
-void                    modest_msg_edit_window_attach_file_noninteractive           (ModestMsgEditWindow *window, const gchar *file_uri);
+void                    modest_msg_edit_window_attach_file_one           (ModestMsgEditWindow *window, const gchar *file_uri);
 
 /**
  * modest_msg_edit_window_remove_attachments: