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

📄 net.c

📁 系统任务管理器
💻 C
📖 第 1 页 / 共 5 页
字号:
	*(p->textstyle) = *gkrellm_panel_textstyle(net_style_id);	if (strlen(net->name) > 5)		p->textstyle->font = gkrellm_panel_alt_textstyle(net_style_id)->font;	gkrellm_panel_configure(p, net->name, style);	gkrellm_panel_create(net->vbox, mon_net, p);	setup_net_scaling(cp->config, net);	net->new_text_format = TRUE;	if (first_create)		{		g_signal_connect(G_OBJECT (cp->drawing_area), "expose_event",					G_CALLBACK(net_expose_event), NULL);		g_signal_connect(G_OBJECT(cp->drawing_area), "button_press_event",					G_CALLBACK(cb_chart_press), net);		g_signal_connect(G_OBJECT(cp->drawing_area), "button_release_event",					G_CALLBACK(cb_chart_release), net);		g_signal_connect(G_OBJECT(cp->drawing_area), "enter_notify_event",					G_CALLBACK(cb_chart_enter), net);		g_signal_connect(G_OBJECT(cp->drawing_area), "leave_notify_event",					G_CALLBACK(cb_chart_leave), net);		g_signal_connect(G_OBJECT (p->drawing_area), "expose_event",					G_CALLBACK(net_expose_event), NULL);		g_signal_connect(G_OBJECT(p->drawing_area), "button_press_event",					G_CALLBACK(cb_panel_press), NULL);		gtk_widget_show_all(net->vbox);		}	else		refresh_net_chart(net);	gkrellm_setup_launcher(p, &net->launch, CHART_PANEL_TYPE, 0);	draw_led(net, RX_LED, RX_OFF);	draw_led(net, TX_LED, TX_OFF);	if (net->force_up)		net->locked = TRUE;	}static voidnet_timer_visibility(void)	{	if (timer_button_enabled)		{		gkrellm_panel_show(timer_panel);		gkrellm_spacers_show(mon_timer);		}	else		{		gkrellm_panel_hide(timer_panel);		gkrellm_spacers_hide(mon_timer);		}	}static gintdays_in_year(gint y)	{	if((y % 4) == 0)		return 366;	return 365;	}  /* Adjust a tm date structure to reference its next day.  */static void next_day(struct tm *t)	{	if ((t->tm_wday += 1) > SATURDAY)		t->tm_wday = SUNDAY;	if ((t->tm_yday += 1) >= days_in_year(t->tm_year) )		{		t->tm_year += 1;		t->tm_yday = 0;		}	if ((t->tm_mday += 1) > days_in_month[t->tm_mon])		{		if (   t->tm_mon == 1		    && (((gint)t->tm_year - 80) % 4) == 0		    && t->tm_mday == 29)			;		else			{			if ((t->tm_mon += 1) > 11)				t->tm_mon = 0;			t->tm_mday = 1;			}		}	}static gbooleannet_accounting_month_new(struct tm *tm)	{	if (   tm->tm_mday == reset_mday		|| (   reset_mday > days_in_month[tm->tm_mon]			&& tm->tm_mday == 1		   )	   )		return TRUE;	return FALSE;	}voidgkrellm_net_save_data(void)	{	FILE		*f;	GList		*list;	struct tm	*tm  = gkrellm_get_current_time();	NetMon		*net;	gchar		fname[256];	gint		i;	for (list = net_mon_list; list; list = list->next)		{		net = (NetMon *) list->data;		if (!net->enabled)			continue;		snprintf(fname, sizeof(fname), "%s%c%s", net_data_dir,					G_DIR_SEPARATOR, net->name);		if ((f = fopen(fname, "w")) == NULL)			continue;		fprintf(f, "%d\n", NET_DATA_VERSION);		fputs("wday mday month yday year\n", f);		fprintf(f, "%d %d %d %d %d\n", tm->tm_wday,					tm->tm_mday, tm->tm_mon, tm->tm_yday, tm->tm_year);		fputs("[daily]\n", f);		for (i = 0; i < N_DAY_STATS; ++i)			fprintf(f, "\"%s\" %.0f %.0f %d\n", net->day_stats[i].date,					net->day_stats[i].rx, net->day_stats[i].tx,					net->day_stats[i].connect_time);		fputs("[weekly]\n", f);		for (i = 0; i < N_WEEK_STATS; ++i)			fprintf(f, "\"%s\" %.0f %.0f %d\n", net->week_stats[i].date,					net->week_stats[i].rx, net->week_stats[i].tx,					net->week_stats[i].connect_time);		fputs("[monthly]\n", f);			for (i = 0; i < N_MONTH_STATS; ++i)		fprintf(f, "\"%s\" %.0f %.0f %d\n", net->month_stats[i].date,					net->month_stats[i].rx, net->month_stats[i].tx,					net->month_stats[i].connect_time);		fclose(f);		}	}static gchar *utf8_string(gchar *string)	{	gchar	*utf8 = NULL;	if (   g_utf8_validate(string, -1, NULL)	    || (utf8 = g_locale_to_utf8(string, -1, NULL, NULL, NULL)) == NULL	   )		utf8 = g_strdup(string);	return utf8;	}static voidnet_stat_set_date_string(NetStat *ns, enum StatType stat_type, struct tm *t)	{	struct tm	tm  = *t,				tmx;	gchar		*utf8, buf[32], bufa[32], bufb[32];	if (stat_type == DAY_STAT)		{		strftime(buf, sizeof(buf), "%F", &tm);	/* %Y-%m-%d (the ISO 8601) */		}	else if (stat_type == WEEK_STAT)		{		while (tm.tm_wday != SATURDAY)			next_day(&tm);		strftime(buf, sizeof(buf), "%F", &tm);		}	else if (stat_type == MONTH_STAT)		{		if (reset_mday == 1)			strftime(buf, sizeof(buf), "%B", &tm);	/* full month name */		else			{			tmx = tm;			if (tm.tm_mday < reset_mday)				{				tmx.tm_mon -= 1;				if (tmx.tm_mon < 0)					{					tmx.tm_mon = 11;					tmx.tm_year -= 1;					}				}			else				{				tm.tm_mon += 1;				if (tm.tm_mon > 11)					{					tm.tm_mon = 0;					tm.tm_year += 1;					}				}			tmx.tm_mday = reset_mday;			tm.tm_mday = reset_mday - 1;			if (tmx.tm_mday > days_in_month[tmx.tm_mon])				tmx.tm_mday = days_in_month[tmx.tm_mon];			if (tm.tm_mday > days_in_month[tm.tm_mon])				tm.tm_mday = days_in_month[tm.tm_mon];			strftime(bufa, sizeof(bufa), "%b %e", &tmx);			strftime(bufb, sizeof(bufb), "%b %e", &tm);			snprintf(buf, sizeof(buf), "%s - %s", bufa, bufb);			}		}	else		return;	g_free(ns->date);	utf8 = utf8_string(buf);	ns->date = utf8 ? utf8 : g_strdup("??");	}static voidnet_stat_init(NetMon *net)	{	struct tm	*tm = gkrellm_get_current_time();	gint		i;	for (i = 0; i < N_DAY_STATS; ++i)		net->day_stats[i].date = g_strdup("---");	for (i = 0; i < N_WEEK_STATS; ++i)		net->week_stats[i].date = g_strdup("---");	for (i = 0; i < N_MONTH_STATS; ++i)		net->month_stats[i].date = g_strdup("---");	net_stat_set_date_string(&net->day_stats[0], DAY_STAT, tm);	net_stat_set_date_string(&net->week_stats[0], WEEK_STAT, tm);	net_stat_set_date_string(&net->month_stats[0], MONTH_STAT, tm);	}static voidnet_stats_shift_down(NetStat *ns, gint n_stats, enum StatType stat_type)	{	gint	d;	g_free(ns[n_stats - 1].date);	for (d = n_stats - 1; d > 0; --d)		ns[d] = ns[d - 1];	ns->rx = ns->tx = 0.0;	ns->connect_time = 0;	ns->date = NULL;	net_stat_set_date_string(ns, stat_type, gkrellm_get_current_time());	}static voidload_net_data(void)	{	FILE		*f;	GList		*list;	struct tm	*tm  = gkrellm_get_current_time();	NetMon		*net;	NetStat		*ns = NULL;	gchar		buf[128], fname[256], date[32];	gint		wday, mday, month, yday, year, version;	gint		day_delta, month_delta, n_stats = 0;	for (list = net_mon_list; list; list = list->next)		{		net = (NetMon *) list->data;		snprintf(fname, sizeof(fname), "%s%c%s", net_data_dir,					G_DIR_SEPARATOR, net->name);		if ((f = fopen(fname, "r")) == NULL)			continue;		fgets(buf, sizeof(buf), f);		if (sscanf(buf, "%d\n", &version) != 1)			{			fclose(f);			continue;			}		fgets(buf, sizeof(buf), f);		/* Comment line */		fgets(buf, sizeof(buf), f);		sscanf(buf, "%d %d %d %d %d", &wday, &mday, &month, &yday, &year);		if (version == 1)			{			struct tm	tmx = *gkrellm_get_current_time();			tmx.tm_wday = wday;			tmx.tm_mday = mday;			tmx.tm_mon = month;			tmx.tm_yday = yday;			tmx.tm_year = year;			fgets(buf, sizeof(buf), f);		/* day */			fgets(buf, sizeof(buf), f);			sscanf(buf, "%lf %lf",						&net->day_stats[0].rx, &net->day_stats[0].tx);			fgets(buf, sizeof(buf), f);		/* week */			fgets(buf, sizeof(buf), f);			sscanf(buf, "%lf %lf",						&net->week_stats[0].rx, &net->week_stats[0].tx);			fgets(buf, sizeof(buf), f);		/* month */			fgets(buf, sizeof(buf), f);			sscanf(buf, "%lf %lf",						&net->month_stats[0].rx, &net->month_stats[0].tx);			net_stat_set_date_string(&net->day_stats[0], DAY_STAT, &tmx);			net_stat_set_date_string(&net->week_stats[0], WEEK_STAT, &tmx);			net_stat_set_date_string(&net->month_stats[0], MONTH_STAT, &tmx);			if (   net == net_timed				&& fgets(buf, sizeof(buf), f)	/* connect day*/			   )				{				fgets(buf, sizeof(buf), f);				sscanf(buf, "%d %d %d",						&net->day_stats[0].connect_time,						&net->week_stats[0].connect_time,						&net->month_stats[0].connect_time);				}						}		else if (version == NET_DATA_VERSION)			{			while (fgets(buf, sizeof(buf), f) != NULL)				{				if (!strncmp(buf, "[daily]", 7))					{					ns = &net->day_stats[0];					n_stats = N_DAY_STATS;					}				else if (!strncmp(buf, "[weekly]", 8))					{					ns = &net->week_stats[0];					n_stats = N_WEEK_STATS;					}				else if (!strncmp(buf, "[monthly]", 9))					{					ns = &net->month_stats[0];					n_stats = N_MONTH_STATS;					}				else if (   ns && n_stats > 0				         && sscanf(buf, "\"%31[^\"]\" %lf %lf %d",				               date, &ns->rx, &ns->tx, &ns->connect_time) == 4				        )					{					gkrellm_dup_string(&ns->date, date);					++ns;					--n_stats;					}				}			}		else			{			fclose(f);			continue;			}		fclose(f);		month_delta = (tm->tm_year * 12 + tm->tm_mon) - (year * 12 + month);		if (month_delta == 0)			day_delta = tm->tm_mday - mday;		else if (month_delta == 1)			day_delta = days_in_month[month] - mday + tm->tm_mday;		else			day_delta = 7;		/* max compared to is 6 */		if (day_delta > 0)			net_stats_shift_down(&net->day_stats[0], N_DAY_STATS, DAY_STAT);		if (wday + day_delta != tm->tm_wday)			net_stats_shift_down(&net->week_stats[0], N_WEEK_STATS, WEEK_STAT);		if (   (   tm->tm_mday < reset_mday				&& (   (month_delta > 1)					|| (month_delta == 1 && mday < reset_mday)				   )			   )			|| (   tm->tm_mday >= reset_mday				&& (   (month_delta > 0)					|| (month_delta == 0 && mday < reset_mday)				   )			   )		   )			net_stats_shift_down(&net->month_stats[0], N_MONTH_STATS,						MONTH_STAT);		}	}#define SEC_PAD	0static voidcreate_net_timer(GtkWidget *vbox, gint first_create)	{	GkrellmPanel		*p;	GkrellmStyle		*style;	GkrellmTextstyle	*ts, *ts_alt;	GkrellmMargin		*m;	GkrellmBorder		*tb;	gint				top_margin, bot_margin;	gint				x, y, w, h, w_avail;	if (first_create)		timer_panel = gkrellm_panel_new0();	p = timer_panel;	style = gkrellm_meter_style(timer_style_id);	ts = gkrellm_meter_textstyle(timer_style_id);	ts_alt = gkrellm_meter_alt_textstyle(timer_style_id);	m = gkrellm_get_style_margins(style);	tb = &bg_timer_style->border;	button_decal = gkrellm_create_decal_pixmap(p, decal_timer_button_pixmap,			decal_timer_button_mask, N_TB_DECALS, style, -1, -1);	button_decal->x = gkrellm_chart_width() - m->right - button_decal->w;	w_avail = button_decal->x - m->left - 3;	if (bg_timer_piximage)		w_avail -= tb->left + tb->right;	w = gkrellm_gdk_string_width(ts->font, "0000:0000");	sec_pad = gkrellm_gdk_string_width(ts->font, "0") * 2 / 3;	if (w > w_avail)		w = w_avail;	time_decal = gkrellm_create_decal_text(p, "0:", ts, style, -1, -1, w);	seconds_decal = gkrellm_create_decal_text(p, "00",				ts_alt, style, -1, -1, 0);	gkrellm_panel_configure(p, NULL, style);	/* Some special work needed here if there is a bg_timer.  I have so	|  far the time_decal and button_decal fitting inside top/bottom margins.	|  If I add bg_timer borders to time_decal height and that ends up higher	|  than button_decal, I will need to grow the panel height.	*/	h = time_decal->h;	if (bg_timer_piximage)		{		gkrellm_get_top_bottom_margins(style, &top_margin, &bot_margin);		h += tb->top + tb->bottom;		time_decal->y += tb->top;		time_decal->x += tb->left;		if (h > button_decal->h)	/* Need to grow the height ? */			{			gkrellm_panel_configure_set_height(p, h + top_margin + bot_margin);			button_decal->y += (h - button_decal->h) / 2;			}		else	/* button_decal->y is OK */			time_decal->y += (button_decal->h - h) / 2;		}	else		{		/* time_decal and button_decal are initially at same y = top_margin		*/			if (time_decal->h > button_decal->h)			button_decal->y += (time_decal->h - button_decal->h) / 2;		else			time_decal->y += (button_decal->h - time_decal->h) / 2;		}	seconds_decal->y = time_decal->y + time_decal->h - seconds_decal->h;	gkrellm_panel_create(vbox, mon_timer, p);	gkrellm_move_decal(p, seconds_decal,				time_decal->x + time_decal->w - seconds_decal->w,				seconds_decal->y);	if (first_create)		{		g_signal_connect(G_OBJECT (p->drawing_area), "expose_event",					G_CALLBACK(net_expose_event), NULL);		g_signal_connect(G_OBJECT(p->drawing_area), "button_release_event",					G_CALLBACK(cb_timer_button_release), NULL);		g_signal_connect(G_OBJECT(p->drawing_area), "leave_notify_event",					G_CALLBACK(cb_timer_button_release), NULL);		g_signal_connect(G_OBJECT(p->drawing_area), "button_press_event",					G_CALLBACK(cb_timer_button_press), NULL);		}	if (bg_timer_piximage)		{		w += tb->left + tb->right;		x = time_decal->x - tb->left;		y = time_decal->y - tb->top;		gkrellm_paste_piximage(bg_timer_piximage, p->pixmap, x, y, w, h);		gkrellm_paste_piximage(bg_timer_piximage, p->bg_pixmap, x, y, w, h);		gdk_draw_drawable(p->bg_text_layer_pixmap, _GK.draw1_GC, p->bg_pixmap,                0, 0,  0, 0,  p->w, p->h);		}	set_timer_button_state(timer_button_state);	}static voidupdate_net(void)	{	GList			*list;	NetMon			*net;	struct tm		*tm;	GkrellmPanel	*p;	gint			bytes;	gdouble			rxd, txd;

⌨️ 快捷键说明

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