Skip to content

Commit 5fb037b

Browse files
authored
Revert "WifiPage: update listbox with list model (#419)"
This reverts commit 3fac115.
1 parent 3fac115 commit 5fb037b

File tree

1 file changed

+55
-43
lines changed

1 file changed

+55
-43
lines changed

src/Views/WifiPage.vala

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public class Network.WifiInterface : Network.Widgets.Page {
99
public NM.DeviceWifi? wifi_device;
1010
private NM.AccessPoint? active_ap;
1111

12-
private ListStore ap_list_store;
1312
private Gtk.ListBox wifi_list;
1413

1514
private WifiMenuItem? active_wifi_item { get; set; }
@@ -38,8 +37,6 @@ public class Network.WifiInterface : Network.Widgets.Page {
3837
construct {
3938
icon = new ThemedIcon ("network-wireless");
4039

41-
ap_list_store = new ListStore (typeof (NM.AccessPoint));
42-
4340
placeholder = new Gtk.Stack () {
4441
visible = true
4542
};
@@ -49,7 +46,7 @@ public class Network.WifiInterface : Network.Widgets.Page {
4946
selection_mode = SINGLE,
5047
visible = true
5148
};
52-
wifi_list.bind_model (ap_list_store, create_widget_func);
49+
wifi_list.set_sort_func (sort_func);
5350
wifi_list.set_placeholder (placeholder);
5451
wifi_list.add_css_class (Granite.STYLE_CLASS_RICH_LIST);
5552

@@ -160,49 +157,35 @@ public class Network.WifiInterface : Network.Widgets.Page {
160157
}
161158
}
162159

163-
private void access_point_added_cb (Object object) {
164-
var ap = (NM.AccessPoint) object;
160+
void access_point_added_cb (Object ap_) {
161+
NM.AccessPoint ap = (NM.AccessPoint)ap_;
165162

166-
// Don't show connected AP in list
167-
if (ap == wifi_device.get_active_access_point ()) {
168-
return;
169-
}
170-
171-
// Don't add duplicates
172-
uint pos;
173-
if (ap_list_store.find (ap, out pos) != false) {
174-
return;
175-
}
163+
bool found = false;
176164

177-
// Sometimes network manager sends a (fake?) AP without a valid ssid
178-
if (ap.ssid == null) {
179-
return;
165+
if (ap.ssid != null) {
166+
unowned var child = wifi_list.get_first_child ();
167+
while (child != null) {
168+
if (child is WifiMenuItem) {
169+
var menu_item = (WifiMenuItem) child;
170+
if (ap.ssid.compare (menu_item.ssid) == 0) {
171+
found = true;
172+
menu_item.add_ap (ap);
173+
break;
174+
}
175+
}
176+
child = child.get_next_sibling ();
177+
}
180178
}
181179

182-
ap_list_store.insert_sorted (ap, sort_func);
183-
update ();
184-
}
180+
/* Sometimes network manager sends a (fake?) AP without a valid ssid. */
181+
if (!found && ap.ssid != null) {
182+
var item = new WifiMenuItem (ap);
183+
item.user_action.connect (wifi_activate_cb);
185184

186-
private void access_point_removed_cb (Object object) {
187-
var ap = (NM.AccessPoint) object;
185+
wifi_list.append (item);
188186

189-
uint pos;
190-
if (ap_list_store.find (ap, out pos) == false) {
191-
critical ("Couldn't remove an access point which has not been added.");
192-
return;
187+
update ();
193188
}
194-
195-
ap_list_store.remove (pos);
196-
update ();
197-
}
198-
199-
private Gtk.Widget create_widget_func (Object object) {
200-
var ap = (NM.AccessPoint) object;
201-
202-
var row = new WifiMenuItem (ap);
203-
row.user_action.connect (wifi_activate_cb);
204-
205-
return row;
206189
}
207190

208191
void update_active_ap () {
@@ -246,6 +229,34 @@ public class Network.WifiInterface : Network.Widgets.Page {
246229
}
247230
}
248231

232+
void access_point_removed_cb (Object ap_) {
233+
NM.AccessPoint ap = (NM.AccessPoint)ap_;
234+
235+
WifiMenuItem found_item = null;
236+
unowned var child = wifi_list.get_first_child ();
237+
while (child != null && found_item == null) {
238+
if (child is WifiMenuItem) {
239+
var menu_item = (WifiMenuItem) child;
240+
241+
if (ap.ssid.compare (menu_item.ssid) == 0) {
242+
found_item = menu_item;
243+
}
244+
}
245+
246+
child = child.get_next_sibling ();
247+
}
248+
249+
if (found_item == null) {
250+
critical ("Couldn't remove an access point which has not been added.");
251+
} else {
252+
if (!found_item.remove_ap (ap)) {
253+
found_item.destroy ();
254+
}
255+
}
256+
257+
update ();
258+
}
259+
249260
public override void update () {
250261
bool sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);
251262
if (hidden_btn != null) {
@@ -640,11 +651,12 @@ public class Network.WifiInterface : Network.Widgets.Page {
640651
}
641652
}
642653

643-
private int sort_func (Object object1, Object object2) {
644-
if (object1 == null || object1 == null) {
654+
private int sort_func (Gtk.ListBoxRow r1, Gtk.ListBoxRow r2) {
655+
if (r1 == null || r2 == null) {
645656
return 0;
646657
}
647658

648-
return ((NM.AccessPoint) object2).strength - ((NM.AccessPoint) object1).strength;
659+
return ((WifiMenuItem) r2).ap.strength - ((WifiMenuItem) r1).ap.strength;
649660
}
661+
650662
}

0 commit comments

Comments
 (0)