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
1=== modified file 'src/Widgets/WifiInterface.vala'
2--- src/Widgets/WifiInterface.vala 2015-08-06 20:43:28 +0000
3+++ src/Widgets/WifiInterface.vala 2015-08-10 12:09:47 +0000
4@@ -25,12 +25,12 @@
5 namespace Network {
6 public class WifiInterface : AbstractWifiInterface {
7
8- public WifiInterface (NM.Client client, NM.RemoteSettings settings, NM.Device device_) {
9+ public WifiInterface (NM.Client nm_client, NM.RemoteSettings settings, NM.Device device_) {
10 info_box = new InfoBox.from_device (device_);
11 info_box.no_show_all = true;
12 this.init (device_, info_box);
13
14- init_wifi_interface (client, settings, device_);
15+ init_wifi_interface (nm_client, settings, device_);
16
17 this.icon_name = "network-wireless";
18 this.title = _("Wi-Fi Network");
19@@ -63,11 +63,7 @@
20 });
21
22 var hidden_btn = new Gtk.Button.with_label (_("Connect to Hidden Network…"));
23- hidden_btn.clicked.connect (() => {
24- var remote_settings = new NM.RemoteSettings (null);
25- var hidden_dialog = NMGtk.new_wifi_dialog_for_hidden (client, remote_settings);
26- hidden_dialog.run ();
27- });
28+ hidden_btn.clicked.connect (connect_to_hidden);
29
30 var end_btn_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
31 end_btn_box.homogeneous = true;
32@@ -97,7 +93,7 @@
33 var active = control_switch.active;
34 if (active != !software_locked) {
35 rfkill.set_software_lock (RFKillDeviceType.WLAN, !active);
36- nm_client.wireless_set_enabled (active);
37+ client.wireless_set_enabled (active);
38 }
39 }
40
41@@ -111,15 +107,13 @@
42
43 var valid_connection = get_valid_connection (row.ap, ap_connections);
44 if (valid_connection != null) {
45- nm_client.activate_connection (valid_connection, wifi_device, row.ap.get_path (), null);
46+ client.activate_connection (valid_connection, wifi_device, row.ap.get_path (), null);
47 return;
48 }
49
50 var setting_wireless = new NM.SettingWireless ();
51 if (setting_wireless.add_seen_bssid (row.ap.get_bssid ())) {
52 if (row.is_secured) {
53- var remote_settings = new NM.RemoteSettings (null);
54-
55 var connection = new NM.Connection ();
56 var s_con = new NM.SettingConnection ();
57 s_con.@set (NM.SettingConnection.UUID, NM.Utils.uuid_generate ());
58@@ -133,35 +127,21 @@
59 s_wsec.@set (NM.SettingWirelessSecurity.KEY_MGMT, "wpa-psk");
60 connection.add_setting (s_wsec);
61
62- var dialog = new NMAWifiDialog (client,
63- remote_settings,
64+ var wifi_dialog = new NMAWifiDialog (client,
65+ nm_settings,
66 connection,
67 wifi_device,
68 row.ap,
69 false);
70
71- dialog.response.connect ((response) => {
72- if (response != Gtk.ResponseType.OK) {
73- return;
74- }
75-
76- NM.Device dialog_device;
77- NM.AccessPoint dialog_ap;
78- var dialog_connection = dialog.get_connection (out dialog_device, out dialog_ap);
79-
80- client.add_and_activate_connection (dialog_connection,
81- dialog_device,
82- dialog_ap.get_path (),
83- finish_connection_callback);
84- });
85-
86- dialog.run ();
87- dialog.destroy ();
88+ set_wifi_dialog_cb (wifi_dialog);
89+ wifi_dialog.run ();
90+ wifi_dialog.destroy ();
91 } else {
92 client.add_and_activate_connection (new NM.Connection (),
93 wifi_device,
94 row.ap.get_path (),
95- finish_connection_callback);
96+ finish_connection_cb);
97 }
98 }
99 }
100@@ -169,7 +149,7 @@
101 /* Do an update at the next iteration of the main loop, so as every
102 * signal is flushed (for instance signals responsible for radio button
103 * checked) */
104- Idle.add( () => { update (); return false; });
105+ Idle.add(() => { update (); return false; });
106 }
107 }
108
109@@ -183,15 +163,66 @@
110 return null;
111 }
112
113- private void finish_connection_callback (NM.Client _client,
114- NM.ActiveConnection connection,
115- string new_connection_path,
116- Error error) {
117- bool success = false;
118- _client.get_active_connections ().@foreach ((c) => {
119- if (c == connection) {
120- success = true;
121- }
122+ private void finish_connection_cb (NM.Client? cb_client,
123+ NM.ActiveConnection? cb_connection,
124+ string? new_connection_path,
125+ Error? error) {
126+ if (error != null && error.code != 0) {
127+ warning ("%s\n", error.message);
128+ }
129+ }
130+
131+ private void connect_to_hidden () {
132+ var hidden_dialog = new NMAWifiDialog.for_other (client, nm_settings);
133+ set_wifi_dialog_cb (hidden_dialog);
134+ hidden_dialog.run ();
135+ hidden_dialog.destroy ();
136+ }
137+
138+ private void set_wifi_dialog_cb (NMAWifiDialog wifi_dialog) {
139+ wifi_dialog.response.connect ((response) => {
140+ if (response == Gtk.ResponseType.OK) {
141+ NM.Connection? fuzzy = null;
142+ NM.Device dialog_device;
143+ NM.AccessPoint? dialog_ap = null;
144+ var dialog_connection = wifi_dialog.get_connection (out dialog_device, out dialog_ap);
145+
146+ foreach (var possible in nm_settings.list_connections ()) {
147+ if (dialog_connection.compare (possible, NM.SettingCompareFlags.FUZZY | NM.SettingCompareFlags.IGNORE_ID)) {
148+ fuzzy = possible;
149+ }
150+ }
151+
152+ string? path = null;
153+ if (dialog_ap != null) {
154+ path = dialog_ap.get_path ();
155+ }
156+
157+ if (fuzzy != null) {
158+ client.activate_connection (fuzzy, wifi_device, path, null);
159+ } else {
160+ var connection_setting = dialog_connection.get_setting (typeof (NM.Setting));;
161+
162+ string? mode = null;
163+ var setting_wireless = (NM.SettingWireless) dialog_connection.get_setting (typeof (NM.SettingWireless));
164+ if (setting_wireless != null) {
165+ mode = setting_wireless.get_mode ();
166+ }
167+
168+ if (mode == "adhoc") {
169+ if (connection_setting == null) {
170+ connection_setting = new NM.SettingConnection ();
171+ }
172+
173+ dialog_connection.add_setting (connection_setting);
174+ }
175+
176+ client.add_and_activate_connection (dialog_connection,
177+ dialog_device,
178+ path,
179+ finish_connection_cb);
180+ }
181+ }
182 });
183 }
184 }
185
186=== modified file 'src/libnm-gtk.vapi'
187--- src/libnm-gtk.vapi 2015-08-01 18:41:32 +0000
188+++ src/libnm-gtk.vapi 2015-08-10 12:09:47 +0000
189@@ -1,12 +1,6 @@
190 [CCode (cheader_filename = "nm-wifi-dialog.h")]
191 class NMAWifiDialog : Gtk.Dialog {
192- public NMAWifiDialog (NM.Client client, NM.RemoteSettings settings, NM.Connection connection, NM.Device device, NM.AccessPoint ap, bool secrets_only);
193+ public NMAWifiDialog (NM.Client client, NM.RemoteSettings settings, NM.Connection 0connection, NM.Device device, NM.AccessPoint ap, bool secrets_only);
194+ public NMAWifiDialog.for_other (NM.Client client, NM.RemoteSettings settings);
195 public NM.Connection get_connection (out NM.Device device, out NM.AccessPoint ap);
196-}
197-
198-
199-[CCode (cprefix = "NMGtk", gir_namespace = "NMGtk", gir_version = "1.0", lower_case_cprefix = "nmgtk_")]
200-namespace NMGtk {
201- [CCode (cheader_filename = "libnm-gtk/nm-wifi-dialog.h", cname = "nma_wifi_dialog_new_for_other")]
202- public Gtk.Dialog new_wifi_dialog_for_hidden (NM.Client client, NM.RemoteSettings settings);
203 }

Subscribers

People subscribed via source and target branches

to all changes: