Skip to content

Commit

Permalink
start the analysis only if all filters are valid
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Dec 15, 2023
1 parent af6ffaf commit 8f8af54
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 19 deletions.
41 changes: 29 additions & 12 deletions src/gui/pages/initial_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use iced::widget::scrollable::Direction;
use iced::widget::text::Shaping;
use iced::widget::tooltip::Position;
use iced::widget::{
button, horizontal_space, vertical_space, Button, Column, Container, Row, Scrollable, Text,
TextInput, Tooltip,
button, horizontal_space, vertical_space, Button, Column, Container, Row, Rule, Scrollable,
Text, TextInput, Tooltip,
};
use iced::Length::FillPortion;
use iced::{alignment, Font, Length, Renderer};
Expand All @@ -24,6 +24,7 @@ use crate::gui::styles::text_input::TextInputType;
use crate::gui::styles::types::gradient_type::GradientType;
use crate::gui::types::message::Message;
use crate::gui::types::sniffer::Sniffer;
use crate::networking::types::filters::Filters;
use crate::networking::types::ip_collection::IpCollection;
use crate::networking::types::port_collection::PortCollection;
use crate::translations::translations::{
Expand Down Expand Up @@ -78,7 +79,19 @@ pub fn initial_page(sniffer: &Sniffer) -> Container<Message, Renderer<StyleType>
.push(col_address_filter)
.push(col_port_filter),
)
.push(button_start(font, language, color_gradient));
.push(Rule::horizontal(40))
.push(
Container::new(button_start(
font,
language,
color_gradient,
&sniffer.filters,
))
.width(Length::Fill)
.height(Length::Fill)
.align_y(Vertical::Center)
.align_x(Horizontal::Center),
);

let body = Column::new().push(vertical_space(Length::Fixed(5.0))).push(
Row::new()
Expand All @@ -98,10 +111,10 @@ fn col_ip_buttons(
let mut buttons_row = Row::new().spacing(5).padding([0, 0, 0, 5]);
for option in IpVersion::ALL {
let is_active = active_ip_filters.contains(&option);
let check_simbol = if is_active { "✔" } else { "✘" };
let check_symbol = if is_active { "✔" } else { "✘" };
buttons_row = buttons_row.push(
Button::new(
Text::new(format!("{check_simbol} {option}"))
Text::new(format!("{option} {check_symbol}"))
.shaping(Shaping::Advanced)
.horizontal_alignment(Horizontal::Center)
.vertical_alignment(Vertical::Center)
Expand Down Expand Up @@ -138,10 +151,10 @@ fn col_transport_buttons(
let mut buttons_row = Row::new().spacing(5).padding([0, 0, 0, 5]);
for option in TransProtocol::ALL {
let is_active = active_transport_filters.contains(&option);
let check_simbol = if is_active { "✔" } else { "✘" };
let check_symbol = if is_active { "✔" } else { "✘" };
buttons_row = buttons_row.push(
Button::new(
Text::new(format!("{check_simbol} {option}"))
Text::new(format!("{option} {check_symbol}"))
.shaping(Shaping::Advanced)
.horizontal_alignment(Horizontal::Center)
.vertical_alignment(Vertical::Center)
Expand Down Expand Up @@ -182,7 +195,7 @@ fn col_address_input(
};
let input_row = Row::new().padding([0, 0, 0, 5]).push(
TextInput::new(IpCollection::PLACEHOLDER_STR, value)
.padding([0, 5])
.padding([2, 5])
.on_input(Message::AddressFilter)
.font(font)
.width(Length::Fixed(310.0))
Expand Down Expand Up @@ -217,7 +230,7 @@ fn col_port_input(
};
let input_row = Row::new().padding([0, 0, 0, 5]).push(
TextInput::new(PortCollection::PLACEHOLDER_STR, value)
.padding([0, 5])
.padding([2, 5])
.on_input(Message::PortFilter)
.font(font)
.width(Length::Fixed(180.0))
Expand All @@ -244,8 +257,9 @@ fn button_start(
font: Font,
language: Language,
color_gradient: GradientType,
filters: &Filters,
) -> Tooltip<'static, Message, Renderer<StyleType>> {
let content = button(
let mut content = button(
Icon::Rocket
.to_text()
.size(25)
Expand All @@ -255,8 +269,11 @@ fn button_start(
.padding(10)
.height(Length::Fixed(80.0))
.width(Length::Fixed(160.0))
.style(ButtonType::Gradient(color_gradient))
.on_press(Message::Start);
.style(ButtonType::Gradient(color_gradient));

if filters.are_valid() {
content = content.on_press(Message::Start);
}

let tooltip = start_translation(language).to_string();
//tooltip.push_str(" [⏎]");
Expand Down
26 changes: 25 additions & 1 deletion src/gui/styles/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl button::StyleSheet for StyleType {
&colors,
*gradient_type,
self.is_nightly(),
1.0,
)),
_ => Background::Color(colors.buttons),
}),
Expand Down Expand Up @@ -146,6 +147,29 @@ impl button::StyleSheet for StyleType {
}

fn disabled(&self, style: &Self::Style) -> Appearance {
button::StyleSheet::active(self, style)
let colors = get_colors(*self);
button::Appearance {
background: Some(match style {
ButtonType::Gradient(GradientType::None) => Background::Color(Color {
a: get_alpha_round_containers(*self),
..colors.secondary
}),
ButtonType::Gradient(gradient_type) => Background::Gradient(get_gradient_buttons(
&colors,
*gradient_type,
self.is_nightly(),
get_alpha_round_containers(*self),
)),
_ => Background::Color(colors.buttons),
}),
border_radius: BORDER_BUTTON_RADIUS.into(),
border_width: BORDER_WIDTH,
shadow_offset: Vector::new(0.0, 0.0),
text_color: colors.text_headers,
border_color: Color {
a: get_alpha_round_containers(*self),
..colors.secondary
},
}
}
}
20 changes: 15 additions & 5 deletions src/gui/styles/types/gradient_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub fn get_gradient_buttons(
colors: &Palette,
gradient_type: GradientType,
is_nightly: bool,
alpha: f32,
) -> Gradient {
let mix = if is_nightly {
Color::BLACK
Expand All @@ -61,13 +62,22 @@ pub fn get_gradient_buttons(
iced::gradient::Linear::new(Degrees(225.0))
.add_stop(
0.0,
match gradient_type {
GradientType::Mild => mix_colors(mix, colors.secondary),
GradientType::Wild => colors.outgoing,
GradientType::None => colors.secondary,
Color {
a: alpha,
..match gradient_type {
GradientType::Mild => mix_colors(mix, colors.secondary),
GradientType::Wild => colors.outgoing,
GradientType::None => colors.secondary,
}
},
)
.add_stop(1.0, colors.secondary),
.add_stop(
1.0,
Color {
a: alpha,
..colors.secondary
},
),
)
}

Expand Down
4 changes: 3 additions & 1 deletion src/gui/types/sniffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,9 @@ impl Sniffer {
&& self.settings_page.is_none()
&& self.modal.is_none()
{
return self.update(Message::Start);
if self.filters.are_valid() {
return self.update(Message::Start);
}
} else if self.modal.eq(&Some(MyModal::Quit)) {
return self.update(Message::Reset);
} else if self.modal.eq(&Some(MyModal::ClearAll)) {
Expand Down
7 changes: 7 additions & 0 deletions src/networking/types/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ impl Filters {
&& (self.port_collection.contains(packet_filters_fields.sport)
|| self.port_collection.contains(packet_filters_fields.dport))
}

pub fn are_valid(&self) -> bool {
!self.ip.is_empty()
&& !self.transport.is_empty()
&& IpCollection::new(&self.address_str).is_some()
&& PortCollection::new(&self.port_str).is_some()
}
}

0 comments on commit 8f8af54

Please sign in to comment.