1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* Copyright (C) 2010-2011 Richard Hughes <richard@hughsie.com>
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.
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.
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.
22
#include <glib/gi18n.h>
23
#include <arpa/inet.h>
26
#include "cc-network-panel.h"
29
#include "nm-remote-settings.h"
30
#include "nm-client.h"
31
#include "nm-device.h"
32
#include "nm-device-ethernet.h"
33
#include "nm-device-modem.h"
34
#include "nm-device-wifi.h"
36
#include "nm-active-connection.h"
37
#include "nm-vpn-connection.h"
38
#include "nm-setting-ip4-config.h"
39
#include "nm-setting-ip6-config.h"
40
#include "nm-setting-connection.h"
41
#include "nm-setting-vpn.h"
42
#include "nm-setting-wireless.h"
44
#include "net-object.h"
45
#include "net-device.h"
48
#include "panel-common.h"
49
#include "panel-cell-renderer-mode.h"
50
#include "panel-cell-renderer-signal.h"
51
#include "panel-cell-renderer-security.h"
54
G_DEFINE_DYNAMIC_TYPE (CcNetworkPanel, cc_network_panel, CC_TYPE_PANEL)
56
#define NETWORK_PANEL_PRIVATE(o) \
57
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_NETWORK_PANEL, CcNetworkPanelPrivate))
59
struct _CcNetworkPanelPrivate
61
GCancellable *cancellable;
62
GSettings *proxy_settings;
64
gboolean updating_device;
68
PANEL_DEVICES_COLUMN_ICON,
69
PANEL_DEVICES_COLUMN_TITLE,
70
PANEL_DEVICES_COLUMN_SORT,
71
PANEL_DEVICES_COLUMN_OBJECT,
72
PANEL_DEVICES_COLUMN_LAST
76
PANEL_WIRELESS_COLUMN_ID,
77
PANEL_WIRELESS_COLUMN_TITLE,
78
PANEL_WIRELESS_COLUMN_SORT,
79
PANEL_WIRELESS_COLUMN_STRENGTH,
80
PANEL_WIRELESS_COLUMN_MODE,
81
PANEL_WIRELESS_COLUMN_SECURITY,
82
PANEL_WIRELESS_COLUMN_LAST
85
static void refresh_ui (CcNetworkPanel *panel);
88
cc_network_panel_get_property (GObject *object,
93
switch (property_id) {
95
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
100
cc_network_panel_set_property (GObject *object,
105
switch (property_id) {
107
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
112
cc_network_panel_dispose (GObject *object)
114
CcNetworkPanelPrivate *priv = CC_NETWORK_PANEL (object)->priv;
116
if (priv->proxy_settings) {
117
g_object_unref (priv->proxy_settings);
118
priv->proxy_settings = NULL;
120
if (priv->cancellable != NULL) {
121
g_cancellable_cancel (priv->cancellable);
122
g_object_unref (priv->cancellable);
123
priv->cancellable = NULL;
125
if (priv->builder != NULL) {
126
g_object_unref (priv->builder);
127
priv->builder = NULL;
130
if (priv->client != NULL) {
131
g_object_unref (priv->client);
134
if (priv->remote_settings != NULL) {
135
g_object_unref (priv->remote_settings);
136
priv->remote_settings = NULL;
140
G_OBJECT_CLASS (cc_network_panel_parent_class)->dispose (object);
144
cc_network_panel_finalize (GObject *object)
146
G_OBJECT_CLASS (cc_network_panel_parent_class)->finalize (object);
150
cc_network_panel_class_init (CcNetworkPanelClass *klass)
152
GObjectClass *object_class = G_OBJECT_CLASS (klass);
154
g_type_class_add_private (klass, sizeof (CcNetworkPanelPrivate));
156
object_class->get_property = cc_network_panel_get_property;
157
object_class->set_property = cc_network_panel_set_property;
158
object_class->dispose = cc_network_panel_dispose;
159
object_class->finalize = cc_network_panel_finalize;
163
cc_network_panel_class_finalize (CcNetworkPanelClass *klass)
168
check_wpad_warning (CcNetworkPanel *panel)
171
gchar *autoconfig_url = NULL;
172
GString *string = NULL;
173
gboolean ret = FALSE;
176
string = g_string_new ("");
178
/* check we're using 'Automatic' */
179
mode = g_settings_get_enum (panel->priv->proxy_settings, "mode");
183
/* see if the PAC is blank */
184
autoconfig_url = g_settings_get_string (panel->priv->proxy_settings,
186
ret = autoconfig_url == NULL ||
187
autoconfig_url[0] == '\0';
191
g_string_append (string, "<small>");
193
/* TRANSLATORS: this is when the use leaves the PAC textbox blank */
194
g_string_append (string, _("Web Proxy Autodiscovery is used when a Configuration URL is not provided."));
196
g_string_append (string, " ");
198
/* TRANSLATORS: WPAD is bad: if you enable it on an untrusted
199
* network, then anyone else on that network can tell your
200
* machine that it should proxy all of your web traffic
202
g_string_append (string, _("This is not recommended for untrusted public networks."));
203
g_string_append (string, "</small>");
205
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
206
"label_proxy_warning"));
207
gtk_label_set_markup (GTK_LABEL (widget), string->str);
208
g_free (autoconfig_url);
209
g_string_free (string, TRUE);
213
panel_settings_changed (GSettings *settings,
215
CcNetworkPanel *panel)
217
check_wpad_warning (panel);
222
get_selected_object (CcNetworkPanel *panel)
225
GtkTreeSelection *selection;
228
NetObject *object = NULL;
230
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
231
"treeview_devices"));
232
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
233
if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
237
gtk_tree_model_get (model, &iter,
238
PANEL_DEVICES_COLUMN_OBJECT, &object,
246
panel_proxy_mode_combo_setup_widgets (CcNetworkPanel *panel, guint value)
250
/* hide or show the PAC text box */
251
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
252
"heading_proxy_url"));
253
gtk_widget_set_visible (widget, value == 2);
254
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
256
gtk_widget_set_visible (widget, value == 2);
258
/* hide or show the manual entry text boxes */
259
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
260
"heading_proxy_http"));
261
gtk_widget_set_visible (widget, value == 1);
262
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
263
"entry_proxy_http"));
264
gtk_widget_set_visible (widget, value == 1);
265
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
266
"spinbutton_proxy_http"));
267
gtk_widget_set_visible (widget, value == 1);
269
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
270
"heading_proxy_https"));
271
gtk_widget_set_visible (widget, value == 1);
272
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
273
"entry_proxy_https"));
274
gtk_widget_set_visible (widget, value == 1);
275
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
276
"spinbutton_proxy_https"));
277
gtk_widget_set_visible (widget, value == 1);
278
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
279
"heading_proxy_ftp"));
280
gtk_widget_set_visible (widget, value == 1);
281
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
283
gtk_widget_set_visible (widget, value == 1);
284
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
285
"spinbutton_proxy_ftp"));
286
gtk_widget_set_visible (widget, value == 1);
287
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
288
"heading_proxy_socks"));
289
gtk_widget_set_visible (widget, value == 1);
290
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
291
"entry_proxy_socks"));
292
gtk_widget_set_visible (widget, value == 1);
293
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
294
"spinbutton_proxy_socks"));
295
gtk_widget_set_visible (widget, value == 1);
297
/* perhaps show the wpad warning */
298
check_wpad_warning (panel);
302
panel_proxy_mode_combo_changed_cb (GtkWidget *widget, CcNetworkPanel *panel)
310
ret = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter);
315
model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
316
gtk_tree_model_get (model, &iter,
321
g_settings_set_enum (panel->priv->proxy_settings, "mode", value);
323
/* hide or show the correct widgets */
324
panel_proxy_mode_combo_setup_widgets (panel, value);
328
panel_set_value_for_combo (CcNetworkPanel *panel, GtkComboBox *combo_box, gint value)
336
model = gtk_combo_box_get_model (combo_box);
337
ret = gtk_tree_model_get_iter_first (model, &iter);
341
/* try to make the UI match the setting */
343
gtk_tree_model_get (model, &iter,
346
if (value == value_tmp) {
347
gtk_combo_box_set_active_iter (combo_box, &iter);
350
} while (gtk_tree_model_iter_next (model, &iter));
352
/* hide or show the correct widgets */
353
panel_proxy_mode_combo_setup_widgets (panel, value);
357
select_first_device (CcNetworkPanel *panel)
361
GtkTreeSelection *selection;
363
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
364
"treeview_devices"));
365
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
367
/* select the first device */
368
path = gtk_tree_path_new_from_string ("0");
369
gtk_tree_selection_select_path (selection, path);
370
gtk_tree_path_free (path);
375
panel_device_got_modem_manager_cb (GObject *source_object,
379
GError *error = NULL;
380
GVariant *result = NULL;
382
NMDevice *device = (NMDevice *) user_data;
384
proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
386
g_warning ("Error creating ModemManager proxy: %s",
388
g_error_free (error);
393
result = g_dbus_proxy_get_cached_property (proxy,
394
"EquipmentIdentifier");
397
g_object_set_data_full (G_OBJECT (device),
398
"ControlCenter::EquipmentIdentifier",
399
g_variant_dup_string (result, NULL),
403
g_variant_unref (result);
405
g_object_unref (proxy);
410
panel_get_registration_info_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
412
gchar *operator_code = NULL;
413
GError *error = NULL;
414
guint registration_status;
415
GVariant *result = NULL;
416
gchar *operator_name = NULL;
417
gchar *operator_name_safe = NULL;
418
NMDevice *device = (NMDevice *) user_data;
420
result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
421
if (result == NULL) {
422
g_warning ("Error getting registration info: %s\n",
424
g_error_free (error);
429
g_variant_get (result, "((uss))",
430
®istration_status,
433
if (operator_name != NULL && operator_name[0] != '\0')
434
operator_name_safe = g_strescape (operator_name, NULL);
437
g_object_set_data_full (G_OBJECT (device),
438
"ControlCenter::OperatorName",
442
g_free (operator_name);
443
g_free (operator_name_safe);
444
g_free (operator_code);
445
g_variant_unref (result);
449
panel_device_got_modem_manager_gsm_cb (GObject *source_object,
453
GError *error = NULL;
455
NMDevice *device = (NMDevice *) user_data;
457
proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
459
g_warning ("Error creating ModemManager GSM proxy: %s\n",
461
g_error_free (error);
465
g_dbus_proxy_call (proxy,
466
"GetRegistrationInfo",
468
G_DBUS_CALL_FLAGS_NONE,
471
panel_get_registration_info_cb,
475
g_object_unref (proxy);
480
device_state_notify_changed_cb (NMDevice *device,
482
CcNetworkPanel *panel)
488
object_changed_cb (NetObject *object, CcNetworkPanel *panel)
494
object_removed_cb (NetObject *object, CcNetworkPanel *panel)
497
NetObject *object_tmp;
501
GtkTreeSelection *selection;
503
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
504
"treeview_devices"));
505
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
507
/* remove device from model */
508
model = GTK_TREE_MODEL (gtk_builder_get_object (panel->priv->builder,
509
"liststore_devices"));
510
ret = gtk_tree_model_get_iter_first (model, &iter);
514
/* get the other elements */
516
gtk_tree_model_get (model, &iter,
517
PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
519
if (g_strcmp0 (net_object_get_id (object),
520
net_object_get_id (object_tmp)) == 0) {
521
g_object_unref (object_tmp);
522
if (!gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
523
gtk_tree_model_get_iter_first (model, &iter);
524
gtk_tree_selection_select_iter (selection, &iter);
528
g_object_unref (object_tmp);
529
} while (gtk_tree_model_iter_next (model, &iter));
533
register_object_interest (CcNetworkPanel *panel, NetObject *object)
535
g_signal_connect (object,
537
G_CALLBACK (object_changed_cb),
539
g_signal_connect (object,
541
G_CALLBACK (object_removed_cb),
546
panel_add_device (CcNetworkPanel *panel, NMDevice *device)
548
GtkListStore *liststore_devices;
552
NetDevice *net_device;
553
CcNetworkPanelPrivate *priv = panel->priv;
555
/* do we have an existing object with this id? */
556
if (find_in_model_by_id (panel, nm_device_get_udi (device)) != NULL)
559
/* we don't support bluetooth devices yet -- no mockup */
560
type = nm_device_get_device_type (device);
561
if (type == NM_DEVICE_TYPE_BT)
564
g_debug ("device %s type %i",
565
nm_device_get_udi (device),
566
nm_device_get_device_type (device));
567
g_signal_connect (G_OBJECT (device), "notify::state",
568
(GCallback) device_state_notify_changed_cb, panel);
570
/* do we have to get additonal data from ModemManager */
571
if (type == NM_DEVICE_TYPE_MODEM) {
572
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
573
G_DBUS_PROXY_FLAGS_NONE,
575
"org.freedesktop.ModemManager",
576
nm_device_get_udi (device),
577
"org.freedesktop.ModemManager.Modem",
578
panel->priv->cancellable,
579
panel_device_got_modem_manager_cb,
581
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
582
G_DBUS_PROXY_FLAGS_NONE,
584
"org.freedesktop.ModemManager",
585
nm_device_get_udi (device),
586
"org.freedesktop.ModemManager.Modem.Gsm.Network",
587
panel->priv->cancellable,
588
panel_device_got_modem_manager_gsm_cb,
592
/* make title a bit bigger */
593
title = g_strdup_printf ("<span size=\"large\">%s</span>",
594
panel_device_to_localized_string (device));
596
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
597
"liststore_devices"));
598
net_device = net_device_new ();
599
net_device_set_nm_device (net_device, device);
600
net_object_set_id (NET_OBJECT (net_device), nm_device_get_udi (device));
601
register_object_interest (panel, NET_OBJECT (net_device));
602
gtk_list_store_append (liststore_devices, &iter);
603
gtk_list_store_set (liststore_devices,
605
PANEL_DEVICES_COLUMN_ICON, panel_device_to_icon_name (device),
606
PANEL_DEVICES_COLUMN_SORT, panel_device_to_sortable_string (device),
607
PANEL_DEVICES_COLUMN_TITLE, title,
608
PANEL_DEVICES_COLUMN_OBJECT, net_device,
615
panel_remove_device (CcNetworkPanel *panel, NMDevice *device)
618
NetObject *object_tmp;
622
/* remove device from model */
623
model = GTK_TREE_MODEL (gtk_builder_get_object (panel->priv->builder,
624
"liststore_devices"));
625
ret = gtk_tree_model_get_iter_first (model, &iter);
629
/* get the other elements */
631
gtk_tree_model_get (model, &iter,
632
PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
634
if (g_strcmp0 (net_object_get_id (object_tmp),
635
nm_device_get_udi (device)) == 0) {
636
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
637
g_object_unref (object_tmp);
640
g_object_unref (object_tmp);
641
} while (gtk_tree_model_iter_next (model, &iter));
646
panel_add_devices_columns (CcNetworkPanel *panel, GtkTreeView *treeview)
648
CcNetworkPanelPrivate *priv = panel->priv;
649
GtkCellRenderer *renderer;
650
GtkListStore *liststore_devices;
651
GtkTreeViewColumn *column;
654
renderer = gtk_cell_renderer_pixbuf_new ();
655
g_object_set (renderer, "stock-size", GTK_ICON_SIZE_DND, NULL);
656
column = gtk_tree_view_column_new_with_attributes ("", renderer,
657
"icon-name", PANEL_DEVICES_COLUMN_ICON,
659
gtk_tree_view_append_column (treeview, column);
661
/* column for text */
662
renderer = gtk_cell_renderer_text_new ();
663
g_object_set (renderer,
664
"wrap-mode", PANGO_WRAP_WORD,
666
column = gtk_tree_view_column_new_with_attributes ("", renderer,
667
"markup", PANEL_DEVICES_COLUMN_TITLE,
669
gtk_tree_view_column_set_sort_column_id (column, PANEL_DEVICES_COLUMN_SORT);
670
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
671
"liststore_devices"));
672
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (liststore_devices),
673
PANEL_DEVICES_COLUMN_SORT,
675
gtk_tree_view_append_column (treeview, column);
676
gtk_tree_view_column_set_expand (column, TRUE);
681
panel_set_widget_data (CcNetworkPanel *panel,
682
const gchar *sub_pane,
683
const gchar *widget_suffix,
687
gchar *label_id = NULL;
690
CcNetworkPanelPrivate *priv = panel->priv;
692
/* hide the row if there is no value */
693
heading_id = g_strdup_printf ("heading_%s_%s", sub_pane, widget_suffix);
694
label_id = g_strdup_printf ("label_%s_%s", sub_pane, widget_suffix);
695
heading = GTK_WIDGET (gtk_builder_get_object (priv->builder, heading_id));
696
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, label_id));
697
if (heading == NULL || widget == NULL) {
698
g_critical ("no widgets %s, %s found", heading_id, label_id);
705
gtk_widget_hide (heading);
706
gtk_widget_hide (widget);
708
/* there exists a value */
709
gtk_widget_show (heading);
710
gtk_widget_show (widget);
711
gtk_label_set_label (GTK_LABEL (widget), value);
716
panel_set_widget_heading (CcNetworkPanel *panel,
717
const gchar *sub_pane,
718
const gchar *widget_suffix,
719
const gchar *heading)
721
gchar *label_id = NULL;
724
label_id = g_strdup_printf ("heading_%s_%s", sub_pane, widget_suffix);
725
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, label_id));
727
gtk_label_set_label (GTK_LABEL (widget), heading);
732
get_access_point_security (NMAccessPoint *ap)
734
NM80211ApFlags flags;
735
NM80211ApSecurityFlags wpa_flags;
736
NM80211ApSecurityFlags rsn_flags;
739
flags = nm_access_point_get_flags (ap);
740
wpa_flags = nm_access_point_get_wpa_flags (ap);
741
rsn_flags = nm_access_point_get_rsn_flags (ap);
743
if (!(flags & NM_802_11_AP_FLAGS_PRIVACY) &&
744
wpa_flags == NM_802_11_AP_SEC_NONE &&
745
rsn_flags == NM_802_11_AP_SEC_NONE)
746
type = NM_AP_SEC_NONE;
747
else if ((flags & NM_802_11_AP_FLAGS_PRIVACY) &&
748
wpa_flags == NM_802_11_AP_SEC_NONE &&
749
rsn_flags == NM_802_11_AP_SEC_NONE)
750
type = NM_AP_SEC_WEP;
751
else if (!(flags & NM_802_11_AP_FLAGS_PRIVACY) &&
752
wpa_flags != NM_802_11_AP_SEC_NONE &&
753
rsn_flags != NM_802_11_AP_SEC_NONE)
754
type = NM_AP_SEC_WPA;
756
type = NM_AP_SEC_WPA2;
762
add_access_point (CcNetworkPanel *panel, NMAccessPoint *ap, NMAccessPoint *active)
764
CcNetworkPanelPrivate *priv = panel->priv;
765
const GByteArray *ssid;
766
const gchar *ssid_text;
767
const gchar *object_path;
768
GtkListStore *liststore_wireless_network;
769
GtkTreeIter treeiter;
772
ssid = nm_access_point_get_ssid (ap);
775
ssid_text = nm_utils_escape_ssid (ssid->data, ssid->len);
777
liststore_wireless_network = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
778
"liststore_wireless_network"));
780
object_path = nm_object_get_path (NM_OBJECT (ap));
781
gtk_list_store_append (liststore_wireless_network, &treeiter);
782
gtk_list_store_set (liststore_wireless_network,
784
PANEL_WIRELESS_COLUMN_ID, object_path,
785
PANEL_WIRELESS_COLUMN_TITLE, ssid_text,
786
PANEL_WIRELESS_COLUMN_SORT, ssid_text,
787
PANEL_WIRELESS_COLUMN_STRENGTH, nm_access_point_get_strength (ap),
788
PANEL_WIRELESS_COLUMN_MODE, nm_access_point_get_mode (ap),
789
PANEL_WIRELESS_COLUMN_SECURITY, get_access_point_security (ap),
792
/* is this what we're on already? */
795
if (g_strcmp0 (object_path,
796
nm_object_get_path (NM_OBJECT (active))) == 0) {
797
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
798
"combobox_wireless_network_name"));
799
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &treeiter);
804
add_access_point_other (CcNetworkPanel *panel)
806
CcNetworkPanelPrivate *priv = panel->priv;
807
GtkListStore *liststore_wireless_network;
808
GtkTreeIter treeiter;
810
liststore_wireless_network = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
811
"liststore_wireless_network"));
813
gtk_list_store_append (liststore_wireless_network, &treeiter);
814
gtk_list_store_set (liststore_wireless_network,
816
PANEL_WIRELESS_COLUMN_ID, "ap-other...",
817
/* TRANSLATORS: this is when the access point is not listed
818
* in the dropdown (or hidden) and the user has to select
819
* another entry manually */
820
PANEL_WIRELESS_COLUMN_TITLE, C_("Wireless access point", "Other..."),
822
PANEL_WIRELESS_COLUMN_SORT, "",
823
PANEL_WIRELESS_COLUMN_STRENGTH, 0,
824
PANEL_WIRELESS_COLUMN_MODE, NM_802_11_MODE_UNKNOWN,
825
PANEL_WIRELESS_COLUMN_SECURITY, NM_AP_SEC_UNKNOWN,
831
ip4_address_as_string (guint32 ip)
833
char buf[INET_ADDRSTRLEN+1];
834
struct in_addr tmp_addr;
836
memset (&buf, '\0', sizeof (buf));
837
tmp_addr.s_addr = ip;
839
if (inet_ntop (AF_INET, &tmp_addr, buf, INET_ADDRSTRLEN)) {
840
return g_strdup (buf);
842
g_warning ("error converting IP4 address 0x%X",
843
ntohl (tmp_addr.s_addr));
849
panel_show_ip4_config (NMIP4Config *cfg)
853
const GPtrArray *ptr_array;
857
for (iter = (GSList *) nm_ip4_config_get_addresses (cfg); iter; iter = g_slist_next (iter)) {
858
NMIP4Address *addr = iter->data;
861
tmp = ip4_address_as_string (nm_ip4_address_get_address (addr));
862
g_debug ("IP4 address: %s", tmp);
865
u = nm_ip4_address_get_prefix (addr);
866
tmp = ip4_address_as_string (nm_utils_ip4_prefix_to_netmask (u));
867
g_debug ("IP4 prefix: %d (%s)", u, tmp);
870
tmp = ip4_address_as_string (nm_ip4_address_get_gateway (addr));
871
g_debug ("IP4 gateway: %s", tmp);
875
array = nm_ip4_config_get_nameservers (cfg);
877
g_debug ("IP4 DNS:");
878
for (i = 0; i < array->len; i++) {
879
tmp = ip4_address_as_string (g_array_index (array, guint32, i));
880
g_debug ("\t%s", tmp);
885
ptr_array = nm_ip4_config_get_domains (cfg);
887
g_debug ("IP4 domains:");
888
for (i = 0; i < ptr_array->len; i++)
889
g_debug ("\t%s", (const char *) g_ptr_array_index (ptr_array, i));
892
array = nm_ip4_config_get_wins_servers (cfg);
894
g_debug ("IP4 WINS:");
895
for (i = 0; i < array->len; i++) {
896
tmp = ip4_address_as_string (g_array_index (array, guint32, i));
897
g_debug ("\t%s", tmp);
905
panel_get_strongest_unique_aps (const GPtrArray *aps)
907
const GByteArray *ssid;
908
const GByteArray *ssid_tmp;
909
GPtrArray *aps_unique = NULL;
914
NMAccessPoint *ap_tmp;
916
/* we will have multiple entries for typical hotspots, just
917
* filter to the one with the strongest signal */
918
aps_unique = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
920
for (i = 0; i < aps->len; i++) {
921
ap = NM_ACCESS_POINT (g_ptr_array_index (aps, i));
922
ssid = nm_access_point_get_ssid (ap);
925
/* get already added list */
926
for (j=0; j<aps_unique->len; j++) {
927
ap_tmp = NM_ACCESS_POINT (g_ptr_array_index (aps_unique, j));
928
ssid_tmp = nm_access_point_get_ssid (ap_tmp);
930
/* is this the same type and data? */
931
if (nm_utils_same_ssid (ssid, ssid_tmp, TRUE)) {
933
g_debug ("found duplicate: %s",
934
nm_utils_escape_ssid (ssid_tmp->data,
937
/* the new access point is stronger */
938
if (nm_access_point_get_strength (ap) >
939
nm_access_point_get_strength (ap_tmp)) {
940
g_debug ("removing %s",
941
nm_utils_escape_ssid (ssid_tmp->data,
943
g_ptr_array_remove (aps_unique, ap_tmp);
953
g_debug ("adding %s",
954
nm_utils_escape_ssid (ssid->data,
956
g_ptr_array_add (aps_unique, g_object_ref (ap));
963
get_ap_security_string (NMAccessPoint *ap)
965
NM80211ApSecurityFlags wpa_flags, rsn_flags;
966
NM80211ApFlags flags;
969
flags = nm_access_point_get_flags (ap);
970
wpa_flags = nm_access_point_get_wpa_flags (ap);
971
rsn_flags = nm_access_point_get_rsn_flags (ap);
973
str = g_string_new ("");
974
if ((flags & NM_802_11_AP_FLAGS_PRIVACY) &&
975
(wpa_flags == NM_802_11_AP_SEC_NONE) &&
976
(rsn_flags == NM_802_11_AP_SEC_NONE)) {
977
/* TRANSLATORS: this WEP WiFi security */
978
g_string_append_printf (str, "%s, ", _("WEP"));
980
if (wpa_flags != NM_802_11_AP_SEC_NONE) {
981
/* TRANSLATORS: this WPA WiFi security */
982
g_string_append_printf (str, "%s, ", _("WPA"));
984
if (rsn_flags != NM_802_11_AP_SEC_NONE) {
985
/* TRANSLATORS: this WPA WiFi security */
986
g_string_append_printf (str, "%s, ", _("WPA2"));
988
if ((wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) ||
989
(rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
990
/* TRANSLATORS: this Enterprise WiFi security */
991
g_string_append_printf (str, "%s, ", _("Enterprise"));
994
g_string_set_size (str, str->len - 2);
996
/* TRANSLATORS: this no (!) WiFi security */
997
g_string_append (str, _("None"));
999
return g_string_free (str, FALSE);
1003
get_ipv6_config_address_as_string (NMIP6Config *ip6_config)
1006
const struct in6_addr *addr;
1009
NMIP6Address *address;
1012
list = nm_ip6_config_get_addresses (ip6_config);
1016
/* we only care about one address */
1017
address = list->data;
1018
addr = nm_ip6_address_get_address (address);
1021
inet_ntop (AF_INET6, addr, tmp, sizeof(tmp));
1022
str = g_strdup (tmp);
1027
static NMConnection *
1028
find_connection_for_device (CcNetworkPanel *panel,
1031
const GPtrArray *connections;
1032
const GPtrArray *devices;
1033
NMActiveConnection *c;
1036
connections = nm_client_get_active_connections (panel->priv->client);
1038
for (i = 0; i < connections->len; i++) {
1039
c = (NMActiveConnection *)connections->pdata[i];
1041
devices = nm_active_connection_get_devices (c);
1042
if (devices->pdata[0] == device) {
1043
return (NMConnection *)nm_remote_settings_get_connection_by_path (panel->priv->remote_settings, nm_active_connection_get_connection (c));
1051
device_off_toggled (GtkSwitch *sw,
1053
CcNetworkPanel *panel)
1059
if (panel->priv->updating_device)
1062
active = gtk_switch_get_active (sw);
1064
object = get_selected_object (panel);
1065
if (NET_IS_VPN (object)) {
1067
NMConnection *connection;
1069
connection = net_vpn_get_connection (NET_VPN (object));
1071
nm_client_activate_connection (panel->priv->client,
1072
connection, NULL, NULL,
1076
NMActiveConnection *a;
1077
const GPtrArray *acs;
1080
path = nm_connection_get_path (connection);
1082
acs = nm_client_get_active_connections (panel->priv->client);
1083
for (i = 0; i < acs->len; i++) {
1084
a = (NMActiveConnection*)acs->pdata[i];
1085
if (strcmp (nm_active_connection_get_connection (a), path) == 0) {
1086
nm_client_deactivate_connection (panel->priv->client, a);
1093
if (NET_IS_DEVICE (object)) {
1094
device = net_device_get_nm_device (NET_DEVICE (object));
1095
switch (nm_device_get_device_type (device)) {
1096
case NM_DEVICE_TYPE_ETHERNET:
1098
GSList *list, *filtered;
1100
/* look for an existing connection we can use */
1101
list = nm_remote_settings_list_connections (panel->priv->remote_settings);
1102
filtered = nm_device_filter_connections (device, list);
1104
nm_client_activate_connection (panel->priv->client,
1105
(NMConnection *)filtered->data,
1111
nm_client_add_and_activate_connection (panel->priv->client,
1118
g_slist_free (list);
1119
g_slist_free (filtered);
1121
nm_device_disconnect (device, NULL, NULL);
1124
case NM_DEVICE_TYPE_WIFI:
1125
nm_client_wireless_set_enabled (panel->priv->client, active);
1127
case NM_DEVICE_TYPE_WIMAX:
1128
nm_client_wimax_set_enabled (panel->priv->client, active);
1131
/* FIXME: handle other device types */
1137
wireless_enabled_toggled (NMClient *client,
1139
CcNetworkPanel *panel)
1146
object = get_selected_object (panel);
1149
device = net_device_get_nm_device (NET_DEVICE (object));
1151
if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_WIFI)
1154
enabled = nm_client_wireless_get_enabled (client);
1155
sw = GTK_SWITCH (gtk_builder_get_object (panel->priv->builder,
1156
"device_wireless_off_switch"));
1158
panel->priv->updating_device = TRUE;
1159
gtk_switch_set_active (sw, enabled);
1160
panel->priv->updating_device = FALSE;
1164
wimax_enabled_toggled (NMClient *client,
1166
CcNetworkPanel *panel)
1173
object = get_selected_object (panel);
1176
device = net_device_get_nm_device (NET_DEVICE (object));
1178
if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_WIMAX)
1181
enabled = nm_client_wimax_get_enabled (client);
1182
sw = GTK_SWITCH (gtk_builder_get_object (panel->priv->builder,
1183
"device_wimax_off_switch"));
1185
panel->priv->updating_device = TRUE;
1186
gtk_switch_set_active (sw, enabled);
1187
panel->priv->updating_device = FALSE;
1191
update_off_switch_from_device_state (GtkSwitch *sw, NMDeviceState state, CcNetworkPanel *panel)
1193
panel->priv->updating_device = TRUE;
1195
case NM_DEVICE_STATE_UNMANAGED:
1196
case NM_DEVICE_STATE_UNAVAILABLE:
1197
case NM_DEVICE_STATE_DISCONNECTED:
1198
case NM_DEVICE_STATE_DEACTIVATING:
1199
case NM_DEVICE_STATE_FAILED:
1200
gtk_switch_set_active (sw, FALSE);
1203
gtk_switch_set_active (sw, TRUE);
1206
panel->priv->updating_device = FALSE;
1210
refresh_header_ui (CcNetworkPanel *panel, NMDevice *device, const char *page_name)
1215
NMDeviceState state;
1218
type = nm_device_get_device_type (device);
1220
/* set header icon */
1221
wid_name = g_strdup_printf ("image_%s_device", page_name);
1222
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, wid_name));
1224
gtk_image_set_from_icon_name (GTK_IMAGE (widget),
1225
panel_device_to_icon_name (device),
1226
GTK_ICON_SIZE_DIALOG);
1228
/* set device kind */
1229
wid_name = g_strdup_printf ("label_%s_device", page_name);
1230
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, wid_name));
1232
gtk_label_set_label (GTK_LABEL (widget),
1233
panel_device_to_localized_string (device));
1236
/* set device state */
1237
state = nm_device_get_state (device);
1238
wid_name = g_strdup_printf ("label_%s_status", page_name);
1239
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, wid_name));
1241
str = panel_device_state_to_localized_string (device);
1242
gtk_label_set_label (GTK_LABEL (widget), str);
1245
/* set up the device on/off switch */
1246
wid_name = g_strdup_printf ("device_%s_off_switch", page_name);
1247
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, wid_name));
1250
/* keep this in sync with the signal handler setup in cc_network_panel_init */
1252
case NM_DEVICE_TYPE_ETHERNET:
1253
gtk_widget_set_visible (widget,
1254
state != NM_DEVICE_STATE_UNAVAILABLE
1255
&& state != NM_DEVICE_STATE_UNMANAGED);
1256
update_off_switch_from_device_state (GTK_SWITCH (widget), state, panel);
1258
case NM_DEVICE_TYPE_WIFI:
1259
gtk_widget_show (widget);
1260
wireless_enabled_toggled (panel->priv->client, NULL, panel);
1262
case NM_DEVICE_TYPE_WIMAX:
1263
gtk_widget_show (widget);
1264
wimax_enabled_toggled (panel->priv->client, NULL, panel);
1267
gtk_widget_hide (widget);
1271
/* set up options button */
1272
wid_name = g_strdup_printf ("button_%s_options", page_name);
1273
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, wid_name));
1275
if (widget != NULL) {
1276
gtk_widget_set_sensitive (widget, state == NM_DEVICE_STATE_ACTIVATED);
1281
device_refresh_ethernet_ui (CcNetworkPanel *panel, NetDevice *device)
1284
NMDeviceState state;
1287
NMDevice *nm_device;
1289
nm_device = net_device_get_nm_device (device);
1290
state = nm_device_get_state (nm_device);
1292
refresh_header_ui (panel, nm_device, "wired");
1295
speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (nm_device));
1296
if (state == NM_DEVICE_STATE_UNAVAILABLE)
1299
/* Translators: network device speed */
1300
str_tmp = g_strdup_printf (_("%d Mb/s"), speed);
1302
str_tmp = g_strdup ("");
1303
panel_set_widget_data (panel,
1310
str = nm_device_ethernet_get_hw_address (NM_DEVICE_ETHERNET (nm_device));
1311
panel_set_widget_data (panel,
1319
device_refresh_wifi_ui (CcNetworkPanel *panel, NetDevice *device)
1323
const GPtrArray *aps;
1324
GPtrArray *aps_unique = NULL;
1326
NMDeviceState state;
1328
NMAccessPoint *active_ap;
1331
GtkListStore *liststore_wireless_network;
1333
NMDevice *nm_device;
1335
nm_device = net_device_get_nm_device (device);
1336
state = nm_device_get_state (nm_device);
1338
refresh_header_ui (panel, nm_device, "wireless");
1341
speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (nm_device));
1342
if (state == NM_DEVICE_STATE_UNAVAILABLE)
1345
str_tmp = g_strdup_printf (_("%d Mb/s"),
1348
str_tmp = g_strdup ("");
1349
panel_set_widget_data (panel,
1356
str = nm_device_wifi_get_hw_address (NM_DEVICE_WIFI (nm_device));
1357
panel_set_widget_data (panel,
1362
active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (nm_device));
1363
if (state == NM_DEVICE_STATE_UNAVAILABLE)
1365
else if (active_ap != NULL)
1366
str_tmp = get_ap_security_string (active_ap);
1368
str_tmp = g_strdup ("");
1369
panel_set_widget_data (panel,
1375
heading = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1376
"heading_wireless_network_name"));
1377
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1378
"combobox_wireless_network_name"));
1379
/* populate access point dropdown */
1380
if (state == NM_DEVICE_STATE_UNAVAILABLE) {
1381
gtk_widget_hide (heading);
1382
gtk_widget_hide (widget);
1384
gtk_widget_show (heading);
1385
gtk_widget_show (widget);
1386
liststore_wireless_network = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
1387
"liststore_wireless_network"));
1388
panel->priv->updating_device = TRUE;
1389
gtk_list_store_clear (liststore_wireless_network);
1390
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (nm_device));
1391
aps_unique = panel_get_strongest_unique_aps (aps);
1393
for (i = 0; i < aps_unique->len; i++) {
1394
ap = NM_ACCESS_POINT (g_ptr_array_index (aps_unique, i));
1395
add_access_point (panel, ap, active_ap);
1397
add_access_point_other (panel);
1398
if (active_ap == NULL) {
1399
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1400
"combobox_wireless_network_name"));
1401
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), NULL);
1402
gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (widget))), "");
1405
panel->priv->updating_device = FALSE;
1407
g_ptr_array_unref (aps_unique);
1413
device_refresh_wimax_ui (CcNetworkPanel *panel, NetDevice *device)
1415
NMDevice *nm_device;
1417
nm_device = net_device_get_nm_device (device);
1418
refresh_header_ui (panel, nm_device, "wimax");
1422
device_refresh_modem_ui (CcNetworkPanel *panel, NetDevice *device)
1424
NMDeviceModemCapabilities caps;
1425
NMDevice *nm_device;
1428
nm_device = net_device_get_nm_device (device);
1430
refresh_header_ui (panel, nm_device, "mobilebb");
1432
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (nm_device));
1434
if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
1435
(caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
1437
str = g_object_get_data (G_OBJECT (device),
1438
"ControlCenter::EquipmentIdentifier");
1439
panel_set_widget_data (panel,
1445
str = g_object_get_data (G_OBJECT (device),
1446
"ControlCenter::OperatorName");
1447
panel_set_widget_data (panel,
1453
panel_set_widget_data (panel,
1461
nm_device_refresh_device_ui (CcNetworkPanel *panel, NetDevice *device)
1463
CcNetworkPanelPrivate *priv = panel->priv;
1465
const gchar *sub_pane = NULL;
1467
GHashTable *options = NULL;
1470
NMDHCP4Config *config_dhcp4 = NULL;
1471
NMIP6Config *ip6_config = NULL;
1472
NMDevice *nm_device;
1476
/* we have a new device */
1477
nm_device = net_device_get_nm_device (device);
1478
type = nm_device_get_device_type (nm_device);
1479
g_debug ("device %s type %i", nm_device_get_udi (nm_device), type);
1481
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "notebook_types"));
1484
case NM_DEVICE_TYPE_ETHERNET:
1485
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 0);
1487
device_refresh_ethernet_ui (panel, device);
1489
case NM_DEVICE_TYPE_WIFI:
1490
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 1);
1491
sub_pane = "wireless";
1492
device_refresh_wifi_ui (panel, device);
1494
case NM_DEVICE_TYPE_WIMAX:
1495
device_refresh_wimax_ui (panel, device);
1497
case NM_DEVICE_TYPE_MODEM:
1499
NMDeviceModemCapabilities caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (nm_device));
1500
if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
1501
(caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
1502
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 4);
1503
sub_pane = "mobilebb";
1504
device_refresh_modem_ui (panel, device);
1509
g_assert_not_reached ();
1513
if (sub_pane == NULL)
1516
/* get IP4 parameters */
1517
config_dhcp4 = nm_device_get_dhcp4_config (nm_device);
1518
if (config_dhcp4 != NULL) {
1519
g_object_get (G_OBJECT (config_dhcp4),
1520
NM_DHCP4_CONFIG_OPTIONS, &options,
1524
str = nm_dhcp4_config_get_one_option (config_dhcp4,
1526
panel_set_widget_data (panel,
1530
has_ip4 = str != NULL;
1533
panel_set_widget_data (panel,
1536
nm_dhcp4_config_get_one_option (config_dhcp4,
1537
"domain_name_servers"));
1540
panel_set_widget_data (panel,
1543
nm_dhcp4_config_get_one_option (config_dhcp4,
1547
if (type == NM_DEVICE_TYPE_ETHERNET) {
1548
panel_set_widget_data (panel,
1551
nm_dhcp4_config_get_one_option (config_dhcp4,
1556
panel_set_widget_data (panel,
1563
panel_set_widget_data (panel,
1569
panel_set_widget_data (panel,
1575
if (type == NM_DEVICE_TYPE_ETHERNET) {
1576
panel_set_widget_data (panel,
1583
/* get IP6 parameters */
1584
ip6_config = nm_device_get_ip6_config (nm_device);
1585
if (ip6_config != NULL) {
1588
str_tmp = get_ipv6_config_address_as_string (ip6_config);
1589
panel_set_widget_data (panel, sub_pane, "ipv6", str_tmp);
1590
has_ip6 = str_tmp != NULL;
1593
panel_set_widget_data (panel, sub_pane, "ipv6", NULL);
1597
if (has_ip4 && has_ip6) {
1598
panel_set_widget_heading (panel, sub_pane, "ipv4", _("IPv4 Address"));
1599
panel_set_widget_heading (panel, sub_pane, "ipv6", _("IPv6 Address"));
1602
panel_set_widget_heading (panel, sub_pane, "ipv4", _("IP Address"));
1605
panel_set_widget_heading (panel, sub_pane, "ipv6", _("IP Address"));
1611
nm_device_refresh_vpn_ui (CcNetworkPanel *panel, NetVpn *vpn)
1615
const gchar *sub_pane = "vpn";
1616
const gchar *status;
1617
CcNetworkPanelPrivate *priv = panel->priv;
1618
const GPtrArray *acs;
1619
NMActiveConnection *a;
1623
NMVPNConnectionState state;
1625
sw = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1626
"device_vpn_off_switch"));
1627
gtk_widget_set_visible (sw, TRUE);
1629
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1630
"button_vpn_options"));
1631
gtk_widget_set_visible (widget, TRUE);
1632
gtk_widget_set_sensitive (widget, TRUE);
1634
/* use proxy note page */
1635
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1637
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 3);
1640
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1641
"image_vpn_device"));
1642
gtk_image_set_from_icon_name (GTK_IMAGE (widget),
1644
GTK_ICON_SIZE_DIALOG);
1647
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1648
"label_vpn_device"));
1649
gtk_label_set_label (GTK_LABEL (widget), net_object_get_title (NET_OBJECT (vpn)));
1652
state = net_vpn_get_state (vpn);
1654
acs = nm_client_get_active_connections (priv->client);
1656
path = nm_connection_get_path (net_vpn_get_connection (vpn));
1657
for (i = 0; i < acs->len; i++) {
1658
a = (NMActiveConnection*)acs->pdata[i];
1660
apath = nm_active_connection_get_connection (a);
1661
if (NM_IS_VPN_CONNECTION (a) && strcmp (apath, path) == 0) {
1662
state = nm_vpn_connection_get_vpn_state (NM_VPN_CONNECTION (a));
1668
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1669
"label_vpn_status"));
1670
status = panel_vpn_state_to_localized_string (state);
1671
gtk_label_set_label (GTK_LABEL (widget), status);
1672
priv->updating_device = TRUE;
1673
gtk_switch_set_active (GTK_SWITCH (sw),
1674
state != NM_VPN_CONNECTION_STATE_FAILED &&
1675
state != NM_VPN_CONNECTION_STATE_DISCONNECTED);
1676
priv->updating_device = FALSE;
1679
panel_set_widget_data (panel,
1682
net_vpn_get_gateway (vpn));
1685
panel_set_widget_data (panel,
1688
net_vpn_get_id (vpn));
1691
panel_set_widget_data (panel,
1694
net_vpn_get_username (vpn));
1697
panel_set_widget_data (panel,
1700
net_vpn_get_password (vpn));
1705
refresh_ui (CcNetworkPanel *panel)
1707
GtkTreeSelection *selection;
1709
GtkTreeModel *model;
1711
void *object = NULL;
1712
CcNetworkPanelPrivate *priv = panel->priv;
1714
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1715
"treeview_devices"));
1716
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
1718
/* will only work in single or browse selection mode! */
1719
if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
1720
g_debug ("no row selected");
1724
/* this is the proxy settings device */
1725
if (object == NULL) {
1727
/* set header to something sane */
1728
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1729
"image_proxy_device"));
1730
gtk_image_set_from_icon_name (GTK_IMAGE (widget),
1731
"preferences-system-network",
1732
GTK_ICON_SIZE_DIALOG);
1733
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1734
"label_proxy_device"));
1735
gtk_label_set_label (GTK_LABEL (widget),
1737
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1738
"label_proxy_status"));
1739
gtk_label_set_label (GTK_LABEL (widget), "");
1741
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1743
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 2);
1745
/* hide the switch until we get some more detail in the mockup */
1746
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1747
"device_proxy_off_switch"));
1749
gtk_widget_hide (widget);
1751
/* we shoulnd't be able to delete the proxy device */
1752
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1753
"remove_toolbutton"));
1754
gtk_widget_set_sensitive (widget, FALSE);
1760
if (NET_IS_VPN (object)) {
1761
nm_device_refresh_vpn_ui (panel, NET_VPN (object));
1763
/* we're able to remove the VPN connection */
1764
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1765
"remove_toolbutton"));
1766
gtk_widget_set_sensitive (widget, TRUE);
1771
if (NET_IS_DEVICE (object)) {
1773
/* we're not yet able to remove the connection */
1774
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1775
"remove_toolbutton"));
1776
gtk_widget_set_sensitive (widget, FALSE);
1778
/* refresh device */
1779
nm_device_refresh_device_ui (panel, NET_DEVICE (object));
1787
nm_devices_treeview_clicked_cb (GtkTreeSelection *selection, CcNetworkPanel *panel)
1793
panel_add_proxy_device (CcNetworkPanel *panel)
1796
GtkListStore *liststore_devices;
1799
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
1800
"liststore_devices"));
1801
title = g_strdup_printf ("<span size=\"large\">%s</span>",
1802
_("Network proxy"));
1804
gtk_list_store_append (liststore_devices, &iter);
1805
gtk_list_store_set (liststore_devices,
1807
PANEL_DEVICES_COLUMN_ICON, "preferences-system-network",
1808
PANEL_DEVICES_COLUMN_TITLE, title,
1809
PANEL_DEVICES_COLUMN_SORT, "9",
1810
PANEL_DEVICES_COLUMN_OBJECT, NULL,
1817
cc_network_panel_notify_enable_active_cb (GtkSwitch *sw,
1819
CcNetworkPanel *panel)
1823
/* set enabled state */
1824
enable = !gtk_switch_get_active (sw);
1825
nm_client_wireless_set_enabled (panel->priv->client, enable);
1829
connection_state_changed (NMActiveConnection *c, GParamSpec *pspec, CcNetworkPanel *panel)
1835
active_connections_changed (NMClient *client, GParamSpec *pspec, gpointer user_data)
1837
CcNetworkPanel *panel = user_data;
1838
const GPtrArray *connections;
1841
g_debug ("Active connections changed:");
1842
connections = nm_client_get_active_connections (client);
1843
for (i = 0; connections && (i < connections->len); i++) {
1844
NMActiveConnection *connection;
1845
const GPtrArray *devices;
1847
connection = g_ptr_array_index (connections, i);
1848
g_debug (" %s", nm_object_get_path (NM_OBJECT (connection)));
1849
devices = nm_active_connection_get_devices (connection);
1850
for (j = 0; devices && j < devices->len; j++)
1851
g_debug (" %s", nm_device_get_udi (g_ptr_array_index (devices, j)));
1852
if (NM_IS_VPN_CONNECTION (connection))
1853
g_debug (" VPN base connection: %s", nm_active_connection_get_specific_object (connection));
1855
if (g_object_get_data (G_OBJECT (connection), "has-state-changed-handler") == NULL) {
1856
g_signal_connect_object (connection, "notify::state",
1857
G_CALLBACK (connection_state_changed), panel, 0);
1858
g_object_set_data (G_OBJECT (connection), "has-state-changed-handler", GINT_TO_POINTER (TRUE));
1866
device_added_cb (NMClient *client, NMDevice *device, CcNetworkPanel *panel)
1868
g_debug ("New device added");
1869
panel_add_device (panel, device);
1873
device_removed_cb (NMClient *client, NMDevice *device, CcNetworkPanel *panel)
1875
g_debug ("Device removed");
1876
panel_remove_device (panel, device);
1880
manager_running (NMClient *client, GParamSpec *pspec, gpointer user_data)
1882
const GPtrArray *devices;
1884
NMDevice *device_tmp;
1885
GtkListStore *liststore_devices;
1886
CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);
1888
/* clear all devices we added */
1889
if (!nm_client_get_manager_running (client)) {
1890
g_debug ("NM disappeared");
1891
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
1892
"liststore_devices"));
1893
gtk_list_store_clear (liststore_devices);
1894
panel_add_proxy_device (panel);
1898
g_debug ("coldplugging devices");
1899
devices = nm_client_get_devices (client);
1900
if (devices == NULL) {
1901
g_debug ("No devices to add");
1904
for (i = 0; i < devices->len; i++) {
1905
device_tmp = g_ptr_array_index (devices, i);
1906
panel_add_device (panel, device_tmp);
1909
/* select the first device */
1910
select_first_device (panel);
1914
find_in_model_by_id (CcNetworkPanel *panel, const gchar *id)
1917
NetObject *object_tmp;
1919
GtkTreeModel *model;
1920
NetObject *object = NULL;
1923
model = GTK_TREE_MODEL (gtk_builder_get_object (panel->priv->builder,
1924
"liststore_devices"));
1925
ret = gtk_tree_model_get_iter_first (model, &iter);
1929
/* get the other elements */
1932
gtk_tree_model_get (model, &iter,
1933
PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
1935
if (object_tmp != NULL) {
1936
g_debug ("got %s", net_object_get_id (object_tmp));
1937
if (g_strcmp0 (net_object_get_id (object_tmp), id) == 0)
1938
object = object_tmp;
1939
g_object_unref (object_tmp);
1941
} while (object == NULL && gtk_tree_model_iter_next (model, &iter));
1947
panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection)
1950
gchar *title_markup;
1951
GtkListStore *liststore_devices;
1956
/* does already exist */
1957
id = nm_connection_get_path (connection);
1958
if (find_in_model_by_id (panel, id) != NULL)
1961
/* add as a virtual object */
1962
net_vpn = net_vpn_new ();
1963
net_vpn_set_connection (net_vpn, connection);
1964
net_object_set_id (NET_OBJECT (net_vpn), id);
1965
register_object_interest (panel, NET_OBJECT (net_vpn));
1967
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
1968
"liststore_devices"));
1969
title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (connection));
1970
title_markup = g_strdup_printf ("<span size=\"large\">%s</span>",
1973
net_object_set_title (NET_OBJECT (net_vpn), title);
1974
gtk_list_store_append (liststore_devices, &iter);
1975
gtk_list_store_set (liststore_devices,
1977
PANEL_DEVICES_COLUMN_ICON, "network-vpn",
1978
PANEL_DEVICES_COLUMN_TITLE, title_markup,
1979
PANEL_DEVICES_COLUMN_SORT, "5",
1980
PANEL_DEVICES_COLUMN_OBJECT, net_vpn,
1983
g_free (title_markup);
1987
add_connection (CcNetworkPanel *panel,
1988
NMConnection *connection)
1990
NMSettingConnection *s_con;
1993
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection,
1994
NM_TYPE_SETTING_CONNECTION));
1995
type = nm_setting_connection_get_connection_type (s_con);
1996
if (g_strcmp0 (type, "vpn") != 0)
1998
g_debug ("add %s/%s remote connection: %s",
1999
type, g_type_name_from_instance ((GTypeInstance*)connection),
2000
nm_connection_get_path (connection));
2001
panel_add_vpn_device (panel, connection);
2005
notify_new_connection_cb (NMRemoteSettings *settings,
2006
NMRemoteConnection *connection,
2007
CcNetworkPanel *panel)
2009
add_connection (panel, NM_CONNECTION (connection));
2013
notify_connections_read_cb (NMRemoteSettings *settings,
2014
CcNetworkPanel *panel)
2016
GSList *list, *iter;
2017
NMConnection *connection;
2019
list = nm_remote_settings_list_connections (settings);
2020
g_debug ("%p has %i remote connections",
2021
panel, g_slist_length (list));
2022
for (iter = list; iter; iter = g_slist_next (iter)) {
2023
connection = NM_CONNECTION (iter->data);
2024
add_connection (panel, connection);
2029
display_version_warning_idle (CcNetworkPanel *panel)
2034
const char *message;
2036
/* TRANSLATORS: the user is running a NM that is not API compatible */
2037
message = _("The system network services are not compatible with this version.");
2039
window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel)));
2040
dialog = gtk_message_dialog_new (window,
2046
image = gtk_image_new_from_icon_name ("computer-fail", GTK_ICON_SIZE_DIALOG);
2047
gtk_widget_show (image);
2048
gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
2050
gtk_dialog_run (GTK_DIALOG (dialog));
2051
gtk_widget_destroy (dialog);
2057
panel_check_network_manager_version (CcNetworkPanel *panel)
2059
const gchar *version;
2060
gchar **split = NULL;
2064
gboolean ret = TRUE;
2066
/* parse running version */
2067
version = nm_client_get_version (panel->priv->client);
2068
if (version != NULL) {
2069
split = g_strsplit (version, ".", -1);
2070
major = atoi (split[0]);
2071
minor = atoi (split[1]);
2072
micro = atoi (split[2]);
2075
/* is it too new or old */
2076
if (major > 0 || major > 9 || (minor <= 8 && micro < 992)) {
2079
/* do modal dialog in idle so we don't block startup */
2080
g_idle_add ((GSourceFunc)display_version_warning_idle, panel);
2088
edit_connection (GtkButton *button, CcNetworkPanel *panel)
2097
object = get_selected_object (panel);
2100
else if (NET_IS_VPN (object)) {
2101
c = net_vpn_get_connection (NET_VPN (object));
2104
device = net_device_get_nm_device (NET_DEVICE (object));
2105
c = find_connection_for_device (panel, device);
2108
uuid = nm_connection_get_uuid (c);
2110
cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid);
2111
g_debug ("Launching '%s'\n", cmdline);
2114
if (!g_spawn_command_line_async (cmdline, &error)) {
2115
g_warning ("Failed to launch nm-connection-editor: %s", error->message);
2116
g_error_free (error);
2123
add_connection_cb (GtkToolButton *button, CcNetworkPanel *panel)
2128
dialog = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2129
"connection_type_dialog"));
2130
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel))));
2132
response = gtk_dialog_run (GTK_DIALOG (dialog));
2134
gtk_widget_hide (dialog);
2136
if (response == GTK_RESPONSE_OK) {
2138
GtkTreeModel *model;
2144
combo = GTK_COMBO_BOX (gtk_builder_get_object (panel->priv->builder,
2145
"connection_type_combo"));
2146
model = gtk_combo_box_get_model (combo);
2147
gtk_combo_box_get_active_iter (combo, &iter);
2149
gtk_tree_model_get (model, &iter, 1, &type, -1);
2151
cmdline = g_strdup_printf ("nm-connection-editor --create --type %s", type);
2152
g_debug ("Launching '%s'\n", cmdline);
2155
if (!g_spawn_command_line_async (cmdline, &error)) {
2156
g_warning ("Failed to launch nm-connection-editor: %s", error->message);
2157
g_error_free (error);
2165
remove_connection (GtkToolButton *button, CcNetworkPanel *panel)
2168
NMConnection *connection;
2170
/* get current device */
2171
object = get_selected_object (panel);
2176
if (NET_IS_VPN (object)) {
2177
connection = net_vpn_get_connection (NET_VPN (object));
2178
nm_remote_connection_delete (NM_REMOTE_CONNECTION (connection), NULL, panel);
2185
on_toplevel_map (GtkWidget *widget,
2186
CcNetworkPanel *panel)
2188
/* just select the proxy settings */
2189
select_first_device (panel);
2194
connection_activate_cb (NMClient *client,
2195
NMActiveConnection *connection,
2199
CcNetworkPanel *panel = user_data;
2201
if (connection == NULL) {
2202
/* failed to activate */
2208
connection_add_activate_cb (NMClient *client,
2209
NMActiveConnection *connection,
2214
connection_activate_cb (client, connection, error, user_data);
2218
connect_to_hidden_network_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
2220
GError *error = NULL;
2221
GVariant *result = NULL;
2223
result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
2224
if (result == NULL) {
2225
g_warning ("failed to connect to hidden network: %s",
2227
g_error_free (error);
2233
connect_to_hidden_network (CcNetworkPanel *panel)
2236
GVariant *res = NULL;
2237
GError *error = NULL;
2239
/* connect to NM applet */
2240
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
2241
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
2242
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
2244
"org.gnome.network_manager_applet",
2245
"/org/gnome/network_manager_applet",
2246
"org.gnome.network_manager_applet",
2247
panel->priv->cancellable,
2249
if (proxy == NULL) {
2250
g_warning ("failed to connect to NM applet: %s",
2252
g_error_free (error);
2256
/* try to show the hidden network UI */
2257
g_dbus_proxy_call (proxy,
2258
"ConnectToHiddenNetwork",
2260
G_DBUS_CALL_FLAGS_NONE,
2261
5000, /* don't wait forever */
2262
panel->priv->cancellable,
2263
connect_to_hidden_network_cb,
2267
g_object_unref (proxy);
2269
g_variant_unref (res);
2273
wireless_ap_changed_cb (GtkComboBox *combo_box, CcNetworkPanel *panel)
2275
const GByteArray *ssid;
2276
const gchar *ssid_tmp;
2278
gchar *object_path = NULL;
2279
gchar *ssid_target = NULL;
2283
GtkTreeModel *model;
2285
NMConnection *connection;
2286
NMConnection *connection_activate = NULL;
2288
NMSettingWireless *setting_wireless;
2290
if (panel->priv->updating_device)
2293
ret = gtk_combo_box_get_active_iter (combo_box, &iter);
2297
object = get_selected_object (panel);
2301
device = net_device_get_nm_device (NET_DEVICE (object));
2306
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
2307
gtk_tree_model_get (model, &iter,
2308
PANEL_WIRELESS_COLUMN_ID, &object_path,
2309
PANEL_WIRELESS_COLUMN_TITLE, &ssid_target,
2311
g_debug ("try to connect to WIFI network %s [%s]",
2312
ssid_target, object_path);
2313
if (g_strcmp0 (object_path, "ap-other...") == 0) {
2314
connect_to_hidden_network (panel);
2318
/* look for an existing connection we can use */
2319
list = nm_remote_settings_list_connections (panel->priv->remote_settings);
2320
g_debug ("%i existing remote connections available",
2321
g_slist_length (list));
2322
filtered = nm_device_filter_connections (device, list);
2323
g_debug ("%i suitable remote connections to check",
2324
g_slist_length (filtered));
2325
for (l = filtered; l; l = g_slist_next (l)) {
2326
connection = NM_CONNECTION (l->data);
2327
setting_wireless = nm_connection_get_setting_wireless (connection);
2328
if (!NM_IS_SETTING_WIRELESS (setting_wireless))
2330
ssid = nm_setting_wireless_get_ssid (setting_wireless);
2333
ssid_tmp = nm_utils_escape_ssid (ssid->data, ssid->len);
2334
if (g_strcmp0 (ssid_target, ssid_tmp) == 0) {
2335
g_debug ("we found an existing connection %s to activate!",
2336
nm_connection_get_id (connection));
2337
connection_activate = connection;
2342
g_slist_free (list);
2343
g_slist_free (filtered);
2345
/* activate the connection */
2346
if (connection_activate != NULL) {
2347
nm_client_activate_connection (panel->priv->client,
2348
connection_activate,
2350
connection_activate_cb, panel);
2354
/* create one, as it's missing */
2355
g_debug ("no existing connection found for %s, creating",
2357
nm_client_add_and_activate_connection (panel->priv->client,
2359
device, object_path,
2360
connection_add_activate_cb, panel);
2362
g_free (ssid_target);
2363
g_free (object_path);
2367
wireless_ap_model_sort_cb (GtkTreeModel *model,
2376
gtk_tree_model_get (model, a,
2377
PANEL_WIRELESS_COLUMN_SORT, &str_a,
2379
gtk_tree_model_get (model, b,
2380
PANEL_WIRELESS_COLUMN_SORT, &str_b,
2383
/* special case blank entries to the bottom */
2384
if (g_strcmp0 (str_a, "") == 0) {
2388
if (g_strcmp0 (str_b, "") == 0) {
2393
/* case sensitive search like before */
2394
g_debug ("compare %s with %s", str_a, str_b);
2395
retval = g_strcmp0 (str_a, str_b);
2404
cc_network_panel_init (CcNetworkPanel *panel)
2407
GError *error = NULL;
2409
GSettings *settings_tmp;
2410
GtkAdjustment *adjustment;
2411
GtkCellRenderer *renderer;
2412
GtkComboBox *combobox;
2413
GtkStyleContext *context;
2414
GtkTreeSelection *selection;
2415
GtkTreeSortable *sortable;
2417
GtkWidget *toplevel;
2419
panel->priv = NETWORK_PANEL_PRIVATE (panel);
2421
panel->priv->builder = gtk_builder_new ();
2422
gtk_builder_add_from_file (panel->priv->builder,
2423
GNOMECC_UI_DIR "/network.ui",
2425
if (error != NULL) {
2426
g_warning ("Could not load interface file: %s", error->message);
2427
g_error_free (error);
2431
panel->priv->cancellable = g_cancellable_new ();
2433
panel->priv->proxy_settings = g_settings_new ("org.gnome.system.proxy");
2434
g_signal_connect (panel->priv->proxy_settings,
2436
G_CALLBACK (panel_settings_changed),
2440
value = g_settings_get_enum (panel->priv->proxy_settings, "mode");
2441
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2442
"combobox_proxy_mode"));
2443
panel_set_value_for_combo (panel, GTK_COMBO_BOX (widget), value);
2444
g_signal_connect (widget, "changed",
2445
G_CALLBACK (panel_proxy_mode_combo_changed_cb),
2448
/* bind the proxy values */
2449
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2450
"entry_proxy_url"));
2451
g_settings_bind (panel->priv->proxy_settings, "autoconfig-url",
2453
G_SETTINGS_BIND_DEFAULT);
2455
/* bind the proxy values */
2456
settings_tmp = g_settings_new ("org.gnome.system.proxy.http");
2457
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2458
"entry_proxy_http"));
2459
g_settings_bind (settings_tmp, "host",
2461
G_SETTINGS_BIND_DEFAULT);
2462
adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (panel->priv->builder,
2463
"adjustment_proxy_port_http"));
2464
g_settings_bind (settings_tmp, "port",
2465
adjustment, "value",
2466
G_SETTINGS_BIND_DEFAULT);
2467
g_object_unref (settings_tmp);
2469
/* bind the proxy values */
2470
settings_tmp = g_settings_new ("org.gnome.system.proxy.https");
2471
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2472
"entry_proxy_https"));
2473
g_settings_bind (settings_tmp, "host",
2475
G_SETTINGS_BIND_DEFAULT);
2476
adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (panel->priv->builder,
2477
"adjustment_proxy_port_https"));
2478
g_settings_bind (settings_tmp, "port",
2479
adjustment, "value",
2480
G_SETTINGS_BIND_DEFAULT);
2481
g_object_unref (settings_tmp);
2483
/* bind the proxy values */
2484
settings_tmp = g_settings_new ("org.gnome.system.proxy.ftp");
2485
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2486
"entry_proxy_ftp"));
2487
g_settings_bind (settings_tmp, "host",
2489
G_SETTINGS_BIND_DEFAULT);
2490
adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (panel->priv->builder,
2491
"adjustment_proxy_port_ftp"));
2492
g_settings_bind (settings_tmp, "port",
2493
adjustment, "value",
2494
G_SETTINGS_BIND_DEFAULT);
2495
g_object_unref (settings_tmp);
2497
/* bind the proxy values */
2498
settings_tmp = g_settings_new ("org.gnome.system.proxy.socks");
2499
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2500
"entry_proxy_socks"));
2501
g_settings_bind (settings_tmp, "host",
2503
G_SETTINGS_BIND_DEFAULT);
2504
adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (panel->priv->builder,
2505
"adjustment_proxy_port_socks"));
2506
g_settings_bind (settings_tmp, "port",
2507
adjustment, "value",
2508
G_SETTINGS_BIND_DEFAULT);
2509
g_object_unref (settings_tmp);
2511
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2512
"treeview_devices"));
2513
panel_add_devices_columns (panel, GTK_TREE_VIEW (widget));
2514
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
2515
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
2516
g_signal_connect (selection, "changed",
2517
G_CALLBACK (nm_devices_treeview_clicked_cb), panel);
2519
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2520
"devices_scrolledwindow"));
2521
context = gtk_widget_get_style_context (widget);
2522
gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2524
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2525
"devices_toolbar"));
2526
context = gtk_widget_get_style_context (widget);
2527
gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2529
/* add the virtual proxy device */
2530
panel_add_proxy_device (panel);
2533
/* setup wireless combobox model */
2534
combobox = GTK_COMBO_BOX (gtk_builder_get_object (panel->priv->builder,
2535
"combobox_wireless_network_name"));
2536
g_signal_connect (combobox, "changed",
2537
G_CALLBACK (wireless_ap_changed_cb),
2540
renderer = panel_cell_renderer_mode_new ();
2541
gtk_cell_renderer_set_padding (renderer, 4, 0);
2542
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
2545
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
2546
"mode", PANEL_WIRELESS_COLUMN_MODE,
2549
renderer = panel_cell_renderer_security_new ();
2550
gtk_cell_renderer_set_padding (renderer, 4, 0);
2551
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
2554
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
2555
"security", PANEL_WIRELESS_COLUMN_SECURITY,
2558
/* sort networks in drop down */
2559
sortable = GTK_TREE_SORTABLE (gtk_builder_get_object (panel->priv->builder,
2560
"liststore_wireless_network"));
2561
gtk_tree_sortable_set_sort_column_id (sortable,
2562
PANEL_WIRELESS_COLUMN_SORT,
2563
GTK_SORT_ASCENDING);
2564
gtk_tree_sortable_set_sort_func (sortable,
2565
PANEL_WIRELESS_COLUMN_SORT,
2566
wireless_ap_model_sort_cb,
2570
renderer = panel_cell_renderer_signal_new ();
2571
gtk_cell_renderer_set_padding (renderer, 4, 0);
2572
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
2575
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
2576
"signal", PANEL_WIRELESS_COLUMN_STRENGTH,
2579
/* use NetworkManager client */
2580
panel->priv->client = nm_client_new ();
2581
g_signal_connect (panel->priv->client, "notify::" NM_CLIENT_MANAGER_RUNNING,
2582
G_CALLBACK (manager_running), panel);
2583
g_signal_connect (panel->priv->client, "notify::" NM_CLIENT_ACTIVE_CONNECTIONS,
2584
G_CALLBACK (active_connections_changed), panel);
2585
g_signal_connect (panel->priv->client, "device-added",
2586
G_CALLBACK (device_added_cb), panel);
2587
g_signal_connect (panel->priv->client, "device-removed",
2588
G_CALLBACK (device_removed_cb), panel);
2590
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2591
"device_wired_off_switch"));
2592
g_signal_connect (widget, "notify::active",
2593
G_CALLBACK (device_off_toggled), panel);
2594
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2595
"device_wireless_off_switch"));
2596
g_signal_connect (widget, "notify::active",
2597
G_CALLBACK (device_off_toggled), panel);
2598
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2599
"device_mobilebb_off_switch"));
2600
g_signal_connect (widget, "notify::active",
2601
G_CALLBACK (device_off_toggled), panel);
2602
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2603
"device_vpn_off_switch"));
2604
g_signal_connect (widget, "notify::active",
2605
G_CALLBACK (device_off_toggled), panel);
2606
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2607
"device_proxy_off_switch"));
2608
g_signal_connect (widget, "notify::active",
2609
G_CALLBACK (device_off_toggled), panel);
2611
g_signal_connect (panel->priv->client, "notify::wireless-enabled",
2612
G_CALLBACK (wireless_enabled_toggled), panel);
2613
g_signal_connect (panel->priv->client, "notify::wimax-enabled",
2614
G_CALLBACK (wimax_enabled_toggled), panel);
2616
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2617
"button_wired_options"));
2618
g_signal_connect (widget, "clicked",
2619
G_CALLBACK (edit_connection), panel);
2621
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2622
"button_wireless_options"));
2623
g_signal_connect (widget, "clicked",
2624
G_CALLBACK (edit_connection), panel);
2626
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2627
"button_vpn_options"));
2628
g_signal_connect (widget, "clicked",
2629
G_CALLBACK (edit_connection), panel);
2631
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2633
g_signal_connect (widget, "clicked",
2634
G_CALLBACK (add_connection_cb), panel);
2636
/* disable for now, until we actually show removable connections */
2637
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2638
"remove_toolbutton"));
2639
g_signal_connect (widget, "clicked",
2640
G_CALLBACK (remove_connection), panel);
2642
/* nothing to unlock yet */
2643
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2645
gtk_widget_set_sensitive (widget, FALSE);
2647
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2648
"switch_flight_mode"));
2649
ret = nm_client_wireless_get_enabled (panel->priv->client);
2650
gtk_switch_set_active (GTK_SWITCH (widget), !ret);
2651
g_signal_connect (GTK_SWITCH (widget), "notify::active",
2652
G_CALLBACK (cc_network_panel_notify_enable_active_cb),
2655
/* add remote settings such as VPN settings as virtual devices */
2656
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
2658
g_warning ("Error connecting to system D-Bus: %s",
2660
g_error_free (error);
2662
panel->priv->remote_settings = nm_remote_settings_new (bus);
2663
g_signal_connect (panel->priv->remote_settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ,
2664
G_CALLBACK (notify_connections_read_cb), panel);
2665
g_signal_connect (panel->priv->remote_settings, NM_REMOTE_SETTINGS_NEW_CONNECTION,
2666
G_CALLBACK (notify_new_connection_cb), panel);
2669
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (panel));
2670
g_signal_connect_after (toplevel, "map", G_CALLBACK (on_toplevel_map), panel);
2672
/* hide implementation details */
2673
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2675
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), FALSE);
2677
/* hide stuff that doesn't work yet */
2678
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2680
gtk_widget_hide (widget);
2682
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
2684
gtk_widget_reparent (widget, (GtkWidget *) panel);
2688
cc_network_panel_register (GIOModule *module)
2690
cc_network_panel_register_type (G_TYPE_MODULE (module));
2691
g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
2692
CC_TYPE_NETWORK_PANEL,