2012-04-01 [colin] 3.8.0cvs36
[claws.git] / src / headerview.c
index 38148c2cec3e89f565d76f060200c702812b27ed..ac9f0e9d71af0feaa120ee10eb0960e4a4147c4b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2011 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
 
 #include <glib.h>
 #include <glib/gi18n.h>
-#include <gtk/gtkwidget.h>
-#include <gtk/gtkstyle.h>
-#include <gtk/gtkscrolledwindow.h>
-#include <gtk/gtkhbox.h>
-#include <gtk/gtkvbox.h>
-#include <gtk/gtklabel.h>
-#include <gtk/gtkimage.h>
+#include <gtk/gtk.h>
 #include <stdio.h>
 #include <string.h>
 #include <time.h>
@@ -118,11 +112,11 @@ HeaderView *headerview_create(void)
        gtk_label_set_selectable(GTK_LABEL(subject_body_label), TRUE);
        gtk_label_set_selectable(GTK_LABEL(tags_body_label), TRUE);
 
-       GTK_WIDGET_UNSET_FLAGS(from_body_label, GTK_CAN_FOCUS);
-       GTK_WIDGET_UNSET_FLAGS(to_body_label, GTK_CAN_FOCUS);
-       GTK_WIDGET_UNSET_FLAGS(ng_body_label, GTK_CAN_FOCUS);
-       GTK_WIDGET_UNSET_FLAGS(subject_body_label, GTK_CAN_FOCUS);
-       GTK_WIDGET_UNSET_FLAGS(tags_body_label, GTK_CAN_FOCUS);
+       gtkut_widget_set_can_focus(from_body_label, FALSE);
+       gtkut_widget_set_can_focus(to_body_label, FALSE);
+       gtkut_widget_set_can_focus(ng_body_label, FALSE);
+       gtkut_widget_set_can_focus(subject_body_label, FALSE);
+       gtkut_widget_set_can_focus(tags_body_label, FALSE);
 
        gtk_box_pack_start(GTK_BOX(hbox1), from_header_label, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(hbox1), from_body_label, FALSE, FALSE, 0);
@@ -167,12 +161,22 @@ void headerview_set_font(HeaderView *headerview)
        PangoFontDescription *boldfont = NULL;
        PangoFontDescription *normalfont = NULL;
        
-       if (!boldfont) {
-               normalfont = pango_font_description_from_string(NORMAL_FONT);
+       normalfont = pango_font_description_from_string(NORMAL_FONT);
+       if (normalfont) {
+               gtk_widget_modify_font(headerview->from_body_label, normalfont);
+               gtk_widget_modify_font(headerview->to_body_label, normalfont);
+               gtk_widget_modify_font(headerview->ng_body_label, normalfont);
+               gtk_widget_modify_font(headerview->subject_body_label, normalfont);
+               gtk_widget_modify_font(headerview->tags_body_label, normalfont);
+               pango_font_description_free(normalfont);
+       }
+
+       if (prefs_common.derive_from_normal_font || !BOLD_FONT) {
                boldfont = pango_font_description_from_string(NORMAL_FONT);
                pango_font_description_set_weight(boldfont, PANGO_WEIGHT_BOLD);
+       } else {
+               boldfont = pango_font_description_from_string(BOLD_FONT);
        }
-
        if (boldfont) {
                gtk_widget_modify_font(headerview->from_header_label, boldfont);
                gtk_widget_modify_font(headerview->to_header_label, boldfont);
@@ -180,13 +184,6 @@ void headerview_set_font(HeaderView *headerview)
                gtk_widget_modify_font(headerview->subject_header_label, boldfont);
                gtk_widget_modify_font(headerview->tags_header_label, boldfont);
                pango_font_description_free(boldfont);
-
-               gtk_widget_modify_font(headerview->from_body_label, normalfont);
-               gtk_widget_modify_font(headerview->to_body_label, normalfont);
-               gtk_widget_modify_font(headerview->ng_body_label, normalfont);
-               gtk_widget_modify_font(headerview->subject_body_label, normalfont);
-               gtk_widget_modify_font(headerview->tags_body_label, normalfont);
-               pango_font_description_free(normalfont);
        }
 }
 
@@ -261,13 +258,13 @@ static gint headerview_show_xface(HeaderView *headerview, MsgInfo *msginfo)
            !msginfo->extradata->xface || 
            strlen(msginfo->extradata->xface) < 5) {
                if (headerview->image &&
-                   GTK_WIDGET_VISIBLE(headerview->image)) {
+                   gtk_widget_get_visible(headerview->image)) {
                        gtk_widget_hide(headerview->image);
                        gtk_widget_queue_resize(hbox);
                }
                return -1;
        }
-       if (!GTK_WIDGET_VISIBLE(headerview->hbox)) return -1;
+       if (!gtk_widget_get_visible(headerview->hbox)) return -1;
 
        if (headerview->image) {
                gtk_widget_destroy(headerview->image);
@@ -298,13 +295,13 @@ static gint headerview_show_face (HeaderView *headerview, MsgInfo *msginfo)
 
        if (!msginfo->extradata || !msginfo->extradata->face) {
                if (headerview->image &&
-                   GTK_WIDGET_VISIBLE(headerview->image)) {
+                   gtk_widget_get_visible(headerview->image)) {
                        gtk_widget_hide(headerview->image);
                        gtk_widget_queue_resize(hbox);
                }
                return -1;
        }
-       if (!GTK_WIDGET_VISIBLE(headerview->hbox)) return -1;
+       if (!gtk_widget_get_visible(headerview->hbox)) return -1;
 
        if (headerview->image) {
                gtk_widget_destroy(headerview->image);
@@ -330,11 +327,12 @@ static gint headerview_show_face (HeaderView *headerview, MsgInfo *msginfo)
 
 static void headerview_save_contact_pic (HeaderView *headerview, MsgInfo *msginfo)
 {
+#ifndef USE_NEW_ADDRBOOK
        gchar *filename = NULL;
        GError *error = NULL;
        GdkPixbuf *picture = NULL;
 
-       if (!GTK_WIDGET_VISIBLE(headerview->hbox)) return;
+       if (!gtk_widget_get_visible(headerview->hbox)) return;
 
        if (headerview->image) {
                picture = gtk_image_get_pixbuf(GTK_IMAGE(headerview->image));
@@ -343,13 +341,23 @@ static void headerview_save_contact_pic (HeaderView *headerview, MsgInfo *msginf
        filename = addrindex_get_picture_file(msginfo->from);
        if (!filename)
                return;
-       if (!is_file_exist(filename))
+       if (!is_file_exist(filename)) {
                gdk_pixbuf_save(picture, filename, "png", &error, NULL);
+               if (error) {
+                       g_warning(_("Failed to save image: \n%s"),
+                                       error->message);
+                       g_error_free(error);
+               }
+       }
        g_free(filename);
+#else
+       /* new address book */
+#endif
 }      
 
 static gint headerview_show_contact_pic (HeaderView *headerview, MsgInfo *msginfo)
 {
+#ifndef USE_NEW_ADDRBOOK
        GtkWidget *hbox = headerview->hbox;
        GtkWidget *image;
        gchar *filename = NULL;
@@ -357,7 +365,7 @@ static gint headerview_show_contact_pic (HeaderView *headerview, MsgInfo *msginf
        GdkPixbuf *picture = NULL;
        gint w, h;
 
-       if (!GTK_WIDGET_VISIBLE(headerview->hbox)) return -1;
+       if (!gtk_widget_get_visible(headerview->hbox)) return -1;
 
        if (headerview->image) {
                gtk_widget_destroy(headerview->image);
@@ -381,11 +389,18 @@ static gint headerview_show_contact_pic (HeaderView *headerview, MsgInfo *msginf
                picture = gdk_pixbuf_new_from_file(filename, &error);
 
        g_free(filename);
+       if (error) {
+               debug_print("Failed to import image: \n%s",
+                               error->message);
+               g_error_free(error);
+               return -1;
+       }
        if (picture)
                image = gtk_image_new_from_pixbuf(picture);
        else 
                return -1;
 
+       g_object_unref(picture);
        if (image) {
                gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
                gtk_widget_show(image);
@@ -396,6 +411,10 @@ static gint headerview_show_contact_pic (HeaderView *headerview, MsgInfo *msginf
                return -1;
        else 
                return 0;
+#else
+       /* new address book */
+       return -1;
+#endif
 }
 
 void headerview_clear(HeaderView *headerview)
@@ -415,7 +434,7 @@ void headerview_clear(HeaderView *headerview)
        gtk_widget_hide(headerview->tags_header_label);
        gtk_widget_hide(headerview->tags_body_label);
 
-       if (headerview->image && GTK_WIDGET_VISIBLE(headerview->image)) {
+       if (headerview->image && gtk_widget_get_visible(headerview->image)) {
                gtk_widget_hide(headerview->image);
                gtk_widget_queue_resize(headerview->hbox);
        }