Skip to content

Commit

Permalink
Remove manual sidebar management
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Mar 28, 2024
1 parent 56d0f8b commit 49c459c
Showing 1 changed file with 5 additions and 94 deletions.
99 changes: 5 additions & 94 deletions src/MainView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@ public class Network.MainView : Gtk.Box {

public NM.DeviceState state { private set; get; default = NM.DeviceState.PREPARE; }

private Granite.HeaderLabel devices_header;
private Granite.HeaderLabel virtual_header;
private Gtk.ListBox device_list;
private Gtk.Stack content;
private NM.Device current_device = null;
private Switchboard.SettingsSidebar sidebar;
private VPNPage vpn_page;

construct {
network_interface = new GLib.List<Widgets.Page> ();

// virtual_header = new Granite.HeaderLabel (_("Virtual"));
// devices_header = new Granite.HeaderLabel (_("Devices"));

var proxy = new Widgets.DeviceItem (_("Proxy"), "preferences-system-network") {
item_type = VIRTUAL
};
Expand All @@ -50,15 +45,6 @@ public class Network.MainView : Gtk.Box {
show_title = false
};

device_list = new Gtk.ListBox () {
activate_on_single_click = true,
selection_mode = SINGLE,
hexpand = true,
vexpand = true
};
device_list.set_sort_func (sort_func);
device_list.set_header_func (update_headers);

var label = new Gtk.Label (_("Airplane Mode"));

var airplane_switch = new Gtk.Switch () {
Expand All @@ -84,7 +70,7 @@ public class Network.MainView : Gtk.Box {
content.add_child (vpn_page);
content.add_child (proxy.page);

var sidebar = new Switchboard.SettingsSidebar (content) {
sidebar = new Switchboard.SettingsSidebar (content) {
show_title_buttons = true
};

Expand Down Expand Up @@ -137,8 +123,7 @@ public class Network.MainView : Gtk.Box {
if (widget_interface.device == device) {
network_interface.remove (widget_interface);

// Implementation call
remove_interface (widget_interface);
content.remove (widget_interface);
break;
}
}
Expand Down Expand Up @@ -244,64 +229,20 @@ public class Network.MainView : Gtk.Box {
}

private void add_interface (Widgets.Page page) {
Widgets.DeviceItem item;
if (page is Widgets.HotspotInterface) {
item = new Widgets.DeviceItem.from_page (page) {
item_type = VIRTUAL
};
} else if (page.device.get_iface ().has_prefix ("usb")) {
item = new Widgets.DeviceItem.from_page (page, "drive-removable-media");
} else {
item = new Widgets.DeviceItem.from_page (page);
}

if (content.get_page (page) == null) {
content.add_child (page);
}

device_list.append (item);
update_networking_state ();
}

private void remove_interface (Widgets.Page widget_interface) {
if (content.get_visible_child () == widget_interface) {
var row = device_list.get_selected_row ();
int index = device_list.get_selected_row ().get_index ();
remove_iface_from_list (widget_interface);

if (row != null && row.get_index () >= 0) {
device_list.get_row_at_index (index).activate ();
} else {
device_list.get_row_at_index (0).activate ();
}
} else {
remove_iface_from_list (widget_interface);
}

widget_interface.destroy ();
}

private void remove_iface_from_list (Widgets.Page iface) {
unowned var child = device_list.get_first_child ();
while (child != null) {
if (child is Widgets.DeviceItem && ((Widgets.DeviceItem) child).page == iface) {
device_list.remove (child);
break;
}

child = child.get_next_sibling ();
}
}

private void update_networking_state () {
unowned NetworkManager network_manager = NetworkManager.get_default ();
if (network_manager.client.networking_get_enabled ()) {
device_list.sensitive = true;
device_list.get_row_at_index (0).activate ();
sidebar.sensitive = true;
} else {
device_list.sensitive = false;
sidebar.sensitive = false;
current_device = null;
device_list.select_row (null);
content.set_visible_child_name ("airplane-mode-info");
}
}
Expand All @@ -315,34 +256,4 @@ public class Network.MainView : Gtk.Box {
return 0;
}
}

private void update_headers (Gtk.ListBoxRow row, Gtk.ListBoxRow? before = null) {
unowned Widgets.DeviceItem row_item = (Widgets.DeviceItem) row;
unowned Widgets.DeviceItem? before_item = (Widgets.DeviceItem) before;
if (row_item.item_type == VIRTUAL) {
if (before_item != null && before_item.item_type == VIRTUAL) {
row.set_header (null);
return;
}

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

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

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

row.set_header (devices_header);
} else {
row.set_header (null);
}
}
}

0 comments on commit 49c459c

Please sign in to comment.