[gnome-system-tools] Adapt commit error reporting to new API



commit 00a2d29b0ec23b5a992255be8e36ddc19a8aea33
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Sat Jan 9 12:39:11 2010 +0100

    Adapt commit error reporting to new API
    
    Add function gst_tool_commit_error(), used with custom commit methods such as the new users_config_add_user(). Use it when creating/deleting users and groups.

 src/common/gst-tool.c      |   12 +++++++++++-
 src/common/gst-tool.h      |    3 +++
 src/users/callbacks.c      |    6 +++++-
 src/users/group-settings.c |   13 +++++++++++++
 src/users/user-settings.c  |   15 ++++++++++++---
 5 files changed, 44 insertions(+), 5 deletions(-)
---
diff --git a/src/common/gst-tool.c b/src/common/gst-tool.c
index 46d84ea..645b205 100644
--- a/src/common/gst-tool.c
+++ b/src/common/gst-tool.c
@@ -488,7 +488,7 @@ gst_tool_hide_report_window (GstTool *tool)
 	gtk_widget_hide (tool->report_window);
 }
 
-/* Simple wrapper around oobs_object_commit(), that shows an error if needed */
+/* Simple wrapper around oobs_object_commit() that shows an error if needed */
 OobsResult
 gst_tool_commit (GstTool    *tool,
 		 OobsObject *object)
@@ -501,6 +501,16 @@ gst_tool_commit (GstTool    *tool,
 	return result;
 }
 
+/* Same as gst_tool_commit, but taking the result from an already run operation.
+   Used for non-standard commit methods, such as oobs_users_config_add_user(). */
+void
+gst_tool_commit_error (GstTool   *tool,
+                       OobsResult result)
+{
+	if (result != OOBS_RESULT_OK)
+		show_oobs_error_dialog (tool, OPERATION_COMMIT, result);
+}
+
 static void
 on_commit_finalized (OobsObject *object,
 		     OobsResult  result,
diff --git a/src/common/gst-tool.h b/src/common/gst-tool.h
index 5cd7a70..56aa0f5 100644
--- a/src/common/gst-tool.h
+++ b/src/common/gst-tool.h
@@ -112,6 +112,9 @@ void         gst_tool_commit_async    (GstTool             *tool,
 				       OobsObjectAsyncFunc  func,
 				       gpointer             data);
 
+void         gst_tool_commit_error    (GstTool             *tool,
+                                       OobsResult           result);
+
 void         gst_tool_update_async    (GstTool             *tool);
 
 void         gst_tool_add_configuration_object (GstTool    *tool,
diff --git a/src/users/callbacks.c b/src/users/callbacks.c
index 101b293..fb616ed 100644
--- a/src/users/callbacks.c
+++ b/src/users/callbacks.c
@@ -292,6 +292,7 @@ on_group_new_clicked (GtkButton *button, gpointer user_data)
 	GtkWidget *parent_dialog;
 	OobsGroupsConfig *config;
 	OobsGroup *group;
+	OobsResult result;
 	gint response;
 
 	group = oobs_group_new (NULL);
@@ -304,9 +305,12 @@ 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);
+		result = oobs_groups_config_add_group (config, group);
 
-		if (oobs_groups_config_add_group (config, group) == OOBS_RESULT_OK)
+		if (result == OOBS_RESULT_OK)
 			groups_table_add_group (group);
+		else
+			gst_tool_commit_error (tool, result);
 	}
 }
 
diff --git a/src/users/group-settings.c b/src/users/group-settings.c
index c283f28..e33465a 100644
--- a/src/users/group-settings.c
+++ b/src/users/group-settings.c
@@ -92,6 +92,7 @@ group_delete (GtkTreeModel *model, GtkTreePath *path)
 	GtkTreeIter iter;
 	OobsGroupsConfig *config;
 	OobsGroup *group;
+	OobsResult result;
 	gboolean retval = FALSE;
 
 	if (!gtk_tree_model_get_iter (model, &iter, path))
@@ -108,6 +109,18 @@ group_delete (GtkTreeModel *model, GtkTreePath *path)
 		if (retval)
 			gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
 	}
+	if (check_group_delete (group)) {
+		config = OOBS_GROUPS_CONFIG (GST_USERS_TOOL (tool)->groups_config);
+		result = oobs_groups_config_delete_group (config, group);
+		if (result == OOBS_RESULT_OK) {
+			gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+			retval = TRUE;
+		}
+		else {
+			gst_tool_commit_error (tool, result);
+			retval = FALSE;
+		}
+	}
 
 	g_object_unref (group);
 
diff --git a/src/users/user-settings.c b/src/users/user-settings.c
index 3eb788d..7666cec 100644
--- a/src/users/user-settings.c
+++ b/src/users/user-settings.c
@@ -134,6 +134,7 @@ user_delete (GtkTreeModel *model, GtkTreePath *path)
 	OobsUsersConfig *config;
 	OobsUser *user;
 	OobsListIter *list_iter;
+	OobsResult result;
 	gboolean retval = FALSE;
 
 	if (!gtk_tree_model_get_iter (model, &iter, path))
@@ -146,12 +147,15 @@ user_delete (GtkTreeModel *model, GtkTreePath *path)
 
 	if (check_user_delete (user)) {
 		config = OOBS_USERS_CONFIG (GST_USERS_TOOL (tool)->users_config);
-		if (oobs_users_config_delete_user (config, user)) {
+		result = oobs_users_config_delete_user (config, user);
+		if (result == OOBS_RESULT_OK) {
 			gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
 			retval = TRUE;
 		}
-		else
+		else {
+			gst_tool_commit_error (tool, result);
 			retval = FALSE;
+		}
 	}
 
 	g_object_unref (user);
@@ -909,6 +913,7 @@ on_user_new (GtkButton *button, gpointer user_data)
 	const char *fullname, *login;
 	GstUserProfile *profile;
 	OobsUsersConfig *users_config;
+	OobsResult result;
 
 	user_new_dialog = gst_dialog_get_widget (tool->main_dialog, "user_new_dialog");
 	user_name = gst_dialog_get_widget (tool->main_dialog, "user_new_name");
@@ -957,7 +962,8 @@ on_user_new (GtkButton *button, gpointer user_data)
 	/* 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 (oobs_users_config_add_user (users_config, user) == OOBS_RESULT_OK) {
+	result = oobs_users_config_add_user (users_config, user);
+	if (result == OOBS_RESULT_OK) {
 		gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config);
 		user_path = users_table_add_user (user, NULL);
 		users_table_select_path (user_path);
@@ -967,6 +973,9 @@ on_user_new (GtkButton *button, gpointer user_data)
 		 * User can hit cancel, leaving the account disabled */
 		on_edit_user_passwd (NULL, NULL);
 	}
+	else {
+		gst_tool_commit_error (tool, result);
+	}
 
 	g_object_unref (user);
 }



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