[gnome-system-tools] Move to new users and groups STB protocol



commit 3a92383f93bead9b9740330c2f3376b83deaba71
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Mon Jan 4 19:24:20 2010 +0100

    Move to new users and groups STB protocol
    
    The new protocol in the System Tools Backends >= 2.9 (liboobs 2.29.2) no longer commits users config as a whole. Instead, we use oobs_user_commit() and oobs_users_config_add/delete_user(). Groups are still committed as a whole when changing a user's privileges, but individually in the groups dialog.
    
    Keeping references to OobsListIters for groups in groups and privileges table is now useless, making the functions simpler.

 src/users/callbacks.c        |   17 +++--------------
 src/users/group-settings.c   |   11 +++--------
 src/users/groups-table.c     |   10 ++++------
 src/users/groups-table.h     |    5 +----
 src/users/privileges-table.c |    2 +-
 src/users/privileges-table.h |    3 +--
 src/users/user-settings.c    |   36 ++++++++++++++----------------------
 src/users/users-tool.c       |    4 ++--
 8 files changed, 29 insertions(+), 59 deletions(-)
---
diff --git a/src/users/callbacks.c b/src/users/callbacks.c
index ed06049..f7b5e83 100644
--- a/src/users/callbacks.c
+++ b/src/users/callbacks.c
@@ -292,8 +292,6 @@ on_group_new_clicked (GtkButton *button, gpointer user_data)
 	GtkWidget *parent_dialog;
 	OobsGroupsConfig *config;
 	OobsGroup *group;
-	OobsList *groups_list;
-	OobsListIter list_iter;
 	gint response;
 
 	group = oobs_group_new (NULL);
@@ -305,14 +303,10 @@ on_group_new_clicked (GtkButton *button, gpointer user_data)
 
 	if (response == GTK_RESPONSE_OK) {
 		group = group_settings_dialog_get_group ();
-
 		config = OOBS_GROUPS_CONFIG (GST_USERS_TOOL (tool)->groups_config);
-		groups_list = oobs_groups_config_get_groups (config);
-		oobs_list_append (groups_list, &list_iter);
-		oobs_list_set (groups_list, &list_iter, group);
 
-		if (gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config) == OOBS_RESULT_OK)
-			groups_table_add_group (group, &list_iter);
+		if (oobs_groups_config_add_group (config, group) == OOBS_RESULT_OK)
+			groups_table_add_group (group);
 	}
 }
 
@@ -324,7 +318,6 @@ on_group_settings_clicked (GtkButton *button, gpointer user_data)
 	GtkTreeModel *model;
 	GtkTreeIter filter_iter, iter;
 	OobsGroup *group;
-	OobsListIter *list_iter;
 	gint response;
 
 	table = gst_dialog_get_widget (tool->main_dialog, "groups_table");
@@ -339,7 +332,6 @@ on_group_settings_clicked (GtkButton *button, gpointer user_data)
 
 	gtk_tree_model_get (model, &iter,
 			    COL_GROUP_OBJECT, &group,
-			    COL_GROUP_ITER, &list_iter,
 			    -1);
 	dialog = group_settings_dialog_new (group);
 	parent_dialog = gst_dialog_get_widget (tool->main_dialog, "groups_dialog");
@@ -351,12 +343,11 @@ on_group_settings_clicked (GtkButton *button, gpointer user_data)
 		gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
 								  &filter_iter, &iter);
 		group_settings_dialog_get_data (group);
-		groups_table_set_group (group, list_iter, &filter_iter);
+		groups_table_set_group (group, &filter_iter);
 		gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config);
 	}
 
 	g_object_unref (group);
-	oobs_list_iter_free (list_iter);
 }
 
 void
@@ -378,8 +369,6 @@ on_group_delete_clicked (GtkButton *button, gpointer user_data)
 
 	g_list_foreach (list, (GFunc) gtk_tree_row_reference_free, NULL);
 	g_list_free (list);
-
-	gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config);
 }
 
 /* User settings callbacks */
diff --git a/src/users/group-settings.c b/src/users/group-settings.c
index 36602c7..c283f28 100644
--- a/src/users/group-settings.c
+++ b/src/users/group-settings.c
@@ -92,8 +92,6 @@ group_delete (GtkTreeModel *model, GtkTreePath *path)
 	GtkTreeIter iter;
 	OobsGroupsConfig *config;
 	OobsGroup *group;
-	OobsList *groups_list;
-	OobsListIter *list_iter;
 	gboolean retval = FALSE;
 
 	if (!gtk_tree_model_get_iter (model, &iter, path))
@@ -101,20 +99,17 @@ group_delete (GtkTreeModel *model, GtkTreePath *path)
 
 	gtk_tree_model_get (model, &iter,
 			    COL_GROUP_OBJECT, &group,
-			    COL_GROUP_ITER, &list_iter,
 			    -1);
 
 	if (check_group_delete (group)) {
 		config = OOBS_GROUPS_CONFIG (GST_USERS_TOOL (tool)->groups_config);
-		groups_list = oobs_groups_config_get_groups (config);
-		oobs_list_remove (groups_list, list_iter);
+		retval = (OOBS_RESULT_OK == oobs_groups_config_delete_group (config, group));
 
-		gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
-		retval = TRUE;
+		if (retval)
+			gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
 	}
 
 	g_object_unref (group);
-	oobs_list_iter_free (list_iter);
 
 	return retval;
 
diff --git a/src/users/groups-table.c b/src/users/groups-table.c
index bfb51dc..ca8b800 100644
--- a/src/users/groups-table.c
+++ b/src/users/groups-table.c
@@ -59,8 +59,7 @@ create_groups_model (void)
 	store = gtk_list_store_new (COL_GROUP_LAST,
 	                            G_TYPE_STRING,
 	                            G_TYPE_INT,
-				    G_TYPE_OBJECT,
-				    OOBS_TYPE_LIST_ITER);
+				    G_TYPE_OBJECT);
 
 	return GTK_TREE_MODEL (store);
 }
@@ -100,7 +99,7 @@ create_groups_table (void)
 }
 
 void
-groups_table_set_group (OobsGroup *group, OobsListIter *list_iter, GtkTreeIter *iter)
+groups_table_set_group (OobsGroup *group, GtkTreeIter *iter)
 {
 	GtkWidget *groups_table = gst_dialog_get_widget (tool->main_dialog, "groups_table");
 	GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (groups_table));
@@ -109,19 +108,18 @@ groups_table_set_group (OobsGroup *group, OobsListIter *list_iter, GtkTreeIter *
 			    COL_GROUP_NAME, oobs_group_get_name (group),
 			    COL_GROUP_ID, oobs_group_get_gid (group),
 			    COL_GROUP_OBJECT, group,
-			    COL_GROUP_ITER, list_iter,
 			    -1);
 }
 
 void
-groups_table_add_group (OobsGroup *group, OobsListIter *list_iter)
+groups_table_add_group (OobsGroup *group)
 {
 	GtkWidget *groups_table = gst_dialog_get_widget (tool->main_dialog, "groups_table");
 	GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (groups_table));
 	GtkTreeIter iter;
 
 	gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-	groups_table_set_group (group, list_iter, &iter);
+	groups_table_set_group (group, &iter);
 }
 
 void
diff --git a/src/users/groups-table.h b/src/users/groups-table.h
index 55ccf41..ef8841a 100644
--- a/src/users/groups-table.h
+++ b/src/users/groups-table.h
@@ -28,7 +28,6 @@ enum {
 	COL_GROUP_NAME,
 	COL_GROUP_ID,
 	COL_GROUP_OBJECT,
-	COL_GROUP_ITER,
 	COL_GROUP_LAST
 };
 
@@ -55,9 +54,7 @@ void	populate_groups_table		(void);
 void	group_table_update_content	(void);
 
 void    groups_table_set_group          (OobsGroup    *group,
-                                         OobsListIter *list_iter,
                                          GtkTreeIter  *iter);
-void    groups_table_add_group          (OobsGroup    *group,
-                                         OobsListIter *list_iter);
+void    groups_table_add_group          (OobsGroup    *group);
 
 #endif /* _GROUPS_TABLE_H */
diff --git a/src/users/privileges-table.c b/src/users/privileges-table.c
index 5aaf589..923649d 100644
--- a/src/users/privileges-table.c
+++ b/src/users/privileges-table.c
@@ -190,7 +190,7 @@ create_user_privileges_table (void)
 }
 
 void
-privileges_table_add_group (OobsGroup *group, OobsListIter *list_iter)
+privileges_table_add_group (OobsGroup *group)
 {
 	const PrivilegeDescription *p;
 	GtkWidget *table;
diff --git a/src/users/privileges-table.h b/src/users/privileges-table.h
index 283b8fb..9b766cf 100644
--- a/src/users/privileges-table.h
+++ b/src/users/privileges-table.h
@@ -33,8 +33,7 @@ void     privileges_table_clear            (void);
 void     populate_privileges_table         (GtkWidget*, gchar*);
 GList*   user_privileges_get_list          (GList*);
 
-void     privileges_table_add_group        (OobsGroup    *group,
-                                            OobsListIter *list_iter);
+void     privileges_table_add_group        (OobsGroup    *group);
 
 void     privileges_table_set_from_profile (GstUserProfile *profile);
 void     privileges_table_set_from_user    (OobsUser *user);
diff --git a/src/users/user-settings.c b/src/users/user-settings.c
index ff52073..5020777 100644
--- a/src/users/user-settings.c
+++ b/src/users/user-settings.c
@@ -133,7 +133,6 @@ user_delete (GtkTreeModel *model, GtkTreePath *path)
 	GtkTreeIter iter;
 	OobsUsersConfig *config;
 	OobsUser *user;
-	OobsList *users_list;
 	OobsListIter *list_iter;
 	gboolean retval = FALSE;
 
@@ -147,11 +146,12 @@ user_delete (GtkTreeModel *model, GtkTreePath *path)
 
 	if (check_user_delete (user)) {
 		config = OOBS_USERS_CONFIG (GST_USERS_TOOL (tool)->users_config);
-		users_list = oobs_users_config_get_users (config);
-		oobs_list_remove (users_list, list_iter);
-
-		gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
-		retval = TRUE;
+		if (oobs_users_config_delete_user (config, user)) {
+			gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+			retval = TRUE;
+		}
+		else
+			retval = FALSE;
 	}
 
 	g_object_unref (user);
@@ -182,9 +182,6 @@ on_user_delete_clicked (GtkButton *button, gpointer user_data)
 
 	g_list_foreach (list, (GFunc) gtk_tree_row_reference_free, NULL);
 	g_list_free (list);
-
-	if (count > 0)
-		gst_tool_commit (tool, GST_USERS_TOOL (tool)->users_config);
 }
 
 static void
@@ -284,7 +281,7 @@ set_main_group (OobsUser *user)
 	/* Try to commit before doing anything, to avoid displaying wrong data */
 	if (gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config) == OOBS_RESULT_OK) {
 		if (is_group_new)
-			groups_table_add_group (group, &list_iter);
+			groups_table_add_group (group);
 
 		/* This will be committed with the user himself */
 		oobs_user_set_main_group (user, group);
@@ -975,8 +972,6 @@ on_user_new (GtkButton *button, gpointer user_data)
 	OobsUser *user;
 	const char *fullname, *login;
 	GstUserProfile *profile;
-	OobsList *users_list;
-	OobsListIter list_iter;
 	OobsUsersConfig *users_config;
 
 	user_new_dialog = gst_dialog_get_widget (tool->main_dialog, "user_new_dialog");
@@ -1028,16 +1023,13 @@ on_user_new (GtkButton *button, gpointer user_data)
 	gst_user_profiles_apply (GST_USERS_TOOL (tool)->profiles, profile, user, TRUE);
 
 	users_config = OOBS_USERS_CONFIG (GST_USERS_TOOL (tool)->users_config);
-	users_list = oobs_users_config_get_users (users_config);
-	oobs_list_append (users_list, &list_iter);
-	oobs_list_set (users_list, &list_iter, user);
 
-	/* Commit both users and groups config because of possible memberships
+	/* Commit both user and groups config because of possible memberships
 	 * added by the profile. Avoid showing the new user or trying to commit
 	 * group changes if the user has not been created. */
-	if (gst_tool_commit (tool, OOBS_OBJECT (users_config)) == OOBS_RESULT_OK) {
+	if (oobs_users_config_add_user (users_config, user) == OOBS_RESULT_OK) {
 		gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config);
-		user_path = users_table_add_user (user, &list_iter);
+		user_path = users_table_add_user (user, NULL);
 		users_table_select_path (user_path);
 		gtk_tree_path_free (user_path);
 
@@ -1118,7 +1110,7 @@ on_edit_user_name (GtkButton *button, gpointer user_data)
 
 		fullname = gtk_entry_get_text (GTK_ENTRY (user_name_entry));
 		oobs_user_set_full_name (user, fullname);
-		gst_tool_commit (tool, GST_USERS_TOOL (tool)->users_config);
+		gst_tool_commit (tool, OOBS_OBJECT (user));
 	}
 
 	g_object_unref (user);
@@ -1219,7 +1211,7 @@ on_edit_user_passwd (GtkButton *button, gpointer user_data)
 
 	/* commit both user and groups config
 	 * because of the no_passwd_login_group membership */
-	if (gst_tool_commit (tool, GST_USERS_TOOL (tool)->users_config) == OOBS_RESULT_OK)
+	if (gst_tool_commit (tool, OOBS_OBJECT (user)) == OOBS_RESULT_OK)
 		gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config);
 
 	g_object_unref (user);
@@ -1294,7 +1286,7 @@ on_edit_user_profile (GtkButton *button, gpointer user_data)
 		                           profile, user, FALSE);
 
 		  if (response == GTK_RESPONSE_OK) {
-			  if (gst_tool_commit (tool, GST_USERS_TOOL (tool)->users_config) == OOBS_RESULT_OK)
+			  if (gst_tool_commit (tool, OOBS_OBJECT (user)) == OOBS_RESULT_OK)
 				  gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config);
 		  }
 	  }
@@ -1401,7 +1393,7 @@ on_edit_user_advanced (GtkButton *button, gpointer user_data)
 
 	privileges_table_save (user);
 
-	if (gst_tool_commit (tool, GST_USERS_TOOL (tool)->users_config) == OOBS_RESULT_OK)
+	if (gst_tool_commit (tool, OOBS_OBJECT (user)) == OOBS_RESULT_OK)
 		gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config);
 
 	g_object_unref (user);
diff --git a/src/users/users-tool.c b/src/users/users-tool.c
index 8d6d2ef..d543767 100644
--- a/src/users/users-tool.c
+++ b/src/users/users-tool.c
@@ -162,10 +162,10 @@ update_groups (GstUsersTool *tool)
 
 	while (valid) {
 		group = oobs_list_get (list, &iter);
-		groups_table_add_group (OOBS_GROUP (group), &iter);
+		groups_table_add_group (OOBS_GROUP (group));
 
 		/* update privileges table too */
-		privileges_table_add_group (OOBS_GROUP (group), &iter);
+		privileges_table_add_group (OOBS_GROUP (group));
 
 		g_object_unref (group);
 		valid = oobs_list_iter_next (list, &iter);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]