[gnome-system-tools/users-ui-redesign] Add convenience function users_table_get_current()
- From: Milan Bouchet-Valat <milanbv src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-system-tools/users-ui-redesign] Add convenience function users_table_get_current()
- Date: Tue, 17 Nov 2009 19:12:48 +0000 (UTC)
commit 8dedf41511073fc6c0cab3272b7da8aba7876775
Author: Milan Bouchet-Valat <nalimilan club fr>
Date: Tue Nov 10 13:35:05 2009 +0100
Add convenience function users_table_get_current()
This function returns the current user, which is the first selected user from the table, and the one whose settings are shown. It's now used from on_table_selection_changed(), which will now display the settings for this user if several users are selected, instead of merely skipping.
src/users/callbacks.c | 13 ++-----------
src/users/users-table.c | 28 ++++++++++++++++++++++++++++
src/users/users-table.h | 30 ++++++++++++++++++------------
3 files changed, 48 insertions(+), 23 deletions(-)
---
diff --git a/src/users/callbacks.c b/src/users/callbacks.c
index 405f87e..bd1f251 100644
--- a/src/users/callbacks.c
+++ b/src/users/callbacks.c
@@ -124,17 +124,8 @@ on_table_selection_changed (GtkTreeSelection *selection, gpointer data)
table = GPOINTER_TO_INT (data);
count = gtk_tree_selection_count_selected_rows (selection);
- if (table == TABLE_USERS && count == 1) {
- GtkTreeModel *model;
- GList *selected;
- GtkTreePath *path;
- GtkTreeIter iter;
-
- selected = gtk_tree_selection_get_selected_rows (selection, &model);
- path = (GtkTreePath *) selected->data;
-
- gtk_tree_model_get_iter (model, &iter, path);
- gtk_tree_model_get (model, &iter, COL_USER_OBJECT, &user, -1);
+ if (table == TABLE_USERS) {
+ user = users_table_get_current ();
}
actions_set_sensitive (table, count, user);
diff --git a/src/users/users-table.c b/src/users/users-table.c
index d1e1fca..18c1ea4 100644
--- a/src/users/users-table.c
+++ b/src/users/users-table.c
@@ -206,3 +206,31 @@ users_table_select_first (void)
gtk_tree_selection_select_path (selection, first_user);
}
+/*
+ * Convenience function to get the first selected user of the table,
+ * i.e. the one whose settings are currently shown.
+ * Don't forget to unref the return value
+ */
+OobsUser *
+users_table_get_current (void)
+{
+ GtkWidget *users_table = gst_dialog_get_widget (GST_TOOL (tool)->main_dialog, "users_table");
+ GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (users_table));
+ GtkTreeModel *model;
+ GList *selected;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ OobsUser *user;
+
+ selected = gtk_tree_selection_get_selected_rows (selection, &model);
+
+ /* Only choose the first selected user */
+ path = (GtkTreePath *) selected->data;
+
+ gtk_tree_model_get_iter (model, &iter, path);
+ g_list_foreach (selected, (GFunc) gtk_tree_path_free, NULL);
+ g_list_free (selected);
+
+ gtk_tree_model_get (model, &iter, COL_USER_OBJECT, &user, -1);
+ return user;
+}
diff --git a/src/users/users-table.h b/src/users/users-table.h
index 2e6c28b..49372a8 100644
--- a/src/users/users-table.h
+++ b/src/users/users-table.h
@@ -40,18 +40,24 @@ enum {
COL_USER_LAST
};
-void create_users_table (GstUsersTool *tool);
-void users_table_clear (void);
-void users_table_set_user (OobsUser *user,
- OobsListIter *list_iter,
- GtkTreeIter *iter);
-void users_table_add_user (OobsUser *user,
- OobsListIter *list_iter);
-void users_table_select_first (void);
-
-void users_table_actions_set_sensitive (gint table,
- gint count,
- OobsUser *user);
+void create_users_table (GstUsersTool *tool);
+
+void users_table_clear (void);
+
+void users_table_set_user (OobsUser *user,
+ OobsListIter *list_iter,
+ GtkTreeIter *iter);
+
+void users_table_add_user (OobsUser *user,
+ OobsListIter *list_iter);
+
+void users_table_select_first (void);
+
+OobsUser *users_table_get_current (void);
+
+void users_table_actions_set_sensitive (gint table,
+ gint count,
+ OobsUser *user);
#endif /* _USERS_TABLE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]