2001-04-19 14:21:46 +02:00
|
|
|
/*
|
|
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
2007-01-03 06:42:43 +01:00
|
|
|
* Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
|
2001-04-19 14:21:46 +02:00
|
|
|
*
|
|
|
|
* 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
|
2007-07-11 18:38:12 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-04-19 14:21:46 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-11 18:38:12 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2001-04-19 14:21:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
2005-02-10 13:06:07 +01:00
|
|
|
#include <glib/gi18n.h>
|
2001-04-19 14:21:46 +02:00
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
#include <gtk/gtkvbox.h>
|
|
|
|
#include <gtk/gtkscrolledwindow.h>
|
|
|
|
#include <gtk/gtksignal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2006-07-07 12:50:30 +02:00
|
|
|
#include <errno.h>
|
2006-09-13 12:31:49 +02:00
|
|
|
#if HAVE_SYS_WAIT_H
|
2006-06-27 14:46:42 +02:00
|
|
|
#include <sys/wait.h>
|
2006-09-13 12:31:49 +02:00
|
|
|
#endif
|
2005-10-20 19:49:21 +02:00
|
|
|
#if HAVE_LIBCOMPFACE
|
|
|
|
# include <compface.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_LIBCOMPFACE
|
|
|
|
#define XPM_XFACE_HEIGHT (HEIGHT + 3) /* 3 = 1 header + 2 colors */
|
|
|
|
#endif
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "summaryview.h"
|
|
|
|
#include "procheader.h"
|
|
|
|
#include "prefs_common.h"
|
|
|
|
#include "codeconv.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "gtkutils.h"
|
|
|
|
#include "procmime.h"
|
|
|
|
#include "html.h"
|
2001-11-28 23:48:06 +01:00
|
|
|
#include "enriched.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
#include "compose.h"
|
2001-04-28 20:36:15 +02:00
|
|
|
#include "addressbook.h"
|
2001-05-06 22:06:56 +02:00
|
|
|
#include "displayheader.h"
|
2001-12-26 12:02:33 +01:00
|
|
|
#include "account.h"
|
2002-09-22 12:53:49 +02:00
|
|
|
#include "mimeview.h"
|
2004-01-12 22:28:31 +01:00
|
|
|
#include "alertpanel.h"
|
2004-11-19 11:39:01 +01:00
|
|
|
#include "menu.h"
|
2005-04-01 10:16:46 +02:00
|
|
|
#include "image_viewer.h"
|
|
|
|
#include "filesel.h"
|
2006-02-05 18:56:40 +01:00
|
|
|
#include "base64.h"
|
2006-08-18 10:36:38 +02:00
|
|
|
#include "inputdialog.h"
|
2006-08-23 19:18:36 +02:00
|
|
|
#include "timing.h"
|
2007-07-02 18:35:40 +02:00
|
|
|
#include "tags.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
static GdkColor quote_colors[3] = {
|
|
|
|
{(gulong)0, (gushort)0, (gushort)0, (gushort)0},
|
|
|
|
{(gulong)0, (gushort)0, (gushort)0, (gushort)0},
|
|
|
|
{(gulong)0, (gushort)0, (gushort)0, (gushort)0}
|
|
|
|
};
|
|
|
|
|
2006-04-10 21:16:31 +02:00
|
|
|
static GdkColor quote_bgcolors[3] = {
|
|
|
|
{(gulong)0, (gushort)0, (gushort)0, (gushort)0},
|
|
|
|
{(gulong)0, (gushort)0, (gushort)0, (gushort)0},
|
|
|
|
{(gulong)0, (gushort)0, (gushort)0, (gushort)0}
|
|
|
|
};
|
2002-09-03 16:45:07 +02:00
|
|
|
static GdkColor signature_color = {
|
|
|
|
(gulong)0,
|
|
|
|
(gushort)0x7fff,
|
|
|
|
(gushort)0x7fff,
|
|
|
|
(gushort)0x7fff
|
|
|
|
};
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static GdkColor uri_color = {
|
|
|
|
(gulong)0,
|
|
|
|
(gushort)0,
|
|
|
|
(gushort)0,
|
|
|
|
(gushort)0
|
|
|
|
};
|
|
|
|
|
|
|
|
static GdkColor emphasis_color = {
|
|
|
|
(gulong)0,
|
|
|
|
(gushort)0,
|
|
|
|
(gushort)0,
|
2007-08-06 23:19:29 +02:00
|
|
|
(gushort)0
|
2001-04-19 14:21:46 +02:00
|
|
|
};
|
|
|
|
|
2004-11-06 10:39:33 +01:00
|
|
|
static GdkCursor *hand_cursor = NULL;
|
2004-11-08 12:06:35 +01:00
|
|
|
static GdkCursor *text_cursor = NULL;
|
2006-03-18 20:16:07 +01:00
|
|
|
static GdkCursor *watch_cursor= NULL;
|
2004-11-06 10:39:33 +01:00
|
|
|
|
2005-09-21 19:22:10 +02:00
|
|
|
#define TEXTVIEW_STATUSBAR_PUSH(textview, str) \
|
|
|
|
{ if (textview->messageview->statusbar) \
|
2004-05-10 12:22:28 +02:00
|
|
|
gtk_statusbar_push(GTK_STATUSBAR(textview->messageview->statusbar), \
|
|
|
|
textview->messageview->statusbar_cid, str); \
|
|
|
|
}
|
|
|
|
|
2005-09-21 19:22:10 +02:00
|
|
|
#define TEXTVIEW_STATUSBAR_POP(textview) \
|
|
|
|
{ if (textview->messageview->statusbar) \
|
2004-05-10 12:22:28 +02:00
|
|
|
gtk_statusbar_pop(GTK_STATUSBAR(textview->messageview->statusbar), \
|
|
|
|
textview->messageview->statusbar_cid); \
|
|
|
|
}
|
|
|
|
|
2001-11-28 23:48:06 +01:00
|
|
|
static void textview_show_ertf (TextView *textview,
|
|
|
|
FILE *fp,
|
|
|
|
CodeConverter *conv);
|
2002-03-02 11:02:42 +01:00
|
|
|
static void textview_add_part (TextView *textview,
|
2004-01-12 22:28:31 +01:00
|
|
|
MimeInfo *mimeinfo);
|
2002-05-18 17:22:17 +02:00
|
|
|
static void textview_add_parts (TextView *textview,
|
2004-01-12 22:28:31 +01:00
|
|
|
MimeInfo *mimeinfo);
|
2002-03-02 11:02:42 +01:00
|
|
|
static void textview_write_body (TextView *textview,
|
2004-10-02 18:33:17 +02:00
|
|
|
MimeInfo *mimeinfo);
|
2001-04-19 14:21:46 +02:00
|
|
|
static void textview_show_html (TextView *textview,
|
|
|
|
FILE *fp,
|
|
|
|
CodeConverter *conv);
|
2004-02-21 12:01:01 +01:00
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static void textview_write_line (TextView *textview,
|
|
|
|
const gchar *str,
|
2006-10-06 18:55:13 +02:00
|
|
|
CodeConverter *conv,
|
|
|
|
gboolean do_quote_folding);
|
2003-03-13 12:12:58 +01:00
|
|
|
static void textview_write_link (TextView *textview,
|
2001-10-29 16:42:21 +01:00
|
|
|
const gchar *str,
|
2003-03-13 12:12:58 +01:00
|
|
|
const gchar *uri,
|
2001-10-29 16:42:21 +01:00
|
|
|
CodeConverter *conv);
|
2004-02-21 12:01:01 +01:00
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static GPtrArray *textview_scan_header (TextView *textview,
|
|
|
|
FILE *fp);
|
|
|
|
static void textview_show_header (TextView *textview,
|
|
|
|
GPtrArray *headers);
|
|
|
|
|
2004-11-06 10:39:33 +01:00
|
|
|
static gint textview_key_pressed (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
TextView *textview);
|
|
|
|
static gboolean textview_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *motion,
|
|
|
|
TextView *textview);
|
2005-02-21 11:18:27 +01:00
|
|
|
static gboolean textview_leave_notify (GtkWidget *widget,
|
2004-11-06 10:39:33 +01:00
|
|
|
GdkEventCrossing *event,
|
2005-02-21 11:18:27 +01:00
|
|
|
TextView *textview);
|
2004-11-06 10:39:33 +01:00
|
|
|
static gboolean textview_visibility_notify (GtkWidget *widget,
|
|
|
|
GdkEventVisibility *event,
|
|
|
|
TextView *textview);
|
|
|
|
static void textview_uri_update (TextView *textview,
|
|
|
|
gint x,
|
|
|
|
gint y);
|
|
|
|
static gboolean textview_get_uri_range (TextView *textview,
|
|
|
|
GtkTextIter *iter,
|
|
|
|
GtkTextTag *tag,
|
|
|
|
GtkTextIter *start_iter,
|
|
|
|
GtkTextIter *end_iter);
|
2006-08-02 18:30:28 +02:00
|
|
|
static ClickableText *textview_get_uri_from_range (TextView *textview,
|
2004-11-06 10:39:33 +01:00
|
|
|
GtkTextIter *iter,
|
|
|
|
GtkTextTag *tag,
|
|
|
|
GtkTextIter *start_iter,
|
|
|
|
GtkTextIter *end_iter);
|
2006-08-02 18:30:28 +02:00
|
|
|
static ClickableText *textview_get_uri (TextView *textview,
|
2004-11-06 10:39:33 +01:00
|
|
|
GtkTextIter *iter,
|
|
|
|
GtkTextTag *tag);
|
|
|
|
static gboolean textview_uri_button_pressed (GtkTextTag *tag,
|
|
|
|
GObject *obj,
|
|
|
|
GdkEvent *event,
|
|
|
|
GtkTextIter *iter,
|
|
|
|
TextView *textview);
|
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
static void textview_uri_list_remove_all (GSList *uri_list);
|
|
|
|
|
2006-08-03 08:42:12 +02:00
|
|
|
static void textview_toggle_quote (TextView *textview,
|
2006-09-29 18:57:15 +02:00
|
|
|
GSList *start_list,
|
2006-08-03 08:42:12 +02:00
|
|
|
ClickableText *uri,
|
|
|
|
gboolean expand_only);
|
2006-08-02 18:30:28 +02:00
|
|
|
|
2004-11-19 11:39:01 +01:00
|
|
|
static void open_uri_cb (TextView *textview,
|
|
|
|
guint action,
|
|
|
|
void *data);
|
|
|
|
static void copy_uri_cb (TextView *textview,
|
|
|
|
guint action,
|
|
|
|
void *data);
|
2005-02-09 14:15:30 +01:00
|
|
|
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);
|
2005-02-12 13:45:29 +01:00
|
|
|
static void copy_mail_to_uri_cb (TextView *textview,
|
|
|
|
guint action,
|
|
|
|
void *data);
|
2005-04-01 10:16:46 +02:00
|
|
|
static void save_file_cb (TextView *textview,
|
|
|
|
guint action,
|
|
|
|
void *data);
|
2005-08-22 12:36:39 +02:00
|
|
|
static void open_image_cb (TextView *textview,
|
|
|
|
guint action,
|
|
|
|
void *data);
|
2005-02-09 14:15:30 +01:00
|
|
|
|
|
|
|
static GtkItemFactoryEntry textview_link_popup_entries[] =
|
2004-01-19 20:26:31 +01:00
|
|
|
{
|
2005-06-24 07:36:26 +02:00
|
|
|
{N_("/_Open with Web browser"), NULL, open_uri_cb, 0, NULL},
|
|
|
|
{N_("/Copy this _link"), NULL, copy_uri_cb, 0, NULL},
|
2004-11-19 11:39:01 +01:00
|
|
|
};
|
|
|
|
|
2005-02-09 14:15:30 +01:00
|
|
|
static GtkItemFactoryEntry textview_mail_popup_entries[] =
|
|
|
|
{
|
2005-06-24 07:36:26 +02:00
|
|
|
{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},
|
2005-02-09 14:15:30 +01:00
|
|
|
};
|
|
|
|
|
2005-04-01 10:16:46 +02:00
|
|
|
static GtkItemFactoryEntry textview_file_popup_entries[] =
|
|
|
|
{
|
2005-08-22 12:36:39 +02:00
|
|
|
{N_("/_Open image"), NULL, open_image_cb, 0, NULL},
|
|
|
|
{N_("/_Save image..."), NULL, save_file_cb, 0, NULL},
|
2005-04-01 10:16:46 +02:00
|
|
|
};
|
|
|
|
|
2005-10-20 19:49:21 +02:00
|
|
|
static void scrolled_cb (GtkAdjustment *adj, TextView *textview)
|
|
|
|
{
|
2006-02-06 18:56:35 +01:00
|
|
|
#ifndef WIDTH
|
|
|
|
# define WIDTH 48
|
|
|
|
# define HEIGHT 48
|
|
|
|
#endif
|
2005-10-20 19:49:21 +02:00
|
|
|
if (textview->image) {
|
2005-10-21 19:31:15 +02:00
|
|
|
gint x, y, x1;
|
|
|
|
x1 = textview->text->allocation.width - WIDTH - 5;
|
2005-10-20 19:49:21 +02:00
|
|
|
gtk_text_view_buffer_to_window_coords(
|
|
|
|
GTK_TEXT_VIEW(textview->text),
|
2005-10-21 19:31:15 +02:00
|
|
|
GTK_TEXT_WINDOW_TEXT, x1, 5, &x, &y);
|
2005-10-20 19:49:21 +02:00
|
|
|
gtk_text_view_move_child(GTK_TEXT_VIEW(textview->text),
|
2005-10-21 19:31:15 +02:00
|
|
|
textview->image, x1, y);
|
2005-10-20 19:49:21 +02:00
|
|
|
}
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-10-21 19:31:15 +02:00
|
|
|
static void textview_size_allocate_cb (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
scrolled_cb(NULL, (TextView *)data);
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
TextView *textview_create(void)
|
|
|
|
{
|
|
|
|
TextView *textview;
|
|
|
|
GtkWidget *vbox;
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkWidget *scrolledwin;
|
|
|
|
GtkWidget *text;
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkClipboard *clipboard;
|
2005-04-01 10:16:46 +02:00
|
|
|
GtkItemFactory *link_popupfactory, *mail_popupfactory, *file_popupfactory;
|
|
|
|
GtkWidget *link_popupmenu, *mail_popupmenu, *file_popupmenu;
|
2005-10-20 19:49:21 +02:00
|
|
|
GtkAdjustment *adj;
|
2004-11-19 11:39:01 +01:00
|
|
|
gint n_entries;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-08-15 09:38:17 +02:00
|
|
|
debug_print("Creating text view...\n");
|
2001-04-19 14:21:46 +02:00
|
|
|
textview = g_new0(TextView, 1);
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
scrolledwin = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
|
2005-02-10 13:06:07 +01:00
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2004-02-08 20:52:32 +01:00
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
|
|
|
|
GTK_SHADOW_IN);
|
2005-01-29 17:53:23 +01:00
|
|
|
gtk_widget_set_size_request
|
|
|
|
(scrolledwin, prefs_common.mainview_width, -1);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-01-06 13:21:36 +01:00
|
|
|
/* create GtkSText widgets for single-byte and multi-byte character */
|
2003-10-05 12:10:30 +02:00
|
|
|
text = gtk_text_view_new();
|
2004-11-06 10:39:33 +01:00
|
|
|
gtk_widget_add_events(text, GDK_LEAVE_NOTIFY_MASK);
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_widget_show(text);
|
|
|
|
gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
|
2004-10-21 14:14:46 +02:00
|
|
|
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
|
2004-01-19 20:26:31 +01:00
|
|
|
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE);
|
2005-01-29 17:53:23 +01:00
|
|
|
gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
|
|
|
|
gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
|
2003-10-05 12:10:30 +02:00
|
|
|
|
|
|
|
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
|
|
|
|
clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
|
|
|
|
gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
|
|
|
|
|
|
|
|
gtk_widget_ensure_style(text);
|
|
|
|
|
|
|
|
gtk_widget_ref(scrolledwin);
|
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(scrolledwin), text);
|
|
|
|
|
2005-02-21 11:18:27 +01:00
|
|
|
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);
|
2005-10-20 19:49:21 +02:00
|
|
|
adj = gtk_scrolled_window_get_vadjustment(
|
|
|
|
GTK_SCROLLED_WINDOW(scrolledwin));
|
|
|
|
g_signal_connect(G_OBJECT(adj), "value-changed",
|
|
|
|
G_CALLBACK(scrolled_cb), textview);
|
2005-10-21 19:31:15 +02:00
|
|
|
g_signal_connect(G_OBJECT(text), "size_allocate",
|
|
|
|
G_CALLBACK(textview_size_allocate_cb),
|
|
|
|
textview);
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
|
|
|
|
gtk_widget_show(scrolledwin);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
vbox = gtk_vbox_new(FALSE, 0);
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-02-25 10:25:17 +01:00
|
|
|
gtk_widget_show(vbox);
|
|
|
|
|
2005-02-09 14:15:30 +01:00
|
|
|
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,
|
2004-11-19 11:39:01 +01:00
|
|
|
textview);
|
|
|
|
|
2005-02-09 14:15:30 +01:00
|
|
|
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);
|
|
|
|
|
2005-04-01 10:16:46 +02:00
|
|
|
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);
|
|
|
|
|
2005-02-09 14:15:30 +01:00
|
|
|
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;
|
2005-04-01 10:16:46 +02:00
|
|
|
textview->file_popup_menu = file_popupmenu;
|
|
|
|
textview->file_popup_factory = file_popupfactory;
|
2006-02-05 18:56:40 +01:00
|
|
|
textview->image = NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
return textview;
|
|
|
|
}
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
static void textview_create_tags(GtkTextView *text, TextView *textview)
|
|
|
|
{
|
2005-02-03 08:47:34 +01:00
|
|
|
GtkTextBuffer *buffer;
|
2006-08-02 18:30:28 +02:00
|
|
|
GtkTextTag *tag, *qtag;
|
2007-07-02 18:35:40 +02:00
|
|
|
static GdkColor yellow, black;
|
|
|
|
static gboolean color_init = FALSE;
|
2005-02-03 08:47:34 +01:00
|
|
|
static PangoFontDescription *font_desc, *bold_font_desc;
|
2005-08-01 19:18:42 +02:00
|
|
|
|
2007-07-02 18:35:40 +02:00
|
|
|
if (!color_init) {
|
|
|
|
gdk_color_parse("#f5f6be", &yellow);
|
|
|
|
gdk_color_parse("#000000", &black);
|
|
|
|
color_init = gdk_colormap_alloc_color(
|
|
|
|
gdk_colormap_get_system(), &yellow, FALSE, TRUE);
|
|
|
|
color_init &= gdk_colormap_alloc_color(
|
|
|
|
gdk_colormap_get_system(), &black, FALSE, TRUE);
|
|
|
|
}
|
|
|
|
|
2005-02-03 08:47:34 +01:00
|
|
|
if (!font_desc)
|
|
|
|
font_desc = pango_font_description_from_string
|
|
|
|
(NORMAL_FONT);
|
|
|
|
|
|
|
|
if (!bold_font_desc) {
|
|
|
|
bold_font_desc = pango_font_description_from_string
|
2005-08-31 12:15:44 +02:00
|
|
|
(NORMAL_FONT);
|
2005-02-03 08:47:34 +01:00
|
|
|
pango_font_description_set_weight
|
|
|
|
(bold_font_desc, PANGO_WEIGHT_BOLD);
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = gtk_text_view_get_buffer(text);
|
2003-10-05 12:10:30 +02:00
|
|
|
|
|
|
|
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,
|
2005-02-03 08:47:34 +01:00
|
|
|
"font-desc", font_desc,
|
2006-03-27 18:45:49 +02:00
|
|
|
"left-margin", 3,
|
2003-10-05 12:10:30 +02:00
|
|
|
"left-margin-set", TRUE,
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_create_tag(buffer, "header_title",
|
2005-02-03 08:47:34 +01:00
|
|
|
"font-desc", bold_font_desc,
|
2003-10-05 12:10:30 +02:00
|
|
|
NULL);
|
2006-09-13 19:25:48 +02:00
|
|
|
tag = gtk_text_buffer_create_tag(buffer, "hlink",
|
|
|
|
"pixels-above-lines", 0,
|
|
|
|
"pixels-above-lines-set", TRUE,
|
|
|
|
"pixels-below-lines", 0,
|
|
|
|
"pixels-below-lines-set", TRUE,
|
|
|
|
"font-desc", font_desc,
|
|
|
|
"left-margin", 3,
|
|
|
|
"left-margin-set", TRUE,
|
|
|
|
"foreground-gdk", &uri_color,
|
|
|
|
NULL);
|
|
|
|
g_signal_connect(G_OBJECT(tag), "event",
|
|
|
|
G_CALLBACK(textview_uri_button_pressed), textview);
|
2006-04-10 21:16:31 +02:00
|
|
|
if (prefs_common.enable_bgcolor) {
|
|
|
|
gtk_text_buffer_create_tag(buffer, "quote0",
|
|
|
|
"foreground-gdk", "e_colors[0],
|
|
|
|
"paragraph-background-gdk", "e_bgcolors[0],
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_create_tag(buffer, "quote1",
|
|
|
|
"foreground-gdk", "e_colors[1],
|
|
|
|
"paragraph-background-gdk", "e_bgcolors[1],
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_create_tag(buffer, "quote2",
|
|
|
|
"foreground-gdk", "e_colors[2],
|
|
|
|
"paragraph-background-gdk", "e_bgcolors[2],
|
|
|
|
NULL);
|
|
|
|
} else {
|
|
|
|
gtk_text_buffer_create_tag(buffer, "quote0",
|
|
|
|
"foreground-gdk", "e_colors[0],
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_create_tag(buffer, "quote1",
|
|
|
|
"foreground-gdk", "e_colors[1],
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_create_tag(buffer, "quote2",
|
|
|
|
"foreground-gdk", "e_colors[2],
|
|
|
|
NULL);
|
|
|
|
}
|
2007-07-02 18:35:40 +02:00
|
|
|
#if GTK_CHECK_VERSION(2, 8, 0)
|
|
|
|
gtk_text_buffer_create_tag(buffer, "tags",
|
|
|
|
"foreground-gdk", &black,
|
|
|
|
"paragraph-background-gdk", &yellow,
|
|
|
|
NULL);
|
|
|
|
#else
|
|
|
|
gtk_text_buffer_create_tag(buffer, "tags",
|
|
|
|
"foreground-gdk", &emphasis_color,
|
|
|
|
NULL);
|
|
|
|
#endif
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_text_buffer_create_tag(buffer, "emphasis",
|
2006-04-10 21:16:31 +02:00
|
|
|
"foreground-gdk", &emphasis_color,
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_create_tag(buffer, "signature",
|
|
|
|
"foreground-gdk", &signature_color,
|
|
|
|
NULL);
|
|
|
|
tag = gtk_text_buffer_create_tag(buffer, "link",
|
|
|
|
"foreground-gdk", &uri_color,
|
|
|
|
NULL);
|
2006-08-02 18:30:28 +02:00
|
|
|
qtag = gtk_text_buffer_create_tag(buffer, "qlink",
|
|
|
|
NULL);
|
2004-11-06 10:39:33 +01:00
|
|
|
gtk_text_buffer_create_tag(buffer, "link-hover",
|
2006-04-10 21:16:31 +02:00
|
|
|
"underline", PANGO_UNDERLINE_SINGLE,
|
|
|
|
NULL);
|
2006-08-02 18:30:28 +02:00
|
|
|
g_signal_connect(G_OBJECT(qtag), "event",
|
|
|
|
G_CALLBACK(textview_uri_button_pressed), textview);
|
2005-08-01 19:18:42 +02:00
|
|
|
g_signal_connect(G_OBJECT(tag), "event",
|
2003-10-05 12:10:30 +02:00
|
|
|
G_CALLBACK(textview_uri_button_pressed), textview);
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
void textview_init(TextView *textview)
|
|
|
|
{
|
2005-02-10 13:06:07 +01:00
|
|
|
if (!hand_cursor)
|
|
|
|
hand_cursor = gdk_cursor_new(GDK_HAND2);
|
|
|
|
if (!text_cursor)
|
|
|
|
text_cursor = gdk_cursor_new(GDK_XTERM);
|
2006-03-18 20:16:07 +01:00
|
|
|
if (!watch_cursor)
|
|
|
|
watch_cursor = gdk_cursor_new(GDK_WATCH);
|
2005-02-10 13:06:07 +01:00
|
|
|
|
2005-05-19 11:16:26 +02:00
|
|
|
textview_reflect_prefs(textview);
|
2002-02-04 10:56:44 +01:00
|
|
|
textview_set_all_headers(textview, FALSE);
|
2001-04-19 14:21:46 +02:00
|
|
|
textview_set_font(textview, NULL);
|
2003-10-05 12:10:30 +02:00
|
|
|
textview_create_tags(GTK_TEXT_VIEW(textview->text), textview);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2006-04-16 22:56:16 +02:00
|
|
|
#if GTK_CHECK_VERSION(2, 8, 0)
|
|
|
|
#define CHANGE_TAG_COLOR(tagname, colorfg, colorbg) { \
|
2005-08-01 19:18:42 +02:00
|
|
|
tag = gtk_text_tag_table_lookup(tags, tagname); \
|
2006-04-16 22:56:16 +02:00
|
|
|
if (tag) \
|
2006-04-10 21:16:31 +02:00
|
|
|
g_object_set(G_OBJECT(tag), "foreground-gdk", colorfg, "paragraph-background-gdk", colorbg, NULL); \
|
2006-04-16 22:56:16 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define CHANGE_TAG_COLOR(tagname, colorfg, colorbg) { \
|
|
|
|
tag = gtk_text_tag_table_lookup(tags, tagname); \
|
|
|
|
if (tag) \
|
2006-04-13 22:44:45 +02:00
|
|
|
g_object_set(G_OBJECT(tag), "foreground-gdk", colorfg, NULL); \
|
2006-04-16 22:56:16 +02:00
|
|
|
}
|
|
|
|
#endif
|
2005-08-01 19:18:42 +02:00
|
|
|
|
|
|
|
static void textview_update_message_colors(TextView *textview)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
GdkColor black = {0, 0, 0, 0};
|
2005-08-01 19:18:42 +02:00
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text));
|
|
|
|
|
|
|
|
GtkTextTagTable *tags = gtk_text_buffer_get_tag_table(buffer);
|
|
|
|
GtkTextTag *tag = NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2006-04-10 21:16:31 +02:00
|
|
|
quote_bgcolors[0] = quote_bgcolors[1] = quote_bgcolors[2] = black;
|
|
|
|
quote_colors[0] = quote_colors[1] = quote_colors[2] =
|
|
|
|
uri_color = emphasis_color = signature_color = black;
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
if (prefs_common.enable_color) {
|
|
|
|
/* grab the quote colors, converting from an int to a GdkColor */
|
|
|
|
gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
|
|
|
|
"e_colors[0]);
|
|
|
|
gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
|
|
|
|
"e_colors[1]);
|
|
|
|
gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
|
|
|
|
"e_colors[2]);
|
|
|
|
gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
|
|
|
|
&uri_color);
|
2002-09-04 09:34:15 +02:00
|
|
|
gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
|
|
|
|
&signature_color);
|
2007-08-06 23:19:29 +02:00
|
|
|
gtkut_convert_int_to_gdk_color(prefs_common.emphasis_col,
|
|
|
|
&emphasis_color);
|
2006-04-10 21:16:31 +02:00
|
|
|
}
|
|
|
|
if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
|
|
|
|
gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
|
|
|
|
"e_bgcolors[0]);
|
|
|
|
gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
|
|
|
|
"e_bgcolors[1]);
|
|
|
|
gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
|
|
|
|
"e_bgcolors[2]);
|
|
|
|
CHANGE_TAG_COLOR("quote0", "e_colors[0], "e_bgcolors[0]);
|
|
|
|
CHANGE_TAG_COLOR("quote1", "e_colors[1], "e_bgcolors[1]);
|
|
|
|
CHANGE_TAG_COLOR("quote2", "e_colors[2], "e_bgcolors[2]);
|
2001-04-19 14:21:46 +02:00
|
|
|
} else {
|
2006-04-10 21:16:31 +02:00
|
|
|
CHANGE_TAG_COLOR("quote0", "e_colors[0], NULL);
|
|
|
|
CHANGE_TAG_COLOR("quote1", "e_colors[1], NULL);
|
|
|
|
CHANGE_TAG_COLOR("quote2", "e_colors[2], NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
2005-08-01 19:18:42 +02:00
|
|
|
|
2006-04-10 21:16:31 +02:00
|
|
|
CHANGE_TAG_COLOR("emphasis", &emphasis_color, NULL);
|
|
|
|
CHANGE_TAG_COLOR("signature", &signature_color, NULL);
|
|
|
|
CHANGE_TAG_COLOR("link", &uri_color, NULL);
|
|
|
|
CHANGE_TAG_COLOR("link-hover", &uri_color, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
2005-08-01 19:18:42 +02:00
|
|
|
#undef CHANGE_TAG_COLOR
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-05-19 11:16:26 +02:00
|
|
|
void textview_reflect_prefs(TextView *textview)
|
|
|
|
{
|
2005-08-01 19:18:42 +02:00
|
|
|
textview_set_font(textview, NULL);
|
|
|
|
textview_update_message_colors(textview);
|
2005-05-19 11:16:26 +02:00
|
|
|
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textview->text),
|
|
|
|
prefs_common.textview_cursor_visible);
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
void textview_show_message(TextView *textview, MimeInfo *mimeinfo,
|
|
|
|
const gchar *file)
|
|
|
|
{
|
2006-09-04 18:56:18 +02:00
|
|
|
textview->loading = TRUE;
|
|
|
|
textview->stop_loading = FALSE;
|
|
|
|
|
2002-03-02 11:02:42 +01:00
|
|
|
textview_clear(textview);
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
textview_add_parts(textview, mimeinfo);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
textview_set_position(textview, 0);
|
2006-09-04 18:56:18 +02:00
|
|
|
|
|
|
|
textview->loading = FALSE;
|
|
|
|
textview->stop_loading = FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
|
|
|
|
{
|
2006-09-23 15:31:18 +02:00
|
|
|
START_TIMING("");
|
2001-04-19 14:21:46 +02:00
|
|
|
g_return_if_fail(mimeinfo != NULL);
|
|
|
|
g_return_if_fail(fp != NULL);
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
if ((mimeinfo->type == MIMETYPE_MULTIPART) ||
|
2004-10-26 12:43:50 +02:00
|
|
|
((mimeinfo->type == MIMETYPE_MESSAGE) && !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822"))) {
|
2006-09-04 18:56:18 +02:00
|
|
|
textview->loading = TRUE;
|
|
|
|
textview->stop_loading = FALSE;
|
|
|
|
|
2002-05-18 17:22:17 +02:00
|
|
|
textview_clear(textview);
|
2004-01-12 22:28:31 +01:00
|
|
|
textview_add_parts(textview, mimeinfo);
|
2006-09-04 18:56:18 +02:00
|
|
|
|
|
|
|
textview->loading = FALSE;
|
|
|
|
textview->stop_loading = FALSE;
|
2006-08-23 19:18:36 +02:00
|
|
|
END_TIMING();
|
2002-05-18 17:22:17 +02:00
|
|
|
return;
|
|
|
|
}
|
2006-09-04 18:56:18 +02:00
|
|
|
textview->loading = TRUE;
|
|
|
|
textview->stop_loading = FALSE;
|
2002-03-03 10:32:58 +01:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0)
|
|
|
|
perror("fseek");
|
2004-08-31 11:56:41 +02:00
|
|
|
|
2002-05-25 07:46:08 +02:00
|
|
|
textview_clear(textview);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
if (mimeinfo->type == MIMETYPE_MULTIPART)
|
|
|
|
textview_add_parts(textview, mimeinfo);
|
2002-05-18 17:22:17 +02:00
|
|
|
else
|
2004-10-02 18:33:17 +02:00
|
|
|
textview_write_body(textview, mimeinfo);
|
2006-09-04 18:56:18 +02:00
|
|
|
|
|
|
|
textview->loading = FALSE;
|
|
|
|
textview->stop_loading = FALSE;
|
2006-08-23 19:18:36 +02:00
|
|
|
END_TIMING();
|
2002-03-02 11:02:42 +01:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
|
2002-03-02 11:02:42 +01:00
|
|
|
{
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text;
|
|
|
|
GtkTextBuffer *buffer;
|
2005-04-01 10:16:46 +02:00
|
|
|
GtkTextIter iter, start_iter;
|
2002-03-02 11:02:42 +01:00
|
|
|
gchar buf[BUFFSIZE];
|
|
|
|
GPtrArray *headers = NULL;
|
2004-01-12 22:28:31 +01:00
|
|
|
const gchar *name;
|
2004-10-12 11:45:18 +02:00
|
|
|
gchar *content_type;
|
2004-01-12 22:28:31 +01:00
|
|
|
gint charcount;
|
2006-09-23 15:31:18 +02:00
|
|
|
START_TIMING("");
|
2002-03-02 11:02:42 +01:00
|
|
|
|
|
|
|
g_return_if_fail(mimeinfo != NULL);
|
2003-10-05 12:10:30 +02:00
|
|
|
text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
buffer = gtk_text_view_get_buffer(text);
|
2004-01-12 22:28:31 +01:00
|
|
|
charcount = gtk_text_buffer_get_char_count(buffer);
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_text_buffer_get_end_iter(buffer, &iter);
|
2006-10-11 10:47:22 +02:00
|
|
|
|
2006-09-04 18:56:18 +02:00
|
|
|
if (textview->stop_loading) {
|
|
|
|
return;
|
|
|
|
}
|
2006-08-23 19:18:36 +02:00
|
|
|
if (mimeinfo->type == MIMETYPE_MULTIPART) {
|
|
|
|
END_TIMING();
|
|
|
|
return;
|
|
|
|
}
|
2002-01-28 00:21:17 +01:00
|
|
|
|
2007-04-24 12:05:01 +02:00
|
|
|
textview->prev_quote_level = -1;
|
2006-10-11 10:47:22 +02:00
|
|
|
|
2004-10-26 12:43:50 +02:00
|
|
|
if ((mimeinfo->type == MIMETYPE_MESSAGE) && !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
|
2004-01-12 22:28:31 +01:00
|
|
|
FILE *fp;
|
2002-01-28 00:21:17 +01:00
|
|
|
|
2005-08-19 11:30:30 +02:00
|
|
|
fp = g_fopen(mimeinfo->data.filename, "rb");
|
2004-01-12 22:28:31 +01:00
|
|
|
fseek(fp, mimeinfo->offset, SEEK_SET);
|
2002-03-02 11:02:42 +01:00
|
|
|
headers = textview_scan_header(textview, fp);
|
2002-03-03 10:32:58 +01:00
|
|
|
if (headers) {
|
2004-01-12 22:28:31 +01:00
|
|
|
if (charcount > 0)
|
|
|
|
gtk_text_buffer_insert(buffer, &iter, "\n", 1);
|
2002-03-03 10:32:58 +01:00
|
|
|
textview_show_header(textview, headers);
|
|
|
|
procheader_header_array_destroy(headers);
|
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
fclose(fp);
|
2006-08-23 19:18:36 +02:00
|
|
|
END_TIMING();
|
2002-03-03 10:32:58 +01:00
|
|
|
return;
|
2002-03-02 11:02:42 +01:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
name = procmime_mimeinfo_get_parameter(mimeinfo, "filename");
|
2004-10-12 11:45:18 +02:00
|
|
|
content_type = procmime_get_content_type_str(mimeinfo->type,
|
|
|
|
mimeinfo->subtype);
|
2004-01-12 22:28:31 +01:00
|
|
|
if (name == NULL)
|
|
|
|
name = procmime_mimeinfo_get_parameter(mimeinfo, "name");
|
|
|
|
if (name != NULL)
|
2006-07-27 08:27:19 +02:00
|
|
|
g_snprintf(buf, sizeof(buf), _("[%s %s (%d bytes)]"),
|
2004-10-12 11:45:18 +02:00
|
|
|
name, content_type, mimeinfo->length);
|
2002-03-03 10:32:58 +01:00
|
|
|
else
|
2006-07-27 08:27:19 +02:00
|
|
|
g_snprintf(buf, sizeof(buf), _("[%s (%d bytes)]"),
|
2004-10-12 11:45:18 +02:00
|
|
|
content_type, mimeinfo->length);
|
|
|
|
|
|
|
|
g_free(content_type);
|
2003-10-05 12:10:30 +02:00
|
|
|
|
2006-01-11 13:40:11 +01:00
|
|
|
if (mimeinfo->disposition == DISPOSITIONTYPE_ATTACHMENT
|
|
|
|
|| (mimeinfo->disposition == DISPOSITIONTYPE_INLINE &&
|
|
|
|
mimeinfo->type != MIMETYPE_TEXT)) {
|
2006-07-27 08:27:19 +02:00
|
|
|
gtk_text_buffer_insert(buffer, &iter, "\n", 1);
|
2006-10-07 19:45:59 +02:00
|
|
|
TEXTVIEW_INSERT_LINK(buf, "sc://select_attachment", mimeinfo);
|
2006-07-08 13:24:18 +02:00
|
|
|
gtk_text_buffer_insert(buffer, &iter, " \n", -1);
|
2005-03-21 10:47:35 +01:00
|
|
|
if (mimeinfo->type == MIMETYPE_IMAGE &&
|
|
|
|
prefs_common.inline_img ) {
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar *filename;
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri;
|
2005-03-21 10:47:35 +01:00
|
|
|
gchar *uri_str;
|
2007-01-16 09:13:56 +01:00
|
|
|
gint err;
|
2006-08-23 19:18:36 +02:00
|
|
|
START_TIMING("inserting image");
|
2006-09-04 18:56:18 +02:00
|
|
|
|
2005-03-21 10:47:35 +01:00
|
|
|
filename = procmime_get_tmp_file_name(mimeinfo);
|
2006-08-23 19:18:36 +02:00
|
|
|
|
2007-01-16 09:13:56 +01:00
|
|
|
if ((err = procmime_get_part(filename, mimeinfo)) < 0) {
|
|
|
|
g_warning("Can't get the image file.(%s)", strerror(-err));
|
2005-03-21 10:47:35 +01:00
|
|
|
g_free(filename);
|
2006-08-23 19:18:36 +02:00
|
|
|
END_TIMING();
|
2005-03-21 10:47:35 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-08-23 19:18:36 +02:00
|
|
|
if (!prefs_common.resize_img) {
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file(filename, &error);
|
|
|
|
} else {
|
|
|
|
gint w, h;
|
|
|
|
gdk_pixbuf_get_file_info(filename, &w, &h);
|
2006-12-14 10:49:25 +01:00
|
|
|
if (textview->scrolledwin->allocation.width - 100 > 0 &&
|
|
|
|
w > textview->scrolledwin->allocation.width - 100)
|
2006-08-23 19:18:36 +02:00
|
|
|
pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
|
|
|
|
textview->scrolledwin->allocation.width - 100,
|
|
|
|
-1, TRUE, &error);
|
|
|
|
else
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file(filename, &error);
|
|
|
|
}
|
2005-03-21 10:47:35 +01:00
|
|
|
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);
|
2006-08-23 19:18:36 +02:00
|
|
|
END_TIMING();
|
2005-03-21 10:47:35 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-04-01 10:16:46 +02:00
|
|
|
uri_str = g_filename_to_uri(filename, NULL, NULL);
|
2005-03-21 10:47:35 +01:00
|
|
|
if (uri_str) {
|
2006-08-02 18:30:28 +02:00
|
|
|
uri = g_new0(ClickableText, 1);
|
2005-03-21 10:47:35 +01:00
|
|
|
uri->uri = uri_str;
|
|
|
|
uri->start = gtk_text_iter_get_offset(&iter);
|
2005-04-01 10:16:46 +02:00
|
|
|
|
|
|
|
gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
|
|
|
|
|
2005-03-21 10:47:35 +01:00
|
|
|
uri->end = uri->start + 1;
|
2005-04-01 10:16:46 +02:00
|
|
|
uri->filename = procmime_get_part_file_name(mimeinfo);
|
2005-03-21 10:47:35 +01:00
|
|
|
textview->uri_list =
|
2006-09-29 18:57:15 +02:00
|
|
|
g_slist_prepend(textview->uri_list, uri);
|
2005-04-01 10:16:46 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2005-03-21 10:47:35 +01:00
|
|
|
|
|
|
|
g_object_unref(pixbuf);
|
|
|
|
g_free(filename);
|
2006-08-23 19:18:36 +02:00
|
|
|
END_TIMING();
|
2006-09-04 18:56:18 +02:00
|
|
|
GTK_EVENTS_FLUSH();
|
2005-03-21 10:47:35 +01:00
|
|
|
}
|
2005-11-18 12:26:51 +01:00
|
|
|
} else if (mimeinfo->type == MIMETYPE_TEXT) {
|
2004-01-12 22:28:31 +01:00
|
|
|
if (prefs_common.display_header && (charcount > 0))
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_text_buffer_insert(buffer, &iter, "\n", 1);
|
2002-05-18 17:22:17 +02:00
|
|
|
|
2004-10-02 18:33:17 +02:00
|
|
|
textview_write_body(textview, mimeinfo);
|
|
|
|
}
|
2006-08-23 19:18:36 +02:00
|
|
|
END_TIMING();
|
2004-01-12 22:28:31 +01:00
|
|
|
}
|
2002-05-18 17:22:17 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
static void recursive_add_parts(TextView *textview, GNode *node)
|
|
|
|
{
|
|
|
|
GNode * iter;
|
|
|
|
MimeInfo *mimeinfo;
|
2006-09-23 15:31:18 +02:00
|
|
|
START_TIMING("");
|
2006-08-23 19:18:36 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
mimeinfo = (MimeInfo *) node->data;
|
|
|
|
|
|
|
|
textview_add_part(textview, mimeinfo);
|
|
|
|
|
|
|
|
if ((mimeinfo->type != MIMETYPE_MULTIPART) &&
|
2006-08-23 19:18:36 +02:00
|
|
|
(mimeinfo->type != MIMETYPE_MESSAGE)) {
|
|
|
|
END_TIMING();
|
2004-01-12 22:28:31 +01:00
|
|
|
return;
|
2006-08-23 19:18:36 +02:00
|
|
|
}
|
2004-10-26 12:43:50 +02:00
|
|
|
if (g_ascii_strcasecmp(mimeinfo->subtype, "alternative") == 0) {
|
2004-01-12 22:28:31 +01:00
|
|
|
GNode * prefered_body;
|
|
|
|
int prefered_score;
|
|
|
|
|
|
|
|
/*
|
|
|
|
text/plain : score 3
|
|
|
|
text/ * : score 2
|
|
|
|
other : score 1
|
|
|
|
*/
|
|
|
|
prefered_body = NULL;
|
|
|
|
prefered_score = 0;
|
|
|
|
|
2004-11-12 09:37:48 +01:00
|
|
|
for (iter = g_node_first_child(node) ; iter != NULL ;
|
|
|
|
iter = g_node_next_sibling(iter)) {
|
2004-01-12 22:28:31 +01:00
|
|
|
int score;
|
|
|
|
MimeInfo * submime;
|
|
|
|
|
|
|
|
score = 1;
|
|
|
|
submime = (MimeInfo *) iter->data;
|
|
|
|
if (submime->type == MIMETYPE_TEXT)
|
|
|
|
score = 2;
|
|
|
|
|
|
|
|
if (submime->subtype != NULL) {
|
2004-10-26 12:43:50 +02:00
|
|
|
if (g_ascii_strcasecmp(submime->subtype, "plain") == 0)
|
2004-01-12 22:28:31 +01:00
|
|
|
score = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (score > prefered_score) {
|
|
|
|
prefered_score = score;
|
|
|
|
prefered_body = iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prefered_body != NULL) {
|
|
|
|
recursive_add_parts(textview, prefered_body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2004-11-12 09:37:48 +01:00
|
|
|
for (iter = g_node_first_child(node) ; iter != NULL ;
|
|
|
|
iter = g_node_next_sibling(iter)) {
|
2004-01-12 22:28:31 +01:00
|
|
|
recursive_add_parts(textview, iter);
|
|
|
|
}
|
|
|
|
}
|
2006-08-23 19:18:36 +02:00
|
|
|
END_TIMING();
|
2004-01-12 22:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void textview_add_parts(TextView *textview, MimeInfo *mimeinfo)
|
|
|
|
{
|
|
|
|
g_return_if_fail(mimeinfo != NULL);
|
|
|
|
|
|
|
|
recursive_add_parts(textview, mimeinfo->node);
|
2002-05-18 17:22:17 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
void textview_show_error(TextView *textview)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text;
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkTextIter iter;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
textview_set_font(textview, NULL);
|
|
|
|
textview_clear(textview);
|
2003-03-13 12:12:58 +01:00
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
buffer = gtk_text_view_get_buffer(text);
|
|
|
|
gtk_text_buffer_get_start_iter(buffer, &iter);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2006-10-07 19:45:59 +02:00
|
|
|
TEXTVIEW_INSERT(_("\n"
|
2006-04-05 18:47:17 +02:00
|
|
|
" This message can't be displayed.\n"
|
|
|
|
" This is probably due to a network error.\n"
|
|
|
|
"\n"
|
|
|
|
" Use "));
|
2006-10-07 19:45:59 +02:00
|
|
|
TEXTVIEW_INSERT_LINK(_("'View Log'"), "sc://view_log", NULL);
|
|
|
|
TEXTVIEW_INSERT(_(" in the Tools menu for more information."));
|
2006-04-05 18:47:17 +02:00
|
|
|
textview_show_icon(textview, GTK_STOCK_DIALOG_ERROR);
|
2001-05-10 13:19:38 +02:00
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text;
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkTextIter iter;
|
2007-07-24 18:22:28 +02:00
|
|
|
const gchar *name;
|
|
|
|
gchar *content_type;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
if (!partinfo) return;
|
|
|
|
|
|
|
|
textview_set_font(textview, NULL);
|
|
|
|
textview_clear(textview);
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
buffer = gtk_text_view_get_buffer(text);
|
|
|
|
gtk_text_buffer_get_start_iter(buffer, &iter);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2006-10-07 19:45:59 +02:00
|
|
|
TEXTVIEW_INSERT("\n");
|
2007-07-24 18:22:28 +02:00
|
|
|
|
|
|
|
name = procmime_mimeinfo_get_parameter(partinfo, "filename");
|
|
|
|
if (name == NULL)
|
|
|
|
name = procmime_mimeinfo_get_parameter(partinfo, "name");
|
|
|
|
if (name != NULL) {
|
|
|
|
content_type = procmime_get_content_type_str(partinfo->type,
|
|
|
|
partinfo->subtype);
|
|
|
|
TEXTVIEW_INSERT(" ");
|
|
|
|
TEXTVIEW_INSERT_BOLD(name);
|
|
|
|
TEXTVIEW_INSERT(" (");
|
|
|
|
TEXTVIEW_INSERT(content_type);
|
|
|
|
TEXTVIEW_INSERT(", ");
|
|
|
|
TEXTVIEW_INSERT(to_human_readable(partinfo->length));
|
|
|
|
TEXTVIEW_INSERT("):\n\n");
|
|
|
|
|
|
|
|
g_free(content_type);
|
|
|
|
}
|
|
|
|
TEXTVIEW_INSERT(_(" The following can be performed on this part\n"));
|
|
|
|
#ifndef MAEMO
|
2007-07-25 09:42:58 +02:00
|
|
|
TEXTVIEW_INSERT(_(" by right-clicking the icon or list item:"));
|
2007-07-24 18:22:28 +02:00
|
|
|
#endif
|
2007-07-25 09:42:58 +02:00
|
|
|
TEXTVIEW_INSERT("\n");
|
2006-10-07 19:45:59 +02:00
|
|
|
|
|
|
|
TEXTVIEW_INSERT(_(" - To save, select "));
|
|
|
|
TEXTVIEW_INSERT_LINK(_("'Save as...'"), "sc://save_as", NULL);
|
2007-07-23 18:34:59 +02:00
|
|
|
#ifndef MAEMO
|
2007-07-25 09:42:58 +02:00
|
|
|
TEXTVIEW_INSERT(_(" (Shortcut key: 'y')"));
|
2007-07-23 18:34:59 +02:00
|
|
|
#endif
|
2007-07-25 09:42:58 +02:00
|
|
|
TEXTVIEW_INSERT("\n");
|
|
|
|
|
2006-10-07 19:45:59 +02:00
|
|
|
TEXTVIEW_INSERT(_(" - To display as text, select "));
|
|
|
|
TEXTVIEW_INSERT_LINK(_("'Display as text'"), "sc://display_as_text", NULL);
|
2007-07-25 09:42:58 +02:00
|
|
|
|
2007-07-23 18:34:59 +02:00
|
|
|
#ifndef MAEMO
|
2007-07-25 09:42:58 +02:00
|
|
|
TEXTVIEW_INSERT(_(" (Shortcut key: 't')"));
|
2007-07-23 18:34:59 +02:00
|
|
|
#endif
|
2007-07-25 09:42:58 +02:00
|
|
|
TEXTVIEW_INSERT("\n");
|
|
|
|
|
2006-10-07 19:45:59 +02:00
|
|
|
TEXTVIEW_INSERT(_(" - To open with an external program, select "));
|
|
|
|
TEXTVIEW_INSERT_LINK(_("'Open'"), "sc://open", NULL);
|
2007-07-25 09:42:58 +02:00
|
|
|
|
2007-07-23 18:34:59 +02:00
|
|
|
#ifndef MAEMO
|
2006-10-07 19:45:59 +02:00
|
|
|
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);
|
2007-07-25 09:42:58 +02:00
|
|
|
TEXTVIEW_INSERT(_(" (Shortcut key: 'o')"));
|
2007-07-23 18:34:59 +02:00
|
|
|
#endif
|
2007-07-25 09:42:58 +02:00
|
|
|
TEXTVIEW_INSERT("\n");
|
|
|
|
|
2006-04-05 18:47:17 +02:00
|
|
|
textview_show_icon(textview, GTK_STOCK_DIALOG_INFO);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-10-02 18:33:17 +02:00
|
|
|
static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
|
2002-03-02 11:02:42 +01:00
|
|
|
{
|
|
|
|
FILE *tmpfp;
|
|
|
|
gchar buf[BUFFSIZE];
|
2002-03-07 14:22:39 +01:00
|
|
|
CodeConverter *conv;
|
2006-06-27 14:46:42 +02:00
|
|
|
const gchar *charset, *p, *cmd;
|
2006-08-02 18:30:28 +02:00
|
|
|
GSList *cur;
|
2004-10-02 18:33:17 +02:00
|
|
|
|
|
|
|
if (textview->messageview->forced_charset)
|
|
|
|
charset = textview->messageview->forced_charset;
|
|
|
|
else
|
|
|
|
charset = procmime_mimeinfo_get_parameter(mimeinfo, "charset");
|
2005-09-14 11:12:56 +02:00
|
|
|
|
2004-10-02 18:33:17 +02:00
|
|
|
textview_set_font(textview, charset);
|
2002-03-07 14:22:39 +01:00
|
|
|
|
|
|
|
conv = conv_code_converter_new(charset);
|
2002-03-02 11:02:42 +01:00
|
|
|
|
2004-10-04 12:22:00 +02:00
|
|
|
procmime_force_encoding(textview->messageview->forced_encoding);
|
|
|
|
|
2002-09-03 16:45:07 +02:00
|
|
|
textview->is_in_signature = FALSE;
|
|
|
|
|
2004-10-02 18:33:17 +02:00
|
|
|
procmime_decode_content(mimeinfo);
|
2004-01-12 22:28:31 +01:00
|
|
|
|
2005-03-30 14:01:26 +02:00
|
|
|
if (!g_ascii_strcasecmp(mimeinfo->subtype, "html") &&
|
|
|
|
prefs_common.render_html) {
|
2004-01-12 22:28:31 +01:00
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
filename = procmime_get_tmp_file_name(mimeinfo);
|
|
|
|
if (procmime_get_part(filename, mimeinfo) == 0) {
|
2005-08-19 11:30:30 +02:00
|
|
|
tmpfp = g_fopen(filename, "rb");
|
2002-03-02 11:02:42 +01:00
|
|
|
textview_show_html(textview, tmpfp, conv);
|
2004-01-12 22:28:31 +01:00
|
|
|
fclose(tmpfp);
|
2005-08-19 11:30:30 +02:00
|
|
|
g_unlink(filename);
|
2004-01-12 22:28:31 +01:00
|
|
|
}
|
|
|
|
g_free(filename);
|
2004-10-26 12:43:50 +02:00
|
|
|
} else if (!g_ascii_strcasecmp(mimeinfo->subtype, "enriched")) {
|
2004-01-12 22:28:31 +01:00
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
filename = procmime_get_tmp_file_name(mimeinfo);
|
|
|
|
if (procmime_get_part(filename, mimeinfo) == 0) {
|
2005-08-19 11:30:30 +02:00
|
|
|
tmpfp = g_fopen(filename, "rb");
|
2002-03-02 11:02:42 +01:00
|
|
|
textview_show_ertf(textview, tmpfp, conv);
|
2004-01-12 22:28:31 +01:00
|
|
|
fclose(tmpfp);
|
2005-08-19 11:30:30 +02:00
|
|
|
g_unlink(filename);
|
2004-01-12 22:28:31 +01:00
|
|
|
}
|
|
|
|
g_free(filename);
|
2006-09-13 12:31:49 +02:00
|
|
|
#ifndef G_OS_WIN32
|
2006-06-27 14:46:42 +02:00
|
|
|
} else if ( g_ascii_strcasecmp(mimeinfo->subtype, "plain") &&
|
|
|
|
(cmd = prefs_common.mime_textviewer) && *cmd &&
|
|
|
|
(p = strchr(cmd, '%')) && *(p + 1) == 's') {
|
|
|
|
int pid, pfd[2];
|
|
|
|
const gchar *fname;
|
|
|
|
|
|
|
|
fname = procmime_get_tmp_file_name(mimeinfo);
|
|
|
|
if (procmime_get_part(fname, mimeinfo)) goto textview_default;
|
|
|
|
|
|
|
|
g_snprintf(buf, sizeof(buf), cmd, fname);
|
|
|
|
debug_print("Viewing text content of type: %s (length: %d) "
|
|
|
|
"using %s\n", mimeinfo->subtype, mimeinfo->length, buf);
|
|
|
|
|
|
|
|
if (pipe(pfd) < 0) {
|
|
|
|
g_snprintf(buf, sizeof(buf),
|
|
|
|
"pipe failed for textview\n\n%s\n", strerror(errno));
|
2006-10-06 18:55:13 +02:00
|
|
|
textview_write_line(textview, buf, conv, TRUE);
|
2006-06-27 14:46:42 +02:00
|
|
|
goto textview_default;
|
|
|
|
}
|
|
|
|
pid = fork();
|
|
|
|
if (pid < 0) {
|
|
|
|
g_snprintf(buf, sizeof(buf),
|
|
|
|
"fork failed for textview\n\n%s\n", strerror(errno));
|
2006-10-06 18:55:13 +02:00
|
|
|
textview_write_line(textview, buf, conv, TRUE);
|
2006-06-27 14:46:42 +02:00
|
|
|
close(pfd[0]);
|
|
|
|
close(pfd[1]);
|
|
|
|
goto textview_default;
|
|
|
|
}
|
|
|
|
if (pid == 0) { /* child */
|
2006-07-09 14:19:54 +02:00
|
|
|
int rc;
|
2006-06-27 14:46:42 +02:00
|
|
|
gchar **argv;
|
|
|
|
argv = strsplit_with_quote(buf, " ", 0);
|
|
|
|
close(1);
|
|
|
|
close(pfd[0]);
|
|
|
|
dup(pfd[1]);
|
2006-07-09 14:19:54 +02:00
|
|
|
rc = execvp(argv[0], argv);
|
2006-06-27 14:46:42 +02:00
|
|
|
close(pfd[1]);
|
2006-07-09 14:19:54 +02:00
|
|
|
printf (_("The command to view attachment "
|
|
|
|
"as text failed:\n"
|
|
|
|
" %s\n"
|
|
|
|
"Exit code %d\n"), buf, rc);
|
2006-06-27 14:46:42 +02:00
|
|
|
exit(255);
|
|
|
|
}
|
|
|
|
close(pfd[1]);
|
|
|
|
tmpfp = fdopen(pfd[0], "rb");
|
2006-09-04 18:56:18 +02:00
|
|
|
while (fgets(buf, sizeof(buf), tmpfp)) {
|
2006-10-06 18:55:13 +02:00
|
|
|
textview_write_line(textview, buf, conv, TRUE);
|
2006-09-04 18:56:18 +02:00
|
|
|
|
|
|
|
if (textview->stop_loading) {
|
|
|
|
fclose(tmpfp);
|
|
|
|
waitpid(pid, pfd, 0);
|
|
|
|
unlink(fname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-27 14:46:42 +02:00
|
|
|
fclose(tmpfp);
|
|
|
|
waitpid(pid, pfd, 0);
|
|
|
|
unlink(fname);
|
2006-09-13 12:31:49 +02:00
|
|
|
#endif
|
2004-01-12 22:28:31 +01:00
|
|
|
} else {
|
2006-06-27 14:46:42 +02:00
|
|
|
textview_default:
|
2005-08-19 11:30:30 +02:00
|
|
|
tmpfp = g_fopen(mimeinfo->data.filename, "rb");
|
2004-01-12 22:28:31 +01:00
|
|
|
fseek(tmpfp, mimeinfo->offset, SEEK_SET);
|
|
|
|
debug_print("Viewing text content of type: %s (length: %d)\n", mimeinfo->subtype, mimeinfo->length);
|
2006-08-16 18:24:00 +02:00
|
|
|
while ((ftell(tmpfp) < mimeinfo->offset + mimeinfo->length) &&
|
2006-09-04 18:56:18 +02:00
|
|
|
(fgets(buf, sizeof(buf), tmpfp) != NULL)) {
|
2006-10-06 18:55:13 +02:00
|
|
|
textview_write_line(textview, buf, conv, TRUE);
|
2006-09-04 18:56:18 +02:00
|
|
|
if (textview->stop_loading) {
|
|
|
|
fclose(tmpfp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-03-02 11:02:42 +01:00
|
|
|
fclose(tmpfp);
|
|
|
|
}
|
2002-03-07 14:22:39 +01:00
|
|
|
|
|
|
|
conv_code_converter_destroy(conv);
|
2004-10-04 12:22:00 +02:00
|
|
|
procmime_force_encoding(0);
|
2006-08-02 18:30:28 +02:00
|
|
|
|
2006-09-29 18:57:15 +02:00
|
|
|
textview->uri_list = g_slist_reverse(textview->uri_list);
|
2006-08-02 18:30:28 +02:00
|
|
|
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) {
|
2006-09-29 18:57:15 +02:00
|
|
|
textview_toggle_quote(textview, cur, uri, TRUE);
|
2006-09-04 18:56:18 +02:00
|
|
|
if (textview->stop_loading) {
|
|
|
|
return;
|
|
|
|
}
|
2006-08-02 18:30:28 +02:00
|
|
|
}
|
|
|
|
}
|
2007-08-02 08:49:52 +02:00
|
|
|
|
|
|
|
GTK_EVENTS_FLUSH();
|
2002-03-02 11:02:42 +01:00
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static void textview_show_html(TextView *textview, FILE *fp,
|
|
|
|
CodeConverter *conv)
|
|
|
|
{
|
2006-02-10 08:45:35 +01:00
|
|
|
SC_HTMLParser *parser;
|
2001-04-19 14:21:46 +02:00
|
|
|
gchar *str;
|
2006-09-04 18:56:18 +02:00
|
|
|
gint lines = 0;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2006-02-10 08:45:35 +01:00
|
|
|
parser = sc_html_parser_new(fp, conv);
|
2001-04-19 14:21:46 +02:00
|
|
|
g_return_if_fail(parser != NULL);
|
|
|
|
|
2006-02-10 08:45:35 +01:00
|
|
|
while ((str = sc_html_parse(parser)) != NULL) {
|
|
|
|
if (parser->state == SC_HTML_HREF) {
|
2001-10-29 16:42:21 +01:00
|
|
|
/* first time : get and copy the URL */
|
2003-03-13 12:12:58 +01:00
|
|
|
if (parser->href == NULL) {
|
2006-11-27 09:07:23 +01:00
|
|
|
/* ALF - the claws html parser returns an empty string,
|
2001-11-04 17:13:43 +01:00
|
|
|
* if still inside an <a>, but already parsed past HREF */
|
|
|
|
str = strtok(str, " ");
|
2006-06-06 09:39:23 +02:00
|
|
|
if (str) {
|
|
|
|
while (str && *str && g_ascii_isspace(*str))
|
|
|
|
str++;
|
2004-10-19 09:28:20 +02:00
|
|
|
parser->href = g_strdup(str);
|
2001-11-04 17:13:43 +01:00
|
|
|
/* the URL may (or not) be followed by the
|
|
|
|
* referenced text */
|
|
|
|
str = strtok(NULL, "");
|
|
|
|
}
|
2001-10-29 16:42:21 +01:00
|
|
|
}
|
2003-03-13 12:12:58 +01:00
|
|
|
if (str != NULL)
|
|
|
|
textview_write_link(textview, str, parser->href, NULL);
|
|
|
|
} else
|
2006-10-06 18:55:13 +02:00
|
|
|
textview_write_line(textview, str, NULL, FALSE);
|
2006-09-04 18:56:18 +02:00
|
|
|
lines++;
|
|
|
|
if (lines % 500 == 0)
|
|
|
|
GTK_EVENTS_FLUSH();
|
|
|
|
if (textview->stop_loading) {
|
|
|
|
return;
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
2006-10-06 18:55:13 +02:00
|
|
|
textview_write_line(textview, "\n", NULL, FALSE);
|
2006-02-10 08:45:35 +01:00
|
|
|
sc_html_parser_destroy(parser);
|
2001-11-28 23:48:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void textview_show_ertf(TextView *textview, FILE *fp,
|
|
|
|
CodeConverter *conv)
|
|
|
|
{
|
|
|
|
ERTFParser *parser;
|
|
|
|
gchar *str;
|
2006-09-04 18:56:18 +02:00
|
|
|
gint lines = 0;
|
2001-11-28 23:48:06 +01:00
|
|
|
|
|
|
|
parser = ertf_parser_new(fp, conv);
|
|
|
|
g_return_if_fail(parser != NULL);
|
|
|
|
|
|
|
|
while ((str = ertf_parse(parser)) != NULL) {
|
2006-10-06 18:55:13 +02:00
|
|
|
textview_write_line(textview, str, NULL, FALSE);
|
2006-09-04 18:56:18 +02:00
|
|
|
lines++;
|
|
|
|
if (lines % 500 == 0)
|
|
|
|
GTK_EVENTS_FLUSH();
|
|
|
|
if (textview->stop_loading) {
|
|
|
|
return;
|
|
|
|
}
|
2001-11-28 23:48:06 +01:00
|
|
|
}
|
2002-07-16 01:56:33 +02:00
|
|
|
|
2001-11-28 23:48:06 +01:00
|
|
|
ertf_parser_destroy(parser);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ADD_TXT_POS(bp_, ep_, pti_) \
|
|
|
|
if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
|
|
|
|
last = last->next; \
|
|
|
|
last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
|
|
|
|
last->next = NULL; \
|
|
|
|
} else { \
|
|
|
|
g_warning("alloc error scanning URIs\n"); \
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, \
|
|
|
|
linebuf, -1, \
|
|
|
|
fg_tag, NULL); \
|
2001-04-19 14:21:46 +02:00
|
|
|
return; \
|
|
|
|
}
|
|
|
|
|
2006-08-02 18:30:28 +02:00
|
|
|
#define ADD_TXT_POS_LATER(bp_, ep_, pti_) \
|
|
|
|
if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
|
|
|
|
last = last->next; \
|
|
|
|
last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
|
|
|
|
last->next = NULL; \
|
|
|
|
} else { \
|
|
|
|
g_warning("alloc error scanning URIs\n"); \
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
/* textview_make_clickable_parts() - colorizes clickable parts */
|
2001-05-06 22:06:56 +02:00
|
|
|
static void textview_make_clickable_parts(TextView *textview,
|
2003-10-05 12:10:30 +02:00
|
|
|
const gchar *fg_tag,
|
|
|
|
const gchar *uri_tag,
|
2005-11-08 19:08:15 +01:00
|
|
|
const gchar *linebuf,
|
|
|
|
gboolean hdr)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
|
|
|
|
GtkTextIter iter;
|
2005-07-08 18:38:51 +02:00
|
|
|
gchar *mybuf = g_strdup(linebuf);
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
/* parse table - in order of priority */
|
|
|
|
struct table {
|
|
|
|
const gchar *needle; /* token */
|
|
|
|
|
|
|
|
/* token search function */
|
|
|
|
gchar *(*search) (const gchar *haystack,
|
|
|
|
const gchar *needle);
|
|
|
|
/* part parsing function */
|
|
|
|
gboolean (*parse) (const gchar *start,
|
|
|
|
const gchar *scanpos,
|
|
|
|
const gchar **bp_,
|
2005-11-08 19:08:15 +01:00
|
|
|
const gchar **ep_,
|
|
|
|
gboolean hdr);
|
2001-04-19 14:21:46 +02:00
|
|
|
/* part to URI function */
|
|
|
|
gchar *(*build_uri) (const gchar *bp,
|
|
|
|
const gchar *ep);
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct table parser[] = {
|
|
|
|
{"http://", strcasestr, get_uri_part, make_uri_string},
|
|
|
|
{"https://", strcasestr, get_uri_part, make_uri_string},
|
|
|
|
{"ftp://", strcasestr, get_uri_part, make_uri_string},
|
2006-07-05 20:45:13 +02:00
|
|
|
{"sftp://", strcasestr, get_uri_part, make_uri_string},
|
2004-05-10 12:22:28 +02:00
|
|
|
{"www.", strcasestr, get_uri_part, make_http_string},
|
2001-04-19 14:21:46 +02:00
|
|
|
{"mailto:", strcasestr, get_uri_part, make_uri_string},
|
|
|
|
{"@", strcasestr, get_email_part, make_email_string}
|
|
|
|
};
|
|
|
|
const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
|
|
|
|
|
|
|
|
gint n;
|
|
|
|
const gchar *walk, *bp, *ep;
|
|
|
|
|
|
|
|
struct txtpos {
|
|
|
|
const gchar *bp, *ep; /* text position */
|
|
|
|
gint pti; /* index in parse table */
|
|
|
|
struct txtpos *next; /* next */
|
2004-11-08 16:18:33 +01:00
|
|
|
} head = {NULL, NULL, 0, NULL}, *last = &head;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-07-20 18:50:43 +02:00
|
|
|
if (!g_utf8_validate(linebuf, -1, NULL)) {
|
2006-09-27 18:49:42 +02:00
|
|
|
g_free(mybuf);
|
2005-07-20 18:50:43 +02:00
|
|
|
mybuf = g_malloc(strlen(linebuf)*2 +1);
|
|
|
|
conv_localetodisp(mybuf, strlen(linebuf)*2 +1, linebuf);
|
|
|
|
}
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_text_buffer_get_end_iter(buffer, &iter);
|
2001-05-06 22:06:56 +02:00
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
/* parse for clickable parts, and build a list of begin and end positions */
|
2005-07-08 18:38:51 +02:00
|
|
|
for (walk = mybuf, n = 0;;) {
|
2001-04-19 14:21:46 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scanpos) {
|
|
|
|
/* check if URI can be parsed */
|
2005-11-08 19:08:15 +01:00
|
|
|
if (parser[last_index].parse(walk, scanpos, &bp, &ep, hdr)
|
2001-05-08 21:19:49 +02:00
|
|
|
&& (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
|
2001-04-19 14:21:46 +02:00
|
|
|
ADD_TXT_POS(bp, ep, last_index);
|
|
|
|
walk = ep;
|
|
|
|
} else
|
|
|
|
walk = scanpos +
|
|
|
|
strlen(parser[last_index].needle);
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* colorize this line */
|
|
|
|
if (head.next) {
|
2005-07-08 18:38:51 +02:00
|
|
|
const gchar *normal_text = mybuf;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
/* insert URIs */
|
|
|
|
for (last = head.next; last != NULL;
|
|
|
|
normal_text = last->ep, last = last->next) {
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri;
|
|
|
|
uri = g_new0(ClickableText, 1);
|
2001-04-19 14:21:46 +02:00
|
|
|
if (last->bp - normal_text > 0)
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name
|
|
|
|
(buffer, &iter,
|
|
|
|
normal_text,
|
|
|
|
last->bp - normal_text,
|
|
|
|
fg_tag, NULL);
|
2002-01-06 13:21:36 +01:00
|
|
|
uri->uri = parser[last->pti].build_uri(last->bp,
|
2001-05-23 05:04:46 +02:00
|
|
|
last->ep);
|
2003-10-05 12:10:30 +02:00
|
|
|
uri->start = gtk_text_iter_get_offset(&iter);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name
|
2005-01-29 17:53:23 +01:00
|
|
|
(buffer, &iter, last->bp, last->ep - last->bp,
|
|
|
|
uri_tag, fg_tag, NULL);
|
2003-10-05 12:10:30 +02:00
|
|
|
uri->end = gtk_text_iter_get_offset(&iter);
|
2005-04-01 10:16:46 +02:00
|
|
|
uri->filename = NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
textview->uri_list =
|
2006-09-29 18:57:15 +02:00
|
|
|
g_slist_prepend(textview->uri_list, uri);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*normal_text)
|
2005-01-29 17:53:23 +01:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name
|
|
|
|
(buffer, &iter, normal_text, -1, fg_tag, NULL);
|
2003-10-05 12:10:30 +02:00
|
|
|
} else {
|
2005-01-29 17:53:23 +01:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name
|
2005-07-08 18:38:51 +02:00
|
|
|
(buffer, &iter, mybuf, -1, fg_tag, NULL);
|
2003-10-05 12:10:30 +02:00
|
|
|
}
|
2005-07-08 18:38:51 +02:00
|
|
|
g_free(mybuf);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2006-08-02 18:30:28 +02:00
|
|
|
/* textview_make_clickable_parts() - colorizes clickable parts */
|
|
|
|
static void textview_make_clickable_parts_later(TextView *textview,
|
|
|
|
gint start, gint end)
|
|
|
|
{
|
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
|
|
|
|
GtkTextIter start_iter, end_iter;
|
|
|
|
gchar *mybuf;
|
|
|
|
gint offset = 0;
|
|
|
|
/* parse table - in order of priority */
|
|
|
|
struct table {
|
|
|
|
const gchar *needle; /* token */
|
|
|
|
|
|
|
|
/* token search function */
|
|
|
|
gchar *(*search) (const gchar *haystack,
|
|
|
|
const gchar *needle);
|
|
|
|
/* part parsing function */
|
|
|
|
gboolean (*parse) (const gchar *start,
|
|
|
|
const gchar *scanpos,
|
|
|
|
const gchar **bp_,
|
|
|
|
const gchar **ep_,
|
|
|
|
gboolean hdr);
|
|
|
|
/* part to URI function */
|
|
|
|
gchar *(*build_uri) (const gchar *bp,
|
|
|
|
const gchar *ep);
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct table parser[] = {
|
|
|
|
{"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];
|
|
|
|
|
|
|
|
gint n;
|
|
|
|
const gchar *walk, *bp, *ep;
|
|
|
|
|
|
|
|
struct txtpos {
|
|
|
|
const gchar *bp, *ep; /* text position */
|
|
|
|
gint pti; /* index in parse table */
|
|
|
|
struct txtpos *next; /* next */
|
|
|
|
} head = {NULL, NULL, 0, NULL}, *last = &head;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
|
|
|
|
gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
|
|
|
|
mybuf = gtk_text_buffer_get_text(buffer, &start_iter, &end_iter, FALSE);
|
|
|
|
offset = gtk_text_iter_get_offset(&start_iter);
|
|
|
|
|
|
|
|
/* parse for clickable parts, and build a list of begin and end positions */
|
|
|
|
for (walk = mybuf, n = 0;;) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
|
|
|
if (head.next) {
|
|
|
|
/* insert URIs */
|
2006-08-03 18:37:50 +02:00
|
|
|
for (last = head.next; last != NULL; last = last->next) {
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri;
|
2006-08-03 18:37:50 +02:00
|
|
|
gint start_offset, end_offset;
|
|
|
|
gchar *tmp_str;
|
|
|
|
gchar old_char;
|
2006-08-02 18:30:28 +02:00
|
|
|
uri = g_new0(ClickableText, 1);
|
|
|
|
uri->uri = parser[last->pti].build_uri(last->bp,
|
|
|
|
last->ep);
|
2006-08-03 18:37:50 +02:00
|
|
|
|
|
|
|
tmp_str = mybuf;
|
|
|
|
old_char = tmp_str[last->ep - mybuf];
|
|
|
|
tmp_str[last->ep - mybuf] = '\0';
|
|
|
|
end_offset = g_utf8_strlen(tmp_str, -1);
|
|
|
|
tmp_str[last->ep - mybuf] = old_char;
|
|
|
|
|
|
|
|
old_char = tmp_str[last->bp - mybuf];
|
|
|
|
tmp_str[last->bp - mybuf] = '\0';
|
|
|
|
start_offset = g_utf8_strlen(tmp_str, -1);
|
|
|
|
tmp_str[last->bp - mybuf] = old_char;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start_offset + offset);
|
|
|
|
gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end_offset + offset);
|
2006-08-02 18:30:28 +02:00
|
|
|
|
|
|
|
uri->start = gtk_text_iter_get_offset(&start_iter);
|
|
|
|
|
|
|
|
gtk_text_buffer_apply_tag_by_name(buffer, "link", &start_iter, &end_iter);
|
|
|
|
|
|
|
|
uri->end = gtk_text_iter_get_offset(&end_iter);
|
|
|
|
uri->filename = NULL;
|
|
|
|
textview->uri_list =
|
2006-09-29 18:57:15 +02:00
|
|
|
g_slist_prepend(textview->uri_list, uri);
|
2006-08-02 18:30:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(mybuf);
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
#undef ADD_TXT_POS
|
|
|
|
|
|
|
|
static void textview_write_line(TextView *textview, const gchar *str,
|
2006-10-06 18:55:13 +02:00
|
|
|
CodeConverter *conv, gboolean do_quote_folding)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text;
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkTextIter iter;
|
2001-04-19 14:21:46 +02:00
|
|
|
gchar buf[BUFFSIZE];
|
2003-10-05 12:10:30 +02:00
|
|
|
gchar *fg_color;
|
2006-08-05 11:39:48 +02:00
|
|
|
gint quotelevel = -1, real_quotelevel = -1;
|
2003-10-05 12:10:30 +02:00
|
|
|
gchar quote_tag_str[10];
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
buffer = gtk_text_view_get_buffer(text);
|
|
|
|
gtk_text_buffer_get_end_iter(buffer, &iter);
|
|
|
|
|
2005-02-01 09:58:33 +01:00
|
|
|
if (!conv)
|
2004-08-31 11:56:41 +02:00
|
|
|
strncpy2(buf, str, sizeof(buf));
|
2005-02-01 09:58:33 +01:00
|
|
|
else if (conv_convert(conv, buf, sizeof(buf), str) < 0)
|
2005-07-08 18:38:51 +02:00
|
|
|
conv_localetodisp(buf, sizeof(buf), str);
|
|
|
|
|
2001-11-07 11:29:45 +01:00
|
|
|
strcrchomp(buf);
|
2001-04-19 14:21:46 +02:00
|
|
|
fg_color = NULL;
|
|
|
|
|
|
|
|
/* change color of quotation
|
|
|
|
>, foo>, _> ... ok, <foo>, foo bar>, foo-> ... ng
|
|
|
|
Up to 3 levels of quotations are detected, and each
|
|
|
|
level is colored using a different color. */
|
2002-04-28 22:43:24 +02:00
|
|
|
if (prefs_common.enable_color
|
|
|
|
&& line_has_quote_char(buf, prefs_common.quote_chars)) {
|
2006-08-05 11:39:48 +02:00
|
|
|
real_quotelevel = get_quote_level(buf, prefs_common.quote_chars);
|
|
|
|
quotelevel = real_quotelevel;
|
2001-04-19 14:21:46 +02:00
|
|
|
/* set up the correct foreground color */
|
|
|
|
if (quotelevel > 2) {
|
|
|
|
/* recycle colors */
|
|
|
|
if (prefs_common.recycle_quote_colors)
|
|
|
|
quotelevel %= 3;
|
|
|
|
else
|
|
|
|
quotelevel = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quotelevel == -1)
|
|
|
|
fg_color = NULL;
|
2003-10-05 12:10:30 +02:00
|
|
|
else {
|
|
|
|
g_snprintf(quote_tag_str, sizeof(quote_tag_str),
|
|
|
|
"quote%d", quotelevel);
|
|
|
|
fg_color = quote_tag_str;
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2007-04-26 21:24:15 +02:00
|
|
|
if (prefs_common.enable_color &&
|
|
|
|
(strcmp(buf,"-- \n") == 0 || strcmp(buf, "- -- \n") == 0 || textview->is_in_signature)) {
|
2003-10-05 12:10:30 +02:00
|
|
|
fg_color = "signature";
|
2002-09-03 16:45:07 +02:00
|
|
|
textview->is_in_signature = TRUE;
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2006-10-06 18:55:13 +02:00
|
|
|
if (real_quotelevel > -1 && do_quote_folding) {
|
2006-10-16 19:13:25 +02:00
|
|
|
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);
|
|
|
|
}
|
2006-10-11 10:47:22 +02:00
|
|
|
do_quote:
|
2007-04-24 12:05:01 +02:00
|
|
|
if ( textview->prev_quote_level != real_quotelevel ) {
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri;
|
|
|
|
uri = g_new0(ClickableText, 1);
|
|
|
|
uri->uri = g_strdup("");
|
|
|
|
uri->data = g_strdup(buf);
|
|
|
|
uri->start = gtk_text_iter_get_offset(&iter);
|
2006-09-29 18:57:15 +02:00
|
|
|
uri->is_quote = TRUE;
|
|
|
|
uri->quote_level = real_quotelevel;
|
|
|
|
uri->fg_color = g_strdup(fg_color);
|
|
|
|
|
2006-08-02 18:30:28 +02:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name
|
2006-09-29 18:57:15 +02:00
|
|
|
(buffer, &iter, " [...]", -1,
|
|
|
|
"qlink", fg_color, NULL);
|
2006-08-02 18:30:28 +02:00
|
|
|
uri->end = gtk_text_iter_get_offset(&iter);
|
2006-09-29 18:57:15 +02:00
|
|
|
gtk_text_buffer_insert(buffer, &iter, " \n", -1);
|
|
|
|
|
2006-08-02 18:30:28 +02:00
|
|
|
uri->filename = NULL;
|
|
|
|
textview->uri_list =
|
2006-09-29 18:57:15 +02:00
|
|
|
g_slist_prepend(textview->uri_list, uri);
|
2006-08-02 18:30:28 +02:00
|
|
|
|
2007-04-24 12:05:01 +02:00
|
|
|
textview->prev_quote_level = real_quotelevel;
|
2006-08-02 18:30:28 +02:00
|
|
|
} else {
|
2006-09-29 18:57:15 +02:00
|
|
|
GSList *last = textview->uri_list;
|
2007-04-24 12:05:01 +02:00
|
|
|
ClickableText *lasturi = NULL;
|
2006-10-11 10:47:22 +02:00
|
|
|
gint e_len = 0, n_len = 0;
|
|
|
|
|
2007-04-24 12:05:01 +02:00
|
|
|
if (textview->uri_list) {
|
|
|
|
lasturi = (ClickableText *)last->data;
|
|
|
|
} else {
|
|
|
|
printf("oops (%d %d)\n",
|
|
|
|
real_quotelevel, textview->prev_quote_level);
|
|
|
|
}
|
2006-10-11 10:47:22 +02:00
|
|
|
if (lasturi->is_quote == FALSE) {
|
2007-04-24 12:05:01 +02:00
|
|
|
textview->prev_quote_level = -1;
|
2006-10-11 10:47:22 +02:00
|
|
|
goto do_quote;
|
|
|
|
}
|
|
|
|
e_len = lasturi->data ? strlen(lasturi->data):0;
|
|
|
|
n_len = strlen(buf);
|
2006-09-29 18:57:15 +02:00
|
|
|
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';
|
2006-07-31 19:17:32 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
textview_make_clickable_parts(textview, fg_color, "link", buf, FALSE);
|
2007-04-24 12:05:01 +02:00
|
|
|
textview->prev_quote_level = -1;
|
2006-07-31 19:17:32 +02:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2003-03-13 12:12:58 +01:00
|
|
|
void textview_write_link(TextView *textview, const gchar *str,
|
|
|
|
const gchar *uri, CodeConverter *conv)
|
|
|
|
{
|
|
|
|
GdkColor *link_color = NULL;
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text;
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkTextIter iter;
|
2003-03-13 12:12:58 +01:00
|
|
|
gchar buf[BUFFSIZE];
|
|
|
|
gchar *bufp;
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *r_uri;
|
2003-03-13 12:12:58 +01:00
|
|
|
|
2005-05-27 09:24:34 +02:00
|
|
|
if (!str || *str == '\0')
|
|
|
|
return;
|
|
|
|
if (!uri)
|
2003-03-13 12:12:58 +01:00
|
|
|
return;
|
|
|
|
|
2006-06-06 09:39:23 +02:00
|
|
|
while (uri && *uri && g_ascii_isspace(*uri))
|
|
|
|
uri++;
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
buffer = gtk_text_view_get_buffer(text);
|
|
|
|
gtk_text_buffer_get_end_iter(buffer, &iter);
|
|
|
|
|
|
|
|
if (!conv)
|
|
|
|
strncpy2(buf, str, sizeof(buf));
|
|
|
|
else if (conv_convert(conv, buf, sizeof(buf), str) < 0)
|
2005-02-01 09:58:33 +01:00
|
|
|
conv_utf8todisp(buf, sizeof(buf), str);
|
2003-03-13 12:12:58 +01:00
|
|
|
|
2005-06-06 09:32:31 +02:00
|
|
|
if (g_utf8_validate(buf, -1, NULL) == FALSE)
|
2005-05-27 09:24:34 +02:00
|
|
|
return;
|
|
|
|
|
2003-03-13 12:12:58 +01:00
|
|
|
strcrchomp(buf);
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_text_buffer_get_end_iter(buffer, &iter);
|
2005-05-27 09:24:34 +02:00
|
|
|
for (bufp = buf; *bufp != '\0'; bufp = g_utf8_next_char(bufp)) {
|
|
|
|
gunichar ch;
|
2003-10-05 12:10:30 +02:00
|
|
|
|
2005-05-27 09:24:34 +02:00
|
|
|
ch = g_utf8_get_char(bufp);
|
|
|
|
if (!g_unichar_isspace(ch))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bufp > buf)
|
|
|
|
gtk_text_buffer_insert(buffer, &iter, buf, bufp - buf);
|
2003-03-13 12:12:58 +01:00
|
|
|
|
|
|
|
if (prefs_common.enable_color) {
|
|
|
|
link_color = &uri_color;
|
|
|
|
}
|
2006-08-02 18:30:28 +02:00
|
|
|
r_uri = g_new0(ClickableText, 1);
|
2003-03-13 12:12:58 +01:00
|
|
|
r_uri->uri = g_strdup(uri);
|
2003-10-05 12:10:30 +02:00
|
|
|
r_uri->start = gtk_text_iter_get_offset(&iter);
|
2005-01-29 17:53:23 +01:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name
|
|
|
|
(buffer, &iter, bufp, -1, "link", NULL);
|
2003-10-05 12:10:30 +02:00
|
|
|
r_uri->end = gtk_text_iter_get_offset(&iter);
|
2005-04-01 10:16:46 +02:00
|
|
|
r_uri->filename = NULL;
|
2006-09-29 18:57:15 +02:00
|
|
|
textview->uri_list = g_slist_prepend(textview->uri_list, r_uri);
|
2003-03-13 12:12:58 +01:00
|
|
|
}
|
|
|
|
|
2006-04-18 18:41:51 +02:00
|
|
|
static void textview_set_cursor(GdkWindow *window, GdkCursor *cursor)
|
|
|
|
{
|
|
|
|
if (GDK_IS_WINDOW(window))
|
|
|
|
gdk_window_set_cursor(window, cursor);
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
void textview_clear(TextView *textview)
|
|
|
|
{
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
GtkTextBuffer *buffer;
|
2006-04-05 18:47:17 +02:00
|
|
|
GdkWindow *window = gtk_text_view_get_window(text,
|
|
|
|
GTK_TEXT_WINDOW_TEXT);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
buffer = gtk_text_view_get_buffer(text);
|
2005-01-03 13:54:14 +01:00
|
|
|
gtk_text_buffer_set_text(buffer, "", -1);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
TEXTVIEW_STATUSBAR_POP(textview);
|
2001-04-19 14:21:46 +02:00
|
|
|
textview_uri_list_remove_all(textview->uri_list);
|
|
|
|
textview->uri_list = NULL;
|
2006-04-06 18:18:20 +02:00
|
|
|
textview->uri_hover = NULL;
|
2007-04-24 12:05:01 +02:00
|
|
|
textview->prev_quote_level = -1;
|
2002-05-18 17:22:17 +02:00
|
|
|
|
|
|
|
textview->body_pos = 0;
|
2005-10-20 21:45:53 +02:00
|
|
|
if (textview->image)
|
|
|
|
gtk_widget_destroy(textview->image);
|
|
|
|
textview->image = NULL;
|
2006-04-05 18:47:17 +02:00
|
|
|
|
|
|
|
if (textview->messageview->mainwin->cursor_count == 0) {
|
2006-04-18 18:41:51 +02:00
|
|
|
textview_set_cursor(window, text_cursor);
|
2006-04-05 18:47:17 +02:00
|
|
|
} else {
|
2006-04-18 18:41:51 +02:00
|
|
|
textview_set_cursor(window, watch_cursor);
|
2006-04-05 18:47:17 +02:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void textview_destroy(TextView *textview)
|
|
|
|
{
|
2006-09-21 08:12:00 +02:00
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkClipboard *clipboard;
|
|
|
|
|
|
|
|
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text));
|
|
|
|
clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
|
|
|
|
gtk_text_buffer_remove_selection_clipboard(buffer, clipboard);
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
textview_uri_list_remove_all(textview->uri_list);
|
|
|
|
textview->uri_list = NULL;
|
2007-04-24 12:05:01 +02:00
|
|
|
textview->prev_quote_level = -1;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
g_free(textview);
|
|
|
|
}
|
|
|
|
|
2002-02-04 10:56:44 +01:00
|
|
|
void textview_set_all_headers(TextView *textview, gboolean all_headers)
|
|
|
|
{
|
|
|
|
textview->show_all_headers = all_headers;
|
|
|
|
}
|
|
|
|
|
2005-08-31 12:15:44 +02:00
|
|
|
#define CHANGE_TAG_FONT(tagname, font) { \
|
|
|
|
tag = gtk_text_tag_table_lookup(tags, tagname); \
|
|
|
|
if (tag) \
|
|
|
|
g_object_set(G_OBJECT(tag), "font-desc", font, NULL); \
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
void textview_set_font(TextView *textview, const gchar *codeset)
|
|
|
|
{
|
2005-08-31 12:15:44 +02:00
|
|
|
GtkTextTag *tag;
|
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text));
|
|
|
|
GtkTextTagTable *tags = gtk_text_buffer_get_tag_table(buffer);
|
|
|
|
|
|
|
|
if (NORMAL_FONT) {
|
|
|
|
PangoFontDescription *font_desc, *bold_font_desc;
|
|
|
|
font_desc = pango_font_description_from_string
|
|
|
|
(NORMAL_FONT);
|
|
|
|
bold_font_desc = pango_font_description_from_string
|
|
|
|
(NORMAL_FONT);
|
|
|
|
if (font_desc) {
|
|
|
|
gtk_widget_modify_font(textview->text, font_desc);
|
|
|
|
CHANGE_TAG_FONT("header", font_desc);
|
2007-01-19 20:04:05 +01:00
|
|
|
CHANGE_TAG_FONT("hlink", font_desc);
|
2005-09-08 18:54:33 +02:00
|
|
|
pango_font_description_free(font_desc);
|
2005-08-31 12:15:44 +02:00
|
|
|
}
|
|
|
|
if (bold_font_desc) {
|
|
|
|
pango_font_description_set_weight
|
|
|
|
(bold_font_desc, PANGO_WEIGHT_BOLD);
|
|
|
|
CHANGE_TAG_FONT("header_title", bold_font_desc);
|
|
|
|
pango_font_description_free(bold_font_desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
if (prefs_common.textfont) {
|
2005-08-31 12:15:44 +02:00
|
|
|
PangoFontDescription *font_desc;
|
2003-10-05 12:10:30 +02:00
|
|
|
|
2005-02-03 08:47:34 +01:00
|
|
|
font_desc = pango_font_description_from_string
|
2003-10-05 12:10:30 +02:00
|
|
|
(prefs_common.textfont);
|
|
|
|
if (font_desc) {
|
|
|
|
gtk_widget_modify_font(textview->text, font_desc);
|
|
|
|
pango_font_description_free(font_desc);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
}
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(textview->text),
|
|
|
|
prefs_common.line_space / 2);
|
|
|
|
gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(textview->text),
|
|
|
|
prefs_common.line_space / 2);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
void textview_set_text(TextView *textview, const gchar *text)
|
|
|
|
{
|
2004-01-18 13:41:20 +01:00
|
|
|
GtkTextView *view;
|
2004-01-12 22:28:31 +01:00
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
|
|
|
|
g_return_if_fail(textview != NULL);
|
|
|
|
g_return_if_fail(text != NULL);
|
|
|
|
|
|
|
|
textview_clear(textview);
|
|
|
|
|
2004-01-18 13:41:20 +01:00
|
|
|
view = GTK_TEXT_VIEW(textview->text);
|
|
|
|
buffer = gtk_text_view_get_buffer(view);
|
2004-01-12 22:28:31 +01:00
|
|
|
gtk_text_buffer_set_text(buffer, text, strlen(text));
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
H_DATE = 0,
|
|
|
|
H_FROM = 1,
|
|
|
|
H_TO = 2,
|
|
|
|
H_NEWSGROUPS = 3,
|
|
|
|
H_SUBJECT = 4,
|
|
|
|
H_CC = 5,
|
|
|
|
H_REPLY_TO = 6,
|
|
|
|
H_FOLLOWUP_TO = 7,
|
|
|
|
H_X_MAILER = 8,
|
|
|
|
H_X_NEWSREADER = 9,
|
|
|
|
H_USER_AGENT = 10,
|
|
|
|
H_ORGANIZATION = 11,
|
|
|
|
};
|
|
|
|
|
2001-09-30 13:07:34 +02:00
|
|
|
void textview_set_position(TextView *textview, gint pos)
|
|
|
|
{
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
|
2006-02-15 16:21:49 +01:00
|
|
|
gtkut_text_view_set_position(text, pos);
|
2001-09-30 13:07:34 +02:00
|
|
|
}
|
|
|
|
|
2006-09-06 08:43:33 +02:00
|
|
|
static gboolean header_is_internal(Header *header)
|
|
|
|
{
|
|
|
|
const gchar *internal_hdrs[] =
|
|
|
|
{"AF:", "NF:", "PS:", "SRH:", "SFN:", "DSR:", "MID:",
|
|
|
|
"CFG:", "PT:", "S:", "RQ:", "SSV:", "NSV:", "SSH:",
|
|
|
|
"R:", "MAID:", "SCF:", "RMID:", "FMID:", "NAID:",
|
2006-12-06 09:18:34 +01:00
|
|
|
"X-Claws-Account-Id:", "X-Claws-Sign:", "X-Claws-Encrypt:",
|
|
|
|
"X-Claws-Privacy-System:", "X-Claws-End-Special-Headers:",
|
2006-09-06 08:43:33 +02:00
|
|
|
"X-Sylpheed-Account-Id:", "X-Sylpheed-Sign:", "X-Sylpheed-Encrypt:",
|
|
|
|
"X-Sylpheed-Privacy-System:", "X-Sylpheed-End-Special-Headers:",
|
|
|
|
NULL};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; internal_hdrs[i]; i++) {
|
|
|
|
if (!strcmp(header->name, internal_hdrs[i]))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
|
|
|
|
{
|
2001-05-06 22:06:56 +02:00
|
|
|
gchar buf[BUFFSIZE];
|
|
|
|
GPtrArray *headers, *sorted_headers;
|
|
|
|
GSList *disphdr_list;
|
|
|
|
Header *header;
|
2001-07-15 15:54:20 +02:00
|
|
|
gint i;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(fp != NULL, NULL);
|
|
|
|
|
2006-09-06 08:43:33 +02:00
|
|
|
if (textview->show_all_headers) {
|
|
|
|
headers = procheader_get_header_array_asis(fp);
|
|
|
|
sorted_headers = g_ptr_array_new();
|
|
|
|
for (i = 0; i < headers->len; i++) {
|
|
|
|
header = g_ptr_array_index(headers, i);
|
|
|
|
if (!header_is_internal(header))
|
|
|
|
g_ptr_array_add(sorted_headers, header);
|
|
|
|
else
|
|
|
|
procheader_header_free(header);
|
|
|
|
}
|
|
|
|
g_ptr_array_free(headers, TRUE);
|
|
|
|
return sorted_headers;
|
|
|
|
}
|
2002-02-04 10:56:44 +01:00
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
if (!prefs_common.display_header) {
|
|
|
|
while (fgets(buf, sizeof(buf), fp) != NULL)
|
|
|
|
if (buf[0] == '\r' || buf[0] == '\n') break;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-05-06 22:06:56 +02:00
|
|
|
headers = procheader_get_header_array_asis(fp);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-05-06 22:06:56 +02:00
|
|
|
sorted_headers = g_ptr_array_new();
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-05-06 22:06:56 +02:00
|
|
|
for (disphdr_list = prefs_common.disphdr_list; disphdr_list != NULL;
|
|
|
|
disphdr_list = disphdr_list->next) {
|
|
|
|
DisplayHeaderProp *dp =
|
|
|
|
(DisplayHeaderProp *)disphdr_list->data;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-05-06 22:06:56 +02:00
|
|
|
for (i = 0; i < headers->len; i++) {
|
|
|
|
header = g_ptr_array_index(headers, i);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-05-08 16:25:21 +02:00
|
|
|
if (procheader_headername_equal(header->name,
|
|
|
|
dp->name)) {
|
2001-05-06 22:06:56 +02:00
|
|
|
if (dp->hidden)
|
2001-05-06 06:27:28 +02:00
|
|
|
procheader_header_free(header);
|
2001-05-06 22:06:56 +02:00
|
|
|
else
|
|
|
|
g_ptr_array_add(sorted_headers, header);
|
|
|
|
|
|
|
|
g_ptr_array_remove_index(headers, i);
|
|
|
|
i--;
|
2001-05-01 01:21:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-06 22:06:56 +02:00
|
|
|
if (prefs_common.show_other_header) {
|
|
|
|
for (i = 0; i < headers->len; i++) {
|
|
|
|
header = g_ptr_array_index(headers, i);
|
2006-09-06 08:43:33 +02:00
|
|
|
if (!header_is_internal(header)) {
|
|
|
|
g_ptr_array_add(sorted_headers, header);
|
|
|
|
} else {
|
|
|
|
procheader_header_free(header);
|
|
|
|
}
|
2002-08-04 19:40:45 +02:00
|
|
|
}
|
2002-08-05 10:01:46 +02:00
|
|
|
g_ptr_array_free(headers, TRUE);
|
|
|
|
} else
|
|
|
|
procheader_header_array_destroy(headers);
|
2001-05-01 01:21:18 +02:00
|
|
|
|
2003-03-13 12:12:58 +01:00
|
|
|
|
2001-05-01 01:21:18 +02:00
|
|
|
return sorted_headers;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2006-02-05 18:56:40 +01:00
|
|
|
static void textview_show_face(TextView *textview)
|
|
|
|
{
|
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
MsgInfo *msginfo = textview->messageview->msginfo;
|
|
|
|
int x = 0;
|
2006-02-05 19:18:46 +01:00
|
|
|
|
2006-02-06 18:56:35 +01:00
|
|
|
if (prefs_common.display_header_pane
|
|
|
|
|| !prefs_common.display_xface)
|
2006-02-05 19:18:46 +01:00
|
|
|
goto bail;
|
2006-02-06 18:56:35 +01:00
|
|
|
|
2006-08-24 18:43:55 +02:00
|
|
|
if (!msginfo->extradata || !msginfo->extradata->face) {
|
2006-02-05 18:56:40 +01:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (textview->image)
|
|
|
|
gtk_widget_destroy(textview->image);
|
|
|
|
|
2006-08-24 18:43:55 +02:00
|
|
|
textview->image = face_get_from_header(msginfo->extradata->face);
|
2006-03-06 01:13:24 +01:00
|
|
|
g_return_if_fail(textview->image != NULL);
|
2006-02-06 18:56:35 +01:00
|
|
|
|
2006-02-05 18:56:40 +01:00
|
|
|
gtk_widget_show(textview->image);
|
|
|
|
|
|
|
|
x = textview->text->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;
|
|
|
|
}
|
|
|
|
|
2006-10-07 19:45:59 +02:00
|
|
|
void textview_show_icon(TextView *textview, const gchar *stock_id)
|
2006-04-05 18:47:17 +02:00
|
|
|
{
|
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
if (textview->image)
|
|
|
|
gtk_widget_destroy(textview->image);
|
|
|
|
|
|
|
|
textview->image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_DIALOG);
|
|
|
|
g_return_if_fail(textview->image != NULL);
|
|
|
|
|
|
|
|
gtk_widget_show(textview->image);
|
|
|
|
|
|
|
|
x = textview->text->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;
|
|
|
|
}
|
|
|
|
|
2005-10-20 19:49:21 +02:00
|
|
|
#if HAVE_LIBCOMPFACE
|
|
|
|
static void textview_show_xface(TextView *textview)
|
|
|
|
{
|
|
|
|
MsgInfo *msginfo = textview->messageview->msginfo;
|
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
2005-10-21 19:31:15 +02:00
|
|
|
int x = 0;
|
2006-10-24 19:53:20 +02:00
|
|
|
GdkWindow *window = NULL;
|
|
|
|
|
2005-10-20 19:49:21 +02:00
|
|
|
if (prefs_common.display_header_pane
|
|
|
|
|| !prefs_common.display_xface)
|
|
|
|
goto bail;
|
|
|
|
|
2006-08-24 18:43:55 +02:00
|
|
|
if (!msginfo || !msginfo->extradata)
|
2005-10-20 19:49:21 +02:00
|
|
|
goto bail;
|
|
|
|
|
2006-08-24 18:43:55 +02:00
|
|
|
if (msginfo->extradata->face)
|
2006-02-05 18:56:40 +01:00
|
|
|
return;
|
|
|
|
|
2006-08-24 18:43:55 +02:00
|
|
|
if (!msginfo->extradata->xface || strlen(msginfo->extradata->xface) < 5) {
|
2005-10-20 19:49:21 +02:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (textview->image)
|
|
|
|
gtk_widget_destroy(textview->image);
|
2006-10-24 19:53:20 +02:00
|
|
|
|
|
|
|
window = mainwindow_get_mainwindow() ?
|
|
|
|
mainwindow_get_mainwindow()->window->window :
|
|
|
|
textview->text->window;
|
2006-08-24 18:43:55 +02:00
|
|
|
textview->image = xface_get_from_header(msginfo->extradata->xface,
|
2006-02-06 18:56:35 +01:00
|
|
|
&textview->text->style->white,
|
2006-10-24 19:53:20 +02:00
|
|
|
window);
|
2006-03-06 01:13:24 +01:00
|
|
|
g_return_if_fail(textview->image != NULL);
|
2006-02-06 18:56:35 +01:00
|
|
|
|
2005-10-20 19:49:21 +02:00
|
|
|
gtk_widget_show(textview->image);
|
2005-10-21 19:31:15 +02:00
|
|
|
|
|
|
|
x = textview->text->allocation.width - WIDTH -5;
|
|
|
|
|
2005-10-20 19:49:21 +02:00
|
|
|
gtk_text_view_add_child_in_window(text, textview->image,
|
2005-10-21 19:31:15 +02:00
|
|
|
GTK_TEXT_WINDOW_TEXT, x, 5);
|
2005-10-20 19:49:21 +02:00
|
|
|
|
|
|
|
gtk_widget_show_all(textview->text);
|
|
|
|
|
|
|
|
return;
|
|
|
|
bail:
|
|
|
|
if (textview->image)
|
|
|
|
gtk_widget_destroy(textview->image);
|
|
|
|
textview->image = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-02 18:35:40 +02:00
|
|
|
static void textview_show_tags(TextView *textview)
|
|
|
|
{
|
|
|
|
MsgInfo *msginfo = textview->messageview->msginfo;
|
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
|
|
|
|
GtkTextIter iter;
|
|
|
|
ClickableText *uri;
|
|
|
|
GSList *cur;
|
|
|
|
gboolean found_tag = FALSE;
|
|
|
|
|
|
|
|
if (!msginfo->tags)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (cur = msginfo->tags; cur; cur = cur->next) {
|
|
|
|
if (tags_get_tag(GPOINTER_TO_INT(cur->data)) != NULL) {
|
|
|
|
found_tag = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found_tag)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_end_iter (buffer, &iter);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(buffer,
|
|
|
|
&iter, _("Tags: "), -1,
|
|
|
|
"header_title", "header", "tags", NULL);
|
|
|
|
|
|
|
|
for (cur = msginfo->tags; cur; cur = cur->next) {
|
|
|
|
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,
|
|
|
|
tags_get_tag(GPOINTER_TO_INT(cur->data)), -1,
|
|
|
|
"link", "header", "tags", NULL);
|
|
|
|
uri->end = gtk_text_iter_get_offset(&iter);
|
|
|
|
uri->filename = g_strdup_printf("sc://search_tags:%s", tags_get_tag(GPOINTER_TO_INT(cur->data)));
|
|
|
|
uri->data = NULL;
|
|
|
|
textview->uri_list =
|
|
|
|
g_slist_prepend(textview->uri_list, uri);
|
|
|
|
if (cur->next)
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, ", ", 2,
|
|
|
|
"header", "tags", NULL);
|
|
|
|
else
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, " ", 1,
|
|
|
|
"header", "tags", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "\n", 1,
|
|
|
|
"header", "tags", NULL);
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static void textview_show_header(TextView *textview, GPtrArray *headers)
|
|
|
|
{
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
|
|
|
|
GtkTextIter iter;
|
2001-04-19 14:21:46 +02:00
|
|
|
Header *header;
|
2001-07-15 15:54:20 +02:00
|
|
|
gint i;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
g_return_if_fail(headers != NULL);
|
|
|
|
|
2007-07-02 18:35:40 +02:00
|
|
|
textview_show_tags(textview);
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
for (i = 0; i < headers->len; i++) {
|
|
|
|
header = g_ptr_array_index(headers, i);
|
|
|
|
g_return_if_fail(header->name != NULL);
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_text_buffer_get_end_iter (buffer, &iter);
|
2006-03-12 11:36:15 +01:00
|
|
|
if(prefs_common.trans_hdr == TRUE) {
|
|
|
|
gchar *hdr = g_strndup(header->name, strlen(header->name) - 1);
|
|
|
|
gchar *trans_hdr = gettext(hdr);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(buffer,
|
|
|
|
&iter, trans_hdr, -1,
|
|
|
|
"header_title", "header", NULL);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(buffer,
|
|
|
|
&iter, ":", 1, "header_title", "header", NULL);
|
|
|
|
g_free(hdr);
|
|
|
|
} else {
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(buffer,
|
|
|
|
&iter, header->name,
|
|
|
|
-1, "header_title", "header", NULL);
|
|
|
|
}
|
2001-05-28 00:40:29 +02:00
|
|
|
if (header->name[strlen(header->name) - 1] != ' ')
|
2004-07-03 18:31:08 +02:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name
|
2003-10-05 12:10:30 +02:00
|
|
|
(buffer, &iter, " ", 1,
|
|
|
|
"header_title", "header", NULL);
|
2001-05-06 22:06:56 +02:00
|
|
|
|
2001-05-08 16:25:21 +02:00
|
|
|
if (procheader_headername_equal(header->name, "Subject") ||
|
|
|
|
procheader_headername_equal(header->name, "From") ||
|
|
|
|
procheader_headername_equal(header->name, "To") ||
|
|
|
|
procheader_headername_equal(header->name, "Cc"))
|
2001-05-06 22:06:56 +02:00
|
|
|
unfold_line(header->body);
|
|
|
|
|
2005-08-03 20:24:13 +02:00
|
|
|
if ((procheader_headername_equal(header->name, "X-Mailer") ||
|
2001-05-08 16:25:21 +02:00
|
|
|
procheader_headername_equal(header->name,
|
|
|
|
"X-Newsreader")) &&
|
2006-11-30 19:45:38 +01:00
|
|
|
(strstr(header->body, "Claws Mail") != NULL ||
|
|
|
|
strstr(header->body, "Sylpheed-Claws") != NULL)) {
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_text_buffer_get_end_iter (buffer, &iter);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name
|
|
|
|
(buffer, &iter, header->body, -1,
|
|
|
|
"header", "emphasis", NULL);
|
2005-08-03 20:24:13 +02:00
|
|
|
} else {
|
2005-11-08 19:08:15 +01:00
|
|
|
gboolean hdr =
|
|
|
|
procheader_headername_equal(header->name, "From") ||
|
|
|
|
procheader_headername_equal(header->name, "To") ||
|
|
|
|
procheader_headername_equal(header->name, "Cc") ||
|
2006-05-12 20:08:21 +02:00
|
|
|
procheader_headername_equal(header->name, "Bcc") ||
|
2006-05-19 09:04:40 +02:00
|
|
|
procheader_headername_equal(header->name, "Reply-To") ||
|
2006-05-12 20:08:21 +02:00
|
|
|
procheader_headername_equal(header->name, "Sender");
|
2005-11-08 19:08:15 +01:00
|
|
|
textview_make_clickable_parts(textview, "header",
|
2006-09-13 19:25:48 +02:00
|
|
|
"hlink", header->body,
|
2005-11-08 19:08:15 +01:00
|
|
|
hdr);
|
2005-08-03 20:24:13 +02:00
|
|
|
}
|
2003-10-05 12:10:30 +02:00
|
|
|
gtk_text_buffer_get_end_iter (buffer, &iter);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "\n", 1,
|
|
|
|
"header", NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
2006-02-05 18:56:40 +01:00
|
|
|
|
|
|
|
textview_show_face(textview);
|
2005-10-20 19:49:21 +02:00
|
|
|
#if HAVE_LIBCOMPFACE
|
|
|
|
textview_show_xface(textview);
|
|
|
|
#endif
|
2001-09-24 10:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean textview_search_string(TextView *textview, const gchar *str,
|
|
|
|
gboolean case_sens)
|
|
|
|
{
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
|
2006-02-15 16:21:49 +01:00
|
|
|
return gtkut_text_view_search_string(text, str, case_sens);
|
2001-09-30 13:07:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean textview_search_string_backward(TextView *textview, const gchar *str,
|
|
|
|
gboolean case_sens)
|
|
|
|
{
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
|
2006-02-15 16:21:49 +01:00
|
|
|
return gtkut_text_view_search_string_backward(text, str, case_sens);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void textview_scroll_one_line(TextView *textview, gboolean up)
|
|
|
|
{
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
GtkAdjustment *vadj = text->vadjustment;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2006-09-03 08:50:41 +02:00
|
|
|
gtkutils_scroll_one_line(GTK_WIDGET(text), vadj, up);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean textview_scroll_page(TextView *textview, gboolean up)
|
|
|
|
{
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
|
|
|
|
GtkAdjustment *vadj = text->vadjustment;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2006-09-03 08:50:41 +02:00
|
|
|
return gtkutils_scroll_page(GTK_WIDGET(text), vadj, up);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
#define KEY_PRESS_EVENT_STOP() \
|
|
|
|
g_signal_stop_emission_by_name(G_OBJECT(widget), \
|
|
|
|
"key_press_event");
|
2002-01-29 11:03:33 +01:00
|
|
|
|
|
|
|
static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
|
2001-04-19 14:21:46 +02:00
|
|
|
TextView *textview)
|
|
|
|
{
|
|
|
|
SummaryView *summaryview = NULL;
|
2002-01-29 11:03:33 +01:00
|
|
|
MessageView *messageview = textview->messageview;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-01-29 11:03:33 +01:00
|
|
|
if (!event) return FALSE;
|
|
|
|
if (messageview->mainwin)
|
|
|
|
summaryview = messageview->mainwin->summaryview;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
switch (event->keyval) {
|
|
|
|
case GDK_Tab:
|
|
|
|
case GDK_Home:
|
|
|
|
case GDK_Left:
|
|
|
|
case GDK_Up:
|
|
|
|
case GDK_Right:
|
|
|
|
case GDK_Down:
|
|
|
|
case GDK_Page_Up:
|
|
|
|
case GDK_Page_Down:
|
|
|
|
case GDK_End:
|
|
|
|
case GDK_Control_L:
|
|
|
|
case GDK_Control_R:
|
2005-01-04 09:35:32 +01:00
|
|
|
return FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
case GDK_space:
|
|
|
|
if (summaryview)
|
|
|
|
summary_pass_key_press_event(summaryview, event);
|
|
|
|
else
|
2006-08-29 18:27:14 +02:00
|
|
|
mimeview_scroll_page
|
|
|
|
(messageview->mimeview,
|
2004-11-12 07:41:50 +01:00
|
|
|
(event->state &
|
|
|
|
(GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0);
|
2001-04-19 14:21:46 +02:00
|
|
|
break;
|
|
|
|
case GDK_BackSpace:
|
2006-08-29 18:27:14 +02:00
|
|
|
mimeview_scroll_page(messageview->mimeview, TRUE);
|
2001-04-19 14:21:46 +02:00
|
|
|
break;
|
|
|
|
case GDK_Return:
|
2007-06-15 19:18:19 +02:00
|
|
|
case GDK_KP_Enter:
|
2006-08-29 18:27:14 +02:00
|
|
|
mimeview_scroll_one_line
|
|
|
|
(messageview->mimeview, (event->state &
|
2004-11-12 07:41:50 +01:00
|
|
|
(GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0);
|
2001-04-19 14:21:46 +02:00
|
|
|
break;
|
2002-09-03 09:47:27 +02:00
|
|
|
case GDK_Delete:
|
|
|
|
if (summaryview)
|
|
|
|
summary_pass_key_press_event(summaryview, event);
|
|
|
|
break;
|
2002-01-29 11:03:33 +01:00
|
|
|
case GDK_y:
|
|
|
|
case GDK_t:
|
|
|
|
case GDK_l:
|
2007-07-25 06:56:55 +02:00
|
|
|
case GDK_o:
|
2005-10-16 13:08:46 +02:00
|
|
|
case GDK_c:
|
2007-04-20 18:15:58 +02:00
|
|
|
case GDK_a:
|
2004-01-12 22:28:31 +01:00
|
|
|
if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) == 0) {
|
2002-01-29 11:03:33 +01:00
|
|
|
KEY_PRESS_EVENT_STOP();
|
|
|
|
mimeview_pass_key_press_event(messageview->mimeview,
|
|
|
|
event);
|
|
|
|
break;
|
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
/* possible fall through */
|
2001-04-19 14:21:46 +02:00
|
|
|
default:
|
2002-06-19 10:04:32 +02:00
|
|
|
if (summaryview &&
|
|
|
|
event->window != messageview->mainwin->window->window) {
|
|
|
|
GdkEventKey tmpev = *event;
|
|
|
|
|
|
|
|
tmpev.window = messageview->mainwin->window->window;
|
|
|
|
KEY_PRESS_EVENT_STOP();
|
|
|
|
gtk_widget_event(messageview->mainwin->window,
|
|
|
|
(GdkEvent *)&tmpev);
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
break;
|
|
|
|
}
|
2002-01-29 11:03:33 +01:00
|
|
|
|
|
|
|
return TRUE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-11-06 10:39:33 +01:00
|
|
|
static gboolean textview_motion_notify(GtkWidget *widget,
|
|
|
|
GdkEventMotion *event,
|
|
|
|
TextView *textview)
|
2003-10-05 12:10:30 +02:00
|
|
|
{
|
2006-09-04 18:56:18 +02:00
|
|
|
if (textview->loading)
|
|
|
|
return FALSE;
|
2004-11-06 10:39:33 +01:00
|
|
|
textview_uri_update(textview, event->x, event->y);
|
|
|
|
gdk_window_get_pointer(widget->window, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean textview_leave_notify(GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event,
|
|
|
|
TextView *textview)
|
|
|
|
{
|
2006-09-04 18:56:18 +02:00
|
|
|
if (textview->loading)
|
|
|
|
return FALSE;
|
2004-11-06 10:39:33 +01:00
|
|
|
textview_uri_update(textview, -1, -1);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean textview_visibility_notify(GtkWidget *widget,
|
|
|
|
GdkEventVisibility *event,
|
|
|
|
TextView *textview)
|
|
|
|
{
|
|
|
|
gint wx, wy;
|
2004-11-12 16:55:21 +01:00
|
|
|
GdkWindow *window;
|
|
|
|
|
2006-09-04 18:56:18 +02:00
|
|
|
if (textview->loading)
|
|
|
|
return FALSE;
|
|
|
|
|
2004-11-12 16:55:21 +01:00
|
|
|
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;
|
|
|
|
|
2004-11-06 10:39:33 +01:00
|
|
|
gdk_window_get_pointer(widget->window, &wx, &wy, NULL);
|
|
|
|
textview_uri_update(textview, wx, wy);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-03-18 20:16:07 +01:00
|
|
|
void textview_cursor_wait(TextView *textview)
|
|
|
|
{
|
|
|
|
GdkWindow *window = gtk_text_view_get_window(
|
|
|
|
GTK_TEXT_VIEW(textview->text),
|
|
|
|
GTK_TEXT_WINDOW_TEXT);
|
2006-04-18 18:41:51 +02:00
|
|
|
textview_set_cursor(window, watch_cursor);
|
2006-03-18 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void textview_cursor_normal(TextView *textview)
|
|
|
|
{
|
|
|
|
GdkWindow *window = gtk_text_view_get_window(
|
|
|
|
GTK_TEXT_VIEW(textview->text),
|
|
|
|
GTK_TEXT_WINDOW_TEXT);
|
2006-04-18 18:41:51 +02:00
|
|
|
textview_set_cursor(window, text_cursor);
|
2006-03-18 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2004-11-06 10:39:33 +01:00
|
|
|
static void textview_uri_update(TextView *textview, gint x, gint y)
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer;
|
2003-10-05 12:10:30 +02:00
|
|
|
GtkTextIter start_iter, end_iter;
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri = NULL;
|
2004-10-26 12:43:50 +02:00
|
|
|
|
2004-11-06 10:39:33 +01:00
|
|
|
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text));
|
|
|
|
|
|
|
|
if (x != -1 && y != -1) {
|
|
|
|
gint bx, by;
|
|
|
|
GtkTextIter iter;
|
|
|
|
GSList *tags;
|
|
|
|
GSList *cur;
|
2006-08-03 18:37:50 +02:00
|
|
|
|
2004-11-06 10:39:33 +01:00
|
|
|
gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(textview->text),
|
|
|
|
GTK_TEXT_WINDOW_WIDGET,
|
|
|
|
x, y, &bx, &by);
|
|
|
|
gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(textview->text),
|
|
|
|
&iter, bx, by);
|
|
|
|
|
|
|
|
tags = gtk_text_iter_get_tags(&iter);
|
|
|
|
for (cur = tags; cur != NULL; cur = cur->next) {
|
|
|
|
GtkTextTag *tag = cur->data;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
g_object_get(G_OBJECT(tag), "name", &name, NULL);
|
2006-08-02 18:30:28 +02:00
|
|
|
|
2006-09-13 19:25:48 +02:00
|
|
|
if ((!strcmp(name, "link") || !strcmp(name, "hlink"))
|
2004-11-06 10:39:33 +01:00
|
|
|
&& textview_get_uri_range(textview, &iter, tag,
|
2006-08-02 18:30:28 +02:00
|
|
|
&start_iter, &end_iter)) {
|
|
|
|
|
2006-08-03 21:07:36 +02:00
|
|
|
uri = textview_get_uri_from_range(textview,
|
2006-08-03 18:37:50 +02:00
|
|
|
&iter, tag,
|
|
|
|
&start_iter,
|
|
|
|
&end_iter);
|
|
|
|
}
|
|
|
|
g_free(name);
|
2006-08-03 21:07:36 +02:00
|
|
|
if (uri)
|
2004-11-06 10:39:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_slist_free(tags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uri != textview->uri_hover) {
|
|
|
|
GdkWindow *window;
|
|
|
|
|
|
|
|
if (textview->uri_hover)
|
|
|
|
gtk_text_buffer_remove_tag_by_name(buffer,
|
|
|
|
"link-hover",
|
|
|
|
&textview->uri_hover_start_iter,
|
|
|
|
&textview->uri_hover_end_iter);
|
|
|
|
|
|
|
|
textview->uri_hover = uri;
|
|
|
|
if (uri) {
|
|
|
|
textview->uri_hover_start_iter = start_iter;
|
|
|
|
textview->uri_hover_end_iter = end_iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
window = gtk_text_view_get_window(GTK_TEXT_VIEW(textview->text),
|
|
|
|
GTK_TEXT_WINDOW_TEXT);
|
2006-03-18 20:16:07 +01:00
|
|
|
if (textview->messageview->mainwin->cursor_count == 0) {
|
2006-04-18 18:41:51 +02:00
|
|
|
textview_set_cursor(window, uri ? hand_cursor : text_cursor);
|
2006-03-18 20:16:07 +01:00
|
|
|
} else {
|
2006-04-18 18:41:51 +02:00
|
|
|
textview_set_cursor(window, watch_cursor);
|
2006-03-18 20:16:07 +01:00
|
|
|
}
|
2003-10-05 12:10:30 +02:00
|
|
|
|
2004-11-06 10:39:33 +01:00
|
|
|
TEXTVIEW_STATUSBAR_POP(textview);
|
|
|
|
|
|
|
|
if (uri) {
|
|
|
|
char *trimmed_uri;
|
2003-10-05 12:10:30 +02:00
|
|
|
|
2006-08-02 18:30:28 +02:00
|
|
|
if (!uri->is_quote)
|
|
|
|
gtk_text_buffer_apply_tag_by_name(buffer,
|
2004-11-06 10:39:33 +01:00
|
|
|
"link-hover",
|
|
|
|
&start_iter,
|
|
|
|
&end_iter);
|
|
|
|
|
|
|
|
trimmed_uri = trim_string(uri->uri, 60);
|
|
|
|
TEXTVIEW_STATUSBAR_PUSH(textview, trimmed_uri);
|
|
|
|
g_free(trimmed_uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean textview_get_uri_range(TextView *textview,
|
|
|
|
GtkTextIter *iter,
|
|
|
|
GtkTextTag *tag,
|
|
|
|
GtkTextIter *start_iter,
|
|
|
|
GtkTextIter *end_iter)
|
|
|
|
{
|
2005-11-06 11:24:50 +01:00
|
|
|
return get_tag_range(iter, tag, start_iter, end_iter);
|
2004-11-06 10:39:33 +01:00
|
|
|
}
|
2003-10-05 12:10:30 +02:00
|
|
|
|
2006-08-02 18:30:28 +02:00
|
|
|
static ClickableText *textview_get_uri_from_range(TextView *textview,
|
2004-11-06 10:39:33 +01:00
|
|
|
GtkTextIter *iter,
|
|
|
|
GtkTextTag *tag,
|
|
|
|
GtkTextIter *start_iter,
|
|
|
|
GtkTextIter *end_iter)
|
|
|
|
{
|
2004-11-08 12:06:35 +01:00
|
|
|
gint start_pos, end_pos, cur_pos;
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri = NULL;
|
2004-11-06 10:39:33 +01:00
|
|
|
GSList *cur;
|
|
|
|
|
|
|
|
start_pos = gtk_text_iter_get_offset(start_iter);
|
|
|
|
end_pos = gtk_text_iter_get_offset(end_iter);
|
2004-11-08 12:06:35 +01:00
|
|
|
cur_pos = gtk_text_iter_get_offset(iter);
|
2004-11-06 10:39:33 +01:00
|
|
|
|
|
|
|
for (cur = textview->uri_list; cur != NULL; cur = cur->next) {
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri_ = (ClickableText *)cur->data;
|
2004-11-06 10:39:33 +01:00
|
|
|
if (start_pos == uri_->start &&
|
|
|
|
end_pos == uri_->end) {
|
|
|
|
uri = uri_;
|
|
|
|
break;
|
2006-08-03 18:37:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (cur = textview->uri_list; uri == NULL && cur != NULL; cur = cur->next) {
|
|
|
|
ClickableText *uri_ = (ClickableText *)cur->data;
|
|
|
|
if (start_pos == uri_->start ||
|
2004-11-08 12:06:35 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2004-11-06 10:39:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2006-08-02 18:30:28 +02:00
|
|
|
static ClickableText *textview_get_uri(TextView *textview,
|
2004-11-06 10:39:33 +01:00
|
|
|
GtkTextIter *iter,
|
|
|
|
GtkTextTag *tag)
|
|
|
|
{
|
|
|
|
GtkTextIter start_iter, end_iter;
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri = NULL;
|
2004-11-06 10:39:33 +01:00
|
|
|
|
|
|
|
if (textview_get_uri_range(textview, iter, tag, &start_iter,
|
|
|
|
&end_iter))
|
|
|
|
uri = textview_get_uri_from_range(textview, iter, tag,
|
|
|
|
&start_iter, &end_iter);
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2006-09-29 18:57:15 +02:00
|
|
|
static void textview_shift_uris_after(TextView *textview, GSList *start_list, gint start, gint shift)
|
2006-08-02 18:30:28 +02:00
|
|
|
{
|
|
|
|
GSList *cur;
|
2006-09-29 18:57:15 +02:00
|
|
|
if (!start_list)
|
|
|
|
start_list = textview->uri_list;
|
|
|
|
|
|
|
|
for (cur = start_list; cur; cur = cur->next) {
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri = (ClickableText *)cur->data;
|
|
|
|
if (uri->start <= start)
|
|
|
|
continue;
|
|
|
|
uri->start += shift;
|
|
|
|
uri->end += shift;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void textview_remove_uris_in(TextView *textview, gint start, gint end)
|
|
|
|
{
|
|
|
|
GSList *cur;
|
|
|
|
for (cur = textview->uri_list; cur; ) {
|
|
|
|
ClickableText *uri = (ClickableText *)cur->data;
|
|
|
|
if (uri->start > start && uri->end < end) {
|
|
|
|
cur = cur->next;
|
|
|
|
textview->uri_list = g_slist_remove(textview->uri_list, uri);
|
|
|
|
g_free(uri->uri);
|
|
|
|
g_free(uri->filename);
|
|
|
|
if (uri->is_quote) {
|
|
|
|
g_free(uri->fg_color);
|
|
|
|
g_free(uri->data);
|
|
|
|
/* (only free data in quotes uris) */
|
|
|
|
}
|
|
|
|
g_free(uri);
|
|
|
|
} else {
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-29 18:57:15 +02:00
|
|
|
static void textview_toggle_quote(TextView *textview, GSList *start_list, ClickableText *uri, gboolean expand_only)
|
2006-08-02 18:30:28 +02:00
|
|
|
{
|
|
|
|
GtkTextIter start, end;
|
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text));
|
|
|
|
|
|
|
|
if (!uri->is_quote)
|
|
|
|
return;
|
|
|
|
|
2006-08-03 08:52:53 +02:00
|
|
|
if (uri->q_expanded && expand_only)
|
|
|
|
return;
|
|
|
|
|
2006-08-02 18:30:28 +02:00
|
|
|
gtk_text_buffer_get_iter_at_offset(buffer, &start, uri->start);
|
|
|
|
gtk_text_buffer_get_iter_at_offset(buffer, &end, uri->end);
|
|
|
|
if (textview->uri_hover)
|
|
|
|
gtk_text_buffer_remove_tag_by_name(buffer,
|
|
|
|
"link-hover",
|
|
|
|
&textview->uri_hover_start_iter,
|
|
|
|
&textview->uri_hover_end_iter);
|
|
|
|
textview->uri_hover = NULL;
|
|
|
|
gtk_text_buffer_remove_tag_by_name(buffer,
|
|
|
|
"qlink",
|
|
|
|
&start,
|
|
|
|
&end);
|
|
|
|
/* when shifting URIs start and end, we have to do it per-UTF8-char
|
|
|
|
* so use g_utf8_strlen(). OTOH, when inserting in the text buffer,
|
|
|
|
* we have to pass a number of bytes, so use strlen(). disturbing. */
|
2006-08-03 08:42:12 +02:00
|
|
|
|
2006-08-02 18:30:28 +02:00
|
|
|
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);
|
2006-09-29 18:57:15 +02:00
|
|
|
textview_shift_uris_after(textview, start_list, uri->start,
|
2006-08-02 18:30:28 +02:00
|
|
|
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_insert_with_tags_by_name
|
|
|
|
(buffer, &start, (gchar *)uri->data,
|
|
|
|
strlen((gchar *)uri->data)-1,
|
|
|
|
"qlink", (gchar *)uri->fg_color, NULL);
|
|
|
|
uri->end = gtk_text_iter_get_offset(&start);
|
|
|
|
textview_make_clickable_parts_later(textview,
|
|
|
|
uri->start, uri->end);
|
|
|
|
uri->q_expanded = TRUE;
|
2006-08-03 08:52:53 +02:00
|
|
|
} else {
|
2006-08-02 18:30:28 +02:00
|
|
|
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);
|
2006-09-29 18:57:15 +02:00
|
|
|
textview_shift_uris_after(textview, start_list, uri->start,
|
2006-08-02 18:30:28 +02:00
|
|
|
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);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name
|
|
|
|
(buffer, &start, " [...]", -1,
|
|
|
|
"qlink", (gchar *)uri->fg_color, NULL);
|
|
|
|
uri->end = gtk_text_iter_get_offset(&start);
|
|
|
|
uri->q_expanded = FALSE;
|
|
|
|
}
|
|
|
|
if (textview->messageview->mainwin->cursor_count == 0) {
|
|
|
|
textview_cursor_normal(textview);
|
|
|
|
} else {
|
|
|
|
textview_cursor_wait(textview);
|
|
|
|
}
|
|
|
|
}
|
2004-11-06 10:39:33 +01:00
|
|
|
static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
|
|
|
|
GdkEvent *event, GtkTextIter *iter,
|
|
|
|
TextView *textview)
|
|
|
|
{
|
|
|
|
GdkEventButton *bevent;
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri = NULL;
|
|
|
|
char *tagname;
|
|
|
|
gboolean qlink = FALSE;
|
2004-11-06 10:39:33 +01:00
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (event->type != GDK_BUTTON_PRESS && event->type != GDK_2BUTTON_PRESS
|
|
|
|
&& event->type != GDK_MOTION_NOTIFY)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
uri = textview_get_uri(textview, iter, tag);
|
|
|
|
if (!uri)
|
|
|
|
return FALSE;
|
|
|
|
|
2006-08-02 18:30:28 +02:00
|
|
|
g_object_get(G_OBJECT(tag), "name", &tagname, NULL);
|
|
|
|
|
|
|
|
if (!strcmp(tagname, "qlink"))
|
|
|
|
qlink = TRUE;
|
|
|
|
|
|
|
|
g_free(tagname);
|
|
|
|
|
2004-11-06 10:39:33 +01:00
|
|
|
bevent = (GdkEventButton *) event;
|
|
|
|
|
|
|
|
/* doubleclick: open compose / add address / browser */
|
2006-08-04 18:12:21 +02:00
|
|
|
if (qlink && event->type == GDK_BUTTON_PRESS && bevent->button != 1) {
|
|
|
|
/* pass rightclick through */
|
|
|
|
return FALSE;
|
|
|
|
} else if ((event->type == (qlink ? GDK_2BUTTON_PRESS:GDK_BUTTON_PRESS) && bevent->button == 1) ||
|
2004-11-06 10:39:33 +01:00
|
|
|
bevent->button == 2 || bevent->button == 3) {
|
2006-04-05 18:47:17 +02:00
|
|
|
if (uri->filename && !g_ascii_strncasecmp(uri->filename, "sc://", 5)) {
|
2006-07-04 18:53:47 +02:00
|
|
|
MimeView *mimeview =
|
|
|
|
(textview->messageview)?
|
|
|
|
textview->messageview->mimeview:NULL;
|
|
|
|
if (mimeview && bevent->button == 1) {
|
2006-07-07 10:20:23 +02:00
|
|
|
mimeview_handle_cmd(mimeview, uri->filename, NULL, uri->data);
|
2006-07-04 18:53:47 +02:00
|
|
|
} else if (mimeview && bevent->button == 2 &&
|
|
|
|
!g_ascii_strcasecmp(uri->filename, "sc://select_attachment")) {
|
2006-07-07 10:20:23 +02:00
|
|
|
mimeview_handle_cmd(mimeview, "sc://open_attachment", NULL, uri->data);
|
|
|
|
} else if (mimeview && bevent->button == 3 &&
|
|
|
|
!g_ascii_strcasecmp(uri->filename, "sc://select_attachment")) {
|
|
|
|
mimeview_handle_cmd(mimeview, "sc://menu_attachment", bevent, uri->data);
|
|
|
|
}
|
2006-04-05 18:47:17 +02:00
|
|
|
return TRUE;
|
2006-08-02 18:30:28 +02:00
|
|
|
} else if (qlink && bevent->button == 1) {
|
2006-09-29 18:57:15 +02:00
|
|
|
textview_toggle_quote(textview, NULL, uri, FALSE);
|
2006-08-02 18:30:28 +02:00
|
|
|
return TRUE;
|
2006-04-05 18:47:17 +02:00
|
|
|
} else if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7)) {
|
2004-11-06 10:39:33 +01:00
|
|
|
if (bevent->button == 3) {
|
2005-02-09 14:15:30 +01:00
|
|
|
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);
|
2004-06-25 10:05:09 +02:00
|
|
|
} else {
|
2004-11-06 10:39:33 +01:00
|
|
|
PrefsAccount *account = NULL;
|
2006-09-27 18:49:42 +02:00
|
|
|
FolderItem *folder_item = NULL;
|
2004-11-06 10:39:33 +01:00
|
|
|
if (textview->messageview && textview->messageview->msginfo &&
|
|
|
|
textview->messageview->msginfo->folder) {
|
2006-09-27 18:49:42 +02:00
|
|
|
|
2004-11-06 10:39:33 +01:00
|
|
|
|
|
|
|
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);
|
2007-05-02 19:04:57 +02:00
|
|
|
if (!account)
|
|
|
|
account = account_find_from_item(folder_item);
|
2004-11-06 10:39:33 +01:00
|
|
|
}
|
2006-09-27 18:49:42 +02:00
|
|
|
compose_new_with_folderitem(account, folder_item, uri->uri + 7);
|
2004-06-25 10:05:09 +02:00
|
|
|
}
|
2004-11-06 10:39:33 +01:00
|
|
|
return TRUE;
|
2005-04-01 10:16:46 +02:00
|
|
|
} else if (g_ascii_strncasecmp(uri->uri, "file:", 5)) {
|
2004-11-19 11:39:01 +01:00
|
|
|
if (bevent->button == 1 &&
|
|
|
|
textview_uri_security_check(textview, uri) == TRUE)
|
|
|
|
open_uri(uri->uri,
|
|
|
|
prefs_common.uri_cmd);
|
2006-08-02 18:30:28 +02:00
|
|
|
else if (bevent->button == 3 && !qlink) {
|
2004-11-19 11:39:01 +01:00
|
|
|
g_object_set_data(
|
2005-02-09 14:15:30 +01:00
|
|
|
G_OBJECT(textview->link_popup_menu),
|
2004-11-19 11:39:01 +01:00
|
|
|
"menu_button", uri);
|
2005-02-09 14:15:30 +01:00
|
|
|
gtk_menu_popup(GTK_MENU(textview->link_popup_menu),
|
2004-11-19 11:39:01 +01:00
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
bevent->button, bevent->time);
|
|
|
|
}
|
2004-11-06 10:39:33 +01:00
|
|
|
return TRUE;
|
2005-04-01 10:16:46 +02:00
|
|
|
} else {
|
2006-08-02 18:30:28 +02:00
|
|
|
if (bevent->button == 3 && !qlink) {
|
2005-04-01 10:16:46 +02:00
|
|
|
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;
|
|
|
|
}
|
2004-07-03 13:51:00 +02:00
|
|
|
}
|
2003-10-05 12:10:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2007-02-02 18:48:17 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
/*!
|
|
|
|
*\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
|
|
|
|
*/
|
2007-02-02 18:48:17 +01:00
|
|
|
gboolean textview_uri_security_check(TextView *textview, ClickableText *uri)
|
2004-02-21 12:01:01 +01:00
|
|
|
{
|
|
|
|
gchar *visible_str;
|
|
|
|
gboolean retval = TRUE;
|
|
|
|
|
|
|
|
if (is_uri_string(uri->uri) == FALSE)
|
|
|
|
return TRUE;
|
|
|
|
|
2007-02-02 18:48:17 +01:00
|
|
|
visible_str = textview_get_visible_uri(textview, uri);
|
2004-02-21 12:01:01 +01:00
|
|
|
if (visible_str == NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (strcmp(visible_str, uri->uri) != 0 && is_uri_string(visible_str)) {
|
|
|
|
gchar *uri_path;
|
|
|
|
gchar *visible_uri_path;
|
|
|
|
|
|
|
|
uri_path = get_uri_path(uri->uri);
|
|
|
|
visible_uri_path = get_uri_path(visible_str);
|
2006-03-07 10:03:50 +01:00
|
|
|
if (path_cmp(uri_path, visible_uri_path) != 0)
|
2004-02-21 12:01:01 +01:00
|
|
|
retval = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == FALSE) {
|
|
|
|
gchar *msg;
|
|
|
|
AlertValue aval;
|
|
|
|
|
2006-06-20 15:04:37 +02:00
|
|
|
msg = g_markup_printf_escaped(_("The real URL is different from "
|
|
|
|
"the displayed URL.\n"
|
|
|
|
"\n"
|
|
|
|
"<b>Displayed URL:</b> %s\n"
|
|
|
|
"\n"
|
|
|
|
"<b>Real URL:</b> %s\n"
|
|
|
|
"\n"
|
|
|
|
"Open it anyway?"),
|
|
|
|
visible_str,uri->uri);
|
|
|
|
aval = alertpanel_full(_("Phishing attempt warning"), msg,
|
2006-01-14 12:04:52 +01:00
|
|
|
GTK_STOCK_CANCEL, _("_Open URL"), NULL, FALSE,
|
2006-01-14 10:45:39 +01:00
|
|
|
NULL, ALERT_WARNING, G_ALERTDEFAULT);
|
2004-02-21 12:01:01 +01:00
|
|
|
g_free(msg);
|
2006-01-14 10:45:39 +01:00
|
|
|
if (aval == G_ALERTALTERNATE)
|
2004-02-21 12:01:01 +01:00
|
|
|
retval = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(visible_str);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static void textview_uri_list_remove_all(GSList *uri_list)
|
|
|
|
{
|
|
|
|
GSList *cur;
|
|
|
|
|
|
|
|
for (cur = uri_list; cur != NULL; cur = cur->next) {
|
|
|
|
if (cur->data) {
|
2006-08-02 18:30:28 +02:00
|
|
|
g_free(((ClickableText *)cur->data)->uri);
|
|
|
|
g_free(((ClickableText *)cur->data)->filename);
|
|
|
|
if (((ClickableText *)cur->data)->is_quote) {
|
|
|
|
g_free(((ClickableText *)cur->data)->fg_color);
|
|
|
|
g_free(((ClickableText *)cur->data)->data);
|
|
|
|
/* (only free data in quotes uris) */
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
g_free(cur->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free(uri_list);
|
|
|
|
}
|
2004-11-19 11:39:01 +01:00
|
|
|
|
|
|
|
static void open_uri_cb (TextView *textview, guint action, void *data)
|
|
|
|
{
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri = g_object_get_data(G_OBJECT(textview->link_popup_menu),
|
2004-11-19 11:39:01 +01:00
|
|
|
"menu_button");
|
|
|
|
if (uri == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (textview_uri_security_check(textview, uri) == TRUE)
|
|
|
|
open_uri(uri->uri,
|
|
|
|
prefs_common.uri_cmd);
|
2005-02-09 14:15:30 +01:00
|
|
|
g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button",
|
2004-11-19 11:39:01 +01:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2005-08-22 12:36:39 +02:00
|
|
|
static void open_image_cb (TextView *textview, guint action, void *data)
|
|
|
|
{
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri = g_object_get_data(G_OBJECT(textview->file_popup_menu),
|
2005-08-22 12:36:39 +02:00
|
|
|
"menu_button");
|
|
|
|
|
2006-08-17 21:07:36 +02:00
|
|
|
gchar *cmd = NULL;
|
2005-08-22 12:36:39 +02:00
|
|
|
gchar buf[1024];
|
|
|
|
const gchar *p;
|
|
|
|
gchar *filename = NULL;
|
2005-08-22 13:16:08 +02:00
|
|
|
gchar *tmp_filename = NULL;
|
2005-08-22 12:36:39 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2005-08-22 13:16:08 +02:00
|
|
|
tmp_filename = g_filename_from_uri(uri->uri, NULL, NULL);
|
|
|
|
copy_file(tmp_filename, filename, FALSE);
|
|
|
|
g_free(tmp_filename);
|
|
|
|
|
2006-08-17 21:07:36 +02:00
|
|
|
cmd = mailcap_get_command_for_type("image/jpeg", filename);
|
|
|
|
if (cmd == NULL) {
|
|
|
|
gboolean remember = FALSE;
|
|
|
|
cmd = input_dialog_combo_remember
|
|
|
|
(_("Open with"),
|
|
|
|
_("Enter the command line to open file:\n"
|
|
|
|
"('%s' will be replaced with file name)"),
|
|
|
|
prefs_common.mime_open_cmd,
|
|
|
|
prefs_common.mime_open_cmd_history,
|
|
|
|
TRUE, &remember);
|
|
|
|
if (cmd && remember) {
|
|
|
|
mailcap_update_default("image/jpeg", cmd);
|
|
|
|
}
|
|
|
|
}
|
2005-08-22 12:36:39 +02:00
|
|
|
if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
|
|
|
|
!strchr(p + 2, '%'))
|
|
|
|
g_snprintf(buf, sizeof(buf), cmd, filename);
|
|
|
|
else {
|
2006-08-17 21:07:36 +02:00
|
|
|
g_warning("Image viewer command line is invalid: '%s'", cmd);
|
|
|
|
return;
|
2005-08-22 12:36:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
execute_command_line(buf, TRUE);
|
|
|
|
|
|
|
|
g_free(filename);
|
2006-08-17 21:07:36 +02:00
|
|
|
g_free(cmd);
|
2005-08-22 12:36:39 +02:00
|
|
|
|
|
|
|
g_object_set_data(G_OBJECT(textview->file_popup_menu), "menu_button",
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2005-04-01 10:16:46 +02:00
|
|
|
static void save_file_cb (TextView *textview, guint action, void *data)
|
|
|
|
{
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri = g_object_get_data(G_OBJECT(textview->file_popup_menu),
|
2005-04-01 10:16:46 +02:00
|
|
|
"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);
|
2006-01-14 10:45:39 +01:00
|
|
|
aval = alertpanel(_("Overwrite"), res, GTK_STOCK_CANCEL,
|
|
|
|
GTK_STOCK_OK, NULL);
|
2005-04-01 10:16:46 +02:00
|
|
|
g_free(res);
|
2006-01-14 10:45:39 +01:00
|
|
|
if (G_ALERTALTERNATE != aval)
|
2005-04-01 10:16:46 +02:00
|
|
|
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, ".")) {
|
2006-04-06 12:58:17 +02:00
|
|
|
g_free(prefs_common.attach_save_dir);
|
2006-12-17 14:36:22 +01:00
|
|
|
prefs_common.attach_save_dir = g_filename_to_utf8(filedir, -1, NULL, NULL, NULL);
|
2005-04-01 10:16:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free(filedir);
|
|
|
|
g_free(filepath);
|
|
|
|
|
|
|
|
g_object_set_data(G_OBJECT(textview->file_popup_menu), "menu_button",
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2004-11-19 11:39:01 +01:00
|
|
|
static void copy_uri_cb (TextView *textview, guint action, void *data)
|
|
|
|
{
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri = g_object_get_data(G_OBJECT(textview->link_popup_menu),
|
2004-11-19 11:39:01 +01:00
|
|
|
"menu_button");
|
|
|
|
if (uri == NULL)
|
|
|
|
return;
|
|
|
|
|
2005-07-06 20:22:55 +02:00
|
|
|
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);
|
2005-02-09 14:15:30 +01:00
|
|
|
g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button",
|
2004-11-19 11:39:01 +01:00
|
|
|
NULL);
|
|
|
|
}
|
2005-02-09 14:15:30 +01:00
|
|
|
|
|
|
|
static void add_uri_to_addrbook_cb (TextView *textview, guint action, void *data)
|
|
|
|
{
|
|
|
|
gchar *fromname, *fromaddress;
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
|
2005-02-09 14:15:30 +01:00
|
|
|
"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);
|
2007-02-01 08:27:50 +01:00
|
|
|
|
2005-02-09 14:15:30 +01:00
|
|
|
/* 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;
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
|
2005-02-09 14:15:30 +01:00
|
|
|
"menu_button");
|
|
|
|
if (uri == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2005-02-12 13:45:29 +01:00
|
|
|
static void copy_mail_to_uri_cb (TextView *textview, guint action, void *data)
|
|
|
|
{
|
2006-08-02 18:30:28 +02:00
|
|
|
ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
|
2005-02-12 13:45:29 +01:00
|
|
|
"menu_button");
|
|
|
|
if (uri == NULL)
|
|
|
|
return;
|
|
|
|
|
2005-07-06 20:22:55 +02:00
|
|
|
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);
|
2005-02-12 13:45:29 +01:00
|
|
|
g_object_set_data(G_OBJECT(textview->mail_popup_menu), "menu_button",
|
|
|
|
NULL);
|
|
|
|
}
|
2005-02-09 14:15:30 +01:00
|
|
|
|
2006-12-14 10:49:25 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|