diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2009-03-03 19:55:05 +0000 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@src.gnome.org> | 2009-03-03 19:55:05 +0000 |
commit | b42c5902938f5bad7c8634714d8e0b39e02793a1 (patch) | |
tree | 5452759eb8b33b3e67b58b134bfe9eb67e698f50 /src | |
parent | b25c624aff60381c30ab7950219b79ed0838b50e (diff) | |
download | nautilus-b42c5902938f5bad7c8634714d8e0b39e02793a1.tar.gz |
commit properly the previous ConsoleKit patch.
2009-03-03 Cosimo Cecchi <cosimoc@gnome.org>
* src/nautilus-application.c (nautilus_application_finalize),
(ck_session_active_changed_cb), (ck_call_is_active_cb),
(ck_get_current_session_cb), (do_initialize_consolekit),
(finish_startup), (mount_added_callback):
* src/nautilus-application.h: commit properly the previous
ConsoleKit patch.
svn path=/trunk/; revision=15050
Diffstat (limited to 'src')
-rw-r--r-- | src/nautilus-application.c | 112 | ||||
-rw-r--r-- | src/nautilus-application.h | 3 |
2 files changed, 115 insertions, 0 deletions
diff --git a/src/nautilus-application.c b/src/nautilus-application.c index 52ac32a33..e559abd61 100644 --- a/src/nautilus-application.c +++ b/src/nautilus-application.c @@ -60,6 +60,7 @@ #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> @@ -123,6 +124,10 @@ static void drive_listen_for_eject_button (GDrive *drive, static gboolean is_kdesktop_present (void); 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); @@ -346,6 +351,13 @@ nautilus_application_finalize (GObject *object) application->automount_idle_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_object_unref (application->ck_session_proxy); + application->ck_session_proxy = NULL; + } + G_OBJECT_CLASS (nautilus_application_parent_class)->finalize (object); } @@ -511,6 +523,99 @@ mark_desktop_files_trusted (void) g_free (do_once_file); } +#define CK_NAME "org.freedesktop.ConsoleKit" +#define CK_PATH "/org/freedesktop/ConsoleKit" + +static void +ck_session_active_changed_cb (DBusGProxy *proxy, + gboolean is_active, + void *user_data) +{ + NautilusApplication *application = user_data; + + application->session_is_active = is_active; +} + +static void +ck_call_is_active_cb (DBusGProxy *proxy, + DBusGProxyCall *call_id, + void *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); + + 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); +} + +static void +ck_get_current_session_cb (DBusGProxy *proxy, + DBusGProxyCall *call_id, + void *user_data) +{ + gboolean res; + char *session_id; + NautilusApplication *application; + + application = user_data; + + 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); + + 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_object_unref (proxy); +} + + +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; + + 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); +} + static void do_upgrades_once (NautilusApplication *application, gboolean no_desktop) @@ -538,6 +643,9 @@ finish_startup (NautilusApplication *application, /* Initialize the desktop link monitor singleton */ nautilus_desktop_link_monitor_get (); + /* Initialize the ConsoleKit listener for active session */ + do_initialize_consolekit (application); + /* Watch for mounts so we can restore open windows This used * to be for showing new window on mount, but is not used * anymore */ @@ -1386,6 +1494,10 @@ mount_added_callback (GVolumeMonitor *monitor, { NautilusDirectory *directory; GFile *root; + + if (!application->session_is_active) { + return; + } root = g_mount_get_root (mount); directory = nautilus_directory_get_existing (root); diff --git a/src/nautilus-application.h b/src/nautilus-application.h index ed3fd33d1..fc54469ef 100644 --- a/src/nautilus-application.h +++ b/src/nautilus-application.h @@ -31,6 +31,7 @@ #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" @@ -60,6 +61,8 @@ typedef struct { NautilusUndoManager *undo_manager; GVolumeMonitor *volume_monitor; unsigned int automount_idle_id; + DBusGProxy *ck_session_proxy; + gboolean session_is_active; } NautilusApplication; typedef struct { |