~ubuntu-branches/ubuntu/trusty/network-manager-applet/trusty-updates

« back to all changes in this revision

Viewing changes to .pc/11-user-connections.patch/src/connection-editor/page-wimax.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2014-03-18 14:48:18 UTC
  • Revision ID: package-import@ubuntu.com-20140318144818-iepmr37nqr0nzxup
Tags: 0.9.8.8-0ubuntu3
debian/patches/11-user-connections.patch: Allow users with access to modify
their own connection to create wireless connections without using
system-wide privileges. (LP: #1116317)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
 
2
/* NetworkManager Connection editor -- Connection editor for NetworkManager
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
17
 *
 
18
 * Copyright 2012 Red Hat, Inc.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <gtk/gtk.h>
 
24
#include <glib/gi18n.h>
 
25
 
 
26
#include <nm-setting-connection.h>
 
27
#include <nm-setting-wimax.h>
 
28
#include <nm-device-wimax.h>
 
29
#include <nm-utils.h>
 
30
 
 
31
#include "page-wimax.h"
 
32
 
 
33
G_DEFINE_TYPE (CEPageWimax, ce_page_wimax, CE_TYPE_PAGE)
 
34
 
 
35
#define CE_PAGE_WIMAX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CE_TYPE_PAGE_WIMAX, CEPageWimaxPrivate))
 
36
 
 
37
typedef struct {
 
38
        NMSettingWimax *setting;
 
39
 
 
40
        GtkEntry *name;
 
41
#if GTK_CHECK_VERSION (2,24,0)
 
42
        GtkComboBoxText *device_mac;  /* Permanent MAC of the device */
 
43
#else
 
44
        GtkComboBoxEntry *device_mac;
 
45
#endif
 
46
 
 
47
        gboolean disposed;
 
48
} CEPageWimaxPrivate;
 
49
 
 
50
static void
 
51
wimax_private_init (CEPageWimax *self)
 
52
{
 
53
        CEPageWimaxPrivate *priv = CE_PAGE_WIMAX_GET_PRIVATE (self);
 
54
        GtkBuilder *builder;
 
55
        GtkWidget *align;
 
56
        GtkLabel *label;
 
57
 
 
58
        builder = CE_PAGE (self)->builder;
 
59
 
 
60
        priv->name = GTK_ENTRY (gtk_builder_get_object (builder, "wimax_name"));
 
61
 
 
62
#if GTK_CHECK_VERSION(2,24,0)
 
63
        priv->device_mac = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new_with_entry ());
 
64
        gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (priv->device_mac), 0);
 
65
#else
 
66
        priv->device_mac = GTK_COMBO_BOX_ENTRY (gtk_combo_box_entry_new_text ());
 
67
        gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (priv->device_mac), 0);
 
68
#endif
 
69
        gtk_widget_set_tooltip_text (GTK_WIDGET (priv->device_mac),
 
70
                                     _("This option locks this connection to the network device specified by its permanent MAC address entered here.  Example: 00:11:22:33:44:55"));
 
71
 
 
72
        align = GTK_WIDGET (gtk_builder_get_object (builder, "wimax_device_mac_alignment"));
 
73
        gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (priv->device_mac));
 
74
        gtk_widget_show_all (GTK_WIDGET (priv->device_mac));
 
75
 
 
76
        /* Set mnemonic widget for device MAC label */
 
77
        label = GTK_LABEL (GTK_WIDGET (gtk_builder_get_object (builder, "wimax_device_mac_label")));
 
78
        gtk_label_set_mnemonic_widget (label, GTK_WIDGET (priv->device_mac));
 
79
}
 
80
 
 
81
static void
 
82
populate_ui (CEPageWimax *self)
 
83
{
 
84
        CEPageWimaxPrivate *priv = CE_PAGE_WIMAX_GET_PRIVATE (self);
 
85
        NMSettingWimax *setting = priv->setting;
 
86
        char **mac_list;
 
87
        const GByteArray *s_mac;
 
88
        char *s_mac_str;
 
89
 
 
90
        gtk_entry_set_text (priv->name, nm_setting_wimax_get_network_name (setting));
 
91
        g_signal_connect_swapped (priv->name, "changed", G_CALLBACK (ce_page_changed), self);
 
92
 
 
93
        /* Device MAC address */
 
94
        mac_list = ce_page_get_mac_list (CE_PAGE (self), NM_TYPE_DEVICE_WIMAX,
 
95
                                         NM_DEVICE_WIMAX_HW_ADDRESS);
 
96
        s_mac = nm_setting_wimax_get_mac_address (setting);
 
97
        s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : NULL;
 
98
        ce_page_setup_mac_combo (CE_PAGE (self), GTK_COMBO_BOX (priv->device_mac),
 
99
                                 s_mac_str, mac_list);
 
100
        g_free (s_mac_str);
 
101
        g_strfreev (mac_list);
 
102
        g_signal_connect_swapped (priv->device_mac, "changed", G_CALLBACK (ce_page_changed), self);
 
103
}
 
104
 
 
105
static void
 
106
finish_setup (CEPageWimax *self, gpointer unused, GError *error, gpointer user_data)
 
107
{
 
108
        if (error)
 
109
                return;
 
110
 
 
111
        populate_ui (self);
 
112
}
 
113
 
 
114
CEPage *
 
115
ce_page_wimax_new (NMConnection *connection,
 
116
                   GtkWindow *parent_window,
 
117
                   NMClient *client,
 
118
                   NMRemoteSettings *settings,
 
119
                   const char **out_secrets_setting_name,
 
120
                   GError **error)
 
121
{
 
122
        CEPageWimax *self;
 
123
        CEPageWimaxPrivate *priv;
 
124
 
 
125
        g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
 
126
 
 
127
        self = CE_PAGE_WIMAX (ce_page_new (CE_TYPE_PAGE_WIMAX,
 
128
                                           connection,
 
129
                                           parent_window,
 
130
                                           client,
 
131
                                           settings,
 
132
                                           UIDIR "/ce-page-wimax.ui",
 
133
                                           "WimaxPage",
 
134
                                           _("WiMAX")));
 
135
        if (!self) {
 
136
                g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC,
 
137
                                     _("Could not load WiMAX user interface."));
 
138
                return NULL;
 
139
        }
 
140
 
 
141
        wimax_private_init (self);
 
142
        priv = CE_PAGE_WIMAX_GET_PRIVATE (self);
 
143
 
 
144
        priv->setting = nm_connection_get_setting_wimax (connection);
 
145
        if (!priv->setting) {
 
146
                priv->setting = NM_SETTING_WIMAX (nm_setting_wimax_new ());
 
147
                nm_connection_add_setting (connection, NM_SETTING (priv->setting));
 
148
        }
 
149
 
 
150
        g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL);
 
151
 
 
152
        return CE_PAGE (self);
 
153
}
 
154
 
 
155
static void
 
156
ui_to_setting (CEPageWimax *self)
 
157
{
 
158
        CEPageWimaxPrivate *priv = CE_PAGE_WIMAX_GET_PRIVATE (self);
 
159
        const char *name;
 
160
        GByteArray *device_mac = NULL;
 
161
        GtkWidget *entry;
 
162
 
 
163
        name = gtk_entry_get_text (priv->name);
 
164
 
 
165
        entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
 
166
        if (entry)
 
167
                device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL);
 
168
 
 
169
        g_object_set (priv->setting,
 
170
                      NM_SETTING_WIMAX_NETWORK_NAME, name,
 
171
                      NM_SETTING_WIMAX_MAC_ADDRESS, device_mac,
 
172
                      NULL);
 
173
 
 
174
        if (device_mac)
 
175
                g_byte_array_free (device_mac, TRUE);
 
176
}
 
177
 
 
178
static gboolean
 
179
validate (CEPage *page, NMConnection *connection, GError **error)
 
180
{
 
181
        CEPageWimax *self = CE_PAGE_WIMAX (page);
 
182
        CEPageWimaxPrivate *priv = CE_PAGE_WIMAX_GET_PRIVATE (self);
 
183
        const char *name;
 
184
        gboolean invalid = FALSE;
 
185
        GByteArray *ignore;
 
186
        GtkWidget *entry;
 
187
 
 
188
        name = gtk_entry_get_text (priv->name);
 
189
        if (!*name)
 
190
                return FALSE;
 
191
 
 
192
        entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
 
193
        if (entry) {
 
194
                ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid);
 
195
                if (invalid)
 
196
                        return FALSE;
 
197
                if (ignore)
 
198
                        g_byte_array_free (ignore, TRUE);
 
199
        }
 
200
 
 
201
        ui_to_setting (self);
 
202
        return TRUE;
 
203
}
 
204
 
 
205
static void
 
206
ce_page_wimax_init (CEPageWimax *self)
 
207
{
 
208
}
 
209
 
 
210
static void
 
211
ce_page_wimax_class_init (CEPageWimaxClass *wimax_class)
 
212
{
 
213
        GObjectClass *object_class = G_OBJECT_CLASS (wimax_class);
 
214
        CEPageClass *parent_class = CE_PAGE_CLASS (wimax_class);
 
215
 
 
216
        g_type_class_add_private (object_class, sizeof (CEPageWimaxPrivate));
 
217
 
 
218
        /* virtual methods */
 
219
        parent_class->validate = validate;
 
220
}
 
221
 
 
222
 
 
223
void
 
224
wimax_connection_new (GtkWindow *parent,
 
225
                      const char *detail,
 
226
                      NMRemoteSettings *settings,
 
227
                      PageNewConnectionResultFunc result_func,
 
228
                      gpointer user_data)
 
229
{
 
230
        NMConnection *connection;
 
231
        NMSetting *s_wimax;
 
232
 
 
233
        connection = ce_page_new_connection (_("WiMAX connection %d"),
 
234
                                             NM_SETTING_WIMAX_SETTING_NAME,
 
235
                                             TRUE,
 
236
                                             settings,
 
237
                                             user_data);
 
238
        s_wimax = nm_setting_wimax_new ();
 
239
        nm_connection_add_setting (connection, s_wimax);
 
240
 
 
241
        (*result_func) (connection, FALSE, NULL, user_data);
 
242
}
 
243
 
 
244