Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 55 additions & 43 deletions src/Views/WifiPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class Network.WifiInterface : Network.Widgets.Page {
public NM.DeviceWifi? wifi_device;
private NM.AccessPoint? active_ap;

private ListStore ap_list_store;
private Gtk.ListBox wifi_list;

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

ap_list_store = new ListStore (typeof (NM.AccessPoint));

placeholder = new Gtk.Stack () {
visible = true
};
Expand All @@ -49,7 +46,7 @@ public class Network.WifiInterface : Network.Widgets.Page {
selection_mode = SINGLE,
visible = true
};
wifi_list.bind_model (ap_list_store, create_widget_func);
wifi_list.set_sort_func (sort_func);
wifi_list.set_placeholder (placeholder);
wifi_list.add_css_class (Granite.STYLE_CLASS_RICH_LIST);

Expand Down Expand Up @@ -160,49 +157,35 @@ public class Network.WifiInterface : Network.Widgets.Page {
}
}

private void access_point_added_cb (Object object) {
var ap = (NM.AccessPoint) object;
void access_point_added_cb (Object ap_) {
NM.AccessPoint ap = (NM.AccessPoint)ap_;

// Don't show connected AP in list
if (ap == wifi_device.get_active_access_point ()) {
return;
}

// Don't add duplicates
uint pos;
if (ap_list_store.find (ap, out pos) != false) {
return;
}
bool found = false;

// Sometimes network manager sends a (fake?) AP without a valid ssid
if (ap.ssid == null) {
return;
if (ap.ssid != null) {
unowned var child = wifi_list.get_first_child ();
while (child != null) {
if (child is WifiMenuItem) {
var menu_item = (WifiMenuItem) child;
if (ap.ssid.compare (menu_item.ssid) == 0) {
found = true;
menu_item.add_ap (ap);
break;
}
}
child = child.get_next_sibling ();
}
}

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

private void access_point_removed_cb (Object object) {
var ap = (NM.AccessPoint) object;
wifi_list.append (item);

uint pos;
if (ap_list_store.find (ap, out pos) == false) {
critical ("Couldn't remove an access point which has not been added.");
return;
update ();
}

ap_list_store.remove (pos);
update ();
}

private Gtk.Widget create_widget_func (Object object) {
var ap = (NM.AccessPoint) object;

var row = new WifiMenuItem (ap);
row.user_action.connect (wifi_activate_cb);

return row;
}

void update_active_ap () {
Expand Down Expand Up @@ -246,6 +229,34 @@ public class Network.WifiInterface : Network.Widgets.Page {
}
}

void access_point_removed_cb (Object ap_) {
NM.AccessPoint ap = (NM.AccessPoint)ap_;

WifiMenuItem found_item = null;
unowned var child = wifi_list.get_first_child ();
while (child != null && found_item == null) {
if (child is WifiMenuItem) {
var menu_item = (WifiMenuItem) child;

if (ap.ssid.compare (menu_item.ssid) == 0) {
found_item = menu_item;
}
}

child = child.get_next_sibling ();
}

if (found_item == null) {
critical ("Couldn't remove an access point which has not been added.");
} else {
if (!found_item.remove_ap (ap)) {
found_item.destroy ();
}
}

update ();
}

public override void update () {
bool sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);
if (hidden_btn != null) {
Expand Down Expand Up @@ -640,11 +651,12 @@ public class Network.WifiInterface : Network.Widgets.Page {
}
}

private int sort_func (Object object1, Object object2) {
if (object1 == null || object1 == null) {
private int sort_func (Gtk.ListBoxRow r1, Gtk.ListBoxRow r2) {
if (r1 == null || r2 == null) {
return 0;
}

return ((NM.AccessPoint) object2).strength - ((NM.AccessPoint) object1).strength;
return ((WifiMenuItem) r2).ap.strength - ((WifiMenuItem) r1).ap.strength;
}

}
Loading