aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dbus-shared-names.h2
-rw-r--r--src/indicator-session.c25
-rw-r--r--src/lock-helper.c100
-rw-r--r--src/lock-helper.h2
-rw-r--r--src/session-service.c17
5 files changed, 129 insertions, 17 deletions
diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h
index a6364b1..3ac14b3 100644
--- a/src/dbus-shared-names.h
+++ b/src/dbus-shared-names.h
@@ -44,6 +44,8 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#define USER_ITEM_TYPE "x-canonical-user-item"
#define USER_ITEM_PROP_NAME "user-item-name"
#define USER_ITEM_PROP_LOGGED_IN "user-item-logged-in"
+#define USER_ITEM_PROP_ICON "user-item-icon-path"
+#define USER_ITEM_ICON_DEFAULT "default-icon"
#define RESTART_ITEM_TYPE "x-canonical-restart-item"
#define RESTART_ITEM_LABEL "restart-label"
diff --git a/src/indicator-session.c b/src/indicator-session.c
index 9cf58a5..b54a5d9 100644
--- a/src/indicator-session.c
+++ b/src/indicator-session.c
@@ -28,6 +28,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <glib-object.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
+#include <gio/gio.h>
#include <libdbusmenu-gtk/menu.h>
#include <dbus/dbus-glib.h>
@@ -234,7 +235,27 @@ static gboolean
new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
{
GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new());
- GtkWidget * hbox = gtk_hbox_new(FALSE, 0);
+ gint padding = 0;
+ gtk_widget_style_get(GTK_WIDGET(gmi), "horizontal-padding", &padding, NULL);
+ GtkWidget * hbox = gtk_hbox_new(FALSE, padding);
+
+ GtkWidget * usericon = NULL;
+ const gchar * icon_name = dbusmenu_menuitem_property_get(newitem, USER_ITEM_PROP_ICON);
+ g_debug("Using user icon for '%s' from file: %s", dbusmenu_menuitem_property_get(newitem, USER_ITEM_PROP_NAME), icon_name);
+ if (icon_name != NULL && icon_name[0] != '\0') {
+ if (g_strcmp0(icon_name, USER_ITEM_ICON_DEFAULT) == 0 || !g_file_test(icon_name, G_FILE_TEST_EXISTS)) {
+ GIcon * gicon = g_themed_icon_new_with_default_fallbacks("stock_person-panel");
+ usericon = gtk_image_new_from_gicon(gicon, GTK_ICON_SIZE_MENU);
+ g_object_unref(gicon);
+ } else {
+ usericon = gtk_image_new_from_file(icon_name);
+ }
+ }
+ if (usericon != NULL) {
+ gtk_misc_set_alignment(GTK_MISC(usericon), 0.0, 0.5);
+ gtk_box_pack_start(GTK_BOX(hbox), usericon, FALSE, FALSE, 0);
+ gtk_widget_show(usericon);
+ }
GtkWidget * label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, USER_ITEM_PROP_NAME));
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
@@ -313,7 +334,7 @@ switch_property_change (DbusmenuMenuitem * item, const gchar * property, const G
/* TODO: We need some way to remove the elipsis from appearing
twice in the label. Not sure how to do that yet. */
- finalstring = g_strdup_printf(_("Switch from %s..."), username);
+ finalstring = g_strdup_printf(_("Switch From %s..."), username);
if (ems >= 20.0f) {
set_ellipsize = TRUE;
} else {
diff --git a/src/lock-helper.c b/src/lock-helper.c
index 47dcb71..ba6b182 100644
--- a/src/lock-helper.c
+++ b/src/lock-helper.c
@@ -19,9 +19,14 @@ You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <glib/gi18n.h>
+#include <gconf/gconf-client.h>
#include <dbus/dbus-glib.h>
#include "lock-helper.h"
+#define GCONF_DIR "/apps/gnome-screensaver"
+#define GCONF_KEY GCONF_DIR "/lock_enabled"
+
static DBusGProxy * gss_proxy = NULL;
static GMainLoop * gss_mainloop = NULL;
static guint cookie = 0;
@@ -29,6 +34,8 @@ static DBusGProxyCall * cookie_call = NULL;
static gboolean is_guest = FALSE;
+static GConfClient * gconf_client = NULL;
+
void build_gss_proxy (void);
/* Checks to see if there is an error and reports
@@ -124,7 +131,11 @@ will_lock_screen (void)
return FALSE;
}
- return TRUE;
+ if (gconf_client == NULL) {
+ gconf_client = gconf_client_get_default();
+ }
+
+ return gconf_client_get_bool (gconf_client, GCONF_KEY, NULL);
}
/* When the screensave go active, if we've got a mainloop
@@ -175,24 +186,45 @@ activate_timeout (gpointer data)
return FALSE;
}
+/* Handle errors from activating the screensaver */
+static void
+active_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer user_data)
+{
+ GError * error = NULL;
+
+ dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_INVALID);
+
+ if (error != NULL) {
+ g_warning("Unable to activate screensaver: %s", error->message);
+ g_error_free(error);
+ }
+
+ return;
+}
+
/* A fun little function to actually lock the screen. If,
that's what you want, let's do it! */
void
lock_screen (DbusmenuMenuitem * mi, guint timestamp, gpointer data)
{
g_debug("Lock Screen");
- if (!will_lock_screen()) {
- g_debug("\tUser is guest, blocking lock");
- return;
- }
build_gss_proxy();
g_return_if_fail(gss_proxy != NULL);
- dbus_g_proxy_call_no_reply(gss_proxy,
- "Lock",
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ if (will_lock_screen()) {
+ dbus_g_proxy_call_no_reply(gss_proxy,
+ "Lock",
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ } else {
+ dbus_g_proxy_begin_call(gss_proxy,
+ "SetActive",
+ active_cb, NULL,
+ NULL,
+ G_TYPE_BOOLEAN, TRUE,
+ G_TYPE_INVALID);
+ }
if (gss_mainloop == NULL) {
gss_mainloop = g_main_loop_new(NULL, FALSE);
@@ -221,3 +253,53 @@ lock_screen_setup (gpointer data)
return FALSE;
}
+/* When the GConf key changes we need to adjust the text on
+ what we're going to do with the menu item */
+static void
+lockscreen_update (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data) {
+ DbusmenuMenuitem * mi = (DbusmenuMenuitem*) data;
+ const gchar * key = gconf_entry_get_key (entry);
+
+ if(g_strcmp0 (key, GCONF_KEY) == 0) {
+ if (will_lock_screen()) {
+ dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen"));
+ } else {
+ dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Start Screensaver"));
+ }
+ }
+}
+
+/* Notification handler for lock menuitems. */
+static guint lock_notify = 0;
+
+/* Sets the menu item to be updating. There can
+ only be one. So we clear and reset if we get
+ another. */
+void
+lock_screen_update_item (DbusmenuMenuitem * mi)
+{
+ if (gconf_client == NULL) {
+ gconf_client = gconf_client_get_default();
+ }
+
+ if (lock_notify == 0) {
+ gconf_client_add_dir (gconf_client,
+ GCONF_DIR,
+ GCONF_CLIENT_PRELOAD_ONELEVEL,
+ NULL);
+ }
+
+ if (lock_notify != 0) {
+ gconf_client_notify_remove(gconf_client, lock_notify);
+ lock_notify = 0;
+ }
+
+ lock_notify = gconf_client_notify_add(gconf_client,
+ GCONF_KEY,
+ lockscreen_update,
+ mi,
+ NULL,
+ NULL);
+
+ return;
+}
diff --git a/src/lock-helper.h b/src/lock-helper.h
index 37f1448..1d707d8 100644
--- a/src/lock-helper.h
+++ b/src/lock-helper.h
@@ -31,4 +31,6 @@ gboolean will_lock_screen (void);
void lock_screen (DbusmenuMenuitem * mi, guint timestamp, gpointer data);
gboolean lock_screen_setup (gpointer data);
+void lock_screen_update_item (DbusmenuMenuitem * mi);
+
#endif /* LOCK_HELPER_H__ */
diff --git a/src/session-service.c b/src/session-service.c
index 379a0a2..514a86f 100644
--- a/src/session-service.c
+++ b/src/session-service.c
@@ -516,14 +516,14 @@ rebuild_items (DbusmenuMenuitem *root,
/* Lock screen item */
if (can_lockscreen) {
lock_menuitem = dbusmenu_menuitem_new();
- dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen"));
- g_signal_connect(G_OBJECT(lock_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(lock_screen), NULL);
- dbusmenu_menuitem_child_append(root, lock_menuitem);
- if (!will_lock_screen()) {
- dbusmenu_menuitem_property_set_bool(lock_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE);
+ if (will_lock_screen()) {
+ dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen"));
} else {
- dbusmenu_menuitem_property_set_bool(lock_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
+ dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Start Screensaver"));
}
+ g_signal_connect(G_OBJECT(lock_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(lock_screen), NULL);
+ dbusmenu_menuitem_child_append(root, lock_menuitem);
+ lock_screen_update_item(lock_menuitem);
}
/* Set to NULL just incase we don't end up building one */
@@ -601,6 +601,11 @@ rebuild_items (DbusmenuMenuitem *root,
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;