X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmaemo%2Fmodest-msg-edit-window.c;h=77cedb06ddbecf797ef5653fa89e4facb2bc5efc;hp=fb5f4119fa20a8d1af2f10a6beaf931f79078c0e;hb=a4a4f2640022f8b27dc85bc1ef49ac88dbbcf3d3;hpb=38402a6550ee767271308f42ebfbfc81a1fa736b diff --git a/src/maemo/modest-msg-edit-window.c b/src/maemo/modest-msg-edit-window.c index fb5f411..77cedb0 100644 --- a/src/maemo/modest-msg-edit-window.c +++ b/src/maemo/modest-msg-edit-window.c @@ -56,6 +56,7 @@ #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 @@ -93,7 +94,6 @@ static void modest_msg_edit_window_finalize (GObject *obj); 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); @@ -150,7 +150,14 @@ static gboolean gtk_text_iter_forward_search_insensitive (const GtkTextIter *ite 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 @@ -243,6 +250,7 @@ struct _ModestMsgEditWindowPrivate { gint last_cid; GList *attachments; + GList *images; TnyHeaderFlags priority_flags; @@ -251,6 +259,8 @@ struct _ModestMsgEditWindowPrivate { 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; TnyMsg *outbox_msg; @@ -345,6 +355,7 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj) priv->bcc_field = NULL; priv->subject_field = NULL; priv->attachments = NULL; + priv->images = NULL; priv->last_cid = 0; priv->zoom_level = 1.0; @@ -365,9 +376,14 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj) 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->last_vadj_upper = 0; + + modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(), + GTK_WINDOW(obj),"applications_email_editor"); } @@ -613,14 +629,22 @@ modest_msg_edit_window_disconnect_signals (ModestWindow *window) { ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); - if (g_signal_handler_is_connected (gtk_clipboard_get (GDK_SELECTION_PRIMARY), + if (gtk_clipboard_get (GDK_SELECTION_PRIMARY) && + g_signal_handler_is_connected (gtk_clipboard_get (GDK_SELECTION_PRIMARY), priv->clipboard_change_handler_id)) g_signal_handler_disconnect (gtk_clipboard_get (GDK_SELECTION_PRIMARY), priv->clipboard_change_handler_id); - if (g_signal_handler_is_connected (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD), + if (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD) && + g_signal_handler_is_connected (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD), 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 @@ -631,6 +655,11 @@ modest_msg_edit_window_finalize (GObject *obj) /* Sanity check: shouldn't be needed, the window mgr should call this function before */ modest_msg_edit_window_disconnect_signals (MODEST_WINDOW (obj)); + + if (priv->clipboard_text != NULL) { + g_free (priv->clipboard_text); + priv->clipboard_text = NULL; + } if (priv->draft_msg != NULL) { TnyHeader *header = tny_msg_get_header (priv->draft_msg); @@ -725,7 +754,7 @@ pixbuf_from_stream (TnyStream *stream, const gchar *mime_type) } static void -replace_with_attachments (ModestMsgEditWindow *self, GList *attachments) +replace_with_images (ModestMsgEditWindow *self, GList *attachments) { ModestMsgEditWindowPrivate *priv; GList *node; @@ -742,7 +771,7 @@ replace_with_attachments (ModestMsgEditWindow *self, GList *attachments) g_object_unref (stream); if (pixbuf != NULL) { -/* wp_text_buffer_replace_image (WP_TEXT_BUFFER (priv->text_buffer), cid, pixbuf); */ + wp_text_buffer_replace_image (WP_TEXT_BUFFER (priv->text_buffer), cid, pixbuf); g_object_unref (pixbuf); } } @@ -750,6 +779,62 @@ replace_with_attachments (ModestMsgEditWindow *self, GList *attachments) } 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; @@ -791,7 +876,7 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich) cc = tny_header_get_cc (header); bcc = tny_header_get_bcc (header); subject = tny_header_get_subject (header); - priority_flags = tny_header_get_flags (header) & TNY_HEADER_FLAG_PRIORITY; + priority_flags = tny_header_get_priority (header); if (to) modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->to_field), to); @@ -833,6 +918,20 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich) wp_text_buffer_load_document_end (WP_TEXT_BUFFER (priv->text_buffer)); g_free (body); + /* Add attachments to the view */ + modest_attachments_view_set_message (MODEST_ATTACHMENTS_VIEW (priv->attachments_view), msg); + priv->attachments = modest_attachments_view_get_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view)); + if (priv->attachments == NULL) { + gtk_widget_hide (priv->attachments_caption); + } else { + gtk_widget_set_no_show_all (priv->attachments_caption, FALSE); + gtk_widget_show_all (priv->attachments_caption); + } + 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); /* Get the default format required from configuration */ @@ -851,24 +950,12 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich) value that comes from msg <- not sure, should it be allowed? */ - /* Add attachments to the view */ - modest_attachments_view_set_message (MODEST_ATTACHMENTS_VIEW (priv->attachments_view), msg); - priv->attachments = modest_attachments_view_get_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view)); - if (priv->attachments == NULL) { - gtk_widget_hide (priv->attachments_caption); - } else { - gtk_widget_set_no_show_all (priv->attachments_caption, FALSE); - gtk_widget_show_all (priv->attachments_caption); - replace_with_attachments (self, priv->attachments); - } - update_last_cid (self, priv->attachments); - DEBUG_BUFFER (WP_TEXT_BUFFER (priv->text_buffer)); 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); @@ -884,6 +971,9 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich) if (msg_folder) { if (modest_tny_folder_is_local_folder (msg_folder)) { TnyFolderType type = modest_tny_folder_get_local_or_mmc_folder_type (msg_folder); + if (type == TNY_FOLDER_TYPE_INVALID) + g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__); + if (type == TNY_FOLDER_TYPE_DRAFTS) priv->draft_msg = g_object_ref(msg); if (type == TNY_FOLDER_TYPE_OUTBOX) @@ -1256,7 +1346,16 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre 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; } @@ -1343,6 +1442,35 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window) 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; @@ -1382,6 +1510,8 @@ modest_msg_edit_window_free_msg_data (ModestMsgEditWindow *edit_window, 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); } @@ -1605,7 +1735,7 @@ text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *windo } - +#ifdef MODEST_HILDON_VERSION_0 void modest_msg_edit_window_select_color (ModestMsgEditWindow *window) { @@ -1614,43 +1744,26 @@ modest_msg_edit_window_select_color (ModestMsgEditWindow *window) ModestMsgEditWindowPrivate *priv; GtkWidget *dialog = NULL; gint response; - const GdkColor *new_color = NULL; - + GdkColor *new_color = NULL; + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, FALSE); -#ifdef MODEST_HILDON_VERSION_0 dialog = hildon_color_selector_new (GTK_WINDOW (window)); hildon_color_selector_set_color (HILDON_COLOR_SELECTOR (dialog), &(buffer_format->color)); -#else - dialog = hildon_color_chooser_new (); - hildon_color_chooser_set_color (HILDON_COLOR_CHOOSER (dialog), &(buffer_format->color)); -#endif /*MODEST_HILDON_VERSION_0*/ g_free (buffer_format); - response = gtk_dialog_run (GTK_DIALOG (dialog)); - switch (response) { - case GTK_RESPONSE_OK: { -#ifdef MODEST_HILDON_VERSION_0 + if (gtk_dialog_run (GTK_DIALOG (dialog) == GTK_RESPONSE_OK)) { new_color = hildon_color_selector_get_color (HILDON_COLOR_SELECTOR (dialog)); -#else - GdkColor col; - hildon_color_chooser_get_color (HILDON_COLOR_CHOOSER(dialog), &col); - new_color = &col; -#endif /*MODEST_HILDON_VERSION_0*/ - } - - break; - default: - break; + if (new_color != NULL) { + wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, + (gpointer) new_color); + } } gtk_widget_destroy (dialog); - - if (new_color != NULL) - wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) new_color); - } + void modest_msg_edit_window_select_background_color (ModestMsgEditWindow *window) { @@ -1664,36 +1777,70 @@ modest_msg_edit_window_select_background_color (ModestMsgEditWindow *window) priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); old_color = (GdkColor*)wp_text_buffer_get_background_color (WP_TEXT_BUFFER (priv->text_buffer)); -#ifdef MODEST_HILDON_VERSION_0 dialog = hildon_color_selector_new (GTK_WINDOW (window)); hildon_color_selector_set_color (HILDON_COLOR_SELECTOR (dialog),(GdkColor*)old_color); -#else - dialog = hildon_color_chooser_new (); - hildon_color_chooser_set_color (HILDON_COLOR_CHOOSER (dialog),(GdkColor*)old_color); -#endif /*MODEST_HILDON_VERSION_9*/ - response = gtk_dialog_run (GTK_DIALOG (dialog)); - switch (response) { - case GTK_RESPONSE_OK: { -#ifdef MODEST_HILDON_VERSION_0 + if (gtk_dialog_run (GTK_DIALOG (dialog) == GTK_RESPONSE_OK)) { new_color = hildon_color_selector_get_color (HILDON_COLOR_SELECTOR (dialog)); -#else + if (new_color != NULL) + wp_text_buffer_set_background_color (WP_TEXT_BUFFER (priv->text_buffer), new_color); + } + gtk_widget_destroy (dialog); + +} + +#else +void +modest_msg_edit_window_select_color (ModestMsgEditWindow *window) +{ + + WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1); + ModestMsgEditWindowPrivate *priv; + GtkWidget *dialog = NULL; + + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); + wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, FALSE); + + dialog = hildon_color_chooser_new (); + hildon_color_chooser_set_color (HILDON_COLOR_CHOOSER (dialog), &(buffer_format->color)); + g_free (buffer_format); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) { GdkColor col; hildon_color_chooser_get_color (HILDON_COLOR_CHOOSER(dialog), &col); - new_color = &col; -#endif /*MODEST_HILDON_VERSION_0*/ - } - break; - default: - break; + wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, + (gpointer) &col); } gtk_widget_destroy (dialog); +} - if (new_color != NULL) - wp_text_buffer_set_background_color (WP_TEXT_BUFFER (priv->text_buffer), new_color); +void +modest_msg_edit_window_select_background_color (ModestMsgEditWindow *window) +{ + + ModestMsgEditWindowPrivate *priv; + GtkWidget *dialog = NULL; + GdkColor *old_color = NULL; + + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); + old_color = (GdkColor*)wp_text_buffer_get_background_color (WP_TEXT_BUFFER (priv->text_buffer)); + + dialog = hildon_color_chooser_new (); + hildon_color_chooser_set_color (HILDON_COLOR_CHOOSER (dialog),(GdkColor*)old_color); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) { + GdkColor col; + hildon_color_chooser_get_color (HILDON_COLOR_CHOOSER(dialog), &col); + wp_text_buffer_set_background_color (WP_TEXT_BUFFER (priv->text_buffer), &col); + } + gtk_widget_destroy (dialog); } +#endif /*!MODEST_HILDON_VERSION_0*/ + + + static TnyStream* create_stream_for_uri (const gchar* uri) { if (!uri) @@ -1793,11 +1940,7 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window) 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); @@ -1926,15 +2069,27 @@ modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window, 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); @@ -2331,7 +2486,6 @@ modest_msg_edit_window_set_priority_flags (ModestMsgEditWindow *window, priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); parent_priv = MODEST_WINDOW_GET_PRIVATE (window); - priority_flags = priority_flags & (TNY_HEADER_FLAG_PRIORITY); if (priv->priority_flags != priority_flags) { GtkAction *priority_action = NULL; @@ -2382,6 +2536,7 @@ modest_msg_edit_window_set_file_format (ModestMsgEditWindow *window, 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: { @@ -2529,6 +2684,7 @@ modest_msg_edit_window_select_font (ModestMsgEditWindow *window) fmt.cs.font_size = TRUE; } wp_text_buffer_set_format(WP_TEXT_BUFFER(priv->text_buffer), &fmt); + text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), window); } gtk_widget_destroy (dialog); @@ -2672,8 +2828,8 @@ body_changed (GtkTextBuffer *buffer, ModestMsgEditWindow *editor) 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; @@ -2756,14 +2912,32 @@ modest_msg_edit_window_add_attachment_clicked (GtkButton *button, modest_msg_edit_window_offer_attach_file (window); } +const gchar * +modest_msg_edit_window_get_clipboard_text (ModestMsgEditWindow *win) +{ + ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (win); + + return priv->clipboard_text; +} + static void modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard, GdkEvent *event, ModestMsgEditWindow *window) { + ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); + GtkClipboard *selection_clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + gchar *text = NULL; if (!GTK_WIDGET_VISIBLE (window)) return; + text = gtk_clipboard_wait_for_text (selection_clipboard); + + if (priv->clipboard_text != NULL) { + g_free (priv->clipboard_text); + } + priv->clipboard_text = text; + modest_window_check_dimming_rules_group (MODEST_WINDOW (window), "ModestClipboardDimmingRules"); } static void @@ -2814,6 +2988,11 @@ subject_field_insert_text (GtkEditable *editable, 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); @@ -2839,6 +3018,12 @@ subject_field_insert_text (GtkEditable *editable, 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); } @@ -3028,23 +3213,19 @@ modest_msg_edit_window_set_draft (ModestMsgEditWindow *window, ModestWindowMgr *mgr = modest_runtime_get_window_mgr (); if (priv->draft_msg != NULL) { - header = tny_msg_get_header (priv->draft_msg); - if (TNY_IS_HEADER (header)) { - modest_window_mgr_unregister_header (mgr, header); - } g_object_unref (priv->draft_msg); } if (draft != NULL) { g_object_ref (draft); header = tny_msg_get_header (draft); - if (TNY_IS_HEADER (header)) - modest_window_mgr_register_header (mgr, header); if (priv->msg_uid) { g_free (priv->msg_uid); priv->msg_uid = NULL; } priv->msg_uid = modest_tny_folder_get_header_unique_id (header); + if (GTK_WIDGET_REALIZED (window)) + modest_window_mgr_register_window (mgr, MODEST_WINDOW (window)); } priv->draft_msg = draft; @@ -3062,7 +3243,7 @@ text_buffer_apply_tag (GtkTextBuffer *buffer, GtkTextTag *tag, 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); } } @@ -3124,3 +3305,33 @@ modest_msg_edit_window_get_child_widget (ModestMsgEditWindow *win, return NULL; } } + +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)); + } +}