Skip to content

Commit

Permalink
MainView: Gtk4 prep and cleanup (#366)
Browse files Browse the repository at this point in the history
* MainView: Gtk4 prep and cleanup

* explicit expands
  • Loading branch information
danirabbit authored Jan 7, 2024
1 parent c89da3b commit a69570a
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions src/MainView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Authored by: Adam Bieńkowski <donadigos159@gmail.com>
*/

public class Network.MainView : Gtk.Paned {
public class Network.MainView : Gtk.Box {
protected GLib.List<Widgets.Page>? network_interface;

public NM.DeviceState state { private set; get; default = NM.DeviceState.PREPARE; }
Expand All @@ -30,7 +30,10 @@ public class Network.MainView : Gtk.Paned {
construct {
network_interface = new GLib.List<Widgets.Page> ();

device_list = new Widgets.DeviceList ();
device_list = new Widgets.DeviceList () {
hexpand = true,
vexpand = true
};

var footer = new Widgets.Footer ();

Expand Down Expand Up @@ -60,19 +63,20 @@ public class Network.MainView : Gtk.Paned {
content.add_named (no_devices, "no-devices-info");

var scrolled_window = new Gtk.ScrolledWindow (null, null) {
expand = true
child = device_list
};
scrolled_window.add (device_list);

var sidebar = new Gtk.Grid () {
orientation = Gtk.Orientation.VERTICAL
};
var sidebar = new Gtk.Box (VERTICAL, 0);
sidebar.add (scrolled_window);
sidebar.add (footer);

position = 240;
pack1 (sidebar, false, false);
pack2 (content, true, false);
var paned = new Gtk.Paned (HORIZONTAL) {
position = 200
};
paned.pack1 (sidebar, false, false);
paned.pack2 (content, true, false);

add (paned);

device_list.row_activated.connect ((row) => {
var page = ((Widgets.DeviceItem)row).page;
Expand Down Expand Up @@ -107,7 +111,7 @@ public class Network.MainView : Gtk.Paned {
nm_client.device_removed.connect (device_removed_cb);

nm_client.get_devices ().foreach ((device) => device_added_cb (device));
nm_client.get_connections ().foreach ((connection) => add_connection (connection));
nm_client.get_connections ().foreach ((connection) => device_list.add_connection (connection));

show_all ();
}
Expand Down Expand Up @@ -146,13 +150,13 @@ public class Network.MainView : Gtk.Paned {
private void connection_added_cb (Object obj) {
var connection = (NM.RemoteConnection)obj;

add_connection (connection);
device_list.add_connection (connection);
}

private void connection_removed_cb (Object obj) {
var connection = (NM.RemoteConnection)obj;

remove_connection (connection);
device_list.add_connection (connection);
}

private void device_added_cb (NM.Device device) {
Expand Down Expand Up @@ -196,10 +200,7 @@ public class Network.MainView : Gtk.Paned {
}

update_interfaces_names ();
update_all ();
}

private void update_all () {
foreach (var inter in network_interface) {
inter.update ();
}
Expand Down Expand Up @@ -231,7 +232,7 @@ public class Network.MainView : Gtk.Paned {
if (row != null && row.get_index () >= 0) {
device_list.get_row_at_index (index).activate ();
} else {
select_first ();
device_list.select_first_item ();
}
} else {
device_list.remove_iface_from_list (widget_interface);
Expand All @@ -240,18 +241,6 @@ public class Network.MainView : Gtk.Paned {
widget_interface.destroy ();
}

private void add_connection (NM.RemoteConnection connection) {
device_list.add_connection (connection);
}

private void remove_connection (NM.RemoteConnection connection) {
device_list.remove_connection (connection);
}

private void select_first () {
device_list.select_first_item ();
}

private void update_networking_state () {
unowned NetworkManager network_manager = NetworkManager.get_default ();
if (network_manager.client.networking_get_enabled ()) {
Expand Down

0 comments on commit a69570a

Please sign in to comment.