Skip to content

Commit

Permalink
substituted radio components with buttons and fixed favorite notifica…
Browse files Browse the repository at this point in the history
…tions bug
  • Loading branch information
GyulyVGC committed Dec 21, 2023
1 parent 223352e commit 5274187
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 172 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ All Sniffnet releases with the relative changes are documented in this file.
- 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))
- General aesthetic improvements
- Fixed bug about not delivered favorite notifications in presence of old outgoing connections
- Fixed bug causing the application's icon not to be visible in some Linux environments
- Fixed a build failure on `powerpc64` ([#356](https://github.com/GyulyVGC/sniffnet/pull/356) — fixes [#353](https://github.com/GyulyVGC/sniffnet/issues/353))
- Fixed a typo in Russian translation ([#389](https://github.com/GyulyVGC/sniffnet/pull/389))
Expand Down
2 changes: 1 addition & 1 deletion src/chart/types/chart_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub enum ChartType {
impl ChartType {
pub(crate) const ALL: [ChartType; 2] = [ChartType::Bytes, ChartType::Packets];

pub fn get_radio_label(&self, language: Language) -> &str {
pub fn get_label(&self, language: Language) -> &str {
match self {
ChartType::Packets => packets_translation(language),
ChartType::Bytes => bytes_translation(language),
Expand Down
1 change: 0 additions & 1 deletion src/gui/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ pub mod button;
pub mod footer;
pub mod header;
pub mod modal;
pub mod radio;
pub mod tab;
pub mod types;
131 changes: 0 additions & 131 deletions src/gui/components/radio.rs

This file was deleted.

1 change: 1 addition & 0 deletions src/gui/pages/initial_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ fn col_protocol_buttons(
buttons_row = buttons_row.push(
Button::new(
Text::new(format!("{option} {check_symbol}"))
.width(Length::Fill)
.shaping(Shaping::Advanced)
.horizontal_alignment(Horizontal::Center)
.vertical_alignment(Vertical::Center)
Expand Down
36 changes: 27 additions & 9 deletions src/gui/pages/overview_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use iced::{Alignment, Font, Length, Renderer};

use crate::countries::country_utils::get_flag_tooltip;
use crate::countries::flags_pictures::FLAGS_WIDTH_BIG;
use crate::gui::components::radio::chart_radios;
use crate::gui::components::tab::get_pages_tabs;
use crate::gui::styles::button::ButtonType;
use crate::gui::styles::container::ContainerType;
Expand Down Expand Up @@ -532,14 +531,33 @@ fn col_data_representation(
font: Font,
chart_type: ChartType,
) -> Column<'static, Message, Renderer<StyleType>> {
Column::new()
.width(Length::FillPortion(1))
.push(
Text::new(format!("{}:", data_representation_translation(language)))
.style(TextType::Subtitle)
.font(font),
)
.push(chart_radios(chart_type, font, language))
let mut ret_val = Column::new().spacing(5).width(Length::FillPortion(1)).push(
Text::new(format!("{}:", data_representation_translation(language)))
.style(TextType::Subtitle)
.font(font),
);

for option in ChartType::ALL {
let is_active = chart_type.eq(&option);
ret_val = ret_val.push(
Button::new(
Text::new(option.get_label(language).to_owned())
.width(Length::Fill)
.horizontal_alignment(Horizontal::Center)
.vertical_alignment(Vertical::Center)
.font(font),
)
.width(Length::Fill)
.height(Length::Fixed(33.0))
.style(if is_active {
ButtonType::BorderedRoundSelected
} else {
ButtonType::BorderedRound
})
.on_press(Message::ChartSelection(option)),
);
}
ret_val
}

fn col_bytes_packets(
Expand Down
91 changes: 69 additions & 22 deletions src/gui/pages/settings_notifications_page.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use iced::alignment::{Horizontal, Vertical};
use iced::widget::scrollable::Direction;
use iced::widget::Slider;
use iced::widget::{
horizontal_space, vertical_space, Checkbox, Column, Container, Row, Scrollable, Text, TextInput,
};
use iced::widget::{Button, Slider};
use iced::Length::Fixed;
use iced::{Alignment, Font, Length, Renderer};

use crate::gui::components::button::button_hide;
use crate::gui::components::radio::{
sound_bytes_threshold_radios, sound_favorite_radios, sound_packets_threshold_radios,
};
use crate::gui::components::tab::get_settings_tabs;
use crate::gui::pages::types::settings_page::SettingsPage;
use crate::gui::styles::button::ButtonType;
use crate::gui::styles::container::ContainerType;
use crate::gui::styles::scrollbar::ScrollbarType;
use crate::gui::styles::style_constants::{
Expand All @@ -24,10 +22,12 @@ use crate::gui::types::message::Message;
use crate::notifications::types::notifications::{
BytesNotification, FavoriteNotification, Notification, PacketsNotification,
};
use crate::notifications::types::sound::Sound;
use crate::translations::translations::{
bytes_threshold_translation, favorite_notification_translation,
notifications_title_translation, packets_threshold_translation, per_second_translation,
settings_translation, specify_multiples_translation, threshold_translation, volume_translation,
settings_translation, sound_translation, specify_multiples_translation, threshold_translation,
volume_translation,
};
use crate::utils::types::icon::Icon;
use crate::{Language, Sniffer, StyleType};
Expand Down Expand Up @@ -144,14 +144,13 @@ fn get_packets_notify(
.push(horizontal_space(Fixed(50.0)))
.push(Text::new(format!("{}: ", threshold_translation(language))).font(font))
.push(input_group_packets(packets_notification, font, language));
let sound_row =
Row::new()
.push(horizontal_space(Fixed(50.0)))
.push(sound_packets_threshold_radios(
packets_notification,
font,
language,
));
let sound_row = Row::new()
.push(horizontal_space(Fixed(50.0)))
.push(sound_buttons(
Notification::Packets(packets_notification),
font,
language,
));
ret_val = ret_val
.push(vertical_space(Fixed(5.0)))
.push(input_row)
Expand Down Expand Up @@ -210,14 +209,13 @@ fn get_bytes_notify(
.push(horizontal_space(Fixed(50.0)))
.push(Text::new(format!("{}: ", threshold_translation(language))).font(font))
.push(input_group_bytes(bytes_notification, font, language));
let sound_row =
Row::new()
.push(horizontal_space(Fixed(50.0)))
.push(sound_bytes_threshold_radios(
bytes_notification,
font,
language,
));
let sound_row = Row::new()
.push(horizontal_space(Fixed(50.0)))
.push(sound_buttons(
Notification::Bytes(bytes_notification),
font,
language,
));
ret_val = ret_val
.push(vertical_space(Fixed(5.0)))
.push(input_row)
Expand Down Expand Up @@ -258,7 +256,11 @@ fn get_favorite_notify(
if favorite_notification.notify_on_favorite {
let sound_row = Row::new()
.push(horizontal_space(Fixed(50.0)))
.push(sound_favorite_radios(favorite_notification, font, language));
.push(sound_buttons(
Notification::Favorite(favorite_notification),
font,
language,
));
ret_val = ret_val.push(vertical_space(Fixed(5.0))).push(sound_row);
Column::new().padding(5).push(
Container::new(ret_val)
Expand Down Expand Up @@ -397,6 +399,51 @@ fn volume_slider(
.align_y(Vertical::Center)
}

pub fn sound_buttons(
notification: Notification,
font: Font,
language: Language,
) -> Row<'static, Message, Renderer<StyleType>> {
let current_sound = match notification {
Notification::Packets(n) => n.sound,
Notification::Bytes(n) => n.sound,
Notification::Favorite(n) => n.sound,
};

let mut ret_val = Row::new()
.align_items(Alignment::Center)
.spacing(5)
.push(Text::new(format!("{}:", sound_translation(language))).font(font));

for option in Sound::ALL {
let is_active = current_sound.eq(&option);
let message_value = match notification {
Notification::Packets(n) => {
Notification::Packets(PacketsNotification { sound: option, ..n })
}
Notification::Bytes(n) => Notification::Bytes(BytesNotification { sound: option, ..n }),
Notification::Favorite(n) => {
Notification::Favorite(FavoriteNotification { sound: option, ..n })
}
};
ret_val = ret_val.push(
Button::new(option.get_text(font))
.width(Length::Fixed(90.0))
.height(Length::Fixed(30.0))
.style(if is_active {
ButtonType::BorderedRoundSelected
} else {
ButtonType::BorderedRound
})
.on_press(Message::UpdateNotificationSettings(
message_value,
option.ne(&Sound::None),
)),
);
}
ret_val
}

pub fn settings_header(
font: Font,
font_headers: Font,
Expand Down
2 changes: 1 addition & 1 deletion src/networking/manage_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub fn modify_or_insert_in_map(

if let Some(host_info) = info_traffic
.addresses_resolved
.get(&get_address_to_lookup(key, traffic_direction))
.get(&get_address_to_lookup(key, new_info.traffic_direction))
.cloned()
{
if info_traffic.favorite_hosts.contains(&host_info.1) {
Expand Down
Loading

0 comments on commit 5274187

Please sign in to comment.