X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-text-utils.c;h=93e51ee9d2f58979807ebf80656ae3f79d77ffda;hb=3a00a6ff63e2fcd2feb005314753c6d4f32cf105;hp=5a34f6b03ea6b78485fffc22b42cb62d568bbf40;hpb=bb3ba387cd69e21f69bab554bca5aada0e590fe3;p=modest diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 5a34f6b..93e51ee 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -109,14 +109,14 @@ struct _url_match_t { /* note: match MARK_AMP_URI_STR as well, because after txt->html, a '&' will look like $(MARK_AMP_URI_STR)"amp;" */ #define MAIL_VIEWER_URL_MATCH_PATTERNS { \ - { "(file|rtsp|http|ftp|https|mms|mmsh|rtsp|rdp|lastfm)://[-a-z0-9_$.+!*(),;:@%=?/~#" MARK_AMP_URI_STR \ + { "(feed:|)(file|rtsp|http|ftp|https|mms|mmsh|webcal|feed|rtsp|rdp|lastfm|sip)://[-a-z0-9_$.+!*(),;:@%=?/~#" MARK_AMP_URI_STR \ "]+[-a-z0-9_$%" MARK_AMP_URI_STR "=?/~#]", \ NULL, NULL },\ { "www\\.[-a-z0-9_$.+!*(),;:@%=?/~#" MARK_AMP_URI_STR "]+[-a-z0-9_$%" MARK_AMP_URI_STR "=?/~#]",\ NULL, "http://" }, \ { "ftp\\.[-a-z0-9_$.+!*(),;:@%=?/~#" MARK_AMP_URI_STR "]+[-a-z0-9_$%" MARK_AMP_URI_STR "=?/~#]",\ NULL, "ftp://" },\ - { "(jabberto|voipto|sipto|sip|chatto|xmpp):[-_a-z@0-9.+]+", \ + { "(jabberto|voipto|sipto|sip|chatto|skype|xmpp):[-_a-z@0-9.+]+", \ NULL, NULL}, \ { "mailto:[-_a-z0-9.\\+]+@[-_a-z0-9.]+", \ NULL, NULL},\ @@ -213,14 +213,17 @@ modest_text_utils_cite (const gchar *text, g_return_val_if_fail (text, NULL); g_return_val_if_fail (content_type, NULL); - if (!signature) - retval = g_strdup (""); - else if (strcmp(content_type, "text/html") == 0) { - tmp_sig = g_strconcat ("\n", SIGNATURE_MARKER,"\n", signature, NULL); - retval = modest_text_utils_convert_to_html_body(tmp_sig, -1, TRUE); + if (!signature) { + tmp_sig = g_strdup (text); + } else { + tmp_sig = g_strconcat (text, "\n", 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); } else { - retval = g_strconcat (text, "\n", SIGNATURE_MARKER, "\n", signature, NULL); + retval = tmp_sig; } return retval; @@ -283,6 +286,8 @@ modest_text_utils_strftime(char *s, gsize max, const char *fmt, time_t timet) garbage in the s variable */ if (s) s[0] = '\0'; + else + return 0; /* does not work on old maemo glib: * g_date_set_time_t (&date, timet); @@ -1013,7 +1018,7 @@ modest_text_utils_quote_html (const gchar *text, } quote_html_add_to_gstring (result_string, cite); quoted_text = g_string_new (""); - quoted_text = modest_text_utils_quote_body (quoted_text, text, ">", limit); + quoted_text = modest_text_utils_quote_body (quoted_text, (text) ? text : "", ">", limit); quote_html_add_to_gstring (result_string, quoted_text->str); g_string_free (quoted_text, TRUE); if (attachments) { @@ -1037,6 +1042,7 @@ cmp_offsets_reverse (const url_match_t *match1, const url_match_t *match2) static gint url_matches_block = 0; static url_match_pattern_t patterns[] = MAIL_VIEWER_URL_MATCH_PATTERNS; +static GMutex *url_patterns_mutex = NULL; static gboolean @@ -1071,17 +1077,25 @@ free_patterns () void modest_text_utils_hyperlinkify_begin (void) { + + if (url_patterns_mutex == NULL) { + url_patterns_mutex = g_mutex_new (); + } + g_mutex_lock (url_patterns_mutex); if (url_matches_block == 0) compile_patterns (); url_matches_block ++; + g_mutex_unlock (url_patterns_mutex); } void modest_text_utils_hyperlinkify_end (void) { + g_mutex_lock (url_patterns_mutex); url_matches_block--; if (url_matches_block <= 0) free_patterns (); + g_mutex_unlock (url_patterns_mutex); } @@ -1247,14 +1261,16 @@ modest_text_utils_get_display_address (gchar *address) for (i = 0; address[i]; ++i) { if (address[i] == '<') { - if (G_UNLIKELY(i == 0)) - return; /* there's nothing else, leave it */ - else { + if (G_UNLIKELY(i == 0)) { + break; /* there's nothing else, leave it */ + }else { address[i] = '\0'; /* terminate the string here */ - return; + break; } } } + + g_strchomp (address); } @@ -1655,18 +1671,20 @@ modest_text_utils_get_display_size (guint64 size) const guint MB=1024 * KB; const guint GB=1024 * MB; + if (size == 0) + return g_strdup_printf (_FM("sfil_li_size_kb"), (int) 0); if (0 <= size && size < KB) - return g_strdup_printf (_FM("sfil_li_size_kb"), 1); + return g_strdup_printf (_FM("sfil_li_size_1kb_99kb"), (int) 1); else if (KB <= size && size < 100 * KB) - return g_strdup_printf (_FM("sfil_li_size_1kb_99kb"), size / KB); + return g_strdup_printf (_FM("sfil_li_size_1kb_99kb"), (int) size / KB); else if (100*KB <= size && size < MB) return g_strdup_printf (_FM("sfil_li_size_100kb_1mb"), (float) size / MB); else if (MB <= size && size < 10*MB) return g_strdup_printf (_FM("sfil_li_size_1mb_10mb"), (float) size / MB); else if (10*MB <= size && size < GB) - return g_strdup_printf (_FM("sfil_li_size_10mb_1gb"), size / MB); + return g_strdup_printf (_FM("sfil_li_size_10mb_1gb"), (int) size / MB); else - return g_strdup_printf (_FM("sfil_li_size_1gb_or_greater"), (float) size / GB); + return g_strdup_printf (_FM("sfil_li_size_1gb_or_greater"), (float) size / GB); } static gchar * @@ -1683,11 +1701,11 @@ get_email_from_address (const gchar * address) return g_strndup (left_limit + 1, (right_limit - left_limit) - 1); } -gchar * +gchar * modest_text_utils_get_color_string (GdkColor *color) { g_return_val_if_fail (color, NULL); - + return g_strdup_printf ("#%x%x%x%x%x%x%x%x%x%x%x%x", (color->red >> 12) & 0xf, (color->red >> 8) & 0xf, (color->red >> 4) & 0xf, (color->red) & 0xf,