Changeset 42

Show
Ignore:
Timestamp:
11/05/07 22:51:24
Author:
pvanhoof
Message:

2007-11-05 Philip Van Hoof <pvanhoof@gnome.org>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk

    • Property svn:ignore changed from mkinstalldirs configure Makefile.in config.log depcomp config.guess config.h config.sub ltmain.sh Makefile config.status stamp-h1 config.h.in libtool autom4te.cache missing aclocal.m4 install-sh TODO.tasks .tm_project2.cache tmut.anjuta to .anjuta mkinstalldirs configure Makefile.in config.log depcomp config.guess config.h config.sub ltmain.sh Makefile config.status stamp-h1 config.h.in libtool autom4te.cache missing aclocal.m4 install-sh TODO.tasks .tm_project2.cache tmut.anjuta
  • trunk/.svnignore

    r33 r42  
     1.anjuta 
    12mkinstalldirs 
    23configure 
  • trunk/ChangeLog

    r41 r42  
     12007-11-05  Philip Van Hoof  <pvanhoof@gnome.org> 
     2 
     3        * Sending messages through a TnySendQueue and TnyTransportAccount 
     4        * Fixed forwarding a message 
     5        * Fixed replying a message 
     6 
    172007-11-04  Philip Van Hoof  <pvanhoof@gnome.org> 
    28 
  • trunk/src/tmut-main.c

    r35 r42  
    3333#include "tmut-shell-window.h" 
    3434 
     35TnyPlatformFactory *platfact = NULL; 
     36GHashTable *send_queues = NULL; 
     37 
    3538int  
    3639main (int argc, char **argv) 
    3740{ 
    3841        GtkWidget *window; 
    39         TnyPlatformFactory *platfact; 
    4042        TnyAccountStore *account_store; 
    4143        TnyAccountStoreView *view; 
  • trunk/src/tmut-msg-creator.c

    r40 r42  
    3232 
    3333#include <tny-gtk-account-list-model.h> 
     34#include <tny-platform-factory.h> 
     35#include <tny-camel-mem-stream.h> 
     36#include <tny-camel-send-queue.h> 
     37 
     38#include <string.h> 
    3439 
    3540static GObjectClass *parent_class = NULL; 
     
    4146        GtkEntry *subject_entry, *to_entry; 
    4247        GtkTextView *message_textview; 
    43         GtkButton *send_button
     48        GtkButton *send_button, *attachments_button
    4449        GtkComboBox *accounts_combo; 
     50        TnyList *attachments; 
    4551}; 
    4652 
    4753#define TMUT_MSG_CREATOR_GET_PRIVATE(o) \ 
    4854        (G_TYPE_INSTANCE_GET_PRIVATE ((o), TMUT_TYPE_MSG_CREATOR, TMutMsgCreatorPriv)) 
     55 
     56/* Translator: this is the text on the button next to the Attachments label of 
     57 * the message composer window. It should show how many items are attached to 
     58 * the new message. */ 
     59 
     60#define ATTACH_TXT _("%d attached") 
     61 
     62typedef struct 
     63{ 
     64        TnySendQueue *send_queue; 
     65        TMutMsgCreator *self; 
     66        TnyHeader *header; 
     67} OnResponseInfo; 
     68 
     69static GtkWidget *rem_dialog = NULL; 
     70 
     71static void 
     72on_response (GtkDialog *dialog, gint response, gpointer user_data) 
     73{ 
     74        OnResponseInfo *info = (OnResponseInfo *) user_data; 
     75 
     76        if (response == GTK_RESPONSE_YES) { 
     77                TnyFolder *outbox = tny_send_queue_get_outbox (info->send_queue); 
     78                tny_folder_remove_msg (outbox, info->header, NULL); 
     79                tny_folder_sync (outbox, TRUE, NULL); 
     80                g_object_unref (outbox); 
     81        } 
     82 
     83        g_object_unref (info->header); 
     84        g_object_unref (info->self); 
     85 
     86        gtk_widget_destroy (GTK_WIDGET (dialog)); 
     87        rem_dialog = NULL; 
     88 
     89        g_slice_free (OnResponseInfo, info); 
     90 
     91        return; 
     92} 
     93 
     94 
     95static void  
     96on_send_queue_error_happened (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, GError *err, gpointer user_data) 
     97{ 
     98        TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (user_data); 
     99 
     100        if (header) 
     101        { 
     102                gchar *str = g_strdup_printf (_("%s.\nDo you want to remove the message (%s)?"), 
     103                        err->message, tny_header_get_subject (header)); 
     104 
     105                if (!rem_dialog) 
     106                { 
     107                        OnResponseInfo *info = g_slice_new (OnResponseInfo); 
     108 
     109                        rem_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->shell),  
     110                                0, GTK_MESSAGE_ERROR, GTK_BUTTONS_YES_NO, str); 
     111                        g_free (str); 
     112 
     113                        info->send_queue = (TnySendQueue *) g_object_ref (self); 
     114                        info->self = (TMutMsgCreator *) g_object_ref (user_data); 
     115                        info->header = (TnyHeader *) g_object_ref (header); 
     116 
     117                        g_signal_connect (G_OBJECT (rem_dialog), "response", 
     118                                G_CALLBACK (on_response), info); 
     119 
     120                        gtk_widget_show_all (rem_dialog); 
     121                } 
     122        } 
     123        return; 
     124} 
     125 
     126static TnySendQueue* 
     127get_send_queue_for (TnyAccount *account, TMutMsgCreator *self) 
     128{ 
     129        TnySendQueue *retval; 
     130 
     131        if (!send_queues) 
     132                send_queues = g_hash_table_new (g_direct_hash, g_direct_equal); 
     133 
     134        retval = g_hash_table_lookup (send_queues, (gconstpointer) account); 
     135 
     136        if (!retval) { 
     137                TnySendQueue *send_queue = tny_camel_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT (account)); 
     138                g_signal_connect (G_OBJECT (send_queue), "error-happened", 
     139                        G_CALLBACK (on_send_queue_error_happened), self); 
     140                g_hash_table_insert (send_queues, account, send_queue); 
     141                retval = send_queue; 
     142        } 
     143 
     144        return TNY_SEND_QUEUE (g_object_ref (retval)); 
     145} 
    49146 
    50147static void 
     
    55152        TnyAccount *account = NULL; 
    56153        GtkTreeModel *model = gtk_combo_box_get_model (priv->accounts_combo); 
     154        gboolean not_ready = FALSE; 
    57155 
    58156        if (gtk_combo_box_get_active_iter (priv->accounts_combo, &iter))  
     
    61159                        TNY_GTK_ACCOUNT_LIST_MODEL_INSTANCE_COLUMN,  
    62160                        &account, -1); 
    63                 if (account) { 
    64  
    65                         g_print ("SEND on %s\n", tny_account_get_name (account)); 
    66  
     161                if (account)  
     162                { 
     163                        TnySendQueue *send_queue = get_send_queue_for (account, user_data); 
     164                        GtkTextBuffer *buffer = gtk_text_view_get_buffer (priv->message_textview); 
     165                        GtkTextIter start_iter, end_iter; 
     166                        gchar *text = NULL; 
     167                        TnyMsg *msg = tny_platform_factory_new_msg (platfact); 
     168                        TnyStream *stream = tny_camel_mem_stream_new (); 
     169                        TnyHeader *header = tny_msg_get_header (msg); 
     170                        TnyIterator *iter = tny_list_create_iterator (priv->attachments); 
     171 
     172 
     173                        tny_header_set_subject (header, gtk_entry_get_text (priv->subject_entry)); 
     174                        tny_header_set_from (header, tny_account_get_name (account)); 
     175                        tny_header_set_to (header, gtk_entry_get_text (priv->to_entry)); 
     176 
     177                        g_object_unref (header); 
     178 
     179                        gtk_text_buffer_get_bounds (buffer, &start_iter, &end_iter); 
     180                        text = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE); 
     181                        tny_stream_write (stream, text, strlen (text)); 
     182                        tny_stream_reset (stream); 
     183                        tny_mime_part_construct_from_stream (TNY_MIME_PART (msg), stream, "text/plain");  
     184                        g_object_unref (stream); 
     185 
     186                        tny_mime_part_set_header_pair (TNY_MIME_PART (msg), "X-Mailer", "TMut - " VERSION); 
     187 
     188                        while (!tny_iterator_is_done (iter)) { 
     189                                TnyMimePart *part = TNY_MIME_PART (tny_iterator_get_current (iter)); 
     190                                tny_mime_part_add_part (TNY_MIME_PART (msg), part); 
     191                                g_object_unref (part); 
     192                                tny_iterator_next (iter); 
     193                        } 
     194                        g_object_unref (iter); 
     195 
     196                        tny_send_queue_add (send_queue, msg, NULL); 
     197 
     198                        g_object_unref (msg); 
     199                        g_object_unref (send_queue); 
    67200                        g_object_unref (account); 
    68                 } 
     201                } else  
     202                        not_ready = TRUE; 
     203        } else 
     204                not_ready = TRUE; 
     205 
     206 
     207        if (not_ready) { 
     208                GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (priv->shell),  
     209                                0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,  
     210                        _("E-mail client not ready for sending E-mails. Configure " 
     211                          "an account that is suitable for sending first.")); 
     212                gtk_widget_show_all (dialog); 
    69213        } 
    70214 
     
    146290        gmtime_r (&file_time_raw, &file_time); 
    147291 
     292        /* Translator: this date-format is the date format for when creating a 
     293         * reply of a message. */ 
    148294        readable_date_size = strftime (readable_date, 63, _("%Y-%m-%d, %-I:%M %p"), &file_time); 
    149295 
     
    154300} 
    155301 
    156 /* TODO 
    157 static void  
     302void  
    158303tmut_msg_creator_add_attachment (TMutMsgCreator *self, TnyMimePart *part) 
    159304{ 
    160 
    161 */ 
     305        TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (self); 
     306        gchar *str = NULL; 
     307 
     308        tny_list_prepend (priv->attachments, G_OBJECT (part)); 
     309 
     310        str = g_strdup_printf (ATTACH_TXT, tny_list_get_length (priv->attachments)); 
     311        gtk_button_set_label (priv->attachments_button, str); 
     312        g_free (str); 
     313 
     314        return; 
     315
     316 
     317void  
     318tmut_msg_creator_remove_attachment (TMutMsgCreator *self, TnyMimePart *part) 
     319
     320        TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (self); 
     321        gchar *str = NULL; 
     322 
     323        tny_list_remove (priv->attachments, G_OBJECT (part)); 
     324 
     325        str = g_strdup_printf (ATTACH_TXT, tny_list_get_length (priv->attachments)); 
     326        gtk_button_set_label (priv->attachments_button, str); 
     327        g_free (str); 
     328 
     329        return; 
     330
     331 
     332 
     333static void 
     334on_attachments_button_clicked (GtkButton *button, gpointer user_data) 
     335
     336        TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (user_data); 
     337 
     338g_print ("ATTACHMENTS EDITOR\n"); 
     339 
     340        return; 
     341
    162342 
    163343void  
     
    167347        GtkTextBuffer *text_buffer = gtk_text_view_get_buffer (priv->message_textview); 
    168348        TnyHeader *header = tny_msg_get_header (msg); 
    169         GString *str; 
    170  
    171  
    172         if (header) { 
    173                 str = g_string_new (""); 
    174                 g_string_printf (str, _("On %s, %s wrote:\n"),  
    175                         _get_readable_date (tny_header_get_date_sent (header)), 
    176                         tny_header_get_from (header)); 
    177         } else 
    178                 str = g_string_new (_("You wrote:\n")); 
    179  
    180         /* TODO: Attach as RFC822 in stead  
    181          tmut_msg_creator_add_attachment (self, TNY_MIME_PART (msg)); */ 
    182  
    183         set_reply_msg (self, msg, str); 
    184  
    185         if (str) { 
    186                 gtk_text_buffer_set_text (text_buffer, str->str, str->len); 
    187                 g_string_free (str, TRUE); 
    188         } 
     349 
     350        /* Translator: this Fwd-text is the default subject field when creating 
     351         * a forward of a message */ 
     352        gchar *osubject = (gchar *) tny_header_get_subject (header), 
     353              *str = g_strdup_printf (_("[Fwd: %s]"), osubject?osubject:_("No subject")); 
     354 
     355        gtk_entry_set_text (priv->subject_entry, (const gchar*) str); 
     356 
     357        g_free (str); 
     358 
     359        tmut_msg_creator_add_attachment (self, TNY_MIME_PART (msg)); 
     360 
     361        gtk_text_buffer_set_text (text_buffer, "", 0); 
    189362 
    190363        return; 
     
    197370        GtkTextBuffer *text_buffer = gtk_text_view_get_buffer (priv->message_textview); 
    198371        TnyHeader *header = tny_msg_get_header (msg); 
    199         GString *str; 
    200  
    201         if (header) { 
    202                 str = g_string_new (""); 
    203                 g_string_printf (str, _("On %s, %s wrote:\n"),  
    204                         _get_readable_date (tny_header_get_date_sent (header)), 
    205                         tny_header_get_from (header)); 
    206         } else 
    207                 str = g_string_new (_("You wrote:\n")); 
    208  
    209         set_reply_msg (self, msg, str); 
     372        GString *gstr = g_string_new (""); 
     373 
     374        /* Translator: this Fwd-text is the default subject field when creating 
     375         * a forward of a message */ 
     376        gchar *osubject = (gchar *) tny_header_get_subject (header), 
     377              *str = g_strdup_printf (_("[Re: %s]"), osubject?osubject:_("No subject")); 
     378 
     379        gtk_entry_set_text (priv->subject_entry, (const gchar*) str); 
     380 
     381        g_free (str); 
     382 
     383        g_string_printf (gstr, _("On %s, %s wrote:\n"),  
     384                _get_readable_date (tny_header_get_date_sent (header)), 
     385                tny_header_get_from (header)); 
     386 
     387        set_reply_msg (self, msg, gstr); 
    210388 
    211389        if (str) { 
    212                 gtk_text_buffer_set_text (text_buffer, str->str, str->len); 
    213                 g_string_free (str, TRUE); 
     390                gtk_text_buffer_set_text (text_buffer, gstr->str, gstr->len); 
     391                g_string_free (gstr, TRUE); 
    214392        } 
    215393 
     
    260438        GtkCellRenderer *renderer; 
    261439        GtkTreeViewColumn *column; 
     440        gchar *str = NULL; 
     441 
     442        priv->attachments = tny_simple_list_new (); 
    262443 
    263444        vbox1 = GTK_WIDGET (instance); 
    264445 
    265         table1 = gtk_table_new (3, 2, FALSE); 
     446        table1 = gtk_table_new (4, 2, FALSE); 
    266447        gtk_widget_show (table1); 
    267448        gtk_box_pack_start (GTK_BOX (vbox1), table1, FALSE, TRUE, 0); 
     
    292473        gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5); 
    293474 
     475 
     476        label2 = gtk_label_new (_("<b>Attached:</b>")); 
     477        gtk_widget_show (label2); 
     478        gtk_table_attach (GTK_TABLE (table1), label2, 0, 1, 3, 4, 
     479                        (GtkAttachOptions) (GTK_FILL), 
     480                        (GtkAttachOptions) (0), 0, 0); 
     481        gtk_label_set_use_markup (GTK_LABEL (label2), TRUE); 
     482        gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5); 
     483 
    294484        priv->accounts_combo = GTK_COMBO_BOX (gtk_combo_box_new ()); 
    295485        gtk_widget_show (GTK_WIDGET (priv->accounts_combo)); 
     
    305495                        (GtkAttachOptions) (0), 0, 0); 
    306496 
     497        priv->to_entry = GTK_ENTRY (gtk_entry_new ()); 
     498        gtk_widget_show (GTK_WIDGET (priv->to_entry)); 
     499        gtk_table_attach (GTK_TABLE (table1), GTK_WIDGET (priv->to_entry),  
     500                        1, 2, 1, 2, 
     501                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 
     502                        (GtkAttachOptions) (0), 0, 0); 
     503 
    307504        priv->subject_entry = GTK_ENTRY (gtk_entry_new ()); 
    308505        gtk_widget_show (GTK_WIDGET (priv->subject_entry)); 
    309506        gtk_table_attach (GTK_TABLE (table1), GTK_WIDGET (priv->subject_entry),  
    310                         1, 2, 1, 2
     507                        1, 2, 2, 3
    311508                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 
    312509                        (GtkAttachOptions) (0), 0, 0); 
    313510 
    314         priv->to_entry = GTK_ENTRY (gtk_entry_new ()); 
    315         gtk_widget_show (GTK_WIDGET (priv->to_entry)); 
    316         gtk_table_attach (GTK_TABLE (table1), GTK_WIDGET (priv->to_entry),  
    317                         1, 2, 2, 3, 
     511        str = g_strdup_printf (ATTACH_TXT, 0); 
     512        priv->attachments_button = GTK_BUTTON (gtk_button_new_with_label (str)); 
     513        g_free (str); 
     514        gtk_widget_show (GTK_WIDGET (priv->attachments_button)); 
     515        gtk_table_attach (GTK_TABLE (table1), GTK_WIDGET (priv->attachments_button),  
     516                        1, 2, 3, 4, 
    318517                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 
    319518                        (GtkAttachOptions) (0), 0, 0); 
     
    336535                G_CALLBACK (on_send_button_clicked), instance); 
    337536 
     537        g_signal_connect (G_OBJECT (priv->attachments_button), "clicked", 
     538                G_CALLBACK (on_attachments_button_clicked), instance); 
     539 
    338540        return; 
    339541} 
     
    343545tmut_msg_creator_finalize (GObject *object) 
    344546{ 
     547        TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (object); 
     548 
     549        g_object_unref (priv->attachments); 
     550 
    345551        (*parent_class->finalize) (object); 
    346552 
  • trunk/src/tmut-msg-creator.h

    r40 r42  
    6060void tmut_msg_creator_set_forward_msg (TMutMsgCreator *self, TnyMsg *msg); 
    6161 
     62void tmut_msg_creator_add_attachment (TMutMsgCreator *self, TnyMimePart *part); 
     63void tmut_msg_creator_remove_attachment (TMutMsgCreator *self, TnyMimePart *part); 
     64 
    6265G_END_DECLS 
    6366 
  • trunk/src/tmut-shared.h

    r12 r42  
    11#ifndef TMUT_SHARED_H 
    22#define TMUT_SHARED_H 
     3#include <tny-platform-factory.h> 
     4#include <tny-send-queue.h> 
     5 
    36typedef struct _TMutShellWindow TMutShellWindow; 
    47typedef struct _TMutShellWindowClass TMutShellWindowClass; 
    58typedef struct _TMutShellChild TMutShellChild; 
    69typedef struct _TMutShellChildIface TMutShellChildIface; 
     10 
     11extern TnyPlatformFactory *platfact; 
     12extern GHashTable *send_queues; 
     13 
    714#endif