static void stock_icon_selected (GtkMenuItem *menuitem, UmPhotoDialog *um) { const char *filename; filename = g_object_get_data (G_OBJECT (menuitem), "filename"); act_user_set_icon_file (um->user, filename); }
static gboolean handle_set_icon_data_url (CockpitAccount *object, GDBusMethodInvocation *invocation, const gchar *arg_data) { GError *error = NULL; Account *acc = ACCOUNT (object); if (!account_auth_check (object, invocation, acc)) return TRUE; if (acc->u) { const gchar *base64_data = strstr (arg_data, "base64,"); if (base64_data == NULL) goto out; base64_data += strlen ("base64,"); gsize raw_size; gs_free gchar *raw_data = (gchar *)g_base64_decode (base64_data, &raw_size); gs_unref_object GFileIOStream *tmp_stream = NULL; gs_unref_object GFile *tmp_file = g_file_new_tmp ("cockpit-user-icon-XXXXXX", &tmp_stream, &error); if (tmp_file == NULL) goto out; GOutputStream *out = g_io_stream_get_output_stream (G_IO_STREAM (tmp_stream)); if (!g_output_stream_write_all (out, raw_data, raw_size, NULL, NULL, &error)) goto out; if (!g_io_stream_close (G_IO_STREAM (tmp_stream), NULL, &error)) goto out; gs_free gchar *tmp_path = g_file_get_path (tmp_file); act_user_set_icon_file (acc->u, tmp_path); g_file_delete (tmp_file, NULL, NULL); } out: if (error) { g_dbus_method_invocation_return_error (invocation, COCKPIT_ERROR, COCKPIT_ERROR_FAILED, "%s", error->message); g_clear_error (&error); } else cockpit_account_complete_set_icon_data_url (object, invocation); return TRUE; }
void set_user_icon_data (ActUser *user, GdkPixbuf *pixbuf) { gchar *path; gint fd; GOutputStream *stream; GError *error; path = g_build_filename (g_get_tmp_dir (), "gnome-control-center-user-icon-XXXXXX", NULL); fd = g_mkstemp (path); if (fd == -1) { g_warning ("failed to create temporary file for image data"); g_free (path); return; } stream = g_unix_output_stream_new (fd, TRUE); error = NULL; if (!gdk_pixbuf_save_to_stream (pixbuf, stream, "png", NULL, &error, NULL)) { g_warning ("failed to save image: %s", error->message); g_error_free (error); g_object_unref (stream); return; } g_object_unref (stream); act_user_set_icon_file (user, path); /* if we ever make the dbus call async, the g_remove call needs * to wait for its completion */ g_remove (path); g_free (path); }
static void none_icon_selected (GtkMenuItem *menuitem, UmPhotoDialog *um) { act_user_set_icon_file (um->user, ""); }