summaryrefslogtreecommitdiff
path: root/applets
diff options
context:
space:
mode:
Diffstat (limited to 'applets')
-rw-r--r--applets/brightness/Makefile.am2
-rw-r--r--applets/brightness/brightness-applet.c61
-rw-r--r--applets/brightness/egg-dbus-monitor.c251
-rw-r--r--applets/brightness/egg-dbus-monitor.h65
-rw-r--r--applets/inhibit/Makefile.am2
-rw-r--r--applets/inhibit/egg-dbus-monitor.c251
-rw-r--r--applets/inhibit/egg-dbus-monitor.h65
-rw-r--r--applets/inhibit/inhibit-applet.c65
8 files changed, 66 insertions, 696 deletions
diff --git a/applets/brightness/Makefile.am b/applets/brightness/Makefile.am
index 56ecd5a..e5e210c 100644
--- a/applets/brightness/Makefile.am
+++ b/applets/brightness/Makefile.am
@@ -27,8 +27,6 @@ libexec_PROGRAMS=mate-brightness-applet
mate_brightness_applet_SOURCES = \
brightness-applet.c \
- egg-dbus-monitor.c \
- egg-dbus-monitor.h \
egg-debug.c \
egg-debug.h \
gpm-common.c \
diff --git a/applets/brightness/brightness-applet.c b/applets/brightness/brightness-applet.c
index a35ce2f..154101a 100644
--- a/applets/brightness/brightness-applet.c
+++ b/applets/brightness/brightness-applet.c
@@ -40,7 +40,6 @@
#include <libmate-desktop/mate-aboutdialog.h>
#include "egg-debug.h"
-#include "egg-dbus-monitor.h"
#include "gpm-common.h"
#define GPM_TYPE_BRIGHTNESS_APPLET (gpm_brightness_applet_get_type ())
@@ -63,7 +62,7 @@ typedef struct{
/* connection to g-p-m */
DBusGProxy *proxy;
DBusGConnection *connection;
- EggDbusMonitor *monitor;
+ guint bus_watch_id;
guint level;
/* a cache for panel size */
gint size;
@@ -983,12 +982,9 @@ gpm_applet_destroy_cb (GtkWidget *widget)
{
GpmBrightnessApplet *applet = GPM_BRIGHTNESS_APPLET(widget);
- if (applet->monitor != NULL) {
- g_object_unref (applet->monitor);
- }
- if (applet->icon != NULL) {
+ g_bus_unwatch_name (applet->bus_watch_id);
+ if (applet->icon != NULL)
g_object_unref (applet->icon);
- }
}
/**
@@ -1069,25 +1065,30 @@ gpm_brightness_applet_dbus_disconnect (GpmBrightnessApplet *applet)
}
/**
- * monitor_connection_cb:
- * @proxy: The dbus raw proxy
- * @status: The status of the service, where TRUE is connected
- * @screensaver: This class instance
+ * gpm_brightness_applet_name_appeared_cb:
**/
static void
-monitor_connection_cb (EggDbusMonitor *monitor,
- gboolean status,
- GpmBrightnessApplet *applet)
+gpm_brightness_applet_name_appeared_cb (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ GpmBrightnessApplet *applet)
{
- if (status) {
- gpm_brightness_applet_dbus_connect (applet);
- gpm_applet_update_tooltip (applet);
- gpm_applet_draw_cb (applet);
- } else {
- gpm_brightness_applet_dbus_disconnect (applet);
- gpm_applet_update_tooltip (applet);
- gpm_applet_draw_cb (applet);
- }
+ gpm_brightness_applet_dbus_connect (applet);
+ gpm_applet_update_tooltip (applet);
+ gpm_applet_draw_cb (applet);
+}
+
+/**
+ * gpm_brightness_applet_name_vanished_cb:
+ **/
+void
+gpm_brightness_applet_name_vanished_cb (GDBusConnection *connection,
+ const gchar *name,
+ GpmBrightnessApplet *applet)
+{
+ gpm_brightness_applet_dbus_disconnect (applet);
+ gpm_applet_update_tooltip (applet);
+ gpm_applet_draw_cb (applet);
}
/**
@@ -1113,12 +1114,14 @@ gpm_brightness_applet_init (GpmBrightnessApplet *applet)
GPM_DATA G_DIR_SEPARATOR_S "icons");
- applet->monitor = egg_dbus_monitor_new ();
- g_signal_connect (applet->monitor, "connection-changed",
- G_CALLBACK (monitor_connection_cb), applet);
- connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
- egg_dbus_monitor_assign (applet->monitor, connection, GPM_DBUS_SERVICE);
- gpm_brightness_applet_dbus_connect (applet);
+ /* monitor the daemon */
+ applet->bus_watch_id =
+ g_bus_watch_name (G_BUS_TYPE_SESSION,
+ GPM_DBUS_SERVICE,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ (GBusNameAppearedCallback) gpm_brightness_applet_name_appeared_cb,
+ (GBusNameVanishedCallback) gpm_brightness_applet_name_vanished_cb,
+ applet, NULL);
/* coldplug */
applet->call_worked = gpm_applet_get_brightness (applet);
diff --git a/applets/brightness/egg-dbus-monitor.c b/applets/brightness/egg-dbus-monitor.c
deleted file mode 100644
index b8238d1..0000000
--- a/applets/brightness/egg-dbus-monitor.c
+++ /dev/null
@@ -1,251 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2006-2008 Richard Hughes <[email protected]>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus.h>
-
-#include "egg-debug.h"
-#include "egg-dbus-monitor.h"
-
-static void egg_dbus_monitor_finalize (GObject *object);
-
-#define EGG_DBUS_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EGG_TYPE_DBUS_MONITOR, EggDbusMonitorPrivate))
-
-struct EggDbusMonitorPrivate
-{
- gchar *service;
- DBusGProxy *proxy;
- DBusGConnection *connection;
- const gchar *unique_name;
-};
-
-enum {
- EGG_DBUS_MONITOR_CONNECTION_CHANGED,
- EGG_DBUS_MONITOR_CONNECTION_REPLACED,
- EGG_DBUS_MONITOR_LAST_SIGNAL
-};
-
-static guint signals [EGG_DBUS_MONITOR_LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE (EggDbusMonitor, egg_dbus_monitor, G_TYPE_OBJECT)
-
-/**
- * egg_dbus_monitor_name_owner_changed_cb:
- **/
-static void
-egg_dbus_monitor_name_owner_changed_cb (DBusGProxy *proxy, const gchar *name,
- const gchar *prev, const gchar *new,
- EggDbusMonitor *monitor)
-{
- guint new_len;
- guint prev_len;
-
- g_return_if_fail (EGG_IS_DBUS_MONITOR (monitor));
- if (monitor->priv->proxy == NULL)
- return;
-
- /* not us */
- if (strcmp (name, monitor->priv->service) != 0)
- return;
-
- /* ITS4: ignore, not used for allocation */
- new_len = strlen (new);
- /* ITS4: ignore, not used for allocation */
- prev_len = strlen (prev);
-
- /* something --> nothing */
- if (prev_len != 0 && new_len == 0) {
- g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED], 0, FALSE);
- return;
- }
-
- /* nothing --> something */
- if (prev_len == 0 && new_len != 0) {
- g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED], 0, TRUE);
- return;
- }
-
- /* something --> something (we've replaced the old process) */
- if (prev_len != 0 && new_len != 0) {
- /* only send this to the prev client */
- if (strcmp (monitor->priv->unique_name, prev) == 0)
- g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_REPLACED], 0);
- return;
- }
-}
-
-/**
- * egg_dbus_monitor_assign:
- * @monitor: This class instance
- * @connection: The bus connection
- * @service: The EGG_DBUS_MONITOR service name
- * Return value: success
- *
- * Emits connection-changed(TRUE) if connection is alive - this means you
- * have to connect up the callback before this function is called.
- **/
-gboolean
-egg_dbus_monitor_assign (EggDbusMonitor *monitor, DBusGConnection *connection, const gchar *service)
-{
- GError *error = NULL;
- gboolean connected;
- DBusConnection *conn;
-
- g_return_val_if_fail (EGG_IS_DBUS_MONITOR (monitor), FALSE);
- g_return_val_if_fail (service != NULL, FALSE);
- g_return_val_if_fail (connection != NULL, FALSE);
-
- if (monitor->priv->proxy != NULL) {
- egg_warning ("already assigned!");
- return FALSE;
- }
-
- monitor->priv->service = g_strdup (service);
- monitor->priv->connection = connection;
- monitor->priv->proxy = dbus_g_proxy_new_for_name_owner (monitor->priv->connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- &error);
- if (error != NULL) {
- egg_warning ("Cannot connect to DBUS: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
- dbus_g_proxy_add_signal (monitor->priv->proxy, "NameOwnerChanged",
- G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (monitor->priv->proxy, "NameOwnerChanged",
- G_CALLBACK (egg_dbus_monitor_name_owner_changed_cb),
- monitor, NULL);
-
- /* coldplug */
- connected = egg_dbus_monitor_is_connected (monitor);
- if (connected)
- g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED], 0, TRUE);
-
- /* save this for the replaced check */
- conn = dbus_g_connection_get_connection (monitor->priv->connection);
- monitor->priv->unique_name = dbus_bus_get_unique_name (conn);
- return TRUE;
-}
-
-/**
- * egg_dbus_monitor_is_connected:
- * @monitor: This class instance
- * Return value: if we are connected to a valid watch
- **/
-gboolean
-egg_dbus_monitor_is_connected (EggDbusMonitor *monitor)
-{
- DBusError error;
- DBusConnection *conn;
- gboolean ret;
- g_return_val_if_fail (EGG_IS_DBUS_MONITOR (monitor), FALSE);
-
- /* get raw connection */
- conn = dbus_g_connection_get_connection (monitor->priv->connection);
- dbus_error_init (&error);
- ret = dbus_bus_name_has_owner (conn, monitor->priv->service, &error);
- if (dbus_error_is_set (&error)) {
- egg_debug ("error: %s", error.message);
- dbus_error_free (&error);
- }
-
- return ret;
-}
-
-/**
- * egg_dbus_monitor_class_init:
- * @klass: The EggDbusMonitorClass
- **/
-static void
-egg_dbus_monitor_class_init (EggDbusMonitorClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = egg_dbus_monitor_finalize;
- g_type_class_add_private (klass, sizeof (EggDbusMonitorPrivate));
- signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED] =
- g_signal_new ("connection-changed",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EggDbusMonitorClass, connection_changed),
- NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- signals [EGG_DBUS_MONITOR_CONNECTION_REPLACED] =
- g_signal_new ("connection-replaced",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EggDbusMonitorClass, connection_replaced),
- NULL, NULL, g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-}
-
-/**
- * egg_dbus_monitor_init:
- * @monitor: This class instance
- **/
-static void
-egg_dbus_monitor_init (EggDbusMonitor *monitor)
-{
- monitor->priv = EGG_DBUS_MONITOR_GET_PRIVATE (monitor);
- monitor->priv->service = NULL;
- monitor->priv->connection = NULL;
- monitor->priv->proxy = NULL;
-}
-
-/**
- * egg_dbus_monitor_finalize:
- * @object: The object to finalize
- **/
-static void
-egg_dbus_monitor_finalize (GObject *object)
-{
- EggDbusMonitor *monitor;
-
- g_return_if_fail (EGG_IS_DBUS_MONITOR (object));
-
- monitor = EGG_DBUS_MONITOR (object);
-
- g_return_if_fail (monitor->priv != NULL);
- if (monitor->priv->proxy != NULL)
- g_object_unref (monitor->priv->proxy);
-
- G_OBJECT_CLASS (egg_dbus_monitor_parent_class)->finalize (object);
-}
-
-/**
- * egg_dbus_monitor_new:
- *
- * Return value: a new EggDbusMonitor object.
- **/
-EggDbusMonitor *
-egg_dbus_monitor_new (void)
-{
- EggDbusMonitor *monitor;
- monitor = g_object_new (EGG_TYPE_DBUS_MONITOR, NULL);
- return EGG_DBUS_MONITOR (monitor);
-}
-
diff --git a/applets/brightness/egg-dbus-monitor.h b/applets/brightness/egg-dbus-monitor.h
deleted file mode 100644
index 9efa8b9..0000000
--- a/applets/brightness/egg-dbus-monitor.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2008 Richard Hughes <[email protected]>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef __EGG_DBUS_MONITOR_H
-#define __EGG_DBUS_MONITOR_H
-
-#include <glib-object.h>
-#include <dbus/dbus-glib.h>
-
-G_BEGIN_DECLS
-
-#define EGG_TYPE_DBUS_MONITOR (egg_dbus_monitor_get_type ())
-#define EGG_DBUS_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EGG_TYPE_DBUS_MONITOR, EggDbusMonitor))
-#define EGG_DBUS_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EGG_TYPE_DBUS_MONITOR, EggDbusMonitorClass))
-#define EGG_IS_DBUS_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EGG_TYPE_DBUS_MONITOR))
-#define EGG_IS_DBUS_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EGG_TYPE_DBUS_MONITOR))
-#define EGG_DBUS_MONITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EGG_TYPE_DBUS_MONITOR, EggDbusMonitorClass))
-#define EGG_DBUS_MONITOR_ERROR (egg_dbus_monitor_error_quark ())
-#define EGG_DBUS_MONITOR_TYPE_ERROR (egg_dbus_monitor_error_get_type ())
-
-typedef struct EggDbusMonitorPrivate EggDbusMonitorPrivate;
-
-typedef struct
-{
- GObject parent;
- EggDbusMonitorPrivate *priv;
-} EggDbusMonitor;
-
-typedef struct
-{
- GObjectClass parent_class;
- void (* connection_changed) (EggDbusMonitor *watch,
- gboolean connected);
- void (* connection_replaced) (EggDbusMonitor *watch);
-} EggDbusMonitorClass;
-
-GType egg_dbus_monitor_get_type (void);
-EggDbusMonitor *egg_dbus_monitor_new (void);
-gboolean egg_dbus_monitor_assign (EggDbusMonitor *monitor,
- DBusGConnection *connection,
- const gchar *service);
-gboolean egg_dbus_monitor_is_connected (EggDbusMonitor *monitor);
-
-G_END_DECLS
-
-#endif /* __EGG_DBUS_MONITOR_H */
-
diff --git a/applets/inhibit/Makefile.am b/applets/inhibit/Makefile.am
index f51b281..f98d673 100644
--- a/applets/inhibit/Makefile.am
+++ b/applets/inhibit/Makefile.am
@@ -27,8 +27,6 @@ libexec_PROGRAMS=mate-inhibit-applet
mate_inhibit_applet_SOURCES = \
inhibit-applet.c \
- egg-dbus-monitor.c \
- egg-dbus-monitor.h \
egg-debug.c \
egg-debug.h \
gpm-common.c \
diff --git a/applets/inhibit/egg-dbus-monitor.c b/applets/inhibit/egg-dbus-monitor.c
deleted file mode 100644
index b8238d1..0000000
--- a/applets/inhibit/egg-dbus-monitor.c
+++ /dev/null
@@ -1,251 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2006-2008 Richard Hughes <[email protected]>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus.h>
-
-#include "egg-debug.h"
-#include "egg-dbus-monitor.h"
-
-static void egg_dbus_monitor_finalize (GObject *object);
-
-#define EGG_DBUS_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EGG_TYPE_DBUS_MONITOR, EggDbusMonitorPrivate))
-
-struct EggDbusMonitorPrivate
-{
- gchar *service;
- DBusGProxy *proxy;
- DBusGConnection *connection;
- const gchar *unique_name;
-};
-
-enum {
- EGG_DBUS_MONITOR_CONNECTION_CHANGED,
- EGG_DBUS_MONITOR_CONNECTION_REPLACED,
- EGG_DBUS_MONITOR_LAST_SIGNAL
-};
-
-static guint signals [EGG_DBUS_MONITOR_LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE (EggDbusMonitor, egg_dbus_monitor, G_TYPE_OBJECT)
-
-/**
- * egg_dbus_monitor_name_owner_changed_cb:
- **/
-static void
-egg_dbus_monitor_name_owner_changed_cb (DBusGProxy *proxy, const gchar *name,
- const gchar *prev, const gchar *new,
- EggDbusMonitor *monitor)
-{
- guint new_len;
- guint prev_len;
-
- g_return_if_fail (EGG_IS_DBUS_MONITOR (monitor));
- if (monitor->priv->proxy == NULL)
- return;
-
- /* not us */
- if (strcmp (name, monitor->priv->service) != 0)
- return;
-
- /* ITS4: ignore, not used for allocation */
- new_len = strlen (new);
- /* ITS4: ignore, not used for allocation */
- prev_len = strlen (prev);
-
- /* something --> nothing */
- if (prev_len != 0 && new_len == 0) {
- g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED], 0, FALSE);
- return;
- }
-
- /* nothing --> something */
- if (prev_len == 0 && new_len != 0) {
- g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED], 0, TRUE);
- return;
- }
-
- /* something --> something (we've replaced the old process) */
- if (prev_len != 0 && new_len != 0) {
- /* only send this to the prev client */
- if (strcmp (monitor->priv->unique_name, prev) == 0)
- g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_REPLACED], 0);
- return;
- }
-}
-
-/**
- * egg_dbus_monitor_assign:
- * @monitor: This class instance
- * @connection: The bus connection
- * @service: The EGG_DBUS_MONITOR service name
- * Return value: success
- *
- * Emits connection-changed(TRUE) if connection is alive - this means you
- * have to connect up the callback before this function is called.
- **/
-gboolean
-egg_dbus_monitor_assign (EggDbusMonitor *monitor, DBusGConnection *connection, const gchar *service)
-{
- GError *error = NULL;
- gboolean connected;
- DBusConnection *conn;
-
- g_return_val_if_fail (EGG_IS_DBUS_MONITOR (monitor), FALSE);
- g_return_val_if_fail (service != NULL, FALSE);
- g_return_val_if_fail (connection != NULL, FALSE);
-
- if (monitor->priv->proxy != NULL) {
- egg_warning ("already assigned!");
- return FALSE;
- }
-
- monitor->priv->service = g_strdup (service);
- monitor->priv->connection = connection;
- monitor->priv->proxy = dbus_g_proxy_new_for_name_owner (monitor->priv->connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- &error);
- if (error != NULL) {
- egg_warning ("Cannot connect to DBUS: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
- dbus_g_proxy_add_signal (monitor->priv->proxy, "NameOwnerChanged",
- G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (monitor->priv->proxy, "NameOwnerChanged",
- G_CALLBACK (egg_dbus_monitor_name_owner_changed_cb),
- monitor, NULL);
-
- /* coldplug */
- connected = egg_dbus_monitor_is_connected (monitor);
- if (connected)
- g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED], 0, TRUE);
-
- /* save this for the replaced check */
- conn = dbus_g_connection_get_connection (monitor->priv->connection);
- monitor->priv->unique_name = dbus_bus_get_unique_name (conn);
- return TRUE;
-}
-
-/**
- * egg_dbus_monitor_is_connected:
- * @monitor: This class instance
- * Return value: if we are connected to a valid watch
- **/
-gboolean
-egg_dbus_monitor_is_connected (EggDbusMonitor *monitor)
-{
- DBusError error;
- DBusConnection *conn;
- gboolean ret;
- g_return_val_if_fail (EGG_IS_DBUS_MONITOR (monitor), FALSE);
-
- /* get raw connection */
- conn = dbus_g_connection_get_connection (monitor->priv->connection);
- dbus_error_init (&error);
- ret = dbus_bus_name_has_owner (conn, monitor->priv->service, &error);
- if (dbus_error_is_set (&error)) {
- egg_debug ("error: %s", error.message);
- dbus_error_free (&error);
- }
-
- return ret;
-}
-
-/**
- * egg_dbus_monitor_class_init:
- * @klass: The EggDbusMonitorClass
- **/
-static void
-egg_dbus_monitor_class_init (EggDbusMonitorClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = egg_dbus_monitor_finalize;
- g_type_class_add_private (klass, sizeof (EggDbusMonitorPrivate));
- signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED] =
- g_signal_new ("connection-changed",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EggDbusMonitorClass, connection_changed),
- NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- signals [EGG_DBUS_MONITOR_CONNECTION_REPLACED] =
- g_signal_new ("connection-replaced",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EggDbusMonitorClass, connection_replaced),
- NULL, NULL, g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-}
-
-/**
- * egg_dbus_monitor_init:
- * @monitor: This class instance
- **/
-static void
-egg_dbus_monitor_init (EggDbusMonitor *monitor)
-{
- monitor->priv = EGG_DBUS_MONITOR_GET_PRIVATE (monitor);
- monitor->priv->service = NULL;
- monitor->priv->connection = NULL;
- monitor->priv->proxy = NULL;
-}
-
-/**
- * egg_dbus_monitor_finalize:
- * @object: The object to finalize
- **/
-static void
-egg_dbus_monitor_finalize (GObject *object)
-{
- EggDbusMonitor *monitor;
-
- g_return_if_fail (EGG_IS_DBUS_MONITOR (object));
-
- monitor = EGG_DBUS_MONITOR (object);
-
- g_return_if_fail (monitor->priv != NULL);
- if (monitor->priv->proxy != NULL)
- g_object_unref (monitor->priv->proxy);
-
- G_OBJECT_CLASS (egg_dbus_monitor_parent_class)->finalize (object);
-}
-
-/**
- * egg_dbus_monitor_new:
- *
- * Return value: a new EggDbusMonitor object.
- **/
-EggDbusMonitor *
-egg_dbus_monitor_new (void)
-{
- EggDbusMonitor *monitor;
- monitor = g_object_new (EGG_TYPE_DBUS_MONITOR, NULL);
- return EGG_DBUS_MONITOR (monitor);
-}
-
diff --git a/applets/inhibit/egg-dbus-monitor.h b/applets/inhibit/egg-dbus-monitor.h
deleted file mode 100644
index 9efa8b9..0000000
--- a/applets/inhibit/egg-dbus-monitor.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2008 Richard Hughes <[email protected]>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef __EGG_DBUS_MONITOR_H
-#define __EGG_DBUS_MONITOR_H
-
-#include <glib-object.h>
-#include <dbus/dbus-glib.h>
-
-G_BEGIN_DECLS
-
-#define EGG_TYPE_DBUS_MONITOR (egg_dbus_monitor_get_type ())
-#define EGG_DBUS_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EGG_TYPE_DBUS_MONITOR, EggDbusMonitor))
-#define EGG_DBUS_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EGG_TYPE_DBUS_MONITOR, EggDbusMonitorClass))
-#define EGG_IS_DBUS_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EGG_TYPE_DBUS_MONITOR))
-#define EGG_IS_DBUS_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EGG_TYPE_DBUS_MONITOR))
-#define EGG_DBUS_MONITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EGG_TYPE_DBUS_MONITOR, EggDbusMonitorClass))
-#define EGG_DBUS_MONITOR_ERROR (egg_dbus_monitor_error_quark ())
-#define EGG_DBUS_MONITOR_TYPE_ERROR (egg_dbus_monitor_error_get_type ())
-
-typedef struct EggDbusMonitorPrivate EggDbusMonitorPrivate;
-
-typedef struct
-{
- GObject parent;
- EggDbusMonitorPrivate *priv;
-} EggDbusMonitor;
-
-typedef struct
-{
- GObjectClass parent_class;
- void (* connection_changed) (EggDbusMonitor *watch,
- gboolean connected);
- void (* connection_replaced) (EggDbusMonitor *watch);
-} EggDbusMonitorClass;
-
-GType egg_dbus_monitor_get_type (void);
-EggDbusMonitor *egg_dbus_monitor_new (void);
-gboolean egg_dbus_monitor_assign (EggDbusMonitor *monitor,
- DBusGConnection *connection,
- const gchar *service);
-gboolean egg_dbus_monitor_is_connected (EggDbusMonitor *monitor);
-
-G_END_DECLS
-
-#endif /* __EGG_DBUS_MONITOR_H */
-
diff --git a/applets/inhibit/inhibit-applet.c b/applets/inhibit/inhibit-applet.c
index 1a8bbb1..7a59152 100644
--- a/applets/inhibit/inhibit-applet.c
+++ b/applets/inhibit/inhibit-applet.c
@@ -39,7 +39,6 @@
#include <libmate-desktop/mate-aboutdialog.h>
#include "egg-debug.h"
-#include "egg-dbus-monitor.h"
#include "gpm-common.h"
#define GPM_TYPE_INHIBIT_APPLET (gpm_inhibit_applet_get_type ())
@@ -59,7 +58,7 @@ typedef struct{
/* connection to g-p-m */
DBusGProxy *proxy;
DBusGConnection *connection;
- EggDbusMonitor *monitor;
+ guint bus_watch_id;
guint level;
/* a cache for panel size */
gint size;
@@ -505,12 +504,9 @@ gpm_applet_destroy_cb (GtkWidget *widget)
{
GpmInhibitApplet *applet = GPM_INHIBIT_APPLET(widget);
- if (applet->monitor != NULL) {
- g_object_unref (applet->monitor);
- }
- if (applet->icon != NULL) {
+ g_bus_unwatch_name (applet->bus_watch_id);
+ if (applet->icon != NULL)
g_object_unref (applet->icon);
- }
}
/**
@@ -578,27 +574,32 @@ gpm_inhibit_applet_dbus_disconnect (GpmInhibitApplet *applet)
}
/**
- * monitor_connection_cb:
- * @proxy: The dbus raw proxy
- * @status: The status of the service, where TRUE is connected
- * @screensaver: This class instance
+ * gpm_inhibit_applet_name_appeared_cb:
**/
static void
-monitor_connection_cb (EggDbusMonitor *monitor,
- gboolean status,
- GpmInhibitApplet *applet)
+gpm_inhibit_applet_name_appeared_cb (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ GpmInhibitApplet *applet)
{
- if (status) {
- gpm_inhibit_applet_dbus_connect (applet);
- gpm_applet_update_tooltip (applet);
- gpm_applet_get_icon (applet);
- gpm_applet_draw_cb (applet);
- } else {
- gpm_inhibit_applet_dbus_disconnect (applet);
- gpm_applet_update_tooltip (applet);
- gpm_applet_get_icon (applet);
- gpm_applet_draw_cb (applet);
- }
+ gpm_inhibit_applet_dbus_connect (applet);
+ gpm_applet_update_tooltip (applet);
+ gpm_applet_get_icon (applet);
+ gpm_applet_draw_cb (applet);
+}
+
+/**
+ * gpm_inhibit_applet_name_vanished_cb:
+ **/
+void
+gpm_inhibit_applet_name_vanished_cb (GDBusConnection *connection,
+ const gchar *name,
+ GpmInhibitApplet *applet)
+{
+ gpm_inhibit_applet_dbus_disconnect (applet);
+ gpm_applet_update_tooltip (applet);
+ gpm_applet_get_icon (applet);
+ gpm_applet_draw_cb (applet);
}
/**
@@ -621,12 +622,14 @@ gpm_inhibit_applet_init (GpmInhibitApplet *applet)
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
GPM_DATA G_DIR_SEPARATOR_S "icons");
- applet->monitor = egg_dbus_monitor_new ();
- g_signal_connect (applet->monitor, "connection-changed",
- G_CALLBACK (monitor_connection_cb), applet);
- connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
- egg_dbus_monitor_assign (applet->monitor, connection, GS_DBUS_SERVICE);
- gpm_inhibit_applet_dbus_connect (applet);
+ /* monitor the daemon */
+ applet->bus_watch_id =
+ g_bus_watch_name (G_BUS_TYPE_SESSION,
+ GS_DBUS_SERVICE,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ (GBusNameAppearedCallback) gpm_inhibit_applet_name_appeared_cb,
+ (GBusNameVanishedCallback) gpm_inhibit_applet_name_vanished_cb,
+ applet, NULL);
/* prepare */
mate_panel_applet_set_flags (MATE_PANEL_APPLET (applet), MATE_PANEL_APPLET_EXPAND_MINOR);