X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fhildon2%2Fmodest-msg-edit-window.c;h=55cd46b7ccb4da77a9b59b3cd5a179961a27f861;hb=5f5d20e1973b4928bc70504174de6edd15f59758;hp=cc2b4a99c93b87ef19a5af514c84cf0d00e09019;hpb=4c777ce6473ed97148e961f0f44af25fb6366c68;p=modest diff --git a/src/hildon2/modest-msg-edit-window.c b/src/hildon2/modest-msg-edit-window.c index cc2b4a9..55cd46b 100644 --- a/src/hildon2/modest-msg-edit-window.c +++ b/src/hildon2/modest-msg-edit-window.c @@ -93,7 +93,8 @@ #define DEFAULT_FONT_SCALE 1.5 #define ATTACHMENT_BUTTON_WIDTH 118 #define MAX_FROM_VALUE 36 -#define MAX_BODY_LENGTH 4096 +#define MAX_BODY_LENGTH 128*1024 +#define MAX_BODY_LINES 2048 static gboolean is_wp_text_buffer_started = FALSE; @@ -330,6 +331,7 @@ struct _ModestMsgEditWindowPrivate { GtkWidget *brand_icon; GtkWidget *brand_label; + GtkWidget *brand_container; }; #define MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ @@ -941,6 +943,7 @@ init_window (ModestMsgEditWindow *obj) priv->brand_icon = gtk_image_new (); gtk_misc_set_alignment (GTK_MISC (priv->brand_icon), 0.5, 0.5); priv->brand_label = gtk_label_new (NULL); + hildon_helper_set_logical_font (priv->brand_label, "SmallSystemFont"); gtk_misc_set_alignment (GTK_MISC (priv->brand_label), 0.0, 0.5); gtk_widget_set_no_show_all (priv->brand_icon, TRUE); gtk_widget_set_no_show_all (priv->brand_label, TRUE); @@ -950,8 +953,14 @@ init_window (ModestMsgEditWindow *obj) gtk_box_pack_start (GTK_BOX (from_send_hbox), priv->send_button, FALSE, FALSE, 0); branding_box = gtk_hbox_new (FALSE, MODEST_MARGIN_DEFAULT); + gtk_widget_show (branding_box); + gtk_box_pack_start (GTK_BOX (branding_box), priv->brand_label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (branding_box), priv->brand_icon, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (branding_box), priv->brand_label, TRUE, TRUE, 0); + + priv->brand_container = gtk_alignment_new (0.0, 0.5, 0.0, 1.0); + gtk_alignment_set_padding (GTK_ALIGNMENT (priv->brand_container), 0, 0, MODEST_MARGIN_DOUBLE, 0); + gtk_container_add (GTK_CONTAINER (priv->brand_container), branding_box); + gtk_widget_set_no_show_all (priv->brand_container, TRUE); gtk_box_pack_start (GTK_BOX (priv->header_box), from_send_hbox, FALSE, FALSE, 0); @@ -960,13 +969,13 @@ init_window (ModestMsgEditWindow *obj) gtk_box_pack_start (GTK_BOX (priv->header_box), priv->bcc_caption, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (priv->header_box), subject_caption, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (priv->header_box), priv->attachments_caption, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (priv->header_box), branding_box, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (priv->header_box), priv->brand_container, FALSE, FALSE, 0); gtk_widget_set_no_show_all (priv->attachments_caption, TRUE); init_wp_text_view_style (); priv->msg_body = modest_wp_text_view_new (); - + hildon_gtk_widget_set_theme_size (priv->msg_body, MODEST_EDITABLE_SIZE); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->msg_body), GTK_WRAP_WORD_CHAR); priv->text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->msg_body)); @@ -1098,8 +1107,6 @@ modest_msg_edit_window_finalize (GObject *obj) g_free (priv->last_search); g_free (priv->references); g_free (priv->in_reply_to); - g_object_unref (priv->faces_model); - g_object_unref (priv->sizes_model); g_object_unref (priv->attachments); g_object_unref (priv->images); @@ -1242,9 +1249,9 @@ get_related_images (ModestMsgEditWindow *self, TnyMsg *msg) content_type = tny_mime_part_get_content_type (TNY_MIME_PART (msg)); - if (content_type && !g_strcasecmp (content_type, "multipart/related")) { + if (content_type && !g_ascii_strcasecmp (content_type, "multipart/related")) { parent = g_object_ref (msg); - } else if (content_type && !g_strcasecmp (content_type, "multipart/mixed")) { + } else if (content_type && !g_ascii_strcasecmp (content_type, "multipart/mixed")) { TnyList *parts = TNY_LIST (tny_simple_list_new ()); TnyIterator *iter; @@ -1254,7 +1261,7 @@ get_related_images (ModestMsgEditWindow *self, TnyMsg *msg) 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")) { + if (content_type && !g_ascii_strcasecmp (content_type, "multipart/related")) { parent = part; break; } else { @@ -2527,14 +2534,19 @@ modest_msg_edit_window_offer_attach_file (ModestMsgEditWindow *window) 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")); - conf_folder = modest_conf_get_string (modest_runtime_get_conf (), MODEST_CONF_LATEST_ATTACH_FILE_PATH, NULL); + conf_folder = modest_conf_get_string (modest_runtime_get_conf (), + MODEST_CONF_LATEST_ATTACH_FILE_PATH, NULL); if (conf_folder && conf_folder[0] != '\0') { gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), conf_folder); } else { gchar *docs_folder; - /* Set the default folder to images folder */ - docs_folder = g_build_filename (g_getenv (MODEST_MAEMO_UTILS_MYDOCS_ENV), - ".documents", NULL); + /* Set the default folder to documents folder */ + docs_folder = (gchar *) g_strdup(g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS)); + if (!docs_folder) { + /* fallback */ + docs_folder = g_build_filename (g_getenv (MODEST_MAEMO_UTILS_MYDOCS_ENV), + ".documents", NULL); + } gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), docs_folder); g_free (docs_folder); } @@ -3416,7 +3428,8 @@ gboolean modest_msg_edit_window_check_names (ModestMsgEditWindow *window, gboolean add_to_addressbook) { ModestMsgEditWindowPrivate *priv = NULL; - + GSList *address_list = NULL; + g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), FALSE); priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); @@ -3429,23 +3442,28 @@ modest_msg_edit_window_check_names (ModestMsgEditWindow *window, gboolean add_to return FALSE; } + /* Check names */ g_object_ref (window); - if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->to_field), add_to_addressbook)) { + if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->to_field), &address_list)) { modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->to_field)); g_object_unref (window); return FALSE; } - if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->cc_field), add_to_addressbook)) { + if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->cc_field), &address_list)) { modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->cc_field)); g_object_unref (window); return FALSE; } - if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->bcc_field), add_to_addressbook)) { + if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->bcc_field), &address_list)) { modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->bcc_field)); g_object_unref (window); return FALSE; } + /* Add contacts to address book */ + if (address_list) + modest_address_book_add_address_list (address_list); + if (!modest_recpt_editor_has_focus (MODEST_RECPT_EDITOR (priv->cc_field)) && !modest_recpt_editor_has_focus (MODEST_RECPT_EDITOR (priv->bcc_field))) modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->to_field)); @@ -3564,17 +3582,34 @@ body_insert_text (GtkTextBuffer *buffer, GtkTextIter end_iter; gint offset; glong utf8_len; + gint line; + gchar *text_offset; + gint text_lines; ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (buffer), &end_iter); offset = gtk_text_iter_get_offset (&end_iter); + line = gtk_text_iter_get_line (&end_iter); + + text_offset = text; + text_lines = 0; + while (text_offset < text + len) { + if (*text_offset == '\n') + text_lines++; + if (text_lines + line >= MAX_BODY_LINES) { + len = text_offset - text; + break; + } + text_offset++; + } + utf8_len = g_utf8_strlen (text, len); - if (offset + utf8_len > MAX_BODY_LENGTH) { + if (line > MAX_BODY_LINES || offset + utf8_len > MAX_BODY_LENGTH) { g_signal_stop_emission_by_name (G_OBJECT (buffer), "insert-text"); - if (offset < MAX_BODY_LENGTH) + if (line <= MAX_BODY_LINES && offset < MAX_BODY_LENGTH) { gchar *result; gchar *utf8_end; @@ -3591,7 +3626,7 @@ body_insert_text (GtkTextBuffer *buffer, } } - if (offset + utf8_len > MAX_BODY_LENGTH) { + if (line > MAX_BODY_LINES || offset + utf8_len > MAX_BODY_LENGTH) { if (priv->max_chars_banner == NULL) { priv->max_chars_banner = hildon_banner_show_information (GTK_WIDGET (window), NULL, _CS("ckdg_ib_maximum_characters_reached")); @@ -3958,17 +3993,16 @@ on_account_removed (TnyAccountStore *account_store, } } -static void update_signature (ModestMsgEditWindow *self, - const gchar *old_account, - const gchar *new_account) +static void +update_signature (ModestMsgEditWindow *self, + const gchar *old_account, + const gchar *new_account) { ModestMsgEditWindowPrivate *priv; gboolean has_old_signature, has_new_signature; GtkTextIter iter; - GtkTextIter match_start, match_end; ModestAccountMgr *mgr; gchar *signature; - gchar *full_signature; priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); @@ -3981,15 +4015,21 @@ static void update_signature (ModestMsgEditWindow *self, if (old_account) { signature = modest_account_mgr_get_signature_from_recipient (mgr, old_account, &has_old_signature); if (has_old_signature) { - full_signature = g_strconcat ("\n--\n", signature, NULL); - if (gtk_text_iter_forward_search (&iter, full_signature, 0, &match_start, &match_end, NULL)) { + GtkTextIter match_start, match_end; + /* We cannot use + MODEST_TEXT_UTILS_SIGNATURE_MARKER as it + seems that the search has some problems + with the blank space at the end */ + if (gtk_text_iter_forward_search (&iter, "--", + GTK_TEXT_SEARCH_TEXT_ONLY, + &match_start, NULL, NULL)) { + gtk_text_buffer_get_end_iter (priv->text_buffer ,&match_end); gtk_text_buffer_delete (priv->text_buffer, &match_start, &match_end); iter = match_start; } else if (gtk_text_iter_forward_search (&iter, _("mcen_ia_editor_original_message"), 0, &match_start, &match_end, NULL)) { iter = match_start; } - g_free (full_signature); } g_free (signature); } @@ -3997,7 +4037,8 @@ static void update_signature (ModestMsgEditWindow *self, priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); signature = modest_account_mgr_get_signature_from_recipient (mgr, new_account, &has_new_signature); if (has_new_signature) { - full_signature = g_strconcat ("\n--\n", signature, NULL); + gchar *full_signature = g_strconcat (MODEST_TEXT_UTILS_SIGNATURE_MARKER, "\n", + signature, NULL); gtk_text_buffer_insert (priv->text_buffer, &iter, full_signature, -1); g_free (full_signature); } @@ -4012,6 +4053,7 @@ static void update_branding (ModestMsgEditWindow *self, ModestAccountMgr *mgr; const GdkPixbuf *new_icon = NULL; gchar *new_label = NULL; + gboolean show = FALSE; priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); @@ -4021,6 +4063,7 @@ static void update_branding (ModestMsgEditWindow *self, if (new_icon) { gtk_image_set_from_pixbuf (GTK_IMAGE (priv->brand_icon), (GdkPixbuf *) new_icon); gtk_widget_show (priv->brand_icon); + show = TRUE; } else { gtk_widget_hide (priv->brand_icon); } @@ -4028,9 +4071,15 @@ static void update_branding (ModestMsgEditWindow *self, gtk_label_set_text (GTK_LABEL (priv->brand_label), new_label); gtk_widget_show (priv->brand_label); g_free (new_label); + show = TRUE; } else { gtk_widget_hide (priv->brand_label); } + + if (show) + gtk_widget_show (priv->brand_container); + else + gtk_widget_hide (priv->brand_container); } static void @@ -4043,8 +4092,18 @@ from_field_changed (HildonPickerButton *button, priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); old_account = priv->last_from_account; - priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); - new_account = priv->last_from_account; + new_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); + + if (!new_account) { + g_warning ("%s, could not get the new account", __FUNCTION__); + return; + } + + /* If the From is the same do nothing */ + if (old_account && new_account && !strcmp (old_account, new_account)) + return; + + priv->last_from_account = new_account; update_signature (self, old_account, new_account); update_branding (self, new_account);