[evolution-patches] NameSelector entry options for list and contacts



Hi,

This patch, provides a intuitive way to select one of multiple emails
for a contact and provides a option to not send a mail to a contact
list.

-Srini
Index: e-destination.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/addressbook/libebook/e-destination.c,v
retrieving revision 1.12
diff -u -p -r1.12 e-destination.c
--- e-destination.c	4 May 2005 08:46:12 -0000	1.12
+++ e-destination.c	31 Aug 2005 07:33:03 -0000
@@ -63,6 +63,7 @@ struct _EDestinationPrivate {
 	char *email;
 	char *addr;
 	char *textrep;
+	gboolean ignored;
 
 	GList *list_dests;
 
@@ -154,6 +155,7 @@ e_destination_init (EDestination *dest)
 	dest->priv = g_new0 (struct _EDestinationPrivate, 1);
 
 	dest->priv->auto_recipient = FALSE;
+	dest->priv->ignored = FALSE;
 }
 
 GType
@@ -217,6 +219,7 @@ e_destination_copy (const EDestination *
         new_dest->priv->email              = g_strdup (dest->priv->email);
         new_dest->priv->addr               = g_strdup (dest->priv->addr);
         new_dest->priv->email_num          = dest->priv->email_num;
+        new_dest->priv->ignored            = dest->priv->ignored;
 
 	if (dest->priv->contact)
 		new_dest->priv->contact = g_object_ref (dest->priv->contact);
@@ -377,7 +380,7 @@ e_destination_set_contact (EDestination 
 	g_return_if_fail (dest && E_IS_DESTINATION (dest));
 	g_return_if_fail (contact && E_IS_CONTACT (contact));
 
-	if (dest->priv->contact != contact || dest->priv->email_num != email_num) {
+	if (dest->priv->contact != contact ) {
 		g_object_ref (contact);
 
 		e_destination_clear (dest);
@@ -388,6 +391,8 @@ e_destination_set_contact (EDestination 
 
 		dest->priv->email_num = email_num;
 
+		dest->priv->ignored = FALSE;
+
 		/* handle the mailing list case */
 		if (e_contact_get (dest->priv->contact, E_CONTACT_IS_LIST)) {
 			GList *email = e_contact_get_attributes (dest->priv->contact, E_CONTACT_EMAIL);
@@ -439,6 +444,7 @@ e_destination_set_contact (EDestination 
 					if (name) e_destination_set_name (list_dest, name);
 					if (email_addr) e_destination_set_email (list_dest, email_addr);
 					e_destination_set_html_mail_pref (list_dest, html_pref);
+					list_dest->priv->ignored = FALSE;
 
 					dest->priv->list_dests = g_list_append (dest->priv->list_dests, list_dest);
 				}
@@ -453,7 +459,21 @@ e_destination_set_contact (EDestination 
 		}
 
 		g_signal_emit (dest, signals [CHANGED], 0);
+	} else if (dest->priv->email_num != email_num){
+		/* Splitting here would help the contact lists not rebuiding, so that it remembers ignored values */
+		g_object_ref (contact);
+
+		e_destination_clear (dest);
+
+		dest->priv->contact = contact;
+
+		dest->priv->contact_uid = e_contact_get (dest->priv->contact, E_CONTACT_UID);
+
+		dest->priv->email_num = email_num;
+	
+		g_signal_emit (dest, signals [CHANGED], 0);		
 	}
+	
 }
 
 /**
@@ -770,6 +790,18 @@ e_destination_get_name (const EDestinati
 	return priv->name;
 }
 
+gboolean
+e_destination_is_ignored (const EDestination *dest)
+{
+	return dest->priv->ignored;
+}
+
+void
+e_destination_set_ignored (EDestination *dest, gboolean ignored)
+{
+	dest->priv->ignored = ignored;
+}
+
 /**
  * e_destination_get_email:
  * @dest: an #EDestination
@@ -850,7 +882,7 @@ e_destination_get_address (const EDestin
 			while (iter) {
 				EDestination *list_dest = E_DESTINATION (iter->data);
 				
-				if (!e_destination_empty (list_dest)) {
+				if (!e_destination_empty (list_dest) && !list_dest->priv->ignored) {
 					const char *name, *email;
 					name = e_destination_get_name (list_dest);
 					email = e_destination_get_email (list_dest);
Index: e-destination.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/addressbook/libebook/e-destination.h,v
retrieving revision 1.5
diff -u -p -r1.5 e-destination.h
--- e-destination.h	3 Mar 2005 15:13:58 -0000	1.5
+++ e-destination.h	31 Aug 2005 07:33:03 -0000
@@ -93,6 +93,8 @@ const char    *e_destination_get_address
 gboolean       e_destination_is_evolution_list   (const EDestination *);
 gboolean       e_destination_list_show_addresses (const EDestination *);
 const GList   *e_destination_list_get_dests      (const EDestination *);
+gboolean       e_destination_is_ignored  	 (const EDestination *dest);
+void           e_destination_set_ignored 	 (EDestination *view, gboolean ignored);
 
 /* If true, they want HTML mail. */
 void           e_destination_set_html_mail_pref (EDestination *dest, gboolean flag);
Index: e-name-selector-entry.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/libedataserverui/e-name-selector-entry.c,v
retrieving revision 1.24
diff -u -p -r1.24 e-name-selector-entry.c
--- e-name-selector-entry.c	24 Aug 2005 02:40:35 -0000	1.24
+++ e-name-selector-entry.c	31 Aug 2005 07:31:23 -0000
@@ -28,6 +28,7 @@
 #include <gtk/gtkcelllayout.h>
 #include <gtk/gtkcellrenderertext.h>
 #include <gtk/gtkmenuitem.h>
+#include <gtk/gtkradiomenuitem.h>
 #include <gtk/gtkseparatormenuitem.h>
 #include <glib/gi18n-lib.h>
 
@@ -1763,15 +1810,56 @@ popup_activate_email (ENameSelectorEntry
 }
 
 static void
+popup_activate_list (EDestination *destination, GtkWidget *item)
+{
+	gboolean status = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item));
+	
+	e_destination_set_ignored (destination, !status);	
+}
+
+static void
+destination_set_list (GtkWidget *item, EDestination *destination)
+{
+	EContact *contact;
+	gboolean status = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item));
+
+	contact = e_destination_get_contact (destination);
+	if (!contact)
+		return;
+	
+	e_destination_set_ignored (destination, !status);
+}
+
+static void
+destination_set_email (GtkWidget *item, EDestination *destination)
+{
+	int email_num;
+	EContact *contact;
+
+ 	if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item)))
+		return;
+	contact = e_destination_get_contact (destination);
+	if (!contact)
+		return;
+
+	email_num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "order"));
+	e_destination_set_contact (destination, contact, email_num);
+}
+
+static void
 populate_popup (ENameSelectorEntry *name_selector_entry, GtkMenu *menu)
 {
 	EDestination *destination;
 	EContact     *contact;
 	GtkWidget    *menu_item;
-	GList        *email_list;
+	GList        *email_list = NULL;
 	GList        *l;
 	gint          i;
 	char 	     *edit_label;
+	int 	      email_num, len;
+	GSList 	     *group = NULL;
+	gboolean      is_list;
+	gboolean      show_menu = FALSE;
 
 	destination = name_selector_entry->popup_destination;
 	if (!destination)
@@ -1788,29 +1876,74 @@ populate_popup (ENameSelectorEntry *name
 	menu_item = gtk_separator_menu_item_new ();
 	gtk_widget_show (menu_item);
 	gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
+	email_num = e_destination_get_email_num (destination);
 
 	/* Addresses */
+	is_list = e_contact_get (contact, E_CONTACT_IS_LIST) ? TRUE : FALSE;
+	if (is_list) {
+		const GList *dests = e_destination_list_get_dests (destination);
+		GList *iter;
+		int len = g_list_length ((GList *)dests);
+
+		for (iter = (GList *)dests; iter; iter = iter->next) {
+			EDestination *dest = (EDestination *) iter->data;
+			const char *email = e_destination_get_email (dest);
+			
+			if (!email || *email == '\0')
+				continue;	
+
+			if (len > 1) {
+				menu_item = gtk_check_menu_item_new_with_label (email);
+				g_signal_connect (menu_item, "toggled", G_CALLBACK (destination_set_list), dest);				
+			} else {
+				menu_item = gtk_menu_item_new_with_label (email);
+			}
+			
+			gtk_widget_show (menu_item);
+			gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
+			show_menu = TRUE;
+
+			if ( len > 1 ) {
+				gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), !e_destination_is_ignored(dest));
+				g_signal_connect_swapped (menu_item, "activate", G_CALLBACK (popup_activate_list),
+							  dest);	
+			}
+		}
+		
+	} else {
+		email_list = e_contact_get (contact, E_CONTACT_EMAIL);
+		len = g_list_length (email_list);
 
-	email_list = e_contact_get (contact, E_CONTACT_EMAIL);
-
-	for (l = email_list, i = 0; l; l = g_list_next (l), i++) {
-		gchar *email = l->data;
-
-		if (!email || *email == '\0')
-			continue;
+		for (l = email_list, i = 0; l; l = g_list_next (l), i++) {
+			gchar *email = l->data;
 
-		menu_item = gtk_menu_item_new_with_label (email);
-		gtk_widget_show (menu_item);
-		gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
-
-		g_object_set_data (G_OBJECT (menu_item), "order", GINT_TO_POINTER (i));
-		g_signal_connect_swapped (menu_item, "activate", G_CALLBACK (popup_activate_email),
-					  name_selector_entry);
+			if (!email || *email == '\0')
+				continue;
+		
+			if (len > 1) {
+				menu_item = gtk_radio_menu_item_new_with_label (group, email);
+				group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menu_item));
+				g_signal_connect (menu_item, "toggled", G_CALLBACK (destination_set_email), destination);
+			} else {
+				menu_item = gtk_menu_item_new_with_label (email);			
+			}
+			
+			gtk_widget_show (menu_item);
+			gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
+			show_menu = TRUE;
+			g_object_set_data (G_OBJECT (menu_item), "order", GINT_TO_POINTER (i));			
+
+			if ( i == email_num && len > 1 ) {
+				gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), TRUE);
+				g_signal_connect_swapped (menu_item, "activate", G_CALLBACK (popup_activate_email),
+							  name_selector_entry);
+			}
+		}
 	}
 
 	/* Separator */
 
-	if (email_list) {
+	if (show_menu) {
 		menu_item = gtk_separator_menu_item_new ();
 		gtk_widget_show (menu_item);
 		gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);


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