[gnome-control-center/wip/feborges/new-users-panel: 25/25] user-accounts: Use user_uid to index users instead of position
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/feborges/new-users-panel: 25/25] user-accounts: Use user_uid to index users instead of position
- Date: Wed, 24 Aug 2016 10:10:06 +0000 (UTC)
commit c409944820c625abd5f9c9dfb08963aa594c14c4
Author: Felipe Borges <felipeborges gnome org>
Date: Sun Aug 7 13:29:17 2016 +0200
user-accounts: Use user_uid to index users instead of position
This prevents wrong mapping when removing/adding/sorting users.
https://bugzilla.gnome.org/show_bug.cgi?id=767065
panels/user-accounts/um-arrow-frame.c | 22 +++++++++++-----------
panels/user-accounts/um-carousel.c | 20 +++++++++++++-------
panels/user-accounts/um-user-panel.c | 8 ++++----
3 files changed, 28 insertions(+), 22 deletions(-)
---
diff --git a/panels/user-accounts/um-arrow-frame.c b/panels/user-accounts/um-arrow-frame.c
index c751bc1..334fe45 100644
--- a/panels/user-accounts/um-arrow-frame.c
+++ b/panels/user-accounts/um-arrow-frame.c
@@ -41,7 +41,7 @@ G_DEFINE_TYPE (UmArrowFrame, um_arrow_frame, GTK_TYPE_FRAME)
static void um_arrow_frame_set_item (UmCarousel *carousel, GtkToggleButton *item, UmArrowFrame *frame);
static gint
-um_arrow_frame__get_row_x (UmArrowFrame *frame)
+um_arrow_frame_get_row_x (UmArrowFrame *frame)
{
GtkWidget *widget;
GtkWidget *row;
@@ -69,8 +69,8 @@ um_arrow_frame__get_row_x (UmArrowFrame *frame)
}
static void
-um_arrow_frame__draw_arrow (UmArrowFrame *frame,
- cairo_t *cr)
+um_arrow_frame_draw_arrow (UmArrowFrame *frame,
+ cairo_t *cr)
{
GtkWidget *widget = GTK_WIDGET (frame);
GtkStyleContext *context;
@@ -101,7 +101,7 @@ um_arrow_frame__draw_arrow (UmArrowFrame *frame,
/* widget size */
gtk_widget_get_allocation (widget, &alloc);
- tip_x = um_arrow_frame__get_row_x (frame);
+ tip_x = um_arrow_frame_get_row_x (frame);
start_x = tip_x - (ARROW_WIDTH / 2);
end_x = tip_x + (ARROW_WIDTH / 2);
@@ -118,9 +118,9 @@ um_arrow_frame__draw_arrow (UmArrowFrame *frame,
cairo_line_to (cr, end_x, end_y);
/*
- * * Don't allow that gtk_render_background renders
- * * anything out of (tip_x, start_y) (end_x, end_y).
- * */
+ * Don't allow that gtk_render_background renders
+ * anything out of (tip_x, start_y) (end_x, end_y).
+ */
cairo_clip (cr);
/* render the arrow background */
@@ -157,8 +157,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
-um_arrow_frame__draw_background (UmArrowFrame *frame,
- cairo_t *cr)
+um_arrow_frame_draw_background (UmArrowFrame *frame,
+ cairo_t *cr)
{
GtkWidget *widget = GTK_WIDGET (frame);
GtkStyleContext *context;
@@ -216,9 +216,9 @@ um_arrow_frame_draw (GtkWidget *widget,
UmArrowFrame *frame = UM_ARROW_FRAME (widget);
GtkWidget *child;
- um_arrow_frame__draw_background (frame, cr);
+ um_arrow_frame_draw_background (frame, cr);
if (frame->item)
- um_arrow_frame__draw_arrow (frame, cr);
+ um_arrow_frame_draw_arrow (frame, cr);
child = gtk_bin_get_child (GTK_BIN (widget));
diff --git a/panels/user-accounts/um-carousel.c b/panels/user-accounts/um-carousel.c
index c36a47d..ff5891c 100644
--- a/panels/user-accounts/um-carousel.c
+++ b/panels/user-accounts/um-carousel.c
@@ -21,6 +21,7 @@
#include "um-carousel.h"
+#include <act/act.h>
#include <glib-object.h>
#include <gtk/gtk.h>
@@ -115,7 +116,8 @@ on_item_toggled (GtkToggleButton *item,
static GtkWidget *
create_item (UmCarousel *self,
GtkWidget *child,
- gint position)
+ gint position,
+ gint item_id)
{
GtkStyleProvider *provider;
GtkWidget *item;
@@ -128,7 +130,7 @@ create_item (UmCarousel *self,
g_object_unref (provider);
- g_object_set_data (G_OBJECT (item), "position", GINT_TO_POINTER (position));
+ g_object_set_data (G_OBJECT (item), "item-ref", GINT_TO_POINTER (item_id));
g_signal_connect (item, "toggled", G_CALLBACK (on_item_toggled), self);
if (self->current_button == NULL) {
@@ -168,12 +170,13 @@ forall_items (GtkContainer *container,
static void
insert_item (UmCarousel *self,
GtkWidget *child,
- gint position)
+ gint position,
+ gint item_id)
{
GtkWidget *item, *box;
box = get_page (self);
- item = create_item (self, child, position);
+ item = create_item (self, child, position, item_id);
if (position == 0) {
g_sequence_prepend (self->children, item);
@@ -229,21 +232,24 @@ model_changed (GListModel *list,
for (i = 0; i < added; i++) {
GObject *item;
GtkWidget *widget;
+ uid_t user_uid;
- item = g_list_model_get_item (list, position + i);
+ item = g_list_model_get_object (list, position + i);
+ user_uid = act_user_get_uid (ACT_USER (item));
widget = self->create_widget_func (item, self->create_widget_func_data);
- if (g_object_is_floating (widget))
+ if (g_object_is_floating (widget)) {
g_object_ref_sink (widget);
gtk_widget_show (widget);
- insert_item (self, widget, position + i);
+ insert_item (self, widget, position + i, user_uid);
g_object_unref (widget);
g_object_unref (item);
/* Jump to last page when a new item gets appended. */
set_visible_page (self, g_sequence_get_length (self->pages) -1);
+ }
}
have_more_pages = (g_sequence_get_length (self->pages) > 1);
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index 92c86ef..2e023a6 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -164,12 +164,12 @@ item_toggled (UmCarousel *carousel,
CcUserPanelPrivate *d)
{
ActUser *user;
- gint position;
+ gint user_uid;
- position = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "position"));
- user = g_list_model_get_item (G_LIST_MODEL (d->users_list), position);
+ user_uid = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "item-ref"));
+ user = act_user_manager_get_user_by_id (d->um, user_uid);
- if (ACT_IS_USER (user)) {
+ if (user && ACT_IS_USER (user)) {
show_user (user, d);
gtk_widget_set_sensitive (get_widget (d, "main-user-vbox"), TRUE);
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]