diff --git a/CHANGELOG.md b/CHANGELOG.md index 2157b27f..1e051c53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All Sniffnet releases with the relative changes are documented in this file. ## [UNRELEASED] -- The size of text and widgets can now be customised by setting a proper scale factor value (fixes [#202](https://github.com/GyulyVGC/sniffnet/issues/202) and [#344](https://github.com/GyulyVGC/sniffnet/issues/344)) +- The size of text and widgets can now be customised by setting a proper zoom value (fixes [#202](https://github.com/GyulyVGC/sniffnet/issues/202) and [#344](https://github.com/GyulyVGC/sniffnet/issues/344)) - Added possibility to totally customize the app's theme via styles defined in TOML files ([#286](https://github.com/GyulyVGC/sniffnet/pull/286)) - Added Japanese translation 🇯🇵 ([#343](https://github.com/GyulyVGC/sniffnet/pull/343)) - Added Uzbek translation 🇺🇿 ([#385](https://github.com/GyulyVGC/sniffnet/pull/385)) @@ -11,6 +11,7 @@ All Sniffnet releases with the relative changes are documented in this file. - Users can now provide custom paths for MMDB files to allow using the commercial versions of the country and ASN databases (fixes [#243](https://github.com/GyulyVGC/sniffnet/issues/243)) - The app's configurations are now stored only on application close, instead of needlessly store them each time the settings popup is closed - The textual output report is not generated anymore +- Settings "Language" tab has been removed. Language selection and other options are now included in a new settings tab "General". - Updated Portuguese translation to v1.2 ([#398](https://github.com/GyulyVGC/sniffnet/pull/398)) - Cleaned code implementing the concept of first class theming ([#339](https://github.com/GyulyVGC/sniffnet/pull/339)) - Added documentation about Sniffnet installation on Nix and Tiny Core Linux (respectively [#394](https://github.com/GyulyVGC/sniffnet/pull/394) and [#341](https://github.com/GyulyVGC/sniffnet/pull/341)) diff --git a/src/configs/types/config_advanced_settings.rs b/src/configs/types/config_advanced_settings.rs index 2eb323e4..88c8e864 100644 --- a/src/configs/types/config_advanced_settings.rs +++ b/src/configs/types/config_advanced_settings.rs @@ -1,7 +1,6 @@ //! Module defining the `ConfigAdvancedSettings` struct, which allows to save and reload //! the application advanced settings. -use crate::utils::formatted_strings::get_default_report_file_path; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone, PartialEq)] @@ -10,7 +9,6 @@ pub struct ConfigAdvancedSettings { pub mmdb_country: String, pub mmdb_asn: String, pub style_path: String, - pub output_path: String, } impl ConfigAdvancedSettings { @@ -42,7 +40,6 @@ impl Default for ConfigAdvancedSettings { mmdb_country: String::new(), mmdb_asn: String::new(), style_path: String::new(), - output_path: get_default_report_file_path(), } } } diff --git a/src/gui/app.rs b/src/gui/app.rs index f4c04daa..cc3c42ef 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -20,8 +20,7 @@ use crate::gui::pages::initial_page::initial_page; use crate::gui::pages::inspect_page::inspect_page; use crate::gui::pages::notifications_page::notifications_page; use crate::gui::pages::overview_page::overview_page; -use crate::gui::pages::settings_advanced_page::settings_advanced_page; -use crate::gui::pages::settings_language_page::settings_language_page; +use crate::gui::pages::settings_general_page::settings_general_page; use crate::gui::pages::settings_notifications_page::settings_notifications_page; use crate::gui::pages::settings_style_page::settings_style_page; use crate::gui::pages::types::running_page::RunningPage; @@ -96,8 +95,7 @@ impl Application for Sniffer { let overlay = match settings_page { SettingsPage::Notifications => settings_notifications_page(self), SettingsPage::Appearance => settings_style_page(self), - SettingsPage::Language => settings_language_page(self), - SettingsPage::Advanced => settings_advanced_page(self), + SettingsPage::General => settings_general_page(self), }; Modal::new(content, overlay) diff --git a/src/gui/components/radio.rs b/src/gui/components/radio.rs index 538cdea2..22521157 100644 --- a/src/gui/components/radio.rs +++ b/src/gui/components/radio.rs @@ -1,6 +1,5 @@ -use iced::widget::horizontal_space; use iced::widget::{Column, Radio, Row, Text}; -use iced::{Alignment, Font, Length, Renderer}; +use iced::{Alignment, Font, Renderer}; use crate::gui::styles::style_constants::FONT_SIZE_SUBTITLE; use crate::gui::styles::text::TextType; @@ -68,37 +67,6 @@ pub fn transport_protocol_radios( ret_val } -pub fn language_radios( - active: Language, - collection: &[Language], - font: Font, -) -> Row<'static, Message, Renderer> { - let mut ret_val = Row::new().spacing(10).align_items(Alignment::Center); - for option in collection { - ret_val = ret_val.push( - Row::new().align_items(Alignment::Center).push( - Row::new() - .align_items(Alignment::Center) - .width(Length::Fixed(200.0)) - .push( - Radio::new( - format!("{} ({:?})", option.get_radio_label(), option), - *option, - Some(active), - Message::LanguageSelection, - ) - .spacing(7) - .font(font) - .size(15), - ) - .push(horizontal_space(Length::Fixed(15.0))) - .push(option.get_flag()), - ), - ); - } - ret_val -} - pub fn sound_packets_threshold_radios( packets_notification: PacketsNotification, font: Font, diff --git a/src/gui/components/tab.rs b/src/gui/components/tab.rs index 8377e709..adc77c72 100644 --- a/src/gui/components/tab.rs +++ b/src/gui/components/tab.rs @@ -134,7 +134,7 @@ fn new_settings_tab( language: Language, font: Font, ) -> Button<'static, Message, Renderer> { - let mut content = Row::new() + let content = Row::new() .align_items(Alignment::Center) .push(horizontal_space(Length::FillPortion(1))) .push( @@ -147,9 +147,9 @@ fn new_settings_tab( }) .horizontal_alignment(alignment::Horizontal::Center) .vertical_alignment(alignment::Vertical::Center), - ); - if page.ne(&SettingsPage::Advanced) { - content = content.push(horizontal_space(10)).push( + ) + .push(horizontal_space(10)) + .push( Text::new(page.get_tab_label(language).to_string()) .font(font) .size(FONT_SIZE_SUBTITLE) @@ -160,18 +160,13 @@ fn new_settings_tab( }) .horizontal_alignment(alignment::Horizontal::Center) .vertical_alignment(alignment::Vertical::Center), - ); - } - content = content.push(horizontal_space(Length::FillPortion(1))); + ) + .push(horizontal_space(Length::FillPortion(1))); button(content) .height(Length::Fixed(if active { 35.0 } else { 30.0 })) .padding(0) - .width(if page.eq(&SettingsPage::Advanced) { - Length::Fixed(45.0) - } else { - Length::FillPortion(1) - }) + .width(Length::FillPortion(1)) .style(if active { ButtonType::TabActive } else { diff --git a/src/gui/pages/mod.rs b/src/gui/pages/mod.rs index 1c807c52..0e294a05 100644 --- a/src/gui/pages/mod.rs +++ b/src/gui/pages/mod.rs @@ -3,8 +3,7 @@ pub mod initial_page; pub mod inspect_page; pub mod notifications_page; pub mod overview_page; -pub mod settings_advanced_page; -pub mod settings_language_page; +pub mod settings_general_page; pub mod settings_notifications_page; pub mod settings_style_page; pub mod types; diff --git a/src/gui/pages/settings_advanced_page.rs b/src/gui/pages/settings_general_page.rs similarity index 61% rename from src/gui/pages/settings_advanced_page.rs rename to src/gui/pages/settings_general_page.rs index bcca8a6f..ab8b10cc 100644 --- a/src/gui/pages/settings_advanced_page.rs +++ b/src/gui/pages/settings_general_page.rs @@ -3,7 +3,10 @@ use std::sync::Arc; use iced::advanced::widget::Text; use iced::alignment::{Horizontal, Vertical}; use iced::widget::tooltip::Position; -use iced::widget::{button, vertical_space, Column, Container, Row, Slider, TextInput, Tooltip}; +use iced::widget::{ + button, horizontal_space, vertical_space, Column, Container, PickList, Row, Rule, Slider, + TextInput, Tooltip, +}; use iced::Length::Fixed; use iced::{Alignment, Font, Length, Renderer}; @@ -16,20 +19,18 @@ use crate::gui::styles::text::TextType; use crate::gui::styles::text_input::TextInputType; use crate::gui::types::message::Message; use crate::mmdb::types::mmdb_reader::MmdbReader; +use crate::translations::translations::language_translation; use crate::translations::translations_2::country_translation; use crate::translations::translations_3::{ - advanced_settings_translation, info_mmdb_paths_translation, mmdb_paths_translation, - params_not_editable_translation, scale_factor_translation, + mmdb_files_translation, params_not_editable_translation, zoom_translation, }; use crate::{Language, RunningPage, Sniffer, StyleType}; -pub fn settings_advanced_page(sniffer: &Sniffer) -> Container> { +pub fn settings_general_page(sniffer: &Sniffer) -> Container> { let font = get_font(sniffer.style); let font_headers = get_font_headers(sniffer.style); - let is_editable = sniffer.running_page.eq(&RunningPage::Init); - - let mut content = Column::new() + let content = Column::new() .align_items(Alignment::Center) .width(Length::Fill) .push(settings_header( @@ -39,22 +40,37 @@ pub fn settings_advanced_page(sniffer: &Sniffer) -> Container Column<'static, Message, Renderer> { + let is_editable = sniffer.running_page.eq(&RunningPage::Init); + + let mut column = Column::new() + .align_items(Alignment::Center) + .padding([5, 10]) + .push(row_language_scale_factor( sniffer.language, font, sniffer.advanced_settings.scale_factor, )) - .push(vertical_space(Fixed(10.0))); + .push(Rule::horizontal(25)); if !is_editable { - content = content + column = column .push( Container::new( Text::new(params_not_editable_translation(sniffer.language)).font(font), @@ -65,37 +81,87 @@ pub fn settings_advanced_page(sniffer: &Sniffer) -> Container Row<'static, Message, Renderer> { + Row::new() + .align_items(Alignment::Center) + .height(Length::Fixed(80.0)) + .push(language_picklist(language, font)) + .push(Rule::vertical(25)) + .push(scale_factor_slider(language, font, scale_factor)) + .push(Rule::vertical(25)) + .push(horizontal_space(Length::FillPortion(1))) } -fn title_row(language: Language, font: Font) -> Row<'static, Message, Renderer> { - Row::new().spacing(10).align_items(Alignment::Center).push( - Text::new(advanced_settings_translation(language)) - .style(TextType::Title) +fn language_picklist( + language: Language, + font: Font, +) -> Container<'static, Message, Renderer> { + let mut flag_row = Row::new() + .align_items(Alignment::Center) + .spacing(10) + .push(language.get_flag()); + if ![Language::EN, Language::IT].contains(&language) { + flag_row = flag_row.push( + Tooltip::new( + button( + Text::new("!") + .font(font) + .vertical_alignment(Vertical::Center) + .horizontal_alignment(Horizontal::Center) + .size(15), + ) + .padding(2) + .height(Fixed(20.0)) + .width(Fixed(20.0)), + " The selected language \nis not fully updated to version 1.3", + Position::Right, + ) .font(font) - .size(FONT_SIZE_SUBTITLE), - ) + .style(ContainerType::Tooltip), + ); + } + + let content = Column::new() + .spacing(5) + .align_items(Alignment::Center) + .push( + Text::new(language_translation(language)) + .style(TextType::Subtitle) + .size(FONT_SIZE_SUBTITLE) + .font(font), + ) + .push(flag_row) + .push( + PickList::new( + &Language::ALL[..], + Some(language), + Message::LanguageSelection, + ) + .padding([3, 7]) + .font(font), + ); + + Container::new(content) + .width(Length::FillPortion(1)) + .align_x(Horizontal::Center) + .align_y(Vertical::Center) } fn scale_factor_slider( @@ -110,8 +176,9 @@ fn scale_factor_slider( .spacing(5) .align_items(Alignment::Center) .push( - Text::new(scale_factor_translation(language)) + Text::new(zoom_translation(language)) .style(TextType::Subtitle) + .size(FONT_SIZE_SUBTITLE) .font(font), ) .push(Text::new(format!("x{scale_factor:.2}")).font(font)) @@ -121,6 +188,7 @@ fn scale_factor_slider( .width(Fixed(slider_width)), ), ) + .width(Length::FillPortion(1)) .align_x(Horizontal::Center) .align_y(Vertical::Center) } @@ -160,31 +228,9 @@ fn mmdb_settings( .spacing(5) .align_items(Alignment::Center) .push( - Row::new() - .spacing(10) - .push( - Text::new(mmdb_paths_translation(language)) - .font(font) - .style(TextType::Subtitle), - ) - .push( - Tooltip::new( - button( - Text::new("i") - .font(font) - .vertical_alignment(Vertical::Center) - .horizontal_alignment(Horizontal::Center) - .size(15), - ) - .padding(2) - .height(Fixed(20.0)) - .width(Fixed(20.0)), - info_mmdb_paths_translation(language), - Position::Top, - ) - .font(font) - .style(ContainerType::Tooltip), - ), + Text::new(mmdb_files_translation(language)) + .font(font) + .style(TextType::Subtitle), ) .push( Row::new() diff --git a/src/gui/pages/settings_language_page.rs b/src/gui/pages/settings_language_page.rs deleted file mode 100644 index 7f1cd01f..00000000 --- a/src/gui/pages/settings_language_page.rs +++ /dev/null @@ -1,76 +0,0 @@ -use iced::widget::vertical_space; -use iced::widget::{Column, Container, Text}; -use iced::Length::Fixed; -use iced::{Alignment, Length, Renderer}; - -use crate::gui::components::radio::language_radios; -use crate::gui::components::tab::get_settings_tabs; -use crate::gui::pages::settings_notifications_page::settings_header; -use crate::gui::pages::types::settings_page::SettingsPage; -use crate::gui::styles::container::ContainerType; -use crate::gui::styles::style_constants::{get_font, get_font_headers, FONT_SIZE_SUBTITLE}; -use crate::gui::styles::text::TextType; -use crate::gui::types::message::Message; -use crate::translations::translations::languages_title_translation; -use crate::{Language, Sniffer, StyleType}; - -pub fn settings_language_page(sniffer: &Sniffer) -> Container> { - let font = get_font(sniffer.style); - let font_headers = get_font_headers(sniffer.style); - - let language_active = sniffer.language; - let row_language_radio_1 = language_radios(language_active, &Language::ROW1, font); - let row_language_radio_2 = language_radios(language_active, &Language::ROW2, font); - let row_language_radio_3 = language_radios(language_active, &Language::ROW3, font); - let row_language_radio_4 = language_radios(language_active, &Language::ROW4, font); - let row_language_radio_5 = language_radios(language_active, &Language::ROW5, font); - let row_language_radio_6 = language_radios(language_active, &Language::ROW6, font); - let col_language_radio_all = Column::new() - .spacing(12) - .align_items(Alignment::Center) - .push(row_language_radio_1) - .push(row_language_radio_2) - .push(row_language_radio_3) - .push(row_language_radio_4) - .push(row_language_radio_5) - .push(row_language_radio_6); - - let mut content = Column::new() - .align_items(Alignment::Center) - .width(Length::Fill) - .push(settings_header( - font, - font_headers, - sniffer.color_gradient, - sniffer.language, - )) - .push(get_settings_tabs( - SettingsPage::Language, - font, - sniffer.language, - )) - .push(vertical_space(Fixed(15.0))) - .push( - languages_title_translation(sniffer.language) - .style(TextType::Subtitle) - .font(font) - .size(FONT_SIZE_SUBTITLE), - ) - .push(vertical_space(Fixed(25.0))) - .push(col_language_radio_all); - - if sniffer.language.eq(&Language::EL) { - content = content.push(vertical_space(Fixed(20.0))).push( - Container::new( - Text::new("The selected language is not fully updated to version 1.2").font(font), - ) - .padding(10.0) - .style(ContainerType::Badge), - ); - } - - Container::new(content) - .height(Fixed(400.0)) - .width(Fixed(800.0)) - .style(ContainerType::Modal) -} diff --git a/src/gui/pages/types/settings_page.rs b/src/gui/pages/types/settings_page.rs index 3b6d3aec..d0caf7bb 100644 --- a/src/gui/pages/types/settings_page.rs +++ b/src/gui/pages/types/settings_page.rs @@ -1,9 +1,8 @@ use iced::Renderer; use crate::gui::types::message::Message; -use crate::translations::translations::{ - language_translation, notifications_translation, style_translation, -}; +use crate::translations::translations::{notifications_translation, style_translation}; +use crate::translations::translations_3::general_translation; use crate::utils::types::icon::Icon; use crate::{Language, StyleType}; @@ -14,44 +13,38 @@ pub enum SettingsPage { Notifications, /// Settings Appearance page. Appearance, - /// Settings Language page. - Language, - /// Advanced settings. - Advanced, + /// General settings. + General, } impl SettingsPage { - pub const ALL: [SettingsPage; 4] = [ + pub const ALL: [SettingsPage; 3] = [ SettingsPage::Notifications, SettingsPage::Appearance, - SettingsPage::Language, - SettingsPage::Advanced, + SettingsPage::General, ]; pub fn get_tab_label(&self, language: Language) -> &str { match self { SettingsPage::Notifications => notifications_translation(language), SettingsPage::Appearance => style_translation(language), - SettingsPage::Language => language_translation(language), - SettingsPage::Advanced => "", + SettingsPage::General => general_translation(language), } } pub fn next(self) -> Self { match self { SettingsPage::Notifications => SettingsPage::Appearance, - SettingsPage::Appearance => SettingsPage::Language, - SettingsPage::Language => SettingsPage::Advanced, - SettingsPage::Advanced => SettingsPage::Notifications, + SettingsPage::Appearance => SettingsPage::General, + SettingsPage::General => SettingsPage::Notifications, } } pub fn previous(self) -> Self { match self { - SettingsPage::Notifications => SettingsPage::Advanced, + SettingsPage::Notifications => SettingsPage::General, SettingsPage::Appearance => SettingsPage::Notifications, - SettingsPage::Language => SettingsPage::Appearance, - SettingsPage::Advanced => SettingsPage::Language, + SettingsPage::General => SettingsPage::Appearance, } } @@ -59,8 +52,7 @@ impl SettingsPage { match self { SettingsPage::Notifications => Icon::Notification, SettingsPage::Appearance => Icon::HalfSun, - SettingsPage::Language => Icon::Globe, - SettingsPage::Advanced => Icon::Dots, + SettingsPage::General => Icon::Dots, } .to_text() } @@ -78,21 +70,21 @@ mod tests { fn test_previous_settings_page() { assert_eq!( SettingsPage::Notifications.previous(), - SettingsPage::Advanced + SettingsPage::General ); assert_eq!( SettingsPage::Appearance.previous(), SettingsPage::Notifications ); assert_eq!(SettingsPage::Language.previous(), SettingsPage::Appearance); - assert_eq!(SettingsPage::Advanced.previous(), SettingsPage::Language); + assert_eq!(SettingsPage::General.previous(), SettingsPage::Language); } #[test] fn test_next_settings_page() { assert_eq!(SettingsPage::Notifications.next(), SettingsPage::Appearance); assert_eq!(SettingsPage::Appearance.next(), SettingsPage::Language); - assert_eq!(SettingsPage::Language.next(), SettingsPage::Advanced); - assert_eq!(SettingsPage::Advanced.next(), SettingsPage::Notifications); + assert_eq!(SettingsPage::Language.next(), SettingsPage::General); + assert_eq!(SettingsPage::General.next(), SettingsPage::Notifications); } } diff --git a/src/gui/types/sniffer.rs b/src/gui/types/sniffer.rs index b9f2f7f0..5c5e8c73 100644 --- a/src/gui/types/sniffer.rs +++ b/src/gui/types/sniffer.rs @@ -1160,7 +1160,7 @@ mod tests { assert_eq!(sniffer.settings_page, Some(SettingsPage::Notifications)); assert_eq!(sniffer.running_page, RunningPage::Init); sniffer.update(Message::SwitchPage(false)); - assert_eq!(sniffer.settings_page, Some(SettingsPage::Advanced)); + assert_eq!(sniffer.settings_page, Some(SettingsPage::General)); assert_eq!(sniffer.modal, None); assert_eq!(sniffer.running_page, RunningPage::Init); sniffer.update(Message::SwitchPage(true)); diff --git a/src/translations/translations.rs b/src/translations/translations.rs index 01e58617..16bd90b3 100644 --- a/src/translations/translations.rs +++ b/src/translations/translations.rs @@ -1143,30 +1143,6 @@ pub fn appearance_title_translation(language: Language) -> Text<'static, Rendere }) } -pub fn languages_title_translation(language: Language) -> Text<'static, Renderer> { - Text::new(match language { - Language::EN => "Select your language", - Language::IT => "Seleziona la lingua", - Language::FR => "Sélectionnez votre langue", - Language::ES => "Selecciona tu idioma", - Language::PL => "Wybierz język", - Language::DE => "Stell deine Sprache ein", - Language::UK => "Вибери мову", - Language::ZH => "选择显示语言", - Language::RO => "Selectați limba", - Language::KO => "언어를 선택하세요", - Language::TR => "Dilinizi seçin", - Language::RU => "Выберите язык", - Language::PT => "Selecione o seu idioma", - Language::EL => "Επίλεξε τη γλώσσα σου", - // Language::FA => "زبان خود را انتخاب کنید", - Language::SV => "Välj ditt språk", - Language::FI => "Valitse kielesi", - Language::JA => "表示言語を選択してください", - Language::UZ => "Tilingizni tanlang", - }) -} - pub fn active_filters_translation(language: Language) -> &'static str { match language { Language::EN => "Active filters", diff --git a/src/translations/translations_3.rs b/src/translations/translations_3.rs index 4527dd1c..b013a906 100644 --- a/src/translations/translations_3.rs +++ b/src/translations/translations_3.rs @@ -2,44 +2,27 @@ use crate::Language; -pub fn advanced_settings_translation(language: Language) -> &'static str { +// This is referred to settings (General settings) +pub fn general_translation(language: Language) -> &'static str { match language { - Language::EN => "Advanced settings", - Language::IT => "Impostazioni avanzate", - _ => "Advanced settings", + Language::EN => "General", + Language::IT => "Generali", + _ => "General", } } -pub fn scale_factor_translation(language: Language) -> &'static str { +pub fn zoom_translation(language: Language) -> &'static str { match language { - Language::EN => "Scale factor", - Language::IT => "Fattore di scala", - _ => "Scale factor", + Language::EN | Language::IT => "Zoom", + _ => "Zoom", } } -pub fn mmdb_paths_translation(language: Language) -> &'static str { +pub fn mmdb_files_translation(language: Language) -> &'static str { match language { - Language::EN => "Database file paths (MMDB format)", - Language::IT => "Percorsi dei file di database (formato MMDB)", - _ => "Database file paths (MMDB format)", - } -} - -pub fn info_mmdb_paths_translation(language: Language) -> &'static str { - match language { - Language::EN => { - "You can specify database files different from the default ones. \n\ - This is useful if you own the commercial version of such databases." - } - Language::IT => { - "Puoi specificare file di database diversi da quelli predefiniti. \n\ - Ciò è utile se possiedi la versione commerciale di tali database." - } - _ => { - "You can specify database files different from the default ones. \n\ - This is useful if you own the commercial version of such databases." - } + Language::EN => "Database files (MMDB format)", + Language::IT => "File di database (formato MMDB)", + _ => "Database files (MMDB format)", } } diff --git a/src/translations/types/language.rs b/src/translations/types/language.rs index 7eaf6d4f..43f2b049 100644 --- a/src/translations/types/language.rs +++ b/src/translations/types/language.rs @@ -2,9 +2,10 @@ use iced::widget::svg::Handle; use iced::widget::Svg; use iced::{Length, Renderer}; use serde::{Deserialize, Serialize}; +use std::fmt; use crate::countries::flags_pictures::{ - CN, DE, ES, FI, FLAGS_WIDTH_SMALL, FR, GB, GR, IT, JP, KR, PL, PT, RO, RU, SE, TR, UA, UZ, + CN, DE, ES, FI, FLAGS_WIDTH_BIG, FR, GB, GR, IT, JP, KR, PL, PT, RO, RU, SE, TR, UA, UZ, }; use crate::StyleType; @@ -58,36 +59,26 @@ impl Default for Language { } impl Language { - pub(crate) const ROW1: [Language; 3] = [Language::EN, Language::DE, Language::EL]; - pub(crate) const ROW2: [Language; 3] = [Language::ES, Language::FI, Language::FR]; - pub(crate) const ROW3: [Language; 3] = [Language::IT, Language::JA, Language::KO]; - pub(crate) const ROW4: [Language; 3] = [Language::PL, Language::PT, Language::RO]; - pub(crate) const ROW5: [Language; 3] = [Language::RU, Language::SV, Language::TR]; - pub(crate) const ROW6: [Language; 3] = [Language::UK, Language::UZ, Language::ZH]; - - pub fn get_radio_label(&self) -> &str { - match self { - Language::EN => "English", - Language::IT => "Italiano", - Language::FR => "Français", - Language::ES => "Español", - Language::PL => "Polski", - Language::DE => "Deutsch", - Language::UK => "Українська", - Language::ZH => "简体中文", - Language::RO => "Română", - Language::KO => "한국어", - Language::TR => "Türkçe", - Language::RU => "Русский", - Language::PT => "Português", - Language::EL => "Ελληνικά", - // Language::FA => "فارسی", - Language::SV => "Svenska", - Language::FI => "Suomi", - Language::JA => "日本語", - Language::UZ => "O'zbekcha", - } - } + pub const ALL: [Language; 18] = [ + Language::EN, + Language::DE, + Language::EL, + Language::ES, + Language::FI, + Language::FR, + Language::IT, + Language::JA, + Language::KO, + Language::PL, + Language::PT, + Language::RO, + Language::RU, + Language::SV, + Language::TR, + Language::UK, + Language::UZ, + Language::ZH, + ]; pub fn get_flag(self) -> Svg> { Svg::new(Handle::from_memory(Vec::from(match self { @@ -111,6 +102,33 @@ impl Language { Language::JA => JP, Language::UZ => UZ, }))) - .width(Length::Fixed(FLAGS_WIDTH_SMALL)) + .width(Length::Fixed(FLAGS_WIDTH_BIG)) + } +} + +impl fmt::Display for Language { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let lang_str = match self { + Language::EN => "English", + Language::IT => "Italiano", + Language::FR => "Français", + Language::ES => "Español", + Language::PL => "Polski", + Language::DE => "Deutsch", + Language::UK => "Українська", + Language::ZH => "简体中文", + Language::RO => "Română", + Language::KO => "한국어", + Language::TR => "Türkçe", + Language::RU => "Русский", + Language::PT => "Português", + Language::EL => "Ελληνικά", + // Language::FA => "فارسی", + Language::SV => "Svenska", + Language::FI => "Suomi", + Language::JA => "日本語", + Language::UZ => "O'zbekcha", + }; + write!(f, "{self:?} - {lang_str}") } } diff --git a/src/utils/formatted_strings.rs b/src/utils/formatted_strings.rs index fad5898e..07fa74c0 100644 --- a/src/utils/formatted_strings.rs +++ b/src/utils/formatted_strings.rs @@ -1,5 +1,4 @@ use std::net::IpAddr; -use std::path::PathBuf; use iced::widget::{Column, Text}; use iced::{Font, Renderer}; @@ -13,7 +12,7 @@ use crate::{AppProtocol, IpVersion, Language, StyleType, TransProtocol}; /// Application version number (to be displayed in gui footer) pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION"); -pub const PCAP_FILE_NAME: &str = "sniffnet.pcap"; +// pub const PCAP_FILE_NAME: &str = "sniffnet.pcap"; /// Computes the String representing the percentage of filtered bytes/packets pub fn get_percentage_string(observed: u128, filtered: u128) -> String { @@ -102,18 +101,18 @@ pub fn get_formatted_bytes_string_with_b(bytes: u128) -> String { bytes_string } -/// Returns the default report path -pub fn get_default_report_file_path() -> String { - return if let Ok(mut config_path) = confy::get_configuration_file_path("sniffnet", "file") { - config_path.pop(); - config_path.push(PCAP_FILE_NAME); - config_path.to_string_lossy().to_string() - } else { - let mut path = PathBuf::from(std::env::var_os("HOME").unwrap()); - path.push(PCAP_FILE_NAME); - path.to_string_lossy().to_string() - }; -} +// /// Returns the default report path +// pub fn get_default_report_file_path() -> String { +// return if let Ok(mut config_path) = confy::get_configuration_file_path("sniffnet", "file") { +// config_path.pop(); +// config_path.push(PCAP_FILE_NAME); +// config_path.to_string_lossy().to_string() +// } else { +// let mut path = PathBuf::from(std::env::var_os("HOME").unwrap()); +// path.push(PCAP_FILE_NAME); +// path.to_string_lossy().to_string() +// }; +// } // /// Returns the file to use for the output PCAP report // /// It tries and fallbacks in the order: custom path, configs path, home directory path