[evolution-patches] fix for addressbook 61365 and some other misc source editor issues



Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/ChangeLog,v
retrieving revision 1.1799
diff -u -r1.1799 ChangeLog
--- ChangeLog	22 Jul 2004 13:18:40 -0000	1.1799
+++ ChangeLog	22 Jul 2004 22:57:35 -0000
@@ -1,3 +1,39 @@
+2004-07-22  Chris Toshok  <toshok ximian com>
+
+	[ fixes #61365 and other misc issues with the addressbook source
+	editors ]
+	
+	* gui/component/ldap-config.glade: change the
+	supported-bases-dialog to be initially hidden.
+
+	* gui/component/addressbook-view.c (editor_weak_notify): new
+	function, remove the editor from our hash.
+	(source_list_changed_cb): destroy the editors for given sources if
+	they're up when the source disappears.
+	(edit_addressbook_cb): add the editor (and some other misc info we
+	need) to our uid_to_editor hash so we can look it up later.  only
+	create the editor if one doesn't exist for the given source.
+	(destroy_editor): GHFunc that destroys the widgets.
+	(addressbook_view_dispose): destroy uid_to_editor.
+	(addressbook_view_init): init uid_to_editor.
+
+	* gui/component/addressbook-config.h: change return values for
+	_edit_source and _new_source - they both return GtkWidget*s now.
+
+	* gui/component/addressbook-config.c (addressbook_ldap_init):
+	attempt set the protocol version to LDAPv3.  This makes the
+	ldap_auth stuff work if the server requires v3.
+	(addressbook_root_dse_query): we don't need the separate window
+	arg, since all of this now happens *before* the supported bases
+	dialog is shown.  we just use the source dialog's window for the
+	various error dialogs.
+	(do_ldap_root_dse_query): same.
+	(query_for_supported_bases): same, and set the supported bases
+	dialog as transient-for the source dialog, and make it modal.
+	Lastly, don't make the editor modal.
+	(addressbook_config_edit_source): return the editor's window.
+	(addressbook_config_create_new_source): same.
+
 2004-07-19  Radek Doulik  <rodo ximian com>
 
 	* gui/widgets/eab-vcard-control.c (eab_vcard_control_new): but
Index: gui/component/ldap-config.glade
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/ldap-config.glade,v
retrieving revision 1.29
diff -u -r1.29 ldap-config.glade
--- gui/component/ldap-config.glade	22 Jul 2004 02:12:34 -0000	1.29
+++ gui/component/ldap-config.glade	22 Jul 2004 22:57:35 -0000
@@ -2578,7 +2578,6 @@
 </widget>
 
 <widget class="GtkDialog" id="supported-bases-dialog">
-  <property name="visible">True</property>
   <property name="title" translatable="yes">Supported Search Bases</property>
   <property name="type">GTK_WINDOW_TOPLEVEL</property>
   <property name="window_position">GTK_WIN_POS_CENTER</property>
Index: gui/component/addressbook-view.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/addressbook-view.c,v
retrieving revision 1.14
diff -u -r1.14 addressbook-view.c
--- gui/component/addressbook-view.c	23 Jun 2004 22:40:24 -0000	1.14
+++ gui/component/addressbook-view.c	22 Jul 2004 22:57:35 -0000
@@ -84,6 +84,8 @@
 	GConfClient *gconf_client;
 
 	GHashTable *uid_to_view;
+	GHashTable *uid_to_editor;
+
 	EBook *book;
 	guint activity_id;
 	ESourceList *source_list;
@@ -112,6 +114,22 @@
 static void addressbook_view_class_init	(AddressbookViewClass *klass);
 static void addressbook_view_dispose    (GObject *object);
 
+typedef struct {
+	GtkWidget *editor;
+	char *uid;
+	AddressbookView *view;
+} EditorUidClosure;
+
+static void
+editor_weak_notify (gpointer data, GObject *o)
+{
+	EditorUidClosure *closure = data;
+	AddressbookViewPrivate *priv = closure->view->priv;
+
+	g_hash_table_remove (priv->uid_to_editor,
+			     closure->uid);
+}
+
 static EABView *
 get_current_view (AddressbookView *view)
 {
@@ -469,15 +487,14 @@
 
 	uids = NULL;
 	g_hash_table_foreach (priv->uid_to_view, (GHFunc)gather_uids_foreach, &uids);
-
 	for (l = uids; l; l = l->next) {
 		char *uid = l->data;
 		if (e_source_list_peek_source_by_uid (source_list, uid)) {
 			/* the source still exists, do nothing */
 		}
 		else {
-			/* the source no longer exists, remove the
-			   view and remove it from our hash table. */
+			/* the source no longer exists, remove its
+			   view remove it from our hash table. */
 			v = g_hash_table_lookup (priv->uid_to_view,
 						 uid);
 			g_hash_table_remove (priv->uid_to_view, uid);
@@ -487,6 +504,27 @@
 			g_object_unref (v);
 		}
 	}
+	g_list_free (uids);
+
+	uids = NULL;
+	g_hash_table_foreach (priv->uid_to_editor, (GHFunc)gather_uids_foreach, &uids);
+	for (l = uids; l; l = l->next) {
+		char *uid = l->data;
+		if (e_source_list_peek_source_by_uid (source_list, uid)) {
+			/* the source still exists, do nothing */
+		}
+		else {
+			/* the source no longer exists, remove its
+			   editor remove it from our hash table. */
+			EditorUidClosure *closure = g_hash_table_lookup (priv->uid_to_editor,
+									 uid);
+			g_object_weak_unref (G_OBJECT (closure->editor),
+					     editor_weak_notify, closure);
+			gtk_widget_destroy (closure->editor);
+			g_hash_table_remove (priv->uid_to_editor, uid);
+		}
+	}
+	g_list_free (uids);
 
 	/* make sure we've got the current view selected and updated
 	   properly */
@@ -676,13 +714,34 @@
 {
 	AddressbookViewPrivate *priv = view->priv;
 	ESource *selected_source;
+	const char *uid;;
+	EditorUidClosure *closure;
 
 	selected_source =
 		e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (priv->selector));
 	if (!selected_source)
 		return;
 
-	addressbook_config_edit_source (gtk_widget_get_toplevel (widget), selected_source);
+	uid = e_source_peek_uid (selected_source);
+
+	closure = g_hash_table_lookup (priv->uid_to_editor, uid);
+	if (!closure) {
+		char *uid_copy = g_strdup (uid);
+
+		closure = g_new (EditorUidClosure, 1);
+		closure->editor = addressbook_config_edit_source (gtk_widget_get_toplevel (widget), selected_source);
+		closure->uid = uid_copy;
+		closure->view = view;
+
+		g_hash_table_insert (priv->uid_to_editor,
+				     uid_copy,
+				     closure);
+
+		g_object_weak_ref (G_OBJECT (closure->editor),
+				   editor_weak_notify, closure);
+	}
+
+	gtk_window_present (GTK_WINDOW (closure->editor));
 }
 
 /* Callbacks.  */
@@ -1010,6 +1069,7 @@
 	priv->gconf_client = addressbook_component_peek_gconf_client (addressbook_component_peek ());
 
 	priv->uid_to_view = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL);
+	priv->uid_to_editor = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free);
 
 	priv->notebook = gtk_notebook_new ();
 	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
@@ -1079,6 +1139,19 @@
 }
 
 static void
+destroy_editor (char *key,
+		gpointer value,
+		gpointer nada)
+{
+	EditorUidClosure *closure = value;
+
+	g_object_weak_unref (G_OBJECT (closure->editor),
+			     editor_weak_notify, closure);
+
+	gtk_widget_destroy (GTK_WIDGET (closure->editor));
+}
+
+static void
 addressbook_view_dispose (GObject *object)
 {
 	AddressbookView *view = ADDRESSBOOK_VIEW (object);
@@ -1095,6 +1168,11 @@
 
 		if (priv->uid_to_view)
 			g_hash_table_destroy (priv->uid_to_view);
+
+		if (priv->uid_to_editor) {
+			g_hash_table_foreach (priv->uid_to_editor, (GHFunc)destroy_editor, NULL);
+			g_hash_table_destroy (priv->uid_to_editor);
+		}
 
 		if (priv->creatable_items_handler)
 			g_object_unref (priv->creatable_items_handler);
Index: gui/component/addressbook-config.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/addressbook-config.c,v
retrieving revision 1.85
diff -u -r1.85 addressbook-config.c
--- gui/component/addressbook-config.c	21 Jun 2004 21:49:01 -0000	1.85
+++ gui/component/addressbook-config.c	22 Jul 2004 22:57:35 -0000
@@ -393,15 +393,24 @@
 	LDAP  *ldap;
 	gchar *host;
 	gint   port;
+	int ldap_error;
+	int protocol_version = LDAP_VERSION3;
 
 	if (!source_to_uri_parts (source, &host, NULL, NULL, &port))
 		return NULL;
 
-	if (!(ldap = ldap_init (host, port)))
+	if (!(ldap = ldap_init (host, port))) {
 		e_error_run ((GtkWindow *) window, "addressbook:ldap-init", NULL);
+		goto done;
+	}
+
+	ldap_error = ldap_set_option (ldap, LDAP_OPT_PROTOCOL_VERSION, &protocol_version);
+	if (LDAP_OPT_SUCCESS != ldap_error)
+		g_warning ("failed to set protocol version to LDAPv3");
 
 	/* XXX do TLS if it's configured in */
 
+ done:
 	g_free (host);
 	return ldap;
 }
@@ -420,7 +429,7 @@
 }
 
 static int
-addressbook_root_dse_query (AddressbookSourceDialog *dialog, GtkWindow *window, LDAP *ldap,
+addressbook_root_dse_query (AddressbookSourceDialog *dialog, LDAP *ldap,
 			    char **attrs, LDAPMessage **resp)
 {
 	int ldap_error;
@@ -434,7 +443,7 @@
 					"(objectclass=*)",
 					attrs, 0, NULL, NULL, &timeout, LDAP_NO_LIMIT, resp);
 	if (LDAP_SUCCESS != ldap_error)
-		e_error_run ((GtkWindow *) window, "addressbook:ldap-search-base", NULL);
+		e_error_run (GTK_WINDOW (dialog->window), "addressbook:ldap-search-base", NULL);
 	
 	return ldap_error;
 }
@@ -635,7 +644,7 @@
 }
 
 static gboolean
-do_ldap_root_dse_query (AddressbookSourceDialog *sdialog, GtkWidget *dialog, ETableModel *model, ESource *source, char ***rvalues)
+do_ldap_root_dse_query (AddressbookSourceDialog *sdialog, ETableModel *model, ESource *source, char ***rvalues)
 {
 	LDAP *ldap;
 	char *attrs[2];
@@ -644,24 +653,24 @@
 	LDAPMessage *resp;
 	int i;
 
-	ldap = addressbook_ldap_init (dialog, source);
+	ldap = addressbook_ldap_init (sdialog->window, source);
 	if (!ldap)
 		return FALSE;
 
-	if (LDAP_SUCCESS != addressbook_ldap_auth (dialog, ldap))
+	if (LDAP_SUCCESS != addressbook_ldap_auth (sdialog->window, ldap))
 		goto fail;
 
 	attrs[0] = "namingContexts";
 	attrs[1] = NULL;
 
-	ldap_error = addressbook_root_dse_query (sdialog, GTK_WINDOW (dialog), ldap, attrs, &resp);
+	ldap_error = addressbook_root_dse_query (sdialog, ldap, attrs, &resp);
 
 	if (ldap_error != LDAP_SUCCESS)
 		goto fail;
 
 	values = ldap_get_values (ldap, resp, "namingContexts");
 	if (!values || values[0] == NULL) {
-		e_error_run ((GtkWindow *) dialog, "addressbook:ldap-search-base", NULL);
+		e_error_run (GTK_WINDOW (sdialog->window), "addressbook:ldap-search-base", NULL);
 		goto fail;
 	}
 
@@ -704,6 +713,9 @@
 	gui = glade_xml_new (EVOLUTION_GLADEDIR "/" GLADE_FILE_NAME, "supported-bases-dialog", NULL);
 	dialog = glade_xml_get_widget (gui, "supported-bases-dialog");
 
+	gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (sdialog->window));
+	gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+
 	gtk_widget_realize (dialog);
 	gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 0);
 	gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 12);
@@ -718,7 +730,9 @@
 
 	search_base_selection_model_changed (selection_model, dialog);
 
-	if (do_ldap_root_dse_query (sdialog, dialog, model, source, &values)) {
+	if (do_ldap_root_dse_query (sdialog, model, source, &values)) {
+		gtk_widget_show (dialog);
+
 		id = gtk_dialog_run (GTK_DIALOG (dialog));
 
 		gtk_widget_hide (dialog);
@@ -741,6 +755,8 @@
 		e_table_memory_store_clear (E_TABLE_MEMORY_STORE (model));
 	}
 
+	gtk_widget_destroy (dialog);
+
 	g_object_unref (source);
 }
 
@@ -974,7 +990,6 @@
 	source_to_dialog (sdialog);
 
 	gtk_window_set_type_hint (GTK_WINDOW (sdialog->window), GDK_WINDOW_TYPE_HINT_DIALOG);
-	gtk_window_set_modal (GTK_WINDOW (sdialog->window), TRUE);
 	
 	add_folder_modify (sdialog->window, sdialog);
 
@@ -1181,7 +1196,7 @@
 	}
 }
 
-void
+GtkWidget*
 addressbook_config_edit_source (GtkWidget *parent, ESource *source)
 {
 	AddressbookSourceDialog *sdialog = g_new0 (AddressbookSourceDialog, 1);
@@ -1249,15 +1264,17 @@
 
 	gtk_widget_set_sensitive (sdialog->ok_button, FALSE);
 
-	gtk_window_set_modal (GTK_WINDOW (sdialog->window), TRUE);
-
 	gtk_widget_show (sdialog->window);
+
+	return sdialog->window;
 }
 
-void
+GtkWidget*
 addressbook_config_create_new_source (GtkWidget *parent)
 {
 	AddressbookSourceDialog *dialog;
 
 	dialog = addressbook_add_server_dialog ();
+
+	return dialog->window;
 }
Index: gui/component/addressbook-config.h
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/addressbook-config.h,v
retrieving revision 1.16
diff -u -r1.16 addressbook-config.h
--- gui/component/addressbook-config.h	22 Jul 2004 02:12:34 -0000	1.16
+++ gui/component/addressbook-config.h	22 Jul 2004 22:57:36 -0000
@@ -46,7 +46,7 @@
 	ADDRESSBOOK_LDAP_SSL_NEVER
 } AddressbookLDAPSSLType;
 
-void  addressbook_config_edit_source        (GtkWidget *parent, ESource *source);
-void  addressbook_config_create_new_source  (GtkWidget  *parent);
+GtkWidget* addressbook_config_edit_source        (GtkWidget *parent, ESource *source);
+GtkWidget* addressbook_config_create_new_source  (GtkWidget *parent);
 
 #endif /* __ADDRESSBOOK_CONFIG_H__ */


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