[nautilus] Port to GDBus
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] Port to GDBus
- Date: Sun, 30 May 2010 17:47:04 +0000 (UTC)
commit 8a58f4e298e844c18928e5a0681fa8ac2b9f2ee1
Author: Christian Persch <chpe gnome org>
Date: Mon May 17 20:22:54 2010 +0200
Port to GDBus
Bug #618910.
configure.in | 5 +-
libnautilus-private/nautilus-file-utilities.c | 129 +++++++--------
libnautilus-private/nautilus-mime-actions.c | 212 ++++++++++---------------
src/nautilus-application.c | 168 ++++++++++++--------
src/nautilus-application.h | 4 +-
5 files changed, 250 insertions(+), 268 deletions(-)
---
diff --git a/configure.in b/configure.in
index f97be7c..96b021f 100644
--- a/configure.in
+++ b/configure.in
@@ -2,7 +2,7 @@ AC_PREREQ(2.54)
dnl ===========================================================================
-m4_define(glib_minver, 2.24.0)
+m4_define(glib_minver, 2.25.5)
m4_define(gnome_desktop_minver, 2.29.91)
m4_define(pango_minver, 1.1.2)
m4_define(gtk_minver, 2.20.0)
@@ -69,7 +69,6 @@ PKG_CHECK_MODULES(ALL, [
libxml-2.0 >= xml_minver
gail >= gail_minver
unique-1.0
- dbus-glib-1
])
dnl ==========================================================================
@@ -337,7 +336,7 @@ LIBNAUTILUS_EXTENSION_LIBS="`$PKG_CONFIG --libs $LIBNAUTILUS_EXTENSION_MODULES`"
AC_SUBST(LIBNAUTILUS_EXTENSION_LIBS)
dnl core nautilus
-CORE_MODULES="glib-2.0 gnome-desktop-2.0 gthread-2.0 gio-2.0 gio-unix-2.0 unique-1.0 dbus-glib-1 gail gconf-2.0 libxml-2.0 $EXTRA_CORE_MODULES"
+CORE_MODULES="glib-2.0 gnome-desktop-2.0 gthread-2.0 gio-2.0 gio-unix-2.0 unique-1.0 gail gconf-2.0 libxml-2.0 $EXTRA_CORE_MODULES"
CORE_CFLAGS="`$PKG_CONFIG --cflags $CORE_MODULES` $x_cflags"
AC_SUBST(CORE_CFLAGS)
CORE_LIBS="`$PKG_CONFIG --libs $CORE_MODULES` $x_libs"
diff --git a/libnautilus-private/nautilus-file-utilities.c b/libnautilus-private/nautilus-file-utilities.c
index b52b657..4811ef0 100644
--- a/libnautilus-private/nautilus-file-utilities.c
+++ b/libnautilus-private/nautilus-file-utilities.c
@@ -40,7 +40,6 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
-#include <dbus/dbus-glib.h>
#include <unistd.h>
#include <stdlib.h>
@@ -1004,48 +1003,13 @@ nautilus_is_file_roller_installed (void)
#define GSM_NAME "org.gnome.SessionManager"
#define GSM_PATH "/org/gnome/SessionManager"
+#define GSM_INTERFACE "org.gnome.SessionManager"
/* The following values come from
* http://www.gnome.org/~mccann/gnome-session/docs/gnome-session.html#org.gnome.SessionManager.Inhibit
*/
-#define INHIBIT_LOGOUT 1
-#define INHIBIT_SUSPEND 4
-
-static DBusGProxy *_gsm_proxy = NULL;
-
-static DBusGProxy *
-get_power_manager_proxy (void)
-{
- if (!_gsm_proxy)
- {
- DBusGConnection *bus;
- GError *error;
-
- error = NULL;
- bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (!bus)
- {
- g_warning ("Could not connect to session bus: %s",
- error->message);
- g_error_free (error);
- return NULL;
- }
-
- _gsm_proxy = dbus_g_proxy_new_for_name (bus,
- GSM_NAME,
- GSM_PATH,
- GSM_NAME);
- dbus_g_connection_unref (bus);
-
- if (!_gsm_proxy)
- {
- g_warning ("Creating DBus proxy failed.");
- return NULL;
- }
- }
-
- return _gsm_proxy;
-}
+#define INHIBIT_LOGOUT (1U)
+#define INHIBIT_SUSPEND (4U)
/**
* nautilus_inhibit_power_manager:
@@ -1062,31 +1026,44 @@ get_power_manager_proxy (void)
int
nautilus_inhibit_power_manager (const char *message)
{
- DBusGProxy *proxy;
- GError *error;
+ GDBusConnection *connection;
+ GVariant *result;
+ GError *error = NULL;
int cookie;
- proxy = get_power_manager_proxy ();
-
- g_return_val_if_fail (proxy != NULL, -1);
-
- error = NULL;
- cookie = -1;
- if (!dbus_g_proxy_call (proxy, "Inhibit", &error,
- G_TYPE_STRING, "Nautilus",
- G_TYPE_UINT, 0,
- G_TYPE_STRING, message,
- G_TYPE_UINT, INHIBIT_LOGOUT | INHIBIT_SUSPEND,
- G_TYPE_INVALID,
- G_TYPE_UINT, &cookie,
- G_TYPE_INVALID))
- {
+ g_return_val_if_fail (message != NULL, -1);
+
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (connection == NULL) {
+ g_warning ("Could not connect to session bus: %s", error->message);
+ return -1;
+ }
+
+ result = g_dbus_connection_call_sync (connection,
+ GSM_NAME,
+ GSM_PATH,
+ GSM_INTERFACE,
+ "Inhibit",
+ g_variant_new ("(susu)",
+ "Nautilus",
+ (guint) 0,
+ message,
+ (guint) (INHIBIT_LOGOUT | INHIBIT_SUSPEND)),
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ -1 /* FIXME? */,
+ NULL,
+ &error);
+ g_object_unref (connection);
+ if (result == NULL) {
g_warning ("Could not inhibit power management: %s", error->message);
g_error_free (error);
return -1;
}
- return cookie;
+ g_variant_get (result, "(u)", &cookie);
+ g_variant_unref (result);
+
+ return (int) cookie;
}
/**
@@ -1100,24 +1077,36 @@ nautilus_inhibit_power_manager (const char *message)
void
nautilus_uninhibit_power_manager (gint cookie)
{
- DBusGProxy *proxy;
- GError *error;
- g_return_if_fail (cookie > 0);
+ GDBusConnection *connection;
+ GVariant *result;
+ GError *error = NULL;
- proxy = get_power_manager_proxy ();
-
- g_return_if_fail (proxy != NULL);
-
- error = NULL;
+ g_return_if_fail (cookie > 0);
- if (!dbus_g_proxy_call (proxy, "Uninhibit", &error,
- G_TYPE_UINT, cookie,
- G_TYPE_INVALID,
- G_TYPE_INVALID))
- {
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (connection == NULL) {
+ g_warning ("Could not connect to session bus: %s", error->message);
+ return;
+ }
+
+ result = g_dbus_connection_call_sync (connection,
+ GSM_NAME,
+ GSM_PATH,
+ GSM_INTERFACE,
+ "Uninhibit",
+ g_variant_new ("(u)", (guint) cookie),
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ -1 /* FIXME? */,
+ NULL,
+ &error);
+ g_object_unref (connection);
+ if (result == NULL) {
g_warning ("Could not uninhibit power management: %s", error->message);
g_error_free (error);
+ return;
}
+
+ g_variant_unref (result);
}
/* Returns TRUE if the file is in XDG_DATA_DIRS or
diff --git a/libnautilus-private/nautilus-mime-actions.c b/libnautilus-private/nautilus-mime-actions.c
index eb7aae4..b276199 100644
--- a/libnautilus-private/nautilus-mime-actions.c
+++ b/libnautilus-private/nautilus-mime-actions.c
@@ -32,7 +32,6 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <string.h>
-#include <dbus/dbus-glib.h>
#include <gdk/gdkx.h>
#include "nautilus-file-attributes.h"
@@ -1140,6 +1139,7 @@ typedef struct {
char *activation_directory;
gboolean user_confirmation;
char *uri;
+ GDBusProxy *proxy; /* PackageKit proxy */
} ActivateParametersInstall;
static void
@@ -1155,6 +1155,8 @@ activate_parameters_install_free (ActivateParametersInstall *parameters_install)
nautilus_file_list_free (parameters_install->files);
g_free (parameters_install->activation_directory);
g_free (parameters_install->uri);
+ if (parameters_install->proxy)
+ g_object_unref (parameters_install->proxy);
g_free (parameters_install);
}
@@ -1300,20 +1302,20 @@ show_unhandled_type_error (ActivateParametersInstall *parameters)
}
static void
-search_for_application_dbus_call_notify_cb (DBusGProxy *proxy, DBusGProxyCall *call, ActivateParametersInstall *parameters_install)
+search_for_application_dbus_call_notify_cb (GDBusProxy *proxy,
+ GAsyncResult *result,
+ gpointer user_data)
{
- gboolean ret;
+ ActivateParametersInstall *parameters_install = user_data;
+ GVariant *variant;
GError *error = NULL;
- char *message;
- const char *remote = NULL;
- ret = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
- if (!ret) {
- if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
- remote = dbus_g_error_get_name (error);
- }
- /* we already show an error in the installer if not found, just catch generic failure */
- if (remote == NULL || strcmp (remote, "org.freedesktop.PackageKit.Modify.Failed") == 0) {
+ variant = g_dbus_proxy_call_finish (proxy, result, &error);
+ if (variant == NULL) {
+ if (!g_dbus_error_is_remote_error (error) ||
+ g_strcmp0 (g_dbus_error_get_remote_error (error), "org.freedesktop.PackageKit.Modify.Failed") == 0) {
+ char *message;
+
message = g_strdup_printf ("%s\n%s",
_("There was an internal error trying to search for applications:"),
error->message);
@@ -1321,10 +1323,13 @@ search_for_application_dbus_call_notify_cb (DBusGProxy *proxy, DBusGProxyCall *c
parameters_install->parent_window);
g_free (message);
}
+
g_error_free (error);
+ activate_parameters_install_free (parameters_install);
return;
}
- g_object_unref (proxy);
+
+ g_variant_unref (variant);
/* activate the file again */
nautilus_mime_activate_files (parameters_install->parent_window,
@@ -1335,36 +1340,17 @@ search_for_application_dbus_call_notify_cb (DBusGProxy *proxy, DBusGProxyCall *c
parameters_install->flags,
parameters_install->user_confirmation);
- /* parameters_install freed by destroy notify */
+ activate_parameters_install_free (parameters_install);
}
static void
search_for_application_mime_type (ActivateParametersInstall *parameters_install, const gchar *mime_type)
{
- DBusGConnection *connection;
- DBusGProxy *proxy = NULL;
+ GdkWindow *window;
guint xid = 0;
- GError *error = NULL;
- DBusGProxyCall *call = NULL;
- GtkWidget *dialog;
- GdkWindow *window;
const char *mime_types[2];
- /* get bus */
- connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (connection == NULL) {
- g_error_free (error);
- goto out;
- }
-
- /* get proxy - native clients for for KDE and GNOME */
- proxy = dbus_g_proxy_new_for_name (connection,
- "org.freedesktop.PackageKit",
- "/org/freedesktop/PackageKit",
- "org.freedesktop.PackageKit.Modify");
- if (proxy == NULL) {
- goto out;
- }
+ g_assert (parameters_install->proxy != NULL);
/* get XID from parent window */
window = gtk_widget_get_window (GTK_WIDGET (parameters_install->parent_window));
@@ -1372,40 +1358,23 @@ search_for_application_mime_type (ActivateParametersInstall *parameters_install,
xid = GDK_WINDOW_XID (window);
}
- /* don't timeout, as dbus-glib sets the timeout ~25 seconds */
- dbus_g_proxy_set_default_timeout (proxy, INT_MAX);
-
- /* invoke the method */
mime_types[0] = mime_type;
mime_types[1] = NULL;
- call = dbus_g_proxy_begin_call (proxy, "InstallMimeTypes",
- (DBusGProxyCallNotify) search_for_application_dbus_call_notify_cb,
- parameters_install,
- (GDestroyNotify) activate_parameters_install_free,
- G_TYPE_UINT, xid,
- G_TYPE_STRV, mime_types,
- G_TYPE_STRING, "hide-confirm-search",
- G_TYPE_INVALID);
- if (call == NULL) {
- dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("Could not use system package installer"));
- g_signal_connect (G_OBJECT (dialog), "response",
- G_CALLBACK (gtk_widget_destroy), NULL);
- gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
- gtk_widget_show (dialog);
- goto out;
- }
+
+ g_dbus_proxy_call (parameters_install->proxy,
+ "InstallMimeTypes",
+ g_variant_new ("(u^ass)",
+ xid,
+ mime_types,
+ "hide-confirm-search"),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT /* no timeout */,
+ NULL /* cancellable */,
+ (GAsyncReadyCallback) search_for_application_dbus_call_notify_cb,
+ parameters_install);
nautilus_debug_log (FALSE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
"InstallMimeType method invoked for %s", mime_type);
-out:
- if (call == NULL) {
- /* dbus method was not called, so we're not going to get the async dbus callback */
- activate_parameters_install_free (parameters_install);
- }
}
static void
@@ -1425,29 +1394,33 @@ application_unhandled_file_install (GtkDialog *dialog, gint response_id, Activat
}
}
+static gboolean
+delete_cb (GtkDialog *dialog)
+{
+ gtk_dialog_response (dialog, GTK_RESPONSE_DELETE_EVENT);
+ return TRUE;
+}
+
static void
-packagekit_present_dbus_call_notify_cb (DBusGProxy *proxy, DBusGProxyCall *call, ActivateParametersInstall *parameters_install)
+pk_proxy_constructed_cb (GDBusConnection *connection,
+ GAsyncResult *result,
+ gpointer user_data)
{
- gboolean ret;
- GError *error = NULL;
+ ActivateParametersInstall *parameters_install = user_data;
char *mime_type;
char *error_message;
- gboolean present;
GtkWidget *dialog;
+ GError *error = NULL;
-
- ret = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_BOOLEAN, &present, G_TYPE_INVALID);
- if (!ret) {
+ parameters_install->proxy = g_dbus_proxy_new_finish (result, &error);
+ if (parameters_install->proxy == NULL) {
+ nautilus_debug_log (FALSE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
+ "Failed to construct PackageKit bus proxy: %s", error->message);
g_error_free (error);
+
show_unhandled_type_error (parameters_install);
activate_parameters_install_free (parameters_install);
- present = FALSE;
- goto out;
- }
- if (!present) {
- show_unhandled_type_error (parameters_install);
- activate_parameters_install_free (parameters_install);
- goto out;
+ return;
}
mime_type = nautilus_file_get_mime_type (parameters_install->file);
@@ -1463,11 +1436,9 @@ packagekit_present_dbus_call_notify_cb (DBusGProxy *proxy, DBusGProxyCall *call,
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
g_signal_connect (dialog, "response", G_CALLBACK (application_unhandled_file_install), parameters_install);
+ g_signal_connect (dialog, "delete-event", G_CALLBACK (delete_cb), NULL);
gtk_widget_show_all (dialog);
g_free (mime_type);
-
-out:
- g_object_unref (proxy);
}
static void
@@ -1477,9 +1448,7 @@ application_unhandled_uri (ActivateParameters *parameters, char *uri)
char *mime_type;
NautilusFile *file;
ActivateParametersInstall *parameters_install;
- DBusGConnection *connection;
- DBusGProxy *proxy;
- DBusGProxyCall *call;
+ GDBusConnection *connection;
GError *error = NULL;
file = nautilus_file_get_by_uri (uri);
@@ -1495,7 +1464,7 @@ application_unhandled_uri (ActivateParameters *parameters, char *uri)
g_object_add_weak_pointer (G_OBJECT (parameters_install->parent_window), (gpointer *)¶meters_install->parent_window);
}
parameters_install->activation_directory = g_strdup (parameters->activation_directory);
- parameters_install->file = nautilus_file_ref (file);
+ parameters_install->file = file;
parameters_install->files = get_file_list_for_launch_locations (parameters->locations);
parameters_install->mode = parameters->mode;
parameters_install->flags = parameters->flags;
@@ -1512,50 +1481,41 @@ application_unhandled_uri (ActivateParameters *parameters, char *uri)
/* There is no use trying to look for handlers of application/octet-stream */
if (g_content_type_is_unknown (mime_type)) {
show_install_mime = FALSE;
- }
-
- if (!show_install_mime) {
- goto out;
- }
-
- /* Check whether PackageKit can be spawned */
- connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (connection == NULL) {
- g_error_free (error);
- show_install_mime = FALSE;
- goto out;
- }
-
- proxy = dbus_g_proxy_new_for_name (connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
-
- if (proxy == NULL) {
- show_install_mime = FALSE;
- goto out;
- }
- call = dbus_g_proxy_begin_call (proxy, "NameHasOwner",
- (DBusGProxyCallNotify) packagekit_present_dbus_call_notify_cb,
- parameters_install,
- NULL, /* Don't want to free user_data as we need to pass it on */
- G_TYPE_STRING, "org.freedesktop.PackageKit",
- G_TYPE_INVALID);
- if (call == NULL) {
- show_install_mime = FALSE;
- goto out;
- }
+ goto out;
+ }
+
+ if (!show_install_mime) {
+ goto out;
+ }
+
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (connection == NULL) {
+ g_warning ("Could not connect to session bus: %s", error->message);
+ goto out;
+ }
+
+ g_dbus_proxy_new (connection,
+ G_TYPE_DBUS_PROXY,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.freedesktop.PackageKit",
+ "/org/freedesktop/PackageKit",
+ "org.freedesktop.PackageKit.Modify",
+ NULL /* cancellable */,
+ (GAsyncReadyCallback) pk_proxy_constructed_cb,
+ parameters_install);
+
+ g_object_unref (connection);
+ return;
out:
- if (!show_install_mime) {
- /* show an unhelpful dialog */
- show_unhandled_type_error (parameters_install);
- /* The callback wasn't started, so we have to free the parameters */
- activate_parameters_install_free (parameters_install);
- }
+ /* show an unhelpful dialog */
+ show_unhandled_type_error (parameters_install);
+ /* The callback wasn't started, so we have to free the parameters */
+ activate_parameters_install_free (parameters_install);
- nautilus_file_unref (file);
- g_free (mime_type);
+ g_free (mime_type);
}
typedef struct {
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index d9556e8..4705404 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -61,7 +61,6 @@
#include <glib/gstdio.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
-#include <dbus/dbus-glib.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-gtk-macros.h>
#include <eel/eel-stock-dialogs.h>
@@ -125,10 +124,6 @@ static void drive_listen_for_eject_button (GDrive *drive,
NautilusApplication *application);
static void nautilus_application_load_session (NautilusApplication *application);
static char * nautilus_application_get_session_data (void);
-static void ck_session_active_changed_cb (DBusGProxy *proxy,
- gboolean is_active,
- void *user_data);
-
G_DEFINE_TYPE (NautilusApplication, nautilus_application, G_TYPE_OBJECT);
@@ -358,9 +353,16 @@ nautilus_application_finalize (GObject *object)
application->automount_idle_id = 0;
}
+ if (application->ck_session_watch_id != 0) {
+ g_bus_unwatch_proxy (application->ck_session_watch_id);
+ application->ck_session_watch_id = 0;
+ }
+
if (application->ck_session_proxy != NULL) {
- dbus_g_proxy_disconnect_signal (application->ck_session_proxy, "ActiveChanged",
- G_CALLBACK (ck_session_active_changed_cb), NULL);
+ g_signal_handlers_disconnect_matched (application->ck_session_proxy,
+ G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, NULL,
+ application);
g_object_unref (application->ck_session_proxy);
application->ck_session_proxy = NULL;
}
@@ -530,98 +532,130 @@ mark_desktop_files_trusted (void)
g_free (do_once_file);
}
-#define CK_NAME "org.freedesktop.ConsoleKit"
-#define CK_PATH "/org/freedesktop/ConsoleKit"
-
+#define CK_NAME "org.freedesktop.ConsoleKit"
+#define CK_PATH "/org/freedesktop/ConsoleKit"
+#define CK_INTERFACE "org.freedesktop.ConsoleKit"
static void
-ck_session_active_changed_cb (DBusGProxy *proxy,
- gboolean is_active,
- void *user_data)
+ck_session_proxy_signal_cb (GDBusProxy *proxy,
+ const char *sender_name,
+ const char *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
NautilusApplication *application = user_data;
- application->session_is_active = is_active;
+ if (g_strcmp0 (signal_name, "ActiveChanged") == 0) {
+ g_variant_get (parameters, "(b)", &application->session_is_active);
+ }
}
static void
-ck_call_is_active_cb (DBusGProxy *proxy,
- DBusGProxyCall *call_id,
- void *user_data)
+ck_call_is_active_cb (GDBusProxy *proxy,
+ GAsyncResult *result,
+ gpointer user_data)
{
- gboolean res, is_active;
- NautilusApplication *application;
-
- application = user_data;
-
- res = dbus_g_proxy_end_call (proxy, call_id, NULL,
- G_TYPE_BOOLEAN, &is_active,
- G_TYPE_INVALID);
- if (!res) {
- g_object_unref (proxy);
+ NautilusApplication *application = user_data;
+ GVariant *variant;
+ variant = g_dbus_proxy_call_finish (proxy, result, NULL);
+ if (variant == NULL) {
application->session_is_active = TRUE;
return;
}
- application->session_is_active = is_active;
-
- dbus_g_proxy_add_signal (proxy, "ActiveChanged", G_TYPE_BOOLEAN, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (proxy, "ActiveChanged",
- G_CALLBACK (ck_session_active_changed_cb), application,
- NULL);
+ g_variant_get (variant, "(b)", &application->session_is_active);
+ g_variant_unref (variant);
}
static void
-ck_get_current_session_cb (DBusGProxy *proxy,
- DBusGProxyCall *call_id,
- void *user_data)
+ck_session_proxy_constructed_cb (GDBusConnection *connection,
+ GAsyncResult *result,
+ gpointer user_data)
{
- gboolean res;
- char *session_id;
- NautilusApplication *application;
+ NautilusApplication *application = user_data;
+ GError *error = NULL;
+
+ application->ck_session_proxy = g_dbus_proxy_new_finish (result, &error);
+ if (application->ck_session_proxy == NULL) {
+ application->session_is_active = TRUE;
+ g_object_unref (connection);
+ return;
+ }
+
+ g_signal_connect (application->ck_session_proxy, "g-signal",
+ G_CALLBACK (ck_session_proxy_signal_cb),
+ application);
- application = user_data;
+ g_dbus_proxy_call (application->ck_session_proxy,
+ "IsActive",
+ g_variant_new ("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ (GAsyncReadyCallback) ck_call_is_active_cb,
+ application);
- res = dbus_g_proxy_end_call (proxy, call_id, NULL,
- DBUS_TYPE_G_OBJECT_PATH, &session_id, G_TYPE_INVALID);
- if (!res) {
- g_object_unref (proxy);
+ g_object_unref (connection);
+}
+
+static void
+ck_get_current_session_cb (GDBusConnection *connection,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ NautilusApplication *application = user_data;
+ GVariant *variant;
+ const char *session_path;
+ GError *error = NULL;
+
+ variant = g_dbus_connection_call_finish (connection, result, &error);
+ if (variant == NULL) {
+ g_warning ("Failed to get the current session: %s", error->message);
+ g_error_free (error);
+ g_object_unref (connection);
application->session_is_active = TRUE;
return;
}
- application->ck_session_proxy = dbus_g_proxy_new_from_proxy (proxy, CK_NAME ".Session",
- session_id);
- dbus_g_proxy_begin_call (application->ck_session_proxy, "IsActive", ck_call_is_active_cb,
- application, NULL, G_TYPE_INVALID);
+ g_variant_get (variant, "(&o)", session_path);
- g_free (session_id);
- g_object_unref (proxy);
-}
+ g_dbus_proxy_new (connection,
+ G_TYPE_DBUS_PROXY,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ CK_NAME,
+ session_path,
+ CK_INTERFACE ".Session",
+ NULL,
+ (GAsyncReadyCallback) ck_session_proxy_constructed_cb,
+ application);
+ g_variant_unref (variant);
+}
static void
do_initialize_consolekit (NautilusApplication *application)
{
- DBusGConnection *conn;
- DBusGProxy *proxy;
- GError *error = NULL;
-
- conn = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (error) {
- g_error_free (error);
-
- application->session_is_active = TRUE;
+ GDBusConnection *connection;
- return;
- }
+ connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
+ if (connection == NULL) {
+ application->session_is_active = TRUE;
+ return;
+ }
- proxy = dbus_g_proxy_new_for_name (conn, CK_NAME, CK_PATH "/Manager",
- CK_NAME ".Manager");
- dbus_g_proxy_begin_call (proxy, "GetCurrentSession",
- ck_get_current_session_cb, application,
- NULL, G_TYPE_INVALID);
+ g_dbus_connection_call (connection,
+ CK_NAME,
+ CK_PATH "/Manager",
+ CK_INTERFACE ".Manager",
+ "GetCurrentSession",
+ g_variant_new ("()"),
+ G_DBUS_CALL_FLAGS_NONE /* FIXME? */,
+ -1,
+ NULL /* FIXME? */,
+ (GAsyncReadyCallback) ck_get_current_session_cb,
+ application);
}
static void
diff --git a/src/nautilus-application.h b/src/nautilus-application.h
index 95c201e..0763e01 100644
--- a/src/nautilus-application.h
+++ b/src/nautilus-application.h
@@ -31,7 +31,6 @@
#include <gio/gio.h>
#include <unique/unique.h>
#include <libegg/eggsmclient.h>
-#include <dbus/dbus-glib.h>
#include <libnautilus-private/nautilus-undo-manager.h>
#define NAUTILUS_DESKTOP_ICON_VIEW_IID "OAFIID:Nautilus_File_Manager_Desktop_Icon_View"
@@ -67,7 +66,8 @@ typedef struct {
NautilusUndoManager *undo_manager;
GVolumeMonitor *volume_monitor;
unsigned int automount_idle_id;
- DBusGProxy *ck_session_proxy;
+ GDBusProxy *ck_session_proxy;
+ guint ck_session_watch_id;
gboolean session_is_active;
} NautilusApplication;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]