Changeset 65

Show
Ignore:
Timestamp:
12/02/07 23:02:11
Author:
pvanhoof
Message:
        • Creating the message in a thread, not let the UI hang less
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r64 r65  
    22 
    33        * Creating multipart messages correctly 
     4        * Creating the message in a thread, not let the UI hang less 
    45 
    562007-11-15  Philip Van Hoof  <pvanhoof@gnome.org> 
  • trunk/src/tmut-msg-creator.c

    r64 r65  
    147147} 
    148148 
     149typedef struct { 
     150        TnyAccount *account; 
     151        TnyStream *stream; 
     152        TnySendQueue *send_queue; 
     153        TnyMsg *msg; 
     154        TnyList *attachments; 
     155} CreateAndSendMsgInfo; 
     156 
     157static gpointer  
     158create_and_send_msg_thread (gpointer user_data) 
     159{ 
     160        CreateAndSendMsgInfo *info = (CreateAndSendMsgInfo *) user_data; 
     161 
     162        if (info->attachments && tny_list_get_length (info->attachments) > 0) { 
     163                TnyIterator *iter = tny_list_create_iterator (info->attachments); 
     164                TnyMimePart *msg_part = tny_camel_mime_part_new (); 
     165 
     166                tny_mime_part_construct_from_stream (msg_part, info->stream, "text/plain"); 
     167                tny_mime_part_add_part (TNY_MIME_PART (info->msg), msg_part); 
     168                g_object_unref (msg_part); 
     169 
     170                while (!tny_iterator_is_done (iter)) { 
     171                        TnyMimePart *part = TNY_MIME_PART (tny_iterator_get_current (iter)); 
     172                        tny_mime_part_add_part (TNY_MIME_PART (info->msg), part); 
     173                        g_object_unref (part); 
     174                        tny_iterator_next (iter); 
     175                } 
     176                g_object_unref (iter); 
     177        } else 
     178                tny_mime_part_construct_from_stream (TNY_MIME_PART (info->msg), info->stream, "text/plain");  
     179 
     180        tny_send_queue_add (info->send_queue, info->msg, NULL); 
     181 
     182 
     183        if (info->attachments) 
     184                g_object_unref (info->attachments); 
     185        g_object_unref (info->send_queue); 
     186        g_object_unref (info->msg); 
     187        g_object_unref (info->stream); 
     188        g_object_unref (info->account); 
     189 
     190        g_slice_free (CreateAndSendMsgInfo, info); 
     191 
     192        return NULL; 
     193} 
     194 
    149195static void 
    150196on_send_button_clicked (GtkButton *button, gpointer user_data) 
     
    163209                if (account)  
    164210                { 
     211                        CreateAndSendMsgInfo *info = g_slice_new0 (CreateAndSendMsgInfo); 
    165212                        TnySendQueue *send_queue = get_send_queue_for (account, user_data); 
    166213                        GtkTextBuffer *buffer = gtk_text_view_get_buffer (priv->message_textview); 
    167214                        GtkTextIter start_iter, end_iter; 
    168215                        gchar *text = NULL; 
     216                        TnyStream *stream = tny_camel_mem_stream_new (); 
    169217                        TnyMsg *msg = tny_platform_factory_new_msg (platfact); 
    170                         TnyStream *stream = tny_camel_mem_stream_new (); 
    171218                        TnyHeader *header = tny_msg_get_header (msg); 
    172219 
     
    184231                        tny_mime_part_set_header_pair (TNY_MIME_PART (msg), "X-Mailer", "TMut - " VERSION); 
    185232 
    186                         if (tny_list_get_length (priv->attachments) > 0) { 
    187                                 TnyIterator *iter = tny_list_create_iterator (priv->attachments); 
    188                                 TnyMimePart *msg_part = tny_camel_mime_part_new (); 
    189  
    190                                 tny_mime_part_construct_from_stream (msg_part, stream, "text/plain"); 
    191                                 tny_mime_part_add_part (TNY_MIME_PART (msg), msg_part); 
    192                                 g_object_unref (msg_part); 
    193  
    194                                 while (!tny_iterator_is_done (iter)) { 
    195                                         TnyMimePart *part = TNY_MIME_PART (tny_iterator_get_current (iter)); 
    196                                         tny_mime_part_add_part (TNY_MIME_PART (msg), part); 
    197                                         g_object_unref (part); 
    198                                         tny_iterator_next (iter); 
    199                                 } 
    200                                 g_object_unref (iter); 
    201                         } else 
    202                                 tny_mime_part_construct_from_stream (TNY_MIME_PART (msg), stream, "text/plain");  
     233                        if (priv->attachments) 
     234                                info->attachments = tny_list_copy (priv->attachments); 
     235                        else 
     236                                info->attachments = NULL; 
     237                        info->send_queue = g_object_ref (send_queue); 
     238                        info->msg = g_object_ref (msg); 
     239                        info->stream = g_object_ref (stream); 
     240                        info->account = g_object_ref (account); 
     241 
     242                        g_thread_create (create_and_send_msg_thread, info, FALSE, NULL); 
    203243 
    204244                        g_object_unref (stream); 
    205                         tny_send_queue_add (send_queue, msg, NULL); 
    206  
    207245                        g_object_unref (msg); 
    208246                        g_object_unref (send_queue);