Merge lp:~khurshid-alam/unity-control-center/libnm-port into lp:unity-control-center
- libnm-port
- Merge into trunk
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 | ||||
Related bugs: |
|
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:/
Description of the change
This is a direct port from gnome-control-
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:unity7maint
Community-Thread: https:/
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:/
2) In g-c-c new VPN connections are created within the control center from 8a52138cf6e31d1
currently hit the nm-connection-
3) This also includes support for the 'ModemManager1' interface. See https:/
Preview Diff
1 | === modified file 'configure.ac' | |||
2 | --- configure.ac 2018-11-20 08:48:24 +0000 | |||
3 | +++ configure.ac 2019-05-01 13:56:52 +0000 | |||
4 | @@ -113,7 +113,9 @@ | |||
5 | 113 | CANBERRA_REQUIRED_VERSION=0.13 | 113 | CANBERRA_REQUIRED_VERSION=0.13 |
6 | 114 | GDKPIXBUF_REQUIRED_VERSION=2.23.0 | 114 | GDKPIXBUF_REQUIRED_VERSION=2.23.0 |
7 | 115 | POLKIT_REQUIRED_VERSION=0.103 | 115 | POLKIT_REQUIRED_VERSION=0.103 |
9 | 116 | NETWORK_MANAGER_REQUIRED_VERSION=0.8.992 | 116 | NETWORK_MANAGER_REQUIRED_VERSION=1.2.0 |
10 | 117 | NETWORK_MANAGER_APPLET_REQUIRED_VERSION=1.2.0 | ||
11 | 118 | MODEM_MANAGER_REQUIRED_VERSION=0.7 | ||
12 | 117 | LIBNOTIFY_REQUIRED_VERSION=0.7.3 | 119 | LIBNOTIFY_REQUIRED_VERSION=0.7.3 |
13 | 118 | GNOME_DESKTOP_REQUIRED_VERSION=3.27.3 | 120 | GNOME_DESKTOP_REQUIRED_VERSION=3.27.3 |
14 | 119 | SCHEMAS_REQUIRED_VERSION=3.15.4 | 121 | SCHEMAS_REQUIRED_VERSION=3.15.4 |
15 | @@ -149,7 +151,8 @@ | |||
16 | 149 | PKG_CHECK_MODULES(MEDIA_PANEL, $COMMON_MODULES) | 151 | PKG_CHECK_MODULES(MEDIA_PANEL, $COMMON_MODULES) |
17 | 150 | PKG_CHECK_MODULES(MOUSE_PANEL, $COMMON_MODULES xi >= 1.2 | 152 | PKG_CHECK_MODULES(MOUSE_PANEL, $COMMON_MODULES xi >= 1.2 |
18 | 151 | unity-settings-daemon x11) | 153 | unity-settings-daemon x11) |
20 | 152 | PKG_CHECK_MODULES(NETWORK_PANEL, $COMMON_MODULES) | 154 | PKG_CHECK_MODULES(NETWORK_PANEL, $COMMON_MODULES gmodule-2.0 |
21 | 155 | polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION) | ||
22 | 153 | PKG_CHECK_MODULES(POWER_PANEL, $COMMON_MODULES upower-glib >= 0.9.1 | 156 | PKG_CHECK_MODULES(POWER_PANEL, $COMMON_MODULES upower-glib >= 0.9.1 |
23 | 154 | unity-settings-daemon) | 157 | unity-settings-daemon) |
24 | 155 | PKG_CHECK_MODULES(COLOR_PANEL, $COMMON_MODULES colord >= 0.1.8) | 158 | PKG_CHECK_MODULES(COLOR_PANEL, $COMMON_MODULES colord >= 0.1.8) |
25 | @@ -182,14 +185,16 @@ | |||
26 | 182 | GDESKTOP_PREFIX=`$PKG_CONFIG --variable prefix gsettings-desktop-schemas` | 185 | GDESKTOP_PREFIX=`$PKG_CONFIG --variable prefix gsettings-desktop-schemas` |
27 | 183 | AC_SUBST(GDESKTOP_PREFIX) | 186 | AC_SUBST(GDESKTOP_PREFIX) |
28 | 184 | 187 | ||
34 | 185 | # Check for NetworkManager ~0.9 | 188 | # Check for NetworkManager ~1.2 |
35 | 186 | PKG_CHECK_MODULES(NETWORK_MANAGER, NetworkManager >= $NETWORK_MANAGER_REQUIRED_VERSION | 189 | PKG_CHECK_MODULES(NETWORK_MANAGER, |
36 | 187 | libnm-glib >= $NETWORK_MANAGER_REQUIRED_VERSION | 190 | libnm >= $NETWORK_MANAGER_REQUIRED_VERSION |
37 | 188 | libnm-util >= $NETWORK_MANAGER_REQUIRED_VERSION | 191 | libnma >= $NETWORK_MANAGER_APPLET_REQUIRED_VERSION |
38 | 189 | libnm-gtk >= $NETWORK_MANAGER_REQUIRED_VERSION, | 192 | mm-glib >= $MODEM_MANAGER_REQUIRED_VERSION, |
39 | 190 | [have_networkmanager=yes], have_networkmanager=no) | 193 | [have_networkmanager=yes], have_networkmanager=no) |
40 | 191 | if test "x$have_networkmanager" = xno ; then | 194 | if test "x$have_networkmanager" = xno ; then |
42 | 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) ***) |
43 | 196 | else | ||
44 | 197 | AC_DEFINE(BUILD_NETWORK, 1, [Define to 1 to build the Network panel]) | ||
45 | 193 | fi | 198 | fi |
46 | 194 | AM_CONDITIONAL(BUILD_NETWORK, [test x$have_networkmanager = xyes]) | 199 | AM_CONDITIONAL(BUILD_NETWORK, [test x$have_networkmanager = xyes]) |
47 | 195 | 200 | ||
48 | @@ -516,6 +521,8 @@ | |||
49 | 516 | panels/printers/Makefile | 521 | panels/printers/Makefile |
50 | 517 | panels/printers/unity-printers-panel.desktop.in | 522 | panels/printers/unity-printers-panel.desktop.in |
51 | 518 | panels/network/Makefile | 523 | panels/network/Makefile |
52 | 524 | panels/network/wireless-security/Makefile | ||
53 | 525 | panels/network/connection-editor/Makefile | ||
54 | 519 | panels/network/unity-network-panel.desktop.in | 526 | panels/network/unity-network-panel.desktop.in |
55 | 520 | panels/universal-access/Makefile | 527 | panels/universal-access/Makefile |
56 | 521 | panels/universal-access/unity-universal-access-panel.desktop.in | 528 | panels/universal-access/unity-universal-access-panel.desktop.in |
57 | 522 | 529 | ||
58 | === modified file 'debian/control' | |||
59 | --- debian/control 2019-01-09 16:51:00 +0000 | |||
60 | +++ debian/control 2019-05-01 13:56:52 +0000 | |||
61 | @@ -35,9 +35,9 @@ | |||
62 | 35 | libgtop2-dev, | 35 | libgtop2-dev, |
63 | 36 | libibus-1.0-dev (>= 1.5.0), | 36 | libibus-1.0-dev (>= 1.5.0), |
64 | 37 | libkrb5-dev, | 37 | libkrb5-dev, |
68 | 38 | libnm-glib-dev (>= 0.9) [linux-any], | 38 | libnm-dev (>= 1.2.0) [linux-any], |
69 | 39 | libnm-gtk-dev (>= 0.9) [linux-any], | 39 | libnma-dev (>= 1.2.0) [linux-any], |
70 | 40 | libnm-util-dev (>= 0.9) [linux-any], | 40 | libmm-glib-dev [linux-any], |
71 | 41 | libnotify-dev (>= 0.7.3), | 41 | libnotify-dev (>= 0.7.3), |
72 | 42 | libpolkit-gobject-1-dev (>= 0.103), | 42 | libpolkit-gobject-1-dev (>= 0.103), |
73 | 43 | libpulse-dev (>= 1:2.0), | 43 | libpulse-dev (>= 1:2.0), |
74 | 44 | 44 | ||
75 | === modified file 'panels/network/Makefile.am' | |||
76 | --- panels/network/Makefile.am 2017-04-06 13:23:05 +0000 | |||
77 | +++ panels/network/Makefile.am 2019-05-01 13:56:52 +0000 | |||
78 | @@ -1,19 +1,26 @@ | |||
79 | 1 | cappletname = network | 1 | cappletname = network |
80 | 2 | 2 | ||
82 | 3 | INCLUDES = \ | 3 | SUBDIRS = wireless-security connection-editor |
83 | 4 | |||
84 | 5 | AM_CPPFLAGS = \ | ||
85 | 4 | $(PANEL_CFLAGS) \ | 6 | $(PANEL_CFLAGS) \ |
86 | 5 | $(NETWORK_PANEL_CFLAGS) \ | 7 | $(NETWORK_PANEL_CFLAGS) \ |
87 | 6 | $(NETWORK_MANAGER_CFLAGS) \ | 8 | $(NETWORK_MANAGER_CFLAGS) \ |
88 | 7 | -DGNOMECC_UI_DIR="\"$(uidir)\"" \ | 9 | -DGNOMECC_UI_DIR="\"$(uidir)\"" \ |
89 | 8 | -DGNOMELOCALEDIR="\"$(datadir)/locale\"" \ | 10 | -DGNOMELOCALEDIR="\"$(datadir)/locale\"" \ |
90 | 9 | -DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \ | 11 | -DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \ |
91 | 12 | -I$(srcdir)/wireless-security \ | ||
92 | 10 | $(NULL) | 13 | $(NULL) |
93 | 11 | 14 | ||
94 | 12 | ccpanelsdir = $(PANELS_DIR) | 15 | ccpanelsdir = $(PANELS_DIR) |
95 | 13 | ccpanels_LTLIBRARIES = libnetwork.la | 16 | ccpanels_LTLIBRARIES = libnetwork.la |
96 | 14 | 17 | ||
97 | 18 | BUILT_SOURCES = \ | ||
98 | 19 | cc-network-resources.c \ | ||
99 | 20 | cc-network-resources.h | ||
100 | 21 | |||
101 | 15 | libnetwork_la_SOURCES = \ | 22 | libnetwork_la_SOURCES = \ |
103 | 16 | network-module.c \ | 23 | $(BUILT_SOURCES) \ |
104 | 17 | panel-common.c \ | 24 | panel-common.c \ |
105 | 18 | panel-common.h \ | 25 | panel-common.h \ |
106 | 19 | net-object.c \ | 26 | net-object.c \ |
107 | @@ -22,45 +29,31 @@ | |||
108 | 22 | net-device.h \ | 29 | net-device.h \ |
109 | 23 | net-device-wifi.c \ | 30 | net-device-wifi.c \ |
110 | 24 | net-device-wifi.h \ | 31 | net-device-wifi.h \ |
113 | 25 | net-device-wired.c \ | 32 | net-device-simple.c \ |
114 | 26 | net-device-wired.h \ | 33 | net-device-simple.h \ |
115 | 34 | net-device-ethernet.c \ | ||
116 | 35 | net-device-ethernet.h \ | ||
117 | 27 | net-device-mobile.c \ | 36 | net-device-mobile.c \ |
118 | 28 | net-device-mobile.h \ | 37 | net-device-mobile.h \ |
119 | 29 | net-vpn.c \ | 38 | net-vpn.c \ |
120 | 30 | net-vpn.h \ | 39 | net-vpn.h \ |
121 | 31 | net-proxy.c \ | 40 | net-proxy.c \ |
122 | 32 | net-proxy.h \ | 41 | net-proxy.h \ |
123 | 33 | panel-cell-renderer-mode.c \ | ||
124 | 34 | panel-cell-renderer-mode.h \ | ||
125 | 35 | panel-cell-renderer-security.c \ | ||
126 | 36 | panel-cell-renderer-security.h \ | ||
127 | 37 | panel-cell-renderer-signal.c \ | ||
128 | 38 | panel-cell-renderer-signal.h \ | ||
129 | 39 | panel-cell-renderer-separator.c \ | ||
130 | 40 | panel-cell-renderer-separator.h \ | ||
131 | 41 | panel-cell-renderer-text.c \ | ||
132 | 42 | panel-cell-renderer-text.h \ | ||
133 | 43 | panel-cell-renderer-pixbuf.c \ | ||
134 | 44 | panel-cell-renderer-pixbuf.h \ | ||
135 | 45 | network-dialogs.c \ | 42 | network-dialogs.c \ |
136 | 46 | network-dialogs.h \ | 43 | network-dialogs.h \ |
137 | 44 | network-module.c \ | ||
138 | 47 | cc-network-panel.c \ | 45 | cc-network-panel.c \ |
145 | 48 | cc-network-panel.h \ | 46 | cc-network-panel.h |
146 | 49 | rfkill-glib.c \ | 47 | |
147 | 50 | rfkill-glib.h \ | 48 | libnetwork_la_LIBADD = $(PANEL_LIBS) $(NETWORK_PANEL_LIBS) $(NETWORK_MANAGER_LIBS) $(builddir)/connection-editor/libconnection-editor.la |
148 | 51 | rfkill.h | 49 | |
143 | 52 | |||
144 | 53 | libnetwork_la_LIBADD = $(PANEL_LIBS) $(NETWORK_PANEL_LIBS) $(NETWORK_MANAGER_LIBS) | ||
149 | 54 | libnetwork_la_LDFLAGS = $(PANEL_LDFLAGS) | 50 | libnetwork_la_LDFLAGS = $(PANEL_LDFLAGS) |
150 | 55 | 51 | ||
159 | 56 | uidir = $(pkgdatadir)/ui | 52 | resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/network.gresource.xml) |
160 | 57 | dist_ui_DATA = \ | 53 | cc-network-resources.c: network.gresource.xml $(resource_files) |
161 | 58 | network-proxy.ui \ | 54 | $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name cc_network $< |
162 | 59 | network-vpn.ui \ | 55 | cc-network-resources.h: network.gresource.xml $(resource_files) |
163 | 60 | network-wifi.ui \ | 56 | $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-header --c-name cc_network $< |
156 | 61 | network-wired.ui \ | ||
157 | 62 | network-mobile.ui \ | ||
158 | 63 | network.ui | ||
164 | 64 | 57 | ||
165 | 65 | @INTLTOOL_DESKTOP_RULE@ | 58 | @INTLTOOL_DESKTOP_RULE@ |
166 | 66 | 59 | ||
167 | @@ -68,6 +61,7 @@ | |||
168 | 68 | desktop_in_files = unity-network-panel.desktop.in | 61 | desktop_in_files = unity-network-panel.desktop.in |
169 | 69 | desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) | 62 | desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) |
170 | 70 | 63 | ||
172 | 71 | CLEANFILES = $(desktop_in_files) $(desktop_DATA) | 64 | CLEANFILES = $(desktop_in_files) $(desktop_DATA) $(BUILT_SOURCES) |
173 | 65 | EXTRA_DIST = $(resource_files) network.gresource.xml | ||
174 | 72 | 66 | ||
175 | 73 | -include $(top_srcdir)/git.mk | 67 | -include $(top_srcdir)/git.mk |
176 | 74 | 68 | ||
177 | === modified file 'panels/network/cc-network-panel.c' | |||
178 | --- panels/network/cc-network-panel.c 2016-03-09 21:55:46 +0000 | |||
179 | +++ panels/network/cc-network-panel.c 2019-05-01 13:56:52 +0000 | |||
180 | @@ -2,6 +2,7 @@ | |||
181 | 2 | * | 2 | * |
182 | 3 | * Copyright (C) 2010-2012 Richard Hughes <richard@hughsie.com> | 3 | * Copyright (C) 2010-2012 Richard Hughes <richard@hughsie.com> |
183 | 4 | * Copyright (C) 2012 Thomas Bechtold <thomasbechtold@jpberlin.de> | 4 | * Copyright (C) 2012 Thomas Bechtold <thomasbechtold@jpberlin.de> |
184 | 5 | * Copyright (C) 2013 Aleksander Morgado <aleksander@gnu.org> | ||
185 | 5 | * | 6 | * |
186 | 6 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
187 | 7 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
188 | @@ -14,8 +15,7 @@ | |||
189 | 14 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. |
190 | 15 | * | 16 | * |
191 | 16 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License |
194 | 17 | * along with this program; if not, write to the Free Software | 18 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
193 | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
195 | 19 | * | 19 | * |
196 | 20 | */ | 20 | */ |
197 | 21 | 21 | ||
198 | @@ -24,25 +24,24 @@ | |||
199 | 24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
200 | 25 | 25 | ||
201 | 26 | #include "cc-network-panel.h" | 26 | #include "cc-network-panel.h" |
202 | 27 | #include "cc-network-resources.h" | ||
203 | 27 | 28 | ||
208 | 28 | #include "nm-remote-settings.h" | 29 | #include <NetworkManager.h> |
205 | 29 | #include "nm-client.h" | ||
206 | 30 | #include "nm-device.h" | ||
207 | 31 | #include "nm-device-modem.h" | ||
209 | 32 | 30 | ||
210 | 33 | #include "net-device.h" | 31 | #include "net-device.h" |
211 | 34 | #include "net-device-mobile.h" | 32 | #include "net-device-mobile.h" |
212 | 35 | #include "net-device-wifi.h" | 33 | #include "net-device-wifi.h" |
214 | 36 | #include "net-device-wired.h" | 34 | #include "net-device-ethernet.h" |
215 | 37 | #include "net-object.h" | 35 | #include "net-object.h" |
216 | 38 | #include "net-proxy.h" | 36 | #include "net-proxy.h" |
217 | 39 | #include "net-vpn.h" | 37 | #include "net-vpn.h" |
218 | 40 | 38 | ||
219 | 41 | #include "rfkill-glib.h" | ||
220 | 42 | |||
221 | 43 | #include "panel-common.h" | 39 | #include "panel-common.h" |
222 | 44 | 40 | ||
223 | 45 | #include "network-dialogs.h" | 41 | #include "network-dialogs.h" |
224 | 42 | #include "connection-editor/net-connection-editor.h" | ||
225 | 43 | |||
226 | 44 | #include <libmm-glib.h> | ||
227 | 46 | 45 | ||
228 | 47 | CC_PANEL_REGISTER (CcNetworkPanel, cc_network_panel) | 46 | CC_PANEL_REGISTER (CcNetworkPanel, cc_network_panel) |
229 | 48 | 47 | ||
230 | @@ -64,17 +63,13 @@ | |||
231 | 64 | GtkBuilder *builder; | 63 | GtkBuilder *builder; |
232 | 65 | GtkWidget *treeview; | 64 | GtkWidget *treeview; |
233 | 66 | NMClient *client; | 65 | NMClient *client; |
235 | 67 | NMRemoteSettings *remote_settings; | 66 | MMManager *modem_manager; |
236 | 68 | gboolean updating_device; | 67 | gboolean updating_device; |
237 | 69 | guint add_header_widgets_idle; | ||
238 | 70 | guint nm_warning_idle; | ||
239 | 71 | guint refresh_idle; | ||
240 | 72 | 68 | ||
241 | 73 | /* Killswitch stuff */ | 69 | /* Killswitch stuff */ |
242 | 70 | GDBusProxy *rfkill_proxy; | ||
243 | 74 | GtkWidget *kill_switch_header; | 71 | GtkWidget *kill_switch_header; |
244 | 75 | CcRfkillGlib *rfkill; | ||
245 | 76 | GtkSwitch *rfkill_switch; | 72 | GtkSwitch *rfkill_switch; |
246 | 77 | GHashTable *killswitches; | ||
247 | 78 | 73 | ||
248 | 79 | /* wireless dialog stuff */ | 74 | /* wireless dialog stuff */ |
249 | 80 | CmdlineOperation arg_operation; | 75 | CmdlineOperation arg_operation; |
250 | @@ -85,8 +80,6 @@ | |||
251 | 85 | 80 | ||
252 | 86 | enum { | 81 | enum { |
253 | 87 | PANEL_DEVICES_COLUMN_ICON, | 82 | PANEL_DEVICES_COLUMN_ICON, |
254 | 88 | PANEL_DEVICES_COLUMN_TITLE, | ||
255 | 89 | PANEL_DEVICES_COLUMN_SORT, | ||
256 | 90 | PANEL_DEVICES_COLUMN_OBJECT, | 83 | PANEL_DEVICES_COLUMN_OBJECT, |
257 | 91 | PANEL_DEVICES_COLUMN_LAST | 84 | PANEL_DEVICES_COLUMN_LAST |
258 | 92 | }; | 85 | }; |
259 | @@ -96,7 +89,7 @@ | |||
260 | 96 | PROP_ARGV | 89 | PROP_ARGV |
261 | 97 | }; | 90 | }; |
262 | 98 | 91 | ||
264 | 99 | static NetObject *find_in_model_by_id (CcNetworkPanel *panel, const gchar *id); | 92 | static NetObject *find_in_model_by_id (CcNetworkPanel *panel, const gchar *id, GtkTreeIter *iter_out); |
265 | 100 | static void handle_argv (CcNetworkPanel *panel); | 93 | static void handle_argv (CcNetworkPanel *panel); |
266 | 101 | 94 | ||
267 | 102 | static void | 95 | static void |
268 | @@ -205,27 +198,13 @@ | |||
269 | 205 | g_cancellable_cancel (priv->cancellable); | 198 | g_cancellable_cancel (priv->cancellable); |
270 | 206 | 199 | ||
271 | 207 | g_clear_object (&priv->cancellable); | 200 | g_clear_object (&priv->cancellable); |
272 | 201 | g_clear_object (&priv->rfkill_proxy); | ||
273 | 208 | g_clear_object (&priv->builder); | 202 | g_clear_object (&priv->builder); |
274 | 209 | g_clear_object (&priv->client); | 203 | g_clear_object (&priv->client); |
276 | 210 | g_clear_object (&priv->remote_settings); | 204 | g_clear_object (&priv->modem_manager); |
277 | 211 | g_clear_object (&priv->kill_switch_header); | 205 | g_clear_object (&priv->kill_switch_header); |
278 | 212 | g_clear_object (&priv->rfkill); | ||
279 | 213 | g_clear_pointer (&priv->killswitches, g_hash_table_destroy); | ||
280 | 214 | priv->rfkill_switch = NULL; | 206 | priv->rfkill_switch = NULL; |
281 | 215 | 207 | ||
282 | 216 | if (priv->refresh_idle != 0) { | ||
283 | 217 | g_source_remove (priv->refresh_idle); | ||
284 | 218 | priv->refresh_idle = 0; | ||
285 | 219 | } | ||
286 | 220 | if (priv->nm_warning_idle != 0) { | ||
287 | 221 | g_source_remove (priv->nm_warning_idle); | ||
288 | 222 | priv->nm_warning_idle = 0; | ||
289 | 223 | } | ||
290 | 224 | if (priv->add_header_widgets_idle != 0) { | ||
291 | 225 | g_source_remove (priv->add_header_widgets_idle); | ||
292 | 226 | priv->add_header_widgets_idle = 0; | ||
293 | 227 | } | ||
294 | 228 | |||
295 | 229 | G_OBJECT_CLASS (cc_network_panel_parent_class)->dispose (object); | 208 | G_OBJECT_CLASS (cc_network_panel_parent_class)->dispose (object); |
296 | 230 | } | 209 | } |
297 | 231 | 210 | ||
298 | @@ -242,7 +221,132 @@ | |||
299 | 242 | static const char * | 221 | static const char * |
300 | 243 | cc_network_panel_get_help_uri (CcPanel *panel) | 222 | cc_network_panel_get_help_uri (CcPanel *panel) |
301 | 244 | { | 223 | { |
303 | 245 | return "help:ubuntu-help/net"; | 224 | return "help:gnome-help/net"; |
304 | 225 | } | ||
305 | 226 | |||
306 | 227 | static void | ||
307 | 228 | cc_network_panel_notify_enable_active_cb (GtkSwitch *sw, | ||
308 | 229 | GParamSpec *pspec, | ||
309 | 230 | CcNetworkPanel *panel) | ||
310 | 231 | { | ||
311 | 232 | CcNetworkPanelPrivate *priv = panel->priv; | ||
312 | 233 | gboolean enable; | ||
313 | 234 | enable = gtk_switch_get_active (sw); | ||
314 | 235 | g_dbus_proxy_call (priv->rfkill_proxy, | ||
315 | 236 | "org.freedesktop.DBus.Properties.Set", | ||
316 | 237 | g_variant_new_parsed ("('org.gnome.SettingsDaemon.Rfkill'," | ||
317 | 238 | "'AirplaneMode', %v)", | ||
318 | 239 | g_variant_new_boolean (enable)), | ||
319 | 240 | G_DBUS_CALL_FLAGS_NONE, | ||
320 | 241 | -1, | ||
321 | 242 | priv->cancellable, | ||
322 | 243 | NULL, NULL); | ||
323 | 244 | } | ||
324 | 245 | |||
325 | 246 | static void | ||
326 | 247 | sync_airplane_mode_switch (CcNetworkPanel *panel) | ||
327 | 248 | { | ||
328 | 249 | GVariant *result; | ||
329 | 250 | gboolean enabled, should_show; | ||
330 | 251 | gboolean hw_enabled; | ||
331 | 252 | |||
332 | 253 | result = g_dbus_proxy_get_cached_property (panel->priv->rfkill_proxy, "HasAirplaneMode"); | ||
333 | 254 | enabled = g_variant_get_boolean (result); | ||
334 | 255 | |||
335 | 256 | result = g_dbus_proxy_get_cached_property (panel->priv->rfkill_proxy, "ShouldShowAirplaneMode"); | ||
336 | 257 | should_show = g_variant_get_boolean (result); | ||
337 | 258 | |||
338 | 259 | gtk_widget_set_visible (GTK_WIDGET (panel->priv->kill_switch_header), enabled && should_show); | ||
339 | 260 | if (!enabled || !should_show) | ||
340 | 261 | return; | ||
341 | 262 | |||
342 | 263 | result = g_dbus_proxy_get_cached_property (panel->priv->rfkill_proxy, "AirplaneMode"); | ||
343 | 264 | enabled = g_variant_get_boolean (result); | ||
344 | 265 | |||
345 | 266 | result = g_dbus_proxy_get_cached_property (panel->priv->rfkill_proxy, "HardwareAirplaneMode"); | ||
346 | 267 | hw_enabled = !!g_variant_get_boolean (result); | ||
347 | 268 | |||
348 | 269 | enabled |= hw_enabled; | ||
349 | 270 | |||
350 | 271 | if (enabled != gtk_switch_get_active (panel->priv->rfkill_switch)) { | ||
351 | 272 | g_signal_handlers_block_by_func (panel->priv->rfkill_switch, | ||
352 | 273 | cc_network_panel_notify_enable_active_cb, | ||
353 | 274 | panel); | ||
354 | 275 | gtk_switch_set_active (panel->priv->rfkill_switch, enabled); | ||
355 | 276 | g_signal_handlers_unblock_by_func (panel->priv->rfkill_switch, | ||
356 | 277 | cc_network_panel_notify_enable_active_cb, | ||
357 | 278 | panel); | ||
358 | 279 | } | ||
359 | 280 | |||
360 | 281 | gtk_widget_set_sensitive (GTK_WIDGET (panel->priv->rfkill_switch), !hw_enabled); | ||
361 | 282 | } | ||
362 | 283 | |||
363 | 284 | static void | ||
364 | 285 | on_property_change (GDBusProxy *proxy, | ||
365 | 286 | GVariant *changed_properties, | ||
366 | 287 | GVariant *invalidated_properties, | ||
367 | 288 | gpointer user_data) | ||
368 | 289 | { | ||
369 | 290 | sync_airplane_mode_switch (CC_NETWORK_PANEL (user_data)); | ||
370 | 291 | } | ||
371 | 292 | |||
372 | 293 | static void | ||
373 | 294 | got_rfkill_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) | ||
374 | 295 | { | ||
375 | 296 | GError *error = NULL; | ||
376 | 297 | CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data); | ||
377 | 298 | |||
378 | 299 | panel->priv->rfkill_proxy = g_dbus_proxy_new_for_bus_finish (res, &error); | ||
379 | 300 | if (panel->priv->rfkill_proxy == NULL) { | ||
380 | 301 | g_printerr ("Error creating rfkill proxy: %s\n", error->message); | ||
381 | 302 | g_error_free (error); | ||
382 | 303 | return; | ||
383 | 304 | } | ||
384 | 305 | |||
385 | 306 | g_signal_connect (panel->priv->rfkill_proxy, "g-properties-changed", | ||
386 | 307 | G_CALLBACK (on_property_change), panel); | ||
387 | 308 | sync_airplane_mode_switch (panel); | ||
388 | 309 | } | ||
389 | 310 | |||
390 | 311 | static void | ||
391 | 312 | cc_network_panel_constructed (GObject *object) | ||
392 | 313 | { | ||
393 | 314 | CcNetworkPanel *panel = CC_NETWORK_PANEL (object); | ||
394 | 315 | GtkWidget *box; | ||
395 | 316 | GtkWidget *label; | ||
396 | 317 | GtkWidget *widget; | ||
397 | 318 | |||
398 | 319 | G_OBJECT_CLASS (cc_network_panel_parent_class)->constructed (object); | ||
399 | 320 | |||
400 | 321 | /* add kill switch widgets */ | ||
401 | 322 | box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); | ||
402 | 323 | /* TRANSLATORS: this is to disable the radio hardware in the | ||
403 | 324 | * network panel */ | ||
404 | 325 | label = gtk_label_new_with_mnemonic (_("Air_plane Mode")); | ||
405 | 326 | gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); | ||
406 | 327 | gtk_widget_set_visible (label, TRUE); | ||
407 | 328 | widget = gtk_switch_new (); | ||
408 | 329 | gtk_widget_set_valign (widget, GTK_ALIGN_CENTER); | ||
409 | 330 | gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget); | ||
410 | 331 | gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 4); | ||
411 | 332 | gtk_widget_show_all (box); | ||
412 | 333 | panel->priv->rfkill_switch = GTK_SWITCH (widget); | ||
413 | 334 | cc_shell_embed_widget_in_header (cc_panel_get_shell (CC_PANEL (panel)), box); | ||
414 | 335 | panel->priv->kill_switch_header = g_object_ref (box); | ||
415 | 336 | |||
416 | 337 | g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, | ||
417 | 338 | G_DBUS_PROXY_FLAGS_NONE, | ||
418 | 339 | NULL, | ||
419 | 340 | "org.gnome.SettingsDaemon.Rfkill", | ||
420 | 341 | "/org/gnome/SettingsDaemon/Rfkill", | ||
421 | 342 | "org.gnome.SettingsDaemon.Rfkill", | ||
422 | 343 | panel->priv->cancellable, | ||
423 | 344 | got_rfkill_proxy_cb, | ||
424 | 345 | panel); | ||
425 | 346 | |||
426 | 347 | g_signal_connect (panel->priv->rfkill_switch, "notify::active", | ||
427 | 348 | G_CALLBACK (cc_network_panel_notify_enable_active_cb), | ||
428 | 349 | panel); | ||
429 | 246 | } | 350 | } |
430 | 247 | 351 | ||
431 | 248 | static void | 352 | static void |
432 | @@ -259,6 +363,7 @@ | |||
433 | 259 | object_class->set_property = cc_network_panel_set_property; | 363 | object_class->set_property = cc_network_panel_set_property; |
434 | 260 | object_class->dispose = cc_network_panel_dispose; | 364 | object_class->dispose = cc_network_panel_dispose; |
435 | 261 | object_class->finalize = cc_network_panel_finalize; | 365 | object_class->finalize = cc_network_panel_finalize; |
436 | 366 | object_class->constructed = cc_network_panel_constructed; | ||
437 | 262 | 367 | ||
438 | 263 | g_object_class_override_property (object_class, PROP_ARGV, "argv"); | 368 | g_object_class_override_property (object_class, PROP_ARGV, "argv"); |
439 | 264 | } | 369 | } |
440 | @@ -333,16 +438,140 @@ | |||
441 | 333 | if (g_strcmp0 (net_object_get_id (object), | 438 | if (g_strcmp0 (net_object_get_id (object), |
442 | 334 | net_object_get_id (object_tmp)) == 0) { | 439 | net_object_get_id (object_tmp)) == 0) { |
443 | 335 | g_object_unref (object_tmp); | 440 | g_object_unref (object_tmp); |
448 | 336 | if (!gtk_list_store_remove (GTK_LIST_STORE (model), &iter)) | 441 | if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter)) { |
449 | 337 | gtk_tree_model_get_iter_first (model, &iter); | 442 | if (gtk_tree_model_get_iter_first (model, &iter)) |
450 | 338 | gtk_tree_selection_select_iter (selection, &iter); | 443 | gtk_tree_selection_select_iter (selection, &iter); |
451 | 339 | 444 | } | |
452 | 340 | break; | 445 | break; |
453 | 341 | } | 446 | } |
454 | 342 | g_object_unref (object_tmp); | 447 | g_object_unref (object_tmp); |
455 | 343 | } while (gtk_tree_model_iter_next (model, &iter)); | 448 | } while (gtk_tree_model_iter_next (model, &iter)); |
456 | 344 | } | 449 | } |
457 | 345 | 450 | ||
458 | 451 | GPtrArray * | ||
459 | 452 | cc_network_panel_get_devices (CcNetworkPanel *panel) | ||
460 | 453 | { | ||
461 | 454 | GPtrArray *devices; | ||
462 | 455 | GtkTreeModel *model; | ||
463 | 456 | GtkTreeIter iter; | ||
464 | 457 | NetObject *object; | ||
465 | 458 | |||
466 | 459 | devices = g_ptr_array_new_with_free_func (g_object_unref); | ||
467 | 460 | |||
468 | 461 | model = GTK_TREE_MODEL (gtk_builder_get_object (panel->priv->builder, | ||
469 | 462 | "liststore_devices")); | ||
470 | 463 | if (!gtk_tree_model_get_iter_first (model, &iter)) | ||
471 | 464 | return devices; | ||
472 | 465 | |||
473 | 466 | do { | ||
474 | 467 | gtk_tree_model_get (model, &iter, | ||
475 | 468 | PANEL_DEVICES_COLUMN_OBJECT, &object, | ||
476 | 469 | -1); | ||
477 | 470 | if (NET_IS_DEVICE (object)) | ||
478 | 471 | g_ptr_array_add (devices, object); | ||
479 | 472 | else | ||
480 | 473 | g_object_unref (object); | ||
481 | 474 | } while (gtk_tree_model_iter_next (model, &iter)); | ||
482 | 475 | |||
483 | 476 | return devices; | ||
484 | 477 | } | ||
485 | 478 | |||
486 | 479 | static gint | ||
487 | 480 | panel_net_object_get_sort_category (NetObject *net_object) | ||
488 | 481 | { | ||
489 | 482 | if (NET_IS_DEVICE (net_object)) { | ||
490 | 483 | return panel_device_get_sort_category (net_device_get_nm_device (NET_DEVICE (net_object))); | ||
491 | 484 | } else if (NET_IS_PROXY (net_object)) { | ||
492 | 485 | return 9; | ||
493 | 486 | } else if (NET_IS_VPN (net_object)) { | ||
494 | 487 | return 5; | ||
495 | 488 | } | ||
496 | 489 | |||
497 | 490 | g_assert_not_reached (); | ||
498 | 491 | } | ||
499 | 492 | |||
500 | 493 | static gint | ||
501 | 494 | panel_net_object_sort_func (GtkTreeModel *model, GtkTreeIter *a, | ||
502 | 495 | GtkTreeIter *b, void *data) | ||
503 | 496 | { | ||
504 | 497 | g_autoptr(NetObject) obj_a = NULL; | ||
505 | 498 | g_autoptr(NetObject) obj_b = NULL; | ||
506 | 499 | gint cat_a, cat_b; | ||
507 | 500 | |||
508 | 501 | gtk_tree_model_get (model, a, | ||
509 | 502 | PANEL_DEVICES_COLUMN_OBJECT, &obj_a, | ||
510 | 503 | -1); | ||
511 | 504 | gtk_tree_model_get (model, b, | ||
512 | 505 | PANEL_DEVICES_COLUMN_OBJECT, &obj_b, | ||
513 | 506 | -1); | ||
514 | 507 | |||
515 | 508 | cat_a = panel_net_object_get_sort_category (obj_a); | ||
516 | 509 | cat_b = panel_net_object_get_sort_category (obj_b); | ||
517 | 510 | |||
518 | 511 | if (cat_a != cat_b) | ||
519 | 512 | return cat_a - cat_b; | ||
520 | 513 | |||
521 | 514 | return g_utf8_collate (net_object_get_title (obj_a), net_object_get_title (obj_b)); | ||
522 | 515 | } | ||
523 | 516 | |||
524 | 517 | static void | ||
525 | 518 | panel_net_object_notify_title_cb (NetObject *net_object, GParamSpec *pspec, CcNetworkPanel *panel) | ||
526 | 519 | { | ||
527 | 520 | GtkTreeIter iter; | ||
528 | 521 | GtkListStore *liststore; | ||
529 | 522 | |||
530 | 523 | if (!find_in_model_by_id (panel, net_object_get_id (net_object), &iter)) | ||
531 | 524 | return; | ||
532 | 525 | |||
533 | 526 | liststore = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder, | ||
534 | 527 | "liststore_devices")); | ||
535 | 528 | |||
536 | 529 | /* gtk_tree_model_row_changed would not cause the list store to resort. | ||
537 | 530 | * Instead set the object column to the current value. | ||
538 | 531 | * See https://bugzilla.gnome.org/show_bug.cgi?id=782737 */ | ||
539 | 532 | gtk_list_store_set (liststore, &iter, | ||
540 | 533 | PANEL_DEVICES_COLUMN_OBJECT, net_object, | ||
541 | 534 | -1); | ||
542 | 535 | } | ||
543 | 536 | |||
544 | 537 | static void | ||
545 | 538 | panel_refresh_device_titles (CcNetworkPanel *panel) | ||
546 | 539 | { | ||
547 | 540 | GPtrArray *ndarray, *nmdarray; | ||
548 | 541 | NetDevice **devices; | ||
549 | 542 | NMDevice **nm_devices, *nm_device; | ||
550 | 543 | gchar **titles; | ||
551 | 544 | gint i, num_devices; | ||
552 | 545 | |||
553 | 546 | ndarray = cc_network_panel_get_devices (panel); | ||
554 | 547 | if (!ndarray->len) { | ||
555 | 548 | g_ptr_array_free (ndarray, TRUE); | ||
556 | 549 | return; | ||
557 | 550 | } | ||
558 | 551 | |||
559 | 552 | nmdarray = g_ptr_array_new (); | ||
560 | 553 | for (i = 0; i < ndarray->len; i++) { | ||
561 | 554 | nm_device = net_device_get_nm_device (ndarray->pdata[i]); | ||
562 | 555 | if (nm_device) | ||
563 | 556 | g_ptr_array_add (nmdarray, nm_device); | ||
564 | 557 | else | ||
565 | 558 | g_ptr_array_remove_index (ndarray, i--); | ||
566 | 559 | } | ||
567 | 560 | |||
568 | 561 | devices = (NetDevice **)ndarray->pdata; | ||
569 | 562 | nm_devices = (NMDevice **)nmdarray->pdata; | ||
570 | 563 | num_devices = ndarray->len; | ||
571 | 564 | |||
572 | 565 | titles = nm_device_disambiguate_names (nm_devices, num_devices); | ||
573 | 566 | for (i = 0; i < num_devices; i++) { | ||
574 | 567 | net_object_set_title (NET_OBJECT (devices[i]), titles[i]); | ||
575 | 568 | g_free (titles[i]); | ||
576 | 569 | } | ||
577 | 570 | g_free (titles); | ||
578 | 571 | g_ptr_array_free (ndarray, TRUE); | ||
579 | 572 | g_ptr_array_free (nmdarray, TRUE); | ||
580 | 573 | } | ||
581 | 574 | |||
582 | 346 | static gboolean | 575 | static gboolean |
583 | 347 | handle_argv_for_device (CcNetworkPanel *panel, | 576 | handle_argv_for_device (CcNetworkPanel *panel, |
584 | 348 | NMDevice *device, | 577 | NMDevice *device, |
585 | @@ -350,6 +579,7 @@ | |||
586 | 350 | { | 579 | { |
587 | 351 | CcNetworkPanelPrivate *priv = panel->priv; | 580 | CcNetworkPanelPrivate *priv = panel->priv; |
588 | 352 | NMDeviceType type; | 581 | NMDeviceType type; |
589 | 582 | GtkWidget *toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (panel))); | ||
590 | 353 | 583 | ||
591 | 354 | if (priv->arg_operation == OPERATION_NULL) | 584 | if (priv->arg_operation == OPERATION_NULL) |
592 | 355 | return TRUE; | 585 | return TRUE; |
593 | @@ -363,21 +593,21 @@ | |||
594 | 363 | select_tree_iter (panel, iter); | 593 | select_tree_iter (panel, iter); |
595 | 364 | 594 | ||
596 | 365 | if (priv->arg_operation == OPERATION_CREATE_WIFI) | 595 | if (priv->arg_operation == OPERATION_CREATE_WIFI) |
598 | 366 | cc_network_panel_create_wifi_network (panel, priv->client, priv->remote_settings); | 596 | cc_network_panel_create_wifi_network (toplevel, priv->client); |
599 | 367 | else | 597 | else |
601 | 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); |
602 | 369 | 599 | ||
603 | 370 | reset_command_line_args (panel); /* done */ | 600 | reset_command_line_args (panel); /* done */ |
604 | 371 | return TRUE; | 601 | return TRUE; |
605 | 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) { |
606 | 373 | if (priv->arg_operation == OPERATION_CONNECT_MOBILE) { | 603 | if (priv->arg_operation == OPERATION_CONNECT_MOBILE) { |
608 | 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); |
609 | 375 | 605 | ||
610 | 376 | reset_command_line_args (panel); /* done */ | 606 | reset_command_line_args (panel); /* done */ |
611 | 377 | select_tree_iter (panel, iter); | 607 | select_tree_iter (panel, iter); |
612 | 378 | return TRUE; | 608 | return TRUE; |
613 | 379 | } else if (priv->arg_operation == OPERATION_CONNECT_8021X) { | 609 | } else if (priv->arg_operation == OPERATION_CONNECT_8021X) { |
615 | 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); |
616 | 381 | reset_command_line_args (panel); /* done */ | 611 | reset_command_line_args (panel); /* done */ |
617 | 382 | select_tree_iter (panel, iter); | 612 | select_tree_iter (panel, iter); |
618 | 383 | return TRUE; | 613 | return TRUE; |
619 | @@ -392,6 +622,28 @@ | |||
620 | 392 | return FALSE; | 622 | return FALSE; |
621 | 393 | } | 623 | } |
622 | 394 | 624 | ||
623 | 625 | static gboolean | ||
624 | 626 | handle_argv_for_connection (CcNetworkPanel *panel, | ||
625 | 627 | NMConnection *connection, | ||
626 | 628 | GtkTreeIter *iter) | ||
627 | 629 | { | ||
628 | 630 | CcNetworkPanelPrivate *priv = panel->priv; | ||
629 | 631 | |||
630 | 632 | if (priv->arg_operation == OPERATION_NULL) | ||
631 | 633 | return TRUE; | ||
632 | 634 | if (priv->arg_operation != OPERATION_SHOW_DEVICE) | ||
633 | 635 | return FALSE; | ||
634 | 636 | |||
635 | 637 | if (g_strcmp0 (nm_connection_get_path (connection), priv->arg_device) == 0) { | ||
636 | 638 | reset_command_line_args (panel); | ||
637 | 639 | select_tree_iter (panel, iter); | ||
638 | 640 | return TRUE; | ||
639 | 641 | } | ||
640 | 642 | |||
641 | 643 | return FALSE; | ||
642 | 644 | } | ||
643 | 645 | |||
644 | 646 | |||
645 | 395 | static void | 647 | static void |
646 | 396 | handle_argv (CcNetworkPanel *panel) | 648 | handle_argv (CcNetworkPanel *panel) |
647 | 397 | { | 649 | { |
648 | @@ -408,15 +660,20 @@ | |||
649 | 408 | while (ret) { | 660 | while (ret) { |
650 | 409 | GObject *object_tmp; | 661 | GObject *object_tmp; |
651 | 410 | NMDevice *device; | 662 | NMDevice *device; |
652 | 663 | NMConnection *connection; | ||
653 | 411 | gboolean done = FALSE; | 664 | gboolean done = FALSE; |
654 | 412 | 665 | ||
655 | 413 | gtk_tree_model_get (model, &iter, | 666 | gtk_tree_model_get (model, &iter, |
656 | 414 | PANEL_DEVICES_COLUMN_OBJECT, &object_tmp, | 667 | PANEL_DEVICES_COLUMN_OBJECT, &object_tmp, |
657 | 415 | -1); | 668 | -1); |
659 | 416 | if (g_object_class_find_property (G_OBJECT_GET_CLASS (object_tmp), "nm-device") != NULL) { | 669 | if (NET_IS_DEVICE (object_tmp)) { |
660 | 417 | g_object_get (object_tmp, "nm-device", &device, NULL); | 670 | g_object_get (object_tmp, "nm-device", &device, NULL); |
661 | 418 | done = handle_argv_for_device (panel, device, &iter); | 671 | done = handle_argv_for_device (panel, device, &iter); |
662 | 419 | g_object_unref (device); | 672 | g_object_unref (device); |
663 | 673 | } else if (NET_IS_VPN (object_tmp)) { | ||
664 | 674 | g_object_get (object_tmp, "connection", &connection, NULL); | ||
665 | 675 | done = handle_argv_for_connection (panel, connection, &iter); | ||
666 | 676 | g_object_unref (connection); | ||
667 | 420 | } | 677 | } |
668 | 421 | 678 | ||
669 | 422 | g_object_unref (object_tmp); | 679 | g_object_unref (object_tmp); |
670 | @@ -430,10 +687,31 @@ | |||
671 | 430 | g_debug ("Could not handle argv operation, no matching device yet?"); | 687 | g_debug ("Could not handle argv operation, no matching device yet?"); |
672 | 431 | } | 688 | } |
673 | 432 | 689 | ||
674 | 690 | static void | ||
675 | 691 | state_changed_cb (NMDevice *device, | ||
676 | 692 | NMDeviceState new_state, | ||
677 | 693 | NMDeviceState old_state, | ||
678 | 694 | NMDeviceStateReason reason, | ||
679 | 695 | CcNetworkPanel *panel) | ||
680 | 696 | { | ||
681 | 697 | GtkListStore *store; | ||
682 | 698 | GtkTreeIter iter; | ||
683 | 699 | |||
684 | 700 | if (!find_in_model_by_id (panel, nm_device_get_udi (device), &iter)) { | ||
685 | 701 | return; | ||
686 | 702 | } | ||
687 | 703 | |||
688 | 704 | store = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder, | ||
689 | 705 | "liststore_devices")); | ||
690 | 706 | |||
691 | 707 | gtk_list_store_set (store, &iter, | ||
692 | 708 | PANEL_DEVICES_COLUMN_ICON, panel_device_to_icon_name (device, TRUE), | ||
693 | 709 | -1); | ||
694 | 710 | } | ||
695 | 711 | |||
696 | 433 | static gboolean | 712 | static gboolean |
697 | 434 | panel_add_device (CcNetworkPanel *panel, NMDevice *device) | 713 | panel_add_device (CcNetworkPanel *panel, NMDevice *device) |
698 | 435 | { | 714 | { |
699 | 436 | const gchar *title; | ||
700 | 437 | GtkListStore *liststore_devices; | 715 | GtkListStore *liststore_devices; |
701 | 438 | GtkTreeIter iter; | 716 | GtkTreeIter iter; |
702 | 439 | NMDeviceType type; | 717 | NMDeviceType type; |
703 | @@ -442,20 +720,25 @@ | |||
704 | 442 | GtkNotebook *notebook; | 720 | GtkNotebook *notebook; |
705 | 443 | GtkSizeGroup *size_group; | 721 | GtkSizeGroup *size_group; |
706 | 444 | GType device_g_type; | 722 | GType device_g_type; |
707 | 723 | const char *udi; | ||
708 | 724 | |||
709 | 725 | if (!nm_device_get_managed (device)) | ||
710 | 726 | goto out; | ||
711 | 445 | 727 | ||
712 | 446 | /* do we have an existing object with this id? */ | 728 | /* do we have an existing object with this id? */ |
714 | 447 | if (find_in_model_by_id (panel, nm_device_get_udi (device)) != NULL) | 729 | udi = nm_device_get_udi (device); |
715 | 730 | if (find_in_model_by_id (panel, udi, NULL) != NULL) | ||
716 | 448 | goto out; | 731 | goto out; |
717 | 449 | 732 | ||
718 | 450 | type = nm_device_get_device_type (device); | 733 | type = nm_device_get_device_type (device); |
719 | 451 | 734 | ||
720 | 452 | g_debug ("device %s type %i path %s", | 735 | g_debug ("device %s type %i path %s", |
722 | 453 | nm_device_get_udi (device), type, nm_object_get_path (NM_OBJECT (device))); | 736 | udi, type, nm_object_get_path (NM_OBJECT (device))); |
723 | 454 | 737 | ||
725 | 455 | /* map the NMDeviceType to the GType */ | 738 | /* map the NMDeviceType to the GType, or ignore */ |
726 | 456 | switch (type) { | 739 | switch (type) { |
727 | 457 | case NM_DEVICE_TYPE_ETHERNET: | 740 | case NM_DEVICE_TYPE_ETHERNET: |
729 | 458 | device_g_type = NET_TYPE_DEVICE_WIRED; | 741 | device_g_type = NET_TYPE_DEVICE_ETHERNET; |
730 | 459 | break; | 742 | break; |
731 | 460 | case NM_DEVICE_TYPE_MODEM: | 743 | case NM_DEVICE_TYPE_MODEM: |
732 | 461 | device_g_type = NET_TYPE_DEVICE_MOBILE; | 744 | device_g_type = NET_TYPE_DEVICE_MOBILE; |
733 | @@ -463,23 +746,56 @@ | |||
734 | 463 | case NM_DEVICE_TYPE_WIFI: | 746 | case NM_DEVICE_TYPE_WIFI: |
735 | 464 | device_g_type = NET_TYPE_DEVICE_WIFI; | 747 | device_g_type = NET_TYPE_DEVICE_WIFI; |
736 | 465 | break; | 748 | break; |
737 | 749 | /* not going to set up a cluster in GNOME */ | ||
738 | 750 | case NM_DEVICE_TYPE_VETH: | ||
739 | 751 | /* enterprise features */ | ||
740 | 752 | case NM_DEVICE_TYPE_BOND: | ||
741 | 753 | case NM_DEVICE_TYPE_TEAM: | ||
742 | 754 | /* Don't need the libvirtd bridge */ | ||
743 | 755 | case NM_DEVICE_TYPE_BRIDGE: | ||
744 | 756 | /* Don't add VPN devices */ | ||
745 | 757 | case NM_DEVICE_TYPE_TUN: | ||
746 | 758 | goto out; | ||
747 | 466 | default: | 759 | default: |
749 | 467 | goto out; | 760 | device_g_type = NET_TYPE_DEVICE_SIMPLE; |
750 | 761 | break; | ||
751 | 468 | } | 762 | } |
752 | 469 | 763 | ||
753 | 470 | /* create device */ | 764 | /* create device */ |
754 | 471 | title = panel_device_to_localized_string (device); | ||
755 | 472 | net_device = g_object_new (device_g_type, | 765 | net_device = g_object_new (device_g_type, |
756 | 473 | "panel", panel, | 766 | "panel", panel, |
757 | 474 | "removable", FALSE, | 767 | "removable", FALSE, |
758 | 475 | "cancellable", panel->priv->cancellable, | 768 | "cancellable", panel->priv->cancellable, |
759 | 476 | "client", panel->priv->client, | 769 | "client", panel->priv->client, |
760 | 477 | "remote-settings", panel->priv->remote_settings, | ||
761 | 478 | "nm-device", device, | 770 | "nm-device", device, |
762 | 479 | "id", nm_device_get_udi (device), | 771 | "id", nm_device_get_udi (device), |
763 | 480 | "title", title, | ||
764 | 481 | NULL); | 772 | NULL); |
765 | 482 | 773 | ||
766 | 774 | if (type == NM_DEVICE_TYPE_MODEM && | ||
767 | 775 | g_str_has_prefix (nm_device_get_udi (device), "/org/freedesktop/ModemManager1/Modem/")) { | ||
768 | 776 | GDBusObject *modem_object; | ||
769 | 777 | |||
770 | 778 | if (priv->modem_manager == NULL) { | ||
771 | 779 | g_warning ("Cannot grab information for modem at %s: No ModemManager support", | ||
772 | 780 | nm_device_get_udi (device)); | ||
773 | 781 | goto out; | ||
774 | 782 | } | ||
775 | 783 | |||
776 | 784 | modem_object = g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (priv->modem_manager), | ||
777 | 785 | nm_device_get_udi (device)); | ||
778 | 786 | if (modem_object == NULL) { | ||
779 | 787 | g_warning ("Cannot grab information for modem at %s: Not found", | ||
780 | 788 | nm_device_get_udi (device)); | ||
781 | 789 | goto out; | ||
782 | 790 | } | ||
783 | 791 | |||
784 | 792 | /* Set the modem object in the NetDeviceMobile */ | ||
785 | 793 | g_object_set (net_device, | ||
786 | 794 | "mm-object", modem_object, | ||
787 | 795 | NULL); | ||
788 | 796 | g_object_unref (modem_object); | ||
789 | 797 | } | ||
790 | 798 | |||
791 | 483 | /* add as a panel */ | 799 | /* add as a panel */ |
792 | 484 | if (device_g_type != NET_TYPE_DEVICE) { | 800 | if (device_g_type != NET_TYPE_DEVICE) { |
793 | 485 | notebook = GTK_NOTEBOOK (gtk_builder_get_object (panel->priv->builder, | 801 | notebook = GTK_NOTEBOOK (gtk_builder_get_object (panel->priv->builder, |
794 | @@ -498,11 +814,15 @@ | |||
795 | 498 | gtk_list_store_append (liststore_devices, &iter); | 814 | gtk_list_store_append (liststore_devices, &iter); |
796 | 499 | gtk_list_store_set (liststore_devices, | 815 | gtk_list_store_set (liststore_devices, |
797 | 500 | &iter, | 816 | &iter, |
801 | 501 | PANEL_DEVICES_COLUMN_ICON, panel_device_to_icon_name (device), | 817 | PANEL_DEVICES_COLUMN_ICON, panel_device_to_icon_name (device, TRUE), |
799 | 502 | PANEL_DEVICES_COLUMN_SORT, panel_device_to_sortable_string (device), | ||
800 | 503 | PANEL_DEVICES_COLUMN_TITLE, title, | ||
802 | 504 | PANEL_DEVICES_COLUMN_OBJECT, net_device, | 818 | PANEL_DEVICES_COLUMN_OBJECT, net_device, |
803 | 505 | -1); | 819 | -1); |
804 | 820 | g_signal_connect (net_device, "notify::title", | ||
805 | 821 | G_CALLBACK (panel_net_object_notify_title_cb), panel); | ||
806 | 822 | |||
807 | 823 | g_object_unref (net_device); | ||
808 | 824 | g_signal_connect (device, "state-changed", | ||
809 | 825 | G_CALLBACK (state_changed_cb), panel); | ||
810 | 506 | 826 | ||
811 | 507 | out: | 827 | out: |
812 | 508 | return FALSE; | 828 | return FALSE; |
813 | @@ -539,6 +859,25 @@ | |||
814 | 539 | } | 859 | } |
815 | 540 | 860 | ||
816 | 541 | static void | 861 | static void |
817 | 862 | get_object_title (GtkTreeViewColumn *column, | ||
818 | 863 | GtkCellRenderer *cell, | ||
819 | 864 | GtkTreeModel *model, | ||
820 | 865 | GtkTreeIter *iter, | ||
821 | 866 | gpointer data) | ||
822 | 867 | { | ||
823 | 868 | NetObject *object; | ||
824 | 869 | |||
825 | 870 | gtk_tree_model_get (model, iter, | ||
826 | 871 | PANEL_DEVICES_COLUMN_OBJECT, &object, | ||
827 | 872 | -1); | ||
828 | 873 | if (!object) | ||
829 | 874 | return; | ||
830 | 875 | |||
831 | 876 | g_object_set (cell, "text", net_object_get_title (object), NULL); | ||
832 | 877 | g_object_unref (object); | ||
833 | 878 | } | ||
834 | 879 | |||
835 | 880 | static void | ||
836 | 542 | panel_add_devices_columns (CcNetworkPanel *panel, GtkTreeView *treeview) | 881 | panel_add_devices_columns (CcNetworkPanel *panel, GtkTreeView *treeview) |
837 | 543 | { | 882 | { |
838 | 544 | CcNetworkPanelPrivate *priv = panel->priv; | 883 | CcNetworkPanelPrivate *priv = panel->priv; |
839 | @@ -548,8 +887,13 @@ | |||
840 | 548 | 887 | ||
841 | 549 | /* image */ | 888 | /* image */ |
842 | 550 | renderer = gtk_cell_renderer_pixbuf_new (); | 889 | renderer = gtk_cell_renderer_pixbuf_new (); |
845 | 551 | g_object_set (renderer, "stock-size", gtk_icon_size_from_name ("cc-sidebar-list"), NULL); | 890 | g_object_set (renderer, |
846 | 552 | gtk_cell_renderer_set_padding (renderer, 4, 4); | 891 | "width", 32, |
847 | 892 | "xalign", 1.0, | ||
848 | 893 | "stock-size", GTK_ICON_SIZE_MENU, | ||
849 | 894 | "follow-state", TRUE, | ||
850 | 895 | NULL); | ||
851 | 896 | gtk_cell_renderer_set_padding (renderer, 4, 10); | ||
852 | 553 | 897 | ||
853 | 554 | column = gtk_tree_view_column_new_with_attributes ("icon", renderer, | 898 | column = gtk_tree_view_column_new_with_attributes ("icon", renderer, |
854 | 555 | "icon-name", PANEL_DEVICES_COLUMN_ICON, | 899 | "icon-name", PANEL_DEVICES_COLUMN_ICON, |
855 | @@ -562,14 +906,19 @@ | |||
856 | 562 | "wrap-mode", PANGO_WRAP_WORD, | 906 | "wrap-mode", PANGO_WRAP_WORD, |
857 | 563 | "ellipsize", PANGO_ELLIPSIZE_END, | 907 | "ellipsize", PANGO_ELLIPSIZE_END, |
858 | 564 | NULL); | 908 | NULL); |
863 | 565 | column = gtk_tree_view_column_new_with_attributes ("title", renderer, | 909 | column = gtk_tree_view_column_new_with_attributes ("title", renderer, NULL); |
864 | 566 | "markup", PANEL_DEVICES_COLUMN_TITLE, | 910 | gtk_tree_view_column_set_cell_data_func (GTK_TREE_VIEW_COLUMN (column), |
865 | 567 | NULL); | 911 | renderer, |
866 | 568 | gtk_tree_view_column_set_sort_column_id (column, PANEL_DEVICES_COLUMN_SORT); | 912 | get_object_title, |
867 | 913 | NULL, NULL); | ||
868 | 914 | gtk_tree_view_column_set_sort_column_id (column, PANEL_DEVICES_COLUMN_OBJECT); | ||
869 | 569 | liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (priv->builder, | 915 | liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (priv->builder, |
870 | 570 | "liststore_devices")); | 916 | "liststore_devices")); |
871 | 917 | gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (liststore_devices), | ||
872 | 918 | PANEL_DEVICES_COLUMN_OBJECT, | ||
873 | 919 | panel_net_object_sort_func, NULL, NULL); | ||
874 | 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), |
876 | 572 | PANEL_DEVICES_COLUMN_SORT, | 921 | PANEL_DEVICES_COLUMN_OBJECT, |
877 | 573 | GTK_SORT_ASCENDING); | 922 | GTK_SORT_ASCENDING); |
878 | 574 | gtk_tree_view_append_column (treeview, column); | 923 | gtk_tree_view_append_column (treeview, column); |
879 | 575 | gtk_tree_view_column_set_expand (column, TRUE); | 924 | gtk_tree_view_column_set_expand (column, TRUE); |
880 | @@ -616,6 +965,7 @@ | |||
881 | 616 | } | 965 | } |
882 | 617 | i++; | 966 | i++; |
883 | 618 | } | 967 | } |
884 | 968 | g_object_unref (object); | ||
885 | 619 | out: | 969 | out: |
886 | 620 | g_list_free (panels); | 970 | g_list_free (panels); |
887 | 621 | } | 971 | } |
888 | @@ -623,7 +973,6 @@ | |||
889 | 623 | static void | 973 | static void |
890 | 624 | panel_add_proxy_device (CcNetworkPanel *panel) | 974 | panel_add_proxy_device (CcNetworkPanel *panel) |
891 | 625 | { | 975 | { |
892 | 626 | gchar *title; | ||
893 | 627 | GtkListStore *liststore_devices; | 976 | GtkListStore *liststore_devices; |
894 | 628 | GtkTreeIter iter; | 977 | GtkTreeIter iter; |
895 | 629 | NetProxy *proxy; | 978 | NetProxy *proxy; |
896 | @@ -643,39 +992,21 @@ | |||
897 | 643 | /* add proxy to device list */ | 992 | /* add proxy to device list */ |
898 | 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, |
899 | 645 | "liststore_devices")); | 994 | "liststore_devices")); |
901 | 646 | title = g_strdup_printf ("%s", _("Network proxy")); | 995 | net_object_set_title (NET_OBJECT (proxy), _("Network proxy")); |
902 | 647 | gtk_list_store_append (liststore_devices, &iter); | 996 | gtk_list_store_append (liststore_devices, &iter); |
903 | 648 | gtk_list_store_set (liststore_devices, | 997 | gtk_list_store_set (liststore_devices, |
904 | 649 | &iter, | 998 | &iter, |
908 | 650 | PANEL_DEVICES_COLUMN_ICON, "preferences-system-network", | 999 | PANEL_DEVICES_COLUMN_ICON, "preferences-system-network-symbolic", |
906 | 651 | PANEL_DEVICES_COLUMN_TITLE, title, | ||
907 | 652 | PANEL_DEVICES_COLUMN_SORT, "9", | ||
909 | 653 | PANEL_DEVICES_COLUMN_OBJECT, proxy, | 1000 | PANEL_DEVICES_COLUMN_OBJECT, proxy, |
910 | 654 | -1); | 1001 | -1); |
912 | 655 | g_free (title); | 1002 | |
913 | 1003 | /* NOTE: No connect to notify::title here as it is guaranteed to not | ||
914 | 1004 | * be changed by anyone.*/ | ||
915 | 1005 | |||
916 | 656 | g_object_unref (proxy); | 1006 | g_object_unref (proxy); |
917 | 657 | } | 1007 | } |
918 | 658 | 1008 | ||
919 | 659 | static void | 1009 | static void |
920 | 660 | cc_network_panel_notify_enable_active_cb (GtkSwitch *sw, | ||
921 | 661 | GParamSpec *pspec, | ||
922 | 662 | CcNetworkPanel *panel) | ||
923 | 663 | { | ||
924 | 664 | gboolean enable; | ||
925 | 665 | struct rfkill_event event; | ||
926 | 666 | |||
927 | 667 | enable = gtk_switch_get_active (sw); | ||
928 | 668 | g_debug ("Setting killswitch to %d", enable); | ||
929 | 669 | |||
930 | 670 | memset (&event, 0, sizeof(event)); | ||
931 | 671 | event.op = RFKILL_OP_CHANGE_ALL; | ||
932 | 672 | event.type = RFKILL_TYPE_ALL; | ||
933 | 673 | event.soft = enable ? 1 : 0; | ||
934 | 674 | if (cc_rfkill_glib_send_event (panel->priv->rfkill, &event) < 0) | ||
935 | 675 | g_warning ("Setting the killswitch %s failed", enable ? "on" : "off"); | ||
936 | 676 | } | ||
937 | 677 | |||
938 | 678 | static void | ||
939 | 679 | connection_state_changed (NMActiveConnection *c, GParamSpec *pspec, CcNetworkPanel *panel) | 1010 | connection_state_changed (NMActiveConnection *c, GParamSpec *pspec, CcNetworkPanel *panel) |
940 | 680 | { | 1011 | { |
941 | 681 | } | 1012 | } |
942 | @@ -699,7 +1030,7 @@ | |||
943 | 699 | for (j = 0; devices && j < devices->len; j++) | 1030 | for (j = 0; devices && j < devices->len; j++) |
944 | 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))); |
945 | 701 | if (NM_IS_VPN_CONNECTION (connection)) | 1032 | if (NM_IS_VPN_CONNECTION (connection)) |
947 | 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)); |
948 | 703 | 1034 | ||
949 | 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) { |
950 | 705 | g_signal_connect_object (connection, "notify::state", | 1036 | g_signal_connect_object (connection, "notify::state", |
951 | @@ -714,6 +1045,7 @@ | |||
952 | 714 | { | 1045 | { |
953 | 715 | g_debug ("New device added"); | 1046 | g_debug ("New device added"); |
954 | 716 | panel_add_device (panel, device); | 1047 | panel_add_device (panel, device); |
955 | 1048 | panel_refresh_device_titles (panel); | ||
956 | 717 | } | 1049 | } |
957 | 718 | 1050 | ||
958 | 719 | static void | 1051 | static void |
959 | @@ -721,6 +1053,7 @@ | |||
960 | 721 | { | 1053 | { |
961 | 722 | g_debug ("Device removed"); | 1054 | g_debug ("Device removed"); |
962 | 723 | panel_remove_device (panel, device); | 1055 | panel_remove_device (panel, device); |
963 | 1056 | panel_refresh_device_titles (panel); | ||
964 | 724 | } | 1057 | } |
965 | 725 | 1058 | ||
966 | 726 | static void | 1059 | static void |
967 | @@ -734,7 +1067,7 @@ | |||
968 | 734 | CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data); | 1067 | CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data); |
969 | 735 | 1068 | ||
970 | 736 | /* clear all devices we added */ | 1069 | /* clear all devices we added */ |
972 | 737 | if (!nm_client_get_manager_running (client)) { | 1070 | if (!nm_client_get_nm_running (client)) { |
973 | 738 | g_debug ("NM disappeared"); | 1071 | g_debug ("NM disappeared"); |
974 | 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, |
975 | 740 | "liststore_devices")); | 1073 | "liststore_devices")); |
976 | @@ -759,12 +1092,14 @@ | |||
977 | 759 | select_first_device (panel); | 1092 | select_first_device (panel); |
978 | 760 | } | 1093 | } |
979 | 761 | 1094 | ||
980 | 1095 | panel_refresh_device_titles (panel); | ||
981 | 1096 | |||
982 | 762 | g_debug ("Calling handle_argv() after cold-plugging devices"); | 1097 | g_debug ("Calling handle_argv() after cold-plugging devices"); |
983 | 763 | handle_argv (panel); | 1098 | handle_argv (panel); |
984 | 764 | } | 1099 | } |
985 | 765 | 1100 | ||
986 | 766 | static NetObject * | 1101 | static NetObject * |
988 | 767 | find_in_model_by_id (CcNetworkPanel *panel, const gchar *id) | 1102 | find_in_model_by_id (CcNetworkPanel *panel, const gchar *id, GtkTreeIter *iter_out) |
989 | 768 | { | 1103 | { |
990 | 769 | gboolean ret; | 1104 | gboolean ret; |
991 | 770 | NetObject *object_tmp; | 1105 | NetObject *object_tmp; |
992 | @@ -793,6 +1128,8 @@ | |||
993 | 793 | } | 1128 | } |
994 | 794 | } while (object == NULL && gtk_tree_model_iter_next (model, &iter)); | 1129 | } while (object == NULL && gtk_tree_model_iter_next (model, &iter)); |
995 | 795 | out: | 1130 | out: |
996 | 1131 | if (iter_out) | ||
997 | 1132 | *iter_out = iter; | ||
998 | 796 | return object; | 1133 | return object; |
999 | 797 | } | 1134 | } |
1000 | 798 | 1135 | ||
1001 | @@ -800,7 +1137,6 @@ | |||
1002 | 800 | panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection) | 1137 | panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection) |
1003 | 801 | { | 1138 | { |
1004 | 802 | gchar *title; | 1139 | gchar *title; |
1005 | 803 | gchar *title_markup; | ||
1006 | 804 | GtkListStore *liststore_devices; | 1140 | GtkListStore *liststore_devices; |
1007 | 805 | GtkTreeIter iter; | 1141 | GtkTreeIter iter; |
1008 | 806 | NetVpn *net_vpn; | 1142 | NetVpn *net_vpn; |
1009 | @@ -810,10 +1146,10 @@ | |||
1010 | 810 | 1146 | ||
1011 | 811 | /* does already exist */ | 1147 | /* does already exist */ |
1012 | 812 | id = nm_connection_get_path (connection); | 1148 | id = nm_connection_get_path (connection); |
1014 | 813 | if (find_in_model_by_id (panel, id) != NULL) | 1149 | if (find_in_model_by_id (panel, id, NULL) != NULL) |
1015 | 814 | return; | 1150 | return; |
1016 | 815 | 1151 | ||
1018 | 816 | /* add as a virtual object */ | 1152 | /* add as a VPN object */ |
1019 | 817 | net_vpn = g_object_new (NET_TYPE_VPN, | 1153 | net_vpn = g_object_new (NET_TYPE_VPN, |
1020 | 818 | "panel", panel, | 1154 | "panel", panel, |
1021 | 819 | "removable", TRUE, | 1155 | "removable", TRUE, |
1022 | @@ -836,19 +1172,19 @@ | |||
1023 | 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, |
1024 | 837 | "liststore_devices")); | 1173 | "liststore_devices")); |
1025 | 838 | title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (connection)); | 1174 | title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (connection)); |
1026 | 839 | title_markup = g_strdup (title); | ||
1027 | 840 | 1175 | ||
1028 | 841 | net_object_set_title (NET_OBJECT (net_vpn), title); | 1176 | net_object_set_title (NET_OBJECT (net_vpn), title); |
1029 | 842 | gtk_list_store_append (liststore_devices, &iter); | 1177 | gtk_list_store_append (liststore_devices, &iter); |
1030 | 843 | gtk_list_store_set (liststore_devices, | 1178 | gtk_list_store_set (liststore_devices, |
1031 | 844 | &iter, | 1179 | &iter, |
1035 | 845 | PANEL_DEVICES_COLUMN_ICON, "network-vpn", | 1180 | PANEL_DEVICES_COLUMN_ICON, "network-vpn-symbolic", |
1033 | 846 | PANEL_DEVICES_COLUMN_TITLE, title_markup, | ||
1034 | 847 | PANEL_DEVICES_COLUMN_SORT, "5", | ||
1036 | 848 | PANEL_DEVICES_COLUMN_OBJECT, net_vpn, | 1181 | PANEL_DEVICES_COLUMN_OBJECT, net_vpn, |
1037 | 849 | -1); | 1182 | -1); |
1038 | 1183 | g_signal_connect (net_vpn, "notify::title", | ||
1039 | 1184 | G_CALLBACK (panel_net_object_notify_title_cb), panel); | ||
1040 | 1185 | |||
1041 | 850 | g_free (title); | 1186 | g_free (title); |
1043 | 851 | g_free (title_markup); | 1187 | g_object_unref (net_vpn); |
1044 | 852 | } | 1188 | } |
1045 | 853 | 1189 | ||
1046 | 854 | static void | 1190 | static void |
1047 | @@ -856,130 +1192,91 @@ | |||
1048 | 856 | NMConnection *connection) | 1192 | NMConnection *connection) |
1049 | 857 | { | 1193 | { |
1050 | 858 | NMSettingConnection *s_con; | 1194 | NMSettingConnection *s_con; |
1052 | 859 | const gchar *type; | 1195 | const gchar *type, *iface; |
1053 | 860 | 1196 | ||
1054 | 861 | s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, | 1197 | s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, |
1055 | 862 | NM_TYPE_SETTING_CONNECTION)); | 1198 | NM_TYPE_SETTING_CONNECTION)); |
1056 | 863 | type = nm_setting_connection_get_connection_type (s_con); | 1199 | type = nm_setting_connection_get_connection_type (s_con); |
1059 | 864 | if (g_strcmp0 (type, "vpn") != 0) | 1200 | iface = nm_connection_get_interface_name (connection); |
1060 | 865 | return; | 1201 | if (g_strcmp0 (type, "vpn") != 0 && iface == NULL) |
1061 | 1202 | return; | ||
1062 | 1203 | |||
1063 | 1204 | /* Don't add the libvirtd bridge to the UI */ | ||
1064 | 1205 | if (g_strcmp0 (nm_setting_connection_get_interface_name (s_con), "virbr0") == 0) | ||
1065 | 1206 | return; | ||
1066 | 1207 | |||
1067 | 866 | g_debug ("add %s/%s remote connection: %s", | 1208 | g_debug ("add %s/%s remote connection: %s", |
1068 | 867 | type, g_type_name_from_instance ((GTypeInstance*)connection), | 1209 | type, g_type_name_from_instance ((GTypeInstance*)connection), |
1069 | 868 | nm_connection_get_path (connection)); | 1210 | nm_connection_get_path (connection)); |
1071 | 869 | panel_add_vpn_device (panel, connection); | 1211 | if (!iface) |
1072 | 1212 | panel_add_vpn_device (panel, connection); | ||
1073 | 870 | } | 1213 | } |
1074 | 871 | 1214 | ||
1075 | 872 | static void | 1215 | static void |
1079 | 873 | notify_new_connection_cb (NMRemoteSettings *settings, | 1216 | notify_connection_added_cb (NMClient *client, |
1080 | 874 | NMRemoteConnection *connection, | 1217 | NMRemoteConnection *connection, |
1081 | 875 | CcNetworkPanel *panel) | 1218 | CcNetworkPanel *panel) |
1082 | 876 | { | 1219 | { |
1083 | 877 | add_connection (panel, NM_CONNECTION (connection)); | 1220 | add_connection (panel, NM_CONNECTION (connection)); |
1084 | 878 | } | 1221 | } |
1085 | 879 | 1222 | ||
1086 | 880 | static void | 1223 | static void |
1087 | 881 | notify_connections_read_cb (NMRemoteSettings *settings, | ||
1088 | 882 | CcNetworkPanel *panel) | ||
1089 | 883 | { | ||
1090 | 884 | GSList *list, *iter; | ||
1091 | 885 | NMConnection *connection; | ||
1092 | 886 | |||
1093 | 887 | list = nm_remote_settings_list_connections (settings); | ||
1094 | 888 | g_debug ("%p has %i remote connections", | ||
1095 | 889 | panel, g_slist_length (list)); | ||
1096 | 890 | for (iter = list; iter; iter = g_slist_next (iter)) { | ||
1097 | 891 | connection = NM_CONNECTION (iter->data); | ||
1098 | 892 | add_connection (panel, connection); | ||
1099 | 893 | } | ||
1100 | 894 | } | ||
1101 | 895 | |||
1102 | 896 | static gboolean | ||
1103 | 897 | display_version_warning_idle (CcNetworkPanel *panel) | ||
1104 | 898 | { | ||
1105 | 899 | GtkWidget *dialog; | ||
1106 | 900 | GtkWidget *image; | ||
1107 | 901 | GtkWindow *window; | ||
1108 | 902 | const char *message; | ||
1109 | 903 | |||
1110 | 904 | /* TRANSLATORS: the user is running a NM that is not API compatible */ | ||
1111 | 905 | message = _("The system network services are not compatible with this version."); | ||
1112 | 906 | |||
1113 | 907 | window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel))); | ||
1114 | 908 | dialog = gtk_message_dialog_new (window, | ||
1115 | 909 | GTK_DIALOG_MODAL, | ||
1116 | 910 | GTK_MESSAGE_ERROR, | ||
1117 | 911 | GTK_BUTTONS_CLOSE, | ||
1118 | 912 | "%s", | ||
1119 | 913 | message); | ||
1120 | 914 | image = gtk_image_new_from_icon_name ("computer-fail", GTK_ICON_SIZE_DIALOG); | ||
1121 | 915 | gtk_widget_show (image); | ||
1122 | 916 | gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image); | ||
1123 | 917 | |||
1124 | 918 | gtk_dialog_run (GTK_DIALOG (dialog)); | ||
1125 | 919 | gtk_widget_destroy (dialog); | ||
1126 | 920 | |||
1127 | 921 | return FALSE; | ||
1128 | 922 | } | ||
1129 | 923 | |||
1130 | 924 | static gboolean | ||
1131 | 925 | panel_check_network_manager_version (CcNetworkPanel *panel) | 1224 | panel_check_network_manager_version (CcNetworkPanel *panel) |
1132 | 926 | { | 1225 | { |
1133 | 1226 | GtkWidget *box; | ||
1134 | 1227 | GtkWidget *label; | ||
1135 | 1228 | gchar *markup; | ||
1136 | 927 | const gchar *version; | 1229 | const gchar *version; |
1137 | 928 | guint minor = 0; | ||
1138 | 929 | gboolean ret = TRUE; | ||
1139 | 930 | 1230 | ||
1140 | 931 | /* parse running version */ | 1231 | /* parse running version */ |
1141 | 932 | version = nm_client_get_version (panel->priv->client); | 1232 | version = nm_client_get_version (panel->priv->client); |
1142 | 933 | if (version == NULL) { | 1233 | if (version == NULL) { |
1147 | 934 | ret = FALSE; | 1234 | gtk_container_remove (GTK_CONTAINER (panel), gtk_bin_get_child (GTK_BIN (panel))); |
1148 | 935 | 1235 | ||
1149 | 936 | /* do modal dialog in idle so we don't block startup */ | 1236 | box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 20); |
1150 | 937 | panel->priv->nm_warning_idle = g_idle_add ((GSourceFunc)display_version_warning_idle, panel); | 1237 | gtk_box_set_homogeneous (GTK_BOX (box), TRUE); |
1151 | 1238 | gtk_widget_set_vexpand (box, TRUE); | ||
1152 | 1239 | gtk_container_add (GTK_CONTAINER (panel), box); | ||
1153 | 1240 | |||
1154 | 1241 | label = gtk_label_new (_("Oops, something has gone wrong. Please contact your software vendor.")); | ||
1155 | 1242 | gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); | ||
1156 | 1243 | gtk_widget_set_valign (label, GTK_ALIGN_END); | ||
1157 | 1244 | gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0); | ||
1158 | 1245 | |||
1159 | 1246 | markup = g_strdup_printf ("<small><tt>%s</tt></small>", | ||
1160 | 1247 | _("NetworkManager needs to be running.")); | ||
1161 | 1248 | label = gtk_label_new (NULL); | ||
1162 | 1249 | gtk_label_set_markup (GTK_LABEL (label), markup); | ||
1163 | 1250 | gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); | ||
1164 | 1251 | gtk_widget_set_valign (label, GTK_ALIGN_START); | ||
1165 | 1252 | gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0); | ||
1166 | 1253 | |||
1167 | 1254 | gtk_widget_show_all (box); | ||
1168 | 1255 | g_free (markup); | ||
1169 | 1256 | } else { | ||
1170 | 1257 | manager_running (panel->priv->client, NULL, panel); | ||
1171 | 938 | } | 1258 | } |
1172 | 1259 | } | ||
1173 | 939 | 1260 | ||
1175 | 940 | return ret; | 1261 | static void |
1176 | 1262 | editor_done (NetConnectionEditor *editor, | ||
1177 | 1263 | gboolean success, | ||
1178 | 1264 | gpointer user_data) | ||
1179 | 1265 | { | ||
1180 | 1266 | g_object_unref (editor); | ||
1181 | 941 | } | 1267 | } |
1182 | 942 | 1268 | ||
1183 | 943 | static void | 1269 | static void |
1184 | 944 | add_connection_cb (GtkToolButton *button, CcNetworkPanel *panel) | 1270 | add_connection_cb (GtkToolButton *button, CcNetworkPanel *panel) |
1185 | 945 | { | 1271 | { |
1223 | 946 | GtkWidget *dialog; | 1272 | NetConnectionEditor *editor; |
1224 | 947 | gint response; | 1273 | GtkWindow *toplevel; |
1225 | 948 | 1274 | ||
1226 | 949 | dialog = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, | 1275 | toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel))); |
1227 | 950 | "connection_type_dialog")); | 1276 | editor = net_connection_editor_new (toplevel, NULL, NULL, NULL, |
1228 | 951 | gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel)))); | 1277 | panel->priv->client); |
1229 | 952 | 1278 | g_signal_connect (editor, "done", G_CALLBACK (editor_done), panel); | |
1230 | 953 | response = gtk_dialog_run (GTK_DIALOG (dialog)); | 1279 | net_connection_editor_run (editor); |
1194 | 954 | |||
1195 | 955 | gtk_widget_hide (dialog); | ||
1196 | 956 | |||
1197 | 957 | if (response == GTK_RESPONSE_OK) { | ||
1198 | 958 | GtkComboBox *combo; | ||
1199 | 959 | GtkTreeModel *model; | ||
1200 | 960 | GtkTreeIter iter; | ||
1201 | 961 | gchar *type; | ||
1202 | 962 | gchar *cmdline; | ||
1203 | 963 | GError *error; | ||
1204 | 964 | |||
1205 | 965 | combo = GTK_COMBO_BOX (gtk_builder_get_object (panel->priv->builder, | ||
1206 | 966 | "connection_type_combo")); | ||
1207 | 967 | model = gtk_combo_box_get_model (combo); | ||
1208 | 968 | gtk_combo_box_get_active_iter (combo, &iter); | ||
1209 | 969 | type = NULL; | ||
1210 | 970 | gtk_tree_model_get (model, &iter, 1, &type, -1); | ||
1211 | 971 | |||
1212 | 972 | cmdline = g_strdup_printf ("nm-connection-editor --create --type %s", type); | ||
1213 | 973 | g_debug ("Launching '%s'\n", cmdline); | ||
1214 | 974 | |||
1215 | 975 | error = NULL; | ||
1216 | 976 | if (!g_spawn_command_line_async (cmdline, &error)) { | ||
1217 | 977 | g_warning ("Failed to launch nm-connection-editor: %s", error->message); | ||
1218 | 978 | g_error_free (error); | ||
1219 | 979 | } | ||
1220 | 980 | g_free (cmdline); | ||
1221 | 981 | g_free (type); | ||
1222 | 982 | } | ||
1231 | 983 | } | 1280 | } |
1232 | 984 | 1281 | ||
1233 | 985 | static void | 1282 | static void |
1234 | @@ -994,131 +1291,38 @@ | |||
1235 | 994 | 1291 | ||
1236 | 995 | /* delete the object */ | 1292 | /* delete the object */ |
1237 | 996 | net_object_delete (object); | 1293 | net_object_delete (object); |
1238 | 1294 | g_object_unref (object); | ||
1239 | 997 | } | 1295 | } |
1240 | 998 | 1296 | ||
1241 | 999 | static void | 1297 | static void |
1242 | 1000 | on_toplevel_map (GtkWidget *widget, | 1298 | on_toplevel_map (GtkWidget *widget, |
1243 | 1001 | CcNetworkPanel *panel) | 1299 | CcNetworkPanel *panel) |
1244 | 1002 | { | 1300 | { |
1245 | 1003 | gboolean ret; | ||
1246 | 1004 | |||
1247 | 1005 | /* is the user compiling against a new version, but not running | 1301 | /* is the user compiling against a new version, but not running |
1248 | 1006 | * the daemon? */ | 1302 | * the daemon? */ |
1346 | 1007 | ret = panel_check_network_manager_version (panel); | 1303 | panel_check_network_manager_version (panel); |
1250 | 1008 | if (ret) { | ||
1251 | 1009 | manager_running (panel->priv->client, NULL, panel); | ||
1252 | 1010 | } else { | ||
1253 | 1011 | /* just select the proxy settings */ | ||
1254 | 1012 | select_first_device (panel); | ||
1255 | 1013 | } | ||
1256 | 1014 | } | ||
1257 | 1015 | |||
1258 | 1016 | static void | ||
1259 | 1017 | rfkill_changed (CcRfkillGlib *rfkill, | ||
1260 | 1018 | GList *events, | ||
1261 | 1019 | CcNetworkPanel *panel) | ||
1262 | 1020 | { | ||
1263 | 1021 | gboolean enabled; | ||
1264 | 1022 | GList *l; | ||
1265 | 1023 | GHashTableIter iter; | ||
1266 | 1024 | gpointer key, value; | ||
1267 | 1025 | |||
1268 | 1026 | enabled = TRUE; | ||
1269 | 1027 | |||
1270 | 1028 | for (l = events; l != NULL; l = l->next) { | ||
1271 | 1029 | struct rfkill_event *event = l->data; | ||
1272 | 1030 | |||
1273 | 1031 | if (event->op == RFKILL_OP_ADD) | ||
1274 | 1032 | g_hash_table_insert (panel->priv->killswitches, | ||
1275 | 1033 | GINT_TO_POINTER (event->idx), | ||
1276 | 1034 | GINT_TO_POINTER (event->soft || event->hard)); | ||
1277 | 1035 | else if (event->op == RFKILL_OP_CHANGE) | ||
1278 | 1036 | g_hash_table_insert (panel->priv->killswitches, | ||
1279 | 1037 | GINT_TO_POINTER (event->idx), | ||
1280 | 1038 | GINT_TO_POINTER (event->soft || event->hard)); | ||
1281 | 1039 | else if (event->op == RFKILL_OP_DEL) | ||
1282 | 1040 | g_hash_table_remove (panel->priv->killswitches, | ||
1283 | 1041 | GINT_TO_POINTER (event->idx)); | ||
1284 | 1042 | } | ||
1285 | 1043 | |||
1286 | 1044 | g_hash_table_iter_init (&iter, panel->priv->killswitches); | ||
1287 | 1045 | while (g_hash_table_iter_next (&iter, &key, &value)) { | ||
1288 | 1046 | int idx, state; | ||
1289 | 1047 | |||
1290 | 1048 | idx = GPOINTER_TO_INT (key); | ||
1291 | 1049 | state = GPOINTER_TO_INT (value); | ||
1292 | 1050 | g_debug ("Killswitch %d is %s", idx, state ? "enabled" : "disabled"); | ||
1293 | 1051 | |||
1294 | 1052 | /* A single device that's enabled? airplane mode is off */ | ||
1295 | 1053 | if (state == FALSE) { | ||
1296 | 1054 | enabled = FALSE; | ||
1297 | 1055 | break; | ||
1298 | 1056 | } | ||
1299 | 1057 | } | ||
1300 | 1058 | |||
1301 | 1059 | if (enabled != gtk_switch_get_active (panel->priv->rfkill_switch)) { | ||
1302 | 1060 | g_signal_handlers_block_by_func (panel->priv->rfkill_switch, | ||
1303 | 1061 | cc_network_panel_notify_enable_active_cb, | ||
1304 | 1062 | panel); | ||
1305 | 1063 | gtk_switch_set_active (panel->priv->rfkill_switch, enabled); | ||
1306 | 1064 | g_signal_handlers_unblock_by_func (panel->priv->rfkill_switch, | ||
1307 | 1065 | cc_network_panel_notify_enable_active_cb, | ||
1308 | 1066 | panel); | ||
1309 | 1067 | } | ||
1310 | 1068 | } | ||
1311 | 1069 | |||
1312 | 1070 | static gboolean | ||
1313 | 1071 | network_add_shell_header_widgets_cb (gpointer user_data) | ||
1314 | 1072 | { | ||
1315 | 1073 | CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data); | ||
1316 | 1074 | GtkWidget *box; | ||
1317 | 1075 | GtkWidget *label; | ||
1318 | 1076 | GtkWidget *widget; | ||
1319 | 1077 | |||
1320 | 1078 | box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); | ||
1321 | 1079 | /* TRANSLATORS: this is to disable the radio hardware in the | ||
1322 | 1080 | * network panel */ | ||
1323 | 1081 | label = gtk_label_new_with_mnemonic (_("Air_plane Mode")); | ||
1324 | 1082 | gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); | ||
1325 | 1083 | gtk_widget_set_visible (label, TRUE); | ||
1326 | 1084 | widget = gtk_switch_new (); | ||
1327 | 1085 | gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget); | ||
1328 | 1086 | gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0); | ||
1329 | 1087 | gtk_widget_show_all (box); | ||
1330 | 1088 | panel->priv->rfkill_switch = GTK_SWITCH (widget); | ||
1331 | 1089 | cc_shell_embed_widget_in_header (cc_panel_get_shell (CC_PANEL (panel)), box); | ||
1332 | 1090 | panel->priv->kill_switch_header = g_object_ref (box); | ||
1333 | 1091 | |||
1334 | 1092 | panel->priv->killswitches = g_hash_table_new (g_direct_hash, g_direct_equal); | ||
1335 | 1093 | panel->priv->rfkill = cc_rfkill_glib_new (); | ||
1336 | 1094 | g_signal_connect (G_OBJECT (panel->priv->rfkill), "changed", | ||
1337 | 1095 | G_CALLBACK (rfkill_changed), panel); | ||
1338 | 1096 | if (cc_rfkill_glib_open (panel->priv->rfkill) < 0) | ||
1339 | 1097 | gtk_widget_hide (box); | ||
1340 | 1098 | |||
1341 | 1099 | g_signal_connect (panel->priv->rfkill_switch, "notify::active", | ||
1342 | 1100 | G_CALLBACK (cc_network_panel_notify_enable_active_cb), | ||
1343 | 1101 | panel); | ||
1344 | 1102 | |||
1345 | 1103 | return FALSE; | ||
1347 | 1104 | } | 1304 | } |
1348 | 1105 | 1305 | ||
1349 | 1106 | static void | 1306 | static void |
1350 | 1107 | cc_network_panel_init (CcNetworkPanel *panel) | 1307 | cc_network_panel_init (CcNetworkPanel *panel) |
1351 | 1108 | { | 1308 | { |
1352 | 1109 | DBusGConnection *bus = NULL; | ||
1353 | 1110 | GError *error = NULL; | 1309 | GError *error = NULL; |
1354 | 1111 | GtkStyleContext *context; | 1310 | GtkStyleContext *context; |
1355 | 1112 | GtkTreeSelection *selection; | 1311 | GtkTreeSelection *selection; |
1356 | 1113 | GtkWidget *widget; | 1312 | GtkWidget *widget; |
1357 | 1114 | GtkWidget *toplevel; | 1313 | GtkWidget *toplevel; |
1358 | 1314 | GDBusConnection *system_bus; | ||
1359 | 1315 | GtkCssProvider *provider; | ||
1360 | 1316 | const GPtrArray *connections; | ||
1361 | 1317 | guint i; | ||
1362 | 1115 | 1318 | ||
1363 | 1116 | panel->priv = NETWORK_PANEL_PRIVATE (panel); | 1319 | panel->priv = NETWORK_PANEL_PRIVATE (panel); |
1364 | 1320 | g_resources_register (cc_network_get_resource ()); | ||
1365 | 1117 | 1321 | ||
1366 | 1118 | panel->priv->builder = gtk_builder_new (); | 1322 | panel->priv->builder = gtk_builder_new (); |
1370 | 1119 | gtk_builder_add_from_file (panel->priv->builder, | 1323 | gtk_builder_add_from_resource (panel->priv->builder, |
1371 | 1120 | GNOMECC_UI_DIR "/network.ui", | 1324 | "/org/gnome/control-center/network/network.ui", |
1372 | 1121 | &error); | 1325 | &error); |
1373 | 1122 | if (error != NULL) { | 1326 | if (error != NULL) { |
1374 | 1123 | g_warning ("Could not load interface file: %s", error->message); | 1327 | g_warning ("Could not load interface file: %s", error->message); |
1375 | 1124 | g_error_free (error); | 1328 | g_error_free (error); |
1376 | @@ -1150,16 +1354,35 @@ | |||
1377 | 1150 | panel_add_proxy_device (panel); | 1354 | panel_add_proxy_device (panel); |
1378 | 1151 | 1355 | ||
1379 | 1152 | /* use NetworkManager client */ | 1356 | /* use NetworkManager client */ |
1382 | 1153 | panel->priv->client = nm_client_new (); | 1357 | panel->priv->client = nm_client_new (NULL, NULL); |
1383 | 1154 | g_signal_connect (panel->priv->client, "notify::" NM_CLIENT_MANAGER_RUNNING, | 1358 | g_signal_connect (panel->priv->client, "notify::nm-running" , |
1384 | 1155 | G_CALLBACK (manager_running), panel); | 1359 | G_CALLBACK (manager_running), panel); |
1386 | 1156 | g_signal_connect (panel->priv->client, "notify::" NM_CLIENT_ACTIVE_CONNECTIONS, | 1360 | g_signal_connect (panel->priv->client, "notify::active-connections", |
1387 | 1157 | G_CALLBACK (active_connections_changed), panel); | 1361 | G_CALLBACK (active_connections_changed), panel); |
1388 | 1158 | g_signal_connect (panel->priv->client, "device-added", | 1362 | g_signal_connect (panel->priv->client, "device-added", |
1389 | 1159 | G_CALLBACK (device_added_cb), panel); | 1363 | G_CALLBACK (device_added_cb), panel); |
1390 | 1160 | g_signal_connect (panel->priv->client, "device-removed", | 1364 | g_signal_connect (panel->priv->client, "device-removed", |
1391 | 1161 | G_CALLBACK (device_removed_cb), panel); | 1365 | G_CALLBACK (device_removed_cb), panel); |
1392 | 1162 | 1366 | ||
1393 | 1367 | /* Setup ModemManager client */ | ||
1394 | 1368 | system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); | ||
1395 | 1369 | if (system_bus == NULL) { | ||
1396 | 1370 | g_warning ("Error connecting to system D-Bus: %s", | ||
1397 | 1371 | error->message); | ||
1398 | 1372 | g_clear_error (&error); | ||
1399 | 1373 | } else { | ||
1400 | 1374 | panel->priv->modem_manager = mm_manager_new_sync (system_bus, | ||
1401 | 1375 | G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, | ||
1402 | 1376 | NULL, | ||
1403 | 1377 | &error); | ||
1404 | 1378 | if (panel->priv->modem_manager == NULL) { | ||
1405 | 1379 | g_warning ("Error connecting to ModemManager: %s", | ||
1406 | 1380 | error->message); | ||
1407 | 1381 | g_clear_error (&error); | ||
1408 | 1382 | } | ||
1409 | 1383 | g_object_unref (system_bus); | ||
1410 | 1384 | } | ||
1411 | 1385 | |||
1412 | 1163 | widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, | 1386 | widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, |
1413 | 1164 | "add_toolbutton")); | 1387 | "add_toolbutton")); |
1414 | 1165 | g_signal_connect (widget, "clicked", | 1388 | g_signal_connect (widget, "clicked", |
1415 | @@ -1172,17 +1395,8 @@ | |||
1416 | 1172 | G_CALLBACK (remove_connection), panel); | 1395 | G_CALLBACK (remove_connection), panel); |
1417 | 1173 | 1396 | ||
1418 | 1174 | /* add remote settings such as VPN settings as virtual devices */ | 1397 | /* add remote settings such as VPN settings as virtual devices */ |
1430 | 1175 | bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); | 1398 | g_signal_connect (panel->priv->client, NM_CLIENT_CONNECTION_ADDED, |
1431 | 1176 | if (bus == NULL) { | 1399 | G_CALLBACK (notify_connection_added_cb), panel); |
1421 | 1177 | g_warning ("Error connecting to system D-Bus: %s", | ||
1422 | 1178 | error->message); | ||
1423 | 1179 | g_error_free (error); | ||
1424 | 1180 | } | ||
1425 | 1181 | panel->priv->remote_settings = nm_remote_settings_new (bus); | ||
1426 | 1182 | g_signal_connect (panel->priv->remote_settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ, | ||
1427 | 1183 | G_CALLBACK (notify_connections_read_cb), panel); | ||
1428 | 1184 | g_signal_connect (panel->priv->remote_settings, NM_REMOTE_SETTINGS_NEW_CONNECTION, | ||
1429 | 1185 | G_CALLBACK (notify_new_connection_cb), panel); | ||
1432 | 1186 | 1400 | ||
1433 | 1187 | toplevel = gtk_widget_get_toplevel (GTK_WIDGET (panel)); | 1401 | toplevel = gtk_widget_get_toplevel (GTK_WIDGET (panel)); |
1434 | 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); |
1435 | @@ -1194,10 +1408,22 @@ | |||
1436 | 1194 | 1408 | ||
1437 | 1195 | widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, | 1409 | widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, |
1438 | 1196 | "vbox1")); | 1410 | "vbox1")); |
1443 | 1197 | gtk_widget_reparent (widget, (GtkWidget *) panel); | 1411 | gtk_container_add (GTK_CONTAINER (panel), widget); |
1444 | 1198 | 1412 | ||
1445 | 1199 | /* add kill switch widgets when dialog activated */ | 1413 | provider = gtk_css_provider_new (); |
1446 | 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); |
1447 | 1415 | gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), | ||
1448 | 1416 | GTK_STYLE_PROVIDER (provider), | ||
1449 | 1417 | GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); | ||
1450 | 1418 | g_object_unref (provider); | ||
1451 | 1419 | |||
1452 | 1420 | /* Cold-plug existing connections */ | ||
1453 | 1421 | connections = nm_client_get_connections (panel->priv->client); | ||
1454 | 1422 | for (i = 0; i < connections->len; i++) | ||
1455 | 1423 | add_connection (panel, connections->pdata[i]); | ||
1456 | 1424 | |||
1457 | 1425 | g_debug ("Calling handle_argv() after cold-plugging connections"); | ||
1458 | 1426 | handle_argv (panel); | ||
1459 | 1201 | } | 1427 | } |
1460 | 1202 | 1428 | ||
1461 | 1203 | void | 1429 | void |
1462 | 1204 | 1430 | ||
1463 | === modified file 'panels/network/cc-network-panel.h' | |||
1464 | --- panels/network/cc-network-panel.h 2011-11-07 18:03:14 +0000 | |||
1465 | +++ panels/network/cc-network-panel.h 2019-05-01 13:56:52 +0000 | |||
1466 | @@ -65,7 +65,9 @@ | |||
1467 | 65 | 65 | ||
1468 | 66 | GType cc_network_panel_get_type (void) G_GNUC_CONST; | 66 | GType cc_network_panel_get_type (void) G_GNUC_CONST; |
1469 | 67 | 67 | ||
1471 | 68 | void cc_network_panel_register (GIOModule *module); | 68 | void cc_network_panel_register (GIOModule *module); |
1472 | 69 | |||
1473 | 70 | GPtrArray *cc_network_panel_get_devices (CcNetworkPanel *panel); | ||
1474 | 69 | 71 | ||
1475 | 70 | G_END_DECLS | 72 | G_END_DECLS |
1476 | 71 | 73 | ||
1477 | 72 | 74 | ||
1478 | === added directory 'panels/network/connection-editor' | |||
1479 | === added file 'panels/network/connection-editor/8021x-security-page.ui' | |||
1480 | --- panels/network/connection-editor/8021x-security-page.ui 1970-01-01 00:00:00 +0000 | |||
1481 | +++ panels/network/connection-editor/8021x-security-page.ui 2019-05-01 13:56:52 +0000 | |||
1482 | @@ -0,0 +1,295 @@ | |||
1483 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
1484 | 2 | <interface> | ||
1485 | 3 | <!-- interface-requires gtk+ 3.0 --> | ||
1486 | 4 | <object class="GtkNotebook" id="page"> | ||
1487 | 5 | <property name="visible">True</property> | ||
1488 | 6 | <property name="can_focus">True</property> | ||
1489 | 7 | <property name="show_tabs">False</property> | ||
1490 | 8 | <property name="show_border">False</property> | ||
1491 | 9 | <child> | ||
1492 | 10 | <object class="GtkGrid" id="grid"> | ||
1493 | 11 | <property name="visible">True</property> | ||
1494 | 12 | <property name="can_focus">False</property> | ||
1495 | 13 | <property name="margin_start">50</property> | ||
1496 | 14 | <property name="margin_end">50</property> | ||
1497 | 15 | <property name="margin_top">12</property> | ||
1498 | 16 | <property name="margin_bottom">12</property> | ||
1499 | 17 | <property name="hexpand">True</property> | ||
1500 | 18 | <property name="vexpand">True</property> | ||
1501 | 19 | <property name="row_spacing">10</property> | ||
1502 | 20 | <property name="column_spacing">6</property> | ||
1503 | 21 | <child> | ||
1504 | 22 | <object class="GtkLabel" id="heading_sec"> | ||
1505 | 23 | <property name="visible">True</property> | ||
1506 | 24 | <property name="can_focus">False</property> | ||
1507 | 25 | <property name="xalign">1</property> | ||
1508 | 26 | <property name="label" translatable="yes">802.1x _Security</property> | ||
1509 | 27 | <property name="use_underline">True</property> | ||
1510 | 28 | <property name="mnemonic_widget">8021x_switch</property> | ||
1511 | 29 | </object> | ||
1512 | 30 | <packing> | ||
1513 | 31 | <property name="left_attach">0</property> | ||
1514 | 32 | <property name="top_attach">0</property> | ||
1515 | 33 | <property name="width">1</property> | ||
1516 | 34 | <property name="height">1</property> | ||
1517 | 35 | </packing> | ||
1518 | 36 | </child> | ||
1519 | 37 | <child> | ||
1520 | 38 | <object class="GtkSwitch" id="8021x_switch"> | ||
1521 | 39 | <property name="visible">True</property> | ||
1522 | 40 | <property name="can_focus">True</property> | ||
1523 | 41 | <property name="halign">start</property> | ||
1524 | 42 | <property name="hexpand">True</property> | ||
1525 | 43 | </object> | ||
1526 | 44 | <packing> | ||
1527 | 45 | <property name="left_attach">1</property> | ||
1528 | 46 | <property name="top_attach">0</property> | ||
1529 | 47 | <property name="width">1</property> | ||
1530 | 48 | <property name="height">1</property> | ||
1531 | 49 | </packing> | ||
1532 | 50 | </child> | ||
1533 | 51 | <child> | ||
1534 | 52 | <object class="GtkBox" id="vbox"> | ||
1535 | 53 | <property name="visible">True</property> | ||
1536 | 54 | <property name="can_focus">False</property> | ||
1537 | 55 | <property name="orientation">vertical</property> | ||
1538 | 56 | <child> | ||
1539 | 57 | <placeholder/> | ||
1540 | 58 | </child> | ||
1541 | 59 | </object> | ||
1542 | 60 | <packing> | ||
1543 | 61 | <property name="left_attach">0</property> | ||
1544 | 62 | <property name="top_attach">1</property> | ||
1545 | 63 | <property name="width">2</property> | ||
1546 | 64 | <property name="height">1</property> | ||
1547 | 65 | </packing> | ||
1548 | 66 | </child> | ||
1549 | 67 | </object> | ||
1550 | 68 | </child> | ||
1551 | 69 | <child type="tab"> | ||
1552 | 70 | <object class="GtkLabel" id="label1"> | ||
1553 | 71 | <property name="visible">True</property> | ||
1554 | 72 | <property name="can_focus">False</property> | ||
1555 | 73 | <property name="label" translatable="yes">page 1</property> | ||
1556 | 74 | </object> | ||
1557 | 75 | <packing> | ||
1558 | 76 | <property name="tab_fill">False</property> | ||
1559 | 77 | </packing> | ||
1560 | 78 | </child> | ||
1561 | 79 | <child> | ||
1562 | 80 | <object class="GtkGrid" id="grid1"> | ||
1563 | 81 | <property name="visible">True</property> | ||
1564 | 82 | <property name="can_focus">False</property> | ||
1565 | 83 | <property name="margin_start">50</property> | ||
1566 | 84 | <property name="margin_end">50</property> | ||
1567 | 85 | <property name="margin_top">12</property> | ||
1568 | 86 | <property name="margin_bottom">12</property> | ||
1569 | 87 | <property name="row_spacing">10</property> | ||
1570 | 88 | <property name="column_spacing">6</property> | ||
1571 | 89 | <child> | ||
1572 | 90 | <object class="GtkEntry" id="entry1"> | ||
1573 | 91 | <property name="visible">True</property> | ||
1574 | 92 | <property name="can_focus">True</property> | ||
1575 | 93 | <property name="invisible_char">●</property> | ||
1576 | 94 | <property name="width_chars">35</property> | ||
1577 | 95 | </object> | ||
1578 | 96 | <packing> | ||
1579 | 97 | <property name="left_attach">1</property> | ||
1580 | 98 | <property name="top_attach">0</property> | ||
1581 | 99 | <property name="width">1</property> | ||
1582 | 100 | <property name="height">1</property> | ||
1583 | 101 | </packing> | ||
1584 | 102 | </child> | ||
1585 | 103 | <child> | ||
1586 | 104 | <object class="GtkEntry" id="entry2"> | ||
1587 | 105 | <property name="visible">True</property> | ||
1588 | 106 | <property name="can_focus">True</property> | ||
1589 | 107 | <property name="invisible_char">●</property> | ||
1590 | 108 | </object> | ||
1591 | 109 | <packing> | ||
1592 | 110 | <property name="left_attach">1</property> | ||
1593 | 111 | <property name="top_attach">1</property> | ||
1594 | 112 | <property name="width">1</property> | ||
1595 | 113 | <property name="height">1</property> | ||
1596 | 114 | </packing> | ||
1597 | 115 | </child> | ||
1598 | 116 | <child> | ||
1599 | 117 | <object class="GtkEntry" id="entry3"> | ||
1600 | 118 | <property name="visible">True</property> | ||
1601 | 119 | <property name="can_focus">True</property> | ||
1602 | 120 | <property name="invisible_char">●</property> | ||
1603 | 121 | </object> | ||
1604 | 122 | <packing> | ||
1605 | 123 | <property name="left_attach">1</property> | ||
1606 | 124 | <property name="top_attach">2</property> | ||
1607 | 125 | <property name="width">1</property> | ||
1608 | 126 | <property name="height">1</property> | ||
1609 | 127 | </packing> | ||
1610 | 128 | </child> | ||
1611 | 129 | <child> | ||
1612 | 130 | <object class="GtkEntry" id="entry4"> | ||
1613 | 131 | <property name="visible">True</property> | ||
1614 | 132 | <property name="can_focus">True</property> | ||
1615 | 133 | <property name="invisible_char">●</property> | ||
1616 | 134 | </object> | ||
1617 | 135 | <packing> | ||
1618 | 136 | <property name="left_attach">1</property> | ||
1619 | 137 | <property name="top_attach">3</property> | ||
1620 | 138 | <property name="width">1</property> | ||
1621 | 139 | <property name="height">1</property> | ||
1622 | 140 | </packing> | ||
1623 | 141 | </child> | ||
1624 | 142 | <child> | ||
1625 | 143 | <object class="GtkEntry" id="entry5"> | ||
1626 | 144 | <property name="visible">True</property> | ||
1627 | 145 | <property name="can_focus">True</property> | ||
1628 | 146 | <property name="invisible_char">●</property> | ||
1629 | 147 | </object> | ||
1630 | 148 | <packing> | ||
1631 | 149 | <property name="left_attach">1</property> | ||
1632 | 150 | <property name="top_attach">4</property> | ||
1633 | 151 | <property name="width">1</property> | ||
1634 | 152 | <property name="height">1</property> | ||
1635 | 153 | </packing> | ||
1636 | 154 | </child> | ||
1637 | 155 | <child> | ||
1638 | 156 | <object class="GtkEntry" id="entry6"> | ||
1639 | 157 | <property name="visible">True</property> | ||
1640 | 158 | <property name="can_focus">True</property> | ||
1641 | 159 | <property name="invisible_char">●</property> | ||
1642 | 160 | </object> | ||
1643 | 161 | <packing> | ||
1644 | 162 | <property name="left_attach">1</property> | ||
1645 | 163 | <property name="top_attach">5</property> | ||
1646 | 164 | <property name="width">1</property> | ||
1647 | 165 | <property name="height">1</property> | ||
1648 | 166 | </packing> | ||
1649 | 167 | </child> | ||
1650 | 168 | <child> | ||
1651 | 169 | <object class="GtkEntry" id="entry7"> | ||
1652 | 170 | <property name="visible">True</property> | ||
1653 | 171 | <property name="can_focus">True</property> | ||
1654 | 172 | <property name="invisible_char">●</property> | ||
1655 | 173 | </object> | ||
1656 | 174 | <packing> | ||
1657 | 175 | <property name="left_attach">1</property> | ||
1658 | 176 | <property name="top_attach">6</property> | ||
1659 | 177 | <property name="width">1</property> | ||
1660 | 178 | <property name="height">1</property> | ||
1661 | 179 | </packing> | ||
1662 | 180 | </child> | ||
1663 | 181 | <child> | ||
1664 | 182 | <object class="GtkEntry" id="entry8"> | ||
1665 | 183 | <property name="visible">True</property> | ||
1666 | 184 | <property name="can_focus">True</property> | ||
1667 | 185 | <property name="invisible_char">●</property> | ||
1668 | 186 | </object> | ||
1669 | 187 | <packing> | ||
1670 | 188 | <property name="left_attach">1</property> | ||
1671 | 189 | <property name="top_attach">7</property> | ||
1672 | 190 | <property name="width">1</property> | ||
1673 | 191 | <property name="height">1</property> | ||
1674 | 192 | </packing> | ||
1675 | 193 | </child> | ||
1676 | 194 | <child> | ||
1677 | 195 | <object class="GtkEntry" id="entry9"> | ||
1678 | 196 | <property name="visible">True</property> | ||
1679 | 197 | <property name="can_focus">True</property> | ||
1680 | 198 | <property name="invisible_char">●</property> | ||
1681 | 199 | </object> | ||
1682 | 200 | <packing> | ||
1683 | 201 | <property name="left_attach">1</property> | ||
1684 | 202 | <property name="top_attach">8</property> | ||
1685 | 203 | <property name="width">1</property> | ||
1686 | 204 | <property name="height">1</property> | ||
1687 | 205 | </packing> | ||
1688 | 206 | </child> | ||
1689 | 207 | <child> | ||
1690 | 208 | <object class="GtkEntry" id="entry10"> | ||
1691 | 209 | <property name="visible">True</property> | ||
1692 | 210 | <property name="can_focus">True</property> | ||
1693 | 211 | <property name="invisible_char">●</property> | ||
1694 | 212 | </object> | ||
1695 | 213 | <packing> | ||
1696 | 214 | <property name="left_attach">1</property> | ||
1697 | 215 | <property name="top_attach">9</property> | ||
1698 | 216 | <property name="width">1</property> | ||
1699 | 217 | <property name="height">1</property> | ||
1700 | 218 | </packing> | ||
1701 | 219 | </child> | ||
1702 | 220 | <child> | ||
1703 | 221 | <object class="GtkLabel" id="label3"> | ||
1704 | 222 | <property name="visible">True</property> | ||
1705 | 223 | <property name="can_focus">False</property> | ||
1706 | 224 | <property name="label" translatable="yes">Anony_mous identity</property> | ||
1707 | 225 | <property name="use_underline">True</property> | ||
1708 | 226 | </object> | ||
1709 | 227 | <packing> | ||
1710 | 228 | <property name="left_attach">0</property> | ||
1711 | 229 | <property name="top_attach">0</property> | ||
1712 | 230 | <property name="width">1</property> | ||
1713 | 231 | <property name="height">1</property> | ||
1714 | 232 | </packing> | ||
1715 | 233 | </child> | ||
1716 | 234 | <child> | ||
1717 | 235 | <object class="GtkLabel" id="label4"> | ||
1718 | 236 | <property name="visible">True</property> | ||
1719 | 237 | <property name="can_focus">False</property> | ||
1720 | 238 | <property name="label" translatable="yes">Inner _authentication</property> | ||
1721 | 239 | <property name="use_underline">True</property> | ||
1722 | 240 | </object> | ||
1723 | 241 | <packing> | ||
1724 | 242 | <property name="left_attach">0</property> | ||
1725 | 243 | <property name="top_attach">1</property> | ||
1726 | 244 | <property name="width">1</property> | ||
1727 | 245 | <property name="height">1</property> | ||
1728 | 246 | </packing> | ||
1729 | 247 | </child> | ||
1730 | 248 | <child> | ||
1731 | 249 | <placeholder/> | ||
1732 | 250 | </child> | ||
1733 | 251 | <child> | ||
1734 | 252 | <placeholder/> | ||
1735 | 253 | </child> | ||
1736 | 254 | <child> | ||
1737 | 255 | <placeholder/> | ||
1738 | 256 | </child> | ||
1739 | 257 | <child> | ||
1740 | 258 | <placeholder/> | ||
1741 | 259 | </child> | ||
1742 | 260 | <child> | ||
1743 | 261 | <placeholder/> | ||
1744 | 262 | </child> | ||
1745 | 263 | <child> | ||
1746 | 264 | <placeholder/> | ||
1747 | 265 | </child> | ||
1748 | 266 | <child> | ||
1749 | 267 | <placeholder/> | ||
1750 | 268 | </child> | ||
1751 | 269 | <child> | ||
1752 | 270 | <placeholder/> | ||
1753 | 271 | </child> | ||
1754 | 272 | </object> | ||
1755 | 273 | <packing> | ||
1756 | 274 | <property name="position">1</property> | ||
1757 | 275 | </packing> | ||
1758 | 276 | </child> | ||
1759 | 277 | <child type="tab"> | ||
1760 | 278 | <object class="GtkLabel" id="label2"> | ||
1761 | 279 | <property name="visible">True</property> | ||
1762 | 280 | <property name="can_focus">False</property> | ||
1763 | 281 | <property name="label" translatable="yes">page 2</property> | ||
1764 | 282 | </object> | ||
1765 | 283 | <packing> | ||
1766 | 284 | <property name="position">1</property> | ||
1767 | 285 | <property name="tab_fill">False</property> | ||
1768 | 286 | </packing> | ||
1769 | 287 | </child> | ||
1770 | 288 | <child> | ||
1771 | 289 | <placeholder/> | ||
1772 | 290 | </child> | ||
1773 | 291 | <child type="tab"> | ||
1774 | 292 | <placeholder/> | ||
1775 | 293 | </child> | ||
1776 | 294 | </object> | ||
1777 | 295 | </interface> | ||
1778 | 0 | 296 | ||
1779 | === added file 'panels/network/connection-editor/Makefile.am' | |||
1780 | --- panels/network/connection-editor/Makefile.am 1970-01-01 00:00:00 +0000 | |||
1781 | +++ panels/network/connection-editor/Makefile.am 2019-05-01 13:56:52 +0000 | |||
1782 | @@ -0,0 +1,54 @@ | |||
1783 | 1 | noinst_LTLIBRARIES = libconnection-editor.la | ||
1784 | 2 | |||
1785 | 3 | BUILT_SOURCES = \ | ||
1786 | 4 | net-connection-editor-resources.c \ | ||
1787 | 5 | net-connection-editor-resources.h | ||
1788 | 6 | |||
1789 | 7 | libconnection_editor_la_SOURCES = \ | ||
1790 | 8 | $(BUILT_SOURCES) \ | ||
1791 | 9 | net-connection-editor.h \ | ||
1792 | 10 | net-connection-editor.c \ | ||
1793 | 11 | ce-page.h \ | ||
1794 | 12 | ce-page.c \ | ||
1795 | 13 | ce-page-details.h \ | ||
1796 | 14 | ce-page-details.c \ | ||
1797 | 15 | ce-page-wifi.h \ | ||
1798 | 16 | ce-page-wifi.c \ | ||
1799 | 17 | ce-page-ip4.h \ | ||
1800 | 18 | ce-page-ip4.c \ | ||
1801 | 19 | ce-page-ip6.h \ | ||
1802 | 20 | ce-page-ip6.c \ | ||
1803 | 21 | ce-page-security.h \ | ||
1804 | 22 | ce-page-security.c \ | ||
1805 | 23 | ce-page-ethernet.h \ | ||
1806 | 24 | ce-page-ethernet.c \ | ||
1807 | 25 | ce-page-8021x-security.h \ | ||
1808 | 26 | ce-page-8021x-security.c \ | ||
1809 | 27 | ce-page-vpn.h \ | ||
1810 | 28 | ce-page-vpn.c \ | ||
1811 | 29 | vpn-helpers.h \ | ||
1812 | 30 | vpn-helpers.c \ | ||
1813 | 31 | ui-helpers.h \ | ||
1814 | 32 | ui-helpers.c | ||
1815 | 33 | |||
1816 | 34 | libconnection_editor_la_CPPFLAGS = \ | ||
1817 | 35 | $(PANEL_CFLAGS) \ | ||
1818 | 36 | -I$(srcdir)/../wireless-security \ | ||
1819 | 37 | $(NETWORK_PANEL_CFLAGS) \ | ||
1820 | 38 | $(NETWORK_MANAGER_CFLAGS) | ||
1821 | 39 | |||
1822 | 40 | libconnection_editor_la_LIBADD = \ | ||
1823 | 41 | $(builddir)/../wireless-security/libwireless-security.la \ | ||
1824 | 42 | $(NETWORK_PANEL_LIBS) \ | ||
1825 | 43 | $(NETWORK_MANAGER_LIBS) | ||
1826 | 44 | |||
1827 | 45 | resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/connection-editor.gresource.xml) | ||
1828 | 46 | net-connection-editor-resources.c: connection-editor.gresource.xml $(resource_files) | ||
1829 | 47 | $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name net_connection_editor $< | ||
1830 | 48 | net-connection-editor-resources.h: connection-editor.gresource.xml $(resource_files) | ||
1831 | 49 | $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-header --c-name net_connection_editor $< | ||
1832 | 50 | |||
1833 | 51 | EXTRA_DIST = \ | ||
1834 | 52 | $(resource_files) connection-editor.gresource.xml | ||
1835 | 53 | |||
1836 | 54 | -include $(top_srcdir)/git.mk | ||
1837 | 0 | 55 | ||
1838 | === added file 'panels/network/connection-editor/ce-page-8021x-security.c' | |||
1839 | --- panels/network/connection-editor/ce-page-8021x-security.c 1970-01-01 00:00:00 +0000 | |||
1840 | +++ panels/network/connection-editor/ce-page-8021x-security.c 2019-05-01 13:56:52 +0000 | |||
1841 | @@ -0,0 +1,186 @@ | |||
1842 | 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ | ||
1843 | 2 | /* NetworkManager Connection editor -- Connection editor for NetworkManager | ||
1844 | 3 | * | ||
1845 | 4 | * Dan Williams <dcbw@redhat.com> | ||
1846 | 5 | * | ||
1847 | 6 | * This program is free software; you can redistribute it and/or modify | ||
1848 | 7 | * it under the terms of the GNU General Public License as published by | ||
1849 | 8 | * the Free Software Foundation; either version 2 of the License, or | ||
1850 | 9 | * (at your option) any later version. | ||
1851 | 10 | * | ||
1852 | 11 | * This program is distributed in the hope that it will be useful, | ||
1853 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1854 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1855 | 14 | * GNU General Public License for more details. | ||
1856 | 15 | * | ||
1857 | 16 | * You should have received a copy of the GNU General Public License along | ||
1858 | 17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
1859 | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
1860 | 19 | * | ||
1861 | 20 | * (C) Copyright 2008 - 2012 Red Hat, Inc. | ||
1862 | 21 | */ | ||
1863 | 22 | |||
1864 | 23 | #include "config.h" | ||
1865 | 24 | |||
1866 | 25 | #include <string.h> | ||
1867 | 26 | |||
1868 | 27 | #include <gtk/gtk.h> | ||
1869 | 28 | #include <glib/gi18n.h> | ||
1870 | 29 | |||
1871 | 30 | #include <NetworkManager.h> | ||
1872 | 31 | |||
1873 | 32 | #include "wireless-security.h" | ||
1874 | 33 | #include "ce-page-ethernet.h" | ||
1875 | 34 | #include "ce-page-8021x-security.h" | ||
1876 | 35 | |||
1877 | 36 | G_DEFINE_TYPE (CEPage8021xSecurity, ce_page_8021x_security, CE_TYPE_PAGE) | ||
1878 | 37 | |||
1879 | 38 | static void | ||
1880 | 39 | enable_toggled (GObject *sw, GParamSpec *pspec, gpointer user_data) | ||
1881 | 40 | { | ||
1882 | 41 | CEPage8021xSecurity *page = CE_PAGE_8021X_SECURITY (user_data); | ||
1883 | 42 | |||
1884 | 43 | gtk_widget_set_sensitive (page->security_widget, gtk_switch_get_active (page->enabled)); | ||
1885 | 44 | ce_page_changed (CE_PAGE (page)); | ||
1886 | 45 | } | ||
1887 | 46 | |||
1888 | 47 | static void | ||
1889 | 48 | stuff_changed (WirelessSecurity *sec, gpointer user_data) | ||
1890 | 49 | { | ||
1891 | 50 | ce_page_changed (CE_PAGE (user_data)); | ||
1892 | 51 | } | ||
1893 | 52 | |||
1894 | 53 | static void | ||
1895 | 54 | finish_setup (CEPage8021xSecurity *page, gpointer unused, GError *error, gpointer user_data) | ||
1896 | 55 | { | ||
1897 | 56 | GtkWidget *parent; | ||
1898 | 57 | GtkWidget *vbox; | ||
1899 | 58 | GtkWidget *heading; | ||
1900 | 59 | |||
1901 | 60 | if (error) | ||
1902 | 61 | return; | ||
1903 | 62 | |||
1904 | 63 | vbox = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "vbox")); | ||
1905 | 64 | heading = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "heading_sec")); | ||
1906 | 65 | |||
1907 | 66 | page->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); | ||
1908 | 67 | |||
1909 | 68 | page->security = (WirelessSecurity *) ws_wpa_eap_new (CE_PAGE (page)->connection, TRUE, FALSE); | ||
1910 | 69 | if (!page->security) { | ||
1911 | 70 | g_warning ("Could not load 802.1x user interface."); | ||
1912 | 71 | return; | ||
1913 | 72 | } | ||
1914 | 73 | |||
1915 | 74 | wireless_security_set_changed_notify (page->security, stuff_changed, page); | ||
1916 | 75 | page->security_widget = wireless_security_get_widget (page->security); | ||
1917 | 76 | parent = gtk_widget_get_parent (page->security_widget); | ||
1918 | 77 | if (parent) | ||
1919 | 78 | gtk_container_remove (GTK_CONTAINER (parent), page->security_widget); | ||
1920 | 79 | |||
1921 | 80 | gtk_switch_set_active (page->enabled, page->initial_have_8021x); | ||
1922 | 81 | g_signal_connect (page->enabled, "notify::active", G_CALLBACK (enable_toggled), page); | ||
1923 | 82 | gtk_widget_set_sensitive (page->security_widget, page->initial_have_8021x); | ||
1924 | 83 | |||
1925 | 84 | gtk_size_group_add_widget (page->group, heading); | ||
1926 | 85 | wireless_security_add_to_size_group (page->security, page->group); | ||
1927 | 86 | |||
1928 | 87 | gtk_container_add (GTK_CONTAINER (vbox), page->security_widget); | ||
1929 | 88 | |||
1930 | 89 | } | ||
1931 | 90 | |||
1932 | 91 | CEPage * | ||
1933 | 92 | ce_page_8021x_security_new (NMConnection *connection, | ||
1934 | 93 | NMClient *client) | ||
1935 | 94 | { | ||
1936 | 95 | CEPage8021xSecurity *page; | ||
1937 | 96 | |||
1938 | 97 | page = CE_PAGE_8021X_SECURITY (ce_page_new (CE_TYPE_PAGE_8021X_SECURITY, | ||
1939 | 98 | connection, | ||
1940 | 99 | client, | ||
1941 | 100 | "/org/gnome/control-center/network/8021x-security-page.ui", | ||
1942 | 101 | _("Security"))); | ||
1943 | 102 | |||
1944 | 103 | if (nm_connection_get_setting_802_1x (connection)) | ||
1945 | 104 | page->initial_have_8021x = TRUE; | ||
1946 | 105 | |||
1947 | 106 | page->enabled = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "8021x_switch")); | ||
1948 | 107 | |||
1949 | 108 | g_signal_connect (page, "initialized", G_CALLBACK (finish_setup), NULL); | ||
1950 | 109 | |||
1951 | 110 | if (page->initial_have_8021x) | ||
1952 | 111 | CE_PAGE (page)->security_setting = NM_SETTING_802_1X_SETTING_NAME; | ||
1953 | 112 | |||
1954 | 113 | return CE_PAGE (page); | ||
1955 | 114 | } | ||
1956 | 115 | |||
1957 | 116 | static gboolean | ||
1958 | 117 | validate (CEPage *cepage, NMConnection *connection, GError **error) | ||
1959 | 118 | { | ||
1960 | 119 | CEPage8021xSecurity *page = CE_PAGE_8021X_SECURITY (cepage); | ||
1961 | 120 | gboolean valid = TRUE; | ||
1962 | 121 | |||
1963 | 122 | if (gtk_switch_get_active (page->enabled)) { | ||
1964 | 123 | NMConnection *tmp_connection; | ||
1965 | 124 | NMSetting *s_8021x; | ||
1966 | 125 | |||
1967 | 126 | /* FIXME: get failed property and error out of wireless security objects */ | ||
1968 | 127 | valid = wireless_security_validate (page->security, error); | ||
1969 | 128 | if (valid) { | ||
1970 | 129 | NMSetting *s_con; | ||
1971 | 130 | |||
1972 | 131 | /* Here's a nice hack to work around the fact that ws_802_1x_fill_connection needs wireless setting. */ | ||
1973 | 132 | tmp_connection = nm_simple_connection_new (); | ||
1974 | 133 | nm_connection_add_setting (tmp_connection, nm_setting_wireless_new ()); | ||
1975 | 134 | |||
1976 | 135 | /* temp connection needs a 'connection' setting too, since most of | ||
1977 | 136 | * the EAP methods need the UUID for CA cert ignore stuff. | ||
1978 | 137 | */ | ||
1979 | 138 | s_con = nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); | ||
1980 | 139 | nm_connection_add_setting (tmp_connection, nm_setting_duplicate (s_con)); | ||
1981 | 140 | |||
1982 | 141 | ws_802_1x_fill_connection (page->security, "wpa_eap_auth_combo", tmp_connection); | ||
1983 | 142 | |||
1984 | 143 | s_8021x = nm_connection_get_setting (tmp_connection, NM_TYPE_SETTING_802_1X); | ||
1985 | 144 | nm_connection_add_setting (connection, NM_SETTING (g_object_ref (s_8021x))); | ||
1986 | 145 | |||
1987 | 146 | g_object_unref (tmp_connection); | ||
1988 | 147 | } | ||
1989 | 148 | } else { | ||
1990 | 149 | nm_connection_remove_setting (connection, NM_TYPE_SETTING_802_1X); | ||
1991 | 150 | valid = TRUE; | ||
1992 | 151 | } | ||
1993 | 152 | |||
1994 | 153 | return valid; | ||
1995 | 154 | } | ||
1996 | 155 | |||
1997 | 156 | static void | ||
1998 | 157 | ce_page_8021x_security_init (CEPage8021xSecurity *page) | ||
1999 | 158 | { | ||
2000 | 159 | } | ||
2001 | 160 | |||
2002 | 161 | static void | ||
2003 | 162 | dispose (GObject *object) | ||
2004 | 163 | { | ||
2005 | 164 | CEPage8021xSecurity *page = CE_PAGE_8021X_SECURITY (object); | ||
2006 | 165 | |||
2007 | 166 | if (page->security) { | ||
2008 | 167 | wireless_security_unref (page->security); | ||
2009 | 168 | page->security = NULL; | ||
2010 | 169 | } | ||
2011 | 170 | |||
2012 | 171 | g_clear_object (&page->group); | ||
2013 | 172 | |||
2014 | 173 | G_OBJECT_CLASS (ce_page_8021x_security_parent_class)->dispose (object); | ||
2015 | 174 | } | ||
2016 | 175 | |||
2017 | 176 | static void | ||
2018 | 177 | ce_page_8021x_security_class_init (CEPage8021xSecurityClass *security_class) | ||
2019 | 178 | { | ||
2020 | 179 | GObjectClass *object_class = G_OBJECT_CLASS (security_class); | ||
2021 | 180 | CEPageClass *parent_class = CE_PAGE_CLASS (security_class); | ||
2022 | 181 | |||
2023 | 182 | /* virtual methods */ | ||
2024 | 183 | object_class->dispose = dispose; | ||
2025 | 184 | |||
2026 | 185 | parent_class->validate = validate; | ||
2027 | 186 | } | ||
2028 | 0 | 187 | ||
2029 | === added file 'panels/network/connection-editor/ce-page-8021x-security.h' | |||
2030 | --- panels/network/connection-editor/ce-page-8021x-security.h 1970-01-01 00:00:00 +0000 | |||
2031 | +++ panels/network/connection-editor/ce-page-8021x-security.h 2019-05-01 13:56:52 +0000 | |||
2032 | @@ -0,0 +1,63 @@ | |||
2033 | 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ | ||
2034 | 2 | /* NetworkManager Connection editor -- Connection editor for NetworkManager | ||
2035 | 3 | * | ||
2036 | 4 | * Dan Williams <dcbw@redhat.com> | ||
2037 | 5 | * | ||
2038 | 6 | * This program is free software; you can redistribute it and/or modify | ||
2039 | 7 | * it under the terms of the GNU General Public License as published by | ||
2040 | 8 | * the Free Software Foundation; either version 2 of the License, or | ||
2041 | 9 | * (at your option) any later version. | ||
2042 | 10 | * | ||
2043 | 11 | * This program is distributed in the hope that it will be useful, | ||
2044 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2045 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2046 | 14 | * GNU General Public License for more details. | ||
2047 | 15 | * | ||
2048 | 16 | * You should have received a copy of the GNU General Public License along | ||
2049 | 17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
2050 | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
2051 | 19 | * | ||
2052 | 20 | * (C) Copyright 2008 - 2012 Red Hat, Inc. | ||
2053 | 21 | */ | ||
2054 | 22 | |||
2055 | 23 | #ifndef __CE_PAGE_8021X_SECURITY_H | ||
2056 | 24 | #define __CE_PAGE_8021X_SECURITY_H | ||
2057 | 25 | |||
2058 | 26 | #include <NetworkManager.h> | ||
2059 | 27 | #include "wireless-security.h" | ||
2060 | 28 | |||
2061 | 29 | #include <glib.h> | ||
2062 | 30 | #include <glib-object.h> | ||
2063 | 31 | |||
2064 | 32 | #include "ce-page.h" | ||
2065 | 33 | |||
2066 | 34 | #define CE_TYPE_PAGE_8021X_SECURITY (ce_page_8021x_security_get_type ()) | ||
2067 | 35 | #define CE_PAGE_8021X_SECURITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CE_TYPE_PAGE_8021X_SECURITY, CEPage8021xSecurity)) | ||
2068 | 36 | #define CE_PAGE_8021X_SECURITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CE_TYPE_PAGE_8021X_SECURITY, CEPage8021xSecurityClass)) | ||
2069 | 37 | #define CE_IS_PAGE_8021X_SECURITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CE_TYPE_PAGE_8021X_SECURITY)) | ||
2070 | 38 | #define CE_IS_PAGE_8021X_SECURITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CE_TYPE_PAGE_8021X_SECURITY)) | ||
2071 | 39 | #define CE_PAGE_8021X_SECURITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CE_TYPE_PAGE_8021X_SECURITY, CEPage8021xSecurityClass)) | ||
2072 | 40 | |||
2073 | 41 | typedef struct CEPage8021xSecurity CEPage8021xSecurity; | ||
2074 | 42 | typedef struct CEPage8021xSecurityClass CEPage8021xSecurityClass; | ||
2075 | 43 | |||
2076 | 44 | struct CEPage8021xSecurity { | ||
2077 | 45 | CEPage parent; | ||
2078 | 46 | |||
2079 | 47 | GtkSwitch *enabled; | ||
2080 | 48 | GtkWidget *security_widget; | ||
2081 | 49 | WirelessSecurity *security; | ||
2082 | 50 | GtkSizeGroup *group; | ||
2083 | 51 | gboolean initial_have_8021x; | ||
2084 | 52 | }; | ||
2085 | 53 | |||
2086 | 54 | struct CEPage8021xSecurityClass { | ||
2087 | 55 | CEPageClass parent; | ||
2088 | 56 | }; | ||
2089 | 57 | |||
2090 | 58 | GType ce_page_8021x_security_get_type (void); | ||
2091 | 59 | |||
2092 | 60 | CEPage *ce_page_8021x_security_new (NMConnection *connection, | ||
2093 | 61 | NMClient *client); | ||
2094 | 62 | |||
2095 | 63 | #endif /* __CE_PAGE_8021X_SECURITY_H */ | ||
2096 | 0 | 64 | ||
2097 | === added file 'panels/network/connection-editor/ce-page-details.c' | |||
2098 | --- panels/network/connection-editor/ce-page-details.c 1970-01-01 00:00:00 +0000 | |||
2099 | +++ panels/network/connection-editor/ce-page-details.c 2019-05-01 13:56:52 +0000 | |||
2100 | @@ -0,0 +1,289 @@ | |||
2101 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
2102 | 2 | * | ||
2103 | 3 | * Copyright (C) 2012 Red Hat, Inc | ||
2104 | 4 | * | ||
2105 | 5 | * Licensed under the GNU General Public License Version 2 | ||
2106 | 6 | * | ||
2107 | 7 | * This program is free software; you can redistribute it and/or modify | ||
2108 | 8 | * it under the terms of the GNU General Public License as published by | ||
2109 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
2110 | 10 | * (at your option) any later version. | ||
2111 | 11 | * | ||
2112 | 12 | * This program is distributed in the hope that it will be useful, | ||
2113 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2114 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2115 | 15 | * GNU General Public License for more details. | ||
2116 | 16 | * | ||
2117 | 17 | * You should have received a copy of the GNU General Public License | ||
2118 | 18 | * along with this program; if not, write to the Free Software | ||
2119 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
2120 | 20 | */ | ||
2121 | 21 | |||
2122 | 22 | #include "config.h" | ||
2123 | 23 | |||
2124 | 24 | #include <glib-object.h> | ||
2125 | 25 | #include <glib/gi18n.h> | ||
2126 | 26 | |||
2127 | 27 | #include <NetworkManager.h> | ||
2128 | 28 | |||
2129 | 29 | #include "../panel-common.h" | ||
2130 | 30 | #include "ce-page-details.h" | ||
2131 | 31 | |||
2132 | 32 | G_DEFINE_TYPE (CEPageDetails, ce_page_details, CE_TYPE_PAGE) | ||
2133 | 33 | |||
2134 | 34 | static void | ||
2135 | 35 | forget_cb (GtkButton *button, CEPageDetails *page) | ||
2136 | 36 | { | ||
2137 | 37 | net_connection_editor_forget (page->editor); | ||
2138 | 38 | } | ||
2139 | 39 | |||
2140 | 40 | static gchar * | ||
2141 | 41 | get_ap_security_string (NMAccessPoint *ap) | ||
2142 | 42 | { | ||
2143 | 43 | NM80211ApSecurityFlags wpa_flags, rsn_flags; | ||
2144 | 44 | NM80211ApFlags flags; | ||
2145 | 45 | GString *str; | ||
2146 | 46 | |||
2147 | 47 | flags = nm_access_point_get_flags (ap); | ||
2148 | 48 | wpa_flags = nm_access_point_get_wpa_flags (ap); | ||
2149 | 49 | rsn_flags = nm_access_point_get_rsn_flags (ap); | ||
2150 | 50 | |||
2151 | 51 | str = g_string_new (""); | ||
2152 | 52 | if ((flags & NM_802_11_AP_FLAGS_PRIVACY) && | ||
2153 | 53 | (wpa_flags == NM_802_11_AP_SEC_NONE) && | ||
2154 | 54 | (rsn_flags == NM_802_11_AP_SEC_NONE)) { | ||
2155 | 55 | /* TRANSLATORS: this WEP WiFi security */ | ||
2156 | 56 | g_string_append_printf (str, "%s, ", _("WEP")); | ||
2157 | 57 | } | ||
2158 | 58 | if (wpa_flags != NM_802_11_AP_SEC_NONE) { | ||
2159 | 59 | /* TRANSLATORS: this WPA WiFi security */ | ||
2160 | 60 | g_string_append_printf (str, "%s, ", _("WPA")); | ||
2161 | 61 | } | ||
2162 | 62 | if (rsn_flags != NM_802_11_AP_SEC_NONE) { | ||
2163 | 63 | /* TRANSLATORS: this WPA WiFi security */ | ||
2164 | 64 | g_string_append_printf (str, "%s, ", _("WPA2")); | ||
2165 | 65 | } | ||
2166 | 66 | if ((wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) || | ||
2167 | 67 | (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) { | ||
2168 | 68 | /* TRANSLATORS: this Enterprise WiFi security */ | ||
2169 | 69 | g_string_append_printf (str, "%s, ", _("Enterprise")); | ||
2170 | 70 | } | ||
2171 | 71 | if (str->len > 0) | ||
2172 | 72 | g_string_set_size (str, str->len - 2); | ||
2173 | 73 | else { | ||
2174 | 74 | g_string_append (str, C_("Wifi security", "None")); | ||
2175 | 75 | } | ||
2176 | 76 | return g_string_free (str, FALSE); | ||
2177 | 77 | } | ||
2178 | 78 | |||
2179 | 79 | static void | ||
2180 | 80 | update_last_used (CEPageDetails *page, NMConnection *connection) | ||
2181 | 81 | { | ||
2182 | 82 | gchar *last_used = NULL; | ||
2183 | 83 | GDateTime *now = NULL; | ||
2184 | 84 | GDateTime *then = NULL; | ||
2185 | 85 | gint days; | ||
2186 | 86 | GTimeSpan diff; | ||
2187 | 87 | guint64 timestamp; | ||
2188 | 88 | NMSettingConnection *s_con; | ||
2189 | 89 | |||
2190 | 90 | s_con = nm_connection_get_setting_connection (connection); | ||
2191 | 91 | if (s_con == NULL) | ||
2192 | 92 | goto out; | ||
2193 | 93 | timestamp = nm_setting_connection_get_timestamp (s_con); | ||
2194 | 94 | if (timestamp == 0) { | ||
2195 | 95 | last_used = g_strdup (_("Never")); | ||
2196 | 96 | goto out; | ||
2197 | 97 | } | ||
2198 | 98 | |||
2199 | 99 | /* calculate the amount of time that has elapsed */ | ||
2200 | 100 | now = g_date_time_new_now_utc (); | ||
2201 | 101 | then = g_date_time_new_from_unix_utc (timestamp); | ||
2202 | 102 | |||
2203 | 103 | diff = g_date_time_difference (now, then); | ||
2204 | 104 | days = diff / G_TIME_SPAN_DAY; | ||
2205 | 105 | if (days == 0) | ||
2206 | 106 | last_used = g_strdup (_("Today")); | ||
2207 | 107 | else if (days == 1) | ||
2208 | 108 | last_used = g_strdup (_("Yesterday")); | ||
2209 | 109 | else | ||
2210 | 110 | last_used = g_strdup_printf (ngettext ("%i day ago", "%i days ago", days), days); | ||
2211 | 111 | out: | ||
2212 | 112 | panel_set_device_widget_details (CE_PAGE (page)->builder, "last_used", last_used); | ||
2213 | 113 | if (now != NULL) | ||
2214 | 114 | g_date_time_unref (now); | ||
2215 | 115 | if (then != NULL) | ||
2216 | 116 | g_date_time_unref (then); | ||
2217 | 117 | g_free (last_used); | ||
2218 | 118 | } | ||
2219 | 119 | |||
2220 | 120 | static void | ||
2221 | 121 | all_user_changed (GtkToggleButton *b, CEPageDetails *page) | ||
2222 | 122 | { | ||
2223 | 123 | gboolean all_users; | ||
2224 | 124 | NMSettingConnection *sc; | ||
2225 | 125 | |||
2226 | 126 | sc = nm_connection_get_setting_connection (CE_PAGE (page)->connection); | ||
2227 | 127 | all_users = gtk_toggle_button_get_active (b); | ||
2228 | 128 | |||
2229 | 129 | g_object_set (sc, "permissions", NULL, NULL); | ||
2230 | 130 | if (!all_users) | ||
2231 | 131 | nm_setting_connection_add_permission (sc, "user", g_get_user_name (), NULL); | ||
2232 | 132 | } | ||
2233 | 133 | |||
2234 | 134 | static void | ||
2235 | 135 | connect_details_page (CEPageDetails *page) | ||
2236 | 136 | { | ||
2237 | 137 | NMSettingConnection *sc; | ||
2238 | 138 | GtkWidget *widget; | ||
2239 | 139 | guint speed; | ||
2240 | 140 | guint strength; | ||
2241 | 141 | NMDeviceState state; | ||
2242 | 142 | NMAccessPoint *active_ap; | ||
2243 | 143 | const gchar *str; | ||
2244 | 144 | const gchar *type; | ||
2245 | 145 | gboolean device_is_active; | ||
2246 | 146 | |||
2247 | 147 | if (NM_IS_DEVICE_WIFI (page->device)) | ||
2248 | 148 | active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (page->device)); | ||
2249 | 149 | else | ||
2250 | 150 | active_ap = NULL; | ||
2251 | 151 | |||
2252 | 152 | state = page->device ? nm_device_get_state (page->device) : NM_DEVICE_STATE_DISCONNECTED; | ||
2253 | 153 | |||
2254 | 154 | device_is_active = FALSE; | ||
2255 | 155 | speed = 0; | ||
2256 | 156 | if (active_ap && page->ap == active_ap && state != NM_DEVICE_STATE_UNAVAILABLE) { | ||
2257 | 157 | device_is_active = TRUE; | ||
2258 | 158 | if (NM_IS_DEVICE_WIFI (page->device)) | ||
2259 | 159 | speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (page->device)) / 1000; | ||
2260 | 160 | } else if (page->device) { | ||
2261 | 161 | NMActiveConnection *ac; | ||
2262 | 162 | const gchar *p1, *p2; | ||
2263 | 163 | |||
2264 | 164 | ac = nm_device_get_active_connection (page->device); | ||
2265 | 165 | p1 = ac ? nm_active_connection_get_uuid (ac) : NULL; | ||
2266 | 166 | p2 = nm_connection_get_uuid (CE_PAGE (page)->connection); | ||
2267 | 167 | if (g_strcmp0 (p1, p2) == 0) { | ||
2268 | 168 | device_is_active = TRUE; | ||
2269 | 169 | if (NM_IS_DEVICE_WIFI (page->device)) | ||
2270 | 170 | speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (page->device)) / 1000; | ||
2271 | 171 | else if (NM_IS_DEVICE_ETHERNET (page->device)) | ||
2272 | 172 | speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (page->device)); | ||
2273 | 173 | } | ||
2274 | 174 | } | ||
2275 | 175 | if (speed > 0) | ||
2276 | 176 | str = g_strdup_printf (_("%d Mb/s"), speed); | ||
2277 | 177 | else | ||
2278 | 178 | str = NULL; | ||
2279 | 179 | panel_set_device_widget_details (CE_PAGE (page)->builder, "speed", str); | ||
2280 | 180 | g_clear_pointer (&str, g_free); | ||
2281 | 181 | |||
2282 | 182 | if (NM_IS_DEVICE_WIFI (page->device)) | ||
2283 | 183 | str = nm_device_wifi_get_hw_address (NM_DEVICE_WIFI (page->device)); | ||
2284 | 184 | else if (NM_IS_DEVICE_ETHERNET (page->device)) | ||
2285 | 185 | str = nm_device_ethernet_get_hw_address (NM_DEVICE_ETHERNET (page->device)); | ||
2286 | 186 | |||
2287 | 187 | panel_set_device_widget_details (CE_PAGE (page)->builder, "mac", str); | ||
2288 | 188 | |||
2289 | 189 | str = NULL; | ||
2290 | 190 | if (device_is_active && active_ap) | ||
2291 | 191 | str = get_ap_security_string (active_ap); | ||
2292 | 192 | panel_set_device_widget_details (CE_PAGE (page)->builder, "security", str); | ||
2293 | 193 | g_clear_pointer (&str, g_free); | ||
2294 | 194 | |||
2295 | 195 | strength = 0; | ||
2296 | 196 | if (page->ap != NULL) | ||
2297 | 197 | strength = nm_access_point_get_strength (page->ap); | ||
2298 | 198 | |||
2299 | 199 | if (strength <= 0) | ||
2300 | 200 | str = NULL; | ||
2301 | 201 | else if (strength < 20) | ||
2302 | 202 | str = C_("Signal strength", "None"); | ||
2303 | 203 | else if (strength < 40) | ||
2304 | 204 | str = C_("Signal strength", "Weak"); | ||
2305 | 205 | else if (strength < 50) | ||
2306 | 206 | str = C_("Signal strength", "Ok"); | ||
2307 | 207 | else if (strength < 80) | ||
2308 | 208 | str = C_("Signal strength", "Good"); | ||
2309 | 209 | else | ||
2310 | 210 | str = C_("Signal strength", "Excellent"); | ||
2311 | 211 | panel_set_device_widget_details (CE_PAGE (page)->builder, "strength", str); | ||
2312 | 212 | |||
2313 | 213 | /* set IP entries */ | ||
2314 | 214 | if (device_is_active) | ||
2315 | 215 | panel_set_device_widgets (CE_PAGE (page)->builder, page->device); | ||
2316 | 216 | else | ||
2317 | 217 | panel_unset_device_widgets (CE_PAGE (page)->builder); | ||
2318 | 218 | |||
2319 | 219 | if (!device_is_active && CE_PAGE (page)->connection) | ||
2320 | 220 | update_last_used (page, CE_PAGE (page)->connection); | ||
2321 | 221 | else | ||
2322 | 222 | panel_set_device_widget_details (CE_PAGE (page)->builder, "last_used", NULL); | ||
2323 | 223 | |||
2324 | 224 | /* Auto connect check */ | ||
2325 | 225 | widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, | ||
2326 | 226 | "auto_connect_check")); | ||
2327 | 227 | sc = nm_connection_get_setting_connection (CE_PAGE (page)->connection); | ||
2328 | 228 | g_object_bind_property (sc, "autoconnect", | ||
2329 | 229 | widget, "active", | ||
2330 | 230 | G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); | ||
2331 | 231 | g_signal_connect_swapped (widget, "toggled", G_CALLBACK (ce_page_changed), page); | ||
2332 | 232 | |||
2333 | 233 | /* All users check */ | ||
2334 | 234 | widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, | ||
2335 | 235 | "all_user_check")); | ||
2336 | 236 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), | ||
2337 | 237 | nm_setting_connection_get_num_permissions (sc) == 0); | ||
2338 | 238 | g_signal_connect (widget, "toggled", | ||
2339 | 239 | G_CALLBACK (all_user_changed), page); | ||
2340 | 240 | g_signal_connect_swapped (widget, "toggled", G_CALLBACK (ce_page_changed), page); | ||
2341 | 241 | |||
2342 | 242 | /* Forget button */ | ||
2343 | 243 | widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "button_forget")); | ||
2344 | 244 | g_signal_connect (widget, "clicked", G_CALLBACK (forget_cb), page); | ||
2345 | 245 | |||
2346 | 246 | type = nm_setting_connection_get_connection_type (sc); | ||
2347 | 247 | if (g_str_equal (type, NM_SETTING_WIRELESS_SETTING_NAME)) | ||
2348 | 248 | gtk_button_set_label (GTK_BUTTON (widget), _("Forget Connection")); | ||
2349 | 249 | else if (g_str_equal (type, NM_SETTING_WIRED_SETTING_NAME)) | ||
2350 | 250 | gtk_button_set_label (GTK_BUTTON (widget), _("Remove Connection Profile")); | ||
2351 | 251 | else if (g_str_equal (type, NM_SETTING_VPN_SETTING_NAME)) | ||
2352 | 252 | gtk_button_set_label (GTK_BUTTON (widget), _("Remove VPN")); | ||
2353 | 253 | else | ||
2354 | 254 | gtk_widget_hide (widget); | ||
2355 | 255 | } | ||
2356 | 256 | |||
2357 | 257 | static void | ||
2358 | 258 | ce_page_details_init (CEPageDetails *page) | ||
2359 | 259 | { | ||
2360 | 260 | } | ||
2361 | 261 | |||
2362 | 262 | static void | ||
2363 | 263 | ce_page_details_class_init (CEPageDetailsClass *class) | ||
2364 | 264 | { | ||
2365 | 265 | } | ||
2366 | 266 | |||
2367 | 267 | CEPage * | ||
2368 | 268 | ce_page_details_new (NMConnection *connection, | ||
2369 | 269 | NMClient *client, | ||
2370 | 270 | NMDevice *device, | ||
2371 | 271 | NMAccessPoint *ap, | ||
2372 | 272 | NetConnectionEditor *editor) | ||
2373 | 273 | { | ||
2374 | 274 | CEPageDetails *page; | ||
2375 | 275 | |||
2376 | 276 | page = CE_PAGE_DETAILS (ce_page_new (CE_TYPE_PAGE_DETAILS, | ||
2377 | 277 | connection, | ||
2378 | 278 | client, | ||
2379 | 279 | "/org/gnome/control-center/network/details-page.ui", | ||
2380 | 280 | _("Details"))); | ||
2381 | 281 | |||
2382 | 282 | page->editor = editor; | ||
2383 | 283 | page->device = device; | ||
2384 | 284 | page->ap = ap; | ||
2385 | 285 | |||
2386 | 286 | connect_details_page (page); | ||
2387 | 287 | |||
2388 | 288 | return CE_PAGE (page); | ||
2389 | 289 | } | ||
2390 | 0 | 290 | ||
2391 | === added file 'panels/network/connection-editor/ce-page-details.h' | |||
2392 | --- panels/network/connection-editor/ce-page-details.h 1970-01-01 00:00:00 +0000 | |||
2393 | +++ panels/network/connection-editor/ce-page-details.h 2019-05-01 13:56:52 +0000 | |||
2394 | @@ -0,0 +1,68 @@ | |||
2395 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
2396 | 2 | * | ||
2397 | 3 | * Copyright (C) 2012 Red Hat, Inc. | ||
2398 | 4 | * | ||
2399 | 5 | * Licensed under the GNU General Public License Version 2 | ||
2400 | 6 | * | ||
2401 | 7 | * This program is free software; you can redistribute it and/or modify | ||
2402 | 8 | * it under the terms of the GNU General Public License as published by | ||
2403 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
2404 | 10 | * (at your option) any later version. | ||
2405 | 11 | * | ||
2406 | 12 | * This program is distributed in the hope that it will be useful, | ||
2407 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2408 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2409 | 15 | * GNU General Public License for more details. | ||
2410 | 16 | * | ||
2411 | 17 | * You should have received a copy of the GNU General Public License | ||
2412 | 18 | * along with this program; if not, write to the Free Software | ||
2413 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
2414 | 20 | */ | ||
2415 | 21 | |||
2416 | 22 | #ifndef __CE_PAGE_DETAILS_H | ||
2417 | 23 | #define __CE_PAGE_DETAILS_H | ||
2418 | 24 | |||
2419 | 25 | #include <glib-object.h> | ||
2420 | 26 | |||
2421 | 27 | #include <gtk/gtk.h> | ||
2422 | 28 | #include "net-connection-editor.h" | ||
2423 | 29 | #include "ce-page.h" | ||
2424 | 30 | |||
2425 | 31 | G_BEGIN_DECLS | ||
2426 | 32 | |||
2427 | 33 | #define CE_TYPE_PAGE_DETAILS (ce_page_details_get_type ()) | ||
2428 | 34 | #define CE_PAGE_DETAILS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CE_TYPE_PAGE_DETAILS, CEPageDetails)) | ||
2429 | 35 | #define CE_PAGE_DETAILS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CE_TYPE_PAGE_DETAILS, CEPageDetailsClass)) | ||
2430 | 36 | #define CE_IS_PAGE_DETAILS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CE_TYPE_PAGE_DETAILS)) | ||
2431 | 37 | #define CE_IS_PAGE_DETAILS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CE_TYPE_PAGE_DETAILS)) | ||
2432 | 38 | #define CE_PAGE_DETAILS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CE_TYPE_PAGE_DETAILS, CEPageDetailsClass)) | ||
2433 | 39 | |||
2434 | 40 | typedef struct _CEPageDetails CEPageDetails; | ||
2435 | 41 | typedef struct _CEPageDetailsClass CEPageDetailsClass; | ||
2436 | 42 | |||
2437 | 43 | struct _CEPageDetails | ||
2438 | 44 | { | ||
2439 | 45 | CEPage parent; | ||
2440 | 46 | |||
2441 | 47 | NMDevice *device; | ||
2442 | 48 | NMAccessPoint *ap; | ||
2443 | 49 | NetConnectionEditor *editor; | ||
2444 | 50 | }; | ||
2445 | 51 | |||
2446 | 52 | struct _CEPageDetailsClass | ||
2447 | 53 | { | ||
2448 | 54 | CEPageClass parent_class; | ||
2449 | 55 | }; | ||
2450 | 56 | |||
2451 | 57 | GType ce_page_details_get_type (void); | ||
2452 | 58 | |||
2453 | 59 | CEPage *ce_page_details_new (NMConnection *connection, | ||
2454 | 60 | NMClient *client, | ||
2455 | 61 | NMDevice *device, | ||
2456 | 62 | NMAccessPoint *ap, | ||
2457 | 63 | NetConnectionEditor *editor); | ||
2458 | 64 | |||
2459 | 65 | G_END_DECLS | ||
2460 | 66 | |||
2461 | 67 | #endif /* __CE_PAGE_DETAILS_H */ | ||
2462 | 68 | |||
2463 | 0 | 69 | ||
2464 | === added file 'panels/network/connection-editor/ce-page-ethernet.c' | |||
2465 | --- panels/network/connection-editor/ce-page-ethernet.c 1970-01-01 00:00:00 +0000 | |||
2466 | +++ panels/network/connection-editor/ce-page-ethernet.c 2019-05-01 13:56:52 +0000 | |||
2467 | @@ -0,0 +1,187 @@ | |||
2468 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
2469 | 2 | * | ||
2470 | 3 | * Copyright (C) 2012 Red Hat, Inc | ||
2471 | 4 | * | ||
2472 | 5 | * Licensed under the GNU General Public License Version 2 | ||
2473 | 6 | * | ||
2474 | 7 | * This program is free software; you can redistribute it and/or modify | ||
2475 | 8 | * it under the terms of the GNU General Public License as published by | ||
2476 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
2477 | 10 | * (at your option) any later version. | ||
2478 | 11 | * | ||
2479 | 12 | * This program is distributed in the hope that it will be useful, | ||
2480 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2481 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2482 | 15 | * GNU General Public License for more details. | ||
2483 | 16 | * | ||
2484 | 17 | * You should have received a copy of the GNU General Public License | ||
2485 | 18 | * along with this program; if not, write to the Free Software | ||
2486 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
2487 | 20 | */ | ||
2488 | 21 | |||
2489 | 22 | #include "config.h" | ||
2490 | 23 | |||
2491 | 24 | #include <glib-object.h> | ||
2492 | 25 | #include <glib/gi18n.h> | ||
2493 | 26 | #include <net/if_arp.h> | ||
2494 | 27 | |||
2495 | 28 | #include <NetworkManager.h> | ||
2496 | 29 | |||
2497 | 30 | |||
2498 | 31 | #include "ce-page-ethernet.h" | ||
2499 | 32 | #include "ui-helpers.h" | ||
2500 | 33 | |||
2501 | 34 | G_DEFINE_TYPE (CEPageEthernet, ce_page_ethernet, CE_TYPE_PAGE) | ||
2502 | 35 | |||
2503 | 36 | static void | ||
2504 | 37 | mtu_changed (GtkSpinButton *mtu, CEPageEthernet *page) | ||
2505 | 38 | { | ||
2506 | 39 | if (gtk_spin_button_get_value_as_int (mtu) == 0) | ||
2507 | 40 | gtk_widget_hide (page->mtu_label); | ||
2508 | 41 | else | ||
2509 | 42 | gtk_widget_show (page->mtu_label); | ||
2510 | 43 | } | ||
2511 | 44 | |||
2512 | 45 | static void | ||
2513 | 46 | connect_ethernet_page (CEPageEthernet *page) | ||
2514 | 47 | { | ||
2515 | 48 | NMSettingWired *setting = page->setting_wired; | ||
2516 | 49 | int mtu_def; | ||
2517 | 50 | char **mac_list; | ||
2518 | 51 | const char *s_mac_str; | ||
2519 | 52 | const gchar *name; | ||
2520 | 53 | const gchar *cloned_mac; | ||
2521 | 54 | |||
2522 | 55 | name = nm_setting_connection_get_id (page->setting_connection); | ||
2523 | 56 | gtk_entry_set_text (page->name, name); | ||
2524 | 57 | |||
2525 | 58 | /* Device MAC address */ | ||
2526 | 59 | mac_list = ce_page_get_mac_list (CE_PAGE (page)->client, NM_TYPE_DEVICE_ETHERNET, | ||
2527 | 60 | NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS); | ||
2528 | 61 | s_mac_str = nm_setting_wired_get_mac_address (setting); | ||
2529 | 62 | ce_page_setup_mac_combo (page->device_mac, s_mac_str, mac_list); | ||
2530 | 63 | g_strfreev (mac_list); | ||
2531 | 64 | g_signal_connect_swapped (page->device_mac, "changed", G_CALLBACK (ce_page_changed), page); | ||
2532 | 65 | |||
2533 | 66 | /* Cloned MAC address */ | ||
2534 | 67 | cloned_mac = nm_setting_wired_get_cloned_mac_address (setting); | ||
2535 | 68 | gtk_entry_set_text (GTK_ENTRY (page->cloned_mac), cloned_mac ? cloned_mac : ""); | ||
2536 | 69 | g_signal_connect_swapped (page->cloned_mac, "changed", G_CALLBACK (ce_page_changed), page); | ||
2537 | 70 | |||
2538 | 71 | /* MTU */ | ||
2539 | 72 | mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRED_MTU); | ||
2540 | 73 | g_signal_connect (page->mtu, "output", | ||
2541 | 74 | G_CALLBACK (ce_spin_output_with_default), | ||
2542 | 75 | GINT_TO_POINTER (mtu_def)); | ||
2543 | 76 | gtk_spin_button_set_value (page->mtu, (gdouble) nm_setting_wired_get_mtu (setting)); | ||
2544 | 77 | g_signal_connect (page->mtu, "value-changed", | ||
2545 | 78 | G_CALLBACK (mtu_changed), page); | ||
2546 | 79 | mtu_changed (page->mtu, page); | ||
2547 | 80 | |||
2548 | 81 | g_signal_connect_swapped (page->name, "changed", G_CALLBACK (ce_page_changed), page); | ||
2549 | 82 | g_signal_connect_swapped (page->mtu, "value-changed", G_CALLBACK (ce_page_changed), page); | ||
2550 | 83 | } | ||
2551 | 84 | |||
2552 | 85 | static void | ||
2553 | 86 | ui_to_setting (CEPageEthernet *page) | ||
2554 | 87 | { | ||
2555 | 88 | gchar *device_mac = NULL; | ||
2556 | 89 | gchar *cloned_mac; | ||
2557 | 90 | const gchar *text; | ||
2558 | 91 | GtkWidget *entry; | ||
2559 | 92 | |||
2560 | 93 | entry = gtk_bin_get_child (GTK_BIN (page->device_mac)); | ||
2561 | 94 | if (entry) { | ||
2562 | 95 | text = gtk_entry_get_text (GTK_ENTRY (entry)); | ||
2563 | 96 | device_mac = ce_page_trim_address (text); | ||
2564 | 97 | } | ||
2565 | 98 | text = gtk_entry_get_text (GTK_ENTRY (entry)); | ||
2566 | 99 | cloned_mac = ce_page_trim_address (text); | ||
2567 | 100 | |||
2568 | 101 | g_object_set (page->setting_wired, | ||
2569 | 102 | NM_SETTING_WIRED_MAC_ADDRESS, device_mac, | ||
2570 | 103 | NM_SETTING_WIRED_CLONED_MAC_ADDRESS, cloned_mac, | ||
2571 | 104 | NM_SETTING_WIRED_MTU, (guint32) gtk_spin_button_get_value_as_int (page->mtu), | ||
2572 | 105 | NULL); | ||
2573 | 106 | |||
2574 | 107 | g_object_set (page->setting_connection, | ||
2575 | 108 | NM_SETTING_CONNECTION_ID, gtk_entry_get_text (page->name), | ||
2576 | 109 | NULL); | ||
2577 | 110 | |||
2578 | 111 | g_free (cloned_mac); | ||
2579 | 112 | g_free (device_mac); | ||
2580 | 113 | } | ||
2581 | 114 | |||
2582 | 115 | static gboolean | ||
2583 | 116 | validate (CEPage *page, | ||
2584 | 117 | NMConnection *connection, | ||
2585 | 118 | GError **error) | ||
2586 | 119 | { | ||
2587 | 120 | CEPageEthernet *self = CE_PAGE_ETHERNET (page); | ||
2588 | 121 | GtkWidget *entry; | ||
2589 | 122 | gboolean ret = TRUE; | ||
2590 | 123 | |||
2591 | 124 | entry = gtk_bin_get_child (GTK_BIN (self->device_mac)); | ||
2592 | 125 | if (entry) { | ||
2593 | 126 | if (!ce_page_address_is_valid (gtk_entry_get_text (GTK_ENTRY (entry)))) { | ||
2594 | 127 | widget_set_error (entry); | ||
2595 | 128 | ret = FALSE; | ||
2596 | 129 | } else { | ||
2597 | 130 | widget_unset_error (entry); | ||
2598 | 131 | } | ||
2599 | 132 | } | ||
2600 | 133 | |||
2601 | 134 | if (!ce_page_address_is_valid (gtk_entry_get_text (GTK_ENTRY (self->cloned_mac)))) { | ||
2602 | 135 | widget_set_error (GTK_WIDGET (self->cloned_mac)); | ||
2603 | 136 | ret = FALSE; | ||
2604 | 137 | } else { | ||
2605 | 138 | widget_unset_error (GTK_WIDGET (self->cloned_mac)); | ||
2606 | 139 | } | ||
2607 | 140 | |||
2608 | 141 | if (!ret) | ||
2609 | 142 | return ret; | ||
2610 | 143 | |||
2611 | 144 | ui_to_setting (self); | ||
2612 | 145 | |||
2613 | 146 | return nm_setting_verify (NM_SETTING (self->setting_connection), NULL, error) && | ||
2614 | 147 | nm_setting_verify (NM_SETTING (self->setting_wired), NULL, error); | ||
2615 | 148 | } | ||
2616 | 149 | |||
2617 | 150 | static void | ||
2618 | 151 | ce_page_ethernet_init (CEPageEthernet *page) | ||
2619 | 152 | { | ||
2620 | 153 | } | ||
2621 | 154 | |||
2622 | 155 | static void | ||
2623 | 156 | ce_page_ethernet_class_init (CEPageEthernetClass *class) | ||
2624 | 157 | { | ||
2625 | 158 | CEPageClass *page_class= CE_PAGE_CLASS (class); | ||
2626 | 159 | |||
2627 | 160 | page_class->validate = validate; | ||
2628 | 161 | } | ||
2629 | 162 | |||
2630 | 163 | CEPage * | ||
2631 | 164 | ce_page_ethernet_new (NMConnection *connection, | ||
2632 | 165 | NMClient *client) | ||
2633 | 166 | { | ||
2634 | 167 | CEPageEthernet *page; | ||
2635 | 168 | |||
2636 | 169 | page = CE_PAGE_ETHERNET (ce_page_new (CE_TYPE_PAGE_ETHERNET, | ||
2637 | 170 | connection, | ||
2638 | 171 | client, | ||
2639 | 172 | "/org/gnome/control-center/network/ethernet-page.ui", | ||
2640 | 173 | _("Identity"))); | ||
2641 | 174 | |||
2642 | 175 | page->name = GTK_ENTRY (gtk_builder_get_object (CE_PAGE (page)->builder, "entry_name")); | ||
2643 | 176 | page->device_mac = GTK_COMBO_BOX_TEXT (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_mac")); | ||
2644 | 177 | page->cloned_mac = GTK_ENTRY (gtk_builder_get_object (CE_PAGE (page)->builder, "entry_cloned_mac")); | ||
2645 | 178 | page->mtu = GTK_SPIN_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "spin_mtu")); | ||
2646 | 179 | page->mtu_label = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "label_mtu")); | ||
2647 | 180 | |||
2648 | 181 | page->setting_connection = nm_connection_get_setting_connection (connection); | ||
2649 | 182 | page->setting_wired = nm_connection_get_setting_wired (connection); | ||
2650 | 183 | |||
2651 | 184 | connect_ethernet_page (page); | ||
2652 | 185 | |||
2653 | 186 | return CE_PAGE (page); | ||
2654 | 187 | } | ||
2655 | 0 | 188 | ||
2656 | === added file 'panels/network/connection-editor/ce-page-ethernet.h' | |||
2657 | --- panels/network/connection-editor/ce-page-ethernet.h 1970-01-01 00:00:00 +0000 | |||
2658 | +++ panels/network/connection-editor/ce-page-ethernet.h 2019-05-01 13:56:52 +0000 | |||
2659 | @@ -0,0 +1,71 @@ | |||
2660 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
2661 | 2 | * | ||
2662 | 3 | * Copyright (C) 2012 Red Hat, Inc. | ||
2663 | 4 | * | ||
2664 | 5 | * Licensed under the GNU General Public License Version 2 | ||
2665 | 6 | * | ||
2666 | 7 | * This program is free software; you can redistribute it and/or modify | ||
2667 | 8 | * it under the terms of the GNU General Public License as published by | ||
2668 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
2669 | 10 | * (at your option) any later version. | ||
2670 | 11 | * | ||
2671 | 12 | * This program is distributed in the hope that it will be useful, | ||
2672 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2673 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2674 | 15 | * GNU General Public License for more ethernet. | ||
2675 | 16 | * | ||
2676 | 17 | * You should have received a copy of the GNU General Public License | ||
2677 | 18 | * along with this program; if not, write to the Free Software | ||
2678 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
2679 | 20 | */ | ||
2680 | 21 | |||
2681 | 22 | #ifndef __CE_PAGE_ETHERNET_H | ||
2682 | 23 | #define __CE_PAGE_ETHERNET_H | ||
2683 | 24 | |||
2684 | 25 | #include <glib-object.h> | ||
2685 | 26 | |||
2686 | 27 | #include <NetworkManager.h> | ||
2687 | 28 | |||
2688 | 29 | #include <gtk/gtk.h> | ||
2689 | 30 | #include "ce-page.h" | ||
2690 | 31 | |||
2691 | 32 | G_BEGIN_DECLS | ||
2692 | 33 | |||
2693 | 34 | #define CE_TYPE_PAGE_ETHERNET (ce_page_ethernet_get_type ()) | ||
2694 | 35 | #define CE_PAGE_ETHERNET(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CE_TYPE_PAGE_ETHERNET, CEPageEthernet)) | ||
2695 | 36 | #define CE_PAGE_ETHERNET_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CE_TYPE_PAGE_ETHERNET, CEPageEthernetClass)) | ||
2696 | 37 | #define CE_IS_PAGE_ETHERNET(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CE_TYPE_PAGE_ETHERNET)) | ||
2697 | 38 | #define CE_IS_PAGE_ETHERNET_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CE_TYPE_PAGE_ETHERNET)) | ||
2698 | 39 | #define CE_PAGE_ETHERNET_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CE_TYPE_PAGE_ETHERNET, CEPageEthernetClass)) | ||
2699 | 40 | |||
2700 | 41 | typedef struct _CEPageEthernet CEPageEthernet; | ||
2701 | 42 | typedef struct _CEPageEthernetClass CEPageEthernetClass; | ||
2702 | 43 | |||
2703 | 44 | struct _CEPageEthernet | ||
2704 | 45 | { | ||
2705 | 46 | CEPage parent; | ||
2706 | 47 | |||
2707 | 48 | NMSettingConnection *setting_connection; | ||
2708 | 49 | NMSettingWired *setting_wired; | ||
2709 | 50 | |||
2710 | 51 | GtkEntry *name; | ||
2711 | 52 | GtkComboBoxText *device_mac; | ||
2712 | 53 | GtkEntry *cloned_mac; | ||
2713 | 54 | GtkSpinButton *mtu; | ||
2714 | 55 | GtkWidget *mtu_label; | ||
2715 | 56 | }; | ||
2716 | 57 | |||
2717 | 58 | struct _CEPageEthernetClass | ||
2718 | 59 | { | ||
2719 | 60 | CEPageClass parent_class; | ||
2720 | 61 | }; | ||
2721 | 62 | |||
2722 | 63 | GType ce_page_ethernet_get_type (void); | ||
2723 | 64 | |||
2724 | 65 | CEPage *ce_page_ethernet_new (NMConnection *connection, | ||
2725 | 66 | NMClient *client); | ||
2726 | 67 | |||
2727 | 68 | G_END_DECLS | ||
2728 | 69 | |||
2729 | 70 | #endif /* __CE_PAGE_ETHERNET_H */ | ||
2730 | 71 | |||
2731 | 0 | 72 | ||
2732 | === added file 'panels/network/connection-editor/ce-page-ip4.c' | |||
2733 | --- panels/network/connection-editor/ce-page-ip4.c 1970-01-01 00:00:00 +0000 | |||
2734 | +++ panels/network/connection-editor/ce-page-ip4.c 2019-05-01 13:56:52 +0000 | |||
2735 | @@ -0,0 +1,907 @@ | |||
2736 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
2737 | 2 | * | ||
2738 | 3 | * Copyright (C) 2012 Red Hat, Inc | ||
2739 | 4 | * | ||
2740 | 5 | * Licensed under the GNU General Public License Version 2 | ||
2741 | 6 | * | ||
2742 | 7 | * This program is free software; you can redistribute it and/or modify | ||
2743 | 8 | * it under the terms of the GNU General Public License as published by | ||
2744 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
2745 | 10 | * (at your option) any later version. | ||
2746 | 11 | * | ||
2747 | 12 | * This program is distributed in the hope that it will be useful, | ||
2748 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2749 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2750 | 15 | * GNU General Public License for more details. | ||
2751 | 16 | * | ||
2752 | 17 | * You should have received a copy of the GNU General Public License | ||
2753 | 18 | * along with this program; if not, write to the Free Software | ||
2754 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
2755 | 20 | */ | ||
2756 | 21 | |||
2757 | 22 | #include "config.h" | ||
2758 | 23 | |||
2759 | 24 | #include <errno.h> | ||
2760 | 25 | #include <stdlib.h> | ||
2761 | 26 | #include <arpa/inet.h> | ||
2762 | 27 | #include <glib-object.h> | ||
2763 | 28 | #include <glib/gi18n.h> | ||
2764 | 29 | #include <NetworkManager.h> | ||
2765 | 30 | |||
2766 | 31 | #include "shell/list-box-helper.h" | ||
2767 | 32 | #include "ce-page-ip4.h" | ||
2768 | 33 | #include "ui-helpers.h" | ||
2769 | 34 | |||
2770 | 35 | #define RADIO_IS_ACTIVE(x) (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object(CE_PAGE (page)->builder, x)))) | ||
2771 | 36 | |||
2772 | 37 | static void ensure_empty_address_row (CEPageIP4 *page); | ||
2773 | 38 | static void ensure_empty_routes_row (CEPageIP4 *page); | ||
2774 | 39 | |||
2775 | 40 | G_DEFINE_TYPE (CEPageIP4, ce_page_ip4, CE_TYPE_PAGE) | ||
2776 | 41 | |||
2777 | 42 | enum { | ||
2778 | 43 | METHOD_COL_NAME, | ||
2779 | 44 | METHOD_COL_METHOD | ||
2780 | 45 | }; | ||
2781 | 46 | |||
2782 | 47 | enum { | ||
2783 | 48 | IP4_METHOD_AUTO, | ||
2784 | 49 | IP4_METHOD_MANUAL, | ||
2785 | 50 | IP4_METHOD_LINK_LOCAL, | ||
2786 | 51 | IP4_METHOD_SHARED, | ||
2787 | 52 | IP4_METHOD_DISABLED | ||
2788 | 53 | }; | ||
2789 | 54 | |||
2790 | 55 | static void | ||
2791 | 56 | method_changed (GtkToggleButton *radio, CEPageIP4 *page) | ||
2792 | 57 | { | ||
2793 | 58 | gboolean addr_enabled; | ||
2794 | 59 | gboolean dns_enabled; | ||
2795 | 60 | gboolean routes_enabled; | ||
2796 | 61 | GtkWidget *widget; | ||
2797 | 62 | |||
2798 | 63 | if (RADIO_IS_ACTIVE ("radio_disabled")) { | ||
2799 | 64 | addr_enabled = FALSE; | ||
2800 | 65 | dns_enabled = FALSE; | ||
2801 | 66 | routes_enabled = FALSE; | ||
2802 | 67 | } else { | ||
2803 | 68 | addr_enabled = RADIO_IS_ACTIVE ("radio_manual"); | ||
2804 | 69 | dns_enabled = !RADIO_IS_ACTIVE ("radio_local"); | ||
2805 | 70 | routes_enabled = !RADIO_IS_ACTIVE ("radio_local"); | ||
2806 | 71 | } | ||
2807 | 72 | |||
2808 | 73 | widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section")); | ||
2809 | 74 | gtk_widget_set_visible (widget, addr_enabled); | ||
2810 | 75 | gtk_widget_set_sensitive (page->dns_entry, dns_enabled); | ||
2811 | 76 | gtk_widget_set_sensitive (page->routes_list, routes_enabled); | ||
2812 | 77 | gtk_widget_set_sensitive (page->never_default, routes_enabled); | ||
2813 | 78 | |||
2814 | 79 | ce_page_changed (CE_PAGE (page)); | ||
2815 | 80 | } | ||
2816 | 81 | |||
2817 | 82 | static void | ||
2818 | 83 | switch_toggled (GObject *object, | ||
2819 | 84 | GParamSpec *pspec, | ||
2820 | 85 | CEPage *page) | ||
2821 | 86 | { | ||
2822 | 87 | ce_page_changed (page); | ||
2823 | 88 | } | ||
2824 | 89 | |||
2825 | 90 | static void | ||
2826 | 91 | update_row_sensitivity (CEPageIP4 *page, GtkWidget *list) | ||
2827 | 92 | { | ||
2828 | 93 | GList *children, *l; | ||
2829 | 94 | gint rows = 0, i = 0; | ||
2830 | 95 | |||
2831 | 96 | children = gtk_container_get_children (GTK_CONTAINER (list)); | ||
2832 | 97 | for (l = children; l; l = l->next) { | ||
2833 | 98 | GtkWidget *row = l->data; | ||
2834 | 99 | GtkWidget *button; | ||
2835 | 100 | |||
2836 | 101 | button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "delete-button")); | ||
2837 | 102 | if (button != NULL) | ||
2838 | 103 | rows++; | ||
2839 | 104 | } | ||
2840 | 105 | for (l = children; l; l = l->next) { | ||
2841 | 106 | GtkWidget *row = l->data; | ||
2842 | 107 | GtkWidget *button; | ||
2843 | 108 | |||
2844 | 109 | button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "delete-button")); | ||
2845 | 110 | if (button != NULL) | ||
2846 | 111 | gtk_widget_set_sensitive (button, rows > 1 && ++i < rows); | ||
2847 | 112 | } | ||
2848 | 113 | g_list_free (children); | ||
2849 | 114 | } | ||
2850 | 115 | |||
2851 | 116 | static void | ||
2852 | 117 | update_row_gateway_sensitivity (CEPageIP4 *page) | ||
2853 | 118 | { | ||
2854 | 119 | GList *children, *l; | ||
2855 | 120 | gint rows = 0; | ||
2856 | 121 | |||
2857 | 122 | children = gtk_container_get_children (GTK_CONTAINER (page->address_list)); | ||
2858 | 123 | for (l = children; l; l = l->next) { | ||
2859 | 124 | GtkWidget *row = l->data; | ||
2860 | 125 | GtkWidget *entry; | ||
2861 | 126 | |||
2862 | 127 | entry = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "gateway")); | ||
2863 | 128 | |||
2864 | 129 | gtk_widget_set_sensitive (entry, (rows == 0)); | ||
2865 | 130 | |||
2866 | 131 | rows++; | ||
2867 | 132 | } | ||
2868 | 133 | g_list_free (children); | ||
2869 | 134 | } | ||
2870 | 135 | |||
2871 | 136 | static void | ||
2872 | 137 | remove_row (GtkButton *button, CEPageIP4 *page) | ||
2873 | 138 | { | ||
2874 | 139 | GtkWidget *list; | ||
2875 | 140 | GtkWidget *row; | ||
2876 | 141 | GtkWidget *row_box; | ||
2877 | 142 | |||
2878 | 143 | row_box = gtk_widget_get_parent (GTK_WIDGET (button)); | ||
2879 | 144 | row = gtk_widget_get_parent (row_box); | ||
2880 | 145 | list = gtk_widget_get_parent (row); | ||
2881 | 146 | |||
2882 | 147 | gtk_container_remove (GTK_CONTAINER (list), row); | ||
2883 | 148 | |||
2884 | 149 | ce_page_changed (CE_PAGE (page)); | ||
2885 | 150 | |||
2886 | 151 | update_row_sensitivity (page, list); | ||
2887 | 152 | if (list == page->address_list) | ||
2888 | 153 | update_row_gateway_sensitivity (page); | ||
2889 | 154 | } | ||
2890 | 155 | |||
2891 | 156 | static gboolean | ||
2892 | 157 | validate_row (GtkWidget *row) | ||
2893 | 158 | { | ||
2894 | 159 | GtkWidget *box; | ||
2895 | 160 | GList *children, *l; | ||
2896 | 161 | gboolean valid; | ||
2897 | 162 | |||
2898 | 163 | valid = FALSE; | ||
2899 | 164 | box = gtk_bin_get_child (GTK_BIN (row)); | ||
2900 | 165 | children = gtk_container_get_children (GTK_CONTAINER (box)); | ||
2901 | 166 | |||
2902 | 167 | for (l = children; l != NULL; l = l->next) { | ||
2903 | 168 | if (!GTK_IS_ENTRY (l->data)) | ||
2904 | 169 | continue; | ||
2905 | 170 | |||
2906 | 171 | valid = valid || gtk_entry_get_text_length (l->data) > 0; | ||
2907 | 172 | } | ||
2908 | 173 | |||
2909 | 174 | g_list_free (children); | ||
2910 | 175 | |||
2911 | 176 | return valid; | ||
2912 | 177 | } | ||
2913 | 178 | |||
2914 | 179 | static gint | ||
2915 | 180 | sort_first_last (gconstpointer a, gconstpointer b, gpointer data) | ||
2916 | 181 | { | ||
2917 | 182 | gboolean afirst, bfirst, alast, blast; | ||
2918 | 183 | |||
2919 | 184 | afirst = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (a), "first")); | ||
2920 | 185 | bfirst = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (b), "first")); | ||
2921 | 186 | alast = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (a), "last")); | ||
2922 | 187 | blast = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (b), "last")); | ||
2923 | 188 | |||
2924 | 189 | if (afirst) | ||
2925 | 190 | return -1; | ||
2926 | 191 | if (bfirst) | ||
2927 | 192 | return 1; | ||
2928 | 193 | if (alast) | ||
2929 | 194 | return 1; | ||
2930 | 195 | if (blast) | ||
2931 | 196 | return -1; | ||
2932 | 197 | |||
2933 | 198 | return 0; | ||
2934 | 199 | } | ||
2935 | 200 | |||
2936 | 201 | static void | ||
2937 | 202 | add_address_row (CEPageIP4 *page, | ||
2938 | 203 | const gchar *address, | ||
2939 | 204 | const gchar *network, | ||
2940 | 205 | const gchar *gateway) | ||
2941 | 206 | { | ||
2942 | 207 | GtkSizeGroup *group; | ||
2943 | 208 | GtkWidget *row; | ||
2944 | 209 | GtkWidget *row_box; | ||
2945 | 210 | GtkWidget *widget; | ||
2946 | 211 | GtkWidget *delete_button; | ||
2947 | 212 | GtkWidget *image; | ||
2948 | 213 | |||
2949 | 214 | row = gtk_list_box_row_new (); | ||
2950 | 215 | |||
2951 | 216 | row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); | ||
2952 | 217 | gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked"); | ||
2953 | 218 | |||
2954 | 219 | widget = gtk_entry_new (); | ||
2955 | 220 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
2956 | 221 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page); | ||
2957 | 222 | g_object_set_data (G_OBJECT (row), "address", widget); | ||
2958 | 223 | gtk_entry_set_text (GTK_ENTRY (widget), address); | ||
2959 | 224 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 16); | ||
2960 | 225 | gtk_widget_set_hexpand (widget, TRUE); | ||
2961 | 226 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
2962 | 227 | |||
2963 | 228 | widget = gtk_entry_new (); | ||
2964 | 229 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
2965 | 230 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page); | ||
2966 | 231 | g_object_set_data (G_OBJECT (row), "network", widget); | ||
2967 | 232 | gtk_entry_set_text (GTK_ENTRY (widget), network); | ||
2968 | 233 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 16); | ||
2969 | 234 | gtk_widget_set_hexpand (widget, TRUE); | ||
2970 | 235 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
2971 | 236 | |||
2972 | 237 | widget = gtk_entry_new (); | ||
2973 | 238 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
2974 | 239 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page); | ||
2975 | 240 | g_object_set_data (G_OBJECT (row), "gateway", widget); | ||
2976 | 241 | gtk_entry_set_text (GTK_ENTRY (widget), gateway ? gateway : ""); | ||
2977 | 242 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 16); | ||
2978 | 243 | gtk_widget_set_hexpand (widget, TRUE); | ||
2979 | 244 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
2980 | 245 | |||
2981 | 246 | delete_button = gtk_button_new (); | ||
2982 | 247 | gtk_widget_set_sensitive (delete_button, FALSE); | ||
2983 | 248 | gtk_style_context_add_class (gtk_widget_get_style_context (delete_button), "image-button"); | ||
2984 | 249 | g_signal_connect (delete_button, "clicked", G_CALLBACK (remove_row), page); | ||
2985 | 250 | image = gtk_image_new_from_icon_name ("edit-delete-symbolic", GTK_ICON_SIZE_MENU); | ||
2986 | 251 | atk_object_set_name (gtk_widget_get_accessible (delete_button), _("Delete Address")); | ||
2987 | 252 | gtk_button_set_image (GTK_BUTTON (delete_button), image); | ||
2988 | 253 | gtk_container_add (GTK_CONTAINER (row_box), delete_button); | ||
2989 | 254 | g_object_set_data (G_OBJECT (row), "delete-button", delete_button); | ||
2990 | 255 | |||
2991 | 256 | group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "address_sizegroup")); | ||
2992 | 257 | gtk_size_group_add_widget (group, delete_button); | ||
2993 | 258 | |||
2994 | 259 | gtk_container_add (GTK_CONTAINER (row), row_box); | ||
2995 | 260 | gtk_widget_show_all (row); | ||
2996 | 261 | gtk_container_add (GTK_CONTAINER (page->address_list), row); | ||
2997 | 262 | |||
2998 | 263 | update_row_gateway_sensitivity (page); | ||
2999 | 264 | update_row_sensitivity (page, page->address_list); | ||
3000 | 265 | } | ||
3001 | 266 | |||
3002 | 267 | static void | ||
3003 | 268 | ensure_empty_address_row (CEPageIP4 *page) | ||
3004 | 269 | { | ||
3005 | 270 | GList *children, *l; | ||
3006 | 271 | |||
3007 | 272 | children = gtk_container_get_children (GTK_CONTAINER (page->address_list)); | ||
3008 | 273 | l = children; | ||
3009 | 274 | |||
3010 | 275 | while (l && l->next) | ||
3011 | 276 | l = l->next; | ||
3012 | 277 | |||
3013 | 278 | /* Add the last, stub row if needed*/ | ||
3014 | 279 | if (!l || validate_row (l->data)) | ||
3015 | 280 | add_address_row (page, "", "", ""); | ||
3016 | 281 | |||
3017 | 282 | g_list_free (children); | ||
3018 | 283 | } | ||
3019 | 284 | |||
3020 | 285 | static void | ||
3021 | 286 | add_address_section (CEPageIP4 *page) | ||
3022 | 287 | { | ||
3023 | 288 | GtkWidget *widget; | ||
3024 | 289 | GtkWidget *list; | ||
3025 | 290 | gint i; | ||
3026 | 291 | |||
3027 | 292 | widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section")); | ||
3028 | 293 | |||
3029 | 294 | page->address_list = list = gtk_list_box_new (); | ||
3030 | 295 | gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE); | ||
3031 | 296 | gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL); | ||
3032 | 297 | gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL); | ||
3033 | 298 | gtk_container_add (GTK_CONTAINER (widget), list); | ||
3034 | 299 | |||
3035 | 300 | for (i = 0; i < nm_setting_ip_config_get_num_addresses (page->setting); i++) { | ||
3036 | 301 | NMIPAddress *addr; | ||
3037 | 302 | struct in_addr tmp_addr; | ||
3038 | 303 | gchar network[INET_ADDRSTRLEN + 1]; | ||
3039 | 304 | |||
3040 | 305 | addr = nm_setting_ip_config_get_address (page->setting, i); | ||
3041 | 306 | if (!addr) | ||
3042 | 307 | continue; | ||
3043 | 308 | |||
3044 | 309 | tmp_addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip_address_get_prefix (addr)); | ||
3045 | 310 | (void) inet_ntop (AF_INET, &tmp_addr, &network[0], sizeof (network)); | ||
3046 | 311 | |||
3047 | 312 | add_address_row (page, | ||
3048 | 313 | nm_ip_address_get_address (addr), | ||
3049 | 314 | network, | ||
3050 | 315 | i == 0 ? nm_setting_ip_config_get_gateway (page->setting) : ""); | ||
3051 | 316 | } | ||
3052 | 317 | if (nm_setting_ip_config_get_num_addresses (page->setting) == 0) | ||
3053 | 318 | ensure_empty_address_row (page); | ||
3054 | 319 | |||
3055 | 320 | gtk_widget_show_all (widget); | ||
3056 | 321 | } | ||
3057 | 322 | |||
3058 | 323 | static void | ||
3059 | 324 | add_dns_section (CEPageIP4 *page) | ||
3060 | 325 | { | ||
3061 | 326 | GtkEntry *entry; | ||
3062 | 327 | GString *string; | ||
3063 | 328 | gint i; | ||
3064 | 329 | |||
3065 | 330 | page->auto_dns = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_dns_switch")); | ||
3066 | 331 | gtk_switch_set_active (page->auto_dns, !nm_setting_ip_config_get_ignore_auto_dns (page->setting)); | ||
3067 | 332 | g_signal_connect (page->auto_dns, "notify::active", G_CALLBACK (switch_toggled), page); | ||
3068 | 333 | |||
3069 | 334 | page->dns_entry = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "dns_entry")); | ||
3070 | 335 | entry = GTK_ENTRY (page->dns_entry); | ||
3071 | 336 | string = g_string_new (""); | ||
3072 | 337 | |||
3073 | 338 | for (i = 0; i < nm_setting_ip_config_get_num_dns (page->setting); i++) { | ||
3074 | 339 | const char *address; | ||
3075 | 340 | |||
3076 | 341 | address = nm_setting_ip_config_get_dns (page->setting, i); | ||
3077 | 342 | |||
3078 | 343 | if (i > 0) | ||
3079 | 344 | g_string_append (string, ", "); | ||
3080 | 345 | |||
3081 | 346 | g_string_append (string, address); | ||
3082 | 347 | } | ||
3083 | 348 | |||
3084 | 349 | gtk_entry_set_text (entry, string->str); | ||
3085 | 350 | |||
3086 | 351 | g_signal_connect_swapped (entry, "notify::text", G_CALLBACK (ce_page_changed), page); | ||
3087 | 352 | |||
3088 | 353 | g_string_free (string, TRUE); | ||
3089 | 354 | } | ||
3090 | 355 | |||
3091 | 356 | static void | ||
3092 | 357 | add_route_row (CEPageIP4 *page, | ||
3093 | 358 | const gchar *address, | ||
3094 | 359 | const gchar *netmask, | ||
3095 | 360 | const gchar *gateway, | ||
3096 | 361 | gint metric) | ||
3097 | 362 | { | ||
3098 | 363 | GtkSizeGroup *group; | ||
3099 | 364 | GtkWidget *row; | ||
3100 | 365 | GtkWidget *row_box; | ||
3101 | 366 | GtkWidget *widget; | ||
3102 | 367 | GtkWidget *delete_button; | ||
3103 | 368 | GtkWidget *image; | ||
3104 | 369 | |||
3105 | 370 | row = gtk_list_box_row_new (); | ||
3106 | 371 | |||
3107 | 372 | row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); | ||
3108 | 373 | gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked"); | ||
3109 | 374 | |||
3110 | 375 | widget = gtk_entry_new (); | ||
3111 | 376 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
3112 | 377 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page); | ||
3113 | 378 | g_object_set_data (G_OBJECT (row), "address", widget); | ||
3114 | 379 | gtk_entry_set_text (GTK_ENTRY (widget), address); | ||
3115 | 380 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 16); | ||
3116 | 381 | gtk_widget_set_hexpand (widget, TRUE); | ||
3117 | 382 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
3118 | 383 | |||
3119 | 384 | widget = gtk_entry_new (); | ||
3120 | 385 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
3121 | 386 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page); | ||
3122 | 387 | g_object_set_data (G_OBJECT (row), "netmask", widget); | ||
3123 | 388 | gtk_entry_set_text (GTK_ENTRY (widget), netmask); | ||
3124 | 389 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 16); | ||
3125 | 390 | gtk_widget_set_hexpand (widget, TRUE); | ||
3126 | 391 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
3127 | 392 | |||
3128 | 393 | widget = gtk_entry_new (); | ||
3129 | 394 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
3130 | 395 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page); | ||
3131 | 396 | g_object_set_data (G_OBJECT (row), "gateway", widget); | ||
3132 | 397 | gtk_entry_set_text (GTK_ENTRY (widget), gateway); | ||
3133 | 398 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 16); | ||
3134 | 399 | gtk_widget_set_hexpand (widget, TRUE); | ||
3135 | 400 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
3136 | 401 | |||
3137 | 402 | widget = gtk_entry_new (); | ||
3138 | 403 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
3139 | 404 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page); | ||
3140 | 405 | g_object_set_data (G_OBJECT (row), "metric", widget); | ||
3141 | 406 | if (metric >= 0) { | ||
3142 | 407 | gchar *s = g_strdup_printf ("%d", metric); | ||
3143 | 408 | gtk_entry_set_text (GTK_ENTRY (widget), s); | ||
3144 | 409 | g_free (s); | ||
3145 | 410 | } | ||
3146 | 411 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 5); | ||
3147 | 412 | gtk_widget_set_hexpand (widget, TRUE); | ||
3148 | 413 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
3149 | 414 | |||
3150 | 415 | group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_metric_sizegroup")); | ||
3151 | 416 | gtk_size_group_add_widget (group, widget); | ||
3152 | 417 | |||
3153 | 418 | delete_button = gtk_button_new (); | ||
3154 | 419 | gtk_style_context_add_class (gtk_widget_get_style_context (delete_button), "image-button"); | ||
3155 | 420 | g_signal_connect (delete_button, "clicked", G_CALLBACK (remove_row), page); | ||
3156 | 421 | image = gtk_image_new_from_icon_name ("edit-delete-symbolic", GTK_ICON_SIZE_MENU); | ||
3157 | 422 | atk_object_set_name (gtk_widget_get_accessible (delete_button), _("Delete Route")); | ||
3158 | 423 | gtk_button_set_image (GTK_BUTTON (delete_button), image); | ||
3159 | 424 | gtk_widget_set_halign (delete_button, GTK_ALIGN_CENTER); | ||
3160 | 425 | gtk_widget_set_valign (delete_button, GTK_ALIGN_CENTER); | ||
3161 | 426 | gtk_container_add (GTK_CONTAINER (row_box), delete_button); | ||
3162 | 427 | g_object_set_data (G_OBJECT (row), "delete-button", delete_button); | ||
3163 | 428 | |||
3164 | 429 | group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_sizegroup")); | ||
3165 | 430 | gtk_size_group_add_widget (group, delete_button); | ||
3166 | 431 | |||
3167 | 432 | gtk_container_add (GTK_CONTAINER (row), row_box); | ||
3168 | 433 | gtk_widget_show_all (row); | ||
3169 | 434 | gtk_container_add (GTK_CONTAINER (page->routes_list), row); | ||
3170 | 435 | |||
3171 | 436 | update_row_sensitivity (page, page->routes_list); | ||
3172 | 437 | } | ||
3173 | 438 | |||
3174 | 439 | static void | ||
3175 | 440 | ensure_empty_routes_row (CEPageIP4 *page) | ||
3176 | 441 | { | ||
3177 | 442 | GList *children, *l; | ||
3178 | 443 | |||
3179 | 444 | children = gtk_container_get_children (GTK_CONTAINER (page->routes_list)); | ||
3180 | 445 | l = children; | ||
3181 | 446 | |||
3182 | 447 | while (l && l->next) | ||
3183 | 448 | l = l->next; | ||
3184 | 449 | |||
3185 | 450 | /* Add the last, stub row if needed*/ | ||
3186 | 451 | if (!l || validate_row (l->data)) | ||
3187 | 452 | add_route_row (page, "", "", "", -1); | ||
3188 | 453 | |||
3189 | 454 | g_list_free (children); | ||
3190 | 455 | } | ||
3191 | 456 | |||
3192 | 457 | static void | ||
3193 | 458 | add_routes_section (CEPageIP4 *page) | ||
3194 | 459 | { | ||
3195 | 460 | GtkWidget *widget; | ||
3196 | 461 | GtkWidget *list; | ||
3197 | 462 | gint i; | ||
3198 | 463 | |||
3199 | 464 | widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_section")); | ||
3200 | 465 | |||
3201 | 466 | page->routes_list = list = gtk_list_box_new (); | ||
3202 | 467 | gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE); | ||
3203 | 468 | gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL); | ||
3204 | 469 | gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL); | ||
3205 | 470 | gtk_container_add (GTK_CONTAINER (widget), list); | ||
3206 | 471 | page->auto_routes = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_routes_switch")); | ||
3207 | 472 | gtk_switch_set_active (page->auto_routes, !nm_setting_ip_config_get_ignore_auto_routes (page->setting)); | ||
3208 | 473 | g_signal_connect (page->auto_routes, "notify::active", G_CALLBACK (switch_toggled), page); | ||
3209 | 474 | |||
3210 | 475 | |||
3211 | 476 | for (i = 0; i < nm_setting_ip_config_get_num_routes (page->setting); i++) { | ||
3212 | 477 | NMIPRoute *route; | ||
3213 | 478 | struct in_addr tmp_addr; | ||
3214 | 479 | gchar netmask[INET_ADDRSTRLEN + 1]; | ||
3215 | 480 | |||
3216 | 481 | route = nm_setting_ip_config_get_route (page->setting, i); | ||
3217 | 482 | if (!route) | ||
3218 | 483 | continue; | ||
3219 | 484 | |||
3220 | 485 | tmp_addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip_route_get_prefix (route)); | ||
3221 | 486 | (void) inet_ntop (AF_INET, &tmp_addr, &netmask[0], sizeof (netmask)); | ||
3222 | 487 | |||
3223 | 488 | add_route_row (page, | ||
3224 | 489 | nm_ip_route_get_dest (route), | ||
3225 | 490 | netmask, | ||
3226 | 491 | nm_ip_route_get_next_hop (route), | ||
3227 | 492 | nm_ip_route_get_metric (route)); | ||
3228 | 493 | } | ||
3229 | 494 | if (nm_setting_ip_config_get_num_routes (page->setting) == 0) | ||
3230 | 495 | ensure_empty_routes_row (page); | ||
3231 | 496 | |||
3232 | 497 | gtk_widget_show_all (widget); | ||
3233 | 498 | } | ||
3234 | 499 | |||
3235 | 500 | enum | ||
3236 | 501 | { | ||
3237 | 502 | RADIO_AUTOMATIC, | ||
3238 | 503 | RADIO_LOCAL, | ||
3239 | 504 | RADIO_MANUAL, | ||
3240 | 505 | RADIO_DISABLED, | ||
3241 | 506 | N_RADIO | ||
3242 | 507 | }; | ||
3243 | 508 | |||
3244 | 509 | static void | ||
3245 | 510 | connect_ip4_page (CEPageIP4 *page) | ||
3246 | 511 | { | ||
3247 | 512 | GtkToggleButton *radios[N_RADIO]; | ||
3248 | 513 | GtkWidget *content; | ||
3249 | 514 | const gchar *str_method; | ||
3250 | 515 | gboolean disabled; | ||
3251 | 516 | guint method, i; | ||
3252 | 517 | |||
3253 | 518 | add_address_section (page); | ||
3254 | 519 | add_dns_section (page); | ||
3255 | 520 | add_routes_section (page); | ||
3256 | 521 | |||
3257 | 522 | page->disabled = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_disabled")); | ||
3258 | 523 | |||
3259 | 524 | str_method = nm_setting_ip_config_get_method (page->setting); | ||
3260 | 525 | disabled = g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0; | ||
3261 | 526 | gtk_toggle_button_set_active (page->disabled, disabled); | ||
3262 | 527 | g_signal_connect_swapped (page->disabled, "notify::active", G_CALLBACK (ce_page_changed), page); | ||
3263 | 528 | content = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "page_content")); | ||
3264 | 529 | g_object_bind_property (page->disabled, "active", | ||
3265 | 530 | content, "sensitive", | ||
3266 | 531 | G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN); | ||
3267 | 532 | |||
3268 | 533 | method = IP4_METHOD_AUTO; | ||
3269 | 534 | if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) == 0) { | ||
3270 | 535 | method = IP4_METHOD_LINK_LOCAL; | ||
3271 | 536 | } else if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0) { | ||
3272 | 537 | method = IP4_METHOD_MANUAL; | ||
3273 | 538 | } else if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) { | ||
3274 | 539 | method = IP4_METHOD_SHARED; | ||
3275 | 540 | } else if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0) { | ||
3276 | 541 | method = IP4_METHOD_DISABLED; | ||
3277 | 542 | } | ||
3278 | 543 | |||
3279 | 544 | page->never_default = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "never_default_check")); | ||
3280 | 545 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->never_default), | ||
3281 | 546 | nm_setting_ip_config_get_never_default (page->setting)); | ||
3282 | 547 | g_signal_connect_swapped (page->never_default, "toggled", G_CALLBACK (ce_page_changed), page); | ||
3283 | 548 | |||
3284 | 549 | /* Connect radio buttons */ | ||
3285 | 550 | radios[RADIO_AUTOMATIC] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_automatic")); | ||
3286 | 551 | radios[RADIO_LOCAL] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_local")); | ||
3287 | 552 | radios[RADIO_MANUAL] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_manual")); | ||
3288 | 553 | radios[RADIO_DISABLED] = page->disabled; | ||
3289 | 554 | |||
3290 | 555 | for (i = RADIO_AUTOMATIC; i < RADIO_DISABLED; i++) | ||
3291 | 556 | g_signal_connect (radios[i], "toggled", G_CALLBACK (method_changed), page); | ||
3292 | 557 | |||
3293 | 558 | switch (method) { | ||
3294 | 559 | case IP4_METHOD_AUTO: | ||
3295 | 560 | gtk_toggle_button_set_active (radios[RADIO_AUTOMATIC], TRUE); | ||
3296 | 561 | break; | ||
3297 | 562 | case IP4_METHOD_LINK_LOCAL: | ||
3298 | 563 | gtk_toggle_button_set_active (radios[RADIO_LOCAL], TRUE); | ||
3299 | 564 | break; | ||
3300 | 565 | case IP4_METHOD_MANUAL: | ||
3301 | 566 | gtk_toggle_button_set_active (radios[RADIO_MANUAL], TRUE); | ||
3302 | 567 | break; | ||
3303 | 568 | case IP4_METHOD_DISABLED: | ||
3304 | 569 | gtk_toggle_button_set_active (radios[RADIO_DISABLED], TRUE); | ||
3305 | 570 | break; | ||
3306 | 571 | default: | ||
3307 | 572 | break; | ||
3308 | 573 | } | ||
3309 | 574 | |||
3310 | 575 | method_changed (NULL, page); | ||
3311 | 576 | } | ||
3312 | 577 | |||
3313 | 578 | static gboolean | ||
3314 | 579 | parse_netmask (const char *str, guint32 *prefix) | ||
3315 | 580 | { | ||
3316 | 581 | struct in_addr tmp_addr; | ||
3317 | 582 | glong tmp_prefix; | ||
3318 | 583 | |||
3319 | 584 | errno = 0; | ||
3320 | 585 | |||
3321 | 586 | /* Is it a prefix? */ | ||
3322 | 587 | if (!strchr (str, '.')) { | ||
3323 | 588 | tmp_prefix = strtol (str, NULL, 10); | ||
3324 | 589 | if (!errno && tmp_prefix >= 0 && tmp_prefix <= 32) { | ||
3325 | 590 | *prefix = tmp_prefix; | ||
3326 | 591 | return TRUE; | ||
3327 | 592 | } | ||
3328 | 593 | } | ||
3329 | 594 | |||
3330 | 595 | /* Is it a netmask? */ | ||
3331 | 596 | if (inet_pton (AF_INET, str, &tmp_addr) > 0) { | ||
3332 | 597 | *prefix = nm_utils_ip4_netmask_to_prefix (tmp_addr.s_addr); | ||
3333 | 598 | return TRUE; | ||
3334 | 599 | } | ||
3335 | 600 | |||
3336 | 601 | return FALSE; | ||
3337 | 602 | } | ||
3338 | 603 | |||
3339 | 604 | static gboolean | ||
3340 | 605 | ui_to_setting (CEPageIP4 *page) | ||
3341 | 606 | { | ||
3342 | 607 | const gchar *method; | ||
3343 | 608 | gboolean ignore_auto_dns; | ||
3344 | 609 | gboolean ignore_auto_routes; | ||
3345 | 610 | gboolean never_default; | ||
3346 | 611 | GPtrArray *addresses = NULL; | ||
3347 | 612 | GPtrArray *dns_servers = NULL; | ||
3348 | 613 | GPtrArray *routes = NULL; | ||
3349 | 614 | GStrv dns_addresses = NULL; | ||
3350 | 615 | GList *children, *l; | ||
3351 | 616 | gboolean ret = TRUE; | ||
3352 | 617 | const char *default_gateway = NULL; | ||
3353 | 618 | gchar *dns_text = NULL; | ||
3354 | 619 | guint i; | ||
3355 | 620 | |||
3356 | 621 | if (gtk_toggle_button_get_active (page->disabled)) { | ||
3357 | 622 | method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED; | ||
3358 | 623 | } else { | ||
3359 | 624 | if (RADIO_IS_ACTIVE ("radio_automatic")) | ||
3360 | 625 | method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; | ||
3361 | 626 | else if (RADIO_IS_ACTIVE ("radio_local")) | ||
3362 | 627 | method = NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL; | ||
3363 | 628 | else if (RADIO_IS_ACTIVE ("radio_manual")) | ||
3364 | 629 | method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; | ||
3365 | 630 | } | ||
3366 | 631 | |||
3367 | 632 | addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref); | ||
3368 | 633 | if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) | ||
3369 | 634 | children = gtk_container_get_children (GTK_CONTAINER (page->address_list)); | ||
3370 | 635 | else | ||
3371 | 636 | children = NULL; | ||
3372 | 637 | |||
3373 | 638 | for (l = children; l; l = l->next) { | ||
3374 | 639 | GtkWidget *row = l->data; | ||
3375 | 640 | GtkEntry *entry; | ||
3376 | 641 | GtkEntry *gateway_entry; | ||
3377 | 642 | const gchar *text_address; | ||
3378 | 643 | const gchar *text_netmask; | ||
3379 | 644 | const gchar *text_gateway = ""; | ||
3380 | 645 | NMIPAddress *addr; | ||
3381 | 646 | guint32 prefix; | ||
3382 | 647 | |||
3383 | 648 | entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address")); | ||
3384 | 649 | if (!entry) | ||
3385 | 650 | continue; | ||
3386 | 651 | |||
3387 | 652 | text_address = gtk_entry_get_text (entry); | ||
3388 | 653 | text_netmask = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "network"))); | ||
3389 | 654 | gateway_entry = g_object_get_data (G_OBJECT (row), "gateway"); | ||
3390 | 655 | if (gtk_widget_is_visible (GTK_WIDGET (gateway_entry))) | ||
3391 | 656 | text_gateway = gtk_entry_get_text (gateway_entry); | ||
3392 | 657 | |||
3393 | 658 | if (!*text_address && !*text_netmask && !*text_gateway) { | ||
3394 | 659 | /* ignore empty rows */ | ||
3395 | 660 | widget_unset_error (GTK_WIDGET (entry)); | ||
3396 | 661 | widget_unset_error (g_object_get_data (G_OBJECT (row), "network")); | ||
3397 | 662 | widget_unset_error (GTK_WIDGET (gateway_entry)); | ||
3398 | 663 | continue; | ||
3399 | 664 | } | ||
3400 | 665 | |||
3401 | 666 | if (!nm_utils_ipaddr_valid (AF_INET, text_address)) { | ||
3402 | 667 | widget_set_error (GTK_WIDGET (entry)); | ||
3403 | 668 | ret = FALSE; | ||
3404 | 669 | } else { | ||
3405 | 670 | widget_unset_error (GTK_WIDGET (entry)); | ||
3406 | 671 | } | ||
3407 | 672 | |||
3408 | 673 | if (!parse_netmask (text_netmask, &prefix)) { | ||
3409 | 674 | widget_set_error (g_object_get_data (G_OBJECT (row), "network")); | ||
3410 | 675 | ret = FALSE; | ||
3411 | 676 | } else { | ||
3412 | 677 | widget_unset_error (g_object_get_data (G_OBJECT (row), "network")); | ||
3413 | 678 | } | ||
3414 | 679 | |||
3415 | 680 | if (gtk_widget_is_visible (GTK_WIDGET (gateway_entry)) && | ||
3416 | 681 | *text_gateway && | ||
3417 | 682 | !nm_utils_ipaddr_valid (AF_INET, text_gateway)) { | ||
3418 | 683 | widget_set_error (g_object_get_data (G_OBJECT (row), "gateway")); | ||
3419 | 684 | ret = FALSE; | ||
3420 | 685 | } else { | ||
3421 | 686 | widget_unset_error (GTK_WIDGET (gateway_entry)); | ||
3422 | 687 | if (gtk_widget_is_visible (GTK_WIDGET (gateway_entry)) && *text_gateway) { | ||
3423 | 688 | g_assert (default_gateway == NULL); | ||
3424 | 689 | default_gateway = text_gateway; | ||
3425 | 690 | } | ||
3426 | 691 | } | ||
3427 | 692 | |||
3428 | 693 | if (!ret) | ||
3429 | 694 | continue; | ||
3430 | 695 | |||
3431 | 696 | addr = nm_ip_address_new (AF_INET, text_address, prefix, NULL); | ||
3432 | 697 | if (addr) | ||
3433 | 698 | g_ptr_array_add (addresses, addr); | ||
3434 | 699 | |||
3435 | 700 | if (!l || !l->next) | ||
3436 | 701 | ensure_empty_address_row (page); | ||
3437 | 702 | } | ||
3438 | 703 | g_list_free (children); | ||
3439 | 704 | |||
3440 | 705 | if (addresses->len == 0) { | ||
3441 | 706 | g_ptr_array_free (addresses, TRUE); | ||
3442 | 707 | addresses = NULL; | ||
3443 | 708 | } | ||
3444 | 709 | |||
3445 | 710 | dns_servers = g_ptr_array_new_with_free_func (g_free); | ||
3446 | 711 | dns_text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (page->dns_entry)))); | ||
3447 | 712 | if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) || | ||
3448 | 713 | g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) | ||
3449 | 714 | dns_addresses = g_strsplit_set (dns_text, ", ", -1); | ||
3450 | 715 | else | ||
3451 | 716 | dns_addresses = NULL; | ||
3452 | 717 | |||
3453 | 718 | for (i = 0; dns_addresses && dns_addresses[i]; i++) { | ||
3454 | 719 | const gchar *text; | ||
3455 | 720 | |||
3456 | 721 | text = dns_addresses[i]; | ||
3457 | 722 | |||
3458 | 723 | if (!text || !*text) | ||
3459 | 724 | continue; | ||
3460 | 725 | |||
3461 | 726 | if (!nm_utils_ipaddr_valid (AF_INET, text)) { | ||
3462 | 727 | g_ptr_array_remove_range (dns_servers, 0, dns_servers->len); | ||
3463 | 728 | widget_set_error (page->dns_entry); | ||
3464 | 729 | ret = FALSE; | ||
3465 | 730 | break; | ||
3466 | 731 | } else { | ||
3467 | 732 | widget_unset_error (page->dns_entry); | ||
3468 | 733 | g_ptr_array_add (dns_servers, g_strdup (text)); | ||
3469 | 734 | } | ||
3470 | 735 | } | ||
3471 | 736 | g_clear_pointer (&dns_addresses, g_strfreev); | ||
3472 | 737 | |||
3473 | 738 | if (dns_servers->len == 0) { | ||
3474 | 739 | g_ptr_array_free (dns_servers, TRUE); | ||
3475 | 740 | dns_servers = NULL; | ||
3476 | 741 | } else { | ||
3477 | 742 | g_ptr_array_add (dns_servers, NULL); | ||
3478 | 743 | } | ||
3479 | 744 | |||
3480 | 745 | routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref); | ||
3481 | 746 | if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) || | ||
3482 | 747 | g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) | ||
3483 | 748 | children = gtk_container_get_children (GTK_CONTAINER (page->routes_list)); | ||
3484 | 749 | else | ||
3485 | 750 | children = NULL; | ||
3486 | 751 | |||
3487 | 752 | for (l = children; l; l = l->next) { | ||
3488 | 753 | GtkWidget *row = l->data; | ||
3489 | 754 | GtkEntry *entry; | ||
3490 | 755 | const gchar *text_address; | ||
3491 | 756 | const gchar *text_netmask; | ||
3492 | 757 | const gchar *text_gateway; | ||
3493 | 758 | const gchar *text_metric; | ||
3494 | 759 | gint64 metric; | ||
3495 | 760 | guint32 netmask; | ||
3496 | 761 | NMIPRoute *route; | ||
3497 | 762 | |||
3498 | 763 | entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address")); | ||
3499 | 764 | if (!entry) | ||
3500 | 765 | continue; | ||
3501 | 766 | |||
3502 | 767 | text_address = gtk_entry_get_text (entry); | ||
3503 | 768 | text_netmask = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "netmask"))); | ||
3504 | 769 | text_gateway = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "gateway"))); | ||
3505 | 770 | text_metric = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "metric"))); | ||
3506 | 771 | |||
3507 | 772 | if (!*text_address && !*text_netmask && !*text_gateway && !*text_metric) { | ||
3508 | 773 | /* ignore empty rows */ | ||
3509 | 774 | continue; | ||
3510 | 775 | } | ||
3511 | 776 | |||
3512 | 777 | if (text_address && !nm_utils_ipaddr_valid (AF_INET, text_address)) { | ||
3513 | 778 | widget_set_error (GTK_WIDGET (entry)); | ||
3514 | 779 | ret = FALSE; | ||
3515 | 780 | } else { | ||
3516 | 781 | widget_unset_error (GTK_WIDGET (entry)); | ||
3517 | 782 | } | ||
3518 | 783 | |||
3519 | 784 | if (!parse_netmask (text_netmask, &netmask)) { | ||
3520 | 785 | widget_set_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "netmask"))); | ||
3521 | 786 | ret = FALSE; | ||
3522 | 787 | } else { | ||
3523 | 788 | widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "netmask"))); | ||
3524 | 789 | } | ||
3525 | 790 | |||
3526 | 791 | if (text_gateway && !nm_utils_ipaddr_valid (AF_INET, text_gateway)) { | ||
3527 | 792 | widget_set_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "gateway"))); | ||
3528 | 793 | ret = FALSE; | ||
3529 | 794 | } else { | ||
3530 | 795 | widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "gateway"))); | ||
3531 | 796 | } | ||
3532 | 797 | |||
3533 | 798 | metric = -1; | ||
3534 | 799 | if (*text_metric) { | ||
3535 | 800 | errno = 0; | ||
3536 | 801 | metric = g_ascii_strtoull (text_metric, NULL, 10); | ||
3537 | 802 | if (errno || metric < 0 || metric > G_MAXUINT32) { | ||
3538 | 803 | widget_set_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "metric"))); | ||
3539 | 804 | ret = FALSE; | ||
3540 | 805 | } else { | ||
3541 | 806 | widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "metric"))); | ||
3542 | 807 | } | ||
3543 | 808 | } else { | ||
3544 | 809 | widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "metric"))); | ||
3545 | 810 | } | ||
3546 | 811 | |||
3547 | 812 | if (!ret) | ||
3548 | 813 | continue; | ||
3549 | 814 | |||
3550 | 815 | route = nm_ip_route_new (AF_INET, text_address, netmask, text_gateway, metric, NULL); | ||
3551 | 816 | if (route) | ||
3552 | 817 | g_ptr_array_add (routes, route); | ||
3553 | 818 | |||
3554 | 819 | if (!l || !l->next) | ||
3555 | 820 | ensure_empty_routes_row (page); | ||
3556 | 821 | } | ||
3557 | 822 | g_list_free (children); | ||
3558 | 823 | |||
3559 | 824 | if (routes->len == 0) { | ||
3560 | 825 | g_ptr_array_free (routes, TRUE); | ||
3561 | 826 | routes = NULL; | ||
3562 | 827 | } | ||
3563 | 828 | |||
3564 | 829 | if (!ret) | ||
3565 | 830 | goto out; | ||
3566 | 831 | |||
3567 | 832 | ignore_auto_dns = !gtk_switch_get_active (page->auto_dns); | ||
3568 | 833 | ignore_auto_routes = !gtk_switch_get_active (page->auto_routes); | ||
3569 | 834 | never_default = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (page->never_default)); | ||
3570 | 835 | |||
3571 | 836 | g_object_set (page->setting, | ||
3572 | 837 | NM_SETTING_IP_CONFIG_METHOD, method, | ||
3573 | 838 | NM_SETTING_IP_CONFIG_ADDRESSES, addresses, | ||
3574 | 839 | NM_SETTING_IP_CONFIG_GATEWAY, default_gateway, | ||
3575 | 840 | NM_SETTING_IP_CONFIG_DNS, dns_servers ? dns_servers->pdata : NULL, | ||
3576 | 841 | NM_SETTING_IP_CONFIG_ROUTES, routes, | ||
3577 | 842 | NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns, | ||
3578 | 843 | NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, ignore_auto_routes, | ||
3579 | 844 | NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, | ||
3580 | 845 | NULL); | ||
3581 | 846 | |||
3582 | 847 | out: | ||
3583 | 848 | if (addresses) | ||
3584 | 849 | g_ptr_array_free (addresses, TRUE); | ||
3585 | 850 | |||
3586 | 851 | if (dns_servers) | ||
3587 | 852 | g_ptr_array_free (dns_servers, TRUE); | ||
3588 | 853 | |||
3589 | 854 | if (routes) | ||
3590 | 855 | g_ptr_array_free (routes, TRUE); | ||
3591 | 856 | |||
3592 | 857 | g_clear_pointer (&dns_text, g_free); | ||
3593 | 858 | |||
3594 | 859 | return ret; | ||
3595 | 860 | } | ||
3596 | 861 | |||
3597 | 862 | static gboolean | ||
3598 | 863 | validate (CEPage *page, | ||
3599 | 864 | NMConnection *connection, | ||
3600 | 865 | GError **error) | ||
3601 | 866 | { | ||
3602 | 867 | if (!ui_to_setting (CE_PAGE_IP4 (page))) | ||
3603 | 868 | return FALSE; | ||
3604 | 869 | |||
3605 | 870 | return nm_setting_verify (NM_SETTING (CE_PAGE_IP4 (page)->setting), NULL, error); | ||
3606 | 871 | } | ||
3607 | 872 | |||
3608 | 873 | static void | ||
3609 | 874 | ce_page_ip4_init (CEPageIP4 *page) | ||
3610 | 875 | { | ||
3611 | 876 | } | ||
3612 | 877 | |||
3613 | 878 | static void | ||
3614 | 879 | ce_page_ip4_class_init (CEPageIP4Class *class) | ||
3615 | 880 | { | ||
3616 | 881 | CEPageClass *page_class= CE_PAGE_CLASS (class); | ||
3617 | 882 | |||
3618 | 883 | page_class->validate = validate; | ||
3619 | 884 | } | ||
3620 | 885 | |||
3621 | 886 | CEPage * | ||
3622 | 887 | ce_page_ip4_new (NMConnection *connection, | ||
3623 | 888 | NMClient *client) | ||
3624 | 889 | { | ||
3625 | 890 | CEPageIP4 *page; | ||
3626 | 891 | |||
3627 | 892 | page = CE_PAGE_IP4 (ce_page_new (CE_TYPE_PAGE_IP4, | ||
3628 | 893 | connection, | ||
3629 | 894 | client, | ||
3630 | 895 | "/org/gnome/control-center/network/ip4-page.ui", | ||
3631 | 896 | _("IPv4"))); | ||
3632 | 897 | |||
3633 | 898 | page->setting = nm_connection_get_setting_ip4_config (connection); | ||
3634 | 899 | if (!page->setting) { | ||
3635 | 900 | page->setting = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); | ||
3636 | 901 | nm_connection_add_setting (connection, NM_SETTING (page->setting)); | ||
3637 | 902 | } | ||
3638 | 903 | |||
3639 | 904 | connect_ip4_page (page); | ||
3640 | 905 | |||
3641 | 906 | return CE_PAGE (page); | ||
3642 | 907 | } | ||
3643 | 0 | 908 | ||
3644 | === added file 'panels/network/connection-editor/ce-page-ip4.h' | |||
3645 | --- panels/network/connection-editor/ce-page-ip4.h 1970-01-01 00:00:00 +0000 | |||
3646 | +++ panels/network/connection-editor/ce-page-ip4.h 2019-05-01 13:56:52 +0000 | |||
3647 | @@ -0,0 +1,70 @@ | |||
3648 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
3649 | 2 | * | ||
3650 | 3 | * Copyright (C) 2012 Red Hat, Inc. | ||
3651 | 4 | * | ||
3652 | 5 | * Licensed under the GNU General Public License Version 2 | ||
3653 | 6 | * | ||
3654 | 7 | * This program is free software; you can redistribute it and/or modify | ||
3655 | 8 | * it under the terms of the GNU General Public License as published by | ||
3656 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
3657 | 10 | * (at your option) any later version. | ||
3658 | 11 | * | ||
3659 | 12 | * This program is distributed in the hope that it will be useful, | ||
3660 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3661 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3662 | 15 | * GNU General Public License for more ip4. | ||
3663 | 16 | * | ||
3664 | 17 | * You should have received a copy of the GNU General Public License | ||
3665 | 18 | * along with this program; if not, write to the Free Software | ||
3666 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
3667 | 20 | */ | ||
3668 | 21 | |||
3669 | 22 | #ifndef __CE_PAGE_IP4_H | ||
3670 | 23 | #define __CE_PAGE_IP4_H | ||
3671 | 24 | |||
3672 | 25 | #include <glib-object.h> | ||
3673 | 26 | |||
3674 | 27 | #include <gtk/gtk.h> | ||
3675 | 28 | #include "ce-page.h" | ||
3676 | 29 | |||
3677 | 30 | G_BEGIN_DECLS | ||
3678 | 31 | |||
3679 | 32 | #define CE_TYPE_PAGE_IP4 (ce_page_ip4_get_type ()) | ||
3680 | 33 | #define CE_PAGE_IP4(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CE_TYPE_PAGE_IP4, CEPageIP4)) | ||
3681 | 34 | #define CE_PAGE_IP4_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CE_TYPE_PAGE_IP4, CEPageIP4Class)) | ||
3682 | 35 | #define CE_IS_PAGE_IP4(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CE_TYPE_PAGE_IP4)) | ||
3683 | 36 | #define CE_IS_PAGE_IP4_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CE_TYPE_PAGE_IP4)) | ||
3684 | 37 | #define CE_PAGE_IP4_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CE_TYPE_PAGE_IP4, CEPageIP4Class)) | ||
3685 | 38 | |||
3686 | 39 | typedef struct _CEPageIP4 CEPageIP4; | ||
3687 | 40 | typedef struct _CEPageIP4Class CEPageIP4Class; | ||
3688 | 41 | |||
3689 | 42 | struct _CEPageIP4 | ||
3690 | 43 | { | ||
3691 | 44 | CEPage parent; | ||
3692 | 45 | |||
3693 | 46 | NMSettingIPConfig *setting; | ||
3694 | 47 | |||
3695 | 48 | GtkToggleButton *disabled; | ||
3696 | 49 | GtkWidget *address_list; | ||
3697 | 50 | GtkSwitch *auto_dns; | ||
3698 | 51 | GtkWidget *dns_entry; | ||
3699 | 52 | GtkSwitch *auto_routes; | ||
3700 | 53 | GtkWidget *routes_list; | ||
3701 | 54 | GtkWidget *never_default; | ||
3702 | 55 | }; | ||
3703 | 56 | |||
3704 | 57 | struct _CEPageIP4Class | ||
3705 | 58 | { | ||
3706 | 59 | CEPageClass parent_class; | ||
3707 | 60 | }; | ||
3708 | 61 | |||
3709 | 62 | GType ce_page_ip4_get_type (void); | ||
3710 | 63 | |||
3711 | 64 | CEPage *ce_page_ip4_new (NMConnection *connection, | ||
3712 | 65 | NMClient *client); | ||
3713 | 66 | |||
3714 | 67 | G_END_DECLS | ||
3715 | 68 | |||
3716 | 69 | #endif /* __CE_PAGE_IP4_H */ | ||
3717 | 70 | |||
3718 | 0 | 71 | ||
3719 | === added file 'panels/network/connection-editor/ce-page-ip6.c' | |||
3720 | --- panels/network/connection-editor/ce-page-ip6.c 1970-01-01 00:00:00 +0000 | |||
3721 | +++ panels/network/connection-editor/ce-page-ip6.c 2019-05-01 13:56:52 +0000 | |||
3722 | @@ -0,0 +1,838 @@ | |||
3723 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
3724 | 2 | * | ||
3725 | 3 | * Copyright (C) 2012 Red Hat, Inc | ||
3726 | 4 | * | ||
3727 | 5 | * Licensed under the GNU General Public License Version 2 | ||
3728 | 6 | * | ||
3729 | 7 | * This program is free software; you can redistribute it and/or modify | ||
3730 | 8 | * it under the terms of the GNU General Public License as published by | ||
3731 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
3732 | 10 | * (at your option) any later version. | ||
3733 | 11 | * | ||
3734 | 12 | * This program is distributed in the hope that it will be useful, | ||
3735 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3736 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3737 | 15 | * GNU General Public License for more details. | ||
3738 | 16 | * | ||
3739 | 17 | * You should have received a copy of the GNU General Public License | ||
3740 | 18 | * along with this program; if not, write to the Free Software | ||
3741 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
3742 | 20 | */ | ||
3743 | 21 | |||
3744 | 22 | #include "config.h" | ||
3745 | 23 | |||
3746 | 24 | #include <errno.h> | ||
3747 | 25 | #include <stdlib.h> | ||
3748 | 26 | #include <arpa/inet.h> | ||
3749 | 27 | #include <glib-object.h> | ||
3750 | 28 | #include <glib/gi18n.h> | ||
3751 | 29 | #include <NetworkManager.h> | ||
3752 | 30 | |||
3753 | 31 | #include "shell/list-box-helper.h" | ||
3754 | 32 | #include "ce-page-ip6.h" | ||
3755 | 33 | #include "ui-helpers.h" | ||
3756 | 34 | |||
3757 | 35 | #define RADIO_IS_ACTIVE(x) (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object(CE_PAGE (page)->builder, x)))) | ||
3758 | 36 | |||
3759 | 37 | static void ensure_empty_address_row (CEPageIP6 *page); | ||
3760 | 38 | static void ensure_empty_routes_row (CEPageIP6 *page); | ||
3761 | 39 | |||
3762 | 40 | G_DEFINE_TYPE (CEPageIP6, ce_page_ip6, CE_TYPE_PAGE) | ||
3763 | 41 | |||
3764 | 42 | enum { | ||
3765 | 43 | METHOD_COL_NAME, | ||
3766 | 44 | METHOD_COL_METHOD | ||
3767 | 45 | }; | ||
3768 | 46 | |||
3769 | 47 | enum { | ||
3770 | 48 | IP6_METHOD_AUTO, | ||
3771 | 49 | IP6_METHOD_DHCP, | ||
3772 | 50 | IP6_METHOD_MANUAL, | ||
3773 | 51 | IP6_METHOD_LINK_LOCAL, | ||
3774 | 52 | IP6_METHOD_SHARED, | ||
3775 | 53 | IP6_METHOD_IGNORE | ||
3776 | 54 | }; | ||
3777 | 55 | |||
3778 | 56 | static void | ||
3779 | 57 | method_changed (GtkToggleButton *button, CEPageIP6 *page) | ||
3780 | 58 | { | ||
3781 | 59 | gboolean addr_enabled; | ||
3782 | 60 | gboolean dns_enabled; | ||
3783 | 61 | gboolean routes_enabled; | ||
3784 | 62 | GtkWidget *widget; | ||
3785 | 63 | |||
3786 | 64 | if (RADIO_IS_ACTIVE ("radio_disabled")) { | ||
3787 | 65 | addr_enabled = FALSE; | ||
3788 | 66 | dns_enabled = FALSE; | ||
3789 | 67 | routes_enabled = FALSE; | ||
3790 | 68 | } else { | ||
3791 | 69 | addr_enabled = RADIO_IS_ACTIVE ("radio_manual"); | ||
3792 | 70 | dns_enabled = !RADIO_IS_ACTIVE ("radio_local"); | ||
3793 | 71 | routes_enabled = !RADIO_IS_ACTIVE ("radio_local"); | ||
3794 | 72 | } | ||
3795 | 73 | |||
3796 | 74 | widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section")); | ||
3797 | 75 | gtk_widget_set_visible (widget, addr_enabled); | ||
3798 | 76 | gtk_widget_set_sensitive (page->dns_entry, dns_enabled); | ||
3799 | 77 | gtk_widget_set_sensitive (page->routes_list, routes_enabled); | ||
3800 | 78 | gtk_widget_set_sensitive (page->never_default, routes_enabled); | ||
3801 | 79 | |||
3802 | 80 | ce_page_changed (CE_PAGE (page)); | ||
3803 | 81 | } | ||
3804 | 82 | |||
3805 | 83 | static void | ||
3806 | 84 | switch_toggled (GObject *object, | ||
3807 | 85 | GParamSpec *pspec, | ||
3808 | 86 | CEPage *page) | ||
3809 | 87 | { | ||
3810 | 88 | ce_page_changed (page); | ||
3811 | 89 | } | ||
3812 | 90 | |||
3813 | 91 | static void | ||
3814 | 92 | update_row_sensitivity (CEPageIP6 *page, GtkWidget *list) | ||
3815 | 93 | { | ||
3816 | 94 | GList *children, *l; | ||
3817 | 95 | gint rows = 0, i = 0; | ||
3818 | 96 | |||
3819 | 97 | children = gtk_container_get_children (GTK_CONTAINER (list)); | ||
3820 | 98 | for (l = children; l; l = l->next) { | ||
3821 | 99 | GtkWidget *row = l->data; | ||
3822 | 100 | GtkWidget *button; | ||
3823 | 101 | |||
3824 | 102 | button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "delete-button")); | ||
3825 | 103 | if (button != NULL) | ||
3826 | 104 | rows++; | ||
3827 | 105 | } | ||
3828 | 106 | for (l = children; l; l = l->next) { | ||
3829 | 107 | GtkWidget *row = l->data; | ||
3830 | 108 | GtkWidget *button; | ||
3831 | 109 | |||
3832 | 110 | button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "delete-button")); | ||
3833 | 111 | if (button != NULL) | ||
3834 | 112 | gtk_widget_set_sensitive (button, rows > 1 && ++i < rows); | ||
3835 | 113 | } | ||
3836 | 114 | g_list_free (children); | ||
3837 | 115 | } | ||
3838 | 116 | |||
3839 | 117 | static void | ||
3840 | 118 | remove_row (GtkButton *button, CEPageIP6 *page) | ||
3841 | 119 | { | ||
3842 | 120 | GtkWidget *row; | ||
3843 | 121 | GtkWidget *row_box; | ||
3844 | 122 | GtkWidget *list; | ||
3845 | 123 | |||
3846 | 124 | row_box = gtk_widget_get_parent (GTK_WIDGET (button)); | ||
3847 | 125 | row = gtk_widget_get_parent (row_box); | ||
3848 | 126 | list = gtk_widget_get_parent (row); | ||
3849 | 127 | |||
3850 | 128 | gtk_container_remove (GTK_CONTAINER (list), row); | ||
3851 | 129 | |||
3852 | 130 | ce_page_changed (CE_PAGE (page)); | ||
3853 | 131 | |||
3854 | 132 | update_row_sensitivity (page, list); | ||
3855 | 133 | } | ||
3856 | 134 | |||
3857 | 135 | static gboolean | ||
3858 | 136 | validate_row (GtkWidget *row) | ||
3859 | 137 | { | ||
3860 | 138 | GtkWidget *box; | ||
3861 | 139 | GList *children, *l; | ||
3862 | 140 | gboolean valid; | ||
3863 | 141 | |||
3864 | 142 | valid = FALSE; | ||
3865 | 143 | box = gtk_bin_get_child (GTK_BIN (row)); | ||
3866 | 144 | children = gtk_container_get_children (GTK_CONTAINER (box)); | ||
3867 | 145 | |||
3868 | 146 | for (l = children; l != NULL; l = l->next) { | ||
3869 | 147 | if (!GTK_IS_ENTRY (l->data)) | ||
3870 | 148 | continue; | ||
3871 | 149 | |||
3872 | 150 | valid = valid || gtk_entry_get_text_length (l->data) > 0; | ||
3873 | 151 | } | ||
3874 | 152 | |||
3875 | 153 | g_list_free (children); | ||
3876 | 154 | |||
3877 | 155 | return valid; | ||
3878 | 156 | } | ||
3879 | 157 | |||
3880 | 158 | static gint | ||
3881 | 159 | sort_first_last (gconstpointer a, gconstpointer b, gpointer data) | ||
3882 | 160 | { | ||
3883 | 161 | gboolean afirst, bfirst, alast, blast; | ||
3884 | 162 | |||
3885 | 163 | afirst = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (a), "first")); | ||
3886 | 164 | bfirst = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (b), "first")); | ||
3887 | 165 | alast = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (a), "last")); | ||
3888 | 166 | blast = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (b), "last")); | ||
3889 | 167 | |||
3890 | 168 | if (afirst) | ||
3891 | 169 | return -1; | ||
3892 | 170 | if (bfirst) | ||
3893 | 171 | return 1; | ||
3894 | 172 | if (alast) | ||
3895 | 173 | return 1; | ||
3896 | 174 | if (blast) | ||
3897 | 175 | return -1; | ||
3898 | 176 | |||
3899 | 177 | return 0; | ||
3900 | 178 | } | ||
3901 | 179 | |||
3902 | 180 | static void | ||
3903 | 181 | add_address_row (CEPageIP6 *page, | ||
3904 | 182 | const gchar *address, | ||
3905 | 183 | const gchar *network, | ||
3906 | 184 | const gchar *gateway) | ||
3907 | 185 | { | ||
3908 | 186 | GtkSizeGroup *group; | ||
3909 | 187 | GtkWidget *row; | ||
3910 | 188 | GtkWidget *row_box; | ||
3911 | 189 | GtkWidget *widget; | ||
3912 | 190 | GtkWidget *delete_button; | ||
3913 | 191 | GtkWidget *image; | ||
3914 | 192 | |||
3915 | 193 | row = gtk_list_box_row_new (); | ||
3916 | 194 | |||
3917 | 195 | row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); | ||
3918 | 196 | gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked"); | ||
3919 | 197 | |||
3920 | 198 | widget = gtk_entry_new (); | ||
3921 | 199 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
3922 | 200 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page); | ||
3923 | 201 | g_object_set_data (G_OBJECT (row), "address", widget); | ||
3924 | 202 | gtk_entry_set_text (GTK_ENTRY (widget), address); | ||
3925 | 203 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 16); | ||
3926 | 204 | gtk_widget_set_hexpand (widget, TRUE); | ||
3927 | 205 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
3928 | 206 | |||
3929 | 207 | widget = gtk_entry_new (); | ||
3930 | 208 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
3931 | 209 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page); | ||
3932 | 210 | g_object_set_data (G_OBJECT (row), "prefix", widget); | ||
3933 | 211 | gtk_entry_set_text (GTK_ENTRY (widget), network); | ||
3934 | 212 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 16); | ||
3935 | 213 | gtk_widget_set_hexpand (widget, TRUE); | ||
3936 | 214 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
3937 | 215 | |||
3938 | 216 | widget = gtk_entry_new (); | ||
3939 | 217 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
3940 | 218 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page); | ||
3941 | 219 | g_object_set_data (G_OBJECT (row), "gateway", widget); | ||
3942 | 220 | gtk_entry_set_text (GTK_ENTRY (widget), gateway ? gateway : ""); | ||
3943 | 221 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 16); | ||
3944 | 222 | gtk_widget_set_hexpand (widget, TRUE); | ||
3945 | 223 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
3946 | 224 | |||
3947 | 225 | delete_button = gtk_button_new (); | ||
3948 | 226 | gtk_widget_set_sensitive (delete_button, FALSE); | ||
3949 | 227 | gtk_style_context_add_class (gtk_widget_get_style_context (delete_button), "image-button"); | ||
3950 | 228 | g_signal_connect (delete_button, "clicked", G_CALLBACK (remove_row), page); | ||
3951 | 229 | image = gtk_image_new_from_icon_name ("edit-delete-symbolic", GTK_ICON_SIZE_MENU); | ||
3952 | 230 | atk_object_set_name (gtk_widget_get_accessible (delete_button), _("Delete Address")); | ||
3953 | 231 | gtk_button_set_image (GTK_BUTTON (delete_button), image); | ||
3954 | 232 | gtk_container_add (GTK_CONTAINER (row_box), delete_button); | ||
3955 | 233 | g_object_set_data (G_OBJECT (row), "delete-button", delete_button); | ||
3956 | 234 | |||
3957 | 235 | group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "address_sizegroup")); | ||
3958 | 236 | gtk_size_group_add_widget (group, delete_button); | ||
3959 | 237 | |||
3960 | 238 | gtk_container_add (GTK_CONTAINER (row), row_box); | ||
3961 | 239 | gtk_widget_show_all (row); | ||
3962 | 240 | gtk_container_add (GTK_CONTAINER (page->address_list), row); | ||
3963 | 241 | |||
3964 | 242 | update_row_sensitivity (page, page->address_list); | ||
3965 | 243 | } | ||
3966 | 244 | |||
3967 | 245 | static void | ||
3968 | 246 | ensure_empty_address_row (CEPageIP6 *page) | ||
3969 | 247 | { | ||
3970 | 248 | GList *children, *l; | ||
3971 | 249 | |||
3972 | 250 | children = gtk_container_get_children (GTK_CONTAINER (page->address_list)); | ||
3973 | 251 | l = children; | ||
3974 | 252 | |||
3975 | 253 | while (l && l->next) | ||
3976 | 254 | l = l->next; | ||
3977 | 255 | |||
3978 | 256 | /* Add the last, stub row if needed*/ | ||
3979 | 257 | if (!l || validate_row (l->data)) | ||
3980 | 258 | add_address_row (page, "", "", ""); | ||
3981 | 259 | |||
3982 | 260 | g_list_free (children); | ||
3983 | 261 | } | ||
3984 | 262 | |||
3985 | 263 | static void | ||
3986 | 264 | add_address_section (CEPageIP6 *page) | ||
3987 | 265 | { | ||
3988 | 266 | GtkWidget *widget; | ||
3989 | 267 | GtkWidget *list; | ||
3990 | 268 | gint i; | ||
3991 | 269 | |||
3992 | 270 | widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section")); | ||
3993 | 271 | |||
3994 | 272 | page->address_list = list = gtk_list_box_new (); | ||
3995 | 273 | gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE); | ||
3996 | 274 | gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL); | ||
3997 | 275 | gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL); | ||
3998 | 276 | gtk_container_add (GTK_CONTAINER (widget), list); | ||
3999 | 277 | |||
4000 | 278 | for (i = 0; i < nm_setting_ip_config_get_num_addresses (page->setting); i++) { | ||
4001 | 279 | NMIPAddress *addr; | ||
4002 | 280 | char *netmask; | ||
4003 | 281 | |||
4004 | 282 | addr = nm_setting_ip_config_get_address (page->setting, i); | ||
4005 | 283 | netmask = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr)); | ||
4006 | 284 | add_address_row (page, nm_ip_address_get_address (addr), netmask, | ||
4007 | 285 | i == 0 ? nm_setting_ip_config_get_gateway (page->setting) : NULL); | ||
4008 | 286 | g_free (netmask); | ||
4009 | 287 | } | ||
4010 | 288 | if (nm_setting_ip_config_get_num_addresses (page->setting) == 0) | ||
4011 | 289 | ensure_empty_address_row (page); | ||
4012 | 290 | |||
4013 | 291 | gtk_widget_show_all (widget); | ||
4014 | 292 | } | ||
4015 | 293 | |||
4016 | 294 | static void | ||
4017 | 295 | add_dns_section (CEPageIP6 *page) | ||
4018 | 296 | { | ||
4019 | 297 | GtkEntry *entry; | ||
4020 | 298 | GString *string; | ||
4021 | 299 | gint i; | ||
4022 | 300 | |||
4023 | 301 | page->auto_dns = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_dns_switch")); | ||
4024 | 302 | gtk_switch_set_active (page->auto_dns, !nm_setting_ip_config_get_ignore_auto_dns (page->setting)); | ||
4025 | 303 | g_signal_connect (page->auto_dns, "notify::active", G_CALLBACK (switch_toggled), page); | ||
4026 | 304 | |||
4027 | 305 | page->dns_entry = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "dns_entry")); | ||
4028 | 306 | entry = GTK_ENTRY (page->dns_entry); | ||
4029 | 307 | string = g_string_new (""); | ||
4030 | 308 | |||
4031 | 309 | for (i = 0; i < nm_setting_ip_config_get_num_dns (page->setting); i++) { | ||
4032 | 310 | const char *address; | ||
4033 | 311 | |||
4034 | 312 | address = nm_setting_ip_config_get_dns (page->setting, i); | ||
4035 | 313 | |||
4036 | 314 | if (i > 0) | ||
4037 | 315 | g_string_append (string, ", "); | ||
4038 | 316 | |||
4039 | 317 | g_string_append (string, address); | ||
4040 | 318 | |||
4041 | 319 | } | ||
4042 | 320 | |||
4043 | 321 | gtk_entry_set_text (entry, string->str); | ||
4044 | 322 | |||
4045 | 323 | g_signal_connect_swapped (page->dns_entry, "notify::text", G_CALLBACK (ce_page_changed), page); | ||
4046 | 324 | |||
4047 | 325 | g_string_free (string, TRUE); | ||
4048 | 326 | } | ||
4049 | 327 | |||
4050 | 328 | static void | ||
4051 | 329 | add_route_row (CEPageIP6 *page, | ||
4052 | 330 | const gchar *address, | ||
4053 | 331 | const gchar *prefix, | ||
4054 | 332 | const gchar *gateway, | ||
4055 | 333 | const gchar *metric) | ||
4056 | 334 | { | ||
4057 | 335 | GtkSizeGroup *group; | ||
4058 | 336 | GtkWidget *row; | ||
4059 | 337 | GtkWidget *row_box; | ||
4060 | 338 | GtkWidget *widget; | ||
4061 | 339 | GtkWidget *delete_button; | ||
4062 | 340 | GtkWidget *image; | ||
4063 | 341 | |||
4064 | 342 | row = gtk_list_box_row_new (); | ||
4065 | 343 | |||
4066 | 344 | row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); | ||
4067 | 345 | gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked"); | ||
4068 | 346 | |||
4069 | 347 | widget = gtk_entry_new (); | ||
4070 | 348 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
4071 | 349 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page); | ||
4072 | 350 | g_object_set_data (G_OBJECT (row), "address", widget); | ||
4073 | 351 | gtk_entry_set_text (GTK_ENTRY (widget), address); | ||
4074 | 352 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 16); | ||
4075 | 353 | gtk_widget_set_hexpand (widget, TRUE); | ||
4076 | 354 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
4077 | 355 | |||
4078 | 356 | widget = gtk_entry_new (); | ||
4079 | 357 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
4080 | 358 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page); | ||
4081 | 359 | g_object_set_data (G_OBJECT (row), "prefix", widget); | ||
4082 | 360 | gtk_entry_set_text (GTK_ENTRY (widget), prefix ? prefix : ""); | ||
4083 | 361 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 16); | ||
4084 | 362 | gtk_widget_set_hexpand (widget, TRUE); | ||
4085 | 363 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
4086 | 364 | |||
4087 | 365 | widget = gtk_entry_new (); | ||
4088 | 366 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
4089 | 367 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page); | ||
4090 | 368 | g_object_set_data (G_OBJECT (row), "gateway", widget); | ||
4091 | 369 | gtk_entry_set_text (GTK_ENTRY (widget), gateway); | ||
4092 | 370 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 16); | ||
4093 | 371 | gtk_widget_set_hexpand (widget, TRUE); | ||
4094 | 372 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
4095 | 373 | |||
4096 | 374 | widget = gtk_entry_new (); | ||
4097 | 375 | g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); | ||
4098 | 376 | g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page); | ||
4099 | 377 | g_object_set_data (G_OBJECT (row), "metric", widget); | ||
4100 | 378 | gtk_entry_set_text (GTK_ENTRY (widget), metric ? metric : ""); | ||
4101 | 379 | gtk_entry_set_width_chars (GTK_ENTRY (widget), 5); | ||
4102 | 380 | gtk_widget_set_hexpand (widget, TRUE); | ||
4103 | 381 | gtk_container_add (GTK_CONTAINER (row_box), widget); | ||
4104 | 382 | |||
4105 | 383 | group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_metric_sizegroup")); | ||
4106 | 384 | gtk_size_group_add_widget (group, widget); | ||
4107 | 385 | |||
4108 | 386 | delete_button = gtk_button_new (); | ||
4109 | 387 | gtk_style_context_add_class (gtk_widget_get_style_context (delete_button), "image-button"); | ||
4110 | 388 | g_signal_connect (delete_button, "clicked", G_CALLBACK (remove_row), page); | ||
4111 | 389 | image = gtk_image_new_from_icon_name ("edit-delete-symbolic", GTK_ICON_SIZE_MENU); | ||
4112 | 390 | atk_object_set_name (gtk_widget_get_accessible (delete_button), _("Delete Route")); | ||
4113 | 391 | gtk_button_set_image (GTK_BUTTON (delete_button), image); | ||
4114 | 392 | gtk_widget_set_halign (delete_button, GTK_ALIGN_CENTER); | ||
4115 | 393 | gtk_widget_set_valign (delete_button, GTK_ALIGN_CENTER); | ||
4116 | 394 | gtk_container_add (GTK_CONTAINER (row_box), delete_button); | ||
4117 | 395 | g_object_set_data (G_OBJECT (row), "delete-button", delete_button); | ||
4118 | 396 | |||
4119 | 397 | group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_sizegroup")); | ||
4120 | 398 | gtk_size_group_add_widget (group, delete_button); | ||
4121 | 399 | |||
4122 | 400 | gtk_container_add (GTK_CONTAINER (row), row_box); | ||
4123 | 401 | gtk_widget_show_all (row); | ||
4124 | 402 | gtk_container_add (GTK_CONTAINER (page->routes_list), row); | ||
4125 | 403 | |||
4126 | 404 | update_row_sensitivity (page, page->routes_list); | ||
4127 | 405 | } | ||
4128 | 406 | |||
4129 | 407 | static void | ||
4130 | 408 | ensure_empty_routes_row (CEPageIP6 *page) | ||
4131 | 409 | { | ||
4132 | 410 | GList *children, *l; | ||
4133 | 411 | |||
4134 | 412 | children = gtk_container_get_children (GTK_CONTAINER (page->routes_list)); | ||
4135 | 413 | l = children; | ||
4136 | 414 | |||
4137 | 415 | while (l && l->next) | ||
4138 | 416 | l = l->next; | ||
4139 | 417 | |||
4140 | 418 | /* Add the last, stub row if needed*/ | ||
4141 | 419 | if (!l || validate_row (l->data)) | ||
4142 | 420 | add_route_row (page, "", NULL, "", NULL); | ||
4143 | 421 | |||
4144 | 422 | g_list_free (children); | ||
4145 | 423 | } | ||
4146 | 424 | |||
4147 | 425 | static void | ||
4148 | 426 | add_empty_route_row (CEPageIP6 *page) | ||
4149 | 427 | { | ||
4150 | 428 | add_route_row (page, "", NULL, "", NULL); | ||
4151 | 429 | } | ||
4152 | 430 | |||
4153 | 431 | static void | ||
4154 | 432 | add_routes_section (CEPageIP6 *page) | ||
4155 | 433 | { | ||
4156 | 434 | GtkWidget *widget; | ||
4157 | 435 | GtkWidget *list; | ||
4158 | 436 | gint i; | ||
4159 | 437 | |||
4160 | 438 | widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_section")); | ||
4161 | 439 | |||
4162 | 440 | page->routes_list = list = gtk_list_box_new (); | ||
4163 | 441 | gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE); | ||
4164 | 442 | gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL); | ||
4165 | 443 | gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL); | ||
4166 | 444 | gtk_container_add (GTK_CONTAINER (widget), list); | ||
4167 | 445 | page->auto_routes = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_routes_switch")); | ||
4168 | 446 | gtk_switch_set_active (page->auto_routes, !nm_setting_ip_config_get_ignore_auto_routes (page->setting)); | ||
4169 | 447 | g_signal_connect (page->auto_routes, "notify::active", G_CALLBACK (switch_toggled), page); | ||
4170 | 448 | |||
4171 | 449 | for (i = 0; i < nm_setting_ip_config_get_num_routes (page->setting); i++) { | ||
4172 | 450 | NMIPRoute *route; | ||
4173 | 451 | char *prefix, *metric; | ||
4174 | 452 | |||
4175 | 453 | route = nm_setting_ip_config_get_route (page->setting, i); | ||
4176 | 454 | prefix = g_strdup_printf ("%u", nm_ip_route_get_prefix (route)); | ||
4177 | 455 | metric = g_strdup_printf ("%u", (guint32) MIN (0, nm_ip_route_get_metric (route))); | ||
4178 | 456 | add_route_row (page, nm_ip_route_get_dest (route), | ||
4179 | 457 | prefix, | ||
4180 | 458 | nm_ip_route_get_next_hop (route), | ||
4181 | 459 | metric); | ||
4182 | 460 | g_free (prefix); | ||
4183 | 461 | g_free (metric); | ||
4184 | 462 | } | ||
4185 | 463 | if (nm_setting_ip_config_get_num_routes (page->setting) == 0) | ||
4186 | 464 | add_empty_route_row (page); | ||
4187 | 465 | |||
4188 | 466 | gtk_widget_show_all (widget); | ||
4189 | 467 | } | ||
4190 | 468 | |||
4191 | 469 | enum | ||
4192 | 470 | { | ||
4193 | 471 | RADIO_AUTOMATIC, | ||
4194 | 472 | RADIO_DHCP, | ||
4195 | 473 | RADIO_LOCAL, | ||
4196 | 474 | RADIO_MANUAL, | ||
4197 | 475 | RADIO_DISABLED, | ||
4198 | 476 | N_RADIO | ||
4199 | 477 | }; | ||
4200 | 478 | |||
4201 | 479 | static void | ||
4202 | 480 | connect_ip6_page (CEPageIP6 *page) | ||
4203 | 481 | { | ||
4204 | 482 | GtkToggleButton *radios[N_RADIO]; | ||
4205 | 483 | GtkWidget *content; | ||
4206 | 484 | const gchar *str_method; | ||
4207 | 485 | gboolean disabled; | ||
4208 | 486 | guint method, i; | ||
4209 | 487 | |||
4210 | 488 | add_address_section (page); | ||
4211 | 489 | add_dns_section (page); | ||
4212 | 490 | add_routes_section (page); | ||
4213 | 491 | |||
4214 | 492 | page->disabled = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_disabled")); | ||
4215 | 493 | |||
4216 | 494 | str_method = nm_setting_ip_config_get_method (page->setting); | ||
4217 | 495 | disabled = g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0; | ||
4218 | 496 | gtk_toggle_button_set_active (page->disabled, disabled); | ||
4219 | 497 | g_signal_connect_swapped (page->disabled, "notify::active", G_CALLBACK (ce_page_changed), page); | ||
4220 | 498 | content = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "page_content")); | ||
4221 | 499 | g_object_bind_property (page->disabled, "active", | ||
4222 | 500 | content, "sensitive", | ||
4223 | 501 | G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN); | ||
4224 | 502 | |||
4225 | 503 | method = IP6_METHOD_AUTO; | ||
4226 | 504 | if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) { | ||
4227 | 505 | method = IP6_METHOD_DHCP; | ||
4228 | 506 | } else if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0) { | ||
4229 | 507 | method = IP6_METHOD_LINK_LOCAL; | ||
4230 | 508 | } else if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0) { | ||
4231 | 509 | method = IP6_METHOD_MANUAL; | ||
4232 | 510 | } else if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0) { | ||
4233 | 511 | method = IP6_METHOD_SHARED; | ||
4234 | 512 | } else if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0) { | ||
4235 | 513 | method = IP6_METHOD_IGNORE; | ||
4236 | 514 | } | ||
4237 | 515 | |||
4238 | 516 | page->never_default = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "never_default_check")); | ||
4239 | 517 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->never_default), | ||
4240 | 518 | nm_setting_ip_config_get_never_default (page->setting)); | ||
4241 | 519 | g_signal_connect_swapped (page->never_default, "toggled", G_CALLBACK (ce_page_changed), page); | ||
4242 | 520 | |||
4243 | 521 | |||
4244 | 522 | /* Connect radio buttons */ | ||
4245 | 523 | radios[RADIO_AUTOMATIC] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_automatic")); | ||
4246 | 524 | radios[RADIO_DHCP] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_dhcp")); | ||
4247 | 525 | radios[RADIO_LOCAL] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_local")); | ||
4248 | 526 | radios[RADIO_MANUAL] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_manual")); | ||
4249 | 527 | radios[RADIO_DISABLED] = page->disabled; | ||
4250 | 528 | |||
4251 | 529 | for (i = RADIO_AUTOMATIC; i < RADIO_DISABLED; i++) | ||
4252 | 530 | g_signal_connect (radios[i], "toggled", G_CALLBACK (method_changed), page); | ||
4253 | 531 | |||
4254 | 532 | switch (method) { | ||
4255 | 533 | case IP6_METHOD_AUTO: | ||
4256 | 534 | gtk_toggle_button_set_active (radios[RADIO_AUTOMATIC], TRUE); | ||
4257 | 535 | break; | ||
4258 | 536 | case IP6_METHOD_DHCP: | ||
4259 | 537 | gtk_toggle_button_set_active (radios[RADIO_DHCP], TRUE); | ||
4260 | 538 | break; | ||
4261 | 539 | case IP6_METHOD_LINK_LOCAL: | ||
4262 | 540 | gtk_toggle_button_set_active (radios[RADIO_LOCAL], TRUE); | ||
4263 | 541 | break; | ||
4264 | 542 | case IP6_METHOD_MANUAL: | ||
4265 | 543 | gtk_toggle_button_set_active (radios[RADIO_MANUAL], TRUE); | ||
4266 | 544 | break; | ||
4267 | 545 | case IP6_METHOD_IGNORE: | ||
4268 | 546 | gtk_toggle_button_set_active (radios[RADIO_DISABLED], TRUE); | ||
4269 | 547 | break; | ||
4270 | 548 | default: | ||
4271 | 549 | break; | ||
4272 | 550 | } | ||
4273 | 551 | |||
4274 | 552 | method_changed (NULL, page); | ||
4275 | 553 | } | ||
4276 | 554 | |||
4277 | 555 | static gboolean | ||
4278 | 556 | ui_to_setting (CEPageIP6 *page) | ||
4279 | 557 | { | ||
4280 | 558 | const gchar *method; | ||
4281 | 559 | gboolean ignore_auto_dns; | ||
4282 | 560 | gboolean ignore_auto_routes; | ||
4283 | 561 | gboolean never_default; | ||
4284 | 562 | GList *children, *l; | ||
4285 | 563 | gboolean ret = TRUE; | ||
4286 | 564 | GStrv dns_addresses = NULL; | ||
4287 | 565 | gchar *dns_text = NULL; | ||
4288 | 566 | guint i; | ||
4289 | 567 | |||
4290 | 568 | if (gtk_toggle_button_get_active (page->disabled)) { | ||
4291 | 569 | method = NM_SETTING_IP6_CONFIG_METHOD_IGNORE; | ||
4292 | 570 | } else { | ||
4293 | 571 | if (RADIO_IS_ACTIVE ("radio_manual")) { | ||
4294 | 572 | method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; | ||
4295 | 573 | } else if (RADIO_IS_ACTIVE ("radio_local")) { | ||
4296 | 574 | method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL; | ||
4297 | 575 | } else if (RADIO_IS_ACTIVE ("radio_dhcp")) { | ||
4298 | 576 | method = NM_SETTING_IP6_CONFIG_METHOD_DHCP; | ||
4299 | 577 | } else if (RADIO_IS_ACTIVE ("radio_automatic")) { | ||
4300 | 578 | method = NM_SETTING_IP6_CONFIG_METHOD_AUTO; | ||
4301 | 579 | } | ||
4302 | 580 | } | ||
4303 | 581 | |||
4304 | 582 | nm_setting_ip_config_clear_addresses (page->setting); | ||
4305 | 583 | if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { | ||
4306 | 584 | children = gtk_container_get_children (GTK_CONTAINER (page->address_list)); | ||
4307 | 585 | } else { | ||
4308 | 586 | g_object_set (G_OBJECT (page->setting), | ||
4309 | 587 | NM_SETTING_IP_CONFIG_GATEWAY, NULL, | ||
4310 | 588 | NULL); | ||
4311 | 589 | children = NULL; | ||
4312 | 590 | } | ||
4313 | 591 | |||
4314 | 592 | for (l = children; l; l = l->next) { | ||
4315 | 593 | GtkWidget *row = l->data; | ||
4316 | 594 | GtkEntry *entry; | ||
4317 | 595 | const gchar *text_address; | ||
4318 | 596 | const gchar *text_prefix; | ||
4319 | 597 | const gchar *text_gateway; | ||
4320 | 598 | guint32 prefix; | ||
4321 | 599 | gchar *end; | ||
4322 | 600 | NMIPAddress *addr; | ||
4323 | 601 | gboolean have_gateway = FALSE; | ||
4324 | 602 | |||
4325 | 603 | entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address")); | ||
4326 | 604 | if (!entry) | ||
4327 | 605 | continue; | ||
4328 | 606 | |||
4329 | 607 | text_address = gtk_entry_get_text (entry); | ||
4330 | 608 | text_prefix = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "prefix"))); | ||
4331 | 609 | text_gateway = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "gateway"))); | ||
4332 | 610 | |||
4333 | 611 | if (!*text_address && !*text_prefix && !*text_gateway) { | ||
4334 | 612 | /* ignore empty rows */ | ||
4335 | 613 | widget_unset_error (GTK_WIDGET (entry)); | ||
4336 | 614 | widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix")); | ||
4337 | 615 | widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway")); | ||
4338 | 616 | continue; | ||
4339 | 617 | } | ||
4340 | 618 | |||
4341 | 619 | if (!text_address || !nm_utils_ipaddr_valid (AF_INET6, text_address)) { | ||
4342 | 620 | widget_set_error (GTK_WIDGET (entry)); | ||
4343 | 621 | ret = FALSE; | ||
4344 | 622 | } else { | ||
4345 | 623 | widget_unset_error (GTK_WIDGET (entry)); | ||
4346 | 624 | } | ||
4347 | 625 | |||
4348 | 626 | prefix = strtoul (text_prefix, &end, 10); | ||
4349 | 627 | if (!end || *end || prefix == 0 || prefix > 128) { | ||
4350 | 628 | widget_set_error (g_object_get_data (G_OBJECT (row), "prefix")); | ||
4351 | 629 | ret = FALSE; | ||
4352 | 630 | } else { | ||
4353 | 631 | widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix")); | ||
4354 | 632 | } | ||
4355 | 633 | |||
4356 | 634 | if (text_gateway && !nm_utils_ipaddr_valid (AF_INET6, text_gateway)) { | ||
4357 | 635 | widget_set_error (g_object_get_data (G_OBJECT (row), "gateway")); | ||
4358 | 636 | ret = FALSE; | ||
4359 | 637 | } else { | ||
4360 | 638 | widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway")); | ||
4361 | 639 | have_gateway = TRUE; | ||
4362 | 640 | } | ||
4363 | 641 | |||
4364 | 642 | if (!ret) | ||
4365 | 643 | continue; | ||
4366 | 644 | |||
4367 | 645 | addr = nm_ip_address_new (AF_INET6, text_address, prefix, NULL); | ||
4368 | 646 | if (have_gateway) | ||
4369 | 647 | g_object_set (G_OBJECT (page->setting), | ||
4370 | 648 | NM_SETTING_IP_CONFIG_GATEWAY, text_gateway, | ||
4371 | 649 | NULL); | ||
4372 | 650 | nm_setting_ip_config_add_address (page->setting, addr); | ||
4373 | 651 | |||
4374 | 652 | if (!l || !l->next) | ||
4375 | 653 | ensure_empty_address_row (page); | ||
4376 | 654 | } | ||
4377 | 655 | g_list_free (children); | ||
4378 | 656 | |||
4379 | 657 | nm_setting_ip_config_clear_dns (page->setting); | ||
4380 | 658 | dns_text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (page->dns_entry)))); | ||
4381 | 659 | |||
4382 | 660 | if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) || | ||
4383 | 661 | g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) || | ||
4384 | 662 | g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) | ||
4385 | 663 | dns_addresses = g_strsplit_set (dns_text, ", ", -1); | ||
4386 | 664 | else | ||
4387 | 665 | dns_addresses = NULL; | ||
4388 | 666 | |||
4389 | 667 | for (i = 0; dns_addresses && dns_addresses[i]; i++) { | ||
4390 | 668 | const gchar *text; | ||
4391 | 669 | struct in6_addr tmp_addr; | ||
4392 | 670 | |||
4393 | 671 | text = dns_addresses[i]; | ||
4394 | 672 | |||
4395 | 673 | if (!text || !*text) | ||
4396 | 674 | continue; | ||
4397 | 675 | |||
4398 | 676 | if (inet_pton (AF_INET6, text, &tmp_addr) <= 0) { | ||
4399 | 677 | g_clear_pointer (&dns_addresses, g_strfreev); | ||
4400 | 678 | widget_set_error (page->dns_entry); | ||
4401 | 679 | ret = FALSE; | ||
4402 | 680 | break; | ||
4403 | 681 | } else { | ||
4404 | 682 | widget_unset_error (page->dns_entry); | ||
4405 | 683 | nm_setting_ip_config_add_dns (page->setting, text); | ||
4406 | 684 | } | ||
4407 | 685 | } | ||
4408 | 686 | |||
4409 | 687 | nm_setting_ip_config_clear_routes (page->setting); | ||
4410 | 688 | if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) || | ||
4411 | 689 | g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) || | ||
4412 | 690 | g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) | ||
4413 | 691 | children = gtk_container_get_children (GTK_CONTAINER (page->routes_list)); | ||
4414 | 692 | else | ||
4415 | 693 | children = NULL; | ||
4416 | 694 | |||
4417 | 695 | for (l = children; l; l = l->next) { | ||
4418 | 696 | GtkWidget *row = l->data; | ||
4419 | 697 | GtkEntry *entry; | ||
4420 | 698 | const gchar *text_address; | ||
4421 | 699 | const gchar *text_prefix; | ||
4422 | 700 | const gchar *text_gateway; | ||
4423 | 701 | const gchar *text_metric; | ||
4424 | 702 | guint32 prefix, metric; | ||
4425 | 703 | gchar *end; | ||
4426 | 704 | NMIPRoute *route; | ||
4427 | 705 | |||
4428 | 706 | entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address")); | ||
4429 | 707 | if (!entry) | ||
4430 | 708 | continue; | ||
4431 | 709 | |||
4432 | 710 | text_address = gtk_entry_get_text (entry); | ||
4433 | 711 | text_prefix = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "prefix"))); | ||
4434 | 712 | text_gateway = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "gateway"))); | ||
4435 | 713 | text_metric = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "metric"))); | ||
4436 | 714 | |||
4437 | 715 | if (!*text_address && !*text_prefix && !*text_gateway && !*text_metric) { | ||
4438 | 716 | /* ignore empty rows */ | ||
4439 | 717 | widget_unset_error (GTK_WIDGET (entry)); | ||
4440 | 718 | widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix")); | ||
4441 | 719 | widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway")); | ||
4442 | 720 | widget_unset_error (g_object_get_data (G_OBJECT (row), "metric")); | ||
4443 | 721 | continue; | ||
4444 | 722 | } | ||
4445 | 723 | |||
4446 | 724 | if (!nm_utils_ipaddr_valid (AF_INET6, text_address)) { | ||
4447 | 725 | widget_set_error (GTK_WIDGET (entry)); | ||
4448 | 726 | ret = FALSE; | ||
4449 | 727 | } else { | ||
4450 | 728 | widget_unset_error (GTK_WIDGET (entry)); | ||
4451 | 729 | } | ||
4452 | 730 | |||
4453 | 731 | prefix = strtoul (text_prefix, &end, 10); | ||
4454 | 732 | if (!end || *end || prefix == 0 || prefix > 128) { | ||
4455 | 733 | widget_set_error (g_object_get_data (G_OBJECT (row), "prefix")); | ||
4456 | 734 | ret = FALSE; | ||
4457 | 735 | } else { | ||
4458 | 736 | widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix")); | ||
4459 | 737 | } | ||
4460 | 738 | |||
4461 | 739 | if (!nm_utils_ipaddr_valid (AF_INET6, text_gateway)) { | ||
4462 | 740 | widget_set_error (g_object_get_data (G_OBJECT (row), "gateway")); | ||
4463 | 741 | ret = FALSE; | ||
4464 | 742 | } else { | ||
4465 | 743 | widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway")); | ||
4466 | 744 | } | ||
4467 | 745 | |||
4468 | 746 | metric = 0; | ||
4469 | 747 | if (*text_metric) { | ||
4470 | 748 | errno = 0; | ||
4471 | 749 | metric = strtoul (text_metric, NULL, 10); | ||
4472 | 750 | if (errno) { | ||
4473 | 751 | widget_set_error (g_object_get_data (G_OBJECT (row), "metric")); | ||
4474 | 752 | ret = FALSE; | ||
4475 | 753 | } else { | ||
4476 | 754 | widget_unset_error (g_object_get_data (G_OBJECT (row), "metric")); | ||
4477 | 755 | } | ||
4478 | 756 | } else { | ||
4479 | 757 | widget_unset_error (g_object_get_data (G_OBJECT (row), "metric")); | ||
4480 | 758 | } | ||
4481 | 759 | |||
4482 | 760 | if (!ret) | ||
4483 | 761 | continue; | ||
4484 | 762 | |||
4485 | 763 | route = nm_ip_route_new (AF_INET6, text_address, prefix, text_gateway, metric, NULL); | ||
4486 | 764 | nm_setting_ip_config_add_route (page->setting, route); | ||
4487 | 765 | nm_ip_route_unref (route); | ||
4488 | 766 | |||
4489 | 767 | if (!l || !l->next) | ||
4490 | 768 | ensure_empty_routes_row (page); | ||
4491 | 769 | } | ||
4492 | 770 | g_list_free (children); | ||
4493 | 771 | |||
4494 | 772 | if (!ret) | ||
4495 | 773 | goto out; | ||
4496 | 774 | |||
4497 | 775 | ignore_auto_dns = !gtk_switch_get_active (page->auto_dns); | ||
4498 | 776 | ignore_auto_routes = !gtk_switch_get_active (page->auto_routes); | ||
4499 | 777 | never_default = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (page->never_default)); | ||
4500 | 778 | |||
4501 | 779 | g_object_set (page->setting, | ||
4502 | 780 | NM_SETTING_IP_CONFIG_METHOD, method, | ||
4503 | 781 | NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns, | ||
4504 | 782 | NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, ignore_auto_routes, | ||
4505 | 783 | NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, | ||
4506 | 784 | NULL); | ||
4507 | 785 | |||
4508 | 786 | out: | ||
4509 | 787 | g_clear_pointer (&dns_addresses, g_strfreev); | ||
4510 | 788 | g_clear_pointer (&dns_text, g_free); | ||
4511 | 789 | |||
4512 | 790 | return ret; | ||
4513 | 791 | } | ||
4514 | 792 | |||
4515 | 793 | static gboolean | ||
4516 | 794 | validate (CEPage *page, | ||
4517 | 795 | NMConnection *connection, | ||
4518 | 796 | GError **error) | ||
4519 | 797 | { | ||
4520 | 798 | if (!ui_to_setting (CE_PAGE_IP6 (page))) | ||
4521 | 799 | return FALSE; | ||
4522 | 800 | |||
4523 | 801 | return nm_setting_verify (NM_SETTING (CE_PAGE_IP6 (page)->setting), NULL, error); | ||
4524 | 802 | } | ||
4525 | 803 | |||
4526 | 804 | static void | ||
4527 | 805 | ce_page_ip6_init (CEPageIP6 *page) | ||
4528 | 806 | { | ||
4529 | 807 | } | ||
4530 | 808 | |||
4531 | 809 | static void | ||
4532 | 810 | ce_page_ip6_class_init (CEPageIP6Class *class) | ||
4533 | 811 | { | ||
4534 | 812 | CEPageClass *page_class= CE_PAGE_CLASS (class); | ||
4535 | 813 | |||
4536 | 814 | page_class->validate = validate; | ||
4537 | 815 | } | ||
4538 | 816 | |||
4539 | 817 | CEPage * | ||
4540 | 818 | ce_page_ip6_new (NMConnection *connection, | ||
4541 | 819 | NMClient *client) | ||
4542 | 820 | { | ||
4543 | 821 | CEPageIP6 *page; | ||
4544 | 822 | |||
4545 | 823 | page = CE_PAGE_IP6 (ce_page_new (CE_TYPE_PAGE_IP6, | ||
4546 | 824 | connection, | ||
4547 | 825 | client, | ||
4548 | 826 | "/org/gnome/control-center/network/ip6-page.ui", | ||
4549 | 827 | _("IPv6"))); | ||
4550 | 828 | |||
4551 | 829 | page->setting = nm_connection_get_setting_ip6_config (connection); | ||
4552 | 830 | if (!page->setting) { | ||
4553 | 831 | page->setting = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ()); | ||
4554 | 832 | nm_connection_add_setting (connection, NM_SETTING (page->setting)); | ||
4555 | 833 | } | ||
4556 | 834 | |||
4557 | 835 | connect_ip6_page (page); | ||
4558 | 836 | |||
4559 | 837 | return CE_PAGE (page); | ||
4560 | 838 | } | ||
4561 | 0 | 839 | ||
4562 | === added file 'panels/network/connection-editor/ce-page-ip6.h' | |||
4563 | --- panels/network/connection-editor/ce-page-ip6.h 1970-01-01 00:00:00 +0000 | |||
4564 | +++ panels/network/connection-editor/ce-page-ip6.h 2019-05-01 13:56:52 +0000 | |||
4565 | @@ -0,0 +1,70 @@ | |||
4566 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
4567 | 2 | * | ||
4568 | 3 | * Copyright (C) 2012 Red Hat, Inc. | ||
4569 | 4 | * | ||
4570 | 5 | * Licensed under the GNU General Public License Version 2 | ||
4571 | 6 | * | ||
4572 | 7 | * This program is free software; you can redistribute it and/or modify | ||
4573 | 8 | * it under the terms of the GNU General Public License as published by | ||
4574 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
4575 | 10 | * (at your option) any later version. | ||
4576 | 11 | * | ||
4577 | 12 | * This program is distributed in the hope that it will be useful, | ||
4578 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4579 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4580 | 15 | * GNU General Public License for more ip6. | ||
4581 | 16 | * | ||
4582 | 17 | * You should have received a copy of the GNU General Public License | ||
4583 | 18 | * along with this program; if not, write to the Free Software | ||
4584 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
4585 | 20 | */ | ||
4586 | 21 | |||
4587 | 22 | #ifndef __CE_PAGE_IP6_H | ||
4588 | 23 | #define __CE_PAGE_IP6_H | ||
4589 | 24 | |||
4590 | 25 | #include <glib-object.h> | ||
4591 | 26 | |||
4592 | 27 | #include <gtk/gtk.h> | ||
4593 | 28 | #include "ce-page.h" | ||
4594 | 29 | |||
4595 | 30 | G_BEGIN_DECLS | ||
4596 | 31 | |||
4597 | 32 | #define CE_TYPE_PAGE_IP6 (ce_page_ip6_get_type ()) | ||
4598 | 33 | #define CE_PAGE_IP6(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CE_TYPE_PAGE_IP6, CEPageIP6)) | ||
4599 | 34 | #define CE_PAGE_IP6_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CE_TYPE_PAGE_IP6, CEPageIP6Class)) | ||
4600 | 35 | #define CE_IS_PAGE_IP6(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CE_TYPE_PAGE_IP6)) | ||
4601 | 36 | #define CE_IS_PAGE_IP6_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CE_TYPE_PAGE_IP6)) | ||
4602 | 37 | #define CE_PAGE_IP6_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CE_TYPE_PAGE_IP6, CEPageIP6Class)) | ||
4603 | 38 | |||
4604 | 39 | typedef struct _CEPageIP6 CEPageIP6; | ||
4605 | 40 | typedef struct _CEPageIP6Class CEPageIP6Class; | ||
4606 | 41 | |||
4607 | 42 | struct _CEPageIP6 | ||
4608 | 43 | { | ||
4609 | 44 | CEPage parent; | ||
4610 | 45 | |||
4611 | 46 | NMSettingIPConfig *setting; | ||
4612 | 47 | |||
4613 | 48 | GtkToggleButton *disabled; | ||
4614 | 49 | GtkWidget *address_list; | ||
4615 | 50 | GtkSwitch *auto_dns; | ||
4616 | 51 | GtkWidget *dns_entry; | ||
4617 | 52 | GtkSwitch *auto_routes; | ||
4618 | 53 | GtkWidget *routes_list; | ||
4619 | 54 | GtkWidget *never_default; | ||
4620 | 55 | }; | ||
4621 | 56 | |||
4622 | 57 | struct _CEPageIP6Class | ||
4623 | 58 | { | ||
4624 | 59 | CEPageClass parent_class; | ||
4625 | 60 | }; | ||
4626 | 61 | |||
4627 | 62 | GType ce_page_ip6_get_type (void); | ||
4628 | 63 | |||
4629 | 64 | CEPage *ce_page_ip6_new (NMConnection *connection, | ||
4630 | 65 | NMClient *client); | ||
4631 | 66 | |||
4632 | 67 | G_END_DECLS | ||
4633 | 68 | |||
4634 | 69 | #endif /* __CE_PAGE_IP6_H */ | ||
4635 | 70 | |||
4636 | 0 | 71 | ||
4637 | === added file 'panels/network/connection-editor/ce-page-security.c' | |||
4638 | --- panels/network/connection-editor/ce-page-security.c 1970-01-01 00:00:00 +0000 | |||
4639 | +++ panels/network/connection-editor/ce-page-security.c 2019-05-01 13:56:52 +0000 | |||
4640 | @@ -0,0 +1,467 @@ | |||
4641 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
4642 | 2 | * | ||
4643 | 3 | * Copyright (C) 2012 Red Hat, Inc | ||
4644 | 4 | * | ||
4645 | 5 | * Licensed under the GNU General Public License Version 2 | ||
4646 | 6 | * | ||
4647 | 7 | * This program is free software; you can redistribute it and/or modify | ||
4648 | 8 | * it under the terms of the GNU General Public License as published by | ||
4649 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
4650 | 10 | * (at your option) any later version. | ||
4651 | 11 | * | ||
4652 | 12 | * This program is distributed in the hope that it will be useful, | ||
4653 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4654 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4655 | 15 | * GNU General Public License for more details. | ||
4656 | 16 | * | ||
4657 | 17 | * You should have received a copy of the GNU General Public License | ||
4658 | 18 | * along with this program; if not, write to the Free Software | ||
4659 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
4660 | 20 | */ | ||
4661 | 21 | |||
4662 | 22 | #include "config.h" | ||
4663 | 23 | |||
4664 | 24 | #include <glib-object.h> | ||
4665 | 25 | #include <glib/gi18n.h> | ||
4666 | 26 | |||
4667 | 27 | #include <NetworkManager.h> | ||
4668 | 28 | |||
4669 | 29 | #include "wireless-security.h" | ||
4670 | 30 | #include "ce-page-security.h" | ||
4671 | 31 | |||
4672 | 32 | G_DEFINE_TYPE (CEPageSecurity, ce_page_security, CE_TYPE_PAGE) | ||
4673 | 33 | |||
4674 | 34 | enum { | ||
4675 | 35 | S_NAME_COLUMN, | ||
4676 | 36 | S_SEC_COLUMN, | ||
4677 | 37 | S_ADHOC_VALID_COLUMN | ||
4678 | 38 | }; | ||
4679 | 39 | |||
4680 | 40 | static gboolean | ||
4681 | 41 | find_proto (NMSettingWirelessSecurity *sec, const char *item) | ||
4682 | 42 | { | ||
4683 | 43 | guint32 i; | ||
4684 | 44 | |||
4685 | 45 | for (i = 0; i < nm_setting_wireless_security_get_num_protos (sec); i++) { | ||
4686 | 46 | if (!strcmp (item, nm_setting_wireless_security_get_proto (sec, i))) | ||
4687 | 47 | return TRUE; | ||
4688 | 48 | } | ||
4689 | 49 | return FALSE; | ||
4690 | 50 | } | ||
4691 | 51 | |||
4692 | 52 | static NMUtilsSecurityType | ||
4693 | 53 | get_default_type_for_security (NMSettingWirelessSecurity *sec) | ||
4694 | 54 | { | ||
4695 | 55 | const char *key_mgmt, *auth_alg; | ||
4696 | 56 | |||
4697 | 57 | g_return_val_if_fail (sec != NULL, NMU_SEC_NONE); | ||
4698 | 58 | |||
4699 | 59 | key_mgmt = nm_setting_wireless_security_get_key_mgmt (sec); | ||
4700 | 60 | auth_alg = nm_setting_wireless_security_get_auth_alg (sec); | ||
4701 | 61 | |||
4702 | 62 | /* No IEEE 802.1x */ | ||
4703 | 63 | if (!strcmp (key_mgmt, "none")) | ||
4704 | 64 | return NMU_SEC_STATIC_WEP; | ||
4705 | 65 | |||
4706 | 66 | if (!strcmp (key_mgmt, "ieee8021x")) { | ||
4707 | 67 | if (auth_alg && !strcmp (auth_alg, "leap")) | ||
4708 | 68 | return NMU_SEC_LEAP; | ||
4709 | 69 | return NMU_SEC_DYNAMIC_WEP; | ||
4710 | 70 | } | ||
4711 | 71 | |||
4712 | 72 | if ( !strcmp (key_mgmt, "wpa-none") | ||
4713 | 73 | || !strcmp (key_mgmt, "wpa-psk")) { | ||
4714 | 74 | if (find_proto (sec, "rsn")) | ||
4715 | 75 | return NMU_SEC_WPA2_PSK; | ||
4716 | 76 | else if (find_proto (sec, "wpa")) | ||
4717 | 77 | return NMU_SEC_WPA_PSK; | ||
4718 | 78 | else | ||
4719 | 79 | return NMU_SEC_WPA_PSK; | ||
4720 | 80 | } | ||
4721 | 81 | |||
4722 | 82 | if (!strcmp (key_mgmt, "wpa-eap")) { | ||
4723 | 83 | if (find_proto (sec, "rsn")) | ||
4724 | 84 | return NMU_SEC_WPA2_ENTERPRISE; | ||
4725 | 85 | else if (find_proto (sec, "wpa")) | ||
4726 | 86 | return NMU_SEC_WPA_ENTERPRISE; | ||
4727 | 87 | else | ||
4728 | 88 | return NMU_SEC_WPA_ENTERPRISE; | ||
4729 | 89 | } | ||
4730 | 90 | |||
4731 | 91 | return NMU_SEC_INVALID; | ||
4732 | 92 | } | ||
4733 | 93 | |||
4734 | 94 | static WirelessSecurity * | ||
4735 | 95 | security_combo_get_active (CEPageSecurity *page) | ||
4736 | 96 | { | ||
4737 | 97 | GtkTreeIter iter; | ||
4738 | 98 | GtkTreeModel *model; | ||
4739 | 99 | WirelessSecurity *sec = NULL; | ||
4740 | 100 | |||
4741 | 101 | model = gtk_combo_box_get_model (page->security_combo); | ||
4742 | 102 | gtk_combo_box_get_active_iter (page->security_combo, &iter); | ||
4743 | 103 | gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1); | ||
4744 | 104 | |||
4745 | 105 | return sec; | ||
4746 | 106 | } | ||
4747 | 107 | |||
4748 | 108 | static void | ||
4749 | 109 | wsec_size_group_clear (GtkSizeGroup *group) | ||
4750 | 110 | { | ||
4751 | 111 | GSList *children; | ||
4752 | 112 | GSList *iter; | ||
4753 | 113 | |||
4754 | 114 | g_return_if_fail (group != NULL); | ||
4755 | 115 | |||
4756 | 116 | children = gtk_size_group_get_widgets (group); | ||
4757 | 117 | for (iter = children; iter; iter = g_slist_next (iter)) | ||
4758 | 118 | gtk_size_group_remove_widget (group, GTK_WIDGET (iter->data)); | ||
4759 | 119 | } | ||
4760 | 120 | |||
4761 | 121 | static void | ||
4762 | 122 | security_combo_changed (GtkComboBox *combo, | ||
4763 | 123 | gpointer user_data) | ||
4764 | 124 | { | ||
4765 | 125 | CEPageSecurity *page = CE_PAGE_SECURITY (user_data); | ||
4766 | 126 | GtkWidget *vbox; | ||
4767 | 127 | GList *l, *children; | ||
4768 | 128 | WirelessSecurity *sec; | ||
4769 | 129 | |||
4770 | 130 | wsec_size_group_clear (page->group); | ||
4771 | 131 | |||
4772 | 132 | vbox = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "vbox")); | ||
4773 | 133 | children = gtk_container_get_children (GTK_CONTAINER (vbox)); | ||
4774 | 134 | for (l = children; l; l = l->next) { | ||
4775 | 135 | gtk_container_remove (GTK_CONTAINER (vbox), GTK_WIDGET (l->data)); | ||
4776 | 136 | } | ||
4777 | 137 | |||
4778 | 138 | sec = security_combo_get_active (page); | ||
4779 | 139 | if (sec) { | ||
4780 | 140 | GtkWidget *sec_widget; | ||
4781 | 141 | GtkWidget *parent; | ||
4782 | 142 | |||
4783 | 143 | sec_widget = wireless_security_get_widget (sec); | ||
4784 | 144 | g_assert (sec_widget); | ||
4785 | 145 | parent = gtk_widget_get_parent (sec_widget); | ||
4786 | 146 | if (parent) | ||
4787 | 147 | gtk_container_remove (GTK_CONTAINER (parent), sec_widget); | ||
4788 | 148 | |||
4789 | 149 | gtk_size_group_add_widget (page->group, page->security_heading); | ||
4790 | 150 | wireless_security_add_to_size_group (sec, page->group); | ||
4791 | 151 | |||
4792 | 152 | gtk_container_add (GTK_CONTAINER (vbox), sec_widget); | ||
4793 | 153 | wireless_security_unref (sec); | ||
4794 | 154 | } | ||
4795 | 155 | |||
4796 | 156 | ce_page_changed (CE_PAGE (page)); | ||
4797 | 157 | } | ||
4798 | 158 | |||
4799 | 159 | static void | ||
4800 | 160 | stuff_changed_cb (WirelessSecurity *sec, gpointer user_data) | ||
4801 | 161 | { | ||
4802 | 162 | ce_page_changed (CE_PAGE (user_data)); | ||
4803 | 163 | } | ||
4804 | 164 | |||
4805 | 165 | static void | ||
4806 | 166 | add_security_item (CEPageSecurity *page, | ||
4807 | 167 | WirelessSecurity *sec, | ||
4808 | 168 | GtkListStore *model, | ||
4809 | 169 | GtkTreeIter *iter, | ||
4810 | 170 | const char *text, | ||
4811 | 171 | gboolean adhoc_valid) | ||
4812 | 172 | { | ||
4813 | 173 | wireless_security_set_changed_notify (sec, stuff_changed_cb, page); | ||
4814 | 174 | gtk_list_store_append (model, iter); | ||
4815 | 175 | gtk_list_store_set (model, iter, | ||
4816 | 176 | S_NAME_COLUMN, text, | ||
4817 | 177 | S_SEC_COLUMN, sec, | ||
4818 | 178 | S_ADHOC_VALID_COLUMN, adhoc_valid, | ||
4819 | 179 | -1); | ||
4820 | 180 | wireless_security_unref (sec); | ||
4821 | 181 | } | ||
4822 | 182 | |||
4823 | 183 | static void | ||
4824 | 184 | set_sensitive (GtkCellLayout *cell_layout, | ||
4825 | 185 | GtkCellRenderer *cell, | ||
4826 | 186 | GtkTreeModel *tree_model, | ||
4827 | 187 | GtkTreeIter *iter, | ||
4828 | 188 | gpointer data) | ||
4829 | 189 | { | ||
4830 | 190 | gboolean *adhoc = data; | ||
4831 | 191 | gboolean sensitive = TRUE, adhoc_valid = TRUE; | ||
4832 | 192 | |||
4833 | 193 | gtk_tree_model_get (tree_model, iter, S_ADHOC_VALID_COLUMN, &adhoc_valid, -1); | ||
4834 | 194 | if (*adhoc && !adhoc_valid) | ||
4835 | 195 | sensitive = FALSE; | ||
4836 | 196 | |||
4837 | 197 | g_object_set (cell, "sensitive", sensitive, NULL); | ||
4838 | 198 | } | ||
4839 | 199 | |||
4840 | 200 | static void | ||
4841 | 201 | finish_setup (CEPageSecurity *page) | ||
4842 | 202 | { | ||
4843 | 203 | NMConnection *connection = CE_PAGE (page)->connection; | ||
4844 | 204 | NMSettingWireless *sw; | ||
4845 | 205 | NMSettingWirelessSecurity *sws; | ||
4846 | 206 | gboolean is_adhoc = FALSE; | ||
4847 | 207 | GtkListStore *sec_model; | ||
4848 | 208 | GtkTreeIter iter; | ||
4849 | 209 | const gchar *mode; | ||
4850 | 210 | guint32 dev_caps = 0; | ||
4851 | 211 | NMUtilsSecurityType default_type = NMU_SEC_NONE; | ||
4852 | 212 | int active = -1; | ||
4853 | 213 | int item = 0; | ||
4854 | 214 | GtkComboBox *combo; | ||
4855 | 215 | GtkCellRenderer *renderer; | ||
4856 | 216 | |||
4857 | 217 | sw = nm_connection_get_setting_wireless (connection); | ||
4858 | 218 | g_assert (sw); | ||
4859 | 219 | |||
4860 | 220 | page->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); | ||
4861 | 221 | |||
4862 | 222 | page->security_heading = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "heading_sec")); | ||
4863 | 223 | page->security_combo = combo = GTK_COMBO_BOX (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_sec")); | ||
4864 | 224 | |||
4865 | 225 | dev_caps = NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | ||
4866 | 226 | | NM_WIFI_DEVICE_CAP_CIPHER_WEP104 | ||
4867 | 227 | | NM_WIFI_DEVICE_CAP_CIPHER_TKIP | ||
4868 | 228 | | NM_WIFI_DEVICE_CAP_CIPHER_CCMP | ||
4869 | 229 | | NM_WIFI_DEVICE_CAP_WPA | ||
4870 | 230 | | NM_WIFI_DEVICE_CAP_RSN; | ||
4871 | 231 | |||
4872 | 232 | mode = nm_setting_wireless_get_mode (sw); | ||
4873 | 233 | if (mode && !strcmp (mode, "adhoc")) | ||
4874 | 234 | is_adhoc = TRUE; | ||
4875 | 235 | page->adhoc = is_adhoc; | ||
4876 | 236 | |||
4877 | 237 | sws = nm_connection_get_setting_wireless_security (connection); | ||
4878 | 238 | if (sws) | ||
4879 | 239 | default_type = get_default_type_for_security (sws); | ||
4880 | 240 | |||
4881 | 241 | sec_model = gtk_list_store_new (3, G_TYPE_STRING, WIRELESS_TYPE_SECURITY, G_TYPE_BOOLEAN); | ||
4882 | 242 | |||
4883 | 243 | if (nm_utils_security_valid (NMU_SEC_NONE, dev_caps, FALSE, is_adhoc, 0, 0, 0)) { | ||
4884 | 244 | gtk_list_store_insert_with_values (sec_model, &iter, -1, | ||
4885 | 245 | S_NAME_COLUMN, C_("Wi-Fi/Ethernet security", "None"), | ||
4886 | 246 | S_ADHOC_VALID_COLUMN, TRUE, | ||
4887 | 247 | -1); | ||
4888 | 248 | if (default_type == NMU_SEC_NONE) | ||
4889 | 249 | active = item; | ||
4890 | 250 | item++; | ||
4891 | 251 | } | ||
4892 | 252 | |||
4893 | 253 | if (nm_utils_security_valid (NMU_SEC_STATIC_WEP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) { | ||
4894 | 254 | WirelessSecurityWEPKey *ws_wep; | ||
4895 | 255 | NMWepKeyType wep_type = NM_WEP_KEY_TYPE_KEY; | ||
4896 | 256 | |||
4897 | 257 | if (default_type == NMU_SEC_STATIC_WEP) { | ||
4898 | 258 | sws = nm_connection_get_setting_wireless_security (connection); | ||
4899 | 259 | if (sws) | ||
4900 | 260 | wep_type = nm_setting_wireless_security_get_wep_key_type (sws); | ||
4901 | 261 | if (wep_type == NM_WEP_KEY_TYPE_UNKNOWN) | ||
4902 | 262 | wep_type = NM_WEP_KEY_TYPE_KEY; | ||
4903 | 263 | } | ||
4904 | 264 | |||
4905 | 265 | ws_wep = ws_wep_key_new (connection, NM_WEP_KEY_TYPE_KEY, FALSE, FALSE); | ||
4906 | 266 | if (ws_wep) { | ||
4907 | 267 | add_security_item (page, WIRELESS_SECURITY (ws_wep), sec_model, | ||
4908 | 268 | &iter, _("WEP 40/128-bit Key (Hex or ASCII)"), | ||
4909 | 269 | TRUE); | ||
4910 | 270 | if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (wep_type == NM_WEP_KEY_TYPE_KEY)) | ||
4911 | 271 | active = item; | ||
4912 | 272 | item++; | ||
4913 | 273 | } | ||
4914 | 274 | |||
4915 | 275 | ws_wep = ws_wep_key_new (connection, NM_WEP_KEY_TYPE_PASSPHRASE, FALSE, FALSE); | ||
4916 | 276 | if (ws_wep) { | ||
4917 | 277 | add_security_item (page, WIRELESS_SECURITY (ws_wep), sec_model, | ||
4918 | 278 | &iter, _("WEP 128-bit Passphrase"), TRUE); | ||
4919 | 279 | if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (wep_type == NM_WEP_KEY_TYPE_PASSPHRASE)) | ||
4920 | 280 | active = item; | ||
4921 | 281 | item++; | ||
4922 | 282 | } | ||
4923 | 283 | } | ||
4924 | 284 | |||
4925 | 285 | if (nm_utils_security_valid (NMU_SEC_LEAP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) { | ||
4926 | 286 | WirelessSecurityLEAP *ws_leap; | ||
4927 | 287 | |||
4928 | 288 | ws_leap = ws_leap_new (connection, FALSE); | ||
4929 | 289 | if (ws_leap) { | ||
4930 | 290 | add_security_item (page, WIRELESS_SECURITY (ws_leap), sec_model, | ||
4931 | 291 | &iter, _("LEAP"), FALSE); | ||
4932 | 292 | if ((active < 0) && (default_type == NMU_SEC_LEAP)) | ||
4933 | 293 | active = item; | ||
4934 | 294 | item++; | ||
4935 | 295 | } | ||
4936 | 296 | } | ||
4937 | 297 | |||
4938 | 298 | if (nm_utils_security_valid (NMU_SEC_DYNAMIC_WEP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) { | ||
4939 | 299 | WirelessSecurityDynamicWEP *ws_dynamic_wep; | ||
4940 | 300 | |||
4941 | 301 | ws_dynamic_wep = ws_dynamic_wep_new (connection, TRUE, FALSE); | ||
4942 | 302 | if (ws_dynamic_wep) { | ||
4943 | 303 | add_security_item (page, WIRELESS_SECURITY (ws_dynamic_wep), sec_model, | ||
4944 | 304 | &iter, _("Dynamic WEP (802.1x)"), FALSE); | ||
4945 | 305 | if ((active < 0) && (default_type == NMU_SEC_DYNAMIC_WEP)) | ||
4946 | 306 | active = item; | ||
4947 | 307 | item++; | ||
4948 | 308 | } | ||
4949 | 309 | } | ||
4950 | 310 | |||
4951 | 311 | if (nm_utils_security_valid (NMU_SEC_WPA_PSK, dev_caps, FALSE, is_adhoc, 0, 0, 0) || | ||
4952 | 312 | nm_utils_security_valid (NMU_SEC_WPA2_PSK, dev_caps, FALSE, is_adhoc, 0, 0, 0)) { | ||
4953 | 313 | WirelessSecurityWPAPSK *ws_wpa_psk; | ||
4954 | 314 | |||
4955 | 315 | ws_wpa_psk = ws_wpa_psk_new (connection, FALSE); | ||
4956 | 316 | if (ws_wpa_psk) { | ||
4957 | 317 | add_security_item (page, WIRELESS_SECURITY (ws_wpa_psk), sec_model, | ||
4958 | 318 | &iter, _("WPA & WPA2 Personal"), FALSE); | ||
4959 | 319 | if ((active < 0) && ((default_type == NMU_SEC_WPA_PSK) || (default_type == NMU_SEC_WPA2_PSK))) | ||
4960 | 320 | active = item; | ||
4961 | 321 | item++; | ||
4962 | 322 | } | ||
4963 | 323 | } | ||
4964 | 324 | |||
4965 | 325 | if (nm_utils_security_valid (NMU_SEC_WPA_ENTERPRISE, dev_caps, FALSE, is_adhoc, 0, 0, 0) || | ||
4966 | 326 | nm_utils_security_valid (NMU_SEC_WPA2_ENTERPRISE, dev_caps, FALSE, is_adhoc, 0, 0, 0)) { | ||
4967 | 327 | WirelessSecurityWPAEAP *ws_wpa_eap; | ||
4968 | 328 | |||
4969 | 329 | ws_wpa_eap = ws_wpa_eap_new (connection, TRUE, FALSE); | ||
4970 | 330 | if (ws_wpa_eap) { | ||
4971 | 331 | add_security_item (page, WIRELESS_SECURITY (ws_wpa_eap), sec_model, | ||
4972 | 332 | &iter, _("WPA & WPA2 Enterprise"), FALSE); | ||
4973 | 333 | if ((active < 0) && ((default_type == NMU_SEC_WPA_ENTERPRISE) || (default_type == NMU_SEC_WPA2_ENTERPRISE))) | ||
4974 | 334 | active = item; | ||
4975 | 335 | item++; | ||
4976 | 336 | } | ||
4977 | 337 | } | ||
4978 | 338 | |||
4979 | 339 | gtk_combo_box_set_model (combo, GTK_TREE_MODEL (sec_model)); | ||
4980 | 340 | gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo)); | ||
4981 | 341 | |||
4982 | 342 | renderer = gtk_cell_renderer_text_new (); | ||
4983 | 343 | gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE); | ||
4984 | 344 | gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, "text", S_NAME_COLUMN, NULL); | ||
4985 | 345 | gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), renderer, set_sensitive, &page->adhoc, NULL); | ||
4986 | 346 | |||
4987 | 347 | gtk_combo_box_set_active (combo, active < 0 ? 0 : (guint32) active); | ||
4988 | 348 | g_object_unref (G_OBJECT (sec_model)); | ||
4989 | 349 | |||
4990 | 350 | page->security_combo = combo; | ||
4991 | 351 | |||
4992 | 352 | security_combo_changed (combo, page); | ||
4993 | 353 | g_signal_connect (combo, "changed", | ||
4994 | 354 | G_CALLBACK (security_combo_changed), page); | ||
4995 | 355 | } | ||
4996 | 356 | |||
4997 | 357 | static gboolean | ||
4998 | 358 | validate (CEPage *page, | ||
4999 | 359 | NMConnection *connection, | ||
5000 | 360 | GError **error) |
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