Merge lp:~khurshid-alam/unity-control-center/libnm-port into lp:unity-control-center

Proposed by Khurshid Alam
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 12921
Merged at revision: 12921
Proposed branch: lp:~khurshid-alam/unity-control-center/libnm-port
Merge into: lp:unity-control-center
Diff against target: 29643 lines (+22886/-3425)
112 files modified
configure.ac (+15/-8)
debian/control (+3/-3)
panels/network/Makefile.am (+25/-31)
panels/network/cc-network-panel.c (+541/-315)
panels/network/cc-network-panel.h (+3/-1)
panels/network/connection-editor/8021x-security-page.ui (+295/-0)
panels/network/connection-editor/Makefile.am (+54/-0)
panels/network/connection-editor/ce-page-8021x-security.c (+186/-0)
panels/network/connection-editor/ce-page-8021x-security.h (+63/-0)
panels/network/connection-editor/ce-page-details.c (+289/-0)
panels/network/connection-editor/ce-page-details.h (+68/-0)
panels/network/connection-editor/ce-page-ethernet.c (+187/-0)
panels/network/connection-editor/ce-page-ethernet.h (+71/-0)
panels/network/connection-editor/ce-page-ip4.c (+907/-0)
panels/network/connection-editor/ce-page-ip4.h (+70/-0)
panels/network/connection-editor/ce-page-ip6.c (+838/-0)
panels/network/connection-editor/ce-page-ip6.h (+70/-0)
panels/network/connection-editor/ce-page-security.c (+467/-0)
panels/network/connection-editor/ce-page-security.h (+65/-0)
panels/network/connection-editor/ce-page-vpn.c (+198/-0)
panels/network/connection-editor/ce-page-vpn.h (+71/-0)
panels/network/connection-editor/ce-page-wifi.c (+201/-0)
panels/network/connection-editor/ce-page-wifi.h (+62/-0)
panels/network/connection-editor/ce-page.c (+541/-0)
panels/network/connection-editor/ce-page.h (+114/-0)
panels/network/connection-editor/connection-editor.gresource.xml (+14/-0)
panels/network/connection-editor/connection-editor.ui (+130/-0)
panels/network/connection-editor/details-page.ui (+379/-0)
panels/network/connection-editor/ethernet-page.ui (+236/-0)
panels/network/connection-editor/ip4-page.ui (+428/-0)
panels/network/connection-editor/ip6-page.ui (+442/-0)
panels/network/connection-editor/net-connection-editor.c (+893/-0)
panels/network/connection-editor/net-connection-editor.h (+92/-0)
panels/network/connection-editor/security-page.ui (+294/-0)
panels/network/connection-editor/ui-helpers.c (+38/-0)
panels/network/connection-editor/ui-helpers.h (+27/-0)
panels/network/connection-editor/vpn-helpers.c (+352/-0)
panels/network/connection-editor/vpn-helpers.h (+41/-0)
panels/network/connection-editor/vpn-page.ui (+75/-0)
panels/network/connection-editor/wifi-page.ui (+140/-0)
panels/network/net-device-ethernet.c (+638/-0)
panels/network/net-device-ethernet.h (+68/-0)
panels/network/net-device-mobile.c (+533/-165)
panels/network/net-device-mobile.h (+1/-1)
panels/network/net-device-simple.c (+299/-0)
panels/network/net-device-simple.h (+67/-0)
panels/network/net-device-wifi.c (+1097/-1117)
panels/network/net-device.c (+58/-89)
panels/network/net-device.h (+5/-1)
panels/network/net-object.c (+25/-37)
panels/network/net-object.h (+3/-3)
panels/network/net-proxy.c (+60/-164)
panels/network/net-vpn.c (+131/-53)
panels/network/net-vpn.h (+1/-3)
panels/network/network-dialogs.c (+59/-101)
panels/network/network-dialogs.h (+16/-18)
panels/network/network-ethernet.ui (+219/-0)
panels/network/network-mobile.ui (+114/-86)
panels/network/network-proxy.ui (+141/-90)
panels/network/network-simple.ui (+340/-0)
panels/network/network-vpn.ui (+114/-95)
panels/network/network-wifi.ui (+1593/-635)
panels/network/network.gresource.xml (+12/-0)
panels/network/network.ui (+5/-198)
panels/network/panel-common.c (+163/-202)
panels/network/panel-common.h (+11/-9)
panels/network/wireless-security/Makefile.am (+72/-0)
panels/network/wireless-security/eap-method-fast.c (+450/-0)
panels/network/wireless-security/eap-method-fast.h (+36/-0)
panels/network/wireless-security/eap-method-fast.ui (+202/-0)
panels/network/wireless-security/eap-method-leap.c (+263/-0)
panels/network/wireless-security/eap-method-leap.h (+35/-0)
panels/network/wireless-security/eap-method-leap.ui (+107/-0)
panels/network/wireless-security/eap-method-peap.c (+450/-0)
panels/network/wireless-security/eap-method-peap.h (+36/-0)
panels/network/wireless-security/eap-method-peap.ui (+220/-0)
panels/network/wireless-security/eap-method-simple.c (+366/-0)
panels/network/wireless-security/eap-method-simple.h (+63/-0)
panels/network/wireless-security/eap-method-simple.ui (+120/-0)
panels/network/wireless-security/eap-method-tls.c (+552/-0)
panels/network/wireless-security/eap-method-tls.h (+36/-0)
panels/network/wireless-security/eap-method-tls.ui (+216/-0)
panels/network/wireless-security/eap-method-ttls.c (+476/-0)
panels/network/wireless-security/eap-method-ttls.h (+36/-0)
panels/network/wireless-security/eap-method-ttls.ui (+167/-0)
panels/network/wireless-security/eap-method.c (+676/-0)
panels/network/wireless-security/eap-method.h (+131/-0)
panels/network/wireless-security/helpers.c (+53/-0)
panels/network/wireless-security/helpers.h (+35/-0)
panels/network/wireless-security/nm-connection-editor-to-network-panel.patch (+44/-0)
panels/network/wireless-security/nm-connection-editor-ui-to-network-panel.patch (+495/-0)
panels/network/wireless-security/nm-default.h (+62/-0)
panels/network/wireless-security/utils.c (+77/-0)
panels/network/wireless-security/utils.h (+44/-0)
panels/network/wireless-security/wireless-security.c (+604/-0)
panels/network/wireless-security/wireless-security.gresource.xml (+16/-0)
panels/network/wireless-security/wireless-security.h (+154/-0)
panels/network/wireless-security/ws-dynamic-wep.c (+132/-0)
panels/network/wireless-security/ws-dynamic-wep.h (+32/-0)
panels/network/wireless-security/ws-dynamic-wep.ui (+94/-0)
panels/network/wireless-security/ws-leap.c (+213/-0)
panels/network/wireless-security/ws-leap.h (+30/-0)
panels/network/wireless-security/ws-leap.ui (+108/-0)
panels/network/wireless-security/ws-wep-key.c (+364/-0)
panels/network/wireless-security/ws-wep-key.h (+33/-0)
panels/network/wireless-security/ws-wep-key.ui (+196/-0)
panels/network/wireless-security/ws-wpa-eap.c (+133/-0)
panels/network/wireless-security/ws-wpa-eap.h (+32/-0)
panels/network/wireless-security/ws-wpa-eap.ui (+87/-0)
panels/network/wireless-security/ws-wpa-psk.c (+233/-0)
panels/network/wireless-security/ws-wpa-psk.h (+30/-0)
panels/network/wireless-security/ws-wpa-psk.ui (+117/-0)
To merge this branch: bzr merge lp:~khurshid-alam/unity-control-center/libnm-port
Reviewer Review Type Date Requested Status
Sebastien Bacher Approve
Review via email: mp+366762@code.launchpad.net

Commit message

Network: Port to libnm 1.2

Reference: https://bugzilla.gnome.org/show_bug.cgi?id=765910

Description of the change

This is a direct port from gnome-control-center 3.26. Connection editor & wireless security codes are basically the same. Simply use directory comparison with meld for easier comparison or review.

I would have cherry picked more commits for connection-editor & wifi-security from 3.28/3.30, but in 3.28 they broke away wifi panel and the code is tied with that. But 3.26 is stable and Linux Mint Cinnamon is also using the same.

PPA: ppa:unity7maintainers/unity7-desktop

Community-Thread: https://community.ubuntu.com/t/testing-of-new-wetwork-panel-in-unity-libnm-port-1-2-eoan/10792

Other details:
---------------------

1) Gnome started using g-s-d for switching on/off Airplane mode. We will follow that. Hence rfkill related code was removed from cc-network-panel.c. See https://bugzilla.gnome.org/show_bug.cgi?id=703411 and https://github.com/GNOME/gnome-control-center/commit/085e7695133ae482cfbba78ab151a90a3960052d

2) In g-c-c new VPN connections are created within the control center from 8a52138cf6e31d1030ea2829acb6ec96892a8d8c and other types
currently hit the nm-connection-editor fallback. We are doing the same here. For vpn & otype of conection it will simply fall back using nm-connection-editor See https://bugzilla.gnome.org/show_bug.cgi?id=674498 and https://github.com/GNOME/gnome-control-center/commit/8a52138cf6e31d1030ea2829acb6ec96892a8d8c

3) This also includes support for the 'ModemManager1' interface. See https://github.com/GNOME/gnome-control-center/commit/0225d1a9e73cf741f627d595925abb7e886164be

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks for the work, I don't think it makes sense to review the code there since it's a lot of change and basically a backport from upstream code already used in GNOME, let's rather go through functional testing. Landing the change (especially early in the cycle) is +1 from me, let me know when you are happy uploading

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configure.ac'
--- configure.ac 2018-11-20 08:48:24 +0000
+++ configure.ac 2019-05-01 13:56:52 +0000
@@ -113,7 +113,9 @@
113CANBERRA_REQUIRED_VERSION=0.13113CANBERRA_REQUIRED_VERSION=0.13
114GDKPIXBUF_REQUIRED_VERSION=2.23.0114GDKPIXBUF_REQUIRED_VERSION=2.23.0
115POLKIT_REQUIRED_VERSION=0.103115POLKIT_REQUIRED_VERSION=0.103
116NETWORK_MANAGER_REQUIRED_VERSION=0.8.992116NETWORK_MANAGER_REQUIRED_VERSION=1.2.0
117NETWORK_MANAGER_APPLET_REQUIRED_VERSION=1.2.0
118MODEM_MANAGER_REQUIRED_VERSION=0.7
117LIBNOTIFY_REQUIRED_VERSION=0.7.3119LIBNOTIFY_REQUIRED_VERSION=0.7.3
118GNOME_DESKTOP_REQUIRED_VERSION=3.27.3120GNOME_DESKTOP_REQUIRED_VERSION=3.27.3
119SCHEMAS_REQUIRED_VERSION=3.15.4121SCHEMAS_REQUIRED_VERSION=3.15.4
@@ -149,7 +151,8 @@
149PKG_CHECK_MODULES(MEDIA_PANEL, $COMMON_MODULES)151PKG_CHECK_MODULES(MEDIA_PANEL, $COMMON_MODULES)
150PKG_CHECK_MODULES(MOUSE_PANEL, $COMMON_MODULES xi >= 1.2152PKG_CHECK_MODULES(MOUSE_PANEL, $COMMON_MODULES xi >= 1.2
151 unity-settings-daemon x11)153 unity-settings-daemon x11)
152PKG_CHECK_MODULES(NETWORK_PANEL, $COMMON_MODULES)154PKG_CHECK_MODULES(NETWORK_PANEL, $COMMON_MODULES gmodule-2.0
155 polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION)
153PKG_CHECK_MODULES(POWER_PANEL, $COMMON_MODULES upower-glib >= 0.9.1156PKG_CHECK_MODULES(POWER_PANEL, $COMMON_MODULES upower-glib >= 0.9.1
154 unity-settings-daemon)157 unity-settings-daemon)
155PKG_CHECK_MODULES(COLOR_PANEL, $COMMON_MODULES colord >= 0.1.8)158PKG_CHECK_MODULES(COLOR_PANEL, $COMMON_MODULES colord >= 0.1.8)
@@ -182,14 +185,16 @@
182GDESKTOP_PREFIX=`$PKG_CONFIG --variable prefix gsettings-desktop-schemas`185GDESKTOP_PREFIX=`$PKG_CONFIG --variable prefix gsettings-desktop-schemas`
183AC_SUBST(GDESKTOP_PREFIX)186AC_SUBST(GDESKTOP_PREFIX)
184187
185# Check for NetworkManager ~0.9188# Check for NetworkManager ~1.2
186PKG_CHECK_MODULES(NETWORK_MANAGER, NetworkManager >= $NETWORK_MANAGER_REQUIRED_VERSION189PKG_CHECK_MODULES(NETWORK_MANAGER,
187 libnm-glib >= $NETWORK_MANAGER_REQUIRED_VERSION190 libnm >= $NETWORK_MANAGER_REQUIRED_VERSION
188 libnm-util >= $NETWORK_MANAGER_REQUIRED_VERSION191 libnma >= $NETWORK_MANAGER_APPLET_REQUIRED_VERSION
189 libnm-gtk >= $NETWORK_MANAGER_REQUIRED_VERSION,192 mm-glib >= $MODEM_MANAGER_REQUIRED_VERSION,
190 [have_networkmanager=yes], have_networkmanager=no)193 [have_networkmanager=yes], have_networkmanager=no)
191if test "x$have_networkmanager" = xno ; then194if test "x$have_networkmanager" = xno ; then
192 AC_MSG_WARN(*** Network panel will not be built (NetworkManager ~0.9 or newer not found) ***)195 AC_MSG_WARN(*** Network panel will not be built (NetworkManager ~1.2 or newer not found) ***)
196else
197 AC_DEFINE(BUILD_NETWORK, 1, [Define to 1 to build the Network panel])
193fi198fi
194AM_CONDITIONAL(BUILD_NETWORK, [test x$have_networkmanager = xyes])199AM_CONDITIONAL(BUILD_NETWORK, [test x$have_networkmanager = xyes])
195200
@@ -516,6 +521,8 @@
516panels/printers/Makefile521panels/printers/Makefile
517panels/printers/unity-printers-panel.desktop.in522panels/printers/unity-printers-panel.desktop.in
518panels/network/Makefile523panels/network/Makefile
524panels/network/wireless-security/Makefile
525panels/network/connection-editor/Makefile
519panels/network/unity-network-panel.desktop.in526panels/network/unity-network-panel.desktop.in
520panels/universal-access/Makefile527panels/universal-access/Makefile
521panels/universal-access/unity-universal-access-panel.desktop.in528panels/universal-access/unity-universal-access-panel.desktop.in
522529
=== modified file 'debian/control'
--- debian/control 2019-01-09 16:51:00 +0000
+++ debian/control 2019-05-01 13:56:52 +0000
@@ -35,9 +35,9 @@
35 libgtop2-dev,35 libgtop2-dev,
36 libibus-1.0-dev (>= 1.5.0),36 libibus-1.0-dev (>= 1.5.0),
37 libkrb5-dev,37 libkrb5-dev,
38 libnm-glib-dev (>= 0.9) [linux-any],38 libnm-dev (>= 1.2.0) [linux-any],
39 libnm-gtk-dev (>= 0.9) [linux-any],39 libnma-dev (>= 1.2.0) [linux-any],
40 libnm-util-dev (>= 0.9) [linux-any],40 libmm-glib-dev [linux-any],
41 libnotify-dev (>= 0.7.3),41 libnotify-dev (>= 0.7.3),
42 libpolkit-gobject-1-dev (>= 0.103),42 libpolkit-gobject-1-dev (>= 0.103),
43 libpulse-dev (>= 1:2.0),43 libpulse-dev (>= 1:2.0),
4444
=== modified file 'panels/network/Makefile.am'
--- panels/network/Makefile.am 2017-04-06 13:23:05 +0000
+++ panels/network/Makefile.am 2019-05-01 13:56:52 +0000
@@ -1,19 +1,26 @@
1cappletname = network1cappletname = network
22
3INCLUDES = \3SUBDIRS = wireless-security connection-editor
4
5AM_CPPFLAGS = \
4 $(PANEL_CFLAGS) \6 $(PANEL_CFLAGS) \
5 $(NETWORK_PANEL_CFLAGS) \7 $(NETWORK_PANEL_CFLAGS) \
6 $(NETWORK_MANAGER_CFLAGS) \8 $(NETWORK_MANAGER_CFLAGS) \
7 -DGNOMECC_UI_DIR="\"$(uidir)\"" \9 -DGNOMECC_UI_DIR="\"$(uidir)\"" \
8 -DGNOMELOCALEDIR="\"$(datadir)/locale\"" \10 -DGNOMELOCALEDIR="\"$(datadir)/locale\"" \
9 -DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \11 -DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \
12 -I$(srcdir)/wireless-security \
10 $(NULL)13 $(NULL)
1114
12ccpanelsdir = $(PANELS_DIR)15ccpanelsdir = $(PANELS_DIR)
13ccpanels_LTLIBRARIES = libnetwork.la16ccpanels_LTLIBRARIES = libnetwork.la
1417
18BUILT_SOURCES = \
19 cc-network-resources.c \
20 cc-network-resources.h
21
15libnetwork_la_SOURCES = \22libnetwork_la_SOURCES = \
16 network-module.c \23 $(BUILT_SOURCES) \
17 panel-common.c \24 panel-common.c \
18 panel-common.h \25 panel-common.h \
19 net-object.c \26 net-object.c \
@@ -22,45 +29,31 @@
22 net-device.h \29 net-device.h \
23 net-device-wifi.c \30 net-device-wifi.c \
24 net-device-wifi.h \31 net-device-wifi.h \
25 net-device-wired.c \32 net-device-simple.c \
26 net-device-wired.h \33 net-device-simple.h \
34 net-device-ethernet.c \
35 net-device-ethernet.h \
27 net-device-mobile.c \36 net-device-mobile.c \
28 net-device-mobile.h \37 net-device-mobile.h \
29 net-vpn.c \38 net-vpn.c \
30 net-vpn.h \39 net-vpn.h \
31 net-proxy.c \40 net-proxy.c \
32 net-proxy.h \41 net-proxy.h \
33 panel-cell-renderer-mode.c \
34 panel-cell-renderer-mode.h \
35 panel-cell-renderer-security.c \
36 panel-cell-renderer-security.h \
37 panel-cell-renderer-signal.c \
38 panel-cell-renderer-signal.h \
39 panel-cell-renderer-separator.c \
40 panel-cell-renderer-separator.h \
41 panel-cell-renderer-text.c \
42 panel-cell-renderer-text.h \
43 panel-cell-renderer-pixbuf.c \
44 panel-cell-renderer-pixbuf.h \
45 network-dialogs.c \42 network-dialogs.c \
46 network-dialogs.h \43 network-dialogs.h \
44 network-module.c \
47 cc-network-panel.c \45 cc-network-panel.c \
48 cc-network-panel.h \46 cc-network-panel.h
49 rfkill-glib.c \47
50 rfkill-glib.h \48libnetwork_la_LIBADD = $(PANEL_LIBS) $(NETWORK_PANEL_LIBS) $(NETWORK_MANAGER_LIBS) $(builddir)/connection-editor/libconnection-editor.la
51 rfkill.h49
52
53libnetwork_la_LIBADD = $(PANEL_LIBS) $(NETWORK_PANEL_LIBS) $(NETWORK_MANAGER_LIBS)
54libnetwork_la_LDFLAGS = $(PANEL_LDFLAGS)50libnetwork_la_LDFLAGS = $(PANEL_LDFLAGS)
5551
56uidir = $(pkgdatadir)/ui52resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/network.gresource.xml)
57dist_ui_DATA = \53cc-network-resources.c: network.gresource.xml $(resource_files)
58 network-proxy.ui \54 $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name cc_network $<
59 network-vpn.ui \55cc-network-resources.h: network.gresource.xml $(resource_files)
60 network-wifi.ui \56 $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-header --c-name cc_network $<
61 network-wired.ui \
62 network-mobile.ui \
63 network.ui
6457
65@INTLTOOL_DESKTOP_RULE@58@INTLTOOL_DESKTOP_RULE@
6659
@@ -68,6 +61,7 @@
68desktop_in_files = unity-network-panel.desktop.in61desktop_in_files = unity-network-panel.desktop.in
69desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)62desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
7063
71CLEANFILES = $(desktop_in_files) $(desktop_DATA)64CLEANFILES = $(desktop_in_files) $(desktop_DATA) $(BUILT_SOURCES)
65EXTRA_DIST = $(resource_files) network.gresource.xml
7266
73-include $(top_srcdir)/git.mk67-include $(top_srcdir)/git.mk
7468
=== modified file 'panels/network/cc-network-panel.c'
--- panels/network/cc-network-panel.c 2016-03-09 21:55:46 +0000
+++ panels/network/cc-network-panel.c 2019-05-01 13:56:52 +0000
@@ -2,6 +2,7 @@
2 *2 *
3 * Copyright (C) 2010-2012 Richard Hughes <richard@hughsie.com>3 * Copyright (C) 2010-2012 Richard Hughes <richard@hughsie.com>
4 * Copyright (C) 2012 Thomas Bechtold <thomasbechtold@jpberlin.de>4 * Copyright (C) 2012 Thomas Bechtold <thomasbechtold@jpberlin.de>
5 * Copyright (C) 2013 Aleksander Morgado <aleksander@gnu.org>
5 *6 *
6 * This program is free software; you can redistribute it and/or modify7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by8 * it under the terms of the GNU General Public License as published by
@@ -14,8 +15,7 @@
14 * GNU General Public License for more details.15 * GNU General Public License for more details.
15 *16 *
16 * You should have received a copy of the GNU General Public License17 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *19 *
20 */20 */
2121
@@ -24,25 +24,24 @@
24#include <stdlib.h>24#include <stdlib.h>
2525
26#include "cc-network-panel.h"26#include "cc-network-panel.h"
27#include "cc-network-resources.h"
2728
28#include "nm-remote-settings.h"29#include <NetworkManager.h>
29#include "nm-client.h"
30#include "nm-device.h"
31#include "nm-device-modem.h"
3230
33#include "net-device.h"31#include "net-device.h"
34#include "net-device-mobile.h"32#include "net-device-mobile.h"
35#include "net-device-wifi.h"33#include "net-device-wifi.h"
36#include "net-device-wired.h"34#include "net-device-ethernet.h"
37#include "net-object.h"35#include "net-object.h"
38#include "net-proxy.h"36#include "net-proxy.h"
39#include "net-vpn.h"37#include "net-vpn.h"
4038
41#include "rfkill-glib.h"
42
43#include "panel-common.h"39#include "panel-common.h"
4440
45#include "network-dialogs.h"41#include "network-dialogs.h"
42#include "connection-editor/net-connection-editor.h"
43
44#include <libmm-glib.h>
4645
47CC_PANEL_REGISTER (CcNetworkPanel, cc_network_panel)46CC_PANEL_REGISTER (CcNetworkPanel, cc_network_panel)
4847
@@ -64,17 +63,13 @@
64 GtkBuilder *builder;63 GtkBuilder *builder;
65 GtkWidget *treeview;64 GtkWidget *treeview;
66 NMClient *client;65 NMClient *client;
67 NMRemoteSettings *remote_settings;66 MMManager *modem_manager;
68 gboolean updating_device;67 gboolean updating_device;
69 guint add_header_widgets_idle;
70 guint nm_warning_idle;
71 guint refresh_idle;
7268
73 /* Killswitch stuff */69 /* Killswitch stuff */
70 GDBusProxy *rfkill_proxy;
74 GtkWidget *kill_switch_header;71 GtkWidget *kill_switch_header;
75 CcRfkillGlib *rfkill;
76 GtkSwitch *rfkill_switch;72 GtkSwitch *rfkill_switch;
77 GHashTable *killswitches;
7873
79 /* wireless dialog stuff */74 /* wireless dialog stuff */
80 CmdlineOperation arg_operation;75 CmdlineOperation arg_operation;
@@ -85,8 +80,6 @@
8580
86enum {81enum {
87 PANEL_DEVICES_COLUMN_ICON,82 PANEL_DEVICES_COLUMN_ICON,
88 PANEL_DEVICES_COLUMN_TITLE,
89 PANEL_DEVICES_COLUMN_SORT,
90 PANEL_DEVICES_COLUMN_OBJECT,83 PANEL_DEVICES_COLUMN_OBJECT,
91 PANEL_DEVICES_COLUMN_LAST84 PANEL_DEVICES_COLUMN_LAST
92};85};
@@ -96,7 +89,7 @@
96 PROP_ARGV89 PROP_ARGV
97};90};
9891
99static NetObject *find_in_model_by_id (CcNetworkPanel *panel, const gchar *id);92static NetObject *find_in_model_by_id (CcNetworkPanel *panel, const gchar *id, GtkTreeIter *iter_out);
100static void handle_argv (CcNetworkPanel *panel);93static void handle_argv (CcNetworkPanel *panel);
10194
102static void95static void
@@ -205,27 +198,13 @@
205 g_cancellable_cancel (priv->cancellable);198 g_cancellable_cancel (priv->cancellable);
206199
207 g_clear_object (&priv->cancellable);200 g_clear_object (&priv->cancellable);
201 g_clear_object (&priv->rfkill_proxy);
208 g_clear_object (&priv->builder);202 g_clear_object (&priv->builder);
209 g_clear_object (&priv->client);203 g_clear_object (&priv->client);
210 g_clear_object (&priv->remote_settings);204 g_clear_object (&priv->modem_manager);
211 g_clear_object (&priv->kill_switch_header);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 priv->rfkill_switch = NULL;206 priv->rfkill_switch = NULL;
215207
216 if (priv->refresh_idle != 0) {
217 g_source_remove (priv->refresh_idle);
218 priv->refresh_idle = 0;
219 }
220 if (priv->nm_warning_idle != 0) {
221 g_source_remove (priv->nm_warning_idle);
222 priv->nm_warning_idle = 0;
223 }
224 if (priv->add_header_widgets_idle != 0) {
225 g_source_remove (priv->add_header_widgets_idle);
226 priv->add_header_widgets_idle = 0;
227 }
228
229 G_OBJECT_CLASS (cc_network_panel_parent_class)->dispose (object);208 G_OBJECT_CLASS (cc_network_panel_parent_class)->dispose (object);
230}209}
231210
@@ -242,7 +221,132 @@
242static const char *221static const char *
243cc_network_panel_get_help_uri (CcPanel *panel)222cc_network_panel_get_help_uri (CcPanel *panel)
244{223{
245 return "help:ubuntu-help/net";224 return "help:gnome-help/net";
225}
226
227static void
228cc_network_panel_notify_enable_active_cb (GtkSwitch *sw,
229 GParamSpec *pspec,
230 CcNetworkPanel *panel)
231{
232 CcNetworkPanelPrivate *priv = panel->priv;
233 gboolean enable;
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,
241 -1,
242 priv->cancellable,
243 NULL, NULL);
244}
245
246static void
247sync_airplane_mode_switch (CcNetworkPanel *panel)
248{
249 GVariant *result;
250 gboolean enabled, should_show;
251 gboolean hw_enabled;
252
253 result = g_dbus_proxy_get_cached_property (panel->priv->rfkill_proxy, "HasAirplaneMode");
254 enabled = g_variant_get_boolean (result);
255
256 result = g_dbus_proxy_get_cached_property (panel->priv->rfkill_proxy, "ShouldShowAirplaneMode");
257 should_show = g_variant_get_boolean (result);
258
259 gtk_widget_set_visible (GTK_WIDGET (panel->priv->kill_switch_header), enabled && should_show);
260 if (!enabled || !should_show)
261 return;
262
263 result = g_dbus_proxy_get_cached_property (panel->priv->rfkill_proxy, "AirplaneMode");
264 enabled = g_variant_get_boolean (result);
265
266 result = g_dbus_proxy_get_cached_property (panel->priv->rfkill_proxy, "HardwareAirplaneMode");
267 hw_enabled = !!g_variant_get_boolean (result);
268
269 enabled |= hw_enabled;
270
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,
274 panel);
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,
278 panel);
279 }
280
281 gtk_widget_set_sensitive (GTK_WIDGET (panel->priv->rfkill_switch), !hw_enabled);
282}
283
284static void
285on_property_change (GDBusProxy *proxy,
286 GVariant *changed_properties,
287 GVariant *invalidated_properties,
288 gpointer user_data)
289{
290 sync_airplane_mode_switch (CC_NETWORK_PANEL (user_data));
291}
292
293static void
294got_rfkill_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
295{
296 GError *error = NULL;
297 CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);
298
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);
303 return;
304 }
305
306 g_signal_connect (panel->priv->rfkill_proxy, "g-properties-changed",
307 G_CALLBACK (on_property_change), panel);
308 sync_airplane_mode_switch (panel);
309}
310
311static void
312cc_network_panel_constructed (GObject *object)
313{
314 CcNetworkPanel *panel = CC_NETWORK_PANEL (object);
315 GtkWidget *box;
316 GtkWidget *label;
317 GtkWidget *widget;
318
319 G_OBJECT_CLASS (cc_network_panel_parent_class)->constructed (object);
320
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
324 * network panel */
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);
336
337 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
338 G_DBUS_PROXY_FLAGS_NONE,
339 NULL,
340 "org.gnome.SettingsDaemon.Rfkill",
341 "/org/gnome/SettingsDaemon/Rfkill",
342 "org.gnome.SettingsDaemon.Rfkill",
343 panel->priv->cancellable,
344 got_rfkill_proxy_cb,
345 panel);
346
347 g_signal_connect (panel->priv->rfkill_switch, "notify::active",
348 G_CALLBACK (cc_network_panel_notify_enable_active_cb),
349 panel);
246}350}
247351
248static void352static void
@@ -259,6 +363,7 @@
259 object_class->set_property = cc_network_panel_set_property;363 object_class->set_property = cc_network_panel_set_property;
260 object_class->dispose = cc_network_panel_dispose;364 object_class->dispose = cc_network_panel_dispose;
261 object_class->finalize = cc_network_panel_finalize;365 object_class->finalize = cc_network_panel_finalize;
366 object_class->constructed = cc_network_panel_constructed;
262367
263 g_object_class_override_property (object_class, PROP_ARGV, "argv");368 g_object_class_override_property (object_class, PROP_ARGV, "argv");
264}369}
@@ -333,16 +438,140 @@
333 if (g_strcmp0 (net_object_get_id (object),438 if (g_strcmp0 (net_object_get_id (object),
334 net_object_get_id (object_tmp)) == 0) {439 net_object_get_id (object_tmp)) == 0) {
335 g_object_unref (object_tmp);440 g_object_unref (object_tmp);
336 if (!gtk_list_store_remove (GTK_LIST_STORE (model), &iter))441 if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter)) {
337 gtk_tree_model_get_iter_first (model, &iter);442 if (gtk_tree_model_get_iter_first (model, &iter))
338 gtk_tree_selection_select_iter (selection, &iter);443 gtk_tree_selection_select_iter (selection, &iter);
339444 }
340 break;445 break;
341 }446 }
342 g_object_unref (object_tmp);447 g_object_unref (object_tmp);
343 } while (gtk_tree_model_iter_next (model, &iter));448 } while (gtk_tree_model_iter_next (model, &iter));
344}449}
345450
451GPtrArray *
452cc_network_panel_get_devices (CcNetworkPanel *panel)
453{
454 GPtrArray *devices;
455 GtkTreeModel *model;
456 GtkTreeIter iter;
457 NetObject *object;
458
459 devices = g_ptr_array_new_with_free_func (g_object_unref);
460
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))
464 return devices;
465
466 do {
467 gtk_tree_model_get (model, &iter,
468 PANEL_DEVICES_COLUMN_OBJECT, &object,
469 -1);
470 if (NET_IS_DEVICE (object))
471 g_ptr_array_add (devices, object);
472 else
473 g_object_unref (object);
474 } while (gtk_tree_model_iter_next (model, &iter));
475
476 return devices;
477}
478
479static gint
480panel_net_object_get_sort_category (NetObject *net_object)
481{
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)) {
485 return 9;
486 } else if (NET_IS_VPN (net_object)) {
487 return 5;
488 }
489
490 g_assert_not_reached ();
491}
492
493static gint
494panel_net_object_sort_func (GtkTreeModel *model, GtkTreeIter *a,
495 GtkTreeIter *b, void *data)
496{
497 g_autoptr(NetObject) obj_a = NULL;
498 g_autoptr(NetObject) obj_b = NULL;
499 gint cat_a, cat_b;
500
501 gtk_tree_model_get (model, a,
502 PANEL_DEVICES_COLUMN_OBJECT, &obj_a,
503 -1);
504 gtk_tree_model_get (model, b,
505 PANEL_DEVICES_COLUMN_OBJECT, &obj_b,
506 -1);
507
508 cat_a = panel_net_object_get_sort_category (obj_a);
509 cat_b = panel_net_object_get_sort_category (obj_b);
510
511 if (cat_a != cat_b)
512 return cat_a - cat_b;
513
514 return g_utf8_collate (net_object_get_title (obj_a), net_object_get_title (obj_b));
515}
516
517static void
518panel_net_object_notify_title_cb (NetObject *net_object, GParamSpec *pspec, CcNetworkPanel *panel)
519{
520 GtkTreeIter iter;
521 GtkListStore *liststore;
522
523 if (!find_in_model_by_id (panel, net_object_get_id (net_object), &iter))
524 return;
525
526 liststore = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
527 "liststore_devices"));
528
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,
534 -1);
535}
536
537static void
538panel_refresh_device_titles (CcNetworkPanel *panel)
539{
540 GPtrArray *ndarray, *nmdarray;
541 NetDevice **devices;
542 NMDevice **nm_devices, *nm_device;
543 gchar **titles;
544 gint i, num_devices;
545
546 ndarray = cc_network_panel_get_devices (panel);
547 if (!ndarray->len) {
548 g_ptr_array_free (ndarray, TRUE);
549 return;
550 }
551
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]);
555 if (nm_device)
556 g_ptr_array_add (nmdarray, nm_device);
557 else
558 g_ptr_array_remove_index (ndarray, i--);
559 }
560
561 devices = (NetDevice **)ndarray->pdata;
562 nm_devices = (NMDevice **)nmdarray->pdata;
563 num_devices = ndarray->len;
564
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]);
568 g_free (titles[i]);
569 }
570 g_free (titles);
571 g_ptr_array_free (ndarray, TRUE);
572 g_ptr_array_free (nmdarray, TRUE);
573}
574
346static gboolean575static gboolean
347handle_argv_for_device (CcNetworkPanel *panel,576handle_argv_for_device (CcNetworkPanel *panel,
348 NMDevice *device,577 NMDevice *device,
@@ -350,6 +579,7 @@
350{579{
351 CcNetworkPanelPrivate *priv = panel->priv;580 CcNetworkPanelPrivate *priv = panel->priv;
352 NMDeviceType type;581 NMDeviceType type;
582 GtkWidget *toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (panel)));
353583
354 if (priv->arg_operation == OPERATION_NULL)584 if (priv->arg_operation == OPERATION_NULL)
355 return TRUE;585 return TRUE;
@@ -363,21 +593,21 @@
363 select_tree_iter (panel, iter);593 select_tree_iter (panel, iter);
364594
365 if (priv->arg_operation == OPERATION_CREATE_WIFI)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);
367 else597 else
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);
369599
370 reset_command_line_args (panel); /* done */600 reset_command_line_args (panel); /* done */
371 return TRUE;601 return TRUE;
372 } else if (g_strcmp0 (nm_object_get_path (NM_OBJECT (device)), priv->arg_device) == 0) {602 } else if (g_strcmp0 (nm_object_get_path (NM_OBJECT (device)), priv->arg_device) == 0) {
373 if (priv->arg_operation == OPERATION_CONNECT_MOBILE) {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);
375605
376 reset_command_line_args (panel); /* done */606 reset_command_line_args (panel); /* done */
377 select_tree_iter (panel, iter);607 select_tree_iter (panel, iter);
378 return TRUE;608 return TRUE;
379 } else if (priv->arg_operation == OPERATION_CONNECT_8021X) {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 reset_command_line_args (panel); /* done */611 reset_command_line_args (panel); /* done */
382 select_tree_iter (panel, iter);612 select_tree_iter (panel, iter);
383 return TRUE;613 return TRUE;
@@ -392,6 +622,28 @@
392 return FALSE;622 return FALSE;
393}623}
394624
625static gboolean
626handle_argv_for_connection (CcNetworkPanel *panel,
627 NMConnection *connection,
628 GtkTreeIter *iter)
629{
630 CcNetworkPanelPrivate *priv = panel->priv;
631
632 if (priv->arg_operation == OPERATION_NULL)
633 return TRUE;
634 if (priv->arg_operation != OPERATION_SHOW_DEVICE)
635 return FALSE;
636
637 if (g_strcmp0 (nm_connection_get_path (connection), priv->arg_device) == 0) {
638 reset_command_line_args (panel);
639 select_tree_iter (panel, iter);
640 return TRUE;
641 }
642
643 return FALSE;
644}
645
646
395static void647static void
396handle_argv (CcNetworkPanel *panel)648handle_argv (CcNetworkPanel *panel)
397{649{
@@ -408,15 +660,20 @@
408 while (ret) {660 while (ret) {
409 GObject *object_tmp;661 GObject *object_tmp;
410 NMDevice *device;662 NMDevice *device;
663 NMConnection *connection;
411 gboolean done = FALSE;664 gboolean done = FALSE;
412665
413 gtk_tree_model_get (model, &iter,666 gtk_tree_model_get (model, &iter,
414 PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,667 PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
415 -1);668 -1);
416 if (g_object_class_find_property (G_OBJECT_GET_CLASS (object_tmp), "nm-device") != NULL) {669 if (NET_IS_DEVICE (object_tmp)) {
417 g_object_get (object_tmp, "nm-device", &device, NULL);670 g_object_get (object_tmp, "nm-device", &device, NULL);
418 done = handle_argv_for_device (panel, device, &iter);671 done = handle_argv_for_device (panel, device, &iter);
419 g_object_unref (device);672 g_object_unref (device);
673 } else if (NET_IS_VPN (object_tmp)) {
674 g_object_get (object_tmp, "connection", &connection, NULL);
675 done = handle_argv_for_connection (panel, connection, &iter);
676 g_object_unref (connection);
420 }677 }
421678
422 g_object_unref (object_tmp);679 g_object_unref (object_tmp);
@@ -430,10 +687,31 @@
430 g_debug ("Could not handle argv operation, no matching device yet?");687 g_debug ("Could not handle argv operation, no matching device yet?");
431}688}
432689
690static void
691state_changed_cb (NMDevice *device,
692 NMDeviceState new_state,
693 NMDeviceState old_state,
694 NMDeviceStateReason reason,
695 CcNetworkPanel *panel)
696{
697 GtkListStore *store;
698 GtkTreeIter iter;
699
700 if (!find_in_model_by_id (panel, nm_device_get_udi (device), &iter)) {
701 return;
702 }
703
704 store = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
705 "liststore_devices"));
706
707 gtk_list_store_set (store, &iter,
708 PANEL_DEVICES_COLUMN_ICON, panel_device_to_icon_name (device, TRUE),
709 -1);
710}
711
433static gboolean712static gboolean
434panel_add_device (CcNetworkPanel *panel, NMDevice *device)713panel_add_device (CcNetworkPanel *panel, NMDevice *device)
435{714{
436 const gchar *title;
437 GtkListStore *liststore_devices;715 GtkListStore *liststore_devices;
438 GtkTreeIter iter;716 GtkTreeIter iter;
439 NMDeviceType type;717 NMDeviceType type;
@@ -442,20 +720,25 @@
442 GtkNotebook *notebook;720 GtkNotebook *notebook;
443 GtkSizeGroup *size_group;721 GtkSizeGroup *size_group;
444 GType device_g_type;722 GType device_g_type;
723 const char *udi;
724
725 if (!nm_device_get_managed (device))
726 goto out;
445727
446 /* do we have an existing object with this id? */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)
448 goto out;731 goto out;
449732
450 type = nm_device_get_device_type (device);733 type = nm_device_get_device_type (device);
451734
452 g_debug ("device %s type %i path %s",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)));
454737
455 /* map the NMDeviceType to the GType */738 /* map the NMDeviceType to the GType, or ignore */
456 switch (type) {739 switch (type) {
457 case NM_DEVICE_TYPE_ETHERNET:740 case NM_DEVICE_TYPE_ETHERNET:
458 device_g_type = NET_TYPE_DEVICE_WIRED;741 device_g_type = NET_TYPE_DEVICE_ETHERNET;
459 break;742 break;
460 case NM_DEVICE_TYPE_MODEM:743 case NM_DEVICE_TYPE_MODEM:
461 device_g_type = NET_TYPE_DEVICE_MOBILE;744 device_g_type = NET_TYPE_DEVICE_MOBILE;
@@ -463,23 +746,56 @@
463 case NM_DEVICE_TYPE_WIFI:746 case NM_DEVICE_TYPE_WIFI:
464 device_g_type = NET_TYPE_DEVICE_WIFI;747 device_g_type = NET_TYPE_DEVICE_WIFI;
465 break;748 break;
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:
758 goto out;
466 default:759 default:
467 goto out;760 device_g_type = NET_TYPE_DEVICE_SIMPLE;
761 break;
468 }762 }
469763
470 /* create device */764 /* create device */
471 title = panel_device_to_localized_string (device);
472 net_device = g_object_new (device_g_type,765 net_device = g_object_new (device_g_type,
473 "panel", panel,766 "panel", panel,
474 "removable", FALSE,767 "removable", FALSE,
475 "cancellable", panel->priv->cancellable,768 "cancellable", panel->priv->cancellable,
476 "client", panel->priv->client,769 "client", panel->priv->client,
477 "remote-settings", panel->priv->remote_settings,
478 "nm-device", device,770 "nm-device", device,
479 "id", nm_device_get_udi (device),771 "id", nm_device_get_udi (device),
480 "title", title,
481 NULL);772 NULL);
482773
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;
777
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));
781 goto out;
782 }
783
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));
789 goto out;
790 }
791
792 /* Set the modem object in the NetDeviceMobile */
793 g_object_set (net_device,
794 "mm-object", modem_object,
795 NULL);
796 g_object_unref (modem_object);
797 }
798
483 /* add as a panel */799 /* add as a panel */
484 if (device_g_type != NET_TYPE_DEVICE) {800 if (device_g_type != NET_TYPE_DEVICE) {
485 notebook = GTK_NOTEBOOK (gtk_builder_get_object (panel->priv->builder,801 notebook = GTK_NOTEBOOK (gtk_builder_get_object (panel->priv->builder,
@@ -498,11 +814,15 @@
498 gtk_list_store_append (liststore_devices, &iter);814 gtk_list_store_append (liststore_devices, &iter);
499 gtk_list_store_set (liststore_devices,815 gtk_list_store_set (liststore_devices,
500 &iter,816 &iter,
501 PANEL_DEVICES_COLUMN_ICON, panel_device_to_icon_name (device),817 PANEL_DEVICES_COLUMN_ICON, panel_device_to_icon_name (device, TRUE),
502 PANEL_DEVICES_COLUMN_SORT, panel_device_to_sortable_string (device),
503 PANEL_DEVICES_COLUMN_TITLE, title,
504 PANEL_DEVICES_COLUMN_OBJECT, net_device,818 PANEL_DEVICES_COLUMN_OBJECT, net_device,
505 -1);819 -1);
820 g_signal_connect (net_device, "notify::title",
821 G_CALLBACK (panel_net_object_notify_title_cb), panel);
822
823 g_object_unref (net_device);
824 g_signal_connect (device, "state-changed",
825 G_CALLBACK (state_changed_cb), panel);
506826
507out:827out:
508 return FALSE;828 return FALSE;
@@ -539,6 +859,25 @@
539}859}
540860
541static void861static void
862get_object_title (GtkTreeViewColumn *column,
863 GtkCellRenderer *cell,
864 GtkTreeModel *model,
865 GtkTreeIter *iter,
866 gpointer data)
867{
868 NetObject *object;
869
870 gtk_tree_model_get (model, iter,
871 PANEL_DEVICES_COLUMN_OBJECT, &object,
872 -1);
873 if (!object)
874 return;
875
876 g_object_set (cell, "text", net_object_get_title (object), NULL);
877 g_object_unref (object);
878}
879
880static void
542panel_add_devices_columns (CcNetworkPanel *panel, GtkTreeView *treeview)881panel_add_devices_columns (CcNetworkPanel *panel, GtkTreeView *treeview)
543{882{
544 CcNetworkPanelPrivate *priv = panel->priv;883 CcNetworkPanelPrivate *priv = panel->priv;
@@ -548,8 +887,13 @@
548887
549 /* image */888 /* image */
550 renderer = gtk_cell_renderer_pixbuf_new ();889 renderer = gtk_cell_renderer_pixbuf_new ();
551 g_object_set (renderer, "stock-size", gtk_icon_size_from_name ("cc-sidebar-list"), NULL);890 g_object_set (renderer,
552 gtk_cell_renderer_set_padding (renderer, 4, 4);891 "width", 32,
892 "xalign", 1.0,
893 "stock-size", GTK_ICON_SIZE_MENU,
894 "follow-state", TRUE,
895 NULL);
896 gtk_cell_renderer_set_padding (renderer, 4, 10);
553897
554 column = gtk_tree_view_column_new_with_attributes ("icon", renderer,898 column = gtk_tree_view_column_new_with_attributes ("icon", renderer,
555 "icon-name", PANEL_DEVICES_COLUMN_ICON,899 "icon-name", PANEL_DEVICES_COLUMN_ICON,
@@ -562,14 +906,19 @@
562 "wrap-mode", PANGO_WRAP_WORD,906 "wrap-mode", PANGO_WRAP_WORD,
563 "ellipsize", PANGO_ELLIPSIZE_END,907 "ellipsize", PANGO_ELLIPSIZE_END,
564 NULL);908 NULL);
565 column = gtk_tree_view_column_new_with_attributes ("title", renderer,909 column = gtk_tree_view_column_new_with_attributes ("title", renderer, NULL);
566 "markup", PANEL_DEVICES_COLUMN_TITLE,910 gtk_tree_view_column_set_cell_data_func (GTK_TREE_VIEW_COLUMN (column),
567 NULL);911 renderer,
568 gtk_tree_view_column_set_sort_column_id (column, PANEL_DEVICES_COLUMN_SORT);912 get_object_title,
913 NULL, NULL);
914 gtk_tree_view_column_set_sort_column_id (column, PANEL_DEVICES_COLUMN_OBJECT);
569 liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,915 liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
570 "liststore_devices"));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 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (liststore_devices),920 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (liststore_devices),
572 PANEL_DEVICES_COLUMN_SORT,921 PANEL_DEVICES_COLUMN_OBJECT,
573 GTK_SORT_ASCENDING);922 GTK_SORT_ASCENDING);
574 gtk_tree_view_append_column (treeview, column);923 gtk_tree_view_append_column (treeview, column);
575 gtk_tree_view_column_set_expand (column, TRUE);924 gtk_tree_view_column_set_expand (column, TRUE);
@@ -616,6 +965,7 @@
616 }965 }
617 i++;966 i++;
618 }967 }
968 g_object_unref (object);
619out:969out:
620 g_list_free (panels);970 g_list_free (panels);
621}971}
@@ -623,7 +973,6 @@
623static void973static void
624panel_add_proxy_device (CcNetworkPanel *panel)974panel_add_proxy_device (CcNetworkPanel *panel)
625{975{
626 gchar *title;
627 GtkListStore *liststore_devices;976 GtkListStore *liststore_devices;
628 GtkTreeIter iter;977 GtkTreeIter iter;
629 NetProxy *proxy;978 NetProxy *proxy;
@@ -643,39 +992,21 @@
643 /* add proxy to device list */992 /* add proxy to device list */
644 liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,993 liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
645 "liststore_devices"));994 "liststore_devices"));
646 title = g_strdup_printf ("%s", _("Network proxy"));995 net_object_set_title (NET_OBJECT (proxy), _("Network proxy"));
647 gtk_list_store_append (liststore_devices, &iter);996 gtk_list_store_append (liststore_devices, &iter);
648 gtk_list_store_set (liststore_devices,997 gtk_list_store_set (liststore_devices,
649 &iter,998 &iter,
650 PANEL_DEVICES_COLUMN_ICON, "preferences-system-network",999 PANEL_DEVICES_COLUMN_ICON, "preferences-system-network-symbolic",
651 PANEL_DEVICES_COLUMN_TITLE, title,
652 PANEL_DEVICES_COLUMN_SORT, "9",
653 PANEL_DEVICES_COLUMN_OBJECT, proxy,1000 PANEL_DEVICES_COLUMN_OBJECT, proxy,
654 -1);1001 -1);
655 g_free (title);1002
1003 /* NOTE: No connect to notify::title here as it is guaranteed to not
1004 * be changed by anyone.*/
1005
656 g_object_unref (proxy);1006 g_object_unref (proxy);
657}1007}
6581008
659static void1009static void
660cc_network_panel_notify_enable_active_cb (GtkSwitch *sw,
661 GParamSpec *pspec,
662 CcNetworkPanel *panel)
663{
664 gboolean enable;
665 struct rfkill_event event;
666
667 enable = gtk_switch_get_active (sw);
668 g_debug ("Setting killswitch to %d", enable);
669
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");
676}
677
678static void
679connection_state_changed (NMActiveConnection *c, GParamSpec *pspec, CcNetworkPanel *panel)1010connection_state_changed (NMActiveConnection *c, GParamSpec *pspec, CcNetworkPanel *panel)
680{1011{
681}1012}
@@ -699,7 +1030,7 @@
699 for (j = 0; devices && j < devices->len; j++)1030 for (j = 0; devices && j < devices->len; j++)
700 g_debug (" %s", nm_device_get_udi (g_ptr_array_index (devices, j)));1031 g_debug (" %s", nm_device_get_udi (g_ptr_array_index (devices, j)));
701 if (NM_IS_VPN_CONNECTION (connection))1032 if (NM_IS_VPN_CONNECTION (connection))
702 g_debug (" VPN base connection: %s", nm_active_connection_get_specific_object (connection));1033 g_debug (" VPN base connection: %s", nm_active_connection_get_specific_object_path (connection));
7031034
704 if (g_object_get_data (G_OBJECT (connection), "has-state-changed-handler") == NULL) {1035 if (g_object_get_data (G_OBJECT (connection), "has-state-changed-handler") == NULL) {
705 g_signal_connect_object (connection, "notify::state",1036 g_signal_connect_object (connection, "notify::state",
@@ -714,6 +1045,7 @@
714{1045{
715 g_debug ("New device added");1046 g_debug ("New device added");
716 panel_add_device (panel, device);1047 panel_add_device (panel, device);
1048 panel_refresh_device_titles (panel);
717}1049}
7181050
719static void1051static void
@@ -721,6 +1053,7 @@
721{1053{
722 g_debug ("Device removed");1054 g_debug ("Device removed");
723 panel_remove_device (panel, device);1055 panel_remove_device (panel, device);
1056 panel_refresh_device_titles (panel);
724}1057}
7251058
726static void1059static void
@@ -734,7 +1067,7 @@
734 CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);1067 CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);
7351068
736 /* clear all devices we added */1069 /* clear all devices we added */
737 if (!nm_client_get_manager_running (client)) {1070 if (!nm_client_get_nm_running (client)) {
738 g_debug ("NM disappeared");1071 g_debug ("NM disappeared");
739 liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,1072 liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
740 "liststore_devices"));1073 "liststore_devices"));
@@ -759,12 +1092,14 @@
759 select_first_device (panel);1092 select_first_device (panel);
760 }1093 }
7611094
1095 panel_refresh_device_titles (panel);
1096
762 g_debug ("Calling handle_argv() after cold-plugging devices");1097 g_debug ("Calling handle_argv() after cold-plugging devices");
763 handle_argv (panel);1098 handle_argv (panel);
764}1099}
7651100
766static NetObject *1101static NetObject *
767find_in_model_by_id (CcNetworkPanel *panel, const gchar *id)1102find_in_model_by_id (CcNetworkPanel *panel, const gchar *id, GtkTreeIter *iter_out)
768{1103{
769 gboolean ret;1104 gboolean ret;
770 NetObject *object_tmp;1105 NetObject *object_tmp;
@@ -793,6 +1128,8 @@
793 }1128 }
794 } while (object == NULL && gtk_tree_model_iter_next (model, &iter));1129 } while (object == NULL && gtk_tree_model_iter_next (model, &iter));
795out:1130out:
1131 if (iter_out)
1132 *iter_out = iter;
796 return object;1133 return object;
797}1134}
7981135
@@ -800,7 +1137,6 @@
800panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection)1137panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection)
801{1138{
802 gchar *title;1139 gchar *title;
803 gchar *title_markup;
804 GtkListStore *liststore_devices;1140 GtkListStore *liststore_devices;
805 GtkTreeIter iter;1141 GtkTreeIter iter;
806 NetVpn *net_vpn;1142 NetVpn *net_vpn;
@@ -810,10 +1146,10 @@
8101146
811 /* does already exist */1147 /* does already exist */
812 id = nm_connection_get_path (connection);1148 id = nm_connection_get_path (connection);
813 if (find_in_model_by_id (panel, id) != NULL)1149 if (find_in_model_by_id (panel, id, NULL) != NULL)
814 return;1150 return;
8151151
816 /* add as a virtual object */1152 /* add as a VPN object */
817 net_vpn = g_object_new (NET_TYPE_VPN,1153 net_vpn = g_object_new (NET_TYPE_VPN,
818 "panel", panel,1154 "panel", panel,
819 "removable", TRUE,1155 "removable", TRUE,
@@ -836,19 +1172,19 @@
836 liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,1172 liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
837 "liststore_devices"));1173 "liststore_devices"));
838 title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (connection));1174 title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (connection));
839 title_markup = g_strdup (title);
8401175
841 net_object_set_title (NET_OBJECT (net_vpn), title);1176 net_object_set_title (NET_OBJECT (net_vpn), title);
842 gtk_list_store_append (liststore_devices, &iter);1177 gtk_list_store_append (liststore_devices, &iter);
843 gtk_list_store_set (liststore_devices,1178 gtk_list_store_set (liststore_devices,
844 &iter,1179 &iter,
845 PANEL_DEVICES_COLUMN_ICON, "network-vpn",1180 PANEL_DEVICES_COLUMN_ICON, "network-vpn-symbolic",
846 PANEL_DEVICES_COLUMN_TITLE, title_markup,
847 PANEL_DEVICES_COLUMN_SORT, "5",
848 PANEL_DEVICES_COLUMN_OBJECT, net_vpn,1181 PANEL_DEVICES_COLUMN_OBJECT, net_vpn,
849 -1);1182 -1);
1183 g_signal_connect (net_vpn, "notify::title",
1184 G_CALLBACK (panel_net_object_notify_title_cb), panel);
1185
850 g_free (title);1186 g_free (title);
851 g_free (title_markup);1187 g_object_unref (net_vpn);
852}1188}
8531189
854static void1190static void
@@ -856,130 +1192,91 @@
856 NMConnection *connection)1192 NMConnection *connection)
857{1193{
858 NMSettingConnection *s_con;1194 NMSettingConnection *s_con;
859 const gchar *type;1195 const gchar *type, *iface;
8601196
861 s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection,1197 s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection,
862 NM_TYPE_SETTING_CONNECTION));1198 NM_TYPE_SETTING_CONNECTION));
863 type = nm_setting_connection_get_connection_type (s_con);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);
865 return;1201 if (g_strcmp0 (type, "vpn") != 0 && iface == NULL)
1202 return;
1203
1204 /* Don't add the libvirtd bridge to the UI */
1205 if (g_strcmp0 (nm_setting_connection_get_interface_name (s_con), "virbr0") == 0)
1206 return;
1207
866 g_debug ("add %s/%s remote connection: %s",1208 g_debug ("add %s/%s remote connection: %s",
867 type, g_type_name_from_instance ((GTypeInstance*)connection),1209 type, g_type_name_from_instance ((GTypeInstance*)connection),
868 nm_connection_get_path (connection));1210 nm_connection_get_path (connection));
869 panel_add_vpn_device (panel, connection);1211 if (!iface)
1212 panel_add_vpn_device (panel, connection);
870}1213}
8711214
872static void1215static void
873notify_new_connection_cb (NMRemoteSettings *settings,1216notify_connection_added_cb (NMClient *client,
874 NMRemoteConnection *connection,1217 NMRemoteConnection *connection,
875 CcNetworkPanel *panel)1218 CcNetworkPanel *panel)
876{1219{
877 add_connection (panel, NM_CONNECTION (connection));1220 add_connection (panel, NM_CONNECTION (connection));
878}1221}
8791222
880static void1223static void
881notify_connections_read_cb (NMRemoteSettings *settings,
882 CcNetworkPanel *panel)
883{
884 GSList *list, *iter;
885 NMConnection *connection;
886
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);
893 }
894}
895
896static gboolean
897display_version_warning_idle (CcNetworkPanel *panel)
898{
899 GtkWidget *dialog;
900 GtkWidget *image;
901 GtkWindow *window;
902 const char *message;
903
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.");
906
907 window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel)));
908 dialog = gtk_message_dialog_new (window,
909 GTK_DIALOG_MODAL,
910 GTK_MESSAGE_ERROR,
911 GTK_BUTTONS_CLOSE,
912 "%s",
913 message);
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);
917
918 gtk_dialog_run (GTK_DIALOG (dialog));
919 gtk_widget_destroy (dialog);
920
921 return FALSE;
922}
923
924static gboolean
925panel_check_network_manager_version (CcNetworkPanel *panel)1224panel_check_network_manager_version (CcNetworkPanel *panel)
926{1225{
1226 GtkWidget *box;
1227 GtkWidget *label;
1228 gchar *markup;
927 const gchar *version;1229 const gchar *version;
928 guint minor = 0;
929 gboolean ret = TRUE;
9301230
931 /* parse running version */1231 /* parse running version */
932 version = nm_client_get_version (panel->priv->client);1232 version = nm_client_get_version (panel->priv->client);
933 if (version == NULL) {1233 if (version == NULL) {
934 ret = FALSE;1234 gtk_container_remove (GTK_CONTAINER (panel), gtk_bin_get_child (GTK_BIN (panel)));
9351235
936 /* do modal dialog in idle so we don't block startup */1236 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 20);
937 panel->priv->nm_warning_idle = g_idle_add ((GSourceFunc)display_version_warning_idle, panel);1237 gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
1238 gtk_widget_set_vexpand (box, TRUE);
1239 gtk_container_add (GTK_CONTAINER (panel), box);
1240
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);
1245
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);
1253
1254 gtk_widget_show_all (box);
1255 g_free (markup);
1256 } else {
1257 manager_running (panel->priv->client, NULL, panel);
938 }1258 }
1259}
9391260
940 return ret;1261static void
1262editor_done (NetConnectionEditor *editor,
1263 gboolean success,
1264 gpointer user_data)
1265{
1266 g_object_unref (editor);
941}1267}
9421268
943static void1269static void
944add_connection_cb (GtkToolButton *button, CcNetworkPanel *panel)1270add_connection_cb (GtkToolButton *button, CcNetworkPanel *panel)
945{1271{
946 GtkWidget *dialog;1272 NetConnectionEditor *editor;
947 gint response;1273 GtkWindow *toplevel;
9481274
949 dialog = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,1275 toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel)));
950 "connection_type_dialog"));1276 editor = net_connection_editor_new (toplevel, NULL, NULL, NULL,
951 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel))));1277 panel->priv->client);
9521278 g_signal_connect (editor, "done", G_CALLBACK (editor_done), panel);
953 response = gtk_dialog_run (GTK_DIALOG (dialog));1279 net_connection_editor_run (editor);
954
955 gtk_widget_hide (dialog);
956
957 if (response == GTK_RESPONSE_OK) {
958 GtkComboBox *combo;
959 GtkTreeModel *model;
960 GtkTreeIter iter;
961 gchar *type;
962 gchar *cmdline;
963 GError *error;
964
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);
969 type = NULL;
970 gtk_tree_model_get (model, &iter, 1, &type, -1);
971
972 cmdline = g_strdup_printf ("nm-connection-editor --create --type %s", type);
973 g_debug ("Launching '%s'\n", cmdline);
974
975 error = NULL;
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);
979 }
980 g_free (cmdline);
981 g_free (type);
982 }
983}1280}
9841281
985static void1282static void
@@ -994,131 +1291,38 @@
9941291
995 /* delete the object */1292 /* delete the object */
996 net_object_delete (object);1293 net_object_delete (object);
1294 g_object_unref (object);
997}1295}
9981296
999static void1297static void
1000on_toplevel_map (GtkWidget *widget,1298on_toplevel_map (GtkWidget *widget,
1001 CcNetworkPanel *panel)1299 CcNetworkPanel *panel)
1002{1300{
1003 gboolean ret;
1004
1005 /* is the user compiling against a new version, but not running1301 /* is the user compiling against a new version, but not running
1006 * the daemon? */1302 * the daemon? */
1007 ret = panel_check_network_manager_version (panel);1303 panel_check_network_manager_version (panel);
1008 if (ret) {
1009 manager_running (panel->priv->client, NULL, panel);
1010 } else {
1011 /* just select the proxy settings */
1012 select_first_device (panel);
1013 }
1014}
1015
1016static void
1017rfkill_changed (CcRfkillGlib *rfkill,
1018 GList *events,
1019 CcNetworkPanel *panel)
1020{
1021 gboolean enabled;
1022 GList *l;
1023 GHashTableIter iter;
1024 gpointer key, value;
1025
1026 enabled = TRUE;
1027
1028 for (l = events; l != NULL; l = l->next) {
1029 struct rfkill_event *event = l->data;
1030
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));
1042 }
1043
1044 g_hash_table_iter_init (&iter, panel->priv->killswitches);
1045 while (g_hash_table_iter_next (&iter, &key, &value)) {
1046 int idx, state;
1047
1048 idx = GPOINTER_TO_INT (key);
1049 state = GPOINTER_TO_INT (value);
1050 g_debug ("Killswitch %d is %s", idx, state ? "enabled" : "disabled");
1051
1052 /* A single device that's enabled? airplane mode is off */
1053 if (state == FALSE) {
1054 enabled = FALSE;
1055 break;
1056 }
1057 }
1058
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,
1062 panel);
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,
1066 panel);
1067 }
1068}
1069
1070static gboolean
1071network_add_shell_header_widgets_cb (gpointer user_data)
1072{
1073 CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data);
1074 GtkWidget *box;
1075 GtkWidget *label;
1076 GtkWidget *widget;
1077
1078 box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
1079 /* TRANSLATORS: this is to disable the radio hardware in the
1080 * network panel */
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);
1091
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);
1098
1099 g_signal_connect (panel->priv->rfkill_switch, "notify::active",
1100 G_CALLBACK (cc_network_panel_notify_enable_active_cb),
1101 panel);
1102
1103 return FALSE;
1104}1304}
11051305
1106static void1306static void
1107cc_network_panel_init (CcNetworkPanel *panel)1307cc_network_panel_init (CcNetworkPanel *panel)
1108{1308{
1109 DBusGConnection *bus = NULL;
1110 GError *error = NULL;1309 GError *error = NULL;
1111 GtkStyleContext *context;1310 GtkStyleContext *context;
1112 GtkTreeSelection *selection;1311 GtkTreeSelection *selection;
1113 GtkWidget *widget;1312 GtkWidget *widget;
1114 GtkWidget *toplevel;1313 GtkWidget *toplevel;
1314 GDBusConnection *system_bus;
1315 GtkCssProvider *provider;
1316 const GPtrArray *connections;
1317 guint i;
11151318
1116 panel->priv = NETWORK_PANEL_PRIVATE (panel);1319 panel->priv = NETWORK_PANEL_PRIVATE (panel);
1320 g_resources_register (cc_network_get_resource ());
11171321
1118 panel->priv->builder = gtk_builder_new ();1322 panel->priv->builder = gtk_builder_new ();
1119 gtk_builder_add_from_file (panel->priv->builder,1323 gtk_builder_add_from_resource (panel->priv->builder,
1120 GNOMECC_UI_DIR "/network.ui",1324 "/org/gnome/control-center/network/network.ui",
1121 &error);1325 &error);
1122 if (error != NULL) {1326 if (error != NULL) {
1123 g_warning ("Could not load interface file: %s", error->message);1327 g_warning ("Could not load interface file: %s", error->message);
1124 g_error_free (error);1328 g_error_free (error);
@@ -1150,16 +1354,35 @@
1150 panel_add_proxy_device (panel);1354 panel_add_proxy_device (panel);
11511355
1152 /* use NetworkManager client */1356 /* use NetworkManager client */
1153 panel->priv->client = nm_client_new ();1357 panel->priv->client = nm_client_new (NULL, NULL);
1154 g_signal_connect (panel->priv->client, "notify::" NM_CLIENT_MANAGER_RUNNING,1358 g_signal_connect (panel->priv->client, "notify::nm-running" ,
1155 G_CALLBACK (manager_running), panel);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 G_CALLBACK (active_connections_changed), panel);1361 G_CALLBACK (active_connections_changed), panel);
1158 g_signal_connect (panel->priv->client, "device-added",1362 g_signal_connect (panel->priv->client, "device-added",
1159 G_CALLBACK (device_added_cb), panel);1363 G_CALLBACK (device_added_cb), panel);
1160 g_signal_connect (panel->priv->client, "device-removed",1364 g_signal_connect (panel->priv->client, "device-removed",
1161 G_CALLBACK (device_removed_cb), panel);1365 G_CALLBACK (device_removed_cb), panel);
11621366
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",
1371 error->message);
1372 g_clear_error (&error);
1373 } else {
1374 panel->priv->modem_manager = mm_manager_new_sync (system_bus,
1375 G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
1376 NULL,
1377 &error);
1378 if (panel->priv->modem_manager == NULL) {
1379 g_warning ("Error connecting to ModemManager: %s",
1380 error->message);
1381 g_clear_error (&error);
1382 }
1383 g_object_unref (system_bus);
1384 }
1385
1163 widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,1386 widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1164 "add_toolbutton"));1387 "add_toolbutton"));
1165 g_signal_connect (widget, "clicked",1388 g_signal_connect (widget, "clicked",
@@ -1172,17 +1395,8 @@
1172 G_CALLBACK (remove_connection), panel);1395 G_CALLBACK (remove_connection), panel);
11731396
1174 /* add remote settings such as VPN settings as virtual devices */1397 /* add remote settings such as VPN settings as virtual devices */
1175 bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);1398 g_signal_connect (panel->priv->client, NM_CLIENT_CONNECTION_ADDED,
1176 if (bus == NULL) {1399 G_CALLBACK (notify_connection_added_cb), panel);
1177 g_warning ("Error connecting to system D-Bus: %s",
1178 error->message);
1179 g_error_free (error);
1180 }
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);
11861400
1187 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (panel));1401 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (panel));
1188 g_signal_connect_after (toplevel, "map", G_CALLBACK (on_toplevel_map), panel);1402 g_signal_connect_after (toplevel, "map", G_CALLBACK (on_toplevel_map), panel);
@@ -1194,10 +1408,22 @@
11941408
1195 widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,1409 widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
1196 "vbox1"));1410 "vbox1"));
1197 gtk_widget_reparent (widget, (GtkWidget *) panel);1411 gtk_container_add (GTK_CONTAINER (panel), widget);
11981412
1199 /* add kill switch widgets when dialog activated */1413 provider = gtk_css_provider_new ();
1200 panel->priv->add_header_widgets_idle = g_idle_add (network_add_shell_header_widgets_cb, panel);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);
1419
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]);
1424
1425 g_debug ("Calling handle_argv() after cold-plugging connections");
1426 handle_argv (panel);
1201}1427}
12021428
1203void1429void
12041430
=== modified file 'panels/network/cc-network-panel.h'
--- panels/network/cc-network-panel.h 2011-11-07 18:03:14 +0000
+++ panels/network/cc-network-panel.h 2019-05-01 13:56:52 +0000
@@ -65,7 +65,9 @@
6565
66GType cc_network_panel_get_type (void) G_GNUC_CONST;66GType cc_network_panel_get_type (void) G_GNUC_CONST;
6767
68void cc_network_panel_register (GIOModule *module);68void cc_network_panel_register (GIOModule *module);
69
70GPtrArray *cc_network_panel_get_devices (CcNetworkPanel *panel);
6971
70G_END_DECLS72G_END_DECLS
7173
7274
=== added directory 'panels/network/connection-editor'
=== added file 'panels/network/connection-editor/8021x-security-page.ui'
--- panels/network/connection-editor/8021x-security-page.ui 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/8021x-security-page.ui 2019-05-01 13:56:52 +0000
@@ -0,0 +1,295 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<interface>
3 <!-- interface-requires gtk+ 3.0 -->
4 <object class="GtkNotebook" id="page">
5 <property name="visible">True</property>
6 <property name="can_focus">True</property>
7 <property name="show_tabs">False</property>
8 <property name="show_border">False</property>
9 <child>
10 <object class="GtkGrid" id="grid">
11 <property name="visible">True</property>
12 <property name="can_focus">False</property>
13 <property name="margin_start">50</property>
14 <property name="margin_end">50</property>
15 <property name="margin_top">12</property>
16 <property name="margin_bottom">12</property>
17 <property name="hexpand">True</property>
18 <property name="vexpand">True</property>
19 <property name="row_spacing">10</property>
20 <property name="column_spacing">6</property>
21 <child>
22 <object class="GtkLabel" id="heading_sec">
23 <property name="visible">True</property>
24 <property name="can_focus">False</property>
25 <property name="xalign">1</property>
26 <property name="label" translatable="yes">802.1x _Security</property>
27 <property name="use_underline">True</property>
28 <property name="mnemonic_widget">8021x_switch</property>
29 </object>
30 <packing>
31 <property name="left_attach">0</property>
32 <property name="top_attach">0</property>
33 <property name="width">1</property>
34 <property name="height">1</property>
35 </packing>
36 </child>
37 <child>
38 <object class="GtkSwitch" id="8021x_switch">
39 <property name="visible">True</property>
40 <property name="can_focus">True</property>
41 <property name="halign">start</property>
42 <property name="hexpand">True</property>
43 </object>
44 <packing>
45 <property name="left_attach">1</property>
46 <property name="top_attach">0</property>
47 <property name="width">1</property>
48 <property name="height">1</property>
49 </packing>
50 </child>
51 <child>
52 <object class="GtkBox" id="vbox">
53 <property name="visible">True</property>
54 <property name="can_focus">False</property>
55 <property name="orientation">vertical</property>
56 <child>
57 <placeholder/>
58 </child>
59 </object>
60 <packing>
61 <property name="left_attach">0</property>
62 <property name="top_attach">1</property>
63 <property name="width">2</property>
64 <property name="height">1</property>
65 </packing>
66 </child>
67 </object>
68 </child>
69 <child type="tab">
70 <object class="GtkLabel" id="label1">
71 <property name="visible">True</property>
72 <property name="can_focus">False</property>
73 <property name="label" translatable="yes">page 1</property>
74 </object>
75 <packing>
76 <property name="tab_fill">False</property>
77 </packing>
78 </child>
79 <child>
80 <object class="GtkGrid" id="grid1">
81 <property name="visible">True</property>
82 <property name="can_focus">False</property>
83 <property name="margin_start">50</property>
84 <property name="margin_end">50</property>
85 <property name="margin_top">12</property>
86 <property name="margin_bottom">12</property>
87 <property name="row_spacing">10</property>
88 <property name="column_spacing">6</property>
89 <child>
90 <object class="GtkEntry" id="entry1">
91 <property name="visible">True</property>
92 <property name="can_focus">True</property>
93 <property name="invisible_char">●</property>
94 <property name="width_chars">35</property>
95 </object>
96 <packing>
97 <property name="left_attach">1</property>
98 <property name="top_attach">0</property>
99 <property name="width">1</property>
100 <property name="height">1</property>
101 </packing>
102 </child>
103 <child>
104 <object class="GtkEntry" id="entry2">
105 <property name="visible">True</property>
106 <property name="can_focus">True</property>
107 <property name="invisible_char">●</property>
108 </object>
109 <packing>
110 <property name="left_attach">1</property>
111 <property name="top_attach">1</property>
112 <property name="width">1</property>
113 <property name="height">1</property>
114 </packing>
115 </child>
116 <child>
117 <object class="GtkEntry" id="entry3">
118 <property name="visible">True</property>
119 <property name="can_focus">True</property>
120 <property name="invisible_char">●</property>
121 </object>
122 <packing>
123 <property name="left_attach">1</property>
124 <property name="top_attach">2</property>
125 <property name="width">1</property>
126 <property name="height">1</property>
127 </packing>
128 </child>
129 <child>
130 <object class="GtkEntry" id="entry4">
131 <property name="visible">True</property>
132 <property name="can_focus">True</property>
133 <property name="invisible_char">●</property>
134 </object>
135 <packing>
136 <property name="left_attach">1</property>
137 <property name="top_attach">3</property>
138 <property name="width">1</property>
139 <property name="height">1</property>
140 </packing>
141 </child>
142 <child>
143 <object class="GtkEntry" id="entry5">
144 <property name="visible">True</property>
145 <property name="can_focus">True</property>
146 <property name="invisible_char">●</property>
147 </object>
148 <packing>
149 <property name="left_attach">1</property>
150 <property name="top_attach">4</property>
151 <property name="width">1</property>
152 <property name="height">1</property>
153 </packing>
154 </child>
155 <child>
156 <object class="GtkEntry" id="entry6">
157 <property name="visible">True</property>
158 <property name="can_focus">True</property>
159 <property name="invisible_char">●</property>
160 </object>
161 <packing>
162 <property name="left_attach">1</property>
163 <property name="top_attach">5</property>
164 <property name="width">1</property>
165 <property name="height">1</property>
166 </packing>
167 </child>
168 <child>
169 <object class="GtkEntry" id="entry7">
170 <property name="visible">True</property>
171 <property name="can_focus">True</property>
172 <property name="invisible_char">●</property>
173 </object>
174 <packing>
175 <property name="left_attach">1</property>
176 <property name="top_attach">6</property>
177 <property name="width">1</property>
178 <property name="height">1</property>
179 </packing>
180 </child>
181 <child>
182 <object class="GtkEntry" id="entry8">
183 <property name="visible">True</property>
184 <property name="can_focus">True</property>
185 <property name="invisible_char">●</property>
186 </object>
187 <packing>
188 <property name="left_attach">1</property>
189 <property name="top_attach">7</property>
190 <property name="width">1</property>
191 <property name="height">1</property>
192 </packing>
193 </child>
194 <child>
195 <object class="GtkEntry" id="entry9">
196 <property name="visible">True</property>
197 <property name="can_focus">True</property>
198 <property name="invisible_char">●</property>
199 </object>
200 <packing>
201 <property name="left_attach">1</property>
202 <property name="top_attach">8</property>
203 <property name="width">1</property>
204 <property name="height">1</property>
205 </packing>
206 </child>
207 <child>
208 <object class="GtkEntry" id="entry10">
209 <property name="visible">True</property>
210 <property name="can_focus">True</property>
211 <property name="invisible_char">●</property>
212 </object>
213 <packing>
214 <property name="left_attach">1</property>
215 <property name="top_attach">9</property>
216 <property name="width">1</property>
217 <property name="height">1</property>
218 </packing>
219 </child>
220 <child>
221 <object class="GtkLabel" id="label3">
222 <property name="visible">True</property>
223 <property name="can_focus">False</property>
224 <property name="label" translatable="yes">Anony_mous identity</property>
225 <property name="use_underline">True</property>
226 </object>
227 <packing>
228 <property name="left_attach">0</property>
229 <property name="top_attach">0</property>
230 <property name="width">1</property>
231 <property name="height">1</property>
232 </packing>
233 </child>
234 <child>
235 <object class="GtkLabel" id="label4">
236 <property name="visible">True</property>
237 <property name="can_focus">False</property>
238 <property name="label" translatable="yes">Inner _authentication</property>
239 <property name="use_underline">True</property>
240 </object>
241 <packing>
242 <property name="left_attach">0</property>
243 <property name="top_attach">1</property>
244 <property name="width">1</property>
245 <property name="height">1</property>
246 </packing>
247 </child>
248 <child>
249 <placeholder/>
250 </child>
251 <child>
252 <placeholder/>
253 </child>
254 <child>
255 <placeholder/>
256 </child>
257 <child>
258 <placeholder/>
259 </child>
260 <child>
261 <placeholder/>
262 </child>
263 <child>
264 <placeholder/>
265 </child>
266 <child>
267 <placeholder/>
268 </child>
269 <child>
270 <placeholder/>
271 </child>
272 </object>
273 <packing>
274 <property name="position">1</property>
275 </packing>
276 </child>
277 <child type="tab">
278 <object class="GtkLabel" id="label2">
279 <property name="visible">True</property>
280 <property name="can_focus">False</property>
281 <property name="label" translatable="yes">page 2</property>
282 </object>
283 <packing>
284 <property name="position">1</property>
285 <property name="tab_fill">False</property>
286 </packing>
287 </child>
288 <child>
289 <placeholder/>
290 </child>
291 <child type="tab">
292 <placeholder/>
293 </child>
294 </object>
295</interface>
0296
=== added file 'panels/network/connection-editor/Makefile.am'
--- panels/network/connection-editor/Makefile.am 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/Makefile.am 2019-05-01 13:56:52 +0000
@@ -0,0 +1,54 @@
1noinst_LTLIBRARIES = libconnection-editor.la
2
3BUILT_SOURCES = \
4 net-connection-editor-resources.c \
5 net-connection-editor-resources.h
6
7libconnection_editor_la_SOURCES = \
8 $(BUILT_SOURCES) \
9 net-connection-editor.h \
10 net-connection-editor.c \
11 ce-page.h \
12 ce-page.c \
13 ce-page-details.h \
14 ce-page-details.c \
15 ce-page-wifi.h \
16 ce-page-wifi.c \
17 ce-page-ip4.h \
18 ce-page-ip4.c \
19 ce-page-ip6.h \
20 ce-page-ip6.c \
21 ce-page-security.h \
22 ce-page-security.c \
23 ce-page-ethernet.h \
24 ce-page-ethernet.c \
25 ce-page-8021x-security.h \
26 ce-page-8021x-security.c \
27 ce-page-vpn.h \
28 ce-page-vpn.c \
29 vpn-helpers.h \
30 vpn-helpers.c \
31 ui-helpers.h \
32 ui-helpers.c
33
34libconnection_editor_la_CPPFLAGS = \
35 $(PANEL_CFLAGS) \
36 -I$(srcdir)/../wireless-security \
37 $(NETWORK_PANEL_CFLAGS) \
38 $(NETWORK_MANAGER_CFLAGS)
39
40libconnection_editor_la_LIBADD = \
41 $(builddir)/../wireless-security/libwireless-security.la \
42 $(NETWORK_PANEL_LIBS) \
43 $(NETWORK_MANAGER_LIBS)
44
45resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/connection-editor.gresource.xml)
46net-connection-editor-resources.c: connection-editor.gresource.xml $(resource_files)
47 $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name net_connection_editor $<
48net-connection-editor-resources.h: connection-editor.gresource.xml $(resource_files)
49 $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-header --c-name net_connection_editor $<
50
51EXTRA_DIST = \
52 $(resource_files) connection-editor.gresource.xml
53
54-include $(top_srcdir)/git.mk
055
=== added file 'panels/network/connection-editor/ce-page-8021x-security.c'
--- panels/network/connection-editor/ce-page-8021x-security.c 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/ce-page-8021x-security.c 2019-05-01 13:56:52 +0000
@@ -0,0 +1,186 @@
1/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2/* NetworkManager Connection editor -- Connection editor for NetworkManager
3 *
4 * Dan Williams <dcbw@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * (C) Copyright 2008 - 2012 Red Hat, Inc.
21 */
22
23#include "config.h"
24
25#include <string.h>
26
27#include <gtk/gtk.h>
28#include <glib/gi18n.h>
29
30#include <NetworkManager.h>
31
32#include "wireless-security.h"
33#include "ce-page-ethernet.h"
34#include "ce-page-8021x-security.h"
35
36G_DEFINE_TYPE (CEPage8021xSecurity, ce_page_8021x_security, CE_TYPE_PAGE)
37
38static void
39enable_toggled (GObject *sw, GParamSpec *pspec, gpointer user_data)
40{
41 CEPage8021xSecurity *page = CE_PAGE_8021X_SECURITY (user_data);
42
43 gtk_widget_set_sensitive (page->security_widget, gtk_switch_get_active (page->enabled));
44 ce_page_changed (CE_PAGE (page));
45}
46
47static void
48stuff_changed (WirelessSecurity *sec, gpointer user_data)
49{
50 ce_page_changed (CE_PAGE (user_data));
51}
52
53static void
54finish_setup (CEPage8021xSecurity *page, gpointer unused, GError *error, gpointer user_data)
55{
56 GtkWidget *parent;
57 GtkWidget *vbox;
58 GtkWidget *heading;
59
60 if (error)
61 return;
62
63 vbox = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "vbox"));
64 heading = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "heading_sec"));
65
66 page->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
67
68 page->security = (WirelessSecurity *) ws_wpa_eap_new (CE_PAGE (page)->connection, TRUE, FALSE);
69 if (!page->security) {
70 g_warning ("Could not load 802.1x user interface.");
71 return;
72 }
73
74 wireless_security_set_changed_notify (page->security, stuff_changed, page);
75 page->security_widget = wireless_security_get_widget (page->security);
76 parent = gtk_widget_get_parent (page->security_widget);
77 if (parent)
78 gtk_container_remove (GTK_CONTAINER (parent), page->security_widget);
79
80 gtk_switch_set_active (page->enabled, page->initial_have_8021x);
81 g_signal_connect (page->enabled, "notify::active", G_CALLBACK (enable_toggled), page);
82 gtk_widget_set_sensitive (page->security_widget, page->initial_have_8021x);
83
84 gtk_size_group_add_widget (page->group, heading);
85 wireless_security_add_to_size_group (page->security, page->group);
86
87 gtk_container_add (GTK_CONTAINER (vbox), page->security_widget);
88
89}
90
91CEPage *
92ce_page_8021x_security_new (NMConnection *connection,
93 NMClient *client)
94{
95 CEPage8021xSecurity *page;
96
97 page = CE_PAGE_8021X_SECURITY (ce_page_new (CE_TYPE_PAGE_8021X_SECURITY,
98 connection,
99 client,
100 "/org/gnome/control-center/network/8021x-security-page.ui",
101 _("Security")));
102
103 if (nm_connection_get_setting_802_1x (connection))
104 page->initial_have_8021x = TRUE;
105
106 page->enabled = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "8021x_switch"));
107
108 g_signal_connect (page, "initialized", G_CALLBACK (finish_setup), NULL);
109
110 if (page->initial_have_8021x)
111 CE_PAGE (page)->security_setting = NM_SETTING_802_1X_SETTING_NAME;
112
113 return CE_PAGE (page);
114}
115
116static gboolean
117validate (CEPage *cepage, NMConnection *connection, GError **error)
118{
119 CEPage8021xSecurity *page = CE_PAGE_8021X_SECURITY (cepage);
120 gboolean valid = TRUE;
121
122 if (gtk_switch_get_active (page->enabled)) {
123 NMConnection *tmp_connection;
124 NMSetting *s_8021x;
125
126 /* FIXME: get failed property and error out of wireless security objects */
127 valid = wireless_security_validate (page->security, error);
128 if (valid) {
129 NMSetting *s_con;
130
131 /* Here's a nice hack to work around the fact that ws_802_1x_fill_connection needs wireless setting. */
132 tmp_connection = nm_simple_connection_new ();
133 nm_connection_add_setting (tmp_connection, nm_setting_wireless_new ());
134
135 /* temp connection needs a 'connection' setting too, since most of
136 * the EAP methods need the UUID for CA cert ignore stuff.
137 */
138 s_con = nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
139 nm_connection_add_setting (tmp_connection, nm_setting_duplicate (s_con));
140
141 ws_802_1x_fill_connection (page->security, "wpa_eap_auth_combo", tmp_connection);
142
143 s_8021x = nm_connection_get_setting (tmp_connection, NM_TYPE_SETTING_802_1X);
144 nm_connection_add_setting (connection, NM_SETTING (g_object_ref (s_8021x)));
145
146 g_object_unref (tmp_connection);
147 }
148 } else {
149 nm_connection_remove_setting (connection, NM_TYPE_SETTING_802_1X);
150 valid = TRUE;
151 }
152
153 return valid;
154}
155
156static void
157ce_page_8021x_security_init (CEPage8021xSecurity *page)
158{
159}
160
161static void
162dispose (GObject *object)
163{
164 CEPage8021xSecurity *page = CE_PAGE_8021X_SECURITY (object);
165
166 if (page->security) {
167 wireless_security_unref (page->security);
168 page->security = NULL;
169 }
170
171 g_clear_object (&page->group);
172
173 G_OBJECT_CLASS (ce_page_8021x_security_parent_class)->dispose (object);
174}
175
176static void
177ce_page_8021x_security_class_init (CEPage8021xSecurityClass *security_class)
178{
179 GObjectClass *object_class = G_OBJECT_CLASS (security_class);
180 CEPageClass *parent_class = CE_PAGE_CLASS (security_class);
181
182 /* virtual methods */
183 object_class->dispose = dispose;
184
185 parent_class->validate = validate;
186}
0187
=== added file 'panels/network/connection-editor/ce-page-8021x-security.h'
--- panels/network/connection-editor/ce-page-8021x-security.h 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/ce-page-8021x-security.h 2019-05-01 13:56:52 +0000
@@ -0,0 +1,63 @@
1/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2/* NetworkManager Connection editor -- Connection editor for NetworkManager
3 *
4 * Dan Williams <dcbw@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * (C) Copyright 2008 - 2012 Red Hat, Inc.
21 */
22
23#ifndef __CE_PAGE_8021X_SECURITY_H
24#define __CE_PAGE_8021X_SECURITY_H
25
26#include <NetworkManager.h>
27#include "wireless-security.h"
28
29#include <glib.h>
30#include <glib-object.h>
31
32#include "ce-page.h"
33
34#define CE_TYPE_PAGE_8021X_SECURITY (ce_page_8021x_security_get_type ())
35#define CE_PAGE_8021X_SECURITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CE_TYPE_PAGE_8021X_SECURITY, CEPage8021xSecurity))
36#define CE_PAGE_8021X_SECURITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CE_TYPE_PAGE_8021X_SECURITY, CEPage8021xSecurityClass))
37#define CE_IS_PAGE_8021X_SECURITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CE_TYPE_PAGE_8021X_SECURITY))
38#define CE_IS_PAGE_8021X_SECURITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CE_TYPE_PAGE_8021X_SECURITY))
39#define CE_PAGE_8021X_SECURITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CE_TYPE_PAGE_8021X_SECURITY, CEPage8021xSecurityClass))
40
41typedef struct CEPage8021xSecurity CEPage8021xSecurity;
42typedef struct CEPage8021xSecurityClass CEPage8021xSecurityClass;
43
44struct CEPage8021xSecurity {
45 CEPage parent;
46
47 GtkSwitch *enabled;
48 GtkWidget *security_widget;
49 WirelessSecurity *security;
50 GtkSizeGroup *group;
51 gboolean initial_have_8021x;
52};
53
54struct CEPage8021xSecurityClass {
55 CEPageClass parent;
56};
57
58GType ce_page_8021x_security_get_type (void);
59
60CEPage *ce_page_8021x_security_new (NMConnection *connection,
61 NMClient *client);
62
63#endif /* __CE_PAGE_8021X_SECURITY_H */
064
=== added file 'panels/network/connection-editor/ce-page-details.c'
--- panels/network/connection-editor/ce-page-details.c 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/ce-page-details.c 2019-05-01 13:56:52 +0000
@@ -0,0 +1,289 @@
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2012 Red Hat, Inc
4 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#include "config.h"
23
24#include <glib-object.h>
25#include <glib/gi18n.h>
26
27#include <NetworkManager.h>
28
29#include "../panel-common.h"
30#include "ce-page-details.h"
31
32G_DEFINE_TYPE (CEPageDetails, ce_page_details, CE_TYPE_PAGE)
33
34static void
35forget_cb (GtkButton *button, CEPageDetails *page)
36{
37 net_connection_editor_forget (page->editor);
38}
39
40static gchar *
41get_ap_security_string (NMAccessPoint *ap)
42{
43 NM80211ApSecurityFlags wpa_flags, rsn_flags;
44 NM80211ApFlags flags;
45 GString *str;
46
47 flags = nm_access_point_get_flags (ap);
48 wpa_flags = nm_access_point_get_wpa_flags (ap);
49 rsn_flags = nm_access_point_get_rsn_flags (ap);
50
51 str = g_string_new ("");
52 if ((flags & NM_802_11_AP_FLAGS_PRIVACY) &&
53 (wpa_flags == NM_802_11_AP_SEC_NONE) &&
54 (rsn_flags == NM_802_11_AP_SEC_NONE)) {
55 /* TRANSLATORS: this WEP WiFi security */
56 g_string_append_printf (str, "%s, ", _("WEP"));
57 }
58 if (wpa_flags != NM_802_11_AP_SEC_NONE) {
59 /* TRANSLATORS: this WPA WiFi security */
60 g_string_append_printf (str, "%s, ", _("WPA"));
61 }
62 if (rsn_flags != NM_802_11_AP_SEC_NONE) {
63 /* TRANSLATORS: this WPA WiFi security */
64 g_string_append_printf (str, "%s, ", _("WPA2"));
65 }
66 if ((wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) ||
67 (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
68 /* TRANSLATORS: this Enterprise WiFi security */
69 g_string_append_printf (str, "%s, ", _("Enterprise"));
70 }
71 if (str->len > 0)
72 g_string_set_size (str, str->len - 2);
73 else {
74 g_string_append (str, C_("Wifi security", "None"));
75 }
76 return g_string_free (str, FALSE);
77}
78
79static void
80update_last_used (CEPageDetails *page, NMConnection *connection)
81{
82 gchar *last_used = NULL;
83 GDateTime *now = NULL;
84 GDateTime *then = NULL;
85 gint days;
86 GTimeSpan diff;
87 guint64 timestamp;
88 NMSettingConnection *s_con;
89
90 s_con = nm_connection_get_setting_connection (connection);
91 if (s_con == NULL)
92 goto out;
93 timestamp = nm_setting_connection_get_timestamp (s_con);
94 if (timestamp == 0) {
95 last_used = g_strdup (_("Never"));
96 goto out;
97 }
98
99 /* calculate the amount of time that has elapsed */
100 now = g_date_time_new_now_utc ();
101 then = g_date_time_new_from_unix_utc (timestamp);
102
103 diff = g_date_time_difference (now, then);
104 days = diff / G_TIME_SPAN_DAY;
105 if (days == 0)
106 last_used = g_strdup (_("Today"));
107 else if (days == 1)
108 last_used = g_strdup (_("Yesterday"));
109 else
110 last_used = g_strdup_printf (ngettext ("%i day ago", "%i days ago", days), days);
111out:
112 panel_set_device_widget_details (CE_PAGE (page)->builder, "last_used", last_used);
113 if (now != NULL)
114 g_date_time_unref (now);
115 if (then != NULL)
116 g_date_time_unref (then);
117 g_free (last_used);
118}
119
120static void
121all_user_changed (GtkToggleButton *b, CEPageDetails *page)
122{
123 gboolean all_users;
124 NMSettingConnection *sc;
125
126 sc = nm_connection_get_setting_connection (CE_PAGE (page)->connection);
127 all_users = gtk_toggle_button_get_active (b);
128
129 g_object_set (sc, "permissions", NULL, NULL);
130 if (!all_users)
131 nm_setting_connection_add_permission (sc, "user", g_get_user_name (), NULL);
132}
133
134static void
135connect_details_page (CEPageDetails *page)
136{
137 NMSettingConnection *sc;
138 GtkWidget *widget;
139 guint speed;
140 guint strength;
141 NMDeviceState state;
142 NMAccessPoint *active_ap;
143 const gchar *str;
144 const gchar *type;
145 gboolean device_is_active;
146
147 if (NM_IS_DEVICE_WIFI (page->device))
148 active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (page->device));
149 else
150 active_ap = NULL;
151
152 state = page->device ? nm_device_get_state (page->device) : NM_DEVICE_STATE_DISCONNECTED;
153
154 device_is_active = FALSE;
155 speed = 0;
156 if (active_ap && page->ap == active_ap && state != NM_DEVICE_STATE_UNAVAILABLE) {
157 device_is_active = TRUE;
158 if (NM_IS_DEVICE_WIFI (page->device))
159 speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (page->device)) / 1000;
160 } else if (page->device) {
161 NMActiveConnection *ac;
162 const gchar *p1, *p2;
163
164 ac = nm_device_get_active_connection (page->device);
165 p1 = ac ? nm_active_connection_get_uuid (ac) : NULL;
166 p2 = nm_connection_get_uuid (CE_PAGE (page)->connection);
167 if (g_strcmp0 (p1, p2) == 0) {
168 device_is_active = TRUE;
169 if (NM_IS_DEVICE_WIFI (page->device))
170 speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (page->device)) / 1000;
171 else if (NM_IS_DEVICE_ETHERNET (page->device))
172 speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (page->device));
173 }
174 }
175 if (speed > 0)
176 str = g_strdup_printf (_("%d Mb/s"), speed);
177 else
178 str = NULL;
179 panel_set_device_widget_details (CE_PAGE (page)->builder, "speed", str);
180 g_clear_pointer (&str, g_free);
181
182 if (NM_IS_DEVICE_WIFI (page->device))
183 str = nm_device_wifi_get_hw_address (NM_DEVICE_WIFI (page->device));
184 else if (NM_IS_DEVICE_ETHERNET (page->device))
185 str = nm_device_ethernet_get_hw_address (NM_DEVICE_ETHERNET (page->device));
186
187 panel_set_device_widget_details (CE_PAGE (page)->builder, "mac", str);
188
189 str = NULL;
190 if (device_is_active && active_ap)
191 str = get_ap_security_string (active_ap);
192 panel_set_device_widget_details (CE_PAGE (page)->builder, "security", str);
193 g_clear_pointer (&str, g_free);
194
195 strength = 0;
196 if (page->ap != NULL)
197 strength = nm_access_point_get_strength (page->ap);
198
199 if (strength <= 0)
200 str = NULL;
201 else if (strength < 20)
202 str = C_("Signal strength", "None");
203 else if (strength < 40)
204 str = C_("Signal strength", "Weak");
205 else if (strength < 50)
206 str = C_("Signal strength", "Ok");
207 else if (strength < 80)
208 str = C_("Signal strength", "Good");
209 else
210 str = C_("Signal strength", "Excellent");
211 panel_set_device_widget_details (CE_PAGE (page)->builder, "strength", str);
212
213 /* set IP entries */
214 if (device_is_active)
215 panel_set_device_widgets (CE_PAGE (page)->builder, page->device);
216 else
217 panel_unset_device_widgets (CE_PAGE (page)->builder);
218
219 if (!device_is_active && CE_PAGE (page)->connection)
220 update_last_used (page, CE_PAGE (page)->connection);
221 else
222 panel_set_device_widget_details (CE_PAGE (page)->builder, "last_used", NULL);
223
224 /* Auto connect check */
225 widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder,
226 "auto_connect_check"));
227 sc = nm_connection_get_setting_connection (CE_PAGE (page)->connection);
228 g_object_bind_property (sc, "autoconnect",
229 widget, "active",
230 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
231 g_signal_connect_swapped (widget, "toggled", G_CALLBACK (ce_page_changed), page);
232
233 /* All users check */
234 widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder,
235 "all_user_check"));
236 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget),
237 nm_setting_connection_get_num_permissions (sc) == 0);
238 g_signal_connect (widget, "toggled",
239 G_CALLBACK (all_user_changed), page);
240 g_signal_connect_swapped (widget, "toggled", G_CALLBACK (ce_page_changed), page);
241
242 /* Forget button */
243 widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "button_forget"));
244 g_signal_connect (widget, "clicked", G_CALLBACK (forget_cb), page);
245
246 type = nm_setting_connection_get_connection_type (sc);
247 if (g_str_equal (type, NM_SETTING_WIRELESS_SETTING_NAME))
248 gtk_button_set_label (GTK_BUTTON (widget), _("Forget Connection"));
249 else if (g_str_equal (type, NM_SETTING_WIRED_SETTING_NAME))
250 gtk_button_set_label (GTK_BUTTON (widget), _("Remove Connection Profile"));
251 else if (g_str_equal (type, NM_SETTING_VPN_SETTING_NAME))
252 gtk_button_set_label (GTK_BUTTON (widget), _("Remove VPN"));
253 else
254 gtk_widget_hide (widget);
255}
256
257static void
258ce_page_details_init (CEPageDetails *page)
259{
260}
261
262static void
263ce_page_details_class_init (CEPageDetailsClass *class)
264{
265}
266
267CEPage *
268ce_page_details_new (NMConnection *connection,
269 NMClient *client,
270 NMDevice *device,
271 NMAccessPoint *ap,
272 NetConnectionEditor *editor)
273{
274 CEPageDetails *page;
275
276 page = CE_PAGE_DETAILS (ce_page_new (CE_TYPE_PAGE_DETAILS,
277 connection,
278 client,
279 "/org/gnome/control-center/network/details-page.ui",
280 _("Details")));
281
282 page->editor = editor;
283 page->device = device;
284 page->ap = ap;
285
286 connect_details_page (page);
287
288 return CE_PAGE (page);
289}
0290
=== added file 'panels/network/connection-editor/ce-page-details.h'
--- panels/network/connection-editor/ce-page-details.h 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/ce-page-details.h 2019-05-01 13:56:52 +0000
@@ -0,0 +1,68 @@
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2012 Red Hat, Inc.
4 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#ifndef __CE_PAGE_DETAILS_H
23#define __CE_PAGE_DETAILS_H
24
25#include <glib-object.h>
26
27#include <gtk/gtk.h>
28#include "net-connection-editor.h"
29#include "ce-page.h"
30
31G_BEGIN_DECLS
32
33#define CE_TYPE_PAGE_DETAILS (ce_page_details_get_type ())
34#define CE_PAGE_DETAILS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CE_TYPE_PAGE_DETAILS, CEPageDetails))
35#define CE_PAGE_DETAILS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CE_TYPE_PAGE_DETAILS, CEPageDetailsClass))
36#define CE_IS_PAGE_DETAILS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CE_TYPE_PAGE_DETAILS))
37#define CE_IS_PAGE_DETAILS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CE_TYPE_PAGE_DETAILS))
38#define CE_PAGE_DETAILS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CE_TYPE_PAGE_DETAILS, CEPageDetailsClass))
39
40typedef struct _CEPageDetails CEPageDetails;
41typedef struct _CEPageDetailsClass CEPageDetailsClass;
42
43struct _CEPageDetails
44{
45 CEPage parent;
46
47 NMDevice *device;
48 NMAccessPoint *ap;
49 NetConnectionEditor *editor;
50};
51
52struct _CEPageDetailsClass
53{
54 CEPageClass parent_class;
55};
56
57GType ce_page_details_get_type (void);
58
59CEPage *ce_page_details_new (NMConnection *connection,
60 NMClient *client,
61 NMDevice *device,
62 NMAccessPoint *ap,
63 NetConnectionEditor *editor);
64
65G_END_DECLS
66
67#endif /* __CE_PAGE_DETAILS_H */
68
069
=== added file 'panels/network/connection-editor/ce-page-ethernet.c'
--- panels/network/connection-editor/ce-page-ethernet.c 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/ce-page-ethernet.c 2019-05-01 13:56:52 +0000
@@ -0,0 +1,187 @@
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2012 Red Hat, Inc
4 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#include "config.h"
23
24#include <glib-object.h>
25#include <glib/gi18n.h>
26#include <net/if_arp.h>
27
28#include <NetworkManager.h>
29
30
31#include "ce-page-ethernet.h"
32#include "ui-helpers.h"
33
34G_DEFINE_TYPE (CEPageEthernet, ce_page_ethernet, CE_TYPE_PAGE)
35
36static void
37mtu_changed (GtkSpinButton *mtu, CEPageEthernet *page)
38{
39 if (gtk_spin_button_get_value_as_int (mtu) == 0)
40 gtk_widget_hide (page->mtu_label);
41 else
42 gtk_widget_show (page->mtu_label);
43}
44
45static void
46connect_ethernet_page (CEPageEthernet *page)
47{
48 NMSettingWired *setting = page->setting_wired;
49 int mtu_def;
50 char **mac_list;
51 const char *s_mac_str;
52 const gchar *name;
53 const gchar *cloned_mac;
54
55 name = nm_setting_connection_get_id (page->setting_connection);
56 gtk_entry_set_text (page->name, name);
57
58 /* Device MAC address */
59 mac_list = ce_page_get_mac_list (CE_PAGE (page)->client, NM_TYPE_DEVICE_ETHERNET,
60 NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS);
61 s_mac_str = nm_setting_wired_get_mac_address (setting);
62 ce_page_setup_mac_combo (page->device_mac, s_mac_str, mac_list);
63 g_strfreev (mac_list);
64 g_signal_connect_swapped (page->device_mac, "changed", G_CALLBACK (ce_page_changed), page);
65
66 /* Cloned MAC address */
67 cloned_mac = nm_setting_wired_get_cloned_mac_address (setting);
68 gtk_entry_set_text (GTK_ENTRY (page->cloned_mac), cloned_mac ? cloned_mac : "");
69 g_signal_connect_swapped (page->cloned_mac, "changed", G_CALLBACK (ce_page_changed), page);
70
71 /* MTU */
72 mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRED_MTU);
73 g_signal_connect (page->mtu, "output",
74 G_CALLBACK (ce_spin_output_with_default),
75 GINT_TO_POINTER (mtu_def));
76 gtk_spin_button_set_value (page->mtu, (gdouble) nm_setting_wired_get_mtu (setting));
77 g_signal_connect (page->mtu, "value-changed",
78 G_CALLBACK (mtu_changed), page);
79 mtu_changed (page->mtu, page);
80
81 g_signal_connect_swapped (page->name, "changed", G_CALLBACK (ce_page_changed), page);
82 g_signal_connect_swapped (page->mtu, "value-changed", G_CALLBACK (ce_page_changed), page);
83}
84
85static void
86ui_to_setting (CEPageEthernet *page)
87{
88 gchar *device_mac = NULL;
89 gchar *cloned_mac;
90 const gchar *text;
91 GtkWidget *entry;
92
93 entry = gtk_bin_get_child (GTK_BIN (page->device_mac));
94 if (entry) {
95 text = gtk_entry_get_text (GTK_ENTRY (entry));
96 device_mac = ce_page_trim_address (text);
97 }
98 text = gtk_entry_get_text (GTK_ENTRY (entry));
99 cloned_mac = ce_page_trim_address (text);
100
101 g_object_set (page->setting_wired,
102 NM_SETTING_WIRED_MAC_ADDRESS, device_mac,
103 NM_SETTING_WIRED_CLONED_MAC_ADDRESS, cloned_mac,
104 NM_SETTING_WIRED_MTU, (guint32) gtk_spin_button_get_value_as_int (page->mtu),
105 NULL);
106
107 g_object_set (page->setting_connection,
108 NM_SETTING_CONNECTION_ID, gtk_entry_get_text (page->name),
109 NULL);
110
111 g_free (cloned_mac);
112 g_free (device_mac);
113}
114
115static gboolean
116validate (CEPage *page,
117 NMConnection *connection,
118 GError **error)
119{
120 CEPageEthernet *self = CE_PAGE_ETHERNET (page);
121 GtkWidget *entry;
122 gboolean ret = TRUE;
123
124 entry = gtk_bin_get_child (GTK_BIN (self->device_mac));
125 if (entry) {
126 if (!ce_page_address_is_valid (gtk_entry_get_text (GTK_ENTRY (entry)))) {
127 widget_set_error (entry);
128 ret = FALSE;
129 } else {
130 widget_unset_error (entry);
131 }
132 }
133
134 if (!ce_page_address_is_valid (gtk_entry_get_text (GTK_ENTRY (self->cloned_mac)))) {
135 widget_set_error (GTK_WIDGET (self->cloned_mac));
136 ret = FALSE;
137 } else {
138 widget_unset_error (GTK_WIDGET (self->cloned_mac));
139 }
140
141 if (!ret)
142 return ret;
143
144 ui_to_setting (self);
145
146 return nm_setting_verify (NM_SETTING (self->setting_connection), NULL, error) &&
147 nm_setting_verify (NM_SETTING (self->setting_wired), NULL, error);
148}
149
150static void
151ce_page_ethernet_init (CEPageEthernet *page)
152{
153}
154
155static void
156ce_page_ethernet_class_init (CEPageEthernetClass *class)
157{
158 CEPageClass *page_class= CE_PAGE_CLASS (class);
159
160 page_class->validate = validate;
161}
162
163CEPage *
164ce_page_ethernet_new (NMConnection *connection,
165 NMClient *client)
166{
167 CEPageEthernet *page;
168
169 page = CE_PAGE_ETHERNET (ce_page_new (CE_TYPE_PAGE_ETHERNET,
170 connection,
171 client,
172 "/org/gnome/control-center/network/ethernet-page.ui",
173 _("Identity")));
174
175 page->name = GTK_ENTRY (gtk_builder_get_object (CE_PAGE (page)->builder, "entry_name"));
176 page->device_mac = GTK_COMBO_BOX_TEXT (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_mac"));
177 page->cloned_mac = GTK_ENTRY (gtk_builder_get_object (CE_PAGE (page)->builder, "entry_cloned_mac"));
178 page->mtu = GTK_SPIN_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "spin_mtu"));
179 page->mtu_label = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "label_mtu"));
180
181 page->setting_connection = nm_connection_get_setting_connection (connection);
182 page->setting_wired = nm_connection_get_setting_wired (connection);
183
184 connect_ethernet_page (page);
185
186 return CE_PAGE (page);
187}
0188
=== added file 'panels/network/connection-editor/ce-page-ethernet.h'
--- panels/network/connection-editor/ce-page-ethernet.h 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/ce-page-ethernet.h 2019-05-01 13:56:52 +0000
@@ -0,0 +1,71 @@
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2012 Red Hat, Inc.
4 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more ethernet.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#ifndef __CE_PAGE_ETHERNET_H
23#define __CE_PAGE_ETHERNET_H
24
25#include <glib-object.h>
26
27#include <NetworkManager.h>
28
29#include <gtk/gtk.h>
30#include "ce-page.h"
31
32G_BEGIN_DECLS
33
34#define CE_TYPE_PAGE_ETHERNET (ce_page_ethernet_get_type ())
35#define CE_PAGE_ETHERNET(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CE_TYPE_PAGE_ETHERNET, CEPageEthernet))
36#define CE_PAGE_ETHERNET_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CE_TYPE_PAGE_ETHERNET, CEPageEthernetClass))
37#define CE_IS_PAGE_ETHERNET(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CE_TYPE_PAGE_ETHERNET))
38#define CE_IS_PAGE_ETHERNET_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CE_TYPE_PAGE_ETHERNET))
39#define CE_PAGE_ETHERNET_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CE_TYPE_PAGE_ETHERNET, CEPageEthernetClass))
40
41typedef struct _CEPageEthernet CEPageEthernet;
42typedef struct _CEPageEthernetClass CEPageEthernetClass;
43
44struct _CEPageEthernet
45{
46 CEPage parent;
47
48 NMSettingConnection *setting_connection;
49 NMSettingWired *setting_wired;
50
51 GtkEntry *name;
52 GtkComboBoxText *device_mac;
53 GtkEntry *cloned_mac;
54 GtkSpinButton *mtu;
55 GtkWidget *mtu_label;
56};
57
58struct _CEPageEthernetClass
59{
60 CEPageClass parent_class;
61};
62
63GType ce_page_ethernet_get_type (void);
64
65CEPage *ce_page_ethernet_new (NMConnection *connection,
66 NMClient *client);
67
68G_END_DECLS
69
70#endif /* __CE_PAGE_ETHERNET_H */
71
072
=== added file 'panels/network/connection-editor/ce-page-ip4.c'
--- panels/network/connection-editor/ce-page-ip4.c 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/ce-page-ip4.c 2019-05-01 13:56:52 +0000
@@ -0,0 +1,907 @@
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2012 Red Hat, Inc
4 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#include "config.h"
23
24#include <errno.h>
25#include <stdlib.h>
26#include <arpa/inet.h>
27#include <glib-object.h>
28#include <glib/gi18n.h>
29#include <NetworkManager.h>
30
31#include "shell/list-box-helper.h"
32#include "ce-page-ip4.h"
33#include "ui-helpers.h"
34
35#define RADIO_IS_ACTIVE(x) (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object(CE_PAGE (page)->builder, x))))
36
37static void ensure_empty_address_row (CEPageIP4 *page);
38static void ensure_empty_routes_row (CEPageIP4 *page);
39
40G_DEFINE_TYPE (CEPageIP4, ce_page_ip4, CE_TYPE_PAGE)
41
42enum {
43 METHOD_COL_NAME,
44 METHOD_COL_METHOD
45};
46
47enum {
48 IP4_METHOD_AUTO,
49 IP4_METHOD_MANUAL,
50 IP4_METHOD_LINK_LOCAL,
51 IP4_METHOD_SHARED,
52 IP4_METHOD_DISABLED
53};
54
55static void
56method_changed (GtkToggleButton *radio, CEPageIP4 *page)
57{
58 gboolean addr_enabled;
59 gboolean dns_enabled;
60 gboolean routes_enabled;
61 GtkWidget *widget;
62
63 if (RADIO_IS_ACTIVE ("radio_disabled")) {
64 addr_enabled = FALSE;
65 dns_enabled = FALSE;
66 routes_enabled = FALSE;
67 } else {
68 addr_enabled = RADIO_IS_ACTIVE ("radio_manual");
69 dns_enabled = !RADIO_IS_ACTIVE ("radio_local");
70 routes_enabled = !RADIO_IS_ACTIVE ("radio_local");
71 }
72
73 widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section"));
74 gtk_widget_set_visible (widget, addr_enabled);
75 gtk_widget_set_sensitive (page->dns_entry, dns_enabled);
76 gtk_widget_set_sensitive (page->routes_list, routes_enabled);
77 gtk_widget_set_sensitive (page->never_default, routes_enabled);
78
79 ce_page_changed (CE_PAGE (page));
80}
81
82static void
83switch_toggled (GObject *object,
84 GParamSpec *pspec,
85 CEPage *page)
86{
87 ce_page_changed (page);
88}
89
90static void
91update_row_sensitivity (CEPageIP4 *page, GtkWidget *list)
92{
93 GList *children, *l;
94 gint rows = 0, i = 0;
95
96 children = gtk_container_get_children (GTK_CONTAINER (list));
97 for (l = children; l; l = l->next) {
98 GtkWidget *row = l->data;
99 GtkWidget *button;
100
101 button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "delete-button"));
102 if (button != NULL)
103 rows++;
104 }
105 for (l = children; l; l = l->next) {
106 GtkWidget *row = l->data;
107 GtkWidget *button;
108
109 button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "delete-button"));
110 if (button != NULL)
111 gtk_widget_set_sensitive (button, rows > 1 && ++i < rows);
112 }
113 g_list_free (children);
114}
115
116static void
117update_row_gateway_sensitivity (CEPageIP4 *page)
118{
119 GList *children, *l;
120 gint rows = 0;
121
122 children = gtk_container_get_children (GTK_CONTAINER (page->address_list));
123 for (l = children; l; l = l->next) {
124 GtkWidget *row = l->data;
125 GtkWidget *entry;
126
127 entry = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "gateway"));
128
129 gtk_widget_set_sensitive (entry, (rows == 0));
130
131 rows++;
132 }
133 g_list_free (children);
134}
135
136static void
137remove_row (GtkButton *button, CEPageIP4 *page)
138{
139 GtkWidget *list;
140 GtkWidget *row;
141 GtkWidget *row_box;
142
143 row_box = gtk_widget_get_parent (GTK_WIDGET (button));
144 row = gtk_widget_get_parent (row_box);
145 list = gtk_widget_get_parent (row);
146
147 gtk_container_remove (GTK_CONTAINER (list), row);
148
149 ce_page_changed (CE_PAGE (page));
150
151 update_row_sensitivity (page, list);
152 if (list == page->address_list)
153 update_row_gateway_sensitivity (page);
154}
155
156static gboolean
157validate_row (GtkWidget *row)
158{
159 GtkWidget *box;
160 GList *children, *l;
161 gboolean valid;
162
163 valid = FALSE;
164 box = gtk_bin_get_child (GTK_BIN (row));
165 children = gtk_container_get_children (GTK_CONTAINER (box));
166
167 for (l = children; l != NULL; l = l->next) {
168 if (!GTK_IS_ENTRY (l->data))
169 continue;
170
171 valid = valid || gtk_entry_get_text_length (l->data) > 0;
172 }
173
174 g_list_free (children);
175
176 return valid;
177}
178
179static gint
180sort_first_last (gconstpointer a, gconstpointer b, gpointer data)
181{
182 gboolean afirst, bfirst, alast, blast;
183
184 afirst = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (a), "first"));
185 bfirst = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (b), "first"));
186 alast = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (a), "last"));
187 blast = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (b), "last"));
188
189 if (afirst)
190 return -1;
191 if (bfirst)
192 return 1;
193 if (alast)
194 return 1;
195 if (blast)
196 return -1;
197
198 return 0;
199}
200
201static void
202add_address_row (CEPageIP4 *page,
203 const gchar *address,
204 const gchar *network,
205 const gchar *gateway)
206{
207 GtkSizeGroup *group;
208 GtkWidget *row;
209 GtkWidget *row_box;
210 GtkWidget *widget;
211 GtkWidget *delete_button;
212 GtkWidget *image;
213
214 row = gtk_list_box_row_new ();
215
216 row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
217 gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
218
219 widget = gtk_entry_new ();
220 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
221 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page);
222 g_object_set_data (G_OBJECT (row), "address", widget);
223 gtk_entry_set_text (GTK_ENTRY (widget), address);
224 gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
225 gtk_widget_set_hexpand (widget, TRUE);
226 gtk_container_add (GTK_CONTAINER (row_box), widget);
227
228 widget = gtk_entry_new ();
229 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
230 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page);
231 g_object_set_data (G_OBJECT (row), "network", widget);
232 gtk_entry_set_text (GTK_ENTRY (widget), network);
233 gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
234 gtk_widget_set_hexpand (widget, TRUE);
235 gtk_container_add (GTK_CONTAINER (row_box), widget);
236
237 widget = gtk_entry_new ();
238 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
239 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page);
240 g_object_set_data (G_OBJECT (row), "gateway", widget);
241 gtk_entry_set_text (GTK_ENTRY (widget), gateway ? gateway : "");
242 gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
243 gtk_widget_set_hexpand (widget, TRUE);
244 gtk_container_add (GTK_CONTAINER (row_box), widget);
245
246 delete_button = gtk_button_new ();
247 gtk_widget_set_sensitive (delete_button, FALSE);
248 gtk_style_context_add_class (gtk_widget_get_style_context (delete_button), "image-button");
249 g_signal_connect (delete_button, "clicked", G_CALLBACK (remove_row), page);
250 image = gtk_image_new_from_icon_name ("edit-delete-symbolic", GTK_ICON_SIZE_MENU);
251 atk_object_set_name (gtk_widget_get_accessible (delete_button), _("Delete Address"));
252 gtk_button_set_image (GTK_BUTTON (delete_button), image);
253 gtk_container_add (GTK_CONTAINER (row_box), delete_button);
254 g_object_set_data (G_OBJECT (row), "delete-button", delete_button);
255
256 group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "address_sizegroup"));
257 gtk_size_group_add_widget (group, delete_button);
258
259 gtk_container_add (GTK_CONTAINER (row), row_box);
260 gtk_widget_show_all (row);
261 gtk_container_add (GTK_CONTAINER (page->address_list), row);
262
263 update_row_gateway_sensitivity (page);
264 update_row_sensitivity (page, page->address_list);
265}
266
267static void
268ensure_empty_address_row (CEPageIP4 *page)
269{
270 GList *children, *l;
271
272 children = gtk_container_get_children (GTK_CONTAINER (page->address_list));
273 l = children;
274
275 while (l && l->next)
276 l = l->next;
277
278 /* Add the last, stub row if needed*/
279 if (!l || validate_row (l->data))
280 add_address_row (page, "", "", "");
281
282 g_list_free (children);
283}
284
285static void
286add_address_section (CEPageIP4 *page)
287{
288 GtkWidget *widget;
289 GtkWidget *list;
290 gint i;
291
292 widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section"));
293
294 page->address_list = list = gtk_list_box_new ();
295 gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
296 gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL);
297 gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL);
298 gtk_container_add (GTK_CONTAINER (widget), list);
299
300 for (i = 0; i < nm_setting_ip_config_get_num_addresses (page->setting); i++) {
301 NMIPAddress *addr;
302 struct in_addr tmp_addr;
303 gchar network[INET_ADDRSTRLEN + 1];
304
305 addr = nm_setting_ip_config_get_address (page->setting, i);
306 if (!addr)
307 continue;
308
309 tmp_addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip_address_get_prefix (addr));
310 (void) inet_ntop (AF_INET, &tmp_addr, &network[0], sizeof (network));
311
312 add_address_row (page,
313 nm_ip_address_get_address (addr),
314 network,
315 i == 0 ? nm_setting_ip_config_get_gateway (page->setting) : "");
316 }
317 if (nm_setting_ip_config_get_num_addresses (page->setting) == 0)
318 ensure_empty_address_row (page);
319
320 gtk_widget_show_all (widget);
321}
322
323static void
324add_dns_section (CEPageIP4 *page)
325{
326 GtkEntry *entry;
327 GString *string;
328 gint i;
329
330 page->auto_dns = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_dns_switch"));
331 gtk_switch_set_active (page->auto_dns, !nm_setting_ip_config_get_ignore_auto_dns (page->setting));
332 g_signal_connect (page->auto_dns, "notify::active", G_CALLBACK (switch_toggled), page);
333
334 page->dns_entry = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "dns_entry"));
335 entry = GTK_ENTRY (page->dns_entry);
336 string = g_string_new ("");
337
338 for (i = 0; i < nm_setting_ip_config_get_num_dns (page->setting); i++) {
339 const char *address;
340
341 address = nm_setting_ip_config_get_dns (page->setting, i);
342
343 if (i > 0)
344 g_string_append (string, ", ");
345
346 g_string_append (string, address);
347 }
348
349 gtk_entry_set_text (entry, string->str);
350
351 g_signal_connect_swapped (entry, "notify::text", G_CALLBACK (ce_page_changed), page);
352
353 g_string_free (string, TRUE);
354}
355
356static void
357add_route_row (CEPageIP4 *page,
358 const gchar *address,
359 const gchar *netmask,
360 const gchar *gateway,
361 gint metric)
362{
363 GtkSizeGroup *group;
364 GtkWidget *row;
365 GtkWidget *row_box;
366 GtkWidget *widget;
367 GtkWidget *delete_button;
368 GtkWidget *image;
369
370 row = gtk_list_box_row_new ();
371
372 row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
373 gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
374
375 widget = gtk_entry_new ();
376 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
377 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page);
378 g_object_set_data (G_OBJECT (row), "address", widget);
379 gtk_entry_set_text (GTK_ENTRY (widget), address);
380 gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
381 gtk_widget_set_hexpand (widget, TRUE);
382 gtk_container_add (GTK_CONTAINER (row_box), widget);
383
384 widget = gtk_entry_new ();
385 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
386 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page);
387 g_object_set_data (G_OBJECT (row), "netmask", widget);
388 gtk_entry_set_text (GTK_ENTRY (widget), netmask);
389 gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
390 gtk_widget_set_hexpand (widget, TRUE);
391 gtk_container_add (GTK_CONTAINER (row_box), widget);
392
393 widget = gtk_entry_new ();
394 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
395 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page);
396 g_object_set_data (G_OBJECT (row), "gateway", widget);
397 gtk_entry_set_text (GTK_ENTRY (widget), gateway);
398 gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
399 gtk_widget_set_hexpand (widget, TRUE);
400 gtk_container_add (GTK_CONTAINER (row_box), widget);
401
402 widget = gtk_entry_new ();
403 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
404 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page);
405 g_object_set_data (G_OBJECT (row), "metric", widget);
406 if (metric >= 0) {
407 gchar *s = g_strdup_printf ("%d", metric);
408 gtk_entry_set_text (GTK_ENTRY (widget), s);
409 g_free (s);
410 }
411 gtk_entry_set_width_chars (GTK_ENTRY (widget), 5);
412 gtk_widget_set_hexpand (widget, TRUE);
413 gtk_container_add (GTK_CONTAINER (row_box), widget);
414
415 group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_metric_sizegroup"));
416 gtk_size_group_add_widget (group, widget);
417
418 delete_button = gtk_button_new ();
419 gtk_style_context_add_class (gtk_widget_get_style_context (delete_button), "image-button");
420 g_signal_connect (delete_button, "clicked", G_CALLBACK (remove_row), page);
421 image = gtk_image_new_from_icon_name ("edit-delete-symbolic", GTK_ICON_SIZE_MENU);
422 atk_object_set_name (gtk_widget_get_accessible (delete_button), _("Delete Route"));
423 gtk_button_set_image (GTK_BUTTON (delete_button), image);
424 gtk_widget_set_halign (delete_button, GTK_ALIGN_CENTER);
425 gtk_widget_set_valign (delete_button, GTK_ALIGN_CENTER);
426 gtk_container_add (GTK_CONTAINER (row_box), delete_button);
427 g_object_set_data (G_OBJECT (row), "delete-button", delete_button);
428
429 group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_sizegroup"));
430 gtk_size_group_add_widget (group, delete_button);
431
432 gtk_container_add (GTK_CONTAINER (row), row_box);
433 gtk_widget_show_all (row);
434 gtk_container_add (GTK_CONTAINER (page->routes_list), row);
435
436 update_row_sensitivity (page, page->routes_list);
437}
438
439static void
440ensure_empty_routes_row (CEPageIP4 *page)
441{
442 GList *children, *l;
443
444 children = gtk_container_get_children (GTK_CONTAINER (page->routes_list));
445 l = children;
446
447 while (l && l->next)
448 l = l->next;
449
450 /* Add the last, stub row if needed*/
451 if (!l || validate_row (l->data))
452 add_route_row (page, "", "", "", -1);
453
454 g_list_free (children);
455}
456
457static void
458add_routes_section (CEPageIP4 *page)
459{
460 GtkWidget *widget;
461 GtkWidget *list;
462 gint i;
463
464 widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_section"));
465
466 page->routes_list = list = gtk_list_box_new ();
467 gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
468 gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL);
469 gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL);
470 gtk_container_add (GTK_CONTAINER (widget), list);
471 page->auto_routes = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_routes_switch"));
472 gtk_switch_set_active (page->auto_routes, !nm_setting_ip_config_get_ignore_auto_routes (page->setting));
473 g_signal_connect (page->auto_routes, "notify::active", G_CALLBACK (switch_toggled), page);
474
475
476 for (i = 0; i < nm_setting_ip_config_get_num_routes (page->setting); i++) {
477 NMIPRoute *route;
478 struct in_addr tmp_addr;
479 gchar netmask[INET_ADDRSTRLEN + 1];
480
481 route = nm_setting_ip_config_get_route (page->setting, i);
482 if (!route)
483 continue;
484
485 tmp_addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip_route_get_prefix (route));
486 (void) inet_ntop (AF_INET, &tmp_addr, &netmask[0], sizeof (netmask));
487
488 add_route_row (page,
489 nm_ip_route_get_dest (route),
490 netmask,
491 nm_ip_route_get_next_hop (route),
492 nm_ip_route_get_metric (route));
493 }
494 if (nm_setting_ip_config_get_num_routes (page->setting) == 0)
495 ensure_empty_routes_row (page);
496
497 gtk_widget_show_all (widget);
498}
499
500enum
501{
502 RADIO_AUTOMATIC,
503 RADIO_LOCAL,
504 RADIO_MANUAL,
505 RADIO_DISABLED,
506 N_RADIO
507};
508
509static void
510connect_ip4_page (CEPageIP4 *page)
511{
512 GtkToggleButton *radios[N_RADIO];
513 GtkWidget *content;
514 const gchar *str_method;
515 gboolean disabled;
516 guint method, i;
517
518 add_address_section (page);
519 add_dns_section (page);
520 add_routes_section (page);
521
522 page->disabled = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_disabled"));
523
524 str_method = nm_setting_ip_config_get_method (page->setting);
525 disabled = g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0;
526 gtk_toggle_button_set_active (page->disabled, disabled);
527 g_signal_connect_swapped (page->disabled, "notify::active", G_CALLBACK (ce_page_changed), page);
528 content = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "page_content"));
529 g_object_bind_property (page->disabled, "active",
530 content, "sensitive",
531 G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
532
533 method = IP4_METHOD_AUTO;
534 if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) == 0) {
535 method = IP4_METHOD_LINK_LOCAL;
536 } else if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0) {
537 method = IP4_METHOD_MANUAL;
538 } else if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) {
539 method = IP4_METHOD_SHARED;
540 } else if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0) {
541 method = IP4_METHOD_DISABLED;
542 }
543
544 page->never_default = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "never_default_check"));
545 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->never_default),
546 nm_setting_ip_config_get_never_default (page->setting));
547 g_signal_connect_swapped (page->never_default, "toggled", G_CALLBACK (ce_page_changed), page);
548
549 /* Connect radio buttons */
550 radios[RADIO_AUTOMATIC] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_automatic"));
551 radios[RADIO_LOCAL] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_local"));
552 radios[RADIO_MANUAL] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_manual"));
553 radios[RADIO_DISABLED] = page->disabled;
554
555 for (i = RADIO_AUTOMATIC; i < RADIO_DISABLED; i++)
556 g_signal_connect (radios[i], "toggled", G_CALLBACK (method_changed), page);
557
558 switch (method) {
559 case IP4_METHOD_AUTO:
560 gtk_toggle_button_set_active (radios[RADIO_AUTOMATIC], TRUE);
561 break;
562 case IP4_METHOD_LINK_LOCAL:
563 gtk_toggle_button_set_active (radios[RADIO_LOCAL], TRUE);
564 break;
565 case IP4_METHOD_MANUAL:
566 gtk_toggle_button_set_active (radios[RADIO_MANUAL], TRUE);
567 break;
568 case IP4_METHOD_DISABLED:
569 gtk_toggle_button_set_active (radios[RADIO_DISABLED], TRUE);
570 break;
571 default:
572 break;
573 }
574
575 method_changed (NULL, page);
576}
577
578static gboolean
579parse_netmask (const char *str, guint32 *prefix)
580{
581 struct in_addr tmp_addr;
582 glong tmp_prefix;
583
584 errno = 0;
585
586 /* Is it a prefix? */
587 if (!strchr (str, '.')) {
588 tmp_prefix = strtol (str, NULL, 10);
589 if (!errno && tmp_prefix >= 0 && tmp_prefix <= 32) {
590 *prefix = tmp_prefix;
591 return TRUE;
592 }
593 }
594
595 /* Is it a netmask? */
596 if (inet_pton (AF_INET, str, &tmp_addr) > 0) {
597 *prefix = nm_utils_ip4_netmask_to_prefix (tmp_addr.s_addr);
598 return TRUE;
599 }
600
601 return FALSE;
602}
603
604static gboolean
605ui_to_setting (CEPageIP4 *page)
606{
607 const gchar *method;
608 gboolean ignore_auto_dns;
609 gboolean ignore_auto_routes;
610 gboolean never_default;
611 GPtrArray *addresses = NULL;
612 GPtrArray *dns_servers = NULL;
613 GPtrArray *routes = NULL;
614 GStrv dns_addresses = NULL;
615 GList *children, *l;
616 gboolean ret = TRUE;
617 const char *default_gateway = NULL;
618 gchar *dns_text = NULL;
619 guint i;
620
621 if (gtk_toggle_button_get_active (page->disabled)) {
622 method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
623 } else {
624 if (RADIO_IS_ACTIVE ("radio_automatic"))
625 method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
626 else if (RADIO_IS_ACTIVE ("radio_local"))
627 method = NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL;
628 else if (RADIO_IS_ACTIVE ("radio_manual"))
629 method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
630 }
631
632 addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
633 if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
634 children = gtk_container_get_children (GTK_CONTAINER (page->address_list));
635 else
636 children = NULL;
637
638 for (l = children; l; l = l->next) {
639 GtkWidget *row = l->data;
640 GtkEntry *entry;
641 GtkEntry *gateway_entry;
642 const gchar *text_address;
643 const gchar *text_netmask;
644 const gchar *text_gateway = "";
645 NMIPAddress *addr;
646 guint32 prefix;
647
648 entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
649 if (!entry)
650 continue;
651
652 text_address = gtk_entry_get_text (entry);
653 text_netmask = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "network")));
654 gateway_entry = g_object_get_data (G_OBJECT (row), "gateway");
655 if (gtk_widget_is_visible (GTK_WIDGET (gateway_entry)))
656 text_gateway = gtk_entry_get_text (gateway_entry);
657
658 if (!*text_address && !*text_netmask && !*text_gateway) {
659 /* ignore empty rows */
660 widget_unset_error (GTK_WIDGET (entry));
661 widget_unset_error (g_object_get_data (G_OBJECT (row), "network"));
662 widget_unset_error (GTK_WIDGET (gateway_entry));
663 continue;
664 }
665
666 if (!nm_utils_ipaddr_valid (AF_INET, text_address)) {
667 widget_set_error (GTK_WIDGET (entry));
668 ret = FALSE;
669 } else {
670 widget_unset_error (GTK_WIDGET (entry));
671 }
672
673 if (!parse_netmask (text_netmask, &prefix)) {
674 widget_set_error (g_object_get_data (G_OBJECT (row), "network"));
675 ret = FALSE;
676 } else {
677 widget_unset_error (g_object_get_data (G_OBJECT (row), "network"));
678 }
679
680 if (gtk_widget_is_visible (GTK_WIDGET (gateway_entry)) &&
681 *text_gateway &&
682 !nm_utils_ipaddr_valid (AF_INET, text_gateway)) {
683 widget_set_error (g_object_get_data (G_OBJECT (row), "gateway"));
684 ret = FALSE;
685 } else {
686 widget_unset_error (GTK_WIDGET (gateway_entry));
687 if (gtk_widget_is_visible (GTK_WIDGET (gateway_entry)) && *text_gateway) {
688 g_assert (default_gateway == NULL);
689 default_gateway = text_gateway;
690 }
691 }
692
693 if (!ret)
694 continue;
695
696 addr = nm_ip_address_new (AF_INET, text_address, prefix, NULL);
697 if (addr)
698 g_ptr_array_add (addresses, addr);
699
700 if (!l || !l->next)
701 ensure_empty_address_row (page);
702 }
703 g_list_free (children);
704
705 if (addresses->len == 0) {
706 g_ptr_array_free (addresses, TRUE);
707 addresses = NULL;
708 }
709
710 dns_servers = g_ptr_array_new_with_free_func (g_free);
711 dns_text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (page->dns_entry))));
712 if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) ||
713 g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
714 dns_addresses = g_strsplit_set (dns_text, ", ", -1);
715 else
716 dns_addresses = NULL;
717
718 for (i = 0; dns_addresses && dns_addresses[i]; i++) {
719 const gchar *text;
720
721 text = dns_addresses[i];
722
723 if (!text || !*text)
724 continue;
725
726 if (!nm_utils_ipaddr_valid (AF_INET, text)) {
727 g_ptr_array_remove_range (dns_servers, 0, dns_servers->len);
728 widget_set_error (page->dns_entry);
729 ret = FALSE;
730 break;
731 } else {
732 widget_unset_error (page->dns_entry);
733 g_ptr_array_add (dns_servers, g_strdup (text));
734 }
735 }
736 g_clear_pointer (&dns_addresses, g_strfreev);
737
738 if (dns_servers->len == 0) {
739 g_ptr_array_free (dns_servers, TRUE);
740 dns_servers = NULL;
741 } else {
742 g_ptr_array_add (dns_servers, NULL);
743 }
744
745 routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
746 if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) ||
747 g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
748 children = gtk_container_get_children (GTK_CONTAINER (page->routes_list));
749 else
750 children = NULL;
751
752 for (l = children; l; l = l->next) {
753 GtkWidget *row = l->data;
754 GtkEntry *entry;
755 const gchar *text_address;
756 const gchar *text_netmask;
757 const gchar *text_gateway;
758 const gchar *text_metric;
759 gint64 metric;
760 guint32 netmask;
761 NMIPRoute *route;
762
763 entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
764 if (!entry)
765 continue;
766
767 text_address = gtk_entry_get_text (entry);
768 text_netmask = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "netmask")));
769 text_gateway = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "gateway")));
770 text_metric = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "metric")));
771
772 if (!*text_address && !*text_netmask && !*text_gateway && !*text_metric) {
773 /* ignore empty rows */
774 continue;
775 }
776
777 if (text_address && !nm_utils_ipaddr_valid (AF_INET, text_address)) {
778 widget_set_error (GTK_WIDGET (entry));
779 ret = FALSE;
780 } else {
781 widget_unset_error (GTK_WIDGET (entry));
782 }
783
784 if (!parse_netmask (text_netmask, &netmask)) {
785 widget_set_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "netmask")));
786 ret = FALSE;
787 } else {
788 widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "netmask")));
789 }
790
791 if (text_gateway && !nm_utils_ipaddr_valid (AF_INET, text_gateway)) {
792 widget_set_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "gateway")));
793 ret = FALSE;
794 } else {
795 widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "gateway")));
796 }
797
798 metric = -1;
799 if (*text_metric) {
800 errno = 0;
801 metric = g_ascii_strtoull (text_metric, NULL, 10);
802 if (errno || metric < 0 || metric > G_MAXUINT32) {
803 widget_set_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "metric")));
804 ret = FALSE;
805 } else {
806 widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "metric")));
807 }
808 } else {
809 widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "metric")));
810 }
811
812 if (!ret)
813 continue;
814
815 route = nm_ip_route_new (AF_INET, text_address, netmask, text_gateway, metric, NULL);
816 if (route)
817 g_ptr_array_add (routes, route);
818
819 if (!l || !l->next)
820 ensure_empty_routes_row (page);
821 }
822 g_list_free (children);
823
824 if (routes->len == 0) {
825 g_ptr_array_free (routes, TRUE);
826 routes = NULL;
827 }
828
829 if (!ret)
830 goto out;
831
832 ignore_auto_dns = !gtk_switch_get_active (page->auto_dns);
833 ignore_auto_routes = !gtk_switch_get_active (page->auto_routes);
834 never_default = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (page->never_default));
835
836 g_object_set (page->setting,
837 NM_SETTING_IP_CONFIG_METHOD, method,
838 NM_SETTING_IP_CONFIG_ADDRESSES, addresses,
839 NM_SETTING_IP_CONFIG_GATEWAY, default_gateway,
840 NM_SETTING_IP_CONFIG_DNS, dns_servers ? dns_servers->pdata : NULL,
841 NM_SETTING_IP_CONFIG_ROUTES, routes,
842 NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns,
843 NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, ignore_auto_routes,
844 NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default,
845 NULL);
846
847out:
848 if (addresses)
849 g_ptr_array_free (addresses, TRUE);
850
851 if (dns_servers)
852 g_ptr_array_free (dns_servers, TRUE);
853
854 if (routes)
855 g_ptr_array_free (routes, TRUE);
856
857 g_clear_pointer (&dns_text, g_free);
858
859 return ret;
860}
861
862static gboolean
863validate (CEPage *page,
864 NMConnection *connection,
865 GError **error)
866{
867 if (!ui_to_setting (CE_PAGE_IP4 (page)))
868 return FALSE;
869
870 return nm_setting_verify (NM_SETTING (CE_PAGE_IP4 (page)->setting), NULL, error);
871}
872
873static void
874ce_page_ip4_init (CEPageIP4 *page)
875{
876}
877
878static void
879ce_page_ip4_class_init (CEPageIP4Class *class)
880{
881 CEPageClass *page_class= CE_PAGE_CLASS (class);
882
883 page_class->validate = validate;
884}
885
886CEPage *
887ce_page_ip4_new (NMConnection *connection,
888 NMClient *client)
889{
890 CEPageIP4 *page;
891
892 page = CE_PAGE_IP4 (ce_page_new (CE_TYPE_PAGE_IP4,
893 connection,
894 client,
895 "/org/gnome/control-center/network/ip4-page.ui",
896 _("IPv4")));
897
898 page->setting = nm_connection_get_setting_ip4_config (connection);
899 if (!page->setting) {
900 page->setting = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
901 nm_connection_add_setting (connection, NM_SETTING (page->setting));
902 }
903
904 connect_ip4_page (page);
905
906 return CE_PAGE (page);
907}
0908
=== added file 'panels/network/connection-editor/ce-page-ip4.h'
--- panels/network/connection-editor/ce-page-ip4.h 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/ce-page-ip4.h 2019-05-01 13:56:52 +0000
@@ -0,0 +1,70 @@
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2012 Red Hat, Inc.
4 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more ip4.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#ifndef __CE_PAGE_IP4_H
23#define __CE_PAGE_IP4_H
24
25#include <glib-object.h>
26
27#include <gtk/gtk.h>
28#include "ce-page.h"
29
30G_BEGIN_DECLS
31
32#define CE_TYPE_PAGE_IP4 (ce_page_ip4_get_type ())
33#define CE_PAGE_IP4(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CE_TYPE_PAGE_IP4, CEPageIP4))
34#define CE_PAGE_IP4_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CE_TYPE_PAGE_IP4, CEPageIP4Class))
35#define CE_IS_PAGE_IP4(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CE_TYPE_PAGE_IP4))
36#define CE_IS_PAGE_IP4_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CE_TYPE_PAGE_IP4))
37#define CE_PAGE_IP4_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CE_TYPE_PAGE_IP4, CEPageIP4Class))
38
39typedef struct _CEPageIP4 CEPageIP4;
40typedef struct _CEPageIP4Class CEPageIP4Class;
41
42struct _CEPageIP4
43{
44 CEPage parent;
45
46 NMSettingIPConfig *setting;
47
48 GtkToggleButton *disabled;
49 GtkWidget *address_list;
50 GtkSwitch *auto_dns;
51 GtkWidget *dns_entry;
52 GtkSwitch *auto_routes;
53 GtkWidget *routes_list;
54 GtkWidget *never_default;
55};
56
57struct _CEPageIP4Class
58{
59 CEPageClass parent_class;
60};
61
62GType ce_page_ip4_get_type (void);
63
64CEPage *ce_page_ip4_new (NMConnection *connection,
65 NMClient *client);
66
67G_END_DECLS
68
69#endif /* __CE_PAGE_IP4_H */
70
071
=== added file 'panels/network/connection-editor/ce-page-ip6.c'
--- panels/network/connection-editor/ce-page-ip6.c 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/ce-page-ip6.c 2019-05-01 13:56:52 +0000
@@ -0,0 +1,838 @@
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2012 Red Hat, Inc
4 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#include "config.h"
23
24#include <errno.h>
25#include <stdlib.h>
26#include <arpa/inet.h>
27#include <glib-object.h>
28#include <glib/gi18n.h>
29#include <NetworkManager.h>
30
31#include "shell/list-box-helper.h"
32#include "ce-page-ip6.h"
33#include "ui-helpers.h"
34
35#define RADIO_IS_ACTIVE(x) (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object(CE_PAGE (page)->builder, x))))
36
37static void ensure_empty_address_row (CEPageIP6 *page);
38static void ensure_empty_routes_row (CEPageIP6 *page);
39
40G_DEFINE_TYPE (CEPageIP6, ce_page_ip6, CE_TYPE_PAGE)
41
42enum {
43 METHOD_COL_NAME,
44 METHOD_COL_METHOD
45};
46
47enum {
48 IP6_METHOD_AUTO,
49 IP6_METHOD_DHCP,
50 IP6_METHOD_MANUAL,
51 IP6_METHOD_LINK_LOCAL,
52 IP6_METHOD_SHARED,
53 IP6_METHOD_IGNORE
54};
55
56static void
57method_changed (GtkToggleButton *button, CEPageIP6 *page)
58{
59 gboolean addr_enabled;
60 gboolean dns_enabled;
61 gboolean routes_enabled;
62 GtkWidget *widget;
63
64 if (RADIO_IS_ACTIVE ("radio_disabled")) {
65 addr_enabled = FALSE;
66 dns_enabled = FALSE;
67 routes_enabled = FALSE;
68 } else {
69 addr_enabled = RADIO_IS_ACTIVE ("radio_manual");
70 dns_enabled = !RADIO_IS_ACTIVE ("radio_local");
71 routes_enabled = !RADIO_IS_ACTIVE ("radio_local");
72 }
73
74 widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section"));
75 gtk_widget_set_visible (widget, addr_enabled);
76 gtk_widget_set_sensitive (page->dns_entry, dns_enabled);
77 gtk_widget_set_sensitive (page->routes_list, routes_enabled);
78 gtk_widget_set_sensitive (page->never_default, routes_enabled);
79
80 ce_page_changed (CE_PAGE (page));
81}
82
83static void
84switch_toggled (GObject *object,
85 GParamSpec *pspec,
86 CEPage *page)
87{
88 ce_page_changed (page);
89}
90
91static void
92update_row_sensitivity (CEPageIP6 *page, GtkWidget *list)
93{
94 GList *children, *l;
95 gint rows = 0, i = 0;
96
97 children = gtk_container_get_children (GTK_CONTAINER (list));
98 for (l = children; l; l = l->next) {
99 GtkWidget *row = l->data;
100 GtkWidget *button;
101
102 button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "delete-button"));
103 if (button != NULL)
104 rows++;
105 }
106 for (l = children; l; l = l->next) {
107 GtkWidget *row = l->data;
108 GtkWidget *button;
109
110 button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "delete-button"));
111 if (button != NULL)
112 gtk_widget_set_sensitive (button, rows > 1 && ++i < rows);
113 }
114 g_list_free (children);
115}
116
117static void
118remove_row (GtkButton *button, CEPageIP6 *page)
119{
120 GtkWidget *row;
121 GtkWidget *row_box;
122 GtkWidget *list;
123
124 row_box = gtk_widget_get_parent (GTK_WIDGET (button));
125 row = gtk_widget_get_parent (row_box);
126 list = gtk_widget_get_parent (row);
127
128 gtk_container_remove (GTK_CONTAINER (list), row);
129
130 ce_page_changed (CE_PAGE (page));
131
132 update_row_sensitivity (page, list);
133}
134
135static gboolean
136validate_row (GtkWidget *row)
137{
138 GtkWidget *box;
139 GList *children, *l;
140 gboolean valid;
141
142 valid = FALSE;
143 box = gtk_bin_get_child (GTK_BIN (row));
144 children = gtk_container_get_children (GTK_CONTAINER (box));
145
146 for (l = children; l != NULL; l = l->next) {
147 if (!GTK_IS_ENTRY (l->data))
148 continue;
149
150 valid = valid || gtk_entry_get_text_length (l->data) > 0;
151 }
152
153 g_list_free (children);
154
155 return valid;
156}
157
158static gint
159sort_first_last (gconstpointer a, gconstpointer b, gpointer data)
160{
161 gboolean afirst, bfirst, alast, blast;
162
163 afirst = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (a), "first"));
164 bfirst = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (b), "first"));
165 alast = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (a), "last"));
166 blast = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (b), "last"));
167
168 if (afirst)
169 return -1;
170 if (bfirst)
171 return 1;
172 if (alast)
173 return 1;
174 if (blast)
175 return -1;
176
177 return 0;
178}
179
180static void
181add_address_row (CEPageIP6 *page,
182 const gchar *address,
183 const gchar *network,
184 const gchar *gateway)
185{
186 GtkSizeGroup *group;
187 GtkWidget *row;
188 GtkWidget *row_box;
189 GtkWidget *widget;
190 GtkWidget *delete_button;
191 GtkWidget *image;
192
193 row = gtk_list_box_row_new ();
194
195 row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
196 gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
197
198 widget = gtk_entry_new ();
199 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
200 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page);
201 g_object_set_data (G_OBJECT (row), "address", widget);
202 gtk_entry_set_text (GTK_ENTRY (widget), address);
203 gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
204 gtk_widget_set_hexpand (widget, TRUE);
205 gtk_container_add (GTK_CONTAINER (row_box), widget);
206
207 widget = gtk_entry_new ();
208 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
209 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page);
210 g_object_set_data (G_OBJECT (row), "prefix", widget);
211 gtk_entry_set_text (GTK_ENTRY (widget), network);
212 gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
213 gtk_widget_set_hexpand (widget, TRUE);
214 gtk_container_add (GTK_CONTAINER (row_box), widget);
215
216 widget = gtk_entry_new ();
217 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
218 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page);
219 g_object_set_data (G_OBJECT (row), "gateway", widget);
220 gtk_entry_set_text (GTK_ENTRY (widget), gateway ? gateway : "");
221 gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
222 gtk_widget_set_hexpand (widget, TRUE);
223 gtk_container_add (GTK_CONTAINER (row_box), widget);
224
225 delete_button = gtk_button_new ();
226 gtk_widget_set_sensitive (delete_button, FALSE);
227 gtk_style_context_add_class (gtk_widget_get_style_context (delete_button), "image-button");
228 g_signal_connect (delete_button, "clicked", G_CALLBACK (remove_row), page);
229 image = gtk_image_new_from_icon_name ("edit-delete-symbolic", GTK_ICON_SIZE_MENU);
230 atk_object_set_name (gtk_widget_get_accessible (delete_button), _("Delete Address"));
231 gtk_button_set_image (GTK_BUTTON (delete_button), image);
232 gtk_container_add (GTK_CONTAINER (row_box), delete_button);
233 g_object_set_data (G_OBJECT (row), "delete-button", delete_button);
234
235 group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "address_sizegroup"));
236 gtk_size_group_add_widget (group, delete_button);
237
238 gtk_container_add (GTK_CONTAINER (row), row_box);
239 gtk_widget_show_all (row);
240 gtk_container_add (GTK_CONTAINER (page->address_list), row);
241
242 update_row_sensitivity (page, page->address_list);
243}
244
245static void
246ensure_empty_address_row (CEPageIP6 *page)
247{
248 GList *children, *l;
249
250 children = gtk_container_get_children (GTK_CONTAINER (page->address_list));
251 l = children;
252
253 while (l && l->next)
254 l = l->next;
255
256 /* Add the last, stub row if needed*/
257 if (!l || validate_row (l->data))
258 add_address_row (page, "", "", "");
259
260 g_list_free (children);
261}
262
263static void
264add_address_section (CEPageIP6 *page)
265{
266 GtkWidget *widget;
267 GtkWidget *list;
268 gint i;
269
270 widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section"));
271
272 page->address_list = list = gtk_list_box_new ();
273 gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
274 gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL);
275 gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL);
276 gtk_container_add (GTK_CONTAINER (widget), list);
277
278 for (i = 0; i < nm_setting_ip_config_get_num_addresses (page->setting); i++) {
279 NMIPAddress *addr;
280 char *netmask;
281
282 addr = nm_setting_ip_config_get_address (page->setting, i);
283 netmask = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr));
284 add_address_row (page, nm_ip_address_get_address (addr), netmask,
285 i == 0 ? nm_setting_ip_config_get_gateway (page->setting) : NULL);
286 g_free (netmask);
287 }
288 if (nm_setting_ip_config_get_num_addresses (page->setting) == 0)
289 ensure_empty_address_row (page);
290
291 gtk_widget_show_all (widget);
292}
293
294static void
295add_dns_section (CEPageIP6 *page)
296{
297 GtkEntry *entry;
298 GString *string;
299 gint i;
300
301 page->auto_dns = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_dns_switch"));
302 gtk_switch_set_active (page->auto_dns, !nm_setting_ip_config_get_ignore_auto_dns (page->setting));
303 g_signal_connect (page->auto_dns, "notify::active", G_CALLBACK (switch_toggled), page);
304
305 page->dns_entry = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "dns_entry"));
306 entry = GTK_ENTRY (page->dns_entry);
307 string = g_string_new ("");
308
309 for (i = 0; i < nm_setting_ip_config_get_num_dns (page->setting); i++) {
310 const char *address;
311
312 address = nm_setting_ip_config_get_dns (page->setting, i);
313
314 if (i > 0)
315 g_string_append (string, ", ");
316
317 g_string_append (string, address);
318
319 }
320
321 gtk_entry_set_text (entry, string->str);
322
323 g_signal_connect_swapped (page->dns_entry, "notify::text", G_CALLBACK (ce_page_changed), page);
324
325 g_string_free (string, TRUE);
326}
327
328static void
329add_route_row (CEPageIP6 *page,
330 const gchar *address,
331 const gchar *prefix,
332 const gchar *gateway,
333 const gchar *metric)
334{
335 GtkSizeGroup *group;
336 GtkWidget *row;
337 GtkWidget *row_box;
338 GtkWidget *widget;
339 GtkWidget *delete_button;
340 GtkWidget *image;
341
342 row = gtk_list_box_row_new ();
343
344 row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
345 gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
346
347 widget = gtk_entry_new ();
348 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
349 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page);
350 g_object_set_data (G_OBJECT (row), "address", widget);
351 gtk_entry_set_text (GTK_ENTRY (widget), address);
352 gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
353 gtk_widget_set_hexpand (widget, TRUE);
354 gtk_container_add (GTK_CONTAINER (row_box), widget);
355
356 widget = gtk_entry_new ();
357 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
358 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page);
359 g_object_set_data (G_OBJECT (row), "prefix", widget);
360 gtk_entry_set_text (GTK_ENTRY (widget), prefix ? prefix : "");
361 gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
362 gtk_widget_set_hexpand (widget, TRUE);
363 gtk_container_add (GTK_CONTAINER (row_box), widget);
364
365 widget = gtk_entry_new ();
366 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
367 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page);
368 g_object_set_data (G_OBJECT (row), "gateway", widget);
369 gtk_entry_set_text (GTK_ENTRY (widget), gateway);
370 gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
371 gtk_widget_set_hexpand (widget, TRUE);
372 gtk_container_add (GTK_CONTAINER (row_box), widget);
373
374 widget = gtk_entry_new ();
375 g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
376 g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page);
377 g_object_set_data (G_OBJECT (row), "metric", widget);
378 gtk_entry_set_text (GTK_ENTRY (widget), metric ? metric : "");
379 gtk_entry_set_width_chars (GTK_ENTRY (widget), 5);
380 gtk_widget_set_hexpand (widget, TRUE);
381 gtk_container_add (GTK_CONTAINER (row_box), widget);
382
383 group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_metric_sizegroup"));
384 gtk_size_group_add_widget (group, widget);
385
386 delete_button = gtk_button_new ();
387 gtk_style_context_add_class (gtk_widget_get_style_context (delete_button), "image-button");
388 g_signal_connect (delete_button, "clicked", G_CALLBACK (remove_row), page);
389 image = gtk_image_new_from_icon_name ("edit-delete-symbolic", GTK_ICON_SIZE_MENU);
390 atk_object_set_name (gtk_widget_get_accessible (delete_button), _("Delete Route"));
391 gtk_button_set_image (GTK_BUTTON (delete_button), image);
392 gtk_widget_set_halign (delete_button, GTK_ALIGN_CENTER);
393 gtk_widget_set_valign (delete_button, GTK_ALIGN_CENTER);
394 gtk_container_add (GTK_CONTAINER (row_box), delete_button);
395 g_object_set_data (G_OBJECT (row), "delete-button", delete_button);
396
397 group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_sizegroup"));
398 gtk_size_group_add_widget (group, delete_button);
399
400 gtk_container_add (GTK_CONTAINER (row), row_box);
401 gtk_widget_show_all (row);
402 gtk_container_add (GTK_CONTAINER (page->routes_list), row);
403
404 update_row_sensitivity (page, page->routes_list);
405}
406
407static void
408ensure_empty_routes_row (CEPageIP6 *page)
409{
410 GList *children, *l;
411
412 children = gtk_container_get_children (GTK_CONTAINER (page->routes_list));
413 l = children;
414
415 while (l && l->next)
416 l = l->next;
417
418 /* Add the last, stub row if needed*/
419 if (!l || validate_row (l->data))
420 add_route_row (page, "", NULL, "", NULL);
421
422 g_list_free (children);
423}
424
425static void
426add_empty_route_row (CEPageIP6 *page)
427{
428 add_route_row (page, "", NULL, "", NULL);
429}
430
431static void
432add_routes_section (CEPageIP6 *page)
433{
434 GtkWidget *widget;
435 GtkWidget *list;
436 gint i;
437
438 widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_section"));
439
440 page->routes_list = list = gtk_list_box_new ();
441 gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
442 gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL);
443 gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL);
444 gtk_container_add (GTK_CONTAINER (widget), list);
445 page->auto_routes = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_routes_switch"));
446 gtk_switch_set_active (page->auto_routes, !nm_setting_ip_config_get_ignore_auto_routes (page->setting));
447 g_signal_connect (page->auto_routes, "notify::active", G_CALLBACK (switch_toggled), page);
448
449 for (i = 0; i < nm_setting_ip_config_get_num_routes (page->setting); i++) {
450 NMIPRoute *route;
451 char *prefix, *metric;
452
453 route = nm_setting_ip_config_get_route (page->setting, i);
454 prefix = g_strdup_printf ("%u", nm_ip_route_get_prefix (route));
455 metric = g_strdup_printf ("%u", (guint32) MIN (0, nm_ip_route_get_metric (route)));
456 add_route_row (page, nm_ip_route_get_dest (route),
457 prefix,
458 nm_ip_route_get_next_hop (route),
459 metric);
460 g_free (prefix);
461 g_free (metric);
462 }
463 if (nm_setting_ip_config_get_num_routes (page->setting) == 0)
464 add_empty_route_row (page);
465
466 gtk_widget_show_all (widget);
467}
468
469enum
470{
471 RADIO_AUTOMATIC,
472 RADIO_DHCP,
473 RADIO_LOCAL,
474 RADIO_MANUAL,
475 RADIO_DISABLED,
476 N_RADIO
477};
478
479static void
480connect_ip6_page (CEPageIP6 *page)
481{
482 GtkToggleButton *radios[N_RADIO];
483 GtkWidget *content;
484 const gchar *str_method;
485 gboolean disabled;
486 guint method, i;
487
488 add_address_section (page);
489 add_dns_section (page);
490 add_routes_section (page);
491
492 page->disabled = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_disabled"));
493
494 str_method = nm_setting_ip_config_get_method (page->setting);
495 disabled = g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0;
496 gtk_toggle_button_set_active (page->disabled, disabled);
497 g_signal_connect_swapped (page->disabled, "notify::active", G_CALLBACK (ce_page_changed), page);
498 content = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "page_content"));
499 g_object_bind_property (page->disabled, "active",
500 content, "sensitive",
501 G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
502
503 method = IP6_METHOD_AUTO;
504 if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) {
505 method = IP6_METHOD_DHCP;
506 } else if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0) {
507 method = IP6_METHOD_LINK_LOCAL;
508 } else if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0) {
509 method = IP6_METHOD_MANUAL;
510 } else if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0) {
511 method = IP6_METHOD_SHARED;
512 } else if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0) {
513 method = IP6_METHOD_IGNORE;
514 }
515
516 page->never_default = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "never_default_check"));
517 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->never_default),
518 nm_setting_ip_config_get_never_default (page->setting));
519 g_signal_connect_swapped (page->never_default, "toggled", G_CALLBACK (ce_page_changed), page);
520
521
522 /* Connect radio buttons */
523 radios[RADIO_AUTOMATIC] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_automatic"));
524 radios[RADIO_DHCP] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_dhcp"));
525 radios[RADIO_LOCAL] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_local"));
526 radios[RADIO_MANUAL] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_manual"));
527 radios[RADIO_DISABLED] = page->disabled;
528
529 for (i = RADIO_AUTOMATIC; i < RADIO_DISABLED; i++)
530 g_signal_connect (radios[i], "toggled", G_CALLBACK (method_changed), page);
531
532 switch (method) {
533 case IP6_METHOD_AUTO:
534 gtk_toggle_button_set_active (radios[RADIO_AUTOMATIC], TRUE);
535 break;
536 case IP6_METHOD_DHCP:
537 gtk_toggle_button_set_active (radios[RADIO_DHCP], TRUE);
538 break;
539 case IP6_METHOD_LINK_LOCAL:
540 gtk_toggle_button_set_active (radios[RADIO_LOCAL], TRUE);
541 break;
542 case IP6_METHOD_MANUAL:
543 gtk_toggle_button_set_active (radios[RADIO_MANUAL], TRUE);
544 break;
545 case IP6_METHOD_IGNORE:
546 gtk_toggle_button_set_active (radios[RADIO_DISABLED], TRUE);
547 break;
548 default:
549 break;
550 }
551
552 method_changed (NULL, page);
553}
554
555static gboolean
556ui_to_setting (CEPageIP6 *page)
557{
558 const gchar *method;
559 gboolean ignore_auto_dns;
560 gboolean ignore_auto_routes;
561 gboolean never_default;
562 GList *children, *l;
563 gboolean ret = TRUE;
564 GStrv dns_addresses = NULL;
565 gchar *dns_text = NULL;
566 guint i;
567
568 if (gtk_toggle_button_get_active (page->disabled)) {
569 method = NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
570 } else {
571 if (RADIO_IS_ACTIVE ("radio_manual")) {
572 method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL;
573 } else if (RADIO_IS_ACTIVE ("radio_local")) {
574 method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL;
575 } else if (RADIO_IS_ACTIVE ("radio_dhcp")) {
576 method = NM_SETTING_IP6_CONFIG_METHOD_DHCP;
577 } else if (RADIO_IS_ACTIVE ("radio_automatic")) {
578 method = NM_SETTING_IP6_CONFIG_METHOD_AUTO;
579 }
580 }
581
582 nm_setting_ip_config_clear_addresses (page->setting);
583 if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
584 children = gtk_container_get_children (GTK_CONTAINER (page->address_list));
585 } else {
586 g_object_set (G_OBJECT (page->setting),
587 NM_SETTING_IP_CONFIG_GATEWAY, NULL,
588 NULL);
589 children = NULL;
590 }
591
592 for (l = children; l; l = l->next) {
593 GtkWidget *row = l->data;
594 GtkEntry *entry;
595 const gchar *text_address;
596 const gchar *text_prefix;
597 const gchar *text_gateway;
598 guint32 prefix;
599 gchar *end;
600 NMIPAddress *addr;
601 gboolean have_gateway = FALSE;
602
603 entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
604 if (!entry)
605 continue;
606
607 text_address = gtk_entry_get_text (entry);
608 text_prefix = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "prefix")));
609 text_gateway = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "gateway")));
610
611 if (!*text_address && !*text_prefix && !*text_gateway) {
612 /* ignore empty rows */
613 widget_unset_error (GTK_WIDGET (entry));
614 widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
615 widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway"));
616 continue;
617 }
618
619 if (!text_address || !nm_utils_ipaddr_valid (AF_INET6, text_address)) {
620 widget_set_error (GTK_WIDGET (entry));
621 ret = FALSE;
622 } else {
623 widget_unset_error (GTK_WIDGET (entry));
624 }
625
626 prefix = strtoul (text_prefix, &end, 10);
627 if (!end || *end || prefix == 0 || prefix > 128) {
628 widget_set_error (g_object_get_data (G_OBJECT (row), "prefix"));
629 ret = FALSE;
630 } else {
631 widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
632 }
633
634 if (text_gateway && !nm_utils_ipaddr_valid (AF_INET6, text_gateway)) {
635 widget_set_error (g_object_get_data (G_OBJECT (row), "gateway"));
636 ret = FALSE;
637 } else {
638 widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway"));
639 have_gateway = TRUE;
640 }
641
642 if (!ret)
643 continue;
644
645 addr = nm_ip_address_new (AF_INET6, text_address, prefix, NULL);
646 if (have_gateway)
647 g_object_set (G_OBJECT (page->setting),
648 NM_SETTING_IP_CONFIG_GATEWAY, text_gateway,
649 NULL);
650 nm_setting_ip_config_add_address (page->setting, addr);
651
652 if (!l || !l->next)
653 ensure_empty_address_row (page);
654 }
655 g_list_free (children);
656
657 nm_setting_ip_config_clear_dns (page->setting);
658 dns_text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (page->dns_entry))));
659
660 if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) ||
661 g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) ||
662 g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL))
663 dns_addresses = g_strsplit_set (dns_text, ", ", -1);
664 else
665 dns_addresses = NULL;
666
667 for (i = 0; dns_addresses && dns_addresses[i]; i++) {
668 const gchar *text;
669 struct in6_addr tmp_addr;
670
671 text = dns_addresses[i];
672
673 if (!text || !*text)
674 continue;
675
676 if (inet_pton (AF_INET6, text, &tmp_addr) <= 0) {
677 g_clear_pointer (&dns_addresses, g_strfreev);
678 widget_set_error (page->dns_entry);
679 ret = FALSE;
680 break;
681 } else {
682 widget_unset_error (page->dns_entry);
683 nm_setting_ip_config_add_dns (page->setting, text);
684 }
685 }
686
687 nm_setting_ip_config_clear_routes (page->setting);
688 if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) ||
689 g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) ||
690 g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL))
691 children = gtk_container_get_children (GTK_CONTAINER (page->routes_list));
692 else
693 children = NULL;
694
695 for (l = children; l; l = l->next) {
696 GtkWidget *row = l->data;
697 GtkEntry *entry;
698 const gchar *text_address;
699 const gchar *text_prefix;
700 const gchar *text_gateway;
701 const gchar *text_metric;
702 guint32 prefix, metric;
703 gchar *end;
704 NMIPRoute *route;
705
706 entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
707 if (!entry)
708 continue;
709
710 text_address = gtk_entry_get_text (entry);
711 text_prefix = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "prefix")));
712 text_gateway = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "gateway")));
713 text_metric = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "metric")));
714
715 if (!*text_address && !*text_prefix && !*text_gateway && !*text_metric) {
716 /* ignore empty rows */
717 widget_unset_error (GTK_WIDGET (entry));
718 widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
719 widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway"));
720 widget_unset_error (g_object_get_data (G_OBJECT (row), "metric"));
721 continue;
722 }
723
724 if (!nm_utils_ipaddr_valid (AF_INET6, text_address)) {
725 widget_set_error (GTK_WIDGET (entry));
726 ret = FALSE;
727 } else {
728 widget_unset_error (GTK_WIDGET (entry));
729 }
730
731 prefix = strtoul (text_prefix, &end, 10);
732 if (!end || *end || prefix == 0 || prefix > 128) {
733 widget_set_error (g_object_get_data (G_OBJECT (row), "prefix"));
734 ret = FALSE;
735 } else {
736 widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
737 }
738
739 if (!nm_utils_ipaddr_valid (AF_INET6, text_gateway)) {
740 widget_set_error (g_object_get_data (G_OBJECT (row), "gateway"));
741 ret = FALSE;
742 } else {
743 widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway"));
744 }
745
746 metric = 0;
747 if (*text_metric) {
748 errno = 0;
749 metric = strtoul (text_metric, NULL, 10);
750 if (errno) {
751 widget_set_error (g_object_get_data (G_OBJECT (row), "metric"));
752 ret = FALSE;
753 } else {
754 widget_unset_error (g_object_get_data (G_OBJECT (row), "metric"));
755 }
756 } else {
757 widget_unset_error (g_object_get_data (G_OBJECT (row), "metric"));
758 }
759
760 if (!ret)
761 continue;
762
763 route = nm_ip_route_new (AF_INET6, text_address, prefix, text_gateway, metric, NULL);
764 nm_setting_ip_config_add_route (page->setting, route);
765 nm_ip_route_unref (route);
766
767 if (!l || !l->next)
768 ensure_empty_routes_row (page);
769 }
770 g_list_free (children);
771
772 if (!ret)
773 goto out;
774
775 ignore_auto_dns = !gtk_switch_get_active (page->auto_dns);
776 ignore_auto_routes = !gtk_switch_get_active (page->auto_routes);
777 never_default = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (page->never_default));
778
779 g_object_set (page->setting,
780 NM_SETTING_IP_CONFIG_METHOD, method,
781 NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns,
782 NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, ignore_auto_routes,
783 NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default,
784 NULL);
785
786out:
787 g_clear_pointer (&dns_addresses, g_strfreev);
788 g_clear_pointer (&dns_text, g_free);
789
790 return ret;
791}
792
793static gboolean
794validate (CEPage *page,
795 NMConnection *connection,
796 GError **error)
797{
798 if (!ui_to_setting (CE_PAGE_IP6 (page)))
799 return FALSE;
800
801 return nm_setting_verify (NM_SETTING (CE_PAGE_IP6 (page)->setting), NULL, error);
802}
803
804static void
805ce_page_ip6_init (CEPageIP6 *page)
806{
807}
808
809static void
810ce_page_ip6_class_init (CEPageIP6Class *class)
811{
812 CEPageClass *page_class= CE_PAGE_CLASS (class);
813
814 page_class->validate = validate;
815}
816
817CEPage *
818ce_page_ip6_new (NMConnection *connection,
819 NMClient *client)
820{
821 CEPageIP6 *page;
822
823 page = CE_PAGE_IP6 (ce_page_new (CE_TYPE_PAGE_IP6,
824 connection,
825 client,
826 "/org/gnome/control-center/network/ip6-page.ui",
827 _("IPv6")));
828
829 page->setting = nm_connection_get_setting_ip6_config (connection);
830 if (!page->setting) {
831 page->setting = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ());
832 nm_connection_add_setting (connection, NM_SETTING (page->setting));
833 }
834
835 connect_ip6_page (page);
836
837 return CE_PAGE (page);
838}
0839
=== added file 'panels/network/connection-editor/ce-page-ip6.h'
--- panels/network/connection-editor/ce-page-ip6.h 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/ce-page-ip6.h 2019-05-01 13:56:52 +0000
@@ -0,0 +1,70 @@
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2012 Red Hat, Inc.
4 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more ip6.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#ifndef __CE_PAGE_IP6_H
23#define __CE_PAGE_IP6_H
24
25#include <glib-object.h>
26
27#include <gtk/gtk.h>
28#include "ce-page.h"
29
30G_BEGIN_DECLS
31
32#define CE_TYPE_PAGE_IP6 (ce_page_ip6_get_type ())
33#define CE_PAGE_IP6(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CE_TYPE_PAGE_IP6, CEPageIP6))
34#define CE_PAGE_IP6_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CE_TYPE_PAGE_IP6, CEPageIP6Class))
35#define CE_IS_PAGE_IP6(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CE_TYPE_PAGE_IP6))
36#define CE_IS_PAGE_IP6_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CE_TYPE_PAGE_IP6))
37#define CE_PAGE_IP6_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CE_TYPE_PAGE_IP6, CEPageIP6Class))
38
39typedef struct _CEPageIP6 CEPageIP6;
40typedef struct _CEPageIP6Class CEPageIP6Class;
41
42struct _CEPageIP6
43{
44 CEPage parent;
45
46 NMSettingIPConfig *setting;
47
48 GtkToggleButton *disabled;
49 GtkWidget *address_list;
50 GtkSwitch *auto_dns;
51 GtkWidget *dns_entry;
52 GtkSwitch *auto_routes;
53 GtkWidget *routes_list;
54 GtkWidget *never_default;
55};
56
57struct _CEPageIP6Class
58{
59 CEPageClass parent_class;
60};
61
62GType ce_page_ip6_get_type (void);
63
64CEPage *ce_page_ip6_new (NMConnection *connection,
65 NMClient *client);
66
67G_END_DECLS
68
69#endif /* __CE_PAGE_IP6_H */
70
071
=== added file 'panels/network/connection-editor/ce-page-security.c'
--- panels/network/connection-editor/ce-page-security.c 1970-01-01 00:00:00 +0000
+++ panels/network/connection-editor/ce-page-security.c 2019-05-01 13:56:52 +0000
@@ -0,0 +1,467 @@
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2012 Red Hat, Inc
4 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#include "config.h"
23
24#include <glib-object.h>
25#include <glib/gi18n.h>
26
27#include <NetworkManager.h>
28
29#include "wireless-security.h"
30#include "ce-page-security.h"
31
32G_DEFINE_TYPE (CEPageSecurity, ce_page_security, CE_TYPE_PAGE)
33
34enum {
35 S_NAME_COLUMN,
36 S_SEC_COLUMN,
37 S_ADHOC_VALID_COLUMN
38};
39
40static gboolean
41find_proto (NMSettingWirelessSecurity *sec, const char *item)
42{
43 guint32 i;
44
45 for (i = 0; i < nm_setting_wireless_security_get_num_protos (sec); i++) {
46 if (!strcmp (item, nm_setting_wireless_security_get_proto (sec, i)))
47 return TRUE;
48 }
49 return FALSE;
50}
51
52static NMUtilsSecurityType
53get_default_type_for_security (NMSettingWirelessSecurity *sec)
54{
55 const char *key_mgmt, *auth_alg;
56
57 g_return_val_if_fail (sec != NULL, NMU_SEC_NONE);
58
59 key_mgmt = nm_setting_wireless_security_get_key_mgmt (sec);
60 auth_alg = nm_setting_wireless_security_get_auth_alg (sec);
61
62 /* No IEEE 802.1x */
63 if (!strcmp (key_mgmt, "none"))
64 return NMU_SEC_STATIC_WEP;
65
66 if (!strcmp (key_mgmt, "ieee8021x")) {
67 if (auth_alg && !strcmp (auth_alg, "leap"))
68 return NMU_SEC_LEAP;
69 return NMU_SEC_DYNAMIC_WEP;
70 }
71
72 if ( !strcmp (key_mgmt, "wpa-none")
73 || !strcmp (key_mgmt, "wpa-psk")) {
74 if (find_proto (sec, "rsn"))
75 return NMU_SEC_WPA2_PSK;
76 else if (find_proto (sec, "wpa"))
77 return NMU_SEC_WPA_PSK;
78 else
79 return NMU_SEC_WPA_PSK;
80 }
81
82 if (!strcmp (key_mgmt, "wpa-eap")) {
83 if (find_proto (sec, "rsn"))
84 return NMU_SEC_WPA2_ENTERPRISE;
85 else if (find_proto (sec, "wpa"))
86 return NMU_SEC_WPA_ENTERPRISE;
87 else
88 return NMU_SEC_WPA_ENTERPRISE;
89 }
90
91 return NMU_SEC_INVALID;
92}
93
94static WirelessSecurity *
95security_combo_get_active (CEPageSecurity *page)
96{
97 GtkTreeIter iter;
98 GtkTreeModel *model;
99 WirelessSecurity *sec = NULL;
100
101 model = gtk_combo_box_get_model (page->security_combo);
102 gtk_combo_box_get_active_iter (page->security_combo, &iter);
103 gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
104
105 return sec;
106}
107
108static void
109wsec_size_group_clear (GtkSizeGroup *group)
110{
111 GSList *children;
112 GSList *iter;
113
114 g_return_if_fail (group != NULL);
115
116 children = gtk_size_group_get_widgets (group);
117 for (iter = children; iter; iter = g_slist_next (iter))
118 gtk_size_group_remove_widget (group, GTK_WIDGET (iter->data));
119}
120
121static void
122security_combo_changed (GtkComboBox *combo,
123 gpointer user_data)
124{
125 CEPageSecurity *page = CE_PAGE_SECURITY (user_data);
126 GtkWidget *vbox;
127 GList *l, *children;
128 WirelessSecurity *sec;
129
130 wsec_size_group_clear (page->group);
131
132 vbox = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "vbox"));
133 children = gtk_container_get_children (GTK_CONTAINER (vbox));
134 for (l = children; l; l = l->next) {
135 gtk_container_remove (GTK_CONTAINER (vbox), GTK_WIDGET (l->data));
136 }
137
138 sec = security_combo_get_active (page);
139 if (sec) {
140 GtkWidget *sec_widget;
141 GtkWidget *parent;
142
143 sec_widget = wireless_security_get_widget (sec);
144 g_assert (sec_widget);
145 parent = gtk_widget_get_parent (sec_widget);
146 if (parent)
147 gtk_container_remove (GTK_CONTAINER (parent), sec_widget);
148
149 gtk_size_group_add_widget (page->group, page->security_heading);
150 wireless_security_add_to_size_group (sec, page->group);
151
152 gtk_container_add (GTK_CONTAINER (vbox), sec_widget);
153 wireless_security_unref (sec);
154 }
155
156 ce_page_changed (CE_PAGE (page));
157}
158
159static void
160stuff_changed_cb (WirelessSecurity *sec, gpointer user_data)
161{
162 ce_page_changed (CE_PAGE (user_data));
163}
164
165static void
166add_security_item (CEPageSecurity *page,
167 WirelessSecurity *sec,
168 GtkListStore *model,
169 GtkTreeIter *iter,
170 const char *text,
171 gboolean adhoc_valid)
172{
173 wireless_security_set_changed_notify (sec, stuff_changed_cb, page);
174 gtk_list_store_append (model, iter);
175 gtk_list_store_set (model, iter,
176 S_NAME_COLUMN, text,
177 S_SEC_COLUMN, sec,
178 S_ADHOC_VALID_COLUMN, adhoc_valid,
179 -1);
180 wireless_security_unref (sec);
181}
182
183static void
184set_sensitive (GtkCellLayout *cell_layout,
185 GtkCellRenderer *cell,
186 GtkTreeModel *tree_model,
187 GtkTreeIter *iter,
188 gpointer data)
189{
190 gboolean *adhoc = data;
191 gboolean sensitive = TRUE, adhoc_valid = TRUE;
192
193 gtk_tree_model_get (tree_model, iter, S_ADHOC_VALID_COLUMN, &adhoc_valid, -1);
194 if (*adhoc && !adhoc_valid)
195 sensitive = FALSE;
196
197 g_object_set (cell, "sensitive", sensitive, NULL);
198}
199
200static void
201finish_setup (CEPageSecurity *page)
202{
203 NMConnection *connection = CE_PAGE (page)->connection;
204 NMSettingWireless *sw;
205 NMSettingWirelessSecurity *sws;
206 gboolean is_adhoc = FALSE;
207 GtkListStore *sec_model;
208 GtkTreeIter iter;
209 const gchar *mode;
210 guint32 dev_caps = 0;
211 NMUtilsSecurityType default_type = NMU_SEC_NONE;
212 int active = -1;
213 int item = 0;
214 GtkComboBox *combo;
215 GtkCellRenderer *renderer;
216
217 sw = nm_connection_get_setting_wireless (connection);
218 g_assert (sw);
219
220 page->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
221
222 page->security_heading = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "heading_sec"));
223 page->security_combo = combo = GTK_COMBO_BOX (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_sec"));
224
225 dev_caps = NM_WIFI_DEVICE_CAP_CIPHER_WEP40
226 | NM_WIFI_DEVICE_CAP_CIPHER_WEP104
227 | NM_WIFI_DEVICE_CAP_CIPHER_TKIP
228 | NM_WIFI_DEVICE_CAP_CIPHER_CCMP
229 | NM_WIFI_DEVICE_CAP_WPA
230 | NM_WIFI_DEVICE_CAP_RSN;
231
232 mode = nm_setting_wireless_get_mode (sw);
233 if (mode && !strcmp (mode, "adhoc"))
234 is_adhoc = TRUE;
235 page->adhoc = is_adhoc;
236
237 sws = nm_connection_get_setting_wireless_security (connection);
238 if (sws)
239 default_type = get_default_type_for_security (sws);
240
241 sec_model = gtk_list_store_new (3, G_TYPE_STRING, WIRELESS_TYPE_SECURITY, G_TYPE_BOOLEAN);
242
243 if (nm_utils_security_valid (NMU_SEC_NONE, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
244 gtk_list_store_insert_with_values (sec_model, &iter, -1,
245 S_NAME_COLUMN, C_("Wi-Fi/Ethernet security", "None"),
246 S_ADHOC_VALID_COLUMN, TRUE,
247 -1);
248 if (default_type == NMU_SEC_NONE)
249 active = item;
250 item++;
251 }
252
253 if (nm_utils_security_valid (NMU_SEC_STATIC_WEP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
254 WirelessSecurityWEPKey *ws_wep;
255 NMWepKeyType wep_type = NM_WEP_KEY_TYPE_KEY;
256
257 if (default_type == NMU_SEC_STATIC_WEP) {
258 sws = nm_connection_get_setting_wireless_security (connection);
259 if (sws)
260 wep_type = nm_setting_wireless_security_get_wep_key_type (sws);
261 if (wep_type == NM_WEP_KEY_TYPE_UNKNOWN)
262 wep_type = NM_WEP_KEY_TYPE_KEY;
263 }
264
265 ws_wep = ws_wep_key_new (connection, NM_WEP_KEY_TYPE_KEY, FALSE, FALSE);
266 if (ws_wep) {
267 add_security_item (page, WIRELESS_SECURITY (ws_wep), sec_model,
268 &iter, _("WEP 40/128-bit Key (Hex or ASCII)"),
269 TRUE);
270 if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (wep_type == NM_WEP_KEY_TYPE_KEY))
271 active = item;
272 item++;
273 }
274
275 ws_wep = ws_wep_key_new (connection, NM_WEP_KEY_TYPE_PASSPHRASE, FALSE, FALSE);
276 if (ws_wep) {
277 add_security_item (page, WIRELESS_SECURITY (ws_wep), sec_model,
278 &iter, _("WEP 128-bit Passphrase"), TRUE);
279 if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (wep_type == NM_WEP_KEY_TYPE_PASSPHRASE))
280 active = item;
281 item++;
282 }
283 }
284
285 if (nm_utils_security_valid (NMU_SEC_LEAP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
286 WirelessSecurityLEAP *ws_leap;
287
288 ws_leap = ws_leap_new (connection, FALSE);
289 if (ws_leap) {
290 add_security_item (page, WIRELESS_SECURITY (ws_leap), sec_model,
291 &iter, _("LEAP"), FALSE);
292 if ((active < 0) && (default_type == NMU_SEC_LEAP))
293 active = item;
294 item++;
295 }
296 }
297
298 if (nm_utils_security_valid (NMU_SEC_DYNAMIC_WEP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
299 WirelessSecurityDynamicWEP *ws_dynamic_wep;
300
301 ws_dynamic_wep = ws_dynamic_wep_new (connection, TRUE, FALSE);
302 if (ws_dynamic_wep) {
303 add_security_item (page, WIRELESS_SECURITY (ws_dynamic_wep), sec_model,
304 &iter, _("Dynamic WEP (802.1x)"), FALSE);
305 if ((active < 0) && (default_type == NMU_SEC_DYNAMIC_WEP))
306 active = item;
307 item++;
308 }
309 }
310
311 if (nm_utils_security_valid (NMU_SEC_WPA_PSK, dev_caps, FALSE, is_adhoc, 0, 0, 0) ||
312 nm_utils_security_valid (NMU_SEC_WPA2_PSK, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
313 WirelessSecurityWPAPSK *ws_wpa_psk;
314
315 ws_wpa_psk = ws_wpa_psk_new (connection, FALSE);
316 if (ws_wpa_psk) {
317 add_security_item (page, WIRELESS_SECURITY (ws_wpa_psk), sec_model,
318 &iter, _("WPA & WPA2 Personal"), FALSE);
319 if ((active < 0) && ((default_type == NMU_SEC_WPA_PSK) || (default_type == NMU_SEC_WPA2_PSK)))
320 active = item;
321 item++;
322 }
323 }
324
325 if (nm_utils_security_valid (NMU_SEC_WPA_ENTERPRISE, dev_caps, FALSE, is_adhoc, 0, 0, 0) ||
326 nm_utils_security_valid (NMU_SEC_WPA2_ENTERPRISE, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
327 WirelessSecurityWPAEAP *ws_wpa_eap;
328
329 ws_wpa_eap = ws_wpa_eap_new (connection, TRUE, FALSE);
330 if (ws_wpa_eap) {
331 add_security_item (page, WIRELESS_SECURITY (ws_wpa_eap), sec_model,
332 &iter, _("WPA & WPA2 Enterprise"), FALSE);
333 if ((active < 0) && ((default_type == NMU_SEC_WPA_ENTERPRISE) || (default_type == NMU_SEC_WPA2_ENTERPRISE)))
334 active = item;
335 item++;
336 }
337 }
338
339 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (sec_model));
340 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo));
341
342 renderer = gtk_cell_renderer_text_new ();
343 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
344 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, "text", S_NAME_COLUMN, NULL);
345 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), renderer, set_sensitive, &page->adhoc, NULL);
346
347 gtk_combo_box_set_active (combo, active < 0 ? 0 : (guint32) active);
348 g_object_unref (G_OBJECT (sec_model));
349
350 page->security_combo = combo;
351
352 security_combo_changed (combo, page);
353 g_signal_connect (combo, "changed",
354 G_CALLBACK (security_combo_changed), page);
355}
356
357static gboolean
358validate (CEPage *page,
359 NMConnection *connection,
360 GError **error)
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches