~ubuntu-branches/ubuntu/oneiric/gnome-control-center/oneiric

« back to all changes in this revision

Viewing changes to panels/network/cc-network-panel.c

  • Committer: Package Import Robot
  • Author(s): Rodrigo Moya, Rodrigo Moya, Gunnar Hjalmarsson
  • Date: 2011-08-30 12:24:44 UTC
  • mfrom: (1.1.50 upstream)
  • Revision ID: package-import@ubuntu.com-20110830122444-bmvakubeof8hgbhe
Tags: 1:3.1.90-0ubuntu1
[ Rodrigo Moya ]
* New upstream release
* debian/patches/03_dont_show_region_panel_in_unity.patch:
  - Remove upstreamed patch
* debian/patches/04_add_theme_selection.patch:
  - Set the metacity theme also

[ Gunnar Hjalmarsson ]
* debian/patches/52_ubuntu_language_list_mods.patch:
  - Change the list of options, when setting language from User
    Accounts, to items representing available translations, and with
    that make it similar to the language list in language-selector.
  - Make items representing language @variants be displayed as such.
* debian/control.in:
  - accountsservice (>= 0.6.13-1ubuntu2) added to dependency list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
 
88
88
static void     refresh_ui      (CcNetworkPanel *panel);
89
89
static NetObject *find_in_model_by_id (CcNetworkPanel *panel, const gchar *id);
 
90
static gboolean find_model_iter_by_object (GtkTreeModel *model, const NetObject *object, GtkTreeIter *iter);
90
91
 
91
92
static void
92
93
cc_network_panel_get_property (GObject    *object,
439
440
                                g_free);
440
441
 
441
442
        g_free (operator_name);
442
 
        g_free (operator_name_safe);
443
443
        g_free (operator_code);
444
444
        g_variant_unref (result);
445
445
}
997
997
}
998
998
 
999
999
static gchar *
 
1000
get_ipv4_config_address_as_string (NMIP4Config *ip4_config, const char *what)
 
1001
{
 
1002
        const GSList *list;
 
1003
        struct in_addr addr;
 
1004
        gchar *str = NULL;
 
1005
        gchar tmp[INET_ADDRSTRLEN];
 
1006
        NMIP4Address *address;
 
1007
 
 
1008
        /* get address */
 
1009
        list = nm_ip4_config_get_addresses (ip4_config);
 
1010
        if (list == NULL)
 
1011
                goto out;
 
1012
 
 
1013
        /* we only care about one address */
 
1014
        address = list->data;
 
1015
        if (!strcmp (what, "address"))
 
1016
                addr.s_addr = nm_ip4_address_get_address (address);
 
1017
        else if (!strcmp (what, "gateway"))
 
1018
                addr.s_addr = nm_ip4_address_get_gateway (address);
 
1019
        else if (!strcmp (what, "netmask"))
 
1020
                addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip4_address_get_prefix (address));
 
1021
        else
 
1022
                goto out;
 
1023
 
 
1024
        if (!inet_ntop (AF_INET, &addr, tmp, sizeof(tmp)))
 
1025
                goto out;
 
1026
        str = g_strdup (tmp);
 
1027
out:
 
1028
        return str;
 
1029
}
 
1030
 
 
1031
static gchar *
 
1032
get_ipv4_config_name_servers_as_string (NMIP4Config *ip4_config)
 
1033
{
 
1034
        const GArray *array;
 
1035
        GString *dns;
 
1036
        struct in_addr addr;
 
1037
        gchar tmp[INET_ADDRSTRLEN];
 
1038
        int i;
 
1039
 
 
1040
        dns = g_string_new (NULL);
 
1041
 
 
1042
        array = nm_ip4_config_get_nameservers (ip4_config);
 
1043
        if (array) {
 
1044
                for (i = 0; i < array->len; i++) {
 
1045
                        addr.s_addr = g_array_index (array, guint32, i);
 
1046
                        if (inet_ntop (AF_INET, &addr, tmp, sizeof(tmp)))
 
1047
                                g_string_append_printf (dns, "%s ", tmp);
 
1048
                }
 
1049
        }
 
1050
 
 
1051
        return g_string_free (dns, FALSE);
 
1052
}
 
1053
 
 
1054
static gchar *
1000
1055
get_ipv6_config_address_as_string (NMIP6Config *ip6_config)
1001
1056
{
1002
1057
        const GSList *list;
1003
1058
        const struct in6_addr *addr;
1004
1059
        gchar *str = NULL;
1005
 
        gchar tmp[1024];
 
1060
        gchar tmp[INET6_ADDRSTRLEN];
1006
1061
        NMIP6Address *address;
1007
1062
 
1008
1063
        /* get address */
1126
1181
                case NM_DEVICE_TYPE_WIMAX:
1127
1182
                        nm_client_wimax_set_enabled (panel->priv->client, active);
1128
1183
                        break;
 
1184
                case NM_DEVICE_TYPE_MODEM:
 
1185
                        nm_client_wwan_set_enabled (panel->priv->client, active);
 
1186
                        break;
1129
1187
                default: ;
1130
1188
                        /* FIXME: handle other device types */
1131
1189
                }
1187
1245
}
1188
1246
 
1189
1247
static void
 
1248
mobilebb_enabled_toggled (NMClient       *client,
 
1249
                          GParamSpec     *pspec,
 
1250
                          CcNetworkPanel *panel)
 
1251
{
 
1252
        gboolean enabled;
 
1253
        GtkSwitch *sw;
 
1254
        NMDevice *device;
 
1255
        NetObject *object;
 
1256
 
 
1257
        object = get_selected_object (panel);
 
1258
        if (object == NULL)
 
1259
                return;
 
1260
        device = net_device_get_nm_device (NET_DEVICE (object));
 
1261
 
 
1262
        if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_MODEM)
 
1263
                return;
 
1264
 
 
1265
        enabled = nm_client_wwan_get_enabled (client);
 
1266
        sw = GTK_SWITCH (gtk_builder_get_object (panel->priv->builder,
 
1267
                                                 "device_mobilebb_off_switch"));
 
1268
 
 
1269
        panel->priv->updating_device = TRUE;
 
1270
        gtk_switch_set_active (sw, enabled);
 
1271
        panel->priv->updating_device = FALSE;
 
1272
}
 
1273
 
 
1274
static void
1190
1275
update_off_switch_from_device_state (GtkSwitch *sw, NMDeviceState state, CcNetworkPanel *panel)
1191
1276
{
1192
1277
        panel->priv->updating_device = TRUE;
1385
1470
                gtk_widget_show (widget);
1386
1471
                wimax_enabled_toggled (panel->priv->client, NULL, panel);
1387
1472
                break;
 
1473
        case NM_DEVICE_TYPE_MODEM:
 
1474
                gtk_widget_show (widget);
 
1475
                mobilebb_enabled_toggled (panel->priv->client, NULL, panel);
 
1476
                break;
1388
1477
        default:
1389
1478
                gtk_widget_hide (widget);
1390
1479
                break;
1601
1690
        if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
1602
1691
            (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
1603
1692
                /* IMEI */
1604
 
                str = g_object_get_data (G_OBJECT (device),
 
1693
                str = g_object_get_data (G_OBJECT (nm_device),
1605
1694
                                         "ControlCenter::EquipmentIdentifier");
1606
1695
                panel_set_widget_data (panel,
1607
1696
                                       "mobilebb",
1609
1698
                                       str);
1610
1699
 
1611
1700
                /* operator name */
1612
 
                str = g_object_get_data (G_OBJECT (device),
 
1701
                str = g_object_get_data (G_OBJECT (nm_device),
1613
1702
                                         "ControlCenter::OperatorName");
1614
1703
                panel_set_widget_data (panel,
1615
1704
                                       "mobilebb",
1628
1717
nm_device_refresh_device_ui (CcNetworkPanel *panel, NetDevice *device)
1629
1718
{
1630
1719
        CcNetworkPanelPrivate *priv = panel->priv;
1631
 
        const gchar *str;
1632
1720
        const gchar *sub_pane = NULL;
1633
1721
        gchar *str_tmp;
1634
 
        GHashTable *options = NULL;
1635
1722
        GtkWidget *widget;
1636
1723
        NMDeviceType type;
1637
 
        NMDHCP4Config *config_dhcp4 = NULL;
 
1724
        NMIP4Config *ip4_config = NULL;
1638
1725
        NMIP6Config *ip6_config = NULL;
1639
1726
        NMDevice *nm_device;
1640
1727
        gboolean has_ip4;
1683
1770
                goto out;
1684
1771
 
1685
1772
        /* get IP4 parameters */
1686
 
        config_dhcp4 = nm_device_get_dhcp4_config (nm_device);
1687
 
        if (!is_hotspot && config_dhcp4 != NULL) {
1688
 
                g_object_get (G_OBJECT (config_dhcp4),
1689
 
                              NM_DHCP4_CONFIG_OPTIONS, &options,
1690
 
                              NULL);
1691
 
 
 
1773
        ip4_config = nm_device_get_ip4_config (nm_device);
 
1774
        if (!is_hotspot && ip4_config != NULL) {
1692
1775
                /* IPv4 address */
1693
 
                str = nm_dhcp4_config_get_one_option (config_dhcp4,
1694
 
                                                      "ip_address");
 
1776
 
 
1777
                str_tmp = get_ipv4_config_address_as_string (ip4_config, "address");
1695
1778
                panel_set_widget_data (panel,
1696
1779
                                       sub_pane,
1697
1780
                                       "ipv4",
1698
 
                                       str);
1699
 
                has_ip4 = str != NULL;
 
1781
                                       str_tmp);
 
1782
                has_ip4 = str_tmp != NULL;
 
1783
                g_free (str_tmp);
1700
1784
 
1701
1785
                /* IPv4 DNS */
 
1786
                str_tmp = get_ipv4_config_name_servers_as_string (ip4_config);
1702
1787
                panel_set_widget_data (panel,
1703
1788
                                       sub_pane,
1704
1789
                                       "dns",
1705
 
                                       nm_dhcp4_config_get_one_option (config_dhcp4,
1706
 
                                                                       "domain_name_servers"));
 
1790
                                       str_tmp);
 
1791
                g_free (str_tmp);
1707
1792
 
1708
1793
                /* IPv4 route */
 
1794
                str_tmp = get_ipv4_config_address_as_string (ip4_config, "gateway");
1709
1795
                panel_set_widget_data (panel,
1710
1796
                                       sub_pane,
1711
1797
                                       "route",
1712
 
                                       nm_dhcp4_config_get_one_option (config_dhcp4,
1713
 
                                                                       "routers"));
 
1798
                                       str_tmp);
 
1799
                g_free (str_tmp);
1714
1800
 
1715
1801
                /* IPv4 netmask */
1716
1802
                if (type == NM_DEVICE_TYPE_ETHERNET) {
 
1803
                        str_tmp = get_ipv4_config_address_as_string (ip4_config, "netmask");
1717
1804
                        panel_set_widget_data (panel,
1718
1805
                                               sub_pane,
1719
1806
                                               "subnet",
1720
 
                                               nm_dhcp4_config_get_one_option (config_dhcp4,
1721
 
                                                                               "subnet_mask"));
 
1807
                                               str_tmp);
 
1808
                        g_free (str_tmp);
1722
1809
                }
1723
1810
        } else {
1724
1811
                /* IPv4 address */
1790
1877
        const gchar *path;
1791
1878
        const gchar *apath;
1792
1879
        NMVPNConnectionState state;
 
1880
        gchar *title;
 
1881
        GtkListStore *liststore_devices;
 
1882
        GtkTreeIter iter;
1793
1883
 
1794
1884
        sw = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1795
1885
                                                 "device_vpn_off_switch"));
1812
1902
                                      "network-vpn",
1813
1903
                                      GTK_ICON_SIZE_DIALOG);
1814
1904
 
1815
 
        /* use title */
 
1905
        /* update title */
1816
1906
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
1817
1907
                                                     "label_vpn_device"));
1818
 
        gtk_label_set_label (GTK_LABEL (widget), net_object_get_title (NET_OBJECT (vpn)));
 
1908
        title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (net_vpn_get_connection (vpn)));
 
1909
        net_object_set_title (NET_OBJECT (vpn), title);
 
1910
        gtk_label_set_label (GTK_LABEL (widget), title);
 
1911
 
 
1912
        /* update list store title */
 
1913
        liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
 
1914
                                                                    "liststore_devices"));
 
1915
        if (find_model_iter_by_object (GTK_TREE_MODEL (liststore_devices), NET_OBJECT (vpn), &iter)) {
 
1916
                gtk_list_store_set (liststore_devices,
 
1917
                                    &iter,
 
1918
                                    PANEL_DEVICES_COLUMN_TITLE, title,
 
1919
                                    -1);
 
1920
        }
 
1921
        g_free (title);
1819
1922
 
1820
1923
        /* use status */
1821
1924
        state = net_vpn_get_state (vpn);
1844
1947
                               state != NM_VPN_CONNECTION_STATE_DISCONNECTED);
1845
1948
        priv->updating_device = FALSE;
1846
1949
 
 
1950
        /* service type */
 
1951
        panel_set_widget_data (panel,
 
1952
                               sub_pane,
 
1953
                               "service_type",
 
1954
                               net_vpn_get_service_type (vpn));
 
1955
 
1847
1956
        /* gateway */
1848
1957
        panel_set_widget_data (panel,
1849
1958
                               sub_pane,
1850
1959
                               "gateway",
1851
 
                                net_vpn_get_gateway (vpn));
 
1960
                               net_vpn_get_gateway (vpn));
1852
1961
 
1853
1962
        /* groupname */
1854
1963
        panel_set_widget_data (panel,
1855
1964
                               sub_pane,
1856
1965
                               "group_name",
1857
 
                                net_vpn_get_id (vpn));
 
1966
                               net_vpn_get_id (vpn));
1858
1967
 
1859
1968
        /* username */
1860
1969
        panel_set_widget_data (panel,
1861
1970
                               sub_pane,
1862
1971
                               "username",
1863
 
                                net_vpn_get_username (vpn));
 
1972
                               net_vpn_get_username (vpn));
1864
1973
 
1865
1974
        /* password */
1866
1975
        panel_set_widget_data (panel,
1867
1976
                               sub_pane,
1868
1977
                               "group_password",
1869
 
                                net_vpn_get_password (vpn));
 
1978
                               net_vpn_get_password (vpn));
1870
1979
}
1871
1980
 
1872
1981
static gboolean
2121
2230
        return object;
2122
2231
}
2123
2232
 
 
2233
static gboolean
 
2234
find_model_iter_by_object (GtkTreeModel *model, const NetObject *object, GtkTreeIter *iter)
 
2235
{
 
2236
        gboolean valid;
 
2237
        NetObject *object_tmp;
 
2238
 
 
2239
        /* find iter in model according to the passed object */
 
2240
        valid = gtk_tree_model_get_iter_first (model, iter);
 
2241
        while (valid) {
 
2242
                gtk_tree_model_get (model, iter,
 
2243
                                    PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
 
2244
                                    -1);
 
2245
                if (object_tmp != NULL)
 
2246
                        g_object_unref (object_tmp);
 
2247
                if (object_tmp == object)
 
2248
                        return TRUE;
 
2249
                valid = gtk_tree_model_iter_next (model, iter);
 
2250
        }
 
2251
 
 
2252
        return FALSE;
 
2253
}
 
2254
 
2124
2255
static void
2125
2256
panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection)
2126
2257
{
2671
2802
                str = g_strdup (g_get_host_name ());
2672
2803
        }
2673
2804
 
 
2805
        if (str == NULL || *str == '\0') {
 
2806
                str = g_strdup ("GNOME");
 
2807
        }
 
2808
 
2674
2809
        return str;
2675
2810
}
2676
2811
 
3191
3326
                          G_CALLBACK (wireless_enabled_toggled), panel);
3192
3327
        g_signal_connect (panel->priv->client, "notify::wimax-enabled",
3193
3328
                          G_CALLBACK (wimax_enabled_toggled), panel);
 
3329
        g_signal_connect (panel->priv->client, "notify::wwan-enabled",
 
3330
                          G_CALLBACK (mobilebb_enabled_toggled), panel);
3194
3331
 
3195
3332
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3196
3333
                                                     "start_hotspot_button"));
3213
3350
                          G_CALLBACK (edit_connection), panel);
3214
3351
 
3215
3352
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
 
3353
                                                     "button_mobilebb_options"));
 
3354
        g_signal_connect (widget, "clicked",
 
3355
                          G_CALLBACK (edit_connection), panel);
 
3356
 
 
3357
        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
3216
3358
                                                     "button_vpn_options"));
3217
3359
        g_signal_connect (widget, "clicked",
3218
3360
                          G_CALLBACK (edit_connection), panel);