aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--configure.ac27
-rw-r--r--lib/Makefile.am17
-rw-r--r--lib/ephy-dbus.c398
-rw-r--r--lib/ephy-dbus.h80
-rw-r--r--lib/ephy-marshal.list1
-rw-r--r--src/Makefile.am8
-rw-r--r--src/ephy-shell.c29
-rw-r--r--src/ephy-shell.h2
9 files changed, 576 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 86aa23254..c7807bf67 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2005-01-10 Christian Persch <chpe@cvs.gnome.org>
+
+ * configure.ac:
+ * lib/Makefile.am:
+ A lib/ephy-dbus.c:
+ A lib/ephy-dbus.h:
+ * lib/ephy-marshal.list:
+ * src/Makefile.am:
+ * src/ephy-shell.c: (ephy_shell_finalize),
+ (ephy_shell_get_dbus_service):
+ * src/ephy-shell.h:
+
+ Add experimental dbus service, disabled by default. Configure with
+ --enable-dbus to enable.
+
2005-01-09 Piers Cornwell <piers@gnome.org>
* data/epiphany.desktop.in
diff --git a/configure.ac b/configure.ac
index a68f3e98b..61ca3b769 100644
--- a/configure.ac
+++ b/configure.ac
@@ -471,7 +471,7 @@ fi
AC_MSG_CHECKING([whether to enable native gtk+ filepicker])
AC_ARG_ENABLE([filepicker],
- AS_HELP_STRING([--enable-filepicker],[Whether to enable the gtk+ native filepicker; not neede when the mozilla build itself has native gtk+ filepicker enabled (default:enabled)]),
+ AS_HELP_STRING([--enable-filepicker],[Whether to enable the gtk+ native filepicker; not needed when the mozilla build itself has native gtk+ filepicker enabled (default:enabled)]),
[filepicker=$enableval],
[filepicker=yes])
AC_MSG_RESULT([$filepicker])
@@ -487,6 +487,31 @@ dnl ***************
AC_CHECK_HEADERS([X11/XF86keysym.h])
+dnl ***********************************
+dnl Check for DBUS and DBUS net monitor
+dnl ***********************************
+
+AC_MSG_CHECKING([whether DBUS support is requested])
+
+enable_dbus=no
+AC_ARG_ENABLE([dbus],
+ AS_HELP_STRING([--enable-dbus],[Enable DBUS (default=no)]),
+ [enable_dbus=yes],
+ [enable_dbus=no])
+
+DBUS_REQUIRED=0.22
+DBUS_GLIB_REQUIRED=0.22
+
+if test x"$enable_dbus" = "xyes" ; then
+ AC_DEFINE([ENABLE_DBUS],[1],[Define if DBUS support is enabled (default=disabled)])
+
+ PKG_CHECK_MODULES([DBUS], [dbus-1 >= $DBUS_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED])
+fi
+
+AM_CONDITIONAL([ENABLE_DBUS], [test "x$enable_dbus" = "xyes"])
+
+AC_MSG_RESULT([$enable_dbus])
+
dnl *******************************
dnl Add warning flags
dnl *******************************
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 749c315b4..e190b9750 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -73,6 +73,23 @@ libephymisc_la_CFLAGS = \
$(EPIPHANY_DEPENDENCY_CFLAGS) \
$(AM_CFLAGS)
+libephymisc_la_LIBADD =
+
+if ENABLE_DBUS
+INST_H_FILES += \
+ ephy-dbus.h
+
+TYPES_H_FILES += \
+ ephy-dbus.h
+
+libephymisc_la_SOURCES += \
+ ephy-dbus.c
+
+libephymisc_la_CFLAGS += $(DBUS_CFLAGS)
+
+libephymisc_la_LIBADD += $(DBUS_LIBS)
+endif
+
BUILT_SOURCES = \
ephy-lib-type-builtins.c \
ephy-lib-type-builtins.h \
diff --git a/lib/ephy-dbus.c b/lib/ephy-dbus.c
new file mode 100644
index 000000000..3b76b0614
--- /dev/null
+++ b/lib/ephy-dbus.c
@@ -0,0 +1,398 @@
+/*
+ * Copyright (C) 2004, 2005 Jean-François Rameau
+ *
+ * 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, 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.
+ *
+ * $Id$
+ */
+
+#include "config.h"
+
+#include "ephy-dbus.h"
+#include "ephy-lib-type-builtins.h"
+#include "ephy-marshal.h"
+#include "ephy-debug.h"
+
+#define EPHY_DBUS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_DBUS, EphyDbusPrivate))
+
+struct _EphyDbusPrivate
+{
+ DBusConnection *session_bus;
+ DBusConnection *system_bus;
+ guint reconnect_timeout_id;
+};
+
+enum
+{
+ CONNECTED,
+ DISCONNECTED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static GObjectClass *parent_class = NULL;
+
+/* Epiphany's DBUS identification */
+static const char* epiphany_dbus_service = "org.gnome.Epiphany";
+static const char* epiphany_dbus_object_path = "/org/gnome/Epiphany";
+
+/* This function is called by DBUS when a message directed at the
+ * Epiphany's object path arrives (provided we're the registered instance!)
+ * it routes the message to the correct handler
+ */
+static DBusHandlerResult path_message_func (DBusConnection *connection,
+ DBusMessage *message,
+ gpointer data);
+
+/* Filter signals form session bus */
+static DBusHandlerResult session_filter_func (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data);
+/* Filter signals from system bus */
+static DBusHandlerResult system_filter_func (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data);
+
+/* Both connect to their respective bus */
+static void ephy_dbus_connect_to_session_bus (EphyDbus *dbus);
+static void ephy_dbus_connect_to_system_bus (EphyDbus *dbus);
+
+static DBusObjectPathVTable call_vtable = {
+ NULL,
+ path_message_func,
+ NULL,
+};
+
+/* implementation of the DBUS helpers */
+
+static gboolean
+ephy_dbus_connect_to_session_bus_cb (gpointer user_data)
+{
+ EphyDbus *dbus = EPHY_DBUS (user_data);
+ gboolean success;
+
+ ephy_dbus_connect_to_session_bus (dbus);
+
+ success = (dbus->priv->session_bus != NULL);
+ if (success)
+ {
+ dbus->priv->reconnect_timeout_id = 0;
+ }
+
+ return !success;
+}
+
+static gboolean
+ephy_dbus_connect_to_system_bus_cb (gpointer user_data)
+{
+ EphyDbus *dbus = EPHY_DBUS (user_data);
+
+ ephy_dbus_connect_to_system_bus (dbus);
+
+ return dbus->priv->system_bus != NULL;
+}
+
+static DBusHandlerResult
+session_filter_func (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ EphyDbus *dbus = EPHY_DBUS (user_data);
+
+ if (dbus_message_is_signal (message,
+ DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
+ "Disconnected"))
+ {
+ LOG ("EphyDbus disconnected from session bus")
+
+ dbus_connection_unref (dbus->priv->session_bus);
+ dbus->priv->session_bus = NULL;
+
+ g_signal_emit (dbus, signals[DISCONNECTED], 0, EPHY_DBUS_SESSION);
+
+ /* try to reconnect later ... */
+ dbus->priv->reconnect_timeout_id =
+ g_timeout_add (3000, (GSourceFunc) ephy_dbus_connect_to_session_bus_cb, dbus);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static DBusHandlerResult
+system_filter_func (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ EphyDbus *dbus = EPHY_DBUS (user_data);
+
+ LOG ("EphyDbus filtering message from system bus")
+
+ if (dbus_message_is_signal (message,
+ DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
+ "Disconnected"))
+ {
+ LOG ("EphyDbus disconnected from system bus")
+
+ dbus_connection_unref (dbus->priv->system_bus);
+ dbus->priv->system_bus = NULL;
+
+ g_signal_emit (dbus, signals[DISCONNECTED], 0, EPHY_DBUS_SYSTEM);
+
+ /* try to reconnect later ... */
+ g_timeout_add (3000, ephy_dbus_connect_to_system_bus_cb, (gpointer)dbus);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static void
+ephy_dbus_connect_to_system_bus (EphyDbus *dbus)
+{
+ DBusConnection *bus;
+ DBusError error;
+
+ LOG ("EphyDbus connecting to system DBUS")
+
+ dbus_error_init (&error);
+ bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (bus == NULL)
+ {
+ g_warning ("Failed to connect to the system D-BUS: %s", error.message);
+ dbus_error_free (&error);
+ return;
+ }
+ dbus_connection_setup_with_g_main (bus, NULL);
+
+ dbus_connection_add_filter (bus, system_filter_func, dbus, NULL);
+ dbus_bus_add_match (bus,
+ "type='signal',interface='org.freedesktop.NetworkManager'",
+ &error);
+ if (dbus_error_is_set(&error)) {
+ g_warning ("Couldn't register signal handler (system bus): %s: %s",
+ error.name, error.message);
+ return;
+ }
+
+ dbus->priv->system_bus = bus;
+
+ g_signal_emit (dbus, signals[CONNECTED], 0, EPHY_DBUS_SYSTEM);
+}
+
+static void
+ephy_dbus_connect_to_session_bus (EphyDbus *dbus)
+{
+ DBusError error;
+ DBusConnection *bus;
+
+ LOG ("EphyDbus connecting to session DBUS")
+
+ dbus_error_init (&error);
+ bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
+
+ if (!bus) {
+ g_warning ("EphyDbus failed to connect to the session D-BUS: %s", error.message);
+ dbus_error_free (&error);
+ return;
+ }
+
+ dbus_connection_add_filter (bus, session_filter_func, dbus, NULL);
+
+ dbus_bus_acquire_service (bus, epiphany_dbus_service, 0, &error);
+ if (dbus_error_is_set (&error)) {
+ g_warning ("EphyDbus failed to acquire epiphany service");
+ dbus_error_free (&error);
+ return;
+ }
+
+ dbus_connection_register_object_path (bus,
+ epiphany_dbus_object_path,
+ &call_vtable, dbus);
+
+ dbus_bus_acquire_service (bus, epiphany_dbus_service, 0, NULL);
+
+ dbus_connection_setup_with_g_main (bus, NULL);
+
+ dbus->priv->session_bus = bus;
+
+ g_signal_emit (dbus, signals[CONNECTED], 0, EPHY_DBUS_SESSION);
+}
+
+static void
+ephy_dbus_disconnect_bus (DBusConnection *bus)
+{
+ if (bus != NULL) {
+
+ dbus_connection_disconnect (bus);
+ dbus_connection_unref (bus);
+ }
+}
+
+static DBusHandlerResult
+path_message_func (DBusConnection *connection,
+ DBusMessage *message,
+ gpointer data)
+{
+ DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ LOG ("EphyDbus filtering path messagefrom session bus")
+
+ if (dbus_message_is_method_call (message, epiphany_dbus_service, "load"))
+ {
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ return result;
+}
+
+
+/* Public methods */
+
+void
+ephy_dbus_startup (EphyDbus *dbus)
+{
+ g_return_if_fail (EPHY_IS_DBUS (dbus));
+
+ LOG ("EphyDbus startup")
+
+ ephy_dbus_connect_to_session_bus (dbus);
+ ephy_dbus_connect_to_system_bus (dbus);
+}
+
+void
+ephy_dbus_shutdown (EphyDbus *dbus)
+{
+ g_return_if_fail (EPHY_IS_DBUS (dbus));
+
+ LOG ("EphyDbus shutdown")
+
+ if (dbus->priv->reconnect_timeout_id != 0)
+ {
+ g_source_remove (dbus->priv->reconnect_timeout_id);
+ dbus->priv->reconnect_timeout_id = 0;
+ }
+
+ ephy_dbus_disconnect_bus (dbus->priv->session_bus);
+ ephy_dbus_disconnect_bus (dbus->priv->system_bus);
+}
+
+DBusConnection *
+ephy_dbus_get_bus (EphyDbus *dbus,
+ EphyDbusBus kind)
+{
+ DBusConnection *bus = NULL;
+
+ g_return_val_if_fail (EPHY_IS_DBUS (dbus), NULL);
+
+ switch (kind)
+ {
+ case EPHY_DBUS_SYSTEM:
+ bus = dbus->priv->system_bus;
+ break;
+ case EPHY_DBUS_SESSION:
+ bus = dbus->priv->session_bus;
+ break;
+ default:
+ bus = dbus->priv->session_bus;
+ }
+ return bus;
+}
+
+/* Class implementation */
+
+static void
+ephy_dbus_init (EphyDbus *dbus)
+{
+ dbus->priv = EPHY_DBUS_GET_PRIVATE (dbus);
+
+ LOG ("EphyDbus initialising")
+}
+
+static void
+ephy_dbus_finalize (GObject *object)
+{
+ EphyDbus *dbus = EPHY_DBUS (object);
+
+ ephy_dbus_shutdown (dbus);
+
+ LOG ("EphyDbus finalised")
+
+ parent_class->finalize (object);
+}
+
+static void
+ephy_dbus_class_init (EphyDbusClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ object_class->finalize = ephy_dbus_finalize;
+
+ signals[CONNECTED] =
+ g_signal_new ("connected",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (EphyDbusClass, connected),
+ NULL, NULL,
+ ephy_marshal_VOID__ENUM,
+ G_TYPE_NONE,
+ 1,
+ EPHY_TYPE_DBUS_BUS);
+
+ signals[DISCONNECTED] =
+ g_signal_new ("disconnected",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (EphyDbusClass, disconnected),
+ NULL, NULL,
+ ephy_marshal_VOID__ENUM,
+ G_TYPE_NONE,
+ 1,
+ EPHY_TYPE_DBUS_BUS);
+
+ g_type_class_add_private (object_class, sizeof(EphyDbusPrivate));
+}
+
+GType
+ephy_dbus_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0))
+ {
+ static const GTypeInfo our_info =
+ {
+ sizeof (EphyDbusClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) ephy_dbus_class_init,
+ NULL,
+ NULL, /* class_data */
+ sizeof (EphyDbus),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) ephy_dbus_init
+ };
+
+ type = g_type_register_static (G_TYPE_OBJECT,
+ "EphyDbus",
+ &our_info, 0);
+ }
+
+ return type;
+}
diff --git a/lib/ephy-dbus.h b/lib/ephy-dbus.h
new file mode 100644
index 000000000..e0c718694
--- /dev/null
+++ b/lib/ephy-dbus.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2004 Jean-François rameau
+ *
+ * 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, 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.
+ *
+ * $Id$
+ */
+
+#ifndef EPHY_DBUS_H
+#define EPHY_DBUS_H
+
+#include <glib-object.h>
+
+/* Yes, we know that DBUS API isn't stable yet */
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_DBUS (ephy_dbus_get_type ())
+#define EPHY_DBUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_DBUS, EphyDbus))
+#define EPHY_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_DBUS, EphyDbusClass))
+#define EPHY_IS_DBUS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_DBUS))
+#define EPHY_IS_DBUS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_DBUS))
+#define EPHY_DBUS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_DBUS, EphyDbusClass))
+
+typedef struct _EphyDbus EphyDbus;
+typedef struct _EphyDbusPrivate EphyDbusPrivate;
+typedef struct _EphyDbusClass EphyDbusClass;
+
+typedef enum
+{
+ EPHY_DBUS_SESSION,
+ EPHY_DBUS_SYSTEM
+} EphyDbusBus;
+
+struct _EphyDbus
+{
+ GObject parent;
+
+ /*< private >*/
+ EphyDbusPrivate *priv;
+};
+
+struct _EphyDbusClass
+{
+ GObjectClass parent_class;
+
+ /* Signals */
+ void (* connected) (EphyDbus *dbus,
+ EphyDbusBus kind);
+ void (* disconnected) (EphyDbus *dbus,
+ EphyDbusBus kind);
+};
+
+GType ephy_dbus_get_type (void);
+
+void ephy_dbus_startup (EphyDbus *dbus);
+
+void ephy_dbus_shutdown (EphyDbus *dbus);
+
+DBusConnection *ephy_dbus_get_bus (EphyDbus *dbus,
+ EphyDbusBus kind);
+
+G_END_DECLS
+
+#endif /* !EPHY_DBUS_H */
diff --git a/lib/ephy-marshal.list b/lib/ephy-marshal.list
index 3bfa98df3..bd2aab113 100644
--- a/lib/ephy-marshal.list
+++ b/lib/ephy-marshal.list
@@ -4,6 +4,7 @@ BOOLEAN:VOID
OBJECT:FLAGS
OBJECT:STRING,OBJECT,FLAGS
STRING:VOID
+VOID:ENUM
VOID:POINTER,BOOLEAN
VOID:POINTER,POINTER
VOID:STRING,FLAGS
diff --git a/src/Makefile.am b/src/Makefile.am
index 1d6f3c65d..d865eec3d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -106,6 +106,10 @@ libephymain_la_CFLAGS = \
$(EPIPHANY_DEPENDENCY_CFLAGS) \
$(AM_CFLAGS)
+if ENABLE_DBUS
+libephymain_la_CFLAGS += $(DBUS_CFLAGS)
+endif
+
epiphany_SOURCES = ephy-main.c
epiphany_CPPFLAGS = \
@@ -135,6 +139,10 @@ epiphany_LDADD = \
$(EPIPHANY_DEPENDENCY_LIBS) \
$(INTLLIBS)
+if ENABLE_DBUS
+epiphany_LDADD += $(DBUS_LIBS)
+endif
+
BUILT_SOURCES = \
$(CORBA_SOURCE) \
$(TYPES_SOURCE)
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 3ff22355d..333213721 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -44,6 +44,10 @@
#include "ephy-automation.h"
#include "print-dialog.h"
+#ifdef ENABLE_DBUS
+#include "ephy-dbus.h"
+#endif
+
#include <string.h>
#include <bonobo/bonobo-main.h>
#include <glib/gi18n.h>
@@ -67,6 +71,7 @@ struct _EphyShellPrivate
EggToolbarsModel *toolbars_model;
EggToolbarsModel *fs_toolbars_model;
EphyExtensionsManager *extensions_manager;
+ GObject *dbus_service;
GtkWidget *bme;
GtkWidget *history_window;
GObject *pdm_dialog;
@@ -413,6 +418,14 @@ ephy_shell_finalize (GObject *object)
g_object_unref (shell->priv->extensions_manager);
}
+#ifdef ENABLE_DBUS
+ LOG ("Shutting down DBUS service")
+ if (shell->priv->dbus_service)
+ {
+ g_object_unref (shell->priv->dbus_service);
+ }
+#endif
+
LOG ("Unref session manager")
if (shell->priv->session)
{
@@ -805,3 +818,19 @@ ephy_shell_get_print_setup_dialog (EphyShell *shell)
return shell->priv->print_setup_dialog;
}
+
+#ifdef ENABLE_DBUS
+GObject *
+ephy_shell_get_dbus_service (EphyShell *shell)
+{
+ g_return_val_if_fail (EPHY_IS_SHELL (shell), NULL);
+
+ if (shell->priv->dbus_service == NULL)
+ {
+ shell->priv->dbus_service = g_object_new (EPHY_TYPE_DBUS, NULL);
+ ephy_dbus_startup (EPHY_DBUS (shell->priv->dbus_service));
+ }
+
+ return G_OBJECT (shell->priv->dbus_service);
+}
+#endif
diff --git a/src/ephy-shell.h b/src/ephy-shell.h
index d807cd139..a9867fe97 100644
--- a/src/ephy-shell.h
+++ b/src/ephy-shell.h
@@ -139,6 +139,8 @@ GObject *ephy_shell_get_prefs_dialog (EphyShell *shell);
GObject *ephy_shell_get_print_setup_dialog (EphyShell *shell);
+GObject *ephy_shell_get_dbus_service (EphyShell *shell);
+
G_END_DECLS
#endif