[evolution-couchdb] plugin: Refactor a bit to be able to reuse code for Tasks plugin



commit 90cc1310ad6410151fd6c423d258931f404b455f
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Fri Jun 17 17:08:08 2011 +0200

    plugin: Refactor a bit to be able to reuse code for Tasks plugin

 plugins/Makefile.am               |    5 +-
 plugins/couchdb-contacts-source.c |   62 +-----------------------------
 plugins/couchdb-sources.c         |   75 +++++++++++++++++++++++++++++++++++++
 plugins/couchdb-sources.h         |    9 ++++
 4 files changed, 89 insertions(+), 62 deletions(-)
---
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 512ac00..f8adc8c 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -10,8 +10,9 @@ plugindir = $(EVOLUTION_PLUGINS_DIR)
 plugin_DATA = org-gnome-evolution-couchdb.eplug
 plugin_LTLIBRARIES = liborg-gnome-evolution-couchdb.la
 
-liborg_gnome_evolution_couchdb_la_SOURCES =        \
-	couchdb-contacts-source.h \
+liborg_gnome_evolution_couchdb_la_SOURCES =     \
+	couchdb-sources.c			\
+	couchdb-sources.h 			\
 	couchdb-contacts-source.c
 
 liborg_gnome_evolution_couchdb_la_LIBADD = 	\
diff --git a/plugins/couchdb-contacts-source.c b/plugins/couchdb-contacts-source.c
index d657eca..b3f5a58 100644
--- a/plugins/couchdb-contacts-source.c
+++ b/plugins/couchdb-contacts-source.c
@@ -26,54 +26,10 @@
 #endif
 
 #include <glib/gi18n.h>
-#include <gtk/gtk.h>
-#include <e-util/e-config.h>
-#include <e-util/e-plugin.h>
 #include <addressbook/gui/widgets/eab-config.h>
 #include <libedataserver/eds-version.h>
-#include <libedataserver/e-source.h>
-#include <libedataserver/e-source-list.h>
-#include <libedataserver/e-url.h>
-#include <libedataserver/e-account-list.h>
-
-#define COUCHDB_BASE_URI "couchdb://"
-
-static void
-ensure_couchdb_contacts_source_group (void)
-{
-	ESourceList *source_list;
-
-	source_list = e_source_list_new_for_gconf_default("/apps/evolution/addressbook/sources");
-	if (source_list) {
-		e_source_list_ensure_group (source_list, _("CouchDB"), COUCHDB_BASE_URI, FALSE);
-
-		g_object_unref (G_OBJECT (source_list));
-	}
-}
-
-static void
-remove_couchdb_contacts_source_group (void)
-{
-	ESourceList *source_list;
-
-	source_list = e_source_list_new_for_gconf_default("/apps/evolution/addressbook/sources");
-	if (source_list) {
-		ESourceGroup *group;
-
-		group = e_source_list_peek_group_by_base_uri (source_list, COUCHDB_BASE_URI);
-		if (group) {
-			GSList *sources;
-
-			sources = e_source_group_peek_sources (group);
-			if (sources == NULL) {
-				e_source_list_remove_group (source_list, group);
-				e_source_list_sync (source_list, NULL);
-			}
-		}
-
-		g_object_unref (G_OBJECT (source_list));
-	}
-}
+#include <libebook/e-book.h>
+#include "couchdb-sources.h"
 
 typedef struct {
 	ESource *source;
@@ -257,17 +213,3 @@ plugin_couchdb_contacts (EPlugin *epl, EConfigHookItemFactoryData *data)
 	return NULL;
 }
 
-gint
-#if EDS_CHECK_VERSION(2, 30, 0)
-e_plugin_lib_enable (EPlugin *ep, gint enable)
-#else
-e_plugin_lib_enable (EPluginLib *ep, gint enable)
-#endif
-{
-	if (enable)
-		ensure_couchdb_contacts_source_group ();
-	else
-		remove_couchdb_contacts_source_group ();
-
-	return 0;
-}
diff --git a/plugins/couchdb-sources.c b/plugins/couchdb-sources.c
new file mode 100644
index 0000000..d9ef516
--- /dev/null
+++ b/plugins/couchdb-sources.c
@@ -0,0 +1,75 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* couchdb-contacts-source.c - CouchDB contact backend
+ *
+ * Copyright (C) 2009 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>
+ */
+
+#include <glib/gi18n.h>
+#include <libedataserver/eds-version.h>
+#include <libedataserver/e-source.h>
+#include <libedataserver/e-source-list.h>
+#include "couchdb-sources.h"
+
+void
+ensure_source_group (ESourceList *source_list)
+{
+	if (source_list) {
+		e_source_list_ensure_group (source_list, "CouchDB", COUCHDB_BASE_URI, FALSE);
+	}
+}
+
+void
+remove_source_group (ESourceList *source_list)
+{
+	if (source_list) {
+		ESourceGroup *group;
+
+		group = e_source_list_peek_group_by_base_uri (source_list, COUCHDB_BASE_URI);
+		if (group) {
+			GSList *sources;
+
+			sources = e_source_group_peek_sources (group);
+			if (sources == NULL) {
+				e_source_list_remove_group (source_list, group);
+				e_source_list_sync (source_list, NULL);
+			}
+		}
+
+		g_object_unref (G_OBJECT (source_list));
+	}
+}
+
+gint
+#if EDS_CHECK_VERSION(2, 30, 0)
+e_plugin_lib_enable (EPlugin *ep, gint enable)
+#else
+e_plugin_lib_enable (EPluginLib *ep, gint enable)
+#endif
+{
+	ESourceList *book_sources;
+
+	e_book_get_addressbooks (&book_sources, NULL);
+
+	if (enable)
+		ensure_source_group (book_sources);
+	else
+		remove_source_group (book_sources);
+
+	return 0;
+}
diff --git a/plugins/couchdb-sources.h b/plugins/couchdb-sources.h
index c846162..1d4b9a1 100644
--- a/plugins/couchdb-sources.h
+++ b/plugins/couchdb-sources.h
@@ -23,6 +23,15 @@
 #ifndef __COUCHDB_CONTACTS_SOURCE_H__
 #define __COUCHDB_CONTACTS_SOURCE_H__
 
+#include <gtk/gtk.h>
+#include <e-util/e-config.h>
+#include <e-util/e-plugin.h>
+
+#define COUCHDB_BASE_URI "couchdb://"
+
+void       ensure_source_group (ESourceList *source_list);
+void       remove_source_group (ESourceList *source_list);
+
 GtkWidget *plugin_couchdb_contacts (EPlugin                    *epl,
 				    EConfigHookItemFactoryData *data);
 



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