diff options
author | Conor Curran <conor.curran@canonical.com> | 2011-07-06 17:55:08 +0100 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2011-07-06 17:55:08 +0100 |
commit | b2a247c043866468fd7b898c8e904611fc087388 (patch) | |
tree | ecb6d62ae6b0ffec1361df30f2b479c03b903430 /src | |
parent | 9ee6a254c71c3bd7196f7b7f1921d0ec66ef3b01 (diff) | |
download | ayatana-indicator-session-b2a247c043866468fd7b898c8e904611fc087388.tar.gz ayatana-indicator-session-b2a247c043866468fd7b898c8e904611fc087388.tar.bz2 ayatana-indicator-session-b2a247c043866468fd7b898c8e904611fc087388.zip |
tidy up
Diffstat (limited to 'src')
-rw-r--r-- | src/indicator-session.c | 30 | ||||
-rw-r--r-- | src/session-service.c | 221 |
2 files changed, 151 insertions, 100 deletions
diff --git a/src/indicator-session.c b/src/indicator-session.c index 185e184..5c582b4 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -276,6 +276,7 @@ new_user_item (DbusmenuMenuitem * newitem, DbusmenuClient * client, gpointer user_data) { + g_debug ("new user item called "); GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new()); gint padding = 0; gtk_widget_style_get(GTK_WIDGET(gmi), "horizontal-padding", &padding, NULL); @@ -356,7 +357,7 @@ user_property_change (DbusmenuMenuitem * item, } -/*static void +static void icon_name_get_cb (GObject * obj, GAsyncResult * res, gpointer user_data) { IndicatorSession * self = INDICATOR_SESSION(user_data); @@ -376,32 +377,45 @@ icon_name_get_cb (GObject * obj, GAsyncResult * res, gpointer user_data) return; } - indicator_image_helper_update(self->status_image, name); + indicator_image_helper_update(self->users.image, name); return; -}*/ +} static void service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointer user_data) { - //IndicatorSession * self = INDICATOR_SESSION(user_data); + IndicatorSession * self = INDICATOR_SESSION (user_data); if (connected) { - /*g_dbus_proxy_call(self->service_proxy, "GetIcon", NULL, + g_dbus_proxy_call(self->service_proxy, "GetIcon", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, - icon_name_get_cb, user_data);*/ + icon_name_get_cb, user_data); } else { - //indicator_image_helper_update(self->status_image, ICON_DEFAULT); + indicator_image_helper_update(self->users.image, ICON_DEFAULT); } return; } +static void +icon_changed (IndicatorSession * session, const gchar * icon_name) +{ + indicator_image_helper_update(session->users.image, icon_name); + return; +} + /* Receives all signals from the service, routed to the appropriate functions */ static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data) { - //IndicatorSession * self = INDICATOR_SESSION(user_data); + IndicatorSession * self = INDICATOR_SESSION(user_data); + + if (g_strcmp0(signal_name, "IconUpdated") == 0) { + const gchar *name; + g_variant_get (parameters, "(&s)", &name); + icon_changed(self, name); + } return; } diff --git a/src/session-service.c b/src/session-service.c index d1b9bb3..ed95080 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -549,12 +549,13 @@ static void rebuild_user_items (DbusmenuMenuitem *root, UsersServiceDbus *service) { - DbusmenuMenuitem *guest_mi = NULL; DbusmenuMenuitem *mi = NULL; - - GList *children; + DbusmenuMenuitem * guest_mi = NULL; + GList *u; + UserData *user; gboolean can_activate; - + gboolean can_lockscreen; + GList *children; /* Make sure we have a valid GConf client, and build one if needed */ @@ -563,103 +564,140 @@ rebuild_user_items (DbusmenuMenuitem *root, /* Check to see which menu items we're allowed to have */ can_activate = users_service_dbus_can_activate_session (service) && !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL); + can_lockscreen = !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL); /* Remove the old menu items if that makes sense */ children = dbusmenu_menuitem_take_children (root); - g_list_foreach (children, (GFunc)g_object_unref, NULL); g_list_free (children); - GList *u; - UserData *user; - - GList * users = NULL; - users = users_service_dbus_get_user_list (service); - guint user_count = g_list_length(users); - if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { - users = g_list_sort (users, (GCompareFunc)compare_users_by_username); - } + /* Lock screen item */ + if (can_lockscreen) { + lock_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (lock_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Lock Screen")); - for (u = users; u != NULL; u = g_list_next (u)) { - user = u->data; - user->service = service; - - if (user->uid == getuid()) { - /* Hide me from the list */ - continue; - } - - if (g_strcmp0(user->user_name, "guest") == 0) { - /* Check to see if the guest has sessions and so therefore should - get a check mark. */ - if (user->sessions != NULL) { - dbusmenu_menuitem_property_set_bool (guest_mi, USER_ITEM_PROP_LOGGED_IN, TRUE); - } - /* If we're showing user accounts, keep going through the list */ - if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { - continue; - } - /* If not, we can stop here */ - break; - } - - if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); - if (user->real_name_conflict) { - gchar * conflictedname = g_strdup_printf("%s (%s)", user->real_name, user->user_name); - dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, conflictedname); - g_free(conflictedname); - } else { - dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, user->real_name); - } - dbusmenu_menuitem_property_set_bool (mi, USER_ITEM_PROP_LOGGED_IN, user->sessions != NULL); - if (user->icon_url != NULL && user->icon_url[0] != '\0' && g_str_has_prefix(user->icon_url, "file://")) { - dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, user->icon_url + strlen("file://")); - } else { - dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, USER_ITEM_ICON_DEFAULT); - } - dbusmenu_menuitem_child_append (root, mi); - g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_user_session), user); - user->menuitem = mi; - } + gchar * shortcut = gconf_client_get_string(gconf_client, KEY_LOCK_SCREEN, NULL); + if (shortcut != NULL) { + g_debug("Lock screen shortcut: %s", shortcut); + dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, shortcut); + g_free(shortcut); + } else { + g_debug("Unable to get lock screen shortcut."); + } + + g_signal_connect (G_OBJECT(lock_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(lock_screen), + NULL); + dbusmenu_menuitem_child_append(root, lock_menuitem); } - g_list_free(users); - /* Set to NULL just incase we don't end up building one */ users_service_dbus_set_guest_item(service, NULL); /* Build all of the user switching items */ if (can_activate == TRUE) - { - 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 (root, guest_mi); - g_signal_connect (G_OBJECT (guest_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK (activate_guest_session), - service); - users_service_dbus_set_guest_item(service, guest_mi); - } - - if (check_new_session ()) { - switch_menuitem = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (switch_menuitem, + if (can_lockscreen) { + DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set_bool (separator1, + DBUSMENU_MENUITEM_PROP_VISIBLE, + TRUE); + dbusmenu_menuitem_property_set (separator1, DBUSMENU_MENUITEM_PROP_TYPE, - MENU_SWITCH_TYPE); - dbusmenu_menuitem_property_set (switch_menuitem, MENU_SWITCH_USER, g_get_user_name()); - dbusmenu_menuitem_child_append (root, switch_menuitem); - g_signal_connect (G_OBJECT (switch_menuitem), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK (activate_new_session), NULL); - } - } + DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append (root, separator1); + } + + if (check_guest_session ()) + { + guest_mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set_bool (guest_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + TRUE); + 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 (root, guest_mi); + g_signal_connect (G_OBJECT (guest_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_guest_session), service); + users_service_dbus_set_guest_item(service, guest_mi); + } + + if (check_new_session ()) + { + + switch_menuitem = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (switch_menuitem, DBUSMENU_MENUITEM_PROP_TYPE, MENU_SWITCH_TYPE); + dbusmenu_menuitem_property_set (switch_menuitem, MENU_SWITCH_USER, g_get_user_name()); + dbusmenu_menuitem_child_append (root, switch_menuitem); + g_signal_connect (G_OBJECT (switch_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL); + } + + GList * users = NULL; + users = users_service_dbus_get_user_list (service); + guint user_count = g_list_length(users); + + if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { + users = g_list_sort (users, (GCompareFunc)compare_users_by_username); + } + + for (u = users; u != NULL; u = g_list_next (u)) { + user = u->data; + user->service = service; + + if (user->uid == getuid()) { + /* Hide me from the list */ + continue; + } + + if (g_strcmp0(user->user_name, "guest") == 0) { + /* Check to see if the guest has sessions and so therefore should + get a check mark. */ + if (user->sessions != NULL) { + dbusmenu_menuitem_property_set_bool (guest_mi, USER_ITEM_PROP_LOGGED_IN, TRUE); + } + /* If we're showing user accounts, keep going through the list */ + if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { + continue; + } + /* If not, we can stop here */ + break; + } + + if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); + if (user->real_name_conflict) { + gchar * conflictedname = g_strdup_printf("%s (%s)", user->real_name, user->user_name); + dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, conflictedname); + g_free(conflictedname); + } else { + dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, user->real_name); + } + dbusmenu_menuitem_property_set_bool (mi, USER_ITEM_PROP_LOGGED_IN, user->sessions != NULL); + if (user->icon_url != NULL && user->icon_url[0] != '\0' && g_str_has_prefix(user->icon_url, "file://")) { + dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, user->icon_url + strlen("file://")); + } else { + dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, USER_ITEM_ICON_DEFAULT); + } + dbusmenu_menuitem_child_append (root, mi); + g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_user_session), user); + user->menuitem = mi; + } + } + + g_list_free(users); + } + + /* If there were a bunch of items before us, we need a + separator. */ + if (can_lockscreen || can_activate) { + DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append(root, separator); + } } static void @@ -890,14 +928,12 @@ main (int argc, char ** argv) rebuild_session_items (session_root_menuitem, dbus_interface); - setup_restart_watch(); - - setup_up(); DbusmenuServer * server = dbusmenu_server_new(INDICATOR_SESSION_DBUS_OBJECT); dbusmenu_server_set_root(server, session_root_menuitem); users_root_menuitem = dbusmenu_menuitem_new(); + rebuild_user_items (users_root_menuitem, dbus_interface); g_signal_connect (G_OBJECT (dbus_interface), "user-added", G_CALLBACK (user_change), @@ -906,15 +942,16 @@ main (int argc, char ** argv) "user-removed", G_CALLBACK (user_change), users_root_menuitem); - - rebuild_user_items (users_root_menuitem, dbus_interface); - DbusmenuServer * users_server = dbusmenu_server_new(INDICATOR_USERS_DBUS_OBJECT); + setup_restart_watch(); + setup_up(); + + DbusmenuServer * users_server = dbusmenu_server_new (INDICATOR_USERS_DBUS_OBJECT); dbusmenu_server_set_root (users_server, users_root_menuitem); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); - + return 0; } |