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>
24
#include <netinet/ether.h>
29
#include <gdesktop-enums.h>
31
#include "cc-network-panel.h"
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"
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"
49
#include "net-object.h"
50
#include "net-device.h"
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"
58
#include "network-dialogs.h"
60
G_DEFINE_DYNAMIC_TYPE (CcNetworkPanel, cc_network_panel, CC_TYPE_PANEL)
62
#define NETWORK_PANEL_PRIVATE(o) \
63
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_NETWORK_PANEL, CcNetworkPanelPrivate))
67
OPERATION_SHOW_DEVICE,
68
OPERATION_CREATE_WIFI,
69
OPERATION_CONNECT_HIDDEN,
70
OPERATION_CONNECT_8021X,
71
OPERATION_CONNECT_MOBILE
74
struct _CcNetworkPanelPrivate
76
GCancellable *cancellable;
77
GSettings *proxy_settings;
80
NMRemoteSettings *remote_settings;
81
gboolean updating_device;
82
guint add_header_widgets_idle;
83
guint nm_warning_idle;
85
GtkWidget *kill_switch_header;
87
/* wireless dialog stuff */
88
CmdlineOperation arg_operation;
90
gchar *arg_access_point;
91
gboolean operation_done;
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
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
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);
122
cc_network_panel_get_property (GObject *object,
127
switch (property_id) {
129
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
133
static CmdlineOperation
134
cmdline_operation_from_string (const gchar *string)
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;
147
g_warning ("Invalid additional argument %s", string);
148
return OPERATION_NULL;
152
cc_network_panel_set_property (GObject *object,
157
CcNetworkPanel *self = CC_NETWORK_PANEL (object);
158
CcNetworkPanelPrivate *priv = self->priv;
160
switch (property_id) {
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;
170
args = g_value_get_boxed (value);
173
g_debug ("Invoked with operation %s", 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]);
185
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
190
cc_network_panel_dispose (GObject *object)
192
CcNetworkPanelPrivate *priv = CC_NETWORK_PANEL (object)->priv;
194
if (priv->proxy_settings) {
195
g_object_unref (priv->proxy_settings);
196
priv->proxy_settings = NULL;
198
if (priv->cancellable != NULL) {
199
g_cancellable_cancel (priv->cancellable);
200
g_object_unref (priv->cancellable);
201
priv->cancellable = NULL;
203
if (priv->builder != NULL) {
204
g_object_unref (priv->builder);
205
priv->builder = NULL;
207
if (priv->client != NULL) {
208
g_object_unref (priv->client);
211
if (priv->remote_settings != NULL) {
212
g_object_unref (priv->remote_settings);
213
priv->remote_settings = NULL;
215
if (priv->kill_switch_header != NULL) {
216
g_clear_object (&priv->kill_switch_header);
218
if (priv->refresh_idle != 0) {
219
g_source_remove (priv->refresh_idle);
220
priv->refresh_idle = 0;
222
if (priv->nm_warning_idle != 0) {
223
g_source_remove (priv->nm_warning_idle);
224
priv->nm_warning_idle = 0;
226
if (priv->add_header_widgets_idle != 0) {
227
g_source_remove (priv->add_header_widgets_idle);
228
priv->add_header_widgets_idle = 0;
231
G_OBJECT_CLASS (cc_network_panel_parent_class)->dispose (object);
235
cc_network_panel_finalize (GObject *object)
237
CcNetworkPanelPrivate *priv = CC_NETWORK_PANEL (object)->priv;
238
g_free (priv->arg_device);
239
g_free (priv->arg_access_point);
241
G_OBJECT_CLASS (cc_network_panel_parent_class)->finalize (object);
245
cc_network_panel_class_init (CcNetworkPanelClass *klass)
247
GObjectClass *object_class = G_OBJECT_CLASS (klass);
249
g_type_class_add_private (klass, sizeof (CcNetworkPanelPrivate));
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;
256
g_object_class_override_property (object_class, PROP_ARGV, "argv");
260
cc_network_panel_class_finalize (CcNetworkPanelClass *klass)
265
check_wpad_warning (CcNetworkPanel *panel)
268
gchar *autoconfig_url = NULL;
269
GString *string = NULL;
270
gboolean ret = FALSE;
273
string = g_string_new ("");
275
/* check we're using 'Automatic' */
276
mode = g_settings_get_enum (panel->priv->proxy_settings, "mode");
280
/* see if the PAC is blank */
281
autoconfig_url = g_settings_get_string (panel->priv->proxy_settings,
283
ret = autoconfig_url == NULL ||
284
autoconfig_url[0] == '\0';
288
g_string_append (string, "<small>");
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."));
293
g_string_append (string, "\n");
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
299
g_string_append (string, _("This is not recommended for untrusted public networks."));
300
g_string_append (string, "</small>");
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);
310
panel_settings_changed (GSettings *settings,
312
CcNetworkPanel *panel)
314
check_wpad_warning (panel);
318
get_selected_object (CcNetworkPanel *panel)
321
GtkTreeSelection *selection;
324
NetObject *object = NULL;
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)) {
333
gtk_tree_model_get (model, &iter,
334
PANEL_DEVICES_COLUMN_OBJECT, &object,
341
panel_proxy_mode_combo_setup_widgets (CcNetworkPanel *panel, guint value)
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,
351
gtk_widget_set_visible (widget, value == 2);
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);
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,
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);
392
/* perhaps show the wpad warning */
393
check_wpad_warning (panel);
397
panel_proxy_mode_combo_changed_cb (GtkWidget *widget, CcNetworkPanel *panel)
405
ret = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter);
410
model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
411
gtk_tree_model_get (model, &iter,
416
g_settings_set_enum (panel->priv->proxy_settings, "mode", value);
418
/* hide or show the correct widgets */
419
panel_proxy_mode_combo_setup_widgets (panel, value);
423
panel_set_value_for_combo (CcNetworkPanel *panel, GtkComboBox *combo_box, gint value)
431
model = gtk_combo_box_get_model (combo_box);
432
ret = gtk_tree_model_get_iter_first (model, &iter);
436
/* try to make the UI match the setting */
438
gtk_tree_model_get (model, &iter,
441
if (value == value_tmp) {
442
gtk_combo_box_set_active_iter (combo_box, &iter);
445
} while (gtk_tree_model_iter_next (model, &iter));
447
/* hide or show the correct widgets */
448
panel_proxy_mode_combo_setup_widgets (panel, value);
452
select_first_device (CcNetworkPanel *panel)
456
GtkTreeSelection *selection;
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));
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);
469
select_tree_iter (CcNetworkPanel *panel, GtkTreeIter *iter)
472
GtkTreeSelection *selection;
474
widget = GTK_TREE_VIEW (gtk_builder_get_object (panel->priv->builder,
475
"treeview_devices"));
476
selection = gtk_tree_view_get_selection (widget);
478
gtk_tree_selection_select_iter (selection, iter);
482
panel_device_got_modem_manager_cb (GObject *source_object,
486
GError *error = NULL;
487
GVariant *result = NULL;
489
NMDevice *device = (NMDevice *) user_data;
491
proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
493
g_warning ("Error creating ModemManager proxy: %s",
495
g_error_free (error);
500
result = g_dbus_proxy_get_cached_property (proxy,
501
"EquipmentIdentifier");
504
g_object_set_data_full (G_OBJECT (device),
505
"ControlCenter::EquipmentIdentifier",
506
g_variant_dup_string (result, NULL),
510
g_variant_unref (result);
512
g_object_unref (proxy);
517
panel_get_registration_info_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
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;
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",
531
g_error_free (error);
536
g_variant_get (result, "((uss))",
537
®istration_status,
540
if (operator_name != NULL && operator_name[0] != '\0')
541
operator_name_safe = g_strescape (operator_name, NULL);
544
g_object_set_data_full (G_OBJECT (device),
545
"ControlCenter::OperatorName",
549
g_free (operator_name);
550
g_free (operator_code);
551
g_variant_unref (result);
555
panel_device_got_modem_manager_gsm_cb (GObject *source_object,
559
GError *error = NULL;
561
NMDevice *device = (NMDevice *) user_data;
563
proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
565
g_warning ("Error creating ModemManager GSM proxy: %s\n",
567
g_error_free (error);
571
g_dbus_proxy_call (proxy,
572
"GetRegistrationInfo",
574
G_DBUS_CALL_FLAGS_NONE,
577
panel_get_registration_info_cb,
581
g_object_unref (proxy);
586
device_state_notify_changed_cb (NMDevice *device,
588
CcNetworkPanel *panel)
594
object_changed_cb (NetObject *object, CcNetworkPanel *panel)
600
object_removed_cb (NetObject *object, CcNetworkPanel *panel)
603
NetObject *object_tmp;
607
GtkTreeSelection *selection;
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));
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);
620
/* get the other elements */
622
gtk_tree_model_get (model, &iter,
623
PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
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);
634
g_object_unref (object_tmp);
635
} while (gtk_tree_model_iter_next (model, &iter));
639
register_object_interest (CcNetworkPanel *panel, NetObject *object)
641
g_signal_connect (object,
643
G_CALLBACK (object_changed_cb),
645
g_signal_connect (object,
647
G_CALLBACK (object_removed_cb),
652
panel_refresh_killswitch_visibility (CcNetworkPanel *panel)
655
gboolean show_flight_toggle = FALSE;
658
NetObject *object_tmp;
659
NMDeviceModemCapabilities caps;
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);
669
gtk_tree_model_get (model, &iter,
670
PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
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;
679
case NM_DEVICE_TYPE_MODEM:
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;
691
g_object_unref (object_tmp);
692
} while (!show_flight_toggle && gtk_tree_model_iter_next (model, &iter));
694
/* only show toggle if there are wireless devices */
695
gtk_widget_set_visible (panel->priv->kill_switch_header,
700
panel_add_device (CcNetworkPanel *panel, NMDevice *device)
702
GtkListStore *liststore_devices;
706
NetDevice *net_device;
707
CcNetworkPanelPrivate *priv = panel->priv;
709
/* do we have an existing object with this id? */
710
if (find_in_model_by_id (panel, nm_device_get_udi (device)) != NULL)
713
/* we don't support bluetooth devices yet -- no mockup */
714
type = nm_device_get_device_type (device);
716
if (type == NM_DEVICE_TYPE_BT)
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);
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,
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,
736
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
737
G_DBUS_PROXY_FLAGS_NONE,
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,
747
/* make title a bit bigger */
748
title = g_strdup_printf ("%s", panel_device_to_localized_string (device));
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,
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,
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);
772
if (priv->arg_operation == OPERATION_CREATE_WIFI)
773
cc_network_panel_create_wifi_network (panel, priv->client, priv->remote_settings);
775
cc_network_panel_connect_to_hidden_network (panel, priv->client, priv->remote_settings);
777
priv->arg_operation = OPERATION_NULL; /* done */
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);
783
priv->arg_operation = OPERATION_NULL; /* done */
784
select_tree_iter (panel, &iter);
786
} else if (priv->arg_operation == OPERATION_CONNECT_8021X
787
|| priv->arg_operation == OPERATION_SHOW_DEVICE) {
788
select_tree_iter (panel, &iter);
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;
806
panel_remove_device (CcNetworkPanel *panel, NMDevice *device)
809
NetObject *object_tmp;
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);
820
/* get the other elements */
822
gtk_tree_model_get (model, &iter,
823
PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
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);
831
g_object_unref (object_tmp);
832
} while (gtk_tree_model_iter_next (model, &iter));
836
panel_add_devices_columns (CcNetworkPanel *panel, GtkTreeView *treeview)
838
CcNetworkPanelPrivate *priv = panel->priv;
839
GtkCellRenderer *renderer;
840
GtkListStore *liststore_devices;
841
GtkTreeViewColumn *column;
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);
848
column = gtk_tree_view_column_new_with_attributes ("", renderer,
849
"icon-name", PANEL_DEVICES_COLUMN_ICON,
851
gtk_tree_view_append_column (treeview, column);
853
/* column for text */
854
renderer = gtk_cell_renderer_text_new ();
855
g_object_set (renderer,
856
"wrap-mode", PANGO_WRAP_WORD,
858
column = gtk_tree_view_column_new_with_attributes ("", renderer,
859
"markup", PANEL_DEVICES_COLUMN_TITLE,
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,
867
gtk_tree_view_append_column (treeview, column);
868
gtk_tree_view_column_set_expand (column, TRUE);
872
panel_set_widget_data (CcNetworkPanel *panel,
873
const gchar *sub_pane,
874
const gchar *widget_suffix,
878
gchar *label_id = NULL;
881
CcNetworkPanelPrivate *priv = panel->priv;
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);
896
gtk_widget_hide (heading);
897
gtk_widget_hide (widget);
899
/* there exists a value */
900
gtk_widget_show (heading);
901
gtk_widget_show (widget);
902
gtk_label_set_label (GTK_LABEL (widget), value);
907
panel_set_widget_heading (CcNetworkPanel *panel,
908
const gchar *sub_pane,
909
const gchar *widget_suffix,
910
const gchar *heading)
912
gchar *label_id = NULL;
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));
918
gtk_label_set_label (GTK_LABEL (widget), heading);
923
get_access_point_security (NMAccessPoint *ap)
925
NM80211ApFlags flags;
926
NM80211ApSecurityFlags wpa_flags;
927
NM80211ApSecurityFlags rsn_flags;
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);
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;
947
type = NM_AP_SEC_WPA2;
953
add_access_point (CcNetworkPanel *panel, NMAccessPoint *ap, NMAccessPoint *active, NMDevice *device)
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;
963
ssid = nm_access_point_get_ssid (ap);
966
ssid_text = nm_utils_escape_ssid (ssid->data, ssid->len);
968
liststore_wireless_network = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
969
"liststore_wireless_network"));
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,
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),
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);
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,
995
priv->remote_settings,
998
priv->arg_operation = OPERATION_NULL; /* done */
1003
add_access_point_other (CcNetworkPanel *panel)
1005
CcNetworkPanelPrivate *priv = panel->priv;
1006
GtkListStore *liststore_wireless_network;
1007
GtkTreeIter treeiter;
1009
liststore_wireless_network = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
1010
"liststore_wireless_network"));
1012
gtk_list_store_append (liststore_wireless_network, &treeiter);
1013
gtk_list_store_set (liststore_wireless_network,
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..."),
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,
1030
ip4_address_as_string (guint32 ip)
1032
char buf[INET_ADDRSTRLEN+1];
1033
struct in_addr tmp_addr;
1035
memset (&buf, '\0', sizeof (buf));
1036
tmp_addr.s_addr = ip;
1038
if (inet_ntop (AF_INET, &tmp_addr, buf, INET_ADDRSTRLEN)) {
1039
return g_strdup (buf);
1041
g_warning ("error converting IP4 address 0x%X",
1042
ntohl (tmp_addr.s_addr));
1048
panel_show_ip4_config (NMIP4Config *cfg)
1051
const GArray *array;
1052
const GPtrArray *ptr_array;
1056
for (iter = (GSList *) nm_ip4_config_get_addresses (cfg); iter; iter = g_slist_next (iter)) {
1057
NMIP4Address *addr = iter->data;
1060
tmp = ip4_address_as_string (nm_ip4_address_get_address (addr));
1061
g_debug ("IP4 address: %s", tmp);
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);
1069
tmp = ip4_address_as_string (nm_ip4_address_get_gateway (addr));
1070
g_debug ("IP4 gateway: %s", tmp);
1074
array = nm_ip4_config_get_nameservers (cfg);
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);
1084
ptr_array = nm_ip4_config_get_domains (cfg);
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));
1091
array = nm_ip4_config_get_wins_servers (cfg);
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);
1104
panel_get_strongest_unique_aps (const GPtrArray *aps)
1106
const GByteArray *ssid;
1107
const GByteArray *ssid_tmp;
1108
GPtrArray *aps_unique = NULL;
1113
NMAccessPoint *ap_tmp;
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);
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);
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);
1129
/* is this the same type and data? */
1130
if (nm_utils_same_ssid (ssid, ssid_tmp, TRUE)) {
1132
g_debug ("found duplicate: %s",
1133
nm_utils_escape_ssid (ssid_tmp->data,
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,
1142
g_ptr_array_remove (aps_unique, ap_tmp);
1152
g_debug ("adding %s",
1153
nm_utils_escape_ssid (ssid->data,
1155
g_ptr_array_add (aps_unique, g_object_ref (ap));
1162
get_ap_security_string (NMAccessPoint *ap)
1164
NM80211ApSecurityFlags wpa_flags, rsn_flags;
1165
NM80211ApFlags flags;
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);
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"));
1179
if (wpa_flags != NM_802_11_AP_SEC_NONE) {
1180
/* TRANSLATORS: this WPA WiFi security */
1181
g_string_append_printf (str, "%s, ", _("WPA"));
1183
if (rsn_flags != NM_802_11_AP_SEC_NONE) {
1184
/* TRANSLATORS: this WPA WiFi security */
1185
g_string_append_printf (str, "%s, ", _("WPA2"));
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"));
1193
g_string_set_size (str, str->len - 2);
1195
/* TRANSLATORS: this no (!) WiFi security */
1196
g_string_append (str, _("None"));
1198
return g_string_free (str, FALSE);
1202
get_ipv4_config_address_as_string (NMIP4Config *ip4_config, const char *what)
1205
struct in_addr addr;
1207
gchar tmp[INET_ADDRSTRLEN];
1208
NMIP4Address *address;
1211
list = nm_ip4_config_get_addresses (ip4_config);
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));
1226
if (!inet_ntop (AF_INET, &addr, tmp, sizeof(tmp)))
1228
str = g_strdup (tmp);
1234
get_ipv4_config_name_servers_as_string (NMIP4Config *ip4_config)
1236
const GArray *array;
1238
struct in_addr addr;
1239
gchar tmp[INET_ADDRSTRLEN];
1242
dns = g_string_new (NULL);
1244
array = nm_ip4_config_get_nameservers (ip4_config);
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);
1253
return g_string_free (dns, FALSE);
1257
get_ipv6_config_address_as_string (NMIP6Config *ip6_config)
1260
const struct in6_addr *addr;
1262
gchar tmp[INET6_ADDRSTRLEN];
1263
NMIP6Address *address;
1266
list = nm_ip6_config_get_addresses (ip6_config);
1270
/* we only care about one address */
1271
address = list->data;
1272
addr = nm_ip6_address_get_address (address);
1275
inet_ntop (AF_INET6, addr, tmp, sizeof(tmp));
1276
str = g_strdup (tmp);
1281
static NMConnection *
1282
find_connection_for_device (CcNetworkPanel *panel,
1285
const GPtrArray *connections;
1286
const GPtrArray *devices;
1287
NMActiveConnection *c;
1290
connections = nm_client_get_active_connections (panel->priv->client);
1291
if (connections == NULL) {
1295
for (i = 0; i < connections->len; i++) {
1296
c = (NMActiveConnection *)connections->pdata[i];
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));
1308
device_off_toggled (GtkSwitch *sw,
1310
CcNetworkPanel *panel)
1316
if (panel->priv->updating_device)
1319
active = gtk_switch_get_active (sw);
1321
object = get_selected_object (panel);
1322
if (NET_IS_VPN (object)) {
1324
NMConnection *connection;
1326
connection = net_vpn_get_connection (NET_VPN (object));
1328
nm_client_activate_connection (panel->priv->client,
1329
connection, NULL, NULL,
1333
NMActiveConnection *a;
1334
const GPtrArray *acs;
1337
path = nm_connection_get_path (connection);
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);
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:
1355
GSList *list, *filtered;
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);
1361
nm_client_activate_connection (panel->priv->client,
1362
(NMConnection *)filtered->data,
1367
nm_client_add_and_activate_connection (panel->priv->client,
1374
g_slist_free (list);
1375
g_slist_free (filtered);
1377
nm_device_disconnect (device, NULL, NULL);
1380
case NM_DEVICE_TYPE_WIFI:
1381
nm_client_wireless_set_enabled (panel->priv->client, active);
1383
case NM_DEVICE_TYPE_WIMAX:
1384
nm_client_wimax_set_enabled (panel->priv->client, active);
1386
case NM_DEVICE_TYPE_MODEM:
1387
nm_client_wwan_set_enabled (panel->priv->client, active);
1390
/* FIXME: handle other device types */
1396
wireless_enabled_toggled (NMClient *client,
1398
CcNetworkPanel *panel)
1405
object = get_selected_object (panel);
1408
device = net_device_get_nm_device (NET_DEVICE (object));
1410
if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_WIFI)
1413
enabled = nm_client_wireless_get_enabled (client);
1414
sw = GTK_SWITCH (gtk_builder_get_object (panel->priv->builder,
1415
"device_wireless_off_switch"));
1417
panel->priv->updating_device = TRUE;
1418
gtk_switch_set_active (sw, enabled);
1419
panel->priv->updating_device = FALSE;
1423
wimax_enabled_toggled (NMClient *client,
1425
CcNetworkPanel *panel)
1432
object = get_selected_object (panel);
1435
device = net_device_get_nm_device (NET_DEVICE (object));
1437
if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_WIMAX)
1440
enabled = nm_client_wimax_get_enabled (client);
1441
sw = GTK_SWITCH (gtk_builder_get_object (panel->priv->builder,
1442
"device_wimax_off_switch"));
1444
panel->priv->updating_device = TRUE;
1445
gtk_switch_set_active (sw, enabled);
1446
panel->priv->updating_device = FALSE;
1450
mobilebb_enabled_toggled (NMClient *client,
1452
CcNetworkPanel *panel)
1459
object = get_selected_object (panel);
1462
device = net_device_get_nm_device (NET_DEVICE (object));
1464
if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_MODEM)
1467
enabled = nm_client_wwan_get_enabled (client);
1468
sw = GTK_SWITCH (gtk_builder_get_object (panel->priv->builder,
1469
"device_mobilebb_off_switch"));
1471
panel->priv->updating_device = TRUE;
1472
gtk_switch_set_active (sw, enabled);
1473
panel->priv->updating_device = FALSE;
1477
update_off_switch_from_device_state (GtkSwitch *sw, NMDeviceState state, CcNetworkPanel *panel)
1479
panel->priv->updating_device = TRUE;
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);
1489
gtk_switch_set_active (sw, TRUE);
1492
panel->priv->updating_device = FALSE;
1496
device_is_hotspot (CcNetworkPanel *panel,
1500
NMSettingIP4Config *s_ip4;
1502
if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_WIFI) {
1506
c = find_connection_for_device (panel, device);
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) {
1520
static const GByteArray *
1521
device_get_hotspot_ssid (CcNetworkPanel *panel,
1525
NMSettingWireless *sw;
1527
c = find_connection_for_device (panel, device);
1532
sw = nm_connection_get_setting_wireless (c);
1533
return nm_setting_wireless_get_ssid (sw);
1537
get_secrets_cb (NMRemoteConnection *c,
1538
GHashTable *secrets,
1542
CcNetworkPanel *panel = data;
1543
NMSettingWireless *sw;
1545
sw = nm_connection_get_setting_wireless (NM_CONNECTION (c));
1547
nm_connection_update_secrets (NM_CONNECTION (c),
1548
nm_setting_wireless_get_security (sw),
1555
device_get_hotspot_security_details (CcNetworkPanel *panel,
1561
NMSettingWireless *sw;
1562
NMSettingWirelessSecurity *sws;
1563
const gchar *key_mgmt;
1564
const gchar *tmp_secret;
1565
const gchar *tmp_security;
1567
c = find_connection_for_device (panel, device);
1572
sw = nm_connection_get_setting_wireless (c);
1573
sws = nm_connection_get_setting_wireless_security (c);
1574
if (sw == NULL || sws == NULL) {
1579
tmp_security = _("None");
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");
1586
else if (strcmp (key_mgmt, "wpa-none") == 0) {
1587
tmp_secret = nm_setting_wireless_security_get_psk (sws);
1588
tmp_security = _("WPA");
1590
g_warning ("unhandled security key-mgmt: %s", key_mgmt);
1593
/* If we don't have secrets, request them from NM and bail.
1594
* We'll refresh the UI when secrets arrive.
1596
if (tmp_secret == NULL) {
1597
nm_remote_connection_get_secrets ((NMRemoteConnection*)c,
1598
nm_setting_wireless_get_security (sw),
1605
*secret = g_strdup (tmp_secret);
1609
*security = g_strdup (tmp_security);
1614
refresh_header_ui (CcNetworkPanel *panel, NMDevice *device, const char *page_name)
1619
NMDeviceState state;
1621
gboolean is_hotspot;
1624
type = nm_device_get_device_type (device);
1625
state = nm_device_get_state (device);
1626
is_hotspot = device_is_hotspot (panel, device);
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));
1632
gtk_image_set_from_icon_name (GTK_IMAGE (widget),
1633
panel_device_to_icon_name (device),
1634
GTK_ICON_SIZE_DIALOG);
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));
1640
gtk_label_set_label (GTK_LABEL (widget),
1641
panel_device_to_localized_string (device));
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));
1648
/* keep this in sync with the signal handler setup in cc_network_panel_init */
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));
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));
1665
case NM_DEVICE_TYPE_WIMAX:
1666
gtk_widget_show (widget);
1667
wimax_enabled_toggled (panel->priv->client, NULL, panel);
1669
case NM_DEVICE_TYPE_MODEM:
1670
gtk_widget_show (widget);
1671
mobilebb_enabled_toggled (panel->priv->client, NULL, panel);
1674
gtk_widget_hide (widget);
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));
1683
str = g_string_new (_("Hotspot"));
1685
str = g_string_new (panel_device_state_to_localized_string (device));
1688
g_string_append (str, " - ");
1689
/* Translators: network device speed */
1690
g_string_append_printf (str, _("%d Mb/s"), speed);
1692
gtk_label_set_label (GTK_LABEL (widget), str->str);
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));
1698
if (widget != NULL) {
1699
gtk_widget_set_sensitive (widget, find_connection_for_device (panel, device) != NULL);
1701
g_string_free (str, TRUE);
1705
device_refresh_ethernet_ui (CcNetworkPanel *panel, NetDevice *device)
1708
NMDevice *nm_device;
1710
nm_device = net_device_get_nm_device (device);
1712
refresh_header_ui (panel, nm_device, "wired");
1715
str = nm_device_ethernet_get_hw_address (NM_DEVICE_ETHERNET (nm_device));
1716
panel_set_widget_data (panel,
1724
device_refresh_wifi_ui (CcNetworkPanel *panel, NetDevice *device)
1728
const GPtrArray *aps;
1729
GPtrArray *aps_unique = NULL;
1731
NMDeviceState state;
1733
NMAccessPoint *active_ap;
1736
GtkListStore *liststore_wireless_network;
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;
1746
nm_device = net_device_get_nm_device (device);
1747
state = nm_device_get_state (nm_device);
1749
refresh_header_ui (panel, nm_device, "wireless");
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;
1757
const GByteArray *ssid;
1758
ssid = device_get_hotspot_ssid (panel, nm_device);
1760
hotspot_ssid = nm_utils_ssid_to_utf8 (ssid);
1762
device_get_hotspot_security_details (panel, nm_device, &hotspot_secret, &hotspot_security);
1765
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1766
"start_hotspot_button"));
1767
gtk_widget_set_visible (widget, !is_hotspot);
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);
1777
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1778
"stop_hotspot_button"));
1779
gtk_widget_set_visible (widget, is_hotspot);
1781
panel_set_widget_data (panel, "hotspot", "network_name", hotspot_ssid);
1782
g_free (hotspot_ssid);
1784
panel_set_widget_data (panel, "hotspot", "security_key", hotspot_secret);
1785
g_free (hotspot_secret);
1788
str = nm_device_wifi_get_hw_address (NM_DEVICE_WIFI (nm_device));
1789
panel_set_widget_data (panel,
1794
active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (nm_device));
1795
if (state == NM_DEVICE_STATE_UNAVAILABLE)
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);
1802
str_tmp = g_strdup ("");
1803
panel_set_widget_data (panel,
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);
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);
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);
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))), "");
1839
panel->priv->updating_device = FALSE;
1841
g_ptr_array_unref (aps_unique);
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);
1851
device_refresh_wimax_ui (CcNetworkPanel *panel, NetDevice *device)
1853
NMDevice *nm_device;
1855
nm_device = net_device_get_nm_device (device);
1856
refresh_header_ui (panel, nm_device, "wimax");
1860
device_refresh_modem_ui (CcNetworkPanel *panel, NetDevice *device)
1862
NMDeviceModemCapabilities caps;
1863
NMDevice *nm_device;
1866
nm_device = net_device_get_nm_device (device);
1868
refresh_header_ui (panel, nm_device, "mobilebb");
1870
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (nm_device));
1872
if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
1873
(caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
1875
str = g_object_get_data (G_OBJECT (nm_device),
1876
"ControlCenter::EquipmentIdentifier");
1877
panel_set_widget_data (panel,
1883
str = g_object_get_data (G_OBJECT (nm_device),
1884
"ControlCenter::OperatorName");
1885
panel_set_widget_data (panel,
1891
panel_set_widget_data (panel,
1899
nm_device_refresh_device_ui (CcNetworkPanel *panel, NetDevice *device)
1901
CcNetworkPanelPrivate *priv = panel->priv;
1902
const gchar *sub_pane = NULL;
1906
NMIP4Config *ip4_config = NULL;
1907
NMIP6Config *ip6_config = NULL;
1908
NMDevice *nm_device;
1911
gboolean is_hotspot;
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);
1919
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "notebook_types"));
1922
case NM_DEVICE_TYPE_ETHERNET:
1923
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 0);
1925
device_refresh_ethernet_ui (panel, device);
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);
1932
case NM_DEVICE_TYPE_WIMAX:
1933
device_refresh_wimax_ui (panel, device);
1935
case NM_DEVICE_TYPE_MODEM:
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);
1947
g_assert_not_reached ();
1951
if (sub_pane == NULL)
1954
/* get IP4 parameters */
1955
ip4_config = nm_device_get_ip4_config (nm_device);
1956
if (!is_hotspot && ip4_config != NULL) {
1959
str_tmp = get_ipv4_config_address_as_string (ip4_config, "address");
1960
panel_set_widget_data (panel,
1964
has_ip4 = str_tmp != NULL;
1968
str_tmp = get_ipv4_config_name_servers_as_string (ip4_config);
1969
panel_set_widget_data (panel,
1976
str_tmp = get_ipv4_config_address_as_string (ip4_config, "gateway");
1977
panel_set_widget_data (panel,
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,
1994
panel_set_widget_data (panel,
2001
panel_set_widget_data (panel,
2007
panel_set_widget_data (panel,
2013
if (type == NM_DEVICE_TYPE_ETHERNET) {
2014
panel_set_widget_data (panel,
2021
/* get IP6 parameters */
2022
ip6_config = nm_device_get_ip6_config (nm_device);
2023
if (!is_hotspot && ip6_config != NULL) {
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;
2031
panel_set_widget_data (panel, sub_pane, "ipv6", NULL);
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"));
2040
panel_set_widget_heading (panel, sub_pane, "ipv4", _("IP Address"));
2043
panel_set_widget_heading (panel, sub_pane, "ipv6", _("IP Address"));
2049
nm_device_refresh_vpn_ui (CcNetworkPanel *panel, NetVpn *vpn)
2053
const gchar *sub_pane = "vpn";
2054
const gchar *status;
2055
CcNetworkPanelPrivate *priv = panel->priv;
2056
const GPtrArray *acs;
2057
NMActiveConnection *a;
2061
NMVPNConnectionState state;
2063
GtkListStore *liststore_devices;
2066
sw = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2067
"device_vpn_off_switch"));
2068
gtk_widget_set_visible (sw, TRUE);
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);
2075
/* use proxy note page */
2076
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2078
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 3);
2081
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2082
"image_vpn_device"));
2083
gtk_image_set_from_icon_name (GTK_IMAGE (widget),
2085
GTK_ICON_SIZE_DIALOG);
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);
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,
2100
PANEL_DEVICES_COLUMN_TITLE, title,
2106
state = net_vpn_get_state (vpn);
2108
acs = nm_client_get_active_connections (priv->client);
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];
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));
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;
2133
panel_set_widget_data (panel,
2136
net_vpn_get_service_type (vpn));
2139
panel_set_widget_data (panel,
2142
net_vpn_get_gateway (vpn));
2145
panel_set_widget_data (panel,
2148
net_vpn_get_id (vpn));
2151
panel_set_widget_data (panel,
2154
net_vpn_get_username (vpn));
2157
panel_set_widget_data (panel,
2160
net_vpn_get_password (vpn));
2164
refresh_ui_idle (gpointer data)
2166
CcNetworkPanel *panel = data;
2167
GtkTreeSelection *selection;
2169
GtkTreeModel *model;
2171
NetObject *object = NULL;
2172
CcNetworkPanelPrivate *priv = panel->priv;
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));
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");
2184
object = get_selected_object (panel);
2186
/* this is the proxy settings device */
2187
if (object == NULL) {
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),
2199
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2200
"label_proxy_status"));
2201
gtk_label_set_label (GTK_LABEL (widget), "");
2203
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
2205
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 2);
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"));
2211
gtk_widget_hide (widget);
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);
2221
if (NET_IS_VPN (object)) {
2222
nm_device_refresh_vpn_ui (panel, NET_VPN (object));
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);
2232
if (NET_IS_DEVICE (object)) {
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);
2239
/* refresh device */
2240
nm_device_refresh_device_ui (panel, NET_DEVICE (object));
2243
priv->refresh_idle = 0;
2249
refresh_ui (CcNetworkPanel *panel)
2251
if (panel->priv->refresh_idle != 0)
2254
panel->priv->refresh_idle = g_idle_add (refresh_ui_idle, panel);
2258
nm_devices_treeview_clicked_cb (GtkTreeSelection *selection, CcNetworkPanel *panel)
2264
panel_add_proxy_device (CcNetworkPanel *panel)
2267
GtkListStore *liststore_devices;
2270
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
2271
"liststore_devices"));
2272
title = g_strdup_printf ("%s", _("Network proxy"));
2274
gtk_list_store_append (liststore_devices, &iter);
2275
gtk_list_store_set (liststore_devices,
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,
2286
cc_network_panel_notify_enable_active_cb (GtkSwitch *sw,
2288
CcNetworkPanel *panel)
2292
/* set enabled state */
2293
enable = !gtk_switch_get_active (sw);
2294
nm_client_wireless_set_enabled (panel->priv->client, enable);
2298
connection_state_changed (NMActiveConnection *c, GParamSpec *pspec, CcNetworkPanel *panel)
2304
active_connections_changed (NMClient *client, GParamSpec *pspec, gpointer user_data)
2306
CcNetworkPanel *panel = user_data;
2307
const GPtrArray *connections;
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;
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));
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));
2335
device_added_cb (NMClient *client, NMDevice *device, CcNetworkPanel *panel)
2337
g_debug ("New device added");
2338
panel_add_device (panel, device);
2339
panel_refresh_killswitch_visibility (panel);
2343
device_removed_cb (NMClient *client, NMDevice *device, CcNetworkPanel *panel)
2345
g_debug ("Device removed");
2346
panel_remove_device (panel, device);
2347
panel_refresh_killswitch_visibility (panel);
2351
manager_running (NMClient *client, GParamSpec *pspec, gpointer user_data)
2353
const GPtrArray *devices;
2355
NMDevice *device_tmp;
2356
GtkListStore *liststore_devices;
2357
gboolean selected = FALSE;
2358
CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);
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);
2370
g_debug ("coldplugging devices");
2371
devices = nm_client_get_devices (client);
2372
if (devices == NULL) {
2373
g_debug ("No devices to add");
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;
2382
/* select the first device */
2383
select_first_device (panel);
2388
find_in_model_by_id (CcNetworkPanel *panel, const gchar *id)
2391
NetObject *object_tmp;
2393
GtkTreeModel *model;
2394
NetObject *object = NULL;
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);
2403
/* get the other elements */
2406
gtk_tree_model_get (model, &iter,
2407
PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
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);
2415
} while (object == NULL && gtk_tree_model_iter_next (model, &iter));
2421
find_model_iter_by_object (GtkTreeModel *model, const NetObject *object, GtkTreeIter *iter)
2424
NetObject *object_tmp;
2426
/* find iter in model according to the passed object */
2427
valid = gtk_tree_model_get_iter_first (model, iter);
2429
gtk_tree_model_get (model, iter,
2430
PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
2432
if (object_tmp != NULL)
2433
g_object_unref (object_tmp);
2434
if (object_tmp == object)
2436
valid = gtk_tree_model_iter_next (model, iter);
2443
panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection)
2446
gchar *title_markup;
2447
GtkListStore *liststore_devices;
2452
/* does already exist */
2453
id = nm_connection_get_path (connection);
2454
if (find_in_model_by_id (panel, id) != NULL)
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));
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);
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,
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,
2478
g_free (title_markup);
2482
add_connection (CcNetworkPanel *panel,
2483
NMConnection *connection)
2485
NMSettingConnection *s_con;
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)
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);
2500
notify_new_connection_cb (NMRemoteSettings *settings,
2501
NMRemoteConnection *connection,
2502
CcNetworkPanel *panel)
2504
add_connection (panel, NM_CONNECTION (connection));
2508
notify_connections_read_cb (NMRemoteSettings *settings,
2509
CcNetworkPanel *panel)
2511
GSList *list, *iter;
2512
NMConnection *connection;
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);
2524
display_version_warning_idle (CcNetworkPanel *panel)
2529
const char *message;
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.");
2534
window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel)));
2535
dialog = gtk_message_dialog_new (window,
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);
2545
gtk_dialog_run (GTK_DIALOG (dialog));
2546
gtk_widget_destroy (dialog);
2552
panel_check_network_manager_version (CcNetworkPanel *panel)
2554
const gchar *version;
2555
gchar **split = NULL;
2559
gboolean ret = TRUE;
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]);
2570
/* is it too new or old */
2571
if (major > 0 || major > 9 || (minor <= 8 && micro < 992)) {
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);
2583
edit_connection (GtkButton *button, CcNetworkPanel *panel)
2592
object = get_selected_object (panel);
2595
else if (NET_IS_VPN (object)) {
2596
c = net_vpn_get_connection (NET_VPN (object));
2599
device = net_device_get_nm_device (NET_DEVICE (object));
2600
c = find_connection_for_device (panel, device);
2603
uuid = nm_connection_get_uuid (c);
2605
cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid);
2606
g_debug ("Launching '%s'\n", cmdline);
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);
2618
add_connection_cb (GtkToolButton *button, CcNetworkPanel *panel)
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))));
2627
response = gtk_dialog_run (GTK_DIALOG (dialog));
2629
gtk_widget_hide (dialog);
2631
if (response == GTK_RESPONSE_OK) {
2633
GtkTreeModel *model;
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);
2644
gtk_tree_model_get (model, &iter, 1, &type, -1);
2646
cmdline = g_strdup_printf ("nm-connection-editor --create --type %s", type);
2647
g_debug ("Launching '%s'\n", cmdline);
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);
2660
forget_network_connection_delete_cb (NMRemoteConnection *connection,
2666
g_warning ("failed to delete connection %s: %s",
2667
nm_object_get_path (NM_OBJECT (connection)),
2672
forget_network_response_cb (GtkWidget *dialog,
2674
CcNetworkPanel *panel)
2678
NMRemoteConnection *remote_connection;
2680
if (response != GTK_RESPONSE_OK)
2683
/* get current device */
2684
object = get_selected_object (panel);
2687
device = net_device_get_nm_device (NET_DEVICE (object));
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");
2697
nm_remote_connection_delete (remote_connection,
2698
forget_network_connection_delete_cb,
2701
gtk_widget_destroy (dialog);
2705
wireless_button_clicked_cb (GtkButton *button, CcNetworkPanel *panel)
2708
gchar *ssid_pretty = NULL;
2709
gchar *ssid_target = NULL;
2710
gchar *warning = NULL;
2711
GtkComboBox *combobox;
2713
GtkTreeModel *model;
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);
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,
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,
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,
2742
g_signal_connect (dialog, "response",
2743
G_CALLBACK (forget_network_response_cb), panel);
2744
gtk_window_present (GTK_WINDOW (dialog));
2746
g_free (ssid_target);
2747
g_free (ssid_pretty);
2752
remove_connection (GtkToolButton *button, CcNetworkPanel *panel)
2755
NMConnection *connection;
2757
/* get current device */
2758
object = get_selected_object (panel);
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);
2771
on_toplevel_map (GtkWidget *widget,
2772
CcNetworkPanel *panel)
2776
/* is the user compiling against a new version, but running an
2777
* old daemon version? */
2778
ret = panel_check_network_manager_version (panel);
2780
manager_running (panel->priv->client, NULL, panel);
2782
/* just select the proxy settings */
2783
select_first_device (panel);
2788
connection_activate_cb (NMClient *client,
2789
NMActiveConnection *connection,
2793
CcNetworkPanel *panel = user_data;
2795
if (connection == NULL) {
2796
/* failed to activate */
2802
connection_add_activate_cb (NMClient *client,
2803
NMActiveConnection *connection,
2808
connection_activate_cb (client, connection, error, user_data);
2812
connect_to_hidden_network (CcNetworkPanel *panel)
2814
CcNetworkPanelPrivate *priv = panel->priv;
2816
cc_network_panel_connect_to_hidden_network (panel, priv->client, priv->remote_settings);
2820
wireless_ap_changed_cb (GtkComboBox *combo_box, CcNetworkPanel *panel)
2822
const GByteArray *ssid;
2823
const gchar *ssid_tmp;
2825
gchar *object_path = NULL;
2826
gchar *ssid_target = NULL;
2830
GtkTreeModel *model;
2832
NMConnection *connection;
2833
NMConnection *connection_activate = NULL;
2835
NMSettingWireless *setting_wireless;
2837
if (panel->priv->updating_device)
2840
ret = gtk_combo_box_get_active_iter (combo_box, &iter);
2844
object = get_selected_object (panel);
2848
device = net_device_get_nm_device (NET_DEVICE (object));
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,
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);
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))
2877
ssid = nm_setting_wireless_get_ssid (setting_wireless);
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;
2889
g_slist_free (list);
2890
g_slist_free (filtered);
2892
/* activate the connection */
2893
if (connection_activate != NULL) {
2894
nm_client_activate_connection (panel->priv->client,
2895
connection_activate,
2897
connection_activate_cb, panel);
2901
/* create one, as it's missing */
2902
g_debug ("no existing connection found for %s, creating",
2904
nm_client_add_and_activate_connection (panel->priv->client,
2906
device, object_path,
2907
connection_add_activate_cb, panel);
2909
g_free (ssid_target);
2910
g_free (object_path);
2914
wireless_ap_model_sort_cb (GtkTreeModel *model,
2923
gtk_tree_model_get (model, a,
2924
PANEL_WIRELESS_COLUMN_SORT, &str_a,
2926
gtk_tree_model_get (model, b,
2927
PANEL_WIRELESS_COLUMN_SORT, &str_b,
2930
/* special case blank entries to the bottom */
2931
if (g_strcmp0 (str_a, "") == 0) {
2935
if (g_strcmp0 (str_b, "") == 0) {
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);
2950
ssid_to_byte_array (const gchar *ssid)
2955
len = strlen (ssid);
2956
ba = g_byte_array_sized_new (len);
2957
g_byte_array_append (ba, (guchar *)ssid, len);
2963
activate_cb (NMClient *client,
2964
NMActiveConnection *connection,
2966
CcNetworkPanel *panel)
2969
g_warning ("Failed to add new connection: (%d) %s",
2979
activate_new_cb (NMClient *client,
2980
NMActiveConnection *connection,
2983
CcNetworkPanel *panel)
2985
activate_cb (client, connection, error, panel);
2991
GDBusConnection *bus;
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);
3005
res = g_dbus_connection_call_sync (bus,
3006
"org.freedesktop.hostname1",
3007
"/org/freedesktop/hostname1",
3008
"org.freedesktop.DBus.Properties",
3010
g_variant_new ("(ss)",
3011
"org.freedesktop.hostname1",
3013
(GVariantType*)"(v)",
3014
G_DBUS_CALL_FLAGS_NONE,
3018
g_object_unref (bus);
3020
if (error != NULL) {
3021
g_warning ("Getting pretty hostname failed: %s", error->message);
3022
g_error_free (error);
3028
g_variant_get (res, "(v)", &inner);
3029
str = g_variant_dup_string (inner, NULL);
3030
g_variant_unref (res);
3033
if (str == NULL || *str == '\0') {
3034
str = g_strdup (g_get_host_name ());
3037
if (str == NULL || *str == '\0') {
3038
str = g_strdup ("GNOME");
3045
generate_ssid_for_hotspot (CcNetworkPanel *panel)
3047
GByteArray *ssid_array;
3050
ssid = get_hostname ();
3051
ssid_array = ssid_to_byte_array (ssid);
3058
generate_wep_key (CcNetworkPanel *panel)
3062
const gchar *hexdigits = "0123456789abcdef";
3064
/* generate a 10-digit hex WEP key */
3065
for (i = 0; i < 10; i++) {
3067
digit = g_random_int_range (0, 16);
3068
key[i] = hexdigits[digit];
3072
return g_strdup (key);
3076
is_hotspot_connection (NMConnection *connection)
3078
NMSettingConnection *sc;
3079
NMSettingWireless *sw;
3080
NMSettingIP4Config *sip;
3082
sc = nm_connection_get_setting_connection (connection);
3083
if (g_strcmp0 (nm_setting_connection_get_connection_type (sc), "802-11-wireless") != 0) {
3086
sw = nm_connection_get_setting_wireless (connection);
3087
if (g_strcmp0 (nm_setting_wireless_get_mode (sw), "adhoc") != 0) {
3090
if (g_strcmp0 (nm_setting_wireless_get_security (sw), "802-11-wireless-security") != 0) {
3093
sip = nm_connection_get_setting_ip4_config (connection);
3094
if (g_strcmp0 (nm_setting_ip4_config_get_method (sip), "shared") != 0) {
3102
start_shared_connection (CcNetworkPanel *panel)
3106
NMSettingConnection *sc;
3107
NMSettingWireless *sw;
3108
NMSettingIP4Config *sip;
3109
NMSettingWirelessSecurity *sws;
3112
GByteArray *ssid_array;
3114
const gchar *str_mac;
3115
struct ether_addr *bin_mac;
3116
GSList *connections;
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);
3124
connections = nm_remote_settings_list_connections (panel->priv->remote_settings);
3125
filtered = nm_device_filter_connections (device, connections);
3126
g_slist_free (connections);
3128
for (l = filtered; l; l = l->next) {
3130
if (is_hotspot_connection (tmp)) {
3135
g_slist_free (filtered);
3138
g_debug ("activate existing hotspot connection\n");
3139
nm_client_activate_connection (panel->priv->client,
3143
(NMClientActivateFn)activate_cb,
3148
g_debug ("create new hotspot connection\n");
3149
c = nm_connection_new ();
3151
sc = (NMSettingConnection *)nm_setting_connection_new ();
3153
"type", "802-11-wireless",
3155
"autoconnect", FALSE,
3157
nm_connection_add_setting (c, (NMSetting *)sc);
3159
sw = (NMSettingWireless *)nm_setting_wireless_new ();
3162
"security", "802-11-wireless-security",
3165
str_mac = nm_device_wifi_get_permanent_hw_address (NM_DEVICE_WIFI (device));
3166
bin_mac = ether_aton (str_mac);
3168
GByteArray *hw_address;
3170
hw_address = g_byte_array_sized_new (ETH_ALEN);
3171
g_byte_array_append (hw_address, bin_mac->ether_addr_octet, ETH_ALEN);
3173
"mac-address", hw_address,
3175
g_byte_array_unref (hw_address);
3177
nm_connection_add_setting (c, (NMSetting *)sw);
3179
sip = (NMSettingIP4Config*) nm_setting_ip4_config_new ();
3180
g_object_set (sip, "method", "shared", NULL);
3181
nm_connection_add_setting (c, (NMSetting *)sip);
3183
ssid_array = generate_ssid_for_hotspot (panel);
3187
g_byte_array_unref (ssid_array);
3189
sws = (NMSettingWirelessSecurity*) nm_setting_wireless_security_new ();
3190
wep_key = generate_wep_key (panel);
3193
"wep-key0", wep_key,
3194
"wep-key-type", NM_WEP_KEY_TYPE_KEY,
3197
nm_connection_add_setting (c, (NMSetting *)sws);
3199
nm_client_add_and_activate_connection (panel->priv->client,
3203
(NMClientAddActivateFn)activate_new_cb,
3210
start_hotspot_response_cb (GtkWidget *dialog, gint response, CcNetworkPanel *panel)
3212
if (response == GTK_RESPONSE_OK) {
3213
start_shared_connection (panel);
3215
gtk_widget_destroy (dialog);
3219
start_hotspot (GtkButton *button, CcNetworkPanel *panel)
3223
gboolean is_default;
3224
const GPtrArray *connections;
3225
const GPtrArray *devices;
3226
NMActiveConnection *c;
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?"));
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);
3255
if (active_ssid != NULL) {
3257
str = g_string_new ("");
3258
g_string_append_printf (str, _("Disconnect from %s and create a new hotspot?"), active_ssid);
3260
g_string_append (str, "\n\n");
3261
g_string_append (str, _("This is your only connection to the internet."));
3263
warning = g_string_free (str, FALSE);
3267
if (warning != NULL) {
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,
3277
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
3278
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3279
_("Create _Hotspot"), GTK_RESPONSE_OK,
3281
g_signal_connect (dialog, "response",
3282
G_CALLBACK (start_hotspot_response_cb), panel);
3283
gtk_window_present (GTK_WINDOW (dialog));
3288
/* if we get here, things look good to go ahead */
3289
start_shared_connection (panel);
3293
stop_shared_connection (CcNetworkPanel *panel)
3295
const GPtrArray *connections;
3296
const GPtrArray *devices;
3300
NMActiveConnection *c;
3302
object = get_selected_object (panel);
3303
device = net_device_get_nm_device (NET_DEVICE (object));
3305
connections = nm_client_get_active_connections (panel->priv->client);
3306
for (i = 0; i < connections->len; i++) {
3307
c = (NMActiveConnection *)connections->pdata[i];
3309
devices = nm_active_connection_get_devices (c);
3310
if (devices && devices->pdata[0] == device) {
3311
nm_client_deactivate_connection (panel->priv->client, c);
3320
stop_hotspot_response_cb (GtkWidget *dialog, gint response, CcNetworkPanel *panel)
3322
if (response == GTK_RESPONSE_OK) {
3323
stop_shared_connection (panel);
3325
gtk_widget_destroy (dialog);
3329
stop_hotspot (GtkButton *button, CcNetworkPanel *panel)
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,
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,
3344
g_signal_connect (dialog, "response",
3345
G_CALLBACK (stop_hotspot_response_cb), panel);
3346
gtk_window_present (GTK_WINDOW (dialog));
3350
network_add_shell_header_widgets_cb (gpointer user_data)
3352
CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);
3357
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3358
/* TRANSLATORS: this is to disable the radio hardware in the
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);
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),
3374
panel_refresh_killswitch_visibility (panel);
3380
is_in_admin_group (int id_group)
3382
gid_t groups [1024];
3385
ngroups = getgroups (1024, groups);
3387
perror ("getgroups");
3391
for (i = 0; i < ngroups; ++i) {
3392
if (groups[i] == id_group)
3402
struct group *admin_group;
3404
admin_group = getgrnam ("admin");
3405
if (admin_group != NULL && is_in_admin_group (admin_group->gr_gid))
3408
admin_group = getgrnam ("sudo");
3409
if (admin_group != NULL && is_in_admin_group (admin_group->gr_gid))
3416
reset_system_proxy (GDBusProxy *proxy, const gchar *protocol)
3419
GError *error = NULL;
3421
result = g_dbus_proxy_call_sync (proxy, "set_proxy",
3422
g_variant_new ("(ss)", protocol, ""),
3423
G_DBUS_CALL_FLAGS_NONE,
3426
g_variant_unref (result);
3428
g_warning ("Error while calling set_proxy for %s protocol: %s", protocol, error->message);
3429
g_error_free (error);
3434
set_proxy_for_protocol (GDBusProxy *proxy, const gchar *protocol, GSettings *settings)
3438
GError *error = NULL;
3440
proxy_str = g_strdup_printf ("%s://%s:%i/",
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,
3449
g_variant_unref (result);
3451
g_warning ("Error while calling set_proxy for %s protocol: %s", protocol, error->message);
3452
g_error_free (error);
3457
g_object_unref (settings);
3461
on_proxy_apply_system_wide (GtkButton *button, gpointer user_data)
3463
GDBusConnection *bus;
3466
GDesktopProxyMode proxy_mode;
3467
CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);
3470
bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
3472
g_warning ("Could not retrieve system bus: %s", error->message);
3473
g_error_free (error);
3478
proxy = g_dbus_proxy_new_sync (bus, 0, NULL,
3479
"com.ubuntu.SystemService",
3481
"com.ubuntu.SystemService",
3485
g_warning ("Could not retrieve bus object: %s", error->message);
3486
g_error_free (error);
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");
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"));
3509
g_object_unref (proxy);
3513
cc_network_panel_init (CcNetworkPanel *panel)
3515
DBusGConnection *bus = NULL;
3516
GError *error = NULL;
3518
GSettings *settings_tmp;
3519
GtkAdjustment *adjustment;
3520
GtkCellRenderer *renderer;
3521
GtkComboBox *combobox;
3522
GtkStyleContext *context;
3523
GtkTreeSelection *selection;
3524
GtkTreeSortable *sortable;
3526
GtkWidget *toplevel;
3528
panel->priv = NETWORK_PANEL_PRIVATE (panel);
3530
panel->priv->builder = gtk_builder_new ();
3531
gtk_builder_add_from_file (panel->priv->builder,
3532
GNOMECC_UI_DIR "/network.ui",
3534
if (error != NULL) {
3535
g_warning ("Could not load interface file: %s", error->message);
3536
g_error_free (error);
3540
panel->priv->cancellable = g_cancellable_new ();
3542
panel->priv->proxy_settings = g_settings_new ("org.gnome.system.proxy");
3543
g_signal_connect (panel->priv->proxy_settings,
3545
G_CALLBACK (panel_settings_changed),
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,
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),
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",
3568
G_SETTINGS_BIND_DEFAULT);
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",
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);
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",
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);
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",
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);
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",
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);
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);
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);
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);
3644
/* add the virtual proxy device */
3645
panel_add_proxy_device (panel);
3647
/* System wide proxy settings */
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);
3652
gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "system_proxy_button")));
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),
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),
3666
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
3667
"mode", PANEL_WIRELESS_COLUMN_MODE,
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),
3675
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
3676
"security", PANEL_WIRELESS_COLUMN_SECURITY,
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,
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),
3696
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
3697
"signal", PANEL_WIRELESS_COLUMN_STRENGTH,
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);
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);
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);
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);
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);
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);
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);
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);
3769
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3771
g_signal_connect (widget, "clicked",
3772
G_CALLBACK (add_connection_cb), panel);
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);
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);
3786
/* add remote settings such as VPN settings as virtual devices */
3787
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
3789
g_warning ("Error connecting to system D-Bus: %s",
3791
g_error_free (error);
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);
3799
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (panel));
3800
g_signal_connect_after (toplevel, "map", G_CALLBACK (on_toplevel_map), panel);
3802
/* hide implementation details */
3803
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3805
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), FALSE);
3807
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3809
gtk_widget_reparent (widget, (GtkWidget *) panel);
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);
3816
cc_network_panel_register (GIOModule *module)
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,