diff options
author | Conor Curran <conor.curran@canonical.com> | 2011-07-14 13:06:38 +0100 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2011-07-14 13:06:38 +0100 |
commit | d8eae0b9560084bc68781d73c14fcb54cd53fd02 (patch) | |
tree | 5154306e3838d7617fa1c6dc8270317461e5b68b | |
parent | ee23d617b4f66ddeddaa355faef5760d62314823 (diff) | |
download | ayatana-indicator-session-d8eae0b9560084bc68781d73c14fcb54cd53fd02.tar.gz ayatana-indicator-session-d8eae0b9560084bc68781d73c14fcb54cd53fd02.tar.bz2 ayatana-indicator-session-d8eae0b9560084bc68781d73c14fcb54cd53fd02.zip |
dynamic user menu hiding on the way#
-rw-r--r-- | src/indicator-session.c | 58 | ||||
-rw-r--r-- | src/session-dbus.c | 42 | ||||
-rw-r--r-- | src/session-dbus.h | 1 | ||||
-rw-r--r-- | src/session-dbus.xml | 9 | ||||
-rw-r--r-- | src/session-service.c | 4 |
5 files changed, 104 insertions, 10 deletions
diff --git a/src/indicator-session.c b/src/indicator-session.c index ab3e87a..704e959 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -65,6 +65,7 @@ struct _IndicatorSession { IndicatorServiceManager * service; IndicatorObjectEntry users; IndicatorObjectEntry devices; + gboolean show_users_entry; GCancellable * service_proxy_cancel; GDBusProxy * service_proxy; }; @@ -94,6 +95,7 @@ static void service_connection_cb (IndicatorServiceManager * sm, gboolean connec static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data); static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); static void user_real_name_get_cb (GObject * obj, GAsyncResult * res, gpointer user_data); +static void user_menu_visibility_get_cb (GObject* obj, GAsyncResult* res, gpointer user_data); static void indicator_session_class_init (IndicatorSessionClass *klass); static void indicator_session_init (IndicatorSession *self); @@ -122,6 +124,7 @@ indicator_session_init (IndicatorSession *self) self->service = NULL; self->service_proxy_cancel = NULL; self->service_proxy = NULL; + self->show_users_entry = FALSE; /* Now let's fire these guys up. */ self->service = indicator_service_manager_new_version(INDICATOR_SESSION_DBUS_NAME, @@ -244,8 +247,10 @@ indicator_session_get_entries (IndicatorObject* obj) IndicatorSession* self = INDICATOR_SESSION (obj); GList * retval = NULL; - - retval = g_list_prepend (retval, &self->users); + // Only show the users menu if we have more than one + if (self->show_users_entry == TRUE){ + retval = g_list_prepend (retval, &self->users); + } retval = g_list_prepend (retval, &self->devices); if (retval != NULL) { @@ -263,7 +268,15 @@ service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointe if (connected) { if (self->service_proxy != NULL){ // Its a reconnect ! - // fetch the users's real name and return + // Fetch synchronisation data and return (proxy is still legit) + g_dbus_proxy_call (self->service_proxy, + "GetUserMenuVisibility", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + user_menu_visibility_get_cb, + user_data); g_dbus_proxy_call (self->service_proxy, "GetUserRealName", NULL, @@ -317,6 +330,16 @@ service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self); + // Figure out whether we should show the user menu at all. + g_dbus_proxy_call (self->service_proxy, + "GetUserMenuVisibility", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + user_menu_visibility_get_cb, + user_data); + // Fetch the user's real name for the user entry label g_dbus_proxy_call (self->service_proxy, "GetUserRealName", @@ -382,6 +405,31 @@ user_real_name_get_cb (GObject * obj, GAsyncResult * res, gpointer user_data) return; } +static void +user_menu_visibility_get_cb (GObject* obj, GAsyncResult* res, gpointer user_data) +{ + IndicatorSession * self = INDICATOR_SESSION(user_data); + GError * error = NULL; + GVariant * result; + + result = g_dbus_proxy_call_finish(self->service_proxy, res, &error); + + if (error != NULL) { + g_warning ("unable to complete real name dbus query"); + g_error_free (error); + return; + } + gboolean update; + g_variant_get (result, "(b)", &update); + g_debug ("GET VISIBILITY CB: NEW VALUE = %i", update); + self->show_users_entry = update; + g_signal_emit_by_name (user_data, + "entry-added", + self->parent, + self->users); + return; +} + /* Receives all signals from the service, routed to the appropriate functions */ static void @@ -398,6 +446,10 @@ receive_signal (GDBusProxy * proxy, g_variant_get (parameters, "(s)", &username); indicator_session_update_users_label (self, username); } + else if (g_strcmp0(signal_name, "UserMenuIsVisible") == 0) { + gboolean result = g_variant_get_boolean (parameters); + g_debug ("GET VISIBILITY signal: NEW VALUE = %i", result); + } return; } diff --git a/src/session-dbus.c b/src/session-dbus.c index d28629b..9e24141 100644 --- a/src/session-dbus.c +++ b/src/session-dbus.c @@ -38,6 +38,7 @@ static void bus_method_call (GDBusConnection * connection, const gchar * sender, typedef struct _SessionDbusPrivate SessionDbusPrivate; struct _SessionDbusPrivate { gchar * name; + gboolean user_menu_is_visible; GDBusConnection * bus; GCancellable * bus_cancel; guint dbus_registration; @@ -103,6 +104,7 @@ session_dbus_init (SessionDbus *self) priv->bus = NULL; priv->bus_cancel = NULL; priv->dbus_registration = 0; + priv->user_menu_is_visible = FALSE; priv->bus_cancel = g_cancellable_new(); g_bus_get(G_BUS_TYPE_SESSION, @@ -161,15 +163,20 @@ bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data) { - SessionDbus * service = SESSION_DBUS(user_data); + SessionDbus * service = SESSION_DBUS (user_data); + SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE (service); + GVariant * retval = NULL; if (g_strcmp0(method, "GetUserRealName") == 0) { retval = get_users_real_name (service); - } else { - g_warning("Calling method '%s' on the indicator service and it's unknown", method); } - + else if (g_strcmp0 (method, "GetUserMenuVisibility") == 0){ + retval = g_variant_new ("(b)", priv->user_menu_is_visible); + } + else { + g_warning("Calling method '%s' on the indicator service and it's unknown", method); + } g_dbus_method_invocation_return_value(invocation, retval); return; } @@ -264,3 +271,30 @@ session_dbus_set_users_real_name (SessionDbus * session, const gchar * name) } return; } + +void +session_dbus_set_user_menu_visibility (SessionDbus* session, + gboolean visible) +{ + SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(session); + GError * error = NULL; + + g_debug ("sesssion dbus set user visibility - %i", visible); + + priv->user_menu_is_visible = visible; + + if (priv->bus != NULL) { + g_dbus_connection_emit_signal (priv->bus, + NULL, + INDICATOR_SESSION_SERVICE_DBUS_OBJECT, + INDICATOR_SESSION_SERVICE_DBUS_IFACE, + "UserMenuIsVisible", + g_variant_new ("(b)", priv->user_menu_is_visible), + &error); + + if (error != NULL) { + g_warning("Unable to send UserMenuIsVisible signal: %s", error->message); + g_error_free(error); + } + } +} diff --git a/src/session-dbus.h b/src/session-dbus.h index 377212b..45ebae2 100644 --- a/src/session-dbus.h +++ b/src/session-dbus.h @@ -50,6 +50,7 @@ GType session_dbus_get_type (void); SessionDbus * session_dbus_new (void); void session_dbus_set_name (SessionDbus * session, const gchar * name); void session_dbus_set_users_real_name (SessionDbus * session, const gchar * name); +void session_dbus_set_user_menu_visibility (SessionDbus* session, gboolean visible); G_END_DECLS diff --git a/src/session-dbus.xml b/src/session-dbus.xml index 82c8dc8..f496ff1 100644 --- a/src/session-dbus.xml +++ b/src/session-dbus.xml @@ -2,14 +2,17 @@ <node name="/com/canonical/indicator/session/service"> <interface name="com.canonical.indicator.session.service"> - <!-- Icon --> <method name="GetUserRealName"> <arg name="name" direction="out" type="s"/> </method> - + <method name="GetUserMenuVisibility"> + <arg name="update" direction="out" type="b"/> + </method> <signal name="UserRealNameUpdated"> <arg name="name" type="s"/> </signal> - + <signal name="UserMenuIsVisible"> + <arg name="update" type="b"/> + </signal> </interface> </node> diff --git a/src/session-service.c b/src/session-service.c index 2110241..812769e 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -490,6 +490,10 @@ rebuild_user_items (DbusmenuMenuitem *root, GList * users = NULL; users = users_service_dbus_get_user_list (service); guint user_count = g_list_length(users); + g_debug ("USER COUNT = %i", user_count); + // We only want to show this menu when we have more than one registered + // user + session_dbus_set_user_menu_visibility (session_dbus, user_count > 1); if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { users = g_list_sort (users, (GCompareFunc)compare_users_by_username); |