aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2010-07-28 22:21:40 +0800
committerMilan Crha <mcrha@redhat.com>2010-07-28 22:21:40 +0800
commit6158bcecd722a9e8b23dd2d3bcfc148e37d5c039 (patch)
tree93e617d831c9f2b41987cd895863c1f86196f3e9
parentdd2c7ddfba1e556e2bb8f7b233a3b59bf18bcff9 (diff)
downloadgsoc2013-evolution-6158bcecd722a9e8b23dd2d3bcfc148e37d5c039.tar
gsoc2013-evolution-6158bcecd722a9e8b23dd2d3bcfc148e37d5c039.tar.gz
gsoc2013-evolution-6158bcecd722a9e8b23dd2d3bcfc148e37d5c039.tar.bz2
gsoc2013-evolution-6158bcecd722a9e8b23dd2d3bcfc148e37d5c039.tar.lz
gsoc2013-evolution-6158bcecd722a9e8b23dd2d3bcfc148e37d5c039.tar.xz
gsoc2013-evolution-6158bcecd722a9e8b23dd2d3bcfc148e37d5c039.tar.zst
gsoc2013-evolution-6158bcecd722a9e8b23dd2d3bcfc148e37d5c039.zip
Bug #622912 - Migrate from dbus-glib to glib's GDBus
-rw-r--r--configure.ac10
-rw-r--r--modules/connman/Makefile.am6
-rw-r--r--modules/connman/evolution-connman.c124
-rw-r--r--modules/network-manager/Makefile.am4
-rw-r--r--modules/network-manager/evolution-network-manager.c132
-rw-r--r--plugins/mail-notification/Makefile.am2
-rw-r--r--plugins/mail-notification/mail-notification.c106
7 files changed, 185 insertions, 199 deletions
diff --git a/configure.ac b/configure.ac
index 93427b0d54..7566ba93a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,7 +35,7 @@ dnl Automake 1.11 - Silent Build Rules
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
dnl Required Packages
-m4_define([glib_minimum_version], [2.22.0])
+m4_define([glib_minimum_version], [2.25.11])
m4_define([eds_minimum_version], [evo_version])
m4_define([gnome_icon_theme_minimum_version], [2.19.91])
m4_define([pangoft2_minimum_version], [1.0.1]) dnl For libgnomecanvas
@@ -44,7 +44,6 @@ m4_define([libsoup_minimum_version], [2.4.0]) dnl XXX Just a Guess
m4_define([libxml_minimum_version], [2.7.3])
m4_define([shared_mime_info_minimum_version], [0.22])
m4_define([libpst_minimum_version], [0.6.41])
-m4_define([dbus_glib_minimum_version], [0.74])
dnl Optional Packages
m4_define([nm_minimum_version],[0.7])
@@ -1160,13 +1159,6 @@ fi
AC_SUBST(TNEF_CFLAGS)
dnl ******************************
-dnl Check for dbus-glib-1 and dbus
-dnl ******************************
-PKG_CHECK_MODULES([DBUS_GLIB], [dbus-glib-1 >= dbus_glib_minimum_version])
-AC_SUBST(DBUS_GLIB_CFLAGS)
-AC_SUBST(DBUS_GLIB_LIBS)
-
-dnl ******************************
dnl Check for NetworkManager
dnl ******************************
AC_ARG_ENABLE([nm],
diff --git a/modules/connman/Makefile.am b/modules/connman/Makefile.am
index 63822262c4..58defdd838 100644
--- a/modules/connman/Makefile.am
+++ b/modules/connman/Makefile.am
@@ -4,8 +4,7 @@ libevolution_module_connman_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
-I$(top_srcdir) \
-DG_LOG_DOMAIN=\"evolution-connman\" \
- $(GNOME_PLATFORM_CFLAGS) \
- $(DBUS_GLIB_CFLAGS)
+ $(GNOME_PLATFORM_CFLAGS)
libevolution_module_connman_la_SOURCES = \
evolution-connman.c
@@ -13,8 +12,7 @@ libevolution_module_connman_la_SOURCES = \
libevolution_module_connman_la_LIBADD = \
$(top_builddir)/e-util/libeutil.la \
$(top_builddir)/shell/libeshell.la \
- $(GNOME_PLATFORM_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(GNOME_PLATFORM_LIBS)
libevolution_module_connman_la_LDFLAGS = \
-module -avoid-version $(NO_UNDEFINED)
diff --git a/modules/connman/evolution-connman.c b/modules/connman/evolution-connman.c
index 6a302889a4..18187b41ca 100644
--- a/modules/connman/evolution-connman.c
+++ b/modules/connman/evolution-connman.c
@@ -16,9 +16,7 @@
*
*/
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
#include <shell/e-shell.h>
#include <e-util/e-extension.h>
@@ -36,7 +34,7 @@
typedef struct {
EExtension parent;
- DBusConnection *connection;
+ GDBusConnection *connection;
} EConnMan;
typedef EExtensionClass EConnManClass;
@@ -61,67 +59,77 @@ extension_set_state (EConnMan *extension, const gchar *state)
e_shell_set_network_available (E_SHELL (extensible), !g_strcmp0 (state, "online"));
}
-static DBusHandlerResult
-connman_monitor (DBusConnection *connection G_GNUC_UNUSED,
- DBusMessage *message,
- gpointer user_data)
+static void
+cm_connection_closed_cb (GDBusConnection *pconnection, gboolean remote_peer_vanished, GError *error, gpointer user_data)
{
- gchar *value;
EConnMan *extension = user_data;
- DBusError error = DBUS_ERROR_INIT;
- DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- if (!dbus_message_has_path (message, CM_DBUS_PATH) ||
- !dbus_message_has_interface (message, CM_DBUS_INTERFACE) ||
- !dbus_message_has_member (message, "StateChanged"))
- goto err_exit;
+ g_object_unref (extension->connection);
+ extension->connection = NULL;
- if (!dbus_message_get_args (message, &error,
- DBUS_TYPE_STRING, &value,
- DBUS_TYPE_INVALID))
- goto err_exit;
+ g_timeout_add_seconds (
+ 3, (GSourceFunc) network_manager_connect, extension);
+}
- extension_set_state (extension, value);
- ret = DBUS_HANDLER_RESULT_HANDLED;
+static void
+conn_manager_signal_cb (GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ EConnMan *extension = user_data;
+ gchar *state = NULL;
- err_exit:
- return ret;
+ if (g_strcmp0 (interface_name, CM_DBUS_INTERFACE) != 0
+ || g_strcmp0 (object_path, CM_DBUS_PATH) != 0
+ || g_strcmp0 (signal_name, "StateChanged") != 0)
+ return;
+
+ g_variant_get (parameters, "(s)", &state);
+ extension_set_state (extension, state);
+ g_free (state);
}
static void
connman_check_initial_state (EConnMan *extension)
{
- DBusMessage *message = NULL;
- DBusMessage *response = NULL;
- DBusError error = DBUS_ERROR_INIT;
+ GDBusMessage *message = NULL;
+ GDBusMessage *response = NULL;
+ GError *error = NULL;
- message = dbus_message_new_method_call (
+ message = g_dbus_message_new_method_call (
CM_DBUS_SERVICE, CM_DBUS_PATH, CM_DBUS_INTERFACE, "GetState");
/* XXX Assuming this should be safe to call synchronously. */
- response = dbus_connection_send_with_reply_and_block (
- extension->connection, message, 100, &error);
+ response = g_dbus_connection_send_message_with_reply_sync (
+ extension->connection, message, 100, NULL, NULL, &error);
if (response != NULL) {
- const gchar *value;
- if (dbus_message_get_args (message, &error,
- DBUS_TYPE_STRING, &value,
- DBUS_TYPE_INVALID))
- extension_set_state (extension, value);
+ gchar *state = NULL;
+ GVariant *body = g_dbus_message_get_body (response);
+
+ g_variant_get (body, "(s)", &state);
+ extension_set_state (extension, state);
+ g_free (state);
} else {
- g_warning ("%s", error.message);
- dbus_error_free (&error);
+ g_warning ("%s: %s", G_STRFUNC, error ? error->message : "Unknown error");
+ if (error)
+ g_error_free (error);
+ g_object_unref (message);
return;
}
- dbus_message_unref (message);
- dbus_message_unref (response);
+ g_object_unref (message);
+ g_object_unref (response);
}
static gboolean
network_manager_connect (EConnMan *extension)
{
- DBusError error = DBUS_ERROR_INIT;
+ GError *error = NULL;
/* This is a timeout callback, so the return value denotes
* whether to reschedule, not whether we're successful. */
@@ -129,40 +137,38 @@ network_manager_connect (EConnMan *extension)
if (extension->connection != NULL)
return FALSE;
- extension->connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+ extension->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (extension->connection == NULL) {
- g_warning ("%s", error.message);
- dbus_error_free (&error);
+ g_warning ("%s: %s", G_STRFUNC, error ? error->message : "Unknown error");
+ g_error_free (error);
+
return TRUE;
}
- dbus_connection_setup_with_g_main (extension->connection, NULL);
- dbus_connection_set_exit_on_disconnect (extension->connection, FALSE);
+ g_dbus_connection_set_exit_on_close (extension->connection, FALSE);
- if (!dbus_connection_add_filter (
- extension->connection, connman_monitor, extension, NULL))
- goto fail;
-
- dbus_bus_add_match (
+ if (!g_dbus_connection_signal_subscribe (
extension->connection,
- "type='signal',"
- "interface='" CM_DBUS_INTERFACE "',"
- "sender='" CM_DBUS_SERVICE "',"
- "member='StateChanged',"
- "path='" CM_DBUS_PATH "'",
- &error);
- if (dbus_error_is_set (&error)) {
- g_warning ("%s", error.message);
- dbus_error_free (&error);
+ CM_DBUS_SERVICE,
+ CM_DBUS_INTERFACE,
+ NULL,
+ CM_DBUS_PATH,
+ NULL,
+ conn_manager_signal_cb,
+ extension,
+ NULL)) {
+ g_warning ("%s: Failed to subscribe for a signal", G_STRFUNC);
goto fail;
}
+ g_signal_connect (extension->connection, "closed", G_CALLBACK (cm_connection_closed_cb), extension);
+
connman_check_initial_state (extension);
return FALSE;
fail:
- dbus_connection_unref (extension->connection);
+ g_object_unref (extension->connection);
extension->connection = NULL;
return TRUE;
diff --git a/modules/network-manager/Makefile.am b/modules/network-manager/Makefile.am
index 90579dae38..6a7134d942 100644
--- a/modules/network-manager/Makefile.am
+++ b/modules/network-manager/Makefile.am
@@ -5,7 +5,6 @@ libevolution_module_network_manager_la_CPPFLAGS = \
-I$(top_srcdir) \
-DG_LOG_DOMAIN=\"evolution-network-manager\" \
$(GNOME_PLATFORM_CFLAGS) \
- $(DBUS_GLIB_CFLAGS) \
$(NM_CFLAGS)
libevolution_module_network_manager_la_SOURCES = \
@@ -14,8 +13,7 @@ libevolution_module_network_manager_la_SOURCES = \
libevolution_module_network_manager_la_LIBADD = \
$(top_builddir)/e-util/libeutil.la \
$(top_builddir)/shell/libeshell.la \
- $(GNOME_PLATFORM_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(GNOME_PLATFORM_LIBS)
libevolution_module_network_manager_la_LDFLAGS = \
-module -avoid-version $(NO_UNDEFINED)
diff --git a/modules/network-manager/evolution-network-manager.c b/modules/network-manager/evolution-network-manager.c
index 7dc110f411..d63eed22cf 100644
--- a/modules/network-manager/evolution-network-manager.c
+++ b/modules/network-manager/evolution-network-manager.c
@@ -16,9 +16,7 @@
*
*/
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
#include <NetworkManager/NetworkManager.h>
#include <shell/e-shell.h>
@@ -36,7 +34,7 @@ typedef struct _ENetworkManagerClass ENetworkManagerClass;
struct _ENetworkManager {
EExtension parent;
- DBusConnection *connection;
+ GDBusConnection *connection;
};
struct _ENetworkManagerClass {
@@ -63,45 +61,38 @@ network_manager_get_shell (ENetworkManager *extension)
return E_SHELL (extensible);
}
-static DBusHandlerResult
-network_manager_monitor (DBusConnection *connection G_GNUC_UNUSED,
- DBusMessage *message,
- gpointer user_data)
+static void
+nm_connection_closed_cb (GDBusConnection *pconnection, gboolean remote_peer_vanished, GError *error, gpointer user_data)
{
ENetworkManager *extension = user_data;
- EShell *shell;
- const gchar *path;
- guint32 state;
- DBusError error = DBUS_ERROR_INIT;
-
- shell = network_manager_get_shell (extension);
-
- path = dbus_message_get_path (message);
-
- if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") &&
- g_strcmp0 (path, DBUS_PATH_LOCAL) == 0) {
- dbus_connection_unref (extension->connection);
- extension->connection = NULL;
- g_timeout_add_seconds (
- 3, (GSourceFunc) network_manager_connect, extension);
+ g_object_unref (extension->connection);
+ extension->connection = NULL;
- return DBUS_HANDLER_RESULT_HANDLED;
- }
+ g_timeout_add_seconds (
+ 3, (GSourceFunc) network_manager_connect, extension);
+}
- if (!dbus_message_is_signal (message, NM_DBUS_INTERFACE, "StateChanged"))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+static void
+network_manager_signal_cb (GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ ENetworkManager *extension = user_data;
+ EShell *shell;
+ guint32 state;
- dbus_message_get_args (
- message, &error,
- DBUS_TYPE_UINT32, &state,
- DBUS_TYPE_INVALID);
+ shell = network_manager_get_shell (extension);
- if (dbus_error_is_set (&error)) {
- g_warning ("%s", error.message);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ if (g_strcmp0 (interface_name, NM_DBUS_INTERFACE) != 0
+ || g_strcmp0 (signal_name, "StateChanged") != 0)
+ return;
+ g_variant_get (parameters, "(u)", &state);
switch (state) {
case NM_STATE_CONNECTED:
e_shell_set_network_available (shell, TRUE);
@@ -113,35 +104,35 @@ network_manager_monitor (DBusConnection *connection G_GNUC_UNUSED,
default:
break;
}
-
- return DBUS_HANDLER_RESULT_HANDLED;
}
static void
network_manager_check_initial_state (ENetworkManager *extension)
{
EShell *shell;
- DBusMessage *message = NULL;
- DBusMessage *response = NULL;
+ GDBusMessage *message = NULL;
+ GDBusMessage *response = NULL;
guint32 state = -1;
- DBusError error = DBUS_ERROR_INIT;
+ GError *error = NULL;
shell = network_manager_get_shell (extension);
- message = dbus_message_new_method_call (
+ message = g_dbus_message_new_method_call (
NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state");
/* XXX Assuming this should be safe to call synchronously. */
- response = dbus_connection_send_with_reply_and_block (
- extension->connection, message, 100, &error);
+ response = g_dbus_connection_send_message_with_reply_sync (
+ extension->connection, message, 100, NULL, NULL, &error);
if (response != NULL) {
- dbus_message_get_args (
- response, &error, DBUS_TYPE_UINT32,
- &state, DBUS_TYPE_INVALID);
+ GVariant *body = g_dbus_message_get_body (response);
+
+ g_variant_get (body, "(u)", &state);
} else {
- g_warning ("%s", error.message);
- dbus_error_free (&error);
+ g_warning ("%s: %s", G_STRFUNC, error ? error->message : "Unknown error");
+ if (error)
+ g_error_free (error);
+ g_object_unref (message);
return;
}
@@ -150,14 +141,14 @@ network_manager_check_initial_state (ENetworkManager *extension)
if (state == NM_STATE_ASLEEP || state == NM_STATE_DISCONNECTED)
e_shell_set_network_available (shell, FALSE);
- dbus_message_unref (message);
- dbus_message_unref (response);
+ g_object_unref (message);
+ g_object_unref (response);
}
static gboolean
network_manager_connect (ENetworkManager *extension)
{
- DBusError error = DBUS_ERROR_INIT;
+ GError *error = NULL;
/* This is a timeout callback, so the return value denotes
* whether to reschedule, not whether we're successful. */
@@ -165,40 +156,37 @@ network_manager_connect (ENetworkManager *extension)
if (extension->connection != NULL)
return FALSE;
- extension->connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+ extension->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (extension->connection == NULL) {
- g_warning ("%s", error.message);
- dbus_error_free (&error);
+ g_warning ("%s: %s", G_STRFUNC, error ? error->message : "Unknown error");
+ g_error_free (error);
+
return TRUE;
}
- dbus_connection_setup_with_g_main (extension->connection, NULL);
- dbus_connection_set_exit_on_disconnect (extension->connection, FALSE);
+ g_dbus_connection_set_exit_on_close (extension->connection, FALSE);
- if (!dbus_connection_add_filter (
+ if (!g_dbus_connection_signal_subscribe (
extension->connection,
- network_manager_monitor, extension, NULL))
+ NM_DBUS_SERVICE,
+ NM_DBUS_INTERFACE,
+ NULL,
+ NM_DBUS_PATH,
+ NULL,
+ network_manager_signal_cb,
+ extension,
+ NULL)) {
+ g_warning ("%s: Failed to subscribe for a signal", G_STRFUNC);
goto fail;
+ }
+ g_signal_connect (extension->connection, "closed", G_CALLBACK (nm_connection_closed_cb), extension);
network_manager_check_initial_state (extension);
- dbus_bus_add_match (
- extension->connection,
- "type='signal',"
- "interface='" NM_DBUS_INTERFACE "',"
- "sender='" NM_DBUS_SERVICE "',"
- "path='" NM_DBUS_PATH "'",
- &error);
- if (dbus_error_is_set (&error)) {
- g_warning ("%s", error.message);
- dbus_error_free (&error);
- goto fail;
- }
-
return FALSE;
fail:
- dbus_connection_unref (extension->connection);
+ g_object_unref (extension->connection);
extension->connection = NULL;
return TRUE;
diff --git a/plugins/mail-notification/Makefile.am b/plugins/mail-notification/Makefile.am
index e70dca5e83..ed916e64ec 100644
--- a/plugins/mail-notification/Makefile.am
+++ b/plugins/mail-notification/Makefile.am
@@ -17,7 +17,6 @@ liborg_gnome_mail_notification_la_CPPFLAGS = \
-I$(top_srcdir)/widgets \
$(GNOME_PLATFORM_CFLAGS) \
$(EVOLUTION_MAIL_CFLAGS) \
- $(DBUS_GLIB_CFLAGS) \
$(LIBNOTIFY_CFLAGS) \
$(CANBERRA_CFLAGS)
@@ -26,7 +25,6 @@ liborg_gnome_mail_notification_la_SOURCES = mail-notification.c
liborg_gnome_mail_notification_la_LDFLAGS = -module -avoid-version $(NO_UNDEFINED)
liborg_gnome_mail_notification_la_LIBADD = \
- $(DBUS_GLIB_LIBS) \
$(CANBERRA_LIBS) \
$(LIBNOTIFY_LIBS) \
$(top_builddir)/e-util/libeutil.la \
diff --git a/plugins/mail-notification/mail-notification.c b/plugins/mail-notification/mail-notification.c
index efce1115ab..d988091fc2 100644
--- a/plugins/mail-notification/mail-notification.c
+++ b/plugins/mail-notification/mail-notification.c
@@ -29,14 +29,12 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <gconf/gconf-client.h>
+#include <gio/gio.h>
#ifdef HAVE_CANBERRA
#include <canberra-gtk.h>
#endif
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
#include <time.h>
#include <e-util/e-binding.h>
@@ -112,39 +110,46 @@ is_part_enabled (const gchar *gconf_key)
#define DBUS_PATH "/org/gnome/evolution/mail/newmail"
#define DBUS_INTERFACE "org.gnome.evolution.mail.dbus.Signal"
-static DBusConnection *bus = NULL;
+static GDBusConnection *connection = NULL;
-static gboolean init_dbus (void);
+static gboolean init_gdbus (void);
static void
send_dbus_message (const gchar *name,
const gchar *data,
- guint new,
+ guint new_count,
const gchar *msg_uid,
const gchar *msg_sender,
const gchar *msg_subject)
{
- DBusMessage *message;
+ GDBusMessage *message;
+ GVariantBuilder *builder;
+ GError *error = NULL;
/* Create a new message on the DBUS_INTERFACE */
- if (!(message = dbus_message_new_signal (DBUS_PATH, DBUS_INTERFACE, name)))
+ if (!(message = g_dbus_message_new_signal (DBUS_PATH, DBUS_INTERFACE, name)))
return;
+ builder = g_variant_builder_new (G_VARIANT_TYPE_TUPLE);
+
/* Appends the data as an argument to the message */
- dbus_message_append_args (message, DBUS_TYPE_STRING, &data, DBUS_TYPE_INVALID);
+ g_variant_builder_add (builder, "(s)", data);
+
+ if (new_count) {
+ gchar *display_name = em_utils_folder_name_from_uri (data);
- if (new) {
- gchar * display_name = em_utils_folder_name_from_uri (data);
- dbus_message_append_args (message,
- DBUS_TYPE_STRING, &display_name, DBUS_TYPE_UINT32, &new,
- DBUS_TYPE_INVALID);
+ g_variant_builder_add (builder, "(s)", display_name);
+ g_variant_builder_add (builder, "(u)", new_count);
+
+ g_free (display_name);
}
- #define add_named_param(name, value) \
- if (value) { \
- gchar *val; \
+ #define add_named_param(name, value) \
+ if (value) { \
+ gchar *val; \
val = g_strconcat (name, ":", value, NULL); \
- dbus_message_append_args (message, DBUS_TYPE_STRING, &val, DBUS_TYPE_INVALID); \
+ g_variant_builder_add (builder, "(s)", val); \
+ g_free (val); \
}
add_named_param ("msg_uid", msg_uid);
@@ -153,58 +158,59 @@ send_dbus_message (const gchar *name,
#undef add_named_param
+ g_dbus_message_set_body (message, g_variant_builder_end (builder));
+
/* Sends the message */
- dbus_connection_send (bus, message, NULL);
+ g_dbus_connection_send_message (connection, message, NULL, &error);
/* Frees the message */
- dbus_message_unref (message);
+ g_object_unref (message);
+
+ if (error) {
+ g_debug ("Mail-Notification: %s: Error while sending DBus message: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
}
static gboolean
-reinit_dbus (gpointer user_data)
+reinit_gdbus (gpointer user_data)
{
- if (!enabled || init_dbus ())
+ if (!enabled || init_gdbus ())
return FALSE;
/* keep trying to re-establish dbus connection */
return TRUE;
}
-static DBusHandlerResult
-filter_function (DBusConnection *connection, DBusMessage *message, gpointer user_data)
+static void
+connection_closed_cb (GDBusConnection *pconnection, gboolean remote_peer_vanished, GError *error, gpointer user_data)
{
- if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") &&
- strcmp (dbus_message_get_path (message), DBUS_PATH_LOCAL) == 0) {
- dbus_connection_unref (bus);
- bus = NULL;
-
- g_timeout_add (3000, reinit_dbus, NULL);
+ g_return_if_fail (connection != pconnection);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
+ g_object_unref (connection);
+ connection = NULL;
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ g_timeout_add (3000, reinit_gdbus, NULL);
}
static gboolean
-init_dbus (void)
+init_gdbus (void)
{
- DBusError error;
+ GError *error = NULL;
- if (bus != NULL)
+ if (connection != NULL)
return TRUE;
- dbus_error_init (&error);
- if (!(bus = dbus_bus_get (DBUS_BUS_SESSION, &error))) {
- g_warning ("could not get system bus: %s\n", error.message);
- dbus_error_free (&error);
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (error) {
+ g_warning ("could not get system bus: %s\n", error->message);
+ g_error_free (error);
+
return FALSE;
}
- dbus_connection_setup_with_g_main (bus, NULL);
- dbus_connection_set_exit_on_disconnect (bus, FALSE);
-
- dbus_connection_add_filter (bus, filter_function, NULL, NULL);
+ g_dbus_connection_set_exit_on_close (connection, FALSE);
+ g_signal_connect (connection, "closed", G_CALLBACK (connection_closed_cb), NULL);
return TRUE;
}
@@ -214,7 +220,7 @@ init_dbus (void)
static void
new_notify_dbus (EMEventTargetFolder *t)
{
- if (bus != NULL)
+ if (connection != NULL)
send_dbus_message (
"Newmail", t->uri, t->new, t->msg_uid,
t->msg_sender, t->msg_subject);
@@ -223,7 +229,7 @@ new_notify_dbus (EMEventTargetFolder *t)
static void
read_notify_dbus (EMEventTargetMessage *t)
{
- if (bus != NULL)
+ if (connection != NULL)
send_dbus_message (
"MessageReading",
camel_folder_get_name (t->folder),
@@ -235,10 +241,10 @@ enable_dbus (gint enable)
{
if (enable) {
/* we ignore errors here */
- init_dbus ();
- } else if (bus != NULL) {
- dbus_connection_unref (bus);
- bus = NULL;
+ init_gdbus ();
+ } else if (connection != NULL) {
+ g_object_unref (connection);
+ connection = NULL;
}
}