Merge lp:~donadigo/switchboard-plug-networking/connect-to-hidden into lp:~elementary-pantheon/switchboard-plug-networking/trunk

Proposed by Adam Bieńkowski
Status: Merged
Approved by: xapantu
Approved revision: 138
Merged at revision: 137
Proposed branch: lp:~donadigo/switchboard-plug-networking/connect-to-hidden
Merge into: lp:~elementary-pantheon/switchboard-plug-networking/trunk
Diff against target: 203 lines (+74/-49)
2 files modified
src/Widgets/WifiInterface.vala (+72/-41)
src/libnm-gtk.vapi (+2/-8)
To merge this branch: bzr merge lp:~donadigo/switchboard-plug-networking/connect-to-hidden
Reviewer Review Type Date Requested Status
xapantu (community) Approve
Review via email: mp+267457@code.launchpad.net

Commit message

* Connect to hidden access point.
* One method to connect to create connection.
* Code clean.
* Use static, main client in WifiInterface.vala

Description of the change

This branch enables functionality to connect to hidden access point. The connecting is now also unified to one method.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Can connect to hidden AP. Works :D

138. By Adam Bieńkowski

Remove unrefing

Revision history for this message
xapantu (xapantu) wrote :

Looks good (however I can't test that).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Widgets/WifiInterface.vala'
--- src/Widgets/WifiInterface.vala 2015-08-06 20:43:28 +0000
+++ src/Widgets/WifiInterface.vala 2015-08-10 12:09:47 +0000
@@ -25,12 +25,12 @@
25namespace Network {25namespace Network {
26 public class WifiInterface : AbstractWifiInterface {26 public class WifiInterface : AbstractWifiInterface {
27 27
28 public WifiInterface (NM.Client client, NM.RemoteSettings settings, NM.Device device_) {28 public WifiInterface (NM.Client nm_client, NM.RemoteSettings settings, NM.Device device_) {
29 info_box = new InfoBox.from_device (device_);29 info_box = new InfoBox.from_device (device_);
30 info_box.no_show_all = true;30 info_box.no_show_all = true;
31 this.init (device_, info_box);31 this.init (device_, info_box);
32 32
33 init_wifi_interface (client, settings, device_);33 init_wifi_interface (nm_client, settings, device_);
3434
35 this.icon_name = "network-wireless";35 this.icon_name = "network-wireless";
36 this.title = _("Wi-Fi Network");36 this.title = _("Wi-Fi Network");
@@ -63,11 +63,7 @@
63 });63 });
6464
65 var hidden_btn = new Gtk.Button.with_label (_("Connect to Hidden Network…"));65 var hidden_btn = new Gtk.Button.with_label (_("Connect to Hidden Network…"));
66 hidden_btn.clicked.connect (() => {66 hidden_btn.clicked.connect (connect_to_hidden);
67 var remote_settings = new NM.RemoteSettings (null);
68 var hidden_dialog = NMGtk.new_wifi_dialog_for_hidden (client, remote_settings);
69 hidden_dialog.run ();
70 });
7167
72 var end_btn_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);68 var end_btn_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
73 end_btn_box.homogeneous = true;69 end_btn_box.homogeneous = true;
@@ -97,7 +93,7 @@
97 var active = control_switch.active;93 var active = control_switch.active;
98 if (active != !software_locked) {94 if (active != !software_locked) {
99 rfkill.set_software_lock (RFKillDeviceType.WLAN, !active);95 rfkill.set_software_lock (RFKillDeviceType.WLAN, !active);
100 nm_client.wireless_set_enabled (active);96 client.wireless_set_enabled (active);
101 }97 }
102 }98 }
10399
@@ -111,15 +107,13 @@
111107
112 var valid_connection = get_valid_connection (row.ap, ap_connections);108 var valid_connection = get_valid_connection (row.ap, ap_connections);
113 if (valid_connection != null) {109 if (valid_connection != null) {
114 nm_client.activate_connection (valid_connection, wifi_device, row.ap.get_path (), null);110 client.activate_connection (valid_connection, wifi_device, row.ap.get_path (), null);
115 return;111 return;
116 }112 }
117 113
118 var setting_wireless = new NM.SettingWireless ();114 var setting_wireless = new NM.SettingWireless ();
119 if (setting_wireless.add_seen_bssid (row.ap.get_bssid ())) {115 if (setting_wireless.add_seen_bssid (row.ap.get_bssid ())) {
120 if (row.is_secured) {116 if (row.is_secured) {
121 var remote_settings = new NM.RemoteSettings (null);
122
123 var connection = new NM.Connection ();117 var connection = new NM.Connection ();
124 var s_con = new NM.SettingConnection ();118 var s_con = new NM.SettingConnection ();
125 s_con.@set (NM.SettingConnection.UUID, NM.Utils.uuid_generate ());119 s_con.@set (NM.SettingConnection.UUID, NM.Utils.uuid_generate ());
@@ -133,35 +127,21 @@
133 s_wsec.@set (NM.SettingWirelessSecurity.KEY_MGMT, "wpa-psk");127 s_wsec.@set (NM.SettingWirelessSecurity.KEY_MGMT, "wpa-psk");
134 connection.add_setting (s_wsec);128 connection.add_setting (s_wsec);
135129
136 var dialog = new NMAWifiDialog (client,130 var wifi_dialog = new NMAWifiDialog (client,
137 remote_settings,131 nm_settings,
138 connection,132 connection,
139 wifi_device,133 wifi_device,
140 row.ap,134 row.ap,
141 false);135 false);
142 136
143 dialog.response.connect ((response) => {137 set_wifi_dialog_cb (wifi_dialog);
144 if (response != Gtk.ResponseType.OK) {138 wifi_dialog.run ();
145 return;139 wifi_dialog.destroy ();
146 }
147
148 NM.Device dialog_device;
149 NM.AccessPoint dialog_ap;
150 var dialog_connection = dialog.get_connection (out dialog_device, out dialog_ap);
151
152 client.add_and_activate_connection (dialog_connection,
153 dialog_device,
154 dialog_ap.get_path (),
155 finish_connection_callback);
156 });
157
158 dialog.run ();
159 dialog.destroy ();
160 } else {140 } else {
161 client.add_and_activate_connection (new NM.Connection (),141 client.add_and_activate_connection (new NM.Connection (),
162 wifi_device,142 wifi_device,
163 row.ap.get_path (),143 row.ap.get_path (),
164 finish_connection_callback);144 finish_connection_cb);
165 } 145 }
166 }146 }
167 }147 }
@@ -169,7 +149,7 @@
169 /* Do an update at the next iteration of the main loop, so as every149 /* Do an update at the next iteration of the main loop, so as every
170 * signal is flushed (for instance signals responsible for radio button150 * signal is flushed (for instance signals responsible for radio button
171 * checked) */151 * checked) */
172 Idle.add( () => { update (); return false; });152 Idle.add(() => { update (); return false; });
173 }153 }
174 }154 }
175155
@@ -183,15 +163,66 @@
183 return null;163 return null;
184 }164 }
185165
186 private void finish_connection_callback (NM.Client _client,166 private void finish_connection_cb (NM.Client? cb_client,
187 NM.ActiveConnection connection,167 NM.ActiveConnection? cb_connection,
188 string new_connection_path,168 string? new_connection_path,
189 Error error) {169 Error? error) {
190 bool success = false;170 if (error != null && error.code != 0) {
191 _client.get_active_connections ().@foreach ((c) => {171 warning ("%s\n", error.message);
192 if (c == connection) {172 }
193 success = true;173 }
194 }174
175 private void connect_to_hidden () {
176 var hidden_dialog = new NMAWifiDialog.for_other (client, nm_settings);
177 set_wifi_dialog_cb (hidden_dialog);
178 hidden_dialog.run ();
179 hidden_dialog.destroy ();
180 }
181
182 private void set_wifi_dialog_cb (NMAWifiDialog wifi_dialog) {
183 wifi_dialog.response.connect ((response) => {
184 if (response == Gtk.ResponseType.OK) {
185 NM.Connection? fuzzy = null;
186 NM.Device dialog_device;
187 NM.AccessPoint? dialog_ap = null;
188 var dialog_connection = wifi_dialog.get_connection (out dialog_device, out dialog_ap);
189
190 foreach (var possible in nm_settings.list_connections ()) {
191 if (dialog_connection.compare (possible, NM.SettingCompareFlags.FUZZY | NM.SettingCompareFlags.IGNORE_ID)) {
192 fuzzy = possible;
193 }
194 }
195
196 string? path = null;
197 if (dialog_ap != null) {
198 path = dialog_ap.get_path ();
199 }
200
201 if (fuzzy != null) {
202 client.activate_connection (fuzzy, wifi_device, path, null);
203 } else {
204 var connection_setting = dialog_connection.get_setting (typeof (NM.Setting));;
205
206 string? mode = null;
207 var setting_wireless = (NM.SettingWireless) dialog_connection.get_setting (typeof (NM.SettingWireless));
208 if (setting_wireless != null) {
209 mode = setting_wireless.get_mode ();
210 }
211
212 if (mode == "adhoc") {
213 if (connection_setting == null) {
214 connection_setting = new NM.SettingConnection ();
215 }
216
217 dialog_connection.add_setting (connection_setting);
218 }
219
220 client.add_and_activate_connection (dialog_connection,
221 dialog_device,
222 path,
223 finish_connection_cb);
224 }
225 }
195 });226 });
196 }227 }
197 }228 }
198229
=== modified file 'src/libnm-gtk.vapi'
--- src/libnm-gtk.vapi 2015-08-01 18:41:32 +0000
+++ src/libnm-gtk.vapi 2015-08-10 12:09:47 +0000
@@ -1,12 +1,6 @@
1[CCode (cheader_filename = "nm-wifi-dialog.h")]1[CCode (cheader_filename = "nm-wifi-dialog.h")]
2class NMAWifiDialog : Gtk.Dialog {2class NMAWifiDialog : Gtk.Dialog {
3 public NMAWifiDialog (NM.Client client, NM.RemoteSettings settings, NM.Connection connection, NM.Device device, NM.AccessPoint ap, bool secrets_only);3 public NMAWifiDialog (NM.Client client, NM.RemoteSettings settings, NM.Connection 0connection, NM.Device device, NM.AccessPoint ap, bool secrets_only);
4 public NMAWifiDialog.for_other (NM.Client client, NM.RemoteSettings settings);
4 public NM.Connection get_connection (out NM.Device device, out NM.AccessPoint ap);5 public NM.Connection get_connection (out NM.Device device, out NM.AccessPoint ap);
5}
6
7
8[CCode (cprefix = "NMGtk", gir_namespace = "NMGtk", gir_version = "1.0", lower_case_cprefix = "nmgtk_")]
9namespace NMGtk {
10 [CCode (cheader_filename = "libnm-gtk/nm-wifi-dialog.h", cname = "nma_wifi_dialog_new_for_other")]
11 public Gtk.Dialog new_wifi_dialog_for_hidden (NM.Client client, NM.RemoteSettings settings);
12}6}

Subscribers

People subscribed via source and target branches

to all changes: