@@ -2,30 +2,32 @@ use iced::Length::FillPortion;
22use iced:: widget:: scrollable:: Direction ;
33use iced:: widget:: text:: LineHeight ;
44use iced:: widget:: tooltip:: Position ;
5- use iced:: widget:: { Column , Container , Row , Scrollable , Text , Tooltip } ;
5+ use iced:: widget:: { Column , Container , Row , Scrollable , Text , Tooltip , horizontal_space } ;
66use iced:: widget:: { Space , button, vertical_space} ;
77use iced:: { Alignment , Font , Length , Padding } ;
88use std:: fmt:: Write ;
99
1010use crate :: chart:: types:: chart_type:: ChartType ;
11+ use crate :: countries:: country_utils:: get_computer_tooltip;
1112use crate :: gui:: components:: header:: get_button_settings;
1213use crate :: gui:: components:: tab:: get_pages_tabs;
1314use crate :: gui:: components:: types:: my_modal:: MyModal ;
14- use crate :: gui:: pages:: overview_page:: host_bar;
15+ use crate :: gui:: pages:: overview_page:: { get_bars , get_bars_length , host_bar} ;
1516use crate :: gui:: pages:: types:: settings_page:: SettingsPage ;
1617use crate :: gui:: styles:: container:: ContainerType ;
1718use crate :: gui:: styles:: scrollbar:: ScrollbarType ;
1819use crate :: gui:: styles:: style_constants:: FONT_SIZE_FOOTER ;
1920use crate :: gui:: styles:: text:: TextType ;
2021use crate :: gui:: types:: message:: Message ;
22+ use crate :: networking:: types:: data_info:: DataInfo ;
23+ use crate :: networking:: types:: traffic_type:: TrafficType ;
2124use crate :: notifications:: types:: logged_notification:: {
22- BytesThresholdExceeded , FavoriteTransmitted , LoggedNotification , PacketsThresholdExceeded ,
25+ DataThresholdExceeded , FavoriteTransmitted , LoggedNotification ,
2326} ;
2427use crate :: translations:: translations:: {
25- bytes_exceeded_translation, bytes_exceeded_value_translation, clear_all_translation,
26- favorite_transmitted_translation, incoming_translation, no_notifications_received_translation,
27- no_notifications_set_translation, only_last_30_translation, outgoing_translation,
28- packets_exceeded_translation, packets_exceeded_value_translation, per_second_translation,
28+ bytes_exceeded_translation, clear_all_translation, favorite_transmitted_translation,
29+ no_notifications_received_translation, no_notifications_set_translation,
30+ only_last_30_translation, packets_exceeded_translation, per_second_translation,
2931 threshold_translation,
3032} ;
3133use crate :: utils:: types:: icon:: Icon ;
@@ -140,7 +142,7 @@ fn body_no_notifications_received(
140142}
141143
142144fn packets_notification_log < ' a > (
143- logged_notification : PacketsThresholdExceeded ,
145+ logged_notification : DataThresholdExceeded ,
144146 language : Language ,
145147 font : Font ,
146148) -> Container < ' a , Message , StyleType > {
@@ -150,14 +152,6 @@ fn packets_notification_log<'a>(
150152 logged_notification. threshold,
151153 per_second_translation( language)
152154 ) ;
153- let mut incoming_str = " - " . to_string ( ) ;
154- incoming_str. push_str ( incoming_translation ( language) ) ;
155- incoming_str. push_str ( ": " ) ;
156- incoming_str. push_str ( & logged_notification. incoming . to_string ( ) ) ;
157- let mut outgoing_str = " - " . to_string ( ) ;
158- outgoing_str. push_str ( outgoing_translation ( language) ) ;
159- outgoing_str. push_str ( ": " ) ;
160- outgoing_str. push_str ( & logged_notification. outgoing . to_string ( ) ) ;
161155 let content = Row :: new ( )
162156 . align_y ( Alignment :: Center )
163157 . height ( Length :: Fill )
@@ -190,19 +184,13 @@ fn packets_notification_log<'a>(
190184 . font ( font) ,
191185 ) ,
192186 )
193- . push (
194- Column :: new ( )
195- . spacing ( 7 )
196- . push (
197- Text :: new ( packets_exceeded_value_translation (
198- language,
199- logged_notification. incoming + logged_notification. outgoing ,
200- ) )
201- . font ( font) ,
202- )
203- . push ( Text :: new ( incoming_str) . font ( font) )
204- . push ( Text :: new ( outgoing_str) . font ( font) ) ,
205- ) ;
187+ . push ( threshold_bar (
188+ logged_notification. data_info ,
189+ ChartType :: Packets ,
190+ logged_notification. data_info ,
191+ font,
192+ language,
193+ ) ) ;
206194 Container :: new ( content)
207195 . height ( 120 )
208196 . width ( Length :: Fill )
@@ -211,7 +199,7 @@ fn packets_notification_log<'a>(
211199}
212200
213201fn bytes_notification_log < ' a > (
214- logged_notification : BytesThresholdExceeded ,
202+ logged_notification : DataThresholdExceeded ,
215203 language : Language ,
216204 font : Font ,
217205) -> Container < ' a , Message , StyleType > {
@@ -220,20 +208,7 @@ fn bytes_notification_log<'a>(
220208 threshold_str. push_str ( & ByteMultiple :: formatted_string (
221209 ( logged_notification. threshold ) . into ( ) ,
222210 ) ) ;
223-
224211 let _ = write ! ( threshold_str, " {}" , per_second_translation( language) ) ;
225- let mut incoming_str = " - " . to_string ( ) ;
226- incoming_str. push_str ( incoming_translation ( language) ) ;
227- incoming_str. push_str ( ": " ) ;
228- incoming_str. push_str ( & ByteMultiple :: formatted_string ( u128:: from (
229- logged_notification. incoming ,
230- ) ) ) ;
231- let mut outgoing_str = " - " . to_string ( ) ;
232- outgoing_str. push_str ( outgoing_translation ( language) ) ;
233- outgoing_str. push_str ( ": " ) ;
234- outgoing_str. push_str ( & ByteMultiple :: formatted_string ( u128:: from (
235- logged_notification. outgoing ,
236- ) ) ) ;
237212 let content = Row :: new ( )
238213 . spacing ( 30 )
239214 . align_y ( Alignment :: Center )
@@ -266,21 +241,13 @@ fn bytes_notification_log<'a>(
266241 . font ( font) ,
267242 ) ,
268243 )
269- . push (
270- Column :: new ( )
271- . spacing ( 7 )
272- . push (
273- Text :: new ( bytes_exceeded_value_translation (
274- language,
275- & ByteMultiple :: formatted_string ( u128:: from (
276- logged_notification. incoming + logged_notification. outgoing ,
277- ) ) ,
278- ) )
279- . font ( font) ,
280- )
281- . push ( Text :: new ( incoming_str) . font ( font) )
282- . push ( Text :: new ( outgoing_str) . font ( font) ) ,
283- ) ;
244+ . push ( threshold_bar (
245+ logged_notification. data_info ,
246+ ChartType :: Bytes ,
247+ logged_notification. data_info ,
248+ font,
249+ language,
250+ ) ) ;
284251 Container :: new ( content)
285252 . height ( 120 )
286253 . width ( Length :: Fill )
@@ -330,7 +297,7 @@ fn favorite_notification_log<'a>(
330297 . font ( font) ,
331298 ) ,
332299 )
333- . push ( Column :: new ( ) . spacing ( 7 ) . push ( host_bar) ) ;
300+ . push ( host_bar) ;
334301
335302 Container :: new ( content)
336303 . height ( 120 )
@@ -387,3 +354,41 @@ fn logged_notifications<'a>(sniffer: &Sniffer) -> Column<'a, Message, StyleType>
387354 }
388355 ret_val
389356}
357+
358+ fn threshold_bar < ' a > (
359+ data_info : DataInfo ,
360+ chart_type : ChartType ,
361+ first_entry_data_info : DataInfo ,
362+ font : Font ,
363+ language : Language ,
364+ ) -> Row < ' a , Message , StyleType > {
365+ let ( incoming_bar_len, outgoing_bar_len) =
366+ get_bars_length ( chart_type, & first_entry_data_info, & data_info) ;
367+
368+ Row :: new ( )
369+ . align_y ( Alignment :: Center )
370+ . spacing ( 5 )
371+ . push ( get_computer_tooltip (
372+ true ,
373+ true ,
374+ None ,
375+ TrafficType :: Unicast ,
376+ language,
377+ font,
378+ ) )
379+ . push (
380+ Column :: new ( )
381+ . spacing ( 1 )
382+ . push (
383+ Row :: new ( ) . push ( horizontal_space ( ) ) . push (
384+ Text :: new ( if chart_type. eq ( & ChartType :: Packets ) {
385+ data_info. tot_packets ( ) . to_string ( )
386+ } else {
387+ ByteMultiple :: formatted_string ( data_info. tot_bytes ( ) )
388+ } )
389+ . font ( font) ,
390+ ) ,
391+ )
392+ . push ( get_bars ( incoming_bar_len, outgoing_bar_len) ) ,
393+ )
394+ }
0 commit comments