[gnome-system-tools/users-ui-redesign] Add a "lock-button" property to GstDialog and GstTool



commit e5fc61011d220f3b1274b32a1282d8e1d4e48738
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Mon Nov 30 19:46:09 2009 +0100

    Add a "lock-button" property to GstDialog and GstTool
    
    This GObject boolean property determines whether the PolkitLockButton will be created and added to the action area of the main dialog. It is used on creation by GstUsersTool, since users-admin now directly triggers authentication on commit. Other tools could follow in that direction.

 src/common/gst-dialog.c |   31 ++++++++++++++++++++++++-------
 src/common/gst-dialog.h |    3 ++-
 src/common/gst-tool.c   |   16 ++++++++++++++--
 src/common/gst-tool.h   |    1 +
 src/users/users-tool.c  |    1 +
 5 files changed, 42 insertions(+), 10 deletions(-)
---
diff --git a/src/common/gst-dialog.c b/src/common/gst-dialog.c
index 13d9692..ebf2641 100644
--- a/src/common/gst-dialog.c
+++ b/src/common/gst-dialog.c
@@ -44,6 +44,7 @@ struct _GstDialogPrivate {
 
 	gchar   *title;
 	gchar   *widget_name;
+	gboolean lock_button;
 
 	GtkBuilder *builder;
 	GtkWidget  *child;
@@ -95,7 +96,8 @@ enum {
 	PROP_0,
 	PROP_TOOL,
 	PROP_WIDGET_NAME,
-	PROP_TITLE
+	PROP_TITLE,
+	PROP_LOCK_BUTTON
 };
 
 enum {
@@ -146,6 +148,14 @@ gst_dialog_class_init (GstDialogClass *class)
 							      NULL,
 							      G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
 
+	g_object_class_install_property (object_class,
+					 PROP_LOCK_BUTTON,
+					 g_param_spec_boolean ("lock_button",
+					                       "Lock button",
+					                       "Show PolkitLockButton",
+					                       TRUE,
+					                       G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+
 	signals [LOCK_CHANGED] =
 		g_signal_new ("lock-changed",
 			      G_OBJECT_CLASS_TYPE (object_class),
@@ -227,12 +237,15 @@ gst_dialog_constructor (GType                  type,
 		const gchar *action;
 		GtkWidget *action_area;
 
-		action = oobs_session_get_authentication_action (priv->tool->session);
-		priv->polkit_button = polkit_lock_button_new (action);
-		gtk_widget_show (priv->polkit_button);
+		/* Some tools don't use the lock button at all */
+		if (priv->lock_button) {
+			action = oobs_session_get_authentication_action (priv->tool->session);
+			priv->polkit_button = polkit_lock_button_new (action);
 
-		action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
-		gtk_box_pack_start (GTK_BOX (action_area), priv->polkit_button, TRUE, TRUE, 0);
+			action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
+			gtk_box_pack_start (GTK_BOX (action_area), priv->polkit_button, TRUE, TRUE, 0);
+			gtk_widget_show (priv->polkit_button);
+		}
 
 		g_signal_connect_swapped (priv->polkit_button, "changed",
 					  G_CALLBACK (gst_dialog_lock_changed), dialog);
@@ -270,6 +283,9 @@ gst_dialog_set_property (GObject      *object,
 	case PROP_TITLE:
 		priv->title = g_value_dup_string (value);
 		break;
+	case PROP_LOCK_BUTTON:
+		priv->lock_button = g_value_get_boolean (value);
+		break;
 	}
 }
 
@@ -338,13 +354,14 @@ gst_dialog_delete_event (GtkWidget   *widget,
 }
 
 GstDialog*
-gst_dialog_new (GstTool *tool, const char *widget, const char *title)
+gst_dialog_new (GstTool *tool, const char *widget, const char *title, gboolean lock_button)
 {
 	return g_object_new (GST_TYPE_DIALOG,
 			     "has-separator", FALSE,
 			     "tool", tool,
 			     "widget-name", widget,
 			     "title", title,
+	                     "lock-button", lock_button,
 			     NULL);
 }
 
diff --git a/src/common/gst-dialog.h b/src/common/gst-dialog.h
index d3225b8..219f4fe 100644
--- a/src/common/gst-dialog.h
+++ b/src/common/gst-dialog.h
@@ -56,7 +56,8 @@ GType               gst_dialog_get_type            (void);
 
 GstDialog          *gst_dialog_new                 (GstTool *tool, 
 						    const char *widget, 
-						    const char *title);
+						    const char *title,
+						    gboolean    lock_button);
 
 void                gst_dialog_connect_signals     (GstDialog *xd, GstDialogSignal *signals);
 void                gst_dialog_connect_signals_after (GstDialog *xd, GstDialogSignal *signals);
diff --git a/src/common/gst-tool.c b/src/common/gst-tool.c
index 68785e3..46d84ea 100644
--- a/src/common/gst-tool.c
+++ b/src/common/gst-tool.c
@@ -64,7 +64,8 @@ enum {
 	PROP_0,
 	PROP_NAME,
 	PROP_TITLE,
-	PROP_ICON
+	PROP_ICON,
+	PROP_LOCK_BUTTON
 };
 
 typedef struct _GstAsyncData {
@@ -109,6 +110,14 @@ gst_tool_class_init (GstToolClass *class)
 							      "Tool icon",
 							      NULL,
 							      G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+
+	g_object_class_install_property (object_class,
+					 PROP_LOCK_BUTTON,
+					 g_param_spec_boolean ("lock_button",
+					                       "Lock button",
+					                       "Show PolkitLockButton",
+					                       TRUE,
+					                       G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
 }
 
 static gboolean
@@ -231,7 +240,7 @@ gst_tool_constructor (GType                  type,
 		tool->ui_path = g_strdup_printf (INTERFACES_DIR "/%s.ui", tool->name);
 
 		widget_name = g_strdup_printf ("%s_admin", tool->name);
-		tool->main_dialog = gst_dialog_new (tool, widget_name, tool->title);
+		tool->main_dialog = gst_dialog_new (tool, widget_name, tool->title, tool->lock_button);
 		g_free (widget_name);
 	}
 
@@ -269,6 +278,9 @@ gst_tool_set_property (GObject      *object,
 	case PROP_ICON:
 		tool->icon = g_value_dup_string (value);
 		break;
+	case PROP_LOCK_BUTTON:
+		tool->lock_button = g_value_get_boolean (value);
+		break;
 	}
 }
 
diff --git a/src/common/gst-tool.h b/src/common/gst-tool.h
index 1f1f7f2..2845621 100644
--- a/src/common/gst-tool.h
+++ b/src/common/gst-tool.h
@@ -48,6 +48,7 @@ struct _GstTool {
 	gchar *name;
 	gchar *title;
 	gchar *icon;
+	gboolean lock_button;
 
 	OobsSession *session;
 	GPtrArray   *objects;
diff --git a/src/users/users-tool.c b/src/users/users-tool.c
index 94ceeda..468b02c 100644
--- a/src/users/users-tool.c
+++ b/src/users/users-tool.c
@@ -231,5 +231,6 @@ gst_users_tool_new (void)
 			     "name", "users",
 			     "title", _("Users Settings"),
 			     "icon", "config-users",
+	                     "lock-button", FALSE,
 			     NULL);
 }



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