mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-22 17:33:26 +01:00
Add config option to show real-time network info in UI
This commit is contained in:
parent
15ab58aa13
commit
fd263e3e0a
@ -138,6 +138,11 @@ Show welcome message on startup\&. true or false
|
||||
Enable friend connection change notifications\&. true or false
|
||||
.RE
|
||||
.PP
|
||||
\fBshow_network_info\fR
|
||||
.RS 4
|
||||
Show network information in the UI home window\&. true or false
|
||||
.RE
|
||||
.PP
|
||||
\fBnodelist_update_freq\fR
|
||||
.RS 4
|
||||
How often in days to update the DHT nodes list\&. (integer; 0 to disable)
|
||||
|
@ -87,6 +87,9 @@ OPTIONS
|
||||
*show_connection_msg*;;
|
||||
Enable friend connection change notifications. true or false
|
||||
|
||||
*show_network_info*;;
|
||||
Show network information in the UI home window. true or false
|
||||
|
||||
*nodelist_update_freq*;;
|
||||
How often in days to update the DHT nodes list. (integer; 0 to disable)
|
||||
|
||||
|
@ -56,6 +56,9 @@ ui = {
|
||||
// true to show friend connection change messages on the home screen
|
||||
show_connection_msg=true;
|
||||
|
||||
// true to show network information in the UI home window
|
||||
show_network_info=true;
|
||||
|
||||
// How often in days to update the DHT nodes list. (0 to disable updates)
|
||||
nodeslist_update_freq=7;
|
||||
|
||||
|
@ -277,4 +277,23 @@ void netprof_log_dump(const Tox *m, FILE *fp, time_t run_time)
|
||||
fflush(fp);
|
||||
}
|
||||
|
||||
uint64_t netprof_get_bytes_up(const Tox *m)
|
||||
{
|
||||
const uint64_t UDP_bytes_sent = tox_netprof_get_packet_total_bytes(m, TOX_NETPROF_PACKET_TYPE_UDP,
|
||||
TOX_NETPROF_DIRECTION_SENT);
|
||||
const uint64_t TCP_bytes_sent = tox_netprof_get_packet_total_bytes(m, TOX_NETPROF_PACKET_TYPE_TCP,
|
||||
TOX_NETPROF_DIRECTION_SENT);
|
||||
|
||||
return UDP_bytes_sent + TCP_bytes_sent;
|
||||
|
||||
}
|
||||
|
||||
uint64_t netprof_get_bytes_down(const Tox *m)
|
||||
{
|
||||
const uint64_t UDP_bytes_recv = tox_netprof_get_packet_total_bytes(m, TOX_NETPROF_PACKET_TYPE_UDP,
|
||||
TOX_NETPROF_DIRECTION_RECV);
|
||||
const uint64_t TCP_bytes_recv = tox_netprof_get_packet_total_bytes(m, TOX_NETPROF_PACKET_TYPE_TCP,
|
||||
TOX_NETPROF_DIRECTION_RECV);
|
||||
|
||||
return UDP_bytes_recv + TCP_bytes_recv;
|
||||
}
|
||||
|
@ -29,4 +29,7 @@
|
||||
|
||||
void netprof_log_dump(const Tox *m, FILE *fp, time_t run_time);
|
||||
|
||||
uint64_t netprof_get_bytes_down(const Tox *m);
|
||||
uint64_t netprof_get_bytes_up(const Tox *m);
|
||||
|
||||
#endif // TOXIC_NETPROF
|
||||
|
76
src/prompt.c
76
src/prompt.c
@ -36,6 +36,7 @@
|
||||
#include "line_info.h"
|
||||
#include "log.h"
|
||||
#include "misc_tools.h"
|
||||
#include "netprof.h"
|
||||
#include "notify.h"
|
||||
#include "prompt.h"
|
||||
#include "settings.h"
|
||||
@ -305,6 +306,77 @@ static bool prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
return input_ret;
|
||||
}
|
||||
|
||||
#define NET_INFO_REFRESH_INTERVAL 1
|
||||
static void draw_network_info(const Tox *m, StatusBar *stb)
|
||||
{
|
||||
WINDOW *win = stb->topline;
|
||||
|
||||
wattron(win, COLOR_PAIR(BAR_TEXT));
|
||||
wprintw(win, "%s", stb->network_info);
|
||||
wattroff(win, COLOR_PAIR(BAR_TEXT));
|
||||
|
||||
if (!timed_out(stb->time_last_refreshed, NET_INFO_REFRESH_INTERVAL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
stb->time_last_refreshed = get_unix_time();
|
||||
|
||||
const uint64_t up_bytes = netprof_get_bytes_up(m);
|
||||
const uint64_t down_bytes = netprof_get_bytes_down(m);
|
||||
|
||||
const uint64_t up_delta = (up_bytes - stb->up_bytes) / NET_INFO_REFRESH_INTERVAL;
|
||||
const uint64_t down_delta = (down_bytes - stb->down_bytes) / NET_INFO_REFRESH_INTERVAL;
|
||||
|
||||
stb->up_bytes = up_bytes;
|
||||
stb->down_bytes = down_bytes;
|
||||
|
||||
float up = up_bytes;
|
||||
float down = down_bytes;
|
||||
const char *up_unit = "bytes";
|
||||
const char *down_unit = "bytes";
|
||||
|
||||
if (up_bytes > MiB) {
|
||||
up /= (float)MiB;
|
||||
up_unit = "MiB";
|
||||
} else if (up_bytes > KiB) {
|
||||
up /= (float)KiB;
|
||||
up_unit = "KiB";
|
||||
}
|
||||
|
||||
if (down_bytes > MiB) {
|
||||
down /= (float)MiB;
|
||||
down_unit = "MiB";
|
||||
} else if (down_bytes > KiB) {
|
||||
down /= (float)KiB;
|
||||
down_unit = "KiB";
|
||||
}
|
||||
|
||||
float up_bps = up_delta;
|
||||
float down_bps = down_delta;
|
||||
const char *up_bps_unit = "b/s";
|
||||
const char *down_bps_unit = "b/s";
|
||||
|
||||
if (up_bps > MiB) {
|
||||
up_bps /= (float)MiB;
|
||||
up_bps_unit = "MiB/s";
|
||||
} else if (up_bps > KiB) {
|
||||
up_bps /= (float)KiB;
|
||||
up_bps_unit = "KiB/s";
|
||||
}
|
||||
|
||||
if (down_bps > MiB) {
|
||||
down_bps /= (float)MiB;
|
||||
down_bps_unit = "MiB/s";
|
||||
} else if (down_bps > KiB) {
|
||||
down_bps /= (float)KiB;
|
||||
down_bps_unit = "KiB/s";
|
||||
}
|
||||
|
||||
snprintf(stb->network_info, sizeof(stb->network_info),
|
||||
" | [Up: %.1f%s (%.1f%s) | Down: %.1f%s (%.1f%s)]", up, up_unit, up_bps, up_bps_unit,
|
||||
down, down_unit, down_bps, down_bps_unit);
|
||||
}
|
||||
|
||||
static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
{
|
||||
int x2;
|
||||
@ -462,6 +534,10 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
wattroff(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
||||
}
|
||||
|
||||
if (user_settings->show_network_info) {
|
||||
draw_network_info(m, statusbar);
|
||||
}
|
||||
|
||||
int y;
|
||||
int x;
|
||||
getyx(self->window, y, x);
|
||||
|
@ -63,6 +63,7 @@ static struct ui_strings {
|
||||
const char *show_typing_other;
|
||||
const char *show_welcome_msg;
|
||||
const char *show_connection_msg;
|
||||
const char *show_network_info;
|
||||
const char *nodeslist_update_freq;
|
||||
const char *autosave_freq;
|
||||
|
||||
@ -97,6 +98,7 @@ static struct ui_strings {
|
||||
"show_typing_other",
|
||||
"show_welcome_msg",
|
||||
"show_connection_msg",
|
||||
"show_network_info",
|
||||
"nodeslist_update_freq",
|
||||
"autosave_freq",
|
||||
"line_join",
|
||||
@ -130,6 +132,7 @@ static void ui_defaults(struct user_settings *settings)
|
||||
settings->show_typing_other = SHOW_TYPING_ON;
|
||||
settings->show_welcome_msg = SHOW_WELCOME_MSG_ON;
|
||||
settings->show_connection_msg = SHOW_CONNECTION_MSG_ON;
|
||||
settings->show_network_info = SHOW_NETWORK_INFO_OFF;
|
||||
settings->nodeslist_update_freq = 7;
|
||||
settings->autosave_freq = 600;
|
||||
|
||||
@ -398,6 +401,7 @@ int settings_load(struct user_settings *s, const char *patharg)
|
||||
config_setting_lookup_bool(setting, ui_strings.show_typing_other, &s->show_typing_other);
|
||||
config_setting_lookup_bool(setting, ui_strings.show_welcome_msg, &s->show_welcome_msg);
|
||||
config_setting_lookup_bool(setting, ui_strings.show_connection_msg, &s->show_connection_msg);
|
||||
config_setting_lookup_bool(setting, ui_strings.show_network_info, &s->show_network_info);
|
||||
|
||||
config_setting_lookup_int(setting, ui_strings.history_size, &s->history_size);
|
||||
config_setting_lookup_int(setting, ui_strings.notification_timeout, &s->notification_timeout);
|
||||
|
@ -54,6 +54,7 @@ struct user_settings {
|
||||
int show_typing_other; /* boolean */
|
||||
int show_welcome_msg; /* boolean */
|
||||
int show_connection_msg; /* boolean */
|
||||
int show_network_info; /* boolean */
|
||||
int nodeslist_update_freq; /* int (<= 0 to disable updates) */
|
||||
int autosave_freq; /* int (<= 0 to disable autosave) */
|
||||
|
||||
@ -120,6 +121,9 @@ enum settings_values {
|
||||
SHOW_CONNECTION_MSG_OFF = 0,
|
||||
SHOW_CONNECTION_MSG_ON = 1,
|
||||
|
||||
SHOW_NETWORK_INFO_OFF = 0,
|
||||
SHOW_NETWORK_INFO_ON = 1,
|
||||
|
||||
DFLT_HST_SIZE = 700,
|
||||
|
||||
MPLEX_OFF = 0,
|
||||
|
@ -252,6 +252,12 @@ struct StatusBar {
|
||||
size_t nick_len;
|
||||
Tox_User_Status status;
|
||||
Tox_Connection connection;
|
||||
|
||||
/* network info */
|
||||
uint64_t up_bytes;
|
||||
uint64_t down_bytes;
|
||||
uint64_t time_last_refreshed;
|
||||
char network_info[MAX_STR_SIZE];
|
||||
};
|
||||
|
||||
#ifdef AUDIO
|
||||
|
Loading…
Reference in New Issue
Block a user