[evolution-patches] Autocompletion for contact list editor



Hi,

I have attached the patch. Please review it.

-Srini
? contact-list-editor.gladep
Index: contact-list-editor.glade
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/contact-list-editor/contact-list-editor.glade,v
retrieving revision 1.17
diff -u -p -r1.17 contact-list-editor.glade
--- contact-list-editor.glade	6 May 2005 06:13:33 -0000	1.17
+++ contact-list-editor.glade	30 Aug 2005 09:01:32 -0000
@@ -249,21 +249,17 @@
 		      </child>
 
 		      <child>
-			<widget class="GtkEntry" id="email-entry">
+			<widget class="Custom" id="email-entry">
 			  <property name="visible">True</property>
-			  <property name="can_focus">True</property>
-			  <property name="editable">True</property>
-			  <property name="visibility">True</property>
-			  <property name="max_length">0</property>
-			  <property name="text" translatable="yes"></property>
-			  <property name="has_frame">True</property>
-			  <property name="invisible_char" translatable="yes">*</property>
-			  <property name="activates_default">False</property>
+			  <property name="creation_function">e_contact_list_editor_create_name_selector</property>
+			  <property name="int1">0</property>
+			  <property name="int2">0</property>
+			  <property name="last_modification_time">Sat, 27 Aug 2005 13:47:20 GMT</property>
 			</widget>
 			<packing>
 			  <property name="padding">0</property>
-			  <property name="expand">False</property>
-			  <property name="fill">False</property>
+			  <property name="expand">True</property>
+			  <property name="fill">True</property>
 			</packing>
 		      </child>
 
Index: e-contact-list-editor.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/contact-list-editor/e-contact-list-editor.c,v
retrieving revision 1.72
diff -u -p -r1.72 e-contact-list-editor.c
--- e-contact-list-editor.c	24 Aug 2005 03:06:51 -0000	1.72
+++ e-contact-list-editor.c	30 Aug 2005 09:01:33 -0000
@@ -49,6 +49,7 @@
 #include "e-contact-list-model.h"
 #include "e-contact-list-editor-marshal.h"
 #include "eab-contact-merging.h"
+#include <gdk/gdkkeysyms.h>
 
 static void e_contact_list_editor_init		(EContactListEditor		 *editor);
 static void e_contact_list_editor_class_init	(EContactListEditorClass	 *klass);
@@ -76,6 +77,8 @@ static void list_name_changed_cb (GtkWid
 static void list_image_changed_cb (GtkWidget *w, EContactListEditor *editor);
 static void visible_addrs_toggled_cb (GtkWidget *w, EContactListEditor *editor);
 static void source_selected (GtkWidget *source_option_menu, ESource *source, EContactListEditor *editor);
+static gboolean email_key_pressed (GtkWidget *w, GdkEventKey *event, EContactListEditor *editor);
+static void email_match_selected (GtkWidget *w, EDestination *destination, EContactListEditor *editor);
 
 static void close_cb (GtkWidget *widget, EContactListEditor *editor);
 static void save_and_close_cb (GtkWidget *widget, EContactListEditor *editor);
@@ -232,6 +235,8 @@ e_contact_list_editor_init (EContactList
 			  "clicked", G_CALLBACK(add_email_cb), editor);
 	g_signal_connect (editor->email_entry,
 			  "activate", G_CALLBACK(add_email_cb), editor);
+	g_signal_connect ((ENameSelectorEntry *)editor->email_entry,
+			  "updated", G_CALLBACK(email_match_selected), editor);
 	g_signal_connect (editor->remove_button,
 			  "clicked", G_CALLBACK(remove_entry_cb), editor);
 	g_signal_connect (editor->select_button,
@@ -240,6 +245,8 @@ e_contact_list_editor_init (EContactList
 			  "changed", G_CALLBACK(list_name_changed_cb), editor);
 	g_signal_connect (editor->visible_addrs_checkbutton,
 			  "toggled", G_CALLBACK(visible_addrs_toggled_cb), editor);
+	g_signal_connect (editor->email_entry, 
+	 		  "key-press-event", G_CALLBACK(email_key_pressed), editor);
 
 	e_table_drag_dest_set (e_table_scrolled_get_table (E_TABLE_SCROLLED (editor->table)),
 			       0, list_drag_types, num_list_drag_types, GDK_ACTION_LINK);
@@ -299,6 +306,8 @@ new_target_cb (EBook *new_book, EBookSta
 		return;
 	}
 
+	e_contact_store_add_book (((ENameSelectorEntry *)editor->email_entry)->contact_store, new_book);
+
 	g_object_set (editor, "book", new_book, NULL);
 	g_object_unref (new_book);
 }
@@ -767,6 +776,32 @@ e_contact_list_editor_create_source_opti
 	return menu;
 }
 
+GtkWidget *
+e_contact_list_editor_create_name_selector (gchar *name,
+						 gchar *string1, gchar *string2,
+						 gint int1, gint int2);
+
+GtkWidget *
+e_contact_list_editor_create_name_selector (gchar *name,
+						 gchar *string1, gchar *string2,
+						 gint int1, gint int2)
+{
+	ENameSelectorModel *name_selector_model;
+	ENameSelectorEntry *name_selector_entry;
+	ENameSelector *name_selector = e_name_selector_new ();
+
+	name_selector_model = e_name_selector_peek_model (name_selector);
+	e_name_selector_model_add_section (name_selector_model, "Members", "Members", NULL);
+	
+	name_selector_entry = e_name_selector_peek_section_entry (name_selector, "Members");
+
+	e_name_selector_entry_set_contact_editor_func (name_selector_entry, e_contact_editor_new);
+	e_name_selector_entry_set_contact_list_editor_func (name_selector_entry, e_contact_list_editor_new);
+	gtk_widget_show (GTK_WIDGET (name_selector_entry));
+	
+	return (GtkWidget *)name_selector_entry;
+}
+
 static void
 add_email_cb (GtkWidget *w, EContactListEditor *editor)
 {
@@ -789,6 +824,32 @@ add_email_cb (GtkWidget *w, EContactList
 }
 
 static void
+email_match_selected (GtkWidget *w, EDestination *destination, EContactListEditor *editor)
+{
+	char *email;
+	EDestinationStore *store;
+	GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (editor->table));
+	
+	email = g_strdup(e_destination_get_address (destination));
+	store = e_name_selector_entry_peek_destination_store ((ENameSelectorEntry *)w);
+	e_destination_store_remove_destination (store, destination);
+	gtk_entry_set_text (GTK_ENTRY(editor->email_entry), "");	
+	
+	if (email && *email) {
+		e_contact_list_model_add_email (E_CONTACT_LIST_MODEL(editor->model), email);
+
+		/* Skip to the end of the list */
+		if (adj->upper - adj->lower > adj->page_size)
+			gtk_adjustment_set_value (adj, adj->upper);
+		
+		editor->changed = TRUE;
+	}
+
+	g_free (email);
+	command_state_changed (editor);
+}
+
+static void
 prepend_selected_rows (int model_row, GList **list)
 {
 	int *idx = g_new (int, 1);
@@ -855,6 +916,22 @@ visible_addrs_toggled_cb (GtkWidget *w, 
 	command_state_changed (editor);
 }
 
+static gboolean
+email_key_pressed (GtkWidget *w, GdkEventKey *event, EContactListEditor *editor)
+{
+
+        if (event->keyval == GDK_comma || event->keyval == GDK_Return) {
+		ENameSelectorEntry *entry = (ENameSelectorEntry *)w;
+		
+		g_signal_emit_by_name (entry, "activate", 0);
+		add_email_cb (w, editor);
+
+                return TRUE;
+        }
+
+	return FALSE;
+}
+
 static void
 set_editable (EContactListEditor *editor)
 {
@@ -1138,6 +1215,7 @@ fill_in_info(EContactListEditor *editor)
 
 		source = e_book_get_source (editor->book);		
 		e_source_option_menu_select (E_SOURCE_OPTION_MENU (editor->source_menu), source);
+		e_contact_store_add_book (((ENameSelectorEntry *)editor->email_entry)->contact_store, editor->book);
 		gtk_widget_set_sensitive (editor->source_menu, editor->is_new_list);
 		gtk_widget_set_sensitive (glade_xml_get_widget (editor->gui, "source-label"), editor->is_new_list);
 	}
? .e-name-selector-entry.c.swp
? bk
? test-contact-store
? test-name-selector
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/evolution-data-server/libedataserverui/Makefile.am,v
retrieving revision 1.13
diff -u -p -r1.13 Makefile.am
--- Makefile.am	13 Aug 2005 02:29:01 -0000	1.13
+++ Makefile.am	30 Aug 2005 08:36:03 -0000
@@ -35,11 +35,10 @@ libedataserverui_1_2_la_SOURCES =	\
 
 libedataserverui_1_2_la_LIBADD = 				\
 	$(top_builddir)/addressbook/libebook/libebook-1.2.la	\
-	$(top_builddir)/libedataserver/libedataserver-1.2.la	\
-	$(E_DATA_SERVER_UI_LIBS)
+	$(E_DATA_SERVER_LIBS)
 
 libedataserverui_1_2_la_LDFLAGS = 										\
-	-version-info $(LIBEDATASERVERUI_CURRENT):$(LIBEDATASERVERUI_REVISION):$(LIBEDATASERVERUI_AGE) $(NO_UNDEFINED)
+	-version-info $(LIBEDATASERVERUI_CURRENT):$(LIBEDATASERVERUI_REVISION):$(LIBEDATASERVERUI_AGE) 
 
 libedataserveruiincludedir = $(privincludedir)/libedataserverui
 
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	30 Aug 2005 08:36:05 -0000
@@ -36,9 +36,15 @@
 #include <libebook/e-destination.h>
 #include <libedataserverui/e-book-auth-util.h>
 #include <libedataserver/e-sexp.h>
-
+#include <libedataserverui/e-data-server-ui-marshal.h>
 #include "e-name-selector-entry.h"
 
+enum {
+	UPDATED,
+	LAST_SIGNAL
+};
+static guint signals[LAST_SIGNAL] = { 0 };
+
 #define ENS_DEBUG(x)
 
 #define COMPLETION_CUE_MIN_LEN 3
@@ -100,6 +106,12 @@ e_name_selector_entry_finalize (GObject 
 }
 
 static void
+e_name_selector_entry_updated (ENameSelectorEntry *entry, char *email)
+{
+	g_return_if_fail (E_IS_NAME_SELECTOR_ENTRY (entry));
+}
+
+static void
 e_name_selector_entry_class_init (ENameSelectorEntryClass *name_selector_entry_class)
 {
 	GObjectClass   *object_class = G_OBJECT_CLASS (name_selector_entry_class);
@@ -109,6 +121,7 @@ e_name_selector_entry_class_init (ENameS
 	object_class->set_property = e_name_selector_entry_set_property;
 	object_class->dispose      = e_name_selector_entry_dispose;
 	object_class->finalize     = e_name_selector_entry_finalize;
+	name_selector_entry_class->updated	   = e_name_selector_entry_updated;
 
 	widget_class->realize      = e_name_selector_entry_realize;
 
@@ -116,6 +129,15 @@ e_name_selector_entry_class_init (ENameS
 
 	/* Install signals */
 
+	signals[UPDATED] = g_signal_new ("updated",
+					 E_TYPE_NAME_SELECTOR_ENTRY,
+					 G_SIGNAL_RUN_FIRST,
+					 G_STRUCT_OFFSET (ENameSelectorEntryClass, updated),
+					 NULL,
+					 NULL,
+					 e_data_server_ui_marshal_VOID__POINTER,
+					 G_TYPE_NONE, 1, G_TYPE_POINTER);
+
 }
 
 /* Remove unquoted commas from string */
@@ -1241,6 +1263,8 @@ completion_match_selected (ENameSelector
 	/* Place cursor at end of address */
 
 	gtk_editable_set_position (GTK_EDITABLE (name_selector_entry), cursor_pos);
+	g_signal_emit (name_selector_entry, signals[UPDATED], 0, destination, NULL);
+	
 	return TRUE;
 }
 
@@ -1249,18 +1273,40 @@ entry_activate (ENameSelectorEntry *name
 {
 	gint         cursor_pos;
 	gint         range_start, range_end;
-	const gchar *text;
+	EContact      *contact;
+	EContactField  matched_field;
+	EDestination  *destination;
+	gchar         *textrep;
+	gint           range_len;
+	const gchar   *text;
+	gchar         *cue_str;
+	
+	cursor_pos = gtk_editable_get_position (GTK_EDITABLE (name_selector_entry));
+	if (cursor_pos < 0)
+		return;
 
-	/* Show us what's really there */
+	text = gtk_entry_get_text (GTK_ENTRY (name_selector_entry));
+	get_range_at_position (text, cursor_pos, &range_start, &range_end);
+	range_len = range_end - range_start;
+	if (range_len < COMPLETION_CUE_MIN_LEN)
+		return;
 
-	cursor_pos = gtk_editable_get_position (GTK_EDITABLE (name_selector_entry));
+	destination = find_destination_at_position (name_selector_entry, cursor_pos);
+
+	cue_str = get_entry_substring (name_selector_entry, range_start, range_end);
+	if (!find_existing_completion (name_selector_entry, cue_str, &contact,
+				       &textrep, &matched_field)) {
+		g_free (cue_str);
+		return;
+	}
+	g_free (cue_str);	
+
+	/* Show us what's really there */
 	sync_destination_at_position (name_selector_entry, cursor_pos, &cursor_pos);
 
 	/* Place cursor at end of address */
-
-	text = gtk_entry_get_text (GTK_ENTRY (name_selector_entry));
-	get_range_at_position (text, cursor_pos, &range_start, &range_end);
 	gtk_editable_set_position (GTK_EDITABLE (name_selector_entry), range_end);
+	g_signal_emit (name_selector_entry, signals[UPDATED], 0, destination, NULL);
 }
 
 static gboolean
Index: e-name-selector-entry.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/libedataserverui/e-name-selector-entry.h,v
retrieving revision 1.6
diff -u -p -r1.6 e-name-selector-entry.h
--- e-name-selector-entry.h	24 Aug 2005 02:40:35 -0000	1.6
+++ e-name-selector-entry.h	30 Aug 2005 08:36:06 -0000
@@ -44,6 +44,7 @@ typedef struct ENameSelectorEntryClass E
 
 struct ENameSelectorEntryClass {
 	GtkEntryClass parent_class;
+	void (*updated) (ENameSelectorEntry *entry, char *email);	
 };
 
 struct ENameSelectorEntry {


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