Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 1aa76bfd6288ccc30327662ddd60e0c0 > files > 11

evolution-2.12.3-19.el5.src.rpm

--- evolution-2.12.3/addressbook/addressbook.error.xml.addr-quick-add	2009-03-12 16:16:16.000000000 +0100
+++ evolution-2.12.3/addressbook/addressbook.error.xml	2009-03-12 16:16:43.000000000 +0100
@@ -118,4 +118,10 @@
   <_secondary>Permission Denied.</_secondary>
  </error>
 
+ <error id="error-read-only" type="error" default="GTK_RESPONSE_YES">
+  <_primary>Cannot add new contact</_primary>
+  <_secondary>The address book {0} is read only, thus you cannot add contacts there. Select other address book, please.</_secondary>
+  <button stock ="gtk-ok" response="GTK_RESPONSE_YES"/>
+ </error>
+
 </error-list>
--- evolution-2.12.3/addressbook/gui/contact-editor/e-contact-quick-add.c.addr-quick-add	2009-03-12 16:16:35.000000000 +0100
+++ evolution-2.12.3/addressbook/gui/contact-editor/e-contact-quick-add.c	2009-03-12 16:16:43.000000000 +0100
@@ -43,6 +43,7 @@
 #include "e-contact-editor.h"
 #include "e-contact-quick-add.h"
 #include "eab-contact-merging.h"
+#include "e-util/e-error.h"
 
 typedef struct _QuickAdd QuickAdd;
 struct _QuickAdd {
@@ -54,6 +55,7 @@
 	EContactQuickAddCallback cb;
 	gpointer closure;
 
+	GtkWidget *dialog;
 	GtkWidget *name_entry;
 	GtkWidget *email_entry;
 	GtkWidget *option_menu;
@@ -122,7 +124,11 @@
 	QuickAdd *qa = (QuickAdd *) closure;
 
 	if (status == E_BOOK_ERROR_OK) {
-		eab_merging_book_add_contact (book, qa->contact, NULL, NULL);
+		if (e_book_is_writable (book))
+			eab_merging_book_add_contact (book, qa->contact, NULL, NULL);
+		else
+			e_error_run (NULL, "addressbook:error-read-only", e_source_peek_name (e_book_get_source (book)), NULL);
+
 		if (qa->cb)
 			qa->cb (qa->contact, qa->closure);
 		g_object_unref (book);
@@ -269,17 +275,35 @@
 }
 
 static void
+sanitize_widgets (QuickAdd *qa)
+{
+	gboolean enabled = TRUE;
+
+	g_return_if_fail (qa != NULL);
+	g_return_if_fail (qa->dialog != NULL);
+
+	/* do not call here e_book_is_writable (qa->book), because it requires opened book, which takes time for remote books */
+	enabled = qa->book != NULL && e_source_combo_box_get_active_uid (E_SOURCE_COMBO_BOX (qa->option_menu));
+
+	gtk_dialog_set_response_sensitive (GTK_DIALOG (qa->dialog), QUICK_ADD_RESPONSE_EDIT_FULL, enabled);
+	gtk_dialog_set_response_sensitive (GTK_DIALOG (qa->dialog), GTK_RESPONSE_OK, enabled);
+}
+
+static void
 source_changed (ESourceComboBox *source_combo_box, QuickAdd *qa)
 {
 	ESource *source;
 
 	source = e_source_combo_box_get_active (source_combo_box);
-
-	if (qa->book) {
-		g_object_unref (qa->book);
-		qa->book = NULL;
+	if (source != NULL) {
+		if (qa->book) {
+			g_object_unref (qa->book);
+			qa->book = NULL;
+		}
+		qa->book = e_book_new (source, NULL);
 	}
-	qa->book = e_book_new (source, NULL);
+
+	sanitize_widgets (qa);
 }
 
 static GtkWidget *
@@ -311,6 +335,8 @@
 
 	g_signal_connect (dialog, "response", G_CALLBACK (clicked_cb), qa);
 
+	qa->dialog = dialog;
+
 	qa->name_entry = gtk_entry_new ();
 	if (qa->name)
 		gtk_entry_set_text (GTK_ENTRY (qa->name_entry), qa->name);
@@ -328,11 +354,32 @@
 	e_source_combo_box_set_active (
 		E_SOURCE_COMBO_BOX (qa->option_menu),
 		e_book_get_source (book));
+
+	if (!e_source_combo_box_get_active_uid (E_SOURCE_COMBO_BOX (qa->option_menu))) {
+		/* this means the e_book_new_default_addressbook didn't find any "default" nor "system" source,
+		    and created new one for us. That is wrong, choose one from combo instead. */
+
+		if (book) {
+			g_object_unref (book);
+			book = NULL;
+		}
+
+		book = e_book_new (e_source_list_peek_source_any (source_list), NULL);
+		e_source_combo_box_set_active (E_SOURCE_COMBO_BOX (qa->option_menu), e_book_get_source (book));
+
+		if (!e_source_combo_box_get_active_uid (E_SOURCE_COMBO_BOX (qa->option_menu))) {
+			/* Does it failed again? What is going on? */
+			if (book)
+				g_object_unref (book);
+			book = NULL;
+		}
+	}
+
 	if (qa->book) {
 		g_object_unref (qa->book);
 		qa->book = NULL;
 	}
-	qa->book = book ;
+	qa->book = book;
 	source_changed (E_SOURCE_COMBO_BOX (qa->option_menu), qa);
 	g_signal_connect (
 		qa->option_menu, "changed",