[evolution-couchdb] Added UI for selecting different CouchDB instances
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Subject: [evolution-couchdb] Added UI for selecting different CouchDB instances
- Date: Mon, 27 Jul 2009 21:56:32 +0000 (UTC)
commit 61fa0c835e11ef1787a5edf0e55de20749d949e8
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Mon Jul 27 23:56:19 2009 +0200
Added UI for selecting different CouchDB instances
plugins/couchdb-contacts-source.c | 128 +++++++++++++++++++++++++++++++++++++
1 files changed, 128 insertions(+), 0 deletions(-)
---
diff --git a/plugins/couchdb-contacts-source.c b/plugins/couchdb-contacts-source.c
index 79a6afc..4c1f972 100644
--- a/plugins/couchdb-contacts-source.c
+++ b/plugins/couchdb-contacts-source.c
@@ -138,12 +138,77 @@ remove_couchdb_contacts_source_group (void)
}
}
+typedef struct {
+ ESource *source;
+ GtkWidget *vbox;
+ GtkWidget *user_db_button;
+ GtkWidget *system_db_button;
+ GtkWidget *remote_db_button;
+ GtkWidget *remote_db_entry;
+} UIData;
+
+static void
+destroy_ui_data (gpointer data)
+{
+ UIData *ui = data;
+
+ if (ui) {
+ gtk_widget_destroy (ui->vbox);
+ g_object_unref (ui->source);
+ g_free (ui);
+ }
+}
+
+static void
+on_user_db_toggled (GtkToggleButton *button, gpointer *user_data)
+{
+ UIData *ui = (UIData *) user_data;
+
+ if (gtk_toggle_button_get_active (button)) {
+ e_source_set_property (ui->source, "couchdb_instance", "user");
+ gtk_widget_set_sensitive (ui->remote_db_entry, FALSE);
+ }
+}
+
+static void
+on_system_db_toggled (GtkToggleButton *button, gpointer *user_data)
+{
+ UIData *ui = (UIData *) 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);
+ }
+}
+
+static void
+on_remote_db_toggled (GtkToggleButton *button, gpointer *user_data)
+{
+ UIData *ui = (UIData *) 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);
+ }
+}
+
+static on_remote_db_changed (GtkEditable *entry, gpointer user_data)
+{
+ UIData *ui = (UIData *) user_data;
+
+ e_source_set_property (ui->source, "couchdb_remote_server", gtk_entry_get_text (GTK_ENTRY (entry)));
+}
+
GtkWidget *
plugin_couchdb_contacts (EPlugin *epl, EConfigHookItemFactoryData *data)
{
ESource *source;
ESourceGroup *group;
const gchar *base_uri;
+ GtkWidget *parent, *parent_vbox;
+ GtkWidget *table, *label;
+ UIData *ui;
+ const gchar *property;
EABConfigTargetSource *t = (EABConfigTargetSource *) data->target;
source = t->source;
@@ -156,6 +221,69 @@ plugin_couchdb_contacts (EPlugin *epl, EConfigHookItemFactoryData *data)
if (strcmp(base_uri, COUCHDB_BASE_URI) != 0)
return NULL;
+ /* Build up the UI */
+ ui = g_new0 (UIData, 1);
+ ui->source = g_object_ref (source);
+
+ parent = data->parent;
+ parent_vbox = gtk_widget_get_ancestor (gtk_widget_get_parent (parent), GTK_TYPE_VBOX);
+
+ ui->vbox = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (parent_vbox), ui->vbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new (NULL);
+ gtk_label_set_markup (GTK_LABEL (label), _("<b>Server</b>"));
+ 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, 2, FALSE);
+ gtk_box_pack_start (GTK_BOX (ui->vbox), table, TRUE, TRUE, 0);
+
+ ui->user_db_button = gtk_radio_button_new_with_label (NULL, _("User local database"));
+ gtk_table_attach (GTK_TABLE (table), ui->user_db_button, 0, 2, 0, 1,
+ GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
+
+ ui->system_db_button = gtk_radio_button_new_with_label (
+ gtk_radio_button_get_group (GTK_RADIO_BUTTON (ui->user_db_button)),
+ _("System wide database"));
+ gtk_table_attach (GTK_TABLE (table), ui->system_db_button, 0, 2, 1, 2,
+ GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
+
+ ui->remote_db_button = gtk_radio_button_new_with_label (
+ gtk_radio_button_get_group (GTK_RADIO_BUTTON (ui->user_db_button)),
+ _("Remote database"));
+ gtk_table_attach (GTK_TABLE (table), ui->remote_db_button, 0, 1, 2, 3,
+ GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
+ ui->remote_db_entry = gtk_entry_new ();
+ gtk_table_attach (GTK_TABLE (table), ui->remote_db_entry, 1, 2, 2, 3,
+ 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_instance");
+ if (g_strcmp0 (property, "system") == 0) {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ui->system_db_button), TRUE);
+ gtk_widget_set_sensitive (ui->remote_db_entry, FALSE);
+ } else if (g_strcmp0 (property, "remote") == 0) {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ui->remote_db_button), TRUE);
+ gtk_widget_set_sensitive (ui->remote_db_entry, TRUE);
+ gtk_entry_set_text (GTK_ENTRY (ui->remote_db_entry),
+ e_source_get_property (ui->source, "couchdb_remote_server"));
+ } else {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ui->user_db_button), TRUE);
+ gtk_widget_set_sensitive (ui->remote_db_entry, FALSE);
+ }
+
+ g_object_set_data_full (G_OBJECT (epl), "gwidget", ui, destroy_ui_data);
+ g_signal_connect (ui->vbox, "destroy", G_CALLBACK (gtk_widget_destroyed), &ui->vbox);
+
+ /* Signals */
+ g_signal_connect (G_OBJECT (ui->user_db_button), "toggled", G_CALLBACK (on_user_db_toggled), ui);
+ 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);
+
return NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]