#include "modest-tny-platform-factory.h"
#include "modest-tny-msg.h"
#include "modest-tny-folder.h"
+#include "modest-tny-account.h"
#include "modest-address-book.h"
#include "modest-text-utils.h"
#include <tny-simple-list.h>
static gboolean msg_body_focus (GtkWidget *focus, GdkEventFocus *event, gpointer userdata);
static void body_changed (GtkTextBuffer *buffer, ModestMsgEditWindow *editor);
static void recpt_field_changed (GtkTextBuffer *buffer, ModestMsgEditWindow *editor);
-static void reset_modified (ModestMsgEditWindow *editor);
static void text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *window);
static void text_buffer_can_undo (GtkTextBuffer *buffer, gboolean can_undo, ModestMsgEditWindow *window);
const gchar *str,
GtkTextIter *match_start,
GtkTextIter *match_end);
-
+
+static void remove_tags (WPTextBuffer *buffer);
+
+static void on_account_removed (TnyAccountStore *account_store,
+ TnyAccount *account,
+ gpointer user_data);
+
+
static void DEBUG_BUFFER (WPTextBuffer *buffer)
{
#ifdef DEBUG
gint last_cid;
GList *attachments;
+ GList *images;
TnyHeaderFlags priority_flags;
gboolean can_undo, can_redo;
gulong clipboard_change_handler_id;
gulong default_clipboard_change_handler_id;
+ gulong account_removed_handler_id;
gchar *clipboard_text;
TnyMsg *draft_msg;
priv->bcc_field = NULL;
priv->subject_field = NULL;
priv->attachments = NULL;
+ priv->images = NULL;
priv->last_cid = 0;
priv->zoom_level = 1.0;
priv->can_redo = FALSE;
priv->clipboard_change_handler_id = 0;
priv->default_clipboard_change_handler_id = 0;
+ priv->account_removed_handler_id = 0;
priv->clipboard_text = NULL;
priv->sent = FALSE;
priv->default_clipboard_change_handler_id))
g_signal_handler_disconnect (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD),
priv->default_clipboard_change_handler_id);
+
+ if (priv->account_removed_handler_id &&
+ g_signal_handler_is_connected (modest_runtime_get_account_store (),
+ priv->account_removed_handler_id))
+ g_signal_handler_disconnect(modest_runtime_get_account_store (),
+ priv->account_removed_handler_id);
}
static void
}
static void
-replace_with_attachments (ModestMsgEditWindow *self, GList *attachments)
+replace_with_images (ModestMsgEditWindow *self, GList *attachments)
{
ModestMsgEditWindowPrivate *priv;
GList *node;
}
static void
+get_related_images (ModestMsgEditWindow *self, TnyMsg *msg)
+{
+ TnyMimePart *parent = NULL;
+ const gchar *content_type = NULL;
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+
+ content_type = tny_mime_part_get_content_type (TNY_MIME_PART (msg));
+
+ if (content_type && !g_strcasecmp (content_type, "multipart/related")) {
+ parent = g_object_ref (msg);
+ } else if (content_type && !g_strcasecmp (content_type, "multipart/mixed")) {
+ TnyList *parts = TNY_LIST (tny_simple_list_new ());
+ TnyIterator *iter;
+
+ tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
+ iter = tny_list_create_iterator (parts);
+ while (!tny_iterator_is_done (iter)) {
+ TnyMimePart *part;
+ part = TNY_MIME_PART (tny_iterator_get_current (iter));
+ content_type = tny_mime_part_get_content_type (part);
+ if (content_type && !g_strcasecmp (content_type, "multipart/related")) {
+ parent = part;
+ break;
+ } else {
+ g_object_unref (part);
+ }
+ tny_iterator_next (iter);
+ }
+ g_object_unref (iter);
+ g_object_unref (parts);
+ }
+
+ if (parent != NULL) {
+ TnyList *parts = TNY_LIST (tny_simple_list_new ());
+ TnyIterator *iter;
+
+ tny_mime_part_get_parts (TNY_MIME_PART (parent), parts);
+ iter = tny_list_create_iterator (parts);
+ while (!tny_iterator_is_done (iter)) {
+ TnyMimePart *part;
+ part = TNY_MIME_PART (tny_iterator_get_current (iter));
+ content_type = tny_mime_part_get_content_type (part);
+ if (content_type && g_str_has_prefix (content_type, "image/")) {
+ priv->images = g_list_prepend (priv->images, part);
+ } else {
+ g_object_unref (part);
+ }
+ tny_iterator_next (iter);
+ }
+ g_object_unref (iter);
+ g_object_unref (parts);
+ g_object_unref (parent);
+ }
+}
+
+static void
update_last_cid (ModestMsgEditWindow *self, GList *attachments)
{
GList *node;
} else {
gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
gtk_widget_show_all (priv->attachments_caption);
- replace_with_attachments (self, priv->attachments);
}
+ get_related_images (self, msg);
update_last_cid (self, priv->attachments);
+ update_last_cid (self, priv->images);
+ replace_with_images (self, priv->images);
if (preserve_is_rich && !is_html) {
wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
gtk_text_buffer_get_start_iter (priv->text_buffer, &iter);
gtk_text_buffer_place_cursor (priv->text_buffer, &iter);
- reset_modified (self);
+ modest_msg_edit_window_reset_modified (self);
modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (self));
text_buffer_can_undo (priv->text_buffer, FALSE, self);
modest_window_check_dimming_rules_group (MODEST_WINDOW (obj), "ModestClipboardDimmingRules");
priv->update_caption_visibility = TRUE;
- reset_modified (MODEST_MSG_EDIT_WINDOW (obj));
+ modest_msg_edit_window_reset_modified (MODEST_MSG_EDIT_WINDOW (obj));
+
+ /* Track account-removed signal, this window should be closed
+ in the case we're creating a mail associated to the account
+ that is deleted */
+ priv->account_removed_handler_id =
+ g_signal_connect (G_OBJECT (modest_runtime_get_account_store ()),
+ "account_removed",
+ G_CALLBACK(on_account_removed),
+ obj);
return (ModestWindow*) obj;
}
g_object_ref (cursor->data));
cursor = g_list_next (cursor);
}
+
+ GtkTextTagTable *tag_table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (priv->text_buffer));
+ cursor = priv->images;
+ data->images = NULL;
+ while (cursor) {
+ const gchar *cid;
+ if (!(TNY_IS_MIME_PART(cursor->data))) {
+ g_warning ("strange data in attachment list");
+ cursor = g_list_next (cursor);
+ continue;
+ }
+ cid = tny_mime_part_get_content_id (cursor->data);
+ if (cid) {
+ gchar *image_tag_id;
+ GtkTextTag *image_tag;
+ GtkTextIter iter;
+ image_tag_id = g_strdup_printf ("image-tag-%s", cid);
+ image_tag = gtk_text_tag_table_lookup (tag_table, image_tag_id);
+ g_free (image_tag_id);
+
+ gtk_text_buffer_get_start_iter (priv->text_buffer, &iter);
+ if (image_tag &&
+ ((gtk_text_iter_has_tag (&iter, image_tag))||
+ (gtk_text_iter_forward_to_tag_toggle (&iter, image_tag))))
+ data->images = g_list_append (data->images,
+ g_object_ref (cursor->data));
+ }
+ cursor = g_list_next (cursor);
+ }
data->priority_flags = priv->priority_flags;
g_list_foreach (data->attachments, (GFunc)unref_gobject, NULL);
g_list_free (data->attachments);
+ g_list_foreach (data->images, (GFunc)unref_gobject, NULL);
+ g_list_free (data->images);
g_slice_free (MsgData, data);
}
wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, g_strdup (tny_mime_part_get_content_id (mime_part)), pixbuf);
}
- 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);
+ priv->images = g_list_prepend (priv->images, mime_part);
gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
g_free (filename);
gboolean dialog_response;
GList *node;
gchar *message = NULL;
- const gchar *filename = NULL;
+ gchar *filename = NULL;
if (att_list->next == NULL) {
- filename = tny_mime_part_get_filename (TNY_MIME_PART (att_list->data));
+ if (TNY_IS_MSG (att_list->data)) {
+ TnyHeader *header = tny_msg_get_header (TNY_MSG (att_list->data));
+ if (header) {
+ filename = g_strdup (tny_header_get_subject (header));
+ g_object_unref (header);
+ }
+ if (filename == NULL) {
+ filename = g_strdup (_("mail_va_no_subject"));
+ }
+ } else {
+ filename = g_strdup (tny_mime_part_get_filename (TNY_MIME_PART (att_list->data)));
+ }
} else {
- filename = "";
+ filename = g_strdup ("");
}
message = g_strdup_printf (ngettext("emev_nc_delete_attachment", "emev_nc_delete_attachments",
att_list->next == NULL), filename);
+ g_free (filename);
confirmation_dialog = hildon_note_new_confirmation (GTK_WINDOW (window), message);
g_free (message);
dialog_response = (gtk_dialog_run (GTK_DIALOG (confirmation_dialog))==GTK_RESPONSE_OK);
switch (file_format) {
case MODEST_FILE_FORMAT_FORMATTED_TEXT:
wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
+ remove_tags (WP_TEXT_BUFFER (priv->text_buffer));
break;
case MODEST_FILE_FORMAT_PLAIN_TEXT:
{
modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (editor));
}
-static void
-reset_modified (ModestMsgEditWindow *editor)
+void
+modest_msg_edit_window_reset_modified (ModestMsgEditWindow *editor)
{
ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
GtkTextBuffer *buffer;
GString *result = g_string_new ("");
gchar *current;
gint result_len = 0;
+ const gchar *entry_text = NULL;
+ gint old_length;
+
+ entry_text = gtk_entry_get_text (GTK_ENTRY (editable));
+ old_length = g_utf8_strlen (entry_text, -1);
for (current = new_text; current != NULL && *current != '\0'; current = g_utf8_next_char (current)) {
gunichar c = g_utf8_get_char_validated (current, 8);
g_signal_handlers_unblock_by_func(G_OBJECT(editable), G_CALLBACK(subject_field_insert_text), window);
}
}
+
+ if (result_len + old_length > 1000) {
+ hildon_banner_show_information (GTK_WIDGET (window), NULL,
+ dgettext("hildon-common-strings",
+ "ckdg_ib_maximum_characters_reached"));
+ }
g_string_free (result, TRUE);
}
if (tag == NULL+13) return;
g_object_get (G_OBJECT (tag), "name", &tag_name, NULL);
if ((tag_name != NULL) && (g_str_has_prefix (tag_name, "image-tag-replace-"))) {
- replace_with_attachments (window, priv->attachments);
+ replace_with_images (window, priv->images);
}
}
}
}
+static void
+remove_tags (WPTextBuffer *buffer)
+{
+ GtkTextIter start, end;
+
+ gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &start);
+ gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (buffer), &end);
+
+ gtk_text_buffer_remove_all_tags (GTK_TEXT_BUFFER (buffer), &start, &end);
+}
+
+static void
+on_account_removed (TnyAccountStore *account_store,
+ TnyAccount *account,
+ gpointer user_data)
+{
+ /* Do nothing if it's a store account, because we use the
+ transport to send the messages */
+ if (tny_account_get_account_type(account) == TNY_ACCOUNT_TYPE_TRANSPORT) {
+ const gchar *parent_acc = NULL;
+ const gchar *our_acc = NULL;
+
+ our_acc = modest_window_get_active_account (MODEST_WINDOW (user_data));
+ parent_acc = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+ /* Close this window if I'm showing a message of the removed account */
+ if (strcmp (parent_acc, our_acc) == 0)
+ modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (user_data));
+ }
+}