[evolution-couchdb] Allow users to specify database names, instead of assuming everyone uses 'contacts'



commit 81c168957f7303c27f49167e362b79955487bde3
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Thu Nov 4 11:31:34 2010 +0100

    Allow users to specify database names, instead of assuming everyone uses 'contacts'

 addressbook/e-book-backend-couchdb.c |   11 ++++++++---
 plugins/couchdb-contacts-source.c    |   30 +++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 4 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index a0ba43d..7240942 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -991,6 +991,7 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
 	const gchar *property;
 	GError *error = NULL;
 	GSList *doc_list, *sl;
+	const gchar *db_name;
 	EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
 
 #if EDS_CHECK_VERSION(2, 31, 0)
@@ -1045,10 +1046,14 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
 		g_free (uri);
 	}
 
+	db_name = e_source_get_property (source, "couchdb_database");
+	if (db_name == NULL)
+		db_name = "contacts";
+
 	/* check if only_if_exists */
 	error = NULL;
 	couchdb_backend->database = couchdb_session_get_database (couchdb_backend->couchdb,
-								  "contacts",
+								  db_name,
 								  &error);
 	if (couchdb_backend->database == NULL) {
 		if (error) {
@@ -1069,7 +1074,7 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
 		/* if it does not exist, create it */
 		error = NULL;
 		if (!couchdb_session_create_database (couchdb_backend->couchdb,
-						      "contacts",
+						      db_name,
 						      &error)) {
 #if EDS_CHECK_VERSION(2, 31, 0)
 			g_set_error (ret_error, ERROR_QUARK, error->code, "%s: %s",
@@ -1086,7 +1091,7 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
 		}
 
 		couchdb_backend->database = couchdb_session_get_database (couchdb_backend->couchdb,
-									  "contacts",
+									  db_name,
 									  &error);
 	}
 
diff --git a/plugins/couchdb-contacts-source.c b/plugins/couchdb-contacts-source.c
index f234d7a..3919102 100644
--- a/plugins/couchdb-contacts-source.c
+++ b/plugins/couchdb-contacts-source.c
@@ -145,6 +145,7 @@ typedef struct {
 	GtkWidget *system_db_button;
 	GtkWidget *remote_db_button;
 	GtkWidget *remote_db_entry;
+	GtkWidget *db_name_entry;
 } UIData;
 
 static void
@@ -165,7 +166,9 @@ on_user_db_toggled (GtkToggleButton *button, gpointer *user_data)
 
 	if (gtk_toggle_button_get_active (button)) {
 		e_source_set_property (ui->source, "couchdb_instance", "user");
+		e_source_set_property (ui->source, "couchdb_database", "contacts");
 		gtk_widget_set_sensitive (ui->remote_db_entry, FALSE);
+		gtk_widget_set_sensitive (ui->db_name_entry, FALSE);
 	}
 }
 
@@ -177,6 +180,7 @@ on_system_db_toggled (GtkToggleButton *button, gpointer *user_data)
 	if (gtk_toggle_button_get_active (button)) {
 		e_source_set_property (ui->source, "couchdb_instance", "system");
 		gtk_widget_set_sensitive (ui->remote_db_entry, FALSE);
+		gtk_widget_set_sensitive (ui->db_name_entry, TRUE);
 	}
 }
 
@@ -188,6 +192,7 @@ on_remote_db_toggled (GtkToggleButton *button, gpointer *user_data)
 	if (gtk_toggle_button_get_active (button)) {
 		e_source_set_property (ui->source, "couchdb_instance", "remote");
 		gtk_widget_set_sensitive (ui->remote_db_entry, TRUE);
+		gtk_widget_set_sensitive (ui->db_name_entry, TRUE);
 	}
 }
 
@@ -199,6 +204,14 @@ on_remote_db_changed (GtkEditable *entry, gpointer user_data)
 	e_source_set_property (ui->source, "couchdb_remote_server", gtk_entry_get_text (GTK_ENTRY (entry)));
 }
 
+static void
+on_db_name_changed (GtkEditable *entry, gpointer user_data)
+{
+	UIData *ui = (UIData *) user_data;
+
+	e_source_set_property (ui->source, "couchdb_database", gtk_entry_get_text (GTK_ENTRY (entry)));
+}
+
 GtkWidget *
 plugin_couchdb_contacts (EPlugin *epl, EConfigHookItemFactoryData *data)
 {
@@ -236,7 +249,7 @@ plugin_couchdb_contacts (EPlugin *epl, EConfigHookItemFactoryData *data)
 	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
 	gtk_box_pack_start (GTK_BOX (ui->vbox), label, FALSE, FALSE, 0);
 
-	table = gtk_table_new (3, 3, FALSE);
+	table = gtk_table_new (4, 3, FALSE);
 	gtk_box_pack_start (GTK_BOX (ui->vbox), table, TRUE, TRUE, 0);
 
 	label = gtk_label_new ("   ");
@@ -261,9 +274,22 @@ plugin_couchdb_contacts (EPlugin *epl, EConfigHookItemFactoryData *data)
 	gtk_table_attach (GTK_TABLE (table), ui->remote_db_entry, 2, 3, 2, 3,
 			  GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
 
+	label = gtk_label_new (_("Database name:"));
+	gtk_table_attach (GTK_TABLE (table), label, 1, 2, 3, 4,
+			  GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
+	ui->db_name_entry = gtk_entry_new ();
+	gtk_table_attach (GTK_TABLE (table), ui->db_name_entry, 2, 3, 3, 4,
+			  GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
+
 	gtk_widget_show_all (ui->vbox);
 
 	/* Set values from the source */
+	property = e_source_get_property (ui->source, "couchdb_database");
+	if (property != NULL)
+		gtk_entry_set_text (GTK_ENTRY (ui->db_name_entry), property);
+	else
+		gtk_entry_set_text (GTK_ENTRY (ui->db_name_entry), "contacts");
+
 	property = e_source_get_property (ui->source, "couchdb_instance");
 	if (g_strcmp0 (property, "system") == 0) {
 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ui->system_db_button), TRUE);
@@ -278,6 +304,7 @@ plugin_couchdb_contacts (EPlugin *epl, EConfigHookItemFactoryData *data)
 		if (!property)
 			e_source_set_property (ui->source, "couchdb_instance", "user");
 		gtk_widget_set_sensitive (ui->remote_db_entry, FALSE);
+		gtk_widget_set_sensitive (ui->db_name_entry, FALSE);
 	}
 
 	g_object_set_data_full (G_OBJECT (epl), "cwidget", ui, destroy_ui_data);
@@ -288,6 +315,7 @@ plugin_couchdb_contacts (EPlugin *epl, EConfigHookItemFactoryData *data)
 	g_signal_connect (G_OBJECT (ui->system_db_button), "toggled", G_CALLBACK (on_system_db_toggled), ui);
 	g_signal_connect (G_OBJECT (ui->remote_db_button), "toggled", G_CALLBACK (on_remote_db_toggled), ui);
 	g_signal_connect (G_OBJECT (ui->remote_db_entry), "changed", G_CALLBACK (on_remote_db_changed), ui);
+	g_signal_connect (G_OBJECT (ui->db_name_entry), "changed", G_CALLBACK (on_db_name_changed), ui);
 
 	return NULL;
 }



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