#include "defs.h"
#include <glib.h>
+#include <glib/gi18n.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkvbox.h>
#include <string.h>
#include <stdlib.h>
-#include "intl.h"
#include "main.h"
#include "summaryview.h"
#include "procheader.h"
#include "mimeview.h"
#include "alertpanel.h"
#include "menu.h"
+#include "image_viewer.h"
+#include "filesel.h"
struct _RemoteURI
{
gchar *uri;
+ gchar *filename;
+
guint start;
guint end;
};
static gboolean textview_motion_notify (GtkWidget *widget,
GdkEventMotion *motion,
TextView *textview);
-static gboolean textview_leave_notify (GtkWidget *widget,
+static gboolean textview_leave_notify (GtkWidget *widget,
GdkEventCrossing *event,
- TextView *textview);
+ TextView *textview);
static gboolean textview_visibility_notify (GtkWidget *widget,
GdkEventVisibility *event,
TextView *textview);
static void copy_uri_cb (TextView *textview,
guint action,
void *data);
+static void add_uri_to_addrbook_cb (TextView *textview,
+ guint action,
+ void *data);
+static void mail_to_uri_cb (TextView *textview,
+ guint action,
+ void *data);
+static void copy_mail_to_uri_cb (TextView *textview,
+ guint action,
+ void *data);
+static void save_file_cb (TextView *textview,
+ guint action,
+ void *data);
+
+static GtkItemFactoryEntry textview_link_popup_entries[] =
+{
+ {N_("/_Open with Web browser"), NULL, open_uri_cb, 0, NULL},
+ {N_("/Copy this _link"), NULL, copy_uri_cb, 0, NULL},
+};
+
+static GtkItemFactoryEntry textview_mail_popup_entries[] =
+{
+ {N_("/Compose _new message"), NULL, mail_to_uri_cb, 0, NULL},
+ {N_("/Add to _address book"), NULL, add_uri_to_addrbook_cb, 0, NULL},
+ {N_("/Copy this add_ress"), NULL, copy_mail_to_uri_cb, 0, NULL},
+};
-static GtkItemFactoryEntry textview_popup_entries[] =
+static GtkItemFactoryEntry textview_file_popup_entries[] =
{
- {N_("/_Open link"), NULL, open_uri_cb, 0, NULL},
- {N_("/_Copy link location"), NULL, copy_uri_cb, 0, NULL},
+ {N_("/_Save this image..."), NULL, save_file_cb, 0, NULL},
};
GtkWidget *text;
GtkTextBuffer *buffer;
GtkClipboard *clipboard;
- GtkItemFactory *popupfactory;
- GtkWidget *popupmenu;
+ GtkItemFactory *link_popupfactory, *mail_popupfactory, *file_popupfactory;
+ GtkWidget *link_popupmenu, *mail_popupmenu, *file_popupmenu;
gint n_entries;
- PangoFontDescription *font_desc = NULL;
debug_print("Creating text view...\n");
textview = g_new0(TextView, 1);
scrolledwin = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
- GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
GTK_SHADOW_IN);
gtk_widget_set_size_request
gtk_widget_ensure_style(text);
- if (prefs_common.normalfont)
- font_desc = pango_font_description_from_string
- (prefs_common.normalfont);
- if (font_desc) {
- gtk_widget_modify_font(text, font_desc);
- }
- pango_font_description_free(font_desc);
-
gtk_widget_ref(scrolledwin);
gtk_container_add(GTK_CONTAINER(scrolledwin), text);
- if (!hand_cursor)
- hand_cursor = gdk_cursor_new(GDK_HAND2);
- if (!text_cursor)
- text_cursor = gdk_cursor_new(GDK_XTERM);
-
- g_signal_connect(G_OBJECT(text), "key_press_event",
- G_CALLBACK(textview_key_pressed),
- textview);
- g_signal_connect(G_OBJECT(text), "motion_notify_event",
- G_CALLBACK(textview_motion_notify),
- textview);
- g_signal_connect(G_OBJECT(text), "leave_notify_event",
- G_CALLBACK(textview_leave_notify),
- textview);
- g_signal_connect(G_OBJECT(text), "visibility_notify_event",
- G_CALLBACK(textview_visibility_notify),
- textview);
+ g_signal_connect(G_OBJECT(text), "key-press-event",
+ G_CALLBACK(textview_key_pressed), textview);
+ g_signal_connect(G_OBJECT(text), "motion-notify-event",
+ G_CALLBACK(textview_motion_notify), textview);
+ g_signal_connect(G_OBJECT(text), "leave-notify-event",
+ G_CALLBACK(textview_leave_notify), textview);
+ g_signal_connect(G_OBJECT(text), "visibility-notify-event",
+ G_CALLBACK(textview_visibility_notify), textview);
gtk_widget_show(scrolledwin);
gtk_widget_show(vbox);
- n_entries = sizeof(textview_popup_entries) /
- sizeof(textview_popup_entries[0]);
- popupmenu = menu_create_items(textview_popup_entries, n_entries,
- "<UriPopupMenu>", &popupfactory,
+ n_entries = sizeof(textview_link_popup_entries) /
+ sizeof(textview_link_popup_entries[0]);
+ link_popupmenu = menu_create_items(textview_link_popup_entries, n_entries,
+ "<UriPopupMenu>", &link_popupfactory,
textview);
- textview->vbox = vbox;
- textview->scrolledwin = scrolledwin;
- textview->text = text;
- textview->uri_list = NULL;
- textview->body_pos = 0;
- textview->show_all_headers = FALSE;
- textview->last_buttonpress = GDK_NOTHING;
- textview->popup_menu = popupmenu;
- textview->popup_factory = popupfactory;
+ n_entries = sizeof(textview_mail_popup_entries) /
+ sizeof(textview_mail_popup_entries[0]);
+ mail_popupmenu = menu_create_items(textview_mail_popup_entries, n_entries,
+ "<UriPopupMenu>", &mail_popupfactory,
+ textview);
+
+ n_entries = sizeof(textview_file_popup_entries) /
+ sizeof(textview_file_popup_entries[0]);
+ file_popupmenu = menu_create_items(textview_file_popup_entries, n_entries,
+ "<FilePopupMenu>", &file_popupfactory,
+ textview);
+
+ textview->vbox = vbox;
+ textview->scrolledwin = scrolledwin;
+ textview->text = text;
+ textview->uri_list = NULL;
+ textview->body_pos = 0;
+ textview->show_all_headers = FALSE;
+ textview->last_buttonpress = GDK_NOTHING;
+ textview->link_popup_menu = link_popupmenu;
+ textview->link_popup_factory = link_popupfactory;
+ textview->mail_popup_menu = mail_popupmenu;
+ textview->mail_popup_factory = mail_popupfactory;
+ textview->file_popup_menu = file_popupmenu;
+ textview->file_popup_factory = file_popupfactory;
return textview;
}
static void textview_create_tags(GtkTextView *text, TextView *textview)
{
- GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
+ GtkTextBuffer *buffer;
GtkTextTag *tag;
+ static PangoFontDescription *font_desc, *bold_font_desc;
+
+ if (!font_desc)
+ font_desc = pango_font_description_from_string
+ (NORMAL_FONT);
+
+ if (!bold_font_desc) {
+ bold_font_desc = pango_font_description_from_string
+ (BOLD_FONT);
+ pango_font_description_set_weight
+ (bold_font_desc, PANGO_WEIGHT_BOLD);
+ }
+
+ buffer = gtk_text_view_get_buffer(text);
gtk_text_buffer_create_tag(buffer, "header",
"pixels-above-lines", 0,
"pixels-above-lines-set", TRUE,
"pixels-below-lines", 0,
"pixels-below-lines-set", TRUE,
+ "font-desc", font_desc,
"left-margin", 0,
"left-margin-set", TRUE,
NULL);
gtk_text_buffer_create_tag(buffer, "header_title",
- "font", prefs_common.boldfont,
+ "font-desc", bold_font_desc,
NULL);
gtk_text_buffer_create_tag(buffer, "quote0",
"foreground-gdk", "e_colors[0],
"foreground-gdk", &uri_color,
NULL);
gtk_text_buffer_create_tag(buffer, "link-hover",
+ "foreground-gdk", &uri_color,
"underline", PANGO_UNDERLINE_SINGLE,
NULL);
void textview_init(TextView *textview)
{
- textview_update_message_colors();
+ if (!hand_cursor)
+ hand_cursor = gdk_cursor_new(GDK_HAND2);
+ if (!text_cursor)
+ text_cursor = gdk_cursor_new(GDK_XTERM);
+
+ textview_reflect_prefs(textview);
textview_set_all_headers(textview, FALSE);
textview_set_font(textview, NULL);
textview_create_tags(GTK_TEXT_VIEW(textview->text), textview);
}
}
+void textview_reflect_prefs(TextView *textview)
+{
+ textview_update_message_colors();
+ gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textview->text),
+ prefs_common.textview_cursor_visible);
+}
+
void textview_show_message(TextView *textview, MimeInfo *mimeinfo,
const gchar *file)
{
void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
{
- GtkTextView *text;
-
g_return_if_fail(mimeinfo != NULL);
g_return_if_fail(fp != NULL);
{
GtkTextView *text;
GtkTextBuffer *buffer;
- GtkTextIter iter;
+ GtkTextIter iter, start_iter;
gchar buf[BUFFSIZE];
GPtrArray *headers = NULL;
const gchar *name;
if (mimeinfo->type != MIMETYPE_TEXT) {
gtk_text_buffer_insert(buffer, &iter, buf, -1);
+ if (mimeinfo->type == MIMETYPE_IMAGE &&
+ prefs_common.inline_img ) {
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
+ gchar *filename;
+ RemoteURI *uri;
+ gchar *uri_str;
+ FILE *fp;
+
+ fp = fopen(mimeinfo->data.filename, "rb");
+ fseek(fp, mimeinfo->offset, SEEK_SET);
+
+ filename = procmime_get_tmp_file_name(mimeinfo);
+ if (procmime_get_part(filename, mimeinfo) < 0) {
+ g_warning("Can't get the image file.");
+ g_free(filename);
+ return;
+ }
+
+ pixbuf = gdk_pixbuf_new_from_file(filename, &error);
+ if (error != NULL) {
+ g_warning("%s\n", error->message);
+ g_error_free(error);
+ }
+ if (!pixbuf) {
+ g_warning("Can't load the image.");
+ g_free(filename);
+ return;
+ }
+
+ if (prefs_common.resize_img) {
+ int new_width, new_height;
+ GdkPixbuf *scaled;
+ image_viewer_get_resized_size(gdk_pixbuf_get_width(pixbuf),
+ gdk_pixbuf_get_height(pixbuf),
+ textview->scrolledwin->allocation.width - 100,
+ gdk_pixbuf_get_height(pixbuf),
+ &new_width, &new_height);
+ scaled = gdk_pixbuf_scale_simple
+ (pixbuf, new_width, new_height, GDK_INTERP_BILINEAR);
+
+ g_object_unref(pixbuf);
+ pixbuf = scaled;
+ }
+
+ uri_str = g_filename_to_uri(filename, NULL, NULL);
+ if (uri_str) {
+ uri = g_new(RemoteURI, 1);
+ uri->uri = uri_str;
+ uri->start = gtk_text_iter_get_offset(&iter);
+
+ gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
+
+ uri->end = uri->start + 1;
+ uri->filename = procmime_get_part_file_name(mimeinfo);
+ textview->uri_list =
+ g_slist_append(textview->uri_list, uri);
+
+ gtk_text_buffer_insert(buffer, &iter, " ", 1);
+ gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, uri->start);
+ gtk_text_buffer_apply_tag_by_name(buffer, "link",
+ &start_iter, &iter);
+ } else {
+ gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
+ gtk_text_buffer_insert(buffer, &iter, " ", 1);
+ }
+
+ g_object_unref(pixbuf);
+ g_free(filename);
+ }
} else if (mimeinfo->disposition != DISPOSITIONTYPE_ATTACHMENT) {
if (prefs_common.display_header && (charcount > 0))
gtk_text_buffer_insert(buffer, &iter, "\n", 1);
procmime_decode_content(mimeinfo);
- if (!g_ascii_strcasecmp(mimeinfo->subtype, "html")) {
+ if (!g_ascii_strcasecmp(mimeinfo->subtype, "html") &&
+ prefs_common.render_html) {
gchar *filename;
filename = procmime_get_tmp_file_name(mimeinfo);
} else
textview_write_line(textview, str, NULL);
}
+ textview_write_line(textview, "\n", NULL);
html_parser_destroy(parser);
}
&& (((bp_ + 1) < ep_) && isalnum(*(bp_ + 1)))) {
/* hyphens are allowed, but only in
between alnums */
- } else if (!ispunct(*bp_)) {
+ } else if (!strchr(",;:=?./+<>!&\r\n\t", *bp_)) {
/* but anything not being a punctiation
is ok */
} else {
(buffer, &iter, last->bp, last->ep - last->bp,
uri_tag, fg_tag, NULL);
uri->end = gtk_text_iter_get_offset(&iter);
+ uri->filename = NULL;
textview->uri_list =
g_slist_append(textview->uri_list, uri);
}
gchar *bufp;
RemoteURI *r_uri;
- if (*str == '\0')
+ if (!str || *str == '\0')
+ return;
+ if (!uri)
return;
text = GTK_TEXT_VIEW(textview->text);
else if (conv_convert(conv, buf, sizeof(buf), str) < 0)
conv_utf8todisp(buf, sizeof(buf), str);
+ if (g_utf8_validate(buf, -1, NULL) == FALSE)
+ return;
+
strcrchomp(buf);
gtk_text_buffer_get_end_iter(buffer, &iter);
+ for (bufp = buf; *bufp != '\0'; bufp = g_utf8_next_char(bufp)) {
+ gunichar ch;
- for (bufp = buf; isspace(*(guchar *)bufp); bufp++)
- gtk_text_buffer_insert(buffer, &iter, bufp, 1);
+ ch = g_utf8_get_char(bufp);
+ if (!g_unichar_isspace(ch))
+ break;
+ }
+ if (bufp > buf)
+ gtk_text_buffer_insert(buffer, &iter, buf, bufp - buf);
if (prefs_common.enable_color) {
link_color = &uri_color;
gtk_text_buffer_insert_with_tags_by_name
(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);
}
if (prefs_common.textfont) {
PangoFontDescription *font_desc = NULL;
- if (prefs_common.textfont)
- font_desc = pango_font_description_from_string
+ font_desc = pango_font_description_from_string
(prefs_common.textfont);
if (font_desc) {
gtk_widget_modify_font(textview->text, font_desc);
procheader_headername_equal(header->name, "Cc"))
unfold_line(header->body);
-#warning FIXME_GTK2
-#if 0
- if (textview->text_is_mb == TRUE)
- conv_unreadable_locale(header->body);
-#endif
-
if (prefs_common.enable_color &&
(procheader_headername_equal(header->name, "X-Mailer") ||
procheader_headername_equal(header->name,
gboolean case_sens)
{
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
- GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
+ GtkTextBuffer *buffer;
+ GtkTextIter iter, match_pos;
GtkTextMark *mark;
- GtkTextIter iter, start, end, real_end, *pos;
- gboolean found = FALSE;
- gint insert_offset, selbound_offset;
-
- /* reset selection */
- mark = gtk_text_buffer_get_mark(buffer, "insert");
- gtk_text_buffer_get_iter_at_mark(buffer, &start, mark);
- insert_offset = gtk_text_iter_get_offset(&start);
- mark = gtk_text_buffer_get_mark(buffer, "selection_bound");
- gtk_text_buffer_get_iter_at_mark(buffer, &end, mark);
- selbound_offset = gtk_text_iter_get_offset(&end);
-
- pos = insert_offset > selbound_offset ? &start : &end;
- gtk_text_buffer_place_cursor(buffer, pos);
-
- /* search */
+ gint len;
+
+ g_return_val_if_fail(str != NULL, FALSE);
+
+ buffer = gtk_text_view_get_buffer(text);
+
+ len = g_utf8_strlen(str, -1);
+ g_return_val_if_fail(len >= 0, FALSE);
+
mark = gtk_text_buffer_get_insert(buffer);
gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
- if (case_sens) {
- found = gtk_text_iter_forward_search(&iter, str,
- GTK_TEXT_SEARCH_VISIBLE_ONLY,
- &start, &end, NULL);
- } else {
- gchar *text = NULL;
- int i = 0;
- gtk_text_buffer_get_end_iter(buffer, &real_end);
- text = gtk_text_buffer_get_text(buffer, &iter,
- &real_end, FALSE);
-
- while (!found && i++ < strlen(text) - 1) {
- found = (strncasecmp(text+i, str, strlen(str)) == 0);
- }
-
- i += gtk_text_iter_get_offset(&end);
-
- if (found) {
- gtk_text_buffer_get_iter_at_offset(buffer, &start, i);
- gtk_text_buffer_get_iter_at_offset(buffer, &end,
- i + strlen(str));
- }
-
- g_free(text);
- }
-
- if (found) {
- gtk_text_buffer_place_cursor(buffer, &start);
- gtk_text_buffer_move_mark_by_name(buffer, "selection_bound",
- &end);
- mark = gtk_text_buffer_get_mark(buffer, "insert");
- gtk_text_view_scroll_mark_onscreen(text, mark);
+
+ if (gtkut_text_buffer_find(buffer, &iter, str, case_sens,
+ &match_pos)) {
+ GtkTextIter end = match_pos;
+
+ gtk_text_iter_forward_chars(&end, len);
+ /* place "insert" at the last character */
+ gtk_text_buffer_select_range(buffer, &end, &match_pos);
+ gtk_text_view_scroll_to_mark(text, mark, 0.0, FALSE, 0.0, 0.0);
+ return TRUE;
}
- return found;
+ return FALSE;
}
gboolean textview_search_string_backward(TextView *textview, const gchar *str,
gboolean case_sens)
{
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
- GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
+ GtkTextBuffer *buffer;
+ GtkTextIter iter, match_pos;
GtkTextMark *mark;
- GtkTextIter iter, start, real_start, end, *pos;
- gboolean found = FALSE;
- gint insert_offset, selbound_offset;
-
- /* reset selection */
- mark = gtk_text_buffer_get_mark(buffer, "insert");
- gtk_text_buffer_get_iter_at_mark(buffer, &start, mark);
- insert_offset = gtk_text_iter_get_offset(&start);
- mark = gtk_text_buffer_get_mark(buffer, "selection_bound");
- gtk_text_buffer_get_iter_at_mark(buffer, &end, mark);
- selbound_offset = gtk_text_iter_get_offset(&end);
-
- pos = insert_offset < selbound_offset ? &start : &end;
- gtk_text_buffer_place_cursor(buffer, pos);
-
- /* search */
+ gint len;
+
+ g_return_val_if_fail(str != NULL, FALSE);
+
+ buffer = gtk_text_view_get_buffer(text);
+
+ len = g_utf8_strlen(str, -1);
+ g_return_val_if_fail(len >= 0, FALSE);
+
mark = gtk_text_buffer_get_insert(buffer);
gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
- if (case_sens) {
- found = gtk_text_iter_backward_search(&iter, str,
- GTK_TEXT_SEARCH_VISIBLE_ONLY,
- &start, &end, NULL);
- } else {
- gchar *text = NULL;
- int i = 0;
- if (gtk_text_iter_get_offset(&iter) == 0)
- gtk_text_buffer_get_end_iter(buffer, &iter);
-
- i = gtk_text_iter_get_offset(&iter) - strlen(str) - 1;
- gtk_text_buffer_get_start_iter(buffer, &real_start);
-
- text = gtk_text_buffer_get_text(buffer, &real_start,
- &iter, FALSE);
- while (!found && i-- > 0) {
- found = (strncasecmp(text+i, str, strlen(str)) == 0);
- }
-
- if (found) {
- gtk_text_buffer_get_iter_at_offset(buffer, &start, i);
- gtk_text_buffer_get_iter_at_offset(buffer, &end,
- i + strlen(str));
- }
-
- g_free(text);
- }
-
- if (found) {
- gtk_text_buffer_place_cursor(buffer, &end);
- gtk_text_buffer_move_mark_by_name(buffer, "selection_bound",
- &start);
- mark = gtk_text_buffer_get_mark(buffer, "insert");
- gtk_text_view_scroll_mark_onscreen(text, mark);
+ if (gtkut_text_buffer_find_backward(buffer, &iter, str, case_sens,
+ &match_pos)) {
+ GtkTextIter end = match_pos;
+
+ gtk_text_iter_forward_chars(&end, len);
+ gtk_text_buffer_select_range(buffer, &match_pos, &end);
+ gtk_text_view_scroll_to_mark(text, mark, 0.0, FALSE, 0.0, 0.0);
+ return TRUE;
}
- return found;
+ return FALSE;
}
void textview_scroll_one_line(TextView *textview, gboolean up)
vadj->value = last_value;
g_signal_emit_by_name(G_OBJECT(vadj), "value_changed", 0);
+
+ gtk_widget_queue_draw(GTK_WIDGET(text));
}
static void textview_smooth_scroll_one_line(TextView *textview, gboolean up)
{
GdkEventButton *bevent;
RemoteURI *uri = NULL;
- GSList *cur;
- gchar *trimmed_uri;
if (!event)
return FALSE;
bevent->button == 2 || bevent->button == 3) {
if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7)) {
if (bevent->button == 3) {
- gchar *fromname, *fromaddress;
-
- /* extract url */
- fromaddress = g_strdup(uri->uri + 7);
- /* 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 );
-
- g_free(fromaddress);
- g_free(fromname);
+ g_object_set_data(
+ G_OBJECT(textview->mail_popup_menu),
+ "menu_button", uri);
+ gtk_menu_popup(GTK_MENU(textview->mail_popup_menu),
+ NULL, NULL, NULL, NULL,
+ bevent->button, bevent->time);
} else {
PrefsAccount *account = NULL;
compose_new(account, uri->uri + 7, NULL);
}
return TRUE;
- } else {
+ } else if (g_ascii_strncasecmp(uri->uri, "file:", 5)) {
if (bevent->button == 1 &&
textview_uri_security_check(textview, uri) == TRUE)
open_uri(uri->uri,
prefs_common.uri_cmd);
else if (bevent->button == 3) {
g_object_set_data(
- G_OBJECT(textview->popup_menu),
+ G_OBJECT(textview->link_popup_menu),
"menu_button", uri);
- gtk_menu_popup(GTK_MENU(textview->popup_menu),
+ gtk_menu_popup(GTK_MENU(textview->link_popup_menu),
NULL, NULL, NULL, NULL,
bevent->button, bevent->time);
}
return TRUE;
+ } else {
+ if (bevent->button == 3) {
+ g_object_set_data(
+ G_OBJECT(textview->file_popup_menu),
+ "menu_button", uri);
+ gtk_menu_popup(GTK_MENU(textview->file_popup_menu),
+ NULL, NULL, NULL, NULL,
+ bevent->button, bevent->time);
+ return TRUE;
+ }
}
}
for (cur = uri_list; cur != NULL; cur = cur->next) {
if (cur->data) {
g_free(((RemoteURI *)cur->data)->uri);
+ g_free(((RemoteURI *)cur->data)->filename);
g_free(cur->data);
}
}
static void open_uri_cb (TextView *textview, guint action, void *data)
{
- RemoteURI *uri = g_object_get_data(G_OBJECT(textview->popup_menu),
+ RemoteURI *uri = g_object_get_data(G_OBJECT(textview->link_popup_menu),
"menu_button");
if (uri == NULL)
return;
if (textview_uri_security_check(textview, uri) == TRUE)
open_uri(uri->uri,
prefs_common.uri_cmd);
- g_object_set_data(G_OBJECT(textview->popup_menu), "menu_button",
+ g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button",
+ NULL);
+}
+
+static void save_file_cb (TextView *textview, guint action, void *data)
+{
+ RemoteURI *uri = g_object_get_data(G_OBJECT(textview->file_popup_menu),
+ "menu_button");
+ gchar *filename = NULL;
+ gchar *filepath = NULL;
+ gchar *filedir = NULL;
+ gchar *tmp_filename = NULL;
+ if (uri == NULL)
+ return;
+
+ if (uri->filename == NULL)
+ return;
+
+ filename = g_strdup(uri->filename);
+
+ if (!g_utf8_validate(filename, -1, NULL)) {
+ gchar *tmp = conv_filename_to_utf8(filename);
+ g_free(filename);
+ filename = tmp;
+ }
+
+ subst_for_filename(filename);
+
+ if (prefs_common.attach_save_dir)
+ filepath = g_strconcat(prefs_common.attach_save_dir,
+ G_DIR_SEPARATOR_S, filename, NULL);
+ else
+ filepath = g_strdup(filename);
+
+ g_free(filename);
+
+ filename = filesel_select_file_save(_("Save as"), filepath);
+ if (!filename) {
+ g_free(filepath);
+ return;
+ }
+
+ if (is_file_exist(filename)) {
+ AlertValue aval;
+ gchar *res;
+
+ res = g_strdup_printf(_("Overwrite existing file '%s'?"),
+ filename);
+ aval = alertpanel(_("Overwrite"), res, GTK_STOCK_OK,
+ GTK_STOCK_CANCEL, NULL);
+ g_free(res);
+ if (G_ALERTDEFAULT != aval)
+ return;
+ }
+
+ tmp_filename = g_filename_from_uri(uri->uri, NULL, NULL);
+ copy_file(tmp_filename, filename, FALSE);
+ g_free(tmp_filename);
+
+ filedir = g_path_get_dirname(filename);
+ if (filedir && strcmp(filedir, ".")) {
+ if (prefs_common.attach_save_dir)
+ g_free(prefs_common.attach_save_dir);
+ prefs_common.attach_save_dir = g_strdup(filedir);
+ }
+
+ g_free(filedir);
+ g_free(filepath);
+
+ g_object_set_data(G_OBJECT(textview->file_popup_menu), "menu_button",
NULL);
}
static void copy_uri_cb (TextView *textview, guint action, void *data)
{
- RemoteURI *uri = g_object_get_data(G_OBJECT(textview->popup_menu),
+ RemoteURI *uri = g_object_get_data(G_OBJECT(textview->link_popup_menu),
+ "menu_button");
+ if (uri == NULL)
+ return;
+
+ gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), uri->uri, -1);
+ gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), uri->uri, -1);
+ g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button",
+ NULL);
+}
+
+static void add_uri_to_addrbook_cb (TextView *textview, guint action, void *data)
+{
+ gchar *fromname, *fromaddress;
+ RemoteURI *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
+ "menu_button");
+ if (uri == NULL)
+ return;
+
+ /* extract url */
+ fromaddress = g_strdup(uri->uri + 7);
+ /* 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 );
+
+ g_free(fromaddress);
+ g_free(fromname);
+}
+
+static void mail_to_uri_cb (TextView *textview, guint action, void *data)
+{
+ PrefsAccount *account = NULL;
+ RemoteURI *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
"menu_button");
if (uri == NULL)
return;
- gtk_clipboard_set_text(gtk_clipboard_get(GDK_NONE), uri->uri, -1);
- g_object_set_data(G_OBJECT(textview->popup_menu), "menu_button",
+ if (textview->messageview && textview->messageview->msginfo &&
+ textview->messageview->msginfo->folder) {
+ FolderItem *folder_item;
+
+ folder_item = textview->messageview->msginfo->folder;
+ if (folder_item->prefs && folder_item->prefs->enable_default_account)
+ account = account_find_from_id(folder_item->prefs->default_account);
+ }
+ compose_new(account, uri->uri + 7, NULL);
+}
+
+static void copy_mail_to_uri_cb (TextView *textview, guint action, void *data)
+{
+ RemoteURI *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
+ "menu_button");
+ if (uri == NULL)
+ return;
+
+ gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), uri->uri +7, -1);
+ gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), uri->uri +7, -1);
+ g_object_set_data(G_OBJECT(textview->mail_popup_menu), "menu_button",
NULL);
}
+