Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ namespace Network {
public enum ItemType {
DEVICE = 0,
VIRTUAL,
INVALID
INVALID;
public string to_string () {
switch (this) {
case DEVICE: return _("Devices");
case VIRTUAL: return _("Virtual");
default: return _("Invalid");
}
}
}

public static string state_to_string (NM.DeviceState state) {
Expand Down
34 changes: 2 additions & 32 deletions src/Widgets/DeviceList.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,13 @@ namespace Network.Widgets {
public class DeviceList : Gtk.ListBox {
public signal void show_no_devices (bool show);

private Gtk.Label virtual_l;
private Gtk.Label devices_l;
private DeviceItem proxy;
private DeviceItem vpn;

construct {
selection_mode = Gtk.SelectionMode.SINGLE;
activate_on_single_click = true;

virtual_l = new Gtk.Label (_("Virtual")) {
halign = Gtk.Align.START
};
virtual_l.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL);

devices_l = new Gtk.Label (_("Devices")) {
halign = Gtk.Align.START
};
devices_l.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL);

set_header_func (update_headers);
set_sort_func (sort_items);

Expand Down Expand Up @@ -140,28 +128,10 @@ namespace Network.Widgets {
private void update_headers (Gtk.ListBoxRow row, Gtk.ListBoxRow? before = null) {
unowned DeviceItem row_item = (DeviceItem) row;
unowned DeviceItem? before_item = (DeviceItem) before;
if (row_item.item_type == Utils.ItemType.VIRTUAL) {
if (before_item != null && before_item.item_type == Utils.ItemType.VIRTUAL) {
row.set_header (null);
return;
}

if (virtual_l.get_parent () != null) {
virtual_l.unparent ();
}

row.set_header (virtual_l);
} else if (row_item.item_type == Utils.ItemType.DEVICE) {
if (before_item != null && before_item.item_type == Utils.ItemType.DEVICE) {
row.set_header (null);
return;
}

if (devices_l.get_parent () != null) {
devices_l.unparent ();
}

row.set_header (devices_l);
if (before_item == null || row_item.item_type != before_item.item_type) {
row.set_header (new Granite.HeaderLabel (row_item.item_type.to_string ()));
} else {
row.set_header (null);
}
Expand Down