[gnome-control-center] user-accounts: Logged in status identification



commit bd26688df9893d935c6004f32b0d5e60fdc09ad6
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Aug 29 15:18:24 2012 +0200

    user-accounts: Logged in status identification
    
    https://bugzilla.gnome.org/show_bug.cgi?id=681769

 panels/user-accounts/um-password-dialog.c |    2 +-
 panels/user-accounts/um-user-panel.c      |    6 +-
 panels/user-accounts/um-user.c            |   63 +++++++++++++++++++++++++++--
 panels/user-accounts/um-user.h            |   12 ++++-
 4 files changed, 72 insertions(+), 11 deletions(-)
---
diff --git a/panels/user-accounts/um-password-dialog.c b/panels/user-accounts/um-password-dialog.c
index 65ac67a..020c254 100644
--- a/panels/user-accounts/um-password-dialog.c
+++ b/panels/user-accounts/um-password-dialog.c
@@ -646,7 +646,7 @@ um_password_dialog_set_user (UmPasswordDialog *um,
         if (user) {
                 um->user = g_object_ref (user);
 
-                pixbuf = um_user_render_icon (user, FALSE, 48);
+                pixbuf = um_user_render_icon (user, UM_ICON_STYLE_NONE, 48);
                 gtk_image_set_from_pixbuf (GTK_IMAGE (um->user_icon), pixbuf);
                 g_object_unref (pixbuf);
 
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index ee56f73..3008f56 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -137,7 +137,7 @@ user_added (UmUserManager *um, UmUser *user, UmUserPanelPrivate *d)
         store = GTK_LIST_STORE (model);
         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
 
-        pixbuf = um_user_render_icon (user, TRUE, 48);
+        pixbuf = um_user_render_icon (user, UM_ICON_STYLE_FRAME | UM_ICON_STYLE_STATUS, 48);
         text = get_name_col_str (user);
 
         if (um_user_get_uid (user) == getuid ()) {
@@ -260,7 +260,7 @@ user_changed (UmUserManager *um, UmUser *user, UmUserPanelPrivate *d)
         do {
                 gtk_tree_model_get (model, &iter, USER_COL, &current, -1);
                 if (current == user) {
-                        pixbuf = um_user_render_icon (user, TRUE, 48);
+                        pixbuf = um_user_render_icon (user, UM_ICON_STYLE_FRAME | UM_ICON_STYLE_STATUS, 48);
                         text = get_name_col_str (user);
 
                         gtk_list_store_set (GTK_LIST_STORE (model), &iter,
@@ -567,7 +567,7 @@ show_user (UmUser *user, UmUserPanelPrivate *d)
         GtkTreeIter iter;
         gboolean show, enable;
 
-        pixbuf = um_user_render_icon (user, FALSE, 48);
+        pixbuf = um_user_render_icon (user, UM_ICON_STYLE_NONE, 48);
         image = get_widget (d, "user-icon-image");
         gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
         image = get_widget (d, "user-icon-image2");
diff --git a/panels/user-accounts/um-user.c b/panels/user-accounts/um-user.c
index 933a5ab..e80ebc6 100644
--- a/panels/user-accounts/um-user.c
+++ b/panels/user-accounts/um-user.c
@@ -425,10 +425,57 @@ frame_pixbuf (GdkPixbuf *source)
         return dest;
 }
 
+static GdkPixbuf *
+logged_in_pixbuf (GdkPixbuf *pixbuf)
+{
+        cairo_format_t format;
+        cairo_surface_t *surface;
+        cairo_pattern_t *pattern;
+        cairo_t *cr;
+        gint width, height;
+        GdkRGBA color;
+
+        width = gdk_pixbuf_get_width (pixbuf);
+        height = gdk_pixbuf_get_height (pixbuf);
+
+        g_return_val_if_fail (width > 15 && height > 15, pixbuf);
+
+        format = gdk_pixbuf_get_has_alpha (pixbuf) ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24;
+        surface = cairo_image_surface_create (format, width, height);
+        cr = cairo_create (surface);
+
+        gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+        cairo_paint (cr);
+
+        /* Draw pattern */
+        cairo_rectangle (cr, 0, 0, width, height);
+        pattern = cairo_pattern_create_radial (width - 9.5, height - 10, 0, width - 8.5, height - 7.5, 7.7);
+        cairo_pattern_add_color_stop_rgb (pattern, 0, 0.4, 0.9, 0);
+        cairo_pattern_add_color_stop_rgb (pattern, 0.7, 0.3, 0.6, 0);
+        cairo_pattern_add_color_stop_rgb (pattern, 0.8, 0.4, 0.4, 0.4);
+        cairo_pattern_add_color_stop_rgba (pattern, 1.0, 0, 0, 0, 0);
+        cairo_set_source (cr, pattern);
+        cairo_fill (cr);
+
+        /* Draw border */
+        cairo_set_line_width (cr, 0.9);
+        cairo_arc (cr, width - 8.5, height - 8.5, 6, 0, 2 * G_PI);
+        gdk_rgba_parse (&color, "#ffffff");
+        gdk_cairo_set_source_rgba (cr, &color);
+        cairo_stroke (cr);
+
+        pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);
+
+        cairo_surface_finish (surface);
+        cairo_destroy (cr);
+
+        return pixbuf;
+}
+
 GdkPixbuf *
-um_user_render_icon (UmUser   *user,
-                     gboolean  with_frame,
-                     gint      icon_size)
+um_user_render_icon (UmUser     *user,
+                     UmIconStyle style,
+                     gint        icon_size)
 {
         GdkPixbuf    *pixbuf;
         GdkPixbuf    *framed;
@@ -471,7 +518,7 @@ um_user_render_icon (UmUser   *user,
 
  out:
 
-        if (pixbuf != NULL && with_frame) {
+        if (pixbuf != NULL && (style & UM_ICON_STYLE_FRAME)) {
                 framed = frame_pixbuf (pixbuf);
                 if (framed != NULL) {
                         g_object_unref (pixbuf);
@@ -479,6 +526,14 @@ um_user_render_icon (UmUser   *user,
                 }
         }
 
+        if (pixbuf != NULL && (style & UM_ICON_STYLE_STATUS) && um_user_is_logged_in (user)) {
+                framed = logged_in_pixbuf (pixbuf);
+                if (framed != NULL) {
+                        g_object_unref (pixbuf);
+                        pixbuf = framed;
+                }
+        }
+
         return pixbuf;
 }
 
diff --git a/panels/user-accounts/um-user.h b/panels/user-accounts/um-user.h
index 6ee7bdb..d1b583a 100644
--- a/panels/user-accounts/um-user.h
+++ b/panels/user-accounts/um-user.h
@@ -45,6 +45,12 @@ typedef enum {
         UM_PASSWORD_MODE_ENABLED
 } UmPasswordMode;
 
+typedef enum {
+        UM_ICON_STYLE_NONE   = 0,
+        UM_ICON_STYLE_FRAME  = 1 << 0,
+        UM_ICON_STYLE_STATUS = 1 << 1
+} UmIconStyle;
+
 typedef struct _UmUser UmUser;
 
 GType          um_user_get_type            (void) G_GNUC_CONST;
@@ -95,9 +101,9 @@ void           um_user_set_password        (UmUser      *user,
                                             const gchar *password_hint);
 gboolean       um_user_is_logged_in        (UmUser   *user);
 
-GdkPixbuf     *um_user_render_icon         (UmUser   *user,
-                                            gboolean  framed,
-                                            gint      icon_size);
+GdkPixbuf     *um_user_render_icon         (UmUser     *user,
+                                            UmIconStyle style,
+                                            gint        icon_size);
 gint           um_user_collate             (UmUser   *user1,
                                             UmUser   *user2);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]