/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
+ * Copyright (C) 1999-2007 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
#include "inputdialog.h"
#include "timing.h"
-struct _ClickableText
-{
- gchar *uri;
-
- gchar *filename;
-
- gpointer data;
-
- guint start;
- guint end;
-
- gboolean is_quote;
- gint quote_level;
- gboolean q_expanded;
- gchar *fg_color;
-};
-
gint previousquotelevel = -1;
static GdkColor quote_colors[3] = {
static void textview_write_line (TextView *textview,
const gchar *str,
- CodeConverter *conv);
+ CodeConverter *conv,
+ gboolean do_quote_folding);
static void textview_write_link (TextView *textview,
const gchar *str,
const gchar *uri,
static void textview_uri_list_remove_all (GSList *uri_list);
static void textview_toggle_quote (TextView *textview,
+ GSList *start_list,
ClickableText *uri,
gboolean expand_only);
static void open_image_cb (TextView *textview,
guint action,
void *data);
-static void textview_show_icon(TextView *textview, const gchar *stock_id);
static GtkItemFactoryEntry textview_link_popup_entries[] =
{
END_TIMING();
}
-#define TEXT_INSERT(str) \
- gtk_text_buffer_insert_with_tags_by_name \
- (buffer, &iter, str, -1,\
- "header", NULL)
-
-#define TEXT_INSERT_LINK(str, fname, udata) { \
- ClickableText *uri; \
- uri = g_new0(ClickableText, 1); \
- uri->uri = g_strdup(""); \
- uri->start = gtk_text_iter_get_offset(&iter); \
- gtk_text_buffer_insert_with_tags_by_name \
- (buffer, &iter, str, -1, \
- "link", "header_title", "header", \
- NULL); \
- uri->end = gtk_text_iter_get_offset(&iter); \
- uri->filename = fname?g_strdup(fname):NULL; \
- uri->data = udata; \
- textview->uri_list = \
- g_slist_append(textview->uri_list, uri); \
-}
-
static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
{
GtkTextView *text;
buffer = gtk_text_view_get_buffer(text);
charcount = gtk_text_buffer_get_char_count(buffer);
gtk_text_buffer_get_end_iter(buffer, &iter);
-
+
if (textview->stop_loading) {
return;
}
return;
}
+ previousquotelevel = -1;
+
if ((mimeinfo->type == MIMETYPE_MESSAGE) && !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
FILE *fp;
|| (mimeinfo->disposition == DISPOSITIONTYPE_INLINE &&
mimeinfo->type != MIMETYPE_TEXT)) {
gtk_text_buffer_insert(buffer, &iter, "\n", 1);
- TEXT_INSERT_LINK(buf, "sc://select_attachment", mimeinfo);
+ TEXTVIEW_INSERT_LINK(buf, "sc://select_attachment", mimeinfo);
gtk_text_buffer_insert(buffer, &iter, " \n", -1);
if (mimeinfo->type == MIMETYPE_IMAGE &&
prefs_common.inline_img ) {
gchar *filename;
ClickableText *uri;
gchar *uri_str;
+ gint err;
START_TIMING("inserting image");
filename = procmime_get_tmp_file_name(mimeinfo);
- if (procmime_get_part(filename, mimeinfo) < 0) {
- g_warning("Can't get the image file.");
+ if ((err = procmime_get_part(filename, mimeinfo)) < 0) {
+ g_warning("Can't get the image file.(%s)", strerror(-err));
g_free(filename);
END_TIMING();
return;
} else {
gint w, h;
gdk_pixbuf_get_file_info(filename, &w, &h);
- if (w > textview->scrolledwin->allocation.width - 100)
+ if (textview->scrolledwin->allocation.width - 100 > 0 &&
+ w > textview->scrolledwin->allocation.width - 100)
pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
textview->scrolledwin->allocation.width - 100,
-1, TRUE, &error);
uri->end = uri->start + 1;
uri->filename = procmime_get_part_file_name(mimeinfo);
textview->uri_list =
- g_slist_append(textview->uri_list, uri);
+ g_slist_prepend(textview->uri_list, uri);
gtk_text_buffer_insert(buffer, &iter, " ", 1);
gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, uri->start);
buffer = gtk_text_view_get_buffer(text);
gtk_text_buffer_get_start_iter(buffer, &iter);
- TEXT_INSERT(_("\n"
+ TEXTVIEW_INSERT(_("\n"
" This message can't be displayed.\n"
" This is probably due to a network error.\n"
"\n"
" Use "));
- TEXT_INSERT_LINK(_("'View Log'"), "sc://view_log", NULL);
- TEXT_INSERT(_(" in the Tools menu for more information."));
+ TEXTVIEW_INSERT_LINK(_("'View Log'"), "sc://view_log", NULL);
+ TEXTVIEW_INSERT(_(" in the Tools menu for more information."));
textview_show_icon(textview, GTK_STOCK_DIALOG_ERROR);
}
buffer = gtk_text_view_get_buffer(text);
gtk_text_buffer_get_start_iter(buffer, &iter);
- TEXT_INSERT("\n");
- TEXT_INSERT(_(" The following can be performed on this part by\n"));
- TEXT_INSERT(_(" right-clicking the icon or list item:\n"));
-
- TEXT_INSERT(_(" - To save, select "));
- TEXT_INSERT_LINK(_("'Save as...'"), "sc://save_as", NULL);
- TEXT_INSERT(_(" (Shortcut key: 'y')\n"));
- TEXT_INSERT(_(" - To display as text, select "));
- TEXT_INSERT_LINK(_("'Display as text'"), "sc://display_as_text", NULL);
- TEXT_INSERT(_(" (Shortcut key: 't')\n"));
- TEXT_INSERT(_(" - To open with an external program, select "));
- TEXT_INSERT_LINK(_("'Open'"), "sc://open", NULL);
- TEXT_INSERT(_(" (Shortcut key: 'l')\n"));
- TEXT_INSERT(_(" (alternately double-click, or click the middle "));
- TEXT_INSERT(_("mouse button)\n"));
- TEXT_INSERT(_(" - Or use "));
- TEXT_INSERT_LINK(_("'Open with...'"), "sc://open_with", NULL);
- TEXT_INSERT(_(" (Shortcut key: 'o')\n"));
+ TEXTVIEW_INSERT("\n");
+ TEXTVIEW_INSERT(_(" The following can be performed on this part by\n"));
+ TEXTVIEW_INSERT(_(" right-clicking the icon or list item:\n"));
+
+ TEXTVIEW_INSERT(_(" - To save, select "));
+ TEXTVIEW_INSERT_LINK(_("'Save as...'"), "sc://save_as", NULL);
+ TEXTVIEW_INSERT(_(" (Shortcut key: 'y')\n"));
+ TEXTVIEW_INSERT(_(" - To display as text, select "));
+ TEXTVIEW_INSERT_LINK(_("'Display as text'"), "sc://display_as_text", NULL);
+ TEXTVIEW_INSERT(_(" (Shortcut key: 't')\n"));
+ TEXTVIEW_INSERT(_(" - To open with an external program, select "));
+ TEXTVIEW_INSERT_LINK(_("'Open'"), "sc://open", NULL);
+ TEXTVIEW_INSERT(_(" (Shortcut key: 'l')\n"));
+ TEXTVIEW_INSERT(_(" (alternately double-click, or click the middle "));
+ TEXTVIEW_INSERT(_("mouse button)\n"));
+ TEXTVIEW_INSERT(_(" - Or use "));
+ TEXTVIEW_INSERT_LINK(_("'Open with...'"), "sc://open_with", NULL);
+ TEXTVIEW_INSERT(_(" (Shortcut key: 'o')\n"));
textview_show_icon(textview, GTK_STOCK_DIALOG_INFO);
}
-#undef TEXT_INSERT
-#undef TEXT_INSERT_LINK
-
static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
{
FILE *tmpfp;
if (pipe(pfd) < 0) {
g_snprintf(buf, sizeof(buf),
"pipe failed for textview\n\n%s\n", strerror(errno));
- textview_write_line(textview, buf, conv);
+ textview_write_line(textview, buf, conv, TRUE);
goto textview_default;
}
pid = fork();
if (pid < 0) {
g_snprintf(buf, sizeof(buf),
"fork failed for textview\n\n%s\n", strerror(errno));
- textview_write_line(textview, buf, conv);
+ textview_write_line(textview, buf, conv, TRUE);
close(pfd[0]);
close(pfd[1]);
goto textview_default;
close(pfd[1]);
tmpfp = fdopen(pfd[0], "rb");
while (fgets(buf, sizeof(buf), tmpfp)) {
- textview_write_line(textview, buf, conv);
+ textview_write_line(textview, buf, conv, TRUE);
lines++;
if (lines % 500 == 0)
debug_print("Viewing text content of type: %s (length: %d)\n", mimeinfo->subtype, mimeinfo->length);
while ((ftell(tmpfp) < mimeinfo->offset + mimeinfo->length) &&
(fgets(buf, sizeof(buf), tmpfp) != NULL)) {
- textview_write_line(textview, buf, conv);
+ textview_write_line(textview, buf, conv, TRUE);
lines++;
if (lines % 500 == 0)
GTK_EVENTS_FLUSH();
procmime_force_encoding(0);
lines = 0;
+ textview->uri_list = g_slist_reverse(textview->uri_list);
for (cur = textview->uri_list; cur; cur = cur->next) {
ClickableText *uri = (ClickableText *)cur->data;
if (!uri->is_quote)
continue;
if (!prefs_common.hide_quotes ||
uri->quote_level+1 < prefs_common.hide_quotes) {
- textview_toggle_quote(textview, uri, TRUE);
+ textview_toggle_quote(textview, cur, uri, TRUE);
lines++;
if (lines % 500 == 0)
GTK_EVENTS_FLUSH();
if (parser->state == SC_HTML_HREF) {
/* first time : get and copy the URL */
if (parser->href == NULL) {
- /* ALF - the sylpheed html parser returns an empty string,
+ /* ALF - the claws html parser returns an empty string,
* if still inside an <a>, but already parsed past HREF */
str = strtok(str, " ");
if (str) {
if (str != NULL)
textview_write_link(textview, str, parser->href, NULL);
} else
- textview_write_line(textview, str, NULL);
+ textview_write_line(textview, str, NULL, FALSE);
lines++;
if (lines % 500 == 0)
GTK_EVENTS_FLUSH();
return;
}
}
- textview_write_line(textview, "\n", NULL);
+ textview_write_line(textview, "\n", NULL, FALSE);
sc_html_parser_destroy(parser);
}
g_return_if_fail(parser != NULL);
while ((str = ertf_parse(parser)) != NULL) {
- textview_write_line(textview, str, NULL);
+ textview_write_line(textview, str, NULL, FALSE);
lines++;
if (lines % 500 == 0)
GTK_EVENTS_FLUSH();
uri->end = gtk_text_iter_get_offset(&iter);
uri->filename = NULL;
textview->uri_list =
- g_slist_append(textview->uri_list, uri);
+ g_slist_prepend(textview->uri_list, uri);
}
if (*normal_text)
uri->end = gtk_text_iter_get_offset(&end_iter);
uri->filename = NULL;
textview->uri_list =
- g_slist_append(textview->uri_list, uri);
+ g_slist_prepend(textview->uri_list, uri);
}
}
#undef ADD_TXT_POS
static void textview_write_line(TextView *textview, const gchar *str,
- CodeConverter *conv)
+ CodeConverter *conv, gboolean do_quote_folding)
{
GtkTextView *text;
GtkTextBuffer *buffer;
textview->is_in_signature = TRUE;
}
- if (real_quotelevel > -1) {
+ if (real_quotelevel > -1 && do_quote_folding) {
+ if (!g_utf8_validate(buf, -1, NULL)) {
+ gchar *utf8buf = NULL;
+ utf8buf = g_malloc(BUFFSIZE);
+ conv_localetodisp(utf8buf, BUFFSIZE, buf);
+ strncpy2(buf, utf8buf, BUFFSIZE-1);
+ g_free(utf8buf);
+ }
+do_quote:
if ( previousquotelevel != real_quotelevel ) {
ClickableText *uri;
uri = g_new0(ClickableText, 1);
uri->uri = g_strdup("");
uri->data = g_strdup(buf);
uri->start = gtk_text_iter_get_offset(&iter);
+ uri->is_quote = TRUE;
+ uri->quote_level = real_quotelevel;
+ uri->fg_color = g_strdup(fg_color);
+
gtk_text_buffer_insert_with_tags_by_name
- (buffer, &iter, " [...]", -1,
- "qlink", fg_color, NULL);
+ (buffer, &iter, " [...]", -1,
+ "qlink", fg_color, NULL);
uri->end = gtk_text_iter_get_offset(&iter);
+ gtk_text_buffer_insert(buffer, &iter, " \n", -1);
+
uri->filename = NULL;
- uri->fg_color = g_strdup(fg_color);
- uri->is_quote = TRUE;
- uri->quote_level = real_quotelevel;
textview->uri_list =
- g_slist_append(textview->uri_list, uri);
- gtk_text_buffer_insert(buffer, &iter, " \n", -1);
+ g_slist_prepend(textview->uri_list, uri);
previousquotelevel = real_quotelevel;
} else {
- GSList *last = g_slist_last(textview->uri_list);
+ GSList *last = textview->uri_list;
ClickableText *lasturi = (ClickableText *)last->data;
- gchar *tmp = g_strdup_printf("%s%s", (gchar *)lasturi->data, buf);
- g_free(lasturi->data);
- lasturi->data = tmp;
+ gint e_len = 0, n_len = 0;
+
+ if (lasturi->is_quote == FALSE) {
+ previousquotelevel = -1;
+ goto do_quote;
+ }
+ e_len = lasturi->data ? strlen(lasturi->data):0;
+ n_len = strlen(buf);
+ lasturi->data = g_realloc((gchar *)lasturi->data, e_len + n_len + 1);
+ strcpy((gchar *)lasturi->data + e_len, buf);
+ *((gchar *)lasturi->data + e_len + n_len) = '\0';
}
} else {
textview_make_clickable_parts(textview, fg_color, "link", buf, FALSE);
(buffer, &iter, bufp, -1, "link", NULL);
r_uri->end = gtk_text_iter_get_offset(&iter);
r_uri->filename = NULL;
- textview->uri_list = g_slist_append(textview->uri_list, r_uri);
+ textview->uri_list = g_slist_prepend(textview->uri_list, r_uri);
}
static void textview_set_cursor(GdkWindow *window, GdkCursor *cursor)
if (font_desc) {
gtk_widget_modify_font(textview->text, font_desc);
CHANGE_TAG_FONT("header", font_desc);
+ CHANGE_TAG_FONT("hlink", font_desc);
pango_font_description_free(font_desc);
}
if (bold_font_desc) {
{"AF:", "NF:", "PS:", "SRH:", "SFN:", "DSR:", "MID:",
"CFG:", "PT:", "S:", "RQ:", "SSV:", "NSV:", "SSH:",
"R:", "MAID:", "SCF:", "RMID:", "FMID:", "NAID:",
+ "X-Claws-Account-Id:", "X-Claws-Sign:", "X-Claws-Encrypt:",
+ "X-Claws-Privacy-System:", "X-Claws-End-Special-Headers:",
"X-Sylpheed-Account-Id:", "X-Sylpheed-Sign:", "X-Sylpheed-Encrypt:",
"X-Sylpheed-Privacy-System:", "X-Sylpheed-End-Special-Headers:",
NULL};
textview->image = NULL;
}
-static void textview_show_icon(TextView *textview, const gchar *stock_id)
+void textview_show_icon(TextView *textview, const gchar *stock_id)
{
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
int x = 0;
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 (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,
- textview->text->window);
+ window);
g_return_if_fail(textview->image != NULL);
gtk_widget_show(textview->image);
if ((procheader_headername_equal(header->name, "X-Mailer") ||
procheader_headername_equal(header->name,
"X-Newsreader")) &&
- strstr(header->body, "Sylpheed-Claws") != NULL) {
+ (strstr(header->body, "Claws Mail") != NULL ||
+ strstr(header->body, "Sylpheed-Claws") != NULL)) {
gtk_text_buffer_get_end_iter (buffer, &iter);
gtk_text_buffer_insert_with_tags_by_name
(buffer, &iter, header->body, -1,
return uri;
}
-static void textview_shift_uris_after(TextView *textview, gint start, gint shift)
+static void textview_shift_uris_after(TextView *textview, GSList *start_list, gint start, gint shift)
{
GSList *cur;
- for (cur = textview->uri_list; cur; cur = cur->next) {
+ if (!start_list)
+ start_list = textview->uri_list;
+
+ for (cur = start_list; cur; cur = cur->next) {
ClickableText *uri = (ClickableText *)cur->data;
if (uri->start <= start)
continue;
}
}
-static void textview_toggle_quote(TextView *textview, ClickableText *uri, gboolean expand_only)
+static void textview_toggle_quote(TextView *textview, GSList *start_list, ClickableText *uri, gboolean expand_only)
{
GtkTextIter start, end;
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text));
if (!uri->q_expanded) {
gtk_text_buffer_get_iter_at_offset(buffer, &start, uri->start);
gtk_text_buffer_get_iter_at_offset(buffer, &end, uri->end);
- textview_shift_uris_after(textview, uri->start,
+ textview_shift_uris_after(textview, start_list, uri->start,
g_utf8_strlen((gchar *)uri->data, -1)-strlen(" [...]\n"));
gtk_text_buffer_delete(buffer, &start, &end);
gtk_text_buffer_get_iter_at_offset(buffer, &start, uri->start);
gtk_text_buffer_get_iter_at_offset(buffer, &start, uri->start);
gtk_text_buffer_get_iter_at_offset(buffer, &end, uri->end);
textview_remove_uris_in(textview, uri->start, uri->end);
- textview_shift_uris_after(textview, uri->start,
+ textview_shift_uris_after(textview, start_list, uri->start,
strlen(" [...]\n")-g_utf8_strlen((gchar *)uri->data, -1));
gtk_text_buffer_delete(buffer, &start, &end);
gtk_text_buffer_get_iter_at_offset(buffer, &start, uri->start);
}
return TRUE;
} else if (qlink && bevent->button == 1) {
- textview_toggle_quote(textview, uri, FALSE);
+ textview_toggle_quote(textview, NULL, uri, FALSE);
return TRUE;
} else if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7)) {
if (bevent->button == 3) {
filedir = g_path_get_dirname(filename);
if (filedir && strcmp(filedir, ".")) {
g_free(prefs_common.attach_save_dir);
- prefs_common.attach_save_dir = g_strdup(filedir);
+ prefs_common.attach_save_dir = g_filename_to_utf8(filedir, -1, NULL, NULL, NULL);
}
g_free(filedir);
/* Hiroyuki: please put this function in utils.c! */
fromname = procheader_get_fromname(fromaddress);
extract_address(fromaddress);
- g_message("adding from textview %s <%s>", fromname, fromaddress);
+
/* Add to address book - Match */
addressbook_add_contact( fromname, fromaddress, NULL );
NULL);
}
+void textview_get_selection_offsets(TextView *textview, gint *sel_start, gint *sel_end)
+{
+ GtkTextView *text = GTK_TEXT_VIEW(textview->text);
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
+ GtkTextIter start, end;
+ if (gtk_text_buffer_get_selection_bounds(buffer, &start, &end)) {
+ if (sel_start)
+ *sel_start = gtk_text_iter_get_offset(&start);
+ if (sel_end)
+ *sel_end = gtk_text_iter_get_offset(&end);
+ } else {
+ if (sel_start)
+ *sel_start = -1;
+ if (sel_end)
+ *sel_end = -1;
+ }
+}