1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* server-interface-check.h
4 * Copyright (C) 2004 Novell, Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
20 * Author: Sivaiah Nallagatla <snallagatla@novell.com>
27 #include "offline-listener.h"
28 #include <libedata-book/e-data-book-factory.h>
30 #include <libedata-cal/e-data-cal-factory.h>
32 #include <gconf/gconf-client.h>
40 static GObjectClass *parent_class = NULL;
42 struct _OfflineListenerPrivate
44 GConfClient *default_client;
47 EDataCalFactory *cal_factory;
49 EDataBookFactory *book_factory;
50 gboolean is_offline_now;
55 set_online_status (OfflineListener *offline_listener, gboolean is_offline)
57 OfflineListenerPrivate *priv;
59 priv = offline_listener->priv;
62 e_data_cal_factory_set_backend_mode
63 (priv->cal_factory, is_offline ? OFFLINE_MODE : ONLINE_MODE);
65 e_data_book_factory_set_backend_mode
66 (priv->book_factory, is_offline ? OFFLINE_MODE : ONLINE_MODE);
70 online_status_changed (GConfClient *client, int cnxn_id, GConfEntry *entry, gpointer data)
74 OfflineListener *offline_listener;
75 OfflineListenerPrivate *priv;
77 offline_listener = OFFLINE_LISTENER(data);
78 priv = offline_listener->priv;
80 value = gconf_entry_get_value (entry);
82 offline = gconf_value_get_bool (value);
83 if (priv->is_offline_now != offline) {
84 priv->is_offline_now = offline;
85 set_online_status (offline_listener ,offline);
92 setup_offline_listener (OfflineListener *offline_listener)
94 OfflineListenerPrivate *priv = offline_listener->priv;
96 priv->default_client = gconf_client_get_default ();
97 gconf_client_add_dir (priv->default_client, "/apps/evolution/shell", GCONF_CLIENT_PRELOAD_RECURSIVE,NULL);
98 gconf_client_notify_add (priv->default_client, "/apps/evolution/shell/start_offline", (GConfClientNotifyFunc)online_status_changed, offline_listener, NULL, NULL);
99 priv->is_offline_now = gconf_client_get_bool (priv->default_client, "/apps/evolution/shell/start_offline", NULL);
100 set_online_status (offline_listener, priv->is_offline_now);
105 offline_listener_new (EDataBookFactory *book_factory, EDataCalFactory *cal_factory)
108 offline_listener_new (EDataBookFactory *book_factory)
111 OfflineListener *offline_listener = g_object_new (OFFLINE_TYPE_LISTENER, NULL);
112 OfflineListenerPrivate *priv = offline_listener->priv;
114 priv->book_factory = book_factory;
116 priv->cal_factory = cal_factory;
118 setup_offline_listener (offline_listener);
119 return offline_listener;
125 offline_listener_dispose (GObject *object)
127 OfflineListener *offline_listener = OFFLINE_LISTENER (object);
128 if (offline_listener->priv->default_client) {
129 g_object_unref (offline_listener->priv->default_client);
130 offline_listener->priv->default_client = NULL;
132 (* G_OBJECT_CLASS (parent_class)->dispose) (object);
136 offline_listener_finalize (GObject *object)
138 OfflineListener *offline_listener;
139 OfflineListenerPrivate *priv;
141 offline_listener = OFFLINE_LISTENER (object);
142 priv = offline_listener->priv;
145 offline_listener->priv = NULL;
147 parent_class->finalize (object);
151 offline_listener_init (OfflineListener *listener)
153 OfflineListenerPrivate *priv;
155 priv =g_new0 (OfflineListenerPrivate, 1);
156 listener->priv = priv;
163 offline_listener_class_init (OfflineListener *klass)
165 GObjectClass *object_class;
167 parent_class = g_type_class_peek_parent (klass);
169 object_class = G_OBJECT_CLASS (klass);
170 object_class->dispose = offline_listener_dispose;
171 object_class->finalize = offline_listener_finalize;
179 offline_listener_get_type (void)
181 static GType type = 0;
184 static GTypeInfo info = {
185 sizeof (OfflineListenerClass),
186 (GBaseInitFunc) NULL,
187 (GBaseFinalizeFunc) NULL,
188 (GClassInitFunc) offline_listener_class_init,
190 sizeof (OfflineListener),
192 (GInstanceInitFunc) offline_listener_init,
194 type = g_type_register_static (G_TYPE_OBJECT, "OfflineListener", &info, 0);