[gnome-system-tools] Handle returning to locked state by disabling widgets



commit 29e2f53891c25a7758476e84ec693d1d7dfd627e
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Wed Aug 19 20:46:11 2009 +0200

    Handle returning to locked state by disabling widgets
    
    The previous implementation did not allow to revoke authorization. Implementing this required renaming a few functions to be more correct, modifying some of them, and adding calls so that relocking triggers state change. Changes to src/common are enough for all modules but users-admin, which handles users table separately.

 src/common/gst-dialog.c  |   24 ++++++++++++++----------
 src/common/gst-dialog.h  |    2 +-
 src/users/callbacks.c    |   24 +++++++++++++++++++-----
 src/users/callbacks.h    |    4 ++--
 src/users/groups-table.c |    2 +-
 src/users/main.c         |    2 +-
 src/users/users-table.c  |    2 +-
 src/users/users-table.h  |    4 ++++
 src/users/users-tool.c   |    4 ++--
 9 files changed, 45 insertions(+), 23 deletions(-)
---
diff --git a/src/common/gst-dialog.c b/src/common/gst-dialog.c
index 40a065d..10fe7ab 100644
--- a/src/common/gst-dialog.c
+++ b/src/common/gst-dialog.c
@@ -88,7 +88,7 @@ static void     gst_dialog_realize      (GtkWidget   *widget);
 static void     gst_dialog_set_cursor   (GstDialog     *dialog,
 					 GdkCursorType  cursor_type);
 
-static void             gst_dialog_unlock                (GstDialog *dialog);
+static void             gst_dialog_lock_changed          (GstDialog *dialog);
 static GstWidgetPolicy *gst_dialog_get_policy_for_widget (GtkWidget *widget);
 
 enum {
@@ -99,7 +99,7 @@ enum {
 };
 
 enum {
-	UNLOCKED,
+	LOCK_CHANGED,
 	LAST_SIGNAL
 };
 
@@ -146,11 +146,11 @@ gst_dialog_class_init (GstDialogClass *class)
 							      NULL,
 							      G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
 
-	signals [UNLOCKED] =
-		g_signal_new ("unlocked",
+	signals [LOCK_CHANGED] =
+		g_signal_new ("lock-changed",
 			      G_OBJECT_CLASS_TYPE (object_class),
 			      G_SIGNAL_RUN_LAST,
-			      G_STRUCT_OFFSET (GstDialogClass, unlocked),
+			      G_STRUCT_OFFSET (GstDialogClass, lock_changed),
 			      NULL, NULL,
 			      g_cclosure_marshal_VOID__VOID,
 			      G_TYPE_NONE, 0);
@@ -234,7 +234,7 @@ gst_dialog_constructor (GType                  type,
 		gtk_box_pack_start (GTK_BOX (action_area), priv->polkit_button, TRUE, TRUE, 0);
 
 		g_signal_connect_swapped (priv->polkit_button, "changed",
-					  G_CALLBACK (gst_dialog_unlock), dialog);
+					  G_CALLBACK (gst_dialog_lock_changed), dialog);
 	}
 #endif
 
@@ -369,7 +369,7 @@ gst_dialog_get_widget (GstDialog *dialog, const char *widget)
 }
 
 static void
-gst_dialog_unlock (GstDialog *dialog)
+gst_dialog_lock_changed (GstDialog *dialog)
 {
 	GstDialogPrivate *priv;
 	GSList *list;
@@ -381,11 +381,15 @@ gst_dialog_unlock (GstDialog *dialog)
 		GstWidgetPolicy *policy;
 
 		widget = list->data;
-		policy = gst_dialog_get_policy_for_widget (widget);
-		gtk_widget_set_sensitive (widget, policy->was_sensitive);
+		if (gst_dialog_is_authenticated (dialog)) {
+			policy = gst_dialog_get_policy_for_widget (widget);
+			gtk_widget_set_sensitive (widget, policy->was_sensitive);
+		}
+		else
+			gtk_widget_set_sensitive (widget, FALSE);
 	}
 
-	g_signal_emit (dialog, signals [UNLOCKED], 0);
+	g_signal_emit (dialog, signals [LOCK_CHANGED], 0);
 }
 
 static void
diff --git a/src/common/gst-dialog.h b/src/common/gst-dialog.h
index fae067f..d3225b8 100644
--- a/src/common/gst-dialog.h
+++ b/src/common/gst-dialog.h
@@ -49,7 +49,7 @@ struct _GstDialog {
 struct _GstDialogClass {
 	GtkDialogClass parent_class;
 
-	void (* unlocked) (GstDialogClass *button);
+	void (* lock_changed) (GstDialogClass *button);
 };
 
 GType               gst_dialog_get_type            (void);
diff --git a/src/users/callbacks.c b/src/users/callbacks.c
index 5ee2d3c..5f1f262 100644
--- a/src/users/callbacks.c
+++ b/src/users/callbacks.c
@@ -37,30 +37,44 @@
 
 extern GstTool *tool;
 
-/* Unlock signal */
-
+/* PolkitLockButton state has changed, reflect this in the UI */
 void
-on_unlocked (GstDialog *dialog)
+on_lock_changed (GstDialog *dialog)
 {
 	GtkWidget *users_table;
 	GtkTreeModel *model, *store;
+	GtkTreeSelection *selection;
 	GtkTreeIter iter;
+	OobsUser *self, *user;
 	gboolean valid;
+	gboolean is_authenticated;
 
 	users_table = gst_dialog_get_widget (dialog, "users_table");
 
+	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (users_table));
 	model = gtk_tree_view_get_model (GTK_TREE_VIEW (users_table));
 	store = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
 
+	is_authenticated = gst_dialog_is_authenticated (tool->main_dialog);
+	self = oobs_self_config_get_user (OOBS_SELF_CONFIG (GST_USERS_TOOL (tool)->self_config));
+
 	valid = gtk_tree_model_get_iter_first (store, &iter);
 
 	while (valid) {
+		gtk_tree_model_get (store, &iter,
+				    COL_USER_OBJECT, &user,
+				    -1);
+
 		gtk_list_store_set (GTK_LIST_STORE (store), &iter,
-				    COL_USER_SENSITIVE, TRUE,
+				    COL_USER_SENSITIVE, is_authenticated | (user == self),
 				    -1);
 
+		g_object_unref (user);
 		valid = gtk_tree_model_iter_next (store, &iter);
 	}
+
+	/* Update the status depending on the selected user */
+	on_table_selection_changed (selection, NULL);
 }
 
 /* Common stuff to users and groups tables */
@@ -103,7 +117,7 @@ actions_set_sensitive (gint table, gint count, OobsUser *user)
 }
 
 void
-on_table_clicked (GtkTreeSelection *selection, gpointer data)
+on_table_selection_changed (GtkTreeSelection *selection, gpointer data)
 {
 	gint count, table;
 	gboolean active;
diff --git a/src/users/callbacks.h b/src/users/callbacks.h
index fea7f28..63f85e4 100644
--- a/src/users/callbacks.h
+++ b/src/users/callbacks.h
@@ -29,8 +29,8 @@
 #include "gst.h"
 
 /* Main dialog general callbacks */
-void      on_unlocked (GstDialog*);
-void      on_table_clicked (GtkTreeSelection*, gpointer);
+void      on_lock_changed  (GstDialog*);
+void      on_table_selection_changed (GtkTreeSelection*, gpointer);
 gboolean  on_table_button_press (GtkTreeView *treeview, GdkEventButton *event, gpointer gdata);
 gboolean  on_table_popup_menu   (GtkTreeView*, GtkWidget*);
 void      on_popup_add_activate (GtkAction*, gpointer);
diff --git a/src/users/groups-table.c b/src/users/groups-table.c
index 696bccb..eea670d 100644
--- a/src/users/groups-table.c
+++ b/src/users/groups-table.c
@@ -111,7 +111,7 @@ create_groups_table (void)
 				(GDestroyNotify) gtk_widget_destroy);
 
 	g_signal_connect (G_OBJECT (selection), "changed",
-			  G_CALLBACK (on_table_clicked),
+			  G_CALLBACK (on_table_selection_changed),
 			  GINT_TO_POINTER (TABLE_GROUPS));
 	g_signal_connect (G_OBJECT (groups_table), "button_press_event",
 			  G_CALLBACK (on_table_button_press),
diff --git a/src/users/main.c b/src/users/main.c
index c54cc76..371b7fa 100644
--- a/src/users/main.c
+++ b/src/users/main.c
@@ -60,7 +60,7 @@ static GstDialogSignal signals[] = {
 	{ "groups_dialog_help",                 "clicked",              G_CALLBACK (on_groups_dialog_show_help) },
 	{ NULL }};
 
-static const gchar *policy_widgets [] = {
+const gchar *policy_widgets [] = {
 	"user_new",
 	"user_delete",
 	"groups_table",
diff --git a/src/users/users-table.c b/src/users/users-table.c
index f2673bd..fffd2f7 100644
--- a/src/users/users-table.c
+++ b/src/users/users-table.c
@@ -146,7 +146,7 @@ create_users_table (GstUsersTool *tool)
 				(GDestroyNotify) gtk_widget_destroy);
 
 	g_signal_connect (G_OBJECT (selection), "changed",
-			  G_CALLBACK (on_table_clicked),
+			  G_CALLBACK (on_table_selection_changed),
 			  GINT_TO_POINTER (TABLE_USERS));
 	g_signal_connect (G_OBJECT (users_table), "button_press_event",
 			  G_CALLBACK (on_table_button_press),
diff --git a/src/users/users-table.h b/src/users/users-table.h
index 7198bf2..d5514a9 100644
--- a/src/users/users-table.h
+++ b/src/users/users-table.h
@@ -47,5 +47,9 @@ void    users_table_set_user    (OobsUser     *user,
 void    users_table_add_user    (OobsUser     *user,
 				 OobsListIter *list_iter);
 
+void    users_table_actions_set_sensitive (gint      table,
+					   gint      count,
+					   OobsUser *user);
+
 #endif /* _USERS_TABLE_H */
 
diff --git a/src/users/users-tool.c b/src/users/users-tool.c
index a825508..eea298e 100644
--- a/src/users/users-tool.c
+++ b/src/users/users-tool.c
@@ -107,8 +107,8 @@ gst_users_tool_constructor (GType                  type,
 	gst_conf_add_notify (GST_TOOL (tool), "showall",
 			     on_showall_changed, tool);
 
-	g_signal_connect (G_OBJECT (tool->main_dialog), "unlocked",
-			  G_CALLBACK (on_unlocked), NULL);
+	g_signal_connect (G_OBJECT (tool->main_dialog), "lock_changed",
+			  G_CALLBACK (on_lock_changed), NULL);
 
 	return object;
 }



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