Address book patch



The attached patch seems to work... ;) It raw reads the GnomeCard.gcrd file and
uses the FN field as the name.. ideally if this is switched to CORBA, this
would be changed. If there are any bugs, memory leaks, or such, please tell me
about them. It's fairly funky coding at times I think, but there were several
cases I used strange workarounds to make things as simple as I could.

This patch was generated with a diff -rcP between a clean CVS checkout and one
with the address book added. Is there a better more useful format, or such?

---
Mathieu Fenniak
laotzu@pobox.com
diff -rcP balsa-old/src/Makefile.am balsa/src/Makefile.am
*** balsa-old/src/Makefile.am	Thu Mar 18 17:36:51 1999
--- balsa/src/Makefile.am	Thu Jun 10 19:45:44 1999
***************
*** 3,8 ****
--- 3,9 ----
  bin_PROGRAMS = balsa
  
  balsa_SOURCES =	\
+ 	address-book.c		\
  	balsa-app.c		\
  	balsa-icons.c		\
  	balsa-index.c		\
diff -rcP balsa-old/src/address-book.c balsa/src/address-book.c
*** balsa-old/src/address-book.c	Wed Dec 31 17:00:00 1969
--- balsa/src/address-book.c	Thu Jun 10 19:46:14 1999
***************
*** 0 ****
--- 1,259 ----
+ #include <gtk/gtk.h>
+ #include <gnome.h>
+ #include <stdio.h>
+ #include <errno.h>
+ 
+ static GtkWidget *book_clist;
+ static GtkWidget *add_clist;
+ static GtkWidget *ab_entry;
+ gint            composing;
+ 
+ typedef struct {
+     gchar          *name;
+     gchar          *addy;
+ } AddressData;
+ 
+ gint
+ ab_cancel_cb(GtkWidget * widget, gpointer data)
+ {
+     GnomeDialog    *dialog = (GnomeDialog *) data;
+ 
+     g_assert(dialog != NULL);
+     gtk_widget_destroy(GTK_WIDGET(dialog));
+ 
+     return FALSE;
+ }
+ 
+ gint
+ ab_okay_cb(GtkWidget * widget, gpointer data)
+ {
+     gpointer        row;
+     gchar          *text;
+     gchar new[512];
+ 
+     if (composing) {
+ 
+ 	text = gtk_entry_get_text(GTK_ENTRY(ab_entry));
+ 	strcpy(new, text);
+ 
+ 	while (row = gtk_clist_get_row_data(GTK_CLIST(add_clist), 0)) {
+ 	    AddressData    *addy = (AddressData *) row;
+ 	    sprintf(new, "%s%s %s <%s>", new, ((*new != '\0') ? ", " : ""), addy->name, addy->addy);
+ 	    free(addy->name);
+ 	    free(addy->addy);
+ 	    g_free(addy);
+ 	    gtk_clist_remove(GTK_CLIST(add_clist), 0);
+ 	}
+ 
+         gtk_entry_set_text(GTK_ENTRY(ab_entry), new);
+     }
+     ab_cancel_cb(widget, data);
+ 
+     return FALSE;
+ }
+ 
+ gint
+ ab_delete_compare(gconstpointer a, gconstpointer b)
+ {
+     if ((gint) a > (gint) b)
+ 	return 1;
+     else if ((gint) a == (gint) b)
+ 	return 0;
+     else
+ 	return -1;
+ }
+ 
+ gint
+ ab_switch_cb(GtkWidget * widget, gpointer data)
+ {
+     GtkWidget      *from = (GtkWidget *) data;
+     GtkWidget      *to = (data == book_clist) ? add_clist : book_clist;
+     GList          *glist = GTK_CLIST(from)->selection;
+     GList          *deletelist = NULL,
+                    *pointer;
+ 
+     for (pointer = g_list_first(glist); pointer != NULL; pointer = g_list_next(pointer)) {
+ 	gint            num;
+ 	gchar          *listdata[2];
+ 	AddressData    *addy_data;
+ 
+ 	num = (gint) (pointer->data);
+ 
+ 	addy_data = gtk_clist_get_row_data(GTK_CLIST(from), num);
+ 	listdata[0] = addy_data->name;
+ 	listdata[1] = addy_data->addy;
+ 
+ 	deletelist = g_list_append(deletelist, (gpointer) num);
+ 
+ 	num = gtk_clist_append(GTK_CLIST(to), listdata);
+ 	gtk_clist_set_row_data(GTK_CLIST(to), num, (gpointer) addy_data);
+     }
+ 
+     deletelist = g_list_sort(deletelist, (GCompareFunc) ab_delete_compare);
+ 
+     for (pointer = g_list_last(deletelist); pointer != NULL; pointer = g_list_previous(pointer)) {
+ 	gtk_clist_remove(GTK_CLIST(from), (gint) (pointer->data));
+     }
+ 
+     g_list_free(deletelist);
+ 
+     return FALSE;
+ }
+ 
+ void
+ ab_load()
+ {
+     FILE           *gc;
+     gchar           name[256],
+                     email[256],
+                     string[256],
+                    *listdata[2];
+     gint            got_name = FALSE;
+ 
+     gc = fopen(gnome_util_prepend_user_home(".gnome/GnomeCard.gcrd"), "r");
+     if (!gc) {
+ 	g_print(N_("Unable to open ~/.gnome/GnomeCard.gcrd for read.\n - %s\n"), g_unix_error_string(errno));
+ 	return;
+     }
+     while (fgets(string, 255, gc)) {
+ 	if (string[0] == 'F' && string[1] == 'N' && string[2] == ':' && string[3] != '\0') {
+ 	    got_name = TRUE;
+ 	    strcpy(name, &string[3]);
+ 	}
+ 	if (sscanf(string, N_("EMAIL;INTERNET:%s\n"), email)) {
+ 	    int             rownum;
+ 	    AddressData    *data = g_malloc(sizeof(AddressData));
+ 
+ 	    listdata[0] = got_name ? strdup(name) : strdup(N_("No-Name"));
+ 	    listdata[1] = strdup(email);
+ 
+ 	    data->name = listdata[0];
+ 	    data->addy = listdata[1];
+ 
+ 	    rownum = gtk_clist_append(GTK_CLIST(book_clist), listdata);
+ 	    gtk_clist_set_row_data(GTK_CLIST(book_clist), rownum, (gpointer) data);
+ 	    got_name = FALSE;
+ 	}
+     }
+ 
+     gtk_clist_set_column_width(GTK_CLIST(book_clist), 0, gtk_clist_optimal_column_width(GTK_CLIST(book_clist), 0));
+ 
+     fclose(gc);
+ }
+ 
+ gint
+ ab_add_cb(GtkWidget * widget, gpointer data)
+ {
+     GtkWidget      *dialog,
+                    *vbox,
+                    *w,
+                    *hbox;
+ 
+     dialog = gnome_dialog_new(N_("Add New Address"), GNOME_STOCK_BUTTON_CANCEL, GNOME_STOCK_BUTTON_OK, NULL);
+     gnome_dialog_button_connect(GNOME_DIALOG(dialog), 0, GTK_SIGNAL_FUNC(ab_cancel_cb), (gpointer) dialog);
+     vbox = GNOME_DIALOG(dialog)->vbox;
+ 
+     hbox = gtk_hbox_new(FALSE, 5);
+     gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+     gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(N_("Name:")), FALSE, FALSE, 0);
+     w = gtk_entry_new();
+     gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0);
+ 
+     hbox = gtk_hbox_new(FALSE, 5);
+     gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+     gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(N_("E-Mail Address:")), FALSE, FALSE, 0);
+     w = gtk_entry_new();
+     gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0);
+ 
+     gtk_widget_show_all(dialog);
+ 
+     return FALSE;
+ }
+ 
+ gint
+ address_book_cb(GtkWidget * widget, gpointer data)
+ {
+     GtkWidget      *dialog,
+                    *vbox,
+                    *w,
+                    *hbox,
+                    *box2,
+                    *scrolled_window;
+     gchar          *titles[2] =
+     {N_("Name"), N_("E-Mail Address")};
+ 
+     dialog = gnome_dialog_new(N_("Address Book"), GNOME_STOCK_BUTTON_CANCEL, GNOME_STOCK_BUTTON_OK, NULL);
+     gnome_dialog_button_connect(GNOME_DIALOG(dialog), 0, GTK_SIGNAL_FUNC(ab_cancel_cb), (gpointer) dialog);
+     gnome_dialog_button_connect(GNOME_DIALOG(dialog), 1, GTK_SIGNAL_FUNC(ab_okay_cb), (gpointer) dialog);
+     vbox = GNOME_DIALOG(dialog)->vbox;
+ 
+     book_clist = gtk_clist_new_with_titles(2, titles);
+     gtk_clist_set_selection_mode(GTK_CLIST(book_clist), GTK_SELECTION_MULTIPLE);
+     gtk_clist_column_titles_passive(GTK_CLIST(book_clist));
+ 
+     add_clist = gtk_clist_new_with_titles(2, titles);
+     gtk_clist_set_selection_mode(GTK_CLIST(add_clist), GTK_SELECTION_MULTIPLE);
+     gtk_clist_column_titles_passive(GTK_CLIST(add_clist));
+ 
+     ab_entry = (GtkWidget *) data;
+ 
+     composing = FALSE;
+ 
+     hbox = gtk_hbox_new(FALSE, 5);
+     gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+ 
+     box2 = gtk_vbox_new(FALSE, 5);
+     gtk_box_pack_start(GTK_BOX(hbox), box2, FALSE, FALSE, 0);
+     gtk_box_pack_start(GTK_BOX(box2), gtk_label_new(N_("Address Book")), FALSE, FALSE, 0);
+     scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
+ 				 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+     gtk_box_pack_start(GTK_BOX(box2), scrolled_window, TRUE, TRUE, 0);
+     gtk_container_add(GTK_CONTAINER(scrolled_window), book_clist);
+     gtk_widget_set_usize(scrolled_window, 250, 200);
+ 
+     /*
+      * Only display this part of * the window when we're adding to a composing
+      * message.  
+      */
+     if (!GNOME_IS_MDI((GnomeMDI *) data)) {
+ 	composing = TRUE;
+ 
+ 	box2 = gtk_vbox_new(FALSE, 5);
+ 	gtk_box_pack_start(GTK_BOX(hbox), box2, FALSE, FALSE, 0);
+ 	w = gtk_button_new();
+ 	gtk_container_add(GTK_CONTAINER(w), gnome_stock_pixmap_widget(dialog, GNOME_STOCK_PIXMAP_FORWARD));
+ 	gtk_signal_connect(GTK_OBJECT(w), "clicked", GTK_SIGNAL_FUNC(ab_switch_cb), (gpointer) book_clist);
+ 	gtk_box_pack_start(GTK_BOX(box2), w, TRUE, FALSE, 0);
+ 	w = gtk_button_new();
+ 	gtk_container_add(GTK_CONTAINER(w), gnome_stock_pixmap_widget(dialog, GNOME_STOCK_PIXMAP_BACK));
+ 	gtk_signal_connect(GTK_OBJECT(w), "clicked", GTK_SIGNAL_FUNC(ab_switch_cb), (gpointer) add_clist);
+ 	gtk_box_pack_start(GTK_BOX(box2), w, TRUE, FALSE, 0);
+ 
+ 	box2 = gtk_vbox_new(FALSE, 5);
+ 	gtk_box_pack_start(GTK_BOX(hbox), box2, TRUE, TRUE, 0);
+ 	gtk_box_pack_start(GTK_BOX(box2), gtk_label_new(N_("Send-To")), FALSE, FALSE, 0);
+ 	scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+ 	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
+ 				 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ 	gtk_box_pack_start(GTK_BOX(box2), scrolled_window, FALSE, FALSE, 0);
+ 	gtk_container_add(GTK_CONTAINER(scrolled_window), add_clist);
+ 	gtk_clist_set_selection_mode(GTK_CLIST(add_clist), GTK_SELECTION_MULTIPLE);
+ 	gtk_clist_column_titles_passive(GTK_CLIST(add_clist));
+ 	gtk_widget_set_usize(scrolled_window, 250, 200);
+     }
+     hbox = gtk_hbutton_box_new();
+     gtk_hbutton_box_set_layout_default(GTK_BUTTONBOX_START);
+     gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+     w = gnome_pixmap_button(gnome_stock_pixmap_widget(dialog, GNOME_STOCK_PIXMAP_ADD), N_("Add New Entry"));
+     gtk_signal_connect(GTK_OBJECT(w), "clicked", GTK_SIGNAL_FUNC(ab_add_cb), book_clist);
+     gtk_container_add(GTK_CONTAINER(hbox), w);
+     w = gnome_pixmap_button(gnome_stock_pixmap_widget(dialog, GNOME_STOCK_PIXMAP_ADD), N_("Import New Entries"));
+     gtk_container_add(GTK_CONTAINER(hbox), w);
+ 
+     ab_load(book_clist);
+ 
+     gtk_widget_show_all(dialog);
+ 
+     return FALSE;
+ }
diff -rcP balsa-old/src/main-window.c balsa/src/main-window.c
*** balsa-old/src/main-window.c	Tue Feb 23 20:33:13 1999
--- balsa/src/main-window.c	Thu Jun 10 19:49:35 1999
***************
*** 72,77 ****
--- 72,79 ----
  static void delete_message_cb (GtkWidget * widget, gpointer data);
  static void undelete_message_cb (GtkWidget * widget, gpointer data);
  
+ extern gint address_book_cb (GtkWidget *widget, gpointer data);
+ 
  static void filter_dlg_cb (GtkWidget * widget, gpointer data);
  
  static void mailbox_close_child (GtkWidget * widget, gpointer data);
***************
*** 140,145 ****
--- 142,155 ----
      undelete_message_cb, NULL, NULL, GNOME_APP_PIXMAP_STOCK,
      GNOME_STOCK_MENU_UNDELETE, 'U', 0, NULL
    },
+ 
+   GNOMEUIINFO_SEPARATOR,
+   {
+     GNOME_APP_UI_ITEM, N_ ("Address Book"), N_("Opens the address book"),
+     address_book_cb, NULL, NULL, GNOME_APP_PIXMAP_STOCK,
+     GNOME_STOCK_MENU_BOOK_RED, 'B', 0, NULL
+   },
+ 
    GNOMEUIINFO_END
  };
  
***************
*** 425,435 ****
  static void
  check_new_messages_cb (GtkWidget * widget, gpointer data)
  {
-   if (balsa_app.current_index_child != NULL)
-     mailbox_check_new_messages (BALSA_INDEX (balsa_app.current_index_child->index)->mailbox);
- 
    check_all_pop3_hosts (balsa_app.inbox, balsa_app.inbox_input);
    check_all_imap_hosts (balsa_app.inbox, balsa_app.inbox_input);
  }
  
  static void
--- 435,445 ----
  static void
  check_new_messages_cb (GtkWidget * widget, gpointer data)
  {
    check_all_pop3_hosts (balsa_app.inbox, balsa_app.inbox_input);
    check_all_imap_hosts (balsa_app.inbox, balsa_app.inbox_input);
+ 
+   if (balsa_app.current_index_child != NULL)
+     mailbox_check_new_messages (BALSA_INDEX (balsa_app.current_index_child->index)->mailbox);
  }
  
  static void
diff -rcP balsa-old/src/sendmsg-window.c balsa/src/sendmsg-window.c
*** balsa-old/src/sendmsg-window.c	Thu Apr  8 17:52:09 1999
--- balsa/src/sendmsg-window.c	Thu Jun 10 19:49:41 1999
***************
*** 40,45 ****
--- 40,47 ----
  #include "send.h"
  #include "sendmsg-window.h"
  
+ extern gint address_book_cb(GtkWidget *, gpointer);
+ 
  static gint send_message_cb (GtkWidget *, BalsaSendmsg *);
  static gint attach_clicked (GtkWidget *, gpointer);
  static gint close_window (GtkWidget *, gpointer);
***************
*** 328,333 ****
--- 330,337 ----
  	       gnome_stock_pixmap_widget (NULL, GNOME_STOCK_MENU_BOOK_RED));
    gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
  		    0, 0, 0, 0);
+   gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(address_book_cb),
+ 		     (gpointer) msg->to);
    gtk_signal_connect (GTK_OBJECT (msg->to), "drag_data_received",
  		      GTK_SIGNAL_FUNC (to_add), NULL);
    gtk_drag_dest_set (GTK_WIDGET (msg->to), GTK_DEST_DEFAULT_ALL,
***************
*** 381,386 ****
--- 385,392 ----
  	    gnome_stock_pixmap_widget (NULL, GNOME_STOCK_MENU_BOOK_YELLOW));
    gtk_table_attach (GTK_TABLE (table), button, 2, 3, 3, 4,
  		    0, 0, 0, 0);
+   gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(address_book_cb),
+ 		     (gpointer) msg->cc);
    gtk_signal_connect (GTK_OBJECT (msg->cc), "drag_data_received",
  		      GTK_SIGNAL_FUNC (to_add), NULL);
    gtk_drag_dest_set (GTK_WIDGET (msg->cc), GTK_DEST_DEFAULT_ALL,
***************
*** 404,409 ****
--- 410,417 ----
  	     gnome_stock_pixmap_widget (NULL, GNOME_STOCK_MENU_BOOK_GREEN));
    gtk_table_attach (GTK_TABLE (table), button, 2, 3, 4, 5,
  		    0, 0, 0, 0);
+   gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(address_book_cb),
+ 		     (gpointer) msg->bcc);
    gtk_signal_connect (GTK_OBJECT (msg->bcc), "drag_data_received",
  		      GTK_SIGNAL_FUNC (to_add), NULL);
    gtk_drag_dest_set (GTK_WIDGET (msg->bcc), GTK_DEST_DEFAULT_ALL,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]