📄 gui.c
字号:
/*************************************************************************** * gui.c * * Mon Sep 3 09:39:45 2007 * Copyright 2007 hunbuso * hunbuso@gmail.com ****************************************************************************/#include "main.h"#include "gui.h"static GtkListStore *proxy_store = NULL; /**代理存储仓 */static GtkTreeStore *statistics_store = NULL; /**统计存储仓*/static gint update_statistics (void);void window_main_init (void){ GtkWidget *treeview_window_main_proxy_list; GtkWidget *treeview_window_main_statistics; GtkCellRenderer *renderer; GtkCellRenderer *renderer_1; GtkTreeModel *model; GtkTreeModel *model_1; GtkTreeIter iter; g_assert(app->gui.window_main != NULL); treeview_window_main_proxy_list = lookup_widget (GTK_WIDGET(app->gui.window_main), \ "treeview_window_main_proxy_list"); app->gui.textview_window_main_pf_info = lookup_widget(GTK_WIDGET(app->gui.window_main), \ "textview_window_main_pf_info"); treeview_window_main_statistics = lookup_widget(GTK_WIDGET(app->gui.window_main), "treeview_window_main_statistics"); g_assert(treeview_window_main_proxy_list != NULL); g_assert(app->gui.textview_window_main_pf_info != NULL); g_assert(treeview_window_main_statistics != NULL); /*添加心跳*/ app->gui.timeout_update_statistics = gtk_timeout_add(1000, (GtkFunction)update_statistics, NULL);/*****************************代理存储仓****************************************/ /** 创建一个存储仓 */ if (!proxy_store) proxy_store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); /** 添加列视 */ renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview_window_main_proxy_list), -1, _("IP"), renderer, "text", COL_IP, NULL); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview_window_main_proxy_list), -1, _("Port"), renderer, "text", COL_PORT, NULL); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview_window_main_proxy_list), -1, _("Delay"), renderer, "text", COL_DELAY, NULL); model = GTK_TREE_MODEL (proxy_store); gtk_tree_view_set_model (GTK_TREE_VIEW (treeview_window_main_proxy_list), model); g_object_unref (model); /*****************************统计存储仓****************************************/ /*统计用*/ TreeItem proxyinfo[] = { {_("Useable proxy count"), NULL, NULL}, {_("Unuseable proxy count"), NULL, NULL}, {_("total proxy count"), NULL, NULL}, {NULL} }; TreeItem flaw_cacu[] = { {_("Send"), NULL, NULL}, {_("Receive"), NULL, NULL}, {_("Total"), NULL, NULL}, {NULL} }; TreeItem toplevel[] = { {_("Proxy information"), NULL, proxyinfo}, {_("Flow caculation"), NULL, flaw_cacu}, {NULL} }; if (!statistics_store) statistics_store = gtk_tree_store_new (NUM_COLS_STATISTICS, G_TYPE_STRING, G_TYPE_STRING); TreeItem *statistics = toplevel; /*统计树*/ while (statistics->key) { TreeItem *children = statistics->children; gtk_tree_store_append (statistics_store, &iter, NULL); gtk_tree_store_set (statistics_store, &iter, COL_KEYNAME, statistics->key, COL_VALUE, statistics->value, -1); while (children->key) { GtkTreeIter child_iter; gtk_tree_store_append (statistics_store, &child_iter, &iter); gtk_tree_store_set (statistics_store, &child_iter, COL_KEYNAME, children->key, COL_VALUE, children->value, -1); children ++; } statistics ++; } renderer_1 = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(treeview_window_main_statistics), -1, _("KeyName"), renderer_1, "text", COL_KEYNAME, NULL); renderer_1 = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(treeview_window_main_statistics), -1, _("Value"), renderer_1, "text", COL_VALUE, NULL); model_1 = GTK_TREE_MODEL (statistics_store); gtk_tree_view_set_model (GTK_TREE_VIEW (treeview_window_main_statistics), model_1);// g_object_unref (model_1); /*扩展*/ gtk_tree_view_expand_all(GTK_TREE_VIEW(treeview_window_main_statistics));}void append_proxy_to_list (GtkWidget* treeview, gchar* ip, gchar* port, gchar* delay){ GtkTreeIter iter; GtkTreeModel *model; /** 增加行、填充数据 */ gtk_list_store_append (proxy_store, &iter); gtk_list_store_set (proxy_store, &iter, COL_IP, ip, COL_PORT, port, COL_DELAY, delay, -1); model = GTK_TREE_MODEL (proxy_store); gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), model);}/** * 描述: 更新状态条 */void update_statusbar (GtkWidget* statusbar, gchar* message){ if ((NULL == statusbar) || (NULL == message)) return; gtk_statusbar_pop(GTK_STATUSBAR(statusbar), 1); gtk_statusbar_push(GTK_STATUSBAR(statusbar), 1, message);}/** * 描述:更新文本视图 */static void insert_textview (GtkWidget* textview, gchar* message){ if ((NULL == textview) || (NULL == message)) return; guint line_max = 80; /*最大行数,超过则全部裁掉*/ guint line_cout = 0; /*当前行数*/ GtkTextIter startiter; GtkTextIter enditer; GtkTextIter iter; GtkWidget* scrolledwindow_window_main_textview_pf_info; /*滚动窗口*/ GtkAdjustment *v_scrollbar; /*垂直滚动*/ scrolledwindow_window_main_textview_pf_info = lookup_widget(app->gui.window_main, \ "scrolledwindow_window_main_textview_pf_info"); g_assert(scrolledwindow_window_main_textview_pf_info != NULL); v_scrollbar = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolledwindow_window_main_textview_pf_info)); GtkTextBuffer *text_buffer_message = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); gtk_text_buffer_get_bounds(text_buffer_message, &startiter, &enditer); line_cout = gtk_text_buffer_get_line_count(GTK_TEXT_BUFFER(text_buffer_message)); /*若超过最大行数*/ if (line_cout > line_max) gtk_text_buffer_delete(text_buffer_message, &startiter, &enditer); /*下一行*/ gtk_text_buffer_get_iter_at_line(text_buffer_message, &iter, line_cout); /*插入*/ gtk_text_buffer_insert(text_buffer_message, &iter, message, strlen(message)); gtk_text_buffer_insert(text_buffer_message, &iter, "\n", strlen("\n")); /*下滚*/ gtk_adjustment_set_value(GTK_ADJUSTMENT(v_scrollbar), v_scrollbar->upper);}/** * 记录proxyfish运行信息 */void log_proxy_fish_info (gchar* message){ if (NULL == message) return; g_assert(app->gui.textview_window_main_pf_info != NULL); insert_textview(app->gui.textview_window_main_pf_info, message);}/** * 更新统计树的某一项 */static void update_statistics_item (gchar* t_path, gchar* value){ GtkTreePath *path; GtkTreeIter iter; if (NULL == t_path || NULL == value) return; path = gtk_tree_path_new_from_string (t_path); gtk_tree_model_get_iter (GTK_TREE_MODEL(statistics_store), &iter, path); gtk_tree_store_set (statistics_store, &iter, COL_VALUE,value, -1);}/** * 更新统计信息 */static gint update_statistics (void){ GString* s_usea_pro_c = g_string_new("0"); /*可用代理计数*/ GString* s_u_usea_pro_c = g_string_new("0"); /*不可用代理计数*/ GString* s_total_pro_c = g_string_new("0"); /*代理计数*/ GString* s_flaw_send = g_string_new("0"); /*发送流量统计*/ GString* s_flaw_rec = g_string_new("0"); /*接收流量统计*/ GString* s_flaw_total = g_string_new("0"); /*流量统计*/ g_string_printf(s_usea_pro_c, "%u", app->env.proxy_useable_total); g_string_printf(s_u_usea_pro_c, "%u", app->env.proxy_unuseable_total); g_string_printf(s_total_pro_c, "%u", app->env.proxy_useable_total + app->env.proxy_unuseable_total); g_string_printf(s_flaw_send, "%-15u Byte", app->env.flaw_send_total); g_string_printf(s_flaw_rec, "%-15u Byte", app->env.flaw_rec_total); g_string_printf(s_flaw_total, "%u", app->env.flaw_send_total + app->env.flaw_rec_total); gdk_threads_enter(); update_statistics_item("0:0", s_usea_pro_c->str); update_statistics_item("0:1", s_u_usea_pro_c->str); update_statistics_item("0:2", s_total_pro_c->str); update_statistics_item("1:0", s_flaw_send->str); update_statistics_item("1:1", s_flaw_rec->str); update_statistics_item("1:2", s_flaw_total->str); gdk_threads_leave(); g_string_free(s_usea_pro_c, TRUE); g_string_free(s_u_usea_pro_c, TRUE); g_string_free(s_total_pro_c, TRUE); g_string_free(s_flaw_send, TRUE); g_string_free(s_flaw_rec, TRUE); g_string_free(s_flaw_total, TRUE); return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -