summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/greeteruserimage.c137
-rw-r--r--src/greeteruserimage.h30
-rw-r--r--src/lightdm-gtk-greeter.c106
4 files changed, 171 insertions, 104 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 5325a36..861b5d1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,6 +24,8 @@ lightdm_gtk_greeter_SOURCES = \
lightdm-gtk-greeter.c \
greeterbackground.c \
greeterbackground.h \
+ greeteruserimage.c \
+ greeteruserimage.h \
greeterconfiguration.c \
greeterconfiguration.h \
greetermenubar.c \
diff --git a/src/greeteruserimage.c b/src/greeteruserimage.c
new file mode 100644
index 0000000..899b2bf
--- /dev/null
+++ b/src/greeteruserimage.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2010 - 2011, Robert Ancell <robert.ancell@canonical.com>
+ * Copyright (C) 2011, Gunnar Hjalmarsson <ubuntu@gunnar.cc>
+ * Copyright (C) 2012 - 2013, Lionel Le Folgoc <mrpouit@ubuntu.com>
+ * Copyright (C) 2012, Julien Lavergne <gilir@ubuntu.com>
+ * Copyright (C) 2013 - 2015, Simon Steinbeiß <ochosi@shimmerproject.org>
+ * Copyright (C) 2013 - 2020, Sean Davis <sean@bluesabre.org>
+ * Copyright (C) 2014, Andrew P. <pan.pav.7c5@gmail.com>
+ *
+ * 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 the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
+ * license.
+ */
+
+#include <lightdm.h>
+
+#include "greeterconfiguration.h"
+#include "greeteruserimage.h"
+
+static GdkPixbuf *
+get_default_user_image_from_settings (void)
+{
+ GdkPixbuf *image = NULL;
+ gchar *value = NULL;
+ GError *error = NULL;
+
+ value = config_get_string (NULL, CONFIG_KEY_DEFAULT_USER_IMAGE, NULL);
+ if (!value)
+ return NULL;
+
+ if (value[0] == '/')
+ {
+ image = gdk_pixbuf_new_from_file_at_scale (value,
+ 80, 80,
+ FALSE,
+ &error);
+
+ if (!image)
+ {
+ g_warning ("Failed to load default user image from path: %s", error->message);
+ g_clear_error (&error);
+ }
+ }
+ else if (value[0] == '#')
+ {
+ image = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ value + 1,
+ 80,
+ GTK_ICON_LOOKUP_FORCE_SIZE,
+ &error);
+
+ if (!image)
+ {
+ g_warning ("Failed to load default user image from icon theme: %s", error->message);
+ g_clear_error (&error);
+ }
+ }
+
+ g_free (value);
+
+ return image;
+}
+
+GdkPixbuf *
+get_default_user_image (void)
+{
+ GdkPixbuf *image = NULL;
+ GError *error = NULL;
+
+ /* If a file is set by preferences, it must be prioritized. */
+ image = get_default_user_image_from_settings ();
+
+ /* Fallback to avatar-default icon from theme */
+ if (!image)
+ {
+ image = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ "avatar-default",
+ 80,
+ GTK_ICON_LOOKUP_FORCE_SIZE,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Failed to load fallback user image: %s", error->message);
+ g_clear_error (&error);
+ }
+ }
+
+ /* Fallback again to old stock_person icon from theme */
+ if (!image)
+ {
+ image = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ "stock_person",
+ 80,
+ GTK_ICON_LOOKUP_FORCE_SIZE,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Failed to load old fallback user image: %s", error->message);
+ g_clear_error (&error);
+ }
+ }
+
+ return image;
+}
+
+GdkPixbuf *
+get_user_image (const gchar *username)
+{
+ LightDMUser *user = NULL;
+ GdkPixbuf *image = NULL;
+ GError *error = NULL;
+ const gchar *path;
+
+ user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username);
+ if (user)
+ {
+ path = lightdm_user_get_image (user);
+ if (path)
+ {
+ image = gdk_pixbuf_new_from_file_at_scale (path,
+ 80, 80,
+ FALSE,
+ &error);
+ if (!image)
+ {
+ g_debug ("Failed to load user image: %s", error->message);
+ g_clear_error (&error);
+ }
+ }
+ }
+ return image;
+}
+
diff --git a/src/greeteruserimage.h b/src/greeteruserimage.h
new file mode 100644
index 0000000..57c70aa
--- /dev/null
+++ b/src/greeteruserimage.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2010 - 2011, Robert Ancell <robert.ancell@canonical.com>
+ * Copyright (C) 2011, Gunnar Hjalmarsson <ubuntu@gunnar.cc>
+ * Copyright (C) 2012 - 2013, Lionel Le Folgoc <mrpouit@ubuntu.com>
+ * Copyright (C) 2012, Julien Lavergne <gilir@ubuntu.com>
+ * Copyright (C) 2013 - 2015, Simon Steinbeiß <ochosi@shimmerproject.org>
+ * Copyright (C) 2013 - 2020, Sean Davis <sean@bluesabre.org>
+ * Copyright (C) 2014, Andrew P. <pan.pav.7c5@gmail.com>
+ *
+ * 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 the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
+ * license.
+ */
+
+#ifndef GREETER_USER_IMAGE_H
+#define GREETER_USER_IMAGE_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+GdkPixbuf *get_default_user_image (void);
+
+GdkPixbuf *get_user_image (const gchar *username);
+
+G_END_DECLS
+
+#endif // GREETER_USER_IMAGE_H
diff --git a/src/lightdm-gtk-greeter.c b/src/lightdm-gtk-greeter.c
index 9f988a8..4628d8f 100644
--- a/src/lightdm-gtk-greeter.c
+++ b/src/lightdm-gtk-greeter.c
@@ -67,6 +67,7 @@
#include "src/greeterconfiguration.h"
#include "src/greetermenubar.h"
#include "src/greeterbackground.h"
+#include "src/greeteruserimage.h"
#include "src/lightdm-gtk-greeter-ui.h"
#include "src/lightdm-gtk-greeter-css-fallback.h"
#include "src/lightdm-gtk-greeter-css-application.h"
@@ -162,8 +163,6 @@ static gboolean message_label_is_empty (void);
static void set_message_label (LightDMMessageType type, const gchar *text);
/* User image */
-static GdkPixbuf *default_user_pixbuf = NULL;
-static gchar *default_user_icon = NULL;
static void set_user_image (const gchar *username);
/* External command (keyboard, reader) */
@@ -794,94 +793,17 @@ set_message_label (LightDMMessageType type, const gchar *text)
/* User image */
-static GdkPixbuf *
-get_default_user_image (void)
-{
- GtkIconTheme *icon_theme;
- GdkPixbuf *image = NULL;
- GError *error = NULL;
-
- if (default_user_pixbuf)
- {
- return default_user_pixbuf;
- }
-
- icon_theme = gtk_icon_theme_get_default ();
-
- /* Use icon from settings */
- image = gtk_icon_theme_load_icon (icon_theme,
- default_user_icon,
- 80,
- GTK_ICON_LOOKUP_FORCE_SIZE,
- &error);
-
- if (!image)
- {
- g_warning ("Failed to load default user image from icon theme: %s", error->message);
- g_clear_error (&error);
- }
-
- /* Fallback to avatar-default icon from theme */
- if (!image)
- {
- image = gtk_icon_theme_load_icon (icon_theme,
- "avatar-default",
- 80,
- GTK_ICON_LOOKUP_FORCE_SIZE,
- &error);
-
- if (error != NULL)
- {
- g_warning ("Failed to load fallback user image: %s", error->message);
- g_clear_error (&error);
- }
- }
-
- /* Fallback again to old stock_person icon from theme */
- if (!image)
- {
- image = gtk_icon_theme_load_icon (icon_theme,
- "stock_person",
- 80,
- GTK_ICON_LOOKUP_FORCE_SIZE,
- &error);
-
- if (error != NULL)
- {
- g_warning ("Failed to load old fallback user image: %s", error->message);
- g_clear_error (&error);
- }
- }
-
- return image;
-}
-
static void
set_user_image (const gchar *username)
{
- const gchar *path;
- LightDMUser *user = NULL;
GdkPixbuf *image = NULL;
- GError *error = NULL;
if (!gtk_widget_get_visible (GTK_WIDGET (user_image)))
return;
if (username)
- user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username);
-
- if (user)
{
- path = lightdm_user_get_image (user);
- if (path)
- {
- image = gdk_pixbuf_new_from_file_at_scale (path, 80, 80, FALSE, &error);
- if (!image)
- {
- g_debug ("Failed to load user image: %s", error->message);
- g_clear_error (&error);
- }
- }
+ image = get_user_image (username);
}
if (!image)
@@ -2958,8 +2880,6 @@ main (int argc, char **argv)
g_unix_signal_add (SIGTERM, (GSourceFunc)sigterm_cb, /* is_callback */ GINT_TO_POINTER (TRUE));
- default_user_icon = g_strdup("avatar-default");
-
config_init ();
if (config_get_bool (NULL, CONFIG_KEY_DEBUGGING, FALSE))
@@ -3195,28 +3115,6 @@ main (int argc, char **argv)
gtk_widget_hide (GTK_WIDGET (user_image)); /* Hide to mark image is disabled */
gtk_widget_set_size_request (GTK_WIDGET (user_combo), 250, -1);
}
- else
- {
- value = config_get_string (NULL, CONFIG_KEY_DEFAULT_USER_IMAGE, NULL);
- if (value)
- {
- if (value[0] == '#')
- {
- g_free (default_user_icon);
- default_user_icon = g_strdup (value + 1);
- }
- else
- {
- default_user_pixbuf = gdk_pixbuf_new_from_file_at_scale (value, 80, 80, FALSE, &error);
- if (!default_user_pixbuf)
- {
- g_warning ("Failed to load default user image: %s", error->message);
- g_clear_error (&error);
- }
- }
- g_free (value);
- }
- }
icon_theme = gtk_icon_theme_get_default ();