[gnome-control-center] user-accounts: Move non-shared function
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] user-accounts: Move non-shared function
- Date: Tue, 13 Nov 2018 21:16:27 +0000 (UTC)
commit 60ffc24c302274183e59986b62450ad3e5fd4b3f
Author: Robert Ancell <robert ancell canonical com>
Date: Fri Nov 9 09:36:07 2018 +1300
user-accounts: Move non-shared function
The render_user_icon function is only used in CcUserImage
panels/user-accounts/cc-user-image.c | 90 +++++++++++++++++++++++++++++++++++-
panels/user-accounts/um-utils.c | 89 -----------------------------------
panels/user-accounts/um-utils.h | 4 --
3 files changed, 88 insertions(+), 95 deletions(-)
---
diff --git a/panels/user-accounts/cc-user-image.c b/panels/user-accounts/cc-user-image.c
index 94a2880a9..79fefc7cb 100644
--- a/panels/user-accounts/cc-user-image.c
+++ b/panels/user-accounts/cc-user-image.c
@@ -20,8 +20,7 @@
#include <gtk/gtk.h>
#include <act/act.h>
-
-#include "um-utils.h"
+#include <sys/stat.h>
struct _CcUserImage {
GtkImage parent_instance;
@@ -31,6 +30,93 @@ struct _CcUserImage {
G_DEFINE_TYPE (CcUserImage, cc_user_image, GTK_TYPE_IMAGE)
+#define MAX_FILE_SIZE 65536
+
+static gboolean
+check_user_file (const char *filename,
+ gssize max_file_size)
+{
+ struct stat fileinfo;
+
+ if (max_file_size < 0) {
+ max_file_size = G_MAXSIZE;
+ }
+
+ /* Exists/Readable? */
+ if (stat (filename, &fileinfo) < 0) {
+ g_debug ("File does not exist");
+ return FALSE;
+ }
+
+ /* Is a regular file */
+ if (G_UNLIKELY (!S_ISREG (fileinfo.st_mode))) {
+ g_debug ("File is not a regular file");
+ return FALSE;
+ }
+
+ /* Size is sane? */
+ if (G_UNLIKELY (fileinfo.st_size > max_file_size)) {
+ g_debug ("File is too large");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static cairo_surface_t *
+render_user_icon (ActUser *user,
+ gint icon_size,
+ gint scale)
+{
+ GdkPixbuf *pixbuf;
+ 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) {
+ surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
+ g_object_unref (pixbuf);
+ }
+
+ return surface;
+}
+
static void
render_image (CcUserImage *image)
{
diff --git a/panels/user-accounts/um-utils.c b/panels/user-accounts/um-utils.c
index 831d1e2df..db963e2e2 100644
--- a/panels/user-accounts/um-utils.c
+++ b/panels/user-accounts/um-utils.c
@@ -31,7 +31,6 @@
#include <gio/gio.h>
#include <gio/gunixoutputstream.h>
#include <glib/gi18n.h>
-#include <sys/stat.h>
#include <glib/gstdio.h>
#include "um-utils.h"
@@ -666,94 +665,6 @@ generate_username_choices (const gchar *name,
g_string_free (item4, TRUE);
}
-static gboolean
-check_user_file (const char *filename,
- gssize max_file_size)
-{
- struct stat fileinfo;
-
- if (max_file_size < 0) {
- max_file_size = G_MAXSIZE;
- }
-
- /* Exists/Readable? */
- if (stat (filename, &fileinfo) < 0) {
- g_debug ("File does not exist");
- return FALSE;
- }
-
- /* Is a regular file */
- if (G_UNLIKELY (!S_ISREG (fileinfo.st_mode))) {
- g_debug ("File is not a regular file");
- return FALSE;
- }
-
- /* Size is sane? */
- if (G_UNLIKELY (fileinfo.st_size > max_file_size)) {
- g_debug ("File is too large");
- return FALSE;
- }
-
- return TRUE;
-}
-
-#define MAX_FILE_SIZE 65536
-
-cairo_surface_t *
-render_user_icon (ActUser *user,
- gint icon_size,
- gint scale)
-{
- GdkPixbuf *pixbuf;
- 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) {
- surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
- g_object_unref (pixbuf);
- }
-
- return surface;
-}
-
void
set_user_icon_data (ActUser *user,
GdkPixbuf *pixbuf)
diff --git a/panels/user-accounts/um-utils.h b/panels/user-accounts/um-utils.h
index e140d6d10..93b599bb5 100644
--- a/panels/user-accounts/um-utils.h
+++ b/panels/user-accounts/um-utils.h
@@ -45,10 +45,6 @@ gboolean is_valid_username (const gchar *name,
void generate_username_choices (const gchar *name,
GtkListStore *store);
-cairo_surface_t *render_user_icon (ActUser *user,
- gint icon_size,
- gint scale);
-
void set_user_icon_data (ActUser *user,
GdkPixbuf *pixbuf);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]