[evolution-patches] Network Manager support
- From: Shreyas Srinivasan <sshreyas novell com>
- To: evolution-patches gnome org
- Subject: [evolution-patches] Network Manager support
- Date: Wed, 21 Dec 2005 12:47:17 +0530
Hey,
Attaching updated patches of network manager which have went through
a couple of revisions since i last sent it. This fixes a few issues
in the handling of disconnect in the camel code and also fixes
a few configure bugs,
Please review
--
Shreyas
? camel-mime-tables.c
? nm-camel-20.diff
? providers/hula/Makefile
? providers/hula/Makefile.in
Index: camel-disco-store.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-disco-store.c,v
retrieving revision 1.17
diff -u -p -r1.17 camel-disco-store.c
--- camel-disco-store.c 18 Nov 2005 05:55:34 -0000 1.17
+++ camel-disco-store.c 21 Dec 2005 06:52:12 -0000
@@ -296,6 +296,8 @@ static void
set_status(CamelDiscoStore *disco_store, CamelDiscoStoreStatus status, CamelException *ex)
{
CamelException x;
+ CamelService *service = CAMEL_SERVICE (disco_store);
+ gboolean network_state = camel_session_get_network_state (service->session);
if (disco_store->status == status)
return;
@@ -303,32 +305,36 @@ set_status(CamelDiscoStore *disco_store,
camel_exception_init(&x);
/* Sync the folder fully if we've been told to sync online for this store or this folder
and we're going offline */
- if (disco_store->status == CAMEL_DISCO_STORE_ONLINE
- && status == CAMEL_DISCO_STORE_OFFLINE) {
- if (((CamelStore *)disco_store)->folders) {
- GPtrArray *folders;
- CamelFolder *folder;
- int i, sync;
-
- sync = camel_url_get_param(((CamelService *)disco_store)->url, "offline_sync") != NULL;
- folders = camel_object_bag_list(((CamelStore *)disco_store)->folders);
- for (i=0;i<folders->len;i++) {
- folder = folders->pdata[i];
- if (CAMEL_CHECK_TYPE(folder, CAMEL_DISCO_FOLDER_TYPE)
- && (sync || ((CamelDiscoFolder *)folder)->offline_sync)) {
- camel_disco_folder_prepare_for_offline((CamelDiscoFolder *)folder, "(match-all)", &x);
- camel_exception_clear(&x);
+ if (network_state) {
+ if (disco_store->status == CAMEL_DISCO_STORE_ONLINE
+ && status == CAMEL_DISCO_STORE_OFFLINE) {
+ if (((CamelStore *)disco_store)->folders) {
+ GPtrArray *folders;
+ CamelFolder *folder;
+ int i, sync;
+
+ sync = camel_url_get_param(((CamelService *)disco_store)->url, "offline_sync") != NULL;
+
+ folders = camel_object_bag_list(((CamelStore *)disco_store)->folders);
+ for (i=0;i<folders->len;i++) {
+ folder = folders->pdata[i];
+ if (CAMEL_CHECK_TYPE(folder, CAMEL_DISCO_FOLDER_TYPE)
+ && (sync || ((CamelDiscoFolder *)folder)->offline_sync)) {
+ camel_disco_folder_prepare_for_offline((CamelDiscoFolder *)folder, "(match-all)", &x);
+ camel_exception_clear(&x);
+ }
+ camel_object_unref(folder);
}
- camel_object_unref(folder);
+ g_ptr_array_free(folders, TRUE);
}
- g_ptr_array_free(folders, TRUE);
}
+
+ camel_store_sync(CAMEL_STORE (disco_store), FALSE, &x);
+ camel_exception_clear(&x);
}
-
- camel_store_sync(CAMEL_STORE (disco_store), FALSE, &x);
- camel_exception_clear(&x);
- if (!camel_service_disconnect (CAMEL_SERVICE (disco_store), TRUE, ex))
+
+ if (!camel_service_disconnect (CAMEL_SERVICE (disco_store), network_state, ex))
return;
disco_store->status = status;
Index: camel-offline-store.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-offline-store.c,v
retrieving revision 1.5
diff -u -p -r1.5 camel-offline-store.c
--- camel-offline-store.c 6 Dec 2005 04:21:54 -0000 1.5
+++ camel-offline-store.c 21 Dec 2005 06:52:12 -0000
@@ -114,46 +114,53 @@ void
camel_offline_store_set_network_state (CamelOfflineStore *store, int state, CamelException *ex)
{
CamelException lex;
-
+ CamelService *service = CAMEL_SERVICE (store);
+ gboolean network_state = camel_session_get_network_state (service->session);
+
if (store->state == state)
return;
camel_exception_init (&lex);
if (store->state == CAMEL_OFFLINE_STORE_NETWORK_AVAIL) {
/* network available -> network unavailable */
- if (((CamelStore *) store)->folders) {
- GPtrArray *folders;
- CamelFolder *folder;
- int i, sync;
-
- sync = camel_url_get_param (((CamelService *) store)->url, "sync_offline") != NULL;
-
- folders = camel_object_bag_list (((CamelStore *) store)->folders);
- for (i = 0; i < folders->len; i++) {
- folder = folders->pdata[i];
+ if (network_state) {
+ if (((CamelStore *) store)->folders) {
+ GPtrArray *folders;
+ CamelFolder *folder;
+ int i, sync;
+
+ sync = camel_url_get_param (((CamelService *) store)->url, "sync_offline") != NULL;
- if (CAMEL_CHECK_TYPE (folder, CAMEL_OFFLINE_FOLDER_TYPE)
- && (sync || ((CamelOfflineFolder *) folder)->sync_offline)) {
- camel_offline_folder_downsync ((CamelOfflineFolder *) folder, NULL, &lex);
- camel_exception_clear (&lex);
+ folders = camel_object_bag_list (((CamelStore *) store)->folders);
+ for (i = 0; i < folders->len; i++) {
+ folder = folders->pdata[i];
+
+ if (CAMEL_CHECK_TYPE (folder, CAMEL_OFFLINE_FOLDER_TYPE)
+ && (sync || ((CamelOfflineFolder *) folder)->sync_offline)) {
+ camel_offline_folder_downsync ((CamelOfflineFolder *) folder, NULL, &lex);
+ camel_exception_clear (&lex);
+ }
+
+ camel_object_unref (folder);
}
- camel_object_unref (folder);
+ g_ptr_array_free (folders, TRUE);
}
- g_ptr_array_free (folders, TRUE);
+ camel_store_sync (CAMEL_STORE (store), FALSE, &lex);
+ camel_exception_clear (&lex);
}
-
- camel_store_sync (CAMEL_STORE (store), FALSE, &lex);
- camel_exception_clear (&lex);
-
- if (!camel_service_disconnect (CAMEL_SERVICE (store), TRUE, ex))
+
+ if (!camel_service_disconnect (CAMEL_SERVICE (store), network_state, ex))
return;
} else {
/* network unavailable -> network available */
if (!camel_service_connect (CAMEL_SERVICE (store), ex))
return;
+ fprintf (stderr, "i hit this boo wtf\n");
}
+ if (store->state == CAMEL_OFFLINE_STORE_NETWORK_AVAIL)
+ fprintf (stderr,"I do my job well\n");
store->state = state;
}
Index: camel-session.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-session.c,v
retrieving revision 1.114
diff -u -p -r1.114 camel-session.c
--- camel-session.c 14 Dec 2005 13:15:22 -0000 1.114
+++ camel-session.c 21 Dec 2005 06:52:12 -0000
@@ -68,6 +68,7 @@ static void
camel_session_init (CamelSession *session)
{
session->online = TRUE;
+ session->network_state = TRUE;
session->priv = g_malloc0(sizeof(*session->priv));
session->priv->lock = g_mutex_new();
@@ -678,4 +679,20 @@ camel_session_set_check_junk (CamelSessi
g_assert(CAMEL_IS_SESSION(session));
session->check_junk = check_junk;
+}
+
+gboolean
+camel_session_get_network_state (CamelSession *session)
+{
+ g_return_if_fail (CAMEL_IS_SESSION(session));
+
+ return session->network_state;
+}
+
+void
+camel_session_set_network_state (CamelSession *session, gboolean network_state)
+{
+ g_return_if_fail (CAMEL_IS_SESSION(session));
+
+ session->network_state = network_state;
}
Index: camel-session.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-session.h,v
retrieving revision 1.52
diff -u -p -r1.52 camel-session.h
--- camel-session.h 31 Aug 2005 04:21:56 -0000 1.52
+++ camel-session.h 21 Dec 2005 06:52:12 -0000
@@ -68,6 +68,7 @@ struct _CamelSession
gboolean online:1;
gboolean check_junk:1;
+ gboolean network_state:1;
};
typedef struct _CamelSessionThreadOps CamelSessionThreadOps;
@@ -193,7 +194,8 @@ void *camel_session_thread_msg_new(Camel
void camel_session_thread_msg_free(CamelSession *session, CamelSessionThreadMsg *msg);
int camel_session_thread_queue(CamelSession *session, CamelSessionThreadMsg *msg, int flags);
void camel_session_thread_wait(CamelSession *session, int id);
-
+gboolean camel_session_get_network_state (CamelSession *session);
+void camel_session_set_network_state (CamelSession *session, gboolean network_state);
#ifdef __cplusplus
}
#endif /* __cplusplus */
Index: configure.in
===================================================================
RCS file: /cvs/gnome/evolution/configure.in,v
retrieving revision 1.863
diff -u -p -w -r1.863 configure.in
--- configure.in 17 Dec 2005 10:01:08 -0000 1.863
+++ configure.in 21 Dec 2005 06:46:27 -0000
@@ -1195,7 +1195,28 @@ AC_SUBST(LIBFILTER_LIBS)
dnl --- evolution (shell) flags
-EVO_SET_COMPILE_FLAGS(SHELL, libgnome-2.0 libgnomeui-2.0 libbonoboui-2.0 >= $BONOBOUI_REQUIRED libglade-2.0 gnome-vfs-2.0 libgtkhtml-$GTKHTML_PACKAGE >= $GTKHTML_REQUIRED)
+NM_SUPPORT_PACKAGES=""
+
+PKG_CHECK_MODULES(NM, dbus-glib-1 libnm_glib, NM_SUPPORT_GLIB="yes", NM_SUPPORT_GLIB="no")
+if test "x$NM_SUPPORT_GLIB" = "xyes"; then
+ AC_DEFINE(NM_SUPPORT_GLIB, 1, [network manager available])
+ NM_SUPPORT_PACKAGES="dbus-1 dbus-glib-1 libnm_glib"
+else
+ PKG_CHECK_MODULES(NM, dbus-glib-1, NM_SUPPORT="yes", NM_SUPPORT="no")
+ AC_CHECK_HEADER(NetworkManager/NetworkManager.h, [ nm_header="yes" ] )
+if test "x$NM_SUPPORT" = "xyes" -a "x{nm_header}" != "x"; then
+dnl if test "x$NM_SUPPORT" = "xyes"; then
+ AC_DEFINE(NM_SUPPORT, 1, [network manager available])
+ NM_SUPPORT_PACKAGES="dbus-1 dbus-glib-1"
+ fi
+fi
+
+AM_CONDITIONAL(NM_SUPPORT_GLIB, test x$NM_SUPPORT_GLIB = xyes)
+AM_CONDITIONAL(NM_SUPPORT, test x$NM_SUPPORT = xyes)
+
+
+EVO_SET_COMPILE_FLAGS(SHELL, libgnome-2.0 libgnomeui-2.0 libbonoboui-2.0 >= $BONOBOUI_REQUIRED libglade-2.0 gnome-vfs-2.0 libgtkhtml-$GTKHTML_PACKAGE >= $GTKHTML_REQUIRED $NM_SUPPORT_PACKAGES)
+
AC_SUBST(SHELL_CFLAGS)
AC_SUBST(SHELL_LIBS)
Index: mail/mail-component.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-component.c,v
retrieving revision 1.126
diff -u -p -w -r1.126 mail-component.c
--- mail/mail-component.c 18 Dec 2005 08:24:26 -0000 1.126
+++ mail/mail-component.c 21 Dec 2005 06:46:27 -0000
@@ -72,6 +72,7 @@
#include <gtk/gtklabel.h>
#include <e-util/e-mktemp.h>
+#include <Evolution.h>
#include <table/e-tree.h>
#include <table/e-tree-memory.h>
@@ -94,6 +95,9 @@ static void create_local_item_cb(EUserCr
#define PARENT_TYPE evolution_component_get_type ()
static BonoboObjectClass *parent_class = NULL;
+#define OFFLINE 0
+#define ONLINE 1
+
struct _store_info {
CamelStore *store;
char *name;
@@ -965,10 +969,36 @@ setline_check(void *key, void *value, vo
}
}
+int
+status_check (GNOME_Evolution_ShellState shell_state)
+{
+ int status;
+
+ switch (shell_state)
+ {
+ case GNOME_Evolution_USER_OFFLINE:
+ status = OFFLINE;
+ break;
+ case GNOME_Evolution_FORCED_OFFLINE:
+ /*Network is down so change network state on the camel session*/
+ status = OFFLINE;
+ /* Cancel all operations as they wont happen anyway cos Network is down*/
+ mail_cancel_all ();
+ camel_session_set_network_state (session, FALSE);
+ break;
+ case GNOME_Evolution_USER_ONLINE:
+ camel_session_set_network_state (session, TRUE);
+ status = ONLINE;
+ }
+
+ return status;
+}
+
static void
-impl_setLineStatus(PortableServer_Servant servant, CORBA_boolean status, GNOME_Evolution_Listener listener, CORBA_Environment *ev)
+impl_setLineStatus(PortableServer_Servant servant, GNOME_Evolution_ShellState shell_state, GNOME_Evolution_Listener listener, CORBA_Environment *ev)
{
struct _setline_data *sd;
+ int status = status_check(shell_state);
/* This will dis/enable further auto-mail-check action. */
/* FIXME: If send/receive active, wait for it to finish? */
Index: mail/mail-component.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-component.h,v
retrieving revision 1.15
diff -u -p -w -r1.15 mail-component.h
--- mail/mail-component.h 2 Jun 2005 04:30:16 -0000 1.15
+++ mail/mail-component.h 21 Dec 2005 06:46:27 -0000
@@ -98,4 +98,5 @@ struct _CamelStore *mail_component_peek_
struct _CamelFolder *mail_component_get_folder(MailComponent *mc, enum _mail_component_folder_t id);
const char *mail_component_get_folder_uri(MailComponent *mc, enum _mail_component_folder_t id);
+int status_check (GNOME_Evolution_ShellState shell_state);
#endif /* _MAIL_COMPONENT_H_ */
Index: shell/Evolution-Component.idl
===================================================================
RCS file: /cvs/gnome/evolution/shell/Evolution-Component.idl,v
retrieving revision 1.18
diff -u -p -w -r1.18 Evolution-Component.idl
--- shell/Evolution-Component.idl 18 Aug 2005 04:35:30 -0000 1.18
+++ shell/Evolution-Component.idl 21 Dec 2005 06:46:28 -0000
@@ -28,6 +28,11 @@ module Evolution {
CREATABLE_OBJECT,
CREATABLE_FOLDER
};
+ enum ShellState {
+ USER_OFFLINE,
+ FORCED_OFFLINE,
+ USER_ONLINE
+ };
/* A type of item that the component can create when asked by the user,
e.g. a mail message or an appointment. */
@@ -114,7 +119,7 @@ module Evolution {
/* Set the online status of the component asynchronously */
- void setLineStatus(in boolean online, in Listener listener);
+ void setLineStatus(in ShellState shell_state, in Listener listener);
};
};
Index: shell/Makefile.am
===================================================================
RCS file: /cvs/gnome/evolution/shell/Makefile.am,v
retrieving revision 1.212
diff -u -p -w -r1.212 Makefile.am
--- shell/Makefile.am 18 Aug 2005 04:35:30 -0000 1.212
+++ shell/Makefile.am 21 Dec 2005 06:46:28 -0000
@@ -49,6 +49,14 @@ $(IDL_GENERATED_H): $(IDLS)
$(IDL_GENERATED_C): $(IDL_GENERATED_H)
+if NM_SUPPORT_GLIB
+NM_SUPPORT_FILES = e-shell-nm-glib.c
+else
+if NM_SUPPORT
+NM_SUPPORT_FILES = e-shell-nm.c
+endif
+endif
+
# Data Server CORBA stuff
DATASERVER_IDL_GENERATED_H = \
Evolution-DataServer.h
@@ -110,6 +119,7 @@ libeshell_la_LIBADD = \
evolution_SOURCES = \
$(DATASERVER_IDL_GENERATED) \
+ $(NM_SUPPORT_FILES) \
e-component-registry.c \
e-component-registry.h \
e-config-upgrade.c \
Index: shell/e-shell-window-commands.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-shell-window-commands.c,v
retrieving revision 1.44
diff -u -p -w -r1.44 e-shell-window-commands.c
--- shell/e-shell-window-commands.c 18 Dec 2005 04:33:18 -0000 1.44
+++ shell/e-shell-window-commands.c 21 Dec 2005 06:46:28 -0000
@@ -640,7 +640,7 @@ command_work_offline (BonoboUIComponent
EShellWindow *window,
const char *path)
{
- e_shell_go_offline (e_shell_window_peek_shell (window), window);
+ e_shell_go_offline (e_shell_window_peek_shell (window), window, GNOME_Evolution_USER_OFFLINE);
}
static void
@@ -648,7 +648,7 @@ command_work_online (BonoboUIComponent *
EShellWindow *window,
const char *path)
{
- e_shell_go_online (e_shell_window_peek_shell (window), window);
+ e_shell_go_online (e_shell_window_peek_shell (window), window, GNOME_Evolution_USER_ONLINE);
}
static void
Index: shell/e-shell-window.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-shell-window.c,v
retrieving revision 1.41
diff -u -p -w -r1.41 e-shell-window.c
--- shell/e-shell-window.c 18 Dec 2005 04:33:23 -0000 1.41
+++ shell/e-shell-window.c 21 Dec 2005 06:46:28 -0000
@@ -422,10 +422,10 @@ offline_toggle_clicked_callback (GtkButt
switch (e_shell_get_line_status (priv->shell)) {
case E_SHELL_LINE_STATUS_ONLINE:
- e_shell_go_offline (priv->shell, window);
+ e_shell_go_offline (priv->shell, window, GNOME_Evolution_USER_OFFLINE);
break;
case E_SHELL_LINE_STATUS_OFFLINE:
- e_shell_go_online (priv->shell, window);
+ e_shell_go_online (priv->shell, window, GNOME_Evolution_USER_ONLINE);
break;
default:
g_assert_not_reached ();
@@ -556,6 +556,16 @@ setup_statusbar_notebook (EShellWindow *
}
static void
+setup_nm_support (EShellWindow *window)
+{
+ #ifdef NM_SUPPORT_GLIB
+ e_shell_nm_glib_initialise (window);
+ #elif NM_SUPPORT
+ e_shell_dbus_initialise (window);
+ #endif
+}
+
+static void
setup_status_bar (EShellWindow *window)
{
EShellWindowPrivate *priv;
@@ -566,6 +576,9 @@ setup_status_bar (EShellWindow *window)
priv->status_bar = gtk_hbox_new (FALSE, 2);
if(gconf_client_get_bool (gconf_client_get_default(),"/apps/evolution/shell/view_defaults/statusbar_visible",NULL))
gtk_widget_show (priv->status_bar);
+
+ /* setup dbus interface here*/
+ setup_nm_support (window);
setup_offline_toggle (window);
setup_menu_hint_label (window);
Index: shell/e-shell.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-shell.c,v
retrieving revision 1.268
diff -u -p -w -r1.268 e-shell.c
--- shell/e-shell.c 18 Dec 2005 04:33:25 -0000 1.268
+++ shell/e-shell.c 21 Dec 2005 06:46:28 -0000
@@ -303,9 +303,9 @@ impl_Shell_setLineStatus (PortableServer
e_passwords_set_online(online);
if (online)
- e_shell_go_online (shell, NULL);
+ e_shell_go_online (shell, NULL, GNOME_Evolution_USER_ONLINE);
else
- e_shell_go_offline (shell, NULL);
+ e_shell_go_offline (shell, NULL, GNOME_Evolution_USER_OFFLINE);
}
static GNOME_Evolution_Component
@@ -699,7 +699,7 @@ e_shell_construct (EShell *shell,
e_passwords_set_online(start_online);
if (start_online)
- e_shell_go_online (shell, NULL);
+ e_shell_go_online (shell, NULL, GNOME_Evolution_USER_ONLINE);
return E_SHELL_CONSTRUCT_RESULT_OK;
}
@@ -1109,16 +1109,22 @@ set_line_status_complete(EvolutionListen
}
static void
-set_line_status(EShell *shell, gboolean status)
+set_line_status(EShell *shell, GNOME_Evolution_ShellState shell_state)
{
EShellPrivate *priv;
GSList *component_infos;
GSList *p;
CORBA_Environment ev;
GConfClient *client;
+ gboolean status;
priv = shell->priv;
+ if (shell_state == GNOME_Evolution_FORCED_OFFLINE || shell_state == GNOME_Evolution_USER_OFFLINE)
+ status = FALSE;
+ else
+ status = TRUE;
+
if ((status && priv->line_status == E_SHELL_LINE_STATUS_ONLINE)
|| (!status && priv->line_status != E_SHELL_LINE_STATUS_ONLINE))
return;
@@ -1142,7 +1148,7 @@ set_line_status(EShell *shell, gboolean
CORBA_exception_init (&ev);
- GNOME_Evolution_Component_setLineStatus(info->iface, status, bonobo_object_corba_objref((BonoboObject *)priv->line_status_listener), &ev);
+ GNOME_Evolution_Component_setLineStatus(info->iface, shell_state, bonobo_object_corba_objref((BonoboObject *)priv->line_status_listener), &ev);
if (ev._major == CORBA_NO_EXCEPTION)
priv->line_status_pending++;
@@ -1163,14 +1169,14 @@ set_line_status(EShell *shell, gboolean
**/
void
e_shell_go_offline (EShell *shell,
- EShellWindow *action_window)
+ EShellWindow *action_window, GNOME_Evolution_ShellState shell_state)
{
g_return_if_fail (shell != NULL);
g_return_if_fail (E_IS_SHELL (shell));
g_return_if_fail (action_window != NULL);
g_return_if_fail (action_window == NULL || E_IS_SHELL_WINDOW (action_window));
- set_line_status(shell, FALSE);
+ set_line_status(shell, shell_state);
}
/**
@@ -1182,13 +1188,13 @@ e_shell_go_offline (EShell *shell,
**/
void
e_shell_go_online (EShell *shell,
- EShellWindow *action_window)
+ EShellWindow *action_window, GNOME_Evolution_ShellState shell_state)
{
g_return_if_fail (shell != NULL);
g_return_if_fail (E_IS_SHELL (shell));
g_return_if_fail (action_window == NULL || E_IS_SHELL_WINDOW (action_window));
- set_line_status(shell, TRUE);
+ set_line_status(shell, shell_state);
}
void
Index: shell/e-shell.h
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-shell.h,v
retrieving revision 1.69
diff -u -p -w -r1.69 e-shell.h
--- shell/e-shell.h 18 Aug 2005 04:35:31 -0000 1.69
+++ shell/e-shell.h 21 Dec 2005 06:46:28 -0000
@@ -119,9 +119,9 @@ void e_shell_close_all_wi
EShellLineStatus e_shell_get_line_status (EShell *shell);
void e_shell_go_offline (EShell *shell,
- EShellWindow *action_window);
+ EShellWindow *action_window, GNOME_Evolution_ShellState shell_state);
void e_shell_go_online (EShell *shell,
- EShellWindow *action_window);
+ EShellWindow *action_window, GNOME_Evolution_ShellState shell_state);
void e_shell_send_receive (EShell *shell);
--- /dev/null 2005-12-19 17:19:25.400201000 +0530
+++ shell/e-shell-nm.c 2005-12-21 17:56:12.000000000 +0530
@@ -0,0 +1,116 @@
+/*
+ * Shreyas Srinivasan <sshreyas novell 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * (C) Copyright 2005 Novell, Inc.
+ */
+
+#define DBUS_API_SUBJECT_TO_CHANGE 1
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <glib.h>
+#include <e-shell-window.h>
+#include <Evolution.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus-glib.h>
+#include <NetworkManager/NetworkManager.h>
+
+int shell_dbus_initialize (EShellWindow *window);
+
+enum _ShellLineStatus {
+ E_SHELL_LINE_DOWN,
+ E_SHELL_LINE_UP
+};
+
+
+typedef enum _ShellLineStatus ShellLineStatus;
+
+static DBusHandlerResult e_shell_network_monitor (DBusConnection *connection G_GNUC_UNUSED,
+ DBusMessage *message,
+ void* user_data)
+{
+ DBusError error;
+ const char *object;
+ ShellLineStatus status;
+ EShellWindow *window = E_SHELL_WINDOW (user_data);
+ EShell *shell = e_shell_window_peek_shell ((EShellWindow *) user_data);
+ GNOME_Evolution_ShellState shell_state;
+ EShellLineStatus line_status;
+
+ dbus_error_init (&error);
+ object = dbus_message_get_path (message);
+
+ if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNoLongerActive"))
+ status = E_SHELL_LINE_DOWN;
+ else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNowActive"))
+ status = E_SHELL_LINE_UP;
+ else
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+
+ if (!dbus_message_get_args (message, &error, DBUS_TYPE_OBJECT_PATH,
+ &object, DBUS_TYPE_INVALID))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ line_status = e_shell_get_line_status (shell);
+
+ if (line_status == E_SHELL_LINE_STATUS_ONLINE && status == E_SHELL_LINE_DOWN) {
+ shell_state = GNOME_Evolution_FORCED_OFFLINE;
+ e_shell_go_offline (shell, window, shell_state);
+ } else if (line_status == E_SHELL_LINE_STATUS_OFFLINE && status == E_SHELL_LINE_UP) {
+ shell_state = GNOME_Evolution_USER_ONLINE;
+ e_shell_go_online (shell, window, shell_state);
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+int e_shell_dbus_initialise (EShellWindow *window)
+{
+ DBusConnection *connection;
+ DBusError error;
+
+ g_type_init ();
+
+ dbus_error_init (&error);
+ connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (connection == NULL) {
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ dbus_connection_setup_with_g_main (connection, NULL);
+
+ if (!dbus_connection_add_filter (connection, e_shell_network_monitor, window, NULL))
+ return FALSE;
+
+ dbus_bus_add_match (connection,
+ "type='signal',"
+ "interface='" NM_DBUS_INTERFACE "',"
+ "sender='" NM_DBUS_SERVICE "',"
+ "path='" NM_DBUS_PATH "'", &error);
+ if (dbus_error_is_set (&error)) {
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
--- /dev/null 2005-12-19 17:19:25.400201000 +0530
+++ shell/e-shell-nm-glib.c 2005-12-21 17:55:33.000000000 +0530
@@ -0,0 +1,78 @@
+/*
+ * Shreyas Srinivasan <sshreyas novell 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * (C) Copyright 2005 Novell, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <NetworkManager/libnm_glib.h>
+#include <e-shell-window.h>
+
+
+static void e_shell_glib_network_monitor (libnm_glib_ctx *ctx, gpointer user_data)
+{
+ libnm_glib_state state;
+ EShellLineStatus line_status;
+ EShellWindow *window = E_SHELL_WINDOW (user_data);
+ EShell *shell = e_shell_window_peek_shell (window);
+ GNOME_Evolution_ShellState shell_state;
+
+ g_return_if_fail (ctx != NULL);
+
+ state = libnm_glib_get_network_state (ctx);
+ line_status = e_shell_get_line_status (shell);
+
+ if (line_status == E_SHELL_LINE_STATUS_ONLINE && state == LIBNM_NO_NETWORK_CONNECTION) {
+ shell_state = GNOME_Evolution_FORCED_OFFLINE;
+ e_shell_go_offline (shell, window, shell_state);
+ } else if (line_status == E_SHELL_LINE_STATUS_OFFLINE && state == LIBNM_ACTIVE_NETWORK_CONNECTION) {
+ shell_state = GNOME_Evolution_USER_ONLINE;
+ e_shell_go_online (shell, window, shell_state);
+ } else
+ return LIBNM_INVALID_CONTEXT;
+
+ return FALSE;
+}
+
+
+int e_shell_nm_glib_initialise (EShellWindow *window )
+{
+ libnm_glib_ctx *ctx;
+ guint id;
+
+ ctx = libnm_glib_init ();
+ if (!ctx)
+ {
+ fprintf (stderr, "Could not initialize libnm.\n");
+ return FALSE;
+ }
+
+ id = libnm_glib_register_callback (ctx, e_shell_glib_network_monitor, window, NULL);
+ libnm_glib_unregister_callback (ctx, id);
+
+ id = libnm_glib_register_callback (ctx, e_shell_glib_network_monitor, window, NULL);
+ fprintf (stderr, "Registered Callback with ID %d\n", id);
+
+ return TRUE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]