aboutsummaryrefslogtreecommitdiff
path: root/src/user-menu-mgr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/user-menu-mgr.c')
-rw-r--r--src/user-menu-mgr.c99
1 files changed, 80 insertions, 19 deletions
diff --git a/src/user-menu-mgr.c b/src/user-menu-mgr.c
index 8477354..30ea0ff 100644
--- a/src/user-menu-mgr.c
+++ b/src/user-menu-mgr.c
@@ -20,13 +20,13 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <libdbusmenu-glib/client.h>
#include "user-menu-mgr.h"
-#include "gconf-helper.h"
+#include "settings-helper.h"
#include "dbus-shared-names.h"
#include "dbusmenu-shared.h"
#include "lock-helper.h"
#include "users-service-dbus.h"
-static GConfClient * gconf_client = NULL;
+static GSettings* settings = NULL;
static DbusmenuMenuitem *switch_menuitem = NULL;
struct _UserMenuMgr
@@ -49,13 +49,19 @@ static gint compare_users_by_username (const gchar *a,
static void activate_online_accounts (DbusmenuMenuitem *mi,
guint timestamp,
gpointer user_data);
-static void user_menu_mgr_rebuild_items (UserMenuMgr *self);
+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_gconf_client ();
+static void ensure_settings_client ();
+static gboolean check_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);
@@ -93,7 +99,7 @@ user_menu_mgr_class_init (UserMenuMgrClass *klass)
/* Builds up the menu for us */
static void
-user_menu_mgr_rebuild_items (UserMenuMgr *self)
+user_menu_mgr_rebuild_items (UserMenuMgr *self, gboolean greeter_mode)
{
DbusmenuMenuitem *mi = NULL;
DbusmenuMenuitem *guest_mi = NULL;
@@ -104,11 +110,11 @@ user_menu_mgr_rebuild_items (UserMenuMgr *self)
/* Make sure we have a valid GConf client, and build one
if needed */
- ensure_gconf_client ();
+ ensure_settings_client ();
/* Check to see which menu items we're allowed to have */
can_activate = users_service_dbus_can_activate_session (self->users_dbus_interface) &&
- !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL);
+ !g_settings_get_boolean (settings, LOCKDOWN_KEY_USER);
/* Remove the old menu items if that makes sense */
children = dbusmenu_menuitem_take_children (self->root_item);
@@ -121,6 +127,7 @@ user_menu_mgr_rebuild_items (UserMenuMgr *self)
/* Build all of the user switching items */
if (can_activate == TRUE)
{
+
if (check_new_session ()){
switch_menuitem = dbusmenu_menuitem_new ();
dbusmenu_menuitem_property_set (switch_menuitem,
@@ -134,14 +141,41 @@ user_menu_mgr_rebuild_items (UserMenuMgr *self)
DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
G_CALLBACK (activate_new_session),
self->users_dbus_interface);
+ }
+
+ if (check_guest_session ())
+ {
+ guest_mi = dbusmenu_menuitem_new ();
+ dbusmenu_menuitem_property_set (guest_mi,
+ DBUSMENU_MENUITEM_PROP_TYPE,
+ USER_ITEM_TYPE);
+ dbusmenu_menuitem_property_set (guest_mi,
+ USER_ITEM_PROP_NAME,
+ _("Guest Session"));
+ dbusmenu_menuitem_property_set_bool (guest_mi,
+ USER_ITEM_PROP_LOGGED_IN,
+ FALSE);
+ dbusmenu_menuitem_child_append (self->root_item, guest_mi);
+ g_signal_connect (G_OBJECT (guest_mi),
+ DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
+ G_CALLBACK (activate_guest_session),
+ self);
+ users_service_dbus_set_guest_item (self->users_dbus_interface,
+ guest_mi);
}
-
+
GList * users = NULL;
users = users_service_dbus_get_user_list (self->users_dbus_interface);
self->user_count = g_list_length(users);
- g_debug ("USER COUNT = %i", self->user_count);
- session_dbus_set_user_menu_visibility (self->session_dbus_interface, self->user_count > 1);
+ gboolean user_menu_is_visible = FALSE;
+
+ if (!greeter_mode){
+ user_menu_is_visible = self->user_count > 1;
+ }
+
+ 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);
@@ -254,9 +288,9 @@ check_new_session ()
locking the screen. If not, lock it. */
static void
lock_if_possible (void) {
- ensure_gconf_client ();
+ ensure_settings_client ();
- if (!gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL)) {
+ if (!g_settings_get_boolean (settings, LOCKDOWN_KEY_SCREENSAVER)) {
lock_screen(NULL, 0, NULL);
}
@@ -339,13 +373,12 @@ user_change (UsersServiceDbus *service,
/* Ensures that we have a GConf client and if we build one
set up the signal handler. */
static void
-ensure_gconf_client ()
+ensure_settings_client ()
{
- if (!gconf_client) {
- gconf_client = gconf_client_get_default ();
- gconf_client_add_dir (gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
- gconf_client_add_dir (gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+ if(!settings) {
+ settings = g_settings_new (LOCKDOWN_SCHEMA);
}
+ return;
}
DbusmenuMenuitem*
@@ -354,15 +387,43 @@ user_mgr_get_root_item (UserMenuMgr* self)
return self->root_item;
}
+/* Checks to see if we should show the guest suession item */
+static gboolean
+check_guest_session (void)
+{
+ if (geteuid() < 500) {
+ /* System users shouldn't have guest account shown. Mosly
+ this would be the case of the guest user itself. */
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* Called when someone clicks on the guest session item. */
+static void
+activate_guest_session (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data)
+{
+ g_return_if_fail (USER_IS_MENU_MGR (user_data));
+ UserMenuMgr* user_mgr = USER_MENU_MGR(user_data);
+ UsersServiceDbus *service = user_mgr->users_dbus_interface;
+
+ lock_if_possible();
+
+ if (users_service_dbus_activate_guest_session(service)) {
+ return;
+ }
+}
+
/*
* Clean Entry Point
*/
-UserMenuMgr* user_menu_mgr_new (SessionDbus* session_dbus)
+UserMenuMgr* user_menu_mgr_new (SessionDbus* session_dbus, gboolean greeter_mode)
{
UserMenuMgr* user_mgr = g_object_new (USER_TYPE_MENU_MGR, NULL);
user_mgr->session_dbus_interface = session_dbus;
- user_menu_mgr_rebuild_items (user_mgr);
+ user_menu_mgr_rebuild_items (user_mgr, greeter_mode);
return user_mgr;
}