2010-10-30 16:14:30 -04:00
|
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2009-2010 Red Hat, Inc,
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2012-09-06 07:43:05 -04:00
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2010-10-30 16:14:30 -04:00
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 12:57:27 +01:00
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2010-10-30 16:14:30 -04:00
|
|
|
|
*
|
|
|
|
|
* Written by: Matthias Clasen <mclasen@redhat.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2011-01-24 23:42:27 -05:00
|
|
|
|
#include <math.h>
|
2011-05-18 21:20:39 -04:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <sys/types.h>
|
2019-08-29 11:51:48 +08:00
|
|
|
|
#include <sys/wait.h>
|
2014-02-12 12:07:34 -05:00
|
|
|
|
#include <limits.h>
|
|
|
|
|
#include <unistd.h>
|
2018-01-31 14:31:02 -06:00
|
|
|
|
#include <utmpx.h>
|
2011-05-18 21:20:39 -04:00
|
|
|
|
#include <pwd.h>
|
2011-01-24 23:42:27 -05:00
|
|
|
|
|
2019-08-29 11:59:55 +08:00
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
|
#include <sysexits.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-12-04 12:48:57 -05:00
|
|
|
|
#include <gio/gio.h>
|
2010-10-30 16:14:30 -04:00
|
|
|
|
#include <glib/gi18n.h>
|
2019-02-04 15:46:16 +00:00
|
|
|
|
#include <glib/gstdio.h>
|
2010-10-30 16:14:30 -04:00
|
|
|
|
|
2018-11-08 11:00:37 +13:00
|
|
|
|
#include "user-utils.h"
|
2010-10-30 16:14:30 -04:00
|
|
|
|
|
2018-01-31 14:31:02 -06:00
|
|
|
|
/* Taken from defines.h in shadow-utils. On Linux, this value is much smaller
|
|
|
|
|
* than the sysconf limit LOGIN_NAME_MAX, and values larger than this will
|
|
|
|
|
* result in failure when running useradd. We could check UT_NAMESIZE instead,
|
|
|
|
|
* but that is nonstandard. Better to use POSIX utmpx.
|
|
|
|
|
*/
|
2018-11-10 09:59:14 +13:00
|
|
|
|
gsize
|
|
|
|
|
get_username_max_length (void)
|
|
|
|
|
{
|
|
|
|
|
return sizeof (((struct utmpx *)NULL)->ut_user);
|
|
|
|
|
}
|
2011-05-18 21:20:39 -04:00
|
|
|
|
|
2018-11-10 09:59:14 +13:00
|
|
|
|
gboolean
|
2011-05-18 21:20:39 -04:00
|
|
|
|
is_username_used (const gchar *username)
|
|
|
|
|
{
|
|
|
|
|
struct passwd *pwent;
|
|
|
|
|
|
|
|
|
|
if (username == NULL || username[0] == '\0') {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pwent = getpwnam (username);
|
|
|
|
|
|
|
|
|
|
return pwent != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
is_valid_name (const gchar *name)
|
|
|
|
|
{
|
2013-05-08 16:55:16 +01:00
|
|
|
|
gboolean is_empty = TRUE;
|
2023-02-19 01:33:54 -04:00
|
|
|
|
gboolean found_comma = FALSE;
|
2013-05-08 16:55:16 +01:00
|
|
|
|
const gchar *c;
|
|
|
|
|
|
2022-01-26 10:13:58 +01:00
|
|
|
|
if (name == NULL)
|
|
|
|
|
return is_empty;
|
|
|
|
|
|
2013-05-08 16:55:16 +01:00
|
|
|
|
/* Valid names must contain:
|
|
|
|
|
* 1) at least one character.
|
|
|
|
|
* 2) at least one non-"space" character.
|
2023-02-19 01:33:54 -04:00
|
|
|
|
* 3) comma character not allowed. Issue #888
|
2013-05-08 16:55:16 +01:00
|
|
|
|
*/
|
|
|
|
|
for (c = name; *c; c++) {
|
|
|
|
|
gunichar unichar;
|
2011-05-18 21:20:39 -04:00
|
|
|
|
|
2013-05-08 16:55:16 +01:00
|
|
|
|
unichar = g_utf8_get_char_validated (c, -1);
|
|
|
|
|
|
|
|
|
|
/* Partial UTF-8 sequence or end of string */
|
|
|
|
|
if (unichar == (gunichar) -1 || unichar == (gunichar) -2)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* Check for non-space character */
|
2023-02-19 01:33:54 -04:00
|
|
|
|
if (is_empty && !g_unichar_isspace (unichar)) {
|
2013-05-08 16:55:16 +01:00
|
|
|
|
is_empty = FALSE;
|
2023-02-19 01:33:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unichar == ',') {
|
|
|
|
|
found_comma = TRUE;
|
2013-05-08 16:55:16 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-18 21:20:39 -04:00
|
|
|
|
|
2023-02-19 01:33:54 -04:00
|
|
|
|
return !is_empty && !found_comma;
|
2011-05-18 21:20:39 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 16:32:20 +01:00
|
|
|
|
typedef struct {
|
|
|
|
|
gchar *username;
|
|
|
|
|
gchar *tip;
|
|
|
|
|
} isValidUsernameData;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
is_valid_username_data_free (isValidUsernameData *data)
|
2011-05-18 21:20:39 -04:00
|
|
|
|
{
|
2020-11-02 11:09:17 +13:00
|
|
|
|
g_clear_pointer (&data->username, g_free);
|
|
|
|
|
g_clear_pointer (&data->tip, g_free);
|
2019-01-25 16:32:20 +01:00
|
|
|
|
g_free (data);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 11:59:55 +08:00
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
|
/* Taken from pw(8) man page. */
|
|
|
|
|
#define E_SUCCESS EX_OK
|
|
|
|
|
#define E_BAD_ARG EX_DATAERR
|
|
|
|
|
#define E_NOTFOUND EX_NOUSER
|
|
|
|
|
#else
|
2019-01-25 16:32:20 +01:00
|
|
|
|
/* Taken from usermod.c in shadow-utils. */
|
|
|
|
|
#define E_SUCCESS 0
|
|
|
|
|
#define E_BAD_ARG 3
|
|
|
|
|
#define E_NOTFOUND 6
|
2019-08-29 11:59:55 +08:00
|
|
|
|
#endif
|
2019-01-25 16:32:20 +01:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
is_valid_username_child_watch_cb (GPid pid,
|
|
|
|
|
gint status,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2020-11-02 11:09:17 +13:00
|
|
|
|
g_autoptr(GTask) task = G_TASK (user_data);
|
2019-01-25 16:32:20 +01:00
|
|
|
|
isValidUsernameData *data = g_task_get_task_data (task);
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
gboolean valid = FALSE;
|
|
|
|
|
const gchar *tip = NULL;
|
|
|
|
|
|
|
|
|
|
if (WIFEXITED (status)) {
|
|
|
|
|
switch (WEXITSTATUS (status)) {
|
|
|
|
|
case E_NOTFOUND:
|
|
|
|
|
valid = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
case E_BAD_ARG:
|
|
|
|
|
tip = _("The username should usually only consist of lower case letters from a-z, digits and the following characters: - _");
|
|
|
|
|
valid = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
case E_SUCCESS:
|
|
|
|
|
tip = _("Sorry, that user name isn’t available. Please try another.");
|
|
|
|
|
valid = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (valid || tip != NULL) {
|
|
|
|
|
data->tip = g_strdup (tip);
|
|
|
|
|
g_task_return_boolean (task, valid);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-05-31 15:21:37 +12:00
|
|
|
|
g_spawn_check_wait_status (status, &error);
|
2019-01-25 16:32:20 +01:00
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_spawn_close_pid (pid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
is_valid_username_async (const gchar *username,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer callback_data)
|
|
|
|
|
{
|
2020-11-02 11:09:17 +13:00
|
|
|
|
g_autoptr(GTask) task = NULL;
|
2019-01-25 16:32:20 +01:00
|
|
|
|
isValidUsernameData *data;
|
|
|
|
|
gchar *argv[6];
|
|
|
|
|
GPid pid;
|
2019-08-29 11:58:02 +08:00
|
|
|
|
GError *error = NULL;
|
2019-01-25 16:32:20 +01:00
|
|
|
|
|
|
|
|
|
task = g_task_new (NULL, cancellable, callback, callback_data);
|
|
|
|
|
g_task_set_source_tag (task, is_valid_username_async);
|
|
|
|
|
|
|
|
|
|
data = g_new0 (isValidUsernameData, 1);
|
|
|
|
|
data->username = g_strdup (username);
|
|
|
|
|
g_task_set_task_data (task, data, (GDestroyNotify) is_valid_username_data_free);
|
2011-05-18 21:20:39 -04:00
|
|
|
|
|
|
|
|
|
if (username == NULL || username[0] == '\0') {
|
2019-01-25 16:32:20 +01:00
|
|
|
|
g_task_return_boolean (task, FALSE);
|
|
|
|
|
return;
|
2011-05-18 21:20:39 -04:00
|
|
|
|
}
|
2019-01-25 16:32:20 +01:00
|
|
|
|
else if (strlen (username) > get_username_max_length ()) {
|
|
|
|
|
data->tip = g_strdup (_("The username is too long."));
|
|
|
|
|
g_task_return_boolean (task, FALSE);
|
|
|
|
|
return;
|
2011-05-18 21:20:39 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 11:59:55 +08:00
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
|
/* Abuse "pw usershow -n <name>" in the same way as the code below. We
|
|
|
|
|
* don't use "pw usermod -n <name> -N -l <newname>" here because it has
|
|
|
|
|
* a special case for "root" to reject changes to the root user.
|
|
|
|
|
*/
|
|
|
|
|
argv[0] = "pw";
|
|
|
|
|
argv[1] = "usershow";
|
|
|
|
|
argv[2] = "-n";
|
|
|
|
|
argv[3] = data->username;
|
|
|
|
|
argv[4] = NULL;
|
|
|
|
|
#else
|
2019-01-25 16:32:20 +01:00
|
|
|
|
/* "usermod --login" is meant to be used to change a username, but the
|
|
|
|
|
* exit codes can be safely abused to check the validity of username.
|
|
|
|
|
* However, the current "usermod" implementation may change in the
|
|
|
|
|
* future, so it would be nice to have some official way for this
|
|
|
|
|
* instead of relying on the current "--login" implementation.
|
|
|
|
|
*/
|
2019-12-11 15:30:33 +08:00
|
|
|
|
argv[0] = "/usr/sbin/usermod";
|
2019-01-25 16:32:20 +01:00
|
|
|
|
argv[1] = "--login";
|
|
|
|
|
argv[2] = data->username;
|
|
|
|
|
argv[3] = "--";
|
|
|
|
|
argv[4] = data->username;
|
|
|
|
|
argv[5] = NULL;
|
2019-08-29 11:59:55 +08:00
|
|
|
|
#endif
|
2019-01-25 16:32:20 +01:00
|
|
|
|
|
|
|
|
|
if (!g_spawn_async (NULL, argv, NULL,
|
|
|
|
|
G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD |
|
|
|
|
|
G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
|
|
|
|
|
NULL, NULL, &pid, &error)) {
|
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
|
return;
|
2011-05-18 21:20:39 -04:00
|
|
|
|
}
|
2019-01-25 16:32:20 +01:00
|
|
|
|
|
|
|
|
|
g_child_watch_add (pid, (GChildWatchFunc) is_valid_username_child_watch_cb, task);
|
2020-11-02 11:09:17 +13:00
|
|
|
|
g_steal_pointer (&task);
|
2019-01-25 16:32:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
is_valid_username_finish (GAsyncResult *result,
|
|
|
|
|
gchar **tip,
|
|
|
|
|
gchar **username,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
GTask *task;
|
|
|
|
|
isValidUsernameData *data;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_task_is_valid (result, NULL), FALSE);
|
|
|
|
|
|
|
|
|
|
task = G_TASK (result);
|
|
|
|
|
data = g_task_get_task_data (task);
|
|
|
|
|
|
|
|
|
|
if (tip != NULL) {
|
|
|
|
|
*tip = g_steal_pointer (&data->tip);
|
2011-05-18 21:20:39 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 16:32:20 +01:00
|
|
|
|
if (username != NULL)
|
|
|
|
|
*username = g_steal_pointer (&data->username);
|
|
|
|
|
|
|
|
|
|
return g_task_propagate_boolean (task, error);
|
2011-05-18 21:20:39 -04:00
|
|
|
|
}
|
2019-02-04 15:27:19 +00:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
/* This function was taken from AdwAvatar and modified so that it's possible to
|
|
|
|
|
* export a GdkTexture at a different size than the AdwAvatar is rendered
|
|
|
|
|
* See: https://gitlab.gnome.org/GNOME/libadwaita/-/blob/afd0fab86ff9b4332d165b985a435ea6f822d41b/src/adw-avatar.c#L751
|
|
|
|
|
* License: LGPL-2.1-or-later */
|
|
|
|
|
GdkTexture *
|
|
|
|
|
draw_avatar_to_texture (AdwAvatar *avatar, int size)
|
2019-02-04 15:27:19 +00:00
|
|
|
|
{
|
2023-10-05 11:32:44 +02:00
|
|
|
|
GdkTexture *result;
|
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
GtkSnapshot *snapshot;
|
|
|
|
|
GdkPaintable *paintable;
|
|
|
|
|
GtkNative *native;
|
|
|
|
|
GskRenderer *renderer;
|
|
|
|
|
int real_size;
|
|
|
|
|
graphene_matrix_t transform;
|
|
|
|
|
gboolean transform_ok;
|
2019-02-04 15:27:19 +00:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
real_size = adw_avatar_get_size (avatar);
|
2019-02-04 15:27:19 +00:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
/* This works around the issue that when the custom-image or text of the AdwAvatar changes the
|
|
|
|
|
* allocation gets invalidated and therefore we can't snapshot the widget till the allocation
|
|
|
|
|
* is recalculated */
|
|
|
|
|
gtk_widget_measure (GTK_WIDGET (avatar), GTK_ORIENTATION_HORIZONTAL, real_size, NULL, NULL, NULL, NULL);
|
|
|
|
|
gtk_widget_allocate (GTK_WIDGET (avatar), real_size, real_size, -1, NULL);
|
2019-02-04 15:27:19 +00:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
transform_ok = gtk_widget_compute_transform (GTK_WIDGET (avatar),
|
|
|
|
|
gtk_widget_get_first_child (GTK_WIDGET (avatar)),
|
|
|
|
|
&transform);
|
2019-02-04 15:46:16 +00:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
g_assert (transform_ok);
|
2019-02-04 15:46:16 +00:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
snapshot = gtk_snapshot_new ();
|
|
|
|
|
gtk_snapshot_transform_matrix (snapshot, &transform);
|
|
|
|
|
GTK_WIDGET_GET_CLASS (avatar)->snapshot (GTK_WIDGET (avatar), snapshot);
|
2020-08-06 13:19:58 +02:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
/* Create first a GdkPaintable at the size the avatar was drawn
|
|
|
|
|
* then create a GdkSnapshot of it at the size requested */
|
|
|
|
|
paintable = gtk_snapshot_free_to_paintable (snapshot, &GRAPHENE_SIZE_INIT (real_size, real_size));
|
|
|
|
|
snapshot = gtk_snapshot_new ();
|
|
|
|
|
gdk_paintable_snapshot (paintable, snapshot, size, size);
|
|
|
|
|
g_object_unref (paintable);
|
2019-02-04 15:46:16 +00:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
node = gtk_snapshot_free_to_node (snapshot);
|
2019-02-04 15:46:16 +00:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
native = gtk_widget_get_native (GTK_WIDGET (avatar));
|
|
|
|
|
renderer = gtk_native_get_renderer (native);
|
2019-02-04 15:46:16 +00:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
result = gsk_renderer_render_texture (renderer, node, &GRAPHENE_RECT_INIT (-1, 0, size, size));
|
2019-02-04 15:46:16 +00:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
gsk_render_node_unref (node);
|
2019-02-04 15:46:16 +00:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
return result;
|
2019-02-04 15:46:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-10-09 18:41:58 +02:00
|
|
|
|
set_user_icon_data (ActUser *user,
|
|
|
|
|
GdkTexture *texture,
|
|
|
|
|
const gchar *image_source)
|
2019-02-04 15:46:16 +00:00
|
|
|
|
{
|
2020-11-02 11:09:17 +13:00
|
|
|
|
g_autofree gchar *path = NULL;
|
|
|
|
|
g_autoptr(GError) error = NULL;
|
2023-10-05 11:32:44 +02:00
|
|
|
|
int fd;
|
2019-02-04 15:46:16 +00:00
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
fd = g_file_open_tmp ("gnome-control-center-user-icon-XXXXXX", &path, &error);
|
2019-02-04 15:46:16 +00:00
|
|
|
|
|
|
|
|
|
if (fd == -1) {
|
2023-10-05 11:32:44 +02:00
|
|
|
|
g_warning ("Failed to create temporary user icon: %s", error->message);
|
2019-02-04 15:46:16 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 18:41:58 +02:00
|
|
|
|
g_autoptr(GdkPixbuf) pixbuf = gdk_pixbuf_get_from_texture (texture);
|
|
|
|
|
gdk_pixbuf_save (pixbuf, path, "png", &error, IMAGE_SOURCE_KEY, image_source, NULL);
|
|
|
|
|
|
|
|
|
|
if (error != NULL) {
|
|
|
|
|
g_warning ("Failed to create temporary user icon: %s", error->message);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-05 11:32:44 +02:00
|
|
|
|
close (fd);
|
2019-02-04 15:46:16 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-17 13:33:59 +02:00
|
|
|
|
const gchar *
|
|
|
|
|
get_real_or_user_name (ActUser *user)
|
|
|
|
|
{
|
|
|
|
|
const gchar *name;
|
|
|
|
|
|
|
|
|
|
name = act_user_get_real_name (user);
|
|
|
|
|
if (name == NULL)
|
|
|
|
|
name = act_user_get_user_name (user);
|
|
|
|
|
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
setup_avatar_for_user (AdwAvatar *avatar, ActUser *user)
|
|
|
|
|
{
|
|
|
|
|
const gchar *avatar_file;
|
|
|
|
|
|
|
|
|
|
adw_avatar_set_custom_image (avatar, NULL);
|
|
|
|
|
adw_avatar_set_text (avatar, get_real_or_user_name (user));
|
|
|
|
|
|
|
|
|
|
avatar_file = act_user_get_icon_file (user);
|
|
|
|
|
if (avatar_file) {
|
|
|
|
|
g_autoptr(GdkPixbuf) pixbuf = NULL;
|
2023-10-09 18:41:58 +02:00
|
|
|
|
const gchar *image_source;
|
|
|
|
|
gboolean is_generated = TRUE;
|
2023-10-17 13:33:59 +02:00
|
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file_at_size (avatar_file,
|
|
|
|
|
adw_avatar_get_size (avatar),
|
|
|
|
|
adw_avatar_get_size (avatar),
|
|
|
|
|
NULL);
|
2023-10-09 18:41:58 +02:00
|
|
|
|
|
2023-10-17 13:33:59 +02:00
|
|
|
|
if (pixbuf) {
|
2023-10-09 18:41:58 +02:00
|
|
|
|
image_source = gdk_pixbuf_get_option (pixbuf, IMAGE_SOURCE_KEY);
|
|
|
|
|
|
|
|
|
|
if (image_source == NULL)
|
|
|
|
|
g_debug ("User avatar's source isn't defined");
|
|
|
|
|
else
|
|
|
|
|
g_debug ("User avatar's source is %s", image_source);
|
|
|
|
|
|
|
|
|
|
is_generated = g_strcmp0 (image_source, "gnome-generated") == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_generated) {
|
2023-10-17 13:33:59 +02:00
|
|
|
|
g_autoptr(GdkTexture) texture = NULL;
|
|
|
|
|
|
|
|
|
|
texture = gdk_texture_new_for_pixbuf (pixbuf);
|
|
|
|
|
adw_avatar_set_custom_image (avatar, GDK_PAINTABLE (texture));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GSettings *
|
|
|
|
|
settings_or_null (const gchar *schema)
|
|
|
|
|
{
|
|
|
|
|
GSettingsSchemaSource *source = NULL;
|
|
|
|
|
g_auto(GStrv) non_relocatable = NULL;
|
|
|
|
|
GSettings *settings = NULL;
|
|
|
|
|
|
|
|
|
|
source = g_settings_schema_source_get_default ();
|
|
|
|
|
if (!source)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
g_settings_schema_source_list_schemas (source, TRUE, &non_relocatable, NULL);
|
|
|
|
|
|
|
|
|
|
if (g_strv_contains ((const gchar * const *)non_relocatable, schema))
|
|
|
|
|
settings = g_settings_new (schema);
|
|
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
|
}
|