static gboolean handle_get_icon_data_url (CockpitAccount *object, GDBusMethodInvocation *invocation) { Account *acc = ACCOUNT (object); gs_free gchar *raw_data = NULL; gsize raw_size; gs_free gchar *base64_data = NULL; gs_free gchar *data = NULL; if (acc->u == NULL) goto out; const gchar *icon_file = act_user_get_icon_file (acc->u); if (icon_file == NULL) goto out; if (!g_file_get_contents (icon_file, &raw_data, &raw_size, NULL)) goto out; base64_data = g_base64_encode ((guchar *)raw_data, raw_size); data = g_strdup_printf ("data:image/png;base64,%s", base64_data); out: cockpit_account_complete_get_icon_data_url (object, invocation, data? data : ""); return TRUE; }
cairo_surface_t * render_user_icon (ActUser *user, UmIconStyle style, gint icon_size, gint scale) { GdkPixbuf *pixbuf; GdkPixbuf *framed; gboolean res; GError *error; const gchar *icon_file; cairo_surface_t *surface = NULL; g_return_val_if_fail (ACT_IS_USER (user), NULL); g_return_val_if_fail (icon_size > 12, NULL); icon_file = act_user_get_icon_file (user); pixbuf = NULL; if (icon_file) { res = check_user_file (icon_file, MAX_FILE_SIZE); if (res) { pixbuf = gdk_pixbuf_new_from_file_at_size (icon_file, icon_size * scale, icon_size * scale, NULL); } else { pixbuf = NULL; } } if (pixbuf != NULL) { goto out; } error = NULL; pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "avatar-default", icon_size * scale, GTK_ICON_LOOKUP_FORCE_SIZE, &error); if (error) { g_warning ("%s", error->message); g_error_free (error); } out: if (pixbuf != NULL && (style & UM_ICON_STYLE_FRAME)) { framed = frame_pixbuf (pixbuf, scale); if (framed != NULL) { g_object_unref (pixbuf); pixbuf = framed; } } if (pixbuf != NULL && (style & UM_ICON_STYLE_STATUS) && act_user_is_logged_in (user)) { framed = logged_in_pixbuf (pixbuf, scale); if (framed != NULL) { g_object_unref (pixbuf); pixbuf = framed; } } if (pixbuf != NULL) { surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL); g_object_unref (pixbuf); } return surface; }
void um_photo_dialog_set_user (UmPhotoDialog *um, ActUser *user) { ActUserManager *manager; GSList *list, *l; ActUser *u; GIcon *icon; GEmblem *emblem; GList *children, *c; g_return_if_fail (um != NULL); if (um->user) { g_object_unref (um->user); um->user = NULL; } um->user = user; if (um->user) { g_object_ref (um->user); children = gtk_container_get_children (GTK_CONTAINER (um->photo_popup)); g_list_foreach (children, (GFunc) clear_tip, NULL); manager = act_user_manager_get_default (); list = act_user_manager_list_users (manager); icon = g_themed_icon_new ("avatar-default"); emblem = g_emblem_new (icon); g_object_unref (icon); for (l = list; l; l = l->next) { const char *filename; u = l->data; if (u == user) continue; filename = act_user_get_icon_file (u); if (filename == NULL) continue; for (c = children; c; c = c->next) { const char *f; f = g_object_get_data (G_OBJECT (c->data), "filename"); if (f == NULL) continue; if (strcmp (f, filename) == 0) { char *tip; tip = g_strdup_printf (_("Used by %s"), act_user_get_real_name (u)); set_tip (GTK_WIDGET (c->data), tip, emblem); g_free (tip); break; } } } g_slist_free (list); g_object_unref (emblem); } }