[gnome-control-center/wip/networking2: 11/36] network: Listen for permission changes



commit 94eea02b380f9255534189f1cb4151073f2b4213
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Dec 14 22:42:34 2012 -0500

    network: Listen for permission changes
    
    Also, add a net_connection_editor_run() function to match the
    NMConnectionEditor api.

 .../network/connection-editor/connection-editor.ui |   13 ++--
 .../connection-editor/net-connection-editor.c      |   65 +++++++++++++++++---
 .../connection-editor/net-connection-editor.h      |    4 +
 panels/network/net-device-wifi.c                   |    2 +-
 4 files changed, 68 insertions(+), 16 deletions(-)
---
diff --git a/panels/network/connection-editor/connection-editor.ui b/panels/network/connection-editor/connection-editor.ui
index a8cb2d9..94562f5 100644
--- a/panels/network/connection-editor/connection-editor.ui
+++ b/panels/network/connection-editor/connection-editor.ui
@@ -17,12 +17,12 @@
     <property name="default_height">300</property>
     <property name="type_hint">dialog</property>
     <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox2">
+      <object class="GtkBox" id="dialog-vbox">
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
         <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area2">
+          <object class="GtkButtonBox" id="dialog-action_area">
             <property name="can_focus">False</property>
             <property name="valign">end</property>
             <property name="layout_style">end</property>
@@ -37,22 +37,21 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">2</property>
+                <property name="position">0</property>
               </packing>
             </child>
             <child>
               <object class="GtkButton" id="details_apply_button">
-                <property name="label">gtk-apply</property>
+                <property name="label" translatable="yes">_Apply</property>
                 <property name="visible">True</property>
-                <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
+                <property name="use_underline">True</property>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">3</property>
+                <property name="position">1</property>
               </packing>
             </child>
           </object>
diff --git a/panels/network/connection-editor/net-connection-editor.c b/panels/network/connection-editor/net-connection-editor.c
index f778e39..c2e0faf 100644
--- a/panels/network/connection-editor/net-connection-editor.c
+++ b/panels/network/connection-editor/net-connection-editor.c
@@ -107,9 +107,8 @@ apply_edits (NetConnectionEditor *editor)
 static void
 net_connection_editor_init (NetConnectionEditor *editor)
 {
-        GtkTreeSelection *selection;
         GError *error = NULL;
-        GtkWidget *button;
+        GtkTreeSelection *selection;
 
         editor->builder = gtk_builder_new ();
 
@@ -122,13 +121,17 @@ net_connection_editor_init (NetConnectionEditor *editor)
                 return;
         }
 
-        /* set up widgets */
-
         editor->window = GTK_WIDGET (gtk_builder_get_object (editor->builder, "details_dialog"));
         selection = GTK_TREE_SELECTION (gtk_builder_get_object (editor->builder,
                                                                 "details_page_list_selection"));
         g_signal_connect (selection, "changed",
                           G_CALLBACK (selection_changed), editor);
+}
+
+void
+net_connection_editor_run (NetConnectionEditor *editor)
+{
+        GtkWidget *button;
 
         button = GTK_WIDGET (gtk_builder_get_object (editor->builder, "details_cancel_button"));
         g_signal_connect_swapped (button, "clicked",
@@ -139,6 +142,8 @@ net_connection_editor_init (NetConnectionEditor *editor)
         button = GTK_WIDGET (gtk_builder_get_object (editor->builder, "details_apply_button"));
         g_signal_connect_swapped (button, "clicked",
                                   G_CALLBACK (apply_edits), editor);
+
+        net_connection_editor_present (editor);
 }
 
 static void
@@ -199,6 +204,31 @@ editor_is_initialized (NetConnectionEditor *editor)
 }
 
 static void
+update_sensitivity (NetConnectionEditor *editor)
+{
+        NMSettingConnection *sc;
+        gboolean sensitive;
+        GtkWidget *widget;
+        GSList *l;
+
+        if (!editor_is_initialized (editor))
+                return;
+
+        sc = nm_connection_get_setting_connection (editor->connection);
+
+        if (nm_setting_connection_get_read_only (sc)) {
+                sensitive = FALSE;
+        } else {
+                sensitive = editor->can_modify;
+        }
+
+        for (l = editor->pages; l; l = l->next) {
+                widget = ce_page_get_page (CE_PAGE (l->data));
+                gtk_widget_set_sensitive (widget, sensitive);
+        }
+}
+
+static void
 validate (NetConnectionEditor *editor)
 {
         gboolean valid = FALSE;
@@ -222,6 +252,7 @@ validate (NetConnectionEditor *editor)
                 }
         }
 
+        update_sensitivity (editor);
 done:
         gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (editor->builder, "details_apply_button")), valid);
 }
@@ -382,6 +413,23 @@ net_connection_editor_set_connection (NetConnectionEditor *editor,
         g_slist_free (pages);
 }
 
+static void
+permission_changed (NMClient                 *client,
+                    NMClientPermission        permission,
+                    NMClientPermissionResult  result,
+                    NetConnectionEditor      *editor)
+{
+        if (permission != NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM)
+                return;
+
+        if (result == NM_CLIENT_PERMISSION_RESULT_YES || result == NM_CLIENT_PERMISSION_RESULT_AUTH)
+                editor->can_modify = TRUE;
+        else
+                editor->can_modify = FALSE;
+
+        validate (editor);
+}
+
 NetConnectionEditor *
 net_connection_editor_new (GtkWindow        *parent_window,
                            NMConnection     *connection,
@@ -405,6 +453,10 @@ net_connection_editor_new (GtkWindow        *parent_window,
         editor->client = g_object_ref (client);
         editor->settings = g_object_ref (settings);
 
+        editor->can_modify = nm_client_get_permission_result (client, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM);
+        editor->permission_id = g_signal_connect (editor->client, "permission-changed",
+                                                  G_CALLBACK (permission_changed), editor);
+
         net_connection_editor_set_connection (editor, connection);
 
         return editor;
@@ -435,8 +487,5 @@ forgotten_cb (NMRemoteConnection *connection,
 void
 net_connection_editor_forget (NetConnectionEditor *editor)
 {
-        if (NM_IS_REMOTE_CONNECTION (editor->orig_connection))
-                nm_remote_connection_delete (NM_REMOTE_CONNECTION (editor->orig_connection), forgotten_cb, editor);
-        else
-                g_print ("why u no remote connection ?!\n");
+        nm_remote_connection_delete (NM_REMOTE_CONNECTION (editor->orig_connection), forgotten_cb, editor);
 }
diff --git a/panels/network/connection-editor/net-connection-editor.h b/panels/network/connection-editor/net-connection-editor.h
index 15f60f1..8a93dbe 100644
--- a/panels/network/connection-editor/net-connection-editor.h
+++ b/panels/network/connection-editor/net-connection-editor.h
@@ -59,6 +59,9 @@ struct _NetConnectionEditor
 
         GSList *initializing_pages;
         GSList *pages;
+
+        guint                    permission_id;
+        NMClientPermissionResult can_modify;
 };
 
 struct _NetConnectionEditorClass
@@ -75,6 +78,7 @@ NetConnectionEditor *net_connection_editor_new      (GtkWindow        *parent_wi
                                                      NMAccessPoint    *ap,
                                                      NMClient         *client,
                                                      NMRemoteSettings *settings);
+void                 net_connection_editor_run      (NetConnectionEditor   *editor);
 void                 net_connection_editor_present  (NetConnectionEditor   *editor);
 void                 net_connection_editor_forget   (NetConnectionEditor   *editor);
 
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index ca95e38..3e8549c 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -1696,7 +1696,7 @@ show_details_for_row (GtkButton *button, NetDeviceWifi *device_wifi)
         settings = net_object_get_remote_settings (NET_OBJECT (device_wifi));
         editor = net_connection_editor_new (GTK_WINDOW (window), connection, device, ap, client, settings);
         g_signal_connect (editor, "done", G_CALLBACK (editor_done), device_wifi);
-        net_connection_editor_present (editor);
+        net_connection_editor_run (editor);
 }
 
 static void



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