Skip to content

Commit

Permalink
Merge pull request #659 from GyulyVGC/combobox
Browse files Browse the repository at this point in the history
Network host filters autocompletion via a dropdown menu
  • Loading branch information
GyulyVGC authored Jan 1, 2025
2 parents 5d97292 + 2152b51 commit 4be7847
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All Sniffnet releases with the relative changes are documented in this file.

## [UNRELEASED]
- Dropdown menus for network host filters ([#659](https://github.com/GyulyVGC/sniffnet/pull/659) — fixes [#354](https://github.com/GyulyVGC/sniffnet/issues/354))
- Added CLI argument `--adapter [<NAME>]` to allow immediately starting the capture from a given network interface ([#643](https://github.com/GyulyVGC/sniffnet/pull/643) — fixes [#636](https://github.com/GyulyVGC/sniffnet/issues/636))
- Added Vietnamese translation 🇻🇳 ([#577](https://github.com/GyulyVGC/sniffnet/pull/577))
- Ask for quit confirmation before stopping an ongoing analysis ([#652](https://github.com/GyulyVGC/sniffnet/pull/652) — fixes [#570](https://github.com/GyulyVGC/sniffnet/issues/570))
Expand Down
6 changes: 3 additions & 3 deletions src/gui/components/footer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! GUI bottom footer
use std::sync::{Arc, Mutex};
use std::sync::Mutex;

use iced::widget::text::LineHeight;
use iced::widget::tooltip::Position;
Expand Down Expand Up @@ -28,7 +28,7 @@ pub fn footer<'a>(
color_gradient: GradientType,
font: Font,
font_footer: Font,
newer_release_available: &Arc<Mutex<Option<bool>>>,
newer_release_available: &Mutex<Option<bool>>,
) -> Container<'a, Message, StyleType> {
if thumbnail {
return thumbnail_footer();
Expand Down Expand Up @@ -136,7 +136,7 @@ fn get_release_details<'a>(
language: Language,
font: Font,
font_footer: Font,
newer_release_available: &Arc<Mutex<Option<bool>>>,
newer_release_available: &Mutex<Option<bool>>,
) -> Row<'a, Message, StyleType> {
let mut ret_val = Row::new()
.align_y(Alignment::Center)
Expand Down
115 changes: 99 additions & 16 deletions src/gui/pages/inspect_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use iced::widget::text::LineHeight;
use iced::widget::text_input::Side;
use iced::widget::tooltip::Position;
use iced::widget::{
button, horizontal_space, text_input, vertical_space, Rule, Space, Toggler, Tooltip,
button, combo_box, horizontal_space, text_input, vertical_space, ComboBox, Rule, Space,
Toggler, Tooltip,
};
use iced::widget::{lazy, Button, Column, Container, Row, Scrollable, Text, TextInput};
use iced::{alignment, Alignment, Font, Length, Padding, Pixels};
Expand All @@ -20,6 +21,7 @@ use crate::gui::styles::text::TextType;
use crate::gui::styles::text_input::TextInputType;
use crate::gui::types::message::Message;
use crate::networking::types::address_port_pair::AddressPortPair;
use crate::networking::types::host_data_states::HostStates;
use crate::networking::types::info_address_port_pair::InfoAddressPortPair;
use crate::networking::types::traffic_direction::TrafficDirection;
use crate::report::get_report_entries::get_searched_entries;
Expand Down Expand Up @@ -87,9 +89,14 @@ pub fn inspect_page(sniffer: &Sniffer) -> Container<Message, StyleType> {

body = body
.push(
Container::new(host_filters_col(&sniffer.search, font, language))
.padding(10)
.class(ContainerType::BorderedRound),
Container::new(host_filters_col(
&sniffer.search,
&sniffer.host_data_states.states,
font,
language,
))
.padding(10)
.class(ContainerType::BorderedRound),
)
.push(
Container::new(col_report)
Expand Down Expand Up @@ -307,11 +314,12 @@ fn row_report_entry<'a>(
ret_val
}

fn host_filters_col(
search_params: &SearchParameters,
fn host_filters_col<'a>(
search_params: &'a SearchParameters,
host_states: &'a HostStates,
font: Font,
language: Language,
) -> Column<Message, StyleType> {
) -> Column<'a, Message, StyleType> {
let search_params2 = search_params.clone();

let mut title_row = Row::new().spacing(10).align_y(Alignment::Center).push(
Expand All @@ -327,30 +335,47 @@ fn host_filters_col(
));
}

let input_country =
filter_input(FilterInputType::Country, search_params.clone(), font).width(95);
let input_domain =
filter_input(FilterInputType::Domain, search_params.clone(), font).width(190);
let input_as_name =
filter_input(FilterInputType::AsName, search_params.clone(), font).width(190);
let combobox_country = filter_combobox(
FilterInputType::Country,
&host_states.countries,
search_params.clone(),
font,
)
.width(95);

let combobox_domain = filter_combobox(
FilterInputType::Domain,
&host_states.domains,
search_params.clone(),
font,
)
.width(190);

let combobox_as_name = filter_combobox(
FilterInputType::AsName,
&host_states.asns,
search_params.clone(),
font,
)
.width(190);

let container_country = Row::new()
.spacing(5)
.align_y(Alignment::Center)
.push(Text::new(format!("{}:", country_translation(language))).font(font))
.push(input_country);
.push(combobox_country);

let container_domain = Row::new()
.spacing(5)
.align_y(Alignment::Center)
.push(Text::new(format!("{}:", domain_name_translation(language))).font(font))
.push(input_domain);
.push(combobox_domain);

let container_as_name = Row::new()
.spacing(5)
.align_y(Alignment::Center)
.push(Text::new(format!("{}:", administrative_entity_translation(language))).font(font))
.push(input_as_name);
.push(combobox_as_name);

let col1 = Column::new()
.align_x(Alignment::Start)
Expand Down Expand Up @@ -446,6 +471,64 @@ fn filter_input<'a>(
})
}

fn filter_combobox(
filter_input_type: FilterInputType,
combo_box_state: &combo_box::State<String>,
search_params: SearchParameters,
font: Font,
) -> Container<Message, StyleType> {
let filter_value = filter_input_type.current_value(&search_params).to_string();
let is_filter_active = !filter_value.is_empty();

let button_clear = button_clear_filter(filter_input_type.clear_search(&search_params), font);

let update_fn =
move |new_value| Message::Search(filter_input_type.new_search(&search_params, new_value));

let mut combobox = ComboBox::new(combo_box_state, "", Some(&filter_value), update_fn.clone())
.on_input(update_fn)
.padding([2, 5])
.size(FONT_SIZE_FOOTER)
.font(font)
.width(Length::Fill)
.input_class(if is_filter_active {
TextInputType::Badge
} else {
TextInputType::Standard
});

if !is_filter_active {
combobox = combobox.icon(text_input::Icon {
font: ICONS,
code_point: Icon::Funnel.codepoint(),
size: Some(Pixels(12.0)),
spacing: 2.0,
side: Side::Left,
});
}

let mut content = Row::new()
.spacing(5)
.align_y(Alignment::Center)
.push(combobox);

if is_filter_active {
content = content.push(button_clear);
}

Container::new(content)
.padding(if is_filter_active {
Padding::new(5.0).left(10)
} else {
Padding::new(5.0).right(3).left(3)
})
.class(if is_filter_active {
ContainerType::Badge
} else {
ContainerType::Standard
})
}

fn get_button_change_page<'a>(increment: bool) -> Button<'a, Message, StyleType> {
button(
if increment {
Expand Down
18 changes: 7 additions & 11 deletions src/gui/pages/settings_general_page.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use iced::widget::text::LineHeight;
use iced::widget::tooltip::Position;
use iced::widget::{
Expand All @@ -16,7 +14,7 @@ use crate::gui::styles::container::ContainerType;
use crate::gui::styles::style_constants::FONT_SIZE_SUBTITLE;
use crate::gui::styles::text::TextType;
use crate::gui::types::message::Message;
use crate::mmdb::types::mmdb_reader::MmdbReader;
use crate::mmdb::types::mmdb_reader::{MmdbReader, MmdbReaders};
use crate::translations::translations::language_translation;
use crate::translations::translations_2::country_translation;
use crate::translations::translations_3::{
Expand Down Expand Up @@ -91,8 +89,7 @@ fn column_all_general_setting(sniffer: &Sniffer, font: Font) -> Column<Message,
font,
&mmdb_country,
&mmdb_asn,
&sniffer.country_mmdb_reader,
&sniffer.asn_mmdb_reader,
&sniffer.mmdb_readers,
));

column
Expand Down Expand Up @@ -249,8 +246,7 @@ fn mmdb_settings<'a>(
font: Font,
country_path: &str,
asn_path: &str,
country_reader: &Arc<MmdbReader>,
asn_reader: &Arc<MmdbReader>,
mmdb_readers: &MmdbReaders,
) -> Column<'a, Message, StyleType> {
Column::new()
.spacing(5)
Expand All @@ -266,7 +262,7 @@ fn mmdb_settings<'a>(
font,
Message::CustomCountryDb,
country_path,
country_reader,
&mmdb_readers.country,
country_translation(language),
language,
))
Expand All @@ -275,7 +271,7 @@ fn mmdb_settings<'a>(
font,
Message::CustomAsnDb,
asn_path,
asn_reader,
&mmdb_readers.asn,
"ASN",
language,
))
Expand All @@ -286,14 +282,14 @@ fn mmdb_selection_row<'a>(
font: Font,
message: fn(String) -> Message,
custom_path: &str,
mmdb_reader: &Arc<MmdbReader>,
mmdb_reader: &MmdbReader,
caption: &str,
language: Language,
) -> Row<'a, Message, StyleType> {
let is_error = if custom_path.is_empty() {
false
} else {
match **mmdb_reader {
match *mmdb_reader {
MmdbReader::Default(_) => true,
MmdbReader::Custom(_) => false,
}
Expand Down
6 changes: 3 additions & 3 deletions src/gui/pages/thumbnail_page.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::cmp::min;
use std::net::IpAddr;
use std::sync::{Arc, Mutex};
use std::sync::Mutex;

use iced::widget::{lazy, vertical_space, Column, Container, Row, Rule, Space, Text};
use iced::{Alignment, Font, Length};
Expand Down Expand Up @@ -61,7 +61,7 @@ pub fn thumbnail_page(sniffer: &Sniffer) -> Container<Message, StyleType> {
}

fn host_col<'a>(
info_traffic: &Arc<Mutex<InfoTraffic>>,
info_traffic: &Mutex<InfoTraffic>,
chart_type: ChartType,
font: Font,
) -> Column<'a, Message, StyleType> {
Expand Down Expand Up @@ -103,7 +103,7 @@ fn host_col<'a>(
}

fn service_col<'a>(
info_traffic: &Arc<Mutex<InfoTraffic>>,
info_traffic: &Mutex<InfoTraffic>,
chart_type: ChartType,
font: Font,
) -> Column<'a, Message, StyleType> {
Expand Down
Loading

0 comments on commit 4be7847

Please sign in to comment.