/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2014 Hiroyuki Yamamoto and the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
-#if HAVE_LIBCOMPFACE
-# include <compface.h>
-#endif
-
-#if HAVE_LIBCOMPFACE
-#define XPM_XFACE_HEIGHT (HEIGHT + 3) /* 3 = 1 header + 2 colors */
-#endif
#include "main.h"
#include "summaryview.h"
#include "tags.h"
#include "manage_window.h"
#include "folder_item_prefs.h"
+#include "hooks.h"
+#include "avatars.h"
static GdkColor quote_colors[3] = {
{(gulong)0, (gushort)0, (gushort)0, (gushort)0},
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
GtkTextIter iter;
- gint mybuf_len = strlen(linebuf);
- gchar *mybuf = g_strndup(linebuf, mybuf_len);
+ gchar *mybuf = g_strdup(linebuf);
/* parse table - in order of priority */
struct table {
/* token search function */
gchar *(*search) (const gchar *haystack,
- gint haystack_len,
const gchar *needle);
/* part parsing function */
gboolean (*parse) (const gchar *start,
};
static struct table parser[] = {
- {"http://", strncasestr, get_uri_part, make_uri_string},
- {"https://", strncasestr, get_uri_part, make_uri_string},
- {"ftp://", strncasestr, get_uri_part, make_uri_string},
- {"sftp://", strncasestr, get_uri_part, make_uri_string},
- {"gopher://",strncasestr, get_uri_part, make_uri_string},
- {"www.", strncasestr, get_uri_part, make_http_string},
- {"mailto:", strncasestr, get_uri_part, make_uri_string},
- {"@", strncasestr, get_email_part, make_email_string}
+ {"http://", strcasestr, get_uri_part, make_uri_string},
+ {"https://", strcasestr, get_uri_part, make_uri_string},
+ {"ftp://", strcasestr, get_uri_part, make_uri_string},
+ {"sftp://", strcasestr, get_uri_part, make_uri_string},
+ {"gopher://",strcasestr, get_uri_part, make_uri_string},
+ {"www.", strcasestr, get_uri_part, make_http_string},
+ {"mailto:", strcasestr, get_uri_part, make_uri_string},
+ {"@", strcasestr, get_email_part, make_email_string}
};
const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
if (!g_utf8_validate(linebuf, -1, NULL)) {
g_free(mybuf);
- mybuf = g_malloc(mybuf_len*2 +1);
- conv_localetodisp(mybuf, mybuf_len*2 +1, linebuf);
- mybuf_len = strlen(mybuf);
+ mybuf = g_malloc(strlen(linebuf)*2 +1);
+ conv_localetodisp(mybuf, strlen(linebuf)*2 +1, linebuf);
}
gtk_text_buffer_get_end_iter(buffer, &iter);
/* parse for clickable parts, and build a list of begin and end positions */
- for (n = 0; n < PARSE_ELEMS; n++) {
- gint len = mybuf_len;
- gint needle_len = strlen(parser[n].needle);
- for (walk = mybuf;;) {
- gchar *scanpos = parser[n].search(walk, len, parser[n].needle);
- if (scanpos) {
- /* check if URI can be parsed */
- if (parser[n].parse(walk, scanpos, &bp, &ep, hdr)
- && (size_t) (ep - bp - 1) > needle_len) {
- ADD_TXT_POS(bp, ep, n);
- len -= ep - walk;
- walk = ep;
- } else {
- len -= (scanpos + needle_len) - walk;
- walk = scanpos + needle_len;
+ for (walk = mybuf;;) {
+ gint last_index = PARSE_ELEMS;
+ gchar *scanpos = NULL;
+
+ /* FIXME: this looks phony. scanning for anything in the parse table */
+ for (n = 0; n < PARSE_ELEMS; n++) {
+ gchar *tmp;
+
+ tmp = parser[n].search(walk, parser[n].needle);
+ if (tmp) {
+ if (scanpos == NULL || tmp < scanpos) {
+ scanpos = tmp;
+ last_index = n;
}
- } else
- break;
+ }
}
+
+ if (scanpos) {
+ /* check if URI can be parsed */
+ if (parser[last_index].parse(walk, scanpos, &bp, &ep, hdr)
+ && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
+ ADD_TXT_POS(bp, ep, last_index);
+ walk = ep;
+ } else
+ walk = scanpos +
+ strlen(parser[last_index].needle);
+ } else
+ break;
}
/* colorize this line */
GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
GtkTextIter start_iter, end_iter;
gchar *mybuf;
- gint mybuf_len;
gint offset = 0;
/* parse table - in order of priority */
struct table {
/* token search function */
gchar *(*search) (const gchar *haystack,
- gint haystack_len,
const gchar *needle);
/* part parsing function */
gboolean (*parse) (const gchar *start,
};
static struct table parser[] = {
- {"http://", strncasestr, get_uri_part, make_uri_string},
- {"https://", strncasestr, get_uri_part, make_uri_string},
- {"ftp://", strncasestr, get_uri_part, make_uri_string},
- {"sftp://", strncasestr, get_uri_part, make_uri_string},
- {"www.", strncasestr, get_uri_part, make_http_string},
- {"mailto:", strncasestr, get_uri_part, make_uri_string},
- {"@", strncasestr, get_email_part, make_email_string}
+ {"http://", strcasestr, get_uri_part, make_uri_string},
+ {"https://", strcasestr, get_uri_part, make_uri_string},
+ {"ftp://", strcasestr, get_uri_part, make_uri_string},
+ {"sftp://", strcasestr, get_uri_part, make_uri_string},
+ {"www.", strcasestr, get_uri_part, make_http_string},
+ {"mailto:", strcasestr, get_uri_part, make_uri_string},
+ {"@", strcasestr, get_email_part, make_email_string}
};
const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
offset = gtk_text_iter_get_offset(&start_iter);
/* parse for clickable parts, and build a list of begin and end positions */
- mybuf_len = strlen(mybuf);
- for (n = 0; n < PARSE_ELEMS; n++) {
- gint len = mybuf_len;
- gint needle_len = strlen(parser[n].needle);
- for (walk = mybuf;;) {
- gchar *scanpos = parser[n].search(walk, len, parser[n].needle);
- if (scanpos) {
- /* check if URI can be parsed */
- if (parser[n].parse(walk, scanpos, &bp, &ep, FALSE)
- && (size_t) (ep - bp - 1) > needle_len) {
- ADD_TXT_POS_LATER(bp, ep, n);
- len -= ep - walk;
- walk = ep;
- } else {
- len -= (scanpos + needle_len) - walk;
- walk = scanpos + needle_len;
+ for (walk = mybuf;;) {
+ gint last_index = PARSE_ELEMS;
+ gchar *scanpos = NULL;
+
+ /* FIXME: this looks phony. scanning for anything in the parse table */
+ for (n = 0; n < PARSE_ELEMS; n++) {
+ gchar *tmp;
+
+ tmp = parser[n].search(walk, parser[n].needle);
+ if (tmp) {
+ if (scanpos == NULL || tmp < scanpos) {
+ scanpos = tmp;
+ last_index = n;
}
- } else
- break;
+ }
}
+
+ if (scanpos) {
+ /* check if URI can be parsed */
+ if (parser[last_index].parse(walk, scanpos, &bp, &ep, FALSE)
+ && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
+ ADD_TXT_POS_LATER(bp, ep, last_index);
+ walk = ep;
+ } else
+ walk = scanpos +
+ strlen(parser[last_index].needle);
+ } else
+ break;
}
/* colorize this line */
return sorted_headers;
}
-static void textview_show_face(TextView *textview)
+static void textview_show_avatar(TextView *textview)
{
GtkAllocation allocation;
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
MsgInfo *msginfo = textview->messageview->msginfo;
int x = 0;
+ AvatarRender *avatarr;
- if (prefs_common.display_header_pane
- || !prefs_common.display_xface)
+ if (prefs_common.display_header_pane || !prefs_common.display_xface)
goto bail;
- if (!msginfo->extradata || !msginfo->extradata->face) {
+ avatarr = avatars_avatarrender_new(msginfo);
+ hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
+
+ if (!avatarr->image) {
+ avatars_avatarrender_free(avatarr);
goto bail;
}
if (textview->image)
gtk_widget_destroy(textview->image);
- textview->image = face_get_from_header(msginfo->extradata->face);
- cm_return_if_fail(textview->image != NULL);
+ textview->image = avatarr->image;
+ avatarr->image = NULL; /* avoid destroying */
+ avatars_avatarrender_free(avatarr);
gtk_widget_show(textview->image);
GTK_TEXT_WINDOW_TEXT, x, 5);
gtk_widget_show_all(textview->text);
-
return;
bail:
return;
}
-#if HAVE_LIBCOMPFACE
-static void textview_show_xface(TextView *textview)
-{
- GtkAllocation allocation;
- MsgInfo *msginfo = textview->messageview->msginfo;
- GtkTextView *text = GTK_TEXT_VIEW(textview->text);
- int x = 0;
- GdkWindow *window = NULL;
-
- if (prefs_common.display_header_pane
- || !prefs_common.display_xface)
- goto bail;
-
- if (!msginfo || !msginfo->extradata)
- goto bail;
-
- if (msginfo->extradata->face)
- return;
-
- if (!msginfo->extradata->xface || strlen(msginfo->extradata->xface) < 5) {
- goto bail;
- }
-
- if (textview->image)
- gtk_widget_destroy(textview->image);
-
- window = mainwindow_get_mainwindow() ?
- mainwindow_get_mainwindow()->window->window :
- textview->text->window;
- textview->image = xface_get_from_header(msginfo->extradata->xface,
- &textview->text->style->white,
- window);
- cm_return_if_fail(textview->image != NULL);
-
- gtk_widget_show(textview->image);
-
- gtk_widget_get_allocation(textview->text, &allocation);
- x = allocation.width - WIDTH -5;
-
- gtk_text_view_add_child_in_window(text, textview->image,
- GTK_TEXT_WINDOW_TEXT, x, 5);
-
- gtk_widget_show_all(textview->text);
-
- return;
-bail:
- if (textview->image)
- gtk_widget_destroy(textview->image);
- textview->image = NULL;
-
-}
-#endif
-
static void textview_save_contact_pic(TextView *textview)
{
#ifndef USE_NEW_ADDRBOOK
gchar *filename = NULL;
GError *error = NULL;
GdkPixbuf *picture = NULL;
-
- if (!msginfo->extradata || (!msginfo->extradata->face && !msginfo->extradata->xface))
+
+ if (!msginfo->extradata || !msginfo->extradata->avatars)
return;
if (textview->image)
GError *error = NULL;
GdkPixbuf *picture = NULL;
gint w, h;
-
+ GtkAllocation allocation;
+
if (prefs_common.display_header_pane
- || !prefs_common.display_xface)
+ || !prefs_common.display_xface)
goto bail;
- if (msginfo->extradata && (msginfo->extradata->face || msginfo->extradata->xface))
+ if (msginfo->extradata && msginfo->extradata->avatars)
return;
if (textview->image)
gtk_widget_show(textview->image);
- x = textview->text->allocation.width - WIDTH -5;
+ gtk_widget_get_allocation(textview->text, &allocation);
+ x = allocation.width - WIDTH -5;
gtk_text_view_add_child_in_window(text, textview->image,
GTK_TEXT_WINDOW_TEXT, x, 5);
"header", NULL);
}
- textview_show_face(textview);
-#if HAVE_LIBCOMPFACE
- textview_show_xface(textview);
-#endif
+ textview_show_avatar(textview);
+
textview_save_contact_pic(textview);
textview_show_contact_pic(textview);
}
gchar *fromname, *fromaddress;
ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
"menu_button");
- GtkWidget *image = NULL;
+ AvatarRender *avatarr = NULL;
GdkPixbuf *picture = NULL;
gboolean use_picture = FALSE;
fromname = procheader_get_fromname(fromaddress);
extract_address(fromaddress);
- if (use_picture &&
- textview->messageview->msginfo &&
- textview->messageview->msginfo->extradata &&
- textview->messageview->msginfo->extradata->face) {
- image = face_get_from_header(textview->messageview->msginfo->extradata->face);
- }
-#if HAVE_LIBCOMPFACE
- else if (use_picture &&
- textview->messageview->msginfo &&
- textview->messageview->msginfo->extradata &&
- textview->messageview->msginfo->extradata->xface) {
- image = xface_get_from_header(textview->messageview->msginfo->extradata->xface,
- &textview->text->style->white,
- mainwindow_get_mainwindow()->window->window);
+ if (use_picture) {
+ avatarr = avatars_avatarrender_new(textview->messageview->msginfo);
+ hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
+ }
+
+ if (avatarr && avatarr->image) {
+ picture = gtk_image_get_pixbuf(GTK_IMAGE(avatarr->image));
+ }
+ if (avatarr) {
+ avatars_avatarrender_free(avatarr);
}
-#endif
- if (image)
- picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
#ifndef USE_NEW_ADDRBOOK
addressbook_add_contact( fromname, fromaddress, NULL, picture);