Merge lp:~alucryd/switchboard-plug-networking/no-ifconfig into lp:~elementary-pantheon/switchboard-plug-networking/trunk

Proposed by Maxime Gauduin
Status: Superseded
Proposed branch: lp:~alucryd/switchboard-plug-networking/no-ifconfig
Merge into: lp:~elementary-pantheon/switchboard-plug-networking/trunk
Diff against target: 117 lines (+25/-41)
1 file modified
src/Widgets/Device/DevicePage.vala (+25/-41)
To merge this branch: bzr merge lp:~alucryd/switchboard-plug-networking/no-ifconfig
Reviewer Review Type Date Requested Status
Adam Bieńkowski (community) Needs Fixing
Viko Adi Rahmawan (community) Needs Fixing
Review via email: mp+262346@code.launchpad.net

This proposal has been superseded by a proposal from 2015-07-04.

Description of the change

ifconfig has been deprecated for some time by most distros. This change makes the plug read the received and transferred bytes values from /sys and process them to make them look pretty.
I also fixed all whitespace issues while I was at it.

I'm open to criticism as I've never written any vala or C code before so I may have done some stupid things.

To post a comment you must log in.
86. By Danielle Foré

use "channel-secure-symbolic" instead of "lock-screen"

87. By Launchpad Translations on behalf of elementary-pantheon

Launchpad automatic translations update.

88. By Adam Bieńkowski

Check for duplicates in access points list

89. By Danielle Foré

* Fix mixed tabs and spaces
* Cuddle else

90. By Cody Garver

Packaging dependencies

91. By Cody Garver

Valac dependency

92. By Danielle Foré

* Set margins and spacing to multiples of 3
* Use 12px outside margin, 24px between sections as in alert/dialog
* Replace three dots with ellipsis char
* Add ellipsis to actions that occur in a new window
* Group actions that affect this network and set homogeneous
* Ungroup action that affects a new/different network

93. By Adam Bieńkowski

For now disable the duplicate checking; fixed: device switch gets into loop when switching it

94. By Adam Bieńkowski

Fixed: add exeption is on the wrong side + title case

95. By Launchpad Translations on behalf of elementary-pantheon

Launchpad automatic translations update.

96. By Launchpad Translations on behalf of elementary-pantheon

Launchpad automatic translations update.

97. By Launchpad Translations on behalf of elementary-pantheon

Launchpad automatic translations update.

Revision history for this message
Viko Adi Rahmawan (vikoadi) wrote :

You can use format_size (http://valadoc.org/#!api=glib-2.0/GLib.format_size) instead of dividing by 1024

review: Needs Fixing
Revision history for this message
Corentin Noël (tintou) wrote :

The format_size fonction is definitely the way to go, it also returns a translated string (Byte is Octet in french so kb becomes ko)

Revision history for this message
Maxime Gauduin (alucryd) wrote :

Thx for the suggestion, works like a charm!

Revision history for this message
Adam Bieńkowski (donadigo) wrote :

It works well, but the code has some issues:
* Branch the current revision to apply the latest changes;
* Diff lines from 101 to 107 don't have proper ident;
* The code throws 2 additional warnings on the compile: unhandled error `GLib.FileError':
I think you should change the SpawnError to FileError.

* Lastly I would change diff line 109 to: error ("%s\n", e.message);

Other than that it is okay ;)

review: Needs Fixing
98. By Launchpad Translations on behalf of elementary-pantheon

Launchpad automatic translations update.

99. By Maxime Gauduin

Ditch deprecated ifconfig

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Widgets/Device/DevicePage.vala'
2--- src/Widgets/Device/DevicePage.vala 2015-06-23 21:22:11 +0000
3+++ src/Widgets/Device/DevicePage.vala 2015-07-04 08:53:41 +0000
4@@ -30,10 +30,10 @@
5 private Gtk.Label sent;
6 private Gtk.Label received;
7
8- private string sent_l = (_("Sent:") + SUFFIX);
9- private string received_l = (_("Received:") + SUFFIX);
10+ private string sent_l = (_("Sent:") + SUFFIX);
11+ private string received_l = (_("Received:") + SUFFIX);
12
13- public DevicePage.from_owner (DeviceItem? _owner) {
14+ public DevicePage.from_owner (DeviceItem? _owner) {
15 owner = _owner;
16 device = owner.get_item_device ();
17
18@@ -50,16 +50,16 @@
19
20 var device_img = new Gtk.Image.from_icon_name (owner.get_item_icon_name (), Gtk.IconSize.DIALOG);
21 device_img.margin_end = 15;
22-
23+
24 var device_label = new Gtk.Label (Utils.type_to_string (device.get_device_type ()));
25 device_label.get_style_context ().add_class ("h2");
26-
27+
28 control_switch = new Gtk.Switch ();
29
30 var control_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 10);
31 control_box.pack_start (device_img, false, false, 0);
32 control_box.pack_start (device_label, false, false, 0);
33- control_box.pack_end (control_switch, false, false, 0);
34+ control_box.pack_end (control_switch, false, false, 0);
35
36 var activitybox = new Gtk.Box (Gtk.Orientation.VERTICAL, 1);
37 activitybox.hexpand = true;
38@@ -75,11 +75,10 @@
39
40 var details_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
41 details_box.pack_start (Utils.get_advanced_button_from_device (device), false, false, 0);
42-
43 activitybox.add (new Gtk.Label ("\n"));
44 activitybox.add (sent);
45 activitybox.add (received);
46-
47+
48 update_activity ();
49 update_switch_state ();
50
51@@ -89,11 +88,11 @@
52 this.show_all ();
53 }
54
55- private void update_activity () {
56+ private void update_activity () {
57 string sent_bytes, received_bytes;
58 get_activity_information (device.get_iface (), out sent_bytes, out received_bytes);
59 sent.label = sent_l + sent_bytes ?? UNKNOWN;
60- received.label = received_l + received_bytes ?? UNKNOWN;
61+ received.label = received_l + received_bytes ?? UNKNOWN;
62 }
63
64 private void update_switch_state () {
65@@ -101,36 +100,21 @@
66 }
67
68 /* Main method to get all information about the interface */
69- private void get_activity_information (string iface, out string received_bytes, out string transfered_bytes) {
70+ private void get_activity_information (string iface, out string sent_bytes, out string received_bytes) {
71+ sent_bytes = UNKNOWN;
72 received_bytes = UNKNOWN;
73- transfered_bytes = UNKNOWN;
74-
75- try {
76- string[] spawn_args = { "ifconfig", iface };
77- string[] spawn_env = Environ.get ();
78- string output;
79-
80- Process.spawn_sync ("/",
81- spawn_args,
82- spawn_env,
83- SpawnFlags.SEARCH_PATH,
84- null,
85- out output,
86- null,
87- null);
88-
89- string[] data = output.split ("\n");
90- foreach (string line in data) {
91- if (line.contains ("RX bytes:")) {
92- string[] inf3 = line.split (":");
93- received_bytes = inf3[1].split (" ")[0].split (" ", 2)[1].replace ("(", "").replace (")", "");
94- transfered_bytes = inf3[2].split (" ", 2)[1].replace ("(", "").replace (")", "");
95- }
96- }
97-
98- } catch (SpawnError e) {
99- error (e.message);
100- }
101- }
102- }
103+
104+ try {
105+ string tx_bytes, rx_bytes;
106+
107+ FileUtils.get_contents ("/sys/class/net/" + iface + "/statistics/tx_bytes", out tx_bytes);
108+ FileUtils.get_contents ("/sys/class/net/" + iface + "/statistics/rx_bytes", out rx_bytes);
109+
110+ sent_bytes = format_size (uint64.parse (tx_bytes));
111+ received_bytes = format_size (uint64.parse (rx_bytes));
112+ } catch (FileError e) {
113+ error ("%s\n", e.message);
114+ }
115+ }
116+ }
117 }

Subscribers

People subscribed via source and target branches