#include "account.h"
#include "mimeview.h"
#include "alertpanel.h"
+#include "menu.h"
struct _RemoteURI
{
static GdkCursor *hand_cursor = NULL;
+static GdkCursor *text_cursor = NULL;
#define TEXTVIEW_STATUSBAR_PUSH(textview, str) \
{ \
RemoteURI *uri);
static void textview_uri_list_remove_all (GSList *uri_list);
+static void open_uri_cb (TextView *textview,
+ guint action,
+ void *data);
+static void copy_uri_cb (TextView *textview,
+ guint action,
+ void *data);
-static void populate_popup(GtkTextView *textview, GtkMenu *menu,
- gpointer *dummy)
+static GtkItemFactoryEntry textview_popup_entries[] =
{
- gtk_menu_detach(menu);
-}
+ {N_("/_Open link"), NULL, open_uri_cb, 0, NULL},
+ {N_("/_Copy link location"), NULL, copy_uri_cb, 0, NULL},
+};
+
TextView *textview_create(void)
{
GtkWidget *text;
GtkTextBuffer *buffer;
GtkClipboard *clipboard;
+ GtkItemFactory *popupfactory;
+ GtkWidget *popupmenu;
+ gint n_entries;
PangoFontDescription *font_desc = NULL;
debug_print("Creating text view...\n");
gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE);
- g_signal_connect(G_OBJECT(text), "populate-popup",
- G_CALLBACK(populate_popup), NULL);
-
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
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),
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,
+ textview);
+
textview->vbox = vbox;
textview->scrolledwin = scrolledwin;
textview->text = text;
textview->body_pos = 0;
textview->show_all_headers = FALSE;
textview->last_buttonpress = GDK_NOTHING;
+ textview->popup_menu = popupmenu;
+ textview->popup_factory = popupfactory;
return textview;
}
prefered_body = NULL;
prefered_score = 0;
- for(iter = g_node_first_child(node) ; iter != NULL ;
- iter = g_node_next_sibling(iter)) {
+ for (iter = g_node_first_child(node) ; iter != NULL ;
+ iter = g_node_next_sibling(iter)) {
int score;
MimeInfo * submime;
}
}
else {
- for(iter = g_node_first_child(node) ; iter != NULL ;
- iter = g_node_next_sibling(iter)) {
+ for (iter = g_node_first_child(node) ; iter != NULL ;
+ iter = g_node_next_sibling(iter)) {
recursive_add_parts(textview, iter);
}
}
const gchar *last_dot = NULL;
const gchar *prelast_dot = NULL;
const gchar *last_tld_char = NULL;
-
+
/* the informative part of the email address (describing the name
* of the email address owner) may contain quoted parts. the
* closure stack stores the last encountered quotes. */
if (!result) return FALSE;
+ if (*(bp_ - 1) == '"' && *(ep_) == '"'
+ && *(ep_ + 1) == ' ' && *(ep_ + 2) == '<'
+ && IS_RFC822_CHAR(*(ep_ + 3))) {
+ /* this informative part with an @ in it is
+ * followed by the email address */
+ ep_ += 3;
+
+ /* go to matching '>' (or next non-rfc822 char, like \n) */
+ for (; *ep_ != '>' && *ep != '\0' && IS_RFC822_CHAR(*ep_); ep_++)
+ ;
+
+ /* include the bracket */
+ if (*ep_ == '>') ep_++;
+
+ /* include the leading quote */
+ bp_--;
+
+ *ep = ep_;
+ *bp = bp_;
+ return TRUE;
+ }
+
/* skip if it's between quotes "'alfons@proteus.demon.nl'" <alfons@proteus.demon.nl> */
- if (bp_ - 1 > start && IS_QUOTE(*(bp_ - 1)) && IS_QUOTE(*ep_))
+ if (bp_ - 1 > start && IS_QUOTE(*(bp_ - 1)) && IS_QUOTE(*ep_))
return FALSE;
/* see if this is <bracketed>; in this case we also scan for the informative part. */
*ep = ep_;
*bp = bp_;
-
+
return result;
}
for (last = head.next; last != NULL;
normal_text = last->ep, last = last->next) {
RemoteURI *uri;
-
uri = g_new(RemoteURI, 1);
if (last->bp - normal_text > 0)
gtk_text_buffer_insert_with_tags_by_name
gchar *text = NULL;
int i = 0;
gtk_text_buffer_get_end_iter(buffer, &real_end);
- text = strdup(gtk_text_buffer_get_text(buffer, &iter,
- &real_end, FALSE));
+ 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(&iter) - strlen(str) - 1;
gtk_text_buffer_get_start_iter(buffer, &real_start);
- text = strdup(gtk_text_buffer_get_text(buffer, &real_start,
- &iter, FALSE));
+ text = gtk_text_buffer_get_text(buffer, &real_start,
+ &iter, FALSE);
while (!found && i-- > 0) {
found = (strncasecmp(text+i, str, strlen(str)) == 0);
if (summaryview)
summary_pass_key_press_event(summaryview, event);
else
- textview_scroll_page(textview, FALSE);
+ textview_scroll_page
+ (textview,
+ (event->state &
+ (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0);
break;
case GDK_BackSpace:
textview_scroll_page(textview, TRUE);
break;
case GDK_Return:
- textview_scroll_one_line(textview,
- (event->state & GDK_MOD1_MASK) != 0);
+ textview_scroll_one_line
+ (textview, (event->state &
+ (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0);
break;
case GDK_Delete:
if (summaryview)
return TRUE;
}
-/*!
- *\brief Check to see if a web URL has been disguised as a different
- * URL (possible with HTML email).
- *
- *\param uri The uri to check
- *
- *\param textview The TextView the URL is contained in
- *
- *\return gboolean TRUE if the URL is ok, or if the user chose to open
- * it anyway, otherwise FALSE
- */
-static gboolean uri_security_check(RemoteURI *uri, TextView *textview)
-{
- gchar *clicked_str;
- gboolean retval = TRUE;
-
- if (g_ascii_strncasecmp(uri->uri, "http:", 5) &&
- g_ascii_strncasecmp(uri->uri, "https:", 6) &&
- g_ascii_strncasecmp(uri->uri, "www.", 4))
- return retval;
-
- clicked_str = gtk_editable_get_chars(GTK_EDITABLE(textview->text),
- uri->start,
- uri->end);
- if (clicked_str == NULL)
- return TRUE;
-
- if (strcmp(clicked_str, uri->uri) &&
- (!g_ascii_strncasecmp(clicked_str, "http:", 5) ||
- !g_ascii_strncasecmp(clicked_str, "https:", 6) ||
- !g_ascii_strncasecmp(clicked_str, "www.", 4))) {
- gchar *str;
- retval = FALSE;
-
- /* allow uri->uri == http://somewhere.com
- and clicked_str == somewhere.com */
- str = g_strconcat("http://", clicked_str, NULL);
-
- if (!g_ascii_strcasecmp(str, uri->uri))
- retval = TRUE;
- g_free(str);
- }
-
- if (retval == FALSE) {
- gchar *msg = NULL;
- AlertValue resp;
-
- msg = g_strdup_printf(_("The real URL (%s) is different from\n"
- "the apparent URL (%s). \n"
- "Open it anyway?"),
- uri->uri, clicked_str);
- resp = alertpanel_with_type(_("Warning"),
- msg,
- _("Yes"),
- _("No"),
- NULL, NULL, ALERT_WARNING);
- g_free(msg);
- if (resp == G_ALERTDEFAULT)
- retval = TRUE;
- }
- g_free(clicked_str);
- return retval;
-}
-
static gboolean textview_motion_notify(GtkWidget *widget,
GdkEventMotion *event,
TextView *textview)
TextView *textview)
{
gint wx, wy;
-
+ GdkWindow *window;
+
+ window = gtk_text_view_get_window(GTK_TEXT_VIEW(widget),
+ GTK_TEXT_WINDOW_TEXT);
+
+ /* check if occurred for the text window part */
+ if (window != event->window)
+ return FALSE;
+
gdk_window_get_pointer(widget->window, &wx, &wy, NULL);
textview_uri_update(textview, wx, wy);
window = gtk_text_view_get_window(GTK_TEXT_VIEW(textview->text),
GTK_TEXT_WINDOW_TEXT);
- gdk_window_set_cursor(window, uri ? hand_cursor : NULL);
+ gdk_window_set_cursor(window, uri ? hand_cursor : text_cursor);
TEXTVIEW_STATUSBAR_POP(textview);
{
GtkTextIter _start_iter, _end_iter;
- _start_iter = *iter;
- if(!gtk_text_iter_backward_to_tag_toggle(&_start_iter, tag)) {
- debug_print("Can't find start.");
+ _end_iter = *iter;
+ if (!gtk_text_iter_forward_to_tag_toggle(&_end_iter, tag)) {
+ debug_print("Can't find end");
return FALSE;
}
- _end_iter = *iter;
- if(!gtk_text_iter_forward_to_tag_toggle(&_end_iter, tag)) {
- debug_print("Can't find end");
+ _start_iter = _end_iter;
+ if (!gtk_text_iter_backward_to_tag_toggle(&_start_iter, tag)) {
+ debug_print("Can't find start.");
return FALSE;
}
GtkTextIter *start_iter,
GtkTextIter *end_iter)
{
- gint start_pos, end_pos;
+ gint start_pos, end_pos, cur_pos;
RemoteURI *uri = NULL;
GSList *cur;
start_pos = gtk_text_iter_get_offset(start_iter);
end_pos = gtk_text_iter_get_offset(end_iter);
+ cur_pos = gtk_text_iter_get_offset(iter);
for (cur = textview->uri_list; cur != NULL; cur = cur->next) {
RemoteURI *uri_ = (RemoteURI *)cur->data;
-
if (start_pos == uri_->start &&
end_pos == uri_->end) {
uri = uri_;
break;
- }
+ } else if (start_pos == uri_->start ||
+ end_pos == uri_->end) {
+ /* in case of contiguous links, textview_get_uri_range
+ * returns a broader range (start of 1st link to end
+ * of last link).
+ * In that case, correct link is the one covering
+ * current iter.
+ */
+ if (uri_->start <= cur_pos && cur_pos <= uri_->end) {
+ uri = uri_;
+ break;
+ }
+ }
}
return uri;
}
return TRUE;
} else {
- if (textview_uri_security_check(textview, uri) == TRUE)
- open_uri(uri->uri,
- prefs_common.uri_cmd);
+ 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),
+ "menu_button", uri);
+ gtk_menu_popup(GTK_MENU(textview->popup_menu),
+ NULL, NULL, NULL, NULL,
+ bevent->button, bevent->time);
+ }
return TRUE;
}
}
{
gchar *visible_str;
gboolean retval = TRUE;
+ GtkTextBuffer *buffer;
+ GtkTextIter start, end;
if (is_uri_string(uri->uri) == FALSE)
return TRUE;
- visible_str = gtk_editable_get_chars(GTK_EDITABLE(textview->text),
- uri->start, uri->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);
+
+ visible_str = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
+
if (visible_str == NULL)
return TRUE;
g_slist_free(uri_list);
}
+
+static void open_uri_cb (TextView *textview, guint action, void *data)
+{
+ RemoteURI *uri = g_object_get_data(G_OBJECT(textview->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",
+ NULL);
+}
+
+static void copy_uri_cb (TextView *textview, guint action, void *data)
+{
+ RemoteURI *uri = g_object_get_data(G_OBJECT(textview->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",
+ NULL);
+}