Skip to content

Commit

Permalink
Merge pull request #451 from nokyan/show-link-speed
Browse files Browse the repository at this point in the history
Show link speeds for network devices
  • Loading branch information
nokyan authored Feb 16, 2025
2 parents e6ecf9d + 567a494 commit fc7d375
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 38 deletions.
2 changes: 1 addition & 1 deletion data/resources/ui/pages/drive.ui
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</object>
</child>
<child>
<object class="AdwActionRow" id="link">
<object class="AdwActionRow" id="link"><!--Translators: "Link" refers to something like "PCIe 4.0 ×16"-->
<property name="title" translatable="yes">Link</property>
<style>
<class name="property"/>
Expand Down
2 changes: 1 addition & 1 deletion data/resources/ui/pages/gpu.ui
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
</object>
</child>
<child>
<object class="AdwActionRow" id="link">
<object class="AdwActionRow" id="link"><!--Translators: "Link" refers to something like "PCIe 4.0 ×16"-->
<property name="title" translatable="yes">Link</property>
<style>
<class name="property"/>
Expand Down
9 changes: 9 additions & 0 deletions data/resources/ui/pages/network.ui
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@
<property name="title" translatable="yes">Hardware Address</property>
</object>
</child>
<child>
<object class="AdwActionRow" id="link_speed">
<style>
<class name="property"/>
</style>
<property name="subtitle-selectable">true</property>
<property name="title" translatable="yes">Link Speed</property>
</object>
</child>
</object>
</child>
</object>
Expand Down
36 changes: 21 additions & 15 deletions po/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: resources\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-02-16 19:23+0100\n"
"PO-Revision-Date: 2025-02-16 19:23+0100\n"
"POT-Creation-Date: 2025-02-16 20:19+0100\n"
"PO-Revision-Date: 2025-02-16 20:12+0100\n"
"Last-Translator: nokyan <[email protected]>\n"
"Language-Team: German <[email protected]>\n"
"Language: de\n"
Expand Down Expand Up @@ -165,14 +165,15 @@ msgstr "Icon von"
#: src/ui/pages/memory.rs:231 src/ui/pages/memory.rs:232
#: src/ui/pages/memory.rs:236 src/ui/pages/memory.rs:237
#: src/ui/pages/memory.rs:265 src/ui/pages/memory.rs:326
#: src/ui/pages/network.rs:237 src/ui/pages/network.rs:244
#: src/ui/pages/network.rs:251 src/ui/pages/network.rs:257
#: src/ui/pages/network.rs:260 src/ui/pages/network.rs:326
#: src/ui/pages/network.rs:329 src/ui/pages/network.rs:331
#: src/ui/pages/network.rs:360 src/ui/pages/network.rs:363
#: src/ui/pages/network.rs:365 src/ui/pages/npu.rs:214 src/ui/pages/npu.rs:249
#: src/ui/pages/npu.rs:304 src/ui/pages/npu.rs:313 src/ui/pages/npu.rs:325
#: src/ui/pages/npu.rs:332 src/ui/pages/npu.rs:336 src/ui/pages/npu.rs:357
#: src/ui/pages/network.rs:240 src/ui/pages/network.rs:247
#: src/ui/pages/network.rs:254 src/ui/pages/network.rs:260
#: src/ui/pages/network.rs:263 src/ui/pages/network.rs:272
#: src/ui/pages/network.rs:336 src/ui/pages/network.rs:339
#: src/ui/pages/network.rs:341 src/ui/pages/network.rs:370
#: src/ui/pages/network.rs:373 src/ui/pages/network.rs:375
#: src/ui/pages/npu.rs:214 src/ui/pages/npu.rs:249 src/ui/pages/npu.rs:304
#: src/ui/pages/npu.rs:313 src/ui/pages/npu.rs:325 src/ui/pages/npu.rs:332
#: src/ui/pages/npu.rs:336 src/ui/pages/npu.rs:357
#: src/ui/pages/processes/mod.rs:1219 src/ui/pages/processes/mod.rs:1285
#: src/ui/pages/processes/mod.rs:1351 src/ui/pages/processes/mod.rs:1417
#: src/ui/pages/processes/mod.rs:1899 src/ui/pages/processes/mod.rs:1901
Expand Down Expand Up @@ -371,7 +372,7 @@ msgstr "Leistungsaufnahme"

#: src/ui/pages/battery.rs:278 src/ui/pages/cpu.rs:412
#: src/ui/pages/drive.rs:340 src/ui/pages/drive.rs:371 src/ui/pages/gpu.rs:422
#: src/ui/pages/network.rs:318 src/ui/pages/network.rs:352
#: src/ui/pages/network.rs:328 src/ui/pages/network.rs:362
#: src/ui/pages/npu.rs:300 src/ui/pages/npu.rs:349
msgid "Highest:"
msgstr "Höchste:"
Expand Down Expand Up @@ -442,21 +443,21 @@ msgstr "{} MT/s"
msgid "{} / {} · Swap: {} %"
msgstr "{} / {} · Ausl.: {} %"

#: src/ui/pages/network.rs:115 src/utils/network.rs:136
#: src/ui/pages/network.rs:118 src/utils/network.rs:136
msgid "Network Interface"
msgstr "Netzwerkschnittstelle"

#: src/ui/pages/network.rs:226
#: src/ui/pages/network.rs:229
msgid "Receiving"
msgstr "Empfangen"

#: src/ui/pages/network.rs:230
#: src/ui/pages/network.rs:233
msgid "Sending"
msgstr "Senden"

#. Translators: This is an abbreviation for "Receive" and "Send". This is displayed in the sidebar so
#. your translation should preferably be quite short or an abbreviation
#: src/ui/pages/network.rs:375
#: src/ui/pages/network.rs:385
msgid "R: {} · S: {}"
msgstr "E: {} · S: {}"

Expand Down Expand Up @@ -1721,6 +1722,7 @@ msgstr "Beschreibbar"
msgid "Removable"
msgstr "Wechselspeicher"

#. Translators: "Link" refers to something like "PCIe 4.0 ×16"
#: data/resources/ui/pages/drive.ui:102 data/resources/ui/pages/gpu.ui:113
msgid "Link"
msgstr "Anbindung"
Expand Down Expand Up @@ -1786,6 +1788,10 @@ msgstr "Schnittstelle"
msgid "Hardware Address"
msgstr "Geräteadresse"

#: data/resources/ui/pages/network.ui:94
msgid "Link Speed"
msgstr "Verbindungsgeschwindigkeit"

#: data/resources/ui/pages/npu.ui:31
msgid "NPU Frequency"
msgstr "NPU-Frequenz"
Expand Down
34 changes: 20 additions & 14 deletions po/resources.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-02-16 19:23+0100\n"
"POT-Creation-Date: 2025-02-16 20:19+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -160,14 +160,15 @@ msgstr ""
#: src/ui/pages/memory.rs:231 src/ui/pages/memory.rs:232
#: src/ui/pages/memory.rs:236 src/ui/pages/memory.rs:237
#: src/ui/pages/memory.rs:265 src/ui/pages/memory.rs:326
#: src/ui/pages/network.rs:237 src/ui/pages/network.rs:244
#: src/ui/pages/network.rs:251 src/ui/pages/network.rs:257
#: src/ui/pages/network.rs:260 src/ui/pages/network.rs:326
#: src/ui/pages/network.rs:329 src/ui/pages/network.rs:331
#: src/ui/pages/network.rs:360 src/ui/pages/network.rs:363
#: src/ui/pages/network.rs:365 src/ui/pages/npu.rs:214 src/ui/pages/npu.rs:249
#: src/ui/pages/npu.rs:304 src/ui/pages/npu.rs:313 src/ui/pages/npu.rs:325
#: src/ui/pages/npu.rs:332 src/ui/pages/npu.rs:336 src/ui/pages/npu.rs:357
#: src/ui/pages/network.rs:240 src/ui/pages/network.rs:247
#: src/ui/pages/network.rs:254 src/ui/pages/network.rs:260
#: src/ui/pages/network.rs:263 src/ui/pages/network.rs:272
#: src/ui/pages/network.rs:336 src/ui/pages/network.rs:339
#: src/ui/pages/network.rs:341 src/ui/pages/network.rs:370
#: src/ui/pages/network.rs:373 src/ui/pages/network.rs:375
#: src/ui/pages/npu.rs:214 src/ui/pages/npu.rs:249 src/ui/pages/npu.rs:304
#: src/ui/pages/npu.rs:313 src/ui/pages/npu.rs:325 src/ui/pages/npu.rs:332
#: src/ui/pages/npu.rs:336 src/ui/pages/npu.rs:357
#: src/ui/pages/processes/mod.rs:1219 src/ui/pages/processes/mod.rs:1285
#: src/ui/pages/processes/mod.rs:1351 src/ui/pages/processes/mod.rs:1417
#: src/ui/pages/processes/mod.rs:1899 src/ui/pages/processes/mod.rs:1901
Expand Down Expand Up @@ -362,7 +363,7 @@ msgstr ""

#: src/ui/pages/battery.rs:278 src/ui/pages/cpu.rs:412
#: src/ui/pages/drive.rs:340 src/ui/pages/drive.rs:371 src/ui/pages/gpu.rs:422
#: src/ui/pages/network.rs:318 src/ui/pages/network.rs:352
#: src/ui/pages/network.rs:328 src/ui/pages/network.rs:362
#: src/ui/pages/npu.rs:300 src/ui/pages/npu.rs:349
msgid "Highest:"
msgstr ""
Expand Down Expand Up @@ -433,21 +434,21 @@ msgstr ""
msgid "{} / {} · Swap: {} %"
msgstr ""

#: src/ui/pages/network.rs:115 src/utils/network.rs:136
#: src/ui/pages/network.rs:118 src/utils/network.rs:136
msgid "Network Interface"
msgstr ""

#: src/ui/pages/network.rs:226
#: src/ui/pages/network.rs:229
msgid "Receiving"
msgstr ""

#: src/ui/pages/network.rs:230
#: src/ui/pages/network.rs:233
msgid "Sending"
msgstr ""

#. Translators: This is an abbreviation for "Receive" and "Send". This is displayed in the sidebar so
#. your translation should preferably be quite short or an abbreviation
#: src/ui/pages/network.rs:375
#: src/ui/pages/network.rs:385
msgid "R: {} · S: {}"
msgstr ""

Expand Down Expand Up @@ -1700,6 +1701,7 @@ msgstr ""
msgid "Removable"
msgstr ""

#. Translators: "Link" refers to something like "PCIe 4.0 ×16"
#: data/resources/ui/pages/drive.ui:102 data/resources/ui/pages/gpu.ui:113
msgid "Link"
msgstr ""
Expand Down Expand Up @@ -1765,6 +1767,10 @@ msgstr ""
msgid "Hardware Address"
msgstr ""

#: data/resources/ui/pages/network.ui:94
msgid "Link Speed"
msgstr ""

#: data/resources/ui/pages/npu.ui:31
msgid "NPU Frequency"
msgstr ""
Expand Down
12 changes: 11 additions & 1 deletion src/ui/pages/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use log::trace;
use crate::config::PROFILE;
use crate::i18n::{i18n, i18n_f};
use crate::utils::network::{NetworkData, NetworkInterface};
use crate::utils::units::{convert_speed, convert_storage};
use crate::utils::units::{convert_speed, convert_speed_bits_decimal, convert_storage};

pub const TAB_ID_PREFIX: &str = "network";

Expand Down Expand Up @@ -44,6 +44,8 @@ mod imp {
pub interface: TemplateChild<adw::ActionRow>,
#[template_child]
pub hw_address: TemplateChild<adw::ActionRow>,
#[template_child]
pub link_speed: TemplateChild<adw::ActionRow>,
pub old_received_bytes: Cell<Option<usize>>,
pub old_sent_bytes: Cell<Option<usize>>,
pub last_timestamp: Cell<SystemTime>,
Expand Down Expand Up @@ -108,6 +110,7 @@ mod imp {
driver: Default::default(),
interface: Default::default(),
hw_address: Default::default(),
link_speed: Default::default(),
uses_progress_bar: Cell::new(true),
main_graph_color: glib::Bytes::from_static(&super::ResNetwork::MAIN_GRAPH_COLOR),
icon: RefCell::new(ThemedIcon::new("unknown-network-type-symbolic").into()),
Expand Down Expand Up @@ -262,6 +265,13 @@ impl ResNetwork {
imp.hw_address.set_subtitle(&hw_address);
}

imp.link_speed.set_subtitle(
&network_interface
.link_speed()
.map(|bps| convert_speed_bits_decimal(bps as f64))
.unwrap_or_else(|_| i18n("N/A")),
);

imp.last_timestamp.set(
SystemTime::now()
.checked_sub(Duration::from_secs(1))
Expand Down
14 changes: 14 additions & 0 deletions src/utils/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,20 @@ impl NetworkInterface {
.context("parsing failure")
}

/// Returns the link speed of this connection in bits per second
///
/// # Errors
///
/// Will return `Err` if the link speed couldn't be determined (e. g. for Wi-Fi connections)
pub fn link_speed(&self) -> Result<usize> {
std::fs::read_to_string(&self.sysfs_path.join("speed"))
.context("read failure")?
.replace('\n', "")
.parse::<usize>()
.context("parsing failure")
.map(|mbps| mbps.saturating_mul(1_000_000))
}

/// Returns the appropriate Icon for the type of drive
pub fn icon(&self) -> Icon {
match self.interface_type {
Expand Down
12 changes: 6 additions & 6 deletions src/utils/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn convert_storage(bytes: f64, integer: bool) -> String {
}
}

fn convert_storage_decimal(bytes: f64, integer: bool) -> String {
pub fn convert_storage_decimal(bytes: f64, integer: bool) -> String {
let (mut number, prefix) = to_largest_prefix(bytes, Base::Decimal);
if integer {
number = number.round();
Expand Down Expand Up @@ -124,7 +124,7 @@ fn convert_storage_decimal(bytes: f64, integer: bool) -> String {
}
}

fn convert_storage_binary(bytes: f64, integer: bool) -> String {
pub fn convert_storage_binary(bytes: f64, integer: bool) -> String {
let (mut number, prefix) = to_largest_prefix(bytes, Base::Binary);
if integer {
number = number.round();
Expand Down Expand Up @@ -177,7 +177,7 @@ pub fn convert_speed(bytes_per_second: f64, network: bool) -> String {
}
}

fn convert_speed_decimal(bytes_per_second: f64) -> String {
pub fn convert_speed_decimal(bytes_per_second: f64) -> String {
let (number, prefix) = to_largest_prefix(bytes_per_second, Base::Decimal);
match prefix {
Prefix::None => i18n_f("{} B/s", &[&format!("{}", number.round())]),
Expand All @@ -194,7 +194,7 @@ fn convert_speed_decimal(bytes_per_second: f64) -> String {
}
}

fn convert_speed_binary(bytes_per_second: f64) -> String {
pub fn convert_speed_binary(bytes_per_second: f64) -> String {
let (number, prefix) = to_largest_prefix(bytes_per_second, Base::Binary);
match prefix {
Prefix::None => i18n_f("{} B/s", &[&format!("{}", number.round())]),
Expand All @@ -211,7 +211,7 @@ fn convert_speed_binary(bytes_per_second: f64) -> String {
}
}

fn convert_speed_bits_decimal(bits_per_second: f64) -> String {
pub fn convert_speed_bits_decimal(bits_per_second: f64) -> String {
let (number, prefix) = to_largest_prefix(bits_per_second, Base::Decimal);
match prefix {
Prefix::None => i18n_f("{} b/s", &[&format!("{}", number.round())]),
Expand All @@ -228,7 +228,7 @@ fn convert_speed_bits_decimal(bits_per_second: f64) -> String {
}
}

fn convert_speed_bits_binary(bits_per_second: f64) -> String {
pub fn convert_speed_bits_binary(bits_per_second: f64) -> String {
let (number, prefix) = to_largest_prefix(bits_per_second, Base::Binary);
match prefix {
Prefix::None => i18n_f("{} b/s", &[&format!("{}", number.round())]),
Expand Down

0 comments on commit fc7d375

Please sign in to comment.