~vcs-imports/network-manager-applet/trunk

« back to all changes in this revision

Viewing changes to src/connection-editor/page-wired-security.c

  • Committer: dcbw
  • Date: 2009-04-03 13:28:12 UTC
  • Revision ID: vcs-imports@canonical.com-20090403132812-u8nztkdrskz0mxp1
2009-04-03  Dan Williams  <dcbw@redhat.com>

        * Ensure PolicyKit autorization before editing system connections, and
                request secrets from the system settings service for system connections.
                This requires splitting each CEPage subclass's *_new() method into
                two parts, the first doing minimal setup, and the second filling in
                the UI with details from the backing NMConnection.  Between the first
                and second parts, if required, secrets are requested from the system
                settings service using PolicyKit.  As a bonus, actually handle errors
                instead of dropping them on the floor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        GtkWidget *security_widget;
48
48
        WirelessSecurity *security;
49
49
 
 
50
        gboolean initial_have_8021x;
 
51
 
50
52
        gboolean disposed;
51
53
} CEPageWiredSecurityPrivate;
52
54
 
65
67
        ce_page_changed (CE_PAGE (user_data));
66
68
}
67
69
 
68
 
CEPageWiredSecurity *
69
 
ce_page_wired_security_new (NMConnection *connection)
 
70
static void
 
71
finish_setup (CEPageWiredSecurity *self, gpointer unused, GError *error, gpointer user_data)
 
72
{
 
73
        CEPage *parent = CE_PAGE (self);
 
74
        CEPageWiredSecurityPrivate *priv = CE_PAGE_WIRED_SECURITY_GET_PRIVATE (self);
 
75
        const char *glade_file = GLADEDIR "/applet.glade";
 
76
 
 
77
        if (error)
 
78
                return;
 
79
 
 
80
        priv->security = (WirelessSecurity *) ws_wpa_eap_new (glade_file, parent->connection);
 
81
        if (!priv->security) {
 
82
                g_warning ("Could not load wired 802.1x user interface.");
 
83
                return;
 
84
        }
 
85
 
 
86
        wireless_security_set_changed_notify (priv->security, stuff_changed, self);
 
87
        priv->security_widget = wireless_security_get_widget (priv->security);
 
88
 
 
89
        gtk_toggle_button_set_active (priv->enabled, priv->initial_have_8021x);
 
90
        g_signal_connect_swapped (priv->enabled, "toggled", G_CALLBACK (ce_page_changed), self);
 
91
        gtk_widget_set_sensitive (priv->security_widget, priv->initial_have_8021x);
 
92
 
 
93
        gtk_box_pack_start (GTK_BOX (parent->page), GTK_WIDGET (priv->enabled), FALSE, TRUE, 12);
 
94
        gtk_box_pack_start (GTK_BOX (parent->page), priv->security_widget, TRUE, TRUE, 0);
 
95
        gtk_widget_show_all (parent->page);
 
96
}
 
97
 
 
98
CEPage *
 
99
ce_page_wired_security_new (NMConnection *connection, GtkWindow *parent_window, GError **error)
70
100
{
71
101
        CEPageWiredSecurity *self;
72
102
        CEPage *parent;
73
103
        CEPageWiredSecurityPrivate *priv;
74
 
        const char *glade_file = GLADEDIR "/applet.glade";
75
 
        NMSetting *setting;
76
104
 
77
 
        self = CE_PAGE_WIRED_SECURITY (g_object_new (CE_TYPE_PAGE_WIRED_SECURITY, NULL));
 
105
        self = CE_PAGE_WIRED_SECURITY (g_object_new (CE_TYPE_PAGE_WIRED_SECURITY,
 
106
                                                     CE_PAGE_CONNECTION, connection,
 
107
                                                     CE_PAGE_PARENT_WINDOW, parent_window,
 
108
                                                     NULL));
78
109
        parent = CE_PAGE (self);
79
110
        priv = CE_PAGE_WIRED_SECURITY_GET_PRIVATE (self);
80
111
 
81
112
        parent->title = g_strdup (_("802.1x Security"));
82
113
        parent->page = gtk_vbox_new (FALSE, 6);
 
114
        g_object_ref_sink (G_OBJECT (parent->page));
83
115
        gtk_container_set_border_width (GTK_CONTAINER (parent->page), 6);
84
116
 
85
 
        setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X);
86
 
 
87
 
        priv->security = (WirelessSecurity *) ws_wpa_eap_new (glade_file, connection);
88
 
        wireless_security_set_changed_notify (priv->security, stuff_changed, self);
89
 
        priv->security_widget = wireless_security_get_widget (priv->security);
 
117
        if (nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X))
 
118
                priv->initial_have_8021x = TRUE;
90
119
 
91
120
        priv->enabled = GTK_TOGGLE_BUTTON (gtk_check_button_new_with_label (_("Use 802.1X security for this connection")));
92
121
        g_signal_connect (priv->enabled, "toggled",
93
122
                                          G_CALLBACK (enable_toggled), self);
94
123
 
95
 
        gtk_toggle_button_set_active (priv->enabled, setting != NULL);
96
 
        g_signal_connect_swapped (priv->enabled, "toggled", G_CALLBACK (ce_page_changed), self);
97
 
        gtk_widget_set_sensitive (priv->security_widget, setting != NULL);
98
 
 
99
 
        gtk_box_pack_start (GTK_BOX (parent->page), GTK_WIDGET (priv->enabled), FALSE, TRUE, 12);
100
 
        gtk_box_pack_start (GTK_BOX (parent->page), priv->security_widget, TRUE, TRUE, 0);
101
 
        g_object_ref_sink (parent->page);
102
 
        gtk_widget_show_all (parent->page);
103
 
 
104
 
        return self;
 
124
        g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL);
 
125
        if (!ce_page_initialize (parent, NM_SETTING_802_1X_SETTING_NAME, error)) {
 
126
                g_object_unref (self);
 
127
                return NULL;
 
128
        }
 
129
 
 
130
        return CE_PAGE (self);
105
131
}
106
132
 
107
133
static gboolean
152
178
                return;
153
179
 
154
180
        priv->disposed = TRUE;
155
 
        wireless_security_unref (priv->security);
 
181
 
 
182
        if (priv->security)
 
183
                wireless_security_unref (priv->security);
156
184
 
157
185
        G_OBJECT_CLASS (ce_page_wired_security_parent_class)->dispose (object);
158
186
}