X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-text-utils.c;h=cc02fb52b9e9e3d53ced5efb77cab0942eac0631;hp=c37beebea4a01ca69d4b66094cfdeeacdff3f2cc;hb=HEAD;hpb=ee7885c54afe6dfed0c70cd65d6e434c3078b8d3 diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index c37beeb..cc02fb5 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -207,23 +208,26 @@ modest_text_utils_cite (const gchar *text, const gchar *from, time_t sent_date) { - gchar *retval; - gchar *tmp_sig; - + gchar *retval, *tmp; + g_return_val_if_fail (text, NULL); g_return_val_if_fail (content_type, NULL); - - if (!signature) { - tmp_sig = g_strdup (text); - } else { - tmp_sig = g_strconcat (text, "\n", MODEST_TEXT_UTILS_SIGNATURE_MARKER, "\n", signature, NULL); - } if (strcmp (content_type, "text/html") == 0) { - retval = modest_text_utils_convert_to_html_body (tmp_sig, -1, TRUE); - g_free (tmp_sig); + tmp = modest_text_utils_convert_to_html_body (text, -1, TRUE); + if (signature) { + gchar *colored_signature = modest_text_utils_create_colored_signature (signature); + retval = g_strconcat (tmp, colored_signature, NULL); + g_free (colored_signature); + g_free (tmp); + } else { + retval = tmp; + } } else { - retval = tmp_sig; + if (signature) + retval = g_strconcat (text, "\n", MODEST_TEXT_UTILS_SIGNATURE_MARKER, "\n", signature, NULL); + else + retval = g_strdup (text); } return retval; @@ -302,8 +306,7 @@ modest_text_utils_derived_subject (const gchar *subject, gboolean is_reply) gchar *tmp, *subject_dup, *retval, *prefix; const gchar *untranslated_prefix; gint prefix_len, untranslated_prefix_len; - gboolean translated_found = FALSE; - gboolean first_time; + gboolean found = FALSE; if (!subject || subject[0] == '\0') subject = _("mail_va_no_subject"); @@ -318,54 +321,33 @@ modest_text_utils_derived_subject (const gchar *subject, gboolean is_reply) untranslated_prefix = (is_reply) ? "Re:" : "Fw:"; untranslated_prefix_len = 3; - /* We do not want things like "Re: Re: Re:" or "Fw: Fw:" so - delete the previous ones */ - first_time = TRUE; - do { - if (g_str_has_prefix (tmp, prefix)) { - tmp += prefix_len; - tmp = g_strchug (tmp); - /* Do not consider translated prefixes in the - middle of a Re:Re:..Re: like sequence */ - if (G_UNLIKELY (first_time)) - translated_found = TRUE; - } else if (g_str_has_prefix (tmp, untranslated_prefix)) { - tmp += untranslated_prefix_len; - tmp = g_strchug (tmp); - } else { - gchar *prefix_down, *tmp_down; - - /* We need this to properly check the cases of - some clients adding FW: instead of Fw: for - example */ - prefix_down = g_utf8_strdown (prefix, -1); - tmp_down = g_utf8_strdown (tmp, -1); - if (g_str_has_prefix (tmp_down, prefix_down)) { - tmp += prefix_len; - tmp = g_strchug (tmp); - g_free (prefix_down); - g_free (tmp_down); - } else { - g_free (prefix_down); - g_free (tmp_down); - break; - } - } - first_time = FALSE; - } while (tmp); + if (g_str_has_prefix (tmp, prefix) || + g_str_has_prefix (tmp, untranslated_prefix)) { + found = TRUE; + } else { + gchar *prefix_down, *tmp_down, *untranslated_down; - if (!g_strcmp0 (subject, tmp)) { - /* normal case */ - retval = g_strdup_printf ("%s %s", untranslated_prefix, tmp); + prefix_down = g_utf8_strdown (prefix, -1); + untranslated_down = g_utf8_strdown (untranslated_prefix, -1); + tmp_down = g_utf8_strdown (tmp, -1); + if (g_str_has_prefix (tmp_down, prefix_down) || + g_str_has_prefix (tmp_down, untranslated_down) || + (!is_reply && g_str_has_prefix (tmp_down, "fwd:"))) + found = TRUE; + + g_free (prefix_down); + g_free (untranslated_down); + g_free (tmp_down); + } + + if (found) { + /* If the prefix is already present do not touch the subject */ + retval = subject_dup; } else { - if (translated_found) { - /* Found a translated prefix, i.e, "VS:" in Finish */ - retval = g_strdup_printf ("%s %s", prefix, tmp); - } else { - retval = g_strdup_printf ("%s %s", untranslated_prefix, tmp); - } + /* Normal case, add the prefix */ + retval = g_strdup_printf ("%s %s", untranslated_prefix, tmp); + g_free (subject_dup); } - g_free (subject_dup); g_free (prefix); return retval; @@ -901,9 +883,11 @@ unquote_line (GString * l, const gchar *quote_symbol) quote_len = strlen (quote_symbol); while (p[0]) { if (g_str_has_prefix (p, quote_symbol)) { - if (p[quote_len] == ' ') { - p += quote_len; + p+=quote_len; + while (p[0] && p[0] == ' ') { + p++; } + continue; } else { break; } @@ -1162,18 +1146,19 @@ modest_text_utils_quote_html (const gchar *text, { GString *result_string; - result_string = + result_string = g_string_new ( \ "\n" \ "\n" \ - "\n
\n"); + "\n"); if (text || cite || signature) { GString *quoted_text; g_string_append (result_string, "
\n");
 		if (signature) {
-			quote_html_add_to_gstring (result_string, MODEST_TEXT_UTILS_SIGNATURE_MARKER);
-			quote_html_add_to_gstring (result_string, signature);
+			gchar *colored_signature = modest_text_utils_create_colored_signature (signature);
+			g_string_append_printf (result_string, "%s
", colored_signature); + g_free (colored_signature); } quote_html_add_to_gstring (result_string, cite); quoted_text = g_string_new (""); @@ -2323,3 +2308,60 @@ modest_text_utils_no_recipient (GtkTextBuffer *buffer) return retval; } + +gchar * +modest_text_utils_create_colored_signature (const gchar *signature) +{ + gchar *gray_color_markup = NULL, *retval; + GdkColor color; + GtkWidget *widget; + + /* Get color from widgets */ + widget = (GtkWidget *) modest_window_mgr_get_current_top (modest_runtime_get_window_mgr ()); + if (widget && gtk_style_lookup_color (gtk_widget_get_style (widget), "SecondaryTextColor", &color)) + gray_color_markup = modest_text_utils_get_color_string (&color); + + retval = g_strdup_printf ("
\n%s
\n%s
\n
", + (gray_color_markup) ? gray_color_markup : "#babababababa", + MODEST_TEXT_UTILS_SIGNATURE_MARKER, + signature); + + if (gray_color_markup) + g_free (gray_color_markup); + + return retval; +} + +gboolean +modest_text_utils_live_search_find (const gchar *haystack, const gchar *needles) +{ + gchar *haystack_fold; + gchar *needles_fold; + gchar **needle, **current; + gboolean match; + + match = FALSE; + + haystack_fold = g_utf8_casefold (haystack, -1); + needles_fold = g_utf8_casefold (needles, -1); + + needle = g_strsplit (needles_fold, " ", -1); + + current = needle; + while (current && *current != NULL) { + + if (g_strstr_len (haystack_fold, -1, *current) != NULL) { + match = TRUE; + } else { + match = FALSE; + break; + } + current++; + } + + g_strfreev (needle); + g_free (needles_fold); + g_free (haystack_fold); + + return match; +}