205
198
g_cancellable_cancel (priv->cancellable);
207
200
g_clear_object (&priv->cancellable);
201
g_clear_object (&priv->rfkill_proxy);
208
202
g_clear_object (&priv->builder);
209
203
g_clear_object (&priv->client);
210
g_clear_object (&priv->remote_settings);
204
g_clear_object (&priv->modem_manager);
211
205
g_clear_object (&priv->kill_switch_header);
212
g_clear_object (&priv->rfkill);
213
g_clear_pointer (&priv->killswitches, g_hash_table_destroy);
214
206
priv->rfkill_switch = NULL;
216
if (priv->refresh_idle != 0) {
217
g_source_remove (priv->refresh_idle);
218
priv->refresh_idle = 0;
220
if (priv->nm_warning_idle != 0) {
221
g_source_remove (priv->nm_warning_idle);
222
priv->nm_warning_idle = 0;
224
if (priv->add_header_widgets_idle != 0) {
225
g_source_remove (priv->add_header_widgets_idle);
226
priv->add_header_widgets_idle = 0;
229
208
G_OBJECT_CLASS (cc_network_panel_parent_class)->dispose (object);
242
221
static const char *
243
222
cc_network_panel_get_help_uri (CcPanel *panel)
245
return "help:ubuntu-help/net";
224
return "help:gnome-help/net";
228
cc_network_panel_notify_enable_active_cb (GtkSwitch *sw,
230
CcNetworkPanel *panel)
232
CcNetworkPanelPrivate *priv = panel->priv;
234
enable = gtk_switch_get_active (sw);
235
g_dbus_proxy_call (priv->rfkill_proxy,
236
"org.freedesktop.DBus.Properties.Set",
237
g_variant_new_parsed ("('org.gnome.SettingsDaemon.Rfkill',"
238
"'AirplaneMode', %v)",
239
g_variant_new_boolean (enable)),
240
G_DBUS_CALL_FLAGS_NONE,
247
sync_airplane_mode_switch (CcNetworkPanel *panel)
250
gboolean enabled, should_show;
253
result = g_dbus_proxy_get_cached_property (panel->priv->rfkill_proxy, "HasAirplaneMode");
254
enabled = g_variant_get_boolean (result);
256
result = g_dbus_proxy_get_cached_property (panel->priv->rfkill_proxy, "ShouldShowAirplaneMode");
257
should_show = g_variant_get_boolean (result);
259
gtk_widget_set_visible (GTK_WIDGET (panel->priv->kill_switch_header), enabled && should_show);
260
if (!enabled || !should_show)
263
result = g_dbus_proxy_get_cached_property (panel->priv->rfkill_proxy, "AirplaneMode");
264
enabled = g_variant_get_boolean (result);
266
result = g_dbus_proxy_get_cached_property (panel->priv->rfkill_proxy, "HardwareAirplaneMode");
267
hw_enabled = !!g_variant_get_boolean (result);
269
enabled |= hw_enabled;
271
if (enabled != gtk_switch_get_active (panel->priv->rfkill_switch)) {
272
g_signal_handlers_block_by_func (panel->priv->rfkill_switch,
273
cc_network_panel_notify_enable_active_cb,
275
gtk_switch_set_active (panel->priv->rfkill_switch, enabled);
276
g_signal_handlers_unblock_by_func (panel->priv->rfkill_switch,
277
cc_network_panel_notify_enable_active_cb,
281
gtk_widget_set_sensitive (GTK_WIDGET (panel->priv->rfkill_switch), !hw_enabled);
285
on_property_change (GDBusProxy *proxy,
286
GVariant *changed_properties,
287
GVariant *invalidated_properties,
290
sync_airplane_mode_switch (CC_NETWORK_PANEL (user_data));
294
got_rfkill_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
296
GError *error = NULL;
297
CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);
299
panel->priv->rfkill_proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
300
if (panel->priv->rfkill_proxy == NULL) {
301
g_printerr ("Error creating rfkill proxy: %s\n", error->message);
302
g_error_free (error);
306
g_signal_connect (panel->priv->rfkill_proxy, "g-properties-changed",
307
G_CALLBACK (on_property_change), panel);
308
sync_airplane_mode_switch (panel);
312
cc_network_panel_constructed (GObject *object)
314
CcNetworkPanel *panel = CC_NETWORK_PANEL (object);
319
G_OBJECT_CLASS (cc_network_panel_parent_class)->constructed (object);
321
/* add kill switch widgets */
322
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
323
/* TRANSLATORS: this is to disable the radio hardware in the
325
label = gtk_label_new_with_mnemonic (_("Air_plane Mode"));
326
gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
327
gtk_widget_set_visible (label, TRUE);
328
widget = gtk_switch_new ();
329
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
330
gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
331
gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 4);
332
gtk_widget_show_all (box);
333
panel->priv->rfkill_switch = GTK_SWITCH (widget);
334
cc_shell_embed_widget_in_header (cc_panel_get_shell (CC_PANEL (panel)), box);
335
panel->priv->kill_switch_header = g_object_ref (box);
337
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
338
G_DBUS_PROXY_FLAGS_NONE,
340
"org.gnome.SettingsDaemon.Rfkill",
341
"/org/gnome/SettingsDaemon/Rfkill",
342
"org.gnome.SettingsDaemon.Rfkill",
343
panel->priv->cancellable,
347
g_signal_connect (panel->priv->rfkill_switch, "notify::active",
348
G_CALLBACK (cc_network_panel_notify_enable_active_cb),
333
438
if (g_strcmp0 (net_object_get_id (object),
334
439
net_object_get_id (object_tmp)) == 0) {
335
440
g_object_unref (object_tmp);
336
if (!gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
337
gtk_tree_model_get_iter_first (model, &iter);
338
gtk_tree_selection_select_iter (selection, &iter);
441
if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter)) {
442
if (gtk_tree_model_get_iter_first (model, &iter))
443
gtk_tree_selection_select_iter (selection, &iter);
342
447
g_object_unref (object_tmp);
343
448
} while (gtk_tree_model_iter_next (model, &iter));
452
cc_network_panel_get_devices (CcNetworkPanel *panel)
459
devices = g_ptr_array_new_with_free_func (g_object_unref);
461
model = GTK_TREE_MODEL (gtk_builder_get_object (panel->priv->builder,
462
"liststore_devices"));
463
if (!gtk_tree_model_get_iter_first (model, &iter))
467
gtk_tree_model_get (model, &iter,
468
PANEL_DEVICES_COLUMN_OBJECT, &object,
470
if (NET_IS_DEVICE (object))
471
g_ptr_array_add (devices, object);
473
g_object_unref (object);
474
} while (gtk_tree_model_iter_next (model, &iter));
480
panel_net_object_get_sort_category (NetObject *net_object)
482
if (NET_IS_DEVICE (net_object)) {
483
return panel_device_get_sort_category (net_device_get_nm_device (NET_DEVICE (net_object)));
484
} else if (NET_IS_PROXY (net_object)) {
486
} else if (NET_IS_VPN (net_object)) {
490
g_assert_not_reached ();
494
panel_net_object_sort_func (GtkTreeModel *model, GtkTreeIter *a,
495
GtkTreeIter *b, void *data)
497
g_autoptr(NetObject) obj_a = NULL;
498
g_autoptr(NetObject) obj_b = NULL;
501
gtk_tree_model_get (model, a,
502
PANEL_DEVICES_COLUMN_OBJECT, &obj_a,
504
gtk_tree_model_get (model, b,
505
PANEL_DEVICES_COLUMN_OBJECT, &obj_b,
508
cat_a = panel_net_object_get_sort_category (obj_a);
509
cat_b = panel_net_object_get_sort_category (obj_b);
512
return cat_a - cat_b;
514
return g_utf8_collate (net_object_get_title (obj_a), net_object_get_title (obj_b));
518
panel_net_object_notify_title_cb (NetObject *net_object, GParamSpec *pspec, CcNetworkPanel *panel)
521
GtkListStore *liststore;
523
if (!find_in_model_by_id (panel, net_object_get_id (net_object), &iter))
526
liststore = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
527
"liststore_devices"));
529
/* gtk_tree_model_row_changed would not cause the list store to resort.
530
* Instead set the object column to the current value.
531
* See https://bugzilla.gnome.org/show_bug.cgi?id=782737 */
532
gtk_list_store_set (liststore, &iter,
533
PANEL_DEVICES_COLUMN_OBJECT, net_object,
538
panel_refresh_device_titles (CcNetworkPanel *panel)
540
GPtrArray *ndarray, *nmdarray;
542
NMDevice **nm_devices, *nm_device;
546
ndarray = cc_network_panel_get_devices (panel);
548
g_ptr_array_free (ndarray, TRUE);
552
nmdarray = g_ptr_array_new ();
553
for (i = 0; i < ndarray->len; i++) {
554
nm_device = net_device_get_nm_device (ndarray->pdata[i]);
556
g_ptr_array_add (nmdarray, nm_device);
558
g_ptr_array_remove_index (ndarray, i--);
561
devices = (NetDevice **)ndarray->pdata;
562
nm_devices = (NMDevice **)nmdarray->pdata;
563
num_devices = ndarray->len;
565
titles = nm_device_disambiguate_names (nm_devices, num_devices);
566
for (i = 0; i < num_devices; i++) {
567
net_object_set_title (NET_OBJECT (devices[i]), titles[i]);
571
g_ptr_array_free (ndarray, TRUE);
572
g_ptr_array_free (nmdarray, TRUE);
347
576
handle_argv_for_device (CcNetworkPanel *panel,
348
577
NMDevice *device,
363
593
select_tree_iter (panel, iter);
365
595
if (priv->arg_operation == OPERATION_CREATE_WIFI)
366
cc_network_panel_create_wifi_network (panel, priv->client, priv->remote_settings);
596
cc_network_panel_create_wifi_network (toplevel, priv->client);
368
cc_network_panel_connect_to_hidden_network (panel, priv->client, priv->remote_settings);
598
cc_network_panel_connect_to_hidden_network (toplevel, priv->client);
370
600
reset_command_line_args (panel); /* done */
372
602
} else if (g_strcmp0 (nm_object_get_path (NM_OBJECT (device)), priv->arg_device) == 0) {
373
603
if (priv->arg_operation == OPERATION_CONNECT_MOBILE) {
374
cc_network_panel_connect_to_3g_network (panel, priv->client, priv->remote_settings, device);
604
cc_network_panel_connect_to_3g_network (toplevel, priv->client, device);
376
606
reset_command_line_args (panel); /* done */
377
607
select_tree_iter (panel, iter);
379
609
} else if (priv->arg_operation == OPERATION_CONNECT_8021X) {
380
cc_network_panel_connect_to_8021x_network (panel, priv->client, priv->remote_settings, device, priv->arg_access_point);
610
cc_network_panel_connect_to_8021x_network (toplevel, priv->client, device, priv->arg_access_point);
381
611
reset_command_line_args (panel); /* done */
382
612
select_tree_iter (panel, iter);
442
720
GtkNotebook *notebook;
443
721
GtkSizeGroup *size_group;
444
722
GType device_g_type;
725
if (!nm_device_get_managed (device))
446
728
/* do we have an existing object with this id? */
447
if (find_in_model_by_id (panel, nm_device_get_udi (device)) != NULL)
729
udi = nm_device_get_udi (device);
730
if (find_in_model_by_id (panel, udi, NULL) != NULL)
450
733
type = nm_device_get_device_type (device);
452
735
g_debug ("device %s type %i path %s",
453
nm_device_get_udi (device), type, nm_object_get_path (NM_OBJECT (device)));
736
udi, type, nm_object_get_path (NM_OBJECT (device)));
455
/* map the NMDeviceType to the GType */
738
/* map the NMDeviceType to the GType, or ignore */
457
740
case NM_DEVICE_TYPE_ETHERNET:
458
device_g_type = NET_TYPE_DEVICE_WIRED;
741
device_g_type = NET_TYPE_DEVICE_ETHERNET;
460
743
case NM_DEVICE_TYPE_MODEM:
461
744
device_g_type = NET_TYPE_DEVICE_MOBILE;
463
746
case NM_DEVICE_TYPE_WIFI:
464
747
device_g_type = NET_TYPE_DEVICE_WIFI;
749
/* not going to set up a cluster in GNOME */
750
case NM_DEVICE_TYPE_VETH:
751
/* enterprise features */
752
case NM_DEVICE_TYPE_BOND:
753
case NM_DEVICE_TYPE_TEAM:
754
/* Don't need the libvirtd bridge */
755
case NM_DEVICE_TYPE_BRIDGE:
756
/* Don't add VPN devices */
757
case NM_DEVICE_TYPE_TUN:
760
device_g_type = NET_TYPE_DEVICE_SIMPLE;
470
764
/* create device */
471
title = panel_device_to_localized_string (device);
472
765
net_device = g_object_new (device_g_type,
474
767
"removable", FALSE,
475
768
"cancellable", panel->priv->cancellable,
476
769
"client", panel->priv->client,
477
"remote-settings", panel->priv->remote_settings,
478
770
"nm-device", device,
479
771
"id", nm_device_get_udi (device),
774
if (type == NM_DEVICE_TYPE_MODEM &&
775
g_str_has_prefix (nm_device_get_udi (device), "/org/freedesktop/ModemManager1/Modem/")) {
776
GDBusObject *modem_object;
778
if (priv->modem_manager == NULL) {
779
g_warning ("Cannot grab information for modem at %s: No ModemManager support",
780
nm_device_get_udi (device));
784
modem_object = g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (priv->modem_manager),
785
nm_device_get_udi (device));
786
if (modem_object == NULL) {
787
g_warning ("Cannot grab information for modem at %s: Not found",
788
nm_device_get_udi (device));
792
/* Set the modem object in the NetDeviceMobile */
793
g_object_set (net_device,
794
"mm-object", modem_object,
796
g_object_unref (modem_object);
483
799
/* add as a panel */
484
800
if (device_g_type != NET_TYPE_DEVICE) {
485
801
notebook = GTK_NOTEBOOK (gtk_builder_get_object (panel->priv->builder,
498
814
gtk_list_store_append (liststore_devices, &iter);
499
815
gtk_list_store_set (liststore_devices,
501
PANEL_DEVICES_COLUMN_ICON, panel_device_to_icon_name (device),
502
PANEL_DEVICES_COLUMN_SORT, panel_device_to_sortable_string (device),
503
PANEL_DEVICES_COLUMN_TITLE, title,
817
PANEL_DEVICES_COLUMN_ICON, panel_device_to_icon_name (device, TRUE),
504
818
PANEL_DEVICES_COLUMN_OBJECT, net_device,
820
g_signal_connect (net_device, "notify::title",
821
G_CALLBACK (panel_net_object_notify_title_cb), panel);
823
g_object_unref (net_device);
824
g_signal_connect (device, "state-changed",
825
G_CALLBACK (state_changed_cb), panel);
562
906
"wrap-mode", PANGO_WRAP_WORD,
563
907
"ellipsize", PANGO_ELLIPSIZE_END,
565
column = gtk_tree_view_column_new_with_attributes ("title", renderer,
566
"markup", PANEL_DEVICES_COLUMN_TITLE,
568
gtk_tree_view_column_set_sort_column_id (column, PANEL_DEVICES_COLUMN_SORT);
909
column = gtk_tree_view_column_new_with_attributes ("title", renderer, NULL);
910
gtk_tree_view_column_set_cell_data_func (GTK_TREE_VIEW_COLUMN (column),
914
gtk_tree_view_column_set_sort_column_id (column, PANEL_DEVICES_COLUMN_OBJECT);
569
915
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
570
916
"liststore_devices"));
917
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (liststore_devices),
918
PANEL_DEVICES_COLUMN_OBJECT,
919
panel_net_object_sort_func, NULL, NULL);
571
920
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (liststore_devices),
572
PANEL_DEVICES_COLUMN_SORT,
921
PANEL_DEVICES_COLUMN_OBJECT,
573
922
GTK_SORT_ASCENDING);
574
923
gtk_tree_view_append_column (treeview, column);
575
924
gtk_tree_view_column_set_expand (column, TRUE);
643
992
/* add proxy to device list */
644
993
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
645
994
"liststore_devices"));
646
title = g_strdup_printf ("%s", _("Network proxy"));
995
net_object_set_title (NET_OBJECT (proxy), _("Network proxy"));
647
996
gtk_list_store_append (liststore_devices, &iter);
648
997
gtk_list_store_set (liststore_devices,
650
PANEL_DEVICES_COLUMN_ICON, "preferences-system-network",
651
PANEL_DEVICES_COLUMN_TITLE, title,
652
PANEL_DEVICES_COLUMN_SORT, "9",
999
PANEL_DEVICES_COLUMN_ICON, "preferences-system-network-symbolic",
653
1000
PANEL_DEVICES_COLUMN_OBJECT, proxy,
1003
/* NOTE: No connect to notify::title here as it is guaranteed to not
1004
* be changed by anyone.*/
656
1006
g_object_unref (proxy);
660
cc_network_panel_notify_enable_active_cb (GtkSwitch *sw,
662
CcNetworkPanel *panel)
665
struct rfkill_event event;
667
enable = gtk_switch_get_active (sw);
668
g_debug ("Setting killswitch to %d", enable);
670
memset (&event, 0, sizeof(event));
671
event.op = RFKILL_OP_CHANGE_ALL;
672
event.type = RFKILL_TYPE_ALL;
673
event.soft = enable ? 1 : 0;
674
if (cc_rfkill_glib_send_event (panel->priv->rfkill, &event) < 0)
675
g_warning ("Setting the killswitch %s failed", enable ? "on" : "off");
679
1010
connection_state_changed (NMActiveConnection *c, GParamSpec *pspec, CcNetworkPanel *panel)
836
1172
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
837
1173
"liststore_devices"));
838
1174
title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (connection));
839
title_markup = g_strdup (title);
841
1176
net_object_set_title (NET_OBJECT (net_vpn), title);
842
1177
gtk_list_store_append (liststore_devices, &iter);
843
1178
gtk_list_store_set (liststore_devices,
845
PANEL_DEVICES_COLUMN_ICON, "network-vpn",
846
PANEL_DEVICES_COLUMN_TITLE, title_markup,
847
PANEL_DEVICES_COLUMN_SORT, "5",
1180
PANEL_DEVICES_COLUMN_ICON, "network-vpn-symbolic",
848
1181
PANEL_DEVICES_COLUMN_OBJECT, net_vpn,
1183
g_signal_connect (net_vpn, "notify::title",
1184
G_CALLBACK (panel_net_object_notify_title_cb), panel);
851
g_free (title_markup);
1187
g_object_unref (net_vpn);
856
1192
NMConnection *connection)
858
1194
NMSettingConnection *s_con;
1195
const gchar *type, *iface;
861
1197
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection,
862
1198
NM_TYPE_SETTING_CONNECTION));
863
1199
type = nm_setting_connection_get_connection_type (s_con);
864
if (g_strcmp0 (type, "vpn") != 0)
1200
iface = nm_connection_get_interface_name (connection);
1201
if (g_strcmp0 (type, "vpn") != 0 && iface == NULL)
1204
/* Don't add the libvirtd bridge to the UI */
1205
if (g_strcmp0 (nm_setting_connection_get_interface_name (s_con), "virbr0") == 0)
866
1208
g_debug ("add %s/%s remote connection: %s",
867
1209
type, g_type_name_from_instance ((GTypeInstance*)connection),
868
1210
nm_connection_get_path (connection));
869
panel_add_vpn_device (panel, connection);
1212
panel_add_vpn_device (panel, connection);
873
notify_new_connection_cb (NMRemoteSettings *settings,
874
NMRemoteConnection *connection,
875
CcNetworkPanel *panel)
1216
notify_connection_added_cb (NMClient *client,
1217
NMRemoteConnection *connection,
1218
CcNetworkPanel *panel)
877
1220
add_connection (panel, NM_CONNECTION (connection));
881
notify_connections_read_cb (NMRemoteSettings *settings,
882
CcNetworkPanel *panel)
885
NMConnection *connection;
887
list = nm_remote_settings_list_connections (settings);
888
g_debug ("%p has %i remote connections",
889
panel, g_slist_length (list));
890
for (iter = list; iter; iter = g_slist_next (iter)) {
891
connection = NM_CONNECTION (iter->data);
892
add_connection (panel, connection);
897
display_version_warning_idle (CcNetworkPanel *panel)
904
/* TRANSLATORS: the user is running a NM that is not API compatible */
905
message = _("The system network services are not compatible with this version.");
907
window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel)));
908
dialog = gtk_message_dialog_new (window,
914
image = gtk_image_new_from_icon_name ("computer-fail", GTK_ICON_SIZE_DIALOG);
915
gtk_widget_show (image);
916
gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
918
gtk_dialog_run (GTK_DIALOG (dialog));
919
gtk_widget_destroy (dialog);
925
1224
panel_check_network_manager_version (CcNetworkPanel *panel)
927
1229
const gchar *version;
931
1231
/* parse running version */
932
1232
version = nm_client_get_version (panel->priv->client);
933
1233
if (version == NULL) {
936
/* do modal dialog in idle so we don't block startup */
937
panel->priv->nm_warning_idle = g_idle_add ((GSourceFunc)display_version_warning_idle, panel);
1234
gtk_container_remove (GTK_CONTAINER (panel), gtk_bin_get_child (GTK_BIN (panel)));
1236
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 20);
1237
gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
1238
gtk_widget_set_vexpand (box, TRUE);
1239
gtk_container_add (GTK_CONTAINER (panel), box);
1241
label = gtk_label_new (_("Oops, something has gone wrong. Please contact your software vendor."));
1242
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1243
gtk_widget_set_valign (label, GTK_ALIGN_END);
1244
gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
1246
markup = g_strdup_printf ("<small><tt>%s</tt></small>",
1247
_("NetworkManager needs to be running."));
1248
label = gtk_label_new (NULL);
1249
gtk_label_set_markup (GTK_LABEL (label), markup);
1250
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1251
gtk_widget_set_valign (label, GTK_ALIGN_START);
1252
gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
1254
gtk_widget_show_all (box);
1257
manager_running (panel->priv->client, NULL, panel);
1262
editor_done (NetConnectionEditor *editor,
1266
g_object_unref (editor);
944
1270
add_connection_cb (GtkToolButton *button, CcNetworkPanel *panel)
949
dialog = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
950
"connection_type_dialog"));
951
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel))));
953
response = gtk_dialog_run (GTK_DIALOG (dialog));
955
gtk_widget_hide (dialog);
957
if (response == GTK_RESPONSE_OK) {
965
combo = GTK_COMBO_BOX (gtk_builder_get_object (panel->priv->builder,
966
"connection_type_combo"));
967
model = gtk_combo_box_get_model (combo);
968
gtk_combo_box_get_active_iter (combo, &iter);
970
gtk_tree_model_get (model, &iter, 1, &type, -1);
972
cmdline = g_strdup_printf ("nm-connection-editor --create --type %s", type);
973
g_debug ("Launching '%s'\n", cmdline);
976
if (!g_spawn_command_line_async (cmdline, &error)) {
977
g_warning ("Failed to launch nm-connection-editor: %s", error->message);
978
g_error_free (error);
1272
NetConnectionEditor *editor;
1273
GtkWindow *toplevel;
1275
toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel)));
1276
editor = net_connection_editor_new (toplevel, NULL, NULL, NULL,
1277
panel->priv->client);
1278
g_signal_connect (editor, "done", G_CALLBACK (editor_done), panel);
1279
net_connection_editor_run (editor);
995
1292
/* delete the object */
996
1293
net_object_delete (object);
1294
g_object_unref (object);
1000
1298
on_toplevel_map (GtkWidget *widget,
1001
1299
CcNetworkPanel *panel)
1005
1301
/* is the user compiling against a new version, but not running
1006
1302
* the daemon? */
1007
ret = panel_check_network_manager_version (panel);
1009
manager_running (panel->priv->client, NULL, panel);
1011
/* just select the proxy settings */
1012
select_first_device (panel);
1017
rfkill_changed (CcRfkillGlib *rfkill,
1019
CcNetworkPanel *panel)
1023
GHashTableIter iter;
1024
gpointer key, value;
1028
for (l = events; l != NULL; l = l->next) {
1029
struct rfkill_event *event = l->data;
1031
if (event->op == RFKILL_OP_ADD)
1032
g_hash_table_insert (panel->priv->killswitches,
1033
GINT_TO_POINTER (event->idx),
1034
GINT_TO_POINTER (event->soft || event->hard));
1035
else if (event->op == RFKILL_OP_CHANGE)
1036
g_hash_table_insert (panel->priv->killswitches,
1037
GINT_TO_POINTER (event->idx),
1038
GINT_TO_POINTER (event->soft || event->hard));
1039
else if (event->op == RFKILL_OP_DEL)
1040
g_hash_table_remove (panel->priv->killswitches,
1041
GINT_TO_POINTER (event->idx));
1044
g_hash_table_iter_init (&iter, panel->priv->killswitches);
1045
while (g_hash_table_iter_next (&iter, &key, &value)) {
1048
idx = GPOINTER_TO_INT (key);
1049
state = GPOINTER_TO_INT (value);
1050
g_debug ("Killswitch %d is %s", idx, state ? "enabled" : "disabled");
1052
/* A single device that's enabled? airplane mode is off */
1053
if (state == FALSE) {
1059
if (enabled != gtk_switch_get_active (panel->priv->rfkill_switch)) {
1060
g_signal_handlers_block_by_func (panel->priv->rfkill_switch,
1061
cc_network_panel_notify_enable_active_cb,
1063
gtk_switch_set_active (panel->priv->rfkill_switch, enabled);
1064
g_signal_handlers_unblock_by_func (panel->priv->rfkill_switch,
1065
cc_network_panel_notify_enable_active_cb,
1071
network_add_shell_header_widgets_cb (gpointer user_data)
1073
CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);
1078
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
1079
/* TRANSLATORS: this is to disable the radio hardware in the
1081
label = gtk_label_new_with_mnemonic (_("Air_plane Mode"));
1082
gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1083
gtk_widget_set_visible (label, TRUE);
1084
widget = gtk_switch_new ();
1085
gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
1086
gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
1087
gtk_widget_show_all (box);
1088
panel->priv->rfkill_switch = GTK_SWITCH (widget);
1089
cc_shell_embed_widget_in_header (cc_panel_get_shell (CC_PANEL (panel)), box);
1090
panel->priv->kill_switch_header = g_object_ref (box);
1092
panel->priv->killswitches = g_hash_table_new (g_direct_hash, g_direct_equal);
1093
panel->priv->rfkill = cc_rfkill_glib_new ();
1094
g_signal_connect (G_OBJECT (panel->priv->rfkill), "changed",
1095
G_CALLBACK (rfkill_changed), panel);
1096
if (cc_rfkill_glib_open (panel->priv->rfkill) < 0)
1097
gtk_widget_hide (box);
1099
g_signal_connect (panel->priv->rfkill_switch, "notify::active",
1100
G_CALLBACK (cc_network_panel_notify_enable_active_cb),
1303
panel_check_network_manager_version (panel);
1107
1307
cc_network_panel_init (CcNetworkPanel *panel)
1109
DBusGConnection *bus = NULL;
1110
1309
GError *error = NULL;
1111
1310
GtkStyleContext *context;
1112
1311
GtkTreeSelection *selection;
1113
1312
GtkWidget *widget;
1114
1313
GtkWidget *toplevel;
1314
GDBusConnection *system_bus;
1315
GtkCssProvider *provider;
1316
const GPtrArray *connections;
1116
1319
panel->priv = NETWORK_PANEL_PRIVATE (panel);
1320
g_resources_register (cc_network_get_resource ());
1118
1322
panel->priv->builder = gtk_builder_new ();
1119
gtk_builder_add_from_file (panel->priv->builder,
1120
GNOMECC_UI_DIR "/network.ui",
1323
gtk_builder_add_from_resource (panel->priv->builder,
1324
"/org/gnome/control-center/network/network.ui",
1122
1326
if (error != NULL) {
1123
1327
g_warning ("Could not load interface file: %s", error->message);
1124
1328
g_error_free (error);
1150
1354
panel_add_proxy_device (panel);
1152
1356
/* use NetworkManager client */
1153
panel->priv->client = nm_client_new ();
1154
g_signal_connect (panel->priv->client, "notify::" NM_CLIENT_MANAGER_RUNNING,
1357
panel->priv->client = nm_client_new (NULL, NULL);
1358
g_signal_connect (panel->priv->client, "notify::nm-running" ,
1155
1359
G_CALLBACK (manager_running), panel);
1156
g_signal_connect (panel->priv->client, "notify::" NM_CLIENT_ACTIVE_CONNECTIONS,
1360
g_signal_connect (panel->priv->client, "notify::active-connections",
1157
1361
G_CALLBACK (active_connections_changed), panel);
1158
1362
g_signal_connect (panel->priv->client, "device-added",
1159
1363
G_CALLBACK (device_added_cb), panel);
1160
1364
g_signal_connect (panel->priv->client, "device-removed",
1161
1365
G_CALLBACK (device_removed_cb), panel);
1367
/* Setup ModemManager client */
1368
system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
1369
if (system_bus == NULL) {
1370
g_warning ("Error connecting to system D-Bus: %s",
1372
g_clear_error (&error);
1374
panel->priv->modem_manager = mm_manager_new_sync (system_bus,
1375
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
1378
if (panel->priv->modem_manager == NULL) {
1379
g_warning ("Error connecting to ModemManager: %s",
1381
g_clear_error (&error);
1383
g_object_unref (system_bus);
1163
1386
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1164
1387
"add_toolbutton"));
1165
1388
g_signal_connect (widget, "clicked",
1172
1395
G_CALLBACK (remove_connection), panel);
1174
1397
/* add remote settings such as VPN settings as virtual devices */
1175
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
1177
g_warning ("Error connecting to system D-Bus: %s",
1179
g_error_free (error);
1181
panel->priv->remote_settings = nm_remote_settings_new (bus);
1182
g_signal_connect (panel->priv->remote_settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ,
1183
G_CALLBACK (notify_connections_read_cb), panel);
1184
g_signal_connect (panel->priv->remote_settings, NM_REMOTE_SETTINGS_NEW_CONNECTION,
1185
G_CALLBACK (notify_new_connection_cb), panel);
1398
g_signal_connect (panel->priv->client, NM_CLIENT_CONNECTION_ADDED,
1399
G_CALLBACK (notify_connection_added_cb), panel);
1187
1401
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (panel));
1188
1402
g_signal_connect_after (toplevel, "map", G_CALLBACK (on_toplevel_map), panel);
1195
1409
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1197
gtk_widget_reparent (widget, (GtkWidget *) panel);
1199
/* add kill switch widgets when dialog activated */
1200
panel->priv->add_header_widgets_idle = g_idle_add (network_add_shell_header_widgets_cb, panel);
1411
gtk_container_add (GTK_CONTAINER (panel), widget);
1413
provider = gtk_css_provider_new ();
1414
gtk_css_provider_load_from_data (provider, ".circular-button { border-radius: 20px; -gtk-outline-radius: 20px; }", -1, NULL);
1415
gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
1416
GTK_STYLE_PROVIDER (provider),
1417
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
1418
g_object_unref (provider);
1420
/* Cold-plug existing connections */
1421
connections = nm_client_get_connections (panel->priv->client);
1422
for (i = 0; i < connections->len; i++)
1423
add_connection (panel, connections->pdata[i]);
1425
g_debug ("Calling handle_argv() after cold-plugging connections");
1426
handle_argv (panel);