[evolution-couchdb] plugin: Add UI for calendar (tasks) source settings



commit ff080f8f47471f06b19d8361779d1a7d9dbbbc91
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Fri Jun 17 17:45:04 2011 +0200

    plugin: Add UI for calendar (tasks) source settings

 plugins/Makefile.am                              |    3 +-
 plugins/couchdb-calendar-source.c                |   51 +++++++
 plugins/couchdb-contacts-source.c                |  162 +---------------------
 plugins/couchdb-sources.c                        |  168 +++++++++++++++++++++-
 plugins/couchdb-sources.h                        |    7 +-
 plugins/org-gnome-evolution-couchdb.eplug.xml.in |    5 +
 6 files changed, 231 insertions(+), 165 deletions(-)
---
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index f8adc8c..da815e0 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -13,7 +13,8 @@ plugin_LTLIBRARIES = liborg-gnome-evolution-couchdb.la
 liborg_gnome_evolution_couchdb_la_SOURCES =     \
 	couchdb-sources.c			\
 	couchdb-sources.h 			\
-	couchdb-contacts-source.c
+	couchdb-contacts-source.c		\
+	couchdb-calendar-source.c
 
 liborg_gnome_evolution_couchdb_la_LIBADD = 	\
 	$(EVOLUTION_CALENDAR_LIBS)		\
diff --git a/plugins/couchdb-calendar-source.c b/plugins/couchdb-calendar-source.c
new file mode 100644
index 0000000..33757b0
--- /dev/null
+++ b/plugins/couchdb-calendar-source.c
@@ -0,0 +1,51 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* couchdb-contacts-source.h - CouchDB contact backend
+ *
+ * Copyright (C) 2011 Canonical, Ltd. (www.canonical.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Rodrigo Moya <rodrigo moya canonical com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <calendar/gui/e-cal-config.h>
+#include "couchdb-sources.h"
+
+GtkWidget *
+plugin_couchdb_calendar (EPlugin *epl, EConfigHookItemFactoryData *data)
+{
+	ESource *source;
+	ESourceGroup *group;
+	const gchar *base_uri;
+	ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target;
+
+	source = t->source;
+        group  = e_source_peek_group (source);
+
+        base_uri = e_source_group_peek_base_uri (group);
+
+        g_object_set_data (G_OBJECT (epl), "cwidget", NULL);
+
+	if (strcmp (base_uri, COUCHDB_BASE_URI) != 0)
+                return NULL;
+
+	build_couchdb_settings (epl, source, data->parent);
+
+	return NULL;
+}
diff --git a/plugins/couchdb-contacts-source.c b/plugins/couchdb-contacts-source.c
index b3f5a58..c3accf1 100644
--- a/plugins/couchdb-contacts-source.c
+++ b/plugins/couchdb-contacts-source.c
@@ -27,94 +27,15 @@
 
 #include <glib/gi18n.h>
 #include <addressbook/gui/widgets/eab-config.h>
-#include <libedataserver/eds-version.h>
 #include <libebook/e-book.h>
 #include "couchdb-sources.h"
 
-typedef struct {
-	ESource *source;
-	GtkWidget *vbox;
-	GtkWidget *user_db_button;
-	GtkWidget *system_db_button;
-	GtkWidget *remote_db_button;
-	GtkWidget *remote_db_entry;
-	GtkWidget *db_name_entry;
-} UIData;
-
-static void
-destroy_ui_data (gpointer data)
-{
-	UIData *ui = data;
-
-	if (ui && ui->vbox)
-		gtk_widget_destroy (ui->vbox);
-
-	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");
-		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);
-	}
-}
-
-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);
-		gtk_widget_set_sensitive (ui->db_name_entry, TRUE);
-	}
-}
-
-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);
-		gtk_widget_set_sensitive (ui->db_name_entry, TRUE);
-	}
-}
-
-static void
-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)));
-}
-
-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)
 {
 	ESource *source;
         ESourceGroup *group;
 	const gchar *base_uri;
-	GtkWidget *parent;
-	GtkWidget *table, *label, *parent_vbox;
-	UIData *ui;
-	const gchar *property;
 	EABConfigTargetSource *t = (EABConfigTargetSource *) data->target;
 
 	source = t->source;
@@ -127,88 +48,7 @@ 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 = t->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 (4, 3, FALSE);
-	gtk_box_pack_start (GTK_BOX (ui->vbox), table, TRUE, TRUE, 0);
-
-	label = gtk_label_new ("   ");
-	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
-
-	ui->user_db_button = gtk_radio_button_new_with_label (NULL, _("Desktop CouchDB"));
-	gtk_table_attach (GTK_TABLE (table), ui->user_db_button, 1, 3, 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 CouchDB"));
-	gtk_table_attach (GTK_TABLE (table), ui->system_db_button, 1, 3, 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 CouchDB server"));
-	gtk_table_attach (GTK_TABLE (table), ui->remote_db_button, 1, 2, 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, 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);
-		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);
-		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);
-	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);
-	g_signal_connect (G_OBJECT (ui->db_name_entry), "changed", G_CALLBACK (on_db_name_changed), ui);
+	build_couchdb_settings (epl, source, data->parent);
 
 	return NULL;
 }
diff --git a/plugins/couchdb-sources.c b/plugins/couchdb-sources.c
index d9ef516..16af839 100644
--- a/plugins/couchdb-sources.c
+++ b/plugins/couchdb-sources.c
@@ -24,8 +24,173 @@
 #include <libedataserver/eds-version.h>
 #include <libedataserver/e-source.h>
 #include <libedataserver/e-source-list.h>
+#include <libecal/e-cal.h>
 #include "couchdb-sources.h"
 
+typedef struct {
+	ESource *source;
+	GtkWidget *vbox;
+	GtkWidget *user_db_button;
+	GtkWidget *system_db_button;
+	GtkWidget *remote_db_button;
+	GtkWidget *remote_db_entry;
+	GtkWidget *db_name_entry;
+} UIData;
+
+static void
+destroy_ui_data (gpointer data)
+{
+	UIData *ui = data;
+
+	if (ui && ui->vbox)
+		gtk_widget_destroy (ui->vbox);
+
+	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");
+		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);
+	}
+}
+
+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);
+		gtk_widget_set_sensitive (ui->db_name_entry, TRUE);
+	}
+}
+
+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);
+		gtk_widget_set_sensitive (ui->db_name_entry, TRUE);
+	}
+}
+
+static void
+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)));
+}
+
+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)));
+}
+
+void
+build_couchdb_settings (EPlugin *epl, ESource *source, GtkWidget *parent)
+{
+	GtkWidget *table, *label, *parent_vbox;
+	UIData *ui;
+	const gchar *property;
+
+	/* Build up the UI */
+	ui = g_new0 (UIData, 1);
+	ui->source = source;
+
+	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 (4, 3, FALSE);
+	gtk_box_pack_start (GTK_BOX (ui->vbox), table, TRUE, TRUE, 0);
+
+	label = gtk_label_new ("   ");
+	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+
+	ui->user_db_button = gtk_radio_button_new_with_label (NULL, _("Desktop CouchDB"));
+	gtk_table_attach (GTK_TABLE (table), ui->user_db_button, 1, 3, 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 CouchDB"));
+	gtk_table_attach (GTK_TABLE (table), ui->system_db_button, 1, 3, 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 CouchDB server"));
+	gtk_table_attach (GTK_TABLE (table), ui->remote_db_button, 1, 2, 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, 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);
+		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);
+		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);
+	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);
+	g_signal_connect (G_OBJECT (ui->db_name_entry), "changed", G_CALLBACK (on_db_name_changed), ui);
+}
+
 void
 ensure_source_group (ESourceList *source_list)
 {
@@ -62,9 +227,10 @@ e_plugin_lib_enable (EPlugin *ep, gint enable)
 e_plugin_lib_enable (EPluginLib *ep, gint enable)
 #endif
 {
-	ESourceList *book_sources;
+	ESourceList *book_sources, *task_sources;
 
 	e_book_get_addressbooks (&book_sources, NULL);
+	e_cal_get_sources (&task_sources, E_CAL_SOURCE_TYPE_TODO, NULL);
 
 	if (enable)
 		ensure_source_group (book_sources);
diff --git a/plugins/couchdb-sources.h b/plugins/couchdb-sources.h
index 1d4b9a1..42b4255 100644
--- a/plugins/couchdb-sources.h
+++ b/plugins/couchdb-sources.h
@@ -24,6 +24,7 @@
 #define __COUCHDB_CONTACTS_SOURCE_H__
 
 #include <gtk/gtk.h>
+#include <libedataserver/e-source-list.h>
 #include <e-util/e-config.h>
 #include <e-util/e-plugin.h>
 
@@ -32,7 +33,9 @@
 void       ensure_source_group (ESourceList *source_list);
 void       remove_source_group (ESourceList *source_list);
 
-GtkWidget *plugin_couchdb_contacts (EPlugin                    *epl,
-				    EConfigHookItemFactoryData *data);
+void       build_couchdb_settings (EPlugin *epl, ESource *source, GtkWidget *parent);
+
+GtkWidget *plugin_couchdb_contacts (EPlugin *epl, EConfigHookItemFactoryData *data);
+GtkWidget *plugin_couchdb_calendar (EPlugin *epl, EConfigHookItemFactoryData *data);
 
 #endif
diff --git a/plugins/org-gnome-evolution-couchdb.eplug.xml.in b/plugins/org-gnome-evolution-couchdb.eplug.xml.in
index d242db1..2893f82 100644
--- a/plugins/org-gnome-evolution-couchdb.eplug.xml.in
+++ b/plugins/org-gnome-evolution-couchdb.eplug.xml.in
@@ -10,5 +10,10 @@
         <item type="item" path="00.general/10.display/00.couchdb" factory="plugin_couchdb_contacts"/>
       </group>
     </hook>
+    <hook class="org.gnome.evolution.calendar.config:1.0">
+      <group target="source" id="org.gnome.evolution.calendar.calendarProperties">
+        <item type="item_table" path="00.general/00.source/99.couchdb" factory="plugin_couchdb_calendar"/>
+      </group>
+    </hook>
   </e-plugin>
 </e-plugin-list>



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