/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2011 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2014 Hiroyuki Yamamoto and the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifdef HAVE_CONFIG_H
# include "config.h"
+#include "claws-features.h"
#endif
#include "defs.h"
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
-#if HAVE_LIBCOMPFACE
-# include <compface.h>
-#endif
-
-#if HAVE_LIBCOMPFACE
-#define XPM_XFACE_HEIGHT (HEIGHT + 3) /* 3 = 1 header + 2 colors */
-#endif
#include "main.h"
#include "summaryview.h"
#include "html.h"
#include "enriched.h"
#include "compose.h"
-#include "addressbook.h"
+#ifndef USE_NEW_ADDRBOOK
+ #include "addressbook.h"
+ #include "addrindex.h"
+#else
+ #include "addressbook-dbus.h"
+ #include "addressadd.h"
+#endif
#include "displayheader.h"
#include "account.h"
#include "mimeview.h"
#include "inputdialog.h"
#include "timing.h"
#include "tags.h"
-#include "addrindex.h"
+#include "manage_window.h"
+#include "folder_item_prefs.h"
+#include "hooks.h"
+#include "avatars.h"
static GdkColor quote_colors[3] = {
{(gulong)0, (gushort)0, (gushort)0, (gushort)0},
(gushort)0
};
+static GdkColor diff_added_color = {
+ (gulong)0,
+ (gushort)0,
+ (gushort)0,
+ (gushort)0
+};
+
+static GdkColor diff_deleted_color = {
+ (gulong)0,
+ (gushort)0,
+ (gushort)0,
+ (gushort)0
+};
+
+static GdkColor diff_hunk_color = {
+ (gulong)0,
+ (gushort)0,
+ (gushort)0,
+ (gushort)0
+};
+
static GdkCursor *hand_cursor = NULL;
static GdkCursor *text_cursor = NULL;
static GdkCursor *watch_cursor= NULL;
gtk_text_buffer_create_tag(buffer, "link-hover",
"underline", PANGO_UNDERLINE_SINGLE,
NULL);
+ gtk_text_buffer_create_tag(buffer, "diff-add",
+ "foreground-gdk", &diff_added_color,
+ NULL);
+ gtk_text_buffer_create_tag(buffer, "diff-del",
+ "foreground-gdk", &diff_deleted_color,
+ NULL);
+ gtk_text_buffer_create_tag(buffer, "diff-add-file",
+ "foreground-gdk", &diff_added_color,
+ "weight", PANGO_WEIGHT_BOLD,
+ NULL);
+ gtk_text_buffer_create_tag(buffer, "diff-del-file",
+ "foreground-gdk", &diff_deleted_color,
+ "weight", PANGO_WEIGHT_BOLD,
+ NULL);
+ gtk_text_buffer_create_tag(buffer, "diff-hunk",
+ "foreground-gdk", &diff_hunk_color,
+ "weight", PANGO_WEIGHT_BOLD,
+ NULL);
g_signal_connect(G_OBJECT(qtag), "event",
G_CALLBACK(textview_uri_button_pressed), textview);
g_signal_connect(G_OBJECT(tag), "event",
GtkTextTag *tag = NULL;
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;
+ quote_colors[0] = quote_colors[1] = quote_colors[2] = black;
+ uri_color = emphasis_color = signature_color = diff_added_color =
+ diff_deleted_color = diff_hunk_color = black;
if (prefs_common.enable_color) {
/* grab the quote colors, converting from an int to a GdkColor */
&signature_color);
gtkut_convert_int_to_gdk_color(prefs_common.emphasis_col,
&emphasis_color);
+ gtkut_convert_int_to_gdk_color(prefs_common.diff_added_color,
+ &diff_added_color);
+ gtkut_convert_int_to_gdk_color(prefs_common.diff_deleted_color,
+ &diff_deleted_color);
+ gtkut_convert_int_to_gdk_color(prefs_common.diff_hunk_color,
+ &diff_hunk_color);
}
if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
CHANGE_TAG_COLOR("signature", &signature_color, NULL);
CHANGE_TAG_COLOR("link", &uri_color, NULL);
CHANGE_TAG_COLOR("link-hover", &uri_color, NULL);
+ CHANGE_TAG_COLOR("diff-add", &diff_added_color, NULL);
+ CHANGE_TAG_COLOR("diff-del", &diff_deleted_color, NULL);
+ CHANGE_TAG_COLOR("diff-add-file", &diff_added_color, NULL);
+ CHANGE_TAG_COLOR("diff-del-file", &diff_deleted_color, NULL);
+ CHANGE_TAG_COLOR("diff-hunk", &diff_hunk_color, NULL);
}
#undef CHANGE_TAG_COLOR
TEXTVIEW_INSERT(info_str);
textview_show_icon(textview, GTK_STOCK_DIALOG_INFO);
+ textview_cursor_normal(textview);
}
void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
GtkTextBuffer *buffer;
GtkTextIter iter;
const gchar *name;
- gchar *content_type;
+ gchar *content_type, *shortcut;
+ GtkUIManager *ui_manager;
if (!partinfo) return;
+ if (textview->messageview->window != NULL)
+ ui_manager = textview->messageview->ui_manager;
+ else
+ ui_manager = textview->messageview->mainwin->ui_manager;
+
textview_set_font(textview, NULL);
textview_clear(textview);
TEXTVIEW_INSERT(_(" - To save, select "));
TEXTVIEW_INSERT_LINK(_("'Save as...'"), "sc://save_as", NULL);
#ifndef GENERIC_UMPC
- TEXTVIEW_INSERT(_(" (Shortcut key: 'y')"));
+ TEXTVIEW_INSERT(_(" (Shortcut key: '"));
+ shortcut = cm_menu_item_get_shortcut(ui_manager, "Menu/File/SavePartAs");
+ TEXTVIEW_INSERT(shortcut);
+ g_free(shortcut);
+ TEXTVIEW_INSERT("')");
#endif
TEXTVIEW_INSERT("\n");
TEXTVIEW_INSERT_LINK(_("'Display as text'"), "sc://display_as_text", NULL);
#ifndef GENERIC_UMPC
- TEXTVIEW_INSERT(_(" (Shortcut key: 't')"));
+ TEXTVIEW_INSERT(_(" (Shortcut key: '"));
+ shortcut = cm_menu_item_get_shortcut(ui_manager, "Menu/View/Part/AsText");
+ TEXTVIEW_INSERT(shortcut);
+ g_free(shortcut);
+ TEXTVIEW_INSERT("')");
#endif
TEXTVIEW_INSERT("\n");
TEXTVIEW_INSERT_LINK(_("'Open'"), "sc://open", NULL);
#ifndef GENERIC_UMPC
- TEXTVIEW_INSERT(_(" (Shortcut key: 'l')\n"));
+ TEXTVIEW_INSERT(_(" (Shortcut key: '"));
+ shortcut = cm_menu_item_get_shortcut(ui_manager, "Menu/View/Part/Open");
+ TEXTVIEW_INSERT(shortcut);
+ g_free(shortcut);
+ TEXTVIEW_INSERT("')\n");
TEXTVIEW_INSERT(_(" (alternately double-click, or click the middle "));
TEXTVIEW_INSERT(_("mouse button)\n"));
#ifndef G_OS_WIN32
TEXTVIEW_INSERT(_(" - Or use "));
TEXTVIEW_INSERT_LINK(_("'Open with...'"), "sc://open_with", NULL);
- TEXTVIEW_INSERT(_(" (Shortcut key: 'o')"));
+ TEXTVIEW_INSERT(_(" (Shortcut key: '"));
+ shortcut = cm_menu_item_get_shortcut(ui_manager, "Menu/View/Part/OpenWith");
+ TEXTVIEW_INSERT(shortcut);
+ g_free(shortcut);
+ TEXTVIEW_INSERT("')");
#endif
#endif
TEXTVIEW_INSERT("\n");
procmime_force_encoding(textview->messageview->forced_encoding);
textview->is_in_signature = FALSE;
+ textview->is_diff = FALSE;
procmime_decode_content(mimeinfo);
#endif
} else {
textview_default:
+ if (!g_ascii_strcasecmp(mimeinfo->subtype, "x-patch")
+ || !g_ascii_strcasecmp(mimeinfo->subtype, "x-diff"))
+ textview->is_diff = TRUE;
+
if (mimeinfo->content == MIMECONTENT_MEM)
tmpfp = str_open_as_stream(mimeinfo->data.mem);
else
gtk_text_buffer_get_end_iter(buffer, &iter);
/* parse for clickable parts, and build a list of begin and end positions */
- for (walk = mybuf, n = 0;;) {
+ for (walk = mybuf;;) {
gint last_index = PARSE_ELEMS;
gchar *scanpos = NULL;
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;;) {
+ for (walk = mybuf;;) {
gint last_index = PARSE_ELEMS;
gchar *scanpos = NULL;
fg_color = quote_tag_str;
}
- if (prefs_common.enable_color &&
- (strcmp(buf,"-- \n") == 0 || strcmp(buf, "- -- \n") == 0 || textview->is_in_signature)) {
- fg_color = "signature";
- textview->is_in_signature = TRUE;
+ if (prefs_common.enable_color) {
+ if (textview->is_diff) {
+ if (strncmp(buf, "+++ ", 4) == 0)
+ fg_color = "diff-add-file";
+ else if (buf[0] == '+')
+ fg_color = "diff-add";
+ else if (strncmp(buf, "--- ", 4) == 0)
+ fg_color = "diff-del-file";
+ else if (buf[0] == '-')
+ fg_color = "diff-del";
+ else if (strncmp(buf, "@@ ", 3) == 0 &&
+ strcmp(buf+strlen(buf)-4, " @@\n") == 0)
+ fg_color = "diff-hunk";
+ } else if (strcmp(buf,"-- \n") == 0
+ || strcmp(buf, "- -- \n") == 0
+ || textview->is_in_signature) {
+ fg_color = "signature";
+ textview->is_in_signature = TRUE;
+ }
}
if (real_quotelevel > -1 && do_quote_folding) {
uri = g_new0(ClickableText, 1);
uri->uri = g_strdup("");
uri->data = g_strdup(buf);
+ uri->data_len = strlen(uri->data);
uri->start = gtk_text_iter_get_offset(&iter);
uri->is_quote = TRUE;
uri->quote_level = real_quotelevel;
textview->prev_quote_level = -1;
goto do_quote;
}
- e_len = lasturi->data ? strlen(lasturi->data):0;
+ e_len = lasturi->data ? lasturi->data_len:0;
n_len = strlen(buf);
lasturi->data = g_realloc((gchar *)lasturi->data, e_len + n_len + 1);
strcpy((gchar *)lasturi->data + e_len, buf);
*((gchar *)lasturi->data + e_len + n_len) = '\0';
+ lasturi->data_len += n_len;
}
}
} else {
void textview_write_link(TextView *textview, const gchar *str,
const gchar *uri, CodeConverter *conv)
{
- GdkColor *link_color = NULL;
GtkTextView *text;
GtkTextBuffer *buffer;
GtkTextIter iter;
if (bufp > buf)
gtk_text_buffer_insert(buffer, &iter, buf, bufp - buf);
- if (prefs_common.enable_color) {
- link_color = &uri_color;
- }
r_uri = g_new0(ClickableText, 1);
r_uri->uri = g_strdup(uri);
r_uri->start = gtk_text_iter_get_offset(&iter);
return sorted_headers;
}
-static void textview_show_face(TextView *textview)
+static void textview_show_avatar(TextView *textview)
{
GtkAllocation allocation;
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
MsgInfo *msginfo = textview->messageview->msginfo;
int x = 0;
+ AvatarRender *avatarr;
- if (prefs_common.display_header_pane
- || !prefs_common.display_xface)
+ if (prefs_common.display_header_pane || !prefs_common.display_xface)
goto bail;
- if (!msginfo->extradata || !msginfo->extradata->face) {
+ avatarr = avatars_avatarrender_new(msginfo);
+ hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
+
+ if (!avatarr->image) {
+ avatars_avatarrender_free(avatarr);
goto bail;
}
if (textview->image)
gtk_widget_destroy(textview->image);
- textview->image = face_get_from_header(msginfo->extradata->face);
- cm_return_if_fail(textview->image != NULL);
+ textview->image = avatarr->image;
+ avatarr->image = NULL; /* avoid destroying */
+ avatars_avatarrender_free(avatarr);
gtk_widget_show(textview->image);
GTK_TEXT_WINDOW_TEXT, x, 5);
gtk_widget_show_all(textview->text);
-
return;
bail:
return;
}
-#if HAVE_LIBCOMPFACE
-static void textview_show_xface(TextView *textview)
-{
- MsgInfo *msginfo = textview->messageview->msginfo;
- GtkTextView *text = GTK_TEXT_VIEW(textview->text);
- int x = 0;
- GdkWindow *window = NULL;
-
- if (prefs_common.display_header_pane
- || !prefs_common.display_xface)
- goto bail;
-
- if (!msginfo || !msginfo->extradata)
- goto bail;
-
- if (msginfo->extradata->face)
- return;
-
- if (!msginfo->extradata->xface || strlen(msginfo->extradata->xface) < 5) {
- goto bail;
- }
-
- if (textview->image)
- gtk_widget_destroy(textview->image);
-
- window = mainwindow_get_mainwindow() ?
- mainwindow_get_mainwindow()->window->window :
- textview->text->window;
- textview->image = xface_get_from_header(msginfo->extradata->xface,
- &textview->text->style->white,
- window);
- cm_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;
-bail:
- if (textview->image)
- gtk_widget_destroy(textview->image);
- textview->image = NULL;
-
-}
-#endif
-
static void textview_save_contact_pic(TextView *textview)
{
+#ifndef USE_NEW_ADDRBOOK
MsgInfo *msginfo = textview->messageview->msginfo;
gchar *filename = NULL;
GError *error = NULL;
GdkPixbuf *picture = NULL;
-
- if (!msginfo->extradata || (!msginfo->extradata->face && !msginfo->extradata->xface))
+
+ if (!msginfo->extradata || !msginfo->extradata->avatars)
return;
if (textview->image)
}
}
g_free(filename);
+#else
+ /* new address book */
+#endif
}
static void textview_show_contact_pic(TextView *textview)
{
- GtkAllocation allocation;
+#ifndef USE_NEW_ADDRBOOK
MsgInfo *msginfo = textview->messageview->msginfo;
GtkTextView *text = GTK_TEXT_VIEW(textview->text);
int x = 0;
GError *error = NULL;
GdkPixbuf *picture = NULL;
gint w, h;
-
+ GtkAllocation allocation;
+
if (prefs_common.display_header_pane
- || !prefs_common.display_xface)
+ || !prefs_common.display_xface)
goto bail;
- if (msginfo->extradata && (msginfo->extradata->face || msginfo->extradata->xface))
+ if (msginfo->extradata && msginfo->extradata->avatars)
return;
if (textview->image)
if (textview->image)
gtk_widget_destroy(textview->image);
textview->image = NULL;
-
+#else
+ /* new address book */
+#endif
}
static gint textview_tag_cmp_list(gconstpointer a, gconstpointer b)
"header", NULL);
}
- textview_show_face(textview);
-#if HAVE_LIBCOMPFACE
- textview_show_xface(textview);
-#endif
+ textview_show_avatar(textview);
+
textview_save_contact_pic(textview);
textview_show_contact_pic(textview);
}
if (summaryview)
summary_pass_key_press_event(summaryview, event);
break;
- case GDK_KEY_y:
- case GDK_KEY_t:
- case GDK_KEY_l:
- case GDK_KEY_o:
- case GDK_KEY_c:
- case GDK_KEY_a:
- if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) == 0) {
- KEY_PRESS_EVENT_STOP();
- mimeview_pass_key_press_event(messageview->mimeview,
- event);
- break;
- }
- /* possible fall through */
default:
window = gtk_widget_get_window(messageview->mainwin->window);
if (summaryview &&
gchar *filepath = NULL;
gchar *filedir = NULL;
gchar *tmp_filename = NULL;
+ GtkWidget *window;
+
if (uri == NULL)
return;
g_free(filename);
+ /* Pick correct window to set the file dialog "transient for" */
+ if (textview->messageview->window != NULL)
+ window = textview->messageview->window;
+ else
+ window = textview->messageview->mainwin->window;
+
+ manage_window_focus_in(window, NULL, NULL);
+
filename = filesel_select_file_save(_("Save as"), filepath);
if (!filename) {
g_free(filepath);
gchar *fromname, *fromaddress;
ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
"menu_button");
- GtkWidget *image = NULL;
+ AvatarRender *avatarr = NULL;
GdkPixbuf *picture = NULL;
gboolean use_picture = FALSE;
+
if (uri == NULL)
return;
fromname = procheader_get_fromname(fromaddress);
extract_address(fromaddress);
- if (use_picture &&
- textview->messageview->msginfo &&
- textview->messageview->msginfo->extradata &&
- textview->messageview->msginfo->extradata->face) {
- image = face_get_from_header(textview->messageview->msginfo->extradata->face);
- }
-#if HAVE_LIBCOMPFACE
- else if (use_picture &&
- textview->messageview->msginfo &&
- textview->messageview->msginfo->extradata &&
- textview->messageview->msginfo->extradata->xface) {
- image = xface_get_from_header(textview->messageview->msginfo->extradata->xface,
- &textview->text->style->white,
- mainwindow_get_mainwindow()->window->window);
+ if (use_picture) {
+ avatarr = avatars_avatarrender_new(textview->messageview->msginfo);
+ hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
}
-#endif
- if (image)
- picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
+ if (avatarr && avatarr->image) {
+ picture = gtk_image_get_pixbuf(GTK_IMAGE(avatarr->image));
+ }
+ if (avatarr) {
+ avatars_avatarrender_free(avatarr);
+ }
+
+#ifndef USE_NEW_ADDRBOOK
addressbook_add_contact( fromname, fromaddress, NULL, picture);
+#else
+ if (addressadd_selection(fromname, fromaddress, NULL, picture)) {
+ debug_print( "addressbook_add_contact - added\n" );
+ }
+#endif
g_free(fromaddress);
g_free(fromname);