[evolution-data-server] Added a crude gconf based offline listener for e-addressbook-factory



commit 91967da817478dafb76d87791661230d65314d23
Author: Johnny Jacob <jjohnny novell com>
Date:   Mon Aug 3 12:52:08 2009 +0530

    Added a crude gconf based offline listener for e-addressbook-factory

 addressbook/libedata-book/Makefile.am        |    2 +
 addressbook/libedata-book/offline-listener.c |  183 ++++++++++++++++++++++++++
 addressbook/libedata-book/offline-listener.h |   64 +++++++++
 3 files changed, 249 insertions(+), 0 deletions(-)
---
diff --git a/addressbook/libedata-book/Makefile.am b/addressbook/libedata-book/Makefile.am
index cf8f0b8..a13e143 100644
--- a/addressbook/libedata-book/Makefile.am
+++ b/addressbook/libedata-book/Makefile.am
@@ -35,6 +35,8 @@ libedata_book_1_2_la_SOURCES =				\
 	e-data-book.c					\
 	ximian-vcard.h					\
 	opid.c opid.h					\
+	offline-listener.c				\
+	offline-listener.h				\
 	$(ENUM_GENERATED)
 
 libedata_book_1_2_la_LIBADD =					\
diff --git a/addressbook/libedata-book/offline-listener.c b/addressbook/libedata-book/offline-listener.c
new file mode 100644
index 0000000..f52b889
--- /dev/null
+++ b/addressbook/libedata-book/offline-listener.c
@@ -0,0 +1,183 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* server-interface-check.h
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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 Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Sivaiah Nallagatla <snallagatla novell com>
+ */
+
+/*Note : Copied from src/offline_listner.c . This should be replaced */
+/* with network manager code */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "offline-listener.h"
+#include <libedata-book/e-data-book-factory.h>
+#include <gconf/gconf-client.h>
+
+enum {
+
+	OFFLINE_MODE=0,
+	ONLINE_MODE
+};
+
+static GObjectClass *parent_class = NULL;
+
+struct _OfflineListenerPrivate
+{
+	GConfClient *default_client;
+
+	EDataBookFactory *book_factory;
+
+	gboolean is_offline_now;
+};
+
+
+static void
+set_online_status (OfflineListener *offline_listener, gboolean is_offline)
+{
+	OfflineListenerPrivate *priv;
+
+	priv = offline_listener->priv;
+
+	e_data_book_factory_set_backend_mode
+		(priv->book_factory, is_offline ? OFFLINE_MODE : ONLINE_MODE);
+}
+
+static void
+online_status_changed (GConfClient *client, gint cnxn_id, GConfEntry *entry, gpointer data)
+{
+	GConfValue *value;
+	gboolean offline;
+        OfflineListener *offline_listener;
+	OfflineListenerPrivate *priv;
+
+	offline_listener = OFFLINE_LISTENER(data);
+	priv = offline_listener->priv;
+	offline = FALSE;
+	value = gconf_entry_get_value (entry);
+	if (value)
+		offline = gconf_value_get_bool (value);
+	if (priv->is_offline_now != offline) {
+		priv->is_offline_now = offline;
+		set_online_status (offline_listener ,offline);
+	}
+
+}
+
+
+static void
+setup_offline_listener (OfflineListener *offline_listener)
+{
+	OfflineListenerPrivate *priv = offline_listener->priv;
+
+	priv->default_client = gconf_client_get_default ();
+	gconf_client_add_dir (priv->default_client, "/apps/evolution/shell", GCONF_CLIENT_PRELOAD_RECURSIVE,NULL);
+	gconf_client_notify_add (priv->default_client, "/apps/evolution/shell/start_offline", 
+				 (GConfClientNotifyFunc)online_status_changed, 
+				 offline_listener, NULL, NULL);
+
+	priv->is_offline_now = gconf_client_get_bool (priv->default_client, "/apps/evolution/shell/start_offline", NULL);
+	set_online_status (offline_listener, priv->is_offline_now);
+}
+
+OfflineListener*
+offline_listener_new (EDataBookFactory *book_factory)
+{
+	OfflineListener *offline_listener = g_object_new (OFFLINE_TYPE_LISTENER, NULL);
+	OfflineListenerPrivate *priv = offline_listener->priv;
+
+	priv->book_factory = book_factory;
+	setup_offline_listener (offline_listener);
+	return offline_listener;
+
+}
+
+
+static void
+offline_listener_dispose (GObject *object)
+{
+	OfflineListener *offline_listener = OFFLINE_LISTENER (object);
+	if (offline_listener->priv->default_client) {
+		g_object_unref (offline_listener->priv->default_client);
+		offline_listener->priv->default_client = NULL;
+	}
+	(* G_OBJECT_CLASS (parent_class)->dispose) (object);
+}
+
+static void
+offline_listener_finalize (GObject *object)
+{
+	OfflineListener *offline_listener;
+	OfflineListenerPrivate *priv;
+
+	offline_listener = OFFLINE_LISTENER (object);
+	priv = offline_listener->priv;
+
+	g_free (priv);
+	offline_listener->priv = NULL;
+
+	parent_class->finalize (object);
+}
+
+static void
+offline_listener_init (OfflineListener *listener)
+{
+	OfflineListenerPrivate *priv;
+
+	priv =g_new0 (OfflineListenerPrivate, 1);
+	listener->priv = priv;
+
+}
+
+
+
+static void
+offline_listener_class_init (OfflineListener *klass)
+{
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (klass);
+
+	object_class = G_OBJECT_CLASS (klass);
+	object_class->dispose = offline_listener_dispose;
+	object_class->finalize = offline_listener_finalize;
+}
+
+GType
+offline_listener_get_type (void)
+{
+	static GType type = 0;
+
+	if (!type) {
+		static GTypeInfo info = {
+                        sizeof (OfflineListenerClass),
+                        (GBaseInitFunc) NULL,
+                        (GBaseFinalizeFunc) NULL,
+                        (GClassInitFunc) offline_listener_class_init,
+                        NULL, NULL,
+                        sizeof (OfflineListener),
+                        0,
+                        (GInstanceInitFunc) offline_listener_init,
+                };
+		type = g_type_register_static (G_TYPE_OBJECT, "OfflineListener", &info, 0);
+	}
+
+	return type;
+}
diff --git a/addressbook/libedata-book/offline-listener.h b/addressbook/libedata-book/offline-listener.h
new file mode 100644
index 0000000..276d107
--- /dev/null
+++ b/addressbook/libedata-book/offline-listener.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* server-interface-check.h
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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 Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Sivaiah Nallagatla <snallagatla novell com>
+ */
+
+#ifndef _OFFLINE_LISTNER_H_
+#define _OFFLINE_LISTNER_H_
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib-object.h>
+#include <libedata-book/e-data-book-factory.h>
+
+G_BEGIN_DECLS
+
+#define OFFLINE_TYPE_LISTENER			(offline_listener_get_type ())
+#define OFFLINE_LISTENER(obj)			((G_TYPE_CHECK_INSTANCE_CAST((obj), OFFLINE_TYPE_LISTENER, OfflineListener)))
+#define OFFLINE_LISTENER_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass), OFFLINE_TYPE_LISTENER, OfflineListenerClass))
+#define OFFLINE_IS_LISTENER(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), OFFLINE_TYPE_LISTENER))
+#define OFFLINE_IS_LISTENER_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((obj), OFFLINE_TYPE_LISTENER))
+
+
+typedef struct _OfflineListener        OfflineListener;
+typedef struct _OfflineListenerPrivate  OfflineListenerPrivate;
+typedef struct _OfflineListenerClass   OfflineListenerClass;
+
+struct _OfflineListener {
+	GObject parent;
+	OfflineListenerPrivate *priv;
+
+};
+
+struct _OfflineListenerClass {
+	GObjectClass  parent_class;
+
+};
+
+
+GType offline_listener_get_type  (void);
+
+OfflineListener  *offline_listener_new (EDataBookFactory *cal_factory);
+
+G_END_DECLS
+
+#endif /* _OFFLINE_LISTNER_H_ */



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