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
1=== modified file 'src/common/Utils.vala'
2--- src/common/Utils.vala 2017-01-01 10:58:24 +0000
3+++ src/common/Utils.vala 2017-01-06 14:22:44 +0000
4@@ -29,7 +29,33 @@
5 CONNECTING_WIFI,
6 CONNECTING_WIRED,
7 FAILED_WIRED,
8- FAILED_WIFI
9+ FAILED_WIFI;
10+
11+ public int get_priority()
12+ {
13+ switch(this) {
14+ case Network.State.CONNECTING_WIRED:
15+ return 0;
16+ case Network.State.CONNECTING_WIFI:
17+ return 1;
18+ case Network.State.CONNECTED_WIRED:
19+ return 2;
20+ case Network.State.CONNECTED_WIFI:
21+ case Network.State.CONNECTED_WIFI_WEAK:
22+ case Network.State.CONNECTED_WIFI_OK:
23+ case Network.State.CONNECTED_WIFI_GOOD:
24+ case Network.State.CONNECTED_WIFI_EXCELLENT:
25+ return 3;
26+ case Network.State.FAILED_WIRED:
27+ case Network.State.FAILED_WIFI:
28+ return 4;
29+ case Network.State.DISCONNECTED_WIRED:
30+ case Network.State.DISCONNECTED_AIRPLANE_MODE:
31+ return 5;
32+ default:
33+ return 6;
34+ }
35+ }
36 }
37
38 namespace Network.Common.Utils {
39
40=== modified file 'src/common/Widgets/NMVisualizer.vala'
41--- src/common/Widgets/NMVisualizer.vala 2017-01-02 00:07:05 +0000
42+++ src/common/Widgets/NMVisualizer.vala 2017-01-06 14:22:44 +0000
43@@ -38,7 +38,7 @@
44
45 nm_client.device_added.connect (device_added_cb);
46 nm_client.device_removed.connect (device_removed_cb);
47-
48+
49 nm_client.notify["networking-enabled"].connect (update_state);
50
51 var devices = nm_client.get_devices ();
52@@ -144,9 +144,14 @@
53 state = Network.State.DISCONNECTED_AIRPLANE_MODE;
54 } else {
55 var next_state = Network.State.DISCONNECTED;
56+ var best_score = int.MAX;
57+
58 foreach (var inter in network_interface) {
59- if (inter.state != Network.State.DISCONNECTED) {
60+ var score = inter.state.get_priority();
61+
62+ if (score < best_score) {
63 next_state = inter.state;
64+ best_score = score;
65 }
66 }
67

Subscribers

People subscribed via source and target branches