[evolution-patches] Addressbook contact editor simplification patch



While debugging something else, I found a way to simplify the contact
editor writeability code and eliminate a runtime warning.

--
Hans Petter
? 57795.patch
? 58921.patch
? birthdate.patch
? contact-editor.patch
? log.diff
? out.diff
? gui/component/ldap-config.gladep
? gui/component/old
? gui/component/out
? gui/component/select-names/crap
? gui/contact-editor/hpj-contact-editor.glade
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/ChangeLog,v
retrieving revision 1.1793
diff -u -p -r1.1793 ChangeLog
--- ChangeLog	16 Jul 2004 08:13:51 -0000	1.1793
+++ ChangeLog	16 Jul 2004 20:15:22 -0000
@@ -1,3 +1,23 @@
+2004-07-16  Hans Petter Jansson  <hpj ximian com>
+
+	* gui/contact-editor/e-contact-editor.c (contact_added_cb)
+	(save_contact)
+	(app_delete_event_cb): Check source book writeability directly instead
+	of relying on stored state.
+	(e_contact_editor_init): Don't init source_editable.
+	(e_contact_editor_dispose): We don't listen for source writeability
+	anymore.
+	(writable_changed): Source writeability doesn't affect widget
+	status; remove code to check for it.
+	(e_contact_editor_set_property): Do nothing if book being set is
+	the same as currently set book; previously we would end up
+	unreffing then reffing it. Don't watch for source writeability, but
+	do so for target; fixes a warning. Only call sensitize_all() if
+	writeability on target changed.
+
+	* gui/contact-editor/e-contact-editor.h (EContactEditor): We don't
+	need the source_editable and source_editable_id vars anymore.
+
 2004-07-14  Chris Toshok  <toshok ximian com>
 
 	[ fixes #60873, and possibly other crashes ]
Index: gui/contact-editor/e-contact-editor.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/contact-editor/e-contact-editor.c,v
retrieving revision 1.211
diff -u -p -r1.211 e-contact-editor.c
--- gui/contact-editor/e-contact-editor.c	30 Jun 2004 15:32:37 -0000	1.211
+++ gui/contact-editor/e-contact-editor.c	16 Jul 2004 20:15:23 -0000
@@ -2580,7 +2580,7 @@ contact_added_cb (EBook *book, EBookStat
 	EContactEditor *ce = ecs->ce;
 	gboolean should_close = ecs->should_close;
 
-	if (ce->source_book != ce->target_book && ce->source_editable &&
+	if (ce->source_book != ce->target_book && e_book_is_writable (ce->source_book) &&
 	    status == E_BOOK_ERROR_OK && ce->is_new_contact == FALSE) {
 		ecs->new_id = g_strdup (id);
 		e_book_async_remove_contact (ce->source_book, ce->contact,
@@ -2675,7 +2675,7 @@ save_contact (EContactEditor *ce, gboole
 	if (!e_contact_editor_is_valid (EAB_EDITOR (ce)))
 		return;
 
-	if (ce->target_editable && !ce->source_editable) {
+	if (ce->target_editable && !e_book_is_writable (ce->source_book)) {
 		if (e_error_run (GTK_WINDOW (ce->app), "addressbook:prompt-move", NULL) == GTK_RESPONSE_NO)
 			return;
 	}
@@ -2811,7 +2811,7 @@ app_delete_event_cb (GtkWidget *widget, 
 		if (response != GTK_RESPONSE_YES)
 			return TRUE;
 	}
-	else if (!ce->source_editable) {
+	else if (!e_book_is_writable (ce->source_book)) {
 		GtkWidget *dialog;
 		gint       response;
 
@@ -2922,7 +2922,6 @@ e_contact_editor_init (EContactEditor *e
 	e_contact_editor->changed = FALSE;
 	e_contact_editor->image_set = FALSE;
 	e_contact_editor->in_async_call = FALSE;
-	e_contact_editor->source_editable = TRUE;
 	e_contact_editor->target_editable = TRUE;
 
 	e_contact_editor->load_source_id = 0;
@@ -2999,7 +2998,6 @@ e_contact_editor_dispose (GObject *objec
 	}
 	
 	if (e_contact_editor->source_book) {
-		g_signal_handler_disconnect (e_contact_editor->source_book, e_contact_editor->source_editable_id);
 		g_object_unref(e_contact_editor->source_book);
 		e_contact_editor->source_book = NULL;
 	}
@@ -3083,19 +3081,14 @@ e_contact_editor_new (EBook *book,
 static void
 writable_changed (EBook *book, gboolean writable, EContactEditor *ce)
 {
-	int new_source_editable, new_target_editable;
+	int new_target_editable;
 	gboolean changed = FALSE;
 
-	new_source_editable = e_book_is_writable (ce->source_book);
 	new_target_editable = e_book_is_writable (ce->target_book);
 
-	if (ce->source_editable != new_source_editable)
-		changed = TRUE;
-
 	if (ce->target_editable != new_target_editable)
 		changed = TRUE;
 
-	ce->source_editable = new_source_editable;
 	ce->target_editable = new_target_editable;
 
 	if (changed)
@@ -3111,62 +3104,80 @@ e_contact_editor_set_property (GObject *
 	
 	switch (prop_id){
 	case PROP_SOURCE_BOOK: {
-		gboolean writable;
-		gboolean changed = FALSE;
+		gboolean  writable;
+		gboolean  changed = FALSE;
+		EBook    *source_book;
+
+		source_book = E_BOOK (g_value_get_object (value));
+
+		if (source_book == editor->source_book)
+			break;
 
-		if (editor->source_book) {
-			g_signal_handler_disconnect (editor->source_book, editor->source_editable_id);
+		if (editor->source_book)
 			g_object_unref(editor->source_book);
-		}
-		editor->source_book = E_BOOK (g_value_get_object (value));
+
+		editor->source_book = source_book;
 		g_object_ref (editor->source_book);
-		editor->source_editable_id = g_signal_connect (editor->source_book, "writable_status",
-							       G_CALLBACK (writable_changed), editor);
  
 		if (!editor->target_book) {
 			editor->target_book = editor->source_book;
 			g_object_ref (editor->target_book);
 
+			editor->target_editable_id = g_signal_connect (editor->target_book, "writable_status",
+								       G_CALLBACK (writable_changed), editor);
+
 			e_book_async_get_supported_fields (editor->target_book,
 							   (EBookEListCallback) supported_fields_cb, editor);
 		}
 
-		writable = e_book_is_writable (editor->source_book);
-		if (writable != editor->source_editable) {
-			editor->source_editable = writable;
-			changed = TRUE;
-		}
-
 		writable = e_book_is_writable (editor->target_book);
 		if (writable != editor->target_editable) {
 			editor->target_editable = writable;
 			changed = TRUE;
 		}
 
-		if (changed) {
+		if (changed)
 			sensitize_all (editor);
-		}
+
 		break;
 	}
 
 	case PROP_TARGET_BOOK: {
+		gboolean  writable;
+		gboolean  changed = FALSE;
+		EBook    *target_book;
+
+		target_book = E_BOOK (g_value_get_object (value));
+
+		if (target_book == editor->target_book)
+			break;
+
 		if (editor->target_book) {
 			g_signal_handler_disconnect (editor->target_book, editor->target_editable_id);
 			g_object_unref(editor->target_book);
 		}
-		editor->target_book = E_BOOK (g_value_get_object (value));
+
+		editor->target_book = target_book;
 		g_object_ref (editor->target_book);
+
 		editor->target_editable_id = g_signal_connect (editor->target_book, "writable_status",
 							       G_CALLBACK (writable_changed), editor);
 
 		e_book_async_get_supported_fields (editor->target_book,
 						   (EBookEListCallback) supported_fields_cb, editor);
 
-		if (!editor->changed && !editor->is_new_contact)
+		if (!editor->is_new_contact)
 			editor->changed = TRUE;
 
-		editor->target_editable = e_book_is_writable (editor->target_book);
-		sensitize_all (editor);
+		writable = e_book_is_writable (editor->target_book);
+
+		if (writable != editor->target_editable) {
+			editor->target_editable = writable;
+			changed = TRUE;
+		}
+
+		if (changed)
+			sensitize_all (editor);
 
 		/* If we're trying to load a new target book, cancel that here. */
 		cancel_load (editor);
@@ -3209,11 +3220,13 @@ e_contact_editor_set_property (GObject *
 	case PROP_WRITABLE_FIELDS:
 		if (editor->writable_fields)
 			g_object_unref(editor->writable_fields);
+
 		editor->writable_fields = g_value_get_object (value);
 		if (editor->writable_fields)
 			g_object_ref (editor->writable_fields);
 		else
 			editor->writable_fields = e_list_new(NULL, NULL, NULL);
+
 		sensitize_all (editor);
 		break;
 	default:
Index: gui/contact-editor/e-contact-editor.h
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/contact-editor/e-contact-editor.h,v
retrieving revision 1.48
diff -u -p -r1.48 e-contact-editor.h
--- gui/contact-editor/e-contact-editor.h	30 Jun 2004 15:32:37 -0000	1.48
+++ gui/contact-editor/e-contact-editor.h	16 Jul 2004 20:15:23 -0000
@@ -82,9 +82,6 @@ struct _EContactEditor
 	/* Whether the contact has been changed since bringing up the contact editor */
 	guint changed : 1;
 
-	/* Whether the contact editor will accept delete */
-	guint source_editable : 1;
-
 	/* Whether the contact editor will accept modifications, save */
 	guint target_editable : 1;
 
@@ -98,7 +95,6 @@ struct _EContactEditor
 	EBook *load_book;
 
 	/* signal ids for "writable_status" */
-	int source_editable_id;
 	int target_editable_id;
 };
 


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