-
-
Notifications
You must be signed in to change notification settings - Fork 14
Show an indicator icon for each active connection #201
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
Draft
meisenzahl
wants to merge
19
commits into
master
Choose a base branch
from
show-an-indicator-icon-for-each-active-connection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e76b005
Show an indicator icon for each active connection
meisenzahl d01da45
Satisfy linter
meisenzahl b4e44b5
Handle DISCONNECTED
meisenzahl 0107952
Change order of icons based on reliability
meisenzahl 85567bb
Add icon for vpn
meisenzahl 45a56f3
Merge branch 'master' into show-an-indicator-icon-for-each-active-con…
meisenzahl d0084d9
Merge branch 'master' into show-an-indicator-icon-for-each-active-con…
meisenzahl 1ba63f9
Merge branch 'master' into show-an-indicator-icon-for-each-active-con…
meisenzahl 9b52566
Merge branch 'master' into show-an-indicator-icon-for-each-active-con…
meisenzahl 12f2153
Merge branch 'master' into show-an-indicator-icon-for-each-active-con…
14e789a
Merge branch 'master' into show-an-indicator-icon-for-each-active-con…
meisenzahl ebf3ea0
Rename connection state variables
meisenzahl 6802227
Add connection revealer
meisenzahl f20e6d6
Handle DISCONNECTED_WIRED
meisenzahl bd5242c
Remove own implementation of to_string ()
meisenzahl 7c41624
Only reveal network by default
meisenzahl 5e9ea02
Add image in construct
meisenzahl 077ff84
Merge branch 'master' into show-an-indicator-icon-for-each-active-con…
meisenzahl 2884519
Merge branch 'master' into show-an-indicator-icon-for-each-active-con…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,12 @@ | |
*/ | ||
|
||
public class Network.Widgets.DisplayWidget : Gtk.Grid { | ||
private Gtk.Image image; | ||
private ConnectionRevealer cellular_revealer; | ||
private ConnectionRevealer vpn_revealer; | ||
private ConnectionRevealer wifi_revealer; | ||
private ConnectionRevealer wired_revealer; | ||
private ConnectionRevealer network_revealer; | ||
|
||
private Gtk.Label extra_info_label; | ||
private Gtk.Revealer extra_info_revealer; | ||
|
||
|
@@ -26,8 +31,28 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { | |
private uint cellular_animation_timeout; | ||
private int cellular_animation_state = 0; | ||
|
||
private enum ConnectionState { | ||
DISCONNECTED = 0, | ||
CONNECTING = 1, | ||
CONNECTED = 2 | ||
} | ||
|
||
private ConnectionState cellular_connection_state = ConnectionState.DISCONNECTED; | ||
private ConnectionState wifi_connection_state = ConnectionState.DISCONNECTED; | ||
private ConnectionState wired_connection_state = ConnectionState.DISCONNECTED; | ||
|
||
construct { | ||
image = new Gtk.Image.from_icon_name ("network-wired-symbolic", Gtk.IconSize.LARGE_TOOLBAR); | ||
cellular_revealer = new ConnectionRevealer.from_icon_name ("network-cellular-offline-symbolic"); | ||
|
||
vpn_revealer = new ConnectionRevealer.from_icon_name ("network-vpn-symbolic"); | ||
|
||
wifi_revealer = new ConnectionRevealer.from_icon_name ("network-wireless-offline-symbolic"); | ||
|
||
wired_revealer = new ConnectionRevealer.from_icon_name ("network-wired-offline-symbolic"); | ||
|
||
network_revealer = new ConnectionRevealer.from_icon_name ("network-offline-symbolic") { | ||
reveal_child = true | ||
}; | ||
|
||
extra_info_label = new Gtk.Label (null) { | ||
margin_start = 4, | ||
|
@@ -40,11 +65,19 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { | |
}; | ||
extra_info_revealer.add (extra_info_label); | ||
|
||
add (image); | ||
add (vpn_revealer); | ||
add (wired_revealer); | ||
add (wifi_revealer); | ||
add (cellular_revealer); | ||
add (network_revealer); | ||
add (extra_info_revealer); | ||
|
||
update_icons (); | ||
} | ||
|
||
public void update_state (Network.State state, bool secure, string? extra_info = null) { | ||
info ("Network state changed to \"%s\"\n", state.to_string ()); | ||
|
||
extra_info_revealer.reveal_child = extra_info != null; | ||
extra_info_label.label = extra_info; | ||
|
||
|
@@ -59,29 +92,65 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { | |
} | ||
|
||
switch (state) { | ||
case Network.State.DISCONNECTED: | ||
network_revealer.image.icon_name = "network-offline-symbolic"; | ||
cellular_connection_state = ConnectionState.DISCONNECTED; | ||
wifi_connection_state = ConnectionState.DISCONNECTED; | ||
wired_connection_state = ConnectionState.DISCONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.DISCONNECTED_AIRPLANE_MODE: | ||
image.icon_name = "airplane-mode-symbolic"; | ||
network_revealer.image.icon_name = "airplane-mode-symbolic"; | ||
cellular_connection_state = ConnectionState.DISCONNECTED; | ||
wifi_connection_state = ConnectionState.DISCONNECTED; | ||
wired_connection_state = ConnectionState.DISCONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.DISCONNECTED_WIRED: | ||
wired_revealer.image.icon_name = "network-wired-disconnected"; | ||
wired_connection_state = ConnectionState.DISCONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.CONNECTED_VPN: | ||
vpn_revealer.reveal_child = true; | ||
break; | ||
case Network.State.FAILED_VPN: | ||
vpn_revealer.reveal_child = false; | ||
break; | ||
case Network.State.CONNECTING_WIRED: | ||
image.icon_name = "network-wired-acquiring-symbolic"; | ||
wired_revealer.image.icon_name = "network-wired-acquiring-symbolic"; | ||
wired_connection_state = ConnectionState.CONNECTING; | ||
update_icons (); | ||
break; | ||
case Network.State.CONNECTED_WIRED: | ||
image.icon_name = "network-wired-%ssymbolic".printf (secure? "secure-" : ""); | ||
wired_revealer.image.icon_name = "network-wired-%ssymbolic".printf (secure? "secure-" : ""); | ||
wired_connection_state = ConnectionState.CONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.CONNECTED_WIFI: | ||
image.icon_name = "network-wireless-connected-symbolic"; | ||
wifi_revealer.image.icon_name = "network-wireless-connected-symbolic"; | ||
wifi_connection_state = ConnectionState.CONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.CONNECTED_WIFI_WEAK: | ||
image.icon_name = "network-wireless-signal-weak-%ssymbolic".printf (secure? "secure-" : ""); | ||
wifi_revealer.image.icon_name = "network-wireless-signal-weak-%ssymbolic".printf (secure? "secure-" : ""); | ||
wifi_connection_state = ConnectionState.CONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.CONNECTED_WIFI_OK: | ||
image.icon_name = "network-wireless-signal-ok-%ssymbolic".printf (secure? "secure-" : ""); | ||
wifi_revealer.image.icon_name = "network-wireless-signal-ok-%ssymbolic".printf (secure? "secure-" : ""); | ||
wifi_connection_state = ConnectionState.CONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.CONNECTED_WIFI_GOOD: | ||
image.icon_name = "network-wireless-signal-good-%ssymbolic".printf (secure? "secure-" : ""); | ||
wifi_revealer.image.icon_name = "network-wireless-signal-good-%ssymbolic".printf (secure? "secure-" : ""); | ||
wifi_connection_state = ConnectionState.CONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.CONNECTED_WIFI_EXCELLENT: | ||
image.icon_name = "network-wireless-signal-excellent-%ssymbolic".printf (secure? "secure-" : ""); | ||
wifi_revealer.image.icon_name = "network-wireless-signal-excellent-%ssymbolic".printf (secure? "secure-" : ""); | ||
wifi_connection_state = ConnectionState.CONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.CONNECTING_WIFI: | ||
wifi_animation_timeout = Timeout.add (300, () => { | ||
|
@@ -101,21 +170,31 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { | |
strength = "excellent"; | ||
break; | ||
} | ||
image.icon_name = "network-wireless-signal-" + strength + (secure? "-secure" : "") + "-symbolic"; | ||
wifi_revealer.image.icon_name = "network-wireless-signal-" + strength + (secure? "-secure" : "") + "-symbolic"; | ||
wifi_connection_state = ConnectionState.CONNECTING; | ||
update_icons (); | ||
return true; | ||
}); | ||
break; | ||
case Network.State.CONNECTED_MOBILE_WEAK: | ||
image.icon_name = "network-cellular-signal-weak-%ssymbolic".printf (secure ? "secure-" : ""); | ||
cellular_revealer.image.icon_name = "network-cellular-signal-weak-%ssymbolic".printf (secure ? "secure-" : ""); | ||
cellular_connection_state = ConnectionState.CONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.CONNECTED_MOBILE_OK: | ||
image.icon_name = "network-cellular-signal-ok-%ssymbolic".printf (secure ? "secure-" : ""); | ||
cellular_revealer.image.icon_name = "network-cellular-signal-ok-%ssymbolic".printf (secure ? "secure-" : ""); | ||
cellular_connection_state = ConnectionState.CONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.CONNECTED_MOBILE_GOOD: | ||
image.icon_name = "network-cellular-signal-good-%ssymbolic".printf (secure ? "secure-" : ""); | ||
cellular_revealer.image.icon_name = "network-cellular-signal-good-%ssymbolic".printf (secure ? "secure-" : ""); | ||
cellular_connection_state = ConnectionState.CONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.CONNECTED_MOBILE_EXCELLENT: | ||
image.icon_name = "network-cellular-signal-excellent-%ssymbolic".printf (secure ? "secure-" : ""); | ||
cellular_revealer.image.icon_name = "network-cellular-signal-excellent-%ssymbolic".printf (secure ? "secure-" : ""); | ||
cellular_connection_state = ConnectionState.CONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.CONNECTING_MOBILE: | ||
cellular_animation_timeout = Timeout.add (300, () => { | ||
|
@@ -136,24 +215,83 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { | |
break; | ||
} | ||
|
||
image.icon_name = "network-cellular-signal-" + strength + (secure ? "secure-" : "") + "-symbolic"; | ||
cellular_revealer.image.icon_name = "network-cellular-signal-" + strength + (secure ? "secure-" : "") + "-symbolic"; | ||
cellular_connection_state = ConnectionState.CONNECTING; | ||
update_icons (); | ||
return true; | ||
}); | ||
break; | ||
case Network.State.FAILED_MOBILE: | ||
image.icon_name = "network-cellular-offline-symbolic"; | ||
cellular_revealer.image.icon_name = "network-cellular-offline-symbolic"; | ||
cellular_connection_state = ConnectionState.DISCONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.FAILED_WIFI: | ||
case Network.State.DISCONNECTED: | ||
image.icon_name = "network-wireless-offline-symbolic"; | ||
wifi_revealer.image.icon_name = "network-wireless-offline-symbolic"; | ||
wifi_connection_state = ConnectionState.DISCONNECTED; | ||
update_icons (); | ||
break; | ||
case Network.State.FAILED_WIRED: | ||
case Network.State.WIRED_UNPLUGGED: | ||
image.icon_name = "network-wired-offline-symbolic"; | ||
wired_revealer.image.icon_name = "network-wired-offline-symbolic"; | ||
wired_connection_state = ConnectionState.DISCONNECTED; | ||
update_icons (); | ||
break; | ||
default: | ||
image.icon_name = "network-offline-symbolic"; | ||
network_revealer.image.icon_name = "network-offline-symbolic"; | ||
cellular_connection_state = ConnectionState.DISCONNECTED; | ||
wifi_connection_state = ConnectionState.DISCONNECTED; | ||
wired_connection_state = ConnectionState.DISCONNECTED; | ||
update_icons (); | ||
critical ("Unknown network state, cannot show the good icon: %s", state.to_string ()); | ||
break; | ||
} | ||
} | ||
|
||
private void update_icons () { | ||
if ((cellular_connection_state + wifi_connection_state + wired_connection_state) > 0) { | ||
network_revealer.reveal_child = false; | ||
} else { | ||
cellular_revealer.reveal_child = false; | ||
wifi_revealer.reveal_child = false; | ||
wired_revealer.reveal_child = false; | ||
network_revealer.reveal_child = true; | ||
|
||
return; | ||
} | ||
|
||
if (cellular_connection_state > 0) { | ||
cellular_revealer.reveal_child = true; | ||
} else { | ||
cellular_revealer.reveal_child = false; | ||
} | ||
|
||
if (wifi_connection_state > 0) { | ||
wifi_revealer.reveal_child = true; | ||
} else { | ||
wifi_revealer.reveal_child = false; | ||
} | ||
|
||
if (wired_connection_state > 0) { | ||
wired_revealer.reveal_child = true; | ||
} else { | ||
wired_revealer.reveal_child = false; | ||
} | ||
} | ||
|
||
private class ConnectionRevealer : Gtk.Revealer { | ||
public Gtk.Image image { get; construct set; } | ||
private string _icon_name; | ||
|
||
public ConnectionRevealer.from_icon_name (string icon_name) { | ||
_icon_name = icon_name; | ||
} | ||
|
||
construct { | ||
image = new Gtk.Image.from_icon_name (_icon_name, Gtk.IconSize.LARGE_TOOLBAR); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably need to add tooltips to the images themselves rather than the overall display widget. |
||
transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT; | ||
|
||
add (image); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.