diff --git a/gvfs/monitor/proxy/gvfsproxyvolumemonitordaemon.c b/gvfs/monitor/proxy/gvfsproxyvolumemonitordaemon.c index 0201cf2..4e87a7a 100644 --- a/gvfs/monitor/proxy/gvfsproxyvolumemonitordaemon.c +++ b/gvfs/monitor/proxy/gvfsproxyvolumemonitordaemon.c @@ -45,6 +45,8 @@ static gboolean always_call_mount = FALSE; static GVfsRemoteVolumeMonitor *monitor_daemon = NULL; +static GDBusProxy *session_active_proxy = NULL; + #define DEBUG_ENABLED #ifdef DEBUG_ENABLED @@ -1750,7 +1752,32 @@ emit_signal (GVfsRemoteVolumeMonitor *instance, MonitorSignalFunc signal_func, v { char *id; GVariant *val; - + GVariant *res = NULL, *inner = NULL; + GError *error = NULL; + gchar *state; + + if (session_active_proxy != NULL) { + res = g_dbus_proxy_call_sync (session_active_proxy , "Get", + g_variant_new( "(ss)", + "org.freedesktop.login1.Session", + "State"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error + ); + + + if (error == NULL && res != NULL) { + g_variant_get(res, "(v)", &inner ); + state = g_variant_get_string(inner,NULL); + } else if (error != NULL ) { + print_debug ("Error in dbus - %s", error->message); + g_error_free (error); + } + } + if (session_active_proxy == NULL || g_strcmp0(state,"active") == 0) { + print_debug ("emit_signal: %p", object); id = g_strdup_printf ("%p", object); @@ -1759,6 +1786,13 @@ emit_signal (GVfsRemoteVolumeMonitor *instance, MonitorSignalFunc signal_func, v signal_func (instance, the_dbus_name, id, val); g_free (id); + } + else print_debug ("inactive session\n"); + + if (inner != NULL) + g_variant_unref (inner); + if (res != NULL) + g_variant_unref (res); } static void @@ -1980,6 +2014,10 @@ g_vfs_proxy_volume_monitor_daemon_main (int argc, GType volume_monitor_type) { guint name_owner_id; + GDBusProxy *logind_proxy; + GVariant *res; + GError *error = NULL; + gchar *session_obj_path; name_owner_id = 0; @@ -1994,6 +2032,47 @@ g_vfs_proxy_volume_monitor_daemon_main (int argc, the_dbus_name = dbus_name; unique_names_being_watched = g_hash_table_new_full (g_str_hash, g_int_equal, g_free, NULL); + logind_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + "org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + NULL, + &error ); + if (logind_proxy == NULL) { + print_debug("Error creating proxy - %s", error->message); + g_error_free (error); + } else { + res = g_dbus_proxy_call_sync (logind_proxy, "GetSessionByPID", + g_variant_new( "(u)", getpid() ), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error + ); + + if (error == NULL && res != NULL) { + g_variant_get(res,"(o)", &session_obj_path); + } + else { + print_debug( "Error getting session - %s", error->message); + } + + g_object_unref(logind_proxy); + session_active_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + "org.freedesktop.login1", + session_obj_path, + "org.freedesktop.DBus.Properties", + NULL, + &error ); + if (session_active_proxy == NULL) { + g_error_free (error); + } + } + /* try and create the monitor */ monitor_try_create ();