[gnome-control-center] user-accounts: hidpi support for user's icons
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] user-accounts: hidpi support for user's icons
- Date: Tue, 20 Jan 2015 16:09:56 +0000 (UTC)
commit 5c305302719a2e2cc58c09d499fe84efd942ad26
Author: Ondrej Holy <oholy redhat com>
Date: Wed Jan 14 09:14:19 2015 +0100
user-accounts: hidpi support for user's icons
This patch adds UmUserImage widget which respect scale factor.
https://bugzilla.gnome.org/show_bug.cgi?id=742395
panels/user-accounts/Makefile.am | 2 +
panels/user-accounts/data/user-accounts-dialog.ui | 4 +-
panels/user-accounts/um-user-image.c | 96 +++++++++++++++++++++
panels/user-accounts/um-user-image.h | 55 ++++++++++++
panels/user-accounts/um-user-panel.c | 9 +-
5 files changed, 159 insertions(+), 7 deletions(-)
---
diff --git a/panels/user-accounts/Makefile.am b/panels/user-accounts/Makefile.am
index 1de5719..1bf22e0 100644
--- a/panels/user-accounts/Makefile.am
+++ b/panels/user-accounts/Makefile.am
@@ -56,6 +56,8 @@ libuser_accounts_la_SOURCES = \
um-realm-manager.h \
um-history-dialog.h \
um-history-dialog.c \
+ um-user-image.h \
+ um-user-image.c \
$(BUILT_SOURCES)
libuser_accounts_la_LIBADD = \
diff --git a/panels/user-accounts/data/user-accounts-dialog.ui
b/panels/user-accounts/data/user-accounts-dialog.ui
index 54b4252..8f86810 100644
--- a/panels/user-accounts/data/user-accounts-dialog.ui
+++ b/panels/user-accounts/data/user-accounts-dialog.ui
@@ -323,7 +323,7 @@
</packing>
</child>
<child>
- <object class="GtkImage" id="user-icon-image">
+ <object class="UmUserImage" id="user-icon-image">
<property name="visible">True</property>
<property name="icon_name">avatar-default</property>
<property name="icon-size">6</property>
@@ -352,7 +352,7 @@
</object>
</child>
<child>
- <object class="GtkImage" id="user-icon-image2">
+ <object class="UmUserImage" id="user-icon-image2">
<property name="visible">True</property>
<property name="icon_name">avatar-default</property>
<property name="icon-size">6</property>
diff --git a/panels/user-accounts/um-user-image.c b/panels/user-accounts/um-user-image.c
new file mode 100644
index 0000000..9bb8f31
--- /dev/null
+++ b/panels/user-accounts/um-user-image.c
@@ -0,0 +1,96 @@
+/*
+ * 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 2 of the License, or
+ * (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 along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2015 Red Hat, Inc.
+ */
+
+#include "um-user-image.h"
+
+#include <gtk/gtk.h>
+#include <act/act.h>
+
+#include "um-utils.h"
+
+struct _UmUserImagePrivate {
+ ActUser *user;
+};
+
+#define UM_USER_IMAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), UM_TYPE_USER_IMAGE,
UmUserImagePrivate))
+
+G_DEFINE_TYPE_WITH_CODE (UmUserImage, um_user_image, GTK_TYPE_IMAGE, G_ADD_PRIVATE (UmUserImage));
+
+static void
+render_image (UmUserImage *image)
+{
+ cairo_surface_t *surface;
+ gint scale;
+
+ scale = gtk_widget_get_scale_factor (GTK_WIDGET (image));
+ surface = render_user_icon (image->priv->user, UM_ICON_STYLE_NONE, 48, scale);
+ gtk_image_set_from_surface (GTK_IMAGE (image), surface);
+ cairo_surface_destroy (surface);
+}
+
+void
+um_user_image_set_user (UmUserImage *image,
+ ActUser *user)
+{
+ g_clear_object (&image->priv->user);
+ image->priv->user = g_object_ref (user);
+
+ render_image (image);
+}
+
+static void
+on_scale_factor_changed (GObject *object,
+ GParamSpec *pspec,
+ gpointer data)
+{
+ UmUserImage *image = UM_USER_IMAGE (object);
+
+ render_image (image);
+}
+
+static void
+um_user_image_finalize (GObject *object)
+{
+ UmUserImage *image = UM_USER_IMAGE (object);
+
+ g_clear_object (&image->priv->user);
+
+ G_OBJECT_CLASS (um_user_image_parent_class)->finalize (object);
+}
+
+static void
+um_user_image_class_init (UmUserImageClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->finalize = um_user_image_finalize;
+}
+
+static void
+um_user_image_init (UmUserImage *image)
+{
+ image->priv = UM_USER_IMAGE_GET_PRIVATE (image);
+
+ g_signal_connect (image, "notify::scale-factor", G_CALLBACK (on_scale_factor_changed), NULL);
+}
+
+GtkWidget *
+um_user_image_new (void)
+{
+ return g_object_new (UM_TYPE_USER_IMAGE, NULL);
+}
diff --git a/panels/user-accounts/um-user-image.h b/panels/user-accounts/um-user-image.h
new file mode 100644
index 0000000..371b404
--- /dev/null
+++ b/panels/user-accounts/um-user-image.h
@@ -0,0 +1,55 @@
+/*
+ * 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 2 of the License, or
+ * (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 along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2015 Red Hat, Inc.
+ */
+
+#ifndef _UM_USER_IMAGE_H
+#define _UM_USER_IMAGE_H
+
+#include <gtk/gtk.h>
+#include <act/act.h>
+
+G_BEGIN_DECLS
+
+#define UM_TYPE_USER_IMAGE um_user_image_get_type()
+
+#define UM_USER_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UM_TYPE_USER_IMAGE, UmUserImage))
+#define UM_USER_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UM_TYPE_USER_IMAGE, UmUserImageClass))
+#define UM_IS_USER_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UM_TYPE_USER_IMAGE))
+#define UM_IS_USER_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UM_TYPE_USER_IMAGE))
+#define UM_USER_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UM_TYPE_USER_IMAGE,
UmUserImageClass))
+
+typedef struct _UmUserImage UmUserImage;
+typedef struct _UmUserImageClass UmUserImageClass;
+typedef struct _UmUserImagePrivate UmUserImagePrivate;
+
+struct _UmUserImage {
+ GtkImage parent;
+
+ UmUserImagePrivate *priv;
+};
+
+struct _UmUserImageClass {
+ GtkImageClass parent_class;
+};
+
+GType um_user_image_get_type (void) G_GNUC_CONST;
+GtkWidget *um_user_image_new (void);
+void um_user_image_set_user (UmUserImage *image, ActUser *user);
+
+G_END_DECLS
+
+#endif /* _UM_USER_IMAGE_H */
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index 0b47dc8..9639ac9 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -47,6 +47,7 @@
#include "um-editable-button.h"
#include "um-editable-combo.h"
+#include "um-user-image.h"
#include "um-account-dialog.h"
#include "cc-language-chooser.h"
@@ -878,18 +879,15 @@ show_user (ActUser *user, CcUserPanelPrivate *d)
{
GtkWidget *image;
GtkWidget *label;
- cairo_surface_t *surface;
gchar *lang, *text, *name;
GtkWidget *widget;
gboolean show, enable;
ActUser *current;
- surface = render_user_icon (user, UM_ICON_STYLE_NONE, 48, 1);
image = get_widget (d, "user-icon-image");
- gtk_image_set_from_surface (GTK_IMAGE (image), surface);
+ um_user_image_set_user (UM_USER_IMAGE (image), user);
image = get_widget (d, "user-icon-image2");
- gtk_image_set_from_surface (GTK_IMAGE (image), surface);
- cairo_surface_destroy (surface);
+ um_user_image_set_user (UM_USER_IMAGE (image), user);
um_photo_dialog_set_user (d->photo_dialog, user);
@@ -1707,6 +1705,7 @@ cc_user_panel_init (CcUserPanel *self)
type = um_editable_button_get_type ();
type = cc_editable_entry_get_type ();
type = um_editable_combo_get_type ();
+ type = um_user_image_get_type ();
gtk_widget_set_size_request (GTK_WIDGET (self), -1, 350);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]