network-manager-applet r967 - in trunk: . src/connection-editor
- From: dcbw svn gnome org
- To: svn-commits-list gnome org
- Subject: network-manager-applet r967 - in trunk: . src/connection-editor
- Date: Fri, 24 Oct 2008 21:24:48 +0000 (UTC)
Author: dcbw
Date: Fri Oct 24 21:24:47 2008
New Revision: 967
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=967&view=rev
Log:
2008-10-24 Dan Williams <dcbw redhat com>
* src/connection-editor/nm-connection-editor.c
src/connection-editor/nm-connection-editor.h
src/connection-editor/nm-connection-editor.glade
- Improve PolicyKit auth to only ask once, and to sensitize/desensitize
the dialog dynamically based on what the user can and cannot do for
the given connection scope
Modified:
trunk/ChangeLog
trunk/src/connection-editor/nm-connection-editor.c
trunk/src/connection-editor/nm-connection-editor.glade
trunk/src/connection-editor/nm-connection-editor.h
Modified: trunk/src/connection-editor/nm-connection-editor.c
==============================================================================
--- trunk/src/connection-editor/nm-connection-editor.c (original)
+++ trunk/src/connection-editor/nm-connection-editor.c Fri Oct 24 21:24:47 2008
@@ -124,7 +124,7 @@
autoconnect = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_AUTOCONNECT, autoconnect, NULL);
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->system_button)))
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->system_checkbutton)))
nm_connection_set_scope (editor->connection, NM_CONNECTION_SCOPE_SYSTEM);
else
nm_connection_set_scope (editor->connection, NM_CONNECTION_SCOPE_USER);
@@ -158,14 +158,106 @@
valid = TRUE;
done:
- gtk_widget_set_sensitive (editor->ok_button, valid);
+ g_object_set (editor->system_gnome_action, "master-sensitive", valid, NULL);
+}
+
+static void
+system_checkbutton_toggled_cb (GtkWidget *widget, NMConnectionEditor *editor)
+{
+ gboolean req_privs = FALSE;
+
+ /* If the connection was originally a system connection, obviously
+ * privileges are required to change it. If it was originally a user
+ * connection, but the user requests that it be changed to a system
+ * connection, privileges are also required.
+ */
+
+ if (editor->orig_scope == NM_CONNECTION_SCOPE_USER) {
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
+ req_privs = TRUE;
+ } else
+ req_privs = TRUE;
+
+ if (req_privs)
+ g_object_set (editor->system_gnome_action, "polkit-action", editor->system_action, NULL);
+ else
+ g_object_set (editor->system_gnome_action, "polkit-action", NULL, NULL);
+
+ connection_editor_validate (editor);
+}
+
+static void
+set_editor_sensitivity (NMConnectionEditor *editor, gboolean sensitive)
+{
+ GtkWidget *widget;
+ GSList *iter;
+
+ /* Cancel button is always sensitive */
+ gtk_widget_set_sensitive (GTK_WIDGET (editor->cancel_button), TRUE);
+
+ widget = glade_xml_get_widget (editor->xml, "connection_name_label");
+ gtk_widget_set_sensitive (widget, sensitive);
+
+ widget = glade_xml_get_widget (editor->xml, "connection_name");
+ gtk_widget_set_sensitive (widget, sensitive);
+
+ widget = glade_xml_get_widget (editor->xml, "connection_autoconnect");
+ gtk_widget_set_sensitive (widget, sensitive);
+
+ widget = glade_xml_get_widget (editor->xml, "connection_name");
+ gtk_widget_set_sensitive (widget, sensitive);
+
+ gtk_widget_set_sensitive (GTK_WIDGET (editor->system_checkbutton), sensitive);
+
+ for (iter = editor->pages; iter; iter = g_slist_next (iter)) {
+ widget = ce_page_get_page (CE_PAGE (iter->data));
+ gtk_widget_set_sensitive (widget, sensitive);
+ }
+}
+
+static void
+update_sensitivity (NMConnectionEditor *editor, PolKitResult pk_result)
+{
+ gboolean denied = FALSE;
+
+ if (pk_result == POLKIT_RESULT_UNKNOWN)
+ pk_result = polkit_gnome_action_get_polkit_result (editor->system_gnome_action);
+
+ if (pk_result == POLKIT_RESULT_NO || pk_result == POLKIT_RESULT_UNKNOWN)
+ denied = TRUE;
+
+ switch (editor->orig_scope) {
+ case NM_CONNECTION_SCOPE_SYSTEM:
+ /* If the user cannot ever be authorized to change system connections, and
+ * the connection is a system connection, we desensitize the entire dialog.
+ */
+ set_editor_sensitivity (editor, !denied);
+ break;
+ default:
+ /* If the user cannot ever be authorized to change system connections, and
+ * the connection is a user connection, we desensitize system_checkbutton.
+ */
+ set_editor_sensitivity (editor, TRUE);
+ if (denied)
+ gtk_widget_set_sensitive (GTK_WIDGET (editor->system_checkbutton), FALSE);
+ break;
+ }
+}
+
+static void
+system_pk_result_changed_cb (PolKitGnomeAction *gnome_action,
+ PolKitResult result,
+ NMConnectionEditor *editor)
+{
+ update_sensitivity (editor, result);
}
static void
nm_connection_editor_init (NMConnectionEditor *editor)
{
- GtkWidget *dialog;
- PolKitAction *pk_action;
+ GtkWidget *dialog, *hbox;
+ const char *auth_label, *auth_tooltip;
+ const char *label, *tooltip;
/* Yes, we mean applet.glade, not nm-connection-editor.glade. The wireless security bits
are taken from applet.glade. */
@@ -195,23 +287,62 @@
}
editor->window = glade_xml_get_widget (editor->xml, "nm-connection-editor");
- editor->ok_button = glade_xml_get_widget (editor->xml, "ok_button");
editor->cancel_button = glade_xml_get_widget (editor->xml, "cancel_button");
gtk_window_set_default_icon_name ("preferences-system-network");
- editor->pages = NULL;
+ editor->system_checkbutton = glade_xml_get_widget (editor->xml, "system_checkbutton");
+
+ editor->system_action = polkit_action_new ();
+ polkit_action_set_action_id (editor->system_action, "org.freedesktop.network-manager-settings.system.modify");
+
+ editor->system_gnome_action = polkit_gnome_action_new ("system");
- pk_action = polkit_action_new ();
- polkit_action_set_action_id (pk_action, "org.freedesktop.network-manager-settings.system.modify");
- editor->system_action = polkit_gnome_toggle_action_new_default ("system", pk_action,
- _("Available to everyone..."),
- _("Available to everyone"));
- polkit_action_unref (pk_action);
-
- editor->system_button = glade_xml_get_widget (editor->xml, "system_checkbutton");
- gtk_action_connect_proxy (GTK_ACTION (editor->system_action), editor->system_button);
- g_signal_connect_swapped (editor->system_button, "toggled", G_CALLBACK (connection_editor_validate), editor);
+ auth_label = _("Apply...");
+ auth_tooltip = _("Authenticate to save this connection for all users of this machine.");
+ label = _("Apply");
+ tooltip = _("Save this connection for all users of this machine.");
+ g_object_set (editor->system_gnome_action,
+ "polkit-action", NULL,
+
+ "self-blocked-visible", TRUE,
+ "self-blocked-sensitive", FALSE,
+ "self-blocked-short-label", label,
+ "self-blocked-label", label,
+ "self-blocked-tooltip", tooltip,
+ "self-blocked-icon-name", GTK_STOCK_APPLY,
+
+ "no-visible", TRUE,
+ "no-sensitive", FALSE,
+ "no-short-label", label,
+ "no-label", label,
+ "no-tooltip", tooltip,
+ "no-icon-name", GTK_STOCK_APPLY,
+
+ "auth-visible", TRUE,
+ "auth-sensitive", TRUE,
+ "auth-short-label", auth_label,
+ "auth-label", auth_label,
+ "auth-tooltip", auth_tooltip,
+ "auth-icon-name", GTK_STOCK_DIALOG_AUTHENTICATION,
+
+ "yes-visible", TRUE,
+ "yes-sensitive", TRUE,
+ "yes-short-label", label,
+ "yes-label", label,
+ "yes-tooltip", tooltip,
+ "yes-icon-name", GTK_STOCK_APPLY,
+
+ "master-visible", TRUE,
+ "master-sensitive", TRUE,
+ NULL);
+ g_signal_connect (editor->system_gnome_action, "polkit-result-changed",
+ G_CALLBACK (system_pk_result_changed_cb), editor);
+
+
+ editor->ok_button = polkit_gnome_action_create_button (editor->system_gnome_action);
+ hbox = glade_xml_get_widget (editor->xml, "action_area_hbox");
+ gtk_box_pack_end (GTK_BOX (hbox), editor->ok_button, TRUE, TRUE, 0);
}
static void
@@ -231,7 +362,8 @@
gtk_widget_destroy (editor->window);
g_object_unref (editor->xml);
- g_object_unref (editor->system_action);
+ polkit_action_unref (editor->system_action);
+ g_object_unref (editor->system_gnome_action);
G_OBJECT_CLASS (nm_connection_editor_parent_class)->dispose (object);
}
@@ -296,6 +428,12 @@
g_signal_connect_swapped (name, "changed", G_CALLBACK (connection_editor_validate), editor);
g_signal_connect_swapped (autoconnect, "toggled", G_CALLBACK (connection_editor_validate), editor);
+ g_signal_connect (editor->system_checkbutton, "toggled", G_CALLBACK (system_checkbutton_toggled_cb), editor);
+
+ if (editor->orig_scope == NM_CONNECTION_SCOPE_SYSTEM)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->system_checkbutton), TRUE);
+
+ update_sensitivity (editor, POLKIT_RESULT_UNKNOWN);
}
static void
@@ -341,15 +479,7 @@
g_object_unref (editor->connection);
editor->connection = g_object_ref (connection);
- if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
- gtk_action_block_activate_from (GTK_ACTION (editor->system_action), editor->system_button);
- g_signal_handlers_block_by_func (editor->system_button, connection_editor_validate, editor);
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->system_button), TRUE);
-
- g_signal_handlers_unblock_by_func (editor->system_button, connection_editor_validate, editor);
- gtk_action_unblock_activate_from (GTK_ACTION (editor->system_action), editor->system_button);
- }
+ editor->orig_scope = nm_connection_get_scope (connection);
nm_connection_editor_update_title (editor);
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (editor->connection, NM_TYPE_SETTING_CONNECTION));
Modified: trunk/src/connection-editor/nm-connection-editor.glade
==============================================================================
--- trunk/src/connection-editor/nm-connection-editor.glade (original)
+++ trunk/src/connection-editor/nm-connection-editor.glade Fri Oct 24 21:24:47 2008
@@ -535,7 +535,7 @@
<property name="visible">True</property>
<property name="spacing">12</property>
<child>
- <widget class="GtkLabel" id="label1">
+ <widget class="GtkLabel" id="connection_name_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Connection _name:</property>
<property name="use_underline">True</property>
@@ -600,7 +600,7 @@
<widget class="GtkCheckButton" id="system_checkbutton">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="label" translatable="yes">Available to all users...</property>
+ <property name="label" translatable="yes">Available to all users</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
@@ -612,7 +612,7 @@
</packing>
</child>
<child>
- <widget class="GtkHButtonBox" id="hbuttonbox2">
+ <widget class="GtkHButtonBox" id="action_area_hbox">
<property name="visible">True</property>
<property name="spacing">6</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
@@ -627,17 +627,7 @@
</widget>
</child>
<child>
- <widget class="GtkButton" id="ok_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="label" translatable="yes">gtk-ok</property>
- <property name="use_stock">True</property>
- <property name="response_id">0</property>
- </widget>
- <packing>
- <property name="position">1</property>
- </packing>
+ <placeholder/>
</child>
</widget>
<packing>
Modified: trunk/src/connection-editor/nm-connection-editor.h
==============================================================================
--- trunk/src/connection-editor/nm-connection-editor.h (original)
+++ trunk/src/connection-editor/nm-connection-editor.h Fri Oct 24 21:24:47 2008
@@ -42,8 +42,11 @@
/* private data */
NMConnection *connection;
- PolKitGnomeToggleAction *system_action;
- GtkWidget *system_button;
+ NMConnectionScope orig_scope;
+ PolKitAction *system_action;
+ PolKitGnomeAction *system_gnome_action;
+
+ GtkWidget *system_checkbutton;
GSList *pages;
GladeXML *xml;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]