2007-06-06 Marcus Bauer <marcusb@openismus.com>
authorMarcus Bauer <marcusb@openismus.com>
Tue, 5 Jun 2007 23:56:44 +0000 (23:56 +0000)
committerMarcus Bauer <marcusb@openismus.com>
Tue, 5 Jun 2007 23:56:44 +0000 (23:56 +0000)
* libmodest-dbus-client/libmodest-dbus-client.h:
added libmodest_dbus_client_compose_mail()
* src/dbus_api/modest-dbus-callbacks.c: (on_idle_compose_mail),
(on_compose_mail):
added functions needed for SendAsMail() functionality
* src/maemo/modest-msg-edit-window.c:
(modest_msg_edit_window_attach_file_noninteractive):
non interactively attaching files to message edit window
* src/widgets/modest-msg-edit-window.h:
* tests/dbus_api/Makefile.am:
added test_compose_mail.c
* tests/dbus_api/test_compose_mail.c: (main):

pmo-trunk-r2075

ChangeLog2
libmodest-dbus-client/libmodest-dbus-client.h
src/dbus_api/modest-dbus-callbacks.c
src/maemo/modest-msg-edit-window.c
src/widgets/modest-msg-edit-window.h
tests/dbus_api/Makefile.am
tests/dbus_api/test_compose_mail.c [new file with mode: 0644]

index 8d4fced..bfc4c1f 100644 (file)
@@ -1,3 +1,19 @@
+
+2007-06-06  Marcus Bauer  <marcusb@openismus.com>
+
+       * libmodest-dbus-client/libmodest-dbus-client.h:
+       added libmodest_dbus_client_compose_mail()
+       * src/dbus_api/modest-dbus-callbacks.c: (on_idle_compose_mail),
+       (on_compose_mail):
+       added functions needed for SendAsMail() functionality
+       * src/maemo/modest-msg-edit-window.c:
+       (modest_msg_edit_window_attach_file_noninteractive):
+       non interactively attaching files to message edit window
+       * src/widgets/modest-msg-edit-window.h:
+       * tests/dbus_api/Makefile.am:
+       added test_compose_mail.c
+       * tests/dbus_api/test_compose_mail.c: (main):
+
 2007-06-05  Johannes Schmid <johannes.schmid@openismus.com>
 
        * src/modest-account-view.c:
index c78fa06..6afc269 100644 (file)
@@ -38,6 +38,11 @@ gboolean
 libmodest_dbus_client_send_mail (osso_context_t *osso_context, const gchar *to, 
        const gchar *cc, const gchar *bcc, const gchar* subject, const gchar* body, 
        GSList *attachments);
+
+gboolean
+libmodest_dbus_client_compose_mail (osso_context_t *osso_context, const gchar *to, 
+       const gchar *cc, const gchar *bcc, const gchar* subject, const gchar* body, 
+       GSList *attachments);
        
 gboolean 
 libmodest_dbus_client_mail_to (osso_context_t *osso_context, 
index ee307d1..875eb09 100644 (file)
@@ -33,6 +33,7 @@
 #include "modest-account-mgr-helpers.h"
 #include "modest-tny-account.h"
 #include "modest-ui-actions.h"
+
 #include "modest-search.h"
 #include "widgets/modest-msg-edit-window.h"
 #include "modest-tny-msg.h"
@@ -40,6 +41,9 @@
 #include <libgnomevfs/gnome-vfs-utils.h>
 #include <stdio.h>
 #include <string.h>
+#include <glib/gstdio.h>
+#include <libgnomevfs/gnome-vfs-mime.h>
+#include <tny-fs-stream.h>
 
 #include <tny-list.h>
 #include <tny-iterator.h>
@@ -61,7 +65,7 @@ typedef struct
        gchar *bcc;
        gchar *subject;
        gchar *body;
-       GSList *attachments;
+       gchar *attachments;
 } ComposeMailIdleData;
 
 static gboolean
@@ -393,10 +397,15 @@ static gint on_mail_to(GArray * arguments, gpointer data, osso_rpc_t * retval)
 }
 
 
+
+
+
 static gboolean
 on_idle_compose_mail(gpointer user_data)
 {
        ComposeMailIdleData *idle_data = (ComposeMailIdleData*)user_data;
+       gchar **list = NULL;
+       gint i = 0;
 
        /* Get the TnyTransportAccount so we can instantiate a mail operation: */
        ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
@@ -412,18 +421,18 @@ on_idle_compose_mail(gpointer user_data)
        }
        
        if (!account) {
-               g_printerr ("modest: failed to get tny account folder'\n", account_name);
+               g_printerr ("modest: failed to get tny account folder'%s'\n", account_name);
        } else {
                gchar * from = modest_account_mgr_get_from_string (account_mgr,
                                                                  account_name);
                if (!from) {
                        g_printerr ("modest: no from address for account '%s'\n", account_name);
                } else {
-                       
+       
                        /* Create the message: */
                        TnyMsg *msg  = modest_tny_msg_new (idle_data->to, from, 
                                idle_data->cc, idle_data->bcc, idle_data->subject, idle_data->body, 
-                               idle_data->attachments);
+                               NULL); /* NULL because m_t_m_n doesn't use it */
                                
                        if (!msg) {
                                g_printerr ("modest: failed to create message\n");
@@ -439,6 +448,14 @@ on_idle_compose_mail(gpointer user_data)
                                        tny_folder_add_msg (folder, msg, NULL); /* TODO: check err */
                
                                        ModestWindow *win = modest_msg_edit_window_new (msg, account_name);
+
+                                       list = g_strsplit(idle_data->attachments, ",", 0);
+                                       for (i=0; list[i] != NULL; i++) {
+                                               modest_msg_edit_window_attach_file_noninteractive(
+                                                               (ModestMsgEditWindow *)win, list[i]);
+                                       }
+                                       g_strfreev(list);
+                                       
                                        gtk_widget_show_all (GTK_WIDGET (win));
                                
                                        g_object_unref (G_OBJECT(folder));
@@ -466,8 +483,7 @@ on_idle_compose_mail(gpointer user_data)
 
 static gint on_compose_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
 {
-       gchar **list = NULL;
-       gint i = 0;
+
        
        if (arguments->len != MODEST_DEBUS_COMPOSE_MAIL_ARGS_COUNT)
        return OSSO_ERROR;
@@ -492,17 +508,9 @@ static gint on_compose_mail(GArray * arguments, gpointer data, osso_rpc_t * retv
        idle_data->body = g_strdup (val.value.s);
        
        val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_ATTACHMENTS);
-       gchar *attachments_str = g_strdup (val.value.s);
+       idle_data->attachments = g_strdup (val.value.s);
 
-       list = g_strsplit(attachments_str, ",", 0);
-       for (i=0; list[i] != NULL; i++) {
-               idle_data->attachments = g_slist_append(idle_data->attachments, g_strdup(list[i]));
-       }
-       g_strfreev(list);
-
-       
-       /* printf("  debug: to=%s\n", idle_data->to); */
-       g_idle_add(on_idle_compose_mail, (gpointer)idle_data);
+       g_idle_add(on_idle_compose_mail, (gpointer)idle_data);
        
        /* Note that we cannot report failures during sending, 
         * because that would be asynchronous. */
index 85c5e53..3a13607 100644 (file)
@@ -1484,6 +1484,54 @@ modest_msg_edit_window_attach_file (ModestMsgEditWindow *window)
 }
 
 void
+modest_msg_edit_window_attach_file_noninteractive (
+               ModestMsgEditWindow *window,
+               gchar *filename)
+{
+       
+       ModestMsgEditWindowPrivate *priv;
+       
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+       if (filename) {
+               gint file_id;
+               
+               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;
+                       
+                       mime_type = gnome_vfs_get_file_mime_type_fast (filename, NULL);
+                       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);
+               }
+       }
+}
+
+void
 modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window,
                                          GList *att_list)
 {
index f3fafaa..e69ec76 100644 (file)
@@ -211,6 +211,15 @@ void                    modest_msg_edit_window_insert_image          (ModestMsgE
 void                    modest_msg_edit_window_attach_file           (ModestMsgEditWindow *window);
 
 /**
+ * modest_msg_edit_window_attach_file_noninteractive:
+ * @self: a #ModestMsgEditWindow
+ *
+ * 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, gchar *filename);
+
+/**
  * modest_msg_edit_window_remove_attachments:
  * @self: a #ModestMsgEditWindow
  * @att_list: a #GList of #TnyMimePart
@@ -306,4 +315,3 @@ gboolean        modest_msg_edit_window_check_names    (ModestMsgEditWindow *wind
 G_END_DECLS
 
 #endif /* __MODEST_MSG_EDIT_WINDOW_H__ */
-
index 7c5abbd..c92fa4d 100644 (file)
@@ -20,7 +20,8 @@ noinst_PROGRAMS = test_send_mail      \
                  test_mail_to        \
                  test_open_message   \
                  test_search         \
-                 test_delete_message
+                 test_delete_message \
+                 test_compose_mail
 
 test_send_mail_SOURCES = test_send_mail.c
 test_send_mail_LDADD = $(objects)
@@ -31,9 +32,14 @@ test_mail_to_LDADD = $(objects)
 test_open_message_SOURCES = test_open_message.c
 test_open_message_LDADD = $(objects)
 
+
+test_compose_mail_SOURCES = test_compose_mail.c
+test_compose_mail_LDADD = $(objects)
+
 test_search_SOURCES = test_search.c
 test_search_LDADD = $(objects)
 
+
 test_delete_message_SOURCES = test_delete_message.c
 test_delete_message_LDADD = $(objects)
 
diff --git a/tests/dbus_api/test_compose_mail.c b/tests/dbus_api/test_compose_mail.c
new file mode 100644 (file)
index 0000000..ac6af70
--- /dev/null
@@ -0,0 +1,43 @@
+#include <libmodest-dbus-client/libmodest-dbus-client.h>
+#include <stdio.h>
+
+
+int main(int argc, char *argv[])
+{
+       GSList *attachments = NULL;
+       /* Initialize maemo application */
+       osso_context_t * osso_context = osso_initialize(
+           "test_hello", "0.0.1", TRUE, NULL);
+              
+       /* Check that initialization was ok */
+       if (osso_context == NULL)
+       {
+               printf("osso_initialize() failed.\n");
+           return OSSO_ERROR;
+       }
+       
+       /* Call the function in libmodest-dbus-client: */
+       /* TODO: The Message URI system is not yet implemented. */
+       
+       attachments = g_slist_append(attachments, "/home/m/MyDocs/bar1.txt,/home/m/MyDocs/foo.txt");
+       
+       const gboolean ret = libmodest_dbus_client_compose_mail (
+               osso_context,
+               "marcusb@openismus.com", /* to */
+               "cc test", /* cc */
+               "bcc test", /* bcc */
+               "test subject", /* subject */
+               "test body\nline two", /* body */
+               attachments);
+               
+       
+       if (!ret) {
+                       printf("libmodest_dbus_client_open_message() failed.\n");
+               return OSSO_ERROR;
+       } else {
+               printf("libmodest_dbus_client_open_message() succeeded!\n");
+       }
+               
+    /* Exit */
+    return 0;
+}