⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 net.c

📁 系统任务管理器
💻 C
📖 第 1 页 / 共 5 页
字号:
		gkrellm_chart_show(net->chart, TRUE);	/* Make sure panel is shown */	else if (!net->force_up && !net_is_up && chart_is_visible)		{		gkrellm_chart_hide(net->chart, FALSE);  /* Don't hide the panel */		/* Save data whenever net has transitioned to a "not up" state.		|  Don't have the info to do this when there's a force_up and in		|  this case just rely on the every six hour tick data save.		*/		gkrellm_net_save_data();		}	}static gintnet_expose_event(GtkWidget *widget, GdkEventExpose *ev)	{	GList		*list;	NetMon		*net;	GdkPixmap	*pixmap	= NULL;	if (timer_panel->drawing_area == widget)		pixmap = timer_panel->pixmap;	else		for (list = net_mon_list; list; list = list->next)			{			net = (NetMon *) list->data;			if (!net->chart || !net->chart->panel)	/* A disabled iface */				continue;			if (net->chart->drawing_area == widget)				pixmap = net->chart->pixmap;			else if (net->chart->panel->drawing_area == widget)				pixmap = net->chart->panel->pixmap;			if (pixmap)				break;			}	if (pixmap)		gdk_draw_drawable(widget->window, gkrellm_draw_GC(1), pixmap,			ev->area.x, ev->area.y, ev->area.x, ev->area.y,			ev->area.width, ev->area.height);	return FALSE;	}static gintmap_x(gint x, gint width)	{	gint	xnew, chart_width;	xnew = x;	chart_width = gkrellm_chart_width();	if (x < 0)		xnew += chart_width - width;	return xnew;	}static gintgrid_resolution_default(NetMon *net)	{	gchar	*s 	= net->name;	gint	res;	if (! strncmp(s, "ppp", 3))		res = 2000;#if defined(__FreeBSD__)	else if (! strncmp(s, "tun", 3))		res = 2000;#endif	else if (! strncmp(s, "plip", 3) || ! strncmp(s, "ippp", 4))		res = 5000;	else if (! strncmp(s, "eth", 3))		res = 20000;	else		res = 10000;	return res;	}static voidsetup_net_scaling(GkrellmChartconfig *cf, NetMon *net)	{	GkrellmChart	*cp  = net->chart;	gint	grids, res;	grids = gkrellm_get_chartconfig_fixed_grids(cf);	if (!grids)		grids = FULL_SCALE_GRIDS;	res = gkrellm_get_chartconfig_grid_resolution(cf);	KRELL(cp->panel)->full_scale = res * grids / gkrellm_update_HZ();	}static voiddestroy_chart(NetMon *net)	{	GkrellmChart	*cp;	if (!net)		return;	cp = net->chart;	if (cp)		{		net->launch.button = NULL;		net->launch.tooltip = NULL;		g_free(cp->panel->textstyle);		cp->panel->textstyle = NULL;		gkrellm_chart_destroy(cp);		gtk_widget_destroy(net->vbox);		net->chart = NULL;		net->vbox = NULL;		net->parent_vbox = NULL;		}	net->locked = FALSE;	}static GkrellmSizeAbbrev	current_bytes_abbrev[]	=	{	{ KB_SIZE(1),		1,				"%.0f" },	{ KB_SIZE(20),		KB_SIZE(1),		"%.1fK" },	{ MB_SIZE(1),		KB_SIZE(1),		"%.0fK" },	{ MB_SIZE(20),		MB_SIZE(1),		"%.1fM" },	{ GB_SIZE(1),		MB_SIZE(1),		"%.0fM" },	{ GB_SIZE(20),		GB_SIZE(1),		"%.1fG" },	{ TB_SIZE(1),		GB_SIZE(1),		"%.0fG" },	{ TB_SIZE(20),		TB_SIZE(1),		"%.1fT" },	{ TB_SIZE(1000),	TB_SIZE(1),		"%.0fT" }	};static GkrellmSizeAbbrev	total_bytes_abbrev[]	=	{	{ KB_SIZE(100),		1,				"%.0f" },	{ MB_SIZE(1),		KB_SIZE(1),		"%.1fK" },	{ MB_SIZE(10),		MB_SIZE(1),		"%.3fM" },	{ MB_SIZE(100),		MB_SIZE(1),		"%.2fM" },	{ GB_SIZE(1),		MB_SIZE(1),		"%.1fM" },	{ GB_SIZE(10),		GB_SIZE(1),		"%.3fG" },	{ GB_SIZE(100),		GB_SIZE(1),		"%.2fG" },	{ TB_SIZE(1),		GB_SIZE(1),		"%.1fG" },	{ TB_SIZE(10),		TB_SIZE(1),		"%.3fT" },	{ TB_SIZE(100),		TB_SIZE(1),		"%.2fT" },	{ TB_SIZE(1000),	TB_SIZE(1),		"%.1fT" }	};#define	DEFAULT_TEXT_FORMAT	"$T\\b\\c\\f$L"static gchar    *text_format,				*text_format_locale;static voidformat_net_data(NetMon *net, gchar *src_string, gchar *buf, gint size)	{	GkrellmChart	*cp;	gchar			c, *s, *s1, *result;	gint			len, bytes;	gdouble			fbytes;	gboolean		month, day, week;	if (!buf || size < 1)		return;	--size;	*buf = '\0';	result = buf;	if (!src_string)		return;	cp = net->chart;	net->totals_shown = FALSE;	if ((_GK.debug_level & DEBUG_CHART_TEXT))		printf("net chart text: %s\n", src_string);	for (s = src_string; *s != '\0' && size > 0; ++s)		{		len = 1;		month = week = day = FALSE;		if (*s == '$' && *(s + 1) != '\0')			{			bytes = -1;			fbytes = -1.0;			if ((c = *(s + 2)) == 'm')	/* cumulative modifiers */				month = TRUE;			else if (c == 'w')				week = TRUE;			else if (c == 'd')				day = TRUE;			if ((c = *(s + 1)) == 'T')				bytes = net->rx_current + net->tx_current;			else if (c == 'M')				bytes = gkrellm_get_chart_scalemax(cp);			else if (c == 't')				bytes = net->tx_current;			else if (c == 'r')				bytes = net->rx_current;			else if (c == 'o')				{				if (month)					fbytes = net->month_stats[0].tx;				else if (week)					fbytes = net->week_stats[0].tx;				else if (day)					fbytes = net->day_stats[0].tx;				else					fbytes = net->show_totalB								? net->tx_totalB : net->tx_totalA;				}			else if (c == 'i')				{				if (month)					fbytes = net->month_stats[0].rx;				else if (week)					fbytes = net->week_stats[0].rx;				else if (day)					fbytes = net->day_stats[0].rx;				else					fbytes = net->show_totalB								? net->rx_totalB : net->rx_totalA;				}			else if (c == 'O')				{				if (month)					fbytes = net->month_stats[0].rx + net->month_stats[0].tx;				else if (week)					fbytes = net->week_stats[0].rx + net->week_stats[0].tx;				else if (day)					fbytes = net->day_stats[0].rx + net->day_stats[0].tx;				else					fbytes = net->show_totalB							? (net->rx_totalB + net->tx_totalB)							: (net->rx_totalA + net->tx_totalA);				}			else if (c == 'L')				{				if (!*(net->label))					s1 = " ";				else					s1 = net->label;				len = snprintf(buf, size, "%s", s1);				}			else if (c == 'I')				len = snprintf(buf, size, "%s", net->name);			else if (c == 'H')				len = snprintf(buf, size, "%s", gkrellm_sys_get_host_name());			else				{				*buf = *s;				if (size > 1)					{					*(buf + 1) = *(s + 1);					++len;					}				}			if (bytes >= 0)				len = gkrellm_format_size_abbrev(buf, size, (gfloat) bytes,					&current_bytes_abbrev[0],					sizeof(current_bytes_abbrev) / sizeof(GkrellmSizeAbbrev));			else if (fbytes >= 0)				{				len = gkrellm_format_size_abbrev(buf, size, (gfloat) fbytes,					&total_bytes_abbrev[0],					sizeof(total_bytes_abbrev) /sizeof(GkrellmSizeAbbrev));				if (!day && !week && !month)					net->totals_shown = TRUE;				}			++s;			if (day || week || month)				++s;			}		else			*buf = *s;		size -= len;		buf += len;		}	*buf = '\0';		if ((_GK.debug_level & DEBUG_CHART_TEXT))		printf("              : %s\n", result);	}static voiddraw_net_chart_labels(NetMon *net)	{	GkrellmChart		*cp = net->chart;	gchar		buf[128];	if (!net->chart_labels)		return;	format_net_data(net, text_format_locale, buf, sizeof(buf));	if (!net->new_text_format)		gkrellm_chart_reuse_text_format(cp);	net->new_text_format = FALSE;	gkrellm_draw_chart_text(cp, net_style_id, buf);	}static voidcb_command_process(GkrellmAlert *alert, gchar *src, gchar *dst, gint len,			NetMon *net)	{	format_net_data(net, src, dst, len);	}static voiddraw_chart_buttons(NetMon *net)	{	gint	frame, x, y;	if (   net->totals_shown && net->chart_labels		&& decal_totalA && decal_totalB && decal_reset	   )		{		x = gkrellm_chart_width() - 2 * decal_totalA->w;		y = 2;		frame = net->show_totalB ? D_MISC_BUTTON_OUT : D_MISC_BUTTON_IN;		gkrellm_draw_decal_pixmap(NULL, decal_totalA, frame);		gkrellm_draw_decal_on_chart(net->chart, decal_totalA, x, y);		frame = net->show_totalB ? D_MISC_BUTTON_IN : D_MISC_BUTTON_OUT;		gkrellm_draw_decal_pixmap(NULL, decal_totalB, frame);		gkrellm_draw_decal_on_chart(net->chart, decal_totalB,					x + decal_totalA->w, y);		frame = net->reset_button_in ? D_MISC_BUTTON_IN : D_MISC_BUTTON_OUT;		gkrellm_draw_decal_pixmap(NULL, decal_reset, frame);		gkrellm_draw_decal_on_chart(net->chart, decal_reset,					x + decal_totalA->w, y + decal_totalA->h + 4);		}	if (decal_stats)		{		x = gkrellm_chart_width() - decal_stats->w;		y = net->chart->h - decal_stats->h;		frame = net->stats_button_in ? D_MISC_BUTTON_IN : D_MISC_BUTTON_OUT;		gkrellm_draw_decal_pixmap(NULL, decal_stats, frame);		gkrellm_draw_decal_on_chart(net->chart, decal_stats, x, y);		}	}static voidrefresh_net_chart(NetMon *net)	{	if (!net->chart)		return;	gkrellm_draw_chartdata(net->chart);	draw_net_chart_labels(net);	if (net->mouse_in_chart)		draw_chart_buttons(net);	gkrellm_draw_chart_to_screen(net->chart);	}static gintcb_chart_press(GtkWidget *widget, GdkEventButton *ev, NetMon *net)	{	gboolean	check_button;	check_button = net->chart_labels && net->totals_shown;	if (check_button && gkrellm_in_decal(decal_totalA, ev))		{		net->show_totalB = FALSE;		refresh_net_chart(net);		}	else if (check_button && gkrellm_in_decal(decal_totalB, ev))		{		net->show_totalB = TRUE;		refresh_net_chart(net);		}	else if (check_button && gkrellm_in_decal(decal_reset, ev))		{		net->reset_button_in = TRUE;		refresh_net_chart(net);		}	else if (gkrellm_in_decal(decal_stats, ev))		{		net->stats_button_in = TRUE;		refresh_net_chart(net);		}	else if (ev->button == 1 && ev->type == GDK_BUTTON_PRESS)		{		net->chart_labels = !net->chart_labels;		gkrellm_config_modified();		refresh_net_chart(net);		}	else if (   ev->button == 3			 || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS)			)			gkrellm_chartconfig_window_create(net->chart);	return FALSE;	}static gintcb_chart_release(GtkWidget *widget, GdkEventButton *ev, NetMon *net)	{	if (!net->reset_button_in && !net->stats_button_in)		return FALSE;	if (net->stats_button_in && gkrellm_in_decal(decal_stats, ev))		net_stats_window_show(net);	if (net->reset_button_in && gkrellm_in_decal(decal_reset, ev))		{		if (net->show_totalB)			net->rx_totalB = net->tx_totalB = 0;		else			net->rx_totalA = net->tx_totalA = 0;		}	net->reset_button_in = FALSE;	net->stats_button_in = FALSE;	refresh_net_chart(net);	return FALSE;	}static gintcb_chart_enter(GtkWidget *w, GdkEventButton *ev, NetMon *net)	{	net->mouse_in_chart = TRUE;	draw_chart_buttons(net);	gkrellm_draw_chart_to_screen(net->chart);	return FALSE;	}static gintcb_chart_leave(GtkWidget *w, GdkEventButton *ev, NetMon *net)	{	net->mouse_in_chart = FALSE;	net->reset_button_in = FALSE;	net->stats_button_in = FALSE;	refresh_net_chart(net);	return FALSE;	}static gintcb_panel_press(GtkWidget *widget, GdkEventButton *ev)	{	if (ev->button == 3)		gkrellm_open_config_window(mon_net);	return FALSE;	}  /* Make sure net charts appear in same order as the sorted net_mon_list  */static voidnet_chart_reorder(NetMon *new_net)	{	NetMon		*net;	GList		*list;	gint		i;	for (i = 0, list = net_mon_list; list; list = list->next)		{		net = (NetMon *) list->data;		if (net->parent_vbox != new_net->parent_vbox)			continue;		if (net == new_net)			break;		++i;		}	if (!list || !list->next)		return;	gtk_box_reorder_child(GTK_BOX(new_net->parent_vbox), new_net->vbox, i);	}static voidcreate_net_monitor(GtkWidget *vbox, NetMon *net, gint first_create)	{	GkrellmStyle	*style;	GkrellmChart	*cp;	GkrellmPanel	*p;	if (first_create)		{		net->parent_vbox = vbox;		net->vbox = gtk_vbox_new(FALSE, 0);		gtk_box_pack_start(GTK_BOX(vbox), net->vbox, FALSE, FALSE, 0);		net->chart = gkrellm_chart_new0();		net->chart->panel = gkrellm_panel_new0();		net->chart->panel->textstyle = gkrellm_textstyle_new0();		net_chart_reorder(net);		}	cp = net->chart;	p = cp->panel;	gkrellm_chart_create(net->vbox, mon_net, cp, &net->chart_config);	net->tx_cd = gkrellm_add_default_chartdata(cp, _("tx bytes"));	net->rx_cd = gkrellm_add_default_chartdata(cp, _("rx bytes"));	gkrellm_set_draw_chart_function(cp, refresh_net_chart, net);    gkrellm_chartconfig_fixed_grids_connect(cp->config,                setup_net_scaling, net);    gkrellm_chartconfig_grid_resolution_connect(cp->config,                setup_net_scaling, net);    gkrellm_chartconfig_grid_resolution_adjustment(cp->config, TRUE,                0, (gfloat) MIN_GRID_RES, (gfloat) MAX_GRID_RES, 0, 0, 0, 0);    gkrellm_chartconfig_grid_resolution_label(cp->config,                _("rx/tx bytes per sec"));    if (gkrellm_get_chartconfig_grid_resolution(cp->config) < MIN_GRID_RES)        gkrellm_set_chartconfig_grid_resolution(cp->config,				grid_resolution_default(net));    gkrellm_alloc_chartdata(cp);	style = gkrellm_panel_style(net_style_id);	gkrellm_create_krell(p, gkrellm_krell_panel_piximage(net_style_id), style);	net->rxled = gkrellm_create_decal_pixmap(p, decal_net_led_pixmap,				decal_net_led_mask, N_LEDS, style, 0, _GK.rx_led_y);	net->rxled->x = map_x(_GK.rx_led_x, net->rxled->w);	net->txled = gkrellm_create_decal_pixmap(p, decal_net_led_pixmap,				decal_net_led_mask, N_LEDS, style, 0, _GK.tx_led_y);	net->txled->x = map_x(_GK.tx_led_x, net->txled->w);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -