2007-10-09 [colin] 3.0.2cvs44
authorColin Leroy <colin@colino.net>
Tue, 9 Oct 2007 16:37:50 +0000 (16:37 +0000)
committerColin Leroy <colin@colino.net>
Tue, 9 Oct 2007 16:37:50 +0000 (16:37 +0000)
* src/addrduplicates.c
* src/addressadd.c
* src/addressadd.h
* src/addressbook.c
* src/addressbook.h
* src/addrindex.c
* src/addrindex.h
* src/addritem.c
* src/addritem.h
* src/compose.c
* src/editaddress.c
* src/editaddress_other_attributes_ldap.h
* src/headerview.c
* src/messageview.c
* src/mimeview.c
* src/summaryview.c
* src/textview.c
* src/gtk/gtkutils.c
Automatically set contacts' pictures from Face
or X-Face if they have no picture
Display the contact picture in textview or
headerview for mails sent by people in the
addressbook, that have no Face or X-Face
Fix a few details in the Person edition dialog
(ability to unset picture)
Remove picture file when deleting contacts

21 files changed:
ChangeLog
PATCHSETS
configure.ac
src/addrduplicates.c
src/addressadd.c
src/addressadd.h
src/addressbook.c
src/addressbook.h
src/addrindex.c
src/addrindex.h
src/addritem.c
src/addritem.h
src/compose.c
src/editaddress.c
src/editaddress_other_attributes_ldap.h
src/gtk/gtkutils.c
src/headerview.c
src/messageview.c
src/mimeview.c
src/summaryview.c
src/textview.c

index 65eab4d..b9ef36a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2007-10-09 [colin]     3.0.2cvs44
+
+       * src/addrduplicates.c
+       * src/addressadd.c
+       * src/addressadd.h
+       * src/addressbook.c
+       * src/addressbook.h
+       * src/addrindex.c
+       * src/addrindex.h
+       * src/addritem.c
+       * src/addritem.h
+       * src/compose.c
+       * src/editaddress.c
+       * src/editaddress_other_attributes_ldap.h
+       * src/headerview.c
+       * src/messageview.c
+       * src/mimeview.c
+       * src/summaryview.c
+       * src/textview.c
+       * src/gtk/gtkutils.c
+               Automatically set contacts' pictures from Face 
+               or X-Face if they have no picture
+               Display the contact picture in textview or
+               headerview for mails sent by people in the 
+               addressbook, that have no Face or X-Face
+               Fix a few details in the Person edition dialog
+               (ability to unset picture)
+               Remove picture file when deleting contacts
+
 2007-10-09 [iwkse]     3.0.2cvs43
 
        * src/gtk/about.c
index f220806..901c023 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.94.2.154 -r 1.94.2.155 src/messageview.c;  ) > 3.0.2cvs41.patchset
 ( cvs diff -u -r 1.30.2.44 -r 1.30.2.45 src/prefs_toolbar.c;  ) > 3.0.2cvs42.patchset
 ( cvs diff -u -r 1.4.2.52 -r 1.4.2.53 src/gtk/about.c;  ) > 3.0.2cvs43.patchset
+( cvs diff -u -r 1.1.2.2 -r 1.1.2.3 src/addrduplicates.c;  cvs diff -u -r 1.9.2.16 -r 1.9.2.17 src/addressadd.c;  cvs diff -u -r 1.2.16.5 -r 1.2.16.6 src/addressadd.h;  cvs diff -u -r 1.60.2.101 -r 1.60.2.102 src/addressbook.c;  cvs diff -u -r 1.18.2.10 -r 1.18.2.11 src/addressbook.h;  cvs diff -u -r 1.28.2.33 -r 1.28.2.34 src/addrindex.c;  cvs diff -u -r 1.9.2.13 -r 1.9.2.14 src/addrindex.h;  cvs diff -u -r 1.13.2.14 -r 1.13.2.15 src/addritem.c;  cvs diff -u -r 1.12.2.12 -r 1.12.2.13 src/addritem.h;  cvs diff -u -r 1.382.2.414 -r 1.382.2.415 src/compose.c;  cvs diff -u -r 1.14.2.30 -r 1.14.2.31 src/editaddress.c;  cvs diff -u -r 1.1.2.4 -r 1.1.2.5 src/editaddress_other_attributes_ldap.h;  cvs diff -u -r 1.8.2.22 -r 1.8.2.23 src/headerview.c;  cvs diff -u -r 1.94.2.155 -r 1.94.2.156 src/messageview.c;  cvs diff -u -r 1.83.2.118 -r 1.83.2.119 src/mimeview.c;  cvs diff -u -r 1.395.2.327 -r 1.395.2.328 src/summaryview.c;  cvs diff -u -r 1.96.2.182 -r 1.96.2.183 src/textview.c;  cvs diff -u -r 1.5.2.66 -r 1.5.2.67 src/gtk/gtkutils.c;  ) > 3.0.2cvs44.patchset
index 37fa6b2..fddc679 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=0
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=43
+EXTRA_VERSION=44
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index ec22a70..34a2411 100644 (file)
@@ -594,8 +594,13 @@ static gboolean delete_item(ItemPerson *item, AddressDataSource *ds)
 
 #endif
 
-       if(item)
+       if(item) {
+               gchar *filename = addritem_person_get_picture(item);
+               if (filename && is_file_exist(filename))
+                       g_unlink(filename);
+               g_free(filename);
                addritem_free_item_person(item);
+       }
 
        return TRUE;
 }
index befd122..4f0df55 100644 (file)
@@ -57,6 +57,7 @@ typedef struct {
 
 static struct _AddressAdd_dlg {
        GtkWidget *window;
+       GtkWidget *picture;
        GtkWidget *entry_name;
        GtkWidget *label_address;
        GtkWidget *entry_remarks;
@@ -155,9 +156,10 @@ static void addressadd_size_allocate_cb(GtkWidget *widget,
 
 static void addressadd_create( void ) {
        GtkWidget *window;
-       GtkWidget *vbox;
+       GtkWidget *vbox, *hbox;
        GtkWidget *table;
        GtkWidget *label;
+       GtkWidget *picture;
        GtkWidget *entry_name;
        GtkWidget *label_addr;
        GtkWidget *entry_rems;
@@ -184,12 +186,17 @@ static void addressadd_create( void ) {
        g_signal_connect(G_OBJECT(window), "size_allocate",
                         G_CALLBACK(addressadd_size_allocate_cb), NULL);
 
+       hbox = gtk_hbox_new(FALSE, 6);
        vbox = gtk_vbox_new(FALSE, 8);
        gtk_container_add(GTK_CONTAINER(window), vbox);
        gtk_container_set_border_width( GTK_CONTAINER(vbox), 8 );
 
+       picture = gtk_image_new();
+       gtk_box_pack_start(GTK_BOX(hbox), picture, FALSE, FALSE, 0);
+
        table = gtk_table_new(3, 2, FALSE);
-       gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), table, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
        gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
        gtk_table_set_row_spacings(GTK_TABLE(table), 8);
        gtk_table_set_col_spacings(GTK_TABLE(table), 8);
@@ -283,6 +290,7 @@ static void addressadd_create( void ) {
        gtk_widget_show_all(vbox);
 
        addressadd_dlg.window        = window;
+       addressadd_dlg.picture       = picture;
        addressadd_dlg.entry_name    = entry_name;
        addressadd_dlg.label_address = label_addr;
        addressadd_dlg.entry_remarks = entry_rems;
@@ -377,7 +385,8 @@ static void addressadd_load_data( AddressIndex *addrIndex ) {
        }
 }
 
-gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, const gchar *address, const gchar *remarks ) {
+gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, 
+               const gchar *address, const gchar *remarks, GdkPixbuf *picture ) {
        gboolean retVal = FALSE;
        ItemPerson *person = NULL;
        FolderInfo *fi = NULL;
@@ -403,7 +412,12 @@ gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, const
                gtk_label_set_text( GTK_LABEL(addressadd_dlg.label_address ), address );
        if( remarks )
                gtk_entry_set_text( GTK_ENTRY(addressadd_dlg.entry_remarks ), remarks );
-
+       if( picture ) {
+               gtk_image_set_from_pixbuf(GTK_IMAGE(addressadd_dlg.picture), picture);
+               gtk_widget_show(GTK_WIDGET(addressadd_dlg.picture));
+       } else {
+               gtk_widget_hide(GTK_WIDGET(addressadd_dlg.picture));
+       }
        gtk_main();
        gtk_widget_hide( addressadd_dlg.window );
 
@@ -421,6 +435,15 @@ gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, const
                                                        address, 
                                                        returned_remarks);
                        person->status = ADD_ENTRY;
+
+                       if (picture) {
+                               GError *error = NULL;
+                               gchar *name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
+                                                       ADDRITEM_ID(person), NULL );
+                               gdk_pixbuf_save(picture, name, "png", &error, NULL);
+                               addritem_person_set_picture( person, ADDRITEM_ID(person) ) ;
+                               g_free( name );
+                       }
 #ifdef USE_LDAP
                        if (fi->book->type == ADBOOKTYPE_LDAP) {
                                LdapServer *server = (LdapServer *) fi->book;
index 52d11c2..09ef6d2 100644 (file)
@@ -25,7 +25,9 @@
 #define __ADDRESS_ADD_H__
 
 #include "addrindex.h"
+#include "gtk/gtk.h"
 
-gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, const gchar *address, const gchar *remarks );
+gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, const gchar *address, const gchar *remarks,
+                              GdkPixbuf *picture );
 
 #endif /* __ADDRESS_ADD_H__ */
index bc91430..d82f76b 100644 (file)
@@ -1480,6 +1480,10 @@ static void addressbook_del_clicked(GtkButton *button, gpointer data)
                                }
 #endif
                                if( item ) {
+                                       gchar *filename = addritem_person_get_picture(item);
+                                       if (filename && is_file_exist(filename))
+                                               g_unlink(filename);
+                                       g_free(filename);
                                        addritem_free_item_person( item );
                                }
                        }
@@ -4943,10 +4947,11 @@ static void addrbookctl_build_ifselect( void ) {
  * This function is used by the Add sender to address book function.
  */
 gboolean addressbook_add_contact(
-               const gchar *name, const gchar *address, const gchar *remarks )
+               const gchar *name, const gchar *address, const gchar *remarks,
+               GdkPixbuf *picture )
 {
        debug_print( "addressbook_add_contact: name/address: %s - %s\n", name, address );
-       if( addressadd_selection( _addressIndex_, name, address, remarks ) ) {
+       if( addressadd_selection( _addressIndex_, name, address, remarks, picture ) ) {
                debug_print( "addressbook_add_contact - added\n" );
                addressbook_refresh();
        }
index f412185..94fa204 100644 (file)
@@ -38,7 +38,8 @@ void addressbook_destroy              ( void );
 
 gboolean addressbook_add_contact       ( const gchar *name,
                                          const gchar *address,
-                                         const gchar *remarks );
+                                         const gchar *remarks,
+                                         GdkPixbuf *picture );
                                          
 gboolean addressbook_folder_selection( gchar **folderpath );
 gboolean addressbook_peek_folder_exists( gchar *folderpath,
index 4ad70c5..41ca856 100644 (file)
@@ -3170,6 +3170,69 @@ gboolean addrindex_load_person_ds( gint (*callBackFunc)
        return TRUE;
 }
 
+gchar *addrindex_get_picture_file(const gchar *emailaddr)
+{
+       AddressDataSource *ds;
+       GList *nodeIf, *nodeDS;
+       GList *listP, *nodeP;
+       gboolean found = FALSE;
+       gchar *filename = NULL;
+       gchar *raw_addr = NULL;
+       
+       Xstrdup_a(raw_addr, emailaddr, return NULL);
+       extract_address(raw_addr);
+
+       nodeIf = addrindex_get_interface_list( _addressIndex_ );
+       while( nodeIf ) {
+               AddressInterface *iface = nodeIf->data;
+
+               nodeIf = g_list_next( nodeIf );
+
+               if( ! iface->useInterface || iface->externalQuery )
+                       continue;
+
+               nodeDS = iface->listSource;
+               while( nodeDS && !found) {
+                       ds = nodeDS->data;
+
+                       /* Read address book */
+                       if( addrindex_ds_get_modify_flag( ds ) ) {
+                               addrindex_ds_read_data( ds );
+                       }
+
+                       if( ! addrindex_ds_get_read_flag( ds ) ) {
+                               addrindex_ds_read_data( ds );
+                       }
+
+                       /* Get all persons */
+                       listP = addrindex_ds_get_all_persons( ds );
+                       nodeP = listP;
+                       while( nodeP ) {
+                               GList *nodeM;
+                               ItemPerson *person = nodeP->data;
+                               nodeM = person->listEMail;
+                               while(nodeM) {
+                                       ItemEMail *email = nodeM->data;
+                                       if (email->address && !strcasecmp(raw_addr, email->address)) {
+                                               found = TRUE;
+                                               filename = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, 
+                                                       ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
+                                                       person->picture, NULL );
+                                               break;
+                                       }
+                                       nodeM = nodeM->next;
+                               }
+                               nodeP = g_list_next( nodeP );
+                       }
+                       /* Free up the list */
+                       g_list_free( listP );
+
+                       nodeDS = g_list_next( nodeDS );
+               }
+       }
+
+       return filename;
+}
 
 /*
  * End of Source.
index 8255855..fac0c2b 100644 (file)
@@ -174,7 +174,7 @@ gboolean addrindex_load_person_attribute( const gchar *attr,
 
 gboolean addrindex_load_person_ds( gint (*callBackFunc)
                        ( ItemPerson *, AddressDataSource * ) );
-                       
+gchar *addrindex_get_picture_file(const gchar *emailaddr);             
 #endif /* __ADDRINDEX_H__ */
 
 /*
index 4da7edd..c60798c 100644 (file)
@@ -268,6 +268,17 @@ void addritem_person_set_picture( ItemPerson *person, const gchar *value ) {
                g_free(out);
        }
 }
+
+/**
+ * Get picture for person object.
+ * \param person Person object.
+ * \param value Picture.
+ */
+gchar *addritem_person_get_picture( ItemPerson *person) {
+       if (person->picture)
+               return g_strdup(person->picture);
+       return NULL;
+}
 /**
  * Specify first name for person object.
  * \param person Person object.
@@ -1025,10 +1036,10 @@ GList *addritem_folder_get_person_list( ItemFolder *folder ) {
        node = folder->listPerson;
        while( node ) {
                ItemPerson *person = node->data;
-               list = g_list_append( list, person );
+               list = g_list_prepend( list, person );
                node = g_list_next( node );
        }
-       return list;
+       return g_list_reverse(list);
 }
 
 /**
@@ -1048,10 +1059,10 @@ GList *addritem_folder_get_group_list( ItemFolder *folder ) {
        node = folder->listGroup;
        while( node ) {
                ItemGroup *group = node->data;
-               list = g_list_append( list, group );
+               list = g_list_prepend( list, group );
                node = g_list_next( node );
        }
-       return list;
+       return g_list_reverse(list);
 }
 
 /**
index 1e79755..3981b8a 100644 (file)
@@ -137,6 +137,7 @@ void addritem_free_attribute                ( UserAttribute *item );
 ItemPerson *addritem_create_item_person        ( void );
 ItemPerson *addritem_copy_item_person  ( ItemPerson *item );
 void addritem_person_set_picture       ( ItemPerson *person, const gchar *value );
+gchar *addritem_person_get_picture     ( ItemPerson *person);
 void addritem_person_set_first_name    ( ItemPerson *person, const gchar *value );
 void addritem_person_set_last_name     ( ItemPerson *person, const gchar *value );
 void addritem_person_set_nick_name     ( ItemPerson *person, const gchar *value );
index fa082a8..b0c7370 100644 (file)
@@ -5963,7 +5963,7 @@ static void compose_add_to_addressbook_cb(GtkMenuItem *menuitem, gpointer user_d
        if (*address != '\0') {
                gchar *name = procheader_get_fromname(address);
                extract_address(address);
-               addressbook_add_contact(name, address, NULL);
+               addressbook_add_contact(name, address, NULL, NULL);
        }
        g_free(address);
 }
index 5a98609..b182b18 100644 (file)
@@ -45,6 +45,7 @@
 #include "editaddress.h"
 #include "editaddress_other_attributes_ldap.h"
 #include "prefs_common.h"
+#include "menu.h"
 
 /* transient data */
 static struct _PersonEdit_dlg personeditdlg;
@@ -696,20 +697,34 @@ void addressbook_edit_person_widgetset_hide( void )
                gtk_widget_hide( personeditdlg.container );
 }
 
-GtkWidget *picture;
+static void addressbook_edit_person_unset_picture (void *obj, guint action, void *data)
+{
+       personeditdlg.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 48, 48);
+       gdk_pixbuf_fill(personeditdlg.pixbuf, 0xffffff00);
+       personeditdlg.picture_set = FALSE;
+       gtk_image_set_from_pixbuf(GTK_IMAGE(personeditdlg.image), personeditdlg.pixbuf);
+}
+
+static GtkItemFactoryEntry editaddr_popup_entries[] =
+{
+       {N_("/_Unset picture"),         NULL, addressbook_edit_person_unset_picture, 0, NULL},
+};
 
-static void addressbook_edit_person_set_picture(gpointer data)
+static void addressbook_edit_person_set_picture(GtkWidget *widget, 
+               GdkEventButton *event, gpointer data)
 {
-               GError *error = NULL;
-               gchar *filename;
-               int width, height, scalewidth, scaleheight;
+       GError *error = NULL;
+       gchar *filename;
+       int width, height, scalewidth, scaleheight;
+       
+       if (event->button == 1) {
                if ( (filename = filesel_select_file_open(_("Choose a picture"), NULL)) ) {
-                       personeditdlg.picture = gdk_pixbuf_new_from_file(filename, &error);
+                       personeditdlg.pixbuf = gdk_pixbuf_new_from_file(filename, &error);
                        personeditdlg.picture_set = TRUE;
                        g_free(filename);
-                       width = gdk_pixbuf_get_width(personeditdlg.picture);
-                       height = gdk_pixbuf_get_height(personeditdlg.picture);
-                       
+                       width = gdk_pixbuf_get_width(personeditdlg.pixbuf);
+                       height = gdk_pixbuf_get_height(personeditdlg.pixbuf);
+
                        if ( width > 128 || height > 128 ) {
                                if (width > height) {
                                        scaleheight = (height * 128) / width;
@@ -719,10 +734,15 @@ static void addressbook_edit_person_set_picture(gpointer data)
                                        scalewidth = (width * 128) / height;
                                        scaleheight = 128;
                                }
-                               personeditdlg.picture = gdk_pixbuf_scale_simple(personeditdlg.picture, scalewidth, scaleheight, GDK_INTERP_BILINEAR);
+                               personeditdlg.pixbuf = gdk_pixbuf_scale_simple(personeditdlg.pixbuf, scalewidth, scaleheight, GDK_INTERP_BILINEAR);
                        }
-               gtk_image_set_from_pixbuf(GTK_IMAGE(picture), personeditdlg.picture);
+               gtk_image_set_from_pixbuf(GTK_IMAGE(personeditdlg.image), personeditdlg.pixbuf);
                }
+       } else {
+               gtk_menu_popup(GTK_MENU(personeditdlg.editaddr_popupmenu), 
+                              NULL, NULL, NULL, NULL, 
+                              event->button, event->time);
+       }
 }
 
 static void addressbook_edit_person_page_basic( gint pageNum, gchar *pageLbl ) {
@@ -738,6 +758,7 @@ static void addressbook_edit_person_page_basic( gint pageNum, gchar *pageLbl ) {
        GtkWidget *entry_nn;
        const gchar *locale;
        gint top = 0;
+       gint n_entries;
 
        vbox = gtk_vbox_new( FALSE, 20 );
        hbox = gtk_hbox_new( FALSE, 8 );
@@ -749,11 +770,12 @@ static void addressbook_edit_person_page_basic( gint pageNum, gchar *pageLbl ) {
        frame_picture = gtk_frame_new("Photo");
        
        /* Room for a photo */
-       personeditdlg.picture = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 128, 128);
+       personeditdlg.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 48, 48);
+       gdk_pixbuf_fill(personeditdlg.pixbuf, 0xffffff00);
        personeditdlg.picture_set = FALSE;
-       picture = gtk_image_new_from_pixbuf(personeditdlg.picture);
+       personeditdlg.image = gtk_image_new_from_pixbuf(personeditdlg.pixbuf);
        
-       gtk_container_add(GTK_CONTAINER(ebox_picture), picture);
+       gtk_container_add(GTK_CONTAINER(ebox_picture), personeditdlg.image);
        gtk_container_add(GTK_CONTAINER(frame_picture), ebox_picture);  
        gtk_container_add(GTK_CONTAINER( personeditdlg.notebook ), hbox );
        gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
@@ -771,6 +793,12 @@ static void addressbook_edit_person_page_basic( gint pageNum, gchar *pageLbl ) {
        g_signal_connect(G_OBJECT(ebox_picture), "button_press_event", 
                        G_CALLBACK(addressbook_edit_person_set_picture), NULL);
 
+       n_entries = sizeof(editaddr_popup_entries) /
+               sizeof(editaddr_popup_entries[0]);
+       personeditdlg.editaddr_popupmenu = menu_create_items(editaddr_popup_entries, n_entries,
+                                     "<EditAddrPopupMenu>", &personeditdlg.editaddr_popupfactory,
+                                     NULL);
+
        table = gtk_table_new( 3, 3, FALSE);
 
 #define ATTACH_ROW(text, entry) \
@@ -1405,9 +1433,14 @@ static gboolean addressbook_edit_person_close( gboolean cancelled )
                if (personeditdlg.picture_set) {
                        name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
                                                        ADDRITEM_ID(current_person), NULL );
-                       gdk_pixbuf_save(personeditdlg.picture, name, "png", &error, NULL);
+                       gdk_pixbuf_save(personeditdlg.pixbuf, name, "png", &error, NULL);
                        addritem_person_set_picture( current_person, ADDRITEM_ID(current_person) ) ;
                        g_free( name );
+               } else {
+                       name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
+                                                       ADDRITEM_ID(current_person), NULL );
+                       g_unlink(name);
+                       g_free(name);
                }
                name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_first), 0, -1 );
                addritem_person_set_first_name( current_person, name );
@@ -1487,19 +1520,25 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent_fo
        if( current_person ) {
                if( ADDRITEM_NAME(current_person) )
                        gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_name), ADDRITEM_NAME(person) );
-               else
-                       personeditdlg.picture = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 128, 128);
+
                if( current_person->picture ) { 
                        gchar *filename = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
                                                        current_person->picture, NULL );
-                       personeditdlg.picture = gdk_pixbuf_new_from_file(filename, &error);
-                       personeditdlg.picture_set = TRUE;
+                       if (is_file_exist(filename)) {
+                               personeditdlg.pixbuf = gdk_pixbuf_new_from_file(filename, &error);
+                               personeditdlg.picture_set = TRUE;
+                       } else {
+                               personeditdlg.picture_set = FALSE;
+                               personeditdlg.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 48, 48);
+                               gdk_pixbuf_fill(personeditdlg.pixbuf, 0xffffff00);
+                       }
                        g_free(filename);
                } else {
                        personeditdlg.picture_set = FALSE;
-                       personeditdlg.picture = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 128, 128);
+                       personeditdlg.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 48, 48);
+                       gdk_pixbuf_fill(personeditdlg.pixbuf, 0xffffff00);
                }
-               gtk_image_set_from_pixbuf(GTK_IMAGE(picture), personeditdlg.picture);
+               gtk_image_set_from_pixbuf(GTK_IMAGE(personeditdlg.image), personeditdlg.pixbuf);
 
                if( current_person->firstName )
                        gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_first), current_person->firstName );
index c369cac..1e9cd55 100644 (file)
@@ -33,6 +33,7 @@
 #include <gtk/gtkvbox.h>
 #include <gtk/gtkentry.h>
 #include <gtk/gtktable.h>
+#include <gtk/gtkitemfactory.h>
 
 typedef struct _PersonEdit_dlg PersonEditDlg;
 struct _PersonEdit_dlg {
@@ -45,7 +46,8 @@ struct _PersonEdit_dlg {
        gint status_cid;
 
        /* User data tab */
-       GdkPixbuf *picture;
+       GdkPixbuf *pixbuf;
+       GtkWidget *image;
        gboolean picture_set;
        GtkWidget *entry_name;
        GtkWidget *entry_first;
@@ -76,6 +78,8 @@ struct _PersonEdit_dlg {
        gboolean editNew;
        gboolean read_only;
        gboolean ldap;
+       GtkItemFactory *editaddr_popupfactory;
+       GtkWidget *editaddr_popupmenu;
 };
 
 #ifdef USE_LDAP
index ec877d0..2e5e3f7 100644 (file)
@@ -1233,7 +1233,8 @@ GtkWidget *xface_get_from_header(const gchar *o_xface, GdkColor *background,
        pixmap = gdk_pixmap_create_from_xpm_d
                (window, &mask, 
                 background, xpm_xface);
-       return gtk_image_new_from_pixmap(pixmap, mask);
+       return gtk_image_new_from_pixbuf(
+               gdk_pixbuf_new_from_xpm_data((const char **)xpm_xface));
 }
 #endif
 
index 6b1d76e..38148c2 100644 (file)
 #include "utils.h"
 #include "base64.h"
 #include "headers.h"
+#include "addrindex.h"
 
 #if HAVE_LIBCOMPFACE
 #define XPM_XFACE_HEIGHT       (HEIGHT + 3)  /* 3 = 1 header + 2 colors */
 
 static gchar *xpm_xface[XPM_XFACE_HEIGHT];
 
-static void headerview_show_xface      (HeaderView     *headerview,
+static gint headerview_show_xface      (HeaderView     *headerview,
                                         MsgInfo        *msginfo);
 #endif
 
 static gint headerview_show_face       (HeaderView     *headerview,
                                         MsgInfo        *msginfo);
+static gint headerview_show_contact_pic        (HeaderView     *headerview,
+                                        MsgInfo        *msginfo);
+static void headerview_save_contact_pic        (HeaderView     *headerview,
+                                        MsgInfo        *msginfo);
 
 HeaderView *headerview_create(void)
 {
@@ -237,12 +242,17 @@ void headerview_show(HeaderView *headerview, MsgInfo *msginfo)
                return;
 
 #if HAVE_LIBCOMPFACE
-       headerview_show_xface(headerview, msginfo);
+       if (!headerview_show_xface(headerview, msginfo))
+               return;
 #endif
+
+       if (!headerview_show_contact_pic(headerview, msginfo))
+               return;
+
 }
 
 #if HAVE_LIBCOMPFACE
-static void headerview_show_xface(HeaderView *headerview, MsgInfo *msginfo)
+static gint headerview_show_xface(HeaderView *headerview, MsgInfo *msginfo)
 {
        GtkWidget *hbox = headerview->hbox;
        GtkWidget *image;
@@ -255,9 +265,9 @@ static void headerview_show_xface(HeaderView *headerview, MsgInfo *msginfo)
                        gtk_widget_hide(headerview->image);
                        gtk_widget_queue_resize(hbox);
                }
-               return;
+               return -1;
        }
-       if (!GTK_WIDGET_VISIBLE(headerview->hbox)) return;
+       if (!GTK_WIDGET_VISIBLE(headerview->hbox)) return -1;
 
        if (headerview->image) {
                gtk_widget_destroy(headerview->image);
@@ -274,6 +284,10 @@ static void headerview_show_xface(HeaderView *headerview, MsgInfo *msginfo)
        }
 
        headerview->image = image;
+       if (image) {
+               headerview_save_contact_pic(headerview, msginfo);
+       }
+       return 0;
 }
 #endif
 
@@ -305,6 +319,78 @@ static gint headerview_show_face (HeaderView *headerview, MsgInfo *msginfo)
                gtk_widget_show(image);
        }
 
+       headerview->image = image;
+       if (image == NULL)
+               return -1;
+       else {
+               headerview_save_contact_pic(headerview, msginfo);
+               return 0;
+       }
+}
+
+static void headerview_save_contact_pic (HeaderView *headerview, MsgInfo *msginfo)
+{
+       gchar *filename = NULL;
+       GError *error = NULL;
+       GdkPixbuf *picture = NULL;
+
+       if (!GTK_WIDGET_VISIBLE(headerview->hbox)) return;
+
+       if (headerview->image) {
+               picture = gtk_image_get_pixbuf(GTK_IMAGE(headerview->image));
+       }
+       
+       filename = addrindex_get_picture_file(msginfo->from);
+       if (!filename)
+               return;
+       if (!is_file_exist(filename))
+               gdk_pixbuf_save(picture, filename, "png", &error, NULL);
+       g_free(filename);
+}      
+
+static gint headerview_show_contact_pic (HeaderView *headerview, MsgInfo *msginfo)
+{
+       GtkWidget *hbox = headerview->hbox;
+       GtkWidget *image;
+       gchar *filename = NULL;
+       GError *error = NULL;
+       GdkPixbuf *picture = NULL;
+       gint w, h;
+
+       if (!GTK_WIDGET_VISIBLE(headerview->hbox)) return -1;
+
+       if (headerview->image) {
+               gtk_widget_destroy(headerview->image);
+               headerview->image = NULL;
+       }
+       
+       filename = addrindex_get_picture_file(msginfo->from);
+       
+       if (!filename)
+               return -1;
+       if (!is_file_exist(filename)) {
+               g_free(filename);
+               return -1;
+       }
+       gdk_pixbuf_get_file_info(filename, &w, &h);
+       
+       if (w > 48 || h > 48)
+               picture = gdk_pixbuf_new_from_file_at_scale(filename, 
+                                               48, 48, TRUE, &error);
+       else
+               picture = gdk_pixbuf_new_from_file(filename, &error);
+
+       g_free(filename);
+       if (picture)
+               image = gtk_image_new_from_pixbuf(picture);
+       else 
+               return -1;
+
+       if (image) {
+               gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
+               gtk_widget_show(image);
+       }
+
        headerview->image = image;
        if (image == NULL)
                return -1;
index ae89fc5..89309ad 100644 (file)
@@ -2260,15 +2260,37 @@ static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
 static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
 {
        MessageView *messageview = (MessageView *)data;
-       MsgInfo *msginfo;
+       MsgInfo *msginfo, *full_msginfo;
        gchar *from;
+       GtkWidget *image = NULL;
+       GdkPixbuf *picture = NULL;
 
        if (!messageview->msginfo) return;
        msginfo = messageview->msginfo;
        Xstrdup_a(from, msginfo->from, return);
        eliminate_address_comment(from);
        extract_address(from);
-       addressbook_add_contact(msginfo->fromname, from, NULL);
+       
+       full_msginfo = procmsg_msginfo_get_full_info(msginfo);
+       if (full_msginfo &&
+           full_msginfo->extradata &&
+           full_msginfo->extradata->face) {
+               image = face_get_from_header(full_msginfo->extradata->face);
+       } else if (full_msginfo &&
+                full_msginfo->extradata &&
+                full_msginfo->extradata->xface) {
+               image = xface_get_from_header(full_msginfo->extradata->xface,
+                               &messageview->mainwin->summaryview->ctree->style->white,
+                               messageview->window->window);   
+       }
+       procmsg_msginfo_free(full_msginfo);
+       if (image)
+               picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
+
+       addressbook_add_contact(msginfo->fromname, from, NULL, picture);
+
+       if (image)
+               gtk_widget_destroy(image);
 }
 
 static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
index 854b81f..fb23456 100644 (file)
@@ -41,6 +41,8 @@
 #include <gtk/gtkcontainer.h>
 #include <gtk/gtkbutton.h>
 #include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #ifndef HAVE_APACHE_FNMATCH
 /* kludge: apache's fnmatch clashes with <regex.h>, don't include
index 43b2e6e..cfb9f49 100644 (file)
@@ -4307,8 +4307,10 @@ void summary_copy_to(SummaryView *summaryview)
 
 void summary_add_address(SummaryView *summaryview)
 {
-       MsgInfo *msginfo;
+       MsgInfo *msginfo, *full_msginfo;
        gchar *from;
+       GtkWidget *image = NULL;
+       GdkPixbuf *picture = NULL;
 
        msginfo = gtk_ctree_node_get_row_data(GTK_CTREE(summaryview->ctree),
                                              summaryview->selected);
@@ -4317,7 +4319,27 @@ void summary_add_address(SummaryView *summaryview)
        Xstrdup_a(from, msginfo->from, return);
        eliminate_address_comment(from);
        extract_address(from);
-       addressbook_add_contact(msginfo->fromname, from, NULL);
+       
+       full_msginfo = procmsg_msginfo_get_full_info(msginfo);
+       if (full_msginfo &&
+           full_msginfo->extradata &&
+           full_msginfo->extradata->face) {
+               image = face_get_from_header(full_msginfo->extradata->face);
+       } else if (full_msginfo &&
+                full_msginfo->extradata &&
+                full_msginfo->extradata->xface) {
+               image = xface_get_from_header(full_msginfo->extradata->xface,
+                               &summaryview->ctree->style->white,
+                               summaryview->mainwin->window->window);  
+       }
+       procmsg_msginfo_free(full_msginfo);
+       if (image)
+               picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
+
+       addressbook_add_contact(msginfo->fromname, from, NULL, picture);
+
+       if (image)
+               gtk_widget_destroy(image);
 }
 
 void summary_select_all(SummaryView *summaryview)
index b7bca8f..9f9d09d 100644 (file)
@@ -69,6 +69,7 @@
 #include "inputdialog.h"
 #include "timing.h"
 #include "tags.h"
+#include "addrindex.h"
 
 static GdkColor quote_colors[3] = {
        {(gulong)0, (gushort)0, (gushort)0, (gushort)0},
@@ -1904,6 +1905,88 @@ bail:
 }
 #endif
 
+static void textview_save_contact_pic(TextView *textview)
+{
+       MsgInfo *msginfo = textview->messageview->msginfo;
+       gchar *filename = NULL;
+       GError *error = NULL;
+       GdkPixbuf *picture = NULL;
+                               
+       if (!msginfo->extradata || (!msginfo->extradata->face && !msginfo->extradata->xface))
+               return;
+
+       if (textview->image) 
+               picture = gtk_image_get_pixbuf(GTK_IMAGE(textview->image));
+
+       filename = addrindex_get_picture_file(msginfo->from);
+       if (!filename)
+               return;
+       if (!is_file_exist(filename))
+               gdk_pixbuf_save(picture, filename, "png", &error, NULL);
+       g_free(filename);
+}
+
+static void textview_show_contact_pic(TextView *textview)
+{
+       MsgInfo *msginfo = textview->messageview->msginfo;
+       GtkTextView *text = GTK_TEXT_VIEW(textview->text);
+       int x = 0;
+       gchar *filename = NULL;
+       GError *error = NULL;
+       GdkPixbuf *picture = NULL;
+       gint w, h;
+                               
+       if (prefs_common.display_header_pane
+       ||  !prefs_common.display_xface)
+               goto bail;
+       
+       if (msginfo->extradata && (msginfo->extradata->face || msginfo->extradata->xface))
+               return;
+
+       if (textview->image) 
+               gtk_widget_destroy(textview->image);
+
+       filename = addrindex_get_picture_file(msginfo->from);
+       
+       if (!filename)
+               goto bail;
+       if (!is_file_exist(filename)) {
+               g_free(filename);
+               goto bail;
+       }
+
+       gdk_pixbuf_get_file_info(filename, &w, &h);
+       
+       if (w > 48 || h > 48)
+               picture = gdk_pixbuf_new_from_file_at_scale(filename, 
+                                               48, 48, TRUE, &error);
+       else
+               picture = gdk_pixbuf_new_from_file(filename, &error);
+
+       g_free(filename);
+
+       if (picture)
+               textview->image = gtk_image_new_from_pixbuf(picture);
+
+       g_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;
+       
+}
+
 static void textview_show_tags(TextView *textview)
 {
        MsgInfo *msginfo = textview->messageview->msginfo;
@@ -2027,6 +2110,8 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
 #if HAVE_LIBCOMPFACE
        textview_show_xface(textview);
 #endif
+       textview_save_contact_pic(textview);
+       textview_show_contact_pic(textview);
 }
 
 gboolean textview_search_string(TextView *textview, const gchar *str,
@@ -2812,6 +2897,9 @@ static void add_uri_to_addrbook_cb (TextView *textview, guint action, void *data
        gchar *fromname, *fromaddress;
        ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
                                           "menu_button");
+       GtkWidget *image = NULL;
+       GdkPixbuf *picture = NULL;
+
        if (uri == NULL)
                return;
 
@@ -2821,8 +2909,21 @@ static void add_uri_to_addrbook_cb (TextView *textview, guint action, void *data
        fromname = procheader_get_fromname(fromaddress);
        extract_address(fromaddress);
 
-       /* Add to address book - Match */
-       addressbook_add_contact( fromname, fromaddress, NULL );
+       if (textview->messageview->msginfo &&
+           textview->messageview->msginfo->extradata &&
+           textview->messageview->msginfo->extradata->face) {
+               image = face_get_from_header(textview->messageview->msginfo->extradata->face);
+       } else if (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 (image)
+               picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
+
+       addressbook_add_contact( fromname, fromaddress, NULL, picture);
 
        g_free(fromaddress);
        g_free(fromname);