Skip to content

Commit 29d42b4

Browse files
committed
threshold notifications: include hosts & services
1 parent 50c4af5 commit 29d42b4

8 files changed

Lines changed: 225 additions & 78 deletions

File tree

src/countries/country_utils.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ use crate::countries::flags_pictures::{
88
AD, AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, AU, AW, AX, AZ, BA, BB, BD, BE, BF, BG, BH, BI,
99
BJ, BM, BN, BO, BOGON, BR, BROADCAST, BS, BT, BV, BW, BY, BZ, CA, CC, CD, CF, CG, CH, CI, CK,
1010
CL, CM, CN, CO, COMPUTER, CR, CU, CV, CW, CX, CY, CZ, DE, DJ, DK, DM, DO, DZ, EC, EE, EG, EH,
11-
ER, ES, ET, FI, FJ, FK, FLAGS_WIDTH_BIG, FLAGS_WIDTH_SMALL, FM, FO, FR, GA, GB, GD, GE, GG, GH,
12-
GI, GL, GM, GN, GQ, GR, GS, GT, GU, GW, GY, HK, HN, HOME, HR, HT, HU, ID, IE, IL, IM, IN, IO,
13-
IQ, IR, IS, IT, JE, JM, JO, JP, KE, KG, KH, KI, KM, KN, KP, KR, KW, KY, KZ, LA, LB, LC, LI, LK,
14-
LR, LS, LT, LU, LV, LY, MA, MC, MD, ME, MG, MH, MK, ML, MM, MN, MO, MP, MR, MS, MT, MU,
15-
MULTICAST, MV, MW, MX, MY, MZ, NA, NC, NE, NF, NG, NI, NL, NO, NP, NR, NU, NZ, OM, PA, PE, PF,
16-
PG, PH, PK, PL, PN, PR, PS, PT, PW, PY, QA, RO, RS, RU, RW, SA, SB, SC, SD, SE, SG, SH, SI, SK,
17-
SL, SM, SN, SO, SR, SS, ST, SV, SX, SY, SZ, TC, TD, TF, TG, TH, TJ, TK, TL, TM, TN, TO, TR, TT,
18-
TV, TW, TZ, UA, UG, UNKNOWN, US, UY, UZ, VA, VC, VE, VG, VI, VN, VU, WS, YE, ZA, ZM, ZW,
11+
ER, ES, ET, FI, FJ, FK, FLAGS_HEIGHT_BIG, FLAGS_WIDTH_BIG, FLAGS_WIDTH_SMALL, FM, FO, FR, GA,
12+
GB, GD, GE, GG, GH, GI, GL, GM, GN, GQ, GR, GS, GT, GU, GW, GY, HK, HN, HOME, HR, HT, HU, ID,
13+
IE, IL, IM, IN, IO, IQ, IR, IS, IT, JE, JM, JO, JP, KE, KG, KH, KI, KM, KN, KP, KR, KW, KY, KZ,
14+
LA, LB, LC, LI, LK, LR, LS, LT, LU, LV, LY, MA, MC, MD, ME, MG, MH, MK, ML, MM, MN, MO, MP, MR,
15+
MS, MT, MU, MULTICAST, MV, MW, MX, MY, MZ, NA, NC, NE, NF, NG, NI, NL, NO, NP, NR, NU, NZ, OM,
16+
PA, PE, PF, PG, PH, PK, PL, PN, PR, PS, PT, PW, PY, QA, RO, RS, RU, RW, SA, SB, SC, SD, SE, SG,
17+
SH, SI, SK, SL, SM, SN, SO, SR, SS, ST, SV, SX, SY, SZ, TC, TD, TF, TG, TH, TJ, TK, TL, TM, TN,
18+
TO, TR, TT, TV, TW, TZ, UA, UG, UNKNOWN, US, UY, UZ, VA, VC, VE, VG, VI, VN, VU, WS, YE, ZA,
19+
ZM, ZW,
1920
};
2021
use crate::countries::types::country::Country;
2122
use crate::gui::styles::container::ContainerType;
@@ -384,7 +385,7 @@ pub fn get_computer_tooltip<'a>(
384385
)))
385386
.class(SvgType::AdaptColor)
386387
.width(FLAGS_WIDTH_BIG)
387-
.height(FLAGS_WIDTH_BIG * 0.75);
388+
.height(FLAGS_HEIGHT_BIG);
388389

389390
let tooltip = match (is_my_address, is_local, is_bogon, traffic_type) {
390391
(true, _, _, _) => your_network_adapter_translation(language).to_string(),

src/countries/flags_pictures.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
pub const FLAGS_WIDTH_SMALL: f32 = 20.0;
22
pub const FLAGS_WIDTH_BIG: f32 = 37.5;
33

4+
pub const FLAGS_HEIGHT_BIG: f32 = FLAGS_WIDTH_BIG * 3.0 / 4.0;
5+
46
pub const AD: &[u8] = include_bytes!("../../resources/countries_flags/4x3/ad.svg");
57
pub const AE: &[u8] = include_bytes!("../../resources/countries_flags/4x3/ae.svg");
68
pub const AF: &[u8] = include_bytes!("../../resources/countries_flags/4x3/af.svg");

src/gui/pages/notifications_page.rs

Lines changed: 104 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
use iced::Length::FillPortion;
2-
use iced::widget::scrollable::Direction;
3-
use iced::widget::text::LineHeight;
4-
use iced::widget::tooltip::Position;
5-
use iced::widget::{Column, Container, Row, Scrollable, Text, Tooltip, horizontal_space};
6-
use iced::widget::{Space, button, vertical_space};
7-
use iced::{Alignment, Font, Length, Padding};
8-
91
use crate::chart::types::chart_type::ChartType;
10-
use crate::countries::flags_pictures::FLAGS_WIDTH_BIG;
2+
use crate::countries::country_utils::get_computer_tooltip;
3+
use crate::countries::flags_pictures::FLAGS_HEIGHT_BIG;
114
use crate::gui::components::header::get_button_settings;
125
use crate::gui::components::tab::get_pages_tabs;
136
use crate::gui::components::types::my_modal::MyModal;
14-
use crate::gui::pages::overview_page::{get_bars, get_bars_length, host_bar};
7+
use crate::gui::pages::overview_page::{get_bars, get_bars_length, host_bar, service_bar};
158
use crate::gui::pages::types::settings_page::SettingsPage;
16-
use crate::gui::styles::button::ButtonType;
179
use crate::gui::styles::container::ContainerType;
1810
use crate::gui::styles::scrollbar::ScrollbarType;
1911
use crate::gui::styles::style_constants::FONT_SIZE_FOOTER;
2012
use crate::gui::styles::text::TextType;
2113
use crate::gui::types::message::Message;
2214
use crate::networking::types::data_info::DataInfo;
15+
use crate::networking::types::data_info_host::DataInfoHost;
16+
use crate::networking::types::host::Host;
17+
use crate::networking::types::service::Service;
18+
use crate::networking::types::traffic_type::TrafficType;
2319
use crate::notifications::types::logged_notification::{
2420
DataThresholdExceeded, FavoriteTransmitted, LoggedNotification,
2521
};
@@ -32,6 +28,14 @@ use crate::translations::translations::{
3228
};
3329
use crate::utils::types::icon::Icon;
3430
use crate::{ByteMultiple, ConfigSettings, Language, RunningPage, Sniffer, StyleType};
31+
use iced::Length::FillPortion;
32+
use iced::widget::scrollable::Direction;
33+
use iced::widget::text::LineHeight;
34+
use iced::widget::tooltip::Position;
35+
use iced::widget::{Column, Container, Row, Rule, Scrollable, Text, Tooltip, horizontal_space};
36+
use iced::widget::{Space, button, vertical_space};
37+
use iced::{Alignment, Font, Length, Padding};
38+
use std::cmp::max;
3539

3640
/// Computes the body of gui notifications page
3741
pub fn notifications_page(sniffer: &Sniffer) -> Container<Message, StyleType> {
@@ -142,7 +146,7 @@ fn body_no_notifications_received(
142146
}
143147

144148
fn data_notification_log<'a>(
145-
logged_notification: DataThresholdExceeded,
149+
logged_notification: &DataThresholdExceeded,
146150
first_entry_data_info: DataInfo,
147151
language: Language,
148152
font: Font,
@@ -197,26 +201,28 @@ fn data_notification_log<'a>(
197201
),
198202
)
199203
.push(threshold_bar(
200-
&logged_notification,
204+
logged_notification,
201205
chart_type,
202206
first_entry_data_info,
207+
language,
203208
font,
204209
));
205210
let content_and_extra = Column::new()
211+
.spacing(10)
206212
.push(content)
207-
.push(if logged_notification.is_expanded {
208-
Row::new().push(get_button_clear_all(font, language))
209-
} else {
210-
Row::new()
211-
});
213+
.push(button_expand(
214+
logged_notification.id,
215+
logged_notification.is_expanded,
216+
))
217+
.push_maybe(data_notification_extra(logged_notification, font, language));
212218
Container::new(content_and_extra)
213219
.width(Length::Fill)
214220
.padding(15)
215221
.class(ContainerType::BorderedRound)
216222
}
217223

218224
fn favorite_notification_log<'a>(
219-
logged_notification: FavoriteTransmitted,
225+
logged_notification: &FavoriteTransmitted,
220226
first_entry_data_info: DataInfo,
221227
chart_type: ChartType,
222228
language: Language,
@@ -249,7 +255,7 @@ fn favorite_notification_log<'a>(
249255
Row::new()
250256
.spacing(8)
251257
.push(Icon::Clock.to_text())
252-
.push(Text::new(logged_notification.timestamp).font(font)),
258+
.push(Text::new(logged_notification.timestamp.clone()).font(font)),
253259
)
254260
.push(
255261
Text::new(favorite_transmitted_translation(language))
@@ -310,15 +316,15 @@ fn logged_notifications<'a>(sniffer: &Sniffer) -> Column<'a, Message, StyleType>
310316
ret_val = ret_val.push(match logged_notification {
311317
LoggedNotification::DataThresholdExceeded(data_threshold_exceeded) => {
312318
data_notification_log(
313-
data_threshold_exceeded.clone(),
319+
data_threshold_exceeded,
314320
first_entry_data_info,
315321
language,
316322
font,
317323
)
318324
}
319325
LoggedNotification::FavoriteTransmitted(favorite_transmitted) => {
320326
favorite_notification_log(
321-
favorite_transmitted.clone(),
327+
favorite_transmitted,
322328
first_entry_data_info,
323329
chart_type,
324330
language,
@@ -334,19 +340,24 @@ fn threshold_bar<'a>(
334340
logged_notification: &DataThresholdExceeded,
335341
chart_type: ChartType,
336342
first_entry_data_info: DataInfo,
343+
language: Language,
337344
font: Font,
338345
) -> Row<'a, Message, StyleType> {
339346
let data_info = logged_notification.data_info;
340-
let id = logged_notification.id;
341-
let is_expanded = logged_notification.is_expanded;
342-
343347
let (incoming_bar_len, outgoing_bar_len) =
344348
get_bars_length(chart_type, &first_entry_data_info, &data_info);
345349

346350
Row::new()
347351
.align_y(Alignment::Center)
348352
.spacing(5)
349-
.push(button_expand(id, is_expanded))
353+
.push(get_computer_tooltip(
354+
true,
355+
true,
356+
None,
357+
TrafficType::Unicast,
358+
language,
359+
font,
360+
))
350361
.push(
351362
Column::new()
352363
.spacing(1)
@@ -370,21 +381,81 @@ fn button_expand<'a>(
370381
) -> Container<'a, Message, StyleType> {
371382
let button = button(
372383
if is_expanded {
373-
Icon::Collapse
384+
Icon::SortAscending
374385
} else {
375-
Icon::Expand
386+
Icon::SortDescending
376387
}
377388
.to_text()
378-
.size(25)
389+
.size(11)
379390
.align_x(Alignment::Center)
380391
.align_y(Alignment::Center),
381392
)
382-
.width(FLAGS_WIDTH_BIG)
383-
.padding(Padding::ZERO)
384-
.class(ButtonType::SortArrows)
393+
.padding(Padding::ZERO.top(if is_expanded { 0 } else { 2 }))
394+
.width(25)
395+
.height(25)
385396
.on_press(Message::ExpandNotification(notification_id, !is_expanded));
386397

387398
Container::new(button)
388-
.align_x(Alignment::Center)
399+
.padding(Padding::ZERO.left(395))
389400
.align_y(Alignment::Center)
390401
}
402+
403+
fn data_notification_extra<'a>(
404+
logged_notification: &DataThresholdExceeded,
405+
font: Font,
406+
language: Language,
407+
) -> Option<Row<'a, Message, StyleType>> {
408+
let max_entries = max(
409+
logged_notification.hosts.len(),
410+
logged_notification.services.len(),
411+
);
412+
if !logged_notification.is_expanded || max_entries == 0 {
413+
return None;
414+
}
415+
let spacing = 10.0;
416+
#[allow(clippy::cast_precision_loss)]
417+
let height = (FLAGS_HEIGHT_BIG + spacing) * max_entries as f32;
418+
419+
let mut hosts_col = Column::new().spacing(spacing).width(Length::FillPortion(5));
420+
let first_data_info_host = logged_notification
421+
.hosts
422+
.first()
423+
.unwrap_or(&(Host::default(), DataInfoHost::default()))
424+
.1
425+
.data_info;
426+
for (host, data_info_host) in &logged_notification.hosts {
427+
let host_bar = host_bar(
428+
host,
429+
data_info_host,
430+
logged_notification.chart_type,
431+
first_data_info_host,
432+
font,
433+
language,
434+
);
435+
hosts_col = hosts_col.push(host_bar);
436+
}
437+
438+
let mut services_col = Column::new().spacing(spacing).width(Length::FillPortion(2));
439+
let first_data_info_service = logged_notification
440+
.services
441+
.first()
442+
.unwrap_or(&(Service::default(), DataInfo::default()))
443+
.1;
444+
for (service, data_info) in &logged_notification.services {
445+
let service_bar = service_bar(
446+
service,
447+
data_info,
448+
logged_notification.chart_type,
449+
first_data_info_service,
450+
font,
451+
);
452+
services_col = services_col.push(service_bar);
453+
}
454+
455+
Some(
456+
Row::new()
457+
.push(hosts_col)
458+
.push(Container::new(Rule::vertical(30)).height(height))
459+
.push(services_col),
460+
)
461+
}

src/gui/pages/overview_page.rs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use crate::chart::types::donut_chart::donut_chart;
77
use crate::countries::country_utils::get_flag_tooltip;
8-
use crate::countries::flags_pictures::FLAGS_WIDTH_BIG;
8+
use crate::countries::flags_pictures::{FLAGS_HEIGHT_BIG, FLAGS_WIDTH_BIG};
99
use crate::gui::components::tab::get_pages_tabs;
1010
use crate::gui::sniffer::Sniffer;
1111
use crate::gui::styles::button::ButtonType;
@@ -21,6 +21,7 @@ use crate::networking::types::data_info::DataInfo;
2121
use crate::networking::types::data_info_host::DataInfoHost;
2222
use crate::networking::types::filters::Filters;
2323
use crate::networking::types::host::Host;
24+
use crate::networking::types::service::Service;
2425
use crate::report::get_report_entries::{get_host_entries, get_service_entries};
2526
use crate::report::types::search_parameters::SearchParameters;
2627
use crate::report::types::sort_type::SortType;
@@ -334,29 +335,11 @@ fn col_service<'a>(sniffer: &Sniffer) -> Column<'a, Message, StyleType> {
334335
.unwrap_or_default();
335336

336337
for (service, data_info) in &entries {
337-
let (incoming_bar_len, outgoing_bar_len) =
338-
get_bars_length(chart_type, &first_entry_data_info, data_info);
339-
340-
let content = Column::new()
341-
.spacing(1)
342-
.push(
343-
Row::new()
344-
.push(Text::new(service.to_string()).font(font))
345-
.push(horizontal_space())
346-
.push(
347-
Text::new(if chart_type.eq(&ChartType::Packets) {
348-
data_info.tot_packets().to_string()
349-
} else {
350-
ByteMultiple::formatted_string(data_info.tot_bytes())
351-
})
352-
.font(font),
353-
),
354-
)
355-
.push(get_bars(incoming_bar_len, outgoing_bar_len));
338+
let content = service_bar(service, data_info, chart_type, first_entry_data_info, font);
356339

357340
scroll_service = scroll_service.push(
358341
button(content)
359-
.padding(Padding::new(5.0).right(15).bottom(8).left(10))
342+
.padding(Padding::new(5.0).right(15).left(10))
360343
.on_press(Message::Search(SearchParameters::new_service_search(
361344
service,
362345
)))
@@ -413,6 +396,7 @@ pub fn host_bar<'a>(
413396
);
414397

415398
Row::new()
399+
.height(FLAGS_HEIGHT_BIG)
416400
.align_y(Alignment::Center)
417401
.spacing(5)
418402
.push(get_flag_tooltip(
@@ -450,6 +434,40 @@ pub fn host_bar<'a>(
450434
)
451435
}
452436

437+
pub fn service_bar<'a>(
438+
service: &Service,
439+
data_info: &DataInfo,
440+
chart_type: ChartType,
441+
first_entry_data_info: DataInfo,
442+
font: Font,
443+
) -> Row<'a, Message, StyleType> {
444+
let (incoming_bar_len, outgoing_bar_len) =
445+
get_bars_length(chart_type, &first_entry_data_info, data_info);
446+
447+
Row::new()
448+
.height(FLAGS_HEIGHT_BIG)
449+
.align_y(Alignment::Center)
450+
.spacing(5)
451+
.push(
452+
Column::new()
453+
.spacing(1)
454+
.push(
455+
Row::new()
456+
.push(Text::new(service.to_string()).font(font))
457+
.push(horizontal_space())
458+
.push(
459+
Text::new(if chart_type.eq(&ChartType::Packets) {
460+
data_info.tot_packets().to_string()
461+
} else {
462+
ByteMultiple::formatted_string(data_info.tot_bytes())
463+
})
464+
.font(font),
465+
),
466+
)
467+
.push(get_bars(incoming_bar_len, outgoing_bar_len)),
468+
)
469+
}
470+
453471
fn col_info<'a>(sniffer: &Sniffer) -> Container<'a, Message, StyleType> {
454472
let ConfigSettings {
455473
style, language, ..
@@ -780,7 +798,7 @@ fn get_star_button<'a>(is_favorite: bool, host: Host) -> Button<'a, Message, Sty
780798
.align_y(Alignment::Center),
781799
)
782800
.padding(0)
783-
.height(FLAGS_WIDTH_BIG * 0.75)
801+
.height(FLAGS_HEIGHT_BIG)
784802
.width(FLAGS_WIDTH_BIG)
785803
.class(if is_favorite {
786804
ButtonType::Starred

0 commit comments

Comments
 (0)