[evolution-data-server] Bug #597566 - Remote calendars are marked as readonly



commit 5852f5b363b0884225f6ec363fd70cc5dc383863
Author: Milan Crha <mcrha redhat com>
Date:   Tue Oct 6 19:33:04 2009 +0200

    Bug #597566 - Remote calendars are marked as readonly

 addressbook/libedata-book/Makefile.am              |    2 +-
 addressbook/libedata-book/e-data-book-factory.c    |   21 +++-
 addressbook/libedata-book/offline-listener.h       |   64 ----------
 calendar/libecal/e-cal.c                           |   15 ++-
 calendar/libedata-cal/e-data-cal-factory.c         |   20 +++-
 camel/camel-folder.c                               |    4 -
 configure.ac                                       |    2 +-
 libebackend/Makefile.am                            |    2 +
 .../e-offline-listener.c                           |  133 +++++++++++---------
 libebackend/e-offline-listener.h                   |   69 ++++++++++
 10 files changed, 190 insertions(+), 142 deletions(-)
---
diff --git a/addressbook/libedata-book/Makefile.am b/addressbook/libedata-book/Makefile.am
index c3ac0d7..5ab6451 100644
--- a/addressbook/libedata-book/Makefile.am
+++ b/addressbook/libedata-book/Makefile.am
@@ -76,7 +76,7 @@ e_addressbook_factory_CPPFLAGS = \
 	-I$(top_srcdir)/addressbook		\
 	-I$(top_builddir)/addressbook
 
-e_addressbook_factory_SOURCES = e-data-book-factory.c e-data-book-factory.h offline-listener.c	offline-listener.h
+e_addressbook_factory_SOURCES = e-data-book-factory.c e-data-book-factory.h
 
 e_addressbook_factory_LDADD = libedata-book-1.2.la
 
diff --git a/addressbook/libedata-book/e-data-book-factory.c b/addressbook/libedata-book/e-data-book-factory.c
index 0b2a8b3..d455472 100644
--- a/addressbook/libedata-book/e-data-book-factory.c
+++ b/addressbook/libedata-book/e-data-book-factory.c
@@ -30,12 +30,12 @@
 #include <dbus/dbus-glib-lowlevel.h>
 #include <dbus/dbus-glib-bindings.h>
 #include <libebackend/e-data-server-module.h>
+#include <libebackend/e-offline-listener.h>
 #include "e-book-backend-factory.h"
 #include "e-data-book-factory.h"
 #include "e-data-book.h"
 #include "e-book-backend.h"
 #include "e-book-backend-factory.h"
-#include "offline-listener.h"
 
 static void impl_BookFactory_getBook(EDataBookFactory *factory, const char *IN_uri, DBusGMethodInvocation *context);
 #include "e-data-book-factory-glue.h"
@@ -355,6 +355,16 @@ die (const char *prefix, GError *error)
 	exit(1);
 }
 
+static void
+offline_state_changed_cb (EOfflineListener *eol, EDataBookFactory *factory)
+{
+	EOfflineListenerState state = e_offline_listener_get_state (eol);
+
+	g_return_if_fail (state == EOL_STATE_ONLINE || state == EOL_STATE_OFFLINE);
+
+	e_data_book_factory_set_backend_mode (factory, state == EOL_STATE_ONLINE ? E_DATA_BOOK_MODE_REMOTE : E_DATA_BOOK_MODE_LOCAL);
+}
+
 #define E_DATA_BOOK_FACTORY_SERVICE_NAME "org.gnome.evolution.dataserver.AddressBook"
 
 int
@@ -363,8 +373,7 @@ main (int argc, char **argv)
 	GError *error = NULL;
 	DBusGProxy *bus_proxy;
 	guint32 request_name_ret;
-
-	OfflineListener *offline_listener = NULL;
+	EOfflineListener *eol;
 
 	g_type_init ();
 	if (!g_thread_supported ()) g_thread_init (NULL);
@@ -400,11 +409,13 @@ main (int argc, char **argv)
 				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
 	dbus_g_proxy_connect_signal (bus_proxy, "NameOwnerChanged", G_CALLBACK (name_owner_changed), factory, NULL);
 
-	offline_listener = offline_listener_new (factory);
+	eol = e_offline_listener_new ();
+	offline_state_changed_cb (eol, factory);
+	g_signal_connect (eol, "changed", G_CALLBACK (offline_state_changed_cb), factory);
 
 	g_main_loop_run (loop);
 
-	g_object_unref (offline_listener);
+	g_object_unref (eol);
 
 	dbus_g_connection_unref (connection);
 
diff --git a/calendar/libecal/e-cal.c b/calendar/libecal/e-cal.c
index c20b809..c7dc846 100644
--- a/calendar/libecal/e-cal.c
+++ b/calendar/libecal/e-cal.c
@@ -972,10 +972,12 @@ async_signal_idle_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
 	ECalendarStatus status;
 
 	ecal = E_CAL (user_data);
-	if (error)
+	if (error) {
 		status = get_status_from_error (error);
-	else
+	} else {
 		status = E_CALENDAR_STATUS_OK;
+		org_gnome_evolution_dataserver_calendar_Cal_is_read_only (ecal->priv->proxy, NULL);
+	}
 
 	g_signal_emit (G_OBJECT (ecal), e_cal_signals[CAL_OPENED], 0, status);
 }
@@ -1057,7 +1059,7 @@ open_calendar (ECal *ecal, gboolean only_if_exists, GError **error, ECalendarSta
 	priv->load_state = E_CAL_LOAD_LOADING;
 
 	*status = E_CALENDAR_STATUS_OK;
-	if (!async ) {
+	if (!async) {
 		if (!org_gnome_evolution_dataserver_calendar_Cal_open (priv->proxy, only_if_exists, username ? username : "", password ? password : "", error))
 			*status = E_CALENDAR_STATUS_CORBA_EXCEPTION;
 	} else {
@@ -1071,9 +1073,12 @@ open_calendar (ECal *ecal, gboolean only_if_exists, GError **error, ECalendarSta
 	if (*status == E_CALENDAR_STATUS_OK) {
 		GError *error = NULL;
 		priv->load_state = E_CAL_LOAD_LOADED;
-		org_gnome_evolution_dataserver_calendar_Cal_is_read_only (priv->proxy, &error);
-	} else
+
+		if (!async)
+			org_gnome_evolution_dataserver_calendar_Cal_is_read_only (priv->proxy, &error);
+	} else {
 		priv->load_state = E_CAL_LOAD_NOT_LOADED;
+	}
 
 	E_CALENDAR_CHECK_STATUS (*status, error);
 }
diff --git a/calendar/libedata-cal/e-data-cal-factory.c b/calendar/libedata-cal/e-data-cal-factory.c
index f6ed9db..d0a9993 100644
--- a/calendar/libedata-cal/e-data-cal-factory.c
+++ b/calendar/libedata-cal/e-data-cal-factory.c
@@ -37,6 +37,7 @@
 #include "libedataserver/e-source.h"
 #include "libedataserver/e-source-list.h"
 #include "libebackend/e-data-server-module.h"
+#include <libebackend/e-offline-listener.h>
 #include "libecal/e-cal.h"
 #include "e-cal-backend.h"
 #include "e-cal-backend-factory.h"
@@ -397,7 +398,7 @@ impl_CalFactory_getCal (EDataCalFactory		*factory,
 
 	path = construct_cal_factory_path ();
 	dbus_g_connection_register_g_object (connection, path, G_OBJECT (calendar));
-	g_object_weak_ref (G_OBJECT (calendar), (GWeakNotify)my_remove, g_strdup (path));
+	g_object_weak_ref (G_OBJECT (calendar), (GWeakNotify)my_remove, path);
 
 	g_hash_table_insert (priv->calendars, g_strdup (path), calendar);
 
@@ -647,6 +648,16 @@ die (const char *prefix, GError *error)
 	exit(1);
 }
 
+static void
+offline_state_changed_cb (EOfflineListener *eol, EDataCalFactory *factory)
+{
+	EOfflineListenerState state = e_offline_listener_get_state (eol);
+
+	g_return_if_fail (state == EOL_STATE_ONLINE || state == EOL_STATE_OFFLINE);
+
+	e_data_cal_factory_set_backend_mode (factory, state == EOL_STATE_ONLINE ? GNOME_Evolution_Calendar_MODE_REMOTE : GNOME_Evolution_Calendar_MODE_LOCAL);
+}
+
 #define E_DATA_CAL_FACTORY_SERVICE_NAME "org.gnome.evolution.dataserver.Calendar"
 
 int
@@ -655,6 +666,7 @@ main (gint argc, gchar **argv)
 	GError *error = NULL;
 	DBusGProxy *bus_proxy;
 	guint32 request_name_ret;
+	EOfflineListener *eol;
 
 	g_type_init ();
 	if (!g_thread_supported ()) g_thread_init (NULL);
@@ -690,10 +702,16 @@ main (gint argc, gchar **argv)
 		exit (1);
 	}
 
+	eol = e_offline_listener_new ();
+	offline_state_changed_cb (eol, factory);
+	g_signal_connect (eol, "changed", G_CALLBACK (offline_state_changed_cb), factory);
+
 	g_main_loop_run (loop);
 
 	dbus_g_connection_unref (connection);
 
+	g_object_unref (eol);
+
 	printf ("Bye.\n");
 
 	return 0;
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index 208a15a..e5af4af 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -267,10 +267,6 @@ void
 camel_folder_construct (CamelFolder *folder, CamelStore *parent_store,
 			const gchar *full_name, const gchar *name)
 {
-	gchar *store_db_path;
-	CamelService *service = (CamelService *) parent_store;
-	CamelException ex;
-
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 	g_return_if_fail (CAMEL_IS_STORE (parent_store));
 	g_return_if_fail (folder->parent_store == NULL);
diff --git a/configure.ac b/configure.ac
index 8f51cbb..8cc1d3f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1402,7 +1402,7 @@ EVO_SET_COMPILE_FLAGS(E_DATA_SERVER_UI, $E_DATA_SERVER_UI_DEPS, $THREADS_CFLAGS,
 AC_SUBST(E_DATA_SERVER_UI_CFLAGS)
 AC_SUBST(E_DATA_SERVER_UI_LIBS)
 
-E_BACKEND_DEPS="gobject-2.0 libxml-2.0 gmodule-2.0"
+E_BACKEND_DEPS="gobject-2.0 libxml-2.0 gmodule-2.0 gconf-2.0"
 
 dnl ******************************
 dnl libebackend flags
diff --git a/libebackend/Makefile.am b/libebackend/Makefile.am
index 4cc55c1..e2ff4e0 100644
--- a/libebackend/Makefile.am
+++ b/libebackend/Makefile.am
@@ -10,6 +10,7 @@ libebackend_1_2_la_CPPFLAGS = \
 
 libebackend_1_2_la_SOURCES =		\
 	e-data-server-module.c		\
+	e-offline-listener.c		\
 	e-dbhash.c			\
 	e-db3-utils.c			\
 	e-file-cache.c
@@ -26,6 +27,7 @@ libebackendincludedir = $(privincludedir)/libebackend
 
 libebackendinclude_HEADERS =		\
 	e-data-server-module.h		\
+	e-offline-listener.h		\
 	e-db3-utils.h			\
 	e-dbhash.h			\
 	e-file-cache.h
diff --git a/addressbook/libedata-book/offline-listener.c b/libebackend/e-offline-listener.c
similarity index 51%
rename from addressbook/libedata-book/offline-listener.c
rename to libebackend/e-offline-listener.c
index f52b889..136a71f 100644
--- a/addressbook/libedata-book/offline-listener.c
+++ b/libebackend/e-offline-listener.c
@@ -20,44 +20,39 @@
  * Author: Sivaiah Nallagatla <snallagatla novell com>
  */
 
-/*Note : Copied from src/offline_listner.c . This should be replaced */
+/*Note : Copied from src/offline_listener.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 "e-offline-listener.h"
 #include <gconf/gconf-client.h>
 
 enum {
-
-	OFFLINE_MODE=0,
-	ONLINE_MODE
+	CHANGED,
+	NUM_SIGNALS
 };
 
+static guint signals[NUM_SIGNALS] = { 0 };
+
 static GObjectClass *parent_class = NULL;
 
-struct _OfflineListenerPrivate
+struct _EOfflineListenerPrivate
 {
 	GConfClient *default_client;
-
-	EDataBookFactory *book_factory;
-
 	gboolean is_offline_now;
 };
 
-
 static void
-set_online_status (OfflineListener *offline_listener, gboolean is_offline)
+set_online_status (EOfflineListener *eol, gboolean is_offline)
 {
-	OfflineListenerPrivate *priv;
+	EOfflineListenerPrivate *priv;
 
-	priv = offline_listener->priv;
+	priv = eol->priv;
 
-	e_data_book_factory_set_backend_mode
-		(priv->book_factory, is_offline ? OFFLINE_MODE : ONLINE_MODE);
+	g_signal_emit (eol, signals[CHANGED], 0);
 }
 
 static void
@@ -65,119 +60,135 @@ online_status_changed (GConfClient *client, gint cnxn_id, GConfEntry *entry, gpo
 {
 	GConfValue *value;
 	gboolean offline;
-        OfflineListener *offline_listener;
-	OfflineListenerPrivate *priv;
+        EOfflineListener *eol;
+	EOfflineListenerPrivate *priv;
 
-	offline_listener = OFFLINE_LISTENER(data);
-	priv = offline_listener->priv;
+	eol = E_OFFLINE_LISTENER (data);
+	g_return_if_fail (eol != NULL);
+
+	priv = eol->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);
-	}
 
+		set_online_status (eol, offline);
+	}
 }
 
 
 static void
-setup_offline_listener (OfflineListener *offline_listener)
+setup_offline_listener (EOfflineListener *eol)
 {
-	OfflineListenerPrivate *priv = offline_listener->priv;
+	EOfflineListenerPrivate *priv = eol->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);
+				 eol, 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);
+	set_online_status (eol, priv->is_offline_now);
 }
 
-OfflineListener*
-offline_listener_new (EDataBookFactory *book_factory)
+EOfflineListener*
+e_offline_listener_new (void)
 {
-	OfflineListener *offline_listener = g_object_new (OFFLINE_TYPE_LISTENER, NULL);
-	OfflineListenerPrivate *priv = offline_listener->priv;
+	EOfflineListener *eol = g_object_new (E_TYPE_OFFLINE_LISTENER, NULL);
 
-	priv->book_factory = book_factory;
-	setup_offline_listener (offline_listener);
-	return offline_listener;
+	setup_offline_listener (eol);
 
+	return eol;
 }
 
-
 static void
-offline_listener_dispose (GObject *object)
+eol_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;
+	EOfflineListener *eol = E_OFFLINE_LISTENER (object);
+	if (eol->priv->default_client) {
+		g_object_unref (eol->priv->default_client);
+		eol->priv->default_client = NULL;
 	}
+
 	(* G_OBJECT_CLASS (parent_class)->dispose) (object);
 }
 
 static void
-offline_listener_finalize (GObject *object)
+eol_finalize (GObject *object)
 {
-	OfflineListener *offline_listener;
-	OfflineListenerPrivate *priv;
+	EOfflineListener *eol;
+	EOfflineListenerPrivate *priv;
 
-	offline_listener = OFFLINE_LISTENER (object);
-	priv = offline_listener->priv;
+	eol = E_OFFLINE_LISTENER (object);
+	priv = eol->priv;
 
 	g_free (priv);
-	offline_listener->priv = NULL;
+	eol->priv = NULL;
 
 	parent_class->finalize (object);
 }
 
 static void
-offline_listener_init (OfflineListener *listener)
+eol_init (EOfflineListener *eol)
 {
-	OfflineListenerPrivate *priv;
-
-	priv =g_new0 (OfflineListenerPrivate, 1);
-	listener->priv = priv;
+	EOfflineListenerPrivate *priv;
 
+	priv = g_new0 (EOfflineListenerPrivate, 1);
+	eol->priv = priv;
 }
 
-
-
 static void
-offline_listener_class_init (OfflineListener *klass)
+eol_class_init (EOfflineListenerClass *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;
+	object_class->dispose = eol_dispose;
+	object_class->finalize = eol_finalize;
+	
+	signals[CHANGED] =
+		g_signal_new ("changed",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (EOfflineListenerClass, changed),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE, 0);
 }
 
 GType
-offline_listener_get_type (void)
+e_offline_listener_get_type (void)
 {
 	static GType type = 0;
 
 	if (!type) {
 		static GTypeInfo info = {
-                        sizeof (OfflineListenerClass),
+                        sizeof (EOfflineListenerClass),
                         (GBaseInitFunc) NULL,
                         (GBaseFinalizeFunc) NULL,
-                        (GClassInitFunc) offline_listener_class_init,
+                        (GClassInitFunc) eol_class_init,
                         NULL, NULL,
-                        sizeof (OfflineListener),
+                        sizeof (EOfflineListener),
                         0,
-                        (GInstanceInitFunc) offline_listener_init,
+                        (GInstanceInitFunc) eol_init,
                 };
-		type = g_type_register_static (G_TYPE_OBJECT, "OfflineListener", &info, 0);
+
+		type = g_type_register_static (G_TYPE_OBJECT, "EOfflineListener", &info, 0);
 	}
 
 	return type;
 }
+
+EOfflineListenerState
+e_offline_listener_get_state (EOfflineListener *eol)
+{
+	g_return_val_if_fail (E_IS_OFFLINE_LISTENER (eol), EOL_STATE_OFFLINE);
+
+	return eol->priv->is_offline_now ? EOL_STATE_OFFLINE : EOL_STATE_ONLINE;
+}
diff --git a/libebackend/e-offline-listener.h b/libebackend/e-offline-listener.h
new file mode 100644
index 0000000..007d57b
--- /dev/null
+++ b/libebackend/e-offline-listener.h
@@ -0,0 +1,69 @@
+/* -*- 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 _E_OFFLINE_LISTENER_H_
+#define _E_OFFLINE_LISTENER_H_
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define E_TYPE_OFFLINE_LISTENER			(e_offline_listener_get_type ())
+#define E_OFFLINE_LISTENER(obj)			((G_TYPE_CHECK_INSTANCE_CAST((obj), E_TYPE_OFFLINE_LISTENER, EOfflineListener)))
+#define E_OFFLINE_LISTENER_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass), E_TYPE_OFFLINE_LISTENER, EOfflineListenerClass))
+#define E_IS_OFFLINE_LISTENER(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_OFFLINE_LISTENER))
+#define E_IS_OFFLINE_LISTENER_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((obj), E_TYPE_OFFLINE_LISTENER))
+
+typedef struct _EOfflineListener         EOfflineListener;
+typedef struct _EOfflineListenerPrivate  EOfflineListenerPrivate;
+typedef struct _EOfflineListenerClass    EOfflineListenerClass;
+
+typedef enum {
+	EOL_STATE_OFFLINE = 0,
+	EOL_STATE_ONLINE = 1
+} EOfflineListenerState;
+	
+
+struct _EOfflineListener {
+	GObject parent;
+	EOfflineListenerPrivate *priv;
+};
+
+struct _EOfflineListenerClass {
+	GObjectClass  parent_class;
+
+	void (*changed) (EOfflineListener *eol, EOfflineListenerState state);
+};
+
+GType e_offline_listener_get_type  (void);
+
+EOfflineListener  *e_offline_listener_new (void);
+
+EOfflineListenerState e_offline_listener_get_state (EOfflineListener *eol);
+
+G_END_DECLS
+
+#endif /* _E_OFFLINE_LISTENER_H_ */



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