/*
* 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] = {
{(gulong)0, (gushort)0, (gushort)0, (gushort)0},
{(gulong)0, (gushort)0, (gushort)0, (gushort)0},
GtkTextIter *iter,
TextView *textview);
-static gboolean textview_uri_security_check (TextView *textview,
- ClickableText *uri);
static void textview_uri_list_remove_all (GSList *uri_list);
static void textview_toggle_quote (TextView *textview,
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_prepend(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;
}
+ textview->prev_quote_level = -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);
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 (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 (real_quotelevel > -1 && do_quote_folding) {
- if ( previousquotelevel != real_quotelevel ) {
+ 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 ( textview->prev_quote_level != real_quotelevel ) {
ClickableText *uri;
uri = g_new0(ClickableText, 1);
uri->uri = g_strdup("");
textview->uri_list =
g_slist_prepend(textview->uri_list, uri);
- previousquotelevel = real_quotelevel;
+ textview->prev_quote_level = real_quotelevel;
} else {
GSList *last = textview->uri_list;
- ClickableText *lasturi = (ClickableText *)last->data;
- gint e_len = lasturi->data ? strlen(lasturi->data):0;
- gint n_len = strlen(buf);
+ ClickableText *lasturi = NULL;
+ gint e_len = 0, n_len = 0;
+
+ if (textview->uri_list) {
+ lasturi = (ClickableText *)last->data;
+ } else {
+ printf("oops (%d %d)\n",
+ real_quotelevel, textview->prev_quote_level);
+ }
+ if (lasturi->is_quote == FALSE) {
+ textview->prev_quote_level = -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);
- previousquotelevel = -1;
+ textview->prev_quote_level = -1;
}
}
textview_uri_list_remove_all(textview->uri_list);
textview->uri_list = NULL;
textview->uri_hover = NULL;
+ textview->prev_quote_level = -1;
textview->body_pos = 0;
if (textview->image)
textview_uri_list_remove_all(textview->uri_list);
textview->uri_list = NULL;
+ textview->prev_quote_level = -1;
g_free(textview);
}
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,
case GDK_t:
case GDK_l:
case GDK_c:
+ case GDK_a:
if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) == 0) {
KEY_PRESS_EVENT_STOP();
mimeview_pass_key_press_event(messageview->mimeview,
return FALSE;
}
+gchar *textview_get_visible_uri (TextView *textview,
+ ClickableText *uri)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter start, end;
+
+ buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text));
+
+ gtk_text_buffer_get_iter_at_offset(buffer, &start, uri->start);
+ gtk_text_buffer_get_iter_at_offset(buffer, &end, uri->end);
+
+ return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
+}
+
/*!
*\brief Check to see if a web URL has been disguised as a different
* URL (possible with HTML email).
*\return gboolean TRUE if the URL is ok, or if the user chose to open
* it anyway, otherwise FALSE
*/
-static gboolean textview_uri_security_check(TextView *textview, ClickableText *uri)
+gboolean textview_uri_security_check(TextView *textview, ClickableText *uri)
{
gchar *visible_str;
gboolean retval = TRUE;
- GtkTextBuffer *buffer;
- GtkTextIter start, end;
if (is_uri_string(uri->uri) == FALSE)
return TRUE;
- buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text));
-
- gtk_text_buffer_get_iter_at_offset(buffer, &start, uri->start);
- gtk_text_buffer_get_iter_at_offset(buffer, &end, uri->end);
-
- visible_str = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
-
+ visible_str = textview_get_visible_uri(textview, uri);
if (visible_str == NULL)
return TRUE;
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;
+ }
+}