Skip to content

Commit

Permalink
Granite.SimpleSettingsPage → Switchboard.SettingsPage
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Feb 28, 2024
1 parent e8663ba commit d96f87f
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 110 deletions.
1 change: 0 additions & 1 deletion po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ src/Views/ModemPage.vala
src/Views/ProxyPage.vala
src/Views/VPNPage.vala
src/Views/WifiPage.vala
src/Widgets/SettingsButton.vala
src/Widgets/Page.vala
src/Widgets/InfoBox.vala
src/Widgets/DeviceItem.vala
Expand Down
12 changes: 9 additions & 3 deletions src/Views/EthernetPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Network.Widgets {
Object (
activatable: true,
device: device,
icon_name: "network-wired"
icon: new ThemedIcon ("network-wired")
);
}

Expand All @@ -48,9 +48,15 @@ namespace Network.Widgets {
widgets_stack.add_child (no_cable);
widgets_stack.add_child (top_revealer);

content_area.attach (widgets_stack, 0, 0);
child = widgets_stack;

action_area.append (new SettingsButton.from_device (device));
var settings_button = add_button (_("Advanced Settings…"));
settings_button.clicked.connect (open_advanced_settings);

settings_button.sensitive = uuid != "";
notify["uuid"].connect (() => {
settings_button.sensitive = uuid != "";
});

status_switch.bind_property ("active", top_revealer, "reveal-child", GLib.BindingFlags.SYNC_CREATE);
}
Expand Down
16 changes: 10 additions & 6 deletions src/Views/HotspotPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace Network.Widgets {
public class HotspotInterface : Network.Widgets.Page {
public WifiInterface root_iface { get; construct; }
private Gtk.Button hotspot_settings_btn;
private Gtk.Button settings_button;
private bool switch_updating = false;

private Gtk.Entry ssid_entry;
Expand All @@ -37,7 +37,7 @@
root_iface: root_iface,
description: _("Enabling Hotspot will disconnect from any connected wireless networks. You will not be able to connect to a wireless network while Hotspot is active."),
device: root_iface.device,
icon_name: "network-wireless-hotspot"
icon: new ThemedIcon ("network-wireless-hotspot")
);
}

Expand Down Expand Up @@ -104,11 +104,15 @@
main_grid.attach (key_entry, 2, 4);
main_grid.attach (check_btn, 2, 5);

content_area.attach (main_grid, 0, 0);
child = main_grid;

hotspot_settings_btn = new SettingsButton.from_device (device, _("Hotspot Settings…"));
settings_button = add_button (_("Hotspot Settings…"));
settings_button.clicked.connect (open_advanced_settings);

action_area.append (hotspot_settings_btn);
settings_button.sensitive = uuid != "";
notify["uuid"].connect (() => {
settings_button.sensitive = uuid != "";
});

update ();
validate_entries ();
Expand Down Expand Up @@ -184,7 +188,7 @@
var wifi_device = (NM.DeviceWifi) device;
bool hotspot_mode = Utils.get_device_is_hotspot (wifi_device);

hotspot_settings_btn.sensitive = hotspot_mode;
settings_button.sensitive = hotspot_mode;

bool sensitive = !hotspot_mode;
conn_combo.sensitive = sensitive;
Expand Down
16 changes: 12 additions & 4 deletions src/Views/ModemPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Network.Widgets {
Object (
activatable: true,
device: device,
icon_name: "network-cellular"
icon: new ThemedIcon ("network-cellular")
);

device.state_changed.connect (update);
Expand All @@ -38,10 +38,18 @@ namespace Network.Widgets {
child = info_box
};

content_area.attach (top_revealer, 0, 0);
child = top_revealer;

action_area.append (new SettingsButton ());
action_area.append (new SettingsButton.from_device (device));
var connections_button = add_button (_("Edit Connections…"));
connections_button.clicked.connect (edit_connections);

var settings_button = add_button (_("Advanced Settings…"));
settings_button.clicked.connect (open_advanced_settings);

settings_button.sensitive = uuid != "";
notify["uuid"].connect (() => {
settings_button.sensitive = uuid != "";
});

update ();
}
Expand Down
10 changes: 6 additions & 4 deletions src/Views/ProxyPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Network.Widgets {
Object (
activatable: true,
title: _("Proxy"),
icon_name: "preferences-system-network",
icon: new ThemedIcon ("preferences-system-network"),
owner: _owner
);

Expand Down Expand Up @@ -60,9 +60,11 @@ namespace Network.Widgets {
Network.Plug.proxy_settings.changed.connect (update_mode);
update_mode ();

content_area.row_spacing = 12;
content_area.attach (stackswitcher, 0, 0);
content_area.attach (stack, 0, 1);
var box = new Gtk.Box (VERTICAL, 12);
box.append (stackswitcher);
box.append (stack);

child = box;

stack.visible_child = configuration_page;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Views/VPNPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Network.VPNPage : Network.Widgets.Page {
Object (
title: _("VPN"),
description: _("A Virtual Private Network can hide network traffic on public networks or from your internet service provider. It can't protect passwords from attackers or prevent websites from identifying you."),
icon_name: "network-vpn"
icon: new ThemedIcon ("network-vpn")
);
}

Expand Down Expand Up @@ -85,7 +85,7 @@ public class Network.VPNPage : Network.Widgets.Page {
};
main_overlay.add_overlay (remove_vpn_toast);

content_area.attach (main_overlay, 0, 0);
child = main_overlay;

add_button.clicked.connect (() => {
try_connection_editor ("--create --type=vpn");
Expand Down
15 changes: 8 additions & 7 deletions src/Views/WifiPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Network.WifiInterface : Network.Widgets.Page {
}

construct {
icon_name = "network-wireless";
icon = new ThemedIcon ("network-wireless");

placeholder = new Gtk.Stack () {
visible = true
Expand Down Expand Up @@ -93,11 +93,11 @@ public class Network.WifiInterface : Network.Widgets.Page {
transition_type = SLIDE_DOWN
};

hidden_btn = new Gtk.Button.with_label (_("Connect to Hidden Network"));
hidden_btn.clicked.connect (connect_to_hidden);
var settings_button = add_button (_("Edit Connections…"));
settings_button.clicked.connect (edit_connections);

action_area.append (new Network.Widgets.SettingsButton ());
action_area.append (hidden_btn);
hidden_btn = add_button (_("Connect to Hidden Network…"));
hidden_btn.clicked.connect (connect_to_hidden);

wifi_device = (NM.DeviceWifi)device;
active_wifi_item = null;
Expand Down Expand Up @@ -159,7 +159,7 @@ public class Network.WifiInterface : Network.Widgets.Page {
content_box.append (top_revealer);
content_box.append (main_frame);

content_area.attach (content_box, 0, 0);
child = content_box;

update ();
}
Expand Down Expand Up @@ -390,9 +390,10 @@ public class Network.WifiInterface : Network.Widgets.Page {
}
});

settings_btn = new Network.Widgets.SettingsButton.from_device (wifi_device, _("Settings…")) {
settings_btn = new Gtk.Button.with_label (_("Settings…")) {
sensitive = (device.get_state () == NM.DeviceState.ACTIVATED)
};
settings_btn.clicked.connect (open_advanced_settings);

info_btn = new Gtk.MenuButton () {
icon_name = "view-more-symbolic",
Expand Down
12 changes: 6 additions & 6 deletions src/Widgets/DeviceItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ namespace Network.Widgets {
public Widgets.Page? page { get; set; default = null; }
public string title { get; set; default = ""; }
public string subtitle { get; set; default = ""; }
public string icon_name { get; set; default = "network-wired"; }
public Icon icon { get; set; default = new ThemedIcon ("network-wired"); }
public Utils.ItemType item_type { get; set; default = Utils.ItemType.INVALID; }

private Gtk.Image status_image;

public DeviceItem (string title, string icon_name) {
Object (
title: title,
icon_name: icon_name
icon: new ThemedIcon (icon_name)
);
}

public DeviceItem.from_page (Widgets.Page page, string icon_name = "network-wired") {
Object (
device: page.device,
icon_name: icon_name,
icon: new ThemedIcon (icon_name),
item_type: Utils.ItemType.DEVICE,
page: page
);

page.bind_property ("title", this, "title", SYNC_CREATE);
page.bind_property ("icon-name", this, "icon-name", SYNC_CREATE);
page.bind_property ("icon", this, "icon", SYNC_CREATE);

switch_status (Utils.CustomMode.INVALID, page.state);
page.notify["state"].connect (() => {
Expand All @@ -53,7 +53,7 @@ namespace Network.Widgets {
}

construct {
var row_image = new Gtk.Image.from_icon_name (icon_name) {
var row_image = new Gtk.Image.from_gicon (icon) {
icon_size = LARGE,
margin_end = 3
};
Expand Down Expand Up @@ -97,7 +97,7 @@ namespace Network.Widgets {

bind_property ("title", row_title, "label");
bind_property ("subtitle", row_description, "label");
bind_property ("icon-name", row_image, "icon-name");
bind_property ("icon", row_image, "gicon");
}

public void switch_status (Utils.CustomMode custom_mode, NM.DeviceState? state = null) {
Expand Down
51 changes: 46 additions & 5 deletions src/Widgets/Page.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
*/

namespace Network.Widgets {
public abstract class Page : Granite.SimpleSettingsPage {
public abstract class Page : Switchboard.SettingsPage {
public NM.DeviceState state { get; protected set; default = NM.DeviceState.DISCONNECTED; }

public NM.Device? device { get; construct; }

public bool connection_editor_available { get; private set; default = false; }

protected InfoBox? info_box;
protected string uuid = "";
private bool switch_updating = false;

construct {
content_area.orientation = Gtk.Orientation.VERTICAL;
content_area.row_spacing = 24;

if (device != null) {
title = Utils.type_to_string (device.get_device_type ());
} else if (title == null) {
Expand All @@ -47,6 +46,11 @@ namespace Network.Widgets {
vexpand = true
};
info_box.info_changed.connect (update);

get_uuid ();
device.state_changed.connect_after (() => {
get_uuid ();
});
}
}

Expand Down Expand Up @@ -165,5 +169,42 @@ namespace Network.Widgets {
critical (e.message);
}
}

private void get_uuid () {
var active_connection = device.get_active_connection ();
if (active_connection != null) {
uuid = active_connection.get_uuid ();
} else {
var available_connections = device.get_available_connections ();
if (available_connections.length > 0) {
uuid = available_connections[0].get_uuid ();
} else {
uuid = "";
}
}
}

protected void edit_connections () {
try {
var appinfo = AppInfo.create_from_commandline (
"nm-connection-editor", null, AppInfoCreateFlags.NONE
);
appinfo.launch (null, null);
} catch (Error e) {
warning ("%s", e.message);
}
}

protected void open_advanced_settings () {
try {
var appinfo = AppInfo.create_from_commandline (
"nm-connection-editor --edit=%s".printf (uuid), null, AppInfoCreateFlags.NONE
);

appinfo.launch (null, null);
} catch (Error e) {
warning ("%s", e.message);
}
}
}
}
Loading

0 comments on commit d96f87f

Please sign in to comment.