Build diablo build and fix second line font size and color in maemo and gnome
[modest] / src / maemo / modest-msg-edit-window.c
index 5a4180c..9fd2947 100644 (file)
@@ -105,11 +105,6 @@ static void  text_buffer_can_redo (GtkTextBuffer *buffer, gboolean can_redo, Mod
 static void  text_buffer_apply_tag (GtkTextBuffer *buffer, GtkTextTag *tag, 
                                    GtkTextIter *start, GtkTextIter *end,
                                    gpointer userdata);
-static void  text_buffer_insert_text (GtkTextBuffer *buffer,
-                                     GtkTextIter *location,
-                                     gchar *text,
-                                     gint len,
-                                     ModestMsgEditWindow *window);
 static void  text_buffer_delete_images_by_id (GtkTextBuffer *buffer, const gchar * image_id);
 static void  subject_field_changed (GtkEditable *editable, ModestMsgEditWindow *window);
 static void  subject_field_insert_text (GtkEditable *editable, 
@@ -178,8 +173,8 @@ static void text_buffer_mark_set (GtkTextBuffer *buffer,
                                  GtkTextIter *iter,
                                  GtkTextMark *mark,
                                  ModestMsgEditWindow *userdata);
-void vadj_changed (GtkAdjustment *adj, 
-                  ModestMsgEditWindow *window);
+static void vadj_changed (GtkAdjustment *adj, 
+                         ModestMsgEditWindow *window);
 
 static void DEBUG_BUFFER (WPTextBuffer *buffer)
 {
@@ -293,6 +288,8 @@ struct _ModestMsgEditWindowPrivate {
        TnyMsg      *draft_msg;
        TnyMsg      *outbox_msg;
        gchar       *msg_uid;
+       gchar       *references;
+       gchar       *in_reply_to;
 
        gboolean    sent;
 };
@@ -430,6 +427,8 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
        priv->draft_msg = NULL;
        priv->outbox_msg = NULL;
        priv->msg_uid = NULL;
+       priv->references = NULL;
+       priv->in_reply_to = NULL;
 
        priv->can_undo = FALSE;
        priv->can_redo = FALSE;
@@ -480,7 +479,7 @@ get_transports (void)
                gchar *from_string  = NULL;
                if (account_name) {
                        from_string = modest_account_mgr_get_from_string (account_mgr,
-                                                                         account_name);
+                                                                         account_name, NULL);
                }
                
                if (from_string && account_name) {
@@ -632,8 +631,9 @@ copy_clipboard_check (GtkTextView *text_view,
        }
 }
 
-void vadj_changed (GtkAdjustment *adj,
-                  ModestMsgEditWindow *window)
+static void 
+vadj_changed (GtkAdjustment *adj,
+             ModestMsgEditWindow *window)
 {
        ModestMsgEditWindowPrivate *priv;
 
@@ -646,6 +646,14 @@ void vadj_changed (GtkAdjustment *adj,
 }
 
 static void
+attachment_deleted (ModestAttachmentsView *attachments_view,
+                   gpointer user_data)
+{
+       modest_msg_edit_window_remove_attachments (MODEST_MSG_EDIT_WINDOW (user_data),
+                                                  NULL);
+}
+
+static void
 connect_signals (ModestMsgEditWindow *obj)
 {
        ModestMsgEditWindowPrivate *priv;
@@ -662,8 +670,6 @@ connect_signals (ModestMsgEditWindow *obj)
                           G_CALLBACK (body_changed), obj);
        g_signal_connect (G_OBJECT (priv->text_buffer), "modified-changed",
                           G_CALLBACK (body_changed), obj);
-       g_signal_connect (G_OBJECT (priv->text_buffer), "insert-text", 
-                         G_CALLBACK (text_buffer_insert_text), obj);
        g_signal_connect (G_OBJECT (obj), "window-state-event",
                          G_CALLBACK (modest_msg_edit_window_window_state_event),
                          NULL);
@@ -715,7 +721,7 @@ connect_signals (ModestMsgEditWindow *obj)
 
        g_signal_connect (G_OBJECT (priv->msg_body), "cut-clipboard", G_CALLBACK (cut_clipboard_check), NULL);
        g_signal_connect (G_OBJECT (priv->msg_body), "copy-clipboard", G_CALLBACK (copy_clipboard_check), NULL);
-
+       g_signal_connect (G_OBJECT (priv->attachments_view), "delete", G_CALLBACK (attachment_deleted), obj);
 }
 
 static void
@@ -848,9 +854,9 @@ init_window (ModestMsgEditWindow *obj)
        g_object_set (priv->text_buffer, "font_scale", DEFAULT_FONT_SCALE, NULL);
        wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
 #if (GTK_MINOR_VERSION >= 10)
-       gtk_text_buffer_register_serialize_tagset(GTK_TEXT_BUFFER(priv->text_buffer), "wp-text-buffer");
+       gtk_text_buffer_register_serialize_tagset(GTK_TEXT_BUFFER(priv->text_buffer), NULL);
        deserialize_type = gtk_text_buffer_register_deserialize_tagset(GTK_TEXT_BUFFER(priv->text_buffer), 
-                                                                      "wp-text-buffer");
+                                                                      NULL);
        gtk_text_buffer_deserialize_set_can_create_tags (GTK_TEXT_BUFFER (priv->text_buffer), 
                                                         deserialize_type, TRUE);
 #endif
@@ -961,6 +967,8 @@ modest_msg_edit_window_finalize (GObject *obj)
        if (priv->original_account_name)
                g_free (priv->original_account_name);
        g_free (priv->msg_uid);
+       g_free (priv->references);
+       g_free (priv->in_reply_to);
        g_free (priv->last_search);
        g_slist_free (priv->font_items_group);
        g_slist_free (priv->size_items_group);
@@ -998,6 +1006,8 @@ pixbuf_from_stream (TnyStream *stream, const gchar *mime_type, guint64 *stream_s
                readed = tny_stream_read (TNY_STREAM (stream), (char *) read_buffer, 128);
                size += readed;
                if (!gdk_pixbuf_loader_write (loader, read_buffer, readed, &error)) {
+                       if (error)
+                               g_free (error);
                        break;
                }
        }
@@ -1185,6 +1195,7 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
                gtk_entry_set_text (GTK_ENTRY(priv->subject_field), subject);
        modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW(self),
                                                   priority_flags);
+       modest_tny_msg_get_references (TNY_MSG (msg), NULL, &(priv->references), &(priv->in_reply_to));
 
        update_window_title (self);
 
@@ -1219,17 +1230,9 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
 
        if (preserve_is_rich && !is_html) {
                wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
-               /* We must do this here in order to reset the undo
-                  list, because otherwise this action could be
-                  reverted */
-               wp_text_buffer_reset_buffer (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
        /* Get the default format required from configuration */
-       } else if (!modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_PREFER_FORMATTED_TEXT, NULL)) {
+       } else if (!preserve_is_rich && !modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_PREFER_FORMATTED_TEXT, NULL)) {
                wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
-               /* We must do this here in order to reset the undo
-                  list, because otherwise this action could be
-                  reverted */
-               wp_text_buffer_reset_buffer (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
        }
 
        /* Set the default focus depending on having already a To: field or not */
@@ -1474,7 +1477,10 @@ modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window)
 
 
 ModestWindow*
-modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean preserve_is_rich)
+modest_msg_edit_window_new (TnyMsg *msg, 
+                           const gchar *account_name, 
+                           const gchar *mailbox, /* ignored */
+                           gboolean preserve_is_rich)
 {
        GObject *obj;
        ModestWindowPrivate *parent_priv;
@@ -1594,6 +1600,8 @@ get_formatted_data (ModestMsgEditWindow *edit_window)
 
        wp_text_buffer_save_document (WP_TEXT_BUFFER(priv->text_buffer), get_formatted_data_cb, &string_buffer);
 
+       modest_text_utils_hyperlinkify (string_buffer);
+
        gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
 
        return g_string_free (string_buffer, FALSE);
@@ -1619,12 +1627,14 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window)
        /* don't free these (except from) */
        data = g_slice_new0 (MsgData);
        data->from    =  modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
-                                                            account_name);
+                                                            account_name, NULL);
        data->account_name = g_strdup (account_name);
        data->to      =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->to_field)));
        data->cc      =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->cc_field)));
        data->bcc     =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->bcc_field)));
        data->subject =  g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->subject_field)));
+       data->references = g_strdup (priv->references);
+       data->in_reply_to = g_strdup (priv->in_reply_to);
        if (priv->draft_msg) {
                data->draft_msg = g_object_ref (priv->draft_msg);
        } else if (priv->outbox_msg) {
@@ -1724,6 +1734,8 @@ modest_msg_edit_window_free_msg_data (ModestMsgEditWindow *edit_window,
        g_free (data->plain_body);
        g_free (data->html_body);
        g_free (data->account_name);
+       g_free (data->in_reply_to);
+       g_free (data->references);
        
        if (data->draft_msg != NULL) {
                g_object_unref (data->draft_msg);
@@ -1897,8 +1909,12 @@ modest_msg_edit_window_set_format_state (ModestMsgEditWindow *self,
        
        text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), self);
        
+       g_free (buffer_format);
        g_free (current_format);
 
+       /* Check dimming rules */
+       modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (self));
+       modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
 }
 
 static void
@@ -2160,6 +2176,10 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
 
        modest_maemo_utils_setup_images_filechooser (GTK_FILE_CHOOSER (dialog));
 
+       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), 
+                                    GTK_WINDOW (dialog),
+                                    GTK_WINDOW (window));
+
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        switch (response) {
        case GTK_RESPONSE_OK:
@@ -2210,7 +2230,8 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
 
                        if (stream == NULL) {
 
-                               modest_platform_information_banner (NULL, NULL, dgettext("hildon-fm", "sfil_ib_opening_not_allowed"));
+                               modest_platform_information_banner (NULL, NULL, 
+                                                                   _FM("sfil_ib_opening_not_allowed"));
                                
                                g_object_unref (mime_part);
                                gnome_vfs_file_info_unref (info);
@@ -2266,13 +2287,13 @@ modest_msg_edit_window_offer_attach_file (ModestMsgEditWindow *window)
                
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
 
-       if (modest_platform_check_memory_low (MODEST_WINDOW(window)))
+       if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
                return;
        
        dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN);
        gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ti_select_attachment_title"));
        gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
-       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
+       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (window));
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        switch (response) {
@@ -2323,7 +2344,6 @@ modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window,
        ModestMsgEditWindowPrivate *priv;
        GnomeVFSResult result;
        GnomeVFSFileSize size = 0;
-
        g_return_val_if_fail (window, 0);
        g_return_val_if_fail (uri, 0);
                
@@ -2366,8 +2386,8 @@ modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window,
                    info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) {
                        size = info->size;
                        if (size > allowed_size) {
-                               g_warning ("%s: attachment too big", __FUNCTION__);
-                               modest_platform_information_banner (NULL, NULL, dgettext("hildon-fm", "sfil_ib_opening_not_allowed"));
+                               modest_platform_information_banner (NULL, NULL, 
+                                                                   _FM("sfil_ib_opening_not_allowed"));
                                return 0;
                        }
                } else
@@ -2377,7 +2397,7 @@ modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window,
                
                if (stream == NULL) {
 
-                       modest_platform_information_banner (NULL, NULL, dgettext("hildon-fm", "sfil_ib_opening_not_allowed"));
+                       modest_platform_information_banner (NULL, NULL, _FM("sfil_ib_opening_not_allowed"));
 
                        g_object_unref (mime_part);
                        gnome_vfs_file_info_unref (info);
@@ -2430,7 +2450,6 @@ modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window,
        if (tny_list_get_length (att_list) == 0) {
                hildon_banner_show_information (NULL, NULL, _("TODO: no attachments selected to remove"));
        } else {
-               GtkWidget *confirmation_dialog = NULL;
                gboolean dialog_response;
                gchar *message = NULL;
                gchar *filename = NULL;
@@ -2459,11 +2478,11 @@ modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window,
                message = g_strdup_printf (ngettext("emev_nc_delete_attachment", "emev_nc_delete_attachments",
                                                    tny_list_get_length (att_list)), filename);
                g_free (filename);
-               confirmation_dialog = hildon_note_new_confirmation (GTK_WINDOW (window), message);
+
+               dialog_response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window), message);
                g_free (message);
-               dialog_response = (gtk_dialog_run (GTK_DIALOG (confirmation_dialog))==GTK_RESPONSE_OK);
-               gtk_widget_destroy (confirmation_dialog);
-               if (!dialog_response) {
+
+               if (dialog_response != GTK_RESPONSE_OK) {
                        g_object_unref (att_list);
                        return;
                }
@@ -2667,10 +2686,9 @@ modest_msg_edit_window_open_addressbook (ModestMsgEditWindow *window,
        /* we check for low-mem; in that case, show a warning, and don't allow
         * for the addressbook
         */
-       if (modest_platform_check_memory_low (MODEST_WINDOW(window)))
+       if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
                return;
 
-
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
 
        if (editor == NULL) {
@@ -2826,6 +2844,7 @@ modest_msg_edit_window_set_file_format (ModestMsgEditWindow *window,
                        break;
                }
                modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
+               modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
                text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), window);
        }
 }
@@ -2853,7 +2872,7 @@ modest_msg_edit_window_select_font (ModestMsgEditWindow *window)
        
        dialog = hildon_font_selection_dialog_new (GTK_WINDOW (window), NULL);
        modest_window_mgr_set_modal (modest_runtime_get_window_mgr(),
-                                    GTK_WINDOW(dialog));
+                                    GTK_WINDOW(dialog), GTK_WINDOW (window));
 
        /* First we get the currently selected font information */
        wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), &oldfmt, TRUE);
@@ -2889,6 +2908,8 @@ modest_msg_edit_window_select_font (ModestMsgEditWindow *window)
                      "family-set", !oldfmt.cs.font,
                      NULL);
 
+       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), 
+                                    GTK_WINDOW (dialog), GTK_WINDOW (window));
        gtk_widget_show_all (dialog);
        priv->font_dialog = dialog;
        response = gtk_dialog_run (GTK_DIALOG (dialog));
@@ -2978,7 +2999,6 @@ modest_msg_edit_window_undo (ModestMsgEditWindow *window)
 
        modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
        modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
-
 }
 
 void
@@ -3339,55 +3359,12 @@ subject_field_insert_text (GtkEditable *editable,
 
        if (result_len + old_length > 1000) {
                hildon_banner_show_information (GTK_WIDGET (window), NULL, 
-                                               dgettext("hildon-common-strings",
-                                                        "ckdg_ib_maximum_characters_reached"));
+                                               _CS("ckdg_ib_maximum_characters_reached"));
        }
        
        g_string_free (result, TRUE);
 }
 
-static void  
-text_buffer_insert_text (GtkTextBuffer *buffer, 
-                        GtkTextIter *iter,
-                        gchar *new_text,
-                        gint new_text_length,
-                        ModestMsgEditWindow *window)
-{
-       GString *result = g_string_new ("");
-       gchar *current;
-       gint result_len = 0;
-       gboolean changed = FALSE;
-
-       for (current = new_text; current != NULL && *current != '\0'; current = g_utf8_next_char (current)) {
-               gunichar c = g_utf8_get_char_validated (current, 8);
-               /* Invalid unichar, stop */
-               if (c == -1)
-                       break;
-               /* a bullet */
-               switch (c) {
-               case 0x2022:
-                       result = g_string_append_c (result, ' ');
-                       changed = TRUE;
-                       break;
-               default:
-                       result = g_string_append_unichar (result, c);
-               }
-               result_len++;
-       }
-
-       if (changed) {
-               g_signal_stop_emission_by_name (G_OBJECT (buffer), "insert-text");
-               g_signal_handlers_block_by_func(G_OBJECT(buffer), G_CALLBACK(text_buffer_insert_text), window);
-               g_signal_emit_by_name (buffer, "insert-text", 
-                                      (gpointer) iter,
-                                      (gpointer) result->str, (gpointer) result->len,
-                                      (gpointer) window);
-               g_signal_handlers_unblock_by_func(G_OBJECT(buffer), G_CALLBACK(text_buffer_insert_text), window);
-       }
-
-       g_string_free (result, TRUE);
-}
-
 void
 modest_msg_edit_window_toggle_find_toolbar (ModestMsgEditWindow *window,
                                            gboolean show)
@@ -3490,7 +3467,8 @@ modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
                g_free (priv->last_search);
                priv->last_search = NULL;
                /* Information banner about empty search */
-               hildon_banner_show_information (NULL, NULL, dgettext ("hildon-common-strings", "ecdg_ib_find_rep_enter_text"));
+               hildon_banner_show_information (NULL, NULL, 
+                                               _CS ("ecdg_ib_find_rep_enter_text"));
                return;
        }
 
@@ -3506,14 +3484,16 @@ modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
                result = gtk_text_iter_forward_search_insensitive (&selection_end, current_search, 
                                                                   &match_start, &match_end);
                if (!result)
-                       hildon_banner_show_information (NULL, NULL, dgettext ("hildon-libs", "ckct_ib_find_search_complete"));
+                       hildon_banner_show_information (NULL, NULL, 
+                                                       _HL ("ckct_ib_find_search_complete"));
        } else {
                GtkTextIter buffer_start;
                gtk_text_buffer_get_start_iter (priv->text_buffer, &buffer_start);
                result = gtk_text_iter_forward_search_insensitive (&buffer_start, current_search, 
                                                                   &match_start, &match_end);
                if (!result)
-                       hildon_banner_show_information (NULL, NULL, dgettext ("hildon-libs", "ckct_ib_find_no_matches"));
+                       hildon_banner_show_information (NULL, NULL, 
+                                                       _HL ("ckct_ib_find_no_matches"));
        }
 
        /* Mark as selected the string found in search */
@@ -3586,7 +3566,7 @@ modest_msg_edit_window_set_draft (ModestMsgEditWindow *window,
                }
                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));
+                       modest_window_mgr_register_window (mgr, MODEST_WINDOW (window), NULL);
        }
 
        priv->draft_msg = draft;
@@ -3601,7 +3581,7 @@ text_buffer_apply_tag (GtkTextBuffer *buffer, GtkTextTag *tag,
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (userdata);
        gchar *tag_name;
 
-       if (tag == NULL+13) return;
+       if (tag == NULL) 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_images (window, priv->images);
@@ -3701,7 +3681,8 @@ on_zoom_minus_plus_not_implemented (ModestWindow *window)
 {
        g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), FALSE);
 
-       hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here"));
+       hildon_banner_show_information (NULL, NULL, 
+                                       _CS("ckct_ib_cannot_zoom_here"));
        return FALSE;
 
 }