| | 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 | |
|---|
| | 62 | typedef struct |
|---|
| | 63 | { |
|---|
| | 64 | TnySendQueue *send_queue; |
|---|
| | 65 | TMutMsgCreator *self; |
|---|
| | 66 | TnyHeader *header; |
|---|
| | 67 | } OnResponseInfo; |
|---|
| | 68 | |
|---|
| | 69 | static GtkWidget *rem_dialog = NULL; |
|---|
| | 70 | |
|---|
| | 71 | static void |
|---|
| | 72 | on_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 | |
|---|
| | 95 | static void |
|---|
| | 96 | on_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 | |
|---|
| | 126 | static TnySendQueue* |
|---|
| | 127 | get_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 | } |
|---|
| 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); |
|---|
| 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 | |
|---|
| | 317 | void |
|---|
| | 318 | tmut_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 | |
|---|
| | 333 | static void |
|---|
| | 334 | on_attachments_button_clicked (GtkButton *button, gpointer user_data) |
|---|
| | 335 | { |
|---|
| | 336 | TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (user_data); |
|---|
| | 337 | |
|---|
| | 338 | g_print ("ATTACHMENTS EDITOR\n"); |
|---|
| | 339 | |
|---|
| | 340 | return; |
|---|
| | 341 | } |
|---|
| 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); |
|---|
| 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); |
|---|
| | 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 | |
|---|