Made GPG signatures verifiable by clicking the
[claws.git] / src / textview.c
index 4de3d134742dfc835f83a4e872b94866aa74e606..4a7fa8568de83fad69008f56109a2532b9cda09f 100644 (file)
@@ -50,6 +50,7 @@
 #include "addressbook.h"
 #include "displayheader.h"
 #include "account.h"
+#include "mimeview.h"
 
 #define FONT_LOAD(font, s) \
 { \
@@ -78,6 +79,13 @@ static GdkColor quote_colors[3] = {
        {(gulong)0, (gushort)0, (gushort)0, (gushort)0}
 };
 
+static GdkColor signature_color = {
+       (gulong)0,
+       (gushort)0x7fff,
+       (gushort)0x7fff,
+       (gushort)0x7fff
+};
+       
 static GdkColor uri_color = {
        (gulong)0,
        (gushort)0,
@@ -288,9 +296,11 @@ void textview_update_message_colors(void)
                                               &quote_colors[2]);
                gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
                                               &uri_color);
+               gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
+                                              &signature_color);
        } else {
                quote_colors[0] = quote_colors[1] = quote_colors[2] = 
-                       uri_color = emphasis_color = black;
+                       uri_color = emphasis_color = signature_color = black;
        }
 }
 
@@ -493,6 +503,22 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
                g_snprintf(buf, sizeof(buf), "\n[%s (%d bytes)]\n",
                           mimeinfo->content_type, mimeinfo->size);
 
+#if USE_GPGME
+       if (mimeinfo->sigstatus && !mimeinfo->sigstatus_full) {
+               gchar *tmp;
+               /* use standard font */
+               gpointer oldfont = textview->msgfont;
+               textview->msgfont = NULL;
+
+               tmp = g_strconcat("pgp: ", _("Check signature"), NULL);
+               textview_write_link(textview, tmp, buf, NULL);
+               
+               /* put things back */
+               textview->msgfont = (GdkFont *)oldfont;
+               oldfont = NULL;
+               g_free(tmp);
+       } else
+#endif
        if (mimeinfo->mime_type != MIME_TEXT &&
            mimeinfo->mime_type != MIME_TEXT_HTML &&
            mimeinfo->mime_type != MIME_TEXT_ENRICHED) {
@@ -606,7 +632,11 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo,
        conv = conv_code_converter_new(charset);
 
        tmpfp = procmime_decode_content(NULL, fp, mimeinfo);
+       
+       textview->is_in_signature = FALSE;
+
        if (tmpfp) {
+               
                if (mimeinfo->mime_type == MIME_TEXT_HTML)
                        textview_show_html(textview, tmpfp, conv);
                else if (mimeinfo->mime_type == MIME_TEXT_ENRICHED)
@@ -1079,6 +1109,11 @@ static void textview_write_line(TextView *textview, const gchar *str,
        else
                fg_color = &quote_colors[quotelevel];
 
+       if (prefs_common.enable_color && (strcmp(buf,"-- \n") == 0 || textview->is_in_signature)) {
+               fg_color = &signature_color;
+               textview->is_in_signature = TRUE;
+       }
+       
        if (prefs_common.head_space && spacingfont && buf[0] != '\n')
                gtk_stext_insert(text, spacingfont, NULL, NULL, " ", 1);
 
@@ -1661,6 +1696,10 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                textview_scroll_one_line(textview,
                                         (event->state & GDK_MOD1_MASK) != 0);
                break;
+       case GDK_Delete:
+               if (summaryview)
+                       summary_pass_key_press_event(summaryview, event);
+               break;
        case GDK_n:
        case GDK_N:
        case GDK_p:
@@ -1783,7 +1822,18 @@ static gint textview_button_released(GtkWidget *widget, GdkEventButton *event,
                                                }
                                                compose_new(account, uri->uri + 7, NULL);
                                        }
-                               } else {
+                               } else 
+#if USE_GPGME
+                               if (!g_strncasecmp(uri->uri, "pgp:", 4)) {
+                                       GtkAdjustment *pos = gtk_scrolled_window_get_vadjustment(
+                                                               GTK_SCROLLED_WINDOW(textview->scrolledwin));
+                                       gfloat vpos = pos->value;
+                                       mimeview_check_signature(textview->messageview->mimeview);
+                                       /* scroll back where we were */
+                                       gtk_adjustment_set_value(pos, vpos);
+                               } else
+#endif
+                               {
                                        open_uri(uri->uri,
                                                 prefs_common.uri_cmd);
                                }