summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSivaiah Nallagatla <siva@src.gnome.org>2004-12-23 17:45:16 +0000
committerSivaiah Nallagatla <siva@src.gnome.org>2004-12-23 17:45:16 +0000
commite6e9e37a0c1c7455f13a08d32b22c042e62b4a2f (patch)
treeecb8571dc97eb1e84563e95804088db4611e58d6 /src
parent45c21b4ed05021fe0b6a2675edd03a046a69afce (diff)
downloadevolution-data-server-e6e9e37a0c1c7455f13a08d32b22c042e62b4a2f.tar.gz
merge from e-d-s offline brnach
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/offline-listener.c192
-rw-r--r--src/offline-listener.h64
-rw-r--r--src/server.c15
4 files changed, 270 insertions, 5 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index eca731e73..2c1028d6d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,7 +47,9 @@ evolution_data_server_SOURCES = \
server-interface-check.h \
server-logging.c \
server-logging.h \
- server.c
+ server.c \
+ offline-listener.c \
+ offline-listener.h
evolution_data_server_LDADD = \
$(top_builddir)/addressbook/libedata-book/libedata-book-1.2.la \
diff --git a/src/offline-listener.c b/src/offline-listener.c
new file mode 100644
index 000000000..799d14a91
--- /dev/null
+++ b/src/offline-listener.c
@@ -0,0 +1,192 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* server-interface-check.h
+ *
+ * Copyright (C) 2004 Novell, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU 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 General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Sivaiah Nallagatla <snallagatla@novell.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "offline-listener.h"
+#include <libedata-book/e-data-book-factory.h>
+#include <libedata-cal/e-data-cal-factory.h>
+#include <gconf/gconf-client.h>
+
+enum {
+
+ OFFLINE_MODE=1,
+ ONLINE_MODE
+};
+
+static GObjectClass *parent_class = NULL;
+
+struct _OfflineListenerPrivate
+{
+ GConfClient *default_client;
+ EDataCalFactory *cal_factory;
+ EDataBookFactory *book_factory;
+ gboolean is_offline_now;
+};
+
+
+static void
+set_online_status (OfflineListener *offline_listener, gboolean is_offline)
+{
+ OfflineListenerPrivate *priv;
+
+ priv = offline_listener->priv;
+
+ if (is_offline) {
+ e_data_cal_factory_set_backend_mode (priv->cal_factory, OFFLINE_MODE);
+ e_data_book_factory_set_backend_mode (priv->book_factory, OFFLINE_MODE);
+
+ } else {
+ e_data_cal_factory_set_backend_mode (priv->cal_factory, ONLINE_MODE);
+ e_data_book_factory_set_backend_mode (priv->book_factory, ONLINE_MODE);
+ }
+
+}
+static void
+online_status_changed (GConfClient *client, int 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;
+ GConfValue *value;
+
+ 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);
+ value = gconf_client_get (priv->default_client, "/apps/evolution/shell/start_offline", NULL);
+ priv->is_offline_now = gconf_value_get_bool (value);
+ set_online_status (offline_listener, priv->is_offline_now);
+
+
+}
+
+OfflineListener*
+offline_listener_new (EDataBookFactory *book_factory, EDataCalFactory *cal_factory)
+{
+ OfflineListener *offline_listener = g_object_new (OFFLINE_TYPE_LISTENER, NULL);
+ OfflineListenerPrivate *priv = offline_listener->priv;
+
+ priv->book_factory = book_factory;
+ priv->cal_factory = cal_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/src/offline-listener.h b/src/offline-listener.h
new file mode 100644
index 000000000..af6ac002c
--- /dev/null
+++ b/src/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) 2004 Novell, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU 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 General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, 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>
+#include <libedata-cal/e-data-cal-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 *book_factory, EDataCalFactory *cal_factory);
+
+G_END_DECLS
+
+#endif /* _OFFLINE_LISTNER_H_ */
diff --git a/src/server.c b/src/server.c
index 635a0ccb2..bb895d8a4 100644
--- a/src/server.c
+++ b/src/server.c
@@ -41,6 +41,7 @@
#include <bonobo/bonobo-i18n.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-generic-factory.h>
+#include <gconf/gconf-client.h>
#include <libedataserver/e-data-server-module.h>
#include <libedata-book/e-data-book-factory.h>
@@ -48,6 +49,7 @@
#include "server-interface-check.h"
#include "server-logging.h"
+#include "offline-listener.h"
#define E_DATA_SERVER_INTERFACE_CHECK_OAF_ID "OAFIID:GNOME_Evolution_DataServer_InterfaceCheck"
#define E_DATA_SERVER_LOGGING_OAF_ID "OAFIID:GNOME_Evolution_DataServer_Logging"
@@ -134,6 +136,7 @@ setup_segv_handler (void)
static gboolean
termination_handler (gpointer data)
{
+
if (e_data_cal_factory_get_n_backends (e_data_cal_factory) == 0 &&
e_data_book_factory_get_n_backends (e_data_book_factory) == 0) {
g_message ("termination_handler(): Terminating the Server. Have a nice day.");
@@ -269,7 +272,6 @@ setup_interface_check (void)
}
-
#ifdef DEBUG_BACKENDS
static void
dump_backends (int signal)
@@ -283,7 +285,8 @@ int
main (int argc, char **argv)
{
gboolean did_books=FALSE, did_cals=FALSE;
-
+ OfflineListener *offline_listener = NULL;
+
bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
@@ -333,16 +336,20 @@ main (int argc, char **argv)
exit (EXIT_FAILURE);
}
+
+ offline_listener = offline_listener_new (e_data_book_factory, e_data_cal_factory);
+
if ( setup_logging ()) {
if ( setup_interface_check ()) {
g_message ("Server up and running");
-
+
bonobo_main ();
} else
g_error (G_STRLOC "Cannot register DataServer::InterfaceCheck object");
} else
g_error (G_STRLOC "Cannot register DataServer::Logging object");
+ g_object_unref (offline_listener);
bonobo_object_unref (BONOBO_OBJECT (e_data_cal_factory));
e_data_cal_factory = NULL;
@@ -354,7 +361,7 @@ main (int argc, char **argv)
bonobo_object_unref (BONOBO_OBJECT (interface_check_iface));
interface_check_iface = NULL;
-
+
gnome_vfs_shutdown ();
return 0;