diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | data/com.canonical.indicator.session.gschema.xml.in | 6 | ||||
-rw-r--r-- | src/apt-transaction.c | 33 | ||||
-rw-r--r-- | src/apt-watcher.c | 141 | ||||
-rw-r--r-- | src/dbus-shared-names.h | 2 | ||||
-rw-r--r-- | src/indicator-session.c | 22 | ||||
-rw-r--r-- | src/settings-helper.c | 6 | ||||
-rw-r--r-- | src/settings-helper.h | 3 | ||||
-rw-r--r-- | src/user-menu-mgr.c | 47 | ||||
-rw-r--r-- | src/users-service-dbus.c | 59 | ||||
-rw-r--r-- | src/users-service-dbus.h | 2 |
11 files changed, 233 insertions, 90 deletions
diff --git a/configure.ac b/configure.ac index a2f96f5..a89c30d 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT(src/indicator-session.c) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-session, 0.3.4) +AM_INIT_AUTOMAKE(indicator-session, 0.3.4.3) AM_MAINTAINER_MODE diff --git a/data/com.canonical.indicator.session.gschema.xml.in b/data/com.canonical.indicator.session.gschema.xml.in index d1d7d4c..e0d14c3 100644 --- a/data/com.canonical.indicator.session.gschema.xml.in +++ b/data/com.canonical.indicator.session.gschema.xml.in @@ -20,5 +20,11 @@ <_summary>Remove the shutdown item from the session menu</_summary> <_description>Makes it so that the shutdown button doesn’t show in the session menu.</_description> </key> + <key type="b" name="user-show-menu"> + <default>true</default> + <summary>Determine the visibility of the User Menu</summary> + <description>Allow for the user menu to be hidden by the user.</description> + </key> </schema> + </schemalist> diff --git a/src/apt-transaction.c b/src/apt-transaction.c index be1c57b..317d74a 100644 --- a/src/apt-transaction.c +++ b/src/apt-transaction.c @@ -160,7 +160,7 @@ apt_transaction_receive_signal (GDBusProxy * proxy, AptTransaction* self = APT_TRANSACTION(user_data); AptState current_state = DONT_KNOW; - if (g_strcmp0(signal_name, "PropertyChanged") == 0 && self->type == SIMULATION) + if (g_strcmp0(signal_name, "PropertyChanged") == 0) { gchar* prop_name= NULL; GVariant* value = NULL; @@ -204,23 +204,22 @@ apt_transaction_receive_signal (GDBusProxy * proxy, current_state = UP_TO_DATE; } } - } - else if (g_strcmp0(signal_name, "PropertyChanged") == 0 && - self->type == REAL) - { - GVariant* role = g_dbus_proxy_get_cached_property (self->proxy, - "Role"); - if (g_variant_is_of_type (role, G_VARIANT_TYPE_STRING) == TRUE){ - gchar* current_role = NULL; - g_variant_get (role, "s", ¤t_role); - g_debug ("Current transaction role = %s", current_role); - if (g_strcmp0 (current_role, "role-commit-packages") == 0 || - g_strcmp0 (current_role, "role-upgrade-system") == 0){ - g_debug ("UPGRADE IN PROGRESS"); - current_state = UPGRADE_IN_PROGRESS; + if (self->type == REAL) + { + GVariant* role = g_dbus_proxy_get_cached_property (self->proxy, + "Role"); + if (g_variant_is_of_type (role, G_VARIANT_TYPE_STRING) == TRUE){ + gchar* current_role = NULL; + g_variant_get (role, "s", ¤t_role); + //g_debug ("Current transaction role = %s", current_role); + if (g_strcmp0 (current_role, "role-commit-packages") == 0 || + g_strcmp0 (current_role, "role-upgrade-system") == 0){ + g_debug ("UPGRADE IN PROGRESS"); + current_state = UPGRADE_IN_PROGRESS; + } } - } - } + } + } else if (g_strcmp0(signal_name, "Finished") == 0) { g_debug ("TRANSACTION Finished"); diff --git a/src/apt-watcher.c b/src/apt-watcher.c index f5c9d55..e5e1d0e 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -66,6 +66,13 @@ static void apt_watcher_signal_cb (GDBusProxy* proxy, static void apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id); static gboolean apt_watcher_query_reboot_status (gpointer self); +static void apt_watcher_transaction_state_simulation_update_cb (AptTransaction* trans, + gint update, + gpointer user_data); +static void apt_watcher_transaction_state_real_update_cb (AptTransaction* trans, + gint update, + gpointer user_data); + @@ -245,9 +252,9 @@ apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi, } static void -apt_watcher_transaction_state_update_cb (AptTransaction* trans, - gint update, - gpointer user_data) +apt_watcher_transaction_state_real_update_cb (AptTransaction* trans, + gint update, + gpointer user_data) { g_debug ("apt-watcher -transaction update %i", update); g_return_if_fail (APT_IS_WATCHER (user_data)); @@ -259,59 +266,99 @@ apt_watcher_transaction_state_update_cb (AptTransaction* trans, dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Software Up to Date")); - // Simulations don't send a finished signal for some reason - // Anyway from a simulation we just need one state update - // (updates available or not) - if (apt_transaction_get_transaction_type (self->current_transaction) - == SIMULATION){ - g_object_unref (G_OBJECT(self->current_transaction)); - self->current_transaction = NULL; - } - if (self->reboot_query != 0){ - g_source_remove (self->reboot_query); - self->reboot_query = 0; - } - // Wait a sec before querying for reboot status, - // race condition with Apt has been observed. - self->reboot_query = g_timeout_add_seconds (1, - apt_watcher_query_reboot_status, - self); + self->current_state = state; } else if (state == UPDATES_AVAILABLE){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Updates Available…")); - // Simulations don't send a finished signal for some reason - // Anyway from a simulation we just need one state update - // (updates available or not) - if (apt_transaction_get_transaction_type (self->current_transaction) - == SIMULATION){ - g_object_unref (G_OBJECT(self->current_transaction)); - self->current_transaction = NULL; - } + self->current_state = state; } else if (state == UPGRADE_IN_PROGRESS){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Updates Installing…")); + self->current_state = state; } else if (state == FINISHED){ + gboolean query_again = FALSE; + + // Only query if the previous state was an upgrade. + if (self->current_state == UPGRADE_IN_PROGRESS){ + if (self->reboot_query != 0){ + g_source_remove (self->reboot_query); + self->reboot_query = 0; + } + // Wait a sec before querying for reboot status, + // race condition with Apt has been observed. + self->reboot_query = g_timeout_add_seconds (2, + apt_watcher_query_reboot_status, + self); + } + else{ + query_again = TRUE; + } + self->current_state = state; + g_object_unref (G_OBJECT(self->current_transaction)); - self->current_transaction = NULL; + self->current_transaction = NULL; + + // It is impossible to determine from a 'real' transaction whether + // updates are available ? + if (query_again){ + g_dbus_proxy_call (self->proxy, + "UpgradeSystem", + g_variant_new("(b)", TRUE), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + apt_watcher_upgrade_system_cb, + self); + } + } +} + + +static void +apt_watcher_transaction_state_simulation_update_cb (AptTransaction* trans, + gint update, + gpointer user_data) +{ + g_debug ("apt-watcher -transaction update %i", update); + g_return_if_fail (APT_IS_WATCHER (user_data)); + AptWatcher* self = APT_WATCHER (user_data); + + AptState state = (AptState)update; + + if (state == UP_TO_DATE){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Software Up to Date")); if (self->reboot_query != 0){ g_source_remove (self->reboot_query); self->reboot_query = 0; } - // Wait a sec before querying for reboot status, - // race condition with Apt has been observed. - self->reboot_query = g_timeout_add_seconds (1, + self->reboot_query = g_timeout_add_seconds (2, apt_watcher_query_reboot_status, self); + } + else if (state == UPDATES_AVAILABLE){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, - _("Finished Updating…")); + _("Updates Available…")); } + else if (state == UPGRADE_IN_PROGRESS){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Updates Installing…")); + } + self->current_state = state; + + if (self->current_state != UPGRADE_IN_PROGRESS){ + g_object_unref (G_OBJECT(self->current_transaction)); + self->current_transaction = NULL; + } } static void @@ -321,7 +368,7 @@ apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id) self->current_transaction = apt_transaction_new (transaction_id, SIMULATION); g_signal_connect (G_OBJECT(self->current_transaction), "state-update", - G_CALLBACK(apt_watcher_transaction_state_update_cb), self); + G_CALLBACK(apt_watcher_transaction_state_simulation_update_cb), self); } } @@ -354,13 +401,12 @@ apt_watcher_query_reboot_status (gpointer data) DBUSMENU_MENUITEM_PROP_DISPOSITION, DBUSMENU_MENUITEM_DISPOSITION_ALERT); session_dbus_restart_required (self->session_dbus_interface); + self->current_state = RESTART_NEEDED; } self->reboot_query = 0; return FALSE; } -// TODO - Ask MVO about this. -// Signal is of type s not sas which is on d-feet. static void apt_watcher_signal_cb ( GDBusProxy* proxy, gchar* sender_name, gchar* signal_name, @@ -374,21 +420,30 @@ static void apt_watcher_signal_cb ( GDBusProxy* proxy, GVariant *value = g_variant_get_child_value (parameters, 0); if (g_strcmp0(signal_name, "ActiveTransactionsChanged") == 0){ - gchar* input = NULL; - g_variant_get(value, "s", & input); - if (g_str_has_prefix (input, "/org/debian/apt/transaction/") == TRUE){ - g_debug ("Active Transactions signal - input is null = %i", input == NULL); - + gchar* current = NULL; + g_debug ("ActiveTransactionsChanged"); + + g_variant_get(value, "s", ¤t); + + if (g_str_has_prefix (current, "/org/debian/apt/transaction/") == TRUE){ + g_debug ("ActiveTransactionsChanged - current is %s", current); + + // Cancel all existing operations. + if (self->reboot_query != 0){ + g_source_remove (self->reboot_query); + self->reboot_query = 0; + } + if (self->current_transaction != NULL) { g_object_unref (G_OBJECT(self->current_transaction)); self->current_transaction = NULL; } - self->current_transaction = apt_transaction_new (input, REAL); + self->current_transaction = apt_transaction_new (current, REAL); g_signal_connect (G_OBJECT(self->current_transaction), "state-update", - G_CALLBACK(apt_watcher_transaction_state_update_cb), self); + G_CALLBACK(apt_watcher_transaction_state_real_update_cb), self); } } g_variant_unref (parameters); diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index c5372e4..5f35903 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -63,5 +63,7 @@ typedef enum { #define ICON_DEFAULT "system-devices-panel" #define ICON_RESTART "system-devices-panel-alert" +#define GREETER_ICON_DEFAULT "system-shutdown-panel" +#define GREETER_ICON_RESTART "system-shutdown-panel-restart" #endif /* __DBUS_SHARED_NAMES_H__ */ diff --git a/src/indicator-session.c b/src/indicator-session.c index aacef49..f41c841 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -70,6 +70,8 @@ struct _IndicatorSession { GDBusProxy * service_proxy; }; +static gboolean greeter_mode; + GType indicator_session_get_type (void); /* Indicator stuff */ @@ -164,10 +166,18 @@ indicator_session_init (IndicatorSession *self) self->users.label = GTK_LABEL (gtk_label_new (NULL)); + const gchar *greeter_var; + greeter_var = g_getenv("INDICATOR_GREETER_MODE"); + greeter_mode = g_strcmp0(greeter_var, "1") == 0; // devices self->devices.menu = GTK_MENU (dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT)); - self->devices.image = indicator_image_helper (ICON_DEFAULT); + if (greeter_mode){ + self->devices.image = indicator_image_helper (GREETER_ICON_DEFAULT); + } + else{ + self->devices.image = indicator_image_helper (ICON_DEFAULT); + } gtk_widget_show (GTK_WIDGET(self->devices.menu)); gtk_widget_show (GTK_WIDGET(self->devices.image)); @@ -497,8 +507,14 @@ receive_signal (GDBusProxy * proxy, &self->users); } } - else if (g_strcmp0(signal_name, "RestartRequired") == 0) { - self->devices.image = indicator_image_helper (ICON_RESTART); + else if (g_strcmp0(signal_name, "RestartRequired") == 0) { + if (greeter_mode == TRUE){ + self->devices.image = indicator_image_helper (GREETER_ICON_RESTART); + } + else{ + g_debug ("reboot required"); + self->devices.image = indicator_image_helper (ICON_RESTART); + } } } diff --git a/src/settings-helper.c b/src/settings-helper.c index 5a69d17..d70df95 100644 --- a/src/settings-helper.c +++ b/src/settings-helper.c @@ -53,6 +53,12 @@ supress_confirmations (void) { } gboolean +should_show_user_menu (void) { + build_settings(); + return g_settings_get_boolean (settings, SHOW_USER_MENU) ; +} + +gboolean show_logout (void) { build_settings(); return !g_settings_get_boolean (settings, LOGOUT_KEY) ; diff --git a/src/settings-helper.h b/src/settings-helper.h index 7b377ca..ae57575 100644 --- a/src/settings-helper.h +++ b/src/settings-helper.h @@ -36,6 +36,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define LOGOUT_KEY "suppress-logout-menuitem" #define RESTART_KEY "suppress-restart-menuitem" #define SHUTDOWN_KEY "suppress-shutdown-menuitem" +#define SHOW_USER_MENU "user-show-menu" #define LOCKDOWN_SCHEMA "org.gnome.desktop.lockdown" #define LOCKDOWN_KEY_USER "disable-user-switching" @@ -56,5 +57,7 @@ gboolean supress_confirmations (void); gboolean show_logout (void); gboolean show_restart (void); gboolean show_shutdown (void); +gboolean should_show_user_menu (void); + #endif /* __GCONF_HELPER__ */ diff --git a/src/user-menu-mgr.c b/src/user-menu-mgr.c index a4308dd..efb3f7d 100644 --- a/src/user-menu-mgr.c +++ b/src/user-menu-mgr.c @@ -18,7 +18,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <libdbusmenu-glib/client.h> - #include "user-menu-mgr.h" #include "settings-helper.h" #include "dbus-shared-names.h" @@ -54,21 +53,19 @@ static void activate_online_accounts (DbusmenuMenuitem *mi, gpointer user_data); static void activate_user_accounts (DbusmenuMenuitem *mi, guint timestamp, - gpointer user_data); - + gpointer user_data); static void user_menu_mgr_rebuild_items (UserMenuMgr *self, gboolean greeter_mode); static gboolean check_new_session (); static void user_change (UsersServiceDbus *service, const gchar *user_id, gpointer user_data); - static void ensure_settings_client (); -static gboolean check_guest_session (void); +static gboolean is_this_guest_session (void); static void activate_guest_session (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data); - + G_DEFINE_TYPE (UserMenuMgr, user_menu_mgr, G_TYPE_OBJECT); @@ -133,6 +130,25 @@ user_menu_mgr_rebuild_items (UserMenuMgr *self, gboolean greeter_mode) if (can_activate == TRUE) { + gboolean guest_enabled = users_service_dbus_guest_session_enabled (self->users_dbus_interface); + GList * users = NULL; + users = users_service_dbus_get_user_list (self->users_dbus_interface); + self->user_count = g_list_length(users); + + gboolean gsettings_user_menu_is_visible = should_show_user_menu(); + + if (gsettings_user_menu_is_visible == FALSE || greeter_mode == TRUE){ + session_dbus_set_user_menu_visibility (self->session_dbus_interface, + FALSE); + } + else{ + // This needs to be updated once the ability to query guest session support is available + session_dbus_set_user_menu_visibility (self->session_dbus_interface, + guest_enabled || self->user_count > 1); + } + + // TODO we should really return here if the menu is not going to be shown. + if (check_new_session ()){ switch_menuitem = dbusmenu_menuitem_new (); dbusmenu_menuitem_property_set (switch_menuitem, @@ -148,7 +164,7 @@ user_menu_mgr_rebuild_items (UserMenuMgr *self, gboolean greeter_mode) self->users_dbus_interface); } - if (check_guest_session ()) + if ( !is_this_guest_session () && guest_enabled) { guest_mi = dbusmenu_menuitem_new (); dbusmenu_menuitem_property_set (guest_mi, @@ -173,18 +189,7 @@ user_menu_mgr_rebuild_items (UserMenuMgr *self, gboolean greeter_mode) _("Guest")); } - GList * users = NULL; - users = users_service_dbus_get_user_list (self->users_dbus_interface); - self->user_count = g_list_length(users); - - gboolean user_menu_is_visible = FALSE; - if (!greeter_mode){ - user_menu_is_visible = TRUE; - } - - session_dbus_set_user_menu_visibility (self->session_dbus_interface, - user_menu_is_visible); if (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { users = g_list_sort (users, (GCompareFunc)compare_users_by_username); @@ -415,15 +420,15 @@ user_mgr_get_root_item (UserMenuMgr* self) /* Checks to see if we should show the guest suession item */ static gboolean -check_guest_session (void) +is_this_guest_session (void) { if (geteuid() < 500) { /* System users shouldn't have guest account shown. Mostly this would be the case of the guest user itself. */ - return FALSE; + return TRUE; } - return TRUE; + return FALSE; } /* Called when someone clicks on the guest session item. */ diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 4b41f4b..0bab8c8 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -86,6 +86,7 @@ struct _UsersServiceDbusPrivate DBusGProxy *accounts_service_proxy; DBusGProxy *display_manager_proxy; + DBusGProxy *display_manager_props_proxy; DBusGProxy *ck_proxy; DBusGProxy *seat_proxy; DBusGProxy *session_proxy; @@ -95,6 +96,7 @@ struct _UsersServiceDbusPrivate DbusmenuMenuitem * guest_item; gchar * guest_session_id; + gboolean guest_session_enabled; }; #define USERS_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusPrivate)) @@ -148,6 +150,8 @@ users_service_dbus_init (UsersServiceDbus *self) priv->count = 0; priv->guest_item = NULL; priv->guest_session_id = NULL; + + priv->guest_session_enabled = FALSE; /* Get the system bus */ priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); @@ -194,6 +198,7 @@ users_service_dbus_finalize (GObject *object) G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object); } + static void create_display_manager_proxy (UsersServiceDbus *self) { @@ -202,7 +207,7 @@ create_display_manager_proxy (UsersServiceDbus *self) GError *error = NULL; const gchar *cookie = NULL; gchar *seat = NULL; - + cookie = g_getenv ("XDG_SESSION_COOKIE"); if (cookie == NULL || cookie[0] == 0) { @@ -232,11 +237,18 @@ create_display_manager_proxy (UsersServiceDbus *self) return; } g_object_unref (dm_proxy); - + g_debug ("CREATING DM PROXIES WITH %s", seat); priv->display_manager_proxy = dbus_g_proxy_new_for_name (priv->system_bus, "org.freedesktop.DisplayManager", seat, "org.freedesktop.DisplayManager.Seat"); + + priv->display_manager_props_proxy = dbus_g_proxy_new_for_name (priv->system_bus, + "org.freedesktop.DisplayManager", + seat, + "org.freedesktop.DBus.Properties"); + + g_free (seat); if (!priv->display_manager_proxy) @@ -244,6 +256,32 @@ create_display_manager_proxy (UsersServiceDbus *self) g_warning ("Failed to get DisplayManager seat proxy."); return; } + if (!priv->display_manager_props_proxy) + { + g_warning ("Failed to get DisplayManager Properties seat proxy."); + return; + } + + GValue has_guest_session = {0}; + g_value_init (&has_guest_session, G_TYPE_BOOLEAN); + if (!dbus_g_proxy_call (priv->display_manager_props_proxy, + "Get", + &error, + G_TYPE_STRING, + "org.freedesktop.DisplayManager.Seat", + G_TYPE_STRING, + "HasGuestAccount", + G_TYPE_INVALID, + G_TYPE_VALUE, + &has_guest_session, + G_TYPE_INVALID)) + { + g_warning ("Failed to get the HasGuestSession property from the DisplayManager Properties seat proxy. error: %s", error->message); + g_error_free (error); + return; + } + g_debug ("Does seat have a guest account = %i", g_value_get_boolean (&has_guest_session)); + priv->guest_session_enabled = g_value_get_boolean (&has_guest_session); } static void @@ -931,9 +969,11 @@ users_service_dbus_can_activate_session (UsersServiceDbus *self) G_TYPE_BOOLEAN, &can_activate, G_TYPE_INVALID)) { - g_warning ("Failed to determine if seat can activate sessions: %s", error->message); - g_error_free (error); - + if (error != NULL){ + g_warning ("Failed to determine if seat can activate sessions: %s", + error->message); + g_error_free (error); + } return FALSE; } @@ -954,3 +994,12 @@ users_service_dbus_set_guest_item (UsersServiceDbus * self, DbusmenuMenuitem * m return; } + +gboolean users_service_dbus_guest_session_enabled (UsersServiceDbus * self) +{ + g_return_val_if_fail(IS_USERS_SERVICE_DBUS(self), FALSE); + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + return priv->guest_session_enabled; +} + diff --git a/src/users-service-dbus.h b/src/users-service-dbus.h index 4dbf2a4..25942df 100644 --- a/src/users-service-dbus.h +++ b/src/users-service-dbus.h @@ -85,6 +85,8 @@ gboolean users_service_dbus_activate_guest_session (UsersServiceDbus *self); void users_service_dbus_set_guest_item (UsersServiceDbus * self, DbusmenuMenuitem * mi); +gboolean users_service_dbus_guest_session_enabled (UsersServiceDbus * self); + G_END_DECLS #endif |