[gnome-control-center] user-accounts: hidpi support for user's icons in tree view
- 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 in tree view
- Date: Tue, 20 Jan 2015 16:10:01 +0000 (UTC)
commit dba7bf76c40cce4d8069e40c7062a50a4a69c69c
Author: Ondrej Holy <oholy redhat com>
Date: Wed Jan 14 14:28:33 2015 +0100
user-accounts: hidpi support for user's icons in tree view
This patch adds UmCellRendererUserImage object which respect scale factor.
https://bugzilla.gnome.org/show_bug.cgi?id=742395
panels/user-accounts/Makefile.am | 2 +
panels/user-accounts/um-cell-renderer-user-image.c | 137 ++++++++++++++++++++
panels/user-accounts/um-cell-renderer-user-image.h | 53 ++++++++
panels/user-accounts/um-user-panel.c | 16 +--
4 files changed, 196 insertions(+), 12 deletions(-)
---
diff --git a/panels/user-accounts/Makefile.am b/panels/user-accounts/Makefile.am
index 1bf22e0..d473bc5 100644
--- a/panels/user-accounts/Makefile.am
+++ b/panels/user-accounts/Makefile.am
@@ -58,6 +58,8 @@ libuser_accounts_la_SOURCES = \
um-history-dialog.c \
um-user-image.h \
um-user-image.c \
+ um-cell-renderer-user-image.h \
+ um-cell-renderer-user-image.c \
$(BUILT_SOURCES)
libuser_accounts_la_LIBADD = \
diff --git a/panels/user-accounts/um-cell-renderer-user-image.c
b/panels/user-accounts/um-cell-renderer-user-image.c
new file mode 100644
index 0000000..bcd6160
--- /dev/null
+++ b/panels/user-accounts/um-cell-renderer-user-image.c
@@ -0,0 +1,137 @@
+/*
+ * 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-cell-renderer-user-image.h"
+
+#include <gtk/gtk.h>
+#include <act/act.h>
+
+#include "um-utils.h"
+
+struct _UmCellRendererUserImagePrivate {
+ GtkWidget *parent;
+ ActUser *user;
+};
+
+#define UM_CELL_RENDERER_USER_IMAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),
UM_TYPE_CELL_RENDERER_USER_IMAGE, UmCellRendererUserImagePrivate))
+
+enum {
+ PROP_0,
+ PROP_PARENT,
+ PROP_USER
+};
+
+G_DEFINE_TYPE_WITH_CODE (UmCellRendererUserImage, um_cell_renderer_user_image,
GTK_TYPE_CELL_RENDERER_PIXBUF, G_ADD_PRIVATE (UmCellRendererUserImage));
+
+static void
+render_user_image (UmCellRendererUserImage *cell_renderer)
+{
+ cairo_surface_t *surface;
+ gint scale;
+
+ if (cell_renderer->priv->user != NULL) {
+ scale = gtk_widget_get_scale_factor (cell_renderer->priv->parent);
+ surface = render_user_icon (cell_renderer->priv->user, UM_ICON_STYLE_FRAME |
UM_ICON_STYLE_STATUS, 48, scale);
+ g_object_set (GTK_CELL_RENDERER_PIXBUF (cell_renderer), "surface", surface, NULL);
+ cairo_surface_destroy (surface);
+ } else {
+ g_object_set (GTK_CELL_RENDERER_PIXBUF (cell_renderer), "surface", NULL, NULL);
+ }
+}
+
+static void
+on_scale_factor_changed (GObject *object,
+ GParamSpec *pspec,
+ gpointer data)
+{
+ UmCellRendererUserImage *cell_renderer = UM_CELL_RENDERER_USER_IMAGE (data);
+
+ render_user_image (cell_renderer);
+}
+
+static void
+um_cell_renderer_user_image_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ UmCellRendererUserImage *cell_renderer = UM_CELL_RENDERER_USER_IMAGE (object);
+
+ switch (prop_id) {
+ case PROP_PARENT:
+ cell_renderer->priv->parent = g_value_dup_object (value);
+ g_signal_connect (cell_renderer->priv->parent, "notify::scale-factor", G_CALLBACK
(on_scale_factor_changed), cell_renderer);
+ break;
+ case PROP_USER:
+ g_clear_object (&cell_renderer->priv->user);
+ cell_renderer->priv->user = g_value_dup_object (value);
+ render_user_image (cell_renderer);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+um_cell_renderer_user_image_finalize (GObject *object)
+{
+ UmCellRendererUserImage *cell_renderer = UM_CELL_RENDERER_USER_IMAGE (object);
+
+ g_clear_object (&cell_renderer->priv->parent);
+ g_clear_object (&cell_renderer->priv->user);
+
+ G_OBJECT_CLASS (um_cell_renderer_user_image_parent_class)->finalize (object);
+}
+
+static void
+um_cell_renderer_user_image_class_init (UmCellRendererUserImageClass *class)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (class);
+
+ object_class->set_property = um_cell_renderer_user_image_set_property;
+ object_class->finalize = um_cell_renderer_user_image_finalize;
+
+ g_object_class_install_property (object_class, PROP_PARENT,
+ g_param_spec_object ("parent",
+ "Parent",
+ "Tree view aprent widget",
+ GTK_TYPE_WIDGET,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property (object_class, PROP_USER,
+ g_param_spec_object ("user",
+ "User",
+ "Accountsservice user used to generate image",
+ ACT_TYPE_USER,
+ G_PARAM_WRITABLE));
+}
+
+static void
+um_cell_renderer_user_image_init (UmCellRendererUserImage *cell_renderer)
+{
+ cell_renderer->priv = UM_CELL_RENDERER_USER_IMAGE_GET_PRIVATE (cell_renderer);
+}
+
+GtkCellRenderer *
+um_cell_renderer_user_image_new (GtkWidget *parent)
+{
+ return g_object_new (UM_TYPE_CELL_RENDERER_USER_IMAGE, "parent", parent, NULL);
+}
diff --git a/panels/user-accounts/um-cell-renderer-user-image.h
b/panels/user-accounts/um-cell-renderer-user-image.h
new file mode 100644
index 0000000..6176d2b
--- /dev/null
+++ b/panels/user-accounts/um-cell-renderer-user-image.h
@@ -0,0 +1,53 @@
+/*
+ * 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_CELL_RENDERER_USER_IMAGE_H
+#define _UM_CELL_RENDERER_USER_IMAGE_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define UM_TYPE_CELL_RENDERER_USER_IMAGE um_cell_renderer_user_image_get_type()
+
+#define UM_CELL_RENDERER_USER_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
UM_TYPE_CELL_RENDERER_USER_IMAGE, UmCellRendererUserImage))
+#define UM_CELL_RENDERER_USER_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
UM_TYPE_CELL_RENDERER_USER_IMAGE, UmCellRendererUserImageClass))
+#define UM_IS_CELL_RENDERER_USER_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
UM_TYPE_CELL_RENDERER_USER_IMAGE))
+#define UM_IS_CELL_RENDERER_USER_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
UM_TYPE_CELL_RENDERER_USER_IMAGE))
+#define UM_CELL_RENDERER_USER_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
UM_TYPE_CELL_RENDERER_USER_IMAGE, UmCellRendererUserImageClass))
+
+typedef struct _UmCellRendererUserImage UmCellRendererUserImage;
+typedef struct _UmCellRendererUserImageClass UmCellRendererUserImageClass;
+typedef struct _UmCellRendererUserImagePrivate UmCellRendererUserImagePrivate;
+
+struct _UmCellRendererUserImage {
+ GtkCellRendererPixbuf parent;
+
+ UmCellRendererUserImagePrivate *priv;
+};
+
+struct _UmCellRendererUserImageClass {
+ GtkCellRendererPixbufClass parent_class;
+};
+
+GType um_cell_renderer_user_image_get_type (void) G_GNUC_CONST;
+GtkCellRenderer *um_cell_renderer_user_image_new (GtkWidget *parent);
+
+G_END_DECLS
+
+#endif /* _UM_CELL_RENDERER_USER_IMAGE_H */
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index 9639ac9..e7c4a21 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -48,6 +48,7 @@
#include "um-editable-button.h"
#include "um-editable-combo.h"
#include "um-user-image.h"
+#include "um-cell-renderer-user-image.h"
#include "um-account-dialog.h"
#include "cc-language-chooser.h"
@@ -97,7 +98,6 @@ get_widget (CcUserPanelPrivate *d, const char *name)
enum {
USER_COL,
- FACE_COL,
NAME_COL,
USER_ROW_COL,
TITLE_COL,
@@ -192,7 +192,6 @@ user_added (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
GtkListStore *store;
GtkTreeIter iter;
GtkTreeIter dummy;
- cairo_surface_t *surface;
gchar *text, *title;
GtkTreeSelection *selection;
gint sort_key;
@@ -207,7 +206,6 @@ user_added (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
store = GTK_LIST_STORE (model);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
- surface = render_user_icon (user, UM_ICON_STYLE_FRAME | UM_ICON_STYLE_STATUS, 48, 1);
text = get_name_col_str (user);
if (act_user_get_uid (user) == getuid ()) {
@@ -221,14 +219,12 @@ user_added (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
gtk_list_store_set (store, &iter,
USER_COL, user,
- FACE_COL, surface,
NAME_COL, text,
USER_ROW_COL, TRUE,
TITLE_COL, NULL,
HEADING_ROW_COL, FALSE,
SORT_KEY_COL, sort_key,
-1);
- cairo_surface_destroy (surface);
g_free (text);
if (sort_key == 1 &&
@@ -344,7 +340,6 @@ user_changed (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
GtkTreeModel *model;
GtkTreeIter iter;
ActUser *current;
- cairo_surface_t *surface;
char *text;
tv = (GtkTreeView *)get_widget (d, "list-treeview");
@@ -355,15 +350,12 @@ user_changed (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
do {
gtk_tree_model_get (model, &iter, USER_COL, ¤t, -1);
if (current == user) {
- surface = render_user_icon (user, UM_ICON_STYLE_FRAME | UM_ICON_STYLE_STATUS, 48, 1);
text = get_name_col_str (user);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
USER_COL, user,
- FACE_COL, surface,
NAME_COL, text,
-1);
- cairo_surface_destroy (surface);
g_free (text);
g_object_unref (current);
@@ -1568,7 +1560,6 @@ setup_main_window (CcUserPanel *self)
userlist = get_widget (d, "list-treeview");
store = gtk_list_store_new (NUM_USER_LIST_COLS,
ACT_TYPE_USER,
- CAIRO_GOBJECT_TYPE_SURFACE,
G_TYPE_STRING,
G_TYPE_BOOLEAN,
G_TYPE_STRING,
@@ -1599,9 +1590,9 @@ setup_main_window (CcUserPanel *self)
d->other_iter = NULL;
column = gtk_tree_view_column_new ();
- cell = gtk_cell_renderer_pixbuf_new ();
+ cell = um_cell_renderer_user_image_new (userlist);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), cell, FALSE);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "surface", FACE_COL);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "user", USER_COL);
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "visible", USER_ROW_COL);
cell = gtk_cell_renderer_text_new ();
g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
@@ -1706,6 +1697,7 @@ cc_user_panel_init (CcUserPanel *self)
type = cc_editable_entry_get_type ();
type = um_editable_combo_get_type ();
type = um_user_image_get_type ();
+ type = um_cell_renderer_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]