[evolution-patches] (no subject)



Hey,

Attaching the first few patches which dwell into Network Manager 
support for Evolution. Things which work in these patches

1) Evolution goes offline automagically if the network goes down. 
2) Evolution goes online automagically if the network comes up and
syncs 
up mail, contacts whatever.
3) If the network goes down when a sync is happening then evolution
cancels the event and goes offline

Things to be done 

1) Journalling: Although i havent tested this thoroughly my code
intution 
says that if some operation are done and then network goes down and
evolution goes offline then these operations are not journalled and
re-played. Ofcourse the operations which happen after evolution goes
offline are journalled anyway and replayed later.

2) Good UI support: Right now the only Ui which depicts that evolution 
is offline is tiny weeny icon at the bottom of the screen. When we move 
to a state where evolution can transiently disconnect and re-connect
depending on the network, I personally would like to have Evolution
(Disconnected) on the Title bar. 

3) Paranoid conditions checking: 
i)  Should we allow users to switch from offline to online when the
network is down ?
ii) Should we allow users to start in online when the network is down ?

I havent addressed these issues due to acute shortage of hacking time
before the next release. I have tested the code decently ( not
perfectly) and it *just works* (TM).

Cheers,
Shreyas



-- 
What can i do? I am just being me
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/ChangeLog,v
retrieving revision 1.2486
diff -u -p -r1.2486 ChangeLog
--- ChangeLog	23 Oct 2005 15:44:33 -0000	1.2486
+++ ChangeLog	14 Nov 2005 10:09:46 -0000
@@ -1,3 +1,17 @@
+2005-11-14  Shreyas Srinivasan  <sshreyas novell com>
+
+	* Network Manager Support
+	* camel-session.[h,c]: Add a gboolean network_state
+	which the shell uses to set the current network state.
+	Add new api's camel_session_get_network_state and
+	camel_session_set_network_state.
+	* camel-offline-folder.c: If network down then dont 
+	sync folders while going offline and send clean as FALSE
+	to camel_service_disconnect.
+	* camel-disco-folder.c: If network down then dont 
+	sync folders while going offline and send clean as FALSE
+	to camel_service_disconnect.
+	
 2005-10-23  Parthasarathi Susarla <sparthasarathi novell com>
 	
 	** See bug #218177
Index: camel-disco-store.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-disco-store.c,v
retrieving revision 1.16
diff -u -p -r1.16 camel-disco-store.c
--- camel-disco-store.c	31 Aug 2005 04:21:56 -0000	1.16
+++ camel-disco-store.c	14 Nov 2005 10:09:46 -0000
@@ -292,6 +292,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_network_up (service->session);
 
 	if (disco_store->status == status)
 		return;
@@ -299,32 +301,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.4
diff -u -p -r1.4 camel-offline-store.c
--- camel-offline-store.c	31 Aug 2005 04:21:56 -0000	1.4
+++ camel-offline-store.c	14 Nov 2005 10:09:48 -0000
@@ -115,40 +115,44 @@ 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 */
Index: camel-service.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-service.c,v
retrieving revision 1.102
diff -u -p -r1.102 camel-service.c
--- camel-service.c	31 Aug 2005 04:21:56 -0000	1.102
+++ camel-service.c	14 Nov 2005 10:09:51 -0000
@@ -414,9 +414,11 @@ camel_service_disconnect (CamelService *
 {
 	gboolean res = TRUE;
 	int unreg = FALSE;
+	CamelSession *session = camel_service_get_session (service);
+
 
 	CAMEL_SERVICE_LOCK (service, connect_lock);
-	
+
 	if (service->status != CAMEL_SERVICE_DISCONNECTED
 	    && service->status != CAMEL_SERVICE_DISCONNECTING) {
 		CAMEL_SERVICE_LOCK (service, connect_op_lock);
@@ -427,20 +429,20 @@ camel_service_disconnect (CamelService *
 			unreg = TRUE;
 		}
 		CAMEL_SERVICE_UNLOCK (service, connect_op_lock);
-
+		
 		service->status = CAMEL_SERVICE_DISCONNECTING;
 		res = CSERV_CLASS (service)->disconnect (service, clean, ex);
 		service->status = CAMEL_SERVICE_DISCONNECTED;
-
+			
 		CAMEL_SERVICE_LOCK (service, connect_op_lock);
 		if (unreg)
 			camel_operation_unregister (service->connect_op);
-
+		
 		camel_operation_unref (service->connect_op);
 		service->connect_op = NULL;
 		CAMEL_SERVICE_UNLOCK (service, connect_op_lock);
 	}
-	
+
 	CAMEL_SERVICE_UNLOCK (service, connect_lock);
 	
 	return res;
Index: camel-session.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-session.c,v
retrieving revision 1.110
diff -u -p -r1.110 camel-session.c
--- camel-session.c	31 Aug 2005 04:21:56 -0000	1.110
+++ camel-session.c	14 Nov 2005 10:09:56 -0000
@@ -67,6 +67,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();
@@ -673,4 +674,20 @@ camel_session_set_check_junk (CamelSessi
 	g_assert(CAMEL_IS_SESSION(session));
 
 	session->check_junk = check_junk;
+}
+
+gboolean
+camel_session_network_up (CamelSession *session)
+{
+	g_assert(CAMEL_IS_SESSION(session));
+	
+	return session->network_state;
+}
+
+void
+camel_session_set_network_state (CamelSession *session, gboolean network_state)
+{
+	g_assert(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	14 Nov 2005 10:09:56 -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_network_up (CamelSession *session);
+void camel_session_set_network_state (CamelSession *session, gboolean network_state);
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/ChangeLog,v
retrieving revision 1.1534
diff -u -p -w -r1.1534 ChangeLog
--- ChangeLog	27 Oct 2005 18:26:01 -0000	1.1534
+++ ChangeLog	14 Nov 2005 09:54:01 -0000
@@ -1,3 +1,9 @@
+2005-11-14  Shreyas Srinivasan  <sshreyas novell com>
+
+	* configure.in: Network Manager support.
+	Add dbus-1 and dbus-glib-1 dependency
+	to shell. 
+	
 2005-10-27  Erdal Ronahi  <erdal ronahi gmail com>
 
 	* configure.in: Added ku (Kurdish) to ALL_LINGUAS
Index: configure.in
===================================================================
RCS file: /cvs/gnome/evolution/configure.in,v
retrieving revision 1.854
diff -u -p -w -r1.854 configure.in
--- configure.in	27 Oct 2005 18:26:01 -0000	1.854
+++ configure.in	14 Nov 2005 09:54:09 -0000
@@ -1246,7 +1246,7 @@ 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)
+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 dbus-1 dbus-glib-1)
 AC_SUBST(SHELL_CFLAGS)
 AC_SUBST(SHELL_LIBS)
 
Index: mail/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
retrieving revision 1.3724
diff -u -p -w -r1.3724 ChangeLog
--- mail/ChangeLog	26 Oct 2005 10:25:42 -0000	1.3724
+++ mail/ChangeLog	14 Nov 2005 09:55:07 -0000
@@ -1,3 +1,8 @@
+2005-11-14  Shreyas Srinivasan  <sshreyas novell com>
+
+	* mail-component.c (impl_setLineStatus): Handle
+	network disconnect by going offline.
+	
 2005-10-26  Vivek Jain <jvivek novell com>
 	
 	**See #313096
Index: mail/mail-component.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-component.c,v
retrieving revision 1.125
diff -u -p -w -r1.125 mail-component.c
--- mail/mail-component.c	22 Aug 2005 02:54:51 -0000	1.125
+++ mail/mail-component.c	14 Nov 2005 09:55:13 -0000
@@ -71,6 +71,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>
@@ -93,6 +94,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;
@@ -964,10 +968,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	14 Nov 2005 09:55:13 -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/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/shell/ChangeLog,v
retrieving revision 1.1543
diff -u -p -w -r1.1543 ChangeLog
--- shell/ChangeLog	10 Nov 2005 10:37:46 -0000	1.1543
+++ shell/ChangeLog	14 Nov 2005 09:55:29 -0000
@@ -1,3 +1,22 @@
+2005-11-14  Shreyas Srinivasan <sshreyas novell com>
+
+	* Network Manager Support for shell
+	* Evolution-Component.idl (setLineStatus): Handle enum ShellState
+	which can represent network down rather than just a boolean.
+	* e-shell-dbus.c: Add new file which adds a dbus_filter  to handle 
+	service "org.freedesktop.NetworkManager".
+	* Makefile.am: Add e-shell-dbus.c to the list of files built into
+	evolution_sources.
+	* e-shell-window_commands.c: Use new changed signature of
+	e_shell_go_offline.
+	* e-shell-window.c (setup_status_bar): Initialise the dbus
+	connection.
+	* e-shell.c (set_line_status): Handle network down triggered
+	Force_offline. New signatures for e_shell_go_offline and 
+	e_shell_go_online.
+	* e-shell.h: New function signatures for e_shell_go_offline and
+	e_shell_go_online.
+	
 2005-11-10  Srinivasa Ragavan <sragavan novell com>
 
 	* e-shell-settings-dialog.c (set_dialog_size) 
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	14 Nov 2005 09:55:31 -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	14 Nov 2005 09:55:31 -0000
@@ -131,6 +131,7 @@ evolution_SOURCES =				\
 	e-shell-window.h			\
 	e-shell.c				\
 	e-shell.h				\
+	e-shell-dbus.c				\
 	e-sidebar.c				\
 	e-sidebar.h				\
 	es-event.c				\
Index: shell/e-shell-window-commands.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-shell-window-commands.c,v
retrieving revision 1.43
diff -u -p -w -r1.43 e-shell-window-commands.c
--- shell/e-shell-window-commands.c	23 Sep 2005 09:44:58 -0000	1.43
+++ shell/e-shell-window-commands.c	14 Nov 2005 09:55:35 -0000
@@ -637,7 +637,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
@@ -645,7 +645,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.39
diff -u -p -w -r1.39 e-shell-window.c
--- shell/e-shell-window.c	23 Sep 2005 09:44:58 -0000	1.39
+++ shell/e-shell-window.c	14 Nov 2005 09:55:40 -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 ();
@@ -566,6 +566,8 @@ 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*/
+	shell_dbus_initialize (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.267
diff -u -p -w -r1.267 e-shell.c
--- shell/e-shell.c	18 Aug 2005 04:35:31 -0000	1.267
+++ shell/e-shell.c	14 Nov 2005 09:55:46 -0000
@@ -298,9 +298,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
@@ -697,7 +697,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;
 }
@@ -1111,7 +1111,7 @@ set_line_status_complete(EvolutionListen
 }
 
 static void
-set_line_status(EShell *shell, gboolean status)
+set_line_status(EShell *shell, gboolean status, GNOME_Evolution_ShellState shell_state)
 {
 	EShellPrivate *priv;
 	GSList *component_infos;
@@ -1144,7 +1144,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++;
 		
@@ -1165,14 +1165,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, FALSE, shell_state);
 }
 
 /**
@@ -1184,13 +1184,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, TRUE, 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	14 Nov 2005 09:55:46 -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-11-14 11:06:57.832103000 +0530
+++ shell/e-shell-dbus.c	2005-11-14 14:45:15.000000000 +0530
@@ -0,0 +1,96 @@
+
+#define DBUS_API_SUBJECT_TO_CHANGE 1
+
+#include <stdio.h>
+
+#include <glib.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus-glib.h>
+#include <e-shell-window.h>
+#include <Evolution.h>
+
+#define NM_SERVICE              "org.freedesktop.NetworkManager"
+#define NM_OBJECT_PATH          "/org/freedesktop/NetworkManager"
+#define NM_INTERFACE            "org.freedesktop.NetworkManager"
+
+enum _ShellLineStatus {
+    E_SHELL_LINE_DOWN,
+    E_SHELL_LINE_UP
+};
+
+typedef enum _ShellLineStatus ShellLineStatus;
+
+int shell_dbus_initialize (EShellWindow *window);
+
+static DBusHandlerResult dbus_filter (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_INTERFACE, "DeviceNoLongerActive"))
+	    status = E_SHELL_LINE_DOWN;
+	else if (dbus_message_is_signal (message, NM_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 shell_dbus_initialize (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 1;
+	}
+
+	dbus_connection_setup_with_g_main (connection, NULL);
+
+	if (!dbus_connection_add_filter (connection, dbus_filter, window, NULL))
+		return 1;
+
+	dbus_bus_add_match (connection,
+			    "type='signal',"
+			    "interface='" NM_INTERFACE "',"
+			    "sender='" NM_SERVICE "',"
+			    "path='" NM_OBJECT_PATH "'", &error);
+	if (dbus_error_is_set (&error)) {
+		dbus_error_free (&error);
+		return 1;
+	}
+	
+	return 0;
+}


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