Skip to content

Commit

Permalink
use bogon tooltip for local addresses when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Jan 18, 2025
1 parent 1af5ab6 commit 9a9d40b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
51 changes: 27 additions & 24 deletions src/countries/country_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ use iced::Font;

use crate::countries::flags_pictures::{
AD, AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, AU, AW, AX, AZ, BA, BB, BD, BE, BF, BG, BH, BI,
BJ, BM, BN, BO, BR, BROADCAST, BS, BT, BV, BW, BY, BZ, CA, CC, CD, CF, CG, CH, CI, CK, CL, CM,
CN, CO, COMPUTER, CR, CU, CV, CW, CX, CY, CZ, DE, DJ, DK, DM, DO, DZ, EC, EE, EG, EH, ER, ES,
ET, FI, FJ, FK, FLAGS_WIDTH_BIG, FLAGS_WIDTH_SMALL, FM, FO, FR, GA, GB, GD, GE, GG, GH, GI, GL,
GM, GN, GQ, GR, GS, GT, GU, GW, GY, HK, HN, HOME, HR, HT, HU, ID, IE, IL, IM, IN, IO, IQ, IR,
IS, IT, JE, JM, JO, JP, KE, KG, KH, KI, KM, KN, KP, KR, KW, KY, KZ, LA, LB, LC, LI, LK, LR, LS,
LT, LU, LV, LY, MA, MC, MD, ME, MG, MH, MK, ML, MM, MN, MO, MP, MR, MS, MT, MU, MULTICAST, MV,
MW, MX, MY, MZ, NA, NC, NE, NF, NG, NI, NL, NO, NP, NR, NU, NZ, OM, PA, PE, PF, PG, PH, PK, PL,
PN, PR, PS, PT, PW, PY, QA, RO, RS, RU, RW, SA, SB, SC, SD, SE, SG, SH, SI, SK, SL, SM, SN, SO,
SR, SS, ST, SV, SX, SY, SZ, TC, TD, TF, TG, TH, TJ, TK, TL, TM, TN, TO, TR, TT, TV, TW, TZ, UA,
UG, UNKNOWN, US, UY, UZ, VA, VC, VE, VG, VI, VN, VU, WS, YE, ZA, ZM, ZW,
BJ, BM, BN, BO, BOGON, BR, BROADCAST, BS, BT, BV, BW, BY, BZ, CA, CC, CD, CF, CG, CH, CI, CK,
CL, CM, CN, CO, COMPUTER, CR, CU, CV, CW, CX, CY, CZ, DE, DJ, DK, DM, DO, DZ, EC, EE, EG, EH,
ER, ES, ET, FI, FJ, FK, FLAGS_WIDTH_BIG, FLAGS_WIDTH_SMALL, FM, FO, FR, GA, GB, GD, GE, GG, GH,
GI, GL, GM, GN, GQ, GR, GS, GT, GU, GW, GY, HK, HN, HOME, HR, HT, HU, ID, IE, IL, IM, IN, IO,
IQ, IR, IS, IT, JE, JM, JO, JP, KE, KG, KH, KI, KM, KN, KP, KR, KW, KY, KZ, LA, LB, LC, LI, LK,
LR, LS, LT, LU, LV, LY, MA, MC, MD, ME, MG, MH, MK, ML, MM, MN, MO, MP, MR, MS, MT, MU,
MULTICAST, MV, MW, MX, MY, MZ, NA, NC, NE, NF, NG, NI, NL, NO, NP, NR, NU, NZ, OM, PA, PE, PF,
PG, PH, PK, PL, PN, PR, PS, PT, PW, PY, QA, RO, RS, RU, RW, SA, SB, SC, SD, SE, SG, SH, SI, SK,
SL, SM, SN, SO, SR, SS, ST, SV, SX, SY, SZ, TC, TD, TF, TG, TH, TJ, TK, TL, TM, TN, TO, TR, TT,
TV, TW, TZ, UA, UG, UNKNOWN, US, UY, UZ, VA, VC, VE, VG, VI, VN, VU, WS, YE, ZA, ZM, ZW,
};
use crate::countries::types::country::Country;
use crate::gui::styles::container::ContainerType;
Expand All @@ -26,6 +26,7 @@ use crate::networking::types::traffic_type::TrafficType;
use crate::translations::translations_2::{
local_translation, unknown_translation, your_network_adapter_translation,
};
use crate::translations::translations_4::reserved_address_translation;
use crate::{Language, StyleType};

fn get_flag_from_country<'a>(
Expand Down Expand Up @@ -358,31 +359,33 @@ pub fn get_flag_tooltip<'a>(
pub fn get_computer_tooltip<'a>(
is_my_address: bool,
is_local: bool,
is_bogon: Option<&str>,
traffic_type: TrafficType,
language: Language,
font: Font,
) -> Tooltip<'a, Message, StyleType> {
let content = Svg::new(Handle::from_memory(Vec::from(
match (is_my_address, is_local, traffic_type) {
(true, _, _) => COMPUTER,
(false, _, TrafficType::Multicast) => MULTICAST,
(false, _, TrafficType::Broadcast) => BROADCAST,
(false, true, _) => HOME,
(false, false, TrafficType::Unicast) => UNKNOWN,
match (is_my_address, is_local, is_bogon, traffic_type) {
(true, _, _, _) => COMPUTER,
(false, _, _, TrafficType::Multicast) => MULTICAST,
(false, _, _, TrafficType::Broadcast) => BROADCAST,
(false, true, _, _) => HOME,
(false, false, Some(_), _) => BOGON,
(false, false, None, TrafficType::Unicast) => UNKNOWN,
},
)))
.class(SvgType::AdaptColor)
.width(FLAGS_WIDTH_BIG)
.height(FLAGS_WIDTH_BIG * 0.75);

let tooltip = match (is_my_address, is_local, traffic_type) {
(true, _, _) => your_network_adapter_translation(language),
(false, _, TrafficType::Multicast) => "Multicast",
(false, _, TrafficType::Broadcast) => "Broadcast",
(false, true, _) => local_translation(language),
(false, false, TrafficType::Unicast) => unknown_translation(language),
}
.to_string();
let tooltip = match (is_my_address, is_local, is_bogon, traffic_type) {
(true, _, _, _) => your_network_adapter_translation(language).to_string(),
(false, _, _, TrafficType::Multicast) => "Multicast".to_string(),
(false, _, _, TrafficType::Broadcast) => "Broadcast".to_string(),
(false, true, _, _) => local_translation(language).to_string(),
(false, false, Some(t), _) => reserved_address_translation(language, t),
(false, false, None, TrafficType::Unicast) => unknown_translation(language).to_string(),
};

Tooltip::new(
content,
Expand Down
2 changes: 2 additions & 0 deletions src/gui/pages/connection_details_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::networking::manage_packets::{
get_address_to_lookup, get_traffic_type, is_local_connection, is_my_address,
};
use crate::networking::types::address_port_pair::AddressPortPair;
use crate::networking::types::bogon::is_bogon;
use crate::networking::types::host::Host;
use crate::networking::types::icmp_type::IcmpType;
use crate::networking::types::info_address_port_pair::InfoAddressPortPair;
Expand Down Expand Up @@ -304,6 +305,7 @@ fn get_local_tooltip<'a>(
get_computer_tooltip(
is_my_address(local_address, my_interface_addresses),
is_local_connection(local_address, my_interface_addresses),
is_bogon(local_address),
get_traffic_type(
if address_to_lookup.eq(&key.address1) {
&key.address2
Expand Down
1 change: 1 addition & 0 deletions src/translations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
pub mod translations;
pub mod translations_2;
pub mod translations_3;
pub mod translations_4;
pub mod types;
11 changes: 11 additions & 0 deletions src/translations/translations_4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![allow(clippy::match_same_arms)]

use crate::translations::types::language::Language;

pub fn reserved_address_translation(language: Language, info: &str) -> String {
match language {
Language::EN => format!("Reserved address ({info})"),
Language::IT => format!("Indirizzo riservato ({info})"),
_ => format!("Reserved address ({info})"),
}
}

0 comments on commit 9a9d40b

Please sign in to comment.