diff --git a/.gitignore b/.gitignore
index e7101d7..280b93e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,11 +56,11 @@ conduits/file/file.conduit
 conduits/file/gpilot-install-file
 conduits/file/palm.keys
 conduits/test/test.conduit
-gpilotd/GNOME_Pilot_Daemon.server
+gpilotd/org.gnome.GnomePilot.service
+gpilotd/gpilot-daemon-glue.h
 gpilotd/gnome-pilot-client-private.h
 gpilotd/gnome-pilot-client.c
 gpilotd/gnome-pilot-client.h
-gpilotd/gnome-pilot-common.c
 gpilotd/gnome-pilot-conduit-backup-private.h
 gpilotd/gnome-pilot-conduit-backup.c
 gpilotd/gnome-pilot-conduit-backup.h
@@ -73,9 +73,6 @@ gpilotd/gnome-pilot-conduit-standard.c
 gpilotd/gnome-pilot-conduit-standard.h
 gpilotd/gnome-pilot-conduit.c
 gpilotd/gnome-pilot-conduit.h
-gpilotd/gnome-pilot-skels.c
-gpilotd/gnome-pilot-stubs.c
-gpilotd/gnome-pilot.h
 gpilotd/gpilotd
 gpilotd/gpilotd-session-wrapper
 gpilotd/gpmarshal.c
@@ -94,3 +91,5 @@ utils/gpilotd-client
 utils/gpilotdcm-client
 po/*.gmo
 cscope*
+*.swp
+*.bak
diff --git a/AUTHORS b/AUTHORS
index c5e23df..013d70c 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -5,6 +5,7 @@ information.
 
 JP Rosevear  <jpr@novell.com>
 Matt Davey <mcdavey@mrao.cam.ac.uk>
+Halton Huo <haltonhuo@gnome.org>
 
 Previous authors:
 Manish Vachharajani <mvachhar@vger.rutgers.edu>
diff --git a/Makefile.am b/Makefile.am
index 9e49bcc..33cb49f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,6 @@ ACLOCAL_AMFLAGS=-I macros
 
 SUBDIRS = 			\
 	po 			\
-	idl 			\
 	gpilotd 		\
 	applet			\
 	capplet 		\
diff --git a/applet/pilot.c b/applet/pilot.c
index 6df18e7..90bc71a 100644
--- a/applet/pilot.c
+++ b/applet/pilot.c
@@ -32,6 +32,7 @@
 
 #include <signal.h>
 
+#include "gpilotd/gpilot-daemon.h"
 #include "gpilot-applet-progress.h"
 #include "gpilotd/gnome-pilot-client.h"
 
@@ -1041,12 +1042,6 @@ timeout (PilotApplet *self)
 			pilot_draw (self);
 			/* FIXME: add gpilot_monitor_state_change () */
 		} else {
-			gnome_pilot_client_monitor_on_all_pilots (self->gpc);
-			
-			gnome_pilot_client_notify_on (self->gpc,GNOME_Pilot_NOTIFY_CONNECT);
-			gnome_pilot_client_notify_on (self->gpc,GNOME_Pilot_NOTIFY_CONDUIT);
-			gnome_pilot_client_notify_on (self->gpc,GNOME_Pilot_NOTIFY_DISCONNECT);
-			
 			gtk_tooltips_set_tip (self->tooltips, 
 					      GTK_WIDGET (self->applet),
 					      _("Ready to synchronize"),
diff --git a/capplet/gnome-pilot-assistant.c b/capplet/gnome-pilot-assistant.c
index 661ed89..c26c38c 100644
--- a/capplet/gnome-pilot-assistant.c
+++ b/capplet/gnome-pilot-assistant.c
@@ -754,6 +754,10 @@ gpd_sync_page_prepare (GnomePilotAssistant *gpd)
 						  GNOME_Pilot_IMMEDIATE,
 						  0,
 						  &priv->handle1);
+                if (priv->handle1 <= 0) {
+                        error_dialog (GTK_WINDOW (priv->assistant), _("Failed sending request to gpilotd"));
+                        return;
+                }
 	} else {
 		/* do get_from_pilot */
 		location = priv->device->type == PILOT_DEVICE_NETWORK ?
@@ -770,15 +774,15 @@ gpd_sync_page_prepare (GnomePilotAssistant *gpd)
 
 		gnome_pilot_client_get_user_info (priv->gpc, priv->device->name, GNOME_Pilot_IMMEDIATE, 0, &priv->handle1);
 		gnome_pilot_client_get_system_info (priv->gpc, priv->device->name, GNOME_Pilot_IMMEDIATE, 0, &priv->handle2);
+
+                if (priv->handle1 <= 0 || priv->handle2 <= 0) {
+                        error_dialog (GTK_WINDOW (priv->assistant), _("Failed sending request to gpilotd"));
+                        return;
+                }
 	}
 	gtk_label_set_text (GTK_LABEL (priv->sync_label), text);
         g_free (text);
 
-	if (priv->handle1 <= 0 || priv->handle2 <= 0) {
-		error_dialog (GTK_WINDOW (priv->assistant), _("Failed sending request to gpilotd"));
-		return;
-	}
-
 	/* disable NEXT until we've synced */
 	gtk_assistant_set_page_complete (GTK_ASSISTANT(priv->assistant),
 	    priv->page_sync, FALSE);
diff --git a/capplet/gpilotd-capplet.ui b/capplet/gpilotd-capplet.ui
index 9e465ca..05136c0 100644
--- a/capplet/gpilotd-capplet.ui
+++ b/capplet/gpilotd-capplet.ui
@@ -1576,13 +1576,13 @@ Press 'Cancel' to exit.</property>
             <property name="can_focus">True</property>
             <property name="model">assistant_device_speed_store</property>
             <property name="active">3</property>
+            <child>
+              <object class="GtkCellRendererText" id="cellrenderertext5"/>
+              <attributes>
+                <attribute name="text">0</attribute>
+              </attributes>
+            </child>
           </object>
-          <child>
-            <object class="GtkCellRendererText" id="cellrenderertext5"/>
-            <attributes>
-              <attribute name="text">0</attribute>
-            </attributes>
-          </child>
           <packing>
             <property name="left_attach">1</property>
             <property name="right_attach">2</property>
diff --git a/capplet/gpilotd-control-applet.c b/capplet/gpilotd-control-applet.c
index 04556a7..b9d4ab1 100644
--- a/capplet/gpilotd-control-applet.c
+++ b/capplet/gpilotd-control-applet.c
@@ -35,8 +35,6 @@
 #include "gnome-pilot-assistant.h"
 #include "gnome-pilot-capplet.h"
 
-#include <bonobo-activation/bonobo-activation.h>
-
 #include "pilot.h"
 #include "util.h"
 
@@ -48,11 +46,8 @@ monitor_pilots (GnomePilotClient *gpc, PilotState * state)
 		while (tmp!= NULL){
 			GPilotPilot *pilot =(GPilotPilot*)tmp->data;
 			g_message ("pilot = %s",pilot->name);
-			gnome_pilot_client_monitor_on (gpc,pilot->name);
 			tmp = tmp->next;
 		}
-		gnome_pilot_client_notify_on (gpc, GNOME_Pilot_NOTIFY_CONNECT);
-		gnome_pilot_client_notify_on (gpc, GNOME_Pilot_NOTIFY_DISCONNECT);
 	}
 }
 
diff --git a/conduits/file/gpilot_install_file.c b/conduits/file/gpilot_install_file.c
index 94b02cc..67d9fb9 100644
--- a/conduits/file/gpilot_install_file.c
+++ b/conduits/file/gpilot_install_file.c
@@ -21,16 +21,12 @@
 
 #include "config.h"
 #include <gtk/gtk.h>
+#include <glib/gi18n-lib.h>
 #include <libgnome/gnome-init.h>
-#include <gpilotd/gnome-pilot-client.h>
-
-#include <bonobo.h>
-#include <bonobo-activation/bonobo-activation.h>
-
 
+#include <gpilotd/gnome-pilot-client.h>
 
 GnomePilotClient *gpc;
-CORBA_Environment ev;
 GSList *handles;
 GSList *failed,*notfailed;
 int handle;
@@ -193,14 +189,13 @@ main (int argc, char *argv[])
 				
 				info = g_strdup (_("Press synchronize on the cradle to install\n" 
 						  " or cancel the operation."));
-				GNOME_Pilot_Daemon_request_conduit (gpc->gpilotddaemon,
-								    gpc->gpilotdclient,
-								    pilots->data,
-								    "File",
-								    GNOME_Pilot_CONDUIT_DEFAULT,
-								    survive,
-								    0,
-								    &ev);
+                                err = gnome_pilot_client_conduit (gpc,
+                                                            pilots->data,
+                                                            "File",
+                                                            GNOME_Pilot_CONDUIT_DEFAULT,
+                                                            survive,
+                                                            0,
+                                                            &handle);
 			}
 						
 			tmp = g_strconcat (message==NULL?"":message,
diff --git a/configure.ac b/configure.ac
index 05c1f9f..0052ff2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -136,10 +136,7 @@ dnl ******************************
 LIBXML_REQUIRED="libxml-2.0"
 LIBGNOME_REQUIRED="libgnome-2.0 >= 2.0.0"
 LIBGTK_REQUIRED="gtk+-2.0 >= 2.13.0"
-ORBIT_REQUIRED="ORBit-2.0 >= 2.0.0"
-LIBBONOBO_REQUIRED="libbonobo-2.0 >= 2.0.0"
-LIBBONOBOUI_REQUIRED="libbonoboui-2.0 >= 2.0.0"
-BONOBO_ACTIVATION_REQUIRED="bonobo-activation-2.0 >= 1.0.3"
+DBUS_GLIB_REQUIRED="dbus-glib-1 >= 0.74"
 LIBPANELAPPLET_REQUIRED="libpanelapplet-2.0 >= 2.0.6"
 GCONF_REQUIRED="gconf-2.0"
 
@@ -148,10 +145,7 @@ PKG_CHECK_MODULES(GNOME_PILOT,
 	$LIBXML_REQUIRED
 	$LIBGNOME_REQUIRED
 	$LIBGTK_REQUIRED
-	$LIBBONOBO_REQUIRED
-	$LIBBONOBOUI_REQUIRED
-	$ORBIT_REQUIRED
-	$BONOBO_ACTIVATION_REQUIRED
+	$DBUS_GLIB_REQUIRED
 ])
 
 GNOME_PILOT_CFLAGS="$GNOME_PILOT_CFLAGS $PISOCK_CFLAGS"
@@ -188,12 +182,6 @@ dnl ***********
 AC_PATH_PROG(GCONFTOOL, gconftool-2, no)
 AM_GCONF_SOURCE_2
 
-dnl ******************************
-dnl ORBit IDL Compiler
-dnl ******************************
-ORBIT_IDL="`$PKG_CONFIG --variable=orbit_idl ORBit-2.0`"
-AC_SUBST(ORBIT_IDL)
-
 dnl **************************************************
 dnl * Marshaller generation
 dnl **************************************************
@@ -256,7 +244,6 @@ conduits/file/Makefile
 conduits/test/Makefile
 capplet/Makefile
 utils/Makefile
-idl/Makefile
 po/Makefile.in
 help/Makefile
 help/C/Makefile
diff --git a/gpilotd/GNOME_Pilot_Daemon.server.in.in b/gpilotd/GNOME_Pilot_Daemon.server.in.in
deleted file mode 100644
index e869d67..0000000
--- a/gpilotd/GNOME_Pilot_Daemon.server.in.in
+++ /dev/null
@@ -1,16 +0,0 @@
-<oaf_info>
-
-<oaf_server iid="OAFIID:GNOME_Pilot_Daemon"
-            type="exe"
-            location="@LIBEXECDIR@/gpilotd">
-
-	<oaf_attribute name="repo_ids" type="stringv">
-		<item value="IDL:GNOME/Pilot/Daemon:2.0"/>
-	</oaf_attribute>
-
-	<oaf_attribute name="description" type="string"
-	               _value="Gnome-Pilot daemon"/>
-
-</oaf_server>
-
-</oaf_info>
diff --git a/gpilotd/Makefile.am b/gpilotd/Makefile.am
index 6d0cfa3..a2bb3a8 100644
--- a/gpilotd/Makefile.am
+++ b/gpilotd/Makefile.am
@@ -100,30 +100,16 @@ gobfiles = 						\
 #$(GOB_BUILT_SRCS): $(gobfiles)
 #	@for GF in $(gobfiles); do (echo -n "$(GOB) -w $$GF..." && $(GOB) -w $$GF && echo " ok"); done;
 
-### IDL and corba grease
-
-idldir = $(datadir)/idl
-
-idl_files = $(top_srcdir)/idl/gnome-pilot.idl
-
-CORBA_SRCLIST = 		\
-	gnome-pilot-common.c 	\
-	gnome-pilot-skels.c 	\
-	gnome-pilot-stubs.c 	\
-	gnome-pilot.h		\
+DBUS_SRCLIST = 		\
+	gpilot-daemon-glue.h \
 	$(NULL)
 
-GPILOTD_ORB_SRCLIST = 		\
-	orbit_daemon_glue.c 	\
-	orbit_daemon_glue.h	\
-	$(NULL)
-
-$(CORBA_SRCLIST): $(idl_files)
-	$(ORBIT_IDL) $(idl_files)
+BUILT_SOURCES = $(DBUS_SRCLIST) $(GOB_BUILT_SRCS)
 
-BUILT_SOURCES = $(CORBA_SRCLIST) $(GOB_BUILT_SRCS) gpmarshal.c gpmarshal.h
+gpilot-daemon-glue.h: gpilot-daemon.xml
+	dbus-binding-tool --prefix=gpilot_daemon --mode=glib-server $< > gpilot-daemon-glue.h
 
-CLEANFILES = $(CORBA_SRCLIST) $(server_DATA)
+CLEANFILES = $(DBUS_SRCLIST) $(service_DATA)
 MAINTAINERCLEANFILES = $(GOB_BUILT_SRCS)
 
 ## LIBGPILOTDCM
@@ -147,8 +133,9 @@ libgpilotdcm_la_LDFLAGS = \
 ## LIBGPILOTD
 
 libgpilotd_la_SOURCES = 		\
-	$(CORBA_SRCLIST) 		\
 	$(GOB_LIBGPILOTD_BUILT_SRCS)	\
+	gpmarshal.c 			\
+	gpmarshal.h			\
 	$(NULL)
 
 libgpilotdincludedir = $(includedir)/gpilotd
@@ -203,7 +190,7 @@ noinst_HEADERS = gnome-pilot-conduit-backup-private.h
 
 gpilotincludedir = $(includedir)/gpilotd
 gpilotinclude_HEADERS = 		\
-	gnome-pilot.h			\
+	gpilot-daemon.h			\
 	gnome-pilot-structures.h	\
 	$(NULL)
 
@@ -213,7 +200,8 @@ gpilotd_SOURCES =			\
 	manager.h			\
 	queue_io.c 			\
 	queue_io.h			\
-	$(GPILOTD_ORB_SRCLIST) 		\
+	gpilot-daemon.c			\
+	gpilot-daemon.h			\
 	$(NULL)
 
 gpilotd_LDFLAGS = -export-dynamic
@@ -234,11 +222,12 @@ gpilotd_session_wrapper_LDADD = 	\
 		$(NULL)
 
 
-serverdir = $(libdir)/bonobo/servers
-server_in_files = GNOME_Pilot_Daemon.server.in.in
-server_DATA = $(server_in_files:.server.in.in=.server)
-@GP_SERVER_RULE@
-@INTLTOOL_SERVER_RULE@
+servicedir = $(datadir)/dbus-1/services
+service_DATA = org.gnome.GnomePilot.service
+
+org.gnome.GnomePilot.service: org.gnome.GnomePilot.service.in \
+	Makefile
+	@sed -e "s|[@]libexecdir[@]|$(libexecdir)|" $< > $@
 
 mimedir = $(datadir)/mime-info
 mime_DATA = palm.mime
@@ -247,12 +236,12 @@ devicedir  = $(datadir)/gnome-pilot
 device_DATA = devices.xml
 
 EXTRA_DIST = 			\
-	GNOME_Pilot_Daemon.server.in.in		\
+	org.gnome.GnomePilot.service.in \
 	gpmarshal.list		\
 	gpmarshal.h		\
 	gpmarshal.c		\
+	gpilot-daemon.xml	\
 	$(gobfiles) 		\
-	$(server_in_files) 	\
 	$(mime_DATA)		\
 	$(device_DATA)		\
 	$(NULL)
diff --git a/gpilotd/gnome-pilot-client.gob b/gpilotd/gnome-pilot-client.gob
index 3608db7..e9b76b5 100644
--- a/gpilotd/gnome-pilot-client.gob
+++ b/gpilotd/gnome-pilot-client.gob
@@ -18,6 +18,7 @@
  * Boston, MA 02111-1307, USA.
  *
  * Authors: Eskil Heyn Olsen <eskil@eskil.org>
+ *	    Halton Huo <haltonhuo@gnome.org>
  *
  */
 
@@ -40,13 +41,21 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
-#include <gtk/gtkobject.h>
-#include <bonobo-activation/bonobo-activation.h>
-#include <libbonobo.h>
-#include <gpilotd/gnome-pilot.h>
+#include <sys/types.h>
+#include <signal.h>
 
 #include <glib.h>
 #include <gio/gio.h>
+#include <gtk/gtkobject.h>
+
+#include "gpilotd/gpilot-daemon.h"
+#include "gpilotd/gpmarshal.h"
+
+#define GP_DBUS_NAME              "org.gnome.GnomePilot"
+#define GP_DBUS_PATH              "/org/gnome/GnomePilot/Daemon"
+#define GP_DBUS_INTERFACE         "org.gnome.GnomePilot.Daemon"
+
+#define IS_STR_SET(x) (x != NULL && x[0] != '\0')
 
 enum GPilotdErrCode {
 	GPILOTD_OK=0,
@@ -60,311 +69,392 @@ enum GPilotdErrCode {
 
 %{
 
-#include <sys/types.h>
-#include <signal.h>
-	
-typedef struct {
-	POA_GNOME_Pilot_Client servant;
-	GnomePilotClient *self;
-} GnomePilotClientServant;
-
-GnomePilotClient* get_self (PortableServer_Servant servant);
 pid_t gpilotd_get_pid (void);
 
-PortableServer_ServantBase__epv base_epv = {
-	NULL,
-	NULL,
-	NULL
-};
-
-static POA_GNOME_Pilot_Client__epv  gnome_pilot_client_epv;
-static POA_GNOME_Pilot_Client__vepv gnome_pilot_client_vepv = { &base_epv, &gnome_pilot_client_epv };
-
-enum get_triple_ptr_action {
-	GPILOTD_APP_PILOT_NAMES,
-	GPILOTD_APP_PILOT_IDS,
-	GPILOTD_APP_PILOTS_BY_NAME,
-	GPILOTD_APP_PILOTS_BY_LOGIN,
-	GPILOTD_APP_USER_NAMES,
-	GPILOTD_APP_DATABASES_FROM_CACHE,
-	GPILOTD_APP_CRADLES
-};
-
 %}
 
 class Gnome:Pilot:Client from Gtk:Object {
-	public GNOME_Pilot_Daemon gpilotddaemon;
-        public GNOME_Pilot_Client gpilotdclient;
-	public CORBA_Environment ev;
-	public CORBA_char *client_id;
-	public CORBA_ORB orb;
+	public DBusGConnection *connection;
+	public DBusGProxy *proxy;
 
 	class_init (class) {
-	}
-
-	private void init_corba_class (self) {
-		static gboolean inited = FALSE;
-		
-		if (inited==FALSE) {
-			self->client_id = NULL;
-			inited = TRUE;
-			gnome_pilot_client_epv._get_client_id = self_corba_get_client_id;
-			gnome_pilot_client_epv._set_client_id = self_corba_set_client_id;
-			gnome_pilot_client_epv.connect = self_corba_connect;
-			gnome_pilot_client_epv.disconnect = self_corba_disconnect;
-			gnome_pilot_client_epv.request_completed = self_corba_request_completed;
-			gnome_pilot_client_epv.userinfo_requested = self_corba_user_info_requested;
-			gnome_pilot_client_epv.sysinfo_requested = self_corba_system_info_requested;
-			gnome_pilot_client_epv.conduit_start = self_corba_conduit_start;
-			gnome_pilot_client_epv.conduit_end = self_corba_conduit_end;
-			gnome_pilot_client_epv.overall_progress = self_corba_overall_progress;
-			gnome_pilot_client_epv.conduit_progress = self_corba_conduit_progress;
-			gnome_pilot_client_epv.conduit_message = self_corba_conduit_message;
-			gnome_pilot_client_epv.daemon_message = self_corba_daemon_message;
-			gnome_pilot_client_epv.daemon_error = self_corba_daemon_error;
-			gnome_pilot_client_epv.conduit_error = self_corba_conduit_error;
-			gnome_pilot_client_epv.pause = self_corba_pause;
-		}
+		GtkObjectClass   *object_class = GTK_OBJECT_CLASS (class);
 	}
 
 	init (self) {
-			int argc=0;
-			char *argv=NULL;
-			CORBA_Environment *ev;
-			PortableServer_POA the_poa;
-			GnomePilotClientServant *gnome_pilot_client_servant;
-
-			ev = &(self->ev);
-			self_init_corba_class (self);
-
-			CORBA_exception_init (ev);
-
-			if (!bonobo_activation_is_initialized ())
-				self->orb = bonobo_activation_init (argc, &argv);
-			else
-				self->orb = bonobo_activation_orb_get ();
-
-			g_assert (self->orb!=NULL);
-					
-			gnome_pilot_client_servant = g_new0(GnomePilotClientServant,1);
-			gnome_pilot_client_servant->servant.vepv = 
-			                            &gnome_pilot_client_vepv;
-			gnome_pilot_client_servant->self = self;
-			
-			the_poa = (PortableServer_POA)CORBA_ORB_resolve_initial_references (self->orb,"RootPOA",ev);
-			if (ev->_major != CORBA_NO_EXCEPTION) {
-				g_warning ("%s:%d: Caught exception: %s",
-					   __FILE__,__LINE__, 
-					   CORBA_exception_id (ev));
-				CORBA_exception_free (ev);
-			}
-
-			PortableServer_POAManager_activate (PortableServer_POA__get_the_POAManager (the_poa, ev), ev);
-			if (ev->_major != CORBA_NO_EXCEPTION) {
-				g_warning ("%s:%d: Caught exception: %s",
-					   __FILE__,__LINE__, 
-					   CORBA_exception_id (ev));
-				CORBA_exception_free (ev);
-			}
-
-			POA_GNOME_Pilot_Client__init ((PortableServer_Servant)gnome_pilot_client_servant,ev);
-			if (ev->_major != CORBA_NO_EXCEPTION) {
-				g_warning ("%s:%d: Caught exception: %s",
-					   __FILE__,__LINE__, 
-					   CORBA_exception_id (ev));
-				CORBA_exception_free (ev);
-			}
 
-			CORBA_free (
-				PortableServer_POA_activate_object (the_poa,
-								   gnome_pilot_client_servant,
-								   ev)
-				);
-			if (ev->_major != CORBA_NO_EXCEPTION) {
-				g_warning ("%s:%d: Caught exception: %s",
-					   __FILE__,__LINE__, 
-					   CORBA_exception_id (ev));
-				CORBA_exception_free (ev);
-			}
-			
-			self->gpilotdclient = 
-				PortableServer_POA_servant_to_reference (the_poa, 
-									gnome_pilot_client_servant, 
-									ev);
-			if (ev->_major != CORBA_NO_EXCEPTION) {
-				g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (ev));
-				CORBA_exception_free (ev);
-			}			
 	}
 
 	public GtkObject*
 	new (void) {
-		GnomePilotClient *ret = GET_NEW;
+		GError		 *error;
+		GnomePilotClient *ret;
+
+		error = NULL;
+		ret = GET_NEW;
+
+		ret->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+		if (ret->connection == NULL) {
+			if (error != NULL) {
+				g_critical ("error getting session bus: %s", error->message);
+				g_error_free (error);
+			}
+			return NULL;
+		}
+
 		return GTK_OBJECT (ret);
 	}
 
-        public void destroy (self) {
-		g_free (self->client_id);
+	public void destroy (self) {
+		self->proxy = NULL;
 		/* FIXME: ick, what more to do here ? */
-        }
+	}
 	
-        public gint connect_to_daemon (self) {
-		Bonobo_ServerInfoList *list;
-		CORBA_Environment *ev;
-		
-		ev = &(self->ev);
-		list = bonobo_activation_query ("repo_ids.has ('IDL:GNOME/Pilot/Daemon:2.0')", NULL, ev);
-		if (list->_length == 0) {
-			return GPILOTD_ERR_NOT_CONNECTED;
-		} else {
-			Bonobo_ServerInfo info;
-			info = list->_buffer[0];
-			g_message ("Activating object %s", info.iid);
-			self->gpilotddaemon = bonobo_activation_activate_from_id (info.iid, 		  
-									    	Bonobo_ACTIVATION_FLAG_NO_LOCAL, NULL, NULL);
+	public gint connect_to_daemon (self) {
+		if (!self->proxy) {
+			self->proxy = dbus_g_proxy_new_for_name (
+						self->connection,
+						GP_DBUS_NAME,
+						GP_DBUS_PATH,
+						GP_DBUS_INTERFACE);
 		}
-		CORBA_free (list);
-		CORBA_exception_free (ev);
 
-		if (self->gpilotddaemon == NULL) return GPILOTD_ERR_NOT_CONNECTED;
+		if (self->proxy == NULL)
+			return GPILOTD_ERR_NOT_CONNECTED;
+
+                dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_UINT,
+                                           G_TYPE_NONE,
+                                           G_TYPE_STRING,
+                                           G_TYPE_UINT,
+                                           G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "RequestCompleted",
+                                         G_TYPE_STRING,
+                                         G_TYPE_UINT,
+                                         G_TYPE_INVALID);
+                dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_UINT_STRING,
+                                           G_TYPE_NONE,
+                                           G_TYPE_STRING,
+                                           G_TYPE_UINT,
+                                           G_TYPE_STRING,
+                                           G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "Connected",
+                                         G_TYPE_STRING,
+                                         G_TYPE_UINT,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "Disconnected",
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "ConduitStart",
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_STRING,
+                                           G_TYPE_NONE,
+                                           G_TYPE_STRING,
+                                           G_TYPE_STRING,
+                                           G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "ConduitEnd",
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_STRING_UINT_UINT,
+                                           G_TYPE_NONE,
+                                           G_TYPE_STRING,
+                                           G_TYPE_STRING,
+                                           G_TYPE_UINT,
+                                           G_TYPE_UINT,
+                                           G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "ConduitProgress",
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_UINT,
+                                         G_TYPE_UINT,
+                                         G_TYPE_INVALID);
+                dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_UINT_UINT,
+                                           G_TYPE_NONE,
+                                           G_TYPE_STRING,
+                                           G_TYPE_UINT,
+                                           G_TYPE_UINT,
+                                           G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "OverallProgress",
+                                         G_TYPE_STRING,
+                                         G_TYPE_UINT,
+                                         G_TYPE_UINT,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "ConduitMessage",
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "ConduitError",
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "DaemonMessage",
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "DaemonError",
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "Paused",
+                                         G_TYPE_BOOLEAN,
+                                         G_TYPE_INVALID);
+
+
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "RequestCompleted",
+                                     G_CALLBACK (self_dbus_request_completed),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "Connected",
+                                     G_CALLBACK (self_dbus_connect),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "Disconnected",
+                                     G_CALLBACK (self_dbus_disconnect),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "ConduitStart",
+                                     G_CALLBACK (self_dbus_conduit_start),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "ConduitEnd",
+                                     G_CALLBACK (self_dbus_conduit_end),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "ConduitProgress",
+                                     G_CALLBACK (self_dbus_conduit_progress),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "OverallProgress",
+                                     G_CALLBACK (self_dbus_overall_progress),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "ConduitMessage",
+                                     G_CALLBACK (self_dbus_conduit_message),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "ConduitError",
+                                     G_CALLBACK (self_dbus_conduit_error),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "DaemonMessage",
+                                     G_CALLBACK (self_dbus_daemon_message),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "DaemonError",
+                                     G_CALLBACK (self_dbus_daemon_error),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "Paused",
+                                     G_CALLBACK (self_dbus_paused),
+                                     self,
+                                     NULL);
 
 		return GPILOTD_OK;
 	}
 
-	private CORBA_char*
-	corba_get_client_id (PortableServer_Servant servant,
-			    CORBA_Environment *ev) {
-		gchar *id;
-		id = get_self (servant)->client_id;
-		if (id==NULL) return CORBA_string_dup ("");
-		return CORBA_string_dup (id);
-	}
-	
 	private void
-	corba_set_client_id (PortableServer_Servant servant,
-			    const CORBA_char *id,
-			    CORBA_Environment *ev) {
-		if (get_self (servant)->client_id!=NULL) {
-			/* throw exception */
-		        g_assert (0);
-		} get_self (servant)->client_id = g_strdup (id);
-	}
+	dbus_connect (DBusGProxy  *proxy,
+		      const gchar *pilot_id,
+                      guint32      uid,
+                      const gchar *username,
+                      gpointer     data) {
+                Self *self = SELF(data);
+                GNOME_Pilot_UserInfo user;
 
-	private void
-	corba_connect (PortableServer_Servant servant,
-		      const CORBA_char *pilot_id,
-		      const GNOME_Pilot_UserInfo *user,
-		      CORBA_Environment *ev) {
-		self_pilot_connect (get_self (servant),pilot_id,user);
+                user.userID = uid;
+                user.username = g_strdup (username);
+
+                g_message ("Get signal 'Connected' pilot_id=%s, userid=%d, username=%s", pilot_id, user.userID, user.username);
+		self_pilot_connect (self, pilot_id, &user);
+
+                g_free (user.username);
 	}
 
 	private void
-	corba_disconnect (PortableServer_Servant servant,
-			 const CORBA_char *pilot_id,
-			 CORBA_Environment *ev) {
-		self_pilot_disconnect (get_self (servant),pilot_id);
+	dbus_disconnect (DBusGProxy  *proxy,
+			 const gchar *pilot_id,
+                         gpointer     data) {
+                Self *self = SELF(data);
+
+                g_message ("Get signal 'Disconnected' pilot_id=%s", pilot_id);
+		self_pilot_disconnect (self, pilot_id);
 	}
  
 	private void
-	corba_request_completed (PortableServer_Servant servant,
-				const CORBA_char *pilot_id,				
-				CORBA_unsigned_long id,
-				CORBA_Environment *ev) {
-		self_completed_request (get_self (servant),pilot_id,id);
+	dbus_request_completed (DBusGProxy  *proxy,
+				const gchar *pilot_id,				
+				guint32      id,
+                                gpointer     data) {
+                Self *self = SELF(data);
+
+                g_message ("Get signal 'RequestCompleted'");
+		self_completed_request (self, pilot_id, id);
 	}
 
-	private void
-	corba_user_info_requested (PortableServer_Servant servant,
-				  const CORBA_char *pilot_id,
-				  const GNOME_Pilot_UserInfo *user,
-				  CORBA_Environment *ev) {
-		self_user_info (get_self (servant),pilot_id,user);
+	public void
+	dbus_user_info_requested (DBusGProxy  *proxy,
+                                  const gchar *pilot_id,
+                                  guint32      uid,
+				  const gchar *username,
+                                  gpointer     data) {
+                Self *self = SELF(data);
+                GNOME_Pilot_UserInfo user;
+
+                g_message ("Get signal 'UserInfoRequested'");
+                user.userID = uid;
+                user.username = g_strdup (username);
+
+		self_user_info (self, pilot_id, &user);
+
+                g_free (user.username);
 	}
 
 	private void
-	corba_system_info_requested (PortableServer_Servant servant,
-				    const CORBA_char *device,				
-				    const GNOME_Pilot_SysInfo *sysinfo,
-				    CORBA_Environment *ev) {
-		self_system_info (get_self (servant),device,sysinfo);
+	dbus_system_info_requested (DBusGProxy  *proxy,
+                                    const gchar *device,
+				    guint32      rom_size,
+				    guint32      ram_size,
+				    guint32      ram_free,
+				    const gchar *name,
+				    const gchar *manufacturer,
+				    guint32      creation,
+				    guint32      rom_version,
+                                    gpointer     data) {
+                Self *self = SELF(data);
+                GNOME_Pilot_SysInfo sysinfo;
+
+                g_message ("Get signal 'SysInfoRequested'");
+                sysinfo.romSize = rom_size;
+                sysinfo.ramSize = ram_size;
+                sysinfo.ramFree = ram_free;
+                sysinfo.name = g_strdup (name);
+                sysinfo.manufacturer = g_strdup (manufacturer);
+                sysinfo.creation = creation;
+                sysinfo.romVersion = rom_version;
+
+		self_system_info (self, device, &sysinfo);
+
+                g_free (sysinfo.name);
+                g_free (sysinfo.manufacturer);
 	}
 
 	private void
-	corba_conduit_start (PortableServer_Servant servant,
-			    const CORBA_char *pilot_id,
-			    const CORBA_char *conduit_name,
-			    const CORBA_char *database,
-			    CORBA_Environment *ev) {
-		self_start_conduit (get_self (servant),pilot_id,conduit_name,database);
+	dbus_conduit_start (DBusGProxy  *proxy,
+			    const gchar *pilot_id,
+			    const gchar *conduit_name,
+			    const gchar *database,
+                            gpointer     data) {
+                Self *self = SELF(data);
+		self_start_conduit (self, pilot_id, conduit_name, database);
 	}
 				
 	private void
-	corba_conduit_end (PortableServer_Servant servant,
-			  const CORBA_char *pilot_id,
-			  const CORBA_char *conduit_name,
-			  CORBA_Environment *ev) {
-		self_end_conduit (get_self (servant),pilot_id,conduit_name);
+	dbus_conduit_end (DBusGProxy  *proxy,
+			  const gchar *pilot_id,
+			  const gchar *conduit_name,
+                          gpointer     data) {
+                Self *self = SELF(data);
+		self_end_conduit (self, pilot_id, conduit_name);
 	}
-				
+
 	private void
-	corba_overall_progress (PortableServer_Servant servant,
-				const CORBA_char *pilot_id,
-				const CORBA_unsigned_long current,
-				const CORBA_unsigned_long total,
-				CORBA_Environment *ev) {
-		self_progress_overall (get_self (servant),pilot_id, current, total);
+	dbus_overall_progress (DBusGProxy  *proxy,
+                               const gchar *pilot_id,
+                               const unsigned long current,
+                               const unsigned long total,
+                               gpointer     data) {
+                Self *self = SELF(data);
+		self_progress_overall (self,pilot_id, current, total);
 	}
 	
 	private void
-	corba_conduit_progress (PortableServer_Servant servant,
-			       const CORBA_char *pilot_id,
-			       const CORBA_char *conduit_name,
-			       const CORBA_unsigned_long current,
-			       const CORBA_unsigned_long total,
-			       CORBA_Environment *ev) {
-		self_progress_conduit (get_self (servant),pilot_id,conduit_name,current,total);
+	dbus_conduit_progress (DBusGProxy  *proxy,
+			       const gchar *pilot_id,
+			       const gchar *conduit_name,
+			       const unsigned long current,
+			       const unsigned long total,
+                               gpointer     data) {
+                Self *self = SELF(data);
+		self_progress_conduit (self, pilot_id, conduit_name, current, total);
 	}
 				
 	private void
-	corba_conduit_message (PortableServer_Servant servant,
-			      const CORBA_char *pilot_id,
-			      const CORBA_char *conduit_name,
-			      const CORBA_char *message,
-			      CORBA_Environment *ev) {
-		self_message_conduit (get_self (servant),pilot_id,conduit_name,message);
+	dbus_conduit_message (DBusGProxy  *proxy,
+                              const gchar *pilot_id,
+                              const gchar *conduit_name,
+                              const gchar *message,
+                              gpointer     data) {
+                Self *self = SELF(data);
+		self_message_conduit (self,pilot_id,conduit_name,message);
 	}	
 
 	private void
-	corba_daemon_message (PortableServer_Servant servant,
-			      const CORBA_char *pilot_id,
-			      const CORBA_char *conduit_name,
-			      const CORBA_char *message,
-			      CORBA_Environment *ev) {
-		self_message_daemon (get_self (servant),pilot_id,conduit_name,message);
+	dbus_daemon_message (DBusGProxy  *proxy,
+                             const gchar *pilot_id,
+                             const gchar *conduit_name,
+                             const gchar *message,
+                             gpointer     data) {
+                Self *self = SELF(data);
+		self_message_daemon (self, pilot_id, conduit_name, message);
 	}	
 
 	private void
-	corba_daemon_error (PortableServer_Servant servant,
-			    const CORBA_char *pilot_id,
-			    const CORBA_char *message,
-			    CORBA_Environment *ev) {
-		self_error_daemon (get_self (servant), pilot_id, message);
+	dbus_daemon_error (DBusGProxy  *proxy,
+                           const gchar *pilot_id,
+                           const gchar *message,
+                           gpointer     data) {
+                Self *self = SELF(data);
+		self_error_daemon (self, pilot_id, message);
 	}	
 		
 	private void
-	corba_conduit_error (PortableServer_Servant servant,
-			    const CORBA_char *pilot_id,
-			    const CORBA_char *conduit_name,
-			    const CORBA_char *message,
-			    CORBA_Environment *ev) {
-		self_error_conduit (get_self (servant),pilot_id,conduit_name,message);
+	dbus_conduit_error (DBusGProxy  *proxy,
+			    const gchar *pilot_id,
+			    const gchar *conduit_name,
+                            const gchar *message,
+                            gpointer     data) {
+                Self *self = SELF(data);
+		self_error_conduit (self,pilot_id,conduit_name,message);
 	}
 
 	private void
-	corba_pause (PortableServer_Servant servant,
-		     const CORBA_boolean on_off,
-		     CORBA_Environment *ev) {
-		self_daemon_pause (get_self (servant), on_off);
+	dbus_paused (DBusGProxy  *proxy,
+		     gboolean     on_off,
+                     gpointer     data) {
+                Self *self = SELF(data);
+		self_daemon_pause (self, on_off);
 	}
 	
 	signal first NONE (POINTER,POINTER)
@@ -411,7 +501,9 @@ class Gnome:Pilot:Client from Gtk:Object {
 	void progress_overall (self, 
 			       const gchar *pilot_name,
 			       guint current, guint total)
-	{}
+	{
+                return;
+        }
 
 	signal first NONE (POINTER,POINTER,POINTER)
 	void message_conduit (self, const gchar *pilot_name, const gchar *conduit_name, const gchar *message) {
@@ -439,36 +531,65 @@ class Gnome:Pilot:Client from Gtk:Object {
 	}
 
         public gint pause_daemon (self) onerror GPILOTD_ERR_INVAL {
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-
-		GNOME_Pilot_Daemon_pause (self->gpilotddaemon,TRUE,&self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		GError   *error;
+		gboolean  res;
+
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"Pause",
+					&error,
+					G_TYPE_BOOLEAN, TRUE,
+					G_TYPE_INVALID,
+                                        G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to pause daemon : %s", error->message);   
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
+
 		return GPILOTD_OK;
 	}
 
         public gint unpause_daemon (self) onerror GPILOTD_ERR_INVAL {
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-
-		GNOME_Pilot_Daemon_pause (self->gpilotddaemon,FALSE,&self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		GError   *error;
+		gboolean  res;
+
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"Pause",
+					&error,
+					G_TYPE_BOOLEAN, FALSE,
+					G_TYPE_INVALID,
+                                        G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to unpause daemon : %s", error->message);   
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
+
 		return GPILOTD_OK;
         }
 
         public gint reread_config (self) onerror GPILOTD_ERR_INVAL {
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
+		GError   *error;
+		gboolean  res;
 
-		GNOME_Pilot_Daemon_reread_config (self->gpilotddaemon, &self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		
+		res = dbus_g_proxy_call (self->proxy,
+					"RereadConfig",
+					&error,
+					G_TYPE_INVALID,
+                                        G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to reread config : %s", error->message);   
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
 
@@ -476,14 +597,24 @@ class Gnome:Pilot:Client from Gtk:Object {
         }
 
         public gint noop (self) onerror GPILOTD_ERR_INVAL {
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
+		GError   *error;
+		gboolean  res;
 
-		GNOME_Pilot_Daemon_noop (self->gpilotddaemon, &self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
-			return GPILOTD_ERR_NOT_CONNECTED;
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		
+		res = dbus_g_proxy_call (self->proxy,
+					"Noop",
+					&error,
+					G_TYPE_INVALID,
+                                        G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to noop : %s", error->message);   
+			g_error_free (error);
+			return GPILOTD_ERR_FAILED;
 		}
+
 		return GPILOTD_OK;
 	}
 
@@ -500,124 +631,37 @@ class Gnome:Pilot:Client from Gtk:Object {
 		return self_connect_to_daemon (self);
         }
 
-	public gint monitor_on (self,
-			       const gchar *pilot_id (check null)) onerror GPILOTD_ERR_INVAL {
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-		g_return_val_if_fail (self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
-		GNOME_Pilot_Daemon_monitor_on (self->gpilotddaemon,self->gpilotdclient,pilot_id,&self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
-			return GPILOTD_ERR_FAILED;
-		}
-		return GPILOTD_OK;
-	}	
-
-        public gint monitor_on_all_pilots (self) {
-		GList   *pilots = NULL,
-			*ptr;
-		gint ret = GPILOTD_OK;
-		
-		if (self_get_pilots (self,&pilots) != GPILOTD_OK) return GPILOTD_ERR_FAILED;
-		
-		for (ptr = pilots; ptr; ptr = ptr->next) {
-			ret = self_monitor_on (self,(gchar*)ptr->data);
-		}
-		g_list_foreach (pilots,(GFunc)g_free,NULL);
-		return ret;
-        }
-
-	public gint monitor_off (self,
-				const gchar *pilot_id (check null)) onerror GPILOTD_ERR_INVAL {
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-		g_return_val_if_fail (self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
-
-		GNOME_Pilot_Daemon_monitor_off (self->gpilotddaemon,self->gpilotdclient,pilot_id,&self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
-			return GPILOTD_ERR_FAILED;
-		}
-		return GPILOTD_OK;
-	}	
-
-        public gint monitor_off_all_pilots (self) {
-		GList   *pilots = NULL,
-			*ptr;
-		gint ret = GPILOTD_OK;
-		
-		if (self_get_pilots (self,&pilots) != GPILOTD_OK) return GPILOTD_ERR_FAILED;
-		
-		for (ptr = pilots; ptr; ptr = ptr->next) {
-			ret = self_monitor_on (self,(gchar*)ptr->data);
-		}
-		g_list_foreach (pilots,(GFunc)g_free,NULL);
-		return ret;
-	}
-
-	public gint notify_on (self,
-			      GNOME_Pilot_EventType type) {
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-		g_return_val_if_fail (self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
-
-		GNOME_Pilot_Daemon_notify_on (self->gpilotddaemon,type,self->gpilotdclient,&self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
-			return GPILOTD_ERR_FAILED;
-		}
-		return GPILOTD_OK;
-	}	
-
-	public gint notify_off (self,
-			       GNOME_Pilot_EventType type) onerror GPILOTD_ERR_INVAL {
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-		g_return_val_if_fail (self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
-
-		GNOME_Pilot_Daemon_notify_off (self->gpilotddaemon,type,self->gpilotdclient,&self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
-			return GPILOTD_ERR_FAILED;
-		}
-		return GPILOTD_OK;
-	}	
-
 	public gint restore (self,
 			    const gchar *pilot_id (check null),
 			    const gchar *directory (check null),
 			    GNOME_Pilot_Survival survival,
 			    gint timeout (check >= 0),
 			    gint *handle) onerror GPILOTD_ERR_INVAL {
-		gint val;
-
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-		g_return_val_if_fail (self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
-
-		val = GNOME_Pilot_Daemon_request_restore (self->gpilotddaemon,
-							 self->gpilotdclient,
-							 pilot_id,
-							 directory,
-							 survival,
-							 timeout,
-							 &self->ev);
-		switch (self->ev._major) {
-		case CORBA_SYSTEM_EXCEPTION:
-		case CORBA_USER_EXCEPTION: {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			if (strcmp (ex_GNOME_Pilot_MissingFile,CORBA_exception_id (&self->ev))==0) {
-				g_warning ("Missing file");
-			} 
-			CORBA_exception_free (&self->ev);
+		GError   *error;
+		gboolean  res;
+		gint      val;
+
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		
+		res = dbus_g_proxy_call (self->proxy,
+					"RequestRestore",
+					&error,
+					G_TYPE_STRING, pilot_id,
+					G_TYPE_STRING, directory,
+					G_TYPE_UINT, survival,
+					G_TYPE_UINT, timeout,
+					G_TYPE_INVALID,
+					G_TYPE_UINT, &val,
+                                        G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to RequestRestore for pilot %s: %s", pilot_id, error->message);   
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
-			break;
-		}
-		case CORBA_NO_EXCEPTION: 
-		default:
-			break;
 		}
 
-		if (handle!=NULL) *handle = val;
+		if (handle != NULL) *handle = val;
 
 		return GPILOTD_OK;
 	}	    
@@ -628,18 +672,17 @@ class Gnome:Pilot:Client from Gtk:Object {
 				 GNOME_Pilot_Survival survival,
 				 gint timeout (check >=0),
 				 gint *handle) onerror GPILOTD_ERR_INVAL {
-		gint val;
+		gint     val;
+		gboolean res;
 		gboolean file_copied = FALSE;
-		gchar *filename;
+		gchar   *filename;
+		GError  *error;
 
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-		g_return_val_if_fail (self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
-	       
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
 		/* g_message ("Installing %s to %s", infile, pilot_name); */
 
 		{
 			gboolean result;
-			GError *err;
 			GFileCopyFlags copy_options = G_FILE_COPY_OVERWRITE;
 			GFile *src_gfile;
 			GFile *dest_gfile;
@@ -669,7 +712,7 @@ class Gnome:Pilot:Client from Gtk:Object {
 			}
 
 			src_gfile = g_file_new_for_path (infile_with_path);
-			dest_gfile = g_file_new_for_path (filename_uri);
+			dest_gfile = g_file_new_for_uri (filename_uri);
 
 			/*
 			g_message ("from : \"%s\"", infile_with_path);
@@ -681,13 +724,13 @@ class Gnome:Pilot:Client from Gtk:Object {
 						     NULL,
 						     NULL,
 						     self,
-						     &err);
+						     &error);
 
 			if (result) {
 				file_copied = TRUE;
 			} else {
 			        g_message("VFS Error: %s\n",
-					err->message);
+					error->message);
 				file_copied = FALSE;
 			}
 			g_free (filename_uri);
@@ -701,35 +744,26 @@ error:		if (file_copied == FALSE) {
 			return GPILOTD_ERR_FAILED;
 		}
 
-		val = GNOME_Pilot_Daemon_request_install (self->gpilotddaemon,
-							 self->gpilotdclient,
-							 pilot_name,
-							 filename,
-							 infile,
-							 survival,
-							 timeout,
-							 &self->ev);
-		switch (self->ev._major) {
-		case CORBA_NO_EXCEPTION: 
-			break;
-		case CORBA_SYSTEM_EXCEPTION:
-		case CORBA_USER_EXCEPTION:
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			
-			if (strcmp (ex_GNOME_Pilot_MissingFile,CORBA_exception_id (&self->ev))==0) {
-				g_warning ("Missing file");
-			} else {
-				unlink (filename);
-			}
-			CORBA_exception_free (&self->ev);
-			free (filename);
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"RequestInstall",
+					&error,
+					G_TYPE_STRING, pilot_name,
+					G_TYPE_STRING, filename,
+					G_TYPE_STRING, infile,
+					G_TYPE_UINT, survival,
+					G_TYPE_UINT, timeout,
+					G_TYPE_INVALID,
+					G_TYPE_UINT, &val,
+                                        G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to RequestInstall for pilot %s: %s", pilot_name, error->message);
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
-			break;
-		default:
-			break;
 		}
 
-		if (handle!=NULL) *handle = val;
+		if (handle != NULL) *handle = val;
 
 		free (filename);
 		return GPILOTD_OK;
@@ -740,25 +774,48 @@ error:		if (file_copied == FALSE) {
 				  GNOME_Pilot_Survival survival,
 				  gint timeout (check >= 0),
 	                          gint *handle) onerror GPILOTD_ERR_INVAL {
-		gint val;
-
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-		g_return_val_if_fail (self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
-
-		val = GNOME_Pilot_Daemon_get_user_info (self->gpilotddaemon,
-						       self->gpilotdclient,
-						       cradle_name,
-						       survival,
-						       timeout,
-						       &self->ev);
-
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		gint      val;
+		GError   *error;
+		gboolean  res;
+
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+
+                dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_UINT_STRING,
+                                           G_TYPE_NONE,
+                                           G_TYPE_STRING,
+                                           G_TYPE_UINT,
+                                           G_TYPE_STRING,
+                                           G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "UserInfoRequested",
+                                         G_TYPE_STRING,
+                                         G_TYPE_UINT,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "UserInfoRequested",
+                                     G_CALLBACK (self_dbus_user_info_requested),
+                                     self,
+                                     NULL);
+
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetUserInfo",
+					&error,
+					G_TYPE_STRING, cradle_name,
+					G_TYPE_UINT, survival,
+					G_TYPE_UINT, timeout,
+					G_TYPE_INVALID,
+					G_TYPE_UINT, &val,
+                                        G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetUserInfo for cradle %s: %s", cradle_name, error->message);
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
 
-		if (handle!=NULL) *handle =val;
+		if (handle != NULL) *handle =val;
 
 		return GPILOTD_OK;
 	}
@@ -770,27 +827,32 @@ error:		if (file_copied == FALSE) {
 				  GNOME_Pilot_Survival survival,
 				  gint timeout (check >= 0),
 				  gint *handle) onerror GPILOTD_ERR_INVAL {
-		gint val;
-
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-		g_return_val_if_fail (self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
-
-		val = GNOME_Pilot_Daemon_set_user_info (self->gpilotddaemon,
-						       self->gpilotdclient,
-						       &user,
-						       cradle_name,
-						       continue_sync,
-						       survival,
-						       timeout,
-						       &self->ev);
-
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		gint      val;
+		GError   *error;
+		gboolean  res;
+
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"SetUserInfo",
+					&error,
+					G_TYPE_STRING, cradle_name,
+					G_TYPE_BOOLEAN, continue_sync,
+					G_TYPE_UINT, survival,
+					G_TYPE_UINT, timeout,
+					G_TYPE_UINT, user.userID,
+					G_TYPE_STRING, user.username,
+					G_TYPE_INVALID,
+					G_TYPE_UINT, &val,
+                                        G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to SetUserInfo for cradle %s: %s", cradle_name, error->message);
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
 
-		if (handle!=NULL) *handle =val;
+		if (handle != NULL) *handle =val;
 
 		return GPILOTD_OK;
 	}
@@ -800,40 +862,82 @@ error:		if (file_copied == FALSE) {
 				    GNOME_Pilot_Survival survival,
 				    gint timeout,
 				    gint *handle) onerror GPILOTD_ERR_INVAL {
-		gint val;
-
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-		g_return_val_if_fail (self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
-
-		val = GNOME_Pilot_Daemon_get_system_info (self->gpilotddaemon,
-							 self->gpilotdclient,
-							 cradle_name,
-							 survival,
-							 timeout,
-							 &self->ev);
-
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		gint      val;
+		GError   *error;
+		gboolean  res;
+
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+
+                dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_UINT_UINT_UINT_STRING_STRING_UINT_UINT,
+                                           G_TYPE_NONE,
+                                           G_TYPE_STRING,
+                                           G_TYPE_UINT,
+                                           G_TYPE_UINT,
+                                           G_TYPE_UINT,
+                                           G_TYPE_STRING,
+                                           G_TYPE_STRING,
+                                           G_TYPE_UINT,
+                                           G_TYPE_UINT,
+                                           G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "SysInfoRequested",
+                                         G_TYPE_STRING,
+                                         G_TYPE_UINT,
+                                         G_TYPE_UINT,
+                                         G_TYPE_UINT,
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_UINT,
+                                         G_TYPE_UINT,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "SysInfoRequested",
+                                     G_CALLBACK (self_dbus_system_info_requested),
+                                     self,
+                                     NULL);
+
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetSystemInfo",
+					&error,
+					G_TYPE_STRING, cradle_name,
+					G_TYPE_UINT, survival,
+					G_TYPE_UINT, timeout,
+					G_TYPE_INVALID,
+					G_TYPE_UINT, &val,
+                                        G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetSystemInfo for cradle %s: %s", cradle_name, error->message);
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
 
-		if (handle!=NULL) *handle =val;
+		if (handle != NULL) *handle =val;
 
 		return GPILOTD_OK;
 	}
 
         public gint remove_request (self,
 				   gint handle) onerror GPILOTD_ERR_INVAL {
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-		g_return_val_if_fail (self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
-
-		GNOME_Pilot_Daemon_remove_request (self->gpilotddaemon,handle,&self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		GError   *error;
+		gboolean  res;
+
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"RemoveRequest",
+					&error,
+					G_TYPE_UINT, handle,
+					G_TYPE_INVALID,
+                                        G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to RemoveRequest for handle %d: %s", handle, error->message);
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
+
 		return GPILOTD_OK;		
 	}
 
@@ -844,203 +948,376 @@ error:		if (file_copied == FALSE) {
 			    GNOME_Pilot_Survival survival, 
 			    gint timeout (check >= 0),
 			    gint *handle) onerror GPILOTD_ERR_INVAL {
-		gint val;
-
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-		g_return_val_if_fail (self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
-		
-		val = GNOME_Pilot_Daemon_request_conduit (self->gpilotddaemon,
-							 self->gpilotdclient,
-							 pilot_name,
-							 conduit_name,
-							 operation,
-							 survival,
-							 timeout,
-							 &self->ev);
-		
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		gint      val;
+		GError   *error;
+		gboolean  res;
+
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"RequestConduit",
+					&error,
+					G_TYPE_STRING, pilot_name,
+					G_TYPE_STRING, conduit_name,
+					G_TYPE_UINT, operation,
+					G_TYPE_UINT, survival,
+					G_TYPE_UINT, timeout,
+					G_TYPE_INVALID,
+					G_TYPE_UINT, &val,
+                                        G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to RequestConduit for pilot %s: %s", pilot_name, error->message);
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
 
-		if (handle!=NULL) *handle =val;
+		if (handle != NULL) *handle =val;
 
 		return GPILOTD_OK;
 	}
 
-	private gint get_triple_ptr (self,
-				    enum get_triple_ptr_action action,
-				    const gchar *name,
-				    GList **output (check null)) onerror GPILOTD_ERR_INVAL {
-		GNOME_Pilot_StringSequence *seq=NULL;
-		GNOME_Pilot_LongSequence *seq_long=NULL;
-	
-#ifndef G_DISABLE_CHECKS		
-		if (*output!=NULL) {
-			g_warning ("%s:%d: get_triple_ptr called with non-null pointer for output, leak-alert!",
+        public gint get_users (self,
+			      GList **output (check null)) onerror GPILOTD_ERR_INVAL {
+		GError     *error;
+		gboolean    res;
+		char      **arr;
+                char      **p;
+
+#ifndef G_DISABLE_CHECKS
+		if (*output != NULL) {
+			g_warning ("%s:%d: get_users called with non-null pointer for output, leak-alert!",
 				  __FILE__,__LINE__);
 		}
 #endif
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-
-		(*output) = NULL;
-
-		switch (action) {
-		case GPILOTD_APP_PILOT_NAMES:
-			seq = GNOME_Pilot_Daemon_get_pilots (self->gpilotddaemon, &self->ev);
-			break;
-		case GPILOTD_APP_PILOT_IDS:
-			seq_long = GNOME_Pilot_Daemon_get_pilot_ids (self->gpilotddaemon, &self->ev);
-			break;
-		case GPILOTD_APP_PILOTS_BY_NAME:
-			seq = GNOME_Pilot_Daemon_get_pilots_by_user_name (self->gpilotddaemon,name,&self->ev);
-			break;
-		case GPILOTD_APP_PILOTS_BY_LOGIN:
-			seq = GNOME_Pilot_Daemon_get_pilots_by_user_login (self->gpilotddaemon,name,&self->ev);
-			break;
-		case GPILOTD_APP_USER_NAMES:
-			seq = GNOME_Pilot_Daemon_get_users (self->gpilotddaemon,&self->ev);
-			break;
-		case GPILOTD_APP_DATABASES_FROM_CACHE:
-			seq = GNOME_Pilot_Daemon_get_databases_from_cache (self->gpilotddaemon,name,&self->ev);
-			break;
-		case GPILOTD_APP_CRADLES:
-			seq = GNOME_Pilot_Daemon_get_cradles (self->gpilotddaemon,&self->ev);
-			break;
-		}
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		arr = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetUsers",
+					&error,
+					G_TYPE_INVALID,
+                                        G_TYPE_STRV, &arr,
+					G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetUsers %s", error->message);
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
-		if (seq && seq->_length>0) {
-			int i;
-			for (i=0;i<seq->_length;i++) {
-				if (strlen (seq->_buffer[i]))
-					(*output) = g_list_append ((*output),g_strdup (seq->_buffer[i]));
-			}
-		} 
-		if (seq_long && seq_long->_length>0) {
-			int i;
-			for (i=0;i<seq_long->_length;i++) {
+
+		(*output) = NULL;
+		for (p = arr; p != NULL && *p != NULL; p++) {
+			if (IS_STR_SET (*p) ) {
 				(*output) = g_list_append ((*output),
-							   GINT_TO_POINTER (seq_long->_buffer[i]));
+							    g_strdup (*p));
 			}
-		} 
-		
-		CORBA_free (seq);
-		CORBA_free (seq_long);
+		}
 
-		return GPILOTD_OK;
-	}
+                g_strfreev (arr);
 
-        public gint get_users (self,
-			      GList **output (check null)) onerror GPILOTD_ERR_INVAL {
-		return self_get_triple_ptr (self,GPILOTD_APP_USER_NAMES,NULL,output);
+		return GPILOTD_OK;
 	}
 
         public gint get_databases_from_cache (self,
 					     const gchar *pilot_name,
 					     GList **output (check null)) onerror GPILOTD_ERR_INVAL {
-		return self_get_triple_ptr (self,GPILOTD_APP_DATABASES_FROM_CACHE,pilot_name,output);
+		GError     *error;
+		gboolean    res;
+		char      **arr;
+		char      **p;
+
+#ifndef G_DISABLE_CHECKS		
+		if (*output != NULL) {
+			g_warning ("%s:%d: get_databases_from_cache called with non-null pointer for output, leak-alert!",
+				  __FILE__,__LINE__);
+		}
+#endif
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		arr = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetDatabasesFromCache",
+					&error,
+					G_TYPE_STRING, pilot_name,
+					G_TYPE_INVALID,
+                                        G_TYPE_STRV, &arr,
+					G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetDatabasesFromCache %s : %s", pilot_name, error->message);
+			g_error_free (error);
+			return GPILOTD_ERR_FAILED;
+		}
+
+		(*output) = NULL;
+                for (p = arr; p != NULL && *p != NULL; p++) {
+                        if (IS_STR_SET (*p) ) {
+                                (*output) = g_list_append ((*output), g_strdup (*p));
+                        }
+                }
+
+
+		g_strfreev (arr);
+		return GPILOTD_OK;
 	}
 
 	public gint get_cradles (self,
 				 GList **output (check null)) onerror GPILOTD_ERR_INVAL {
-		return self_get_triple_ptr (self,GPILOTD_APP_CRADLES,NULL,output);
+		GError     *error;
+		gboolean    res;
+		char      **arr;
+                char      **p;
+
+#ifndef G_DISABLE_CHECKS		
+		if (*output != NULL) {
+			g_warning ("%s:%d: get_cradles called with non-null pointer for output, leak-alert!",
+				  __FILE__,__LINE__);
+		}
+#endif
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		arr = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetCradles",
+					&error,
+					G_TYPE_INVALID,
+					G_TYPE_STRV, &arr,
+					G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetCradles: %s", error->message);
+			g_error_free (error);
+			return GPILOTD_ERR_FAILED;
+		}
+
+		(*output) = NULL;
+		for (p = arr; p != NULL && *p != NULL; p++) {
+			if (IS_STR_SET (*p) ) {
+				(*output) = g_list_append ((*output),
+							    g_strdup (*p));
+			}
+		}
+
+                g_strfreev (arr);
+		return GPILOTD_OK;
 	}
 
 	public gint get_pilots (self,
 				GList **output (check null)) onerror GPILOTD_ERR_INVAL {
-		return self_get_triple_ptr (self,GPILOTD_APP_PILOT_NAMES,NULL,output);
+		GError     *error;
+		gboolean    res;
+		char      **arr;
+                char      **p;
+
+#ifndef G_DISABLE_CHECKS		
+		if (*output != NULL) {
+			g_warning ("%s:%d: get_pilots called with non-null pointer for output, leak-alert!",
+				  __FILE__,__LINE__);
+		}
+#endif
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		arr = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetPilots",
+					&error,
+					G_TYPE_INVALID,
+					G_TYPE_STRV, &arr,
+					G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetPilots: %s", error->message);
+			g_error_free (error);
+			return GPILOTD_ERR_FAILED;
+		}
+
+		(*output) = NULL;
+		for (p = arr; p != NULL && *p != NULL; p++) {
+			if (IS_STR_SET (*p) ) {
+				(*output) = g_list_append ((*output),
+							    g_strdup (*p));
+			}
+		}
+
+                g_strfreev (arr);
+		return GPILOTD_OK;
 	}
 	
 	public gint get_pilot_ids (self,
 				   gint **output (check null)) onerror GPILOTD_ERR_INVAL {
-		GList *long_output = NULL, *ptr;
-		gint result, idx;
+		GError     *error;
+		gboolean    res;
+		GPtrArray  *arr;
+		int         i;
 
-		result = self_get_triple_ptr (self, GPILOTD_APP_PILOT_IDS, NULL, &long_output);
+#ifndef G_DISABLE_CHECKS		
+		if (*output != NULL) {
+			g_warning ("%s:%d: get_pilot_ids called with non-null pointer for output, leak-alert!",
+				  __FILE__,__LINE__);
+		}
+#endif
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		arr = NULL;
+
+		res = dbus_g_proxy_call (self->proxy,
+					"GetPilotIDs",
+					&error,
+					G_TYPE_INVALID,
+					dbus_g_type_get_collection ("GPtrArray", G_TYPE_UINT),
+					&arr,
+					G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetPilotIDs: %s", error->message);
+			g_error_free (error);
+			return GPILOTD_ERR_FAILED;
+		}
 
-		(*output) = g_new0 (int, g_list_length (long_output));
-		idx = 0;
-		for (ptr = long_output; ptr; ptr = g_list_next (ptr)) {
-			(*output)[idx] = GPOINTER_TO_INT (ptr->data);
-			idx++;
+		(*output) = g_new0 (int, arr->len);
+		for (i = 0; i < arr->len; i++) {
+                        (*output)[i] = GPOINTER_TO_UINT (g_ptr_array_index (arr, i));
 		}
-		g_list_free (long_output);
 
-		return result;
+		g_ptr_array_free (arr, FALSE);
+		return GPILOTD_OK;
 	}
 
 
 	public gint get_pilots_by_user_name (self,
 					    const gchar *name (check null),
 					    GList **output (check null)) onerror GPILOTD_ERR_INVAL {
-		return self_get_triple_ptr (self,GPILOTD_APP_PILOTS_BY_NAME,name,output);
+		GError     *error;
+		gboolean    res;
+		char      **arr;
+                char      **p;
+
+#ifndef G_DISABLE_CHECKS		
+		if (*output != NULL) {
+			g_warning ("%s:%d: get_pilots_by_user_name called with non-null pointer for output, leak-alert!",
+				  __FILE__,__LINE__);
+		}
+#endif
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		arr = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetPilotsByUserName",
+					&error,
+					G_TYPE_STRING, name,
+					G_TYPE_INVALID,
+					G_TYPE_STRV, &arr,
+					G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetPilotsByUserName %s : %s", name, error->message);
+			g_error_free (error);
+			return GPILOTD_ERR_FAILED;
+		}
+
+		(*output) = NULL;
+		for (p = arr; p != NULL && *p != NULL; p++) {
+			if (IS_STR_SET (*p) ) {
+				(*output) = g_list_append ((*output),
+							    g_strdup (*p));
+			}
+		}
+
+                g_strfreev (arr);
+
+		return GPILOTD_OK;
 	}
 
 	public gint get_pilots_by_user_login (self,
 					     const gchar *login (check null),
 					     GList **output (check null)) onerror GPILOTD_ERR_INVAL {
-		return self_get_triple_ptr (self,GPILOTD_APP_PILOTS_BY_LOGIN,login,output);
-	}
+		GError     *error;
+		gboolean    res;
+		char      **arr;
+		char      **p;
 
-	public gint get_user_name_by_pilot_name (self,
-						const gchar *pilot_name (check null),
-						gchar **output (check null)) onerror GPILOTD_ERR_INVAL {
-		CORBA_char *user_name = NULL;
-
- 		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
 #ifndef G_DISABLE_CHECKS		
-		if (*output!=NULL) {
-			g_warning ("%s:%d: get_user_name_by_pilot_name called with non-null pointer for output, leak-alert!",
+		if (*output != NULL) {
+			g_warning ("%s:%d: get_pilots_by_user_login called with non-null pointer for output, leak-alert!",
 				  __FILE__,__LINE__);
 		}
 #endif
-		user_name = GNOME_Pilot_Daemon_get_user_name_by_pilot_name (self->gpilotddaemon,
-									    pilot_name,
-									    &self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, 
-				   CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
+		error = NULL;
+		arr = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetPilotsByUserLogin",
+					&error,
+					G_TYPE_STRING, login,
+					G_TYPE_INVALID,
+					G_TYPE_STRV, &arr,
+					G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetPilotsByUserLogin %s : %s", login, error->message);
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
-		
-		*output = g_strdup (user_name);
-		CORBA_free (user_name);
 
-		return GPILOTD_OK;	
+		(*output) = NULL;
+		for (p = arr; p != NULL && *p != NULL; p++) {
+			if (IS_STR_SET (*p) ) {
+				(*output) = g_list_append ((*output),
+							    g_strdup (*p));
+			}
+		}
+
+                g_strfreev (arr);
+		return GPILOTD_OK;
+	}
+
+	public gint get_user_name_by_pilot_name (self,
+						const gchar *pilot_name (check null),
+						gchar **output (check null)) onerror GPILOTD_ERR_INVAL {
+		GError     *error;
+		gboolean    res;
+
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetUserNameByPilotName",
+					&error,
+					G_TYPE_STRING, pilot_name,
+					G_TYPE_INVALID,
+					G_TYPE_STRING, output,
+					G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetUserNameByPilotName %s : %s", pilot_name, error->message);
+			g_error_free (error);
+			return GPILOTD_ERR_FAILED;
+		}
+
+		return GPILOTD_OK;
 	}
 
         public gint get_user_login_by_pilot_name (self,
 						 const gchar *pilot_name (check null),
 						 gchar **output (check null)) onerror GPILOTD_ERR_INVAL {
-		CORBA_char *user_login = NULL;
-
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-#ifndef G_DISABLE_CHECKS		
-		if (*output!=NULL) {
-			g_warning ("%s:%d: get_user_login_by_pilot_name called with non-null pointer for output, leak-alert!",
-				  __FILE__,__LINE__);
-		}
-#endif
-		user_login = GNOME_Pilot_Daemon_get_user_login_by_pilot_name (self->gpilotddaemon,
-									      pilot_name,
-									      &self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, 
-				   CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		GError     *error;
+		gboolean    res;
+
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetUserLoginByPilotName",
+					&error,
+					G_TYPE_STRING, pilot_name,
+					G_TYPE_INVALID,
+					G_TYPE_STRING, output,
+					G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetUserLoginByPilotName %s : %s", pilot_name, error->message);
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
-		
-		*output = g_strdup (user_login);
-		CORBA_free (user_login);
 
-		return GPILOTD_OK;	
+		return GPILOTD_OK;
 	}
 
 	/* Output must be a pointer to a gchar*, and *output should be
@@ -1050,31 +1327,31 @@ error:		if (file_copied == FALSE) {
 	public gint get_pilot_base_dir_by_name (self,
 						const gchar *pilot_name (check null),
 						gchar **output (check null)) onerror GPILOTD_ERR_INVAL {
-		CORBA_char *basedir;
-
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-#ifndef G_DISABLE_CHECKS		
-		if (*output!=NULL) {
-			g_warning ("%s:%d: get_pilot_base_dir_by_name called with non-null pointer for output, leak-alert!",
-				  __FILE__,__LINE__);
-		}
-#endif
-		basedir = GNOME_Pilot_Daemon_get_pilot_base_dir (self->gpilotddaemon,pilot_name,&self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		GError     *error;
+		gboolean    res;
+
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetPilotBaseDir",
+					&error,
+					G_TYPE_STRING, pilot_name,
+					G_TYPE_INVALID,
+					G_TYPE_STRING, output,
+					G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetPilotBaseDir %s : %s", pilot_name, error->message);
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
-		
-		*output = g_strdup (basedir);
-		CORBA_free (basedir);
-		
-		if (strlen (*output)==0) {
+
+		if (!IS_STR_SET (*output)) {
 			g_free (*output);
-		       *output = g_strdup_printf ("%s/%s",g_get_home_dir (),pilot_name);
+		       *output = g_strdup_printf ("%s/%s",g_get_home_dir (), 
+						  pilot_name);
 		}
 		
-		return GPILOTD_OK;	
+		return GPILOTD_OK;
 	}
 
 	public gint get_pilot_base_dir_by_id (self,
@@ -1083,12 +1360,12 @@ error:		if (file_copied == FALSE) {
 		gchar *pilot_name;
 		gint return_code;
 
-		return_code = self_get_pilot_name_by_id (self,pilot_id,&pilot_name);
-		if (return_code!=GPILOTD_OK) {
+		return_code = self_get_pilot_name_by_id (self, pilot_id, &pilot_name);
+		if (return_code != GPILOTD_OK) {
 			return return_code;
 		}
 
-		return_code = self_get_pilot_base_dir_by_name (self,pilot_name,output);
+		return_code = self_get_pilot_base_dir_by_name (self, pilot_name, output);
 		g_free (pilot_name);
 		return return_code;
 	}
@@ -1097,39 +1374,49 @@ error:		if (file_copied == FALSE) {
 	public gint get_pilot_id_by_name (self,
 					   const gchar *pilot_name (check null),
 					   guint32 *output (check null)) onerror GPILOTD_ERR_INVAL {		
-		g_return_val_if_fail (self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
-		
-		*output = GNOME_Pilot_Daemon_get_pilot_id_from_name (self->gpilotddaemon,pilot_name,&self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		GError     *error;
+		gboolean    res;
+
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetPilotIdFromName",
+					&error,
+					G_TYPE_STRING, pilot_name,
+					G_TYPE_INVALID,
+					G_TYPE_UINT, output,
+					G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetPilotIdFromName %s : %s", pilot_name, error->message);
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
-		
-		return GPILOTD_OK;	
+
+		return GPILOTD_OK;
 	}
 
 	public gint get_pilot_name_by_id (self,
 					 guint32 pilot_id,
 					 gchar **output (check null)) onerror GPILOTD_ERR_INVAL {
-		CORBA_char *name;
-#ifndef G_DISABLE_CHECKS		
-		if (*output!=NULL) {
-			g_warning ("%s:%d: get_pilot_name_by_id called with non-null pointer for output, leak-alert!",
-				  __FILE__,__LINE__);
-		}
-#endif
-		name = GNOME_Pilot_Daemon_get_pilot_name_from_id (self->gpilotddaemon,pilot_id,&self->ev);
-		if (self->ev._major != CORBA_NO_EXCEPTION) {
-			g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
-			CORBA_exception_free (&self->ev);
+		GError     *error;
+		gboolean    res;
+
+		error = NULL;
+		res = dbus_g_proxy_call (self->proxy,
+					"GetPilotNameFromId",
+					&error,
+					G_TYPE_UINT, &pilot_id,
+					G_TYPE_INVALID,
+					G_TYPE_STRING, output,
+					G_TYPE_INVALID);
+
+		if (!res) {
+			g_warning ("Unable to GetPilotNameFromId %d : %s", pilot_id, error->message);
+			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
-		
-		*output = g_strdup (name);
-		CORBA_free (name);
-		
-		if (output==NULL || strlen (*output)==0) {
+
+		if (!IS_STR_SET (output)) {
 			g_free (*output);
 			return GPILOTD_ERR_FAILED;
 		}
@@ -1176,11 +1463,4 @@ gpilotd_get_pid (void)
 	}
 }
 
-GnomePilotClient *
-get_self (PortableServer_Servant servant) {
-	GnomePilotClientServant *s;
-	s = (GnomePilotClientServant*)servant;
-	return s->self;
-}
-
 %}
diff --git a/gpilotd/gpilot-daemon.c b/gpilotd/gpilot-daemon.c
new file mode 100644
index 0000000..a390e1f
--- /dev/null
+++ b/gpilotd/gpilot-daemon.c
@@ -0,0 +1,3082 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- *//* 
+ *
+ * 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.
+ *
+ * Authors: Halton Huo <halton.huo@gmail.com>
+ *
+ */
+
+#include "config.h"
+
+/* for crypt () */
+#ifdef USE_XOPEN_SOURCE
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE 
+#endif /* _XOPEN_SOURCE  */
+#endif
+
+#define _BSD_SOURCE 1		/* Or gethostname won't be declared properly
+				   on Linux and GNU platforms. */
+
+#include <unistd.h>
+#include <pwd.h>
+#include <sys/stat.h>
+#include <regex.h>
+#include <crypt.h>
+#include <libxml/xmlmemory.h>
+#include <libxml/entities.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <pi-dlp.h>
+
+#include "gpilot-daemon.h"
+#include "gpilot-daemon-glue.h"
+#include "gnome-pilot-structures.h"
+#include "gnome-pilot-conduit-standard.h"
+#include "queue_io.h"
+#include "gnome-pilot-config.h"
+#include "gpmarshal.h"
+#include "gpilot-gui.h"
+#include "manager.h"
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#ifdef WITH_HAL
+#include <libhal.h>
+#endif
+
+#define GP_DBUS_NAME         "org.gnome.GnomePilot"
+#define GP_DBUS_PATH         "/org/gnome/GnomePilot/Daemon"
+#define GP_DBUS_INTERFACE    "org.gnome.GnomePilot.Daemon"
+
+#define IS_STR_SET(x) (x != NULL && x[0] != '\0')
+
+#define GPILOT_DAEMON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPILOT_TYPE_DAEMON, GpilotDaemonPrivate))
+
+#define DEBUG_CODE
+
+static void     gpilot_daemon_class_init  (GpilotDaemonClass *klass);
+static void     gpilot_daemon_init        (GpilotDaemon      *daemon);
+static void     gpilot_daemon_finalize    (GObject           *object);
+
+static gpointer daemon_object = NULL;
+
+/* Set to true when the config should be reloaded */
+static void monitor_channel (GPilotDevice *dev, GPilotContext *context);
+static gboolean device_in (GIOChannel *, GIOCondition, GPilotContext *);
+static gboolean device_err (GIOChannel *, GIOCondition, GPilotContext *);
+static gboolean network_device_in (GIOChannel *, GIOCondition, GPilotContext *);
+static gboolean network_device_err (GIOChannel *, GIOCondition, GPilotContext *);
+static int pilot_connect (GPilotDevice *device,int *error);
+static int check_usb_config (GPilotDevice *device);
+static gboolean do_cradle_events (int pfd, GPilotContext *context, struct PilotUser *pu, GPilotDevice *device);
+static void gpilot_syncing_unknown_pilot (struct PilotUser pu, int pfd, GPilotDevice *device, GPilotContext *context);
+static void gpilot_syncing_known_pilot (GPilotPilot *pilot, struct PilotUser pu, int pfd, GPilotDevice *device, GPilotContext *context);
+static void pilot_disconnect (int sd);
+static void load_devices_xml (void);
+static int  known_usb_device (gchar *match_str);
+static gboolean sync_device (GPilotDevice *device, GPilotContext *context);
+
+#ifdef WITH_HAL
+static DBusConnection *dbus_connection = NULL;
+static LibHalContext *hal_ctx = NULL;
+
+static gboolean gpilotd_dbus_init (void);
+static LibHalContext *gpilotd_hal_init (void);
+#endif
+
+static guint visor_timeout_id = -1;
+static guint hal_initialised = 0;
+static GPtrArray *vendor_product_ids = NULL;
+static GArray *product_net = NULL;
+
+G_DEFINE_TYPE (GpilotDaemon, gpilot_daemon, G_TYPE_OBJECT)
+
+struct GpilotDaemonPrivate
+{
+        GPilotContext   *gpilotd_context;
+        DBusGProxy      *bus_proxy;
+        DBusGConnection *connection;
+};
+
+enum {
+        CONNECTED,
+        DISCONNECTED,
+        REQUEST_COMPLETED,
+        USERINFO_REQUESTED,
+        SYSINFO_REQUESTED,
+        CONDUIT_START,
+        CONDUIT_PROGRESS,
+        CONDUIT_END,
+        OVERALL_PROGRESS,
+        DAEMON_MESSAGE,
+        DAEMON_ERROR,
+        CONDUIT_MESSAGE,
+        CONDUIT_ERROR,
+        PAUSED,
+        LAST_SIGNAL
+};
+
+static guint signals [LAST_SIGNAL] = { 0, };
+
+static void
+gpilot_daemon_pause_device (GPilotDevice *device,
+                            gpointer      data)
+{
+        if (device->io) {
+                g_source_remove(device->in_handle);
+                g_source_remove(device->err_handle);
+        }
+}
+
+static gint
+match_pilot_and_name(const GPilotPilot *pilot,
+                     const gchar       *name)
+{
+        if(pilot) {
+                return g_ascii_strcasecmp (name, pilot->name);
+        }
+        return -1; 
+}
+
+static gint
+match_pilot_userID (const GPilotPilot   *p,
+                    const guint32       *id)
+{
+        if(p->pilot_id == *id)
+                return 0;
+        return -1;
+}
+
+#ifdef WITH_HAL
+static void
+hal_device_added (LibHalContext *ctx, const char *udi)
+{
+	gboolean visor_net = FALSE;
+	char *bus, *platform, *match_str;
+	int vendor_id, product_id, i;
+	GPilotDevice *device;
+	DBusError error;
+	GList *dev;
+        GpilotDaemonPrivate *priv;
+
+        priv = GPILOT_DAEMON (daemon_object)->priv;
+
+	if (priv->gpilotd_context->paused) 
+		return;
+
+	load_devices_xml ();
+
+	/* HAL match rule: we look for pda.platform == 'palm'
+	 * (or the legacy info.bus == 'usb_device')
+	 * and then try to match the usb_device.product_id and usb_device.vendor_id
+	 * against the list in devices.xml.
+	 */
+	if ((platform = libhal_device_get_property_string (hal_ctx, udi, "pda.platform", NULL))) {
+	    if (strcmp (platform, "palm") != 0) {
+		libhal_free_string (platform);
+		return;
+	    }
+	    libhal_free_string (platform);
+	} else if ((bus = libhal_device_get_property_string (hal_ctx, udi, "info.bus", NULL))) {
+	    if (strcmp (bus, "usb_device") != 0) {
+		libhal_free_string (bus);
+		return;
+	    }
+	    libhal_free_string (bus);
+	} else {
+	    return;
+	}
+
+	dbus_error_init (&error);
+	vendor_id = libhal_device_get_property_int (hal_ctx, udi,
+	    "usb_device.vendor_id", &error);
+	if(vendor_id == -1) {
+		g_warning ("Could not get usb vendor ID from hal: %s", error.message);
+		return;
+	}
+	product_id = libhal_device_get_property_int (hal_ctx, udi,
+	    "usb_device.product_id", NULL);
+	if(product_id == -1) {
+		g_warning ("Could not get usb product ID from hal: %s", error.message);
+		return;
+	}
+	
+	/* now look for a vendor/product match */
+	match_str = g_strdup_printf ("Vendor=%04x ProdID=%04x",
+	    vendor_id, product_id);
+	i = known_usb_device(match_str);
+	g_free(match_str);
+	if(i == -1)
+		return;
+
+	visor_net = g_array_index (product_net, gboolean, i);
+	dev = priv->gpilotd_context->devices;
+	while (dev != NULL) {
+		device = dev->data;
+		if (device->type == PILOT_DEVICE_USB_VISOR) {
+			if (!visor_net)
+				device->type = PILOT_DEVICE_SERIAL;
+			/* problems have been reported with devices
+ 			 * not being ready for sync immediately,
+ 			 * so we wait for 0.4 seconds.  See
+ 			 * bugzilla.gnome #362565
+ 			 */
+			usleep(400000);
+			/* just try to sync.  Until I can talk to 
+			 * the kernel guys this is the best way to 
+			 * go. */
+			sync_device (device, priv->gpilotd_context);
+
+			if (!visor_net)
+				device->type = PILOT_DEVICE_USB_VISOR;
+			
+			break;
+		}
+		
+		dev = dev->next;
+	}
+}
+
+static void
+hal_device_removed (LibHalContext *ctx, const char *udi)
+{
+	
+}
+
+static gboolean
+reinit_dbus (gpointer user_data)
+{
+	if (gpilotd_dbus_init ()) {
+		if ((hal_ctx = gpilotd_hal_init ()))
+			libhal_ctx_set_dbus_connection (hal_ctx, dbus_connection);
+		else
+			exit (1);
+		
+		return FALSE;
+	}
+	
+	return TRUE;
+}
+
+static DBusHandlerResult
+gpilotd_dbus_filter_function (DBusConnection *connection, DBusMessage *message, void *user_data)
+{
+	if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") &&
+	    strcmp (dbus_message_get_path (message), DBUS_PATH_LOCAL) == 0) {
+		libhal_ctx_free (hal_ctx);
+		hal_ctx = NULL;
+		
+		dbus_connection_unref (dbus_connection);
+		dbus_connection = NULL;
+		
+		g_timeout_add (3000, reinit_dbus, NULL);
+		
+		return DBUS_HANDLER_RESULT_HANDLED;
+	}
+	
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static gboolean
+gpilotd_dbus_init (void)
+{
+	DBusError error;
+	
+	if (dbus_connection != NULL)
+		return TRUE;
+	
+	dbus_error_init (&error);
+	if (!(dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
+		g_warning ("could not get system bus: %s", error.message);
+		dbus_error_free (&error);
+		return FALSE;
+	}
+	
+	dbus_connection_setup_with_g_main (dbus_connection, NULL);
+	dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
+	
+	dbus_connection_add_filter (dbus_connection, gpilotd_dbus_filter_function, NULL, NULL);
+	
+	return TRUE;
+}
+
+static LibHalContext *
+gpilotd_hal_init (void)
+{
+	LibHalContext *ctx;
+	DBusError error;
+	char **devices;
+	int nr;
+	
+	if (!gpilotd_dbus_init ()) {
+		g_warning ("failed to initialise DBUS!");
+		return NULL;
+	}
+
+	if (!(ctx = libhal_ctx_new ())) {
+		g_warning ("failed to create a HAL context!");
+		return NULL;
+	}
+	
+	libhal_ctx_set_dbus_connection (ctx, dbus_connection);
+	
+	libhal_ctx_set_device_added (ctx, hal_device_added);
+	libhal_ctx_set_device_removed (ctx, hal_device_removed);
+	/*libhal_ctx_set_device_new_capability (ctx, hal_device_new_capability);*/
+	/*libhal_ctx_set_device_lost_capability (ctx, hal_device_lost_capability);*/
+	/*libhal_ctx_set_device_property_modified (ctx, hal_property_modified);*/
+	/*libhal_ctx_set_device_condition (ctx, hal_device_condition);*/
+	
+	dbus_error_init (&error);
+	if (!libhal_device_property_watch_all (ctx, &error)) {
+		g_warning ("failed to watch all HAL properties!: %s", error.message);
+		dbus_error_free (&error);
+		libhal_ctx_free (ctx);
+		return NULL;
+	}
+	
+	if (!libhal_ctx_init (ctx, &error)) {
+		g_warning ("libhal_ctx_init failed: %s", error.message);
+		dbus_error_free (&error);
+		libhal_ctx_free (ctx);
+		return NULL;
+	}
+	
+	/*
+	 * Do something to ping the HAL daemon - the above functions will
+	 * succeed even if hald is not running, so long as DBUS is.  But we
+	 * want to exit silently if hald is not running, to behave on
+	 * pre-2.6 systems.
+	 */
+	if (!(devices = libhal_get_all_devices (ctx, &nr, &error))) {
+		g_warning ("seems that HAL is not running: %s", error.message);
+		dbus_error_free (&error);
+		
+		libhal_ctx_shutdown (ctx, NULL);
+		libhal_ctx_free (ctx);
+		return NULL;
+	}
+	
+	libhal_free_string_array (devices);
+	
+	return ctx;
+}
+#endif /* WITH_HAL */
+
+static int
+device_equal_by_io (GPilotDevice *dev, GIOChannel *io) 
+{
+	return !(dev->io == io);
+}
+
+static void
+remove_device (GPilotContext *context, GPilotDevice *device) 
+{
+	GList *l;
+
+	g_message ("Removing %s", device->name);
+
+	l = g_list_find (context->devices, device);
+	if (l != NULL) {
+		gpilot_device_free (l->data);
+		context->devices = g_list_remove (context->devices, l);
+		g_list_free_1 (l);
+	} else {
+		g_message ("%s not found",device->name);
+	}
+}
+
+static void 
+pilot_set_baud_rate (GPilotDevice *device) 
+{
+	static char rate_buf[128];
+	
+	g_snprintf (rate_buf, 128, "PILOTRATE=%d", device->speed);
+	g_message ("setting %s", rate_buf);
+	putenv (rate_buf);
+}
+
+/*
+  Sets *error to 1 on fatal error on the device, 2 on other errors , 0 otherwise.
+ */
+static int 
+pilot_connect (GPilotDevice *device,int *error) 
+{
+#define MAX_TIME_FOR_PI_BIND 1000000 /* 1 second, or 1,000,000 usec. */
+#define SLEEP_TIME_FOR_PI_BIND 50000 /* 50 ms */
+	
+#ifndef PILOT_LINK_0_12
+	struct pi_sockaddr addr;
+	union {
+		struct pi_sockaddr *pi_sockaddrp;
+		struct sockaddr *sockaddrp;
+	} addrp;
+#endif
+	int sd, listen_sd, pf;
+	int ret;
+
+	int time_elapsed_pi_bind = 0;
+	
+	if (device->type != PILOT_DEVICE_NETWORK &&
+	    device->type != PILOT_DEVICE_BLUETOOTH) {
+		pilot_set_baud_rate (device);
+	}
+	
+	switch (device->type) {
+	case PILOT_DEVICE_SERIAL:
+		pf = PI_PF_PADP;
+		break;
+	case PILOT_DEVICE_USB_VISOR:
+		pf = PI_PF_NET;
+		break;
+	case PILOT_DEVICE_IRDA:
+		pf = PI_PF_PADP;
+		break;
+	case PILOT_DEVICE_NETWORK:
+	case PILOT_DEVICE_BLUETOOTH:
+		pf = PI_PF_NET;
+		break;
+	default:
+		pf = PI_PF_DLP;
+		break;
+	}
+	
+	if (device->type == PILOT_DEVICE_NETWORK ||
+	    device->type == PILOT_DEVICE_BLUETOOTH) {
+		/* In the case of network pi_sockets, the socket is already
+		 * listening at this point, so move on to accept */
+		listen_sd = device->fd;
+	} else {
+#ifdef PILOT_LINK_0_12
+		/* pl 0.12.0 wants to autodetect the protocol, so pass DLP */
+		/* (at time of writing there's a buglet in pl where if you
+		 * _do_ pass in the correct NET protocol then pl will flush
+		 * pending net input, which might just lose your first
+		 * packet.
+		 */
+		listen_sd = pi_socket (PI_AF_PILOT, PI_SOCK_STREAM, PI_PF_DLP);
+#else
+		listen_sd = pi_socket (PI_AF_PILOT, PI_SOCK_STREAM, pf);
+#endif
+		if (listen_sd < 0) {
+			g_warning ("pi_socket returned error %d (%s)",
+			    listen_sd,
+			    strerror (errno));
+			if (error) *error = 1;
+			return -1;
+		}
+
+		
+		/* 
+		 * When using HAL and USB, the ttyUSB[01] device files are
+		 * not created until after Hal has notified gpilotd that
+		 * a file exists. This causes pi_bind to fail.
+		 * To prevent a failure (and therefore sync), retry pi_bind
+		 * for up to the time allotted, sleeping a little in-between
+		 * tries.
+		 */
+		
+		time_elapsed_pi_bind = 0;
+		do {
+#ifdef PILOT_LINK_0_12
+			ret = pi_bind (listen_sd, device->port);
+#else
+			addr.pi_family = PI_AF_PILOT;
+			strcpy (addr.pi_device,device->port);
+			addrp.pi_sockaddrp = &addr;
+			ret = pi_bind (listen_sd, addrp.sockaddrp,
+			    sizeof (addr));	
+#endif
+			if(ret < 0) {
+				usleep(SLEEP_TIME_FOR_PI_BIND);
+				time_elapsed_pi_bind += SLEEP_TIME_FOR_PI_BIND;
+			}
+		} while(ret<0 && time_elapsed_pi_bind < MAX_TIME_FOR_PI_BIND);
+		
+		if (ret < 0) {
+			g_warning (_("Unable to bind to PDA"));
+			if (error)
+				*error = 1;
+			pi_close(listen_sd);
+			check_usb_config(device);
+			return 0;
+		}
+
+		ret = pi_listen (listen_sd, 1);
+		if (ret != 0) {
+			g_warning ("pi_listen: %s", strerror (errno));
+			if (error)
+				*error = 2;
+			pi_close(listen_sd);
+			return 0;
+		}
+	}
+
+	sd = pi_accept_to (listen_sd, NULL, NULL, device->timeout); 
+	if (sd < 0) {
+		g_warning ("pi_accept_to returned %d: %s", sd, strerror (errno));
+		g_warning ("pi_accept_to: timeout was %d secs", device->timeout);
+		if (error)
+			*error = 2;
+		if (device->type != PILOT_DEVICE_NETWORK &&
+		    device->type != PILOT_DEVICE_BLUETOOTH) {
+			pi_close(listen_sd);
+		}
+		return 0;
+	}
+
+	if (error)
+		*error = 0;
+
+	/* since pilot-link 0.12.0preX, the listen_sd represents
+	 * the accepted connection, so don't close listen_sd
+	 * after the accept */
+#ifndef PILOT_LINK_0_12
+	if (device->type != PILOT_DEVICE_NETWORK &&
+	    device->type != PILOT_DEVICE_BLUETOOTH) {
+		pi_close(listen_sd);
+	}		
+#endif
+	return sd;
+}
+
+static void
+pilot_disconnect (int sd)
+{
+	int ret; 
+
+	dlp_EndOfSync (sd, 0);
+	ret = pi_close (sd);
+	if (ret < 0) {
+		g_warning ("error %d from pi_close.", ret);
+	}
+
+}
+
+static void
+write_sync_stamp (GPilotPilot *pilot, int pfd, struct PilotUser *pu,
+		  guint32 last_sync_pc, time_t t)
+{
+	GKeyFile *kfile;
+	gchar    *iPilot;
+	
+	pu->lastSyncPC = last_sync_pc;
+	pu->lastSyncDate = t;
+	
+	kfile = get_gpilotd_kfile ();
+	iPilot = g_strdup_printf ("Pilot%d", pilot->number);
+	g_key_file_set_integer (kfile, iPilot, "sync_date", t);
+	
+	save_gpilotd_kfile (kfile);
+	g_key_file_free (kfile);
+	g_free (iPilot);
+
+	dlp_WriteUserInfo (pfd, pu);
+}
+
+/** pilot lookup methods **/
+
+static gint
+match_pilot_and_majick (const GPilotPilot *pilot,
+			unsigned long creation,
+			unsigned long romversion)
+{
+	if (pilot->creation == creation &&
+	    pilot->romversion == romversion) {
+		g_message ("pilot %s %ld %ld matches %ld %ld", 
+			   pilot->name, 
+			   pilot->creation,
+			   pilot->romversion, 
+			   creation, 
+			   romversion);
+		return 1;
+	}
+	g_message ("pilot %s %ld %ld doesn't match %ld %ld", 
+		   pilot->name, 
+		   pilot->creation,
+		   pilot->romversion, 
+		   creation, 
+		   romversion);
+	return 0;
+}
+
+
+/* Checks whether visor module is loaded but 'usb:' device is selected,
+ * or vice versa.  Returns 0 if the config looks okay, or -1 otherwise.
+ * raises a gpilot_gui_warning_dialog and a g_warning if the config
+ * looks incorrect.
+ */
+static int
+check_usb_config (GPilotDevice *device)
+{
+#ifdef PILOT_LINK_0_12
+#define MAXLINELEN 256
+	char line[MAXLINELEN];
+	gboolean visor_loaded;
+	gboolean libusb_device;
+	FILE *f;
+	int error = 0;
+
+	if (device->type != PILOT_DEVICE_USB_VISOR)
+		return 0;
+	visor_loaded = FALSE;
+	libusb_device = TRUE; /* defaults, in case we skip block */
+	f = fopen ("/proc/modules", "r");
+	if (f) {
+		while(fgets(line, MAXLINELEN, f) != NULL) {
+			if (strncmp(line, "visor", 5) == 0) {
+				visor_loaded = TRUE;
+				break;
+			}
+		}
+		fclose(f);
+		libusb_device = (strncmp(device->port,
+					 "usb:", 4) == 0);
+	}
+	if (libusb_device && visor_loaded) {
+		g_snprintf(line, MAXLINELEN,_("Failed to connect using "
+					      "device `%s', on port `%s'.  "
+					      "Check your configuration, "
+					      "as you requested "
+					      "new-style libusb `usb:' "
+					      "syncing, but have the "
+					      "old-style `visor' kernel "
+					      "module loaded.  "
+					      "You may need to select a "
+					      "`ttyUSB...' device."),
+			   device->name, device->port);
+		g_warning("%s", line);
+		gpilot_gui_warning_dialog(line);
+		error = 1;
+	} else if (!libusb_device && !visor_loaded) {
+		g_snprintf(line, MAXLINELEN,_("Failed to connect using "
+					      "device `%s', on port `%s'.  "
+					      "Check your configuration, "
+					      "as you requested "
+					      "old-style usbserial `ttyUSB' "
+					      "syncing, but do not have the "
+					      "usbserial `visor' kernel "
+					      "module loaded.  "
+					      "You may need to select a "
+					      "`usb:' device."),
+			   device->name, device->port);
+		g_warning("%s", line);
+		gpilot_gui_warning_dialog(line);
+		error = 1;
+	}
+	return error;
+#else
+        return 0;
+#endif /* PILOT_LINK_0_12 */
+}
+
+
+/**************************/
+
+/*
+ * We get a pfd, a device and the context (called if a pilot
+ * with id == 0 synchronizes)
+ * Get whatever majick number we can get and try to id 
+ * the pilot and offer to restore it. If it can id the
+ * pilot, ask the user to choose one or "make a new pilot"
+ */
+
+static gboolean
+gpilot_attempt_restore (struct PilotUser pu,
+			int pfd, 
+			GPilotDevice *device, 
+			GPilotContext *context)
+{
+	GNOME_Pilot_SysInfo sysinfo;
+	struct CardInfo cardinfo;
+	GPilotPilot *pilot = NULL;
+	GList *iterator;
+	gboolean result = FALSE;
+	
+	dlp_ReadStorageInfo (pfd, 0, &cardinfo);
+	dlp_ReadSysInfo (pfd, &sysinfo);
+
+	if (context->pilots && context->pilots->next == NULL) {
+		pilot = GPILOT_PILOT (g_list_nth (context->pilots, 0)->data);
+		g_message ("D: Only one PDA (%s) profile...", pilot->name);
+	} else {
+		for (iterator = context->pilots; iterator; iterator = g_list_next (iterator)) {
+			pilot = GPILOT_PILOT (iterator->data);
+			if (match_pilot_and_majick (pilot, 
+						    cardinfo.creation,
+						    sysinfo.romVersion)) {
+				break;
+			}
+		}
+	}
+
+	if (pilot) {
+		GPilotPilot *a_pilot;
+		a_pilot = gpilot_gui_restore (context, pilot);
+		if (a_pilot) {
+			dbus_notify_connected (pilot->name,pu);				
+			result = gpilot_start_unknown_restore (pfd, device, a_pilot);
+			dbus_notify_disconnected (pilot->name);
+		}
+	} else {
+		/* MUST GO */
+		gpilot_gui_warning_dialog ("no ident\n"
+					   "restoring PDA with ident\n"
+					   "c/r = %lu/%lu, exciting things\n"
+					   "will soon be here...",
+					   cardinfo.creation,
+					   sysinfo.romVersion);
+	}
+
+	return TRUE;
+}
+
+/*
+ * This function handles when sync_device (...) encounters an unknown pilot
+ */
+
+static void
+gpilot_syncing_unknown_pilot (struct PilotUser pu, 
+			      int pfd,
+			      GPilotDevice *device, 
+			      GPilotContext *context)
+{
+
+	g_warning (_("Unknown PDA, no userID/username match %ld"),pu.userID);
+	/* FIXME: here, restoring one of the available pilots should be
+	   offered to the user. Of course with password prompt if the user
+	   has password set
+	   bug # 8217 */
+	if (pu.userID == 0) {
+		if (gpilot_attempt_restore (pu, pfd, device, context) == FALSE) {
+			gpilot_gui_warning_dialog (_("Use gnomecc to configure PDA"));
+		}
+	} else {
+		/* FIXME: here we should offer to create a profile for the pilot,
+		   bug # 8218 */
+		gpilot_gui_warning_dialog (_("Unknown PDA - no PDA matches ID %ld\n"
+					     "Use gnomecc to configure gnome-pilot"),pu.userID);
+	}
+}
+
+/*
+ * If there are events for the cradle, this executes them,
+ * closes the connection and returns.
+ * Returns TRUE if connection should be closed afterwards, FALSE
+ * is sync should continue
+ */
+static gboolean 
+do_cradle_events (int pfd,
+		 GPilotContext *context,
+		 struct PilotUser *pu,
+		 GPilotDevice *device) 
+{
+	GList *events, *it;
+	gboolean ret = TRUE;
+	
+	/* elements in events freed by gpc_request_purge calls
+	   in dbus_notify_completion */
+	events = gpc_queue_load_requests_for_cradle (device->name);
+	
+	g_message (_("Device %s has %d events"), device->name, g_list_length (events));
+	
+	/* if no events, return FALSE */
+	if (!events)
+		return FALSE;
+	
+	it = events;
+	
+	while (it) {
+		GPilotRequest *req;
+		req = it->data;
+		switch (req->type) {
+		case GREQ_SET_USERINFO:
+			g_message (_("Setting userinfo..."));
+			g_snprintf (pu->username,127,"%s", req->parameters.set_userinfo.user_id);
+			pu->userID = req->parameters.set_userinfo.pilot_id;
+			dlp_WriteUserInfo (pfd,pu);
+			if (req->parameters.set_userinfo.continue_sync) {
+				g_message (_("Sync continues"));
+				ret = FALSE;
+			}
+			dbus_notify_completion (&req);
+			break;
+		case GREQ_GET_SYSINFO: {
+			GNOME_Pilot_SysInfo sysinfo;
+			struct CardInfo cardinfo;
+
+			dlp_ReadStorageInfo (pfd, 0, &cardinfo);
+			dlp_ReadSysInfo (pfd, &sysinfo);
+			dbus_notify_sysinfo (device->name,
+					      sysinfo,
+					      cardinfo, 
+					      &req);
+			dbus_notify_completion (&req);
+		}
+		break;
+		case GREQ_GET_USERINFO:
+			g_message (_("Getting userinfo..."));
+			dbus_notify_userinfo (*pu,&req);
+			dbus_notify_completion (&req);
+			break;
+		case GREQ_NEW_USERINFO:
+			/* FIXME: this is to set the new and return the old (or something) 
+			   g_message ("getting & setting userinfo");
+			   g_snprintf (pu->username,127,"%s",req->parameters.set_userinfo.user_id);
+			   pu->userID = req->parameters.set_userinfo.pilot_id;
+			   dlp_WriteUserInfo (pfd,pu);
+			   dbus_notify_completion (&req);
+			*/
+			break;
+		default:
+			g_warning ("%s:%d: *** type = %d",__FILE__,__LINE__,req->type);
+			g_assert_not_reached ();
+			break;
+		}
+
+		it = g_list_next (it);
+	}
+
+	return ret;
+}
+/**************************/
+
+/*
+  This executes a sync for a pilot.
+
+  If first does some printing to the stdout and some logging to the
+  pilot, so the dudes can see what is going on. Afterwards, it does
+  the initial synchronization operations (which is handling file
+  installs, restores, specific conduits runs). This function (in
+  manager.c) returns a boolean, whic may abort the entire
+  synchronization.
+
+  If it does not, a function in manager.c will be called depending of
+  the default_sync_action setting for the pilot (you know, synchronize
+  vs copy to/from blablabla).
+
+ */
+static void 
+do_sync (int pfd,   
+	GPilotContext *context,
+	struct PilotUser *pu,
+	GPilotPilot *pilot, 
+	GPilotDevice *device)
+{
+	GList *conduit_list, *backup_conduit_list, *file_conduit_list;
+	GnomePilotSyncStamp stamp;
+	char *pilot_name;
+
+	pilot_name = pilot_name_from_id (pu->userID,context);
+
+	gpilot_load_conduits (context,
+			     pilot,
+			     &conduit_list, 
+			     &backup_conduit_list,
+			     &file_conduit_list);
+	stamp.sync_PC_Id=context->sync_PC_Id;
+
+	if (device->type == PILOT_DEVICE_NETWORK) {
+		g_message (_("NetSync request detected, synchronizing PDA"));
+	} else if (device->type == PILOT_DEVICE_BLUETOOTH) {
+		g_message (_("Bluetooth request detected, synchronizing PDA"));
+	} else {
+		g_message (_("HotSync button pressed, synchronizing PDA"));
+	}
+	g_message (_("PDA ID is %ld, name is %s, owner is %s"),
+		  pu->userID,
+		  pilot->name,
+		  pu->username);
+  
+	/* Set a log entry in the pilot */
+	{
+		char hostname[64];
+		gpilot_add_log_entry (pfd,"gnome-pilot v.%s\n",VERSION);
+		if (gethostname (hostname,63)==0)
+			gpilot_add_log_entry (pfd,_("On host %s\n"),hostname);
+		else
+			gpilot_add_log_entry (pfd,_("On host %d\n"),stamp.sync_PC_Id);
+	}
+
+	/* first, run the initial operations, such as single conduit runs,
+	   restores etc. If this returns True, continue with normal conduit running,
+	   if False, don't proceed */
+	if (gpilot_initial_synchronize_operations (pfd,
+						   &stamp,
+						   pu,
+						   conduit_list,
+						   backup_conduit_list,
+						   file_conduit_list,
+						   device,
+						   context)) {
+		gpilot_sync_default (pfd,&stamp,pu,
+				     conduit_list,
+				     backup_conduit_list,
+				     file_conduit_list,
+				     context);
+		g_message (_("Synchronization ended")); 
+		gpilot_add_log_entry (pfd,"Synchronization completed");
+	} else {
+		g_message (_("Synchronization ended early"));
+		gpilot_add_log_entry (pfd,"Synchronization terminated");
+	}
+
+	write_sync_stamp (pilot,pfd,pu,stamp.sync_PC_Id,time (NULL));
+  
+	g_free (pilot_name);
+
+	gpilot_unload_conduits (conduit_list);
+	gpilot_unload_conduits (backup_conduit_list);
+	gpilot_unload_conduits (file_conduit_list);
+}
+
+/*
+ * This function handles when sync_device (...) encounters a known pilot
+ */
+
+static void
+gpilot_syncing_known_pilot (GPilotPilot *pilot,
+			    struct PilotUser pu,
+			    int pfd,
+			    GPilotDevice *device,
+			    GPilotContext *context)
+{
+	struct stat buf; 
+	int ret;
+
+#ifdef PILOT_LINK_0_12
+	iconv_t ic;
+
+	if (pilot->pilot_charset == NULL ||
+	    pilot->pilot_charset == '\0') {
+		g_warning (_("No pilot_charset specified.  Using `%s'."),
+		    GPILOT_DEFAULT_CHARSET);
+		if (pilot->pilot_charset != NULL)
+			g_free(pilot->pilot_charset);
+		pilot->pilot_charset =
+		    g_strdup(GPILOT_DEFAULT_CHARSET);
+	}
+
+
+	/* ensure configured pilot_charset is recognised
+	 * by iconv, and override with warning if not.
+	 */
+	ic = iconv_open(pilot->pilot_charset, "UTF8");
+	if (ic == ((iconv_t)-1)) {
+		g_warning (_("`%s' is not a recognised iconv charset, "
+			       "using `%s' instead."),
+		    pilot->pilot_charset,
+		    GPILOT_DEFAULT_CHARSET);
+		g_free (pilot->pilot_charset);
+		pilot->pilot_charset =
+		    g_strdup(GPILOT_DEFAULT_CHARSET);
+	} else {
+		iconv_close(ic);
+	}
+	/* Set the environment variable PILOT_CHARSET,
+	 * to support legacy conduits that don't use
+	 * pilot_charset
+	 */
+	setenv("PILOT_CHARSET",
+	    pilot->pilot_charset, 1);
+#endif
+
+	ret = stat (pilot->sync_options.basedir, &buf); 
+
+	if (ret < 0 || !( S_ISDIR (buf.st_mode) && (buf.st_mode & (S_IRUSR | S_IWUSR |S_IXUSR))) ) {
+		
+		g_message ("Invalid basedir: %s", pilot->sync_options.basedir);
+		gpilot_gui_warning_dialog (_("The base directory %s is invalid.\n"
+					     "Please fix it or use gnomecc to choose another directory."),
+					   pilot->sync_options.basedir);	
+	} else {
+		gboolean pwd_ok = TRUE;
+		/* If pilot has password, check against the encrypted version
+		   on the pilot */
+		if (pilot->passwd) {
+			char *pwd;
+			
+			pwd = g_strndup (pu.password, pu.passwordLength);
+			if (g_ascii_strcasecmp (pilot->passwd, crypt (pwd, pilot->passwd)) != 0) {
+				pwd_ok = FALSE;
+				gpilot_gui_warning_dialog (_("Unknown PDA - no PDA matches ID %ld\n"
+							     "Use gpilotd-control-applet to set PDA's ID"), pu.userID);
+			}
+			g_free (pwd);
+		}
+		
+		if (pwd_ok) {
+			do_sync (pfd, context, &pu, pilot, device);
+		}
+	}
+}
+
+/*
+  sync_foreach is the first synchronization entry.
+
+  It first connects to the device on which the signal was detected,
+  then it tries to read the user info block from the pilot.
+
+  Hereafter, if there are any events queued for the synchronizing
+  cradle, execute them and stop the synchronization (note,
+  do_cradle_events returns a bool, if this is FALSE, synchronization
+  continues, as some cradle specific events also require a normal sync
+  afterwards, eg. the REVIVE call)
+
+  Anyways, if the sync continues, sync_foreach tries to match the
+  pilot against the known pilots. If this fails, it should handle it
+  intelligently, eg. if the id==0, ask if you want to restore a pilot.
+
+  If the pilot is accepted (dude, there's even a password check!), it
+  continues into do_sync, which does all the magic stuff.
+*/
+   
+static int
+known_usb_device(gchar *match_str)
+{
+	int i;
+	for (i = 0; i < vendor_product_ids->len; i++) {
+		if (!g_strncasecmp (match_str, 
+			vendor_product_ids->pdata[i], 
+			strlen (vendor_product_ids->pdata[i])))
+			return i;
+	}
+	return -1;
+}
+
+static void
+load_devices_xml (void) 
+{
+	xmlDoc *doc = NULL;
+	xmlNode *root, *node;
+	char *filename;
+
+	if (vendor_product_ids)
+		return;
+	
+	vendor_product_ids = g_ptr_array_new ();
+	product_net = g_array_new (FALSE, FALSE, sizeof (gboolean));
+
+	filename = g_build_filename (DEVICE_XML_DIR, "devices.xml", NULL);
+	doc = xmlParseFile (filename);
+	g_free (filename);
+		
+	if (!doc) {
+		g_warning ("Unable to read device file at %s", filename);
+		
+		return;
+	}
+
+	root = xmlDocGetRootElement (doc);
+	if (!root->name || strcmp ((char *) root->name, "device-list"))
+		goto fail;
+	
+	for (node = root->children; node; node = node->next) {
+		xmlChar *vendor, *product, *net;
+		gboolean use_net;
+		
+		if (node->type != XML_ELEMENT_NODE)
+			continue;
+
+		if (!node->name || strcmp ((char *) node->name, "device")) {
+			g_warning ("Invalid sub node %s", node->name != NULL ? (char *) node->name : "");
+
+			continue;
+		}
+		
+		vendor = xmlGetProp (node, (xmlChar *) "vendor_id");
+		product = xmlGetProp (node, (xmlChar *) "product_id");
+
+		if (!vendor || !product) {
+			g_warning ("No vendor or product id");
+
+			continue;
+		}
+		
+		g_message ("Found %s, %s", vendor, product);
+		g_ptr_array_add (vendor_product_ids, g_strdup_printf ("Vendor=%s ProdID=%s", vendor, product));
+
+		xmlFree (vendor);
+		xmlFree (product);
+		
+		net = xmlGetProp (node, (xmlChar *) "use_net");
+		use_net = !net || strcmp ((char *) net, "false");
+		
+		g_message ("Using net %s", use_net ? "TRUE" : "FALSE");
+		g_array_append_val (product_net, use_net);
+
+		xmlFree (net);
+	}
+
+ fail:
+	xmlFreeDoc (doc);
+}
+
+static gboolean 
+sync_device (GPilotDevice *device, GPilotContext *context)
+{
+	GPilotPilot *pilot;
+	int connect_error;
+	struct PilotUser pu;
+	GNOME_Pilot_SysInfo ps;
+	int pfd;
+	
+	g_assert (context != NULL);
+	g_return_val_if_fail (device != NULL, FALSE);
+
+	/* signal (SIGHUP,SIG_DFL); */
+	pfd = pilot_connect (device,&connect_error);
+
+	if (!connect_error) {
+               /* connect succeeded, try to read the systeminfo */
+               if (dlp_ReadSysInfo (pfd, &ps) < 0) {
+                       /* no ? drop connection then */
+                       g_warning (_("An error occurred while getting the PDA's system data"));
+		       check_usb_config(device);
+
+
+		/* connect succeeded, try to read the userinfo */
+		} else if (dlp_ReadUserInfo (pfd,&pu) < 0) {
+			/* no ? drop connection then */
+			g_warning (_("An error occurred while getting the PDA's user data"));
+		} else {
+	
+			/* If there are cradle specific events, handle them and stop */
+			if (do_cradle_events (pfd,context,&pu,device)) {
+				g_message (_("Completed events for device %s (%s)"),device->name,device->port);
+			} else {
+				/* No cradle events, validate pilot */
+				pilot = gpilot_find_pilot_by_id (pu.userID,context->pilots);
+
+				if (pilot == NULL) {
+					/* Pilot is not known */
+					gpilot_syncing_unknown_pilot (pu, pfd, device, context);
+				} else {
+					/* Pilot is known, make connect notifications */
+					dbus_notify_connected (pilot->name,pu);				
+					gpilot_syncing_known_pilot (pilot, pu, pfd, device, context);
+					dbus_notify_disconnected (pilot->name);
+				}				
+			}
+		}
+		pilot_disconnect (pfd);
+		/* now restart the listener.  fairly brute force
+		 * approach, but ensures we re-initialise the listening
+		 * socket correctly.  */
+		if (device->type == PILOT_DEVICE_NETWORK ||
+		    device->type == PILOT_DEVICE_BLUETOOTH) {
+			/*TODO
+                        reread_config = TRUE;
+                        */
+		}
+	} else {
+		if (connect_error==1) return FALSE; /* remove this device */
+		else {
+			if (device->type == PILOT_DEVICE_NETWORK ||
+			    device->type == PILOT_DEVICE_BLUETOOTH) {
+				/* fix broken pisock sockets */
+                                /*TODO
+                                reread_config = TRUE;
+                                */
+			}
+			return TRUE;
+		}
+	}
+
+	return TRUE;
+}
+
+static gboolean 
+device_in (GIOChannel *io_channel, GIOCondition condition, GPilotContext *context)
+{
+	GPilotDevice *device;
+	GList *element;
+	gboolean result = TRUE;
+	
+	g_assert (context != NULL);
+	
+	element = g_list_find_custom (context->devices,
+				     io_channel,
+				     (GCompareFunc)device_equal_by_io);
+	
+	if (element == NULL || element->data == NULL) {
+		g_warning ("cannot find device for active IO channel");
+		return FALSE;
+	}
+	
+	device = element->data; 
+	if (context->paused) {
+		return FALSE; 
+	}	
+	g_message (_("Woke on %s"), device->name);
+	result = sync_device (device, context);
+	
+#ifdef WITH_IRDA
+	if (device->type == PILOT_DEVICE_IRDA) {
+		g_message ("Restarting irda funk...");
+		gpilot_device_deinit (device);
+		gpilot_device_init (device);
+		monitor_channel (device, context);
+		result = FALSE;
+	}
+#endif /* WITH_IRDA */
+	
+	return result;
+}
+
+static gboolean 
+device_err (GIOChannel *io_channel, GIOCondition condition, GPilotContext *context)
+{
+	GPilotDevice *device;
+	GList *element;
+	char *tmp;
+	
+	g_assert (context != NULL);
+	
+	switch (condition) {
+	case G_IO_IN: tmp = g_strdup_printf ("G_IO_IN"); break;
+	case G_IO_OUT : tmp = g_strdup_printf ("G_IO_OUT"); break;
+	case G_IO_PRI : tmp = g_strdup_printf ("G_IO_PRI"); break;
+	case G_IO_ERR : tmp = g_strdup_printf ("G_IO_ERR"); break;
+	case G_IO_HUP : tmp = g_strdup_printf ("G_IO_HUP"); break;
+	case G_IO_NVAL: tmp = g_strdup_printf ("G_IO_NVAL"); break;
+	default: tmp = g_strdup_printf ("unhandled port error"); break;
+	}
+	
+	element = g_list_find_custom (context->devices,io_channel,(GCompareFunc)device_equal_by_io);
+	
+	if (element == NULL) {
+		/* We most likely end here if the device has just been removed.
+		   Eg. start gpilotd with a monitor on a XCopilot fake serial port,
+		   kill xcopilot and watch things blow up as the device fails */
+		g_warning ("Device error on some device, caught %s",tmp); 
+		g_free (tmp);
+		return FALSE;
+	}
+	
+	device = element->data;
+	
+	gpilot_gui_warning_dialog ("Device error on %s (%s)\n"
+				  "Caught %s", device->name, device->port, tmp); 
+	g_warning ("Device error on %s (%s), caught %s", device->name, device->port, tmp);
+	
+	remove_device (context, device);
+	g_free (tmp);
+	
+	return FALSE;
+}
+
+#ifdef WITH_NETWORK
+static gboolean 
+network_device_in (GIOChannel *io_channel, GIOCondition condition, GPilotContext *context)
+{
+	GPilotDevice *device;
+	GList *element;
+	gboolean result = TRUE;
+
+	g_assert (context != NULL);
+      
+	element = g_list_find_custom (context->devices,
+				     io_channel,
+				     (GCompareFunc)device_equal_by_io);
+
+	if (element==NULL || element->data == NULL) {
+		g_warning ("cannot find device for active IO channel");
+		return FALSE;
+	}
+	
+	device = element->data; 
+	if (context->paused) {
+		return FALSE; 
+	}	
+	g_message (_("Woke on network: %s"),device->name);
+	result = sync_device (device,context);
+
+	return result;
+}
+
+static gboolean 
+network_device_err (GIOChannel *io_channel, GIOCondition condition, GPilotContext *context)
+{
+	GPilotDevice *device;
+	GList *element;
+	char *tmp;
+	
+	g_assert (context != NULL);
+	
+	switch (condition) {
+		case G_IO_IN: tmp = g_strdup_printf ("G_IO_IN"); break;
+		case G_IO_OUT : tmp = g_strdup_printf ("G_IO_OUT"); break;
+		case G_IO_PRI : tmp = g_strdup_printf ("G_IO_PRI"); break;
+		case G_IO_ERR : tmp = g_strdup_printf ("G_IO_ERR"); break;
+		case G_IO_HUP : tmp = g_strdup_printf ("G_IO_HUP"); break;
+		case G_IO_NVAL: tmp = g_strdup_printf ("G_IO_NVAL"); break;
+		default: tmp = g_strdup_printf ("unhandled port error"); break;
+	}
+	
+	element = g_list_find_custom (context->devices,io_channel,(GCompareFunc)device_equal_by_io);
+	
+	if (element == NULL) {
+		/* We most likely end here if the device has just been removed.
+		   Eg. start gpilotd with a monitor on a XCopilot fake serial port,
+		   kill xcopilot and watch things blow up as the device fails */
+		g_warning ("Device error on some device, caught %s",tmp); 
+		g_free (tmp);
+		return FALSE;
+	}
+	
+	device = element->data;
+
+	gpilot_gui_warning_dialog ("Device error on %s, caught %s",
+	    device->name, tmp);
+	g_warning ("Device error on %s, caught %s",device->name, tmp);
+
+	remove_device (context, device);
+	g_free (tmp);
+	
+	return FALSE;
+}
+#endif /* WITH_NETWORK */
+
+#ifdef WITH_USB_VISOR
+static gboolean 
+visor_devices_timeout (gpointer data) 
+{
+	GPilotContext *context = data;
+	GPilotDevice *device;
+	GList *l;
+	int i, use_sysfs;
+	static int devfs_warning = 0;
+	gboolean visor_exists = FALSE, visor_net = TRUE;
+	char *usbdevicesfile_str ="/proc/bus/usb/devices";
+	char line[256]; /* this is more than enough to fit any line from 
+			 * /proc/bus/usb/devices */
+	FILE *f;
+	gchar *fcontent;
+	gchar *fname;
+	gchar *vend_id; 
+	gchar *prod_id;
+	gchar *to_match;
+	GError *error = NULL;
+	regex_t regex_pattern;
+
+	GDir *topdir;
+	const gchar *entry;
+	gchar *sysfs_dir_name = "/sys/bus/usb/devices/";
+	gchar *f_vend = "idVendor";
+	gchar *f_prod = "idProduct";
+
+
+	g_assert (context != NULL);
+
+	if (context->paused) 
+		return FALSE;
+
+	load_devices_xml ();
+#ifdef linux
+	/* choose a method for searching for known USB devices:
+	 * If we can't find sysfs, second choice is
+	 * legacy /proc/bus/usb/devices.
+	 */
+	use_sysfs = 1; /* default */
+	topdir = g_dir_open (sysfs_dir_name, 0, &error);
+	if (!topdir) {
+		use_sysfs = 0;
+		f = fopen (usbdevicesfile_str, "r");
+		if (!f)
+			f = fopen ("/proc/bus/usb/devices_please-use-sysfs-instead", "r");
+		if (!f) {
+			if (!devfs_warning) {
+				devfs_warning = 1;
+				char *str = g_strdup_printf (
+				    _("Failed to find directory %s or read file %s.  "
+					"Check that usbfs or sysfs is mounted."),
+				    sysfs_dir_name,
+				    usbdevicesfile_str);
+				g_warning ("%s", str);
+				g_free (str);
+			}
+			return TRUE; /* can't proceed */
+		}
+		devfs_warning = 0;
+	}
+	if (use_sysfs) {
+		/* This regex allows 99 root-hubs and a bus-depth of 6 tiers for
+		 * each root-hub. Each hub can have 99 ports. Refer to "Bus
+		 * Topology" in the USB 2.0 specs and the sysfs structures of
+		 * Linux USB for further explanation */
+		regcomp (&regex_pattern,
+		    "^[[:digit:]]{1,2}[-][[:digit:]]{1,2}([.][[:digit:]]{1,2}){0,5}$",
+		    REG_EXTENDED | REG_NOSUB); 
+
+		entry = g_dir_read_name (topdir);
+		while ((entry != NULL) && (!visor_exists)) {
+			if (!regexec (&regex_pattern, entry, 0, 0, 0)){
+				fname = g_build_filename (sysfs_dir_name, entry,
+				    f_vend, NULL);
+				if (!g_file_get_contents (fname, &fcontent,
+					NULL, &error)){
+					g_warning ("%s", &*error->message);
+					regfree (&regex_pattern);
+					g_free (fname);
+					g_dir_close (topdir);
+					return TRUE;
+				}
+				vend_id = g_strndup (fcontent, 4);
+				g_free (fname);
+				g_free (fcontent);
+
+				fname = g_build_filename (sysfs_dir_name, entry,
+				    f_prod, NULL);
+				if (!g_file_get_contents (fname, &fcontent,
+					NULL, &error)){
+					g_warning ("%s", &*error->message);
+					regfree (&regex_pattern);
+					g_free (fname);
+					g_free (vend_id);
+					g_dir_close (topdir);
+					return TRUE;
+				}
+				prod_id = g_strndup (fcontent, 4);
+				g_free (fname);
+				g_free (fcontent);
+
+				to_match = g_strconcat ("Vendor=", vend_id,
+				    " ProdID=", prod_id, NULL);
+				i = known_usb_device(to_match);
+				if(i != -1) {
+					visor_exists = TRUE;
+					visor_net = g_array_index (
+					    product_net, gboolean, i);
+				}
+				g_free (vend_id);
+				g_free (prod_id);
+				g_free (to_match);
+			}
+			entry = g_dir_read_name (topdir);
+		}
+		g_dir_close (topdir);
+		regfree (&regex_pattern);
+	} else {
+		/* non sysfs branch... read /proc/bus/usb/devices */
+		while (fgets (line, 255, f) != NULL && !visor_exists) {
+			if (line[0] != 'P')
+				continue;
+			i = known_usb_device(line + 4); /* line + strlen("P:  ") */
+			if (i != -1) {
+				visor_exists = TRUE;
+				visor_net = g_array_index (
+				    product_net, gboolean, i);
+			}
+		}
+	
+		fclose (f);
+	}
+	
+#else
+#if defined(sun) && defined (__SVR4) /*for solaris */
+	/* On Solaris we always try to sync.  This isn't
+	 * a great solution, but does enable syncing.  We
+	 * should use HAL on Solaris when it is working
+	 * well.  See bug #385444.
+	 */
+       visor_exists = TRUE;
+#endif /* defined(sun) && defined (__SVR4) */
+#endif /* linux */
+	if (visor_exists) {
+		l = context->devices;
+		while (l) {
+			device = l->data;
+			if (device->type == PILOT_DEVICE_USB_VISOR) {
+				if (!visor_net)
+					device->type = PILOT_DEVICE_SERIAL;
+
+				/* just try to synch.  Until I can talk to 
+				 * the kernel guys this is the best way to 
+                                 * go. */
+				sync_device (device, context);
+				sleep(1);
+
+				if (!visor_net)
+					device->type = PILOT_DEVICE_USB_VISOR;
+				break; /* don't try to sync any more devices! */
+			}
+			l = l->next;
+		}
+	}
+
+	return TRUE;
+}
+#endif /* WITH_USB_VISOR */
+
+static void
+monitor_channel (GPilotDevice *dev, GPilotContext *context) 
+{
+	g_assert (context != NULL);
+	
+	if (dev->type == PILOT_DEVICE_SERIAL
+	    || dev->type == PILOT_DEVICE_IRDA) {
+		dev->in_handle = g_io_add_watch (dev->io,
+						G_IO_IN,
+						(GIOFunc)device_in,
+						(gpointer)context);
+		dev->err_handle = g_io_add_watch (dev->io,
+						 G_IO_ERR|G_IO_PRI|G_IO_HUP|G_IO_NVAL,
+						 (GIOFunc)device_err,
+						 (gpointer)context);
+	} else if (dev->type == PILOT_DEVICE_NETWORK ||
+	    dev->type == PILOT_DEVICE_BLUETOOTH) {
+#ifdef WITH_NETWORK
+		dev->in_handle = g_io_add_watch (dev->io,
+						G_IO_IN,
+						(GIOFunc)network_device_in,
+						(gpointer)context);
+		dev->err_handle = g_io_add_watch (dev->io,
+						 G_IO_ERR|G_IO_PRI|G_IO_HUP|G_IO_NVAL,
+						 (GIOFunc)network_device_err,
+						 (gpointer)context);
+#else /* WITH_NETWORK */
+		g_assert_not_reached ();
+#endif /* WITH_NETWORK */
+	} if (dev->type == PILOT_DEVICE_USB_VISOR) {
+		if(hal_initialised) {
+			/* handled by hal callbacks */
+			dev->device_exists = FALSE;
+		} else {
+#ifdef WITH_USB_VISOR
+#if defined(linux) || (defined(sun) && defined(__SVR4))
+			/* We want to watch for a new recognised USB device
+			 * once per context. */
+			if (visor_timeout_id == -1) {
+				visor_timeout_id = g_timeout_add (2000,
+				    visor_devices_timeout, context);
+			}
+#else /* linux or solaris */
+			g_assert_not_reached ();
+#endif /* linux or solaris */
+#endif /* WITH_USB_VISOR */
+		}
+	}
+
+	if (dev->type == PILOT_DEVICE_NETWORK) {
+                g_message (_("Watching %s (network)"), dev->name);
+        } else if (dev->type == PILOT_DEVICE_BLUETOOTH) {
+                g_message (_("Watching %s (bluetooth)"), dev->name);
+        } else {
+                g_message (_("Watching %s (%s)"), dev->name, dev->port);
+        }
+}
+
+guint32
+pilot_id_from_name (const gchar   *name,
+                    GPilotContext *context)
+{
+        GList *pilot;
+        pilot = g_list_find_custom (context->pilots, (gpointer)name,
+                                    (GCompareFunc)match_pilot_and_name);
+        if(pilot)  
+                return ((GPilotPilot*)pilot->data)->pilot_id;
+        return 0;
+}
+
+gchar*
+pilot_name_from_id (guint32 id,
+                    GPilotContext *context)
+{
+        GList *pilot;
+        pilot = g_list_find_custom (context->pilots, (gpointer)&id,
+                                   (GCompareFunc)match_pilot_userID);
+
+        if(pilot)
+                return g_strdup (((GPilotPilot*)pilot->data)->name);
+
+        return NULL;
+}
+
+GQuark
+gpilot_daemon_error_quark (void)
+{
+        static GQuark ret = 0;
+        if (ret == 0) {
+                ret = g_quark_from_static_string ("gpilot_daemon_error");
+        }
+
+        return ret;
+}
+
+#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+
+GType
+gpilot_daemon_error_get_type (void)
+{
+        static GType etype = 0;
+
+        if (etype == 0) {
+                static const GEnumValue values[] = {
+                        ENUM_ENTRY (GPILOT_DAEMON_ERROR_GENERAL, "GeneralError"),
+                        { 0, 0, 0 }
+                };
+
+                g_assert (GPILOT_DAEMON_NUM_ERRORS == G_N_ELEMENTS (values) - 1);
+
+                etype = g_enum_register_static ("GpilotDaemonError", values);
+        }
+
+        return etype;
+}
+
+static void
+dbus_notify_paused (gboolean on_ff) 
+{
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "Paused");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &on_ff);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+}
+
+/*
+Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.Pause boolean:true
+*/
+gboolean
+gpilot_daemon_pause (GpilotDaemon   *daemon,
+                     gboolean        on_off,
+                     GError        **error)
+{
+        GpilotDaemonPrivate *priv;
+
+        priv = daemon->priv;
+
+        if (priv->gpilotd_context->paused == on_off)
+                return TRUE;
+
+        priv->gpilotd_context->paused = on_off;
+
+        dbus_notify_paused (on_off);
+        if (priv->gpilotd_context->paused) {
+                g_list_foreach (priv->gpilotd_context->devices,
+                                (GFunc)gpilot_daemon_pause_device,
+                                NULL);
+        } else {
+                kill (getpid (), SIGHUP);
+        }
+
+        return TRUE;
+}
+
+/*
+Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.RereadConfig
+*/
+gboolean
+gpilot_daemon_reread_config (GpilotDaemon   *daemon,
+                             GError        **error)
+{
+        GpilotDaemonPrivate *priv;
+
+        priv = daemon->priv;
+
+        g_message (_("Shutting down devices"));
+        gpilot_context_free (priv->gpilotd_context);
+        g_message (_("Rereading configuration..."));
+        gpilot_context_init_user (priv->gpilotd_context);
+        g_list_foreach (priv->gpilotd_context->devices, (GFunc)monitor_channel, priv->gpilotd_context);
+
+        return TRUE;
+}
+
+/* A no-operation call, used by client to occasionally
+   check to see if the daemon has blown up
+Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.Noop
+*/
+gboolean
+gpilot_daemon_noop (GpilotDaemon   *daemon)
+{
+        return TRUE;
+}
+
+/* request operations */
+/*
+Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.RequestInstall \
+string:'MyPDA' string:'/tmp/1' string:'/tmp/1' \
+uint32:0 uint32:0
+*/
+gboolean
+gpilot_daemon_request_install (GpilotDaemon   *daemon,
+                               const char     *pilot_name,
+                               const char     *filename,
+                               const char     *description,
+                               GNOME_Pilot_Survival survival,
+                               unsigned long   timeout,
+                               unsigned long  *handle,
+                               GError        **error)
+{
+        GpilotDaemonPrivate *priv;
+        GPilotRequest        req;
+        gboolean             ret;
+        
+        ret = FALSE;
+        priv = daemon->priv;
+
+        LOG (("request_install(pilot_name=%s (%d),filename=%s,survival=%d,timeout=%d)",                 
+            pilot_name,       
+            pilot_id_from_name (pilot_name, priv->gpilotd_context),
+            filename,
+            survival,
+            timeout));
+
+        req.type = GREQ_INSTALL;
+        req.pilot_id = pilot_id_from_name (pilot_name, priv->gpilotd_context);
+
+        if(req.pilot_id == 0) {
+                g_set_error (error,
+                             GPILOT_DAEMON_ERROR,
+                             GPILOT_DAEMON_ERROR_GENERAL,
+                             "Unknow pilot %s",
+                             pilot_name);
+                goto out;
+        }
+        if(access (filename, R_OK)) {
+                g_set_error (error,
+                             GPILOT_DAEMON_ERROR,
+                             GPILOT_DAEMON_ERROR_GENERAL,
+                             "Missing file %s",
+                             filename);
+                goto out;
+        }
+
+        req.timeout = survival==GNOME_Pilot_PERSISTENT?0:timeout;
+        req.cradle = NULL;
+        req.client_id = g_strdup ("");
+        req.parameters.install.filename = g_strdup (filename);
+        req.parameters.install.description = g_strdup (description);
+
+        *handle = gpc_queue_store_request (req);
+
+        ret = TRUE;
+ out:
+        return ret;
+}
+
+/*
+Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.RequestRestore \
+string:'MyPDA' string:'/tmp/dir1' \
+uint32:0 uint32:0
+*/
+gboolean
+gpilot_daemon_request_restore (GpilotDaemon   *daemon,
+                               const char     *pilot_name,
+                               const char     *directory,
+                               GNOME_Pilot_Survival survival,
+                               unsigned long   timeout,
+                               unsigned long  *handle,
+                               GError        **error)
+{
+        GpilotDaemonPrivate *priv;
+        GPilotRequest        req;
+        gboolean             ret;
+        
+        ret = FALSE;
+        priv = daemon->priv;
+
+        LOG (("request_restore(pilot_name=%s (%d), directory=%s,survival=%d,timeout=%d)",
+              pilot_name,
+              pilot_id_from_name (pilot_name, priv->gpilotd_context),
+              directory,
+              survival,
+              timeout));
+
+        req.type = GREQ_RESTORE;
+        req.pilot_id = pilot_id_from_name (pilot_name, priv->gpilotd_context);
+        if(req.pilot_id == 0) {
+                g_set_error (error,
+                             GPILOT_DAEMON_ERROR,
+                             GPILOT_DAEMON_ERROR_GENERAL,
+                             "Unknow pilot %s",
+                             pilot_name);
+                goto out;
+        }
+        if (!g_file_test (directory, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
+                g_set_error (error,
+                             GPILOT_DAEMON_ERROR,
+                             GPILOT_DAEMON_ERROR_GENERAL,
+                             "Directory %s not accessible",
+                             directory);
+                goto out;
+        }
+
+        req.timeout = survival==GNOME_Pilot_PERSISTENT?0:timeout;
+        req.cradle = NULL;
+        req.client_id = g_strdup ("");
+
+        req.parameters.restore.directory = g_strdup(directory);
+
+        *handle = gpc_queue_store_request (req);
+
+        ret = TRUE;
+ out:
+        return ret;
+}
+
+/*
+Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.RequestConduit \
+string:'MyPDA' string:'Test' \
+uint32:0 uint32:0 uint32:0
+*/
+gboolean
+gpilot_daemon_request_conduit (GpilotDaemon   *daemon,
+                               const char     *pilot_name,
+                               const char     *conduit_name,
+                               GNOME_Pilot_ConduitOperation operation,
+                               GNOME_Pilot_Survival survival,
+                               unsigned long   timeout,
+                               unsigned long  *handle,
+                               GError        **error)
+{
+        GpilotDaemonPrivate *priv;
+        GPilotRequest        req;
+        gboolean             ret;
+        
+        ret = FALSE;
+        priv = daemon->priv;
+
+        LOG (("request_conduit(pilot=%s (%d), conduit=%s)",
+              pilot_name,
+              pilot_id_from_name (pilot_name, priv->gpilotd_context),
+              conduit_name));
+
+        req.pilot_id = pilot_id_from_name (pilot_name, priv->gpilotd_context);
+        if(req.pilot_id == 0) {
+                g_set_error (error,
+                             GPILOT_DAEMON_ERROR,
+                             GPILOT_DAEMON_ERROR_GENERAL,
+                             "Unknow pilot %s",
+                             pilot_name);
+                goto out;
+        }
+
+        req.type = GREQ_CONDUIT;
+        req.timeout = survival==GNOME_Pilot_PERSISTENT?0:timeout;
+        req.cradle = NULL;
+        req.client_id = g_strdup("");
+
+        req.parameters.conduit.name = g_strdup (conduit_name);
+        switch (operation) {
+        case GNOME_Pilot_SYNCHRONIZE:
+                req.parameters.conduit.how = GnomePilotConduitSyncTypeSynchronize; break;
+        case GNOME_Pilot_COPY_FROM_PILOT:
+                req.parameters.conduit.how = GnomePilotConduitSyncTypeCopyFromPilot; break;
+        case GNOME_Pilot_COPY_TO_PILOT:
+                req.parameters.conduit.how = GnomePilotConduitSyncTypeCopyToPilot; break;
+        case GNOME_Pilot_MERGE_FROM_PILOT:
+                req.parameters.conduit.how = GnomePilotConduitSyncTypeMergeFromPilot; break;
+        case GNOME_Pilot_MERGE_TO_PILOT:
+                req.parameters.conduit.how = GnomePilotConduitSyncTypeMergeToPilot; break;
+        case GNOME_Pilot_CONDUIT_DEFAULT:
+                req.parameters.conduit.how = GnomePilotConduitSyncTypeCustom; break;
+        default:
+                g_set_error (error,
+                             GPILOT_DAEMON_ERROR,
+                             GPILOT_DAEMON_ERROR_GENERAL,
+                             "Unknow operation %d",
+                             operation);
+                break;
+        }
+
+        *handle = gpc_queue_store_request (req);
+
+        ret = TRUE;
+ out:
+        return ret;
+}
+
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.RemoveRequest \
+uint32:1
+*/
+gboolean
+gpilot_daemon_remove_request (GpilotDaemon   *daemon,
+                              unsigned long   handle,
+                              GError        **error)
+{
+        gpc_queue_purge_request_point (handle/65535, handle%65535);
+        return TRUE;
+}
+
+
+/* information operations */
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetSystemInfo \
+string:'Cradle' uint32:0 uint32:0
+*/
+gboolean
+gpilot_daemon_get_system_info (GpilotDaemon   *daemon,
+                               const char     *cradle,
+                               GNOME_Pilot_Survival survival,
+                               unsigned long   timeout,
+                               unsigned long  *handle,
+                               GError        **error)
+{
+        GpilotDaemonPrivate *priv;
+        GPilotRequest        req;
+        gboolean             ret;
+        
+        ret = FALSE;
+        priv = daemon->priv;
+
+        LOG (("get_system_info(cradle=%s,survival=%d,timeout=%d)",
+              cradle, survival, timeout));
+
+        req.type = GREQ_GET_SYSINFO;
+        req.timeout = survival==GNOME_Pilot_PERSISTENT?0:timeout;
+        req.pilot_id = 0;
+        req.cradle = g_strdup (cradle);
+        req.client_id = g_strdup ("");
+
+        *handle = gpc_queue_store_request (req);
+        ret = TRUE;
+ out:
+        return ret;
+}
+
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetUsers
+*/
+gboolean
+gpilot_daemon_get_users (GpilotDaemon   *daemon,
+                         char         ***users,
+                         GError        **error)
+{
+        char *username;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_users()"));
+
+        username = daemon->priv->gpilotd_context->user->username;
+        if (IS_STR_SET (username)) {
+                *users = g_new (char *, 2);
+                (*users)[0] = g_strdup (username);
+                (*users)[1] = NULL;
+        }
+        return TRUE;
+}
+
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetCradles
+*/
+gboolean
+gpilot_daemon_get_cradles (GpilotDaemon   *daemon,
+                           char         ***cradles,
+                           GError        **error)
+{
+        int    i;
+        GList *l;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_cradles()"));
+
+        l = daemon->priv->gpilotd_context->devices;
+
+        *cradles = g_new (char *, g_list_length (l)+1);
+        for(i=0; i < g_list_length (l); i++) {
+                GPilotDevice *device = GPILOT_DEVICE (g_list_nth (l, i)->data);
+                (*cradles)[i] = g_strdup (device->name);
+        }
+        (*cradles)[g_list_length (l)] = NULL;
+
+        return TRUE;
+}
+
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetPilots
+*/
+gboolean
+gpilot_daemon_get_pilots (GpilotDaemon   *daemon,
+                          char         ***pilots,
+                          GError        **error)
+{
+        int    i;
+        GList *l;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_pilots()"));
+
+        l = daemon->priv->gpilotd_context->pilots;
+
+        *pilots = g_new (char *, g_list_length (l)+1);
+        for(i=0; i < g_list_length (l); i++) {
+                GPilotPilot *pilot = GPILOT_PILOT (g_list_nth (l, i)->data);
+                (*pilots)[i] = g_strdup (pilot->name);
+        }
+        (*pilots)[g_list_length (l)] = NULL;
+
+        return TRUE;
+}
+
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetPilotIDs
+*/
+gboolean
+gpilot_daemon_get_pilot_ids (GpilotDaemon   *daemon,
+                             GPtrArray     **pilots,
+                             GError        **error)
+{
+        int    i;
+        GList *l;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_pilot_ids()"));
+
+        if (pilots == NULL)
+                return FALSE;
+
+        *pilots = g_ptr_array_new ();
+        l = daemon->priv->gpilotd_context->pilots;
+
+        for(i=0; i < g_list_length (l); i++) {
+                GPilotPilot *pilot = GPILOT_PILOT (g_list_nth (l, i)->data);
+                g_ptr_array_add (*pilots, (pilot->pilot_id));
+        }
+
+        return TRUE;
+}
+
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetPilotsByUserName \
+string:'foo'
+*/
+gboolean
+gpilot_daemon_get_pilots_by_user_name (GpilotDaemon   *daemon,
+                                       const char     *username,
+                                       char         ***pilots,
+                                       GError        **error)
+{
+        int    i;
+        GList *l;
+        GList *matches;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_pilots_by_user_name(%s)", username));
+
+        if (pilots == NULL)
+                return FALSE;
+
+        l = daemon->priv->gpilotd_context->pilots;
+
+        matches = NULL;
+        for(i=0; i < g_list_length (l); i++) {
+                GPilotPilot *pilot = GPILOT_PILOT (g_list_nth (l, i)->data);
+                if (g_str_equal (pilot->pilot_username, username)) {
+                        LOG (("match on %s", pilot->pilot_username));
+                        matches = g_list_append (matches, pilot->name);
+                }
+        }
+
+        *pilots = g_new (char *, g_list_length (matches)+1);
+        for(i=0; i < g_list_length (matches); i++) {
+                (*pilots)[i] = g_strdup (g_list_nth (matches, i)->data);
+        }
+        (*pilots)[g_list_length (matches)] = NULL;
+
+        return TRUE;
+}
+
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetPilotsByUserLogin
+string:'foo'
+*/
+gboolean
+gpilot_daemon_get_pilots_by_user_login (GpilotDaemon   *daemon,
+                                        const char     *uid,
+                                        char         ***pilots,
+                                        GError        **error)
+{
+        gchar   *username;
+        gboolean ret;
+        struct passwd *pwdent;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_pilots_by_user_login(%s)", uid));
+
+        /* find the pwdent matching the login */
+        username = NULL;
+        setpwent ();
+        do {
+                pwdent = getpwent ();
+                if (pwdent) {
+                        if(strcmp (pwdent->pw_name,uid) == 0) {
+                                username = strdup (pwdent->pw_gecos);
+                                pwdent = NULL; /* end the loop */
+                        }
+                }
+        } while (pwdent);
+        endpwent();
+
+        /* no luck ? */
+        if(!username) {
+                LOG (("no realname for %s", uid));
+                return TRUE;
+        }
+
+        /* FIXME: uhm, is this use of username safe ? 
+           or should it be CORBA::strdup'ed ? */
+        ret = gpilot_daemon_get_pilots_by_user_name (daemon, username, pilots, error);
+        g_free (username);
+        return ret ;
+}
+
+gboolean
+gpilot_daemon_get_user_name_by_pilot_name (GpilotDaemon   *daemon,
+                                           const char     *pilot_name,
+                                           char          **username,
+                                           GError        **error)
+{
+        LOG (("FIXME %s:%d get_user_name_by_pilot_name", __FILE__, __LINE__));
+
+        /* FIXME: not implemented yet */
+        return TRUE;
+}
+
+gboolean
+gpilot_daemon_get_user_login_by_pilot_name (GpilotDaemon   *daemon,
+                                            const char     *pilot_name,
+                                            char          **uid,
+                                            GError        **error)
+{
+        LOG (("FIXME %s:%d get_user_login_by_pilot_name", __FILE__, __LINE__));
+
+        /* FIXME: not implemented yet */
+        return TRUE;
+}
+
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetPilotBaseDir \
+string:'MyPDA'
+*/
+gboolean
+gpilot_daemon_get_pilot_base_dir (GpilotDaemon   *daemon,
+                                  const char     *pilot_name,
+                                  char          **base_dir,
+                                  GError        **error)
+{
+        int    i;
+        GList *l;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_pilot_base_dir()"));
+
+        if (base_dir == NULL)
+                return FALSE;
+
+        l = daemon->priv->gpilotd_context->pilots;
+
+        for(i=0; i < g_list_length (l); i++) {
+                GPilotPilot *pilot = GPILOT_PILOT (g_list_nth (l, i)->data);
+                if( g_str_equal (pilot->name, pilot_name)) {
+                        LOG(("match on %s", pilot->name));
+                        *base_dir = g_strdup (pilot->sync_options.basedir);
+                }
+        }
+
+        return TRUE;
+}
+
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetPilotIdFromName \
+string:'MyPDA'
+*/
+gboolean
+gpilot_daemon_get_pilot_id_from_name (GpilotDaemon   *daemon,
+                                      const char     *pilot_name,
+                                      guint          *pilot_id,
+                                      GError        **error)
+{
+        LOG(("get_user_pilot_id_from_name"));
+
+        *pilot_id = pilot_id_from_name (pilot_name,
+                                        daemon->priv->gpilotd_context);
+
+        return TRUE;
+}
+
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetPilotNameFromId \
+uint32:10001
+*/
+gboolean
+gpilot_daemon_get_pilot_name_from_id (GpilotDaemon   *daemon,
+                                      guint           pilot_id,
+                                      char          **pilot_name,
+                                      GError        **error)
+{
+        LOG(("get_pilot_name_from_id(id=%d)", pilot_id));
+                                       
+        *pilot_name = pilot_name_from_id (pilot_id,
+                                          daemon->priv->gpilotd_context);
+        return TRUE;
+}
+
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetDatabasesFromCache \
+string:'MyPDA'
+*/
+gboolean
+gpilot_daemon_get_databases_from_cache (GpilotDaemon   *daemon,
+                                        const char     *pilot_name,
+                                        char         ***databases,
+                                        GError        **error)
+{
+        int       i;
+        gboolean  ret;
+        guint32   pilot_id;
+        GKeyFile *kfile;
+        gsize     num_bases;
+        char    **arr;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_databases_from_cache(...)"));
+
+        ret = FALSE;
+        if (databases == NULL)
+                return FALSE;
+
+        pilot_id = pilot_id_from_name (pilot_name,
+                                       daemon->priv->gpilotd_context);
+
+        if (pilot_id == 0) {
+                g_set_error (error,
+                             GPILOT_DAEMON_ERROR,
+                             GPILOT_DAEMON_ERROR_GENERAL,
+                             "Unknow pilot %s",
+                             pilot_name);
+                goto out;
+        }
+
+        kfile = get_pilot_cache_kfile (pilot_id);
+        arr = g_key_file_get_string_list (kfile, "Databases",
+                                          "databases", &num_bases, NULL);
+        *databases = g_new (char *, num_bases + 1);
+        for (i=0; i<num_bases; i++) {
+                (*databases)[i] = g_strdup (arr[i]);
+        }
+        (*databases)[num_bases] = NULL;
+
+        ret = TRUE;
+ out:
+        g_strfreev (arr);
+        return TRUE;
+}
+
+/* admin operations */
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetUserInfo \
+string:'Cradle' uint32:0 uint32:0
+*/
+gboolean
+gpilot_daemon_get_user_info (GpilotDaemon   *daemon,
+                             const char     *cradle,
+                             GNOME_Pilot_Survival survival,
+                             unsigned long   timeout,
+                             unsigned long  *handle,
+                             GError        **error)
+{
+        GpilotDaemonPrivate *priv;
+        GPilotRequest        req;
+        gboolean             ret;
+        
+        ret = FALSE;
+        priv = daemon->priv;
+
+        LOG (("get_user_info(cradle=%s,survival=%d,timeout=%d)",
+             cradle, survival, timeout));
+
+        req.type = GREQ_GET_USERINFO;
+        req.timeout = survival==GNOME_Pilot_PERSISTENT?0:timeout;
+        req.pilot_id = 0;
+        req.cradle = g_strdup (cradle);
+        req.client_id = g_strdup ("");
+
+        *handle = gpc_queue_store_request (req);
+        ret = TRUE;
+ out:
+        return ret;
+}
+
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.SetUserInfo \
+string:'Cradle' boolean:true uint32:0 \
+uint32:0 uint32:1111 username:'foo' 
+*/
+gboolean
+gpilot_daemon_set_user_info (GpilotDaemon   *daemon,
+                             const char     *cradle,
+                             gboolean        continue_sync,
+                             GNOME_Pilot_Survival survival,
+                             unsigned long   timeout,
+                             unsigned long   uid,
+                             const char     *username,
+                             unsigned long  *handle,
+                             GError        **error)
+{
+        GpilotDaemonPrivate *priv;
+        gboolean             ret;
+        
+        ret = FALSE;
+        priv = daemon->priv;
+
+        LOG (("set_user_info(cradle=%s,survival=%d,timeout=%d",
+            cradle,survival,timeout));
+        LOG (("              device = %s,", cradle));
+        LOG (("              user_id = %d,", uid));
+        LOG (("              user    = %s)", username));
+
+        *handle = gpc_queue_store_set_userinfo_request (
+                        survival==GNOME_Pilot_PERSISTENT?0:timeout, 
+                        cradle,
+                        "",
+                        username,
+                        uid,
+                        continue_sync);
+        ret = TRUE;
+ out:
+        return ret;
+}
+
+void
+dbus_notify_connected (const gchar     *pilot_id,
+                       struct PilotUser user_info)
+{
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+        gchar          *username;
+
+        /* do a strcpy for username to sending sending too long
+         string by dbus */
+        username = g_strdup (user_info.username);
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "Connected");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_id);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &user_info.userID);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &username);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+
+        g_free (username);
+}
+
+void
+dbus_notify_disconnected (const gchar    *pilot_id)
+{
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "Disconnected");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_id);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+}
+
+void
+dbus_notify_completion (GPilotRequest **req)
+{
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+        gchar          *pilot_name;
+
+        g_return_if_fail(req!=NULL);
+        g_return_if_fail(*req!=NULL);
+
+        if ((*req)->cradle)
+                pilot_name = g_strdup ((*req)->cradle);
+        else
+                pilot_name = g_strdup ("");
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "RequestCompleted");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_name);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &(*req)->handle);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+
+        gpc_queue_purge_request (req);
+        g_free (pilot_name);
+}
+
+void
+dbus_notify_userinfo (struct PilotUser    user_info,
+                      GPilotRequest     **req)
+{
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+        gchar          *username;
+
+        /* do a strcpy for username to sending sending too long
+         string by dbus */
+        username = g_strdup (user_info.username);
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "UserInfoRequested");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &(*req)->cradle);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &user_info.userID);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &username);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+
+        g_free (username);
+}
+
+void
+dbus_notify_sysinfo (const gchar      *pilot_id,
+                     GNOME_Pilot_SysInfo    sysinfo,
+                     struct CardInfo   cardinfo,
+                     GPilotRequest   **req)
+{
+        GNOME_Pilot_SysInfo _sysinfo;
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+
+        _sysinfo.romSize = cardinfo.romSize/1024;
+        _sysinfo.ramSize = cardinfo.ramSize/1024;
+        _sysinfo.ramFree = cardinfo.ramFree/1024;
+        _sysinfo.name = g_strdup (cardinfo.name);
+        _sysinfo.manufacturer = g_strdup (cardinfo.manufacturer);
+        _sysinfo.creation = cardinfo.creation;
+        _sysinfo.romVersion = sysinfo.romVersion;
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "SysInfoRequested");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_id);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &_sysinfo.romSize);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &_sysinfo.ramSize);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &_sysinfo.ramFree);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &_sysinfo.name);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &_sysinfo.manufacturer);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &_sysinfo.creation);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &_sysinfo.romVersion);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+}
+
+void
+dbus_notify_conduit_start (const gchar              *pilot_id,
+                           GnomePilotConduit        *conduit,
+                           GnomePilotConduitSyncType type)
+{
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+        gchar          *name;
+        gchar          *database;
+
+        name = gnome_pilot_conduit_get_name (conduit);
+        if(GNOME_IS_PILOT_CONDUIT_STANDARD(conduit))
+                database = g_strdup (gnome_pilot_conduit_standard_get_db_name(GNOME_PILOT_CONDUIT_STANDARD(conduit)));
+        else
+                database = g_strdup (_("(unknown DB)"));
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "ConduitStart");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_id);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &database);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+
+        g_free (name);
+        g_free (database);
+}
+
+void
+dbus_notify_conduit_end (const gchar       *pilot_id,
+                         GnomePilotConduit *conduit)
+{
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+        gchar          *name;
+
+        name = gnome_pilot_conduit_get_name (conduit);
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "ConduitEnd");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_id);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+
+        g_free (name);
+}
+
+void
+dbus_notify_conduit_progress (const gchar       *pilot_id,
+                              GnomePilotConduit *conduit,
+                              guint32            current,
+                              guint32            total)
+{
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+        gchar          *name;
+
+        name = gnome_pilot_conduit_get_name (conduit);
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "ConduitProgress");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_id);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &current);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &total);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+
+        g_free (name);
+}
+
+void
+dbus_notify_overall_progress (const gchar    *pilot_id,
+                              guint32         current,
+                              guint32         total)
+{
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "OverallProgress");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_id);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &current);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &total);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+}
+
+static void
+dbus_notify_message (const gchar       *pilot_id,
+                     GnomePilotConduit *conduit,
+                     const gchar       *msg,
+                     const gchar       *method_call)
+{
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+        gchar          *name;
+
+        if (GNOME_IS_PILOT_CONDUIT (conduit))
+                name = gnome_pilot_conduit_get_name (conduit);
+        else
+                name = NULL;
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                       GP_DBUS_INTERFACE,
+                                       method_call);
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_id);
+        if (IS_STR_SET (name))
+                dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &msg);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+
+        g_free (name);
+}
+
+void
+dbus_notify_conduit_error (const gchar       *pilot_id,
+                           GnomePilotConduit *conduit,
+                           const gchar       *message)
+{
+        dbus_notify_message (pilot_id, conduit, message, "ConduitError");
+}
+
+void
+dbus_notify_conduit_message (const gchar       *pilot_id,
+                             GnomePilotConduit *conduit,
+                             const gchar       *message)
+{
+        dbus_notify_message (pilot_id, conduit, message, "ConduitMessage");
+}
+
+void
+dbus_notify_daemon_message (const gchar       *pilot_id,
+                            GnomePilotConduit *conduit,
+                            const gchar       *message)
+{
+        dbus_notify_message (pilot_id, conduit, message, "DaemonMessage");
+}
+
+void
+dbus_notify_daemon_error (const gchar       *pilot_id,
+                          const gchar       *message)
+{
+        dbus_notify_message (pilot_id, NULL, message, "DaemonError");
+}
+
+static void
+bus_name_owner_changed (DBusGProxy   *bus_proxy,
+                        const char   *service_name,
+                        const char   *old_service_name,
+                        const char   *new_service_name,
+                        GpilotDaemon *daemon)
+{
+        return;
+}
+
+static gboolean
+register_daemon (GpilotDaemon *daemon)
+{
+        GError *error = NULL;
+
+        daemon->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+        if (daemon->priv->connection == NULL) {
+                if (error != NULL) {
+                        g_critical ("error getting session bus: %s", error->message);
+                        g_error_free (error);
+                }
+                exit (1);
+        }
+
+        daemon->priv->bus_proxy = dbus_g_proxy_new_for_name (daemon->priv->connection,
+                                                              DBUS_SERVICE_DBUS,
+                                                              DBUS_PATH_DBUS,
+                                                              DBUS_INTERFACE_DBUS);
+
+        dbus_g_proxy_add_signal (daemon->priv->bus_proxy,
+                                 "NameOwnerChanged",
+                                 G_TYPE_STRING,
+                                 G_TYPE_STRING,
+                                 G_TYPE_STRING,
+                                 G_TYPE_INVALID);
+        dbus_g_proxy_connect_signal (daemon->priv->bus_proxy,
+                                     "NameOwnerChanged",
+                                     G_CALLBACK (bus_name_owner_changed),
+                                     daemon,
+                                     NULL);
+
+        dbus_g_connection_register_g_object (daemon->priv->connection, GP_DBUS_PATH, G_OBJECT (daemon));
+
+        return TRUE;
+}
+
+static void
+gpilot_daemon_class_init (GpilotDaemonClass *klass)
+{
+        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->finalize = gpilot_daemon_finalize;
+
+        signals [CONNECTED] = g_signal_new ("connected",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, connected),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING_UINT_STRING,
+                                            G_TYPE_NONE,
+                                            3,
+                                            G_TYPE_STRING,
+                                            G_TYPE_UINT,
+                                            G_TYPE_STRING);
+        signals [DISCONNECTED] = g_signal_new ("disconnected",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, disconnected),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING,
+                                            G_TYPE_NONE,
+                                            1,
+                                            G_TYPE_STRING);
+        signals [REQUEST_COMPLETED] = g_signal_new ("request-completed",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, request_completed),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING_UINT,
+                                            G_TYPE_NONE,
+                                            2,
+                                            G_TYPE_STRING,
+                                            G_TYPE_UINT);
+        signals [USERINFO_REQUESTED] = g_signal_new ("user-info-requested",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, user_info_requested),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING_UINT_STRING,
+                                            G_TYPE_NONE,
+                                            3,
+                                            G_TYPE_STRING,
+                                            G_TYPE_UINT,
+                                            G_TYPE_STRING);
+        signals [SYSINFO_REQUESTED] = g_signal_new ("sys-info-requested",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, sys_info_requested),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING_UINT_UINT_UINT_STRING_STRING_UINT_UINT,
+                                            G_TYPE_NONE,
+                                            8,
+                                            G_TYPE_STRING,
+                                            G_TYPE_UINT,
+                                            G_TYPE_UINT,
+                                            G_TYPE_UINT,
+                                            G_TYPE_STRING,
+                                            G_TYPE_STRING,
+                                            G_TYPE_UINT,
+                                            G_TYPE_UINT);
+        signals [CONDUIT_START] = g_signal_new ("conduit-start",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, conduit_start),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING_STRING_STRING,
+                                            G_TYPE_NONE,
+                                            3,
+                                            G_TYPE_STRING,
+                                            G_TYPE_STRING,
+                                            G_TYPE_STRING);
+        signals [CONDUIT_PROGRESS] = g_signal_new ("conduit-progress",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, conduit_progress),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING_STRING_UINT_UINT,
+                                            G_TYPE_NONE,
+                                            4,
+                                            G_TYPE_STRING,
+                                            G_TYPE_STRING,
+                                            G_TYPE_UINT,
+                                            G_TYPE_UINT);
+        signals [CONDUIT_END] = g_signal_new ("conduit-end",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, conduit_end),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING,
+                                            G_TYPE_NONE,
+                                            1,
+                                            G_TYPE_STRING);
+        signals [OVERALL_PROGRESS] = g_signal_new ("overall-progress",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, overall_progress),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING_UINT_UINT,
+                                            G_TYPE_NONE,
+                                            3,
+                                            G_TYPE_STRING,
+                                            G_TYPE_UINT,
+                                            G_TYPE_UINT);
+        signals [DAEMON_MESSAGE] = g_signal_new ("daemon-message",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, daemon_message),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING_STRING_STRING,
+                                            G_TYPE_NONE,
+                                            3,
+                                            G_TYPE_STRING,
+                                            G_TYPE_STRING,
+                                            G_TYPE_STRING);
+        signals [DAEMON_ERROR] = g_signal_new ("daemon-error",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, daemon_error),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING_STRING,
+                                            G_TYPE_NONE,
+                                            2,
+                                            G_TYPE_STRING,
+                                            G_TYPE_STRING);
+        signals [CONDUIT_MESSAGE] = g_signal_new ("conduit-message",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, conduit_message),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING_STRING_STRING,
+                                            G_TYPE_NONE,
+                                            3,
+                                            G_TYPE_STRING,
+                                            G_TYPE_STRING,
+                                            G_TYPE_STRING);
+        signals [CONDUIT_ERROR] = g_signal_new ("conduit-error",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, conduit_error),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__STRING_STRING_STRING,
+                                            G_TYPE_NONE,
+                                            3,
+                                            G_TYPE_STRING,
+                                            G_TYPE_STRING,
+                                            G_TYPE_STRING);
+        signals [PAUSED] = g_signal_new ("paused",
+                                            G_TYPE_FROM_CLASS (object_class),
+                                            G_SIGNAL_RUN_LAST,
+                                            G_STRUCT_OFFSET (GpilotDaemonClass, paused),
+                                            NULL,
+                                            NULL,
+                                            gp_marshal_VOID__BOOLEAN,
+                                            G_TYPE_NONE,
+                                            1,
+                                            G_TYPE_BOOLEAN);
+
+        g_type_class_add_private (klass, sizeof (GpilotDaemonPrivate));
+
+        dbus_g_object_type_install_info (GPILOT_TYPE_DAEMON, &dbus_glib_gpilot_daemon_object_info);
+}
+
+static void
+gpilot_daemon_init (GpilotDaemon *daemon)
+{
+#ifdef WITH_HAL
+	if ((hal_ctx = gpilotd_hal_init ()) != NULL)
+		hal_initialised = 1; /* if 0, fall back to polling sysfs */
+#endif
+	
+        daemon->priv = GPILOT_DAEMON_GET_PRIVATE (daemon);
+
+        daemon->priv->gpilotd_context = gpilot_context_new ();
+        gpilot_context_init_user (daemon->priv->gpilotd_context);
+
+        g_list_foreach (daemon->priv->gpilotd_context->devices,
+                        (GFunc)monitor_channel,
+                        daemon->priv->gpilotd_context);
+}
+
+static void
+gpilot_daemon_finalize (GObject *object)
+{
+        GpilotDaemon *daemon;
+
+        g_return_if_fail (object != NULL);
+        g_return_if_fail (GPILOT_IS_DAEMON (object));
+
+        daemon= GPILOT_DAEMON (object);
+
+        g_return_if_fail (daemon->priv != NULL);
+
+        if (daemon->priv->bus_proxy != NULL) {
+                g_object_unref (daemon->priv->bus_proxy);    
+        }
+
+        G_OBJECT_CLASS (gpilot_daemon_parent_class)->finalize (object);
+}
+
+GpilotDaemon*
+gpilot_daemon_new ()
+{
+        if (daemon_object != NULL) {
+                g_object_ref (daemon_object);
+        } else {
+                gboolean res;
+
+                daemon_object = g_object_new (GPILOT_TYPE_DAEMON, NULL);
+                g_object_add_weak_pointer (daemon_object,
+                                           (gpointer *) &daemon_object);
+                res = register_daemon (daemon_object);
+                if (! res) {
+                        g_object_unref (daemon_object);
+                        return NULL;
+                }
+
+        }
+
+        return GPILOT_DAEMON (daemon_object);
+}
diff --git a/gpilotd/gpilot-daemon.h b/gpilotd/gpilot-daemon.h
new file mode 100644
index 0000000..0ebe234
--- /dev/null
+++ b/gpilotd/gpilot-daemon.h
@@ -0,0 +1,313 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- *//* 
+ *
+ * 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.
+ *
+ * Authors: Halton Huo <halton.huo@gmail.com>
+ *
+ */
+
+#ifndef __GPILOT_DAEMON_H
+#define __GPILOT_DAEMON_H
+
+G_BEGIN_DECLS
+
+#include <glib-object.h>
+#include <dbus/dbus-glib.h>
+
+#include "gnome-pilot-structures.h"
+#include "gnome-pilot-dbinfo.h"
+#include "queue_io.h"
+
+#define GPILOT_TYPE_DAEMON         (gpilot_daemon_get_type ())
+#define GPILOT_DAEMON(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GPILOT_TYPE_DAEMON, GpilotDaemon))
+#define GPILOT_DAEMON_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GPILOT_TYPE_DAEMON, GpilotDaemonClass))
+#define GPILOT_IS_DAEMON(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPILOT_TYPE_DAEMON))
+#define GPILOT_IS_DAEMON_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GPILOT_TYPE_DAEMON))
+#define GPILOT_DAEMON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPILOT_TYPE_DAEMON, GpilotDaemonClass))
+
+#define LOG(x) g_message x
+
+typedef struct GpilotDaemonPrivate GpilotDaemonPrivate;
+typedef struct
+{
+        GObject            parent;
+        GpilotDaemonPrivate *priv;
+} GpilotDaemon;
+
+typedef struct
+{
+        GObjectClass   parent_class;
+        void          (* connected)          (GpilotDaemon   *gpilot,
+                                              const char     *pilot_name,
+                                              unsigned long  *uid,
+                                              const char     *user);
+        void          (* disconnected)       (GpilotDaemon   *gpilot,
+                                              const char     *pilot_id);
+        void          (* request_completed)  (GpilotDaemon   *gpilot,
+                                              const char     *pilot_id,
+                                              unsigned long   request_id);
+        void          (* user_info_requested) (GpilotDaemon   *gpilot,
+                                              const char     *device,
+                                              unsigned long   uid,
+                                              const char     *username);
+        void          (* sys_info_requested) (GpilotDaemon   *gpilot,
+                                              const char     *pilot_id,
+                                              int             rom_size,
+                                              int             ram_size,
+                                              int             ram_free,
+                                              const char     *name,
+                                              const char     *manufacturer,
+                                              int             creation,
+                                              int             rom_version);
+        void          (* conduit_start)      (GpilotDaemon   *gpilot,
+                                              const char     *pilot_id,
+                                              const char     *conduit,
+                                              const char     *database);
+        void          (* conduit_progress)   (GpilotDaemon   *gpilot,
+                                              const char     *pilot_id,
+                                              const char     *conduit,
+                                              unsigned long   current,
+                                              unsigned long   total);
+        void          (* conduit_end)        (GpilotDaemon   *gpilot,
+                                              const char     *pilot_id);
+        void          (* overall_progress)   (GpilotDaemon   *gpilot,
+                                              const char     *pilot_id,
+                                              unsigned long   current,
+                                              unsigned long   total);
+        void          (* daemon_message)     (GpilotDaemon   *gpilot,
+                                              const char     *pilot_id,
+                                              const char     *conduit,
+                                              const char     *message);
+        void          (* daemon_error)       (GpilotDaemon   *gpilot,
+                                              const char     *pilot_id,
+                                              const char     *message);
+        void          (* conduit_message)    (GpilotDaemon   *gpilot,
+                                              const char     *pilot_id,
+                                              const char     *conduit,
+                                              const char     *message);
+        void          (* conduit_error)      (GpilotDaemon   *gpilot,
+                                              const char     *pilot_id,
+                                              const char     *conduit,
+                                              const char     *message);
+        void          (* paused)             (GpilotDaemon   *gpilot,
+                                              gboolean        on_ff);
+} GpilotDaemonClass;
+
+typedef struct {
+        unsigned long  userID;
+        gchar         *username;
+} GNOME_Pilot_UserInfo;
+
+typedef struct {
+        long     romSize;
+        long     ramSize;
+        long     ramFree;
+        char    *name;
+        char    *manufacturer;
+        long     creation;
+        long     romVersion;
+} GNOME_Pilot_SysInfo;
+
+typedef enum
+{
+        GNOME_Pilot_IMMEDIATE,
+        GNOME_Pilot_PERSISTENT
+} GNOME_Pilot_Survival;
+
+typedef enum
+{
+        GNOME_Pilot_SYNCHRONIZE,
+        GNOME_Pilot_CONDUIT_DEFAULT,
+        GNOME_Pilot_COPY_FROM_PILOT,
+        GNOME_Pilot_COPY_TO_PILOT,
+        GNOME_Pilot_MERGE_FROM_PILOT,
+        GNOME_Pilot_MERGE_TO_PILOT
+} GNOME_Pilot_ConduitOperation;
+
+typedef enum
+{
+        GPILOT_DAEMON_ERROR_GENERAL,
+        GPILOT_DAEMON_NUM_ERRORS
+} GpilotDaemonError;
+
+#define GPILOT_DAEMON_ERROR gpilot_daemon_error_quark ()
+
+GType           gpilot_daemon_error_get_type    (void);
+#define GPILOT_DAEMON_TYPE_ERROR (gpilot_daemon_error_get_type ())
+
+GQuark          gpilot_daemon_error_quark       (void);
+GType           gpilot_daemon_get_type          (void);
+GpilotDaemon*   gpilot_daemon_new               (void);
+
+/* exported to bus */
+
+/* adm calls */
+gboolean        gpilot_daemon_pause             (GpilotDaemon   *daemon,
+                                                 gboolean        on_off,
+                                                 GError        **error);
+gboolean        gpilot_daemon_reread_config     (GpilotDaemon   *daemon,
+                                                 GError        **error);
+
+/* A no-operation call, used by client to occasionally
+   check to see if the daemon has blown up */
+gboolean        gpilot_daemon_noop              (GpilotDaemon   *daemon);
+/* request operations */
+gboolean        gpilot_daemon_request_install   (GpilotDaemon   *daemon,
+                                                 const char     *pilot_name,
+                                                 const char     *filename,
+                                                 const char     *description,
+                                                 GNOME_Pilot_Survival survival,
+                                                 unsigned long   timeout,
+                                                 unsigned long  *handle,
+                                                 GError        **error);
+gboolean        gpilot_daemon_request_restore   (GpilotDaemon   *daemon,
+                                                 const char     *pilot_name,
+                                                 const char     *directory,
+                                                 GNOME_Pilot_Survival survival,
+                                                 unsigned long   timeout,
+                                                 unsigned long  *handle,
+                                                 GError        **error);
+gboolean        gpilot_daemon_request_conduit   (GpilotDaemon   *daemon,
+                                                 const char     *pilot_name,
+                                                 const char     *conduit_name,
+                                                 GNOME_Pilot_ConduitOperation operation,
+                                                 GNOME_Pilot_Survival survival,
+                                                 unsigned long   timeout,
+                                                 unsigned long  *handle,
+                                                 GError        **error);
+gboolean        gpilot_daemon_remove_request    (GpilotDaemon   *daemon,
+                                                 unsigned long   handle,
+                                                 GError        **error);
+/* information operations */
+gboolean        gpilot_daemon_get_system_info   (GpilotDaemon   *daemon,
+                                                 const char     *cradle,
+                                                 GNOME_Pilot_Survival survival,
+                                                 unsigned long   timeout,
+                                                 unsigned long  *handle,
+                                                 GError        **error);
+gboolean        gpilot_daemon_get_users         (GpilotDaemon   *daemon,
+                                                 char         ***users,
+                                                 GError        **error);
+gboolean        gpilot_daemon_get_cradles       (GpilotDaemon   *daemon,
+                                                 char         ***cradles,
+                                                 GError        **error);
+gboolean        gpilot_daemon_get_pilots        (GpilotDaemon   *daemon,
+                                                 char         ***pilots,
+                                                 GError        **error);
+gboolean        gpilot_daemon_get_pilot_ids     (GpilotDaemon   *daemon,
+                                                 GPtrArray     **pilots,
+                                                 GError        **error);
+gboolean        gpilot_daemon_get_pilots_by_user_name
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *username,
+                                                 char         ***pilots,
+                                                 GError        **error);
+gboolean        gpilot_daemon_get_pilots_by_user_login
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *uid,
+                                                 char         ***pilots,
+                                                 GError        **error);
+gboolean        gpilot_daemon_get_user_name_by_pilot_name
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *pilot_name,
+                                                 char          **username,
+                                                 GError        **error);
+gboolean        gpilot_daemon_get_user_login_by_pilot_name
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *pilot_name,
+                                                 char          **uid,
+                                                 GError        **error);
+gboolean        gpilot_daemon_get_pilot_base_dir
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *pilot_name,
+                                                 char          **base_dir,
+                                                 GError        **error);
+gboolean        gpilot_daemon_get_pilot_id_from_name
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *pilot_name,
+                                                 guint          *pilot_id,
+                                                 GError        **error);
+gboolean        gpilot_daemon_get_pilot_name_from_id
+                                                (GpilotDaemon   *daemon,
+                                                 guint           pilot_id,
+                                                 char          **pilot_name,
+                                                 GError        **error);
+gboolean        gpilot_daemon_get_databases_from_cache
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *pilot_name,
+                                                 char         ***databases,
+                                                 GError        **error);
+/* admin operations */
+gboolean        gpilot_daemon_get_user_info     (GpilotDaemon   *daemon,
+                                                 const char     *cradle,
+                                                 GNOME_Pilot_Survival survival,
+                                                 unsigned long   timeout,
+                                                 unsigned long  *handle,
+                                                 GError        **error);
+gboolean        gpilot_daemon_set_user_info     (GpilotDaemon   *daemon,
+                                                 const char     *cradle,
+                                                 gboolean        continue_sync,
+                                                 GNOME_Pilot_Survival survival,
+                                                 unsigned long   timeout,
+                                                 unsigned long   uid,
+                                                 const char     *username,
+                                                 unsigned long  *handle,
+                                                 GError        **error);
+/* general functions */
+guint32         pilot_id_from_name              (const gchar    *name,
+                                                 GPilotContext  *context);
+gchar*          pilot_name_from_id              (guint32         id,
+                                                 GPilotContext  *context);
+
+/* send dbus signals */
+void            dbus_notify_connected           (const gchar    *pilot_id,
+                                                 struct PilotUser user_info);
+void            dbus_notify_disconnected        (const gchar    *pilot_id);
+void            dbus_notify_completion          (GPilotRequest **req);
+void            dbus_notify_userinfo            (struct PilotUser user_info,
+                                                 GPilotRequest **req);
+void            dbus_notify_sysinfo             (const gchar    *pilot_id,
+                                                 GNOME_Pilot_SysInfo  sysinfo,
+                                                 struct CardInfo cardinfo,
+                                                 GPilotRequest **req);
+
+void            dbus_notify_conduit_start       (const gchar    *pilot_id,
+                                                 GnomePilotConduit *conduit,
+                                                 GnomePilotConduitSyncType);
+void            dbus_notify_conduit_end         (const gchar    *pilot_id,
+                                                 GnomePilotConduit *conduit);
+void            dbus_notify_conduit_error       (const gchar    *pilot_id,
+                                                 GnomePilotConduit *conduit,
+                                                 const gchar    *message);
+void            dbus_notify_conduit_message     (const gchar    *pilot_id,
+                                                 GnomePilotConduit *conduit,
+                                                 const gchar    *message);
+void            dbus_notify_conduit_progress    (const gchar    *pilot_id,
+                                                 GnomePilotConduit *conduit,
+                                                 guint32         current,
+                                                 guint32         total);
+void            dbus_notify_overall_progress    (const gchar    *pilot_id,
+                                                 guint32         current,
+                                                 guint32         total);
+void            dbus_notify_daemon_message      (const gchar    *pilot_id,
+                                                 GnomePilotConduit *conduit,
+                                                 const gchar    *message);
+void            dbus_notify_daemon_error        (const gchar    *pilot_id,
+                                                 const gchar    *message);
+
+G_END_DECLS
+
+#endif /* __GPILOT_DAEMON_H */
diff --git a/gpilotd/gpilot-daemon.xml b/gpilotd/gpilot-daemon.xml
new file mode 100644
index 0000000..2e4022e
--- /dev/null
+++ b/gpilotd/gpilot-daemon.xml
@@ -0,0 +1,770 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+  <interface name="org.gnome.GnomePilot.Daemon">
+    <method name="Pause">
+      <arg name="on_off" direction="in" type="b"/>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to pause or continue the daemon.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="RereadConfig">
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to reload the configuration.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="Noop">
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method does nothing, used by client to occasionally check to see if the daemon has blown up.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="RequestInstall">
+      <arg name="pilot_name" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The pilot name</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="filename" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The file name</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="description" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The description</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="survival" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>Indicate how this operation survive. Currently 0 means immediate, 1 means persitent.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="timeout" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>The time out by second.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="handle" direction="out" type="u">
+        <doc:doc>
+          <doc:summary>The returned handle.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to install a pilot.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="RequestRestore">
+      <arg name="pilot_name" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The pilot name</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="directory" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The pilot directory</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="survival" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>Indicate how this operation survive. Currently 0 means immediate, 1 means persitent.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="timeout" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>The time out by second.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="handle" direction="out" type="u">
+        <doc:doc>
+          <doc:summary>The returned handle.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to restore a pilot.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="RequestConduit">
+      <arg name="pilot_name" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The pilot name</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="conduit_name" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The conduit name</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="operation" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>The conduit operation type. Currently support following operations:
+        0 - SYNCHRONIZE
+        1 - CONDUIT_DEFAULT
+        2 - COPY_FROM_PILOT
+        3 - COPY_TO_PILOT
+        4 - MERGE_FROM_PILOT
+        5 - MERGE_TO_PILOT
+          </doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="survival" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>Indicate how this operation survive. Currently 0 means immediate, 1 means persitent.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="timeout" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>The time out by second.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="handle" direction="out" type="u">
+        <doc:doc>
+          <doc:summary>The returned handle.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to restore a pilot.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="RemoveRequest">
+      <arg name="handle" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>The handle.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to remove a request.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetSystemInfo">
+      <arg name="cradle" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The cradle name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="survival" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>Indicate how this operation survive. Currently 0 means immediate, 1 means persitent.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="timeout" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>The time out by second.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="handle" direction="out" type="u">
+        <doc:doc>
+          <doc:summary>The returned handle.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get system info.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetUsers">
+      <arg name="users" direction="out" type="as">
+        <doc:doc>
+          <doc:summary>An array of user names.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get a list of all the users.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetCradles">
+      <arg name="cradles" direction="out" type="as">
+        <doc:doc>
+          <doc:summary>An array of cradles.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get a list of all the cradles.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetPilots">
+      <arg name="pilots" direction="out" type="as">
+        <doc:doc>
+          <doc:summary>An array of pilot names.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get a list of all the pilot names.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetPilotIDs">
+      <arg name="pilots" direction="out" type="au">
+        <doc:doc>
+          <doc:summary>An array of pilot IDs.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get a list of all the pilot IDs.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetPilotsByUserName">
+      <arg name="username" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The user name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="pilots" direction="out" type="as">
+        <doc:doc>
+          <doc:summary>An array of pilot names.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get a list of all the pilot names by given user name.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetPilotsByUserLogin">
+      <arg name="uid" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The user id.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="pilots" direction="out" type="as">
+        <doc:doc>
+          <doc:summary>An array of pilot names.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get a list of all the pilot names by given user id.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetUserNameByPilotName">
+      <arg name="pilot_name" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The pilot name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="username" direction="out" type="s">
+        <doc:doc>
+          <doc:summary>The returned user name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get the user name by given pilot name.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetUserLoginByPilotName">
+      <arg name="pilot_name" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The pilot name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="uid" direction="out" type="s">
+        <doc:doc>
+          <doc:summary>The returned user id.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get the user id by given pilot name.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetPilotBaseDir">
+      <arg name="pilot_name" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The pilot name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="base_dir" direction="out" type="s">
+        <doc:doc>
+          <doc:summary>The returned base dir.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get the base dir by given pilot name.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetPilotIdFromName">
+      <arg name="pilot_name" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The pilot name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="pilot_id" direction="out" type="u">
+        <doc:doc>
+          <doc:summary>The returned pilot id.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get the pilot id by given pilot name.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetPilotNameFromId">
+      <arg name="pilot_id" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>The pilot id.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="pilot_name" direction="out" type="s">
+        <doc:doc>
+          <doc:summary>The returned pilot name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get the pilot name by given pilot id.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetDatabasesFromCache">
+      <arg name="pilot_name" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The pilot name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="databases" direction="out" type="as">
+        <doc:doc>
+          <doc:summary>An array of databases.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get databases by given pilot name.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="GetUserInfo">
+      <arg name="cradle" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The cradle name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="survival" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>Indicate how this operation survive. Currently 0 means immediate, 1 means persitent.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="timeout" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>The time out by second.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="handle" direction="out" type="u">
+        <doc:doc>
+          <doc:summary>The returned handle.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to get user infos.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="SetUserInfo">
+      <arg name="cradle" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The cradle name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="continue_sync" direction="in" type="b">
+        <doc:doc>
+          <doc:summary>Indicate whether to continue synchronize.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="survival" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>Indicate how this operation survive. Currently 0 means immediate, 1 means persitent.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="timeout" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>The time out by second.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="uid" direction="in" type="u">
+        <doc:doc>
+          <doc:summary>The returned user id.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="username" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>The returned user name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="handle" direction="out" type="u">
+        <doc:doc>
+          <doc:summary>The returned handle.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method initiates a request to set user infos.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <signal name="Connected">
+      <arg name="pilot_id" type="s">
+        <doc:doc>
+          <doc:summary>The pilot id</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="uid" type="u">
+        <doc:doc>
+          <doc:summary>The user id.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="username" type="s">
+        <doc:doc>
+          <doc:summary>The user name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when a pilot connected.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="Disconnected">
+      <arg name="pilot_id" type="s">
+        <doc:doc>
+          <doc:summary>The pilot id</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when a pilot disconnected.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="RequestCompleted">
+      <arg name="pilot_id" type="s">
+        <doc:doc>
+          <doc:summary>The pilot id</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="request_id" type="u">
+        <doc:doc>
+          <doc:summary>The request id.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when a request completed.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="UserInfoRequested">
+      <arg name="device" type="s">
+        <doc:doc>
+          <doc:summary>The device</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="uid" type="u">
+        <doc:doc>
+          <doc:summary>The user id.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="username" type="s">
+        <doc:doc>
+          <doc:summary>The user name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when user info is requested.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="SysInfoRequested">
+      <arg name="pilot_id" type="s">
+        <doc:doc>
+          <doc:summary>The pilot id</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="rom_size" type="i">
+        <doc:doc>
+          <doc:summary>The rom size</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="ram_size" type="i">
+        <doc:doc>
+          <doc:summary>The ram size</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="ram_free" type="i">
+        <doc:doc>
+          <doc:summary>The free ram size</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="name" type="s">
+        <doc:doc>
+          <doc:summary>The name</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="manufacturer" type="s">
+        <doc:doc>
+          <doc:summary>The manufacturer</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="creation" type="i">
+        <doc:doc>
+          <doc:summary>The creation time</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="rom_version" type="i">
+        <doc:doc>
+          <doc:summary>The rom version</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when sys info is requested.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="ConduitStart">
+      <arg name="pilot_id" type="s">
+        <doc:doc>
+          <doc:summary>The pilot id</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="conduit" type="s">
+        <doc:doc>
+          <doc:summary>The conduit name</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="database" type="s">
+        <doc:doc>
+          <doc:summary>The database name</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when conduit syncing start, used for progress bar.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="ConduitProgress">
+      <arg name="pilot_id" type="s">
+        <doc:doc>
+          <doc:summary>The pilot id</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="conduit" type="s">
+        <doc:doc>
+          <doc:summary>The conduit name</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="current" type="u">
+        <doc:doc>
+          <doc:summary>The current number</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="total" type="u">
+        <doc:doc>
+          <doc:summary>The total number</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when conduit syncing in progress, used for progress bar.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="ConduitEnd">
+      <arg name="pilot_id" type="s">
+        <doc:doc>
+          <doc:summary>The pilot id</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="conduit" type="s">
+        <doc:doc>
+          <doc:summary>The conduit name</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when conduit syncing end, used for progress bar.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="OverallProgress">
+      <arg name="pilot_id" type="s">
+        <doc:doc>
+          <doc:summary>The pilot id</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="current" type="u">
+        <doc:doc>
+          <doc:summary>The current number</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="total" type="u">
+        <doc:doc>
+          <doc:summary>The total number</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when the overall syncing in progress, used for progress bar.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="DaemonMessage">
+      <arg name="pilot_id" type="s">
+        <doc:doc>
+          <doc:summary>The pilot id</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="conduit" type="s">
+        <doc:doc>
+          <doc:summary>The conduit name</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="message" type="s">
+        <doc:doc>
+          <doc:summary>The message</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when a daemon message appears.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="DaemonError">
+      <arg name="pilot_id" type="s">
+        <doc:doc>
+          <doc:summary>The pilot id</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="message" type="s">
+        <doc:doc>
+          <doc:summary>The message</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when a daemon error appears.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="ConduitMessage">
+      <arg name="pilot_id" type="s">
+        <doc:doc>
+          <doc:summary>The pilot id</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="conduit" type="s">
+        <doc:doc>
+          <doc:summary>The conduit name</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="message" type="s">
+        <doc:doc>
+          <doc:summary>The message</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when a conduit message appears.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="ConduitError">
+      <arg name="pilot_id" type="s">
+        <doc:doc>
+          <doc:summary>The pilot id</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="conduit" type="s">
+        <doc:doc>
+          <doc:summary>The conduit name</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg name="message" type="s">
+        <doc:doc>
+          <doc:summary>The message</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when a conduit error appears.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="Paused">
+      <arg name="on_off" type="b">
+        <doc:doc>
+          <doc:summary>Indicate pause on or off.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when to pause or unpaused.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+  </interface>
+</node>
diff --git a/gpilotd/gpilotd.c b/gpilotd/gpilotd.c
index 68a1bb6..2eb8ae2 100644
--- a/gpilotd/gpilotd.c
+++ b/gpilotd/gpilotd.c
@@ -27,1510 +27,25 @@
 #include "config.h"
 #endif
 
-#include <glib.h>
-#include <libgnome/gnome-init.h>
-#include <glib/gi18n.h>
-
-/* for crypt () */
-#ifdef USE_XOPEN_SOURCE
-#ifndef _XOPEN_SOURCE
-#define _XOPEN_SOURCE 
-#endif /* _XOPEN_SOURCE  */
-#endif
-
-#define _BSD_SOURCE 1		/* Or gethostname won't be declared properly
-				   on Linux and GNU platforms. */
-
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/wait.h>
-#include <sys/time.h>
 
 #include <glib.h>
-#include <crypt.h>
-#include <pwd.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <regex.h>
-
-#include <libxml/xmlmemory.h>
-#include <libxml/entities.h>
+#include <glib/gi18n.h>
 
-#ifdef WITH_HAL
-#include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
-#include <libhal.h>
-#endif
-
-#include <pi-source.h>
-#include <pi-dlp.h>
-#include <pi-version.h>
-
-#include "manager.h"
-#include "gnome-pilot-structures.h"
-#include "orbit_daemon_glue.h"
-#include "gpilot-gui.h"
-#include "gnome-pilot-conduit-backup.h"
-#include "gnome-pilot-config.h"
-
-#include "../libgpilotdCM/gnome-pilot-conduit-management.h"
 
-static GPilotContext *context = NULL;
+#include "gpilot-daemon.h"
 
-#ifdef WITH_HAL
-static DBusConnection *dbus_connection = NULL;
-static LibHalContext *hal_ctx = NULL;
+#define GP_DBUS_NAME         "org.gnome.GnomePilot"
 
-static gboolean gpilotd_dbus_init (void);
-static LibHalContext *gpilotd_hal_init (void);
-#endif
-static guint visor_timeout_id = -1;
-static guint hal_initialised = 0;
-
-
-/* Set to true when the config should be reloaded */
-static gboolean reread_config = FALSE;
-
-static gboolean device_in (GIOChannel *, GIOCondition, GPilotContext *);
-static gboolean device_err (GIOChannel *, GIOCondition, GPilotContext *);
-static gboolean network_device_in (GIOChannel *, GIOCondition, GPilotContext *);
-static gboolean network_device_err (GIOChannel *, GIOCondition, GPilotContext *);
-static void monitor_channel (GPilotDevice *, GPilotContext *);
 static void remove_pid_file (void);
-#ifdef PILOT_LINK_0_12
-static int check_usb_config(GPilotDevice *device);
-#endif
-
-static int
-device_equal_by_io (GPilotDevice *dev, GIOChannel *io) 
-{
-	return !(dev->io == io);
-}
-
-static void
-remove_device (GPilotContext *context, GPilotDevice *device) 
-{
-	GList *l;
-
-	g_message ("Removing %s", device->name);
-
-	l = g_list_find (context->devices, device);
-	if (l != NULL) {
-		gpilot_device_free (l->data);
-		context->devices = g_list_remove (context->devices, l);
-		g_list_free_1 (l);
-	} else {
-		g_message ("%s not found",device->name);
-	}
-}
-
-static void 
-pilot_set_baud_rate (GPilotDevice *device) 
-{
-	static char rate_buf[128];
-	
-	g_snprintf (rate_buf, 128, "PILOTRATE=%d", device->speed);
-	g_message ("setting %s", rate_buf);
-	putenv (rate_buf);
-}
-
-/*
-  Sets *error to 1 on fatal error on the device, 2 on other errors , 0 otherwise.
- */
-static int 
-pilot_connect (GPilotDevice *device,int *error) 
-{
-#define MAX_TIME_FOR_PI_BIND 1000000 /* 1 second, or 1,000,000 usec. */
-#define SLEEP_TIME_FOR_PI_BIND 50000 /* 50 ms */
-	
-#ifndef PILOT_LINK_0_12
-	struct pi_sockaddr addr;
-	union {
-		struct pi_sockaddr *pi_sockaddrp;
-		struct sockaddr *sockaddrp;
-	} addrp;
-#endif
-	int sd, listen_sd, pf;
-	int ret;
-
-	int time_elapsed_pi_bind = 0;
-	
-	if (device->type != PILOT_DEVICE_NETWORK &&
-	    device->type != PILOT_DEVICE_BLUETOOTH) {
-		pilot_set_baud_rate (device);
-	}
-	
-	switch (device->type) {
-	case PILOT_DEVICE_SERIAL:
-		pf = PI_PF_PADP;
-		break;
-	case PILOT_DEVICE_USB_VISOR:
-		pf = PI_PF_NET;
-		break;
-	case PILOT_DEVICE_IRDA:
-		pf = PI_PF_PADP;
-		break;
-	case PILOT_DEVICE_NETWORK:
-	case PILOT_DEVICE_BLUETOOTH:
-		pf = PI_PF_NET;
-		break;
-	default:
-		pf = PI_PF_DLP;
-		break;
-	}
-	
-	if (device->type == PILOT_DEVICE_NETWORK ||
-	    device->type == PILOT_DEVICE_BLUETOOTH) {
-		/* In the case of network pi_sockets, the socket is already
-		 * listening at this point, so move on to accept */
-		listen_sd = device->fd;
-	} else {
-#ifdef PILOT_LINK_0_12
-		/* pl 0.12.0 wants to autodetect the protocol, so pass DLP */
-		/* (at time of writing there's a buglet in pl where if you
-		 * _do_ pass in the correct NET protocol then pl will flush
-		 * pending net input, which might just lose your first
-		 * packet.
-		 */
-		listen_sd = pi_socket (PI_AF_PILOT, PI_SOCK_STREAM, PI_PF_DLP);
-#else
-		listen_sd = pi_socket (PI_AF_PILOT, PI_SOCK_STREAM, pf);
-#endif
-		if (listen_sd < 0) {
-			g_warning ("pi_socket returned error %d (%s)",
-			    listen_sd,
-			    strerror (errno));
-			if (error) *error = 1;
-			return -1;
-		}
-
-		
-		/* 
-		 * When using HAL and USB, the ttyUSB[01] device files are
-		 * not created until after Hal has notified gpilotd that
-		 * a file exists. This causes pi_bind to fail.
-		 * To prevent a failure (and therefore sync), retry pi_bind
-		 * for up to the time allotted, sleeping a little in-between
-		 * tries.
-		 */
-		
-		time_elapsed_pi_bind = 0;
-		do {
-#ifdef PILOT_LINK_0_12
-			ret = pi_bind (listen_sd, device->port);
-#else
-			addr.pi_family = PI_AF_PILOT;
-			strcpy (addr.pi_device,device->port);
-			addrp.pi_sockaddrp = &addr;
-			ret = pi_bind (listen_sd, addrp.sockaddrp,
-			    sizeof (addr));	
-#endif
-			if(ret < 0) {
-				usleep(SLEEP_TIME_FOR_PI_BIND);
-				time_elapsed_pi_bind += SLEEP_TIME_FOR_PI_BIND;
-			}
-		} while(ret<0 && time_elapsed_pi_bind < MAX_TIME_FOR_PI_BIND);
-		
-		if (ret < 0) {
-			g_warning (_("Unable to bind to PDA"));
-			if (error)
-				*error = 1;
-			pi_close(listen_sd);
-#ifdef PILOT_LINK_0_12
-			check_usb_config(device);
-#endif
-			return 0;
-		}
-
-		ret = pi_listen (listen_sd, 1);
-		if (ret != 0) {
-			g_warning ("pi_listen: %s", strerror (errno));
-			if (error)
-				*error = 2;
-			pi_close(listen_sd);
-			return 0;
-		}
-	}
-
-	sd = pi_accept_to (listen_sd, NULL, NULL, device->timeout); 
-	if (sd < 0) {
-		g_warning ("pi_accept_to returned %d: %s", sd, strerror (errno));
-		g_warning ("pi_accept_to: timeout was %d secs", device->timeout);
-		if (error)
-			*error = 2;
-		if (device->type != PILOT_DEVICE_NETWORK &&
-		    device->type != PILOT_DEVICE_BLUETOOTH) {
-			pi_close(listen_sd);
-		}
-		return 0;
-	}
-
-	if (error)
-		*error = 0;
-
-	/* since pilot-link 0.12.0preX, the listen_sd represents
-	 * the accepted connection, so don't close listen_sd
-	 * after the accept */
-#ifndef PILOT_LINK_0_12
-	if (device->type != PILOT_DEVICE_NETWORK &&
-	    device->type != PILOT_DEVICE_BLUETOOTH) {
-		pi_close(listen_sd);
-	}		
-#endif
-	return sd;
-}
-
-static void
-pilot_disconnect (int sd)
-{
-	int ret; 
-
-	dlp_EndOfSync (sd, 0);
-	ret = pi_close (sd);
-	if (ret < 0) {
-		g_warning ("error %d from pi_close.", ret);
-	}
-
-}
-
-static void
-write_sync_stamp (GPilotPilot *pilot, int pfd, struct PilotUser *pu,
-		  guint32 last_sync_pc, time_t t)
-{
-	GKeyFile *kfile;
-	gchar    *iPilot;
-	
-	pu->lastSyncPC = last_sync_pc;
-	pu->lastSyncDate = t;
-	
-	kfile = get_gpilotd_kfile ();
-	iPilot = g_strdup_printf ("Pilot%d", pilot->number);
-	g_key_file_set_integer (kfile, iPilot, "sync_date", t);
-	
-	save_gpilotd_kfile (kfile);
-	g_key_file_free (kfile);
-	g_free (iPilot);
-
-	dlp_WriteUserInfo (pfd, pu);
-}
-
-/** pilot lookup methods **/
-
-static gint
-match_pilot_and_majick (const GPilotPilot *pilot,
-			unsigned long creation,
-			unsigned long romversion)
-{
-	if (pilot->creation == creation &&
-	    pilot->romversion == romversion) {
-		g_message ("pilot %s %ld %ld matches %ld %ld", 
-			   pilot->name, 
-			   pilot->creation,
-			   pilot->romversion, 
-			   creation, 
-			   romversion);
-		return 1;
-	}
-	g_message ("pilot %s %ld %ld doesn't match %ld %ld", 
-		   pilot->name, 
-		   pilot->creation,
-		   pilot->romversion, 
-		   creation, 
-		   romversion);
-	return 0;
-}
-
-
-#ifdef PILOT_LINK_0_12
-/* Checks whether visor module is loaded but 'usb:' device is selected,
- * or vice versa.  Returns 0 if the config looks okay, or -1 otherwise.
- * raises a gpilot_gui_warning_dialog and a g_warning if the config
- * looks incorrect.
- */
-static int
-check_usb_config(GPilotDevice *device) {
-#define MAXLINELEN 256
-	char line[MAXLINELEN];
-	gboolean visor_loaded;
-	gboolean libusb_device;
-	FILE *f;
-	int error = 0;
-
-	if (device->type != PILOT_DEVICE_USB_VISOR)
-		return 0;
-	visor_loaded = FALSE;
-	libusb_device = TRUE; /* defaults, in case we skip block */
-	f = fopen ("/proc/modules", "r");
-	if (f) {
-		while(fgets(line, MAXLINELEN, f) != NULL) {
-			if (strncmp(line, "visor", 5) == 0) {
-				visor_loaded = TRUE;
-				break;
-			}
-		}
-		fclose(f);
-		libusb_device = (strncmp(device->port,
-					 "usb:", 4) == 0);
-	}
-	if (libusb_device && visor_loaded) {
-		g_snprintf(line, MAXLINELEN,_("Failed to connect using "
-					      "device `%s', on port `%s'.  "
-					      "Check your configuration, "
-					      "as you requested "
-					      "new-style libusb `usb:' "
-					      "syncing, but have the "
-					      "old-style `visor' kernel "
-					      "module loaded.  "
-					      "You may need to select a "
-					      "`ttyUSB...' device."),
-			   device->name, device->port);
-		g_warning("%s", line);
-		gpilot_gui_warning_dialog(line);
-		error = 1;
-	} else if (!libusb_device && !visor_loaded) {
-		g_snprintf(line, MAXLINELEN,_("Failed to connect using "
-					      "device `%s', on port `%s'.  "
-					      "Check your configuration, "
-					      "as you requested "
-					      "old-style usbserial `ttyUSB' "
-					      "syncing, but do not have the "
-					      "usbserial `visor' kernel "
-					      "module loaded.  "
-					      "You may need to select a "
-					      "`usb:' device."),
-			   device->name, device->port);
-		g_warning("%s", line);
-		gpilot_gui_warning_dialog(line);
-		error = 1;
-	}
-	return error;
-}
-#endif /* PILOT_LINK_0_12 */
-
-
-/**************************/
-
-/*
- * We get a pfd, a device and the context (called if a pilot
- * with id == 0 synchronizes)
- * Get whatever majick number we can get and try to id 
- * the pilot and offer to restore it. If it can id the
- * pilot, ask the user to choose one or "make a new pilot"
- */
-
-static gboolean
-gpilot_attempt_restore (struct PilotUser pu,
-			int pfd, 
-			GPilotDevice *device, 
-			GPilotContext *context)
-{
-	struct SysInfo sysinfo;
-	struct CardInfo cardinfo;
-	GPilotPilot *pilot = NULL;
-	GList *iterator;
-	gboolean result = FALSE;
-	
-	dlp_ReadStorageInfo (pfd, 0, &cardinfo);
-	dlp_ReadSysInfo (pfd, &sysinfo);
-
-	if (context->pilots && context->pilots->next == NULL) {
-		pilot = GPILOT_PILOT (g_list_nth (context->pilots, 0)->data);
-		g_message ("D: Only one PDA (%s) profile...", pilot->name);
-	} else {
-		for (iterator = context->pilots; iterator; iterator = g_list_next (iterator)) {
-			pilot = GPILOT_PILOT (iterator->data);
-			if (match_pilot_and_majick (pilot, 
-						    cardinfo.creation,
-						    sysinfo.romVersion)) {
-				break;
-			}
-		}
-	}
-
-	if (pilot) {
-		GPilotPilot *a_pilot;
-		a_pilot = gpilot_gui_restore (context, pilot);
-		if (a_pilot) {
-			orbed_notify_connect (pilot->name,pu);				
-			result = gpilot_start_unknown_restore (pfd, device, a_pilot);
-			orbed_notify_disconnect (pilot->name);
-		}
-	} else {
-		/* MUST GO */
-		gpilot_gui_warning_dialog ("no ident\n"
-					   "restoring PDA with ident\n"
-					   "c/r = %lu/%lu, exciting things\n"
-					   "will soon be here...",
-					   cardinfo.creation,
-					   sysinfo.romVersion);
-	}
-
-	return TRUE;
-}
-
-/*
- * This function handles when sync_device (...) encounters an unknown pilot
- */
-
-static void
-gpilot_syncing_unknown_pilot (struct PilotUser pu, 
-			      int pfd,
-			      GPilotDevice *device, 
-			      GPilotContext *context)
-{
-
-	g_warning (_("Unknown PDA, no userID/username match %ld"),pu.userID);
-	/* FIXME: here, restoring one of the available pilots should be
-	   offered to the user. Of course with password prompt if the user
-	   has password set
-	   bug # 8217 */
-	if (pu.userID == 0) {
-		if (gpilot_attempt_restore (pu, pfd, device, context) == FALSE) {
-			gpilot_gui_warning_dialog (_("Use gnomecc to configure PDA"));
-		}
-	} else {
-		/* FIXME: here we should offer to create a profile for the pilot,
-		   bug # 8218 */
-		gpilot_gui_warning_dialog (_("Unknown PDA - no PDA matches ID %ld\n"
-					     "Use gnomecc to configure gnome-pilot"),pu.userID);
-	}
-}
-
-/*
- * If there are events for the cradle, this executes them,
- * closes the connection and returns.
- * Returns TRUE if connection should be closed afterwards, FALSE
- * is sync should continue
- */
-static gboolean 
-do_cradle_events (int pfd,
-		 GPilotContext *context,
-		 struct PilotUser *pu,
-		 GPilotDevice *device) 
-{
-	GList *events, *it;
-	gboolean ret = TRUE;
-	
-	/* elements in events freed by gpc_request_purge calls
-	   in orbed_notify_completion */
-	events = gpc_queue_load_requests_for_cradle (device->name);
-	
-	g_message (_("Device %s has %d events"), device->name, g_list_length (events));
-	
-	/* if no events, return FALSE */
-	if (!events)
-		return FALSE;
-	
-	it = events;
-	
-	while (it) {
-		GPilotRequest *req;
-		req = it->data;
-		switch (req->type) {
-		case GREQ_SET_USERINFO:
-			g_message (_("Setting userinfo..."));
-			g_snprintf (pu->username,127,"%s", req->parameters.set_userinfo.user_id);
-			pu->userID = req->parameters.set_userinfo.pilot_id;
-			dlp_WriteUserInfo (pfd,pu);
-			if (req->parameters.set_userinfo.continue_sync) {
-				g_message (_("Sync continues"));
-				ret = FALSE;
-			}
-			orbed_notify_completion (&req);
-			break;
-		case GREQ_GET_SYSINFO: {
-			struct SysInfo sysinfo;
-			struct CardInfo cardinfo;
-
-			dlp_ReadStorageInfo (pfd, 0, &cardinfo);
-			dlp_ReadSysInfo (pfd, &sysinfo);
-			orbed_notify_sysinfo (device->name,
-					      sysinfo,
-					      cardinfo, 
-					      &req);
-			orbed_notify_completion (&req);
-		}
-		break;
-		case GREQ_GET_USERINFO:
-			g_message (_("Getting userinfo..."));
-			orbed_notify_userinfo (*pu,&req);
-			orbed_notify_completion (&req);
-			break;
-		case GREQ_NEW_USERINFO:
-			/* FIXME: this is to set the new and return the old (or something) 
-			   g_message ("getting & setting userinfo");
-			   g_snprintf (pu->username,127,"%s",req->parameters.set_userinfo.user_id);
-			   pu->userID = req->parameters.set_userinfo.pilot_id;
-			   dlp_WriteUserInfo (pfd,pu);
-			   orbed_notify_completion (&req);
-			*/
-			break;
-		default:
-			g_warning ("%s:%d: *** type = %d",__FILE__,__LINE__,req->type);
-			g_assert_not_reached ();
-			break;
-		}
-
-		it = g_list_next (it);
-	}
-
-	return ret;
-}
-/**************************/
-
-/*
-  This executes a sync for a pilot.
-
-  If first does some printing to the stdout and some logging to the
-  pilot, so the dudes can see what is going on. Afterwards, it does
-  the initial synchronization operations (which is handling file
-  installs, restores, specific conduits runs). This function (in
-  manager.c) returns a boolean, whic may abort the entire
-  synchronization.
-
-  If it does not, a function in manager.c will be called depending of
-  the default_sync_action setting for the pilot (you know, synchronize
-  vs copy to/from blablabla).
-
- */
-static void 
-do_sync (int pfd,   
-	GPilotContext *context,
-	struct PilotUser *pu,
-	GPilotPilot *pilot, 
-	GPilotDevice *device)
-{
-	GList *conduit_list, *backup_conduit_list, *file_conduit_list;
-	GnomePilotSyncStamp stamp;
-	char *pilot_name;
-
-	pilot_name = pilot_name_from_id (pu->userID,context);
-
-	gpilot_load_conduits (context,
-			     pilot,
-			     &conduit_list, 
-			     &backup_conduit_list,
-			     &file_conduit_list);
-	stamp.sync_PC_Id=context->sync_PC_Id;
-
-	if (device->type == PILOT_DEVICE_NETWORK) {
-		g_message (_("NetSync request detected, synchronizing PDA"));
-	} else if (device->type == PILOT_DEVICE_BLUETOOTH) {
-		g_message (_("Bluetooth request detected, synchronizing PDA"));
-	} else {
-		g_message (_("HotSync button pressed, synchronizing PDA"));
-	}
-	g_message (_("PDA ID is %ld, name is %s, owner is %s"),
-		  pu->userID,
-		  pilot->name,
-		  pu->username);
-  
-	/* Set a log entry in the pilot */
-	{
-		char hostname[64];
-		gpilot_add_log_entry (pfd,"gnome-pilot v.%s\n",VERSION);
-		if (gethostname (hostname,63)==0)
-			gpilot_add_log_entry (pfd,_("On host %s\n"),hostname);
-		else
-			gpilot_add_log_entry (pfd,_("On host %d\n"),stamp.sync_PC_Id);
-	}
-
-	/* first, run the initial operations, such as single conduit runs,
-	   restores etc. If this returns True, continue with normal conduit running,
-	   if False, don't proceed */
-	if (gpilot_initial_synchronize_operations (pfd,
-						   &stamp,
-						   pu,
-						   conduit_list,
-						   backup_conduit_list,
-						   file_conduit_list,
-						   device,
-						   context)) {
-		gpilot_sync_default (pfd,&stamp,pu,
-				     conduit_list,
-				     backup_conduit_list,
-				     file_conduit_list,
-				     context);
-		g_message (_("Synchronization ended")); 
-		gpilot_add_log_entry (pfd,"Synchronization completed");
-	} else {
-		g_message (_("Synchronization ended early"));
-		gpilot_add_log_entry (pfd,"Synchronization terminated");
-	}
-
-	write_sync_stamp (pilot,pfd,pu,stamp.sync_PC_Id,time (NULL));
-  
-	g_free (pilot_name);
-
-	gpilot_unload_conduits (conduit_list);
-	gpilot_unload_conduits (backup_conduit_list);
-	gpilot_unload_conduits (file_conduit_list);
-}
-
-/*
- * This function handles when sync_device (...) encounters a known pilot
- */
-
-static void
-gpilot_syncing_known_pilot (GPilotPilot *pilot,
-			    struct PilotUser pu,
-			    int pfd,
-			    GPilotDevice *device,
-			    GPilotContext *context)
-{
-	struct stat buf; 
-	int ret;
-
-#ifdef PILOT_LINK_0_12
-	iconv_t ic;
-
-	if (pilot->pilot_charset == NULL ||
-	    pilot->pilot_charset == '\0') {
-		g_warning (_("No pilot_charset specified.  Using `%s'."),
-		    GPILOT_DEFAULT_CHARSET);
-		if (pilot->pilot_charset != NULL)
-			g_free(pilot->pilot_charset);
-		pilot->pilot_charset =
-		    g_strdup(GPILOT_DEFAULT_CHARSET);
-	}
-
-
-	/* ensure configured pilot_charset is recognised
-	 * by iconv, and override with warning if not.
-	 */
-	ic = iconv_open(pilot->pilot_charset, "UTF8");
-	if (ic == ((iconv_t)-1)) {
-		g_warning (_("`%s' is not a recognised iconv charset, "
-			       "using `%s' instead."),
-		    pilot->pilot_charset,
-		    GPILOT_DEFAULT_CHARSET);
-		g_free (pilot->pilot_charset);
-		pilot->pilot_charset =
-		    g_strdup(GPILOT_DEFAULT_CHARSET);
-	} else {
-		iconv_close(ic);
-	}
-	/* Set the environment variable PILOT_CHARSET,
-	 * to support legacy conduits that don't use
-	 * pilot_charset
-	 */
-	setenv("PILOT_CHARSET",
-	    pilot->pilot_charset, 1);
-#endif
-
-	ret = stat (pilot->sync_options.basedir, &buf); 
-
-	if (ret < 0 || !( S_ISDIR (buf.st_mode) && (buf.st_mode & (S_IRUSR | S_IWUSR |S_IXUSR))) ) {
-		
-		g_message ("Invalid basedir: %s", pilot->sync_options.basedir);
-		gpilot_gui_warning_dialog (_("The base directory %s is invalid.\n"
-					     "Please fix it or use gnomecc to choose another directory."),
-					   pilot->sync_options.basedir);	
-	} else {
-		gboolean pwd_ok = TRUE;
-		/* If pilot has password, check against the encrypted version
-		   on the pilot */
-		if (pilot->passwd) {
-			char *pwd;
-			
-			pwd = g_strndup (pu.password, pu.passwordLength);
-			if (g_ascii_strcasecmp (pilot->passwd, crypt (pwd, pilot->passwd)) != 0) {
-				pwd_ok = FALSE;
-				gpilot_gui_warning_dialog (_("Unknown PDA - no PDA matches ID %ld\n"
-							     "Use gpilotd-control-applet to set PDA's ID"), pu.userID);
-			}
-			g_free (pwd);
-		}
-		
-		if (pwd_ok) {
-			do_sync (pfd, context, &pu, pilot, device);
-		}
-	}
-}
-
-/*
-  sync_foreach is the first synchronization entry.
-
-  It first connects to the device on which the signal was detected,
-  then it tries to read the user info block from the pilot.
-
-  Hereafter, if there are any events queued for the synchronizing
-  cradle, execute them and stop the synchronization (note,
-  do_cradle_events returns a bool, if this is FALSE, synchronization
-  continues, as some cradle specific events also require a normal sync
-  afterwards, eg. the REVIVE call)
-
-  Anyways, if the sync continues, sync_foreach tries to match the
-  pilot against the known pilots. If this fails, it should handle it
-  intelligently, eg. if the id==0, ask if you want to restore a pilot.
-
-  If the pilot is accepted (dude, there's even a password check!), it
-  continues into do_sync, which does all the magic stuff.
-*/
-   
-static gboolean 
-sync_device (GPilotDevice *device, GPilotContext *context)
-{
-	GPilotPilot *pilot;
-	int connect_error;
-	struct PilotUser pu;
-	struct SysInfo ps;
-	int pfd;
-	
-	g_assert (context != NULL);
-	g_return_val_if_fail (device != NULL, FALSE);
-
-	/* signal (SIGHUP,SIG_DFL); */
-	pfd = pilot_connect (device,&connect_error);
-
-	if (!connect_error) {
-               /* connect succeeded, try to read the systeminfo */
-               if (dlp_ReadSysInfo (pfd, &ps) < 0) {
-                       /* no ? drop connection then */
-                       g_warning (_("An error occurred while getting the PDA's system data"));
-#ifdef PILOT_LINK_0_12
-		       check_usb_config(device);
-#endif
-
-
-		/* connect succeeded, try to read the userinfo */
-		} else if (dlp_ReadUserInfo (pfd,&pu) < 0) {
-			/* no ? drop connection then */
-			g_warning (_("An error occurred while getting the PDA's user data"));
-		} else {
-	
-			/* If there are cradle specific events, handle them and stop */
-			if (do_cradle_events (pfd,context,&pu,device)) {
-				g_message (_("Completed events for device %s (%s)"),device->name,device->port);
-			} else {
-				/* No cradle events, validate pilot */
-				pilot = gpilot_find_pilot_by_id (pu.userID,context->pilots);
-
-				if (pilot == NULL) {
-					/* Pilot is not known */
-					gpilot_syncing_unknown_pilot (pu, pfd, device, context);
-				} else {
-					/* Pilot is known, make connect notifications */
-					orbed_notify_connect (pilot->name,pu);				
-					gpilot_syncing_known_pilot (pilot, pu, pfd, device, context);
-					orbed_notify_disconnect (pilot->name);
-				}				
-			}
-		}
-		pilot_disconnect (pfd);
-		/* now restart the listener.  fairly brute force
-		 * approach, but ensures we re-initialise the listening
-		 * socket correctly.  */
-		if (device->type == PILOT_DEVICE_NETWORK ||
-		    device->type == PILOT_DEVICE_BLUETOOTH) {
-			reread_config = TRUE;
-		}
-	} else {
-		if (connect_error==1) return FALSE; /* remove this device */
-		else {
-			if (device->type == PILOT_DEVICE_NETWORK ||
-			    device->type == PILOT_DEVICE_BLUETOOTH) {
-				/* fix broken pisock sockets */
-				reread_config = TRUE;
-			}
-			return TRUE;
-		}
-	}
-
-	return TRUE;
-}
-
-static gboolean 
-device_in (GIOChannel *io_channel, GIOCondition condition, GPilotContext *context)
-{
-	GPilotDevice *device;
-	GList *element;
-	gboolean result = TRUE;
-	
-	g_assert (context != NULL);
-	
-	element = g_list_find_custom (context->devices,
-				     io_channel,
-				     (GCompareFunc)device_equal_by_io);
-	
-	if (element == NULL || element->data == NULL) {
-		g_warning ("cannot find device for active IO channel");
-		return FALSE;
-	}
-	
-	device = element->data; 
-	if (context->paused) {
-		return FALSE; 
-	}	
-	g_message (_("Woke on %s"), device->name);
-	result = sync_device (device, context);
-	
-#ifdef WITH_IRDA
-	if (device->type == PILOT_DEVICE_IRDA) {
-		g_message ("Restarting irda funk...");
-		gpilot_device_deinit (device);
-		gpilot_device_init (device);
-		monitor_channel (device, context);
-		result = FALSE;
-	}
-#endif /* WITH_IRDA */
-	
-	return result;
-}
-
-static gboolean 
-device_err (GIOChannel *io_channel, GIOCondition condition, GPilotContext *context)
-{
-	GPilotDevice *device;
-	GList *element;
-	char *tmp;
-	
-	g_assert (context != NULL);
-	
-	switch (condition) {
-	case G_IO_IN: tmp = g_strdup_printf ("G_IO_IN"); break;
-	case G_IO_OUT : tmp = g_strdup_printf ("G_IO_OUT"); break;
-	case G_IO_PRI : tmp = g_strdup_printf ("G_IO_PRI"); break;
-	case G_IO_ERR : tmp = g_strdup_printf ("G_IO_ERR"); break;
-	case G_IO_HUP : tmp = g_strdup_printf ("G_IO_HUP"); break;
-	case G_IO_NVAL: tmp = g_strdup_printf ("G_IO_NVAL"); break;
-	default: tmp = g_strdup_printf ("unhandled port error"); break;
-	}
-	
-	element = g_list_find_custom (context->devices,io_channel,(GCompareFunc)device_equal_by_io);
-	
-	if (element == NULL) {
-		/* We most likely end here if the device has just been removed.
-		   Eg. start gpilotd with a monitor on a XCopilot fake serial port,
-		   kill xcopilot and watch things blow up as the device fails */
-		g_warning ("Device error on some device, caught %s",tmp); 
-		g_free (tmp);
-		return FALSE;
-	}
-	
-	device = element->data;
-	
-	gpilot_gui_warning_dialog ("Device error on %s (%s)\n"
-				  "Caught %s", device->name, device->port, tmp); 
-	g_warning ("Device error on %s (%s), caught %s", device->name, device->port, tmp);
-	
-	remove_device (context, device);
-	g_free (tmp);
-	
-	return FALSE;
-}
-
-#ifdef WITH_NETWORK
-static gboolean 
-network_device_in (GIOChannel *io_channel, GIOCondition condition, GPilotContext *context)
-{
-	GPilotDevice *device;
-	GList *element;
-	gboolean result = TRUE;
-
-	g_assert (context != NULL);
-      
-	element = g_list_find_custom (context->devices,
-				     io_channel,
-				     (GCompareFunc)device_equal_by_io);
-
-	if (element==NULL || element->data == NULL) {
-		g_warning ("cannot find device for active IO channel");
-		return FALSE;
-	}
-	
-	device = element->data; 
-	if (context->paused) {
-		return FALSE; 
-	}	
-	g_message (_("Woke on network: %s"),device->name);
-	result = sync_device (device,context);
-
-	return result;
-}
-
-static gboolean 
-network_device_err (GIOChannel *io_channel, GIOCondition condition, GPilotContext *context)
-{
-	GPilotDevice *device;
-	GList *element;
-	char *tmp;
-	
-	g_assert (context != NULL);
-	
-	switch (condition) {
-		case G_IO_IN: tmp = g_strdup_printf ("G_IO_IN"); break;
-		case G_IO_OUT : tmp = g_strdup_printf ("G_IO_OUT"); break;
-		case G_IO_PRI : tmp = g_strdup_printf ("G_IO_PRI"); break;
-		case G_IO_ERR : tmp = g_strdup_printf ("G_IO_ERR"); break;
-		case G_IO_HUP : tmp = g_strdup_printf ("G_IO_HUP"); break;
-		case G_IO_NVAL: tmp = g_strdup_printf ("G_IO_NVAL"); break;
-		default: tmp = g_strdup_printf ("unhandled port error"); break;
-	}
-	
-	element = g_list_find_custom (context->devices,io_channel,(GCompareFunc)device_equal_by_io);
-	
-	if (element == NULL) {
-		/* We most likely end here if the device has just been removed.
-		   Eg. start gpilotd with a monitor on a XCopilot fake serial port,
-		   kill xcopilot and watch things blow up as the device fails */
-		g_warning ("Device error on some device, caught %s",tmp); 
-		g_free (tmp);
-		return FALSE;
-	}
-	
-	device = element->data;
-
-	gpilot_gui_warning_dialog ("Device error on %s, caught %s",
-	    device->name, tmp);
-	g_warning ("Device error on %s, caught %s",device->name, tmp);
-
-	remove_device (context, device);
-	g_free (tmp);
-	
-	return FALSE;
-}
-#endif /* WITH_NETWORK */
-
-static GPtrArray *vendor_product_ids = NULL;
-static GArray *product_net = NULL;
-
-static int
-known_usb_device(gchar *match_str)
-{
-	int i;
-	for (i = 0; i < vendor_product_ids->len; i++) {
-		if (!g_strncasecmp (match_str, 
-			vendor_product_ids->pdata[i], 
-			strlen (vendor_product_ids->pdata[i])))
-			return i;
-	}
-	return -1;
-}
-
-static void
-load_devices_xml (void) 
-{
-	xmlDoc *doc = NULL;
-	xmlNode *root, *node;
-	char *filename;
-
-	if (vendor_product_ids)
-		return;
-	
-	vendor_product_ids = g_ptr_array_new ();
-	product_net = g_array_new (FALSE, FALSE, sizeof (gboolean));
-
-	filename = g_build_filename (DEVICE_XML_DIR, "devices.xml", NULL);
-	doc = xmlParseFile (filename);
-	g_free (filename);
-		
-	if (!doc) {
-		g_warning ("Unable to read device file at %s", filename);
-		
-		return;
-	}
-
-	root = xmlDocGetRootElement (doc);
-	if (!root->name || strcmp ((char *) root->name, "device-list"))
-		goto fail;
-	
-	for (node = root->children; node; node = node->next) {
-		xmlChar *vendor, *product, *net;
-		gboolean use_net;
-		
-		if (node->type != XML_ELEMENT_NODE)
-			continue;
-
-		if (!node->name || strcmp ((char *) node->name, "device")) {
-			g_warning ("Invalid sub node %s", node->name != NULL ? (char *) node->name : "");
-
-			continue;
-		}
-		
-		vendor = xmlGetProp (node, (xmlChar *) "vendor_id");
-		product = xmlGetProp (node, (xmlChar *) "product_id");
-
-		if (!vendor || !product) {
-			g_warning ("No vendor or product id");
-
-			continue;
-		}
-		
-		g_message ("Found %s, %s", vendor, product);
-		g_ptr_array_add (vendor_product_ids, g_strdup_printf ("Vendor=%s ProdID=%s", vendor, product));
-
-		xmlFree (vendor);
-		xmlFree (product);
-		
-		net = xmlGetProp (node, (xmlChar *) "use_net");
-		use_net = !net || strcmp ((char *) net, "false");
-		
-		g_message ("Using net %s", use_net ? "TRUE" : "FALSE");
-		g_array_append_val (product_net, use_net);
-
-		xmlFree (net);
-	}
-
- fail:
-	xmlFreeDoc (doc);
-}
-
-#ifdef WITH_HAL
-static void
-hal_device_added (LibHalContext *ctx, const char *udi)
-{
-	gboolean visor_net = FALSE;
-	char *bus, *platform, *match_str;
-	int vendor_id, product_id, i;
-	GPilotDevice *device;
-	DBusError error;
-	GList *dev;
-
-	if (context->paused) 
-		return;
-
-	load_devices_xml ();
-
-	/* HAL match rule: we look for pda.platform == 'palm'
-	 * (or the legacy info.bus == 'usb_device')
-	 * and then try to match the usb_device.product_id and usb_device.vendor_id
-	 * against the list in devices.xml.
-	 */
-	if ((platform = libhal_device_get_property_string (hal_ctx, udi, "pda.platform", NULL))) {
-	    if (strcmp (platform, "palm") != 0) {
-		libhal_free_string (platform);
-		return;
-	    }
-	    libhal_free_string (platform);
-	} else if ((bus = libhal_device_get_property_string (hal_ctx, udi, "info.bus", NULL))) {
-	    if (strcmp (bus, "usb_device") != 0) {
-		libhal_free_string (bus);
-		return;
-	    }
-	    libhal_free_string (bus);
-	} else {
-	    return;
-	}
-
-	dbus_error_init (&error);
-	vendor_id = libhal_device_get_property_int (hal_ctx, udi,
-	    "usb_device.vendor_id", &error);
-	if(vendor_id == -1) {
-		g_warning ("Could not get usb vendor ID from hal: %s", error.message);
-		return;
-	}
-	product_id = libhal_device_get_property_int (hal_ctx, udi,
-	    "usb_device.product_id", NULL);
-	if(product_id == -1) {
-		g_warning ("Could not get usb product ID from hal: %s", error.message);
-		return;
-	}
-	
-	/* now look for a vendor/product match */
-	match_str = g_strdup_printf ("Vendor=%04x ProdID=%04x",
-	    vendor_id, product_id);
-	i = known_usb_device(match_str);
-	g_free(match_str);
-	if(i == -1)
-		return;
-
-	visor_net = g_array_index (product_net, gboolean, i);
-	dev = context->devices;
-	while (dev != NULL) {
-		device = dev->data;
-		if (device->type == PILOT_DEVICE_USB_VISOR) {
-			if (!visor_net)
-				device->type = PILOT_DEVICE_SERIAL;
-			/* problems have been reported with devices
- 			 * not being ready for sync immediately,
- 			 * so we wait for 0.4 seconds.  See
- 			 * bugzilla.gnome #362565
- 			 */
-			usleep(400000);
-			/* just try to sync.  Until I can talk to 
-			 * the kernel guys this is the best way to 
-			 * go. */
-			sync_device (device, context);
-
-			if (!visor_net)
-				device->type = PILOT_DEVICE_USB_VISOR;
-			
-			break;
-		}
-		
-		dev = dev->next;
-	}
-}
-
-static void
-hal_device_removed (LibHalContext *ctx, const char *udi)
-{
-	
-}
-
-static gboolean
-reinit_dbus (gpointer user_data)
-{
-	if (gpilotd_dbus_init ()) {
-		if ((hal_ctx = gpilotd_hal_init ()))
-			libhal_ctx_set_dbus_connection (hal_ctx, dbus_connection);
-		else
-			exit (1);
-		
-		return FALSE;
-	}
-	
-	return TRUE;
-}
-
-static DBusHandlerResult
-gpilotd_dbus_filter_function (DBusConnection *connection, DBusMessage *message, void *user_data)
-{
-	if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") &&
-	    strcmp (dbus_message_get_path (message), DBUS_PATH_LOCAL) == 0) {
-		libhal_ctx_free (hal_ctx);
-		hal_ctx = NULL;
-		
-		dbus_connection_unref (dbus_connection);
-		dbus_connection = NULL;
-		
-		g_timeout_add (3000, reinit_dbus, NULL);
-		
-		return DBUS_HANDLER_RESULT_HANDLED;
-	}
-	
-	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static gboolean
-gpilotd_dbus_init (void)
-{
-	DBusError error;
-	
-	if (dbus_connection != NULL)
-		return TRUE;
-	
-	dbus_error_init (&error);
-	if (!(dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
-		g_warning ("could not get system bus: %s", error.message);
-		dbus_error_free (&error);
-		return FALSE;
-	}
-	
-	dbus_connection_setup_with_g_main (dbus_connection, NULL);
-	dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
-	
-	dbus_connection_add_filter (dbus_connection, gpilotd_dbus_filter_function, NULL, NULL);
-	
-	return TRUE;
-}
-
-
-static LibHalContext *
-gpilotd_hal_init (void)
-{
-	LibHalContext *ctx;
-	DBusError error;
-	char **devices;
-	int nr;
-	
-	if (!gpilotd_dbus_init ()) {
-		g_warning ("failed to initialise DBUS!");
-		return NULL;
-	}
-
-	if (!(ctx = libhal_ctx_new ())) {
-		g_warning ("failed to create a HAL context!");
-		return NULL;
-	}
-	
-	libhal_ctx_set_dbus_connection (ctx, dbus_connection);
-	
-	libhal_ctx_set_device_added (ctx, hal_device_added);
-	libhal_ctx_set_device_removed (ctx, hal_device_removed);
-	/*libhal_ctx_set_device_new_capability (ctx, hal_device_new_capability);*/
-	/*libhal_ctx_set_device_lost_capability (ctx, hal_device_lost_capability);*/
-	/*libhal_ctx_set_device_property_modified (ctx, hal_property_modified);*/
-	/*libhal_ctx_set_device_condition (ctx, hal_device_condition);*/
-	
-	dbus_error_init (&error);
-	if (!libhal_device_property_watch_all (ctx, &error)) {
-		g_warning ("failed to watch all HAL properties!: %s", error.message);
-		dbus_error_free (&error);
-		libhal_ctx_free (ctx);
-		return NULL;
-	}
-	
-	if (!libhal_ctx_init (ctx, &error)) {
-		g_warning ("libhal_ctx_init failed: %s", error.message);
-		dbus_error_free (&error);
-		libhal_ctx_free (ctx);
-		return NULL;
-	}
-	
-	/*
-	 * Do something to ping the HAL daemon - the above functions will
-	 * succeed even if hald is not running, so long as DBUS is.  But we
-	 * want to exit silently if hald is not running, to behave on
-	 * pre-2.6 systems.
-	 */
-	if (!(devices = libhal_get_all_devices (ctx, &nr, &error))) {
-		g_warning ("seems that HAL is not running: %s", error.message);
-		dbus_error_free (&error);
-		
-		libhal_ctx_shutdown (ctx, NULL);
-		libhal_ctx_free (ctx);
-		return NULL;
-	}
-	
-	libhal_free_string_array (devices);
-	
-	return ctx;
-}
-#endif /* WITH_HAL */
-#ifdef WITH_USB_VISOR
-
-static gboolean 
-visor_devices_timeout (gpointer data) 
-{
-	GPilotContext *context = data;
-	GPilotDevice *device;
-	GList *l;
-	int i, use_sysfs;
-	static int devfs_warning = 0;
-	gboolean visor_exists = FALSE, visor_net = TRUE;
-	char *usbdevicesfile_str ="/proc/bus/usb/devices";
-	char line[256]; /* this is more than enough to fit any line from 
-			 * /proc/bus/usb/devices */
-	FILE *f;
-	gchar *fcontent;
-	gchar *fname;
-	gchar *vend_id; 
-	gchar *prod_id;
-	gchar *to_match;
-	GError *error = NULL;
-	regex_t regex_pattern;
-
-	GDir *topdir;
-	const gchar *entry;
-	gchar *sysfs_dir_name = "/sys/bus/usb/devices/";
-	gchar *f_vend = "idVendor";
-	gchar *f_prod = "idProduct";
-
-
-	g_assert (context != NULL);
-
-	if (context->paused) 
-		return FALSE;
-
-	load_devices_xml ();
-#ifdef linux
-	/* choose a method for searching for known USB devices:
-	 * If we can't find sysfs, second choice is
-	 * legacy /proc/bus/usb/devices.
-	 */
-	use_sysfs = 1; /* default */
-	topdir = g_dir_open (sysfs_dir_name, 0, &error);
-	if (!topdir) {
-		use_sysfs = 0;
-		f = fopen (usbdevicesfile_str, "r");
-		if (!f)
-			f = fopen ("/proc/bus/usb/devices_please-use-sysfs-instead", "r");
-		if (!f) {
-			if (!devfs_warning) {
-				devfs_warning = 1;
-				char *str = g_strdup_printf (
-				    _("Failed to find directory %s or read file %s.  "
-					"Check that usbfs or sysfs is mounted."),
-				    sysfs_dir_name,
-				    usbdevicesfile_str);
-				g_warning ("%s", str);
-				g_free (str);
-			}
-			return TRUE; /* can't proceed */
-		}
-		devfs_warning = 0;
-	}
-	if (use_sysfs) {
-		/* This regex allows 99 root-hubs and a bus-depth of 6 tiers for
-		 * each root-hub. Each hub can have 99 ports. Refer to "Bus
-		 * Topology" in the USB 2.0 specs and the sysfs structures of
-		 * Linux USB for further explanation */
-		regcomp (&regex_pattern,
-		    "^[[:digit:]]{1,2}[-][[:digit:]]{1,2}([.][[:digit:]]{1,2}){0,5}$",
-		    REG_EXTENDED | REG_NOSUB); 
-
-		entry = g_dir_read_name (topdir);
-		while ((entry != NULL) && (!visor_exists)) {
-			if (!regexec (&regex_pattern, entry, 0, 0, 0)){
-				fname = g_build_filename (sysfs_dir_name, entry,
-				    f_vend, NULL);
-				if (!g_file_get_contents (fname, &fcontent,
-					NULL, &error)){
-					g_warning ("%s", &*error->message);
-					regfree (&regex_pattern);
-					g_free (fname);
-					g_dir_close (topdir);
-					return TRUE;
-				}
-				vend_id = g_strndup (fcontent, 4);
-				g_free (fname);
-				g_free (fcontent);
-
-				fname = g_build_filename (sysfs_dir_name, entry,
-				    f_prod, NULL);
-				if (!g_file_get_contents (fname, &fcontent,
-					NULL, &error)){
-					g_warning ("%s", &*error->message);
-					regfree (&regex_pattern);
-					g_free (fname);
-					g_free (vend_id);
-					g_dir_close (topdir);
-					return TRUE;
-				}
-				prod_id = g_strndup (fcontent, 4);
-				g_free (fname);
-				g_free (fcontent);
-
-				to_match = g_strconcat ("Vendor=", vend_id,
-				    " ProdID=", prod_id, NULL);
-				i = known_usb_device(to_match);
-				if(i != -1) {
-					visor_exists = TRUE;
-					visor_net = g_array_index (
-					    product_net, gboolean, i);
-				}
-				g_free (vend_id);
-				g_free (prod_id);
-				g_free (to_match);
-			}
-			entry = g_dir_read_name (topdir);
-		}
-		g_dir_close (topdir);
-		regfree (&regex_pattern);
-	} else {
-		/* non sysfs branch... read /proc/bus/usb/devices */
-		while (fgets (line, 255, f) != NULL && !visor_exists) {
-			if (line[0] != 'P')
-				continue;
-			i = known_usb_device(line + 4); /* line + strlen("P:  ") */
-			if (i != -1) {
-				visor_exists = TRUE;
-				visor_net = g_array_index (
-				    product_net, gboolean, i);
-			}
-		}
-	
-		fclose (f);
-	}
-	
-#else
-#if defined(sun) && defined (__SVR4) /*for solaris */
-	/* On Solaris we always try to sync.  This isn't
-	 * a great solution, but does enable syncing.  We
-	 * should use HAL on Solaris when it is working
-	 * well.  See bug #385444.
-	 */
-       visor_exists = TRUE;
-#endif /* defined(sun) && defined (__SVR4) */
-#endif /* linux */
-	if (visor_exists) {
-		l = context->devices;
-		while (l) {
-			device = l->data;
-			if (device->type == PILOT_DEVICE_USB_VISOR) {
-				if (!visor_net)
-					device->type = PILOT_DEVICE_SERIAL;
-
-				/* just try to synch.  Until I can talk to 
-				 * the kernel guys this is the best way to 
-                                 * go. */
-				sync_device (device, context);
-				sleep(1);
-
-				if (!visor_net)
-					device->type = PILOT_DEVICE_USB_VISOR;
-				break; /* don't try to sync any more devices! */
-			}
-			l = l->next;
-		}
-	}
-
-	return TRUE;
-}
-
-#endif /* WITH_USB_VISOR */
-
-
-static void
-monitor_channel (GPilotDevice *dev, GPilotContext *context) 
-{
-	g_assert (context != NULL);
-	
-	if (dev->type == PILOT_DEVICE_SERIAL
-	    || dev->type == PILOT_DEVICE_IRDA) {
-		dev->in_handle = g_io_add_watch (dev->io,
-						G_IO_IN,
-						(GIOFunc)device_in,
-						(gpointer)context);
-		dev->err_handle = g_io_add_watch (dev->io,
-						 G_IO_ERR|G_IO_PRI|G_IO_HUP|G_IO_NVAL,
-						 (GIOFunc)device_err,
-						 (gpointer)context);
-	} else if (dev->type == PILOT_DEVICE_NETWORK ||
-	    dev->type == PILOT_DEVICE_BLUETOOTH) {
-#ifdef WITH_NETWORK
-		dev->in_handle = g_io_add_watch (dev->io,
-						G_IO_IN,
-						(GIOFunc)network_device_in,
-						(gpointer)context);
-		dev->err_handle = g_io_add_watch (dev->io,
-						 G_IO_ERR|G_IO_PRI|G_IO_HUP|G_IO_NVAL,
-						 (GIOFunc)network_device_err,
-						 (gpointer)context);
-#else /* WITH_NETWORK */
-		g_assert_not_reached ();
-#endif /* WITH_NETWORK */
-	} if (dev->type == PILOT_DEVICE_USB_VISOR) {
-		if(hal_initialised) {
-			/* handled by hal callbacks */
-			dev->device_exists = FALSE;
-		} else {
-#ifdef WITH_USB_VISOR
-#if defined(linux) || (defined(sun) && defined(__SVR4))
-			/* We want to watch for a new recognised USB device
-			 * once per context. */
-			if (visor_timeout_id == -1) {
-				visor_timeout_id = g_timeout_add (2000,
-				    visor_devices_timeout, context);
-			}
-#else /* linux or solaris */
-			g_assert_not_reached ();
-#endif /* linux or solaris */
-#endif /* WITH_USB_VISOR */
-		}
-	}
-
-	if (dev->type == PILOT_DEVICE_NETWORK) {
-		g_message (_("Watching %s (network)"), dev->name);
-	} else if (dev->type == PILOT_DEVICE_BLUETOOTH) {
-		g_message (_("Watching %s (bluetooth)"), dev->name);
-	} else {
-		g_message (_("Watching %s (%s)"), dev->name, dev->port);
-	}
-}
 
 static void 
 sig_hup_handler (int dummy)
 {
 	signal (SIGHUP, sig_hup_handler);
-	reread_config = TRUE;
 }
 
 static void 
@@ -1538,7 +53,6 @@ sig_term_handler (int dummy)
 {
 	g_message (_("Exiting (caught SIGTERM)..."));
 	remove_pid_file ();
-	gpilotd_corba_quit ();
 	exit (0);
 }
 
@@ -1547,7 +61,6 @@ sig_int_handler (int dummy)
 {
 	g_message (_("Exiting (caught SIGINT)..."));
 	remove_pid_file ();
-	gpilotd_corba_quit ();
 	exit (0);
 }
 
@@ -1607,38 +120,6 @@ write_pid_file (void)
 	close (fd);
 }
 
-/*  
-    The main loop. Sets up monitors for the devices and calls
-    g_main_context_iteration to wait for a sync. The monitor handler handles
-    the sync, so look in device_in for the call to the actual sync.
-
-    If reread_config gets set to TRUE (by a SIGHUP signal, free
-    all devices and context and reload it 
-*/
-
-static void 
-wait_for_sync_and_sync (void)
-{
-	signal (SIGTERM, sig_term_handler);
-	signal (SIGINT, sig_int_handler);
-	signal (SIGHUP, sig_hup_handler);
-	
-	g_list_foreach (context->devices, (GFunc)monitor_channel, context);
-	
-	while (1) {
-		if (reread_config) {
-			g_message (_("Shutting down devices"));
-			gpilot_context_free (context);
-			g_message (_("Rereading configuration..."));
-			gpilot_context_init_user (context);
-			reread_config=FALSE;
-			g_list_foreach (context->devices, (GFunc)monitor_channel, context);
-		}
-		/* Enter the gtk main loop */
-		g_main_context_iteration (NULL, TRUE);
-	}
-}
-
 /* This function display which pilot-link version was used
    and which features were enabled at compiletime */
 static void
@@ -1666,46 +147,129 @@ dump_build_info (void)
 	g_string_free (str, TRUE);
 }
 
+static DBusGConnection *
+get_session_bus (void)
+{
+        GError          *error;
+        DBusGConnection *bus;
+        DBusConnection  *connection;
+                        
+        error = NULL;
+        bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+        if (bus == NULL) {
+                g_warning ("Couldn't connect to system bus: %s",
+                           error->message);
+                g_error_free (error);
+                goto out;
+        }
+
+        connection = dbus_g_connection_get_connection (bus);
+        dbus_connection_set_exit_on_disconnect (connection, FALSE);
+
+ out:
+        return bus;
+}
+
+static gboolean
+dbus_acquire_name (DBusGConnection *connection)
+{
+        DBusGProxy *bus_proxy;
+        GError     *error;
+        guint       result;
+        gboolean    ret;
+
+        ret = FALSE;
+        bus_proxy = dbus_g_proxy_new_for_name (connection,
+                                               DBUS_SERVICE_DBUS,
+                                               DBUS_PATH_DBUS,
+                                               DBUS_INTERFACE_DBUS);
+        if (bus_proxy == NULL) {
+                goto out;
+        }
+
+        error = NULL;
+        if (!dbus_g_proxy_call (bus_proxy,
+                                "RequestName",
+                                &error,
+                                G_TYPE_STRING, GP_DBUS_NAME,
+                                G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
+                                G_TYPE_INVALID,
+                                G_TYPE_UINT, &result,
+                                G_TYPE_INVALID)) {
+                if (error != NULL) {
+                        g_warning ("Failed to acquire %s: %s", GP_DBUS_NAME, error->message);
+                        g_error_free (error);
+                } else {
+                        g_warning ("Failed to acquire %s", GP_DBUS_NAME);
+                }
+                goto out;
+        }
+
+        if (result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
+                g_warning (_("gpilotd already running; exiting ...\n"));
+                goto out;
+        }
+
+        ret = TRUE;
+
+ out:
+        return ret;
+}
+
 int 
 main (int argc, char *argv[])
 {
-	GnomeProgram *program;
+        GMainLoop       *loop;
+        GpilotDaemon    *daemon;
+        DBusGConnection *connection;
+        int              ret;
 
-	bindtextdomain (PACKAGE, GNOMELOCALEDIR);
-	textdomain (PACKAGE);
-	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-	
 	/*g_log_set_always_fatal (G_LOG_LEVEL_ERROR |
 				G_LOG_LEVEL_CRITICAL |
 				G_LOG_LEVEL_WARNING);*/
 	
+        ret = 1;
 	/* Intro */
-	g_message ("%s %s starting...",PACKAGE,VERSION);
+	g_message ("%s %s starting...", PACKAGE, VERSION);
 	dump_build_info ();
 	
-	/*	gtk_init(&argc, &argv);*/
-	program = gnome_program_init (PACKAGE, VERSION,
-	    LIBGNOME_MODULE, argc, argv, GNOME_PARAM_NONE);
-
-#ifdef WITH_HAL
-	if ((hal_ctx = gpilotd_hal_init ()) != NULL)
-		hal_initialised = 1; /* if 0, fall back to polling sysfs */
-#endif
-	
 	/* Setup the correct gpilotd.pid file */
 	remove_pid_file ();
 	write_pid_file ();
 	
-	/* Init corba and context, this call also loads the config into context */
 	g_type_init ();
-	gpilotd_corba_init (&argc, argv, &context);
-	
-	/* Begin... */
-	wait_for_sync_and_sync ();
+
+        connection = get_session_bus ();
+        if (connection == NULL) {
+                goto out;
+        }
+
+        daemon = gpilot_daemon_new ();
+        if (daemon == NULL) {
+                goto out;
+        }
+
+        if (! dbus_acquire_name (connection) ) {
+                g_warning ("Could not acquire name; bailing out");
+                goto out;
+        }
+
+        loop = g_main_loop_new (NULL, FALSE);
+
+	signal (SIGTERM, sig_term_handler);
+	signal (SIGINT, sig_int_handler);
+	signal (SIGHUP, sig_hup_handler);
 	
+        g_main_loop_run (loop);
+
+        if (daemon != NULL) {
+                g_object_unref (daemon);
+        }
+
 	/* It is unlikely that we will end here */
 	remove_pid_file ();
-	gpilotd_corba_quit ();
 	
-	return 0;
+	ret = 0;
+ out:
+        return ret;
 }
diff --git a/gpilotd/gpmarshal.list b/gpilotd/gpmarshal.list
index 97afc71..29c6e6c 100644
--- a/gpilotd/gpmarshal.list
+++ b/gpilotd/gpmarshal.list
@@ -5,3 +5,12 @@ INT:POINTER,BOOL
 INT:POINTER,INT,INT
 INT:POINTER
 INT:NONE
+VOID:STRING
+VOID:BOOLEAN
+VOID:STRING,UINT
+VOID:STRING,STRING
+VOID:STRING,UINT,STRING
+VOID:STRING,STRING,STRING
+VOID:STRING,STRING,UINT,UINT
+VOID:STRING,UINT,UINT
+VOID:STRING,UINT,UINT,UINT,STRING,STRING,UINT,UINT
diff --git a/gpilotd/manager.c b/gpilotd/manager.c
index 00a9997..60017c9 100644
--- a/gpilotd/manager.c
+++ b/gpilotd/manager.c
@@ -35,7 +35,7 @@
 
 #include <glib/gi18n.h>
 
-#include "orbit_daemon_glue.h"
+#include "gpilot-daemon.h"
 #include "manager.h"
 #include "queue_io.h"
 #include "gnome-pilot-conduit-backup.h"
@@ -163,7 +163,7 @@ find_matching_conduit_name (GList *conlist, gchar *name)
 
 /**************************************************************************/
 /* Here comes conduit signal handler, used to call methods from 
-   orbit_daemon_glue                                                      */
+   gpilot-daemon                                                      */
 
 typedef struct {
 	GnomePilotInstallCarrier *carrier;
@@ -176,7 +176,7 @@ gnome_pilot_conduit_backup_func (gchar *filename,
 				 gint db,
 				 gint total_dbs,
 				 GnomePilotBackupFuncCarrier *carrier) {
-	orbed_notify_overall_progress (carrier->pilot_name, db, total_dbs);
+	dbus_notify_overall_progress (carrier->pilot_name, db, total_dbs);
 	
 	g_message ("gnome_pilot_conduit_backup_func (%s)", filename);
 
@@ -191,7 +191,7 @@ conduit_progress_callback (GnomePilotConduit *conduit,
 			   gint total,
 			   gint current,
 			   gpointer pilot_id) {
-	orbed_notify_conduit_progress ((gchar*)pilot_id,
+	dbus_notify_conduit_progress ((gchar*)pilot_id,
 				       conduit,
 				       current,
 				       total);
@@ -201,7 +201,7 @@ static void
 conduit_message_callback (GnomePilotConduit *conduit, 
 			  gchar *message,
 			  gpointer pilot_id) {
-	orbed_notify_conduit_message ((gchar*)pilot_id,
+	dbus_notify_conduit_message ((gchar*)pilot_id,
 				      conduit,
 				      message);
 }
@@ -210,7 +210,7 @@ static void
 conduit_error_callback (GnomePilotConduit *conduit, 
 			gchar *message,
 			gpointer pilot_id) {
-	orbed_notify_conduit_error ((gchar*)pilot_id,
+	dbus_notify_conduit_error ((gchar*)pilot_id,
 				    conduit,
 				    message);
 }
@@ -303,7 +303,7 @@ iterate_dbs (gint pfd,
 
 	pilot_info = gpilot_find_pilot_by_id (pu->userID, context->pilots);
 
-	orbed_notify_daemon_message (pilot_info->name, NULL, _("Collecting synchronization info..."));
+	dbus_notify_daemon_message (pilot_info->name, NULL, _("Collecting synchronization info..."));
 
 	while (1) {
 		GnomePilotDBInfo *dbinfo;
@@ -380,7 +380,7 @@ iterate_dbs (gint pfd,
 				set_callbacks (FALSE, GNOME_PILOT_CONDUIT (conduit), pilot_info->name);
 			}
 
-			orbed_notify_overall_progress (pilot_info->name, index, g_list_length (dbs)); 
+			dbus_notify_overall_progress (pilot_info->name, index, g_list_length (dbs)); 
 
 			/*
 			  It seems pretty erratic which has this and which hasn't,
@@ -427,11 +427,11 @@ conduit_synchronize (GnomePilotConduitStandard *conduit, GnomePilotDBInfo *dbinf
 
 	write_sync_type_line_to_pilot (dbinfo, GNOME_PILOT_CONDUIT (conduit), _("Synchronizing %s\n"));
 
-	orbed_notify_conduit_start (dbinfo->pilotInfo->name,
+	dbus_notify_conduit_start (dbinfo->pilotInfo->name,
 				   GNOME_PILOT_CONDUIT (conduit),
 				   GnomePilotConduitSyncTypeSynchronize);
 	err = gnome_pilot_conduit_standard_synchronize (conduit, dbinfo);
-	orbed_notify_conduit_end (dbinfo->pilotInfo->name,
+	dbus_notify_conduit_end (dbinfo->pilotInfo->name,
 				   GNOME_PILOT_CONDUIT (conduit));
 	return err;
 }
@@ -446,11 +446,11 @@ conduit_copy_to_pilot (GnomePilotConduitStandard *conduit, GnomePilotDBInfo *dbi
 
 	write_sync_type_line_to_pilot (dbinfo, GNOME_PILOT_CONDUIT (conduit), _("Copy to PDA %s\n"));
 
-	orbed_notify_conduit_start (dbinfo->pilotInfo->name,
+	dbus_notify_conduit_start (dbinfo->pilotInfo->name,
 				    GNOME_PILOT_CONDUIT (conduit),
 				    GnomePilotConduitSyncTypeCopyToPilot);
 	err = gnome_pilot_conduit_standard_copy_to_pilot (conduit, dbinfo);
-	orbed_notify_conduit_end (dbinfo->pilotInfo->name,
+	dbus_notify_conduit_end (dbinfo->pilotInfo->name,
 				   GNOME_PILOT_CONDUIT (conduit));
 	return err;
 }
@@ -464,11 +464,11 @@ conduit_copy_from_pilot (GnomePilotConduitStandard *conduit, GnomePilotDBInfo *d
 
 	write_sync_type_line_to_pilot (dbinfo, GNOME_PILOT_CONDUIT (conduit), _("Copy from PDA %s\n"));
 
-	orbed_notify_conduit_start (dbinfo->pilotInfo->name,
+	dbus_notify_conduit_start (dbinfo->pilotInfo->name,
 				   GNOME_PILOT_CONDUIT (conduit),
 				   GnomePilotConduitSyncTypeCopyFromPilot);
 	err = gnome_pilot_conduit_standard_copy_from_pilot (conduit, dbinfo);
-	orbed_notify_conduit_end (dbinfo->pilotInfo->name,
+	dbus_notify_conduit_end (dbinfo->pilotInfo->name,
 				   GNOME_PILOT_CONDUIT (conduit));
 	return err;
 }
@@ -482,11 +482,11 @@ conduit_merge_to_pilot (GnomePilotConduitStandard *conduit, GnomePilotDBInfo *db
 
 	write_sync_type_line_to_pilot (dbinfo, GNOME_PILOT_CONDUIT (conduit), _("Merge to PDA %s\n"));
 
-	orbed_notify_conduit_start (dbinfo->pilotInfo->name,
+	dbus_notify_conduit_start (dbinfo->pilotInfo->name,
 				   GNOME_PILOT_CONDUIT (conduit),
 				   GnomePilotConduitSyncTypeMergeToPilot);
 	err = gnome_pilot_conduit_standard_merge_to_pilot (conduit, dbinfo);
-	orbed_notify_conduit_end (dbinfo->pilotInfo->name,
+	dbus_notify_conduit_end (dbinfo->pilotInfo->name,
 				   GNOME_PILOT_CONDUIT (conduit));
 	return err;
 }
@@ -500,11 +500,11 @@ conduit_merge_from_pilot (GnomePilotConduitStandard *conduit, GnomePilotDBInfo *
 
 	write_sync_type_line_to_pilot (dbinfo, GNOME_PILOT_CONDUIT (conduit), _("Merge from PDA %s\n"));
 
-	orbed_notify_conduit_start (dbinfo->pilotInfo->name,
+	dbus_notify_conduit_start (dbinfo->pilotInfo->name,
 				   GNOME_PILOT_CONDUIT (conduit),
 				   GnomePilotConduitSyncTypeMergeFromPilot);
 	err = gnome_pilot_conduit_standard_merge_from_pilot (conduit, dbinfo);
-	orbed_notify_conduit_end (dbinfo->pilotInfo->name,
+	dbus_notify_conduit_end (dbinfo->pilotInfo->name,
 				   GNOME_PILOT_CONDUIT (conduit));
 	return err;
 }
@@ -570,7 +570,7 @@ install_db_foreach (GPilotRequest *req, GnomePilotInstallCarrier *carrier) {
 	set_callbacks (FALSE, carrier->conduit, pilot_name);
 
 	g_free (pilot_name);
-	orbed_notify_completion (&req);
+	dbus_notify_completion (&req);
 }
 
 static void
@@ -600,7 +600,7 @@ do_restore_foreach (GPilotRequest *req, GnomePilotInstallCarrier *carrier)
 
 	pilot_name = pilot_name_from_id (carrier->pu->userID, carrier->context);
 	/* FIXME: if carrier.conduit_list is NULL, the user hasn't
-	  enabled any file conduits. The corba restore call should
+	  enabled any file conduits. The dbus restore call should
 	  throw an exception or something.  */
 	iterator = carrier->conduit_list;
 	while ( iterator != NULL ) {
@@ -628,7 +628,7 @@ do_restore_foreach (GPilotRequest *req, GnomePilotInstallCarrier *carrier)
 	}
 
 	g_free (pilot_name);
-	orbed_notify_completion (&req);
+	dbus_notify_completion (&req);
 }
 
 static void
@@ -783,7 +783,7 @@ gpilot_start_unknown_restore (int pfd,
 		struct PilotUser pu;
 		char *tmp;
 		tmp = g_strdup_printf (_("Setting id/owner to %d/%s..."), pilot->pilot_id, pilot->pilot_username);
-		orbed_notify_daemon_message (pilot->name, NULL, tmp);
+		dbus_notify_daemon_message (pilot->name, NULL, tmp);
 		g_snprintf (pu.username, 127, "%s", pilot->pilot_username);
 		pu.userID = pilot->pilot_id;
 		dlp_WriteUserInfo (pfd, &pu);
@@ -840,7 +840,7 @@ run_conduit_sync_foreach (GPilotRequest *req,
 					  carrier->context); 
 		}
 	}
-	orbed_notify_completion (&req);
+	dbus_notify_completion (&req);
 }
 
 gboolean gpilot_initial_synchronize_operations (int pilot_socket,
diff --git a/gpilotd/orbit_daemon_glue.c b/gpilotd/orbit_daemon_glue.c
deleted file mode 100644
index eca1bbe..0000000
--- a/gpilotd/orbit_daemon_glue.c
+++ /dev/null
@@ -1,2121 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- *//* 
- * Copyright (C) 1998-2000 Free Software Foundation
- *
- * 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.
- *
- * Authors: Eskil Heyn Olsen
- *
- */
-
-#include "config.h"
-
-#include <bonobo-activation/bonobo-activation.h>
-#include <libbonobo.h>
-
-#include "orbit_daemon_glue.h"
-#include "queue_io.h"
-#include "manager.h"
-#include <pwd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include "gnome-pilot-conduit.h"
-#include "gnome-pilot-conduit-standard.h"
-#include "gnome-pilot-config.h"
-#include <sys/types.h>
-#include <signal.h>
-
-/********************************************************************************/
-/* Defines                                                                      */
-
-#define USE_GNORBA
-#define DEBUG_CODE
-
-/* two macros for checking a clients id */
-#define GET_AND_CHECK_CLIENT_ID(s,c,t)                  \
-  s = get_client_id(c);                                 \
-  if(s==NULL) {                                         \
-    GNOME_Pilot_NoAccess *exn;                          \
-    exn = GNOME_Pilot_NoAccess__alloc();                \
-    CORBA_exception_set (ev, CORBA_USER_EXCEPTION,      \
-			 ex_GNOME_Pilot_NoAccess, exn); \
-    return t;                                           \
-  }
-
-#define GET_AND_CHECK_CLIENT_ID_VOID(s,c)           \
-  s = get_client_id(c);                             \
-  if(s==NULL) {                                     \
-    GNOME_Pilot_NoAccess *exn;                      \
-    exn = GNOME_Pilot_NoAccess__alloc();            \
-    CORBA_exception_set (ev, CORBA_USER_EXCEPTION,  \
-      ex_GNOME_Pilot_NoAccess, exn);                \
-    return;                                         \
-  }
-
-/* some macros for throwing exceptions */
-#define gpthrow(exception,returnval)                             \
-  {                                                              \
-	  GNOME_Pilot_##exception *exn;                          \
-          exn = GNOME_Pilot_##exception##__alloc();              \
-	  CORBA_exception_set (ev, CORBA_USER_EXCEPTION,         \
-			       ex_GNOME_Pilot_##exception, exn); \
-	  return returnval;                                      \
-  }
-
-#define gpthrow_with_settings(exception,returnval,name,commands) \
-  {                                                              \
-	  GNOME_Pilot_##exception *name;                         \
-          name = GNOME_Pilot_##exception##__alloc();             \
-          { commands; }                                          \
-	  CORBA_exception_set (ev, CORBA_USER_EXCEPTION,         \
-			       ex_GNOME_Pilot_##exception, name);\
-	  return returnval;                                      \
-  }
-
-#define gpthrow_no_val(exception)                                \
-  {                                                              \
-	  GNOME_Pilot_##exception *exn;                          \
-          exn = GNOME_Pilot_##exception##__alloc();              \
-	  CORBA_exception_set (ev, CORBA_USER_EXCEPTION,         \
-			       ex_GNOME_Pilot_##exception, exn); \
-	  return;                                                \
-  }
-
-#define gpthrow_no_val_with_settings(exception,name,commands)    \
-  {                                                              \
-	  GNOME_Pilot_##exception *name;                         \
-          name = GNOME_Pilot_##exception##__alloc();             \
-          { commands; }                                          \
-	  CORBA_exception_set (ev, CORBA_USER_EXCEPTION,         \
-			       ex_GNOME_Pilot_##exception, name);\
-	  return;                                                \
-  }
-
-/* a macro for logging catched exceptions */
-#define LOGEXN(e) g_warning ("%s:%d Exception: %s\n",   \
-	       	          __FILE__,__LINE__,            \
-			  CORBA_exception_id (&e));
-
-/* CORBA_string_dup doesn't take its argument as a const, meaning
-   passing consts causes warnings. This macor circumvents that */
-#define CORBA_string_dup(s) CORBA_string_dup((CORBA_char*)s)
-
-/********************************************************************************/
-/*  Structures                                                                  */
-
-/* This enum is used to decide which CORBA call to do in the 
-   orbed_notify_foreach method. It switches on the carries setting, and
-   the calls the desired method */
-enum ForEachAction {
-	CALL_CONNECT,
-	CALL_DISCONNECT,
-	CALL_CONDUIT_PROGRESS,
-	CALL_OVERALL_PROGRESS,
-	CALL_CONDUIT_MESSAGE,
-	CALL_CONDUIT_ERROR,
-	CALL_CONDUIT_BEGIN,
-	CALL_CONDUIT_END,
-	CALL_DAEMON_MESSAGE,
-	CALL_DAEMON_ERROR
-};
-
-/* This is used to pass arguments to various _foreach calls */
-typedef struct _GPilotd_notify_foreach_carrier GPilotd_notify_foreach_carrier;
-struct _GPilotd_notify_foreach_carrier {
-	gpointer id;
-	gpointer ptr1,ptr2,ptr3;
-	glong long1,long2;
-	enum ForEachAction action;
-	GSList *purge_list;
-};
-
-typedef struct _GPilotd_notify_on_helper_foreach_carrier GPilotd_notify_on_helper_foreach_carrier;
-struct _GPilotd_notify_on_helper_foreach_carrier {
-  gpointer client_id;
-  GNOME_Pilot_EventType event;
-};
-
-/** structure that carries a GSList to gchar*  (IORs) for
-    each notification type */
-
-typedef struct _GPilotd_Orb_Pilot_Notifications GPilotd_Orb_Pilot_Notifications;
-struct _GPilotd_Orb_Pilot_Notifications {
-  GSList* connect;     
-  GSList* disconnect;
-  GSList* request_complete;
-  GSList* request_timeout;
-  GSList* backup;
-  GSList* conduit;
-  GSList* userinfo_requested;
-  GSList* sysinfo_requested;
-  GSList* userinfo_sent;
-};
-
-/********************************************************************************/
-/*  Globals Variables !                                                         */
-
-CORBA_ORB orb;	
-CORBA_Environment ev;
-GPilotd_Orb_Context *orb_context;
-
-/********************************************************************************/
-static GNOME_Pilot_StringSequence* 
-empty_StringSequence(void) 
-{ 
-	GNOME_Pilot_StringSequence *seq;
-	seq = GNOME_Pilot_StringSequence__alloc(); 
-	seq->_length = 0; 
-	seq->_buffer = NULL; 
-	return seq;
-}
-
-static GNOME_Pilot_LongSequence* 
-empty_LongSequence(void) 
-{ 
-	GNOME_Pilot_LongSequence *seq;
-	seq = GNOME_Pilot_LongSequence__alloc(); 
-	seq->_length = 0; 
-	seq->_buffer = NULL; 
-	return seq;
-}
-
-static gchar *
-get_client_id(const GNOME_Pilot_Client cb) 
-{
-	gchar *client_id,*retval;
-	CORBA_Environment ev;
-	
-	CORBA_exception_init(&ev);
-	client_id = GNOME_Pilot_Client__get_client_id(cb,&ev);
-	if(ev._major != CORBA_NO_EXCEPTION) {
-		LOGEXN (ev);
-		CORBA_exception_free(&ev);
-		return NULL;
-	}
-	
-	if(client_id == NULL || 
-	   strlen(client_id)==0) {
-		
-		client_id = CORBA_ORB_object_to_string(orb,cb,&ev);
-		if(ev._major != CORBA_NO_EXCEPTION) {
-			LOG(("unable to resolve IOR for client"));
-			LOGEXN (ev);
-			CORBA_exception_free(&ev);
-			return NULL;
-		}
-	  
-		GNOME_Pilot_Client__set_client_id(cb,client_id,&ev);
-		if(ev._major != CORBA_NO_EXCEPTION) {
-			LOGEXN (ev);      
-			CORBA_exception_free(&ev);
-			return NULL;
-		}
-	}
-
-	CORBA_exception_free(&ev);
-	retval = g_strdup(client_id);
-	CORBA_free(client_id);
-	return retval;
-}
-
-
-
-/********************************************************************************/
-
-static void
-gpilotd_corba_pause_device(GPilotDevice *device,gpointer data)
-{
-	if (device->io) {
-		g_source_remove(device->in_handle);
-		g_source_remove(device->err_handle);
-	}
-}
-
-static void
-gpilotd_corba_pause_notify_monitor (gchar* key,
-				    GSList **value,
-				    CORBA_boolean *on_off) 
-{	
-	GNOME_Pilot_Client cb = CORBA_ORB_string_to_object(orb, (CORBA_char*)key, &ev);
-	GNOME_Pilot_Client_pause (cb, *on_off, &ev);
-
-	if (ev._major != CORBA_NO_EXCEPTION) {
-		char *client_id = get_client_id (cb);
-		g_message ("corba: monitor %.20s dead", client_id ? client_id : "<unknown>");
-		CORBA_exception_free (&ev);
-		CORBA_free (client_id);
-	}	
-}
-
-static void
-gpilotd_corba_pause(GNOME_Pilot_Daemon obj,
-		    CORBA_boolean on_off,
-		    CORBA_Environment *ev)  
-{
-	if (orb_context->gpilotd_context->paused == on_off) return;
-
-	orb_context->gpilotd_context->paused = on_off;
-
-	g_hash_table_foreach (orb_context->monitors,
-			      (GHFunc)gpilotd_corba_pause_notify_monitor,
-			      &on_off);
-
-	if (orb_context->gpilotd_context->paused) {
-		g_list_foreach(orb_context->gpilotd_context->devices,
-			      (GFunc)gpilotd_corba_pause_device,
-			       NULL);				      
-	} else {
-		kill(getpid(),SIGHUP);
-	}
-	
-	return;
-}
-
-static void
-gpilotd_corba_reread_config (GNOME_Pilot_Daemon obj,
-			     CORBA_Environment *ev)
-{
-	kill(getpid(),SIGHUP);
-}
-
-/********************************************************************************/
-
-static void
-gpilotd_corba_noop (GNOME_Pilot_Daemon obj,
-		    CORBA_Environment *ev)
-{
-	return;
-}
-
-/********************************************************************************/
-
-static CORBA_unsigned_long
-gpilotd_corba_request_install(GNOME_Pilot_Daemon obj,
-			      const GNOME_Pilot_Client cb,
-			      const CORBA_char *pilot_name,
-			      const CORBA_char *filename,
-			      const CORBA_char *description,
-			      const GNOME_Pilot_Survival survival,
-			      const CORBA_unsigned_long timeout,
-			      CORBA_Environment *ev)  
-{
-	GPilotRequest req;
-	gchar *client_id;
-	
-	GET_AND_CHECK_CLIENT_ID(client_id,cb,0);
-
-	LOG(("corba: request_install(pilot_name=%s (%d),filename=%s,survival=%d,timeout=%d)",
-	    pilot_name,
-	    pilot_id_from_name(pilot_name,orb_context->gpilotd_context),
-	    filename,
-	    survival,
-	    timeout));
-
-	req.type = GREQ_INSTALL;
-	req.pilot_id = pilot_id_from_name(pilot_name,orb_context->gpilotd_context);
-
-	/* FIXME: oops, this exception requires some parameters, not setting them causes
-	   ORBit to crash&burn:
-	   Solution:gpthrow(Exn,commands to se,retval) 
-	*/
-	if(req.pilot_id==0) {
-		g_free(client_id);
-		gpthrow_with_settings(UnknownPilot,0,exn,exn->pilotId = CORBA_string_dup(pilot_name));
-	}
-	if(access(filename,R_OK)) {
-		g_free(client_id);
-		gpthrow(MissingFile,0);
-	}
-
-	req.timeout = survival==GNOME_Pilot_PERSISTENT?0:timeout;
-	req.cradle = NULL;
-	req.client_id = g_strdup(client_id);
-	req.parameters.install.filename = g_strdup(filename);
-	req.parameters.install.description = g_strdup(description);
-
-	g_free(client_id);
-
-	return gpc_queue_store_request(req);
-}
-
-/* FIXME: look in manager.c, do_restore_foreach */
-static CORBA_unsigned_long
-gpilotd_corba_request_restore(GNOME_Pilot_Daemon obj,
-			      const GNOME_Pilot_Client cb,
-			      const CORBA_char *pilot_name,
-			      const CORBA_char *_directory,
-			      const GNOME_Pilot_Survival survival,
-			      const CORBA_unsigned_long timeout,
-			      CORBA_Environment *ev)
-{
-	GPilotRequest req;
-	gchar *directory;
-	struct stat statbuf;
-	char *client_id;
-	
-	GET_AND_CHECK_CLIENT_ID(client_id,cb,0);
-
-	directory = g_strdup(_directory);
-	/* FIXME: should be a generic / remover */
-	if (directory[strlen(directory)-1]=='/')
-		directory[strlen(directory)-1]=0;
-	LOG(("corba: request_restore(pilot_name=%s (%d), directory=%s,survival=%d,timeout=%d)",
-	    pilot_name,
-	    pilot_id_from_name(pilot_name,orb_context->gpilotd_context),
-	    directory,
-	    survival,
-	    timeout));
-
-	req.type = GREQ_RESTORE;
-	req.pilot_id = pilot_id_from_name(pilot_name,orb_context->gpilotd_context);
-
-	if(req.pilot_id==0) {
-		g_free(client_id);
-		g_free(directory);
-		gpthrow_with_settings(UnknownPilot,0,exn,exn->pilotId = CORBA_string_dup(pilot_name));
-	}
-	if (stat (directory, &statbuf)==-1) {
-		g_free (client_id);
-		g_free (directory);
-
-		gpthrow (MissingFile,0);
-	}
-	if (S_ISDIR (statbuf.st_mode) && access (directory,R_OK)!=0) {
-		g_free (client_id);
-		g_free (directory);
-		g_message ("or here access=%d, S_ISDIR=%d", access(directory,R_OK), S_ISDIR(statbuf.st_mode));
-		gpthrow (MissingFile, 0);
-	}
-	req.timeout = survival==GNOME_Pilot_PERSISTENT?0:timeout;
-	req.cradle = NULL;
-	req.client_id = g_strdup(client_id);
-
-	req.parameters.restore.directory = g_strdup(directory);
-
-	g_free(directory);
-	g_free(client_id);
-
-	return gpc_queue_store_request(req);
-}
-
-static CORBA_unsigned_long
-gpilotd_corba_request_conduit(GNOME_Pilot_Daemon _obj, 
-			      const GNOME_Pilot_Client cb,
-			      const CORBA_char * pilot_name, 
-			      const CORBA_char * conduit_name, 
-			      const GNOME_Pilot_ConduitOperation operation,
-			      const GNOME_Pilot_Survival survival, 
-			      const CORBA_unsigned_long timeout, 
-			      CORBA_Environment *ev) 
-{
-	GPilotRequest req;
-	char *client_id;
-	
-	GET_AND_CHECK_CLIENT_ID(client_id,cb,0);
-  
-	LOG(("corba: request_conduit(pilot=%s (%d), conduit=%s)",
-	    pilot_name,
-	    pilot_id_from_name(pilot_name,orb_context->gpilotd_context),
-	    conduit_name));
-	req.pilot_id = pilot_id_from_name(pilot_name,orb_context->gpilotd_context);
-
-	if(req.pilot_id==0) {
-		g_free(client_id);
-		gpthrow_with_settings(UnknownPilot,0,exn,exn->pilotId = CORBA_string_dup(pilot_name));
-	}
-
-	/* FIXME: check for conduit existence, throw exn if not */
-
-	req.type = GREQ_CONDUIT;
-	req.timeout = survival==GNOME_Pilot_PERSISTENT?0:timeout;
-	req.cradle = NULL;
-	req.client_id = g_strdup(client_id);
-
-	req.parameters.conduit.name = g_strdup(conduit_name);
-	switch(operation) {
-	case GNOME_Pilot_SYNCHRONIZE:
-		req.parameters.conduit.how = GnomePilotConduitSyncTypeSynchronize; break;
-	case GNOME_Pilot_COPY_FROM_PILOT:
-		req.parameters.conduit.how = GnomePilotConduitSyncTypeCopyFromPilot; break;
-	case GNOME_Pilot_COPY_TO_PILOT:
-		req.parameters.conduit.how = GnomePilotConduitSyncTypeCopyToPilot; break;
-	case GNOME_Pilot_MERGE_FROM_PILOT:
-		req.parameters.conduit.how = GnomePilotConduitSyncTypeMergeFromPilot; break;
-	case GNOME_Pilot_MERGE_TO_PILOT:
-		req.parameters.conduit.how = GnomePilotConduitSyncTypeMergeToPilot; break;
-	case GNOME_Pilot_CONDUIT_DEFAULT:
-		req.parameters.conduit.how = GnomePilotConduitSyncTypeCustom; break;
-	}
-	g_free(client_id);
-	return gpc_queue_store_request(req);
-}
-
-static CORBA_unsigned_long 
-gpilotd_corba_request_remove(GNOME_Pilot_Daemon _obj, 
-			     const CORBA_unsigned_long handle, 
-			     CORBA_Environment *ev) 
-{
-	/* FIXME: portability pitfall in the /% 65535 ? */
-	gpc_queue_purge_request_point(handle/65535,handle%65535);
-	return 1;
-}
-
-static CORBA_unsigned_long
-gpilotd_corba_get_user_info(GNOME_Pilot_Daemon obj,
-			    const GNOME_Pilot_Client cb,
-			    const CORBA_char *cradle, 
-			    const GNOME_Pilot_Survival survival,
-			    const CORBA_unsigned_long timeout,
-			    CORBA_Environment *ev) 
-{
-	GPilotRequest req;
-	char *client_id;
-
-	GET_AND_CHECK_CLIENT_ID(client_id,cb,0);
-
-	LOG(("corba: get_user_info(cradle=%s,survival=%d,timeout=%d)",
-	    cradle,survival,timeout));
-	/* FIXME: check for cradle existance, throw exn if not */
-	req.type = GREQ_GET_USERINFO;
-	req.timeout = survival==GNOME_Pilot_PERSISTENT?0:timeout;
-	req.pilot_id = 0;
-	req.cradle = g_strdup(cradle);
-	req.client_id = g_strdup(client_id);
-
-	g_free(client_id);
-
-	return gpc_queue_store_request(req);
-}
-
-
-static CORBA_unsigned_long
-gpilotd_corba_get_system_info(GNOME_Pilot_Daemon obj,
-			      const GNOME_Pilot_Client cb,
-			      const CORBA_char *cradle, 
-			      const GNOME_Pilot_Survival survival,
-			      const CORBA_unsigned_long timeout,
-			      CORBA_Environment *ev) 
-{
-	GPilotRequest req;
-	gchar *client_id;
-	GET_AND_CHECK_CLIENT_ID(client_id,cb,0);
-	
-	LOG(("corba: get_system_info(cradle=%s,survival=%d,timeout=%d)",
-	    cradle ,survival,timeout));
-	
-	req.type = GREQ_GET_SYSINFO;
-	req.pilot_id = 0;
-	req.timeout = survival==GNOME_Pilot_PERSISTENT?0:timeout;
-	req.cradle = g_strdup (cradle);
-	req.client_id = g_strdup(client_id);
-	
-	g_free(client_id);
-	
-	return gpc_queue_store_request(req);
-}
-
-static CORBA_unsigned_long
-gpilotd_corba_set_user_info(GNOME_Pilot_Daemon obj,
-			    const GNOME_Pilot_Client cb,
-			    GNOME_Pilot_UserInfo *user,
-			    const CORBA_char *cradle, 
-			    const CORBA_boolean continue_sync,
-			    const GNOME_Pilot_Survival survival,
-			    const CORBA_unsigned_long timeout, 
-			    CORBA_Environment *ev) 
-{
-	gchar *client_id;
-	int result;
-
-	GET_AND_CHECK_CLIENT_ID(client_id,cb,0);
-
-	LOG(("corba: set_user_info(cradle=%s,survival=%d,timeout=%d",
-	    cradle,survival,timeout));
-	LOG(("corba:               device = %s,",cradle));
-	LOG(("corba:               user_id = %d,",user->userID));
-	LOG(("corba:               user    = %s)",user->username));
-	/*LOG(("corba:               password= %s)",user->password);*/
-	/* FIXME: check for cradle existance, throw exn if not */
-
-	result = gpc_queue_store_set_userinfo_request (survival==GNOME_Pilot_PERSISTENT?0:timeout,
-						       cradle,
-						       client_id,
-						       user->username,
-						       user->userID,
-						       continue_sync);
-
-	g_free(client_id);
-
-	return result;
-}
-
-#if 0
-static CORBA_unsigned_long
-gpilotd_corba_set_user_info_if_not_set(GNOME_Pilot_Daemon obj,
-				       GNOME_Pilot_UserInfo *user,
-				       const GNOME_Pilot_Client cb,
-				       const CORBA_char *cradle, 
-				       const GNOME_Pilot_Survival survival,
-				       const CORBA_unsigned_long timeout, 
-				       CORBA_Environment *ev) 
-{
-  
-	GPilotRequest req;
-	gchar *client_id;
-	GET_AND_CHECK_CLIENT_ID(client_id,cb,0);
-
-	LOG(("corba: set_user_info_if_not_set(cradle=%s,survival=%d,timeout=%d",
-	    cradle,survival,timeout));
-	LOG(("corba:               device = %s,",cradle));
-	LOG(("corba:               client_id = %.20s...,",client_id));
-	LOG(("corba:               user_id = %d,",user->userID));
-	LOG(("corba:               user    = %s)",user->username));
-	/*LOG(("corba:               password= %s)",user->password));*/
-
-	/* FIXME: check for cradle existance, throw exn if not */
-
-	req.type = GREQ_NEW_USERINFO;
-	req.pilot_id = 0;
-	req.timeout = survival==GNOME_Pilot_PERSISTENT?0:timeout;
-	req.cradle = g_strdup(cradle);
-	req.client_id = g_strdup(client_id);
-	req.parameters.set_userinfo.password = NULL;
-	req.parameters.set_userinfo.user_id = g_strdup(user->username);
-	req.parameters.set_userinfo.pilot_id = user->userID;
-
-	g_free(client_id);
-
-	return gpc_queue_store_request(req);
-}
-#endif
-
-static void
-gpilotd_corba_monitor_on(GNOME_Pilot_Daemon obj,
-			 const GNOME_Pilot_Client cb, 
-			 const CORBA_char *pilot_name, 
-			 CORBA_Environment *ev) 
-{
-	GSList **pilots;
-	GSList *element;
-	gchar *client_id;
-
-#ifdef DEBUG_CODE
-	{
-		GNOME_Pilot_Client tmpcb;
-		CORBA_Environment my_ev;
-		gchar *tmp_client_id;
-
-		CORBA_exception_init(&my_ev);
-		tmp_client_id = CORBA_ORB_object_to_string(orb,cb,&my_ev);
-		if(my_ev._major != CORBA_NO_EXCEPTION) {
-			LOG(("*** Client appears to be disconnected..."));
-			LOGEXN (my_ev);
-		} else {
-			LOG(("Client seems ok"));
-			tmpcb = CORBA_ORB_string_to_object(orb,(CORBA_char*)tmp_client_id,&my_ev); 
-			if(my_ev._major != CORBA_NO_EXCEPTION) {
-				LOG(("**** Client appears to be disconnected..."));
-				LOGEXN (my_ev);
-				g_assert_not_reached();
-			} else {
-				LOG(("Client seems ok"));
-			}
-		}
-	}
-#endif
-
-	GET_AND_CHECK_CLIENT_ID_VOID(client_id,cb);
-
-	LOG(("monitor_on(pilot_name=\"%s\",client_id = %.20s...)",pilot_name,client_id));
-
-	if(pilot_id_from_name(pilot_name,orb_context->gpilotd_context)==0) {
-		g_free(client_id);
-		gpthrow_no_val_with_settings(UnknownPilot,exn,exn->pilotId = CORBA_string_dup(pilot_name));
-	}
-
-	if((pilots = g_hash_table_lookup(orb_context->monitors,client_id))==NULL) {
-		pilots = g_new0(GSList*,1);
-		*pilots = g_slist_prepend(*pilots,g_strdup(pilot_name));
-		g_hash_table_insert(orb_context->monitors,g_strdup(client_id),pilots);
-	} else {
-		element = g_slist_find_custom(*pilots,(gchar*)pilot_name,
-					      (GCompareFunc)strcmp);
-		*pilots = g_slist_prepend(*pilots,g_strdup(pilot_name));
-	}
-
-	g_free(client_id);
-}
-
-/* used by monitor_off_helper to remove callback IORs from a GSList* */
-static void 
-monitor_off_remover(GSList **list,
-		    const gchar *client_id) 
-{
-	GSList *element;
-
-	/* No, these will often be called with NULL pointers, so don't change these
-	   to g_return..., too much output */
-	if(list==NULL) return;
-	if(*list==NULL) return;
-	g_assert(client_id!=NULL);
-
-	element = g_slist_find_custom(*list,(gpointer)client_id,(GCompareFunc)strcmp);
-	if(element) {
-		g_free(element->data);
-		*list = g_slist_remove(*list,element->data); 
-	}
-
-	if(g_slist_length(*list)==0) {
-		g_slist_free(*list);
-		*list=NULL;
-	} 
-}
-
-/* used by monitor_off to erase callback IORs from the 
-   GNOME_Pilot_Orb_Pilot_Notifications object for the given pilot_id */
-static void 
-monitor_off_helper_2(const gchar *pilot,
-		     const gchar* client_id) 
-{
-	GPilotd_Orb_Pilot_Notifications *notifications;
-
-	g_assert(pilot!=NULL);
-	g_assert(client_id!=NULL);
-
-	LOG(("removing monitor on %s for %.10s",pilot,client_id));
-	notifications = g_hash_table_lookup(orb_context->notifications,pilot);
-	if(notifications==NULL) return;
-
-	monitor_off_remover(&notifications->connect,client_id);
-	monitor_off_remover(&notifications->disconnect,client_id);
-	monitor_off_remover(&notifications->backup,client_id);
-	monitor_off_remover(&notifications->conduit,client_id);
-	monitor_off_remover(&notifications->request_complete,client_id);
-	monitor_off_remover(&notifications->request_timeout,client_id);
-	monitor_off_remover(&notifications->userinfo_requested,client_id);
-	monitor_off_remover(&notifications->sysinfo_requested,client_id);
-	monitor_off_remover(&notifications->userinfo_sent,client_id);
-
-	if(notifications->connect == NULL &&
-	   notifications->disconnect == NULL &&
-	   notifications->backup == NULL &&
-	   notifications->conduit == NULL &&
-	   notifications->request_complete == NULL &&
-	   notifications->request_timeout == NULL &&
-	   notifications->userinfo_requested == NULL &&
-	   notifications->sysinfo_requested == NULL &&
-	   notifications->userinfo_sent == NULL) {
-		gpointer key,elem;
- 
-		key = NULL; elem = NULL;
-		g_hash_table_lookup_extended(orb_context->notifications,pilot,&key,&elem);
-		g_hash_table_remove(orb_context->notifications,key);
-		g_free(key);    
-		g_free(elem);
-	}
-     
-}
-
-#ifdef DEBUG_CODE
-void debug_monitors(gchar*, GSList**, gpointer); /* shuts up the compiler */
-void debug_monitors(gchar *key, GSList **value, gpointer data) {
-	GSList *e;
-	GPilotd_Orb_Pilot_Notifications *nots;
-	for (e=*value;e;e = g_slist_next(e)) {
-		g_print("%s is monitoring %s",key,(char*)e->data);
-		nots = g_hash_table_lookup(orb_context->notifications,e->data);
-		if (nots==NULL)
-			g_print (" - no notifications");
-		else {
-			g_print (" - ");
-			if (nots->connect) g_print("connect,");
-			if (nots->disconnect) g_print("disconnect,");
-		}
-		g_print("\n");
-	}
-}
-#endif
-
-static void 
-monitor_off_helper(const gchar *pilot,
-		   const gchar* client_id) 
-{
-	GSList **pilots;
-	if((pilots = g_hash_table_lookup(orb_context->monitors,client_id))!=NULL) {
-		GSList *element;
-		if((element = g_slist_find_custom(*pilots,
-						  (gpointer)pilot,
-						  (GCompareFunc)strcmp))!=NULL) {
-			/* random nuking in the notification lists */
-			monitor_off_helper_2(pilot,client_id);
-
-			/* nuke pilot from list */
-			g_free(element->data);
-			*pilots = g_slist_remove(*pilots,element->data);
-			
-			/* if pilots is empty now, nuke fom orb_context->monitors */
-			if(g_slist_length(*pilots)==0) {
-				gpointer key;
-				gpointer elem;
-				
-				key = NULL; elem = NULL;
-				g_hash_table_lookup_extended(orb_context->monitors,
-							     client_id,
-							     &key,
-							     &elem);
-				g_hash_table_remove(orb_context->monitors,(gchar *)key);
-				g_free((gchar *)key);
-				g_slist_free(*(GSList **)elem);
-				g_free((GSList **)elem); 
-			} 
-		} else {
-			GSList *e;
-			/* This really shouldn't happen, dump list for debug purposes */
-			LOG(("Could not find any link for %s",pilot));
-			for(e=*pilots;e;e = g_slist_next(e)) {
-				LOG(("pilots slist dump: %s",
-				    e->data==NULL?"(null)":(char*)e->data));
-			}			
-		}
-		
-	} else {
-		LOG(("couldn't find any monitor for %.10s",client_id));
-	}
-	
-
-#ifdef DEBUG_CODE
-	g_print("\n");
-	g_hash_table_foreach(orb_context->monitors,(GHFunc)debug_monitors,NULL);
-#endif
-}
-
-static void 
-gpilotd_corba_monitor_off(GNOME_Pilot_Daemon obj,
-			  const GNOME_Pilot_Client cb, 
-			  const CORBA_char *pilot_name, 
-			  CORBA_Environment *ev) 
-{
-	gchar *client_id;
-
-	GET_AND_CHECK_CLIENT_ID_VOID(client_id,cb);
-
-	LOG(("monitor_off(pilot_name=\"%.10s\", client_id = %.20s...)",pilot_name,client_id));
-	if(pilot_id_from_name(pilot_name,orb_context->gpilotd_context)==0) {
-		g_free(client_id);
-		gpthrow_no_val_with_settings(UnknownPilot,exn,exn->pilotId = CORBA_string_dup(pilot_name));
-	}
-	monitor_off_helper(pilot_name,client_id);
-
-	g_free(client_id);
-}
-
-static void 
-notify_on_helper(gchar *pilot,
-		 GPilotd_notify_on_helper_foreach_carrier *carrier) 
-{
-	GPilotd_Orb_Pilot_Notifications *notifications;
-
-	notifications = g_hash_table_lookup(orb_context->notifications,pilot);
-
-	if(notifications==NULL) {    
-		notifications = g_new0(GPilotd_Orb_Pilot_Notifications,1);
-		g_hash_table_insert(orb_context->notifications,g_strdup(pilot),notifications);
-	}
-	switch(carrier->event) {
-	case GNOME_Pilot_NOTIFY_CONNECT: 
-		notifications->connect = g_slist_prepend(notifications->connect,
-							 g_strdup(carrier->client_id));
-		break;
-	case GNOME_Pilot_NOTIFY_DISCONNECT: 
-		notifications->disconnect = g_slist_prepend(notifications->disconnect,
-							    g_strdup(carrier->client_id));
-		break;
-	case GNOME_Pilot_NOTIFY_BACKUP: 
-		notifications->backup = g_slist_prepend(notifications->backup,
-							g_strdup(carrier->client_id));
-		break;
-	case GNOME_Pilot_NOTIFY_CONDUIT: 
-		notifications->conduit = g_slist_prepend(notifications->conduit,
-							 g_strdup(carrier->client_id));
-		break;
-	case GNOME_Pilot_NOTIFY_REQUEST_COMPLETION: 
-		notifications->request_complete = g_slist_prepend(notifications->request_complete,
-								  g_strdup(carrier->client_id));
-		break;
-	case GNOME_Pilot_NOTIFY_REQUEST_TIMEOUT: 
-		notifications->request_timeout = g_slist_prepend(notifications->request_timeout,
-								 g_strdup(carrier->client_id));
-		break;
-	case GNOME_Pilot_NOTIFY_USERINFO_REQUESTED: 
-		/* FIXME: what was this request to do ? notify when the info was requested or when returned ? */
-		/*notifications->userinfo_requested = g_slist_prepend(notifications->connect,g_strdup(carrier->client_id)); */
-		break;
-	case GNOME_Pilot_NOTIFY_SYSINFO_REQUESTED: 
-		/* FIXME: what was this request to do ? notify when the info was requested or when returned ? */
-		/*notifications->sysinfo_requestde = g_slist_prepend(notifications->connect,g_strdup(carrier->client_id));*/
-		break;
-	case GNOME_Pilot_NOTIFY_USERINFO_SENT: 
-		notifications->userinfo_sent = g_slist_prepend(notifications->userinfo_sent,
-							       g_strdup(carrier->client_id));
-		break;
-	default:
-		g_assert_not_reached();
-		break;
-	}
-}
-
-static void
-gpilotd_corba_notify_on(GNOME_Pilot_Daemon obj, 
-			GNOME_Pilot_EventType event, 
-			const GNOME_Pilot_Client cb, 
-			CORBA_Environment * ev) 
-{
-	GSList **pilots;
-	GPilotd_notify_on_helper_foreach_carrier carrier;
-	gchar *client_id;
-
-	GET_AND_CHECK_CLIENT_ID_VOID(client_id,cb);
-
-	{
-		gchar *event_type = NULL;
-		switch(event) {
-		case GNOME_Pilot_NOTIFY_CONNECT: 
-			event_type = g_strdup("CONNECT"); break;
-		case GNOME_Pilot_NOTIFY_DISCONNECT: 
-			event_type = g_strdup("DISCONNECT"); break;
-		case GNOME_Pilot_NOTIFY_BACKUP: 
-			event_type = g_strdup("BACKUP"); break;
-		case GNOME_Pilot_NOTIFY_CONDUIT: 
-			event_type = g_strdup("CONDUIT"); break;
-		case GNOME_Pilot_NOTIFY_REQUEST_COMPLETION: 
-			event_type = g_strdup("REQUEST_COMPLETION"); break;
-		case GNOME_Pilot_NOTIFY_REQUEST_TIMEOUT: 
-			event_type = g_strdup("REQUEST_TIMEOUT"); break;
-		case GNOME_Pilot_NOTIFY_USERINFO_REQUESTED: 
-			event_type = g_strdup("USERINFO_REQUESTED"); break;
-		case GNOME_Pilot_NOTIFY_USERINFO_SENT: 
-			event_type = g_strdup("USERINFO_SENT"); break;
-		default: g_assert_not_reached(); break;
-		}
-		LOG(("corba: notify_on(event_type=%s,callback=%.20s...)",
-		    event_type,client_id));
-		g_free(event_type);
-	}
-
-	if((pilots = g_hash_table_lookup(orb_context->monitors,client_id))==NULL) {
-		g_free(client_id);
-		gpthrow_no_val(NoMonitors);
-	}
-	carrier.client_id = client_id;
-	carrier.event = event;
-	g_slist_foreach(*pilots,(GFunc)notify_on_helper,(gpointer)&carrier);
-
-	g_free(client_id);
-};
-
-static void
-gpilotd_corba_notify_off(GNOME_Pilot_Daemon obj, 
-			 GNOME_Pilot_EventType event, 
-			 const GNOME_Pilot_Client cb, 
-			 CORBA_Environment * ev) 
-{
-	GSList **pilots;
-	GPilotd_notify_on_helper_foreach_carrier carrier;
-	gchar *client_id;
-
-	GET_AND_CHECK_CLIENT_ID_VOID(client_id,cb);
-
-	{
-		gchar *event_type = NULL;
-		switch(event) {
-		case GNOME_Pilot_NOTIFY_CONNECT: 
-			event_type = g_strdup("CONNECT"); break;
-		case GNOME_Pilot_NOTIFY_DISCONNECT: 
-			event_type = g_strdup("DISCONNECT"); break;
-		case GNOME_Pilot_NOTIFY_BACKUP: 
-			event_type = g_strdup("BACKUP"); break;
-		case GNOME_Pilot_NOTIFY_CONDUIT: 
-			event_type = g_strdup("CONDUIT"); break;
-		case GNOME_Pilot_NOTIFY_REQUEST_COMPLETION: 
-			event_type = g_strdup("REQUEST_COMPLETION"); break;
-		case GNOME_Pilot_NOTIFY_REQUEST_TIMEOUT: 
-			event_type = g_strdup("REQUEST_TIMEOUT"); break;
-		case GNOME_Pilot_NOTIFY_USERINFO_REQUESTED: 
-			event_type = g_strdup("USERINFO_REQUESTED"); break;
-		case GNOME_Pilot_NOTIFY_USERINFO_SENT: 
-			event_type = g_strdup("USERINFO_SENT"); break;
-		default: g_assert_not_reached(); break;
-		}
-		LOG(("corba: notify_off(event_type=%s,callback=%.20s...)",
-		    event_type,client_id));
-		g_free(event_type);
-	}
-
-	if((pilots = g_hash_table_lookup(orb_context->monitors,client_id))==NULL) {
-		g_free(client_id);
-		gpthrow_no_val(NoMonitors);
-	}
-
-	carrier.client_id = client_id;
-	carrier.event = event;
-	g_warning("Unimplemented method");
-	/*
-	g_slist_foreach(*pilots,(GFunc)notify_on_helper,(gpointer)&carrier);
-	*/
-	g_free(client_id);
-};
-
-
-/* get_* methods */
-static GNOME_Pilot_StringSequence*
-gpilotd_corba_get_users(GNOME_Pilot_Daemon obj, 
-			CORBA_Environment *ev) 
-{
-
-	LOG(("corba: get_users()"));
-
-	/* FIXME: this isn't complete, it only gives one user, and
-	   doesn't make any NULL checks... */
-	if(orb_context->gpilotd_context->user) {
-		GNOME_Pilot_StringSequence *users;
-		users = GNOME_Pilot_StringSequence__alloc();
-		users->_length = 1;
-		users->_buffer = CORBA_sequence_CORBA_string_allocbuf(users->_length);
-		users->_buffer[0] = CORBA_string_alloc(strlen(orb_context->gpilotd_context->user->username));
-		strcpy(users->_buffer[0],orb_context->gpilotd_context->user->username);
-		return users;
-	} else 
-		return empty_StringSequence();
-}
-
-static GNOME_Pilot_StringSequence*
-gpilotd_corba_get_cradles(GNOME_Pilot_Daemon obj, 
-			  CORBA_Environment *ev) 
-{
-
-	LOG(("corba: get_cradles(...)"));
-
-	if(g_list_length(orb_context->gpilotd_context->devices)>0) {
-		GNOME_Pilot_StringSequence *cradles;
-		int i;
-
-		cradles = GNOME_Pilot_StringSequence__alloc();
-		cradles->_length = g_list_length(orb_context->gpilotd_context->devices);
-		cradles->_buffer = CORBA_sequence_CORBA_string_allocbuf(cradles->_length);
-
-		/* FIXME: this could probably be prettyfied with some _foreach thingies... */
-		for(i=0;i<g_list_length(orb_context->gpilotd_context->devices);i++) {
-			cradles->_buffer[i] = CORBA_string_alloc(strlen(GPILOT_DEVICE(g_list_nth(orb_context->gpilotd_context->devices,i)->data)->name));
-			strcpy(cradles->_buffer[i],GPILOT_DEVICE(g_list_nth(orb_context->gpilotd_context->devices,i)->data)->name);
-		}
-		return cradles;
-	} else 
-		return empty_StringSequence();
-}
-
-static GNOME_Pilot_StringSequence*
-gpilotd_corba_get_pilots(GNOME_Pilot_Daemon obj, 
-			 CORBA_Environment *ev) 
-{
-
-	LOG(("corba: get_pilots(...)"));
-
-	if(g_list_length(orb_context->gpilotd_context->pilots)>0) {
-		GNOME_Pilot_StringSequence *pilots;
-		int i;
-
-		pilots = GNOME_Pilot_StringSequence__alloc();
-		pilots->_length = g_list_length(orb_context->gpilotd_context->pilots);
-		pilots->_buffer = CORBA_sequence_CORBA_string_allocbuf(pilots->_length);
-
-		/* FIXME: this could probably be prettyfied with some _foreach thingies... */
-		for(i=0;i<g_list_length(orb_context->gpilotd_context->pilots);i++) {
-			pilots->_buffer[i] = CORBA_string_alloc(strlen(GPILOT_PILOT(g_list_nth(orb_context->gpilotd_context->pilots,i)->data)->name));
-			strcpy(pilots->_buffer[i],GPILOT_PILOT(g_list_nth(orb_context->gpilotd_context->pilots,i)->data)->name);
-		}
-		return pilots;
-	} else 
-		return empty_StringSequence();
-}
-
-static GNOME_Pilot_LongSequence*
-gpilotd_corba_get_pilot_ids(GNOME_Pilot_Daemon obj, 
-			    CORBA_Environment *ev) 
-{
-
-	LOG(("corba: get_pilot_ids(...)"));
-
-	if(g_list_length(orb_context->gpilotd_context->pilots)>0) {
-		GNOME_Pilot_LongSequence *pilots;
-		int i;
-		
-		pilots = GNOME_Pilot_LongSequence__alloc();
-		pilots->_length = g_list_length(orb_context->gpilotd_context->pilots);
-		pilots->_buffer = CORBA_sequence_CORBA_long_allocbuf(pilots->_length);
-
-		/* FIXME: this could probably be prettyfied with some _foreach thingies... */
-		for(i=0;i<g_list_length(orb_context->gpilotd_context->pilots);i++) {
-			pilots->_buffer[i] = GPILOT_PILOT(g_list_nth(orb_context->gpilotd_context->pilots,i)->data)->pilot_id;
-		}
-		return pilots;
-	} else 
-		return empty_LongSequence();
-}
-
-static GNOME_Pilot_StringSequence*
-gpilotd_corba_get_pilots_by_name(GNOME_Pilot_Daemon obj, 
-				 const CORBA_char * user, 
-				 CORBA_Environment *ev) 
-{
-	int cnt;
-
-	LOG(("corba: get_pilots_by_name(%s)",user));
-
-	/* FIXME: this could probably be prettyfied with some _foreach thingies... */
-	if(g_list_length(orb_context->gpilotd_context->pilots)>0) {
-		GNOME_Pilot_StringSequence *pilots;
-		int i;
-		LOG(("g_list_length(orb_context->gpilotd_context->pilots) = %d",g_list_length(orb_context->gpilotd_context->pilots)));
-
-		/* first count the number of pilots to cp */
-		cnt=0;
-		/* FIXME: this could probably be prettyfied with some _foreach thingies... */
-		for(i=0;i<g_list_length(orb_context->gpilotd_context->pilots);i++) {
-			if(strcmp(GPILOT_PILOT(g_list_nth(orb_context->gpilotd_context->pilots,i)->data)->pilot_username,
-				  user)==0) {
-				LOG(("match on %s",GPILOT_PILOT(g_list_nth(orb_context->gpilotd_context->pilots,i)->data)->name));
-				cnt++;
-			}
-		}
-		if(cnt==0) {
-			LOG(("no matches on %s",user));
-			return empty_StringSequence(); 
-		}
-
-		/* alloc and copy intro string */
-		pilots = GNOME_Pilot_StringSequence__alloc();
-		pilots->_length = cnt;
-		pilots->_buffer = CORBA_sequence_CORBA_string_allocbuf(pilots->_length);
-		/* FIXME: this could probably be prettyfied with some _foreach thingies... */
-		for(i=0;i<g_list_length(orb_context->gpilotd_context->pilots);i++) {
-			if(strcmp(GPILOT_PILOT(g_list_nth(orb_context->gpilotd_context->pilots,i)->data)->pilot_username,
-				  user)==0) {
-				pilots->_buffer[i] = CORBA_string_alloc(strlen(GPILOT_PILOT(g_list_nth(orb_context->gpilotd_context->pilots,i)->data)->name));
-				strcpy(pilots->_buffer[i],GPILOT_PILOT(g_list_nth(orb_context->gpilotd_context->pilots,i)->data)->name);
-			}
-		}
-		return pilots;
-	} else 
-		return empty_StringSequence();
-}
-
-static GNOME_Pilot_StringSequence*
-gpilotd_corba_get_pilots_by_login(GNOME_Pilot_Daemon obj, 
-				  const CORBA_char * uid, 
-				  CORBA_Environment *ev) 
-{
-	gchar *username;
-	struct passwd *pwdent;
-	GNOME_Pilot_StringSequence *pilots;
-
-	LOG(("corba: get_pilots_by_login(%s)",uid));
-
-	/* find the pwdent matching the login */
-	username = NULL;
-	setpwent();
-	do {
-		pwdent = getpwent();
-		if(pwdent) {
-			if(strcmp(pwdent->pw_name,uid)==0) {
-				username = strdup(pwdent->pw_gecos);
-				pwdent=NULL; /* end the loop */
-			}
-		}
-	} while(pwdent);
-	endpwent();
-
-	/* no luck ? */
-	if(!username) {
-		LOG(("no realname for %s",uid));
-		return empty_StringSequence();
-	}
-
-	/* FIXME: uhm, is this use of username safe ? 
-	   or should it be CORBA::strdup'ed ? */
-	pilots = gpilotd_corba_get_pilots_by_name(obj,username,ev);
-	g_free(username);
-	return pilots;
-}
-
-static CORBA_char*
-gpilotd_corba_get_user_name_by_pilot(GNOME_Pilot_Daemon obj, 
-				     const CORBA_char * pilot_name, 
-				     CORBA_Environment *ev) 
-{
-	LOG(("corba: FIXME %s:%d get_user_name_by_pilot", __FILE__, __LINE__));
-
-	/* FIXME: not implemented yet */
-	return CORBA_string_dup ("Foo Bar");
-}
-
-static CORBA_char*
-gpilotd_corba_get_user_login_by_pilot(GNOME_Pilot_Daemon obj, 
-				      const CORBA_char * pilot_name, 
-				      CORBA_Environment *ev) 
-{
-	LOG(("corba: FIXME %s:%d get_user_login_by_pilot", __FILE__, __LINE__));
-
-	/* FIXME: not implemented yet */
-	return CORBA_string_dup ("foo");
-}
-
-static CORBA_char* 
-gpilotd_get_pilot_base_dir(PortableServer_Servant _servant, 
-		     CORBA_char * pilot_name, 
-		     CORBA_Environment * ev) {
-	int i;
-	LOG(("corba: get_pilot_base_dir(id=%s)",pilot_name));
-	
-
-	/* FIXME: this could probably be prettyfied with some _foreach thingies... */
-	if(g_list_length(orb_context->gpilotd_context->pilots)>0) {
-		/* FIXME: this could probably be prettyfied with some _foreach thingies... */
-		for(i=0;i<g_list_length(orb_context->gpilotd_context->pilots);i++) {
-			if(strcmp(GPILOT_PILOT(g_list_nth(orb_context->gpilotd_context->pilots,i)->data)->name,
-				  pilot_name)==0) {
-				LOG(("match on %s",GPILOT_PILOT(g_list_nth(orb_context->gpilotd_context->pilots,i)->data)->name));
-				if(GPILOT_PILOT(g_list_nth(orb_context->gpilotd_context->pilots,i)->data)->sync_options.basedir!=NULL) {
-					return CORBA_string_dup(GPILOT_PILOT(g_list_nth(orb_context->gpilotd_context->pilots,i)->data)->sync_options.basedir);
-				} else {
-					return CORBA_string_dup("");
-				}
-			}
-		}
-		LOG(("no matches on %s",pilot_name));
-		return CORBA_string_dup("");
-	} else 
-		return CORBA_string_dup("");
-}
-
-static CORBA_long 
-gpilotd_get_pilot_id_from_name(PortableServer_Servant _servant, 
-			       CORBA_char * pilot_name, 
-			       CORBA_Environment * ev) {
-	LOG(("corba: get_user_pilot_id_from_name"));
-
-	return pilot_id_from_name(pilot_name,orb_context->gpilotd_context);
-}
-
-static CORBA_char* 
-gpilotd_get_pilot_name_from_id(PortableServer_Servant _servant, 
-			       CORBA_long pilot_name, 
-			       CORBA_Environment * ev) {
-	gchar *tmp;
-	CORBA_char *retval;
-	LOG(("corba: get_pilot_name_from_id(id=%d)",pilot_name));
-
-	tmp = pilot_name_from_id(pilot_name,orb_context->gpilotd_context);
-	retval =  CORBA_string_dup(tmp);
-	g_free(tmp);
-
-	return retval;
-}
-
-static GNOME_Pilot_StringSequence*
-gpilotd_corba_get_databases_from_cache(GNOME_Pilot_Daemon obj, 
-				       const CORBA_char *pilot_name,
-				       CORBA_Environment *ev) 
-{
-	char **databases;
-	gsize num_bases;
-	guint32 pilot_id;
-	GKeyFile *kfile;
-
-	LOG(("corba: get_databases_from_cache(...)"));
-
-	pilot_id = pilot_id_from_name(pilot_name,
-				      orb_context->gpilotd_context);
-
-	/* If no pilot matches the name, set the exn, and exit with a empty stringsequence */
-	if (pilot_id == 0) {
-		/* gpthrow_no_val_with_settings(UnknownPilot,exn,exn->pilotId = CORBA_string_dup(pilot_name)); */
-		return empty_StringSequence();
-		return NULL;
-	} else {
-		kfile = get_pilot_cache_kfile (pilot_id);
-		databases = g_key_file_get_string_list (kfile, "Databases", "databases", &num_bases, NULL);	
-		
-		/* if there were databases, copy into a corba array
-                   and return, otherwise return an empty array */
-		if(num_bases > 0) {
-			GNOME_Pilot_StringSequence *pilots;
-			int i;
-			
-			pilots = GNOME_Pilot_StringSequence__alloc();
-			pilots->_length = num_bases;
-			pilots->_buffer = CORBA_sequence_CORBA_string_allocbuf(pilots->_length);
-			
-			/* FIXME: this could probably be prettyfied
-                           with some _foreach thingies... */
-			for(i = 0; i < num_bases; i++) {
-				pilots->_buffer[i] = CORBA_string_alloc(strlen(databases[i]));
-				strcpy(pilots->_buffer[i],databases[i]);
-				g_free(databases[i]);
-			}
-			g_free (databases);
-			g_key_file_free (kfile);
-			return pilots;
-		} else {
-			g_key_file_free (kfile);
-			return empty_StringSequence();
-		}
-	}
-}
-
-
-
-/*************************************************************************************/
-static gint 
-match_pilot_and_name(const GPilotPilot *pilot,
-		     const gchar *name) 
-{
-	if(pilot) {
-		return g_ascii_strcasecmp (name, pilot->name);
-	}
-	return -1;
-}
-
-gint 
-match_pilot_userID(GPilotPilot *p,
-		   guint32 *id)
-{
-	if(p->pilot_id == *id)
-		return 0;
-	return -1;
-}
-
-guint32 
-pilot_id_from_name(const gchar *name,
-		   GPilotContext *context) 
-{
-	GList *pilot;
-	pilot = g_list_find_custom(context->pilots,(gpointer)name,
-				   (GCompareFunc)match_pilot_and_name);
-	if(pilot)
-		return ((GPilotPilot*)pilot->data)->pilot_id;
-	return 0;
-}
-
-gchar*
-pilot_name_from_id(guint32 id,
-		   GPilotContext *context) 
-{
-	GList *pilot;
-	pilot = g_list_find_custom(context->pilots,(gpointer)&id,
-				   (GCompareFunc)match_pilot_userID);
-
-	if(pilot)
-		return g_strdup(((GPilotPilot*)pilot->data)->name);
-
-	return NULL;
-}
-
-
-/*****************************************************/
-/* orbit init stuff */
-
-PortableServer_ServantBase__epv base_epv = {
-	NULL,
-	NULL,
-	NULL
-};
-
-POA_GNOME_Pilot_Daemon__epv daemon_epv = { 
-	NULL, 
-	(gpointer)&gpilotd_corba_pause,
-	(gpointer)&gpilotd_corba_reread_config,
-	(gpointer)&gpilotd_corba_noop,
-	(gpointer)&gpilotd_corba_request_install,
-	(gpointer)&gpilotd_corba_request_restore,
-	(gpointer)&gpilotd_corba_request_conduit,
-	(gpointer)&gpilotd_corba_request_remove,
-	(gpointer)&gpilotd_corba_get_system_info,
-	(gpointer)&gpilotd_corba_get_users,
-	(gpointer)&gpilotd_corba_get_cradles,
-	(gpointer)&gpilotd_corba_get_pilots,
-	(gpointer)&gpilotd_corba_get_pilot_ids,
-	(gpointer)&gpilotd_corba_get_pilots_by_name,
-	(gpointer)&gpilotd_corba_get_pilots_by_login,
-	(gpointer)&gpilotd_corba_get_user_name_by_pilot,
-	(gpointer)&gpilotd_corba_get_user_login_by_pilot,
-	(gpointer)&gpilotd_get_pilot_base_dir,
-	(gpointer)&gpilotd_get_pilot_id_from_name,
-	(gpointer)&gpilotd_get_pilot_name_from_id,
-	(gpointer)&gpilotd_corba_get_databases_from_cache,
-	(gpointer)&gpilotd_corba_get_user_info,
-	(gpointer)&gpilotd_corba_set_user_info,
-	(gpointer)&gpilotd_corba_monitor_on,
-	(gpointer)&gpilotd_corba_monitor_off,
-	(gpointer)&gpilotd_corba_notify_on,
-	(gpointer)&gpilotd_corba_notify_off,
-};
-
-POA_GNOME_Pilot_Daemon__vepv daemon_vepv = { &base_epv, &daemon_epv };
-POA_GNOME_Pilot_Daemon daemon_servant = { NULL, &daemon_vepv };
-
-/********************************************************************************/
-/* This function is used by orbed_notify_connect/disconnect to
-   remove all clients that have been marked as dead.                            */
-
-static void 
-purge_ior_foreach(const gchar *pilot,
-		  GSList *list) 
-{
-	int i;
-	gchar *ior;
-	GSList *e;
-
-	if(list==NULL || g_slist_length(list)==0) return;
-	g_return_if_fail(pilot);
-  
-	for(i=0;i<g_slist_length(list);i++) {
-		e = g_slist_nth(list,i);
-		g_assert(e);
-		g_assert(e->data);
-		ior = e->data;
-		monitor_off_helper(pilot,ior); 
-	}
-	for(i=0;i<g_slist_length(list);i++) {
-		e = g_slist_nth(list,i);
-		g_free(e->data);
-	}
-	g_slist_free(list);  
-}
-
-/********************************************************************************/
-/*
-                                                                                */
-static void 
-orbed_notify_multi_purpose_foreach(gchar *IOR,
-				   GPilotd_notify_foreach_carrier *carrier) 
-{
-	GNOME_Pilot_Client cb;
-	
-	g_return_if_fail(IOR!=NULL);
-	g_assert(strncmp(IOR,"IOR:",4)==0);
-
-	cb = CORBA_ORB_string_to_object(orb,(CORBA_char*)IOR,&ev);
-	if(ev._major != CORBA_NO_EXCEPTION) {
-		LOG(("Client appears to be disconnected..."));
-		g_warning ("%s:%d Exception: %s\n",
-			   __FILE__,__LINE__, CORBA_exception_id (&ev));
-		CORBA_exception_free(&ev);
-		carrier->purge_list = g_slist_prepend(carrier->purge_list,
-						      g_strdup(IOR));  
-	} else {
-		switch(carrier->action) {
-		case CALL_CONNECT:
-			GNOME_Pilot_Client_connect(cb, 
-						   carrier->id, 
-						   carrier->ptr1,&ev);
-			break;
-		case CALL_DISCONNECT:
-			GNOME_Pilot_Client_disconnect(cb, 
-						      carrier->id, &ev);
-			break;
-		case CALL_CONDUIT_MESSAGE:
-			GNOME_Pilot_Client_conduit_message(cb, 
-							   carrier->id, 
-							   carrier->ptr1, 
-							   carrier->ptr2, &ev);
-			break;
-		case CALL_DAEMON_MESSAGE:
-			GNOME_Pilot_Client_daemon_message(cb, 
-							  carrier->id, 
-							  carrier->ptr1 ? carrier->ptr1 : "", 
-							  carrier->ptr2, &ev);
-			break;
-		case CALL_DAEMON_ERROR:
-			GNOME_Pilot_Client_daemon_error (cb, 
-							 carrier->id, 
-							 carrier->ptr2, &ev);
-			break;
-		case CALL_CONDUIT_ERROR:
-			GNOME_Pilot_Client_conduit_error(cb, 
-							 carrier->id, 
-							 carrier->ptr1, 
-							 carrier->ptr2, &ev);
-			break;
-		case CALL_CONDUIT_PROGRESS:
-			GNOME_Pilot_Client_conduit_progress(cb, 
-							    carrier->id, 
-							    carrier->ptr1, 
-							    carrier->long1,
-							    carrier->long2, &ev);
-			break;
-		case CALL_OVERALL_PROGRESS:
-			GNOME_Pilot_Client_overall_progress(cb, 
-							    carrier->id, 
-							    carrier->long1,
-							    carrier->long2, &ev);
-			break;
-		case CALL_CONDUIT_BEGIN:
-			GNOME_Pilot_Client_conduit_start(cb, 
-							 carrier->id, 
-							 carrier->ptr1, 
-							 carrier->ptr2, &ev);
-			break;
-		case CALL_CONDUIT_END:
-			GNOME_Pilot_Client_conduit_end(cb, 
-						       carrier->id,
-						       carrier->ptr1, &ev);
-			break;
-		}
-		if(ev._major != CORBA_NO_EXCEPTION) {
-			LOG(("Client appears to be disconnected..."));
-			LOGEXN (ev);
-			CORBA_exception_free(&ev);
-			carrier->purge_list = g_slist_prepend(carrier->purge_list,
-							      g_strdup(IOR)); 
-			return; 
-		  
-
-		}    
-		CORBA_Object_release(cb,&ev);
-		CORBA_exception_free(&ev);
-	}
-}
-
-/********************************************************************************/
-/*
-                                                                                */
-void 
-orbed_notify_connect(const gchar *pilot_id, 
-		     struct PilotUser user_info) 
-{
-	GNOME_Pilot_UserInfo user_info_orbed;
-	GPilotd_notify_foreach_carrier carrier;
-	GPilotd_Orb_Pilot_Notifications *notifications;
-
-	if((notifications = g_hash_table_lookup(orb_context->notifications,pilot_id))==NULL) {
-		return;
-	}
-
-	user_info_orbed.userID = user_info.userID;
-	user_info_orbed.username = g_strdup(user_info.username);
-
-	carrier.id = g_strdup(pilot_id);
-	carrier.ptr1 = &user_info_orbed;
-	carrier.purge_list = NULL;
-	carrier.action = CALL_CONNECT;
-#ifdef DEBUG_CODE
-	LOG(("corba: orbed_notify_user, notifications->connect.size = %d, id = %s",
-	    g_slist_length(notifications->connect),pilot_id));
-#endif
-	g_slist_foreach(notifications->connect,
-			(GFunc)orbed_notify_multi_purpose_foreach,
-			&carrier);
-
-	/* FIXME: See note 1 at the end of this file */
-	if(carrier.purge_list)
-		purge_ior_foreach(pilot_id,carrier.purge_list);
-
-	g_free(user_info_orbed.username);
-	g_free(carrier.id);
-}
-
-/********************************************************************************/
-/*
-                                                                                */
-void 
-orbed_notify_disconnect(const gchar *pilot_id) 
-{
-	GPilotd_notify_foreach_carrier carrier;
-	GPilotd_Orb_Pilot_Notifications *notifications;
-
-	g_return_if_fail(pilot_id!=NULL);
-	if((notifications = g_hash_table_lookup(orb_context->notifications,pilot_id))==NULL) {
-		return;
-	}
-	carrier.id = g_strdup(pilot_id);
-	carrier.purge_list = NULL;
-	carrier.action = CALL_DISCONNECT;
-#ifdef DEBUG_CODE
-	LOG(("corba: orbed_notify_user, notifications->disconnect.size = %d, id = %s",
-	    g_slist_length(notifications->disconnect),pilot_id));
-#endif
-	g_slist_foreach(notifications->disconnect,
-			(GFunc)orbed_notify_multi_purpose_foreach,
-			&carrier);
-
-	/* FIXME: See note 1 at the end of this file */
-	if(carrier.purge_list)
-		purge_ior_foreach(pilot_id,carrier.purge_list);
-
-	g_free(carrier.id);
-}
-
-/********************************************************************************/
-/*
-                                                                                */
-void 
-orbed_notify_completion(GPilotRequest **req) 
-{
-	GNOME_Pilot_Client cb;
-	gchar *pilot_name;
-
-	LOG(("orbed_notify_completion(...)"));
-
-	g_return_if_fail(req!=NULL);
-	g_return_if_fail(*req!=NULL);
-
-	/* If there is no client to notify, just purge request and return */
-	if((*req)->client_id==NULL) {
-		LOG(("%s: no client_id in request",G_GNUC_PRETTY_FUNCTION));
-		gpc_queue_purge_request(req);
-		return;
-	}
-	LOG(("%s: client_id = %.20s",G_GNUC_PRETTY_FUNCTION,(*req)->client_id));
-
-	/* check the client id is a IOR */
-	g_return_if_fail(strncmp((*req)->client_id,"IOR:",4)==0);
-
-	/* resolve pilot id */
-	pilot_name = pilot_name_from_id((*req)->pilot_id,orb_context->gpilotd_context);
-
-	/* get the ior, if it fails, print exception and purge request */
-	cb = CORBA_ORB_string_to_object(orb,(CORBA_char*)(*req)->client_id,&ev);
-	if(ev._major != CORBA_NO_EXCEPTION) {
-		LOG(("unable to resolve object for IOR"));
-		LOGEXN (ev);
-		CORBA_exception_free(&ev);
-		/* FIXME: This purges monitors for the client.
-		   Note that only monitors on the pilot that just synced are purged,
-		   this can be considered a leak (if the pilot never syncs). */
-		if (pilot_name != NULL)
-			monitor_off_helper(pilot_name,(*req)->client_id);
-		gpc_queue_purge_request(req);
-		return;
-	}
-
-	/* otherwise return notification and purge */	
-	GNOME_Pilot_Client_request_completed(cb, 
-					     pilot_name==NULL?"":pilot_name, 
-					     (*req)->handle,&ev);
-	if(ev._major != CORBA_NO_EXCEPTION) {
-		LOGEXN (ev);
-		CORBA_exception_free(&ev);
-		/* FIXME: This purges monitors for the client.
-		   Note that only monitors on the pilot that just synced are purged,
-		   this can be considered a leak (if the pilot never syncs). */
-		if (pilot_name != NULL)
-			monitor_off_helper(pilot_name,(*req)->client_id);
-		gpc_queue_purge_request(req);
-		return;
-	}
-	CORBA_Object_release(cb,&ev);
-	CORBA_exception_free(&ev);
-	gpc_queue_purge_request(req);
-	g_free(pilot_name);
-}
-
-/********************************************************************************/
-/*
-                                                                                */
-void 
-orbed_notify_userinfo(struct PilotUser user_info,
-		      GPilotRequest **req) 
-{
-	GNOME_Pilot_UserInfo user;
-	GNOME_Pilot_Client cb;
-
-	g_return_if_fail(req!=NULL);
-	g_return_if_fail(*req!=NULL);
-	if((*req)->client_id==NULL) return;
-	g_return_if_fail(strncmp((*req)->client_id,"IOR:",4)==0);
-
-	cb = CORBA_ORB_string_to_object(orb,(CORBA_char*)(*req)->client_id,&ev);
-
-	if(ev._major != CORBA_NO_EXCEPTION) {
-		LOGEXN (ev);
-		CORBA_exception_free(&ev);
-		return;
-	}
-
-	user.userID = user_info.userID;
-	user.username = g_strdup(user_info.username);
-  
-	GNOME_Pilot_Client_userinfo_requested(cb, (*req)->cradle, &user,&ev);
-	if(ev._major != CORBA_NO_EXCEPTION) {
-		LOGEXN (ev);
-		CORBA_exception_free(&ev);
-		return;
-	}
-	CORBA_Object_release(cb,&ev);
-	CORBA_exception_free(&ev);
-  
-	g_free(user.username);
-}
-
-/********************************************************************************/
-/*
-                                                                                */
-void 
-orbed_notify_sysinfo(gchar *pilot_id,
-		     struct SysInfo sysinfo,
-		     struct CardInfo cardinfo,
-		     GPilotRequest **req) 
-{
-	GNOME_Pilot_SysInfo _sysinfo;
-	GNOME_Pilot_Client cb;
-
-	g_assert(strncmp((*req)->client_id,"IOR:",4)==0);
-
-	cb = CORBA_ORB_string_to_object(orb,(CORBA_char*)(*req)->client_id,&ev);
-
-	if(ev._major != CORBA_NO_EXCEPTION) {
-		LOGEXN (ev);
-		CORBA_exception_free(&ev);
-		return;
-	}
-/*
-	g_message ("sysinfo.romVersion = %lu", sysinfo.romVersion);
-	g_message ("sysinfo.name = %s", sysinfo.name);
-	g_message ("cardinfo.version = %d", cardinfo.version);
-	g_message ("cardinfo.creation = %lu", cardinfo.creation);
-	g_message ("cardinfo.name = %s", cardinfo.name);
-	g_message ("cardinfo.manufacturer = %s", cardinfo.manufacturer);
-*/
-	_sysinfo.romSize = cardinfo.romSize/1024;
-	_sysinfo.ramSize = cardinfo.ramSize/1024;
-	_sysinfo.ramFree = cardinfo.ramFree/1024;
-	_sysinfo.name = g_strdup(cardinfo.name);
-	_sysinfo.manufacturer = g_strdup(cardinfo.manufacturer);
-	_sysinfo.creation = cardinfo.creation;
-	_sysinfo.romVersion = sysinfo.romVersion;
-
-	GNOME_Pilot_Client_sysinfo_requested(cb, pilot_id,&_sysinfo,&ev);
-	if(ev._major != CORBA_NO_EXCEPTION) {
-		LOGEXN (ev);
-		CORBA_exception_free(&ev);
-		return;
-	}
-	CORBA_Object_release(cb,&ev);
-	CORBA_exception_free(&ev);
-}
-
-/********************************************************************************/
-/*
-                                                                                */
-void 
-orbed_notify_timeout(guint handle) {
-	/* FIXME: implement me ! */
-}
-
-
-/********************************************************************************/
-/*
-                                                                                */
-void 
-orbed_notify_conduit_start(gchar *pilot_id,
-			   GnomePilotConduit *conduit,
-			   GnomePilotConduitSyncType synctype) {
-	GPilotd_notify_foreach_carrier carrier;
-	GPilotd_Orb_Pilot_Notifications *notifications;
-	
-	if((notifications = g_hash_table_lookup(orb_context->notifications,pilot_id))==NULL) {
-		return;
-	}
-
-	carrier.id = g_strdup(pilot_id);
-	carrier.ptr1 = gnome_pilot_conduit_get_name(conduit);
-	if(GNOME_IS_PILOT_CONDUIT_STANDARD(conduit))
-		carrier.ptr2 = g_strdup(gnome_pilot_conduit_standard_get_db_name(GNOME_PILOT_CONDUIT_STANDARD(conduit)));
-	else
-		carrier.ptr2 = g_strdup(_("(unknown DB)"));
-	carrier.purge_list = NULL;
-	carrier.action = CALL_CONDUIT_BEGIN;
-	g_slist_foreach(notifications->conduit,
-			(GFunc)orbed_notify_multi_purpose_foreach,
-			&carrier);
-	/* FIXME: See note 1 at the end of this file */
-	if(carrier.purge_list) purge_ior_foreach(pilot_id,carrier.purge_list);
-	g_free(carrier.id);
-	g_free(carrier.ptr1);
-	g_free(carrier.ptr2);
-}
-
-/********************************************************************************/
-/*
-                                                                                */
-void 
-orbed_notify_conduit_end(gchar *pilot_id,
-			 GnomePilotConduit *conduit) {
-	GPilotd_notify_foreach_carrier carrier;
-	GPilotd_Orb_Pilot_Notifications *notifications;
-	
-	if((notifications = g_hash_table_lookup(orb_context->notifications,pilot_id))==NULL) {
-		return;
-	}
-
-	carrier.id = g_strdup(pilot_id);
-	carrier.ptr1 = gnome_pilot_conduit_get_name(conduit);
-	carrier.purge_list = NULL;
-	carrier.action = CALL_CONDUIT_END;
-	g_slist_foreach(notifications->conduit,
-			(GFunc)orbed_notify_multi_purpose_foreach,
-			&carrier);
-	/* FIXME: See note 1 at the end of this file */
-	if(carrier.purge_list) purge_ior_foreach(pilot_id,carrier.purge_list);
-	g_free(carrier.id);
-	g_free(carrier.ptr1);
-}
-
-/********************************************************************************/
-/*
-                                                                                */
-void 
-orbed_notify_conduit_error(gchar *pilot_id,				
-			   GnomePilotConduit *conduit,
-			   gchar *message) {
-	GPilotd_notify_foreach_carrier carrier;
-	GPilotd_Orb_Pilot_Notifications *notifications;
-	
-	g_assert (pilot_id);
-	g_assert (message);
-
-	if((notifications = g_hash_table_lookup(orb_context->notifications,pilot_id))==NULL) {
-		return;
-	}
-
-	carrier.id = g_strdup(pilot_id);
-	carrier.ptr1 = gnome_pilot_conduit_get_name(conduit);
-	carrier.ptr2 = message;
-	carrier.purge_list = NULL;
-	carrier.action = CALL_CONDUIT_ERROR;
-	g_slist_foreach(notifications->conduit,
-			(GFunc)orbed_notify_multi_purpose_foreach,
-			&carrier);
-	/* FIXME: See note 1 at the end of this file */
-	if(carrier.purge_list) purge_ior_foreach(pilot_id,carrier.purge_list);
-	g_free(carrier.id);
-	g_free(carrier.ptr1);
-}
-
-/********************************************************************************/
-/*
-                                                                                */
-void 
-orbed_notify_conduit_message(gchar *pilot_id,				
-			     GnomePilotConduit *conduit,
-			     gchar *message) {
-	GPilotd_notify_foreach_carrier carrier;
-	GPilotd_Orb_Pilot_Notifications *notifications;
-	
-	g_assert (pilot_id);
-	g_assert (message);
-
-	if((notifications = g_hash_table_lookup(orb_context->notifications,pilot_id))==NULL) {
-		return;
-	}
-
-	carrier.id = g_strdup(pilot_id);
-	carrier.ptr1 = gnome_pilot_conduit_get_name(conduit);
-	carrier.ptr2 = message;
-	carrier.purge_list = NULL;
-	carrier.action = CALL_CONDUIT_MESSAGE;
-	g_slist_foreach(notifications->conduit,
-			(GFunc)orbed_notify_multi_purpose_foreach,
-			&carrier);
-	/* FIXME: See note 1 at the end of this file */
-	if(carrier.purge_list) purge_ior_foreach(pilot_id,carrier.purge_list);
-	g_free(carrier.id);
-	g_free(carrier.ptr1);
-}
-
-void 
-orbed_notify_daemon_message(gchar *pilot_id,				
-			    GnomePilotConduit *conduit,
-			    gchar *message) {
-	GPilotd_notify_foreach_carrier carrier;
-	GPilotd_Orb_Pilot_Notifications *notifications;
-	
-	g_assert (pilot_id);
-	g_assert (message);
-
-	if((notifications = g_hash_table_lookup(orb_context->notifications,pilot_id))==NULL) {
-		return;
-	}
-
-	carrier.id = g_strdup(pilot_id);
-	carrier.ptr1 = conduit ? gnome_pilot_conduit_get_name(conduit) : NULL;
-	carrier.ptr2 = message;
-	carrier.purge_list = NULL;
-	carrier.action = CALL_DAEMON_MESSAGE;
-	g_slist_foreach(notifications->conduit,
-			(GFunc)orbed_notify_multi_purpose_foreach,
-			&carrier);
-	/* FIXME: See note 1 at the end of this file */
-	if(carrier.purge_list) purge_ior_foreach(pilot_id,carrier.purge_list);
-	g_free(carrier.id);
-	g_free(carrier.ptr1);
-}
-
-void 
-orbed_notify_daemon_error (gchar *pilot_id,				
-			   gchar *message) {
-	GPilotd_notify_foreach_carrier carrier;
-	GPilotd_Orb_Pilot_Notifications *notifications;
-	
-	g_assert (pilot_id);
-	g_assert (message);
-
-	if((notifications = g_hash_table_lookup(orb_context->notifications,pilot_id))==NULL) {
-		return;
-	}
-
-	carrier.id = g_strdup(pilot_id);
-	carrier.ptr2 = message;
-	carrier.purge_list = NULL;
-	carrier.action = CALL_DAEMON_ERROR;
-	g_slist_foreach(notifications->conduit,
-			(GFunc)orbed_notify_multi_purpose_foreach,
-			&carrier);
-	/* FIXME: See note 1 at the end of this file */
-	if(carrier.purge_list) purge_ior_foreach(pilot_id,carrier.purge_list);
-	g_free(carrier.id);
-	g_free(carrier.ptr1);
-}
-
-void 
-orbed_notify_conduit_progress(gchar *pilot_id,				
-			      GnomePilotConduit *conduit,
-			      int current, 
-			      int total) {
-	GPilotd_notify_foreach_carrier carrier;
-	GPilotd_Orb_Pilot_Notifications *notifications;
-	
-	g_assert (pilot_id);
-	g_assert (conduit);
-
-	if((notifications = g_hash_table_lookup(orb_context->notifications,pilot_id))==NULL) {
-		return;
-	}
-
-	carrier.id = g_strdup(pilot_id);
-	carrier.ptr1 = gnome_pilot_conduit_get_name(conduit);
-	carrier.long1 = current;
-	carrier.long2 = total;
-	carrier.purge_list = NULL;
-	carrier.action = CALL_CONDUIT_PROGRESS;
-	g_slist_foreach(notifications->conduit,
-			(GFunc)orbed_notify_multi_purpose_foreach,
-			&carrier);
-	/* FIXME: See note 1 at the end of this file */
-	if(carrier.purge_list) purge_ior_foreach(pilot_id,carrier.purge_list);
-	g_free(carrier.id);
-	g_free(carrier.ptr1);
-}
-
-void 
-orbed_notify_overall_progress(gchar *pilot_id,				
-			      int current, 
-			      int total) {
-	GPilotd_notify_foreach_carrier carrier;
-	GPilotd_Orb_Pilot_Notifications *notifications;
-	
-	g_assert (pilot_id);
-
-	if((notifications = g_hash_table_lookup(orb_context->notifications,pilot_id))==NULL) {
-		return;
-	}
-
-	carrier.id = g_strdup(pilot_id);
-	carrier.long1 = current;
-	carrier.long2 = total;
-	carrier.purge_list = NULL;
-	carrier.action = CALL_OVERALL_PROGRESS;
-	g_slist_foreach(notifications->conduit,
-			(GFunc)orbed_notify_multi_purpose_foreach,
-			&carrier);
-	/* FIXME: See note 1 at the end of this file */
-	if(carrier.purge_list) purge_ior_foreach(pilot_id,carrier.purge_list);
-	g_free(carrier.id);
-}
-
-/********************************************************************************/
-
-void 
-gpilotd_corba_init_context(GPilotContext *context) 
-{
-	orb_context = g_new(GPilotd_Orb_Context,sizeof(GPilotd_Orb_Context));
-	orb_context->monitors = g_hash_table_new(g_str_hash,g_str_equal);
-	orb_context->notifications = g_hash_table_new(g_str_hash,g_str_equal);
-	orb_context->gpilotd_context = context;
-}
-
-/*
-  Now the follows the stuff that tries to free all that
-  has been allocated. Helps in tracking down leaks 
-*/
-
-static void
-cleanup_code_g_free(gpointer a,gpointer b) 
-{
-	g_free(a);
-}
-
-static void
-cleanup_code_monitors_remover(gchar *key,
-			      GSList **value,
-			      gpointer data) 
-{
-	g_free(key);
-	if (value) g_slist_foreach(*value,cleanup_code_g_free,NULL);
-}
-
-static void 
-cleanup_code_notifications_remover(gchar *key,
-				   GPilotd_Orb_Pilot_Notifications *value,
-				   gpointer data) 
-{
-	g_free(key);
-	if (value){
-		g_slist_foreach(value->connect,cleanup_code_g_free,NULL);
-		g_slist_foreach(value->disconnect,cleanup_code_g_free,NULL);
-		g_slist_foreach(value->request_complete,cleanup_code_g_free,NULL);
-		g_slist_foreach(value->request_timeout,cleanup_code_g_free,NULL);
-		g_slist_foreach(value->backup,cleanup_code_g_free,NULL);
-		g_slist_foreach(value->conduit,cleanup_code_g_free,NULL);
-		g_slist_foreach(value->userinfo_requested,cleanup_code_g_free,NULL);
-		g_slist_foreach(value->sysinfo_requested,cleanup_code_g_free,NULL);
-		g_slist_foreach(value->userinfo_sent,cleanup_code_g_free,NULL);
-		
-		g_slist_free(value->connect);
-		g_slist_free(value->disconnect);
-		g_slist_free(value->request_complete);
-		g_slist_free(value->request_timeout);
-		g_slist_free(value->backup);
-		g_slist_free(value->conduit);
-		g_slist_free(value->userinfo_requested);
-		g_slist_free(value->sysinfo_requested);
-		g_slist_free(value->userinfo_sent);
-		g_free(value);
-	}
-
-}
-
-void 
-gpilotd_corba_clean_up(void) 
-{
-	g_hash_table_foreach_remove(orb_context->monitors,
-				    (GHRFunc)cleanup_code_monitors_remover,
-				    NULL);
-	g_hash_table_destroy(orb_context->monitors);
-	g_hash_table_foreach_remove(orb_context->notifications,
-				    (GHRFunc)cleanup_code_notifications_remover,
-				    NULL);
-	g_hash_table_destroy(orb_context->notifications);
-	g_free(orb_context);
-}
-
-/* Now the cleanup stuff ends */
-
-void 
-gpilotd_corba_quit(void) 
-{
-	gpilotd_corba_clean_up();
-	CORBA_ORB_shutdown(orb, CORBA_FALSE, &ev);
-}
-
-void gpilotd_corba_init(int *argc, 
-			char **argv,
-			GPilotContext **context)
-{
-	PortableServer_ObjectId objid = {0, sizeof("gpilotd"), (unsigned char *) "gpilotd" };
-	PortableServer_POA the_poa;
-	GNOME_Pilot_Daemon acc;
-	static gboolean object_initialised = FALSE;
-	Bonobo_RegistrationResult result;
-
-	if ( object_initialised ) return;
-
-	object_initialised = TRUE;
-
-	CORBA_exception_init(&ev);
-
-	orb = bonobo_activation_orb_get();
-
-	*context = gpilot_context_new();
-	gpilot_context_init_user (*context);
-	gpilotd_corba_init_context(*context);
-
-	the_poa = (PortableServer_POA)CORBA_ORB_resolve_initial_references(orb, "RootPOA", &ev);
-	g_return_if_fail(ev._major == CORBA_NO_EXCEPTION);
-
-	POA_GNOME_Pilot_Daemon__init(&daemon_servant, &ev);
-	g_return_if_fail(ev._major == CORBA_NO_EXCEPTION);
-
-	PortableServer_POAManager_activate(PortableServer_POA__get_the_POAManager(the_poa, &ev), &ev);
-	g_return_if_fail(ev._major == CORBA_NO_EXCEPTION);
-
-	PortableServer_POA_activate_object_with_id(the_poa, &objid, &daemon_servant, &ev);
-	g_return_if_fail(ev._major == CORBA_NO_EXCEPTION);
-
-	acc = PortableServer_POA_servant_to_reference(the_poa, &daemon_servant, &ev);
-	g_return_if_fail(ev._major == CORBA_NO_EXCEPTION);
-
-	g_message ("Activating CORBA server");
-
-	result = bonobo_activation_active_server_register (
-		"OAFIID:GNOME_Pilot_Daemon", acc);
-	g_message ("bonobo_activation_active_server_register = %d", result);
-	switch (result) {
-	case Bonobo_ACTIVATION_REG_SUCCESS:
-		break;
-	case Bonobo_ACTIVATION_REG_NOT_LISTED:
-		g_message ("Cannot register gpilotd because not listed");
-		exit (1);
-	case Bonobo_ACTIVATION_REG_ALREADY_ACTIVE:
-		g_message ("Cannot register gpilotd because already active");
-		exit (0);
-	case Bonobo_ACTIVATION_REG_ERROR:
-	default:
-		g_message ("Cannot register gpilotd because we suck");
-		exit (1);
-	}
-
-	CORBA_Object_release(acc, &ev);
-	g_return_if_fail(ev._major == CORBA_NO_EXCEPTION);
-
-	if (!bonobo_init (argc, argv)) {
-		g_message ("init_bonobo(): could not initialize Bonobo");
-		exit (EXIT_FAILURE);
-	}
-}
-
-
-/* Notes 
-   
-Note 1:
-
-   This purges monitors for clients to whom communication caused an
-   exception.  Note that only monitors on the pilot that just synced
-   are purged, this can be considered a leak (if the pilot never syncs
-   and a client continously connects/ requests the notification and
-   disconnects)
-
-*/
diff --git a/gpilotd/orbit_daemon_glue.h b/gpilotd/orbit_daemon_glue.h
deleted file mode 100644
index 4aff4ba..0000000
--- a/gpilotd/orbit_daemon_glue.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- *//* 
- * Copyright (C) 1998-2000 Free Software Foundation
- *
- * 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.
- *
- * Authors: Eskil Heyn Olsen
- *
- */
-
-#ifndef __ORBIT_GPILOTD_GLUE__
-#define __ORBIT_GPILOTD_GLUE__
-
-#include "gnome-pilot.h"
-#include "queue_io.h"
-#include "gnome-pilot-structures.h"
-#include <pi-dlp.h>
-
-#define GPC_DEBUG
-
-/* the LOG macro cannot by used without a format */
-#ifdef GPC_DEBUG
-#define LOG(x) g_message x
-#else
-#define LOG(x)
-#endif
-
-
-typedef struct GPilotd_Orb_Context GPilotd_Orb_Context;
-struct GPilotd_Orb_Context { 
-  /* maps from a pilot name GPilotd_Orb_Pilot_Notifications* */ 
-  GHashTable *notifications;
-  /* maps from a client_id to GSList** of pilotnames begin monitored */
-  GHashTable *monitors;
-  GPilotContext *gpilotd_context;
-};
-extern GPilotd_Orb_Context *orb_context;
-
-/* returns next time for request timeout (in secs) */
-/* FIXME: is missing, needed to ensure timeout operations */
-guint get_next_timeout();
-
-/* removes requests with req.timeout!= && req.timeout <=timeout */
-/* FIXME: is missing, needed to ensure timeout operations */
-void remove_timeouts(guint timeout);
-
-/* check if a pilot is currently connceted */
-/* FIXME: is missing, needed to ensure, that noone requests
-   stuff of a syncing pilot */
-gint is_pilot_busy(gchar *pilot_id);
-
-
-/* Prototypes for methods declared in orbit_daemon_glue.c */
-
-GList *get_cradle_events(gchar*);
-GList *get_requests_for_pilot(guint32 pilot_id,GPilotRequestType type);
-
-void orbed_notify_connect(const gchar *pilot_id, struct PilotUser user_info);
-void orbed_notify_disconnect(const gchar *pilot_id);
-void orbed_notify_completion(GPilotRequest **req);
-void orbed_notify_timeout(guint handle);
-void orbed_notify_userinfo(struct PilotUser user_info,GPilotRequest **req);
-void orbed_notify_sysinfo(gchar *pilot_id,
-			  struct SysInfo sysinfo,
-			  struct CardInfo cardinfo,
-			  GPilotRequest **req);
-
-void orbed_notify_conduit_start(gchar *pilot_id,
-				GnomePilotConduit *conduit,
-				GnomePilotConduitSyncType);
-void orbed_notify_conduit_end(gchar *pilot_id,
-			      GnomePilotConduit *conduit);
-void orbed_notify_conduit_error(gchar *pilot_id,				
-				GnomePilotConduit *conduit,
-				gchar *message);
-void orbed_notify_conduit_message(gchar *pilot_id,				
-				  GnomePilotConduit *conduit,
-				  gchar *message);
-void orbed_notify_conduit_progress(gchar *pilot_id,				
-				   GnomePilotConduit *conduit,
-				   gint,gint);
-void orbed_notify_overall_progress(gchar *pilot_id,				
-				   gint,gint);
-void orbed_notify_daemon_message(gchar *pilot_id,				
-				 GnomePilotConduit *conduit,
-				 gchar *message);
-void orbed_notify_daemon_error (gchar *pilot_id,				
-				gchar *message);
-
-void gpilotd_corba_init_context(GPilotContext*);
-void gpilotd_corba_clean_up(void);
-void gpilotd_corba_quit(void);
-void gpilotd_corba_init(int*,char **,GPilotContext**);
-int gpilotd_corba_thread();
-
-gint match_pilot_userID(GPilotPilot *,guint32 *);
-guint32 pilot_id_from_name(const gchar*,GPilotContext*);
-gchar *pilot_name_from_id(guint32,GPilotContext *);
-
-#endif
diff --git a/gpilotd/org.gnome.GnomePilot.service.in b/gpilotd/org.gnome.GnomePilot.service.in
new file mode 100644
index 0000000..45140a5
--- /dev/null
+++ b/gpilotd/org.gnome.GnomePilot.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.GnomePilot
+Exec=@libexecdir@/gpilotd
diff --git a/gpilotd/queue_io.c b/gpilotd/queue_io.c
index 1a06ae7..fdb9531 100644
--- a/gpilotd/queue_io.c
+++ b/gpilotd/queue_io.c
@@ -23,7 +23,7 @@
 #include <glib/gi18n.h>
 #include "queue_io.h"
 #include "gnome-pilot-config.h"
-#include "orbit_daemon_glue.h"
+#include "gpilot-daemon.h"
 
 #define NUMREQ "number-of-requests"
 
@@ -261,7 +261,7 @@ gpc_queue_load_request (guint32 pilot_id, gboolean _type, guint num)
 
 /*
   FIXME: Leaks! gpc_queue_store_requests is called from
-  orbit_daemon_glue in a return call, with strings that are strdupped,
+  gpilot_daemon in a return call, with strings that are strdupped,
   thus they're leaked.
  */
 
diff --git a/idl/.cvsignore b/idl/.cvsignore
deleted file mode 100644
index 3dda729..0000000
--- a/idl/.cvsignore
+++ /dev/null
@@ -1,2 +0,0 @@
-Makefile.in
-Makefile
diff --git a/idl/Makefile.am b/idl/Makefile.am
deleted file mode 100644
index 31d181d..0000000
--- a/idl/Makefile.am
+++ /dev/null
@@ -1,4 +0,0 @@
-idldir = $(datadir)/idl
-idl_DATA = gnome-pilot.idl
-
-EXTRA_DIST = $(idl_DATA)
diff --git a/idl/OChangeLog b/idl/OChangeLog
deleted file mode 100644
index 079c631..0000000
--- a/idl/OChangeLog
+++ /dev/null
@@ -1,51 +0,0 @@
-PLEASE USE TOPLEVEL CHANGELOG 
-	eskil - March 22 2001
-
-2000-03-17  Eskil Heyn Olsen  <deity@eskil.dk>
-
-	* gnome-pilot.idl: added the idl defs for the two get_databases calls.
-
-2000-03-25  Vadim Strizhevsky  <vadim@optonline.net>
-
-	* gnome-pilot.idl: Remove the non-existing get_conduits call.
-	Add missing get_databases_from_cache call.
-
-2000-02-17  Eskil Heyn Olsen  <deity@eskil.dk>
-
-	* gnome-pilot.idl: Made a revive call, that takes a pilot id +
-	dir and cradle to install it to.
-
-2000-01-29  Eskil Heyn Olsen  <deity@eskil.dk>
-
-	* changed the type of progress int to unsigned
-
-1999-12-22  Eskil Heyn Olsen  <deity@eskil.dk>
-
-	* gnome-pilot.idl: Finished the api for
-	message/error/progress/begin/end conduit stuff.
-
-1999-12-14  Eskil Heyn Olsen  <deity@eskil.dk>
-
-	* gnome-pilot.idl: Three new calls. Two to get name/id from
-	id/name, and one to get a basedir from a given pilot name.
-
-1999-11-13  Eskil Heyn Olsen  <deity@eskil.dk>
-
-	* gnome-pilot.idl: Made another comment containing a call that is
-	supposed to let conduits inform users about errors.
-
-1999-11-02  Eskil Heyn Olsen  <deity@eskil.dk>
-
-	* gnome-pilot.idl: Added a comment containing the calls that will
-	be used to implement conduit progress hell.
-
-1999-10-25  Eskil Heyn Olsen  <deity@eskil.dk>
-
-	* gnome-pilot.idl: Modyfied the ConduitOperations, to allow Merges 
-	and conduit default.
-
-1999-10-22  Eskil Olsen <deity@eskil.dk>
-
-	* gnome-pilot.idl: renames stringseq to StringSequence, added
- 	LongSequence and a get_pilot_ids. Also renames get_pilots to
- 	get_pilot_names.
diff --git a/idl/gnome-pilot.idl b/idl/gnome-pilot.idl
deleted file mode 100644
index 237ef18..0000000
--- a/idl/gnome-pilot.idl
+++ /dev/null
@@ -1,272 +0,0 @@
-/* -*- Mode: IDL; indent-tabs-mode: t; tab-width: 8 -*- *//* 
- * Copyright (C) 1998-2000 Free Software Foundation
- *
- * 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.
- *
- * Authors: Eskil Heyn Olsen  <eskil@eskil.org>
- */
-
-
-/*
-   IDL for gpilotd communcation
-   $Id$
-   $Author$
-*/
-
-module GNOME {	
-	module Pilot {
-
-		/* typedefinitions and enums */
-		typedef sequence<string> StringSequence;
-		typedef sequence<long> LongSequence;
-
-		/* exception thrown when requested pilot doesn't exist */
-		exception UnknownPilot {
-			string pilotId;
-		};
-	
-		/* exception thrown when user doesn't exist */
-		exception UnknownUser {
-			string user;
-		};
-	
-		/* exception thrown when conduit doesn't exist */
-		exception UnknownConduit {
-			string conduit;
-		};
-	
-		/* exception thrown when requested file or directory doesn't exist */
-		exception MissingFile {
-		};
-	
-		/* exception thrown when no access to file/directory/pilot is give */
-		exception NoAccess {
-		};
-
-		/* exception thrown when no monitors are on, but client called notify */
-		exception NoMonitors {
-		};
-	  
-		/* exception throw when the given request handle doesn't exist */
-		exception NoSuchHandle {
-		};
-	
-		/* exception thrown when the pilot is already syncing */
-		exception PilotBusy {
-		};
-	 
-		/* execption thrown when the cradle is already in use */
-		exception CradleBusy {
-		};
-
-		enum ConfigErrorType {
-			DEVICE_MISSING,
-			DEVICE_CANNOT_BE_OPENED
-		};
-
-		/* exception thrown when the daemon's config prevents it for doing anything */
-		exception ConfigError {
-			ConfigErrorType errorType;
-			string message;
-		};
-	
-		enum Survival {
-			IMMEDIATE,
-			PERSISTENT
-		};
-	
-		enum EventType {
-			NOTIFY_CONNECT,
-			NOTIFY_DISCONNECT,
-			NOTIFY_BACKUP,
-			NOTIFY_CONDUIT,
-			NOTIFY_REQUEST_COMPLETION,
-			NOTIFY_REQUEST_TIMEOUT,
-			NOTIFY_USERINFO_REQUESTED,
-			NOTIFY_SYSINFO_REQUESTED,
-			NOTIFY_USERINFO_SENT
-		};
-
-		enum ConduitOperation {
-			SYNCHRONIZE,
-			CONDUIT_DEFAULT,
-			COPY_FROM_PILOT,
-			COPY_TO_PILOT,
-			MERGE_FROM_PILOT,
-			MERGE_TO_PILOT
-		};
-	
-		struct UserInfo {
-			unsigned long userID;
-			string username;
-		};
-	
-		struct SysInfo {
-			/* memory is KB's */
-			long romSize;
-			long ramSize;
-			long ramFree;
-			string name;
-			string manufacturer;
-			long creation;
-			long romVersion;
-		};
-	
-		interface Client {
-			attribute string client_id;
-			oneway void connect(in string pilot_id, 
-					    in UserInfo userinfo);
-			oneway void disconnect(in string pilot_id);
-			oneway void request_completed(in string pilot_id,
-						      in unsigned long request_id);
-			/*oneway void backup(in string pilot_id,in string filename); */
-			/*oneway void request_timeout(in string pilot_id,
-			  in unsigned long request_id);*/
-			oneway void userinfo_requested(in string device,
-						       in UserInfo user);
-			oneway void sysinfo_requested(in string pilot_id,
-						      in SysInfo sysinfo);
-
-			/* progress bar additions */
-			oneway void conduit_start(in string pilot_id,
-						  in string conduit, 
-						  in string database);
-			oneway void conduit_progress(in string pilot_id,
-						     in string conduit,
-						     in unsigned long current, 
-						     in unsigned long total);
-			oneway void conduit_end(in string pilot_id,
-						in string conduit);
-			oneway void overall_progress (in string pilot_id,
-						      in unsigned long current,
-						      in unsigned long total);
-
-			/* call that lets a conduit give the user some
-                           sort of info or error message */
-			oneway void daemon_message (in string pilot_id,
-						    in string conduit,
-						    in string message);
-			oneway void daemon_error (in string pilot_id,
-						  in string message);
-			oneway void conduit_message(in string pilot_id, 
-						    in string conduit, 
-						    in string message);
-			oneway void conduit_error(in string pilot_id, 
-						  in string conduit, 
-						  in string message);
-
-			oneway void pause (in boolean on_off);
-
-		};
-	
-		interface Daemon {
-			/* adm calls */
-			void pause(in boolean on_off)
-				raises (NoAccess);
-			void reread_config ()
-				raises (NoAccess);
-			
-			/* A no-operation call, used by client to occasionally
-			   check to see if the daemon has blown up */
-			void noop ();
-
-			/* request operations */
-			unsigned long request_install(in Client cb,
-						      in string pilot_id,
-						      in string file_name,
-						      in string description,
-						      in Survival survival,
-						      in unsigned long timeout)
-				raises(UnknownPilot,MissingFile,NoAccess);
-	
-			unsigned long request_restore(in Client cb,
-						      in string pilot_id,
-						      in string directory,
-						      in Survival survival,
-						      in unsigned long timeout)
-				raises(UnknownPilot,MissingFile,NoAccess);
-
-			unsigned long request_conduit(in Client cb,
-						      in string pilot_id,
-						      in string conduit_name,
-						      in ConduitOperation operation,
-						      in Survival survival,
-						      in unsigned long timeout)
-				raises(UnknownPilot,UnknownConduit,NoAccess);
-	    
-			unsigned long remove_request(in unsigned long handle)
-				raises(NoSuchHandle);
-
-			unsigned long get_system_info(in Client cb,
-						      in string cradle,
-						      in Survival survival,
-						      in unsigned long timeout);
-
-			/* information operations */    
-	
-			StringSequence get_users();
-			StringSequence get_cradles();
-			StringSequence get_pilots();
-
-	
-			LongSequence   get_pilot_ids();
-
-			StringSequence get_pilots_by_user_name(in string user);
-			StringSequence get_pilots_by_user_login(in string uid);
-			string         get_user_name_by_pilot_name(in string pilot_id);
-			string         get_user_login_by_pilot_name(in string pilot_id);
-
-			string         get_pilot_base_dir(in string pilot_id);
-			long           get_pilot_id_from_name(in string pilot_id);
-			string         get_pilot_name_from_id(in long pilot_id);
-			StringSequence get_databases_from_cache(in string pilot_id);
-
-			/* admin operations */
-			unsigned long get_user_info(in Client cb,
-						    in string cradle,
-						    in Survival survival,
-						    in unsigned long timeout);
-			unsigned long set_user_info(in Client cb,
-						    in UserInfo user,
-						    in string cradle,
-						    in boolean continue_sync,
-						    in Survival survival,
-						    in unsigned long timeout);
-			/*
-			  unsigned long set_user_info_if_not_set(in UserInfo user,
-			  in Client cb,
-			  in string cradle,
-			  in Survival survival,
-			  in unsigned long timeout);
-			*/
-	
-			/* Notification operations */
-			void monitor_on(in Client cb, in string pilot_id)
-				raises(UnknownPilot,NoAccess);
-			void monitor_off(in Client cb, in string pilot_id)
-				raises(UnknownPilot,NoAccess);
-	
-			/* if a notify_on is done several times for the same eventtype, 
-			   callback to all callback objects */
-	   
-			void notify_on(in EventType event, in Client cb)
-				raises(NoMonitors);
-			void notify_off(in EventType event, in Client cb)
-				raises(NoMonitors);
-		};
-
-	};
-};
diff --git a/utils/gpilotd-client.c b/utils/gpilotd-client.c
index fa28445..0ee08c6 100644
--- a/utils/gpilotd-client.c
+++ b/utils/gpilotd-client.c
@@ -5,13 +5,12 @@
  */
 #include <config.h>
 
-#include <bonobo-activation/bonobo-activation.h>
-
+#include <glib/gi18n.h>
 #include <libgnome/gnome-init.h>
+
 #include <gpilotd/gnome-pilot-client.h>
 
 GnomePilotClient *gpc;
-CORBA_Environment ev;
 
 int     arg_pause=0,
 	arg_unpause=0,
@@ -19,7 +18,8 @@ int     arg_pause=0,
 	arg_restart=0,
 	arg_setuser = 0,
 	arg_listbases = 0,
-	arg_monitorall=0,
+	arg_listusers = 0,
+	arg_listcradles = 0,
 	arg_monitor,
 	arg_getinfo = 0;
 char
@@ -46,11 +46,12 @@ static GOptionEntry options[] = {
 	{"restore", '\0', 0, G_OPTION_ARG_STRING, &arg_restore, N_("Restore directory"), N_("DIRECTORY")},
 	{"conduit", '\0', 0, G_OPTION_ARG_STRING, &arg_conduit, N_("Run conduit"), N_("CONDUIT")},
 	{"userid", '\0', 0, G_OPTION_ARG_STRING, &arg_username, N_("Username to set"), N_("USERNAME")},
-	{"monitor", 'm', 0, G_OPTION_ARG_NONE, &arg_monitor, N_("Monitor the specified PDA's actions"), NULL},
-	{"monitorall", 'A', 0, G_OPTION_ARG_NONE, &arg_monitorall, N_("Monitor all PDAs"), NULL},
+	{"monitor", 'm', 0, G_OPTION_ARG_NONE, &arg_monitor, N_("Monitor all PDAs"), NULL},
 	{"listpilots", '\0', 0, G_OPTION_ARG_STRING, &arg_list_by_login, N_("list PDAs by login (all for all pilots)"), N_("LOGIN")},
 	{"pilot", '\0', 0, G_OPTION_ARG_STRING, &arg_pilot, N_("Specify PDA to operate on (defaults to MyPDA)"), N_("PILOTNAME")},
 	{"cradle", '\0', 0, G_OPTION_ARG_STRING, &arg_cradle, N_("Specify a cradle to operate on (defaults to Cradle0)"), N_("CRADLENAME")},
+	{"listusers", '\0', 0, G_OPTION_ARG_NONE, &arg_listusers, N_("List users"), NULL},
+	{"listcradles", '\0', 0, G_OPTION_ARG_NONE, &arg_listcradles, N_("List cradles"), NULL},
 	{"listbases", 'l', 0, G_OPTION_ARG_NONE, &arg_listbases, N_("List the specified PDA's bases"), NULL},
 	{NULL},
 };
@@ -73,6 +74,87 @@ pilot_disconnect (GnomePilotClient *gpc,
 };
 
 static void
+daemon_pause (GnomePilotClient *gpc, 
+              gboolean          on_ff, 
+              gpointer          data) {
+	g_message ("daemon pause: %d", on_ff);
+}
+
+static void
+conduit_message (GnomePilotClient *gpc, 
+                 const gchar      *pilot_id,
+                 const gchar      *conduit,
+                 const gchar      *message,
+                 gpointer          data) {
+        g_message ("conduit message: pilot=%s, conduit=%s", pilot_id, conduit);
+        g_message ("conduit message: %s", message);
+}
+
+static void
+daemon_message (GnomePilotClient *gpc, 
+                 const gchar      *pilot_id,
+                 const gchar      *conduit,
+                 const gchar      *message,
+                 gpointer          data) {
+        g_message ("daemon message: pilot=%s, conduit=%s", pilot_id, conduit);
+        g_message ("daemon message: %s", message);
+}
+
+static void
+conduit_error (GnomePilotClient *gpc, 
+                 const gchar      *pilot_id,
+                 const gchar      *conduit,
+                 const gchar      *message,
+                 gpointer          data) {
+        g_message ("conduit error: pilot=%s, conduit=%s", pilot_id, conduit);
+        g_message ("conduit error: %s", message);
+}
+
+static void
+daemon_error (GnomePilotClient *gpc, 
+                 const gchar      *pilot_id,
+                 const gchar      *message,
+                 gpointer          data) {
+        g_message ("daemon error: pilot=%s", pilot_id);
+        g_message ("daemon error: %s", message);
+}
+static void
+start_conduit (GnomePilotClient *gpc, 
+               const gchar      *pilot_id, 
+               const gchar      *conduit, 
+               const gchar      *database,
+	       gpointer          data) {
+	g_message ("start_conduit:   pilot_id=%s, conduit=%s, database=%s", pilot_id, conduit, database);
+};
+
+static void
+end_conduit (GnomePilotClient *gpc, 
+             const gchar      *pilot_id, 
+             const gchar      *conduit, 
+	     gpointer          data) {
+	g_message ("end_conduit:   pilot_id=%s, conduit=%s", pilot_id, conduit);
+};
+
+static void
+progress_conduit (GnomePilotClient *gpc, 
+                  const gchar      *pilot_id, 
+                  const gchar      *conduit, 
+                  guint32           current,
+                  guint32           total,
+                  gpointer          data) {
+	g_message ("progress_conduit:   pilot_id=%s, conduit=%s, current=%u, total=%u", pilot_id, conduit, current, total);
+};
+
+static void
+progress_overall (GnomePilotClient *gpc, 
+                  const gchar      *pilot_id, 
+                  guint32           current,
+                  guint32           total,
+                  gpointer          data) {
+	g_message ("progress_overall:   pilot_id=%s, current=%u, total=%u", pilot_id, current, total);
+};
+
+static void
 pilot_request_completed (GnomePilotClient *gpc, gchar *pilot_id, gint handle, gpointer data) {
 	GList *iterator;
 	gint outstanding_request = 0;
@@ -130,6 +212,30 @@ the_loop (void) {
 	}
 }
 
+static void list_users (void) {
+	GList *list = NULL,*ptr;
+
+	gnome_pilot_client_get_users (gpc, &list);
+	if (list)
+		for (ptr = list; ptr; ptr = ptr->next) {
+			g_message ("user %s", (char*)ptr->data);
+		}
+	else 
+		g_message ("No users");
+}
+
+static void list_cradles (void) {
+	GList *list = NULL,*ptr;
+
+	gnome_pilot_client_get_cradles (gpc, &list);
+	if (list)
+		for (ptr = list; ptr; ptr = ptr->next) {
+			g_message ("cradle %s", (char*)ptr->data);
+		}
+	else 
+		g_message ("No cradle");
+}
+
 static void list_bases (void) {
 	GList *list = NULL,*ptr;
 
@@ -393,37 +499,37 @@ main (int argc, char *argv[]) {
 		revive (NULL);
 	} else if (arg_restore!=NULL) {
 		restore (arg_restore);
-	} else if (arg_conduit!=NULL) {
+	} else if (arg_conduit!=NULL && !arg_monitor) {
 		conduit (arg_conduit);
 	} else if (arg_setuser) {
 		set_user ();
+	} else if (arg_listusers) {
+		list_users ();
+	} else if (arg_listcradles) {
+		list_cradles ();
 	} else if (arg_listbases) {
 		list_bases ();
 	} else if (arg_list_by_login) {
 		list_by_login ();
 	} else if (arg_monitor) {
 		g_message ("Monitor on %s",arg_pilot);
-		gnome_pilot_client_monitor_on (gpc,arg_pilot);
-		gnome_pilot_client_notify_on (gpc,GNOME_Pilot_NOTIFY_CONNECT);
-		gnome_pilot_client_notify_on (gpc,GNOME_Pilot_NOTIFY_DISCONNECT);
 		
 		gnome_pilot_client_connect__pilot_connect (gpc, pilot_connect, NULL);
 		gnome_pilot_client_connect__pilot_disconnect (gpc, pilot_disconnect, &stay_alive);
-
+		gnome_pilot_client_connect__daemon_pause (gpc, daemon_pause, NULL);
+		gnome_pilot_client_connect__message_conduit (gpc, conduit_message, NULL);
+		gnome_pilot_client_connect__message_daemon (gpc, daemon_message, NULL);
+		gnome_pilot_client_connect__error_conduit (gpc, conduit_error, NULL);
+		gnome_pilot_client_connect__error_daemon (gpc, daemon_error, NULL);
+
+                if (arg_conduit) {
+                        gnome_pilot_client_connect__start_conduit (gpc, start_conduit, NULL);
+                        gnome_pilot_client_connect__end_conduit (gpc, end_conduit, NULL);
+                        gnome_pilot_client_connect__progress_conduit (gpc, progress_conduit, NULL);
+                        gnome_pilot_client_connect__progress_overall (gpc, progress_overall, NULL);
+                }
 		the_loop ();
 
-		gnome_pilot_client_notify_off (gpc,GNOME_Pilot_NOTIFY_CONNECT);
-		gnome_pilot_client_notify_off (gpc,GNOME_Pilot_NOTIFY_DISCONNECT);
-		gnome_pilot_client_monitor_off (gpc,arg_pilot);
-	} else if (arg_monitorall) {
-		g_message ("Monitor on all");
-		gnome_pilot_client_monitor_on_all_pilots (gpc);
-
-		gnome_pilot_client_connect__pilot_connect (gpc, pilot_connect, NULL);
-		gnome_pilot_client_connect__pilot_disconnect (gpc, pilot_disconnect, &stay_alive);
-
-		the_loop ();
-		gnome_pilot_client_monitor_off_all_pilots (gpc);		
 	} else if (arg_getinfo) {
 		g_message ("Get SystemInfo");
 		get_system_info ();
diff --git a/utils/gpilotdcm-client.c b/utils/gpilotdcm-client.c
index 865326d..863f5a1 100644
--- a/utils/gpilotdcm-client.c
+++ b/utils/gpilotdcm-client.c
@@ -6,7 +6,6 @@
 #include <config.h>
 
 #include <glib/gi18n.h>
-#include <bonobo-activation/bonobo-activation.h>
 #include <libgnome/gnome-init.h>
 
 #include <libgpilotdCM/gnome-pilot-conduit-management.h>
