~ubuntu-branches/ubuntu/saucy/gnome-control-center/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/deal_with_null_ssid.patch/panels/network/cc-network-panel.c

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher, Sebastien Bacher, Robert Ancell, Iain Lane, Edward Donovan, Rico Tzschichholz, Jeremy Bicha, David Henningsson
  • Date: 2012-11-21 19:32:45 UTC
  • mfrom: (1.1.63)
  • Revision ID: package-import@ubuntu.com-20121121193245-mj61nzz1z4fk3z25
Tags: 1:3.6.3-0ubuntu1
[ Sebastien Bacher ]
* New upstream version
* debian/control.in: recommends libcanberra-pulse (lp: #1004973)
* debian/patches/58_ubuntu_icon_views_redesign.patch:
  - drop most of the changes, keep the different grid size though
    to fit on screen with our extra icons
* debian/patches/91_dont_show_in_unity.patch:
  - dropped, show the upstream printer panel and the layout tab
* debian/patches/revert_git_keyboard_gsettings.patch,
  debian/patches/revert_git_stop_using_gconf.patch:
  - dropped the gconf->gsettings reverts

[ Robert Ancell ]
* New upstream release (LP: #1010317)
* debian/control:
  - Bump build-depends on libgnome-desktop-3-dev, libwacom-dev
  - Add build-depends on libclutter-1.0-dev, libclutter-gtk-1.0-dev,
    libpwquality-dev
  - Drop build-depends on libgnomekbd-dev
* debian/patches/60_ubuntu_nav_bar.patch:
  - Disabled for now, doesn't apply
* debian/patches/revert_ua_gsettings.patch:
  - We can use GSettings for universal access now
* debian/patches/00git_online_accounts_gtkgrid.patch:
* debian/patches/00git_online_accounts_layout.part:
* debian/patches/git_wacom_translations.patch:
  - Applied upstream

[ Iain Lane ]
* Add Build-Depends on libxkbfile-dev
* New upstream release.
* Refresh all patches to apply cleanly.

[ Edward Donovan ]
* debian/source_gnome-control-center.py: Fix for Python 3. (LP: #1013171)

[ Rico Tzschichholz ]
* debian/control.in:
  - Build-depend on gtk-doc-tools instead of docbook directly
  - Bump minimum glib-2.0, gnome-desktop3, gnome-settings-daemon
     and gsettings-desktop-schemas

[ Jeremy Bicha ]
* Dropped more patches applied in new version:
  - git_unmute_sound_event.patch
  - git_fix_big_editable_labels.patch
  - 96_sound_nua_panel.patch
* debian/patches/04_new_appearance_settings.patch:
  - Dropped, this is now packaged separately as gnome-control-center-unity
* debian/patches/10_keyboard_layout_on_unity.patch:
  - Don't change the keyboard panel name when not running Unity
* debian/patches/52_ubuntu_language_list_mods.patch:
  - Don't disable adding current language to the list. While this
    fix shows the current language twice, at least it avoids the
    "Ubuntu suddenly in Chinese" bug (LP: #1035219)
* debian/patches/53_use_ubuntu_help.patch:
  - Only show Ubuntu help when running Unity
* debian/patches/58_hide_gdm_notifications.patch:
  - Hide "Show notifications when locked" settings when running Unity
    since it's a GNOME Shell-specific feature
* debian/patches/63_normal_scrollbar_in_a11y.patch:
  - Drop, overlay-scrollbars should handle this instead
* debian/patches/91_dont_show_in_unity.patch:
  - Hide Printers & Region panels in Unity until we're ready to switch
    to them.
* debian/patches/fix-crash-on-user-panel.patch:
  - Dropped, GNOME says it's obsolete
* debian/rules:
  - Build with -z,defs again
  - Explicitly disable ibus support since ibus 1.4 isn't supported in
    this version
* debian/control.in:
  - Drop ubuntu-docs and gnome-user-guide from recommends to suggests
  - Don't recommend indicators; let's leave that to Unity

[ David Henningsson ]
* sound_nua_panel.patch: Rebase to gnome 3.6 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2
 
 *
3
 
 * Copyright (C) 2010-2011 Richard Hughes <richard@hughsie.com>
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
 
 *
19
 
 */
20
 
 
21
 
#include <config.h>
22
 
#include <glib/gi18n.h>
23
 
#include <arpa/inet.h>
24
 
#include <netinet/ether.h>
25
 
#include <stdlib.h>
26
 
#include <grp.h>
27
 
#include <unistd.h>
28
 
#include <gio/gio.h>
29
 
#include <gdesktop-enums.h>
30
 
 
31
 
#include "cc-network-panel.h"
32
 
 
33
 
#include "nm-remote-settings.h"
34
 
#include "nm-client.h"
35
 
#include "nm-device.h"
36
 
#include "nm-device-ethernet.h"
37
 
#include "nm-device-modem.h"
38
 
#include "nm-device-wifi.h"
39
 
#include "nm-utils.h"
40
 
#include "nm-active-connection.h"
41
 
#include "nm-vpn-connection.h"
42
 
#include "nm-setting-wireless.h"
43
 
#include "nm-setting-ip4-config.h"
44
 
#include "nm-setting-ip6-config.h"
45
 
#include "nm-setting-connection.h"
46
 
#include "nm-setting-vpn.h"
47
 
#include "nm-setting-wireless.h"
48
 
 
49
 
#include "net-object.h"
50
 
#include "net-device.h"
51
 
#include "net-vpn.h"
52
 
 
53
 
#include "panel-common.h"
54
 
#include "panel-cell-renderer-mode.h"
55
 
#include "panel-cell-renderer-signal.h"
56
 
#include "panel-cell-renderer-security.h"
57
 
 
58
 
#include "network-dialogs.h"
59
 
 
60
 
G_DEFINE_DYNAMIC_TYPE (CcNetworkPanel, cc_network_panel, CC_TYPE_PANEL)
61
 
 
62
 
#define NETWORK_PANEL_PRIVATE(o) \
63
 
        (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_NETWORK_PANEL, CcNetworkPanelPrivate))
64
 
 
65
 
typedef enum {
66
 
        OPERATION_NULL,
67
 
        OPERATION_SHOW_DEVICE,
68
 
        OPERATION_CREATE_WIFI,
69
 
        OPERATION_CONNECT_HIDDEN,
70
 
        OPERATION_CONNECT_8021X,
71
 
        OPERATION_CONNECT_MOBILE
72
 
} CmdlineOperation;
73
 
 
74
 
struct _CcNetworkPanelPrivate
75
 
{
76
 
        GCancellable     *cancellable;
77
 
        GSettings        *proxy_settings;
78
 
        GtkBuilder       *builder;
79
 
        NMClient         *client;
80
 
        NMRemoteSettings *remote_settings;
81
 
        gboolean          updating_device;
82
 
        guint             add_header_widgets_idle;
83
 
        guint             nm_warning_idle;
84
 
        guint             refresh_idle;
85
 
        GtkWidget        *kill_switch_header;
86
 
 
87
 
        /* wireless dialog stuff */
88
 
        CmdlineOperation  arg_operation;
89
 
        gchar            *arg_device;
90
 
        gchar            *arg_access_point;
91
 
        gboolean          operation_done;
92
 
};
93
 
 
94
 
enum {
95
 
        PANEL_DEVICES_COLUMN_ICON,
96
 
        PANEL_DEVICES_COLUMN_TITLE,
97
 
        PANEL_DEVICES_COLUMN_SORT,
98
 
        PANEL_DEVICES_COLUMN_OBJECT,
99
 
        PANEL_DEVICES_COLUMN_LAST
100
 
};
101
 
 
102
 
enum {
103
 
        PANEL_WIRELESS_COLUMN_ID,
104
 
        PANEL_WIRELESS_COLUMN_TITLE,
105
 
        PANEL_WIRELESS_COLUMN_SORT,
106
 
        PANEL_WIRELESS_COLUMN_STRENGTH,
107
 
        PANEL_WIRELESS_COLUMN_MODE,
108
 
        PANEL_WIRELESS_COLUMN_SECURITY,
109
 
        PANEL_WIRELESS_COLUMN_LAST
110
 
};
111
 
 
112
 
enum {
113
 
        PROP_0,
114
 
        PROP_ARGV
115
 
};
116
 
 
117
 
static void     refresh_ui      (CcNetworkPanel *panel);
118
 
static NetObject *find_in_model_by_id (CcNetworkPanel *panel, const gchar *id);
119
 
static gboolean find_model_iter_by_object (GtkTreeModel *model, const NetObject *object, GtkTreeIter *iter);
120
 
 
121
 
static void
122
 
cc_network_panel_get_property (GObject    *object,
123
 
                               guint       property_id,
124
 
                               GValue     *value,
125
 
                               GParamSpec *pspec)
126
 
{
127
 
        switch (property_id) {
128
 
        default:
129
 
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
130
 
        }
131
 
}
132
 
 
133
 
static CmdlineOperation
134
 
cmdline_operation_from_string (const gchar *string)
135
 
{
136
 
        if (g_strcmp0 (string, "create-wifi") == 0)
137
 
                return OPERATION_CREATE_WIFI;
138
 
        if (g_strcmp0 (string, "connect-hidden-wifi") == 0)
139
 
                return OPERATION_CONNECT_HIDDEN;
140
 
        if (g_strcmp0 (string, "connect-8021x-wifi") == 0)
141
 
                return OPERATION_CONNECT_8021X;
142
 
        if (g_strcmp0 (string, "connect-3g") == 0)
143
 
                return OPERATION_CONNECT_MOBILE;
144
 
        if (g_strcmp0 (string, "show-device") == 0)
145
 
                return OPERATION_SHOW_DEVICE;
146
 
 
147
 
        g_warning ("Invalid additional argument %s", string);
148
 
        return OPERATION_NULL;
149
 
}
150
 
 
151
 
static void
152
 
cc_network_panel_set_property (GObject      *object,
153
 
                               guint         property_id,
154
 
                               const GValue *value,
155
 
                               GParamSpec   *pspec)
156
 
{
157
 
        CcNetworkPanel *self = CC_NETWORK_PANEL (object);
158
 
        CcNetworkPanelPrivate *priv = self->priv;
159
 
 
160
 
        switch (property_id) {
161
 
        case PROP_ARGV: {
162
 
                gchar **args;
163
 
 
164
 
                priv->arg_operation = OPERATION_NULL;
165
 
                g_free (priv->arg_device);
166
 
                priv->arg_device = NULL;
167
 
                g_free (priv->arg_access_point);
168
 
                priv->arg_access_point = NULL;
169
 
 
170
 
                args = g_value_get_boxed (value);
171
 
 
172
 
                if (args) {
173
 
                        g_debug ("Invoked with operation %s", args[0]);
174
 
 
175
 
                        if (args[0])
176
 
                                priv->arg_operation = cmdline_operation_from_string (args[0]);
177
 
                        if (args[0] && args[1])
178
 
                                priv->arg_device = g_strdup (args[1]);
179
 
                        if (args[0] && args[1] && args[2])
180
 
                                priv->arg_access_point = g_strdup (args[2]);
181
 
                }
182
 
                break;
183
 
        }
184
 
        default:
185
 
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
186
 
        }
187
 
}
188
 
 
189
 
static void
190
 
cc_network_panel_dispose (GObject *object)
191
 
{
192
 
        CcNetworkPanelPrivate *priv = CC_NETWORK_PANEL (object)->priv;
193
 
 
194
 
        if (priv->proxy_settings) {
195
 
                g_object_unref (priv->proxy_settings);
196
 
                priv->proxy_settings = NULL;
197
 
        }
198
 
        if (priv->cancellable != NULL) {
199
 
                g_cancellable_cancel (priv->cancellable);
200
 
                g_object_unref (priv->cancellable);
201
 
                priv->cancellable = NULL;
202
 
        }
203
 
        if (priv->builder != NULL) {
204
 
                g_object_unref (priv->builder);
205
 
                priv->builder = NULL;
206
 
        }
207
 
        if (priv->client != NULL) {
208
 
                g_object_unref (priv->client);
209
 
                priv->client = NULL;
210
 
        }
211
 
        if (priv->remote_settings != NULL) {
212
 
                g_object_unref (priv->remote_settings);
213
 
                priv->remote_settings = NULL;
214
 
        }
215
 
        if (priv->kill_switch_header != NULL) {
216
 
                g_clear_object (&priv->kill_switch_header);
217
 
        }
218
 
        if (priv->refresh_idle != 0) {
219
 
                g_source_remove (priv->refresh_idle);
220
 
                priv->refresh_idle = 0;
221
 
        }
222
 
        if (priv->nm_warning_idle != 0) {
223
 
                g_source_remove (priv->nm_warning_idle);
224
 
                priv->nm_warning_idle = 0;
225
 
        }
226
 
        if (priv->add_header_widgets_idle != 0) {
227
 
                g_source_remove (priv->add_header_widgets_idle);
228
 
                priv->add_header_widgets_idle = 0;
229
 
        }
230
 
 
231
 
        G_OBJECT_CLASS (cc_network_panel_parent_class)->dispose (object);
232
 
}
233
 
 
234
 
static void
235
 
cc_network_panel_finalize (GObject *object)
236
 
{
237
 
        CcNetworkPanelPrivate *priv = CC_NETWORK_PANEL (object)->priv;
238
 
        g_free (priv->arg_device);
239
 
        g_free (priv->arg_access_point);
240
 
 
241
 
        G_OBJECT_CLASS (cc_network_panel_parent_class)->finalize (object);
242
 
}
243
 
 
244
 
static void
245
 
cc_network_panel_class_init (CcNetworkPanelClass *klass)
246
 
{
247
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
248
 
 
249
 
        g_type_class_add_private (klass, sizeof (CcNetworkPanelPrivate));
250
 
 
251
 
        object_class->get_property = cc_network_panel_get_property;
252
 
        object_class->set_property = cc_network_panel_set_property;
253
 
        object_class->dispose = cc_network_panel_dispose;
254
 
        object_class->finalize = cc_network_panel_finalize;
255
 
 
256
 
        g_object_class_override_property (object_class, PROP_ARGV, "argv");
257
 
}
258
 
 
259
 
static void
260
 
cc_network_panel_class_finalize (CcNetworkPanelClass *klass)
261
 
{
262
 
}
263
 
 
264
 
static void
265
 
check_wpad_warning (CcNetworkPanel *panel)
266
 
{
267
 
        GtkWidget *widget;
268
 
        gchar *autoconfig_url = NULL;
269
 
        GString *string = NULL;
270
 
        gboolean ret = FALSE;
271
 
        guint mode;
272
 
 
273
 
        string = g_string_new ("");
274
 
 
275
 
        /* check we're using 'Automatic' */
276
 
        mode = g_settings_get_enum (panel->priv->proxy_settings, "mode");
277
 
        if (mode != 2)
278
 
                goto out;
279
 
 
280
 
        /* see if the PAC is blank */
281
 
        autoconfig_url = g_settings_get_string (panel->priv->proxy_settings,
282
 
                                                "autoconfig-url");
283
 
        ret = autoconfig_url == NULL ||
284
 
              autoconfig_url[0] == '\0';
285
 
        if (!ret)
286
 
                goto out;
287
 
 
288
 
        g_string_append (string, "<small>");
289
 
 
290
 
        /* TRANSLATORS: this is when the use leaves the PAC textbox blank */
291
 
        g_string_append (string, _("Web Proxy Autodiscovery is used when a Configuration URL is not provided."));
292
 
 
293
 
        g_string_append (string, "\n");
294
 
 
295
 
        /* TRANSLATORS: WPAD is bad: if you enable it on an untrusted
296
 
         * network, then anyone else on that network can tell your
297
 
         * machine that it should proxy all of your web traffic
298
 
         * through them. */
299
 
        g_string_append (string, _("This is not recommended for untrusted public networks."));
300
 
        g_string_append (string, "</small>");
301
 
out:
302
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
303
 
                                                     "label_proxy_warning"));
304
 
        gtk_label_set_markup (GTK_LABEL (widget), string->str);
305
 
        g_free (autoconfig_url);
306
 
        g_string_free (string, TRUE);
307
 
}
308
 
 
309
 
static void
310
 
panel_settings_changed (GSettings      *settings,
311
 
                        const gchar    *key,
312
 
                        CcNetworkPanel *panel)
313
 
{
314
 
        check_wpad_warning (panel);
315
 
}
316
 
 
317
 
static NetObject *
318
 
get_selected_object (CcNetworkPanel *panel)
319
 
{
320
 
        GtkWidget *widget;
321
 
        GtkTreeSelection *selection;
322
 
        GtkTreeModel *model;
323
 
        GtkTreeIter iter;
324
 
        NetObject *object = NULL;
325
 
 
326
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
327
 
                                                     "treeview_devices"));
328
 
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
329
 
        if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
330
 
                return NULL;
331
 
        }
332
 
 
333
 
        gtk_tree_model_get (model, &iter,
334
 
                            PANEL_DEVICES_COLUMN_OBJECT, &object,
335
 
                            -1);
336
 
 
337
 
        return object;
338
 
}
339
 
 
340
 
static void
341
 
panel_proxy_mode_combo_setup_widgets (CcNetworkPanel *panel, guint value)
342
 
{
343
 
        GtkWidget *widget;
344
 
 
345
 
        /* hide or show the PAC text box */
346
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
347
 
                                                     "heading_proxy_url"));
348
 
        gtk_widget_set_visible (widget, value == 2);
349
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
350
 
                                                     "entry_proxy_url"));
351
 
        gtk_widget_set_visible (widget, value == 2);
352
 
 
353
 
        /* hide or show the manual entry text boxes */
354
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
355
 
                                                     "heading_proxy_http"));
356
 
        gtk_widget_set_visible (widget, value == 1);
357
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
358
 
                                                     "entry_proxy_http"));
359
 
        gtk_widget_set_visible (widget, value == 1);
360
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
361
 
                                                     "spinbutton_proxy_http"));
362
 
        gtk_widget_set_visible (widget, value == 1);
363
 
 
364
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
365
 
                                                     "heading_proxy_https"));
366
 
        gtk_widget_set_visible (widget, value == 1);
367
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
368
 
                                                     "entry_proxy_https"));
369
 
        gtk_widget_set_visible (widget, value == 1);
370
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
371
 
                                                     "spinbutton_proxy_https"));
372
 
        gtk_widget_set_visible (widget, value == 1);
373
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
374
 
                                                     "heading_proxy_ftp"));
375
 
        gtk_widget_set_visible (widget, value == 1);
376
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
377
 
                                                     "entry_proxy_ftp"));
378
 
        gtk_widget_set_visible (widget, value == 1);
379
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
380
 
                                                     "spinbutton_proxy_ftp"));
381
 
        gtk_widget_set_visible (widget, value == 1);
382
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
383
 
                                                     "heading_proxy_socks"));
384
 
        gtk_widget_set_visible (widget, value == 1);
385
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
386
 
                                                     "entry_proxy_socks"));
387
 
        gtk_widget_set_visible (widget, value == 1);
388
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
389
 
                                                     "spinbutton_proxy_socks"));
390
 
        gtk_widget_set_visible (widget, value == 1);
391
 
 
392
 
        /* perhaps show the wpad warning */
393
 
        check_wpad_warning (panel);
394
 
}
395
 
 
396
 
static void
397
 
panel_proxy_mode_combo_changed_cb (GtkWidget *widget, CcNetworkPanel *panel)
398
 
{
399
 
        gboolean ret;
400
 
        gint value;
401
 
        GtkTreeIter iter;
402
 
        GtkTreeModel *model;
403
 
 
404
 
        /* no selection */
405
 
        ret = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter);
406
 
        if (!ret)
407
 
                return;
408
 
 
409
 
        /* get entry */
410
 
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
411
 
        gtk_tree_model_get (model, &iter,
412
 
                            1, &value,
413
 
                            -1);
414
 
 
415
 
        /* set */
416
 
        g_settings_set_enum (panel->priv->proxy_settings, "mode", value);
417
 
 
418
 
        /* hide or show the correct widgets */
419
 
        panel_proxy_mode_combo_setup_widgets (panel, value);
420
 
}
421
 
 
422
 
static void
423
 
panel_set_value_for_combo (CcNetworkPanel *panel, GtkComboBox *combo_box, gint value)
424
 
{
425
 
        gboolean ret;
426
 
        gint value_tmp;
427
 
        GtkTreeIter iter;
428
 
        GtkTreeModel *model;
429
 
 
430
 
        /* get entry */
431
 
        model = gtk_combo_box_get_model (combo_box);
432
 
        ret = gtk_tree_model_get_iter_first (model, &iter);
433
 
        if (!ret)
434
 
                return;
435
 
 
436
 
        /* try to make the UI match the setting */
437
 
        do {
438
 
                gtk_tree_model_get (model, &iter,
439
 
                                    1, &value_tmp,
440
 
                                    -1);
441
 
                if (value == value_tmp) {
442
 
                        gtk_combo_box_set_active_iter (combo_box, &iter);
443
 
                        break;
444
 
                }
445
 
        } while (gtk_tree_model_iter_next (model, &iter));
446
 
 
447
 
        /* hide or show the correct widgets */
448
 
        panel_proxy_mode_combo_setup_widgets (panel, value);
449
 
}
450
 
 
451
 
static void
452
 
select_first_device (CcNetworkPanel *panel)
453
 
{
454
 
        GtkTreePath *path;
455
 
        GtkWidget *widget;
456
 
        GtkTreeSelection *selection;
457
 
 
458
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
459
 
                                                     "treeview_devices"));
460
 
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
461
 
 
462
 
        /* select the first device */
463
 
        path = gtk_tree_path_new_from_string ("0");
464
 
        gtk_tree_selection_select_path (selection, path);
465
 
        gtk_tree_path_free (path);
466
 
}
467
 
 
468
 
static void
469
 
select_tree_iter (CcNetworkPanel *panel, GtkTreeIter *iter)
470
 
{
471
 
        GtkTreeView *widget;
472
 
        GtkTreeSelection *selection;
473
 
 
474
 
        widget = GTK_TREE_VIEW (gtk_builder_get_object (panel->priv->builder,
475
 
                                                        "treeview_devices"));
476
 
        selection = gtk_tree_view_get_selection (widget);
477
 
 
478
 
        gtk_tree_selection_select_iter (selection, iter);
479
 
}
480
 
 
481
 
static void
482
 
panel_device_got_modem_manager_cb (GObject *source_object,
483
 
                                   GAsyncResult *res,
484
 
                                   gpointer user_data)
485
 
{
486
 
        GError *error = NULL;
487
 
        GVariant *result = NULL;
488
 
        GDBusProxy *proxy;
489
 
        NMDevice *device = (NMDevice *) user_data;
490
 
 
491
 
        proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
492
 
        if (proxy == NULL) {
493
 
                g_warning ("Error creating ModemManager proxy: %s",
494
 
                           error->message);
495
 
                g_error_free (error);
496
 
                goto out;
497
 
        }
498
 
 
499
 
        /* get the IMEI */
500
 
        result = g_dbus_proxy_get_cached_property (proxy,
501
 
                                                   "EquipmentIdentifier");
502
 
 
503
 
        /* save */
504
 
        g_object_set_data_full (G_OBJECT (device),
505
 
                                "ControlCenter::EquipmentIdentifier",
506
 
                                g_variant_dup_string (result, NULL),
507
 
                                g_free);
508
 
out:
509
 
        if (result != NULL)
510
 
                g_variant_unref (result);
511
 
        if (proxy != NULL)
512
 
                g_object_unref (proxy);
513
 
        return;
514
 
}
515
 
 
516
 
static void
517
 
panel_get_registration_info_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
518
 
{
519
 
        gchar *operator_code = NULL;
520
 
        GError *error = NULL;
521
 
        guint registration_status;
522
 
        GVariant *result = NULL;
523
 
        gchar *operator_name = NULL;
524
 
        gchar *operator_name_safe = NULL;
525
 
        NMDevice *device = (NMDevice *) user_data;
526
 
 
527
 
        result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
528
 
        if (result == NULL) {
529
 
                g_warning ("Error getting registration info: %s\n",
530
 
                           error->message);
531
 
                g_error_free (error);
532
 
                return;
533
 
        }
534
 
 
535
 
        /* get values */
536
 
        g_variant_get (result, "((uss))",
537
 
                       &registration_status,
538
 
                       &operator_code,
539
 
                       &operator_name);
540
 
        if (operator_name != NULL && operator_name[0] != '\0')
541
 
                operator_name_safe = g_strescape (operator_name, NULL);
542
 
 
543
 
        /* save */
544
 
        g_object_set_data_full (G_OBJECT (device),
545
 
                                "ControlCenter::OperatorName",
546
 
                                operator_name_safe,
547
 
                                g_free);
548
 
 
549
 
        g_free (operator_name);
550
 
        g_free (operator_code);
551
 
        g_variant_unref (result);
552
 
}
553
 
 
554
 
static void
555
 
panel_device_got_modem_manager_gsm_cb (GObject *source_object,
556
 
                                       GAsyncResult *res,
557
 
                                       gpointer user_data)
558
 
{
559
 
        GError *error = NULL;
560
 
        GDBusProxy *proxy;
561
 
        NMDevice *device = (NMDevice *) user_data;
562
 
 
563
 
        proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
564
 
        if (proxy == NULL) {
565
 
                g_warning ("Error creating ModemManager GSM proxy: %s\n",
566
 
                           error->message);
567
 
                g_error_free (error);
568
 
                goto out;
569
 
        }
570
 
 
571
 
        g_dbus_proxy_call (proxy,
572
 
                           "GetRegistrationInfo",
573
 
                           NULL,
574
 
                           G_DBUS_CALL_FLAGS_NONE,
575
 
                           -1,
576
 
                           NULL,
577
 
                           panel_get_registration_info_cb,
578
 
                           device);
579
 
out:
580
 
        if (proxy != NULL)
581
 
                g_object_unref (proxy);
582
 
        return;
583
 
}
584
 
 
585
 
static void
586
 
device_state_notify_changed_cb (NMDevice *device,
587
 
                                GParamSpec *pspec,
588
 
                                CcNetworkPanel *panel)
589
 
{
590
 
        refresh_ui (panel);
591
 
}
592
 
 
593
 
static void
594
 
object_changed_cb (NetObject *object, CcNetworkPanel *panel)
595
 
{
596
 
        refresh_ui (panel);
597
 
}
598
 
 
599
 
static void
600
 
object_removed_cb (NetObject *object, CcNetworkPanel *panel)
601
 
{
602
 
        gboolean ret;
603
 
        NetObject *object_tmp;
604
 
        GtkTreeIter iter;
605
 
        GtkTreeModel *model;
606
 
        GtkWidget *widget;
607
 
        GtkTreeSelection *selection;
608
 
 
609
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
610
 
                                                     "treeview_devices"));
611
 
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
612
 
 
613
 
        /* remove device from model */
614
 
        model = GTK_TREE_MODEL (gtk_builder_get_object (panel->priv->builder,
615
 
                                                        "liststore_devices"));
616
 
        ret = gtk_tree_model_get_iter_first (model, &iter);
617
 
        if (!ret)
618
 
                return;
619
 
 
620
 
        /* get the other elements */
621
 
        do {
622
 
                gtk_tree_model_get (model, &iter,
623
 
                                    PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
624
 
                                    -1);
625
 
                if (g_strcmp0 (net_object_get_id (object),
626
 
                               net_object_get_id (object_tmp)) == 0) {
627
 
                        g_object_unref (object_tmp);
628
 
                        if (!gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
629
 
                                gtk_tree_model_get_iter_first (model, &iter);
630
 
                        gtk_tree_selection_select_iter (selection, &iter);
631
 
 
632
 
                        break;
633
 
                }
634
 
                g_object_unref (object_tmp);
635
 
        } while (gtk_tree_model_iter_next (model, &iter));
636
 
}
637
 
 
638
 
static void
639
 
register_object_interest (CcNetworkPanel *panel, NetObject *object)
640
 
{
641
 
        g_signal_connect (object,
642
 
                          "changed",
643
 
                          G_CALLBACK (object_changed_cb),
644
 
                          panel);
645
 
        g_signal_connect (object,
646
 
                          "removed",
647
 
                          G_CALLBACK (object_removed_cb),
648
 
                          panel);
649
 
}
650
 
 
651
 
static void
652
 
panel_refresh_killswitch_visibility (CcNetworkPanel *panel)
653
 
{
654
 
        gboolean ret;
655
 
        gboolean show_flight_toggle = FALSE;
656
 
        GtkTreeIter iter;
657
 
        GtkTreeModel *model;
658
 
        NetObject *object_tmp;
659
 
        NMDeviceModemCapabilities caps;
660
 
        NMDevice *nm_device;
661
 
 
662
 
        /* find any wireless devices in model */
663
 
        model = GTK_TREE_MODEL (gtk_builder_get_object (panel->priv->builder,
664
 
                                                        "liststore_devices"));
665
 
        ret = gtk_tree_model_get_iter_first (model, &iter);
666
 
        if (!ret)
667
 
                return;
668
 
        do {
669
 
                gtk_tree_model_get (model, &iter,
670
 
                                    PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
671
 
                                    -1);
672
 
                if (NET_IS_DEVICE (object_tmp)) {
673
 
                        nm_device = net_device_get_nm_device (NET_DEVICE (object_tmp));
674
 
                        switch (nm_device_get_device_type (nm_device)) {
675
 
                        case NM_DEVICE_TYPE_WIFI:
676
 
                        case NM_DEVICE_TYPE_WIMAX:
677
 
                                show_flight_toggle = TRUE;
678
 
                                break;
679
 
                        case NM_DEVICE_TYPE_MODEM:
680
 
                                {
681
 
                                caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (nm_device));
682
 
                                if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
683
 
                                    (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO))
684
 
                                        show_flight_toggle = TRUE;
685
 
                                }
686
 
                                break;
687
 
                        default:
688
 
                                break;
689
 
                        }
690
 
                }
691
 
                g_object_unref (object_tmp);
692
 
        } while (!show_flight_toggle && gtk_tree_model_iter_next (model, &iter));
693
 
 
694
 
        /* only show toggle if there are wireless devices */
695
 
        gtk_widget_set_visible (panel->priv->kill_switch_header,
696
 
                                show_flight_toggle);
697
 
}
698
 
 
699
 
static gboolean
700
 
panel_add_device (CcNetworkPanel *panel, NMDevice *device)
701
 
{
702
 
        GtkListStore *liststore_devices;
703
 
        GtkTreeIter iter;
704
 
        gchar *title = NULL;
705
 
        NMDeviceType type;
706
 
        NetDevice *net_device;
707
 
        CcNetworkPanelPrivate *priv = panel->priv;
708
 
 
709
 
        /* do we have an existing object with this id? */
710
 
        if (find_in_model_by_id (panel, nm_device_get_udi (device)) != NULL)
711
 
                goto out;
712
 
 
713
 
        /* we don't support bluetooth devices yet -- no mockup */
714
 
        type = nm_device_get_device_type (device);
715
 
 
716
 
        if (type == NM_DEVICE_TYPE_BT)
717
 
                goto out;
718
 
 
719
 
        g_debug ("device %s type %i",
720
 
                 nm_device_get_udi (device),
721
 
                 nm_device_get_device_type (device));
722
 
        g_signal_connect (G_OBJECT (device), "notify::state",
723
 
                          (GCallback) device_state_notify_changed_cb, panel);
724
 
 
725
 
        /* do we have to get additonal data from ModemManager */
726
 
        if (type == NM_DEVICE_TYPE_MODEM) {
727
 
                g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
728
 
                                          G_DBUS_PROXY_FLAGS_NONE,
729
 
                                          NULL,
730
 
                                          "org.freedesktop.ModemManager",
731
 
                                          nm_device_get_udi (device),
732
 
                                          "org.freedesktop.ModemManager.Modem",
733
 
                                          panel->priv->cancellable,
734
 
                                          panel_device_got_modem_manager_cb,
735
 
                                          device);
736
 
                g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
737
 
                                          G_DBUS_PROXY_FLAGS_NONE,
738
 
                                          NULL,
739
 
                                          "org.freedesktop.ModemManager",
740
 
                                          nm_device_get_udi (device),
741
 
                                          "org.freedesktop.ModemManager.Modem.Gsm.Network",
742
 
                                          panel->priv->cancellable,
743
 
                                          panel_device_got_modem_manager_gsm_cb,
744
 
                                          device);
745
 
        }
746
 
 
747
 
        /* make title a bit bigger */
748
 
        title = g_strdup_printf ("%s", panel_device_to_localized_string (device));
749
 
 
750
 
        liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
751
 
                                            "liststore_devices"));
752
 
        net_device = net_device_new ();
753
 
        net_device_set_nm_device (net_device, device);
754
 
        net_object_set_id (NET_OBJECT (net_device), nm_device_get_udi (device));
755
 
        register_object_interest (panel, NET_OBJECT (net_device));
756
 
        gtk_list_store_append (liststore_devices, &iter);
757
 
        gtk_list_store_set (liststore_devices,
758
 
                            &iter,
759
 
                            PANEL_DEVICES_COLUMN_ICON, panel_device_to_icon_name (device),
760
 
                            PANEL_DEVICES_COLUMN_SORT, panel_device_to_sortable_string (device),
761
 
                            PANEL_DEVICES_COLUMN_TITLE, title,
762
 
                            PANEL_DEVICES_COLUMN_OBJECT, net_device,
763
 
                            -1);
764
 
 
765
 
        if (priv->arg_operation != OPERATION_NULL) {
766
 
                if (type == NM_DEVICE_TYPE_WIFI &&
767
 
                    (priv->arg_operation == OPERATION_CREATE_WIFI ||
768
 
                     priv->arg_operation == OPERATION_CONNECT_HIDDEN)) {
769
 
                        g_debug ("Selecting wifi device");
770
 
                        select_tree_iter (panel, &iter);
771
 
 
772
 
                        if (priv->arg_operation == OPERATION_CREATE_WIFI)
773
 
                                cc_network_panel_create_wifi_network (panel, priv->client, priv->remote_settings);
774
 
                        else
775
 
                                cc_network_panel_connect_to_hidden_network (panel, priv->client, priv->remote_settings);
776
 
 
777
 
                        priv->arg_operation = OPERATION_NULL; /* done */
778
 
                        return TRUE;
779
 
                } else if (g_strcmp0 (nm_object_get_path (NM_OBJECT (device)), priv->arg_device) == 0) {
780
 
                        if (priv->arg_operation == OPERATION_CONNECT_MOBILE) {
781
 
                                cc_network_panel_connect_to_3g_network (panel, priv->client, priv->remote_settings, device);
782
 
 
783
 
                                priv->arg_operation = OPERATION_NULL; /* done */
784
 
                                select_tree_iter (panel, &iter);
785
 
                                return TRUE;
786
 
                        } else if (priv->arg_operation == OPERATION_CONNECT_8021X
787
 
                                   || priv->arg_operation == OPERATION_SHOW_DEVICE) {
788
 
                                select_tree_iter (panel, &iter);
789
 
 
790
 
                                /* 802.11 wireless stuff must be handled in add_access_point, but
791
 
                                   we still select the right page here, whereas if we're just showing
792
 
                                   the device, we're done right away */
793
 
                                if (priv->arg_operation == OPERATION_SHOW_DEVICE)
794
 
                                        priv->arg_operation = OPERATION_NULL;
795
 
                                return TRUE;
796
 
                        }
797
 
                }
798
 
        }
799
 
 
800
 
out:
801
 
        g_free (title);
802
 
        return FALSE;
803
 
}
804
 
 
805
 
static void
806
 
panel_remove_device (CcNetworkPanel *panel, NMDevice *device)
807
 
{
808
 
        gboolean ret;
809
 
        NetObject *object_tmp;
810
 
        GtkTreeIter iter;
811
 
        GtkTreeModel *model;
812
 
 
813
 
        /* remove device from model */
814
 
        model = GTK_TREE_MODEL (gtk_builder_get_object (panel->priv->builder,
815
 
                                                        "liststore_devices"));
816
 
        ret = gtk_tree_model_get_iter_first (model, &iter);
817
 
        if (!ret)
818
 
                return;
819
 
 
820
 
        /* get the other elements */
821
 
        do {
822
 
                gtk_tree_model_get (model, &iter,
823
 
                                    PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
824
 
                                    -1);
825
 
                if (g_strcmp0 (net_object_get_id (object_tmp),
826
 
                               nm_device_get_udi (device)) == 0) {
827
 
                        gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
828
 
                        g_object_unref (object_tmp);
829
 
                        break;
830
 
                }
831
 
                g_object_unref (object_tmp);
832
 
        } while (gtk_tree_model_iter_next (model, &iter));
833
 
}
834
 
 
835
 
static void
836
 
panel_add_devices_columns (CcNetworkPanel *panel, GtkTreeView *treeview)
837
 
{
838
 
        CcNetworkPanelPrivate *priv = panel->priv;
839
 
        GtkCellRenderer *renderer;
840
 
        GtkListStore *liststore_devices;
841
 
        GtkTreeViewColumn *column;
842
 
 
843
 
        /* image */
844
 
        renderer = gtk_cell_renderer_pixbuf_new ();
845
 
        g_object_set (renderer, "stock-size", gtk_icon_size_from_name ("cc-sidebar-list"), NULL);
846
 
        gtk_cell_renderer_set_padding (renderer, 4, 4);
847
 
 
848
 
        column = gtk_tree_view_column_new_with_attributes ("", renderer,
849
 
                                                           "icon-name", PANEL_DEVICES_COLUMN_ICON,
850
 
                                                           NULL);
851
 
        gtk_tree_view_append_column (treeview, column);
852
 
 
853
 
        /* column for text */
854
 
        renderer = gtk_cell_renderer_text_new ();
855
 
        g_object_set (renderer,
856
 
                      "wrap-mode", PANGO_WRAP_WORD,
857
 
                      NULL);
858
 
        column = gtk_tree_view_column_new_with_attributes ("", renderer,
859
 
                                                           "markup", PANEL_DEVICES_COLUMN_TITLE,
860
 
                                                           NULL);
861
 
        gtk_tree_view_column_set_sort_column_id (column, PANEL_DEVICES_COLUMN_SORT);
862
 
        liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
863
 
                                            "liststore_devices"));
864
 
        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (liststore_devices),
865
 
                                              PANEL_DEVICES_COLUMN_SORT,
866
 
                                              GTK_SORT_ASCENDING);
867
 
        gtk_tree_view_append_column (treeview, column);
868
 
        gtk_tree_view_column_set_expand (column, TRUE);
869
 
}
870
 
 
871
 
static void
872
 
panel_set_widget_data (CcNetworkPanel *panel,
873
 
                       const gchar *sub_pane,
874
 
                       const gchar *widget_suffix,
875
 
                       const gchar *value)
876
 
{
877
 
        gchar *heading_id;
878
 
        gchar *label_id = NULL;
879
 
        GtkWidget *heading;
880
 
        GtkWidget *widget;
881
 
        CcNetworkPanelPrivate *priv = panel->priv;
882
 
 
883
 
        /* hide the row if there is no value */
884
 
        heading_id = g_strdup_printf ("heading_%s_%s", sub_pane, widget_suffix);
885
 
        label_id = g_strdup_printf ("label_%s_%s", sub_pane, widget_suffix);
886
 
        heading = GTK_WIDGET (gtk_builder_get_object (priv->builder, heading_id));
887
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, label_id));
888
 
        if (heading == NULL || widget == NULL) {
889
 
                g_critical ("no widgets %s, %s found", heading_id, label_id);
890
 
                return;
891
 
        }
892
 
        g_free (heading_id);
893
 
        g_free (label_id);
894
 
 
895
 
        if (value == NULL) {
896
 
                gtk_widget_hide (heading);
897
 
                gtk_widget_hide (widget);
898
 
        } else {
899
 
                /* there exists a value */
900
 
                gtk_widget_show (heading);
901
 
                gtk_widget_show (widget);
902
 
                gtk_label_set_label (GTK_LABEL (widget), value);
903
 
        }
904
 
}
905
 
 
906
 
static void
907
 
panel_set_widget_heading (CcNetworkPanel *panel,
908
 
                          const gchar *sub_pane,
909
 
                          const gchar *widget_suffix,
910
 
                          const gchar *heading)
911
 
{
912
 
        gchar *label_id = NULL;
913
 
        GtkWidget *widget;
914
 
 
915
 
        label_id = g_strdup_printf ("heading_%s_%s", sub_pane, widget_suffix);
916
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, label_id));
917
 
        if (widget)
918
 
                gtk_label_set_label (GTK_LABEL (widget), heading);
919
 
        g_free (label_id);
920
 
}
921
 
 
922
 
static guint
923
 
get_access_point_security (NMAccessPoint *ap)
924
 
{
925
 
        NM80211ApFlags flags;
926
 
        NM80211ApSecurityFlags wpa_flags;
927
 
        NM80211ApSecurityFlags rsn_flags;
928
 
        guint type;
929
 
 
930
 
        flags = nm_access_point_get_flags (ap);
931
 
        wpa_flags = nm_access_point_get_wpa_flags (ap);
932
 
        rsn_flags = nm_access_point_get_rsn_flags (ap);
933
 
 
934
 
        if (!(flags & NM_802_11_AP_FLAGS_PRIVACY) &&
935
 
            wpa_flags == NM_802_11_AP_SEC_NONE &&
936
 
            rsn_flags == NM_802_11_AP_SEC_NONE)
937
 
                type = NM_AP_SEC_NONE;
938
 
        else if ((flags & NM_802_11_AP_FLAGS_PRIVACY) &&
939
 
                 wpa_flags == NM_802_11_AP_SEC_NONE &&
940
 
                 rsn_flags == NM_802_11_AP_SEC_NONE)
941
 
                type = NM_AP_SEC_WEP;
942
 
        else if (!(flags & NM_802_11_AP_FLAGS_PRIVACY) &&
943
 
                 wpa_flags != NM_802_11_AP_SEC_NONE &&
944
 
                 rsn_flags != NM_802_11_AP_SEC_NONE)
945
 
                type = NM_AP_SEC_WPA;
946
 
        else
947
 
                type = NM_AP_SEC_WPA2;
948
 
 
949
 
        return type;
950
 
}
951
 
 
952
 
static void
953
 
add_access_point (CcNetworkPanel *panel, NMAccessPoint *ap, NMAccessPoint *active, NMDevice *device)
954
 
{
955
 
        CcNetworkPanelPrivate *priv = panel->priv;
956
 
        const GByteArray *ssid;
957
 
        const gchar *ssid_text;
958
 
        const gchar *object_path;
959
 
        GtkListStore *liststore_wireless_network;
960
 
        GtkTreeIter treeiter;
961
 
        GtkWidget *widget;
962
 
 
963
 
        ssid = nm_access_point_get_ssid (ap);
964
 
        if (ssid == NULL)
965
 
                return;
966
 
        ssid_text = nm_utils_escape_ssid (ssid->data, ssid->len);
967
 
 
968
 
        liststore_wireless_network = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
969
 
                                                     "liststore_wireless_network"));
970
 
 
971
 
        object_path = nm_object_get_path (NM_OBJECT (ap));
972
 
        gtk_list_store_append (liststore_wireless_network, &treeiter);
973
 
        gtk_list_store_set (liststore_wireless_network,
974
 
                            &treeiter,
975
 
                            PANEL_WIRELESS_COLUMN_ID, object_path,
976
 
                            PANEL_WIRELESS_COLUMN_TITLE, ssid_text,
977
 
                            PANEL_WIRELESS_COLUMN_SORT, ssid_text,
978
 
                            PANEL_WIRELESS_COLUMN_STRENGTH, nm_access_point_get_strength (ap),
979
 
                            PANEL_WIRELESS_COLUMN_MODE, nm_access_point_get_mode (ap),
980
 
                            PANEL_WIRELESS_COLUMN_SECURITY, get_access_point_security (ap),
981
 
                            -1);
982
 
 
983
 
        /* is this what we're on already? */
984
 
        if (active && nm_utils_same_ssid (ssid, nm_access_point_get_ssid (active), TRUE)) {
985
 
                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
986
 
                                                             "combobox_wireless_network_name"));
987
 
                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &treeiter);
988
 
        }
989
 
 
990
 
        if (priv->arg_operation == OPERATION_CONNECT_8021X &&
991
 
            g_strcmp0(priv->arg_device, nm_object_get_path (NM_OBJECT (device))) == 0 &&
992
 
            g_strcmp0(priv->arg_access_point, object_path) == 0) {
993
 
                cc_network_panel_connect_to_8021x_network (panel,
994
 
                                                           priv->client,
995
 
                                                           priv->remote_settings,
996
 
                                                           device,
997
 
                                                           ap);
998
 
                priv->arg_operation = OPERATION_NULL; /* done */
999
 
        }
1000
 
}
1001
 
 
1002
 
static void
1003
 
add_access_point_other (CcNetworkPanel *panel)
1004
 
{
1005
 
        CcNetworkPanelPrivate *priv = panel->priv;
1006
 
        GtkListStore *liststore_wireless_network;
1007
 
        GtkTreeIter treeiter;
1008
 
 
1009
 
        liststore_wireless_network = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
1010
 
                                                     "liststore_wireless_network"));
1011
 
 
1012
 
        gtk_list_store_append (liststore_wireless_network, &treeiter);
1013
 
        gtk_list_store_set (liststore_wireless_network,
1014
 
                            &treeiter,
1015
 
                            PANEL_WIRELESS_COLUMN_ID, "ap-other...",
1016
 
                            /* TRANSLATORS: this is when the access point is not listed
1017
 
                             * in the dropdown (or hidden) and the user has to select
1018
 
                             * another entry manually */
1019
 
                            PANEL_WIRELESS_COLUMN_TITLE, C_("Wireless access point", "Other..."),
1020
 
                            /* always last */
1021
 
                            PANEL_WIRELESS_COLUMN_SORT, "",
1022
 
                            PANEL_WIRELESS_COLUMN_STRENGTH, 0,
1023
 
                            PANEL_WIRELESS_COLUMN_MODE, NM_802_11_MODE_UNKNOWN,
1024
 
                            PANEL_WIRELESS_COLUMN_SECURITY, NM_AP_SEC_UNKNOWN,
1025
 
                            -1);
1026
 
}
1027
 
 
1028
 
#if 0
1029
 
static gchar *
1030
 
ip4_address_as_string (guint32 ip)
1031
 
{
1032
 
        char buf[INET_ADDRSTRLEN+1];
1033
 
        struct in_addr tmp_addr;
1034
 
 
1035
 
        memset (&buf, '\0', sizeof (buf));
1036
 
        tmp_addr.s_addr = ip;
1037
 
 
1038
 
        if (inet_ntop (AF_INET, &tmp_addr, buf, INET_ADDRSTRLEN)) {
1039
 
                return g_strdup (buf);
1040
 
        } else {
1041
 
                g_warning ("error converting IP4 address 0x%X",
1042
 
                           ntohl (tmp_addr.s_addr));
1043
 
                return NULL;
1044
 
        }
1045
 
}
1046
 
 
1047
 
static void
1048
 
panel_show_ip4_config (NMIP4Config *cfg)
1049
 
{
1050
 
        gchar *tmp;
1051
 
        const GArray *array;
1052
 
        const GPtrArray *ptr_array;
1053
 
        GSList *iter;
1054
 
        int i;
1055
 
 
1056
 
        for (iter = (GSList *) nm_ip4_config_get_addresses (cfg); iter; iter = g_slist_next (iter)) {
1057
 
                NMIP4Address *addr = iter->data;
1058
 
                guint32 u;
1059
 
 
1060
 
                tmp = ip4_address_as_string (nm_ip4_address_get_address (addr));
1061
 
                g_debug ("IP4 address: %s", tmp);
1062
 
                g_free (tmp);
1063
 
 
1064
 
                u = nm_ip4_address_get_prefix (addr);
1065
 
                tmp = ip4_address_as_string (nm_utils_ip4_prefix_to_netmask (u));
1066
 
                g_debug ("IP4 prefix: %d (%s)", u, tmp);
1067
 
                g_free (tmp);
1068
 
 
1069
 
                tmp = ip4_address_as_string (nm_ip4_address_get_gateway (addr));
1070
 
                g_debug ("IP4 gateway: %s", tmp);
1071
 
                g_free (tmp);
1072
 
        }
1073
 
 
1074
 
        array = nm_ip4_config_get_nameservers (cfg);
1075
 
        if (array) {
1076
 
                g_debug ("IP4 DNS:");
1077
 
                for (i = 0; i < array->len; i++) {
1078
 
                        tmp = ip4_address_as_string (g_array_index (array, guint32, i));
1079
 
                        g_debug ("\t%s", tmp);
1080
 
                        g_free (tmp);
1081
 
                }
1082
 
        }
1083
 
 
1084
 
        ptr_array = nm_ip4_config_get_domains (cfg);
1085
 
        if (ptr_array) {
1086
 
                g_debug ("IP4 domains:");
1087
 
                for (i = 0; i < ptr_array->len; i++)
1088
 
                        g_debug ("\t%s", (const char *) g_ptr_array_index (ptr_array, i));
1089
 
        }
1090
 
 
1091
 
        array = nm_ip4_config_get_wins_servers (cfg);
1092
 
        if (array) {
1093
 
                g_debug ("IP4 WINS:");
1094
 
                for (i = 0; i < array->len; i++) {
1095
 
                        tmp = ip4_address_as_string (g_array_index (array, guint32, i));
1096
 
                        g_debug ("\t%s", tmp);
1097
 
                        g_free (tmp);
1098
 
                }
1099
 
        }
1100
 
}
1101
 
#endif
1102
 
 
1103
 
static GPtrArray *
1104
 
panel_get_strongest_unique_aps (const GPtrArray *aps)
1105
 
{
1106
 
        const GByteArray *ssid;
1107
 
        const GByteArray *ssid_tmp;
1108
 
        GPtrArray *aps_unique = NULL;
1109
 
        gboolean add_ap;
1110
 
        guint i;
1111
 
        guint j;
1112
 
        NMAccessPoint *ap;
1113
 
        NMAccessPoint *ap_tmp;
1114
 
 
1115
 
        /* we will have multiple entries for typical hotspots, just
1116
 
         * filter to the one with the strongest signal */
1117
 
        aps_unique = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
1118
 
        if (aps != NULL)
1119
 
                for (i = 0; i < aps->len; i++) {
1120
 
                        ap = NM_ACCESS_POINT (g_ptr_array_index (aps, i));
1121
 
                        ssid = nm_access_point_get_ssid (ap);
1122
 
                        add_ap = TRUE;
1123
 
 
1124
 
                        /* get already added list */
1125
 
                        for (j=0; j<aps_unique->len; j++) {
1126
 
                                ap_tmp = NM_ACCESS_POINT (g_ptr_array_index (aps_unique, j));
1127
 
                                ssid_tmp = nm_access_point_get_ssid (ap_tmp);
1128
 
        
1129
 
                                /* is this the same type and data? */
1130
 
                                if (nm_utils_same_ssid (ssid, ssid_tmp, TRUE)) {
1131
 
 
1132
 
                                        g_debug ("found duplicate: %s",
1133
 
                                                 nm_utils_escape_ssid (ssid_tmp->data,
1134
 
                                                                       ssid_tmp->len));
1135
 
 
1136
 
                                        /* the new access point is stronger */
1137
 
                                        if (nm_access_point_get_strength (ap) >
1138
 
                                            nm_access_point_get_strength (ap_tmp)) {
1139
 
                                                g_debug ("removing %s",
1140
 
                                                         nm_utils_escape_ssid (ssid_tmp->data,
1141
 
                                                                               ssid_tmp->len));
1142
 
                                                g_ptr_array_remove (aps_unique, ap_tmp);
1143
 
                                                add_ap = TRUE;
1144
 
                                        } else {
1145
 
                                                add_ap = FALSE;
1146
 
                                        }
1147
 
 
1148
 
                                        break;
1149
 
                                }
1150
 
                        }
1151
 
                        if (add_ap) {
1152
 
                                g_debug ("adding %s",
1153
 
                                         nm_utils_escape_ssid (ssid->data,
1154
 
                                                               ssid->len));
1155
 
                                g_ptr_array_add (aps_unique, g_object_ref (ap));
1156
 
                        }
1157
 
                }
1158
 
        return aps_unique;
1159
 
}
1160
 
 
1161
 
static gchar *
1162
 
get_ap_security_string (NMAccessPoint *ap)
1163
 
{
1164
 
        NM80211ApSecurityFlags wpa_flags, rsn_flags;
1165
 
        NM80211ApFlags flags;
1166
 
        GString *str;
1167
 
 
1168
 
        flags = nm_access_point_get_flags (ap);
1169
 
        wpa_flags = nm_access_point_get_wpa_flags (ap);
1170
 
        rsn_flags = nm_access_point_get_rsn_flags (ap);
1171
 
 
1172
 
        str = g_string_new ("");
1173
 
        if ((flags & NM_802_11_AP_FLAGS_PRIVACY) &&
1174
 
            (wpa_flags == NM_802_11_AP_SEC_NONE) &&
1175
 
            (rsn_flags == NM_802_11_AP_SEC_NONE)) {
1176
 
                /* TRANSLATORS: this WEP WiFi security */
1177
 
                g_string_append_printf (str, "%s, ", _("WEP"));
1178
 
        }
1179
 
        if (wpa_flags != NM_802_11_AP_SEC_NONE) {
1180
 
                /* TRANSLATORS: this WPA WiFi security */
1181
 
                g_string_append_printf (str, "%s, ", _("WPA"));
1182
 
        }
1183
 
        if (rsn_flags != NM_802_11_AP_SEC_NONE) {
1184
 
                /* TRANSLATORS: this WPA WiFi security */
1185
 
                g_string_append_printf (str, "%s, ", _("WPA2"));
1186
 
        }
1187
 
        if ((wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) ||
1188
 
            (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
1189
 
                /* TRANSLATORS: this Enterprise WiFi security */
1190
 
                g_string_append_printf (str, "%s, ", _("Enterprise"));
1191
 
        }
1192
 
        if (str->len > 0)
1193
 
                g_string_set_size (str, str->len - 2);
1194
 
        else {
1195
 
                /* TRANSLATORS: this no (!) WiFi security */
1196
 
                g_string_append (str, _("None"));
1197
 
        }
1198
 
        return g_string_free (str, FALSE);
1199
 
}
1200
 
 
1201
 
static gchar *
1202
 
get_ipv4_config_address_as_string (NMIP4Config *ip4_config, const char *what)
1203
 
{
1204
 
        const GSList *list;
1205
 
        struct in_addr addr;
1206
 
        gchar *str = NULL;
1207
 
        gchar tmp[INET_ADDRSTRLEN];
1208
 
        NMIP4Address *address;
1209
 
 
1210
 
        /* get address */
1211
 
        list = nm_ip4_config_get_addresses (ip4_config);
1212
 
        if (list == NULL)
1213
 
                goto out;
1214
 
 
1215
 
        /* we only care about one address */
1216
 
        address = list->data;
1217
 
        if (!strcmp (what, "address"))
1218
 
                addr.s_addr = nm_ip4_address_get_address (address);
1219
 
        else if (!strcmp (what, "gateway"))
1220
 
                addr.s_addr = nm_ip4_address_get_gateway (address);
1221
 
        else if (!strcmp (what, "netmask"))
1222
 
                addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip4_address_get_prefix (address));
1223
 
        else
1224
 
                goto out;
1225
 
 
1226
 
        if (!inet_ntop (AF_INET, &addr, tmp, sizeof(tmp)))
1227
 
                goto out;
1228
 
        str = g_strdup (tmp);
1229
 
out:
1230
 
        return str;
1231
 
}
1232
 
 
1233
 
static gchar *
1234
 
get_ipv4_config_name_servers_as_string (NMIP4Config *ip4_config)
1235
 
{
1236
 
        const GArray *array;
1237
 
        GString *dns;
1238
 
        struct in_addr addr;
1239
 
        gchar tmp[INET_ADDRSTRLEN];
1240
 
        int i;
1241
 
 
1242
 
        dns = g_string_new (NULL);
1243
 
 
1244
 
        array = nm_ip4_config_get_nameservers (ip4_config);
1245
 
        if (array) {
1246
 
                for (i = 0; i < array->len; i++) {
1247
 
                        addr.s_addr = g_array_index (array, guint32, i);
1248
 
                        if (inet_ntop (AF_INET, &addr, tmp, sizeof(tmp)))
1249
 
                                g_string_append_printf (dns, "%s ", tmp);
1250
 
                }
1251
 
        }
1252
 
 
1253
 
        return g_string_free (dns, FALSE);
1254
 
}
1255
 
 
1256
 
static gchar *
1257
 
get_ipv6_config_address_as_string (NMIP6Config *ip6_config)
1258
 
{
1259
 
        const GSList *list;
1260
 
        const struct in6_addr *addr;
1261
 
        gchar *str = NULL;
1262
 
        gchar tmp[INET6_ADDRSTRLEN];
1263
 
        NMIP6Address *address;
1264
 
 
1265
 
        /* get address */
1266
 
        list = nm_ip6_config_get_addresses (ip6_config);
1267
 
        if (list == NULL)
1268
 
                goto out;
1269
 
 
1270
 
        /* we only care about one address */
1271
 
        address = list->data;
1272
 
        addr = nm_ip6_address_get_address (address);
1273
 
        if (addr == NULL)
1274
 
                goto out;
1275
 
        inet_ntop (AF_INET6, addr, tmp, sizeof(tmp));
1276
 
        str = g_strdup (tmp);
1277
 
out:
1278
 
        return str;
1279
 
}
1280
 
 
1281
 
static NMConnection *
1282
 
find_connection_for_device (CcNetworkPanel *panel,
1283
 
                            NMDevice       *device)
1284
 
{
1285
 
        const GPtrArray *connections;
1286
 
        const GPtrArray *devices;
1287
 
        NMActiveConnection *c;
1288
 
        gint i;
1289
 
 
1290
 
        connections = nm_client_get_active_connections (panel->priv->client);
1291
 
        if (connections == NULL) {
1292
 
                return NULL;
1293
 
        }
1294
 
 
1295
 
        for (i = 0; i < connections->len; i++) {
1296
 
                c = (NMActiveConnection *)connections->pdata[i];
1297
 
 
1298
 
                devices = nm_active_connection_get_devices (c);
1299
 
                if (devices && devices->pdata[0] == device) {
1300
 
                        return (NMConnection *)nm_remote_settings_get_connection_by_path (panel->priv->remote_settings, nm_active_connection_get_connection (c));
1301
 
                }
1302
 
        }
1303
 
 
1304
 
        return NULL;
1305
 
}
1306
 
 
1307
 
static void
1308
 
device_off_toggled (GtkSwitch      *sw,
1309
 
                    GParamSpec     *pspec,
1310
 
                    CcNetworkPanel *panel)
1311
 
{
1312
 
        NMDevice *device;
1313
 
        gboolean active;
1314
 
        NetObject *object;
1315
 
 
1316
 
        if (panel->priv->updating_device)
1317
 
                return;
1318
 
 
1319
 
        active = gtk_switch_get_active (sw);
1320
 
 
1321
 
        object = get_selected_object (panel);
1322
 
        if (NET_IS_VPN (object)) {
1323
 
 
1324
 
                NMConnection *connection;
1325
 
 
1326
 
                connection = net_vpn_get_connection (NET_VPN (object));
1327
 
                if (active)
1328
 
                        nm_client_activate_connection (panel->priv->client,
1329
 
                                                       connection, NULL, NULL,
1330
 
                                                       NULL, NULL);
1331
 
                else {
1332
 
                        const gchar *path;
1333
 
                        NMActiveConnection *a;
1334
 
                        const GPtrArray *acs;
1335
 
                        gint i;
1336
 
 
1337
 
                        path = nm_connection_get_path (connection);
1338
 
 
1339
 
                        acs = nm_client_get_active_connections (panel->priv->client);
1340
 
                        for (i = 0; i < acs->len; i++) {
1341
 
                                a = (NMActiveConnection*)acs->pdata[i];
1342
 
                                if (strcmp (nm_active_connection_get_connection (a), path) == 0) {
1343
 
                                        nm_client_deactivate_connection (panel->priv->client, a);
1344
 
                                        break;
1345
 
                                }
1346
 
                        }
1347
 
                }
1348
 
        }
1349
 
 
1350
 
        if (NET_IS_DEVICE (object)) {
1351
 
                device = net_device_get_nm_device (NET_DEVICE (object));
1352
 
                switch (nm_device_get_device_type (device)) {
1353
 
                case NM_DEVICE_TYPE_ETHERNET:
1354
 
                        if (active) {
1355
 
                                GSList *list, *filtered;
1356
 
 
1357
 
                                /* look for an existing connection we can use */
1358
 
                                list = nm_remote_settings_list_connections (panel->priv->remote_settings);
1359
 
                                filtered = nm_device_filter_connections (device, list);
1360
 
                                if (filtered) {
1361
 
                                        nm_client_activate_connection (panel->priv->client,
1362
 
                                                                       (NMConnection *)filtered->data,
1363
 
                                                                       device,
1364
 
                                                                       NULL,
1365
 
                                                                       NULL, NULL);
1366
 
                                } else {
1367
 
                                        nm_client_add_and_activate_connection (panel->priv->client,
1368
 
                                                                               NULL,
1369
 
                                                                               device,
1370
 
                                                                               NULL,
1371
 
                                                                               NULL, NULL);
1372
 
                                }
1373
 
 
1374
 
                                g_slist_free (list);
1375
 
                                g_slist_free (filtered);
1376
 
                        } else {
1377
 
                                nm_device_disconnect (device, NULL, NULL);
1378
 
                        }
1379
 
                        break;
1380
 
                case NM_DEVICE_TYPE_WIFI:
1381
 
                        nm_client_wireless_set_enabled (panel->priv->client, active);
1382
 
                        break;
1383
 
                case NM_DEVICE_TYPE_WIMAX:
1384
 
                        nm_client_wimax_set_enabled (panel->priv->client, active);
1385
 
                        break;
1386
 
                case NM_DEVICE_TYPE_MODEM:
1387
 
                        nm_client_wwan_set_enabled (panel->priv->client, active);
1388
 
                        break;
1389
 
                default: ;
1390
 
                        /* FIXME: handle other device types */
1391
 
                }
1392
 
        }
1393
 
}
1394
 
 
1395
 
static void
1396
 
wireless_enabled_toggled (NMClient       *client,
1397
 
                          GParamSpec     *pspec,
1398
 
                          CcNetworkPanel *panel)
1399
 
{
1400
 
        gboolean enabled;
1401
 
        GtkSwitch *sw;
1402
 
        NMDevice *device;
1403
 
        NetObject *object;
1404
 
 
1405
 
        object = get_selected_object (panel);
1406
 
        if (object == NULL)
1407
 
                return;
1408
 
        device = net_device_get_nm_device (NET_DEVICE (object));
1409
 
 
1410
 
        if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_WIFI)
1411
 
                return;
1412
 
 
1413
 
        enabled = nm_client_wireless_get_enabled (client);
1414
 
        sw = GTK_SWITCH (gtk_builder_get_object (panel->priv->builder,
1415
 
                                                 "device_wireless_off_switch"));
1416
 
 
1417
 
        panel->priv->updating_device = TRUE;
1418
 
        gtk_switch_set_active (sw, enabled);
1419
 
        panel->priv->updating_device = FALSE;
1420
 
}
1421
 
 
1422
 
static void
1423
 
wimax_enabled_toggled (NMClient       *client,
1424
 
                       GParamSpec     *pspec,
1425
 
                       CcNetworkPanel *panel)
1426
 
{
1427
 
        gboolean enabled;
1428
 
        GtkSwitch *sw;
1429
 
        NMDevice *device;
1430
 
        NetObject *object;
1431
 
 
1432
 
        object = get_selected_object (panel);
1433
 
        if (object == NULL)
1434
 
                return;
1435
 
        device = net_device_get_nm_device (NET_DEVICE (object));
1436
 
 
1437
 
        if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_WIMAX)
1438
 
                return;
1439
 
 
1440
 
        enabled = nm_client_wimax_get_enabled (client);
1441
 
        sw = GTK_SWITCH (gtk_builder_get_object (panel->priv->builder,
1442
 
                                                 "device_wimax_off_switch"));
1443
 
 
1444
 
        panel->priv->updating_device = TRUE;
1445
 
        gtk_switch_set_active (sw, enabled);
1446
 
        panel->priv->updating_device = FALSE;
1447
 
}
1448
 
 
1449
 
static void
1450
 
mobilebb_enabled_toggled (NMClient       *client,
1451
 
                          GParamSpec     *pspec,
1452
 
                          CcNetworkPanel *panel)
1453
 
{
1454
 
        gboolean enabled;
1455
 
        GtkSwitch *sw;
1456
 
        NMDevice *device;
1457
 
        NetObject *object;
1458
 
 
1459
 
        object = get_selected_object (panel);
1460
 
        if (object == NULL)
1461
 
                return;
1462
 
        device = net_device_get_nm_device (NET_DEVICE (object));
1463
 
 
1464
 
        if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_MODEM)
1465
 
                return;
1466
 
 
1467
 
        enabled = nm_client_wwan_get_enabled (client);
1468
 
        sw = GTK_SWITCH (gtk_builder_get_object (panel->priv->builder,
1469
 
                                                 "device_mobilebb_off_switch"));
1470
 
 
1471
 
        panel->priv->updating_device = TRUE;
1472
 
        gtk_switch_set_active (sw, enabled);
1473
 
        panel->priv->updating_device = FALSE;
1474
 
}
1475
 
 
1476
 
static void
1477
 
update_off_switch_from_device_state (GtkSwitch *sw, NMDeviceState state, CcNetworkPanel *panel)
1478
 
{
1479
 
        panel->priv->updating_device = TRUE;
1480
 
        switch (state) {
1481
 
                case NM_DEVICE_STATE_UNMANAGED:
1482
 
                case NM_DEVICE_STATE_UNAVAILABLE:
1483
 
                case NM_DEVICE_STATE_DISCONNECTED:
1484
 
                case NM_DEVICE_STATE_DEACTIVATING:
1485
 
                case NM_DEVICE_STATE_FAILED:
1486
 
                        gtk_switch_set_active (sw, FALSE);
1487
 
                        break;
1488
 
                default:
1489
 
                        gtk_switch_set_active (sw, TRUE);
1490
 
                        break;
1491
 
        }
1492
 
        panel->priv->updating_device = FALSE;
1493
 
}
1494
 
 
1495
 
static gboolean
1496
 
device_is_hotspot (CcNetworkPanel *panel,
1497
 
                   NMDevice *device)
1498
 
{
1499
 
        NMConnection *c;
1500
 
        NMSettingIP4Config *s_ip4;
1501
 
 
1502
 
        if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_WIFI) {
1503
 
                return FALSE;
1504
 
        }
1505
 
 
1506
 
        c = find_connection_for_device (panel, device);
1507
 
        if (c == NULL) {
1508
 
                return FALSE;
1509
 
        }
1510
 
 
1511
 
        s_ip4 = nm_connection_get_setting_ip4_config (c);
1512
 
        if (g_strcmp0 (nm_setting_ip4_config_get_method (s_ip4),
1513
 
                       NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0) {
1514
 
                return FALSE;
1515
 
        }
1516
 
 
1517
 
        return TRUE;
1518
 
}
1519
 
 
1520
 
static const GByteArray *
1521
 
device_get_hotspot_ssid (CcNetworkPanel *panel,
1522
 
                         NMDevice *device)
1523
 
{
1524
 
        NMConnection *c;
1525
 
        NMSettingWireless *sw;
1526
 
 
1527
 
        c = find_connection_for_device (panel, device);
1528
 
        if (c == NULL) {
1529
 
                return FALSE;
1530
 
        }
1531
 
 
1532
 
        sw = nm_connection_get_setting_wireless (c);
1533
 
        return nm_setting_wireless_get_ssid (sw);
1534
 
}
1535
 
 
1536
 
static void
1537
 
get_secrets_cb (NMRemoteConnection *c,
1538
 
                GHashTable         *secrets,
1539
 
                GError             *error,
1540
 
                gpointer            data)
1541
 
{
1542
 
        CcNetworkPanel *panel = data;
1543
 
        NMSettingWireless *sw;
1544
 
 
1545
 
        sw = nm_connection_get_setting_wireless (NM_CONNECTION (c));
1546
 
 
1547
 
        nm_connection_update_secrets (NM_CONNECTION (c),
1548
 
                                      nm_setting_wireless_get_security (sw),
1549
 
                                      secrets, NULL);
1550
 
 
1551
 
        refresh_ui (panel);
1552
 
}
1553
 
 
1554
 
static void
1555
 
device_get_hotspot_security_details (CcNetworkPanel *panel,
1556
 
                                     NMDevice *device,
1557
 
                                     gchar **secret,
1558
 
                                     gchar **security)
1559
 
{
1560
 
        NMConnection *c;
1561
 
        NMSettingWireless *sw;
1562
 
        NMSettingWirelessSecurity *sws;
1563
 
        const gchar *key_mgmt;
1564
 
        const gchar *tmp_secret;
1565
 
        const gchar *tmp_security;
1566
 
 
1567
 
        c = find_connection_for_device (panel, device);
1568
 
        if (c == NULL) {
1569
 
                return;
1570
 
        }
1571
 
 
1572
 
        sw = nm_connection_get_setting_wireless (c);
1573
 
        sws = nm_connection_get_setting_wireless_security (c);
1574
 
        if (sw == NULL || sws == NULL) {
1575
 
                return;
1576
 
        }
1577
 
 
1578
 
        tmp_secret = NULL;
1579
 
        tmp_security = _("None");
1580
 
 
1581
 
        key_mgmt = nm_setting_wireless_security_get_key_mgmt (sws);
1582
 
        if (strcmp (key_mgmt, "none") == 0) {
1583
 
                tmp_secret = nm_setting_wireless_security_get_wep_key (sws, 0);
1584
 
                tmp_security = _("WEP");
1585
 
        }
1586
 
        else if (strcmp (key_mgmt, "wpa-none") == 0) {
1587
 
                tmp_secret = nm_setting_wireless_security_get_psk (sws);
1588
 
                tmp_security = _("WPA");
1589
 
        } else {
1590
 
                g_warning ("unhandled security key-mgmt: %s", key_mgmt);
1591
 
        }
1592
 
 
1593
 
        /* If we don't have secrets, request them from NM and bail.
1594
 
         * We'll refresh the UI when secrets arrive.
1595
 
         */
1596
 
        if (tmp_secret == NULL) {
1597
 
                nm_remote_connection_get_secrets ((NMRemoteConnection*)c,
1598
 
                                                  nm_setting_wireless_get_security (sw),
1599
 
                                                  get_secrets_cb,
1600
 
                                                  panel);
1601
 
                return;
1602
 
        }
1603
 
 
1604
 
        if (secret) {
1605
 
                *secret = g_strdup (tmp_secret);
1606
 
        }
1607
 
 
1608
 
        if (security) {
1609
 
                *security = g_strdup (tmp_security);
1610
 
        }
1611
 
}
1612
 
 
1613
 
static void
1614
 
refresh_header_ui (CcNetworkPanel *panel, NMDevice *device, const char *page_name)
1615
 
{
1616
 
        GtkWidget *widget;
1617
 
        char *wid_name;
1618
 
        GString *str;
1619
 
        NMDeviceState state;
1620
 
        NMDeviceType type;
1621
 
        gboolean is_hotspot;
1622
 
        guint speed = 0;
1623
 
 
1624
 
        type = nm_device_get_device_type (device);
1625
 
        state = nm_device_get_state (device);
1626
 
        is_hotspot = device_is_hotspot (panel, device);
1627
 
 
1628
 
        /* set header icon */
1629
 
        wid_name = g_strdup_printf ("image_%s_device", page_name);
1630
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, wid_name));
1631
 
        g_free (wid_name);
1632
 
        gtk_image_set_from_icon_name (GTK_IMAGE (widget),
1633
 
                                      panel_device_to_icon_name (device),
1634
 
                                      GTK_ICON_SIZE_DIALOG);
1635
 
 
1636
 
        /* set device kind */
1637
 
        wid_name = g_strdup_printf ("label_%s_device", page_name);
1638
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, wid_name));
1639
 
        g_free (wid_name);
1640
 
        gtk_label_set_label (GTK_LABEL (widget),
1641
 
                             panel_device_to_localized_string (device));
1642
 
 
1643
 
        /* set up the device on/off switch */
1644
 
        wid_name = g_strdup_printf ("device_%s_off_switch", page_name);
1645
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, wid_name));
1646
 
        g_free (wid_name);
1647
 
 
1648
 
        /* keep this in sync with the signal handler setup in cc_network_panel_init */
1649
 
        switch (type) {
1650
 
        case NM_DEVICE_TYPE_ETHERNET:
1651
 
                gtk_widget_set_visible (widget,
1652
 
                                        state != NM_DEVICE_STATE_UNAVAILABLE
1653
 
                                        && state != NM_DEVICE_STATE_UNMANAGED);
1654
 
                update_off_switch_from_device_state (GTK_SWITCH (widget), state, panel);
1655
 
                if (state != NM_DEVICE_STATE_UNAVAILABLE)
1656
 
                        speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (device));
1657
 
                break;
1658
 
        case NM_DEVICE_TYPE_WIFI:
1659
 
                gtk_widget_show (widget);
1660
 
                wireless_enabled_toggled (panel->priv->client, NULL, panel);
1661
 
                if (state != NM_DEVICE_STATE_UNAVAILABLE)
1662
 
                        speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (device));
1663
 
                speed /= 1000;
1664
 
                break;
1665
 
        case NM_DEVICE_TYPE_WIMAX:
1666
 
                gtk_widget_show (widget);
1667
 
                wimax_enabled_toggled (panel->priv->client, NULL, panel);
1668
 
                break;
1669
 
        case NM_DEVICE_TYPE_MODEM:
1670
 
                gtk_widget_show (widget);
1671
 
                mobilebb_enabled_toggled (panel->priv->client, NULL, panel);
1672
 
                break;
1673
 
        default:
1674
 
                gtk_widget_hide (widget);
1675
 
                break;
1676
 
        }
1677
 
 
1678
 
        /* set device state, with status and optionally speed */
1679
 
        wid_name = g_strdup_printf ("label_%s_status", page_name);
1680
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, wid_name));
1681
 
        g_free (wid_name);
1682
 
        if (is_hotspot) {
1683
 
                str = g_string_new (_("Hotspot"));
1684
 
        } else {
1685
 
                str = g_string_new (panel_device_state_to_localized_string (device));
1686
 
        }
1687
 
        if (speed  > 0) {
1688
 
                g_string_append (str, " - ");
1689
 
                /* Translators: network device speed */
1690
 
                g_string_append_printf (str, _("%d Mb/s"), speed);
1691
 
        }
1692
 
        gtk_label_set_label (GTK_LABEL (widget), str->str);
1693
 
 
1694
 
        /* set up options button */
1695
 
        wid_name = g_strdup_printf ("button_%s_options", page_name);
1696
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, wid_name));
1697
 
        g_free (wid_name);
1698
 
        if (widget != NULL) {
1699
 
                gtk_widget_set_sensitive (widget, find_connection_for_device (panel, device) != NULL);
1700
 
        }
1701
 
        g_string_free (str, TRUE);
1702
 
}
1703
 
 
1704
 
static void
1705
 
device_refresh_ethernet_ui (CcNetworkPanel *panel, NetDevice *device)
1706
 
{
1707
 
        const char *str;
1708
 
        NMDevice *nm_device;
1709
 
 
1710
 
        nm_device = net_device_get_nm_device (device);
1711
 
 
1712
 
        refresh_header_ui (panel, nm_device, "wired");
1713
 
 
1714
 
        /* device MAC */
1715
 
        str = nm_device_ethernet_get_hw_address (NM_DEVICE_ETHERNET (nm_device));
1716
 
        panel_set_widget_data (panel,
1717
 
                               "wired",
1718
 
                               "mac",
1719
 
                               str);
1720
 
 
1721
 
}
1722
 
 
1723
 
static void
1724
 
device_refresh_wifi_ui (CcNetworkPanel *panel, NetDevice *device)
1725
 
{
1726
 
        GtkWidget *widget;
1727
 
        GtkWidget *sw;
1728
 
        const GPtrArray *aps;
1729
 
        GPtrArray *aps_unique = NULL;
1730
 
        GtkWidget *heading;
1731
 
        NMDeviceState state;
1732
 
        NMAccessPoint *ap;
1733
 
        NMAccessPoint *active_ap;
1734
 
        const char *str;
1735
 
        gchar *str_tmp;
1736
 
        GtkListStore *liststore_wireless_network;
1737
 
        guint i;
1738
 
        NMDevice *nm_device;
1739
 
        NMClientPermissionResult perm;
1740
 
        gboolean is_hotspot;
1741
 
        gchar *hotspot_ssid;
1742
 
        gchar *hotspot_secret;
1743
 
        gchar *hotspot_security;
1744
 
        gboolean can_start_hotspot;
1745
 
 
1746
 
        nm_device = net_device_get_nm_device (device);
1747
 
        state = nm_device_get_state (nm_device);
1748
 
 
1749
 
        refresh_header_ui (panel, nm_device, "wireless");
1750
 
 
1751
 
        /* sort out hotspot ui */
1752
 
        is_hotspot = device_is_hotspot (panel, nm_device);
1753
 
        hotspot_ssid = NULL;
1754
 
        hotspot_secret = NULL;
1755
 
        hotspot_security = NULL;
1756
 
        if (is_hotspot) {
1757
 
                const GByteArray *ssid;
1758
 
                ssid = device_get_hotspot_ssid (panel, nm_device);
1759
 
                if (ssid) {
1760
 
                        hotspot_ssid = nm_utils_ssid_to_utf8 (ssid);
1761
 
                }
1762
 
                device_get_hotspot_security_details (panel, nm_device, &hotspot_secret, &hotspot_security);
1763
 
        }
1764
 
 
1765
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1766
 
                                                     "start_hotspot_button"));
1767
 
        gtk_widget_set_visible (widget, !is_hotspot);
1768
 
 
1769
 
        sw = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1770
 
                                                 "device_wireless_off_switch"));
1771
 
        perm = nm_client_get_permission_result (panel->priv->client, NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN);
1772
 
        can_start_hotspot = gtk_switch_get_active (GTK_SWITCH (sw)) &&
1773
 
                            (perm == NM_CLIENT_PERMISSION_RESULT_YES ||
1774
 
                             perm == NM_CLIENT_PERMISSION_RESULT_AUTH);
1775
 
        gtk_widget_set_sensitive (widget, can_start_hotspot);
1776
 
 
1777
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1778
 
                                                     "stop_hotspot_button"));
1779
 
        gtk_widget_set_visible (widget, is_hotspot);
1780
 
 
1781
 
        panel_set_widget_data (panel, "hotspot", "network_name", hotspot_ssid);
1782
 
        g_free (hotspot_ssid);
1783
 
 
1784
 
        panel_set_widget_data (panel, "hotspot", "security_key", hotspot_secret);
1785
 
        g_free (hotspot_secret);
1786
 
 
1787
 
        /* device MAC */
1788
 
        str = nm_device_wifi_get_hw_address (NM_DEVICE_WIFI (nm_device));
1789
 
        panel_set_widget_data (panel,
1790
 
                               "wireless",
1791
 
                               "mac",
1792
 
                               str);
1793
 
        /* security */
1794
 
        active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (nm_device));
1795
 
        if (state == NM_DEVICE_STATE_UNAVAILABLE)
1796
 
                str_tmp = NULL;
1797
 
        else if (is_hotspot)
1798
 
                str_tmp = hotspot_security;
1799
 
        else if (active_ap != NULL)
1800
 
                str_tmp = get_ap_security_string (active_ap);
1801
 
        else
1802
 
                str_tmp = g_strdup ("");
1803
 
        panel_set_widget_data (panel,
1804
 
                               "wireless",
1805
 
                               "security",
1806
 
                               str_tmp);
1807
 
        g_free (str_tmp);
1808
 
 
1809
 
        heading = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1810
 
                                                      "heading_wireless_network_name"));
1811
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1812
 
                                                     "combobox_wireless_network_name"));
1813
 
        /* populate access point dropdown */
1814
 
        if (is_hotspot || state == NM_DEVICE_STATE_UNAVAILABLE) {
1815
 
                gtk_widget_hide (heading);
1816
 
                gtk_widget_hide (widget);
1817
 
        } else {
1818
 
                gtk_widget_show (heading);
1819
 
                gtk_widget_show (widget);
1820
 
                liststore_wireless_network = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
1821
 
                                                                                     "liststore_wireless_network"));
1822
 
                panel->priv->updating_device = TRUE;
1823
 
                gtk_list_store_clear (liststore_wireless_network);
1824
 
                aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (nm_device));
1825
 
                aps_unique = panel_get_strongest_unique_aps (aps);
1826
 
 
1827
 
                for (i = 0; i < aps_unique->len; i++) {
1828
 
                        ap = NM_ACCESS_POINT (g_ptr_array_index (aps_unique, i));
1829
 
                        add_access_point (panel, ap, active_ap, nm_device);
1830
 
                }
1831
 
                add_access_point_other (panel);
1832
 
                if (active_ap == NULL) {
1833
 
                        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1834
 
                                                                     "combobox_wireless_network_name"));
1835
 
                        gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), NULL);
1836
 
                        gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (widget))), "");
1837
 
                }
1838
 
 
1839
 
                panel->priv->updating_device = FALSE;
1840
 
 
1841
 
                g_ptr_array_unref (aps_unique);
1842
 
        }
1843
 
 
1844
 
        /* setup wireless button */
1845
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1846
 
                                                     "button_wireless_button"));
1847
 
        gtk_widget_set_visible (widget, active_ap != NULL);
1848
 
}
1849
 
 
1850
 
static void
1851
 
device_refresh_wimax_ui (CcNetworkPanel *panel, NetDevice *device)
1852
 
{
1853
 
        NMDevice *nm_device;
1854
 
 
1855
 
        nm_device = net_device_get_nm_device (device);
1856
 
        refresh_header_ui (panel, nm_device, "wimax");
1857
 
}
1858
 
 
1859
 
static void
1860
 
device_refresh_modem_ui (CcNetworkPanel *panel, NetDevice *device)
1861
 
{
1862
 
        NMDeviceModemCapabilities caps;
1863
 
        NMDevice *nm_device;
1864
 
        const char *str;
1865
 
 
1866
 
        nm_device = net_device_get_nm_device (device);
1867
 
 
1868
 
        refresh_header_ui (panel, nm_device, "mobilebb");
1869
 
 
1870
 
        caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (nm_device));
1871
 
 
1872
 
        if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
1873
 
            (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
1874
 
                /* IMEI */
1875
 
                str = g_object_get_data (G_OBJECT (nm_device),
1876
 
                                         "ControlCenter::EquipmentIdentifier");
1877
 
                panel_set_widget_data (panel,
1878
 
                                       "mobilebb",
1879
 
                                       "imei",
1880
 
                                       str);
1881
 
 
1882
 
                /* operator name */
1883
 
                str = g_object_get_data (G_OBJECT (nm_device),
1884
 
                                         "ControlCenter::OperatorName");
1885
 
                panel_set_widget_data (panel,
1886
 
                                       "mobilebb",
1887
 
                                       "provider",
1888
 
                                       str);
1889
 
 
1890
 
                /* device speed */
1891
 
                panel_set_widget_data (panel,
1892
 
                                       "mobilebb",
1893
 
                                       "speed",
1894
 
                                       NULL);
1895
 
        }
1896
 
}
1897
 
 
1898
 
static void
1899
 
nm_device_refresh_device_ui (CcNetworkPanel *panel, NetDevice *device)
1900
 
{
1901
 
        CcNetworkPanelPrivate *priv = panel->priv;
1902
 
        const gchar *sub_pane = NULL;
1903
 
        gchar *str_tmp;
1904
 
        GtkWidget *widget;
1905
 
        NMDeviceType type;
1906
 
        NMIP4Config *ip4_config = NULL;
1907
 
        NMIP6Config *ip6_config = NULL;
1908
 
        NMDevice *nm_device;
1909
 
        gboolean has_ip4;
1910
 
        gboolean has_ip6;
1911
 
        gboolean is_hotspot;
1912
 
 
1913
 
        /* we have a new device */
1914
 
        nm_device = net_device_get_nm_device (device);
1915
 
        type = nm_device_get_device_type (nm_device);
1916
 
        is_hotspot = device_is_hotspot (panel, nm_device);
1917
 
        g_debug ("device %s type %i", nm_device_get_udi (nm_device), type);
1918
 
 
1919
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "notebook_types"));
1920
 
 
1921
 
        switch (type) {
1922
 
        case NM_DEVICE_TYPE_ETHERNET:
1923
 
                gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 0);
1924
 
                sub_pane = "wired";
1925
 
                device_refresh_ethernet_ui (panel, device);
1926
 
                break;
1927
 
        case NM_DEVICE_TYPE_WIFI:
1928
 
                gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 1);
1929
 
                sub_pane = "wireless";
1930
 
                device_refresh_wifi_ui (panel, device);
1931
 
                break;
1932
 
        case NM_DEVICE_TYPE_WIMAX:
1933
 
                device_refresh_wimax_ui (panel, device);
1934
 
                break;
1935
 
        case NM_DEVICE_TYPE_MODEM:
1936
 
                {
1937
 
                        NMDeviceModemCapabilities caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (nm_device));
1938
 
                        if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
1939
 
                            (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
1940
 
                                gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 4);
1941
 
                                sub_pane = "mobilebb";
1942
 
                                device_refresh_modem_ui (panel, device);
1943
 
                        }
1944
 
                }
1945
 
                break;
1946
 
        default:
1947
 
                g_assert_not_reached ();
1948
 
                break;
1949
 
        }
1950
 
 
1951
 
        if (sub_pane == NULL)
1952
 
                goto out;
1953
 
 
1954
 
        /* get IP4 parameters */
1955
 
        ip4_config = nm_device_get_ip4_config (nm_device);
1956
 
        if (!is_hotspot && ip4_config != NULL) {
1957
 
                /* IPv4 address */
1958
 
 
1959
 
                str_tmp = get_ipv4_config_address_as_string (ip4_config, "address");
1960
 
                panel_set_widget_data (panel,
1961
 
                                       sub_pane,
1962
 
                                       "ipv4",
1963
 
                                       str_tmp);
1964
 
                has_ip4 = str_tmp != NULL;
1965
 
                g_free (str_tmp);
1966
 
 
1967
 
                /* IPv4 DNS */
1968
 
                str_tmp = get_ipv4_config_name_servers_as_string (ip4_config);
1969
 
                panel_set_widget_data (panel,
1970
 
                                       sub_pane,
1971
 
                                       "dns",
1972
 
                                       str_tmp);
1973
 
                g_free (str_tmp);
1974
 
 
1975
 
                /* IPv4 route */
1976
 
                str_tmp = get_ipv4_config_address_as_string (ip4_config, "gateway");
1977
 
                panel_set_widget_data (panel,
1978
 
                                       sub_pane,
1979
 
                                       "route",
1980
 
                                       str_tmp);
1981
 
                g_free (str_tmp);
1982
 
 
1983
 
                /* IPv4 netmask */
1984
 
                if (type == NM_DEVICE_TYPE_ETHERNET) {
1985
 
                        str_tmp = get_ipv4_config_address_as_string (ip4_config, "netmask");
1986
 
                        panel_set_widget_data (panel,
1987
 
                                               sub_pane,
1988
 
                                               "subnet",
1989
 
                                               str_tmp);
1990
 
                        g_free (str_tmp);
1991
 
                }
1992
 
        } else {
1993
 
                /* IPv4 address */
1994
 
                panel_set_widget_data (panel,
1995
 
                                       sub_pane,
1996
 
                                       "ipv4",
1997
 
                                       NULL);
1998
 
                has_ip4 = FALSE;
1999
 
 
2000
 
                /* IPv4 DNS */
2001
 
                panel_set_widget_data (panel,
2002
 
                                       sub_pane,
2003
 
                                       "dns",
2004
 
                                       NULL);
2005
 
 
2006
 
                /* IPv4 route */
2007
 
                panel_set_widget_data (panel,
2008
 
                                       sub_pane,
2009
 
                                       "route",
2010
 
                                       NULL);
2011
 
 
2012
 
                /* IPv4 netmask */
2013
 
                if (type == NM_DEVICE_TYPE_ETHERNET) {
2014
 
                        panel_set_widget_data (panel,
2015
 
                                               sub_pane,
2016
 
                                               "subnet",
2017
 
                                               NULL);
2018
 
                }
2019
 
        }
2020
 
 
2021
 
        /* get IP6 parameters */
2022
 
        ip6_config = nm_device_get_ip6_config (nm_device);
2023
 
        if (!is_hotspot && ip6_config != NULL) {
2024
 
 
2025
 
                /* IPv6 address */
2026
 
                str_tmp = get_ipv6_config_address_as_string (ip6_config);
2027
 
                panel_set_widget_data (panel, sub_pane, "ipv6", str_tmp);
2028
 
                has_ip6 = str_tmp != NULL;
2029
 
                g_free (str_tmp);
2030
 
        } else {
2031
 
                panel_set_widget_data (panel, sub_pane, "ipv6", NULL);
2032
 
                has_ip6 = FALSE;
2033
 
        }
2034
 
 
2035
 
        if (has_ip4 && has_ip6) {
2036
 
                panel_set_widget_heading (panel, sub_pane, "ipv4", _("IPv4 Address"));
2037
 
                panel_set_widget_heading (panel, sub_pane, "ipv6", _("IPv6 Address"));
2038
 
        }
2039
 
        else if (has_ip4) {
2040
 
                panel_set_widget_heading (panel, sub_pane, "ipv4", _("IP Address"));
2041
 
        }
2042
 
        else if (has_ip6) {
2043
 
                panel_set_widget_heading (panel, sub_pane, "ipv6", _("IP Address"));
2044
 
        }
2045
 
out: ;
2046
 
}
2047
 
 
2048
 
static void
2049
 
nm_device_refresh_vpn_ui (CcNetworkPanel *panel, NetVpn *vpn)
2050
 
{
2051
 
        GtkWidget *widget;
2052
 
        GtkWidget *sw;
2053
 
        const gchar *sub_pane = "vpn";
2054
 
        const gchar *status;
2055
 
        CcNetworkPanelPrivate *priv = panel->priv;
2056
 
        const GPtrArray *acs;
2057
 
        NMActiveConnection *a;
2058
 
        gint i;
2059
 
        const gchar *path;
2060
 
        const gchar *apath;
2061
 
        NMVPNConnectionState state;
2062
 
        gchar *title;
2063
 
        GtkListStore *liststore_devices;
2064
 
        GtkTreeIter iter;
2065
 
 
2066
 
        sw = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2067
 
                                                 "device_vpn_off_switch"));
2068
 
        gtk_widget_set_visible (sw, TRUE);
2069
 
 
2070
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2071
 
                                                     "button_vpn_options"));
2072
 
        gtk_widget_set_visible (widget, TRUE);
2073
 
        gtk_widget_set_sensitive (widget, TRUE);
2074
 
 
2075
 
        /* use proxy note page */
2076
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2077
 
                                                     "notebook_types"));
2078
 
        gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 3);
2079
 
 
2080
 
        /* set VPN icon */
2081
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2082
 
                                                     "image_vpn_device"));
2083
 
        gtk_image_set_from_icon_name (GTK_IMAGE (widget),
2084
 
                                      "network-vpn",
2085
 
                                      GTK_ICON_SIZE_DIALOG);
2086
 
 
2087
 
        /* update title */
2088
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2089
 
                                                     "label_vpn_device"));
2090
 
        title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (net_vpn_get_connection (vpn)));
2091
 
        net_object_set_title (NET_OBJECT (vpn), title);
2092
 
        gtk_label_set_label (GTK_LABEL (widget), title);
2093
 
 
2094
 
        /* update list store title */
2095
 
        liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
2096
 
                                                                    "liststore_devices"));
2097
 
        if (find_model_iter_by_object (GTK_TREE_MODEL (liststore_devices), NET_OBJECT (vpn), &iter)) {
2098
 
                gtk_list_store_set (liststore_devices,
2099
 
                                    &iter,
2100
 
                                    PANEL_DEVICES_COLUMN_TITLE, title,
2101
 
                                    -1);
2102
 
        }
2103
 
        g_free (title);
2104
 
 
2105
 
        /* use status */
2106
 
        state = net_vpn_get_state (vpn);
2107
 
 
2108
 
        acs = nm_client_get_active_connections (priv->client);
2109
 
        if (acs != NULL) {
2110
 
                path = nm_connection_get_path (net_vpn_get_connection (vpn));
2111
 
                for (i = 0; i < acs->len; i++) {
2112
 
                        a = (NMActiveConnection*)acs->pdata[i];
2113
 
 
2114
 
                        apath = nm_active_connection_get_connection (a);
2115
 
                        if (NM_IS_VPN_CONNECTION (a) && strcmp (apath, path) == 0) {
2116
 
                                state = nm_vpn_connection_get_vpn_state (NM_VPN_CONNECTION (a));
2117
 
                                break;
2118
 
                        }
2119
 
                }
2120
 
        }
2121
 
 
2122
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2123
 
                                                     "label_vpn_status"));
2124
 
        status = panel_vpn_state_to_localized_string (state);
2125
 
        gtk_label_set_label (GTK_LABEL (widget), status);
2126
 
        priv->updating_device = TRUE;
2127
 
        gtk_switch_set_active (GTK_SWITCH (sw),
2128
 
                               state != NM_VPN_CONNECTION_STATE_FAILED &&
2129
 
                               state != NM_VPN_CONNECTION_STATE_DISCONNECTED);
2130
 
        priv->updating_device = FALSE;
2131
 
 
2132
 
        /* service type */
2133
 
        panel_set_widget_data (panel,
2134
 
                               sub_pane,
2135
 
                               "service_type",
2136
 
                               net_vpn_get_service_type (vpn));
2137
 
 
2138
 
        /* gateway */
2139
 
        panel_set_widget_data (panel,
2140
 
                               sub_pane,
2141
 
                               "gateway",
2142
 
                               net_vpn_get_gateway (vpn));
2143
 
 
2144
 
        /* groupname */
2145
 
        panel_set_widget_data (panel,
2146
 
                               sub_pane,
2147
 
                               "group_name",
2148
 
                               net_vpn_get_id (vpn));
2149
 
 
2150
 
        /* username */
2151
 
        panel_set_widget_data (panel,
2152
 
                               sub_pane,
2153
 
                               "username",
2154
 
                               net_vpn_get_username (vpn));
2155
 
 
2156
 
        /* password */
2157
 
        panel_set_widget_data (panel,
2158
 
                               sub_pane,
2159
 
                               "group_password",
2160
 
                               net_vpn_get_password (vpn));
2161
 
}
2162
 
 
2163
 
static gboolean
2164
 
refresh_ui_idle (gpointer data)
2165
 
{
2166
 
        CcNetworkPanel *panel = data;
2167
 
        GtkTreeSelection *selection;
2168
 
        GtkTreeIter iter;
2169
 
        GtkTreeModel *model;
2170
 
        GtkWidget *widget;
2171
 
        NetObject *object = NULL;
2172
 
        CcNetworkPanelPrivate *priv = panel->priv;
2173
 
 
2174
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2175
 
                                                     "treeview_devices"));
2176
 
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
2177
 
 
2178
 
        /* will only work in single or browse selection mode! */
2179
 
        if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
2180
 
                g_debug ("no row selected");
2181
 
                goto out;
2182
 
        }
2183
 
 
2184
 
        object = get_selected_object (panel);
2185
 
 
2186
 
        /* this is the proxy settings device */
2187
 
        if (object == NULL) {
2188
 
 
2189
 
                /* set header to something sane */
2190
 
                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2191
 
                                                             "image_proxy_device"));
2192
 
                gtk_image_set_from_icon_name (GTK_IMAGE (widget),
2193
 
                                              "preferences-system-network",
2194
 
                                              GTK_ICON_SIZE_DIALOG);
2195
 
                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2196
 
                                                             "label_proxy_device"));
2197
 
                gtk_label_set_label (GTK_LABEL (widget),
2198
 
                                     _("Proxy"));
2199
 
                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2200
 
                                                             "label_proxy_status"));
2201
 
                gtk_label_set_label (GTK_LABEL (widget), "");
2202
 
 
2203
 
                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2204
 
                                                             "notebook_types"));
2205
 
                gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 2);
2206
 
 
2207
 
                /* hide the switch until we get some more detail in the mockup */
2208
 
                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2209
 
                                                             "device_proxy_off_switch"));
2210
 
                if (widget != NULL)
2211
 
                        gtk_widget_hide (widget);
2212
 
 
2213
 
                /* we shoulnd't be able to delete the proxy device */
2214
 
                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2215
 
                                                             "remove_toolbutton"));
2216
 
                gtk_widget_set_sensitive (widget, FALSE);
2217
 
                goto out;
2218
 
        }
2219
 
 
2220
 
        /* VPN */
2221
 
        if (NET_IS_VPN (object)) {
2222
 
                nm_device_refresh_vpn_ui (panel, NET_VPN (object));
2223
 
 
2224
 
                /* we're able to remove the VPN connection */
2225
 
                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2226
 
                                                             "remove_toolbutton"));
2227
 
                gtk_widget_set_sensitive (widget, TRUE);
2228
 
                goto out;
2229
 
        }
2230
 
 
2231
 
        /* device */
2232
 
        if (NET_IS_DEVICE (object)) {
2233
 
 
2234
 
                /* we're not yet able to remove the connection */
2235
 
                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2236
 
                                                             "remove_toolbutton"));
2237
 
                gtk_widget_set_sensitive (widget, FALSE);
2238
 
 
2239
 
                /* refresh device */
2240
 
                nm_device_refresh_device_ui (panel, NET_DEVICE (object));
2241
 
        }
2242
 
out:
2243
 
        priv->refresh_idle = 0;
2244
 
 
2245
 
        return FALSE;
2246
 
}
2247
 
 
2248
 
static void
2249
 
refresh_ui (CcNetworkPanel *panel)
2250
 
{
2251
 
        if (panel->priv->refresh_idle != 0)
2252
 
                return;
2253
 
 
2254
 
        panel->priv->refresh_idle = g_idle_add (refresh_ui_idle, panel);
2255
 
}
2256
 
 
2257
 
static void
2258
 
nm_devices_treeview_clicked_cb (GtkTreeSelection *selection, CcNetworkPanel *panel)
2259
 
{
2260
 
        refresh_ui (panel);
2261
 
}
2262
 
 
2263
 
static void
2264
 
panel_add_proxy_device (CcNetworkPanel *panel)
2265
 
{
2266
 
        gchar *title;
2267
 
        GtkListStore *liststore_devices;
2268
 
        GtkTreeIter iter;
2269
 
 
2270
 
        liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
2271
 
                                            "liststore_devices"));
2272
 
        title = g_strdup_printf ("%s", _("Network proxy"));
2273
 
 
2274
 
        gtk_list_store_append (liststore_devices, &iter);
2275
 
        gtk_list_store_set (liststore_devices,
2276
 
                            &iter,
2277
 
                            PANEL_DEVICES_COLUMN_ICON, "preferences-system-network",
2278
 
                            PANEL_DEVICES_COLUMN_TITLE, title,
2279
 
                            PANEL_DEVICES_COLUMN_SORT, "9",
2280
 
                            PANEL_DEVICES_COLUMN_OBJECT, NULL,
2281
 
                            -1);
2282
 
        g_free (title);
2283
 
}
2284
 
 
2285
 
static void
2286
 
cc_network_panel_notify_enable_active_cb (GtkSwitch *sw,
2287
 
                                          GParamSpec *pspec,
2288
 
                                          CcNetworkPanel *panel)
2289
 
{
2290
 
        gboolean enable;
2291
 
 
2292
 
        /* set enabled state */
2293
 
        enable = !gtk_switch_get_active (sw);
2294
 
        nm_client_wireless_set_enabled (panel->priv->client, enable);
2295
 
}
2296
 
 
2297
 
static void
2298
 
connection_state_changed (NMActiveConnection *c, GParamSpec *pspec, CcNetworkPanel *panel)
2299
 
{
2300
 
        refresh_ui (panel);
2301
 
}
2302
 
 
2303
 
static void
2304
 
active_connections_changed (NMClient *client, GParamSpec *pspec, gpointer user_data)
2305
 
{
2306
 
        CcNetworkPanel *panel = user_data;
2307
 
        const GPtrArray *connections;
2308
 
        int i, j;
2309
 
 
2310
 
        g_debug ("Active connections changed:");
2311
 
        connections = nm_client_get_active_connections (client);
2312
 
        for (i = 0; connections && (i < connections->len); i++) {
2313
 
                NMActiveConnection *connection;
2314
 
                const GPtrArray *devices;
2315
 
 
2316
 
                connection = g_ptr_array_index (connections, i);
2317
 
                g_debug ("    %s", nm_object_get_path (NM_OBJECT (connection)));
2318
 
                devices = nm_active_connection_get_devices (connection);
2319
 
                for (j = 0; devices && j < devices->len; j++)
2320
 
                        g_debug ("           %s", nm_device_get_udi (g_ptr_array_index (devices, j)));
2321
 
                if (NM_IS_VPN_CONNECTION (connection))
2322
 
                        g_debug ("           VPN base connection: %s", nm_active_connection_get_specific_object (connection));
2323
 
 
2324
 
                if (g_object_get_data (G_OBJECT (connection), "has-state-changed-handler") == NULL) {
2325
 
                        g_signal_connect_object (connection, "notify::state",
2326
 
                                                 G_CALLBACK (connection_state_changed), panel, 0);
2327
 
                        g_object_set_data (G_OBJECT (connection), "has-state-changed-handler", GINT_TO_POINTER (TRUE));
2328
 
                }
2329
 
        }
2330
 
 
2331
 
        refresh_ui (panel);
2332
 
}
2333
 
 
2334
 
static void
2335
 
device_added_cb (NMClient *client, NMDevice *device, CcNetworkPanel *panel)
2336
 
{
2337
 
        g_debug ("New device added");
2338
 
        panel_add_device (panel, device);
2339
 
        panel_refresh_killswitch_visibility (panel);
2340
 
}
2341
 
 
2342
 
static void
2343
 
device_removed_cb (NMClient *client, NMDevice *device, CcNetworkPanel *panel)
2344
 
{
2345
 
        g_debug ("Device removed");
2346
 
        panel_remove_device (panel, device);
2347
 
        panel_refresh_killswitch_visibility (panel);
2348
 
}
2349
 
 
2350
 
static void
2351
 
manager_running (NMClient *client, GParamSpec *pspec, gpointer user_data)
2352
 
{
2353
 
        const GPtrArray *devices;
2354
 
        int i;
2355
 
        NMDevice *device_tmp;
2356
 
        GtkListStore *liststore_devices;
2357
 
        gboolean selected = FALSE;
2358
 
        CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);
2359
 
 
2360
 
        /* clear all devices we added */
2361
 
        if (!nm_client_get_manager_running (client)) {
2362
 
                g_debug ("NM disappeared");
2363
 
                liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
2364
 
                                                    "liststore_devices"));
2365
 
                gtk_list_store_clear (liststore_devices);
2366
 
                panel_add_proxy_device (panel);
2367
 
                goto out;
2368
 
        }
2369
 
 
2370
 
        g_debug ("coldplugging devices");
2371
 
        devices = nm_client_get_devices (client);
2372
 
        if (devices == NULL) {
2373
 
                g_debug ("No devices to add");
2374
 
                return;
2375
 
        }
2376
 
        for (i = 0; i < devices->len; i++) {
2377
 
                device_tmp = g_ptr_array_index (devices, i);
2378
 
                selected = panel_add_device (panel, device_tmp) || selected;
2379
 
        }
2380
 
out:
2381
 
        if (!selected) {
2382
 
                /* select the first device */
2383
 
                select_first_device (panel);
2384
 
        }
2385
 
}
2386
 
 
2387
 
static NetObject *
2388
 
find_in_model_by_id (CcNetworkPanel *panel, const gchar *id)
2389
 
{
2390
 
        gboolean ret;
2391
 
        NetObject *object_tmp;
2392
 
        GtkTreeIter iter;
2393
 
        GtkTreeModel *model;
2394
 
        NetObject *object = NULL;
2395
 
 
2396
 
        /* find in model */
2397
 
        model = GTK_TREE_MODEL (gtk_builder_get_object (panel->priv->builder,
2398
 
                                                        "liststore_devices"));
2399
 
        ret = gtk_tree_model_get_iter_first (model, &iter);
2400
 
        if (!ret)
2401
 
                goto out;
2402
 
 
2403
 
        /* get the other elements */
2404
 
        ret = FALSE;
2405
 
        do {
2406
 
                gtk_tree_model_get (model, &iter,
2407
 
                                    PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
2408
 
                                    -1);
2409
 
                if (object_tmp != NULL) {
2410
 
                        g_debug ("got %s", net_object_get_id (object_tmp));
2411
 
                        if (g_strcmp0 (net_object_get_id (object_tmp), id) == 0)
2412
 
                                object = object_tmp;
2413
 
                        g_object_unref (object_tmp);
2414
 
                }
2415
 
        } while (object == NULL && gtk_tree_model_iter_next (model, &iter));
2416
 
out:
2417
 
        return object;
2418
 
}
2419
 
 
2420
 
static gboolean
2421
 
find_model_iter_by_object (GtkTreeModel *model, const NetObject *object, GtkTreeIter *iter)
2422
 
{
2423
 
        gboolean valid;
2424
 
        NetObject *object_tmp;
2425
 
 
2426
 
        /* find iter in model according to the passed object */
2427
 
        valid = gtk_tree_model_get_iter_first (model, iter);
2428
 
        while (valid) {
2429
 
                gtk_tree_model_get (model, iter,
2430
 
                                    PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
2431
 
                                    -1);
2432
 
                if (object_tmp != NULL)
2433
 
                        g_object_unref (object_tmp);
2434
 
                if (object_tmp == object)
2435
 
                        return TRUE;
2436
 
                valid = gtk_tree_model_iter_next (model, iter);
2437
 
        }
2438
 
 
2439
 
        return FALSE;
2440
 
}
2441
 
 
2442
 
static void
2443
 
panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection)
2444
 
{
2445
 
        gchar *title;
2446
 
        gchar *title_markup;
2447
 
        GtkListStore *liststore_devices;
2448
 
        GtkTreeIter iter;
2449
 
        NetVpn *net_vpn;
2450
 
        const gchar *id;
2451
 
 
2452
 
        /* does already exist */
2453
 
        id = nm_connection_get_path (connection);
2454
 
        if (find_in_model_by_id (panel, id) != NULL)
2455
 
                return;
2456
 
 
2457
 
        /* add as a virtual object */
2458
 
        net_vpn = net_vpn_new ();
2459
 
        net_vpn_set_connection (net_vpn, connection);
2460
 
        net_object_set_id (NET_OBJECT (net_vpn), id);
2461
 
        register_object_interest (panel, NET_OBJECT (net_vpn));
2462
 
 
2463
 
        liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
2464
 
                                            "liststore_devices"));
2465
 
        title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (connection));
2466
 
        title_markup = g_strdup (title);
2467
 
 
2468
 
        net_object_set_title (NET_OBJECT (net_vpn), title);
2469
 
        gtk_list_store_append (liststore_devices, &iter);
2470
 
        gtk_list_store_set (liststore_devices,
2471
 
                            &iter,
2472
 
                            PANEL_DEVICES_COLUMN_ICON, "network-vpn",
2473
 
                            PANEL_DEVICES_COLUMN_TITLE, title_markup,
2474
 
                            PANEL_DEVICES_COLUMN_SORT, "5",
2475
 
                            PANEL_DEVICES_COLUMN_OBJECT, net_vpn,
2476
 
                            -1);
2477
 
        g_free (title);
2478
 
        g_free (title_markup);
2479
 
}
2480
 
 
2481
 
static void
2482
 
add_connection (CcNetworkPanel *panel,
2483
 
                NMConnection *connection)
2484
 
{
2485
 
        NMSettingConnection *s_con;
2486
 
        const gchar *type;
2487
 
 
2488
 
        s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection,
2489
 
                                                                  NM_TYPE_SETTING_CONNECTION));
2490
 
        type = nm_setting_connection_get_connection_type (s_con);
2491
 
        if (g_strcmp0 (type, "vpn") != 0)
2492
 
                return;
2493
 
        g_debug ("add %s/%s remote connection: %s",
2494
 
                 type, g_type_name_from_instance ((GTypeInstance*)connection),
2495
 
                 nm_connection_get_path (connection));
2496
 
        panel_add_vpn_device (panel, connection);
2497
 
}
2498
 
 
2499
 
static void
2500
 
notify_new_connection_cb (NMRemoteSettings *settings,
2501
 
                          NMRemoteConnection *connection,
2502
 
                          CcNetworkPanel *panel)
2503
 
{
2504
 
        add_connection (panel, NM_CONNECTION (connection));
2505
 
}
2506
 
 
2507
 
static void
2508
 
notify_connections_read_cb (NMRemoteSettings *settings,
2509
 
                            CcNetworkPanel *panel)
2510
 
{
2511
 
        GSList *list, *iter;
2512
 
        NMConnection *connection;
2513
 
 
2514
 
        list = nm_remote_settings_list_connections (settings);
2515
 
        g_debug ("%p has %i remote connections",
2516
 
                 panel, g_slist_length (list));
2517
 
        for (iter = list; iter; iter = g_slist_next (iter)) {
2518
 
                connection = NM_CONNECTION (iter->data);
2519
 
                add_connection (panel, connection);
2520
 
        }
2521
 
}
2522
 
 
2523
 
static gboolean
2524
 
display_version_warning_idle (CcNetworkPanel *panel)
2525
 
{
2526
 
        GtkWidget  *dialog;
2527
 
        GtkWidget  *image;
2528
 
        GtkWindow  *window;
2529
 
        const char *message;
2530
 
 
2531
 
        /* TRANSLATORS: the user is running a NM that is not API compatible */
2532
 
        message = _("The system network services are not compatible with this version.");
2533
 
 
2534
 
        window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel)));
2535
 
        dialog = gtk_message_dialog_new (window,
2536
 
                                         GTK_DIALOG_MODAL,
2537
 
                                         GTK_MESSAGE_ERROR,
2538
 
                                         GTK_BUTTONS_CLOSE,
2539
 
                                         "%s",
2540
 
                                         message);
2541
 
        image = gtk_image_new_from_icon_name ("computer-fail", GTK_ICON_SIZE_DIALOG);
2542
 
        gtk_widget_show (image);
2543
 
        gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
2544
 
 
2545
 
        gtk_dialog_run (GTK_DIALOG (dialog));
2546
 
        gtk_widget_destroy (dialog);
2547
 
 
2548
 
        return FALSE;
2549
 
}
2550
 
 
2551
 
static gboolean
2552
 
panel_check_network_manager_version (CcNetworkPanel *panel)
2553
 
{
2554
 
        const gchar *version;
2555
 
        gchar **split = NULL;
2556
 
        guint major = 0;
2557
 
        guint micro = 0;
2558
 
        guint minor = 0;
2559
 
        gboolean ret = TRUE;
2560
 
 
2561
 
        /* parse running version */
2562
 
        version = nm_client_get_version (panel->priv->client);
2563
 
        if (version != NULL) {
2564
 
                split = g_strsplit (version, ".", -1);
2565
 
                major = atoi (split[0]);
2566
 
                minor = atoi (split[1]);
2567
 
                micro = atoi (split[2]);
2568
 
        }
2569
 
 
2570
 
        /* is it too new or old */
2571
 
        if (major > 0 || major > 9 || (minor <= 8 && micro < 992)) {
2572
 
                ret = FALSE;
2573
 
 
2574
 
                /* do modal dialog in idle so we don't block startup */
2575
 
                panel->priv->nm_warning_idle = g_idle_add ((GSourceFunc)display_version_warning_idle, panel);
2576
 
        }
2577
 
 
2578
 
        g_strfreev (split);
2579
 
        return ret;
2580
 
}
2581
 
 
2582
 
static void
2583
 
edit_connection (GtkButton *button, CcNetworkPanel *panel)
2584
 
{
2585
 
        NMConnection *c;
2586
 
        const gchar *uuid;
2587
 
        gchar *cmdline;
2588
 
        GError *error;
2589
 
        NetObject *object;
2590
 
        NMDevice *device;
2591
 
 
2592
 
        object = get_selected_object (panel);
2593
 
        if (object == NULL)
2594
 
                return;
2595
 
        else if (NET_IS_VPN (object)) {
2596
 
                c = net_vpn_get_connection (NET_VPN (object));
2597
 
        }
2598
 
        else {
2599
 
                device = net_device_get_nm_device (NET_DEVICE (object));
2600
 
                c = find_connection_for_device (panel, device);
2601
 
        }
2602
 
 
2603
 
        uuid = nm_connection_get_uuid (c);
2604
 
 
2605
 
        cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid);
2606
 
        g_debug ("Launching '%s'\n", cmdline);
2607
 
 
2608
 
        error = NULL;
2609
 
        if (!g_spawn_command_line_async (cmdline, &error)) {
2610
 
                g_warning ("Failed to launch nm-connection-editor: %s", error->message);
2611
 
                g_error_free (error);
2612
 
        }
2613
 
 
2614
 
        g_free (cmdline);
2615
 
}
2616
 
 
2617
 
static void
2618
 
add_connection_cb (GtkToolButton *button, CcNetworkPanel *panel)
2619
 
{
2620
 
        GtkWidget *dialog;
2621
 
        gint response;
2622
 
 
2623
 
        dialog = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2624
 
                                                     "connection_type_dialog"));
2625
 
        gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel))));
2626
 
 
2627
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
2628
 
 
2629
 
        gtk_widget_hide (dialog);
2630
 
 
2631
 
        if (response == GTK_RESPONSE_OK) {
2632
 
                GtkComboBox *combo;
2633
 
                GtkTreeModel *model;
2634
 
                GtkTreeIter iter;
2635
 
                gchar *type;
2636
 
                gchar *cmdline;
2637
 
                GError *error;
2638
 
 
2639
 
                combo = GTK_COMBO_BOX (gtk_builder_get_object (panel->priv->builder,
2640
 
                                                               "connection_type_combo"));
2641
 
                model = gtk_combo_box_get_model (combo);
2642
 
                gtk_combo_box_get_active_iter (combo, &iter);
2643
 
                type = NULL;
2644
 
                gtk_tree_model_get (model, &iter, 1, &type, -1);
2645
 
 
2646
 
                cmdline = g_strdup_printf ("nm-connection-editor --create --type %s", type);
2647
 
                g_debug ("Launching '%s'\n", cmdline);
2648
 
 
2649
 
                error = NULL;
2650
 
                if (!g_spawn_command_line_async (cmdline, &error)) {
2651
 
                        g_warning ("Failed to launch nm-connection-editor: %s", error->message);
2652
 
                        g_error_free (error);
2653
 
                }
2654
 
                g_free (cmdline);
2655
 
                g_free (type);
2656
 
        }
2657
 
}
2658
 
 
2659
 
static void
2660
 
forget_network_connection_delete_cb (NMRemoteConnection *connection,
2661
 
                                     GError *error,
2662
 
                                     gpointer user_data)
2663
 
{
2664
 
        if (error == NULL)
2665
 
                return;
2666
 
        g_warning ("failed to delete connection %s: %s",
2667
 
                   nm_object_get_path (NM_OBJECT (connection)),
2668
 
                   error->message);
2669
 
}
2670
 
 
2671
 
static void
2672
 
forget_network_response_cb (GtkWidget *dialog,
2673
 
                            gint response,
2674
 
                            CcNetworkPanel *panel)
2675
 
{
2676
 
        NetObject *object;
2677
 
        NMDevice *device;
2678
 
        NMRemoteConnection *remote_connection;
2679
 
 
2680
 
        if (response != GTK_RESPONSE_OK)
2681
 
                goto out;
2682
 
 
2683
 
        /* get current device */
2684
 
        object = get_selected_object (panel);
2685
 
        if (object == NULL)
2686
 
                return;
2687
 
        device = net_device_get_nm_device (NET_DEVICE (object));
2688
 
        if (device == NULL)
2689
 
                goto out;
2690
 
 
2691
 
        /* delete the connection */
2692
 
        remote_connection = NM_REMOTE_CONNECTION (find_connection_for_device (panel, device));
2693
 
        if (remote_connection == NULL) {
2694
 
                g_warning ("failed to get remote connection");
2695
 
                goto out;
2696
 
        }
2697
 
        nm_remote_connection_delete (remote_connection,
2698
 
                                     forget_network_connection_delete_cb,
2699
 
                                     panel);
2700
 
out:
2701
 
        gtk_widget_destroy (dialog);
2702
 
}
2703
 
 
2704
 
static void
2705
 
wireless_button_clicked_cb (GtkButton *button, CcNetworkPanel *panel)
2706
 
{
2707
 
        gboolean ret;
2708
 
        gchar *ssid_pretty = NULL;
2709
 
        gchar *ssid_target = NULL;
2710
 
        gchar *warning = NULL;
2711
 
        GtkComboBox *combobox;
2712
 
        GtkTreeIter iter;
2713
 
        GtkTreeModel *model;
2714
 
        GtkWidget *dialog;
2715
 
        GtkWidget *window;
2716
 
 
2717
 
        combobox = GTK_COMBO_BOX (gtk_builder_get_object (panel->priv->builder,
2718
 
                                                          "combobox_wireless_network_name"));
2719
 
        ret = gtk_combo_box_get_active_iter (combobox, &iter);
2720
 
        if (!ret)
2721
 
                goto out;
2722
 
 
2723
 
        /* get entry */
2724
 
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (combobox));
2725
 
        gtk_tree_model_get (model, &iter,
2726
 
                            PANEL_WIRELESS_COLUMN_TITLE, &ssid_target,
2727
 
                            -1);
2728
 
 
2729
 
        ssid_pretty = g_strdup_printf ("<b>%s</b>", ssid_target);
2730
 
        warning = g_strdup_printf (_("Network details for %s including password and any custom configuration will be lost"), ssid_pretty);
2731
 
        window = gtk_widget_get_toplevel (GTK_WIDGET (panel));
2732
 
        dialog = gtk_message_dialog_new (GTK_WINDOW (window),
2733
 
                                         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
2734
 
                                         GTK_MESSAGE_OTHER,
2735
 
                                         GTK_BUTTONS_NONE,
2736
 
                                         NULL);
2737
 
        gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), warning);
2738
 
        gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2739
 
                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2740
 
                                _("Forget"), GTK_RESPONSE_OK,
2741
 
                                NULL);
2742
 
        g_signal_connect (dialog, "response",
2743
 
                          G_CALLBACK (forget_network_response_cb), panel);
2744
 
        gtk_window_present (GTK_WINDOW (dialog));
2745
 
out:
2746
 
        g_free (ssid_target);
2747
 
        g_free (ssid_pretty);
2748
 
        g_free (warning);
2749
 
}
2750
 
 
2751
 
static void
2752
 
remove_connection (GtkToolButton *button, CcNetworkPanel *panel)
2753
 
{
2754
 
        NetObject *object;
2755
 
        NMConnection *connection;
2756
 
 
2757
 
        /* get current device */
2758
 
        object = get_selected_object (panel);
2759
 
        if (object == NULL)
2760
 
                return;
2761
 
 
2762
 
        /* VPN */
2763
 
        if (NET_IS_VPN (object)) {
2764
 
                connection = net_vpn_get_connection (NET_VPN (object));
2765
 
                nm_remote_connection_delete (NM_REMOTE_CONNECTION (connection), NULL, panel);
2766
 
                return;
2767
 
        }
2768
 
}
2769
 
 
2770
 
static void
2771
 
on_toplevel_map (GtkWidget      *widget,
2772
 
                 CcNetworkPanel *panel)
2773
 
{
2774
 
        gboolean ret;
2775
 
 
2776
 
        /* is the user compiling against a new version, but running an
2777
 
         * old daemon version? */
2778
 
        ret = panel_check_network_manager_version (panel);
2779
 
        if (ret) {
2780
 
                manager_running (panel->priv->client, NULL, panel);
2781
 
        } else {
2782
 
                /* just select the proxy settings */
2783
 
                select_first_device (panel);
2784
 
        }
2785
 
}
2786
 
 
2787
 
static void
2788
 
connection_activate_cb (NMClient *client,
2789
 
                        NMActiveConnection *connection,
2790
 
                        GError *error,
2791
 
                        gpointer user_data)
2792
 
{
2793
 
        CcNetworkPanel *panel = user_data;
2794
 
 
2795
 
        if (connection == NULL) {
2796
 
                /* failed to activate */
2797
 
                refresh_ui (panel);
2798
 
        }
2799
 
}
2800
 
 
2801
 
static void
2802
 
connection_add_activate_cb (NMClient *client,
2803
 
                            NMActiveConnection *connection,
2804
 
                            const char *path,
2805
 
                            GError *error,
2806
 
                            gpointer user_data)
2807
 
{
2808
 
        connection_activate_cb (client, connection, error, user_data);
2809
 
}
2810
 
 
2811
 
static void
2812
 
connect_to_hidden_network (CcNetworkPanel *panel)
2813
 
{
2814
 
        CcNetworkPanelPrivate *priv = panel->priv;
2815
 
 
2816
 
        cc_network_panel_connect_to_hidden_network (panel, priv->client, priv->remote_settings);
2817
 
}
2818
 
 
2819
 
static void
2820
 
wireless_ap_changed_cb (GtkComboBox *combo_box, CcNetworkPanel *panel)
2821
 
{
2822
 
        const GByteArray *ssid;
2823
 
        const gchar *ssid_tmp;
2824
 
        gboolean ret;
2825
 
        gchar *object_path = NULL;
2826
 
        gchar *ssid_target = NULL;
2827
 
        GSList *list, *l;
2828
 
        GSList *filtered;
2829
 
        GtkTreeIter iter;
2830
 
        GtkTreeModel *model;
2831
 
        NetObject *object;
2832
 
        NMConnection *connection;
2833
 
        NMConnection *connection_activate = NULL;
2834
 
        NMDevice *device;
2835
 
        NMSettingWireless *setting_wireless;
2836
 
 
2837
 
        if (panel->priv->updating_device)
2838
 
                goto out;
2839
 
 
2840
 
        ret = gtk_combo_box_get_active_iter (combo_box, &iter);
2841
 
        if (!ret)
2842
 
                goto out;
2843
 
 
2844
 
        object = get_selected_object (panel);
2845
 
        if (object == NULL)
2846
 
                goto out;
2847
 
 
2848
 
        device = net_device_get_nm_device (NET_DEVICE (object));
2849
 
        if (device == NULL)
2850
 
                goto out;
2851
 
 
2852
 
        /* get entry */
2853
 
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
2854
 
        gtk_tree_model_get (model, &iter,
2855
 
                            PANEL_WIRELESS_COLUMN_ID, &object_path,
2856
 
                            PANEL_WIRELESS_COLUMN_TITLE, &ssid_target,
2857
 
                            -1);
2858
 
        g_debug ("try to connect to WIFI network %s [%s]",
2859
 
                 ssid_target, object_path);
2860
 
        if (g_strcmp0 (object_path, "ap-other...") == 0) {
2861
 
                connect_to_hidden_network (panel);
2862
 
                goto out;
2863
 
        }
2864
 
 
2865
 
        /* look for an existing connection we can use */
2866
 
        list = nm_remote_settings_list_connections (panel->priv->remote_settings);
2867
 
        g_debug ("%i existing remote connections available",
2868
 
                 g_slist_length (list));
2869
 
        filtered = nm_device_filter_connections (device, list);
2870
 
        g_debug ("%i suitable remote connections to check",
2871
 
                 g_slist_length (filtered));
2872
 
        for (l = filtered; l; l = g_slist_next (l)) {
2873
 
                connection = NM_CONNECTION (l->data);
2874
 
                setting_wireless = nm_connection_get_setting_wireless (connection);
2875
 
                if (!NM_IS_SETTING_WIRELESS (setting_wireless))
2876
 
                        continue;
2877
 
                ssid = nm_setting_wireless_get_ssid (setting_wireless);
2878
 
                if (ssid == NULL)
2879
 
                        continue;
2880
 
                ssid_tmp = nm_utils_escape_ssid (ssid->data, ssid->len);
2881
 
                if (g_strcmp0 (ssid_target, ssid_tmp) == 0) {
2882
 
                        g_debug ("we found an existing connection %s to activate!",
2883
 
                                 nm_connection_get_id (connection));
2884
 
                        connection_activate = connection;
2885
 
                        break;
2886
 
                }
2887
 
        }
2888
 
 
2889
 
        g_slist_free (list);
2890
 
        g_slist_free (filtered);
2891
 
 
2892
 
        /* activate the connection */
2893
 
        if (connection_activate != NULL) {
2894
 
                nm_client_activate_connection (panel->priv->client,
2895
 
                                               connection_activate,
2896
 
                                               device, NULL,
2897
 
                                               connection_activate_cb, panel);
2898
 
                goto out;
2899
 
        }
2900
 
 
2901
 
        /* create one, as it's missing */
2902
 
        g_debug ("no existing connection found for %s, creating",
2903
 
                 ssid_target);
2904
 
        nm_client_add_and_activate_connection (panel->priv->client,
2905
 
                                               NULL,
2906
 
                                               device, object_path,
2907
 
                                               connection_add_activate_cb, panel);
2908
 
out:
2909
 
        g_free (ssid_target);
2910
 
        g_free (object_path);
2911
 
}
2912
 
 
2913
 
static gint
2914
 
wireless_ap_model_sort_cb (GtkTreeModel *model,
2915
 
                           GtkTreeIter *a,
2916
 
                           GtkTreeIter *b,
2917
 
                           gpointer user_data)
2918
 
{
2919
 
        gchar *str_a;
2920
 
        gchar *str_b;
2921
 
        gint retval;
2922
 
 
2923
 
        gtk_tree_model_get (model, a,
2924
 
                            PANEL_WIRELESS_COLUMN_SORT, &str_a,
2925
 
                            -1);
2926
 
        gtk_tree_model_get (model, b,
2927
 
                            PANEL_WIRELESS_COLUMN_SORT, &str_b,
2928
 
                            -1);
2929
 
 
2930
 
        /* special case blank entries to the bottom */
2931
 
        if (g_strcmp0 (str_a, "") == 0) {
2932
 
                retval = 1;
2933
 
                goto out;
2934
 
        }
2935
 
        if (g_strcmp0 (str_b, "") == 0) {
2936
 
                retval = -1;
2937
 
                goto out;
2938
 
        }
2939
 
 
2940
 
        /* case sensitive search like before */
2941
 
        g_debug ("compare %s with %s", str_a, str_b);
2942
 
        retval = g_strcmp0 (str_a, str_b);
2943
 
out:
2944
 
        g_free (str_a);
2945
 
        g_free (str_b);
2946
 
        return retval;
2947
 
}
2948
 
 
2949
 
static GByteArray *
2950
 
ssid_to_byte_array (const gchar *ssid)
2951
 
{
2952
 
        guint32 len;
2953
 
        GByteArray *ba;
2954
 
 
2955
 
        len = strlen (ssid);
2956
 
        ba = g_byte_array_sized_new (len);
2957
 
        g_byte_array_append (ba, (guchar *)ssid, len);
2958
 
 
2959
 
        return ba;
2960
 
}
2961
 
 
2962
 
static void
2963
 
activate_cb (NMClient           *client,
2964
 
             NMActiveConnection *connection,
2965
 
             GError             *error,
2966
 
             CcNetworkPanel     *panel)
2967
 
{
2968
 
        if (error) {
2969
 
                g_warning ("Failed to add new connection: (%d) %s",
2970
 
                           error->code,
2971
 
                           error->message);
2972
 
                return;
2973
 
        }
2974
 
 
2975
 
        refresh_ui (panel);
2976
 
}
2977
 
 
2978
 
static void
2979
 
activate_new_cb (NMClient           *client,
2980
 
                 NMActiveConnection *connection,
2981
 
                 const gchar        *path,
2982
 
                 GError             *error,
2983
 
                 CcNetworkPanel     *panel)
2984
 
{
2985
 
        activate_cb (client, connection, error, panel);
2986
 
}
2987
 
 
2988
 
static gchar *
2989
 
get_hostname (void)
2990
 
{
2991
 
        GDBusConnection *bus;
2992
 
        GVariant *res;
2993
 
        GVariant *inner;
2994
 
        gchar *str;
2995
 
        GError *error;
2996
 
 
2997
 
        error = NULL;
2998
 
        bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
2999
 
        if (error != NULL) {
3000
 
                g_warning ("Failed to get system bus connection: %s", error->message);
3001
 
                g_error_free (error);
3002
 
 
3003
 
                return NULL;
3004
 
        }
3005
 
        res = g_dbus_connection_call_sync (bus,
3006
 
                                           "org.freedesktop.hostname1",
3007
 
                                           "/org/freedesktop/hostname1",
3008
 
                                           "org.freedesktop.DBus.Properties",
3009
 
                                           "Get",
3010
 
                                           g_variant_new ("(ss)",
3011
 
                                                          "org.freedesktop.hostname1",
3012
 
                                                          "PrettyHostname"),
3013
 
                                           (GVariantType*)"(v)",
3014
 
                                           G_DBUS_CALL_FLAGS_NONE,
3015
 
                                           -1,
3016
 
                                           NULL,
3017
 
                                           &error);
3018
 
        g_object_unref (bus);
3019
 
 
3020
 
        if (error != NULL) {
3021
 
                g_warning ("Getting pretty hostname failed: %s", error->message);
3022
 
                g_error_free (error);
3023
 
        }
3024
 
 
3025
 
        str = NULL;
3026
 
 
3027
 
        if (res != NULL) {
3028
 
                g_variant_get (res, "(v)", &inner);
3029
 
                str = g_variant_dup_string (inner, NULL);
3030
 
                g_variant_unref (res);
3031
 
        }
3032
 
 
3033
 
        if (str == NULL || *str == '\0') {
3034
 
                str = g_strdup (g_get_host_name ());
3035
 
        }
3036
 
 
3037
 
        if (str == NULL || *str == '\0') {
3038
 
                str = g_strdup ("GNOME");
3039
 
        }
3040
 
 
3041
 
        return str;
3042
 
}
3043
 
 
3044
 
static GByteArray *
3045
 
generate_ssid_for_hotspot (CcNetworkPanel *panel)
3046
 
{
3047
 
        GByteArray *ssid_array;
3048
 
        gchar *ssid;
3049
 
 
3050
 
        ssid = get_hostname ();
3051
 
        ssid_array = ssid_to_byte_array (ssid);
3052
 
        g_free (ssid);
3053
 
 
3054
 
        return ssid_array;
3055
 
}
3056
 
 
3057
 
static gchar *
3058
 
generate_wep_key (CcNetworkPanel *panel)
3059
 
{
3060
 
        gchar key[11];
3061
 
        gint i;
3062
 
        const gchar *hexdigits = "0123456789abcdef";
3063
 
 
3064
 
        /* generate a 10-digit hex WEP key */
3065
 
        for (i = 0; i < 10; i++) {
3066
 
                gint digit;
3067
 
                digit = g_random_int_range (0, 16);
3068
 
                key[i] = hexdigits[digit];
3069
 
        }
3070
 
        key[10] = 0;
3071
 
 
3072
 
        return g_strdup (key);
3073
 
}
3074
 
 
3075
 
static gboolean
3076
 
is_hotspot_connection (NMConnection *connection)
3077
 
{
3078
 
        NMSettingConnection *sc;
3079
 
        NMSettingWireless *sw;
3080
 
        NMSettingIP4Config *sip;
3081
 
 
3082
 
        sc = nm_connection_get_setting_connection (connection);
3083
 
        if (g_strcmp0 (nm_setting_connection_get_connection_type (sc), "802-11-wireless") != 0) {
3084
 
                return FALSE;
3085
 
        }
3086
 
        sw = nm_connection_get_setting_wireless (connection);
3087
 
        if (g_strcmp0 (nm_setting_wireless_get_mode (sw), "adhoc") != 0) {
3088
 
                return FALSE;
3089
 
        }
3090
 
        if (g_strcmp0 (nm_setting_wireless_get_security (sw), "802-11-wireless-security") != 0) {
3091
 
                return FALSE;
3092
 
        }
3093
 
        sip = nm_connection_get_setting_ip4_config (connection);
3094
 
        if (g_strcmp0 (nm_setting_ip4_config_get_method (sip), "shared") != 0) {
3095
 
                return FALSE;
3096
 
        }
3097
 
 
3098
 
        return TRUE;
3099
 
}
3100
 
 
3101
 
static void
3102
 
start_shared_connection (CcNetworkPanel *panel)
3103
 
{
3104
 
        NMConnection *c;
3105
 
        NMConnection *tmp;
3106
 
        NMSettingConnection *sc;
3107
 
        NMSettingWireless *sw;
3108
 
        NMSettingIP4Config *sip;
3109
 
        NMSettingWirelessSecurity *sws;
3110
 
        NMDevice *device;
3111
 
        NetObject *object;
3112
 
        GByteArray *ssid_array;
3113
 
        gchar *wep_key;
3114
 
        const gchar *str_mac;
3115
 
        struct ether_addr *bin_mac;
3116
 
        GSList *connections;
3117
 
        GSList *filtered;
3118
 
        GSList *l;
3119
 
 
3120
 
        object = get_selected_object (panel);
3121
 
        device = net_device_get_nm_device (NET_DEVICE (object));
3122
 
        g_assert (nm_device_get_device_type (device) == NM_DEVICE_TYPE_WIFI);
3123
 
 
3124
 
        connections = nm_remote_settings_list_connections (panel->priv->remote_settings);
3125
 
        filtered = nm_device_filter_connections (device, connections);
3126
 
        g_slist_free (connections);
3127
 
        c = NULL;
3128
 
        for (l = filtered; l; l = l->next) {
3129
 
                tmp = l->data;
3130
 
                if (is_hotspot_connection (tmp)) {
3131
 
                        c = tmp;
3132
 
                        break;
3133
 
                }
3134
 
        }
3135
 
        g_slist_free (filtered);
3136
 
 
3137
 
        if (c != NULL) {
3138
 
                g_debug ("activate existing hotspot connection\n");
3139
 
                nm_client_activate_connection (panel->priv->client,
3140
 
                                               c,
3141
 
                                               device,
3142
 
                                               NULL,
3143
 
                                               (NMClientActivateFn)activate_cb,
3144
 
                                               panel);
3145
 
                return;
3146
 
        }
3147
 
 
3148
 
        g_debug ("create new hotspot connection\n");
3149
 
        c = nm_connection_new ();
3150
 
 
3151
 
        sc = (NMSettingConnection *)nm_setting_connection_new ();
3152
 
        g_object_set (sc,
3153
 
                      "type", "802-11-wireless",
3154
 
                      "id", "Hotspot",
3155
 
                      "autoconnect", FALSE,
3156
 
                      NULL);
3157
 
        nm_connection_add_setting (c, (NMSetting *)sc);
3158
 
 
3159
 
        sw = (NMSettingWireless *)nm_setting_wireless_new ();
3160
 
        g_object_set (sw,
3161
 
                      "mode", "adhoc",
3162
 
                      "security", "802-11-wireless-security",
3163
 
                      NULL);
3164
 
 
3165
 
        str_mac = nm_device_wifi_get_permanent_hw_address (NM_DEVICE_WIFI (device));
3166
 
        bin_mac = ether_aton (str_mac);
3167
 
        if (bin_mac) {
3168
 
                GByteArray *hw_address;
3169
 
 
3170
 
                hw_address = g_byte_array_sized_new (ETH_ALEN);
3171
 
                g_byte_array_append (hw_address, bin_mac->ether_addr_octet, ETH_ALEN);
3172
 
                g_object_set (sw,
3173
 
                              "mac-address", hw_address,
3174
 
                              NULL);
3175
 
                g_byte_array_unref (hw_address);
3176
 
        }
3177
 
        nm_connection_add_setting (c, (NMSetting *)sw);
3178
 
 
3179
 
        sip = (NMSettingIP4Config*) nm_setting_ip4_config_new ();
3180
 
        g_object_set (sip, "method", "shared", NULL);
3181
 
        nm_connection_add_setting (c, (NMSetting *)sip);
3182
 
 
3183
 
        ssid_array = generate_ssid_for_hotspot (panel);
3184
 
        g_object_set (sw,
3185
 
                      "ssid", ssid_array,
3186
 
                      NULL);
3187
 
        g_byte_array_unref (ssid_array);
3188
 
 
3189
 
        sws = (NMSettingWirelessSecurity*) nm_setting_wireless_security_new ();
3190
 
        wep_key = generate_wep_key (panel);
3191
 
        g_object_set (sws,
3192
 
                      "key-mgmt", "none",
3193
 
                      "wep-key0", wep_key,
3194
 
                      "wep-key-type", NM_WEP_KEY_TYPE_KEY,
3195
 
                      NULL);
3196
 
        g_free (wep_key);
3197
 
        nm_connection_add_setting (c, (NMSetting *)sws);
3198
 
 
3199
 
        nm_client_add_and_activate_connection (panel->priv->client,
3200
 
                                               c,
3201
 
                                               device,
3202
 
                                               NULL,
3203
 
                                               (NMClientAddActivateFn)activate_new_cb,
3204
 
                                               panel);
3205
 
 
3206
 
        g_object_unref (c);
3207
 
}
3208
 
 
3209
 
static void
3210
 
start_hotspot_response_cb (GtkWidget *dialog, gint response, CcNetworkPanel *panel)
3211
 
{
3212
 
        if (response == GTK_RESPONSE_OK) {
3213
 
                start_shared_connection (panel);
3214
 
        }
3215
 
        gtk_widget_destroy (dialog);
3216
 
}
3217
 
 
3218
 
static void
3219
 
start_hotspot (GtkButton *button, CcNetworkPanel *panel)
3220
 
{
3221
 
        NetObject *object;
3222
 
        NMDevice *device;
3223
 
        gboolean is_default;
3224
 
        const GPtrArray *connections;
3225
 
        const GPtrArray *devices;
3226
 
        NMActiveConnection *c;
3227
 
        NMAccessPoint *ap;
3228
 
        gchar *active_ssid;
3229
 
        gchar *warning;
3230
 
        gint i;
3231
 
 
3232
 
        warning = NULL;
3233
 
 
3234
 
        object = get_selected_object (panel);
3235
 
        device = net_device_get_nm_device (NET_DEVICE (object));
3236
 
        connections = nm_client_get_active_connections (panel->priv->client);
3237
 
        if (connections == NULL || connections->len == 0) {
3238
 
                warning = g_strdup_printf ("%s\n\n%s",
3239
 
                                           _("Not connected to the internet."),
3240
 
                                           _("Create the hotspot anyway?"));
3241
 
        } else {
3242
 
                is_default = FALSE;
3243
 
                active_ssid = NULL;
3244
 
                for (i = 0; i < connections->len; i++) {
3245
 
                        c = (NMActiveConnection *)connections->pdata[i];
3246
 
                        devices = nm_active_connection_get_devices (c);
3247
 
                        if (devices && devices->pdata[0] == device) {
3248
 
                                ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (device));
3249
 
                                active_ssid = nm_utils_ssid_to_utf8 (nm_access_point_get_ssid (ap));
3250
 
                                is_default = nm_active_connection_get_default (c);
3251
 
                                break;
3252
 
                        }
3253
 
                }
3254
 
 
3255
 
                if (active_ssid != NULL) {
3256
 
                        GString *str;
3257
 
                        str = g_string_new ("");
3258
 
                        g_string_append_printf (str, _("Disconnect from %s and create a new hotspot?"), active_ssid);
3259
 
                        if (is_default) {
3260
 
                                g_string_append (str, "\n\n");
3261
 
                                g_string_append (str, _("This is your only connection to the internet."));
3262
 
                        }
3263
 
                        warning = g_string_free (str, FALSE);
3264
 
                }
3265
 
        }
3266
 
 
3267
 
        if (warning != NULL) {
3268
 
                GtkWidget *dialog;
3269
 
                GtkWidget *window;
3270
 
 
3271
 
                window = gtk_widget_get_toplevel (GTK_WIDGET (panel));
3272
 
                dialog = gtk_message_dialog_new (GTK_WINDOW (window),
3273
 
                                                 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
3274
 
                                                 GTK_MESSAGE_OTHER,
3275
 
                                                 GTK_BUTTONS_NONE,
3276
 
                                                 "%s", warning);
3277
 
                gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3278
 
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3279
 
                                        _("Create _Hotspot"), GTK_RESPONSE_OK,
3280
 
                                        NULL);
3281
 
                g_signal_connect (dialog, "response",
3282
 
                                  G_CALLBACK (start_hotspot_response_cb), panel);
3283
 
                gtk_window_present (GTK_WINDOW (dialog));
3284
 
 
3285
 
                return;
3286
 
          }
3287
 
 
3288
 
        /* if we get here, things look good to go ahead */
3289
 
        start_shared_connection (panel);
3290
 
}
3291
 
 
3292
 
static void
3293
 
stop_shared_connection (CcNetworkPanel *panel)
3294
 
{
3295
 
        const GPtrArray *connections;
3296
 
        const GPtrArray *devices;
3297
 
        NetObject *object;
3298
 
        NMDevice *device;
3299
 
        gint i;
3300
 
        NMActiveConnection *c;
3301
 
 
3302
 
        object = get_selected_object (panel);
3303
 
        device = net_device_get_nm_device (NET_DEVICE (object));
3304
 
 
3305
 
        connections = nm_client_get_active_connections (panel->priv->client);
3306
 
        for (i = 0; i < connections->len; i++) {
3307
 
                c = (NMActiveConnection *)connections->pdata[i];
3308
 
 
3309
 
                devices = nm_active_connection_get_devices (c);
3310
 
                if (devices && devices->pdata[0] == device) {
3311
 
                        nm_client_deactivate_connection (panel->priv->client, c);
3312
 
                        break;
3313
 
                }
3314
 
        }
3315
 
 
3316
 
        refresh_ui (panel);
3317
 
}
3318
 
 
3319
 
static void
3320
 
stop_hotspot_response_cb (GtkWidget *dialog, gint response, CcNetworkPanel *panel)
3321
 
{
3322
 
        if (response == GTK_RESPONSE_OK) {
3323
 
                stop_shared_connection (panel);
3324
 
        }
3325
 
        gtk_widget_destroy (dialog);
3326
 
}
3327
 
 
3328
 
static void
3329
 
stop_hotspot (GtkButton *button, CcNetworkPanel *panel)
3330
 
{
3331
 
        GtkWidget *dialog;
3332
 
        GtkWidget *window;
3333
 
 
3334
 
        window = gtk_widget_get_toplevel (GTK_WIDGET (panel));
3335
 
        dialog = gtk_message_dialog_new (GTK_WINDOW (window),
3336
 
                                         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
3337
 
                                         GTK_MESSAGE_OTHER,
3338
 
                                         GTK_BUTTONS_NONE,
3339
 
                                         _("Stop hotspot and disconnect any users?"));
3340
 
        gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3341
 
                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3342
 
                                _("_Stop Hotspot"), GTK_RESPONSE_OK,
3343
 
                                NULL);
3344
 
        g_signal_connect (dialog, "response",
3345
 
                          G_CALLBACK (stop_hotspot_response_cb), panel);
3346
 
        gtk_window_present (GTK_WINDOW (dialog));
3347
 
}
3348
 
 
3349
 
static gboolean
3350
 
network_add_shell_header_widgets_cb (gpointer user_data)
3351
 
{
3352
 
        CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);
3353
 
        gboolean ret;
3354
 
        GtkWidget *box;
3355
 
        GtkWidget *widget;
3356
 
 
3357
 
        box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3358
 
        /* TRANSLATORS: this is to disable the radio hardware in the
3359
 
         * network panel */
3360
 
        widget = gtk_label_new (_("Airplane Mode"));
3361
 
        gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
3362
 
        gtk_widget_set_visible (widget, TRUE);
3363
 
        widget = gtk_switch_new ();
3364
 
        gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
3365
 
        gtk_widget_set_visible (widget, TRUE);
3366
 
        cc_shell_embed_widget_in_header (cc_panel_get_shell (CC_PANEL (panel)), box);
3367
 
        panel->priv->kill_switch_header = g_object_ref (box);
3368
 
 
3369
 
        ret = nm_client_wireless_get_enabled (panel->priv->client);
3370
 
        gtk_switch_set_active (GTK_SWITCH (widget), !ret);
3371
 
        g_signal_connect (GTK_SWITCH (widget), "notify::active",
3372
 
                          G_CALLBACK (cc_network_panel_notify_enable_active_cb),
3373
 
                          panel);
3374
 
        panel_refresh_killswitch_visibility (panel);
3375
 
 
3376
 
        return FALSE;
3377
 
}
3378
 
 
3379
 
static gboolean
3380
 
is_in_admin_group (int id_group)
3381
 
{
3382
 
        gid_t groups [1024];
3383
 
       int i, ngroups;
3384
 
 
3385
 
        ngroups = getgroups (1024, groups);
3386
 
        if (ngroups < 0) {
3387
 
                perror ("getgroups");
3388
 
                return FALSE;
3389
 
        }
3390
 
 
3391
 
        for (i = 0; i < ngroups; ++i) {
3392
 
                if (groups[i] == id_group)
3393
 
                        return TRUE;
3394
 
        }
3395
 
 
3396
 
        return FALSE;
3397
 
}
3398
 
 
3399
 
static gboolean
3400
 
is_admin ()
3401
 
{
3402
 
        struct group *admin_group;
3403
 
 
3404
 
        admin_group = getgrnam ("admin");
3405
 
        if (admin_group != NULL && is_in_admin_group (admin_group->gr_gid))
3406
 
                return TRUE;
3407
 
 
3408
 
        admin_group = getgrnam ("sudo");
3409
 
        if (admin_group != NULL && is_in_admin_group (admin_group->gr_gid))
3410
 
                return TRUE;
3411
 
 
3412
 
        return FALSE;
3413
 
}
3414
 
 
3415
 
static void
3416
 
reset_system_proxy (GDBusProxy *proxy, const gchar *protocol)
3417
 
{
3418
 
        GVariant *result;
3419
 
        GError *error = NULL;
3420
 
 
3421
 
        result = g_dbus_proxy_call_sync (proxy, "set_proxy",
3422
 
                                         g_variant_new ("(ss)", protocol, ""),
3423
 
                                         G_DBUS_CALL_FLAGS_NONE,
3424
 
                                         -1, NULL, &error);
3425
 
        if (result)
3426
 
                g_variant_unref (result);
3427
 
        else {
3428
 
                g_warning ("Error while calling set_proxy for %s protocol: %s", protocol, error->message);
3429
 
                g_error_free (error);
3430
 
        }
3431
 
}
3432
 
 
3433
 
static void
3434
 
set_proxy_for_protocol (GDBusProxy *proxy, const gchar *protocol, GSettings *settings)
3435
 
{
3436
 
        GVariant *result;
3437
 
        gchar *proxy_str;
3438
 
        GError *error = NULL;
3439
 
 
3440
 
        proxy_str = g_strdup_printf ("%s://%s:%i/",
3441
 
                                     protocol,
3442
 
                                     g_settings_get_string (settings, "host"),
3443
 
                                     g_settings_get_int (settings, "port"));
3444
 
        result = g_dbus_proxy_call_sync (proxy, "set_proxy",
3445
 
                                         g_variant_new ("(ss)", protocol, proxy_str),
3446
 
                                         G_DBUS_CALL_FLAGS_NONE,
3447
 
                                         -1, NULL, &error);
3448
 
        if (result)
3449
 
                g_variant_unref (result);
3450
 
        else {
3451
 
                g_warning ("Error while calling set_proxy for %s protocol: %s", protocol, error->message);
3452
 
                g_error_free (error);
3453
 
        }
3454
 
 
3455
 
        /* Free memory */
3456
 
        g_free (proxy_str);
3457
 
        g_object_unref (settings);
3458
 
}
3459
 
 
3460
 
static void
3461
 
on_proxy_apply_system_wide (GtkButton *button, gpointer user_data)
3462
 
{
3463
 
        GDBusConnection *bus;
3464
 
        GDBusProxy *proxy;
3465
 
        GError *error;
3466
 
        GDesktopProxyMode proxy_mode;
3467
 
        CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);
3468
 
 
3469
 
        error = NULL;
3470
 
        bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
3471
 
        if (!bus) {
3472
 
                g_warning ("Could not retrieve system bus: %s", error->message);
3473
 
                g_error_free (error);
3474
 
 
3475
 
                return;
3476
 
        }
3477
 
 
3478
 
        proxy = g_dbus_proxy_new_sync (bus, 0, NULL,
3479
 
                                       "com.ubuntu.SystemService",
3480
 
                                       "/",
3481
 
                                       "com.ubuntu.SystemService",
3482
 
                                       NULL,
3483
 
                                       &error);
3484
 
        if (!proxy) {
3485
 
                g_warning ("Could not retrieve bus object: %s", error->message);
3486
 
                g_error_free (error);
3487
 
 
3488
 
                return;
3489
 
        }
3490
 
 
3491
 
        /* Retrieve the current settings */
3492
 
        proxy_mode = g_settings_get_enum (panel->priv->proxy_settings, "mode");
3493
 
        switch (proxy_mode) {
3494
 
        case G_DESKTOP_PROXY_MODE_NONE:
3495
 
                reset_system_proxy (proxy, "http");
3496
 
                reset_system_proxy (proxy, "https");
3497
 
                reset_system_proxy (proxy, "ftp");
3498
 
                reset_system_proxy (proxy, "socks");
3499
 
                break;
3500
 
        case G_DESKTOP_PROXY_MODE_MANUAL:
3501
 
                set_proxy_for_protocol (proxy, "http", g_settings_get_child (panel->priv->proxy_settings, "http"));
3502
 
                set_proxy_for_protocol (proxy, "https", g_settings_get_child (panel->priv->proxy_settings, "https"));
3503
 
                set_proxy_for_protocol (proxy, "ftp", g_settings_get_child (panel->priv->proxy_settings, "ftp"));
3504
 
                set_proxy_for_protocol (proxy, "socks", g_settings_get_child (panel->priv->proxy_settings, "socks"));
3505
 
                break;
3506
 
        }
3507
 
 
3508
 
        /* Free memory */
3509
 
        g_object_unref (proxy);
3510
 
}
3511
 
 
3512
 
static void
3513
 
cc_network_panel_init (CcNetworkPanel *panel)
3514
 
{
3515
 
        DBusGConnection *bus = NULL;
3516
 
        GError *error = NULL;
3517
 
        gint value;
3518
 
        GSettings *settings_tmp;
3519
 
        GtkAdjustment *adjustment;
3520
 
        GtkCellRenderer *renderer;
3521
 
        GtkComboBox *combobox;
3522
 
        GtkStyleContext *context;
3523
 
        GtkTreeSelection *selection;
3524
 
        GtkTreeSortable *sortable;
3525
 
        GtkWidget *widget;
3526
 
        GtkWidget *toplevel;
3527
 
 
3528
 
        panel->priv = NETWORK_PANEL_PRIVATE (panel);
3529
 
 
3530
 
        panel->priv->builder = gtk_builder_new ();
3531
 
        gtk_builder_add_from_file (panel->priv->builder,
3532
 
                                   GNOMECC_UI_DIR "/network.ui",
3533
 
                                   &error);
3534
 
        if (error != NULL) {
3535
 
                g_warning ("Could not load interface file: %s", error->message);
3536
 
                g_error_free (error);
3537
 
                return;
3538
 
        }
3539
 
 
3540
 
        panel->priv->cancellable = g_cancellable_new ();
3541
 
 
3542
 
        panel->priv->proxy_settings = g_settings_new ("org.gnome.system.proxy");
3543
 
        g_signal_connect (panel->priv->proxy_settings,
3544
 
                          "changed",
3545
 
                          G_CALLBACK (panel_settings_changed),
3546
 
                          panel);
3547
 
 
3548
 
        /* explicitly set this to false as the panel has no way of
3549
 
         * linking the http and https proxies them together */
3550
 
        g_settings_set_boolean (panel->priv->proxy_settings,
3551
 
                                "use-same-proxy",
3552
 
                                FALSE);
3553
 
 
3554
 
        /* actions */
3555
 
        value = g_settings_get_enum (panel->priv->proxy_settings, "mode");
3556
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3557
 
                                                     "combobox_proxy_mode"));
3558
 
        panel_set_value_for_combo (panel, GTK_COMBO_BOX (widget), value);
3559
 
        g_signal_connect (widget, "changed",
3560
 
                          G_CALLBACK (panel_proxy_mode_combo_changed_cb),
3561
 
                          panel);
3562
 
 
3563
 
        /* bind the proxy values */
3564
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3565
 
                                                     "entry_proxy_url"));
3566
 
        g_settings_bind (panel->priv->proxy_settings, "autoconfig-url",
3567
 
                         widget, "text",
3568
 
                         G_SETTINGS_BIND_DEFAULT);
3569
 
 
3570
 
        /* bind the HTTP proxy values */
3571
 
        settings_tmp = g_settings_get_child (panel->priv->proxy_settings, "http");
3572
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3573
 
                                                     "entry_proxy_http"));
3574
 
        g_settings_bind (settings_tmp, "host",
3575
 
                         widget, "text",
3576
 
                         G_SETTINGS_BIND_DEFAULT);
3577
 
        adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (panel->priv->builder,
3578
 
                                                             "adjustment_proxy_port_http"));
3579
 
        g_settings_bind (settings_tmp, "port",
3580
 
                         adjustment, "value",
3581
 
                         G_SETTINGS_BIND_DEFAULT);
3582
 
        g_object_unref (settings_tmp);
3583
 
 
3584
 
        /* bind the HTTPS proxy values */
3585
 
        settings_tmp = g_settings_get_child (panel->priv->proxy_settings, "https");
3586
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3587
 
                                                     "entry_proxy_https"));
3588
 
        g_settings_bind (settings_tmp, "host",
3589
 
                         widget, "text",
3590
 
                         G_SETTINGS_BIND_DEFAULT);
3591
 
        adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (panel->priv->builder,
3592
 
                                                             "adjustment_proxy_port_https"));
3593
 
        g_settings_bind (settings_tmp, "port",
3594
 
                         adjustment, "value",
3595
 
                         G_SETTINGS_BIND_DEFAULT);
3596
 
        g_object_unref (settings_tmp);
3597
 
 
3598
 
        /* bind the FTP proxy values */
3599
 
        settings_tmp = g_settings_get_child (panel->priv->proxy_settings, "ftp");
3600
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3601
 
                                                     "entry_proxy_ftp"));
3602
 
        g_settings_bind (settings_tmp, "host",
3603
 
                         widget, "text",
3604
 
                         G_SETTINGS_BIND_DEFAULT);
3605
 
        adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (panel->priv->builder,
3606
 
                                                             "adjustment_proxy_port_ftp"));
3607
 
        g_settings_bind (settings_tmp, "port",
3608
 
                         adjustment, "value",
3609
 
                         G_SETTINGS_BIND_DEFAULT);
3610
 
        g_object_unref (settings_tmp);
3611
 
 
3612
 
        /* bind the SOCKS proxy values */
3613
 
        settings_tmp = g_settings_get_child (panel->priv->proxy_settings, "socks");
3614
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3615
 
                                                     "entry_proxy_socks"));
3616
 
        g_settings_bind (settings_tmp, "host",
3617
 
                         widget, "text",
3618
 
                         G_SETTINGS_BIND_DEFAULT);
3619
 
        adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (panel->priv->builder,
3620
 
                                                             "adjustment_proxy_port_socks"));
3621
 
        g_settings_bind (settings_tmp, "port",
3622
 
                         adjustment, "value",
3623
 
                         G_SETTINGS_BIND_DEFAULT);
3624
 
        g_object_unref (settings_tmp);
3625
 
 
3626
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3627
 
                                                     "treeview_devices"));
3628
 
        panel_add_devices_columns (panel, GTK_TREE_VIEW (widget));
3629
 
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
3630
 
        gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
3631
 
        g_signal_connect (selection, "changed",
3632
 
                          G_CALLBACK (nm_devices_treeview_clicked_cb), panel);
3633
 
 
3634
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3635
 
                                                     "devices_scrolledwindow"));
3636
 
        context = gtk_widget_get_style_context (widget);
3637
 
        gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
3638
 
 
3639
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3640
 
                                                     "devices_toolbar"));
3641
 
        context = gtk_widget_get_style_context (widget);
3642
 
        gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
3643
 
 
3644
 
        /* add the virtual proxy device */
3645
 
        panel_add_proxy_device (panel);
3646
 
 
3647
 
        /* System wide proxy settings */
3648
 
        if (is_admin ()) {
3649
 
                g_signal_connect (G_OBJECT (gtk_builder_get_object (panel->priv->builder, "system_proxy_button")), "clicked",
3650
 
                                  G_CALLBACK (on_proxy_apply_system_wide), panel);
3651
 
        } else
3652
 
                gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "system_proxy_button")));
3653
 
 
3654
 
        /* setup wireless combobox model */
3655
 
        combobox = GTK_COMBO_BOX (gtk_builder_get_object (panel->priv->builder,
3656
 
                                                          "combobox_wireless_network_name"));
3657
 
        g_signal_connect (combobox, "changed",
3658
 
                          G_CALLBACK (wireless_ap_changed_cb),
3659
 
                          panel);
3660
 
 
3661
 
        renderer = panel_cell_renderer_mode_new ();
3662
 
        gtk_cell_renderer_set_padding (renderer, 4, 0);
3663
 
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
3664
 
                                    renderer,
3665
 
                                    FALSE);
3666
 
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
3667
 
                                        "mode", PANEL_WIRELESS_COLUMN_MODE,
3668
 
                                        NULL);
3669
 
 
3670
 
        renderer = panel_cell_renderer_security_new ();
3671
 
        gtk_cell_renderer_set_padding (renderer, 4, 0);
3672
 
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
3673
 
                                    renderer,
3674
 
                                    FALSE);
3675
 
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
3676
 
                                        "security", PANEL_WIRELESS_COLUMN_SECURITY,
3677
 
                                        NULL);
3678
 
 
3679
 
        /* sort networks in drop down */
3680
 
        sortable = GTK_TREE_SORTABLE (gtk_builder_get_object (panel->priv->builder,
3681
 
                                                              "liststore_wireless_network"));
3682
 
        gtk_tree_sortable_set_sort_column_id (sortable,
3683
 
                                              PANEL_WIRELESS_COLUMN_SORT,
3684
 
                                              GTK_SORT_ASCENDING);
3685
 
        gtk_tree_sortable_set_sort_func (sortable,
3686
 
                                         PANEL_WIRELESS_COLUMN_SORT,
3687
 
                                         wireless_ap_model_sort_cb,
3688
 
                                         sortable,
3689
 
                                         NULL);
3690
 
 
3691
 
        renderer = panel_cell_renderer_signal_new ();
3692
 
        gtk_cell_renderer_set_padding (renderer, 4, 0);
3693
 
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
3694
 
                                    renderer,
3695
 
                                    FALSE);
3696
 
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
3697
 
                                        "signal", PANEL_WIRELESS_COLUMN_STRENGTH,
3698
 
                                        NULL);
3699
 
 
3700
 
        /* use NetworkManager client */
3701
 
        panel->priv->client = nm_client_new ();
3702
 
        g_signal_connect (panel->priv->client, "notify::" NM_CLIENT_MANAGER_RUNNING,
3703
 
                          G_CALLBACK (manager_running), panel);
3704
 
        g_signal_connect (panel->priv->client, "notify::" NM_CLIENT_ACTIVE_CONNECTIONS,
3705
 
                          G_CALLBACK (active_connections_changed), panel);
3706
 
        g_signal_connect (panel->priv->client, "device-added",
3707
 
                          G_CALLBACK (device_added_cb), panel);
3708
 
        g_signal_connect (panel->priv->client, "device-removed",
3709
 
                          G_CALLBACK (device_removed_cb), panel);
3710
 
 
3711
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3712
 
                                                     "device_wired_off_switch"));
3713
 
        g_signal_connect (widget, "notify::active",
3714
 
                          G_CALLBACK (device_off_toggled), panel);
3715
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3716
 
                                                     "device_wireless_off_switch"));
3717
 
        g_signal_connect (widget, "notify::active",
3718
 
                          G_CALLBACK (device_off_toggled), panel);
3719
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3720
 
                                                     "device_mobilebb_off_switch"));
3721
 
        g_signal_connect (widget, "notify::active",
3722
 
                          G_CALLBACK (device_off_toggled), panel);
3723
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3724
 
                                                     "device_vpn_off_switch"));
3725
 
        g_signal_connect (widget, "notify::active",
3726
 
                          G_CALLBACK (device_off_toggled), panel);
3727
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3728
 
                                                     "device_proxy_off_switch"));
3729
 
        g_signal_connect (widget, "notify::active",
3730
 
                          G_CALLBACK (device_off_toggled), panel);
3731
 
 
3732
 
        g_signal_connect (panel->priv->client, "notify::wireless-enabled",
3733
 
                          G_CALLBACK (wireless_enabled_toggled), panel);
3734
 
        g_signal_connect (panel->priv->client, "notify::wimax-enabled",
3735
 
                          G_CALLBACK (wimax_enabled_toggled), panel);
3736
 
        g_signal_connect (panel->priv->client, "notify::wwan-enabled",
3737
 
                          G_CALLBACK (mobilebb_enabled_toggled), panel);
3738
 
 
3739
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3740
 
                                                     "start_hotspot_button"));
3741
 
        g_signal_connect (widget, "clicked",
3742
 
                          G_CALLBACK (start_hotspot), panel);
3743
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3744
 
                                                     "stop_hotspot_button"));
3745
 
        g_signal_connect (widget, "clicked",
3746
 
                          G_CALLBACK (stop_hotspot), panel);
3747
 
 
3748
 
 
3749
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3750
 
                                                     "button_wired_options"));
3751
 
        g_signal_connect (widget, "clicked",
3752
 
                          G_CALLBACK (edit_connection), panel);
3753
 
 
3754
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3755
 
                                                     "button_wireless_options"));
3756
 
        g_signal_connect (widget, "clicked",
3757
 
                          G_CALLBACK (edit_connection), panel);
3758
 
 
3759
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3760
 
                                                     "button_mobilebb_options"));
3761
 
        g_signal_connect (widget, "clicked",
3762
 
                          G_CALLBACK (edit_connection), panel);
3763
 
 
3764
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3765
 
                                                     "button_vpn_options"));
3766
 
        g_signal_connect (widget, "clicked",
3767
 
                          G_CALLBACK (edit_connection), panel);
3768
 
 
3769
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3770
 
                                                     "add_toolbutton"));
3771
 
        g_signal_connect (widget, "clicked",
3772
 
                          G_CALLBACK (add_connection_cb), panel);
3773
 
 
3774
 
        /* disable for now, until we actually show removable connections */
3775
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3776
 
                                                     "remove_toolbutton"));
3777
 
        g_signal_connect (widget, "clicked",
3778
 
                          G_CALLBACK (remove_connection), panel);
3779
 
 
3780
 
        /* setup wireless button */
3781
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3782
 
                                                     "button_wireless_button"));
3783
 
        g_signal_connect (widget, "clicked",
3784
 
                          G_CALLBACK (wireless_button_clicked_cb), panel);
3785
 
 
3786
 
        /* add remote settings such as VPN settings as virtual devices */
3787
 
        bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
3788
 
        if (bus == NULL) {
3789
 
                g_warning ("Error connecting to system D-Bus: %s",
3790
 
                           error->message);
3791
 
                g_error_free (error);
3792
 
        }
3793
 
        panel->priv->remote_settings = nm_remote_settings_new (bus);
3794
 
        g_signal_connect (panel->priv->remote_settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ,
3795
 
                          G_CALLBACK (notify_connections_read_cb), panel);
3796
 
        g_signal_connect (panel->priv->remote_settings, NM_REMOTE_SETTINGS_NEW_CONNECTION,
3797
 
                          G_CALLBACK (notify_new_connection_cb), panel);
3798
 
 
3799
 
        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (panel));
3800
 
        g_signal_connect_after (toplevel, "map", G_CALLBACK (on_toplevel_map), panel);
3801
 
 
3802
 
        /* hide implementation details */
3803
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3804
 
                                                     "notebook_types"));
3805
 
        gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), FALSE);
3806
 
 
3807
 
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3808
 
                                                     "vbox1"));
3809
 
        gtk_widget_reparent (widget, (GtkWidget *) panel);
3810
 
 
3811
 
        /* add kill switch widgets when dialog activated */
3812
 
        panel->priv->add_header_widgets_idle = g_idle_add (network_add_shell_header_widgets_cb, panel);
3813
 
}
3814
 
 
3815
 
void
3816
 
cc_network_panel_register (GIOModule *module)
3817
 
{
3818
 
        cc_network_panel_register_type (G_TYPE_MODULE (module));
3819
 
        g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
3820
 
                                        CC_TYPE_NETWORK_PANEL,
3821
 
                                        "network", 0);
3822
 
}