[accounts-dialog] Group the user list a bit betterr
- From: Matthias Clasen <matthiasc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [accounts-dialog] Group the user list a bit betterr
- Date: Sat, 16 Jan 2010 04:55:02 +0000 (UTC)
commit 47501c4ebba39347cf3f4b08e5c7155a0794d981
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jan 15 23:52:47 2010 -0500
Group the user list a bit betterr
src/main.c | 152 +++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 116 insertions(+), 36 deletions(-)
---
diff --git a/src/main.c b/src/main.c
index 03ea90a..79219ba 100644
--- a/src/main.c
+++ b/src/main.c
@@ -84,6 +84,10 @@ enum {
USER_COL,
FACE_COL,
NAME_COL,
+ USER_ROW_COL,
+ TITLE_COL,
+ HEADING_ROW_COL,
+ SORT_KEY_COL,
NUM_USER_LIST_COLS
};
@@ -119,43 +123,57 @@ static void
user_added (UmUserManager *um, UmUser *user, UserAccountDialog *d)
{
GtkWidget *widget;
+ GtkTreeModel *model;
GtkListStore *store;
+ GtkListStore *list_store;
GtkTreeIter iter;
+ GtkTreeIter dummy;
GdkPixbuf *pixbuf;
gchar *text;
GtkTreeSelection *selection;
- GtkTreeIter iter2;
- GtkTreeModel *model;
+ gint sort_key;
+ g_debug ("user added: %d %s\n", um_user_get_uid (user), um_user_get_real_name (user));
widget = get_widget (d, "list-treeview");
- store = (GtkListStore *)gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
+ store = GTK_LIST_STORE (model);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
- g_debug ("user added: %d %s\n", um_user_get_uid (user), um_user_get_real_name (user));
-
pixbuf = um_user_render_icon (user, TRUE, 48);
text = g_strdup_printf ("<b>%s</b>\n<i>%s</i>",
um_user_get_real_name (user),
um_account_type_get_name (um_user_get_account_type (user)));
+ if (um_user_get_uid (user) == getuid ()) {
+ sort_key = 1;
+ }
+ else {
+ sort_key = 3;
+ }
gtk_list_store_append (store, &iter);
+
gtk_list_store_set (store, &iter,
USER_COL, user,
FACE_COL, pixbuf,
NAME_COL, text,
+ USER_ROW_COL, TRUE,
+ TITLE_COL, NULL,
+ HEADING_ROW_COL, FALSE,
+ SORT_KEY_COL, sort_key,
-1);
g_object_unref (pixbuf);
g_free (text);
- if (!gtk_tree_selection_get_selected (selection, &model, &iter2) &&
- um_user_get_uid (user) == getuid ())
+ if (sort_key == 1 &&
+ !gtk_tree_selection_get_selected (selection, &model, &dummy)) {
gtk_tree_selection_select_iter (selection, &iter);
+ }
/* add the user to the automatic login list */
widget = get_widget (d, "dm-automatic-login-combobox");
- store = (GtkListStore*)gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
+ list_store = (GtkListStore*)gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
AUTOLOGIN_NAME_COL, um_user_get_real_name (user),
AUTOLOGIN_USER_COL, user,
-1);
@@ -179,6 +197,7 @@ user_removed (UmUserManager *um, UmUser *user, UserAccountDialog *d)
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkListStore *store;
+ GtkListStore *list_store;
GtkTreeIter iter, next;
GtkComboBox *combo;
UmUser *u;
@@ -187,34 +206,36 @@ user_removed (UmUserManager *um, UmUser *user, UserAccountDialog *d)
tv = (GtkTreeView *)get_widget (d, "list-treeview");
selection = gtk_tree_view_get_selection (tv);
model = gtk_tree_view_get_model (tv);
- store = (GtkListStore *)model;
+ store = GTK_LIST_STORE (model);
if (gtk_tree_model_get_iter_first (model, &iter)) {
do {
gtk_tree_model_get (model, &iter, USER_COL, &u, -1);
- if (um_user_get_uid (user) == um_user_get_uid (u)) {
- next = iter;
- if (!gtk_tree_model_iter_next (model, &next))
- get_previous (model, &iter, &next);
- gtk_list_store_remove (store, &iter);
- gtk_tree_selection_select_iter (selection, &next);
+ if (u != NULL) {
+ if (um_user_get_uid (user) == um_user_get_uid (u)) {
+ next = iter;
+ if (!gtk_tree_model_iter_next (model, &next))
+ get_previous (model, &iter, &next);
+ gtk_list_store_remove (store, &iter);
+ gtk_tree_selection_select_iter (selection, &next);
+ g_object_unref (u);
+ break;
+ }
g_object_unref (u);
- break;
}
- g_object_unref (u);
} while (gtk_tree_model_iter_next (model, &iter));
}
/* remove the user from the automatic login list */
combo = GTK_COMBO_BOX (get_widget (d, "dm-automatic-login-combobox"));
model = gtk_combo_box_get_model (combo);
- store = (GtkListStore*)model;
+ list_store = (GtkListStore*)model;
gtk_combo_box_get_active_iter (combo, &iter);
gtk_tree_model_get (model, &iter, AUTOLOGIN_USER_COL, &u, -1);
if (u != NULL) {
if (um_user_get_uid (user) == um_user_get_uid (u)) {
/* autologin user got removed, set back to Disabled */
- gtk_list_store_remove (store, &iter);
+ gtk_list_store_remove (list_store, &iter);
gtk_combo_box_set_active (combo, 0);
g_object_unref (u);
return;
@@ -227,7 +248,7 @@ user_removed (UmUserManager *um, UmUser *user, UserAccountDialog *d)
if (u != NULL) {
if (um_user_get_uid (user) == um_user_get_uid (u)) {
- gtk_list_store_remove (store, &iter);
+ gtk_list_store_remove (list_store, &iter);
g_object_unref (u);
return;
}
@@ -842,49 +863,100 @@ sort_users (GtkTreeModel *model,
gpointer data)
{
UmUser *ua, *ub;
+ gint sa, sb;
gint result;
- gtk_tree_model_get (model, a, USER_COL, &ua, -1);
- gtk_tree_model_get (model, b, USER_COL, &ub, -1);
+ gtk_tree_model_get (model, a, USER_COL, &ua, SORT_KEY_COL, &sa, -1);
+ gtk_tree_model_get (model, b, USER_COL, &ub, SORT_KEY_COL, &sb, -1);
- if (um_user_get_uid (ua) == getuid ())
+ if (sa < sb) {
result = -1;
- else if (um_user_get_uid (ub) == getuid ())
+ }
+ else if (sa > sb) {
result = 1;
- else
+ }
+ else {
result = um_user_collate (ua, ub);
+ }
- g_object_unref (ua);
- g_object_unref (ub);
+ if (ua) {
+ g_object_unref (ua);
+ }
+ if (ub) {
+ g_object_unref (ub);
+ }
return result;
}
+static gboolean
+dont_select_headings (GtkTreeSelection *selection,
+ GtkTreeModel *model,
+ GtkTreePath *path,
+ gboolean selected,
+ gpointer data)
+{
+ GtkTreeIter iter;
+ gboolean is_user;
+
+ gtk_tree_model_get_iter (model, &iter, path);
+ gtk_tree_model_get (model, &iter, USER_ROW_COL, &is_user, -1);
+
+ return is_user;
+}
+
static void
setup_main_window (UserAccountDialog *d)
{
GtkWidget *window;
GtkWidget *userlist;
- GtkTreeModel *users;
+ GtkTreeModel *model;
+ GtkListStore *store;
GtkTreeViewColumn *column;
GtkCellRenderer *cell;
GtkTreeSelection *selection;
GtkWidget *button;
GSList *list, *l;
+ GtkTreeIter iter;
+ gint expander_size;
window = get_widget (d, "user-account-window");
g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
userlist = get_widget (d, "list-treeview");
- users = (GtkTreeModel*)gtk_list_store_new (3, UM_TYPE_USER, GDK_TYPE_PIXBUF, G_TYPE_STRING);
- gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (users), sort_users, NULL, NULL);
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (users), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
- gtk_tree_view_set_model (GTK_TREE_VIEW (userlist), users);
+ store = gtk_list_store_new (NUM_USER_LIST_COLS,
+ UM_TYPE_USER,
+ GDK_TYPE_PIXBUF,
+ G_TYPE_STRING,
+ G_TYPE_BOOLEAN,
+ G_TYPE_STRING,
+ G_TYPE_BOOLEAN,
+ G_TYPE_INT);
+ model = (GtkTreeModel *)store;
+ gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (model), sort_users, NULL, NULL);
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (userlist), model);
g_signal_connect (d->um, "user-added", G_CALLBACK (user_added), d);
g_signal_connect (d->um, "user-removed", G_CALLBACK (user_removed), d);
g_signal_connect (d->um, "user-changed", G_CALLBACK (user_changed), d);
+ gtk_widget_style_get (userlist, "expander-size", &expander_size, NULL);
+ gtk_tree_view_set_level_indentation (GTK_TREE_VIEW (userlist), - (expander_size + 6));
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ TITLE_COL, "<small><span foreground=\"#555555\">My Account</span></small>",
+ HEADING_ROW_COL, TRUE,
+ SORT_KEY_COL, 0,
+ -1);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ TITLE_COL, "<small><span foreground=\"#555555\">Other Accounts</span></small>",
+ HEADING_ROW_COL, TRUE,
+ SORT_KEY_COL, 2,
+ -1);
+
list = um_user_manager_list_users (d->um);
g_debug ("Got %d users\n", g_slist_length (list));
for (l = list; l; l = l->next) {
@@ -896,16 +968,24 @@ setup_main_window (UserAccountDialog *d)
column = gtk_tree_view_column_new ();
cell = gtk_cell_renderer_pixbuf_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), cell, FALSE);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "pixbuf", 1);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "pixbuf", FACE_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, "width-chars", 18, NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), cell, TRUE);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "markup", 2);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "markup", NAME_COL);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "visible", USER_ROW_COL);
+ cell = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), cell, TRUE);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "markup", TITLE_COL);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "visible", HEADING_ROW_COL);
+
gtk_tree_view_append_column (GTK_TREE_VIEW (userlist), column);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (userlist));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
g_signal_connect (selection, "changed", G_CALLBACK (selected_user_changed), d);
+ gtk_tree_selection_set_select_function (selection, dont_select_headings, NULL, NULL);
button = get_widget (d, "add-user-button");
g_signal_connect (button, "clicked", G_CALLBACK (add_user), d);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]