Merge lp:~fault/wingpanel-indicator-network/fix-1628541 into lp:~wingpanel-devs/wingpanel-indicator-network/trunk

Proposed by Casper Christiansen
Status: Merged
Merged at revision: 231
Proposed branch: lp:~fault/wingpanel-indicator-network/fix-1628541
Merge into: lp:~wingpanel-devs/wingpanel-indicator-network/trunk
Diff against target: 66 lines (+34/-3)
2 files modified
src/common/Utils.vala (+27/-1)
src/common/Widgets/NMVisualizer.vala (+7/-2)
To merge this branch: bzr merge lp:~fault/wingpanel-indicator-network/fix-1628541
Reviewer Review Type Date Requested Status
WingPanel Devs Pending
Review via email: mp+314188@code.launchpad.net

Commit message

Prioritize networks by state

Description of the change

Fixes https://bugs.launchpad.net/wingpanel-indicator-network/+bug/1628541 by prioritizing network states according to their position in an array.

I gave the connecting states higher priority than connected states, due to that probably being something the user wants to know about. This can easily be changed if need be.

To post a comment you must log in.
Revision history for this message
Corentin Noël (tintou) wrote :

Maybe you can get the priority by creating a `int get_priority ()` in the Network.State enum so you don't have to reiterate every time but only do a `score = inter.state.get_priority ();`

Revision history for this message
Casper Christiansen (fault) wrote :

> Maybe you can get the priority by creating a `int get_priority ()` in the
> Network.State enum so you don't have to reiterate every time but only do a
> `score = inter.state.get_priority ();`

You're right, that would be better performance wise. I just realized I even forgot to break the loop early once the score was found. Woops.

Revision history for this message
RabbitBot (rabbitbot-a) wrote :

Attempt to merge into lp:wingpanel-indicator-network failed due to conflicts:

text conflict in src/common/Utils.vala

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/common/Utils.vala'
--- src/common/Utils.vala 2017-01-01 10:58:24 +0000
+++ src/common/Utils.vala 2017-01-06 14:22:44 +0000
@@ -29,7 +29,33 @@
29 CONNECTING_WIFI,29 CONNECTING_WIFI,
30 CONNECTING_WIRED,30 CONNECTING_WIRED,
31 FAILED_WIRED,31 FAILED_WIRED,
32 FAILED_WIFI32 FAILED_WIFI;
33
34 public int get_priority()
35 {
36 switch(this) {
37 case Network.State.CONNECTING_WIRED:
38 return 0;
39 case Network.State.CONNECTING_WIFI:
40 return 1;
41 case Network.State.CONNECTED_WIRED:
42 return 2;
43 case Network.State.CONNECTED_WIFI:
44 case Network.State.CONNECTED_WIFI_WEAK:
45 case Network.State.CONNECTED_WIFI_OK:
46 case Network.State.CONNECTED_WIFI_GOOD:
47 case Network.State.CONNECTED_WIFI_EXCELLENT:
48 return 3;
49 case Network.State.FAILED_WIRED:
50 case Network.State.FAILED_WIFI:
51 return 4;
52 case Network.State.DISCONNECTED_WIRED:
53 case Network.State.DISCONNECTED_AIRPLANE_MODE:
54 return 5;
55 default:
56 return 6;
57 }
58 }
33}59}
3460
35namespace Network.Common.Utils {61namespace Network.Common.Utils {
3662
=== modified file 'src/common/Widgets/NMVisualizer.vala'
--- src/common/Widgets/NMVisualizer.vala 2017-01-02 00:07:05 +0000
+++ src/common/Widgets/NMVisualizer.vala 2017-01-06 14:22:44 +0000
@@ -38,7 +38,7 @@
3838
39 nm_client.device_added.connect (device_added_cb);39 nm_client.device_added.connect (device_added_cb);
40 nm_client.device_removed.connect (device_removed_cb);40 nm_client.device_removed.connect (device_removed_cb);
41 41
42 nm_client.notify["networking-enabled"].connect (update_state);42 nm_client.notify["networking-enabled"].connect (update_state);
4343
44 var devices = nm_client.get_devices ();44 var devices = nm_client.get_devices ();
@@ -144,9 +144,14 @@
144 state = Network.State.DISCONNECTED_AIRPLANE_MODE;144 state = Network.State.DISCONNECTED_AIRPLANE_MODE;
145 } else {145 } else {
146 var next_state = Network.State.DISCONNECTED;146 var next_state = Network.State.DISCONNECTED;
147 var best_score = int.MAX;
148
147 foreach (var inter in network_interface) {149 foreach (var inter in network_interface) {
148 if (inter.state != Network.State.DISCONNECTED) {150 var score = inter.state.get_priority();
151
152 if (score < best_score) {
149 next_state = inter.state;153 next_state = inter.state;
154 best_score = score;
150 }155 }
151 }156 }
152157

Subscribers

People subscribed via source and target branches