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

Add tooltip indicator #199

Merged
merged 24 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7c06193
Add tooltip with fixed text
pongloongyeat Nov 30, 2020
b77d91f
Use Network.State to change tooltip text
pongloongyeat Nov 30, 2020
677cb5f
Remove update_tooltip
pongloongyeat Nov 30, 2020
5b21935
Apply suggestions
pongloongyeat Dec 1, 2020
70b1752
Add get_active_ap method
pongloongyeat Dec 1, 2020
4ed550e
Make wifi_box public
pongloongyeat Dec 1, 2020
43aaab5
Add get_active_network_name method
pongloongyeat Dec 1, 2020
fbf7dc9
Happy wife!=happy life but happy linter==happy life
pongloongyeat Dec 2, 2020
5c0a38d
Use existing update_active_ap
pongloongyeat Dec 2, 2020
6e14449
Update tooltip on start and on network change
pongloongyeat Dec 2, 2020
2691c50
Add public string active_wired_name
pongloongyeat Dec 2, 2020
79e0544
Publicise other_box
pongloongyeat Dec 2, 2020
8f234ba
Separate network name query functions
pongloongyeat Dec 2, 2020
d9b04ad
Get active network name for tooltip by state
pongloongyeat Dec 2, 2020
fa501e4
Apply suggestions
pongloongyeat Dec 3, 2020
933dd83
Apply suggestions
pongloongyeat Dec 18, 2020
4b9ebec
Lint
pongloongyeat Dec 18, 2020
d5a7063
Make "Wired" translatable
pongloongyeat Dec 22, 2020
b3ddfec
Re-use variable
pongloongyeat Dec 22, 2020
2e939be
Ensure we dont return empty string
pongloongyeat Dec 22, 2020
43ab706
Apply suggestions from code review
pongloongyeat Dec 22, 2020
072a133
Remove unnecessary semicolon
pongloongyeat Dec 22, 2020
f9aa48f
Use display_title property for Ethernet connection
pongloongyeat Dec 22, 2020
5614cff
Merge branch 'master' into indicator-tooltip
danirabbit Dec 22, 2020
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
84 changes: 84 additions & 0 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Network.Indicator : Wingpanel.Indicator {
popover_widget.notify["extra-info"].connect (on_state_changed);
popover_widget.settings_shown.connect (() => { close (); });

update_tooltip ();
on_state_changed ();
start_monitor ();
}
Expand Down Expand Up @@ -72,6 +73,8 @@ public class Network.Indicator : Wingpanel.Indicator {
warning ("%s\n", e.message);
}
}

update_tooltip ();
});
}

Expand All @@ -86,6 +89,87 @@ public class Network.Indicator : Wingpanel.Indicator {
popover_widget.closed ();
}
}

private void update_tooltip () {
switch (popover_widget.state) {
case Network.State.CONNECTING_WIRED:
/* If there's only one active ethernet connection,
we get back the string "Wired". We won't want to
show the user Connecting to "Wired" so we'll have
to show them something else if we get back
"Wired" from get_active_wired_name () */

string active_wired_name = get_active_wired_name ();

if (active_wired_name == _("Wired")) {
display_widget.tooltip_markup = _("Connecting to wired network");
} else {
display_widget.tooltip_markup = _("Connecting to “%s”").printf (active_wired_name);
}
break;
case Network.State.CONNECTING_WIFI:
case Network.State.CONNECTING_MOBILE:
display_widget.tooltip_markup = Granite.markup_accel_tooltip ({}, _("Connecting to “%s”".printf (get_active_wifi_name ())));
pongloongyeat marked this conversation as resolved.
Show resolved Hide resolved
break;
case Network.State.CONNECTED_WIRED:
string active_wired_name = get_active_wired_name ();

if (active_wired_name == _("Wired")) {
display_widget.tooltip_markup = _("Connected to wired network");
} else {
display_widget.tooltip_markup = _("Connected to “%s”").printf (active_wired_name);
}
break;
case Network.State.CONNECTED_WIFI:
case Network.State.CONNECTED_WIFI_WEAK:
case Network.State.CONNECTED_WIFI_OK:
case Network.State.CONNECTED_WIFI_GOOD:
case Network.State.CONNECTED_WIFI_EXCELLENT:
case Network.State.CONNECTED_MOBILE_WEAK:
case Network.State.CONNECTED_MOBILE_OK:
case Network.State.CONNECTED_MOBILE_GOOD:
case Network.State.CONNECTED_MOBILE_EXCELLENT:
display_widget.tooltip_markup = _("Connected to “%s”").printf (get_active_wifi_name ());
break;
case Network.State.FAILED_WIRED:
case Network.State.FAILED_WIFI:
case Network.State.FAILED_VPN:
case Network.State.FAILED_MOBILE:
display_widget.tooltip_markup = _("Failed to connect");
break;
case Network.State.DISCONNECTED_WIRED:
case Network.State.DISCONNECTED_AIRPLANE_MODE:
display_widget.tooltip_markup = _("Disconnected");
break;
default:
display_widget.tooltip_markup = _("Not connected");
break;
}
}

private string get_active_wired_name () {
foreach (unowned Gtk.Widget child in popover_widget.other_box.get_children ()) {
if (child is Network.EtherInterface) {
var active_wired_name = ((Network.EtherInterface) child).display_title;
debug ("Active network (Wired): %s".printf (active_wired_name));
return active_wired_name;
}
}

return _("unknown network");
}

private string get_active_wifi_name () {
foreach (unowned Gtk.Widget child in popover_widget.wifi_box.get_children ()) {
if (child is Network.WifiInterface) {
var active_wifi_name = ((Network.WifiInterface) child).active_ap_name;
debug ("Active network (WiFi): %s".printf (active_wifi_name));
return active_wifi_name;
}
}

return _("unknown network");
}
}

public Wingpanel.Indicator get_indicator (Module module, Wingpanel.IndicatorManager.ServerType server_type) {
Expand Down
4 changes: 2 additions & 2 deletions src/Widgets/PopoverWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class Network.Widgets.PopoverWidget : Gtk.Grid {
public string? extra_info { private set; get; default = null; }
public Network.State state { private set; get; default = Network.State.CONNECTING_WIRED; }

private Gtk.Box other_box;
private Gtk.Box wifi_box;
public Gtk.Box other_box { get; private set; }
public Gtk.Box wifi_box { get; private set; }
private Gtk.Box vpn_box;
private Gtk.ModelButton hidden_item;

Expand Down
5 changes: 4 additions & 1 deletion src/Widgets/WifiInterface.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class Network.WifiInterface : Network.WidgetNMInterface {
public NM.DeviceWifi? wifi_device;
public bool hidden_sensitivity { get; set; default = true; }

public string active_ap_name { get; private set; }
danirabbit marked this conversation as resolved.
Show resolved Hide resolved

private Wingpanel.Widgets.Switch wifi_item;
private Gtk.Revealer revealer;

Expand Down Expand Up @@ -456,7 +458,8 @@ public class Network.WifiInterface : Network.WidgetNMInterface {
blank_item.set_active (true);
} else {
unowned GLib.Bytes active_ap_ssid = active_ap.ssid;
debug ("Active ap: %s", NM.Utils.ssid_to_utf8 (active_ap_ssid.get_data ()));
active_ap_name = NM.Utils.ssid_to_utf8 (active_ap_ssid.get_data ());
debug ("Active ap: %s", active_ap_name);

bool found = false;
foreach (weak Gtk.Widget w in wifi_list.get_children ()) {
Expand Down