Skip to content

Commit

Permalink
invalid filters tooltip (initial page)
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Dec 16, 2023
1 parent 8f8af54 commit 60b24db
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/gui/pages/initial_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ use crate::networking::types::ip_collection::IpCollection;
use crate::networking::types::port_collection::PortCollection;
use crate::translations::translations::{
address_translation, addresses_translation, choose_adapters_translation,
ip_version_translation, select_filters_translation, start_translation,
transport_protocol_translation,
ip_version_translation, protocol_translation, select_filters_translation, start_translation,
};
use crate::translations::translations_3::port_translation;
use crate::utils::formatted_strings::get_invalid_filters_string;
use crate::utils::types::icon::Icon;
use crate::{IpVersion, Language, StyleType, TransProtocol};

Expand Down Expand Up @@ -135,7 +135,7 @@ fn col_ip_buttons(
.width(Length::Fill)
.spacing(7)
.push(
ip_version_translation(language)
Text::new(ip_version_translation(language))
.font(font)
.style(TextType::Subtitle)
.size(FONT_SIZE_SUBTITLE),
Expand Down Expand Up @@ -175,7 +175,7 @@ fn col_transport_buttons(
.width(Length::Fill)
.spacing(7)
.push(
Text::new(transport_protocol_translation(language))
Text::new(protocol_translation(language))
.font(font)
.style(TextType::Subtitle)
.size(FONT_SIZE_SUBTITLE),
Expand Down Expand Up @@ -271,12 +271,15 @@ fn button_start(
.width(Length::Fixed(160.0))
.style(ButtonType::Gradient(color_gradient));

let mut tooltip = start_translation(language).to_string();
//tooltip.push_str(" [⏎]");

if filters.are_valid() {
content = content.on_press(Message::Start);
} else {
tooltip = get_invalid_filters_string(filters, language);
}

let tooltip = start_translation(language).to_string();
//tooltip.push_str(" [⏎]");
Tooltip::new(content, tooltip, Position::Top)
.gap(5)
.font(font)
Expand Down
26 changes: 23 additions & 3 deletions src/translations/translations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ pub fn addresses_translation(language: Language) -> &'static str {
}
}

pub fn ip_version_translation(language: Language) -> Text<'static, Renderer<StyleType>> {
Text::new(match language {
pub fn ip_version_translation(language: Language) -> &'static str {
match language {
Language::EN => "IP version",
Language::IT => "Versione IP",
Language::FR => "Version IP",
Expand All @@ -164,7 +164,7 @@ pub fn ip_version_translation(language: Language) -> Text<'static, Renderer<Styl
Language::FI => "IP-versio",
Language::JA => "IP バージョン",
Language::UZ => "IP versiyasi",
})
}
}

pub fn transport_protocol_translation(language: Language) -> &'static str {
Expand All @@ -190,6 +190,26 @@ pub fn transport_protocol_translation(language: Language) -> &'static str {
}
}

pub fn protocol_translation(language: Language) -> &'static str {
match language {
Language::EN | Language::RO => "Protocol",
Language::IT => "Protocollo",
Language::FR => "Protocole",
Language::ES | Language::PT => "Protocolo",
Language::PL => "Protokół",
Language::DE | Language::SV => "Protokoll",
Language::UK | Language::RU => "Протокол",
Language::ZH => "协议",
Language::KO => "프로토콜",
Language::TR => "Protokolü",
Language::EL => "Πρωτόκολλο",
// Language::FA => "پیوندنامهٔ",
Language::FI => "Protokolla",
Language::JA => "プロトコル",
Language::UZ => "Protokoli",
}
}

pub fn traffic_rate_translation(language: Language) -> Text<'static, Renderer<StyleType>> {
Text::new(match language {
Language::EN => "Traffic rate",
Expand Down
8 changes: 8 additions & 0 deletions src/translations/translations_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ pub fn port_translation(language: Language) -> &'static str {
_ => "Port",
}
}

pub fn invalid_filters_translation(language: Language) -> &'static str {
match language {
Language::EN => "Invalid filters",
Language::IT => "Filtri non validi",
_ => "Invalid filters",
}
}
25 changes: 24 additions & 1 deletion src/utils/formatted_strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ use iced::{Font, Renderer};
use crate::gui::styles::text::TextType;
use crate::gui::types::message::Message;
use crate::networking::types::filters::Filters;
use crate::translations::translations::{active_filters_translation, none_translation};
use crate::networking::types::ip_collection::IpCollection;
use crate::networking::types::port_collection::PortCollection;
use crate::translations::translations::{
active_filters_translation, address_translation, ip_version_translation, none_translation,
protocol_translation,
};
use crate::translations::translations_3::{invalid_filters_translation, port_translation};
use crate::{Language, StyleType};

/// Application version number (to be displayed in gui footer)
Expand All @@ -27,6 +33,23 @@ pub fn get_percentage_string(observed: u128, filtered: u128) -> String {
}
}

pub fn get_invalid_filters_string(filters: &Filters, language: Language) -> String {
let mut ret_val = format!("{}:", invalid_filters_translation(language));
if filters.ip.is_empty() {
ret_val.push_str(&format!("\n - {}", ip_version_translation(language)));
}
if filters.transport.is_empty() {
ret_val.push_str(&format!("\n - {}", protocol_translation(language)));
}
if IpCollection::new(&filters.address_str).is_none() {
ret_val.push_str(&format!("\n - {}", address_translation(language)));
}
if PortCollection::new(&filters.port_str).is_none() {
ret_val.push_str(&format!("\n - {}", port_translation(language)));
}
ret_val
}

/// Computes the String representing the active filters
pub fn get_active_filters_col(
filters: &Filters,
Expand Down

0 comments on commit 60b24db

Please sign in to comment.