Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WifiMenuItem: Add Settings Dialog #226

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
64 changes: 21 additions & 43 deletions src/Views/WifiPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,10 @@ namespace Network {
protected Gtk.Stack list_stack;
protected Gtk.ScrolledWindow scrolled;
protected Gtk.Box hotspot_mode_alert;
protected Gtk.Box? connected_box = null;
protected Gtk.Revealer top_revealer;
protected Gtk.Button? disconnect_btn;
protected Gtk.Button? settings_btn;
protected Gtk.Button? hidden_btn;
protected Gtk.ToggleButton info_btn;
protected Gtk.Popover popover;

public WifiInterface (NM.Device device) {
Object (
Expand Down Expand Up @@ -89,15 +86,6 @@ namespace Network {
main_frame.get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW);
main_frame.add (list_stack);

info_box.margin = 12;

popover = new Gtk.Popover (info_btn);
popover.position = Gtk.PositionType.BOTTOM;
popover.add (info_box);
popover.hide.connect (() => {
info_btn.active = false;
});

connected_frame = new Gtk.Frame (null);
connected_frame.get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW);

Expand Down Expand Up @@ -288,10 +276,6 @@ namespace Network {
settings_btn.sensitive = sensitive;
}

if (info_btn != null) {
info_btn.sensitive = sensitive;
}

if (hidden_btn != null) {
hidden_btn.sensitive = (state != NM.DeviceState.UNAVAILABLE);
}
Expand Down Expand Up @@ -383,11 +367,10 @@ namespace Network {
var top_item = new WifiMenuItem (active_access_point);
top_item.state = NM.DeviceState.ACTIVATED;

connected_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
connected_box.add (top_item);

disconnect_btn = new Gtk.Button.with_label (_("Disconnect"));
disconnect_btn.margin = 6;
disconnect_btn.sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);
disconnect_btn.valign = Gtk.Align.CENTER;
disconnect_btn.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
disconnect_btn.clicked.connect (() => {
try {
Expand All @@ -397,34 +380,29 @@ namespace Network {
}
});

settings_btn = new Network.Widgets.SettingsButton.from_device (wifi_device, _("Settings…"));
settings_btn.sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);

info_btn = new Gtk.ToggleButton ();
info_btn.margin_top = info_btn.margin_bottom = 6;
info_btn.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
info_btn.image = new Gtk.Image.from_icon_name ("view-more-symbolic", Gtk.IconSize.SMALL_TOOLBAR);

popover.relative_to = info_btn;
var connected_box = new Gtk.Grid ();
connected_box.add (top_item);
connected_box.add (disconnect_btn);

info_btn.toggled.connect (() => {
popover.visible = info_btn.get_active ();
});
connected_frame.add (connected_box);
connected_frame.show_all ();

var button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
button_box.homogeneous = true;
button_box.margin = 6;
button_box.valign = Gtk.Align.CENTER;
button_box.pack_end (disconnect_btn, false, false, 0);
button_box.pack_end (settings_btn, false, false, 0);
button_box.show_all ();
var settings_dialog = new Granite.MessageDialog.with_image_from_icon_name (
top_item.ssid_label.label,
top_item.status_label.label,
top_item.img_strength.icon_name,
Gtk.ButtonsType.CLOSE
);

connected_box.pack_end (button_box, false, false, 0);
connected_box.pack_end (info_btn, false, false, 0);
connected_frame.add (connected_box);
settings_dialog.transient_for = ((Gtk.Application) Application.get_default ()).active_window;
settings_dialog.add_action_widget (new Network.Widgets.SettingsButton.from_device ((NM.DeviceWifi)device, _("Settings…")), 0);
settings_dialog.custom_bin.add (info_box);

connected_box.show_all ();
connected_frame.show_all ();
top_item.show_settings.connect (() => {
settings_dialog.show_all ();
settings_dialog.run ();
settings_dialog.hide ();
});
}
}

Expand Down
33 changes: 26 additions & 7 deletions src/Widgets/WifiMenuItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

public class Network.WifiMenuItem : Gtk.ListBoxRow {
public signal void user_action ();
public signal void show_settings ();

public bool is_secured { get; private set; }
public bool active { get; set; }
Expand Down Expand Up @@ -46,15 +47,17 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow {
}
}

private Gtk.Image img_strength;
public Gtk.Image img_strength { get; private set; }
public Gtk.Label ssid_label { get; private set; }
public Gtk.Label status_label { get; private set; }

private Gtk.Image lock_img;
private Gtk.Image error_img;
private Gtk.Label ssid_label;
private Gtk.Label status_label;
private Gtk.Revealer connect_button_revealer;
private Gtk.Revealer settings_button_revealer;
private Gtk.Spinner spinner;

public WifiMenuItem (NM.AccessPoint ap) {
public WifiMenuItem (NM.AccessPoint ap, NM.Device? device = null) {
img_strength = new Gtk.Image ();
img_strength.icon_size = Gtk.IconSize.DND;

Expand All @@ -74,11 +77,21 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow {
spinner = new Gtk.Spinner ();

var connect_button = new Gtk.Button.with_label (_("Connect"));
connect_button.halign = Gtk.Align.END;
connect_button.hexpand = true;
connect_button.valign = Gtk.Align.CENTER;

var settings_button = new Gtk.Button.from_icon_name ("view-more-horizontal-symbolic", Gtk.IconSize.SMALL_TOOLBAR) {
halign = Gtk.Align.END,
hexpand = true,
tooltip_text = _("Information and Settings")
};
settings_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);

settings_button_revealer = new Gtk.Revealer ();
settings_button_revealer.reveal_child = false;
settings_button_revealer.add (settings_button);

connect_button_revealer = new Gtk.Revealer ();
connect_button_revealer.transition_type = Gtk.RevealerTransitionType.NONE;
connect_button_revealer.reveal_child = true;
connect_button_revealer.add (connect_button);

Expand All @@ -92,7 +105,8 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow {
grid.attach (lock_img, 2, 0);
grid.attach (error_img, 3, 0, 1, 2);
grid.attach (spinner, 4, 0, 1, 2);
grid.attach (connect_button_revealer, 5, 0, 1, 2);
grid.attach (settings_button_revealer, 5, 0, 1, 2);
grid.attach (connect_button_revealer, 6, 0, 1, 2);

_ap = new Gee.LinkedList<NM.AccessPoint> ();

Expand All @@ -108,6 +122,10 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow {
user_action ();
});

settings_button.clicked.connect (() => {
show_settings ();
});

update ();
}

Expand Down Expand Up @@ -163,6 +181,7 @@ public class Network.WifiMenuItem : Gtk.ListBoxRow {
break;
case NM.DeviceState.ACTIVATED:
connect_button_revealer.reveal_child = false;
settings_button_revealer.reveal_child = true;
break;
}

Expand Down