69
83
"heading_network"));
70
84
gtk_size_group_add_widget (heading_size_group, widget);
73
window = GTK_WINDOW (gtk_builder_get_object (device_mobile->priv->builder,
75
86
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder,
77
g_object_ref (widget);
78
gtk_container_remove (GTK_CONTAINER (window), widget);
79
88
gtk_notebook_append_page (notebook, widget, NULL);
80
g_object_unref (widget);
85
connection_activate_cb (NMClient *client,
86
NMActiveConnection *connection,
93
connection_activate_cb (GObject *source_object,
88
95
gpointer user_data)
90
NetDeviceMobile *device_mobile = NET_DEVICE_MOBILE (user_data);
92
if (connection == NULL) {
99
if (!nm_client_activate_connection_finish (NM_CLIENT (source_object), res, &error)) {
93
100
/* failed to activate */
94
nm_device_mobile_refresh_ui (device_mobile);
101
nm_device_mobile_refresh_ui (user_data);
102
g_error_free (error);
129
136
if (g_strcmp0 (object_path, NULL) == 0) {
130
137
panel = net_object_get_panel (NET_OBJECT (device_mobile));
131
cc_network_panel_connect_to_3g_network (panel,
138
toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (panel)));
139
cc_network_panel_connect_to_3g_network (toplevel,
138
145
/* activate the connection */
139
146
g_debug ("try to switch to connection %s", object_path);
140
connection = (NMConnection*) nm_remote_settings_get_connection_by_path (remote_settings,
147
connection = (NMConnection*) nm_client_get_connection_by_path (client, object_path);
142
148
if (connection != NULL) {
143
149
nm_device_disconnect (device, NULL, NULL);
144
nm_client_activate_connection (client,
147
connection_activate_cb,
150
nm_client_activate_connection_async (client,
153
connection_activate_cb,
181
202
GtkComboBox *combobox)
183
204
NetDeviceMobilePrivate *priv = device_mobile->priv;
185
205
GSList *list, *l;
186
206
GtkTreeIter treeiter;
187
207
NMActiveConnection *active_connection;
188
208
NMConnection *connection;
189
NMRemoteSettings *remote_settings;
191
210
/* get the list of available connections for this device */
192
remote_settings = net_object_get_remote_settings (NET_OBJECT (device_mobile));
193
g_assert (remote_settings != NULL);
194
list = nm_remote_settings_list_connections (remote_settings);
195
filtered = nm_device_filter_connections (nm_device, list);
211
list = net_device_get_valid_connections (NET_DEVICE (device_mobile));
196
212
gtk_list_store_clear (liststore);
197
213
active_connection = nm_device_get_active_connection (nm_device);
198
for (l = filtered; l; l = g_slist_next (l)) {
214
for (l = list; l; l = g_slist_next (l)) {
199
215
connection = NM_CONNECTION (l->data);
200
216
gtk_list_store_append (liststore, &treeiter);
201
217
gtk_list_store_set (liststore,
225
241
g_slist_free (list);
226
g_slist_free (filtered);
245
device_mobile_refresh_equipment_id (NetDeviceMobile *device_mobile)
247
const gchar *equipment_id = NULL;
249
if (device_mobile->priv->mm_object != NULL) {
252
/* Modem interface should always be present */
253
modem = mm_object_peek_modem (device_mobile->priv->mm_object);
254
equipment_id = mm_modem_get_equipment_identifier (modem);
256
/* Set equipment ID */
257
if (equipment_id != NULL) {
258
g_debug ("[%s] Equipment ID set to '%s'",
259
mm_object_get_path (device_mobile->priv->mm_object),
263
/* Assume old MM handling */
264
equipment_id = g_object_get_data (G_OBJECT (device_mobile),
265
"ControlCenter::EquipmentIdentifier");
268
panel_set_device_widget_details (device_mobile->priv->builder, "imei", equipment_id);
272
device_mobile_find_provider (NetDeviceMobile *device_mobile,
276
NMAMobileProvider *provider;
277
GString *name = NULL;
279
if (device_mobile->priv->mpd == NULL) {
280
GError *error = NULL;
283
device_mobile->priv->mpd = nma_mobile_providers_database_new_sync (NULL, NULL, NULL, &error);
284
if (device_mobile->priv->mpd == NULL) {
285
g_debug ("Couldn't load mobile providers database: %s",
286
error ? error->message : "");
287
g_clear_error (&error);
292
if (mccmnc != NULL) {
293
provider = nma_mobile_providers_database_lookup_3gpp_mcc_mnc (device_mobile->priv->mpd, mccmnc);
294
if (provider != NULL)
295
name = g_string_new (nma_mobile_provider_get_name (provider));
299
provider = nma_mobile_providers_database_lookup_cdma_sid (device_mobile->priv->mpd, sid);
300
if (provider != NULL) {
302
name = g_string_new (nma_mobile_provider_get_name (provider));
304
g_string_append_printf (name, ", %s", nma_mobile_provider_get_name (provider));
308
return (name != NULL ? g_string_free (name, FALSE) : NULL);
312
device_mobile_refresh_operator_name (NetDeviceMobile *device_mobile)
314
if (device_mobile->priv->mm_object != NULL) {
315
gchar *operator_name = NULL;
316
MMModem3gpp *modem_3gpp;
317
MMModemCdma *modem_cdma;
319
modem_3gpp = mm_object_peek_modem_3gpp (device_mobile->priv->mm_object);
320
modem_cdma = mm_object_peek_modem_cdma (device_mobile->priv->mm_object);
322
if (modem_3gpp != NULL) {
323
const gchar *operator_name_unsafe;
325
operator_name_unsafe = mm_modem_3gpp_get_operator_name (modem_3gpp);
326
if (operator_name_unsafe != NULL && operator_name_unsafe[0] != '\0')
327
operator_name = g_strescape (operator_name_unsafe, NULL);
330
/* If not directly given in the 3GPP interface, try to guess from
332
if (operator_name == NULL) {
333
const gchar *mccmnc = NULL;
336
if (modem_3gpp != NULL)
337
mccmnc = mm_modem_3gpp_get_operator_code (modem_3gpp);
338
if (modem_cdma != NULL)
339
sid = mm_modem_cdma_get_sid (modem_cdma);
340
operator_name = device_mobile_find_provider (device_mobile, mccmnc, sid);
343
/* Set operator name */
344
if (operator_name != NULL) {
345
g_debug ("[%s] Operator name set to '%s'",
346
mm_object_get_path (device_mobile->priv->mm_object),
350
panel_set_device_widget_details (device_mobile->priv->builder, "provider", operator_name);
351
g_free (operator_name);
356
/* Assume old MM handling */
357
gsm = g_object_get_data (G_OBJECT (device_mobile),
358
"ControlCenter::OperatorNameGsm");
359
cdma = g_object_get_data (G_OBJECT (device_mobile),
360
"ControlCenter::OperatorNameCdma");
362
if (gsm != NULL && cdma != NULL) {
365
both = g_strdup_printf ("%s, %s", gsm, cdma);
366
panel_set_device_widget_details (device_mobile->priv->builder, "provider", both);
368
} else if (gsm != NULL) {
369
panel_set_device_widget_details (device_mobile->priv->builder, "provider", gsm);
370
} else if (cdma != NULL) {
371
panel_set_device_widget_details (device_mobile->priv->builder, "provider", cdma);
373
panel_set_device_widget_details (device_mobile->priv->builder, "provider", NULL);
230
379
nm_device_mobile_refresh_ui (NetDeviceMobile *device_mobile)
233
381
gboolean is_connected;
235
382
GtkListStore *liststore;
236
383
GtkWidget *widget;
238
384
NetDeviceMobilePrivate *priv = device_mobile->priv;
239
385
NMClient *client;
240
386
NMDeviceModemCapabilities caps;
241
387
NMDevice *nm_device;
389
nm_device = net_device_get_nm_device (NET_DEVICE (device_mobile));
243
391
/* set device kind */
244
nm_device = net_device_get_nm_device (NET_DEVICE (device_mobile));
245
392
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder, "label_device"));
246
gtk_label_set_label (GTK_LABEL (widget),
247
panel_device_to_localized_string (nm_device));
393
g_object_bind_property (device_mobile, "title", widget, "label", 0);
249
395
/* set up the device on/off switch */
250
396
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder, "device_off_switch"));
252
398
client = net_object_get_client (NET_OBJECT (device_mobile));
253
399
mobilebb_enabled_toggled (client, NULL, device_mobile);
255
/* set device state, with status and optionally speed */
256
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder, "label_status"));
257
status = g_string_new (panel_device_state_to_localized_string (nm_device));
259
g_string_append (status, " - ");
260
/* Translators: network device speed */
261
g_string_append_printf (status, _("%d Mb/s"), speed);
263
gtk_label_set_label (GTK_LABEL (widget), status->str);
264
g_string_free (status, TRUE);
265
gtk_widget_set_tooltip_text (widget, panel_device_state_reason_to_localized_string (nm_device));
401
/* set device state, with status */
402
panel_set_device_status (device_mobile->priv->builder, "label_status", nm_device, NULL);
267
404
/* sensitive for other connection types if the device is currently connected */
268
405
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder,
330
456
connection = net_device_get_find_connection (NET_DEVICE (device_mobile));
331
457
if (connection == NULL)
333
nm_client_activate_connection (client,
335
net_device_get_nm_device (NET_DEVICE (device_mobile)),
459
nm_client_activate_connection_async (client,
461
net_device_get_nm_device (NET_DEVICE (device_mobile)),
462
NULL, NULL, NULL, NULL);
338
466
connection = net_device_get_find_connection (NET_DEVICE (device_mobile));
339
467
if (connection == NULL)
341
path = nm_connection_get_path (connection);
469
uuid = nm_connection_get_uuid (connection);
342
470
client = net_object_get_client (NET_OBJECT (device_mobile));
343
471
acs = nm_client_get_active_connections (client);
344
for (i = 0; i < acs->len; i++) {
472
for (i = 0; acs && i < acs->len; i++) {
345
473
a = (NMActiveConnection*)acs->pdata[i];
346
if (strcmp (nm_active_connection_get_connection (a), path) == 0) {
347
nm_client_deactivate_connection (client, a);
474
if (strcmp (nm_active_connection_get_uuid (a), uuid) == 0) {
475
nm_client_deactivate_connection (client, a, NULL, NULL);
380
508
"EquipmentIdentifier");
383
g_object_set_data_full (G_OBJECT (device),
384
"ControlCenter::EquipmentIdentifier",
385
g_variant_dup_string (result, NULL),
512
g_object_set_data_full (G_OBJECT (device_mobile),
513
"ControlCenter::EquipmentIdentifier",
514
g_variant_dup_string (result, NULL),
389
516
g_variant_unref (result);
391
g_object_unref (proxy);
519
device_mobile_refresh_equipment_id (device_mobile);
520
g_object_unref (proxy);
395
device_mobile_get_registration_info_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
524
device_mobile_save_operator_name (NetDeviceMobile *device_mobile,
526
const gchar *operator_name)
397
gchar *operator_code = NULL;
398
GError *error = NULL;
399
guint registration_status;
400
GVariant *result = NULL;
401
gchar *operator_name = NULL;
402
528
gchar *operator_name_safe = NULL;
403
NMDevice *device = (NMDevice *) user_data;
405
result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
406
if (result == NULL) {
407
g_warning ("Error getting registration info: %s\n",
409
g_error_free (error);
414
g_variant_get (result, "((uss))",
415
®istration_status,
418
530
if (operator_name != NULL && operator_name[0] != '\0')
419
531
operator_name_safe = g_strescape (operator_name, NULL);
422
g_object_set_data_full (G_OBJECT (device),
423
"ControlCenter::OperatorName",
534
g_object_set_data_full (G_OBJECT (device_mobile),
424
536
operator_name_safe,
539
device_mobile_refresh_operator_name (device_mobile);
543
device_mobile_get_registration_info_cb (GObject *source_object,
547
gchar *operator_code = NULL;
548
GError *error = NULL;
549
guint registration_status;
550
GVariant *result = NULL;
551
gchar *operator_name = NULL;
552
NetDeviceMobile *device_mobile = (NetDeviceMobile *)user_data;
554
result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
555
if (result == NULL) {
556
g_warning ("Error getting registration info: %s\n",
558
g_error_free (error);
563
g_variant_get (result, "((uss))",
564
®istration_status,
568
/* If none give, try to guess it */
569
if (operator_name == NULL || operator_name[0] == '\0') {
570
g_free (operator_name);
571
operator_name = device_mobile_find_provider (device_mobile, operator_code, 0);
574
/* save and refresh */
575
device_mobile_save_operator_name (device_mobile,
576
"ControlCenter::OperatorNameGsm",
427
579
g_free (operator_name);
428
580
g_free (operator_code);
433
device_mobile_device_got_modem_manager_gsm_cb (GObject *source_object,
585
device_mobile_gsm_signal_cb (GDBusProxy *proxy,
588
GVariant *parameters,
591
guint registration_status = 0;
592
gchar *operator_code = NULL;
593
gchar *operator_name = NULL;
594
NetDeviceMobile *device_mobile = (NetDeviceMobile *)user_data;
596
if (!g_str_equal (signal_name, "RegistrationInfo"))
599
g_variant_get (parameters,
601
®istration_status,
605
/* If none given, try to guess it */
606
if (operator_name == NULL || operator_name[0] == '\0') {
607
g_free (operator_name);
608
operator_name = device_mobile_find_provider (device_mobile, operator_code, 0);
611
/* save and refresh */
612
device_mobile_save_operator_name (device_mobile,
613
"ControlCenter::OperatorNameGsm",
616
g_free (operator_code);
617
g_free (operator_name);
621
device_mobile_device_got_modem_manager_gsm_cb (GObject *source_object,
437
625
GError *error = NULL;
439
NMDevice *device = (NMDevice *) user_data;
626
NetDeviceMobile *device_mobile = (NetDeviceMobile *)user_data;
441
proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
628
device_mobile->priv->gsm_proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
629
if (device_mobile->priv->gsm_proxy == NULL) {
443
630
g_warning ("Error creating ModemManager GSM proxy: %s\n",
445
632
g_error_free (error);
449
g_dbus_proxy_call (proxy,
636
/* Setup value updates */
637
g_signal_connect (device_mobile->priv->gsm_proxy,
639
G_CALLBACK (device_mobile_gsm_signal_cb),
642
/* Load initial value */
643
g_dbus_proxy_call (device_mobile->priv->gsm_proxy,
450
644
"GetRegistrationInfo",
452
646
G_DBUS_CALL_FLAGS_NONE,
455
649
device_mobile_get_registration_info_cb,
459
g_object_unref (proxy);
654
device_mobile_get_serving_system_cb (GObject *source_object,
658
NetDeviceMobile *device_mobile = (NetDeviceMobile *)user_data;
659
GVariant *result = NULL;
660
GError *error = NULL;
665
gchar *operator_name;
667
result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
668
if (result == NULL) {
669
g_warning ("Error getting serving system: %s\n",
671
g_error_free (error);
676
g_variant_get (result, "((usu))",
681
operator_name = device_mobile_find_provider (device_mobile, NULL, sid);
683
/* save and refresh */
684
device_mobile_save_operator_name (device_mobile,
685
"ControlCenter::OperatorNameCdma",
689
g_variant_unref (result);
693
device_mobile_device_got_modem_manager_cdma_cb (GObject *source_object,
697
GError *error = NULL;
698
NetDeviceMobile *device_mobile = (NetDeviceMobile *)user_data;
700
device_mobile->priv->cdma_proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
701
if (device_mobile->priv->cdma_proxy == NULL) {
702
g_warning ("Error creating ModemManager CDMA proxy: %s\n",
704
g_error_free (error);
708
/* Load initial value */
709
g_dbus_proxy_call (device_mobile->priv->cdma_proxy,
712
G_DBUS_CALL_FLAGS_NONE,
715
device_mobile_get_serving_system_cb,
466
723
NetDeviceMobile *device_mobile = NET_DEVICE_MOBILE (object);
467
724
NMClient *client;
468
725
NMDevice *device;
726
NMDeviceModemCapabilities caps;
470
728
G_OBJECT_CLASS (net_device_mobile_parent_class)->constructed (object);
472
730
device = net_device_get_nm_device (NET_DEVICE (device_mobile));
473
731
cancellable = net_object_get_cancellable (NET_OBJECT (device_mobile));
474
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
475
G_DBUS_PROXY_FLAGS_NONE,
477
"org.freedesktop.ModemManager",
478
nm_device_get_udi (device),
479
"org.freedesktop.ModemManager.Modem",
481
device_mobile_device_got_modem_manager_cb,
483
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
484
G_DBUS_PROXY_FLAGS_NONE,
486
"org.freedesktop.ModemManager",
487
nm_device_get_udi (device),
488
"org.freedesktop.ModemManager.Modem.Gsm.Network",
490
device_mobile_device_got_modem_manager_gsm_cb,
733
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
735
/* Only load proxies if we have broadband modems of the OLD ModemManager interface */
736
if (g_str_has_prefix (nm_device_get_udi (device), "/org/freedesktop/ModemManager/") &&
737
((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
738
(caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) ||
739
(caps & NM_DEVICE_MODEM_CAPABILITY_LTE))) {
740
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
741
G_DBUS_PROXY_FLAGS_NONE,
743
"org.freedesktop.ModemManager",
744
nm_device_get_udi (device),
745
"org.freedesktop.ModemManager.Modem",
747
device_mobile_device_got_modem_manager_cb,
750
if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
751
(caps & NM_DEVICE_MODEM_CAPABILITY_LTE)) {
752
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
753
G_DBUS_PROXY_FLAGS_NONE,
755
"org.freedesktop.ModemManager",
756
nm_device_get_udi (device),
757
"org.freedesktop.ModemManager.Modem.Gsm.Network",
759
device_mobile_device_got_modem_manager_gsm_cb,
763
if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
764
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
765
G_DBUS_PROXY_FLAGS_NONE,
767
"org.freedesktop.ModemManager",
768
nm_device_get_udi (device),
769
"org.freedesktop.ModemManager.Modem.Cdma",
771
device_mobile_device_got_modem_manager_cdma_cb,
493
776
client = net_object_get_client (NET_OBJECT (device_mobile));
494
g_signal_connect (client, "notify::wwan-enabled",
495
G_CALLBACK (mobilebb_enabled_toggled),
777
g_signal_connect_object (client, "notify::wwan-enabled",
778
G_CALLBACK (mobilebb_enabled_toggled),
497
780
nm_device_mobile_refresh_ui (device_mobile);
501
net_device_mobile_finalize (GObject *object)
784
operator_name_updated (MMModem3gpp *modem_3gpp_iface,
786
NetDeviceMobile *self)
788
device_mobile_refresh_operator_name (self);
792
net_device_mobile_setup_modem_object (NetDeviceMobile *self)
794
MMModem3gpp *modem_3gpp;
796
if (self->priv->mm_object == NULL)
799
/* Load equipment ID initially */
800
device_mobile_refresh_equipment_id (self);
802
/* Follow changes in operator name and load initial values */
803
modem_3gpp = mm_object_peek_modem_3gpp (self->priv->mm_object);
804
if (modem_3gpp != NULL) {
805
g_assert (self->priv->operator_name_updated == 0);
806
self->priv->operator_name_updated = g_signal_connect (modem_3gpp,
807
"notify::operator-name",
808
G_CALLBACK (operator_name_updated),
810
device_mobile_refresh_operator_name (self);
816
net_device_mobile_get_property (GObject *device_,
821
NetDeviceMobile *self = NET_DEVICE_MOBILE (device_);
824
case PROP_MODEM_OBJECT:
825
g_value_set_object (value, self->priv->mm_object);
828
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
834
net_device_mobile_set_property (GObject *device_,
839
NetDeviceMobile *self = NET_DEVICE_MOBILE (device_);
842
case PROP_MODEM_OBJECT:
843
self->priv->mm_object = g_value_dup_object (value);
844
net_device_mobile_setup_modem_object (self);
847
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
853
net_device_mobile_dispose (GObject *object)
503
855
NetDeviceMobile *device_mobile = NET_DEVICE_MOBILE (object);
504
856
NetDeviceMobilePrivate *priv = device_mobile->priv;
506
g_object_unref (priv->builder);
508
G_OBJECT_CLASS (net_device_mobile_parent_class)->finalize (object);
858
g_clear_object (&priv->builder);
859
g_clear_object (&priv->gsm_proxy);
860
g_clear_object (&priv->cdma_proxy);
862
if (priv->operator_name_updated) {
863
g_assert (priv->mm_object != NULL);
864
g_signal_handler_disconnect (mm_object_peek_modem_3gpp (priv->mm_object), priv->operator_name_updated);
865
priv->operator_name_updated = 0;
867
g_clear_object (&priv->mm_object);
868
g_clear_object (&priv->mpd);
870
G_OBJECT_CLASS (net_device_mobile_parent_class)->dispose (object);