Merge lp:~elementary-pantheon/switchboard-plug-networking/hotspot into lp:~elementary-pantheon/switchboard-plug-networking/trunk
- hotspot
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Adam Bieńkowski | ||||
Approved revision: | 188 | ||||
Merged at revision: | 212 | ||||
Proposed branch: | lp:~elementary-pantheon/switchboard-plug-networking/hotspot | ||||
Merge into: | lp:~elementary-pantheon/switchboard-plug-networking/trunk | ||||
Diff against target: |
2361 lines (+1351/-391) 25 files modified
AUTHORS (+3/-2) src/CMakeLists.txt (+5/-0) src/Plug.vala (+15/-19) src/Settings/ProxySettings.vala (+19/-0) src/Utils.vala (+256/-78) src/Widgets/Device/DeviceItem.vala (+57/-51) src/Widgets/Device/DevicePage.vala (+19/-22) src/Widgets/DeviceList.vala (+80/-66) src/Widgets/EtherInterface.vala (+52/-0) src/Widgets/Footer.vala (+15/-18) src/Widgets/Hotspot/HotspotDialog.vala (+227/-0) src/Widgets/HotspotInterface.vala (+169/-0) src/Widgets/InfoBox.vala (+23/-26) src/Widgets/InfoScreen.vala (+15/-18) src/Widgets/Page.vala (+13/-28) src/Widgets/Proxy/ProxyConfigurationPage.vala (+19/-1) src/Widgets/Proxy/ProxyExceptionsPage.vala (+19/-0) src/Widgets/Proxy/ProxyPage.vala (+36/-1) src/Widgets/WifiInterface.vala (+72/-43) src/common/Utils.vala (+27/-0) src/common/Widgets/AbstractEtherInterface.vala (+77/-0) src/common/Widgets/AbstractHotspotInterface.vala (+40/-0) src/common/Widgets/AbstractWifiInterface.vala (+39/-14) src/common/Widgets/NMVisualizer.vala (+40/-4) src/common/Widgets/WidgetNMInterface.vala (+14/-0) |
||||
To merge this branch: | bzr merge lp:~elementary-pantheon/switchboard-plug-networking/hotspot | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Adam Bieńkowski (community) | Approve | ||
kay van der Zander (community) | Approve | ||
Danielle Foré | Approve | ||
Review via email: mp+281010@code.launchpad.net |
Commit message
* New hotspot mode: create and manage hostpot mode.
* Massive code cleanup.
* Update AUTHORS file.
* Update copyright headers.
* Make "Connect to hidden network" button insensitive when cabble unpluged.
* If more devices of one type show their real names.
* Recognize virtual ethernet devices.
* Code logic and typo fixes.
Description of the change
Adam Bieńkowski (donadigo) wrote : | # |
Danielle Foré (danrabbit) wrote : | # |
Hm something has gone awry:
* My Wireless connection shows an ethernet icon in the sidebar
* When I disable my USB ethernet device, in the sidebar is shows "Cable unplugged" instead of "Disabled"
* I think there should be some kind of explanation on the hotspot page. At the moment it's completely blank. We should explain what hotspot is and that you won't be able to connect to other wireless networks while it is enabled (basically the information from the connection dialog).
* If I cancel creating the hotspot, the switch is still in the "on" position.
xapantu (xapantu) wrote : | # |
Ah yes I forgot to re-add the icons back after the refactor.
There is definitively a problem with the ethernet states…
On 20/12/2015 20:22, Daniel Fore wrote:
> Review: Needs Fixing
>
> Hm something has gone awry:
> * My Wireless connection shows an ethernet icon in the sidebar
> * When I disable my USB ethernet device, in the sidebar is shows "Cable unplugged" instead of "Disabled"
>
> * I think there should be some kind of explanation on the hotspot page. At the moment it's completely blank. We should explain what hotspot is and that you won't be able to connect to other wireless networks while it is enabled (basically the information from the connection dialog).
>
> * If I cancel creating the hotspot, the switch is still in the "on" position.
>
xapantu (xapantu) wrote : | # |
So, I just pushed a fix for the ethernet and icons bugs.
For the revealer thing, I am not sure we want a transition here. If we
really want one, which one would suit that part?
Adam, could you take a look at Daniel's bug:
* If I cancel creating the hotspot, the switch is still in the "on"
position.
On 20/12/2015 13:42, Adam Bieńkowski wrote:
> Review: Needs Fixing ui / code
>
> So, the branch improved a lot of the behaviour of the Plug and It's fantastic work, but there are some issues:
>
> * When I disable Ethernet Interface, in the sidebar the state is "Failed" (and red dot) which seems wrong because I turned it off by the switch, and it should be "Disconnected".
>
> * UI: Also in Ethernet Interface, revealers seem to not reveal, but immediately show after switching the state of the device...
>
> I commented on some places, where I could point out fixes.
>
> But overall it's really good branch, and definetely improves a lot of the Plug itself, I would like to see a review from others like Daniel to ensure that there are no other issues.
>
> When I got some time, I will commit fixes for the above ;)
>
> Diff comments:
>
>>
>> === modified file 'src/Widgets/
>> --- src/Widgets/
>> +++ src/Widgets/
>> @@ -30,20 +31,26 @@
>> private Gtk.Image row_image;
>> private Gtk.Image status_image;
>>
>> - private string title;
>> - private string subtitle;
>
> Use spaces.
>
>> + public string title {
>> + set {
>> + row_title.label = value;
>> + }
>> + }
>> +
>> + private string subtitle;
>> private string icon_name;
>>
>> private Gtk.Grid row_grid;
>> private Gtk.Label row_title;
>>
>> public DeviceItem (string _title, string _subtitle, string _icon_name = "network-wired") {
>> - this.title = _title;
>> this.subtitle = _subtitle;
>> this.icon_name = _icon_name;
>> this.type = Utils.ItemType.
>>
>> create_ui (icon_name);
>
> Use spaces.
>
>> +
>> + this.title = _title;
>> }
>>
>> public DeviceItem.
>>
>> === added file 'src/common/
>> --- src/common/
>> +++ src/common/
>> @@ -0,0 +1,70 @@
>> +/*
>> + * Copyright (c) 2015 Wingpanel Developers (http://
>> + *
>> + * This program is free software: you can redistribute it and/or modify
>> + * it under the terms of the GNU Library General Public License as published by
>> + * the Free Software Foundation, either version 2.1 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU Library General Public License for more details.
>>...
Adam Bieńkowski (donadigo) wrote : | # |
I will look at it tommorow.
- 185. By Adam Bieńkowski
-
Update branch; fixed: hotspot switch stays enabled when canceling the hotspot mode; animate revealers in EtherInterface; code clean; fixed info_box.from typo in the code
Adam Bieńkowski (donadigo) wrote : | # |
Branch updated with some requested fixes.
kay van der Zander (kay20) wrote : | # |
i would suggest applying the right copy right header.
example :
/*-
* Copyright (c) 2015-2016 elementary LLC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://
*
* Authored by: Kay van der Zander <email address hidden>
*/
only adjust the authored section
- 186. By Adam Bieńkowski
-
Update copyright headers as requested by kay; updated AUTHORS file
Adam Bieńkowski (donadigo) wrote : | # |
kay20: Updated the copyright headers.
Danielle Foré (danrabbit) wrote : | # |
perhaps "connect to hidden network" should be made insensitive?
Other than that it seems to work correctly as far as I can tell :)
Danielle Foré (danrabbit) wrote : | # |
Oops actually, I just noticed. Please revert changing "Wireless" to "Wi-Fi"
- 187. By Adam Bieńkowski
-
Hidden button only sensitive when Wi-Fi cable plugged; renadme Wi-Fi to Wireless
kay van der Zander (kay20) wrote : | # |
First rebase to the current trunk otherwise history will be lost(and code)
I have seen code in trunk where you branch didn't have it. To make absolutely no mistake i disapprove this branch.
- 188. By Adam Bieńkowski
-
Merge from trunk
Adam Bieńkowski (donadigo) wrote : | # |
kay20: Can you check if the branch is still diverged? I merged the current trunk and everything seems fine.
kay van der Zander (kay20) wrote : | # |
Disapprove resolved. Branch rebased. didn't checked code style or logic
Adam Bieńkowski (donadigo) wrote : | # |
I am going to merge this now since it's a massive branch, if you have other problems with it, please fill a bug report.
Preview Diff
1 | === modified file 'AUTHORS' |
2 | --- AUTHORS 2015-04-03 21:40:36 +0000 |
3 | +++ AUTHORS 2016-02-12 18:38:32 +0000 |
4 | @@ -1,4 +1,5 @@ |
5 | -Copyright (c) 2014 by 1 Developers |
6 | +Copyright (c) 2014 by 2 Developers |
7 | |
8 | -Written by XXX Developers: |
9 | +Written by 2 Developers: |
10 | * Adam Bieńkowski <donadigos159@gmail.com> |
11 | +* xapantu |
12 | \ No newline at end of file |
13 | |
14 | === modified file 'src/CMakeLists.txt' |
15 | --- src/CMakeLists.txt 2015-08-01 23:06:00 +0000 |
16 | +++ src/CMakeLists.txt 2016-02-12 18:38:32 +0000 |
17 | @@ -21,15 +21,20 @@ |
18 | Widgets/Device/DeviceItem.vala |
19 | Widgets/Device/DevicePage.vala |
20 | Widgets/WifiInterface.vala |
21 | + Widgets/EtherInterface.vala |
22 | + Widgets/HotspotInterface.vala |
23 | Widgets/Proxy/ProxyConfigurationPage.vala |
24 | Widgets/Proxy/ProxyExceptionsPage.vala |
25 | Widgets/Proxy/ProxyPage.vala |
26 | Widgets/InfoBox.vala |
27 | Widgets/Footer.vala |
28 | Widgets/InfoScreen.vala |
29 | + Widgets/Hotspot/HotspotDialog.vala |
30 | common/Utils.vala |
31 | common/Widgets/WifiMenuItem.vala |
32 | common/Widgets/AbstractWifiInterface.vala |
33 | + common/Widgets/AbstractEtherInterface.vala |
34 | + common/Widgets/AbstractHotspotInterface.vala |
35 | common/rfkill.vala |
36 | common/Widgets/NMVisualizer.vala |
37 | common/Widgets/WidgetNMInterface.vala |
38 | |
39 | === modified file 'src/Plug.vala' |
40 | --- src/Plug.vala 2016-01-04 19:48:59 +0000 |
41 | +++ src/Plug.vala 2016-02-12 18:38:32 +0000 |
42 | @@ -1,23 +1,20 @@ |
43 | -// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- |
44 | /*- |
45 | - * Copyright (c) 2015 Adam Bieńkowski (http://launchpad.net/switchboard-network-plug) |
46 | - * |
47 | - * This library is free software; you can redistribute it and/or |
48 | - * modify it under the terms of the GNU Library General Public |
49 | - * License as published by the Free Software Foundation; either |
50 | - * version 3 of the License, or (at your option) any later version. |
51 | - * |
52 | - * This library is distributed in the hope that it will be useful, |
53 | + * Copyright (c) 2015-2016 elementary LLC. |
54 | + * |
55 | + * This program is free software: you can redistribute it and/or modify |
56 | + * it under the terms of the GNU Lesser General Public License as published by |
57 | + * the Free Software Foundation, either version 2.1 of the License, or |
58 | + * (at your option) any later version. |
59 | + * |
60 | + * This program is distributed in the hope that it will be useful, |
61 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
62 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
63 | - * Library General Public License for more details. |
64 | - * |
65 | - * You should have received a copy of the GNU Library General Public |
66 | - * License along with this library; if not, write to the |
67 | - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
68 | - * Boston, MA 02111-1307, USA. |
69 | - * |
70 | - * Authored by: Adam Bieńkowski <donadigos159@gmail.com |
71 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
72 | + * GNU Lesser General Public License for more details. |
73 | + * |
74 | + * You should have received a copy of the GNU Lesser General Public License |
75 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
76 | + * |
77 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
78 | */ |
79 | |
80 | /* Main client instance */ |
81 | @@ -64,7 +61,6 @@ |
82 | } |
83 | |
84 | content.remove (widget_interface); |
85 | - |
86 | show_all (); |
87 | } |
88 | |
89 | |
90 | === modified file 'src/Settings/ProxySettings.vala' |
91 | --- src/Settings/ProxySettings.vala 2015-10-09 19:12:42 +0000 |
92 | +++ src/Settings/ProxySettings.vala 2016-02-12 18:38:32 +0000 |
93 | @@ -1,3 +1,22 @@ |
94 | +/*- |
95 | + * Copyright (c) 2015-2016 elementary LLC. |
96 | + * |
97 | + * This program is free software: you can redistribute it and/or modify |
98 | + * it under the terms of the GNU Lesser General Public License as published by |
99 | + * the Free Software Foundation, either version 2.1 of the License, or |
100 | + * (at your option) any later version. |
101 | + * |
102 | + * This program is distributed in the hope that it will be useful, |
103 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
104 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
105 | + * GNU Lesser General Public License for more details. |
106 | + * |
107 | + * You should have received a copy of the GNU Lesser General Public License |
108 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
109 | + * |
110 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
111 | + */ |
112 | + |
113 | namespace Network { |
114 | public class ProxySettings : Granite.Services.Settings { |
115 | public string autoconfig_url { get; set; } |
116 | |
117 | === modified file 'src/Utils.vala' |
118 | --- src/Utils.vala 2015-10-22 16:46:13 +0000 |
119 | +++ src/Utils.vala 2016-02-12 18:38:32 +0000 |
120 | @@ -1,81 +1,259 @@ |
121 | -namespace Network.Utils { |
122 | - public enum ItemType { |
123 | - DEVICE = 0, |
124 | - PROXY, |
125 | - INVALID |
126 | - } |
127 | - |
128 | - public Gtk.Button get_advanced_button_from_device (NM.Device? device, string title = _("Advanced Settings…")) { |
129 | - var details_btn = new Gtk.Button.with_label (title); |
130 | - details_btn.clicked.connect (() => { |
131 | - new Granite.Services.SimpleCommand ("/usr/bin", |
132 | - "nm-connection-editor --edit=" + device.get_active_connection ().get_uuid ()).run (); |
133 | - }); |
134 | - |
135 | - return details_btn; |
136 | - } |
137 | - |
138 | - public string state_to_string (NM.DeviceState state) { |
139 | - switch (state) { |
140 | - case NM.DeviceState.ACTIVATED: |
141 | - return _("Connected"); |
142 | - case NM.DeviceState.DISCONNECTED: |
143 | - return _("Disconnected"); |
144 | - case NM.DeviceState.UNMANAGED: |
145 | - return _("Unmanaged"); |
146 | - case NM.DeviceState.PREPARE: |
147 | - return _("In preparation"); |
148 | - case NM.DeviceState.CONFIG: |
149 | - return _("Connecting..."); |
150 | - case NM.DeviceState.NEED_AUTH: |
151 | - return _("Requires more information"); |
152 | - case NM.DeviceState.IP_CONFIG: |
153 | - return _("Requesting adresses..."); |
154 | - case NM.DeviceState.IP_CHECK: |
155 | - return _("Checking connection..."); |
156 | - case NM.DeviceState.SECONDARIES: |
157 | - return _("Waiting for connection..."); |
158 | - case NM.DeviceState.DEACTIVATING: |
159 | - return _("Disconnecting..."); |
160 | - case NM.DeviceState.FAILED: |
161 | - return _("Failed to connect"); |
162 | - case NM.DeviceState.UNKNOWN: |
163 | - default: |
164 | - return _("Unknown"); |
165 | - } |
166 | - } |
167 | - |
168 | - public string type_to_string (NM.DeviceType type) { |
169 | - switch (type) { |
170 | - case NM.DeviceType.ETHERNET: |
171 | - return _("Ethernet"); |
172 | - case NM.DeviceType.WIFI: |
173 | - return _("Wi-Fi"); |
174 | - case NM.DeviceType.UNUSED1: |
175 | - return _("Not used"); |
176 | - case NM.DeviceType.UNUSED2: |
177 | - return _("Not used"); |
178 | - case NM.DeviceType.BT: |
179 | - return _("Bluetooth"); |
180 | - case NM.DeviceType.OLPC_MESH: |
181 | - return _("OLPC XO"); |
182 | - case NM.DeviceType.WIMAX: |
183 | - return _("WiMAX Broadband"); |
184 | - case NM.DeviceType.MODEM: |
185 | - return _("Modem"); |
186 | - case NM.DeviceType.INFINIBAND: |
187 | - return _("InfiniBand device"); |
188 | - case NM.DeviceType.BOND: |
189 | - return _("Bond master"); |
190 | - case NM.DeviceType.VLAN: |
191 | - return _("VLAN Interface"); |
192 | - case NM.DeviceType.ADSL: |
193 | - return _("ADSL Modem"); |
194 | - case NM.DeviceType.BRIDGE: |
195 | - return _("Bridge master"); |
196 | - case NM.DeviceType.UNKNOWN: |
197 | - default: |
198 | - return _("Unknown"); |
199 | +/*- |
200 | + * Copyright (c) 2015-2016 elementary LLC. |
201 | + * |
202 | + * This program is free software: you can redistribute it and/or modify |
203 | + * it under the terms of the GNU Lesser General Public License as published by |
204 | + * the Free Software Foundation, either version 2.1 of the License, or |
205 | + * (at your option) any later version. |
206 | + * |
207 | + * This program is distributed in the hope that it will be useful, |
208 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
209 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
210 | + * GNU Lesser General Public License for more details. |
211 | + * |
212 | + * You should have received a copy of the GNU Lesser General Public License |
213 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
214 | + * |
215 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
216 | + */ |
217 | + |
218 | +namespace Network { |
219 | + public class Utils { |
220 | + public class Hotspot { |
221 | + public delegate void UpdateSecretCallback (); |
222 | + |
223 | + public static void activate_hotspot (NM.DeviceWifi wifi_device, |
224 | + ByteArray ssid, |
225 | + string key, |
226 | + NM.Connection? selected) { |
227 | + if (selected != null) { |
228 | + client.activate_connection (selected, wifi_device, null, null); |
229 | + return; |
230 | + } |
231 | + |
232 | + var hotspot_c = new NM.Connection (); |
233 | + |
234 | + var setting_connection = new NM.SettingConnection (); |
235 | + setting_connection.@set (NM.SettingConnection.TYPE, "802-11-wireless"); |
236 | + setting_connection.@set (NM.SettingConnection.ID, "Hotspot"); |
237 | + setting_connection.autoconnect = false; |
238 | + hotspot_c.add_setting (setting_connection); |
239 | + |
240 | + var setting_wireless = new NM.SettingWireless (); |
241 | + |
242 | + string? mode = null; |
243 | + var caps = wifi_device.get_capabilities (); |
244 | + if ((caps & NM.DeviceWifiCapabilities.AP) != 0) { |
245 | + mode = NM.SettingWireless.MODE_AP; |
246 | + } else { |
247 | + mode = NM.SettingWireless.MODE_ADHOC; |
248 | + } |
249 | + |
250 | + setting_wireless.mode = mode; |
251 | + setting_wireless.security = "802-11-wireless-security"; |
252 | + |
253 | + hotspot_c.add_setting (setting_wireless); |
254 | + |
255 | + var ip4_setting = new NM.SettingIP4Config (); |
256 | + ip4_setting.method = "shared"; |
257 | + hotspot_c.add_setting (ip4_setting); |
258 | + |
259 | + setting_wireless.@set (NM.SettingWireless.SSID, ssid); |
260 | + |
261 | + var setting_wireless_security = new NM.SettingWirelessSecurity (); |
262 | + |
263 | + if (mode == NM.SettingWireless.MODE_AP) { |
264 | + if ((caps & NM.DeviceWifiCapabilities.RSN) != 0) { |
265 | + set_wpa_key (setting_wireless_security, key); |
266 | + setting_wireless_security.add_proto ("rsn"); |
267 | + setting_wireless_security.add_pairwise ("ccmp"); |
268 | + setting_wireless_security.add_group ("ccmp"); |
269 | + } else if ((caps & NM.DeviceWifiCapabilities.WPA) != 0) { |
270 | + set_wpa_key (setting_wireless_security, key); |
271 | + setting_wireless_security.add_proto ("wpa"); |
272 | + setting_wireless_security.add_pairwise ("tkip"); |
273 | + setting_wireless_security.add_group ("tkip"); |
274 | + } else { |
275 | + set_wep_key (setting_wireless_security, key); |
276 | + } |
277 | + } else { |
278 | + set_wep_key (setting_wireless_security, key); |
279 | + } |
280 | + |
281 | + hotspot_c.add_setting (setting_wireless_security); |
282 | + client.add_and_activate_connection (hotspot_c, |
283 | + wifi_device, |
284 | + null, |
285 | + finish_connection_cb); |
286 | + } |
287 | + |
288 | + public static void update_secrets (NM.RemoteConnection connection, UpdateSecretCallback callback) { |
289 | + connection.get_secrets (connection.get_setting_wireless ().get_security (), ((_connection, secrets, error) => { |
290 | + var setting_wireless = _connection.get_setting_wireless (); |
291 | + try { |
292 | + _connection.update_secrets (setting_wireless.get_security (), secrets); |
293 | + } catch (Error e) { |
294 | + warning ("%s\n", e.message); |
295 | + return; |
296 | + } |
297 | + |
298 | + callback (); |
299 | + })); |
300 | + } |
301 | + |
302 | + public static void deactivate_hotspot (NM.DeviceWifi wifi_device) { |
303 | + client.get_active_connections ().@foreach ((active_connection) => { |
304 | + var devices = active_connection.get_devices (); |
305 | + if (devices != null && devices.@get (0) == wifi_device) { |
306 | + client.deactivate_connection (active_connection); |
307 | + } |
308 | + }); |
309 | + } |
310 | + |
311 | + private static void set_wpa_key (NM.SettingWirelessSecurity setting, string key) { |
312 | + setting.key_mgmt = "wpa-psk"; |
313 | + setting.psk = key; |
314 | + } |
315 | + |
316 | + private static void set_wep_key (NM.SettingWirelessSecurity setting, string key) { |
317 | + setting.key_mgmt = "none"; |
318 | + setting.wep_key0 = key; |
319 | + setting.wep_key_type = NM.WepKeyType.PASSPHRASE; |
320 | + } |
321 | + |
322 | + public static bool get_device_is_hotspot (NM.DeviceWifi wifi_device, NM.RemoteSettings nm_settings) { |
323 | + if (wifi_device.get_active_connection () != null) { |
324 | + var connection = nm_settings.get_connection_by_path (wifi_device.get_active_connection ().get_connection ()); |
325 | + if (connection != null) { |
326 | + var ip4_setting = connection.get_setting_ip4_config (); |
327 | + return (ip4_setting != null && ip4_setting.get_method () == "shared"); |
328 | + } |
329 | + } |
330 | + |
331 | + return false; |
332 | + } |
333 | + |
334 | + public static bool get_connection_is_hotspot (NM.Connection connection) { |
335 | + var setting_connection = connection.get_setting_connection (); |
336 | + if (setting_connection.get_connection_type () != "802-11-wireless") { |
337 | + return false; |
338 | + } |
339 | + |
340 | + var setting_wireless = connection.get_setting_wireless (); |
341 | + if (setting_wireless.get_mode () != "adhoc" |
342 | + && setting_wireless.get_mode () != "ap") { |
343 | + return false; |
344 | + } |
345 | + |
346 | + if (setting_wireless.get_security () != "802-11-wireless-security") { |
347 | + return false; |
348 | + } |
349 | + |
350 | + var ip4_config = connection.get_setting_ip4_config (); |
351 | + if (ip4_config.get_method () != "shared") { |
352 | + return false; |
353 | + } |
354 | + |
355 | + return true; |
356 | + } |
357 | + |
358 | + private static void finish_connection_cb (NM.Client? cb_client, |
359 | + NM.ActiveConnection? cb_connection, |
360 | + string? new_connection_path, |
361 | + Error? error) { |
362 | + if (error != null && error.code != 0) { |
363 | + warning ("%s\n", error.message); |
364 | + } |
365 | + } |
366 | + } |
367 | + |
368 | + public enum CustomMode { |
369 | + PROXY_NONE = 0, |
370 | + PROXY_MANUAL, |
371 | + PROXY_AUTO, |
372 | + HOTSPOT_ENABLED, |
373 | + HOTSPOT_DISABLED, |
374 | + INVALID |
375 | + } |
376 | + |
377 | + public enum ItemType { |
378 | + DEVICE = 0, |
379 | + VIRTUAL, |
380 | + INVALID |
381 | + } |
382 | + |
383 | + public static Gtk.Button get_advanced_button_from_device (NM.Device? device, string title = _("Advanced Settings…")) { |
384 | + var details_btn = new Gtk.Button.with_label (title); |
385 | + details_btn.clicked.connect (() => { |
386 | + new Granite.Services.SimpleCommand ("/usr/bin", |
387 | + "nm-connection-editor --edit=" + device.get_active_connection ().get_uuid ()).run (); |
388 | + }); |
389 | + |
390 | + return details_btn; |
391 | + } |
392 | + |
393 | + public static string state_to_string (NM.DeviceState state) { |
394 | + switch (state) { |
395 | + case NM.DeviceState.ACTIVATED: |
396 | + return _("Connected"); |
397 | + case NM.DeviceState.DISCONNECTED: |
398 | + return _("Disconnected"); |
399 | + case NM.DeviceState.UNMANAGED: |
400 | + return _("Unmanaged"); |
401 | + case NM.DeviceState.PREPARE: |
402 | + return _("In preparation"); |
403 | + case NM.DeviceState.CONFIG: |
404 | + return _("Connecting..."); |
405 | + case NM.DeviceState.NEED_AUTH: |
406 | + return _("Requires more information"); |
407 | + case NM.DeviceState.IP_CONFIG: |
408 | + return _("Requesting adresses..."); |
409 | + case NM.DeviceState.IP_CHECK: |
410 | + return _("Checking connection..."); |
411 | + case NM.DeviceState.SECONDARIES: |
412 | + return _("Waiting for connection..."); |
413 | + case NM.DeviceState.DEACTIVATING: |
414 | + return _("Disconnecting..."); |
415 | + case NM.DeviceState.FAILED: |
416 | + return _("Failed to connect"); |
417 | + case NM.DeviceState.UNKNOWN: |
418 | + default: |
419 | + return _("Unknown"); |
420 | + } |
421 | + } |
422 | + |
423 | + public static string type_to_string (NM.DeviceType type) { |
424 | + switch (type) { |
425 | + case NM.DeviceType.ETHERNET: |
426 | + return _("Ethernet"); |
427 | + case NM.DeviceType.WIFI: |
428 | + return _("Wi-Fi"); |
429 | + case NM.DeviceType.UNUSED1: |
430 | + return _("Not used"); |
431 | + case NM.DeviceType.UNUSED2: |
432 | + return _("Not used"); |
433 | + case NM.DeviceType.BT: |
434 | + return _("Bluetooth"); |
435 | + case NM.DeviceType.OLPC_MESH: |
436 | + return _("OLPC XO"); |
437 | + case NM.DeviceType.WIMAX: |
438 | + return _("WiMAX Broadband"); |
439 | + case NM.DeviceType.MODEM: |
440 | + return _("Modem"); |
441 | + case NM.DeviceType.INFINIBAND: |
442 | + return _("InfiniBand device"); |
443 | + case NM.DeviceType.BOND: |
444 | + return _("Bond master"); |
445 | + case NM.DeviceType.VLAN: |
446 | + return _("VLAN Interface"); |
447 | + case NM.DeviceType.ADSL: |
448 | + return _("ADSL Modem"); |
449 | + case NM.DeviceType.BRIDGE: |
450 | + return _("Bridge master"); |
451 | + case NM.DeviceType.UNKNOWN: |
452 | + default: |
453 | + return _("Unknown"); |
454 | + } |
455 | } |
456 | } |
457 | } |
458 | |
459 | === modified file 'src/Widgets/Device/DeviceItem.vala' |
460 | --- src/Widgets/Device/DeviceItem.vala 2015-10-20 20:34:36 +0000 |
461 | +++ src/Widgets/Device/DeviceItem.vala 2016-02-12 18:38:32 +0000 |
462 | @@ -1,28 +1,26 @@ |
463 | -// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- |
464 | /*- |
465 | - * Copyright (c) 2015 Adam Bieńkowski (http://launchpad.net/switchboard-network-plug) |
466 | - * |
467 | - * This library is free software; you can redistribute it and/or |
468 | - * modify it under the terms of the GNU Library General Public |
469 | - * License as published by the Free Software Foundation; either |
470 | - * version 3 of the License, or (at your option) any later version. |
471 | - * |
472 | - * This library is distributed in the hope that it will be useful, |
473 | + * Copyright (c) 2015-2016 elementary LLC. |
474 | + * |
475 | + * This program is free software: you can redistribute it and/or modify |
476 | + * it under the terms of the GNU Lesser General Public License as published by |
477 | + * the Free Software Foundation, either version 2.1 of the License, or |
478 | + * (at your option) any later version. |
479 | + * |
480 | + * This program is distributed in the hope that it will be useful, |
481 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
482 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
483 | - * Library General Public License for more details. |
484 | - * |
485 | - * You should have received a copy of the GNU Library General Public |
486 | - * License along with this library; if not, write to the |
487 | - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
488 | - * Boston, MA 02111-1307, USA. |
489 | - * |
490 | - * Authored by: Adam Bieńkowski <donadigos159@gmail.com |
491 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
492 | + * GNU Lesser General Public License for more details. |
493 | + * |
494 | + * You should have received a copy of the GNU Lesser General Public License |
495 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
496 | + * |
497 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
498 | */ |
499 | |
500 | namespace Network.Widgets { |
501 | public class DeviceItem : Gtk.ListBoxRow { |
502 | public NM.Device? device = null; |
503 | + private NM.RemoteSettings? nm_settings = null; |
504 | public Gtk.Box? page = null; |
505 | public Utils.ItemType type; |
506 | |
507 | @@ -30,20 +28,26 @@ |
508 | private Gtk.Image row_image; |
509 | private Gtk.Image status_image; |
510 | |
511 | - private string title; |
512 | - private string subtitle; |
513 | + public string title { |
514 | + set { |
515 | + row_title.label = value; |
516 | + } |
517 | + } |
518 | + |
519 | + private string subtitle; |
520 | private string icon_name; |
521 | |
522 | private Gtk.Grid row_grid; |
523 | private Gtk.Label row_title; |
524 | |
525 | public DeviceItem (string _title, string _subtitle, string _icon_name = "network-wired") { |
526 | - this.title = _title; |
527 | this.subtitle = _subtitle; |
528 | this.icon_name = _icon_name; |
529 | this.type = Utils.ItemType.INVALID; |
530 | |
531 | create_ui (icon_name); |
532 | + |
533 | + this.title = _title; |
534 | } |
535 | |
536 | public DeviceItem.from_interface (WidgetNMInterface iface, |
537 | @@ -52,21 +56,22 @@ |
538 | this.page = iface; |
539 | this.device = iface.device; |
540 | this.type = Utils.ItemType.DEVICE; |
541 | - |
542 | - if (_title != "") { |
543 | - this.title = _title; |
544 | - } else { |
545 | - this.title = Utils.type_to_string (device.get_device_type ()); |
546 | - } |
547 | - |
548 | + |
549 | this.subtitle = ""; |
550 | this.icon_name = _icon_name; |
551 | |
552 | create_ui (icon_name); |
553 | - switch_status (device.get_state ()); |
554 | - |
555 | - device.state_changed.connect ( () => { |
556 | - switch_status (device.get_state ()); |
557 | + iface.bind_property ("display-title", this, "title"); |
558 | + |
559 | + switch_status (Utils.CustomMode.INVALID, iface.state); |
560 | + |
561 | + nm_settings = new NM.RemoteSettings (null); |
562 | + nm_settings.connections_read.connect (() => { |
563 | + switch_status (Utils.CustomMode.INVALID, iface.state); |
564 | + }); |
565 | + |
566 | + iface.notify["state"].connect (() => { |
567 | + switch_status (Utils.CustomMode.INVALID, iface.state); |
568 | }); |
569 | } |
570 | |
571 | @@ -82,7 +87,7 @@ |
572 | row_image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DND); |
573 | row_image.pixel_size = 32; |
574 | |
575 | - row_title = new Gtk.Label (title); |
576 | + row_title = new Gtk.Label (""); |
577 | row_title.get_style_context ().add_class ("h3"); |
578 | row_title.ellipsize = Pango.EllipsizeMode.END; |
579 | row_title.halign = Gtk.Align.START; |
580 | @@ -120,45 +125,46 @@ |
581 | return icon_name; |
582 | } |
583 | |
584 | - public void switch_status (NM.DeviceState? state = null, string proxy_mode = "") { |
585 | + public void switch_status (Utils.CustomMode custom_mode, Network.State? state = null) { |
586 | if (state != null) { |
587 | switch (state) { |
588 | - case NM.DeviceState.ACTIVATED: |
589 | + case Network.State.CONNECTED_WIFI: |
590 | + case Network.State.CONNECTED_WIFI_WEAK: |
591 | + case Network.State.CONNECTED_WIFI_OK: |
592 | + case Network.State.CONNECTED_WIFI_GOOD: |
593 | + case Network.State.CONNECTED_WIFI_EXCELLENT: |
594 | + case Network.State.CONNECTED_WIRED: |
595 | status_image.icon_name = "user-available"; |
596 | break; |
597 | - case NM.DeviceState.DISCONNECTED: |
598 | + case Network.State.DISCONNECTED: |
599 | status_image.icon_name = "user-offline"; |
600 | break; |
601 | - case NM.DeviceState.FAILED: |
602 | + case Network.State.FAILED_WIRED: |
603 | + case Network.State.FAILED_WIFI: |
604 | status_image.icon_name = "user-busy"; |
605 | break; |
606 | - case NM.DeviceState.UNMANAGED: |
607 | + /*case NM.DeviceState.UNMANAGED: |
608 | status_image.icon_name = "user-invisible"; |
609 | - break; |
610 | + break;*/ |
611 | default: |
612 | - if (Utils.state_to_string (device.get_state ()) == "Unknown") { |
613 | - status_image.icon_name = "user-offline"; |
614 | - } else { |
615 | - status_image.icon_name = "user-away"; |
616 | - } |
617 | - |
618 | + status_image.icon_name = "user-away"; |
619 | break; |
620 | } |
621 | |
622 | - row_description.label = Utils.state_to_string (state); |
623 | + row_description.label = Common.Utils.network_state_to_string (state); |
624 | } |
625 | |
626 | - if (proxy_mode != "") { |
627 | - switch (proxy_mode) { |
628 | - case "none": |
629 | + if (custom_mode != Utils.CustomMode.INVALID) { |
630 | + switch (custom_mode) { |
631 | + case Utils.CustomMode.PROXY_NONE: |
632 | row_description.label = _("Disabled"); |
633 | status_image.icon_name = "user-offline"; |
634 | break; |
635 | - case "manual": |
636 | + case Utils.CustomMode.PROXY_MANUAL: |
637 | row_description.label = _("Enabled (manual mode)"); |
638 | status_image.icon_name = "user-available"; |
639 | break; |
640 | - case "auto": |
641 | + case Utils.CustomMode.PROXY_AUTO: |
642 | row_description.label = _("Enabled (auto mode)"); |
643 | status_image.icon_name = "user-available"; |
644 | break; |
645 | |
646 | === modified file 'src/Widgets/Device/DevicePage.vala' |
647 | --- src/Widgets/Device/DevicePage.vala 2015-10-08 19:04:34 +0000 |
648 | +++ src/Widgets/Device/DevicePage.vala 2016-02-12 18:38:32 +0000 |
649 | @@ -1,36 +1,33 @@ |
650 | -// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- |
651 | /*- |
652 | - * Copyright (c) 2015 Adam Bieńkowski (http://launchpad.net/switchboard-network-plug) |
653 | - * |
654 | - * This library is free software; you can redistribute it and/or |
655 | - * modify it under the terms of the GNU Library General Public |
656 | - * License as published by the Free Software Foundation; either |
657 | - * version 3 of the License, or (at your option) any later version. |
658 | - * |
659 | - * This library is distributed in the hope that it will be useful, |
660 | + * Copyright (c) 2015-2016 elementary LLC. |
661 | + * |
662 | + * This program is free software: you can redistribute it and/or modify |
663 | + * it under the terms of the GNU Lesser General Public License as published by |
664 | + * the Free Software Foundation, either version 2.1 of the License, or |
665 | + * (at your option) any later version. |
666 | + * |
667 | + * This program is distributed in the hope that it will be useful, |
668 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
669 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
670 | - * Library General Public License for more details. |
671 | - * |
672 | - * You should have received a copy of the GNU Library General Public |
673 | - * License along with this library; if not, write to the |
674 | - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
675 | - * Boston, MA 02111-1307, USA. |
676 | - * |
677 | - * Authored by: Adam Bieńkowski <donadigos159@gmail.com |
678 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
679 | + * GNU Lesser General Public License for more details. |
680 | + * |
681 | + * You should have received a copy of the GNU Lesser General Public License |
682 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
683 | + * |
684 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
685 | */ |
686 | |
687 | namespace Network.Widgets { |
688 | public class DevicePage : Network.WidgetNMInterface { |
689 | |
690 | public DevicePage (NM.Client client, NM.RemoteSettings settings, NM.Device device) { |
691 | - info_box = new info_box.from_device (device); |
692 | + info_box = new InfoBox.from_device (device); |
693 | this.init (device, info_box); |
694 | |
695 | bottom_revealer.transition_type = Gtk.RevealerTransitionType.NONE; |
696 | |
697 | this.icon_name = "network-wired"; |
698 | - this.title = Utils.type_to_string (device.get_device_type ()); |
699 | + display_title = Utils.type_to_string (device.get_device_type ()); |
700 | |
701 | var details_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); |
702 | details_box.pack_end (Utils.get_advanced_button_from_device (device), false, false, 0); |
703 | @@ -45,11 +42,11 @@ |
704 | } |
705 | |
706 | public DevicePage.from_owner (DeviceItem? owner) { |
707 | - info_box = new info_box.from_owner (owner); |
708 | + info_box = new InfoBox.from_owner (owner); |
709 | this.init (owner.get_item_device (), info_box); |
710 | |
711 | this.icon_name = owner.get_item_icon_name (); |
712 | - this.title = Utils.type_to_string (device.get_device_type ()); |
713 | + display_title = Utils.type_to_string (device.get_device_type ()); |
714 | |
715 | var details_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); |
716 | details_box.pack_start (Utils.get_advanced_button_from_device (device), false, false, 0); |
717 | |
718 | === modified file 'src/Widgets/DeviceList.vala' |
719 | --- src/Widgets/DeviceList.vala 2015-10-22 17:08:56 +0000 |
720 | +++ src/Widgets/DeviceList.vala 2016-02-12 18:38:32 +0000 |
721 | @@ -1,75 +1,64 @@ |
722 | -// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- |
723 | /*- |
724 | - * Copyright (c) 2015 Adam Bieńkowski (http://launchpad.net/switchboard-network-plug) |
725 | - * |
726 | - * This library is free software; you can redistribute it and/or |
727 | - * modify it under the terms of the GNU Library General Public |
728 | - * License as published by the Free Software Foundation; either |
729 | - * version 3 of the License, or (at your option) any later version. |
730 | - * |
731 | - * This library is distributed in the hope that it will be useful, |
732 | + * Copyright (c) 2015-2016 elementary LLC. |
733 | + * |
734 | + * This program is free software: you can redistribute it and/or modify |
735 | + * it under the terms of the GNU Lesser General Public License as published by |
736 | + * the Free Software Foundation, either version 2.1 of the License, or |
737 | + * (at your option) any later version. |
738 | + * |
739 | + * This program is distributed in the hope that it will be useful, |
740 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
741 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
742 | - * Library General Public License for more details. |
743 | - * |
744 | - * You should have received a copy of the GNU Library General Public |
745 | - * License along with this library; if not, write to the |
746 | - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
747 | - * Boston, MA 02111-1307, USA. |
748 | - * |
749 | - * Authored by: Adam Bieńkowski <donadigos159@gmail.com |
750 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
751 | + * GNU Lesser General Public License for more details. |
752 | + * |
753 | + * You should have received a copy of the GNU Lesser General Public License |
754 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
755 | + * |
756 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
757 | */ |
758 | |
759 | namespace Network.Widgets { |
760 | public class DeviceList : Gtk.ListBox { |
761 | public signal void show_no_devices (bool show); |
762 | - |
763 | - public NM.Client client; |
764 | - |
765 | - private List<DeviceItem> items; |
766 | - private DeviceItem item; |
767 | - |
768 | - private Gtk.Label settings_l; |
769 | + |
770 | + private Gtk.Label virtual_l; |
771 | private Gtk.Label devices_l; |
772 | private DeviceItem proxy; |
773 | |
774 | - private int wireless_item = 0; |
775 | - |
776 | public DeviceList () { |
777 | + virtual_l = new Gtk.Label (_("Virtual")); |
778 | + virtual_l.get_style_context ().add_class ("h4"); |
779 | + virtual_l.halign = Gtk.Align.START; |
780 | + |
781 | + devices_l = new Gtk.Label (_("Devices")); |
782 | + devices_l.get_style_context ().add_class ("h4"); |
783 | + devices_l.halign = Gtk.Align.START; |
784 | + |
785 | this.selection_mode = Gtk.SelectionMode.SINGLE; |
786 | this.activate_on_single_click = true; |
787 | this.set_header_func (update_headers); |
788 | - |
789 | - items = new List<DeviceItem> (); |
790 | - |
791 | - settings_l = new Gtk.Label (_("Virtual")); |
792 | - settings_l.get_style_context ().add_class ("h4"); |
793 | - settings_l.halign = Gtk.Align.START; |
794 | - |
795 | - devices_l = new Gtk.Label (_("Devices")); |
796 | - devices_l.get_style_context ().add_class ("h4"); |
797 | - devices_l.halign = Gtk.Align.START; |
798 | - |
799 | - bool show = (items.length () > 0); |
800 | + this.set_sort_func (sort_items); |
801 | + |
802 | + bool show = (get_children ().length () > 0); |
803 | this.show_no_devices (!show); |
804 | this.add_proxy (); |
805 | } |
806 | |
807 | public void add_device_to_list (WidgetNMInterface iface) { |
808 | - if (iface.device.get_device_type () == NM.DeviceType.WIFI) { |
809 | - string title = _("Wireless"); |
810 | - if (wireless_item > 0) { |
811 | - title += SUFFIX + wireless_item.to_string (); |
812 | - } |
813 | + DeviceItem item; |
814 | + if (iface is AbstractWifiInterface) { |
815 | + item = new DeviceItem.from_interface (iface, "network-wireless"); |
816 | + } else if (iface is AbstractHotspotInterface) { |
817 | + item = new DeviceItem.from_interface (iface, "network-wireless-hotspot"); |
818 | + item.no_show_all = true; |
819 | + iface.device.state_changed.connect ((state) => { |
820 | + item.visible = (state != NM.DeviceState.UNAVAILABLE |
821 | + && state != NM.DeviceState.UNMANAGED |
822 | + && state != NM.DeviceState.UNKNOWN); |
823 | + }); |
824 | |
825 | - item = new DeviceItem.from_interface (iface, "network-wireless", title); |
826 | - wireless_item++; |
827 | + item.type = Utils.ItemType.VIRTUAL; |
828 | } else { |
829 | - |
830 | - if (!iface.device.get_managed ()) { |
831 | - warning ("Unmanaged device, probably something that has just been added."); |
832 | - } |
833 | - |
834 | if (iface.device.get_iface ().has_prefix ("usb")) { |
835 | item = new DeviceItem.from_interface (iface, "drive-removable-media"); |
836 | } else { |
837 | @@ -77,33 +66,29 @@ |
838 | } |
839 | } |
840 | |
841 | - items.append (item); |
842 | - insert (item, (int) items.length () - 1); |
843 | + add (item); |
844 | show_all (); |
845 | } |
846 | |
847 | public void remove_device_from_list (NM.Device device) { |
848 | - foreach (var list_item in items) { |
849 | + foreach (Gtk.Widget _list_item in get_children ()) { |
850 | + var list_item = (DeviceItem)_list_item; |
851 | if (list_item.device == device) { |
852 | remove_row_from_list (list_item); |
853 | - break; |
854 | } |
855 | } |
856 | } |
857 | |
858 | public void remove_row_from_list (DeviceItem item) { |
859 | - if (item.device.get_device_type () == NM.DeviceType.WIFI && wireless_item > 0) { |
860 | - wireless_item--; |
861 | - } |
862 | - |
863 | - items.remove (item); |
864 | - this.remove (item); |
865 | + this.remove (item); |
866 | + show_all (); |
867 | } |
868 | |
869 | private void add_proxy () { |
870 | proxy = new DeviceItem (_("Proxy"), "", "preferences-system-network"); |
871 | - proxy.page = new Widgets.ProxyPage (proxy); |
872 | - proxy.type = Utils.ItemType.PROXY; |
873 | + proxy.page = new ProxyPage (proxy); |
874 | + proxy.type = Utils.ItemType.VIRTUAL; |
875 | + |
876 | this.add (proxy); |
877 | } |
878 | |
879 | @@ -111,14 +96,43 @@ |
880 | this.get_row_at_index (0).activate (); |
881 | } |
882 | |
883 | + private int sort_items (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) { |
884 | + if (((DeviceItem) row1).type == Utils.ItemType.DEVICE) { |
885 | + return -1; |
886 | + } else if (((DeviceItem) row1).type == Utils.ItemType.VIRTUAL) { |
887 | + return 1; |
888 | + } else { |
889 | + return 0; |
890 | + } |
891 | + } |
892 | + |
893 | private void update_headers (Gtk.ListBoxRow row, Gtk.ListBoxRow? before = null) { |
894 | - if (((DeviceItem) row).type != Utils.ItemType.DEVICE) { |
895 | - row.set_header (settings_l); |
896 | - } else if (row == items.nth_data (0)) { |
897 | + if (((DeviceItem) row).type == Utils.ItemType.VIRTUAL) { |
898 | + if (before != null && ((DeviceItem) before).type == Utils.ItemType.VIRTUAL) { |
899 | + return; |
900 | + } |
901 | + |
902 | + remove_headers_for_type (Utils.ItemType.VIRTUAL); |
903 | + row.set_header (virtual_l); |
904 | + } else if (((DeviceItem) row).type == Utils.ItemType.DEVICE) { |
905 | + if (before != null && ((DeviceItem) before).type == Utils.ItemType.DEVICE) { |
906 | + return; |
907 | + } |
908 | + |
909 | + remove_headers_for_type (Utils.ItemType.DEVICE); |
910 | row.set_header (devices_l); |
911 | } else { |
912 | row.set_header (null); |
913 | } |
914 | } |
915 | + |
916 | + private void remove_headers_for_type (Utils.ItemType type) { |
917 | + foreach (Gtk.Widget _item in get_children ()) { |
918 | + var item = (DeviceItem)_item; |
919 | + if (item.type == type) { |
920 | + item.set_header (null); |
921 | + } |
922 | + } |
923 | + } |
924 | } |
925 | } |
926 | |
927 | === added file 'src/Widgets/EtherInterface.vala' |
928 | --- src/Widgets/EtherInterface.vala 1970-01-01 00:00:00 +0000 |
929 | +++ src/Widgets/EtherInterface.vala 2016-02-12 18:38:32 +0000 |
930 | @@ -0,0 +1,52 @@ |
931 | +/*- |
932 | + * Copyright (c) 2015-2016 elementary LLC. |
933 | + * |
934 | + * This program is free software: you can redistribute it and/or modify |
935 | + * it under the terms of the GNU Lesser General Public License as published by |
936 | + * the Free Software Foundation, either version 2.1 of the License, or |
937 | + * (at your option) any later version. |
938 | + * |
939 | + * This program is distributed in the hope that it will be useful, |
940 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
941 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
942 | + * GNU Lesser General Public License for more details. |
943 | + * |
944 | + * You should have received a copy of the GNU Lesser General Public License |
945 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
946 | + * |
947 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
948 | + */ |
949 | + |
950 | +namespace Network.Widgets { |
951 | + public class EtherInterface : Network.AbstractEtherInterface { |
952 | + private Gtk.Revealer top_revealer; |
953 | + |
954 | + public EtherInterface (NM.Client client, NM.RemoteSettings settings, NM.Device device) { |
955 | + info_box = new InfoBox.from_device (device); |
956 | + this.init (device, info_box); |
957 | + |
958 | + this.icon_name = "network-wired"; |
959 | + |
960 | + top_revealer = new Gtk.Revealer (); |
961 | + top_revealer.valign = Gtk.Align.START; |
962 | + top_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN; |
963 | + top_revealer.add (info_box); |
964 | + |
965 | + var button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6); |
966 | + button_box.pack_end (Utils.get_advanced_button_from_device (device), false, false, 0); |
967 | + |
968 | + bottom_box.add (button_box); |
969 | + |
970 | + this.pack_start (top_revealer); |
971 | + this.pack_end (bottom_revealer, false, false, 0); |
972 | + this.show_all (); |
973 | + |
974 | + update (); |
975 | + } |
976 | + |
977 | + public override void update () { |
978 | + top_revealer.set_reveal_child (control_switch.active); |
979 | + base.update (); |
980 | + } |
981 | + } |
982 | +} |
983 | |
984 | === modified file 'src/Widgets/Footer.vala' |
985 | --- src/Widgets/Footer.vala 2015-12-31 03:49:32 +0000 |
986 | +++ src/Widgets/Footer.vala 2016-02-12 18:38:32 +0000 |
987 | @@ -1,23 +1,20 @@ |
988 | -// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- |
989 | /*- |
990 | - * Copyright (c) 2015 Adam Bieńkowski (http://launchpad.net/switchboard-network-plug) |
991 | - * |
992 | - * This library is free software; you can redistribute it and/or |
993 | - * modify it under the terms of the GNU Library General Public |
994 | - * License as published by the Free Software Foundation; either |
995 | - * version 3 of the License, or (at your option) any later version. |
996 | - * |
997 | - * This library is distributed in the hope that it will be useful, |
998 | + * Copyright (c) 2015-2016 elementary LLC. |
999 | + * |
1000 | + * This program is free software: you can redistribute it and/or modify |
1001 | + * it under the terms of the GNU Lesser General Public License as published by |
1002 | + * the Free Software Foundation, either version 2.1 of the License, or |
1003 | + * (at your option) any later version. |
1004 | + * |
1005 | + * This program is distributed in the hope that it will be useful, |
1006 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1007 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1008 | - * Library General Public License for more details. |
1009 | - * |
1010 | - * You should have received a copy of the GNU Library General Public |
1011 | - * License along with this library; if not, write to the |
1012 | - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
1013 | - * Boston, MA 02111-1307, USA. |
1014 | - * |
1015 | - * Authored by: Adam Bieńkowski <donadigos159@gmail.com |
1016 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1017 | + * GNU Lesser General Public License for more details. |
1018 | + * |
1019 | + * You should have received a copy of the GNU Lesser General Public License |
1020 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1021 | + * |
1022 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
1023 | */ |
1024 | |
1025 | namespace Network { |
1026 | |
1027 | === added directory 'src/Widgets/Hotspot' |
1028 | === added file 'src/Widgets/Hotspot/HotspotDialog.vala' |
1029 | --- src/Widgets/Hotspot/HotspotDialog.vala 1970-01-01 00:00:00 +0000 |
1030 | +++ src/Widgets/Hotspot/HotspotDialog.vala 2016-02-12 18:38:32 +0000 |
1031 | @@ -0,0 +1,227 @@ |
1032 | +/*- |
1033 | + * Copyright (c) 2015-2016 elementary LLC. |
1034 | + * |
1035 | + * This program is free software: you can redistribute it and/or modify |
1036 | + * it under the terms of the GNU Lesser General Public License as published by |
1037 | + * the Free Software Foundation, either version 2.1 of the License, or |
1038 | + * (at your option) any later version. |
1039 | + * |
1040 | + * This program is distributed in the hope that it will be useful, |
1041 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1042 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1043 | + * GNU Lesser General Public License for more details. |
1044 | + * |
1045 | + * You should have received a copy of the GNU Lesser General Public License |
1046 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1047 | + * |
1048 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
1049 | + */ |
1050 | + |
1051 | +namespace Network.Widgets { |
1052 | + public class HotspotDialog : Gtk.Dialog { |
1053 | + private const string NEW_ID = "0"; |
1054 | + private Gtk.Entry ssid_entry; |
1055 | + private Gtk.Entry key_entry; |
1056 | + |
1057 | + private Gtk.Label ssid_label; |
1058 | + private Gtk.Label key_label; |
1059 | + |
1060 | + private Gtk.ComboBoxText conn_combo; |
1061 | + |
1062 | + private Gtk.CheckButton check_btn; |
1063 | + private Gtk.Label dumb; |
1064 | + |
1065 | + private Gtk.Button create_btn; |
1066 | + |
1067 | + private HashTable<string, NM.Connection> conn_hash; |
1068 | + private unowned List<NM.Connection> available; |
1069 | + |
1070 | + public HotspotDialog (NM.AccessPoint? active, List<NM.Connection> _available) { |
1071 | + this.available = _available; |
1072 | + this.deletable = false; |
1073 | + this.resizable = false; |
1074 | + this.border_width = 6; |
1075 | + |
1076 | + conn_hash = new HashTable<string, NM.Connection> (str_hash, str_equal); |
1077 | + |
1078 | + var content_area = this.get_content_area (); |
1079 | + content_area.halign = content_area.valign = Gtk.Align.CENTER; |
1080 | + |
1081 | + var main_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); |
1082 | + var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 6); |
1083 | + |
1084 | + vbox.margin_left = vbox.margin_right = 6; |
1085 | + |
1086 | + string? ssid_str = null; |
1087 | + if (active != null) { |
1088 | + ssid_str = NM.Utils.ssid_to_utf8 (active.get_ssid ()); |
1089 | + } else { |
1090 | + ssid_str = _("current"); |
1091 | + } |
1092 | + |
1093 | + var title = new Gtk.Label ("<span weight='bold' size='larger'>" + _("Wireless Hotspot") + "</span>"); |
1094 | + title.use_markup = true; |
1095 | + title.halign = Gtk.Align.START; |
1096 | + |
1097 | + var image = new Gtk.Image.from_icon_name ("network-wireless-hotspot", Gtk.IconSize.DIALOG); |
1098 | + image.valign = Gtk.Align.START; |
1099 | + main_box.add (image); |
1100 | + |
1101 | + var info_label = new Gtk.Label (_("Enabling Wireless Hotspot will disconnect from %s network.").printf (ssid_str) + "\n" + |
1102 | + _("You will not be able to connect to a wireless network while Hotspot is active.")); |
1103 | + info_label.halign = Gtk.Align.START; |
1104 | + info_label.margin_top = 6; |
1105 | + info_label.use_markup = true; |
1106 | + |
1107 | + var grid = new Gtk.Grid (); |
1108 | + grid.hexpand = true; |
1109 | + grid.row_spacing = 6; |
1110 | + grid.column_spacing = 12; |
1111 | + grid.vexpand_set = true; |
1112 | + |
1113 | + ssid_entry = new Gtk.Entry (); |
1114 | + ssid_entry.hexpand = true; |
1115 | + ssid_entry.text = get_ssid_for_hotspot (); |
1116 | + |
1117 | + key_entry = new Gtk.Entry (); |
1118 | + key_entry.hexpand = true; |
1119 | + key_entry.visibility = false; |
1120 | + key_entry.secondary_icon_tooltip_text = _("Password needs to be at least 8 characters long."); |
1121 | + |
1122 | + check_btn = new Gtk.CheckButton.with_label (_("Show Password")); |
1123 | + check_btn.toggled.connect (() => { |
1124 | + key_entry.visibility = check_btn.active; |
1125 | + }); |
1126 | + |
1127 | + ssid_entry.changed.connect (update); |
1128 | + key_entry.changed.connect (update); |
1129 | + |
1130 | + ssid_label = new Gtk.Label (_("Network Name:")); |
1131 | + ssid_label.halign = Gtk.Align.END; |
1132 | + |
1133 | + key_label = new Gtk.Label (_("Password:")); |
1134 | + key_label.halign = Gtk.Align.END; |
1135 | + |
1136 | + conn_combo = new Gtk.ComboBoxText (); |
1137 | + conn_combo.append (NEW_ID, _("New…")); |
1138 | + int i = 1; |
1139 | + foreach (var connection in available) { |
1140 | + var setting_wireless = connection.get_setting_wireless (); |
1141 | + conn_combo.append (i.to_string (), NM.Utils.ssid_to_utf8 (setting_wireless.get_ssid ())); |
1142 | + conn_hash.insert (i.to_string (), connection); |
1143 | + i++; |
1144 | + } |
1145 | + |
1146 | + conn_combo.active_id = NEW_ID; |
1147 | + conn_combo.changed.connect (update); |
1148 | + |
1149 | + var conn_label = new Gtk.Label (_("Connection:")); |
1150 | + conn_label.halign = Gtk.Align.END; |
1151 | + |
1152 | + grid.attach (conn_label, 0, 0, 1, 1); |
1153 | + grid.attach_next_to (conn_combo, conn_label, Gtk.PositionType.RIGHT, 1, 1); |
1154 | + |
1155 | + dumb = new Gtk.Label (""); |
1156 | + |
1157 | + grid.attach_next_to (ssid_label, conn_label, Gtk.PositionType.BOTTOM, 1, 1); |
1158 | + grid.attach_next_to (ssid_entry, ssid_label, Gtk.PositionType.RIGHT, 1, 1); |
1159 | + grid.attach_next_to (key_label, ssid_label, Gtk.PositionType.BOTTOM, 1, 1); |
1160 | + grid.attach_next_to (key_entry, key_label, Gtk.PositionType.RIGHT, 1, 1); |
1161 | + grid.attach_next_to (dumb, key_label, Gtk.PositionType.BOTTOM, 1, 1); |
1162 | + grid.attach_next_to (check_btn, dumb, Gtk.PositionType.RIGHT, 1, 1); |
1163 | + |
1164 | + var cancel_btn = new Gtk.Button.with_label (_("Cancel")); |
1165 | + create_btn = new Gtk.Button.with_label (_("Enable Hotspot")); |
1166 | + if (active != null) { |
1167 | + create_btn.label = _("Switch to Hotspot"); |
1168 | + } |
1169 | + |
1170 | + create_btn.get_style_context ().add_class ("suggested-action"); |
1171 | + |
1172 | + this.add_action_widget (cancel_btn, 0); |
1173 | + this.add_action_widget (create_btn, 1); |
1174 | + |
1175 | + vbox.add (title); |
1176 | + vbox.add (info_label); |
1177 | + vbox.add (grid); |
1178 | + |
1179 | + update (); |
1180 | + |
1181 | + main_box.add (vbox); |
1182 | + content_area.add (main_box); |
1183 | + this.show_all (); |
1184 | + } |
1185 | + |
1186 | + public ByteArray get_ssid () { |
1187 | + var byte_array = new ByteArray (); |
1188 | + byte_array.append (ssid_entry.get_text ().data); |
1189 | + return byte_array; |
1190 | + } |
1191 | + |
1192 | + public string get_key () { |
1193 | + return key_entry.get_text (); |
1194 | + } |
1195 | + |
1196 | + public NM.Connection? get_selected_connection () { |
1197 | + return conn_hash[conn_combo.get_active_id ()]; |
1198 | + } |
1199 | + |
1200 | + private string get_ssid_for_hotspot () { |
1201 | + string hostname = ""; |
1202 | + try { |
1203 | + Process.spawn_command_line_sync ("hostname", out hostname, null, null); |
1204 | + } catch (SpawnError e) { |
1205 | + warning ("%s\n", e.message); |
1206 | + } |
1207 | + |
1208 | + return hostname.strip ().replace ("\n", ""); |
1209 | + } |
1210 | + |
1211 | + private void update () { |
1212 | + bool sensitive = (conn_combo.get_active_id () == NEW_ID); |
1213 | + ssid_label.sensitive = sensitive; |
1214 | + key_label.sensitive = sensitive; |
1215 | + |
1216 | + ssid_entry.sensitive = sensitive; |
1217 | + key_entry.sensitive = sensitive; |
1218 | + |
1219 | + check_btn.sensitive = sensitive; |
1220 | + dumb.sensitive = sensitive; |
1221 | + |
1222 | + string? secret = null; |
1223 | + if (get_selected_connection () != null) { |
1224 | + var setting_wireless_security = get_selected_connection ().get_setting_wireless_security (); |
1225 | + |
1226 | + string key_mgmt = setting_wireless_security.get_key_mgmt (); |
1227 | + if (key_mgmt == "none") { |
1228 | + secret = setting_wireless_security.get_wep_key (0); |
1229 | + } else if (key_mgmt == "wpa-psk" || |
1230 | + key_mgmt == "wpa-none") { |
1231 | + secret = setting_wireless_security.get_psk (); |
1232 | + } |
1233 | + |
1234 | + if (secret == null) { |
1235 | + var connection = get_selected_connection (); |
1236 | + Utils.Hotspot.update_secrets (((NM.RemoteConnection) connection), update); |
1237 | + } |
1238 | + } |
1239 | + |
1240 | + if (conn_combo.get_active_id () != NEW_ID) { |
1241 | + ssid_entry.text = NM.Utils.ssid_to_utf8 (get_selected_connection ().get_setting_wireless ().get_ssid ()); |
1242 | + if (secret == null) { |
1243 | + secret = ""; |
1244 | + } |
1245 | + |
1246 | + key_entry.text = secret; |
1247 | + } |
1248 | + |
1249 | + create_btn.sensitive = ((ssid_entry.get_text () != "" && key_entry.get_text ().to_utf8 ().length >= 8) || !sensitive); |
1250 | + |
1251 | + if (key_entry.get_text ().to_utf8 ().length < 8 && key_entry.get_text () != "") { |
1252 | + key_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "process-error-symbolic"); |
1253 | + } else { |
1254 | + key_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, ""); |
1255 | + } |
1256 | + } |
1257 | + } |
1258 | +} |
1259 | \ No newline at end of file |
1260 | |
1261 | === added file 'src/Widgets/HotspotInterface.vala' |
1262 | --- src/Widgets/HotspotInterface.vala 1970-01-01 00:00:00 +0000 |
1263 | +++ src/Widgets/HotspotInterface.vala 2016-02-12 18:38:32 +0000 |
1264 | @@ -0,0 +1,169 @@ |
1265 | +/*- |
1266 | + * Copyright (c) 2015-2016 elementary LLC. |
1267 | + * |
1268 | + * This program is free software: you can redistribute it and/or modify |
1269 | + * it under the terms of the GNU Lesser General Public License as published by |
1270 | + * the Free Software Foundation, either version 2.1 of the License, or |
1271 | + * (at your option) any later version. |
1272 | + * |
1273 | + * This program is distributed in the hope that it will be useful, |
1274 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1275 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1276 | + * GNU Lesser General Public License for more details. |
1277 | + * |
1278 | + * You should have received a copy of the GNU Lesser General Public License |
1279 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1280 | + * |
1281 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
1282 | + */ |
1283 | + |
1284 | + namespace Network.Widgets { |
1285 | + public class HotspotInterface : Network.AbstractHotspotInterface { |
1286 | + |
1287 | + private NM.RemoteSettings nm_settings; |
1288 | + private Gtk.Revealer hotspot_revealer; |
1289 | + private Gtk.Button hotspot_settings_btn; |
1290 | + private Gtk.Label ssid_label; |
1291 | + private Gtk.Label key_label; |
1292 | + private bool switch_updating = false; |
1293 | + |
1294 | + public HotspotInterface (WifiInterface _root_iface) { |
1295 | + root_iface = _root_iface; |
1296 | + nm_settings = _root_iface.get_nm_settings (); |
1297 | + info_box = new InfoBox.from_device (root_iface.device); |
1298 | + this.init (root_iface.device, info_box); |
1299 | + |
1300 | + this.icon_name = "network-wireless-hotspot"; |
1301 | + |
1302 | + hotspot_revealer = new Gtk.Revealer (); |
1303 | + hotspot_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN; |
1304 | + |
1305 | + hotspot_settings_btn = Utils.get_advanced_button_from_device (device, _("Hotspot Settings…")); |
1306 | + |
1307 | + var hinfo_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6); |
1308 | + |
1309 | + ssid_label = new Gtk.Label (""); |
1310 | + ssid_label.halign = Gtk.Align.START; |
1311 | + |
1312 | + key_label = new Gtk.Label (""); |
1313 | + key_label.halign = Gtk.Align.START; |
1314 | + |
1315 | + hinfo_box.add (ssid_label); |
1316 | + hinfo_box.add (key_label); |
1317 | + hotspot_revealer.add (hinfo_box); |
1318 | + |
1319 | + bottom_revealer = new Gtk.Revealer (); |
1320 | + |
1321 | + var button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6); |
1322 | + button_box.pack_end (hotspot_settings_btn, false, false, 0); |
1323 | + bottom_revealer.add (button_box); |
1324 | + |
1325 | + nm_settings.connections_read.connect (update); |
1326 | + device.state_changed.connect (update); |
1327 | + |
1328 | + update (); |
1329 | + |
1330 | + this.add (hotspot_revealer); |
1331 | + this.pack_end (bottom_revealer, false, false); |
1332 | + this.show_all (); |
1333 | + } |
1334 | + |
1335 | + protected override void update () { |
1336 | + if (hotspot_settings_btn != null) { |
1337 | + hotspot_settings_btn.sensitive = Utils.Hotspot.get_device_is_hotspot (root_iface.wifi_device, root_iface.nm_settings); |
1338 | + } |
1339 | + |
1340 | + update_hotspot_info (); |
1341 | + update_switch (); |
1342 | + base.update (); |
1343 | + } |
1344 | + |
1345 | + protected override void update_switch () { |
1346 | + switch_updating = true; |
1347 | + control_switch.active = state == Network.State.CONNECTED_WIFI; |
1348 | + switch_updating = false; |
1349 | + } |
1350 | + |
1351 | + protected override void control_switch_activated () { |
1352 | + if (switch_updating) { |
1353 | + switch_updating = false; |
1354 | + return; |
1355 | + } |
1356 | + |
1357 | + var wifi_device = (NM.DeviceWifi)device; |
1358 | + if (!control_switch.active && Utils.Hotspot.get_device_is_hotspot (wifi_device, nm_settings)) { |
1359 | + Utils.Hotspot.deactivate_hotspot (wifi_device); |
1360 | + } else { |
1361 | + var hotspot_dialog = new HotspotDialog (wifi_device.get_active_access_point (), get_hotspot_connections ()); |
1362 | + hotspot_dialog.response.connect ((response) => { |
1363 | + if (response == 1) { |
1364 | + Utils.Hotspot.activate_hotspot (wifi_device, |
1365 | + hotspot_dialog.get_ssid (), |
1366 | + hotspot_dialog.get_key (), |
1367 | + hotspot_dialog.get_selected_connection ()); |
1368 | + |
1369 | + } else { |
1370 | + switch_updating = true; |
1371 | + control_switch.active = false; |
1372 | + } |
1373 | + }); |
1374 | + |
1375 | + hotspot_dialog.run (); |
1376 | + hotspot_dialog.destroy (); |
1377 | + } |
1378 | + } |
1379 | + |
1380 | + private void update_hotspot_info () { |
1381 | + var wifi_device = (NM.DeviceWifi)device; |
1382 | + bool hotspot_mode = Utils.Hotspot.get_device_is_hotspot (wifi_device, nm_settings); |
1383 | + |
1384 | + var mode = Utils.CustomMode.HOTSPOT_DISABLED; |
1385 | + if (hotspot_mode) { |
1386 | + mode = Utils.CustomMode.HOTSPOT_ENABLED; |
1387 | + } |
1388 | + |
1389 | + hotspot_revealer.set_reveal_child (hotspot_mode); |
1390 | + |
1391 | + if (hotspot_mode) { |
1392 | + var connection = nm_settings.get_connection_by_path (wifi_device.get_active_connection ().get_connection ()); |
1393 | + |
1394 | + var setting_wireless = connection.get_setting_wireless (); |
1395 | + ssid_label.label = _("Network Name (SSID): %s").printf (NM.Utils.ssid_to_utf8 (setting_wireless.get_ssid ())); |
1396 | + |
1397 | + var setting_wireless_security = connection.get_setting_wireless_security (); |
1398 | + |
1399 | + string key_mgmt = setting_wireless_security.get_key_mgmt (); |
1400 | + string? secret = null; |
1401 | + string security = ""; |
1402 | + if (key_mgmt == "none") { |
1403 | + secret = setting_wireless_security.get_wep_key (0); |
1404 | + security = _("(WEP)"); |
1405 | + } else if (key_mgmt == "wpa-psk" || |
1406 | + key_mgmt == "wpa-none") { |
1407 | + security = _("(WPA)"); |
1408 | + secret = setting_wireless_security.get_psk (); |
1409 | + } |
1410 | + |
1411 | + if (secret == null) { |
1412 | + Utils.Hotspot.update_secrets (connection, update); |
1413 | + return; |
1414 | + } |
1415 | + |
1416 | + key_label.label = _("Password %s: %s").printf (security, secret); |
1417 | + } |
1418 | + } |
1419 | + |
1420 | + private List<NM.Connection> get_hotspot_connections () { |
1421 | + var list = new List<NM.Connection> (); |
1422 | + var connections = nm_settings.list_connections (); |
1423 | + |
1424 | + foreach (var connection in connections) { |
1425 | + if (Utils.Hotspot.get_connection_is_hotspot (connection)) { |
1426 | + list.append (connection); |
1427 | + } |
1428 | + } |
1429 | + |
1430 | + return list; |
1431 | + } |
1432 | + } |
1433 | +} |
1434 | |
1435 | === modified file 'src/Widgets/InfoBox.vala' |
1436 | --- src/Widgets/InfoBox.vala 2015-10-20 20:34:36 +0000 |
1437 | +++ src/Widgets/InfoBox.vala 2016-02-12 18:38:32 +0000 |
1438 | @@ -1,23 +1,20 @@ |
1439 | -// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- |
1440 | /*- |
1441 | - * Copyright (c) 2015 Adam Bieńkowski (http://launchpad.net/switchboard-network-plug) |
1442 | - * |
1443 | - * This library is free software; you can redistribute it and/or |
1444 | - * modify it under the terms of the GNU Library General Public |
1445 | - * License as published by the Free Software Foundation; either |
1446 | - * version 3 of the License, or (at your option) any later version. |
1447 | - * |
1448 | - * This library is distributed in the hope that it will be useful, |
1449 | + * Copyright (c) 2015-2016 elementary LLC. |
1450 | + * |
1451 | + * This program is free software: you can redistribute it and/or modify |
1452 | + * it under the terms of the GNU Lesser General Public License as published by |
1453 | + * the Free Software Foundation, either version 2.1 of the License, or |
1454 | + * (at your option) any later version. |
1455 | + * |
1456 | + * This program is distributed in the hope that it will be useful, |
1457 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1458 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1459 | - * Library General Public License for more details. |
1460 | - * |
1461 | - * You should have received a copy of the GNU Library General Public |
1462 | - * License along with this library; if not, write to the |
1463 | - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
1464 | - * Boston, MA 02111-1307, USA. |
1465 | - * |
1466 | - * Authored by: Adam Bieńkowski <donadigos159@gmail.com |
1467 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1468 | + * GNU Lesser General Public License for more details. |
1469 | + * |
1470 | + * You should have received a copy of the GNU Lesser General Public License |
1471 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1472 | + * |
1473 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
1474 | */ |
1475 | |
1476 | namespace Network.Widgets { |
1477 | @@ -59,8 +56,6 @@ |
1478 | this.orientation = Gtk.Orientation.HORIZONTAL; |
1479 | this.spacing = 1; |
1480 | |
1481 | - var main_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 1); |
1482 | - |
1483 | var info_grid = new Gtk.Grid (); |
1484 | info_grid.column_spacing = 12; |
1485 | info_grid.row_spacing = 6; |
1486 | @@ -68,13 +63,15 @@ |
1487 | var activity_info = new Gtk.Grid (); |
1488 | activity_info.expand = true; |
1489 | activity_info.column_spacing = 12; |
1490 | - activity_info.row_spacing = 6; |
1491 | + activity_info.row_spacing = 8; |
1492 | |
1493 | var sent_head = new Gtk.Label (sent_l); |
1494 | + sent_head.margin_start = 6; |
1495 | sent = new Gtk.Label (""); |
1496 | sent.halign = Gtk.Align.END; |
1497 | |
1498 | var received_head = new Gtk.Label (received_l); |
1499 | + received_head.margin_start = 8; |
1500 | received = new Gtk.Label (""); |
1501 | |
1502 | fix_halign (Gtk.Align.END, activity_info, sent_head, |
1503 | @@ -123,8 +120,6 @@ |
1504 | info_grid.attach_next_to (broadcast_head, router_head, Gtk.PositionType.BOTTOM); |
1505 | info_grid.attach_next_to (broadcast, broadcast_head, Gtk.PositionType.RIGHT); |
1506 | |
1507 | - main_box.add (info_grid); |
1508 | - |
1509 | device.state_changed.connect (() => { |
1510 | update_status (); |
1511 | info_changed (); |
1512 | @@ -132,7 +127,7 @@ |
1513 | |
1514 | update_status (); |
1515 | |
1516 | - this.add (main_box); |
1517 | + this.add (info_grid); |
1518 | this.pack_end (activity_info, false, true, 0); |
1519 | this.show_all (); |
1520 | } |
1521 | @@ -157,8 +152,9 @@ |
1522 | broadcast.label = _("Unknown"); |
1523 | } |
1524 | |
1525 | - if (owner != null) |
1526 | + if (owner != null) { |
1527 | update_sidebar (owner); |
1528 | + } |
1529 | |
1530 | this.show_all (); |
1531 | } |
1532 | @@ -168,7 +164,7 @@ |
1533 | do { |
1534 | ((Gtk.Misc) wid).xalign = 1; |
1535 | wid = list.arg (); |
1536 | - } while(wid != null); |
1537 | + } while (wid != null); |
1538 | } |
1539 | |
1540 | private void fix_halign (Gtk.Align val, ...) { |
1541 | @@ -178,6 +174,7 @@ |
1542 | if (wid == null) { |
1543 | break; |
1544 | } |
1545 | + |
1546 | wid.halign = val; |
1547 | } |
1548 | } |
1549 | |
1550 | === modified file 'src/Widgets/InfoScreen.vala' |
1551 | --- src/Widgets/InfoScreen.vala 2015-07-18 16:56:50 +0000 |
1552 | +++ src/Widgets/InfoScreen.vala 2016-02-12 18:38:32 +0000 |
1553 | @@ -1,23 +1,20 @@ |
1554 | -// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- |
1555 | /*- |
1556 | - * Copyright (c) 2015 Adam Bieńkowski (http://launchpad.net/switchboard-network-plug) |
1557 | - * |
1558 | - * This library is free software; you can redistribute it and/or |
1559 | - * modify it under the terms of the GNU Library General Public |
1560 | - * License as published by the Free Software Foundation; either |
1561 | - * version 3 of the License, or (at your option) any later version. |
1562 | - * |
1563 | - * This library is distributed in the hope that it will be useful, |
1564 | + * Copyright (c) 2015-2016 elementary LLC. |
1565 | + * |
1566 | + * This program is free software: you can redistribute it and/or modify |
1567 | + * it under the terms of the GNU Lesser General Public License as published by |
1568 | + * the Free Software Foundation, either version 2.1 of the License, or |
1569 | + * (at your option) any later version. |
1570 | + * |
1571 | + * This program is distributed in the hope that it will be useful, |
1572 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1573 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1574 | - * Library General Public License for more details. |
1575 | - * |
1576 | - * You should have received a copy of the GNU Library General Public |
1577 | - * License along with this library; if not, write to the |
1578 | - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
1579 | - * Boston, MA 02111-1307, USA. |
1580 | - * |
1581 | - * Authored by: Adam Bieńkowski <donadigos159@gmail.com |
1582 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1583 | + * GNU Lesser General Public License for more details. |
1584 | + * |
1585 | + * You should have received a copy of the GNU Lesser General Public License |
1586 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1587 | + * |
1588 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
1589 | */ |
1590 | |
1591 | namespace Network { |
1592 | |
1593 | === modified file 'src/Widgets/Page.vala' |
1594 | --- src/Widgets/Page.vala 2015-10-09 19:12:42 +0000 |
1595 | +++ src/Widgets/Page.vala 2016-02-12 18:38:32 +0000 |
1596 | @@ -1,21 +1,18 @@ |
1597 | -// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- |
1598 | /*- |
1599 | - * Copyright (c) 2015 Adam Bieńkowski (http://launchpad.net/switchboard-network-plug) |
1600 | - * |
1601 | - * This library is free software; you can redistribute it and/or |
1602 | - * modify it under the terms of the GNU Library General Public |
1603 | - * License as published by the Free Software Foundation; either |
1604 | - * version 3 of the License, or (at your option) any later version. |
1605 | - * |
1606 | - * This library is distributed in the hope that it will be useful, |
1607 | + * Copyright (c) 2015-2016 elementary LLC. |
1608 | + * |
1609 | + * This program is free software: you can redistribute it and/or modify |
1610 | + * it under the terms of the GNU Lesser General Public License as published by |
1611 | + * the Free Software Foundation, either version 2.1 of the License, or |
1612 | + * (at your option) any later version. |
1613 | + * |
1614 | + * This program is distributed in the hope that it will be useful, |
1615 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1616 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1617 | - * Library General Public License for more details. |
1618 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1619 | + * GNU Lesser General Public License for more details. |
1620 | * |
1621 | - * You should have received a copy of the GNU Library General Public |
1622 | - * License along with this library; if not, write to the |
1623 | - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
1624 | - * Boston, MA 02111-1307, USA. |
1625 | + * You should have received a copy of the GNU Lesser General Public License |
1626 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1627 | * |
1628 | * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
1629 | * xapantu |
1630 | @@ -41,20 +38,8 @@ |
1631 | } |
1632 | } |
1633 | |
1634 | - private string _title; |
1635 | - public string title { |
1636 | - get { |
1637 | - return _title; |
1638 | - } |
1639 | - |
1640 | - set { |
1641 | - _title = value; |
1642 | - device_label.label = _title; |
1643 | - } |
1644 | - } |
1645 | - |
1646 | private Gtk.Image device_img; |
1647 | - private Gtk.Label device_label; |
1648 | + protected Gtk.Label device_label; |
1649 | |
1650 | protected Gtk.Revealer bottom_revealer; |
1651 | protected Gtk.Box bottom_box; |
1652 | |
1653 | === modified file 'src/Widgets/Proxy/ProxyConfigurationPage.vala' |
1654 | --- src/Widgets/Proxy/ProxyConfigurationPage.vala 2016-01-04 19:56:07 +0000 |
1655 | +++ src/Widgets/Proxy/ProxyConfigurationPage.vala 2016-02-12 18:38:32 +0000 |
1656 | @@ -1,5 +1,23 @@ |
1657 | +/*- |
1658 | + * Copyright (c) 2015-2016 elementary LLC. |
1659 | + * |
1660 | + * This program is free software: you can redistribute it and/or modify |
1661 | + * it under the terms of the GNU Lesser General Public License as published by |
1662 | + * the Free Software Foundation, either version 2.1 of the License, or |
1663 | + * (at your option) any later version. |
1664 | + * |
1665 | + * This program is distributed in the hope that it will be useful, |
1666 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1667 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1668 | + * GNU Lesser General Public License for more details. |
1669 | + * |
1670 | + * You should have received a copy of the GNU Lesser General Public License |
1671 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1672 | + * |
1673 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
1674 | + */ |
1675 | + |
1676 | namespace Network.Widgets { |
1677 | - |
1678 | public class ConfigurationPage : Gtk.Box { |
1679 | private const string DEFAULT_PROXY = "host:port"; |
1680 | private bool syntax_error = false; |
1681 | |
1682 | === modified file 'src/Widgets/Proxy/ProxyExceptionsPage.vala' |
1683 | --- src/Widgets/Proxy/ProxyExceptionsPage.vala 2015-08-03 00:16:24 +0000 |
1684 | +++ src/Widgets/Proxy/ProxyExceptionsPage.vala 2016-02-12 18:38:32 +0000 |
1685 | @@ -1,3 +1,22 @@ |
1686 | +/*- |
1687 | + * Copyright (c) 2015-2016 elementary LLC. |
1688 | + * |
1689 | + * This program is free software: you can redistribute it and/or modify |
1690 | + * it under the terms of the GNU Lesser General Public License as published by |
1691 | + * the Free Software Foundation, either version 2.1 of the License, or |
1692 | + * (at your option) any later version. |
1693 | + * |
1694 | + * This program is distributed in the hope that it will be useful, |
1695 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1696 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1697 | + * GNU Lesser General Public License for more details. |
1698 | + * |
1699 | + * You should have received a copy of the GNU Lesser General Public License |
1700 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1701 | + * |
1702 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
1703 | + */ |
1704 | + |
1705 | namespace Network.Widgets { |
1706 | public class ExecepionsPage : Gtk.Box { |
1707 | private Gtk.ListBox ignored_list; |
1708 | |
1709 | === modified file 'src/Widgets/Proxy/ProxyPage.vala' |
1710 | --- src/Widgets/Proxy/ProxyPage.vala 2015-10-20 20:34:36 +0000 |
1711 | +++ src/Widgets/Proxy/ProxyPage.vala 2016-02-12 18:38:32 +0000 |
1712 | @@ -1,3 +1,22 @@ |
1713 | +/*- |
1714 | + * Copyright (c) 2015-2016 elementary LLC. |
1715 | + * |
1716 | + * This program is free software: you can redistribute it and/or modify |
1717 | + * it under the terms of the GNU Lesser General Public License as published by |
1718 | + * the Free Software Foundation, either version 2.1 of the License, or |
1719 | + * (at your option) any later version. |
1720 | + * |
1721 | + * This program is distributed in the hope that it will be useful, |
1722 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1723 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1724 | + * GNU Lesser General Public License for more details. |
1725 | + * |
1726 | + * You should have received a copy of the GNU Lesser General Public License |
1727 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1728 | + * |
1729 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
1730 | + */ |
1731 | + |
1732 | namespace Network.Widgets { |
1733 | public class ProxyPage : Gtk.Box { |
1734 | public Gtk.Stack stack; |
1735 | @@ -34,7 +53,23 @@ |
1736 | } |
1737 | |
1738 | public void update_mode () { |
1739 | - owner.switch_status (null, proxy_settings.mode); |
1740 | + var mode = Utils.CustomMode.INVALID; |
1741 | + switch (proxy_settings.mode) { |
1742 | + case "none": |
1743 | + mode = Utils.CustomMode.PROXY_NONE; |
1744 | + break; |
1745 | + case "manual": |
1746 | + mode = Utils.CustomMode.PROXY_MANUAL; |
1747 | + break; |
1748 | + case "auto": |
1749 | + mode = Utils.CustomMode.PROXY_AUTO; |
1750 | + break; |
1751 | + default: |
1752 | + mode = Utils.CustomMode.INVALID; |
1753 | + break; |
1754 | + } |
1755 | + |
1756 | + owner.switch_status (mode); |
1757 | } |
1758 | } |
1759 | } |
1760 | |
1761 | === modified file 'src/Widgets/WifiInterface.vala' |
1762 | --- src/Widgets/WifiInterface.vala 2015-10-09 19:12:42 +0000 |
1763 | +++ src/Widgets/WifiInterface.vala 2016-02-12 18:38:32 +0000 |
1764 | @@ -1,23 +1,20 @@ |
1765 | -// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- |
1766 | /*- |
1767 | - * Copyright (c) 2015 Adam Bieńkowski (http://launchpad.net/switchboard-network-plug) |
1768 | - * |
1769 | - * This library is free software; you can redistribute it and/or |
1770 | - * modify it under the terms of the GNU Library General Public |
1771 | - * License as published by the Free Software Foundation; either |
1772 | - * version 3 of the License, or (at your option) any later version. |
1773 | - * |
1774 | - * This library is distributed in the hope that it will be useful, |
1775 | + * Copyright (c) 2015-2016 elementary LLC. |
1776 | + * |
1777 | + * This program is free software: you can redistribute it and/or modify |
1778 | + * it under the terms of the GNU Lesser General Public License as published by |
1779 | + * the Free Software Foundation, either version 2.1 of the License, or |
1780 | + * (at your option) any later version. |
1781 | + * |
1782 | + * This program is distributed in the hope that it will be useful, |
1783 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1784 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1785 | - * Library General Public License for more details. |
1786 | - * |
1787 | - * You should have received a copy of the GNU Library General Public |
1788 | - * License along with this library; if not, write to the |
1789 | - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
1790 | - * Boston, MA 02111-1307, USA. |
1791 | - * |
1792 | - * Authored by: Adam Bieńkowski <donadigos159@gmail.com |
1793 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1794 | + * GNU Lesser General Public License for more details. |
1795 | + * |
1796 | + * You should have received a copy of the GNU Lesser General Public License |
1797 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1798 | + * |
1799 | + * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
1800 | */ |
1801 | |
1802 | using Network.Widgets; |
1803 | @@ -25,24 +22,21 @@ |
1804 | namespace Network { |
1805 | public class WifiInterface : AbstractWifiInterface { |
1806 | protected Gtk.Frame connected_frame; |
1807 | + protected Gtk.Stack list_stack; |
1808 | + protected Gtk.ScrolledWindow scrolled; |
1809 | + protected Gtk.Box hotspot_mode_box; |
1810 | protected Gtk.Box? connected_box = null; |
1811 | protected Gtk.Revealer top_revealer; |
1812 | protected Gtk.Button disconnect_btn; |
1813 | protected Gtk.Button settings_btn; |
1814 | + protected Gtk.Button hidden_btn; |
1815 | protected Gtk.ToggleButton info_btn; |
1816 | protected Gtk.Popover popover; |
1817 | |
1818 | - public WifiInterface (NM.Client nm_client, NM.RemoteSettings settings, NM.Device device_) { |
1819 | - info_box = new InfoBox.from_device (device_); |
1820 | + public WifiInterface (NM.Client nm_client, NM.RemoteSettings settings, NM.Device _device) { |
1821 | + info_box = new InfoBox.from_device (_device); |
1822 | info_box.margin = 12; |
1823 | - this.init (device_, info_box); |
1824 | - |
1825 | - var css_provider = new Gtk.CssProvider (); |
1826 | - try { |
1827 | - css_provider.load_from_data ("GtkFrame {\nbackground: #ffffff;\n}", -1); |
1828 | - } catch (Error e) { |
1829 | - warning ("%s\n", e.message); |
1830 | - } |
1831 | + this.init (_device, info_box); |
1832 | |
1833 | popover = new Gtk.Popover (info_btn); |
1834 | popover.position = Gtk.PositionType.BOTTOM; |
1835 | @@ -52,45 +46,68 @@ |
1836 | }); |
1837 | |
1838 | connected_frame = new Gtk.Frame (null); |
1839 | - connected_frame.get_style_context ().add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); |
1840 | + connected_frame.override_background_color (0, { 255, 255, 255, 255 }); |
1841 | |
1842 | top_revealer = new Gtk.Revealer (); |
1843 | top_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN; |
1844 | top_revealer.add (connected_frame); |
1845 | |
1846 | - init_wifi_interface (nm_client, settings, device_); |
1847 | + init_wifi_interface (nm_client, settings, device); |
1848 | |
1849 | this.icon_name = "network-wireless"; |
1850 | - this.title = _("Wireless"); |
1851 | this.spacing = 0; |
1852 | |
1853 | control_box.margin_bottom = 12; |
1854 | |
1855 | + list_stack = new Gtk.Stack (); |
1856 | + |
1857 | + hotspot_mode_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); |
1858 | + hotspot_mode_box.visible = true; |
1859 | + hotspot_mode_box.valign = Gtk.Align.CENTER; |
1860 | + |
1861 | + var main_frame = new Gtk.Frame (null); |
1862 | + main_frame.margin_bottom = 24; |
1863 | + main_frame.margin_top = 12; |
1864 | + main_frame.vexpand = true; |
1865 | + main_frame.override_background_color (0, { 255, 255, 255, 255 }); |
1866 | + |
1867 | + var hotspot_mode = construct_placeholder_label (_("This device is in Hotspot Mode"), true); |
1868 | + var hotspot_mode_desc = construct_placeholder_label (_("Turn off the Hotspot Mode to connect to other Access Points."), false); |
1869 | + hotspot_mode_box.add (hotspot_mode); |
1870 | + hotspot_mode_box.add (hotspot_mode_desc); |
1871 | + |
1872 | wifi_list.selection_mode = Gtk.SelectionMode.SINGLE; |
1873 | - wifi_list.activate_on_single_click = false; |
1874 | + wifi_list.activate_on_single_click = false; |
1875 | + wifi_list.visible = true; |
1876 | |
1877 | - var scrolled = new Gtk.ScrolledWindow (null, null); |
1878 | - scrolled.margin_bottom = 24; |
1879 | - scrolled.margin_top = 12; |
1880 | + scrolled = new Gtk.ScrolledWindow (null, null); |
1881 | scrolled.add (wifi_list); |
1882 | - scrolled.vexpand = true; |
1883 | - scrolled.shadow_type = Gtk.ShadowType.OUT; |
1884 | + |
1885 | + list_stack.add (hotspot_mode_box); |
1886 | + list_stack.add (scrolled); |
1887 | + list_stack.visible_child = scrolled; |
1888 | + |
1889 | + main_frame.add (list_stack); |
1890 | |
1891 | var button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6); |
1892 | |
1893 | - var hidden_btn = new Gtk.Button.with_label (_("Connect to Hidden Network…")); |
1894 | + hidden_btn = new Gtk.Button.with_label (_("Connect to Hidden Network…")); |
1895 | hidden_btn.clicked.connect (connect_to_hidden); |
1896 | |
1897 | button_box.pack_start (hidden_btn, false, false, 0); |
1898 | |
1899 | - update (); |
1900 | - |
1901 | bottom_box.add (button_box); |
1902 | |
1903 | this.add (top_revealer); |
1904 | - this.add (scrolled); |
1905 | + this.add (main_frame); |
1906 | this.add (bottom_revealer); |
1907 | this.show_all (); |
1908 | + |
1909 | + update (); |
1910 | + } |
1911 | + |
1912 | + public NM.RemoteSettings get_nm_settings () { |
1913 | + return nm_settings; |
1914 | } |
1915 | |
1916 | public override void update () { |
1917 | @@ -107,11 +124,23 @@ |
1918 | info_btn.sensitive = sensitive; |
1919 | } |
1920 | |
1921 | + if (hidden_btn != null) { |
1922 | + hidden_btn.sensitive = (state != State.WIRED_UNPLUGGED); |
1923 | + } |
1924 | + |
1925 | var old_active = active_wifi_item; |
1926 | |
1927 | base.update (); |
1928 | |
1929 | - top_revealer.set_reveal_child (wifi_device.get_active_access_point () != null); |
1930 | + bool is_hotspot = Utils.Hotspot.get_device_is_hotspot (wifi_device, nm_settings); |
1931 | + |
1932 | + top_revealer.set_reveal_child (wifi_device.get_active_access_point () != null && !is_hotspot); |
1933 | + |
1934 | + if (is_hotspot) { |
1935 | + list_stack.visible_child = hotspot_mode_box; |
1936 | + } else { |
1937 | + list_stack.visible_child = scrolled; |
1938 | + } |
1939 | |
1940 | if (wifi_device.get_active_access_point () == null && old_active != null) { |
1941 | old_active.no_show_all = false; |
1942 | @@ -186,7 +215,7 @@ |
1943 | |
1944 | protected override void control_switch_activated () { |
1945 | var active = control_switch.active; |
1946 | - if (active != !software_locked) { |
1947 | + if (active == software_locked) { |
1948 | rfkill.set_software_lock (RFKillDeviceType.WLAN, !active); |
1949 | client.wireless_set_enabled (active); |
1950 | } |
1951 | |
1952 | === modified file 'src/common/Utils.vala' |
1953 | --- src/common/Utils.vala 2015-10-09 19:12:42 +0000 |
1954 | +++ src/common/Utils.vala 2016-02-12 18:38:32 +0000 |
1955 | @@ -17,6 +17,7 @@ |
1956 | |
1957 | public enum Network.State { |
1958 | DISCONNECTED, |
1959 | + WIRED_UNPLUGGED, |
1960 | CONNECTED_WIRED, |
1961 | CONNECTED_WIFI, |
1962 | CONNECTED_WIFI_WEAK, |
1963 | @@ -28,3 +29,29 @@ |
1964 | FAILED_WIRED, |
1965 | FAILED_WIFI |
1966 | } |
1967 | + |
1968 | +namespace Network.Common.Utils { |
1969 | + public string network_state_to_string (Network.State state) { |
1970 | + switch(state) { |
1971 | + case Network.State.DISCONNECTED: |
1972 | + return _("Disconnected"); |
1973 | + case Network.State.CONNECTED_WIFI: |
1974 | + case Network.State.CONNECTED_WIFI_WEAK: |
1975 | + case Network.State.CONNECTED_WIFI_OK: |
1976 | + case Network.State.CONNECTED_WIFI_GOOD: |
1977 | + case Network.State.CONNECTED_WIFI_EXCELLENT: |
1978 | + case Network.State.CONNECTED_WIRED: |
1979 | + return _("Connected"); |
1980 | + case Network.State.FAILED_WIRED: |
1981 | + case Network.State.FAILED_WIFI: |
1982 | + return _("Failed"); |
1983 | + case Network.State.CONNECTING_WIFI: |
1984 | + case Network.State.CONNECTING_WIRED: |
1985 | + return _("Connecting"); |
1986 | + case Network.State.WIRED_UNPLUGGED: |
1987 | + return _("Cable unplugged"); |
1988 | + } |
1989 | + return _("Unknown"); |
1990 | + } |
1991 | +} |
1992 | + |
1993 | |
1994 | === added file 'src/common/Widgets/AbstractEtherInterface.vala' |
1995 | --- src/common/Widgets/AbstractEtherInterface.vala 1970-01-01 00:00:00 +0000 |
1996 | +++ src/common/Widgets/AbstractEtherInterface.vala 2016-02-12 18:38:32 +0000 |
1997 | @@ -0,0 +1,77 @@ |
1998 | +/* |
1999 | + * Copyright (c) 2015 Wingpanel Developers (http://launchpad.net/wingpanel) |
2000 | + * |
2001 | + * This program is free software: you can redistribute it and/or modify |
2002 | + * it under the terms of the GNU Library General Public License as published by |
2003 | + * the Free Software Foundation, either version 2.1 of the License, or |
2004 | + * (at your option) any later version. |
2005 | + * |
2006 | + * This program is distributed in the hope that it will be useful, |
2007 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2008 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2009 | + * GNU Library General Public License for more details. |
2010 | + * |
2011 | + * You should have received a copy of the GNU Library General Public License |
2012 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2013 | + */ |
2014 | + |
2015 | +public abstract class Network.AbstractEtherInterface : Network.WidgetNMInterface { |
2016 | + |
2017 | + public override void update_name (int count) { |
2018 | + var name = device.get_description (); |
2019 | + |
2020 | + /* At least for docker related interfaces, which can be fairly common */ |
2021 | + if (name.has_prefix ("veth")) { |
2022 | + display_title = _("Virtual network: %s").printf(name); |
2023 | + } |
2024 | + else { |
2025 | + if (count <= 1) { |
2026 | + display_title = _("Ethernet"); |
2027 | + } |
2028 | + else { |
2029 | + display_title = name; |
2030 | + } |
2031 | + } |
2032 | + } |
2033 | + |
2034 | + public override void update () { |
2035 | + base.update (); |
2036 | + |
2037 | + switch (device.state) { |
2038 | + case NM.DeviceState.UNKNOWN: |
2039 | + case NM.DeviceState.UNMANAGED: |
2040 | + case NM.DeviceState.FAILED: |
2041 | + state = State.FAILED_WIRED; |
2042 | + break; |
2043 | + |
2044 | + /* physically not connected */ |
2045 | + case NM.DeviceState.UNAVAILABLE: |
2046 | + state = State.WIRED_UNPLUGGED; |
2047 | + break; |
2048 | + |
2049 | + /* virtually not working */ |
2050 | + case NM.DeviceState.DISCONNECTED: |
2051 | + state = State.DISCONNECTED; |
2052 | + break; |
2053 | + |
2054 | + case NM.DeviceState.DEACTIVATING: |
2055 | + state = State.FAILED_WIRED; |
2056 | + break; |
2057 | + |
2058 | + /* configuration */ |
2059 | + case NM.DeviceState.PREPARE: |
2060 | + case NM.DeviceState.CONFIG: |
2061 | + case NM.DeviceState.NEED_AUTH: |
2062 | + case NM.DeviceState.IP_CONFIG: |
2063 | + case NM.DeviceState.IP_CHECK: |
2064 | + case NM.DeviceState.SECONDARIES: |
2065 | + state = State.CONNECTING_WIRED; |
2066 | + break; |
2067 | + |
2068 | + /* working */ |
2069 | + case NM.DeviceState.ACTIVATED: |
2070 | + state = State.CONNECTED_WIRED; |
2071 | + break; |
2072 | + } |
2073 | + } |
2074 | +} |
2075 | |
2076 | === added file 'src/common/Widgets/AbstractHotspotInterface.vala' |
2077 | --- src/common/Widgets/AbstractHotspotInterface.vala 1970-01-01 00:00:00 +0000 |
2078 | +++ src/common/Widgets/AbstractHotspotInterface.vala 2016-02-12 18:38:32 +0000 |
2079 | @@ -0,0 +1,40 @@ |
2080 | +/* |
2081 | + * Copyright (c) 2015 Wingpanel Developers (http://launchpad.net/wingpanel) |
2082 | + * |
2083 | + * This program is free software: you can redistribute it and/or modify |
2084 | + * it under the terms of the GNU Library General Public License as published by |
2085 | + * the Free Software Foundation, either version 2.1 of the License, or |
2086 | + * (at your option) any later version. |
2087 | + * |
2088 | + * This program is distributed in the hope that it will be useful, |
2089 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2090 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2091 | + * GNU Library General Public License for more details. |
2092 | + * |
2093 | + * You should have received a copy of the GNU Library General Public License |
2094 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2095 | + */ |
2096 | + |
2097 | +public abstract class Network.AbstractHotspotInterface : Network.WidgetNMInterface { |
2098 | + protected AbstractWifiInterface root_iface; |
2099 | + |
2100 | + public override void update_name (int count) { |
2101 | + if (count <= 1) { |
2102 | + display_title = _("Hotspot"); |
2103 | + } |
2104 | + else { |
2105 | + display_title = _("Hotspot %s").printf (device.get_description ()); |
2106 | + } |
2107 | + } |
2108 | + |
2109 | + public override void update () { |
2110 | +#if PLUG_NETWORK |
2111 | + if (Utils.Hotspot.get_device_is_hotspot (root_iface.wifi_device, root_iface.nm_settings)) { |
2112 | + state = State.CONNECTED_WIFI; |
2113 | + } |
2114 | + else { |
2115 | + state = State.DISCONNECTED; |
2116 | + } |
2117 | +#endif |
2118 | + } |
2119 | +} |
2120 | |
2121 | === modified file 'src/common/Widgets/AbstractWifiInterface.vala' |
2122 | --- src/common/Widgets/AbstractWifiInterface.vala 2015-10-22 16:46:13 +0000 |
2123 | +++ src/common/Widgets/AbstractWifiInterface.vala 2016-02-12 18:38:32 +0000 |
2124 | @@ -17,13 +17,13 @@ |
2125 | |
2126 | public abstract class Network.AbstractWifiInterface : Network.WidgetNMInterface { |
2127 | protected RFKillManager rfkill; |
2128 | - protected NM.DeviceWifi? wifi_device; |
2129 | + public NM.DeviceWifi? wifi_device; |
2130 | protected NM.AccessPoint? active_ap; |
2131 | |
2132 | protected Gtk.ListBox wifi_list; |
2133 | |
2134 | protected NM.Client nm_client; |
2135 | - protected NM.RemoteSettings nm_settings; |
2136 | + public NM.RemoteSettings nm_settings; |
2137 | |
2138 | protected WifiMenuItem? active_wifi_item { get; set; } |
2139 | protected WifiMenuItem? blank_item = null; |
2140 | @@ -39,13 +39,10 @@ |
2141 | this.nm_client = nm_client; |
2142 | this.nm_settings = nm_settings; |
2143 | device = _device; |
2144 | - wifi_device = device as NM.DeviceWifi; |
2145 | + wifi_device = (NM.DeviceWifi)device; |
2146 | blank_item = new WifiMenuItem.blank (); |
2147 | active_wifi_item = null; |
2148 | |
2149 | - placeholder = new Gtk.Stack (); |
2150 | - placeholder.visible = true; |
2151 | - |
2152 | var no_aps_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6); |
2153 | no_aps_box.visible = true; |
2154 | no_aps_box.valign = Gtk.Align.CENTER; |
2155 | @@ -82,16 +79,11 @@ |
2156 | scanning_box.visible = true; |
2157 | scanning_box.valign = Gtk.Align.CENTER; |
2158 | |
2159 | - |
2160 | placeholder.add_named (no_aps_box, "no-aps"); |
2161 | placeholder.add_named (wireless_off_box, "wireless-off"); |
2162 | placeholder.add_named (scanning_box, "scanning"); |
2163 | placeholder.visible_child_name = "no-aps"; |
2164 | |
2165 | - wifi_list = new Gtk.ListBox (); |
2166 | - wifi_list.set_sort_func (sort_func); |
2167 | - wifi_list.set_placeholder (placeholder); |
2168 | - |
2169 | /* Monitor killswitch status */ |
2170 | rfkill = new RFKillManager (); |
2171 | rfkill.open (); |
2172 | @@ -99,7 +91,9 @@ |
2173 | rfkill.device_changed.connect (update); |
2174 | rfkill.device_deleted.connect (update); |
2175 | |
2176 | - wifi_device.notify["active-access-point"].connect (() => { update (); }); |
2177 | + nm_settings.connections_read.connect (update); |
2178 | + |
2179 | + wifi_device.notify["active-access-point"].connect (update); |
2180 | wifi_device.access_point_added.connect (access_point_added_cb); |
2181 | wifi_device.access_point_removed.connect (access_point_removed_cb); |
2182 | wifi_device.state_changed.connect (update); |
2183 | @@ -112,7 +106,24 @@ |
2184 | update(); |
2185 | } |
2186 | |
2187 | - Gtk.Label construct_placeholder_label (string text, bool title) { |
2188 | + construct { |
2189 | + placeholder = new Gtk.Stack (); |
2190 | + placeholder.visible = true; |
2191 | + |
2192 | + wifi_list = new Gtk.ListBox (); |
2193 | + wifi_list.set_sort_func (sort_func); |
2194 | + wifi_list.set_placeholder (placeholder); |
2195 | + } |
2196 | + |
2197 | + public override void update_name (int count) { |
2198 | + if (count <= 1) { |
2199 | + display_title = _("Wireless"); |
2200 | + } else { |
2201 | + display_title = device.get_description (); |
2202 | + } |
2203 | + } |
2204 | + |
2205 | + protected Gtk.Label construct_placeholder_label (string text, bool title) { |
2206 | var label = new Gtk.Label (text); |
2207 | label.visible = true; |
2208 | label.use_markup = true; |
2209 | @@ -157,7 +168,6 @@ |
2210 | item.user_action.connect (wifi_activate_cb); |
2211 | |
2212 | wifi_list.add (item); |
2213 | - |
2214 | wifi_list.show_all (); |
2215 | |
2216 | update (); |
2217 | @@ -241,6 +251,13 @@ |
2218 | } |
2219 | |
2220 | public override void update () { |
2221 | +#if PLUG_NETWORK |
2222 | + if (Utils.Hotspot.get_device_is_hotspot (wifi_device, nm_settings)) { |
2223 | + state = State.DISCONNECTED; |
2224 | + return; |
2225 | + } |
2226 | +#endif |
2227 | + |
2228 | switch (wifi_device.state) { |
2229 | case NM.DeviceState.UNKNOWN: |
2230 | case NM.DeviceState.UNMANAGED: |
2231 | @@ -275,6 +292,7 @@ |
2232 | |
2233 | case NM.DeviceState.ACTIVATED: |
2234 | set_scan_placeholder (); |
2235 | + |
2236 | /* That can happen if active_ap has not been added yet, at startup. */ |
2237 | if (active_ap != null) { |
2238 | state = strength_to_state(active_ap.get_strength()); |
2239 | @@ -298,6 +316,7 @@ |
2240 | if (device.hardware_lock) |
2241 | hardware_locked = true; |
2242 | } |
2243 | + |
2244 | locked = hardware_locked || software_locked; |
2245 | |
2246 | update_active_ap (); |
2247 | @@ -319,6 +338,12 @@ |
2248 | cancel_scan (); |
2249 | wifi_device.request_scan_simple (null); |
2250 | timeout_scan = Timeout.add(5000, () => { |
2251 | +#if PLUG_NETWORK |
2252 | + if (Utils.Hotspot.get_device_is_hotspot (wifi_device, nm_settings)) { |
2253 | + return false; |
2254 | + } |
2255 | +#endif |
2256 | + |
2257 | timeout_scan = 0; |
2258 | placeholder.visible_child_name = "no-aps"; |
2259 | return false; |
2260 | |
2261 | === modified file 'src/common/Widgets/NMVisualizer.vala' |
2262 | --- src/common/Widgets/NMVisualizer.vala 2015-08-02 12:30:11 +0000 |
2263 | +++ src/common/Widgets/NMVisualizer.vala 2016-02-12 18:38:32 +0000 |
2264 | @@ -56,20 +56,43 @@ |
2265 | break; |
2266 | } |
2267 | } |
2268 | + |
2269 | + update_interfaces_names (); |
2270 | + } |
2271 | + |
2272 | + void update_interfaces_names () { |
2273 | + var count_type = new Gee.HashMap<string, int?> (); |
2274 | + foreach (var iface in network_interface) { |
2275 | + var type = iface.get_type ().name (); |
2276 | + if (count_type.has_key (type)) { |
2277 | + count_type[type] = count_type[type] + 1; |
2278 | + } |
2279 | + else { |
2280 | + count_type[type] = 1; |
2281 | + } |
2282 | + } |
2283 | + |
2284 | + foreach (var iface in network_interface) { |
2285 | + var type = iface.get_type ().name (); |
2286 | + iface.update_name (count_type [type]); |
2287 | + } |
2288 | } |
2289 | |
2290 | private void device_added_cb (NM.Device device) { |
2291 | WidgetNMInterface? widget_interface = null; |
2292 | +#if PLUG_NETWORK |
2293 | + WidgetNMInterface? hotspot_interface = null; |
2294 | +#endif |
2295 | |
2296 | if (device is NM.DeviceWifi) { |
2297 | widget_interface = new WifiInterface (nm_client, nm_settings, device); |
2298 | +#if PLUG_NETWORK |
2299 | + hotspot_interface = new HotspotInterface((WifiInterface)widget_interface); |
2300 | +#endif |
2301 | + |
2302 | debug ("Wifi interface added"); |
2303 | } else if (device is NM.DeviceEthernet) { |
2304 | -#if INDICATOR_NETWORK |
2305 | widget_interface = new EtherInterface (nm_client, nm_settings, device); |
2306 | -#else |
2307 | - widget_interface = new Widgets.DevicePage (nm_client, nm_settings, device); |
2308 | -#endif |
2309 | debug ("Ethernet interface added"); |
2310 | } else { |
2311 | debug ("Unknown device: %s\n", device.get_device_type().to_string()); |
2312 | @@ -83,6 +106,19 @@ |
2313 | |
2314 | } |
2315 | |
2316 | +#if PLUG_NETWORK |
2317 | + if (hotspot_interface != null) { |
2318 | + // Implementation call |
2319 | + network_interface.append (hotspot_interface); |
2320 | + add_interface(hotspot_interface); |
2321 | + hotspot_interface.notify["state"].connect(update_state); |
2322 | + |
2323 | + } |
2324 | +#endif |
2325 | + |
2326 | + update_interfaces_names (); |
2327 | + |
2328 | + |
2329 | update_all(); |
2330 | |
2331 | show_all(); |
2332 | |
2333 | === modified file 'src/common/Widgets/WidgetNMInterface.vala' |
2334 | --- src/common/Widgets/WidgetNMInterface.vala 2015-08-01 22:16:50 +0000 |
2335 | +++ src/common/Widgets/WidgetNMInterface.vala 2016-02-12 18:38:32 +0000 |
2336 | @@ -23,6 +23,16 @@ |
2337 | #endif |
2338 | public Network.State state { get; protected set; default = Network.State.DISCONNECTED; } |
2339 | |
2340 | + public string display_title { get; protected set; default = _("Unknown device"); } |
2341 | + |
2342 | +#if PLUG_NETWORK |
2343 | + construct { |
2344 | + notify["display-title"].connect ( () => { |
2345 | + device_label.label = display_title; |
2346 | + }); |
2347 | + } |
2348 | +#endif |
2349 | + |
2350 | #if INDICATOR_NETWORK |
2351 | public Wingpanel.Widgets.Separator? sep = null; |
2352 | |
2353 | @@ -41,4 +51,8 @@ |
2354 | public virtual void update () { |
2355 | #endif |
2356 | } |
2357 | + |
2358 | + public virtual void update_name (int count) { |
2359 | + display_title = _("Unknown type: %s ").printf (device.get_description ()); |
2360 | + } |
2361 | } |
So, the branch improved a lot of the behaviour of the Plug and It's fantastic work, but there are some issues:
* When I disable Ethernet Interface, in the sidebar the state is "Failed" (and red dot) which seems wrong because I turned it off by the switch, and it should be "Disconnected".
* UI: Also in Ethernet Interface, revealers seem to not reveal, but immediately show after switching the state of the device...
I commented on some places, where I could point out fixes.
But overall it's really good branch, and definetely improves a lot of the Plug itself, I would like to see a review from others like Daniel to ensure that there are no other issues.
When I got some time, I will commit fixes for the above ;)