2007-07-25 [iwkse] 2.10.0cvs60
[claws.git] / src / textview.c
index 70ba0364b70dc8208e96c64d1940ecf8e00dc47d..99d16f78e5437fa562e420c1fd0106680018e971 100644 (file)
@@ -4,7 +4,7 @@
  *
  * 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
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -68,6 +68,7 @@
 #include "base64.h"
 #include "inputdialog.h"
 #include "timing.h"
+#include "tags.h"
 
 static GdkColor quote_colors[3] = {
        {(gulong)0, (gushort)0, (gushort)0, (gushort)0},
@@ -358,8 +359,19 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
 {
        GtkTextBuffer *buffer;
        GtkTextTag *tag, *qtag;
+       static GdkColor yellow, black;
+       static gboolean color_init = FALSE;
        static PangoFontDescription *font_desc, *bold_font_desc;
        
+       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);
+       }
+
        if (!font_desc)
                font_desc = pango_font_description_from_string
                        (NORMAL_FONT);
@@ -421,6 +433,16 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
                                "foreground-gdk", &quote_colors[2],
                                NULL);
        }
+#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
        gtk_text_buffer_create_tag(buffer, "emphasis",
                        "foreground-gdk", &emphasis_color,
                        NULL);
@@ -822,6 +844,8 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        GtkTextView *text;
        GtkTextBuffer *buffer;
        GtkTextIter iter;
+       const gchar *name;
+       gchar *content_type;
 
        if (!partinfo) return;
 
@@ -833,23 +857,48 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        gtk_text_buffer_get_start_iter(buffer, &iter);
 
        TEXTVIEW_INSERT("\n");
-       TEXTVIEW_INSERT(_("  The following can be performed on this part by\n"));
-       TEXTVIEW_INSERT(_("  right-clicking the icon or list item:\n"));
+
+       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
+       TEXTVIEW_INSERT(_("  by right-clicking the icon or list item:\n"));
+#endif
 
        TEXTVIEW_INSERT(_("     - To save, select "));
        TEXTVIEW_INSERT_LINK(_("'Save as...'"), "sc://save_as", NULL);
+#ifndef MAEMO
        TEXTVIEW_INSERT(_(" (Shortcut key: 'y')\n"));
+#endif
        TEXTVIEW_INSERT(_("     - To display as text, select "));
        TEXTVIEW_INSERT_LINK(_("'Display as text'"), "sc://display_as_text", NULL);
+#ifndef MAEMO
        TEXTVIEW_INSERT(_(" (Shortcut key: 't')\n"));
+#endif
        TEXTVIEW_INSERT(_("     - To open with an external program, select "));
        TEXTVIEW_INSERT_LINK(_("'Open'"), "sc://open", NULL);
+#ifndef MAEMO
        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);
        TEXTVIEW_INSERT(_(" (Shortcut key: 'o')\n"));
+#endif
        textview_show_icon(textview, GTK_STOCK_DIALOG_INFO);
 }
 
@@ -1856,6 +1905,57 @@ bail:
 }
 #endif
 
+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);
+}
+
 static void textview_show_header(TextView *textview, GPtrArray *headers)
 {
        GtkTextView *text = GTK_TEXT_VIEW(textview->text);
@@ -1866,6 +1966,8 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
 
        g_return_if_fail(headers != NULL);
 
+       textview_show_tags(textview);
+
        for (i = 0; i < headers->len; i++) {
                header = g_ptr_array_index(headers, i);
                g_return_if_fail(header->name != NULL);
@@ -2012,6 +2114,7 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
        case GDK_y:
        case GDK_t:
        case GDK_l:
+       case GDK_o:
        case GDK_c:
        case GDK_a:
                if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) == 0) {