📄 iptuxsetup.cpp
字号:
//// C++ Implementation: IptuxSetup//// Description:////// Author: Jally <jallyx@163.com>, (C) 2008//// Copyright: See COPYING file that comes with this distribution////#include "IptuxSetup.h"#include "Control.h"#include "my_entry.h"#include "my_chooser.h"#include "UdpData.h"#include "Command.h"#include "Pal.h"#include "support.h"#include "output.h"#include "baling.h"#include "utils.h"GtkWidget *IptuxSetup::setup = NULL; IptuxSetup::IptuxSetup():icon_model(NULL), ip_model(NULL),myname(NULL), myicon(NULL), save_path(NULL), ad(NULL),sign(NULL), encode(NULL), palicon(NULL), font(NULL),tidy(NULL), log(NULL), black(NULL), proof(NULL), entry1(NULL), entry2(NULL), ipseg_view(NULL){}IptuxSetup::~IptuxSetup(){ g_object_unref(icon_model); g_object_unref(ip_model);}void IptuxSetup::SetupEntry(){ IptuxSetup *ipst; if (IptuxSetup::CheckExist()) return; ipst = new IptuxSetup; ipst->InitSetup(); ipst->CreateSetup();}void IptuxSetup::InitSetup(){ icon_model = CreateIconModel(); ip_model = CreateIpModel();}void IptuxSetup::CreateSetup(){ GtkWidget *box; GtkWidget *notebook, *hbb; setup = create_window(_("Iptux setup"), 132, 100); gtk_container_set_border_width(GTK_CONTAINER(setup), 5); g_signal_connect_swapped(setup, "destroy", G_CALLBACK(SetupDestroy), this); box = create_box(); gtk_container_add(GTK_CONTAINER(setup), box); notebook = gtk_notebook_new(); gtk_widget_show(notebook); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_LEFT); gtk_box_pack_start(GTK_BOX(box), notebook, TRUE, TRUE, 0); CreatePerson(notebook); CreateSystem(notebook); CreateIpseg(notebook); hbb = create_button_box(FALSE); gtk_box_pack_start(GTK_BOX(box), hbb, FALSE, FALSE, 0); CreateFuncButton(hbb);}void IptuxSetup::CreatePerson(GtkWidget * note){ extern Control ctr; char path[MAX_PATHBUF]; GtkWidget *label, *frame, *sw, *button; GtkWidget *box, *hbox; GdkPixbuf *pixbuf; box = create_box(); label = create_label(_("Personal Setup")); gtk_notebook_append_page(GTK_NOTEBOOK(note), box, label); hbox = create_box(FALSE); gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); myname = create_label(_("Your nickname:")); gtk_box_pack_start(GTK_BOX(hbox), myname, FALSE, FALSE, 0); myname = my_entry::create_entry(ctr.myname, _("Please Input your nickname!"), FALSE); gtk_box_pack_start(GTK_BOX(hbox), myname, TRUE, TRUE, 0); hbox = create_box(FALSE); gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); myicon = create_label(_("Your head portrait:")); gtk_box_pack_start(GTK_BOX(hbox), myicon, FALSE, FALSE, 0); myicon = CreateComboBoxWithModel(icon_model, ctr.myicon); gtk_box_pack_start(GTK_BOX(hbox), myicon, TRUE, TRUE, 0); button = create_button("..."); g_signal_connect_swapped(button, "clicked", G_CALLBACK(AddPalIcon), myicon); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); hbox = create_box(FALSE); gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); save_path = create_label(_("Save file to:")); gtk_box_pack_start(GTK_BOX(hbox), save_path, FALSE, FALSE, 0); save_path = CreateFolderChooser(); gtk_box_pack_start(GTK_BOX(hbox), save_path, TRUE, TRUE, 0); /***************************/ hbox = create_box(FALSE); gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); /***************************/ frame = create_frame(_("Personal portrait")); gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 3); button = gtk_button_new(); gtk_widget_show(button); gtk_widget_set_size_request(button, MAX_PREVIEWSIZE, MAX_PREVIEWSIZE); gtk_container_add(GTK_CONTAINER(frame), button); ad = gtk_image_new(); gtk_widget_show(ad); gtk_container_add(GTK_CONTAINER(button), ad); snprintf(path, MAX_PATHBUF, "%s/.iptux/myad", getenv("HOME")); if (pixbuf = gdk_pixbuf_new_from_file(path, NULL)) { pixbuf_shrink_scale_1(&pixbuf, MAX_PREVIEWSIZE, MAX_PREVIEWSIZE); gtk_image_set_from_pixbuf(GTK_IMAGE(ad), pixbuf); g_object_unref(pixbuf); } g_signal_connect_swapped(button, "clicked", G_CALLBACK(ChoosePortrait), ad); frame = create_frame(_("Personal signature")); gtk_box_pack_end(GTK_BOX(hbox), frame, TRUE, TRUE, 3); sw = create_scrolled_window(); gtk_container_add(GTK_CONTAINER(frame), sw); sign = create_text_view(); gtk_container_add(GTK_CONTAINER(sw), sign); gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(sign)), ctr.sign?ctr.sign:"", -1);}void IptuxSetup::CreateSystem(GtkWidget * note){ extern Control ctr; GtkWidget *label, *button; GtkWidget *box, *hbox; box = create_box(); label = create_label(_("System Setup")); gtk_notebook_append_page(GTK_NOTEBOOK(note), box, label); hbox = create_box(FALSE); gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); encode = create_label(_("Default network encode:")); gtk_box_pack_start(GTK_BOX(hbox), encode, FALSE, FALSE, 0); encode = my_entry::create_entry(ctr.encode, _("Default network encode(before modify,you must understand what you are doing)"), FALSE); gtk_box_pack_start(GTK_BOX(hbox), encode, TRUE, TRUE, 0); hbox = create_box(FALSE); gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); palicon = create_label(_("Pal's default head portrait:")); gtk_box_pack_start(GTK_BOX(hbox), palicon, FALSE, FALSE, 0); palicon = CreateComboBoxWithModel(icon_model, ctr.palicon); gtk_box_pack_start(GTK_BOX(hbox), palicon, TRUE, TRUE, 0); button = create_button("..."); g_signal_connect_swapped(button, "clicked", G_CALLBACK(AddPalIcon), palicon); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); hbox = create_box(FALSE); gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); font = create_label(_("Font to show for panel:")); gtk_box_pack_start(GTK_BOX(hbox), font, FALSE, FALSE, 0); font = CreateFontChooser(); gtk_box_pack_start(GTK_BOX(hbox), font, TRUE, TRUE, 0); tidy = gtk_check_button_new_with_label(_ ("Automatic clear up chat history")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tidy), FLAG_ISSET(ctr.flags, 3)); gtk_widget_show(tidy); gtk_box_pack_start(GTK_BOX(box), tidy, FALSE, FALSE, 0); log = gtk_check_button_new_with_label(_ ("Run the log of the message record")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(log), FLAG_ISSET(ctr.flags, 2)); gtk_widget_show(log); gtk_box_pack_start(GTK_BOX(box), log, FALSE, FALSE, 0); black = gtk_check_button_new_with_label(_ ("Use the blacklist(not recommended)")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(black), FLAG_ISSET(ctr.flags, 1)); gtk_widget_show(black); gtk_box_pack_start(GTK_BOX(box), black, FALSE, FALSE, 0); proof = gtk_check_button_new_with_label(_ ("Filter the request for shared files")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(proof), FLAG_ISSET(ctr.flags, 0)); gtk_widget_show(proof); gtk_box_pack_start(GTK_BOX(box), proof, FALSE, FALSE, 0);}void IptuxSetup::CreateIpseg(GtkWidget * note){ extern Control ctr; char buf[MAX_BUF]; GtkWidget *box, *label; GtkWidget *hbox, *button; GtkWidget *frame, *sw; box = create_box(); label = create_label(_("IP Section Setup")); gtk_notebook_append_page(GTK_NOTEBOOK(note), box, label); hbox = create_box(FALSE); gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); entry1 = create_label(_("Begin:")); gtk_box_pack_start(GTK_BOX(hbox), entry1, FALSE, FALSE, 0); entry1 = my_entry::create_entry(NULL, _("begin IPv4"), TRUE); gtk_box_pack_start(GTK_BOX(hbox), entry1, TRUE, TRUE, 0); entry2 = create_label(_("End:")); gtk_box_pack_start(GTK_BOX(hbox), entry2, FALSE, FALSE, 0); entry2 = my_entry::create_entry(NULL, _("end IPv4"), TRUE); gtk_box_pack_start(GTK_BOX(hbox), entry2, TRUE, TRUE, 0); hbox = create_button_box(FALSE); gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_SPREAD); gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); snprintf(buf, MAX_BUF, "%s↓↓", _("Add")); button = create_button(buf); g_signal_connect_swapped(button, "clicked", G_CALLBACK(ClickAddIpseg), this); gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); snprintf(buf, MAX_BUF, "%s↑↑", _("Delete")); button = create_button(buf); g_signal_connect_swapped(button, "clicked", G_CALLBACK(ClickDelIpseg), this); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); frame = create_frame(_("Added IPv4 section:")); gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 5); sw = create_scrolled_window(); gtk_container_add(GTK_CONTAINER(frame), sw); ipseg_view = CreateIpsegView(); gtk_container_add(GTK_CONTAINER(sw), ipseg_view);}void IptuxSetup::CreateFuncButton(GtkWidget * hbb){ GtkWidget *button; button = create_button(_("OK")); g_signal_connect_swapped(button, "clicked", G_CALLBACK(ClickOk), this); gtk_box_pack_end(GTK_BOX(hbb), button, FALSE, FALSE, 1); button = create_button(_("Apply")); g_signal_connect_swapped(button, "clicked", G_CALLBACK(ClickApply), this); gtk_box_pack_end(GTK_BOX(hbb), button, FALSE, FALSE, 1); button = create_button(_("Cancel")); g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_widget_destroy), setup); gtk_box_pack_end(GTK_BOX(hbb), button, FALSE, FALSE, 1);}//IP 2,0 ip,1 ipGtkTreeModel *IptuxSetup::CreateIpModel(){ extern Control ctr; GtkListStore *model; GtkTreeIter iter; GSList *tmp; model = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); pthread_mutex_lock(&ctr.mutex); tmp = ctr.ipseg; while (tmp) { gtk_list_store_append(model, &iter); gtk_list_store_set(model, &iter, 0, (gchar *) tmp->data, -1); tmp = tmp->next; gtk_list_store_set(model, &iter, 1, (gchar *) tmp->data, -1); tmp = tmp->next; } pthread_mutex_unlock(&ctr.mutex); return GTK_TREE_MODEL(model);}GtkWidget *IptuxSetup::CreateFolderChooser(){ extern Control ctr; GtkWidget *chooser; chooser = gtk_file_chooser_button_new(_("Save file to"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER (chooser), TRUE); gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(chooser), TRUE); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), ctr.path); gtk_widget_show(chooser); return chooser;}GtkWidget *IptuxSetup::CreateFontChooser(){ extern Control ctr; GtkWidget *chooser; chooser = gtk_font_button_new_with_font(ctr.font); gtk_font_button_set_show_style(GTK_FONT_BUTTON(chooser), TRUE); gtk_font_button_set_show_size(GTK_FONT_BUTTON(chooser), TRUE); gtk_font_button_set_use_font(GTK_FONT_BUTTON(chooser), TRUE); gtk_font_button_set_use_size(GTK_FONT_BUTTON(chooser), TRUE); gtk_font_button_set_title(GTK_FONT_BUTTON(chooser), _("Please choose a font")); gtk_widget_show(chooser); return chooser;}GtkWidget *IptuxSetup::CreateIpsegView(){ GtkWidget *view; GtkCellRenderer *renderer; GtkTreeViewColumn *column; view = gtk_tree_view_new_with_model(ip_model); gtk_widget_show(view); column = gtk_tree_view_column_new(); gtk_tree_view_column_set_resizable(column, TRUE); gtk_tree_view_column_set_expand(column, TRUE); gtk_tree_view_column_set_title(column, _("begin IPv4")); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(column, renderer, TRUE); gtk_tree_view_column_set_attributes(column, renderer, "text", 0, NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -