fix implicit declaration warning
[claws.git] / src / textview.c
index 2bd0d115403c8d8ebc819967ea995e5446f26840..ef50dd8f0350085b51d8c594bb5b432fecdeb6b7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 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
@@ -19,6 +19,7 @@
 
 #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 "inputdialog.h"
 #include "timing.h"
 #include "tags.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},
@@ -942,10 +940,16 @@ 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);
 
@@ -980,7 +984,11 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        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");
 
@@ -988,7 +996,11 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        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");
 
@@ -996,13 +1008,21 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        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");
@@ -1336,7 +1356,7 @@ static void textview_make_clickable_parts(TextView *textview,
        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;
 
@@ -1456,7 +1476,7 @@ static void textview_make_clickable_parts_later(TextView *textview,
        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;
 
@@ -1612,6 +1632,7 @@ do_quote:
                        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;
@@ -1644,11 +1665,12 @@ do_quote:
                                        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 {
@@ -1660,7 +1682,6 @@ do_quote:
 void textview_write_link(TextView *textview, const gchar *str,
                         const gchar *uri, CodeConverter *conv)
 {
-       GdkColor *link_color = NULL;
        GtkTextView *text;
        GtkTextBuffer *buffer;
        GtkTextIter iter;
@@ -1701,9 +1722,6 @@ void textview_write_link(TextView *textview, const gchar *str,
        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);
@@ -1946,26 +1964,31 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
        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);
        
@@ -1976,7 +1999,6 @@ static void textview_show_face(TextView *textview)
                GTK_TEXT_WINDOW_TEXT, x, 5);
 
        gtk_widget_show_all(textview->text);
-       
 
        return;
 bail:
@@ -2011,59 +2033,6 @@ void textview_show_icon(TextView *textview, const gchar *stock_id)
        return;
 }
 
-#if HAVE_LIBCOMPFACE
-static void textview_show_xface(TextView *textview)
-{
-       GtkAllocation allocation;
-       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);
-       
-       gtk_widget_get_allocation(textview->text, &allocation);
-       x = 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
@@ -2071,8 +2040,8 @@ static void textview_save_contact_pic(TextView *textview)
        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) 
@@ -2105,12 +2074,13 @@ static void textview_show_contact_pic(TextView *textview)
        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) 
@@ -2149,7 +2119,8 @@ static void textview_show_contact_pic(TextView *textview)
 
        gtk_widget_show(textview->image);
        
-       x = textview->text->allocation.width - WIDTH -5;
+       gtk_widget_get_allocation(textview->text, &allocation);
+       x = allocation.width - WIDTH -5;
 
        gtk_text_view_add_child_in_window(text, textview->image, 
                GTK_TEXT_WINDOW_TEXT, x, 5);
@@ -2316,10 +2287,8 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
                                                         "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);
 }
@@ -2425,19 +2394,6 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                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 &&
@@ -3059,6 +3015,8 @@ static void save_file_cb (GtkAction *action, TextView *textview)
        gchar *filepath = NULL;
        gchar *filedir = NULL;
        gchar *tmp_filename = NULL;
+       GtkWidget *window;
+
        if (uri == NULL)
                return;
 
@@ -3083,6 +3041,14 @@ static void save_file_cb (GtkAction *action, TextView *textview)
 
        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);
@@ -3144,7 +3110,7 @@ static void add_uri_to_addrbook_cb (GtkAction *action, TextView *textview)
        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;
 
@@ -3161,24 +3127,17 @@ static void add_uri_to_addrbook_cb (GtkAction *action, TextView *textview)
        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);
+       }
+
+       if (avatarr && avatarr->image) {
+               picture = gtk_image_get_pixbuf(GTK_IMAGE(avatarr->image));
+       }
+       if (avatarr) {
+               avatars_avatarrender_free(avatarr);
        }
-#endif
-       if (image)
-               picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
 
 #ifndef USE_NEW_ADDRBOOK
        addressbook_add_contact( fromname, fromaddress, NULL, picture);