📄 prefs.c
字号:
/* gwcc/src/prefs.c * * Copyright (C) 2000-2001 by Brent D. Ely * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */// Good old config.h #ifdef HAVE_CONFIG_H # include <config.h> #endif// Include Libraries #include <gnome.h> /* (what do u think?) */ #include <string.h> /* for string functs */ #include <fcntl.h> /* for open() command */ #include <sys/stat.h> /* for mkdir() funct */ #include "prefs.h" #include "utils.h" #include "interface.h" #include "support.h"// Global Variables // Declare refs to app1 and others so we can interact with our widgets! extern GtkWidget *app1; // The Main Application Window extern GtkWidget *propertybox1; // Dialog - Preferences GtkWidget *dialog_save_as; // Dialog - "Save As..." GtkWidget *dialog_print; // Dialog - "Print" // Global Preference Variables // (Tabs: General, Workstation Utils, Grep, Network). int file_save_flag = 0; int timestamp_saved_file = 0; gchar *fixed_font_ptr; char fixed_font[240] = ""; int display_units = 0; int timestamp_scn_output = 0; int toolbar_setting_int = 0; int ifconfig_flag = 0; int df_flag_a = 0; int df_flag_h = 0; int df_flag_t = 0; int netstat_flag = 0; int grep_flag = 0; int use_grep_i_flag = 0; int omit_grep_sh_output = 0; int ping_c = 0; int ping_w = 0; int ping_i = 0; int use_traceroute_n = 0; int use_host_v = 0; int finger_flag = 0; int nslookup_retries = 0; int nslookup_timeout = 0;// ------------------------------------------------------------------------- //// -----------------> Read Preferences From Disk <------------------- //// ------------------------------------------------------------------------- //voidread_prefs_from_disk(){ // Local Variables char *name = ""; char *env_homedir = ""; char file_name[80] = ""; char dir_name[80] = ""; char in_string[80] = ""; char dialog_str[80] = ""; int value = 0; FILE *file_ptr; extern int errno; // Comes from <sys/stat.h> - used for determining exact error. EEXIST // Determine users home directory env_homedir = getenv("HOME"); if (env_homedir == NULL) { gnome_dialog_run_and_close(GNOME_DIALOG(gnome_error_dialog ("Cannot determine your $HOME directory... Thats weird."))); return; } // Construct final file_ptr string to prefs file strcpy(file_name, env_homedir); strcat(file_name, "/.gwcc/prefs.conf"); // Check for existence of .gwcc sub-directory / Create one if necc. // NOTE: This also covers the SAVE PREFS function below - because this is always called first! strcpy(dir_name, env_homedir); strcat(dir_name, "/.gwcc"); if ((mkdir(dir_name, (S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)) != 0) && (errno != 17)) {// printf("DEBUG: errno = %d \n", errno); sprintf(dialog_str, "Could not create PREFS directory (%s) - please do so yourself.", dir_name); gnome_dialog_run_and_close(GNOME_DIALOG(gnome_error_dialog(dialog_str))); return; } // Read Prefs File one line at a time -and- Assign Variables as we go if ((file_ptr = fopen(file_name, "r")) == NULL) { // Maybe this is the first time the program was run.. just ignore this exception. return; } while (fgets(in_string, 80, file_ptr) != NULL) { name = strtok(in_string, "="); // Assign Value to fixed_font Variable (its a char, so its different) if ((strcmp(name, "fixed_font") == 0) && (strlen(name) <= 10)) { sprintf(fixed_font, "%s", strtok(NULL, "=")); } else { value = atoi(strtok(NULL, "=")); } // Assign Values to Variables if (strcmp(name, "file_save_flag") == 0) file_save_flag = value; if (strcmp(name, "timestamp_saved_file") == 0) timestamp_saved_file = value; if (strcmp(name, "display_units") == 0) display_units = value; if (strcmp(name, "timestamp_scn_output") == 0) timestamp_scn_output = value; if (strcmp(name, "toolbar_setting_int") == 0) toolbar_setting_int = value; if (strcmp(name, "ifconfig_flag") == 0) ifconfig_flag = value; if (strcmp(name, "df_flag_a") == 0) df_flag_a = value; if (strcmp(name, "df_flag_h") == 0) df_flag_h = value; if (strcmp(name, "df_flag_t") == 0) df_flag_t = value; if (strcmp(name, "netstat_flag") == 0) netstat_flag = value; if (strcmp(name, "grep_flag") == 0) grep_flag = value; if (strcmp(name, "use_grep_i_flag") == 0) use_grep_i_flag = value; if (strcmp(name, "omit_grep_sh_output") == 0) omit_grep_sh_output = value; if (strcmp(name, "ping_c") == 0) ping_c = value; if (strcmp(name, "ping_w") == 0) ping_w = value; if (strcmp(name, "ping_i") == 0) ping_i = value; if (strcmp(name, "use_traceroute_n") == 0) use_traceroute_n = value; if (strcmp(name, "use_host_v") == 0) use_host_v = value; if (strcmp(name, "finger_flag") == 0) finger_flag = value; if (strcmp(name, "nslookup_retries") == 0) nslookup_retries = value; if (strcmp(name, "nslookup_timeout") == 0) nslookup_timeout = value; } fclose(file_ptr);}// ------------------------------------------------------------------------- //// ------------------> Save Preferences To Disk <------------------- //// ------------------------------------------------------------------------- //intsave_all_changes (GnomePropertyBox *gnomepropertybox, gint arg1, gpointer user_data){ // Local Variables char *env_homedir = ""; char file_name[80] = ""; char out_string[80] = ""; FILE *file_ptr; // Determine users home directory env_homedir = getenv("HOME"); if (env_homedir == NULL) { printf("ERROR: Cannot determine HOME directory!"); return(-1); } // Construct final file_ptr string to prefs file strcpy(file_name, env_homedir); strcat(file_name, "/.gwcc/prefs.conf"); // Write Prefs File to user's home directory under gwcc subdir if ((file_ptr = fopen(file_name, "w")) != NULL) { sprintf(out_string, "file_save_flag=%d\n", file_save_flag); fputs(out_string, file_ptr); sprintf(out_string, "timestamp_saved_file=%d\n", timestamp_saved_file); fputs(out_string, file_ptr); sprintf(out_string, "fixed_font=%s=\n", fixed_font); fputs(out_string, file_ptr); sprintf(out_string, "display_units=%d\n", display_units); fputs(out_string, file_ptr); sprintf(out_string, "timestamp_scn_output=%d\n", timestamp_scn_output); fputs(out_string, file_ptr); sprintf(out_string, "toolbar_setting_int=%d\n", toolbar_setting_int); fputs(out_string, file_ptr); sprintf(out_string, "ifconfig_flag=%d\n", ifconfig_flag); fputs(out_string, file_ptr); sprintf(out_string, "df_flag_a=%d\n", df_flag_a); fputs(out_string, file_ptr); sprintf(out_string, "df_flag_h=%d\n", df_flag_h); fputs(out_string, file_ptr); sprintf(out_string, "df_flag_t=%d\n", df_flag_t); fputs(out_string, file_ptr); sprintf(out_string, "netstat_flag=%d\n", netstat_flag); fputs(out_string, file_ptr); sprintf(out_string, "grep_flag=%d\n", grep_flag); fputs(out_string, file_ptr); sprintf(out_string, "use_grep_i_flag=%d\n", use_grep_i_flag); fputs(out_string, file_ptr); sprintf(out_string, "omit_grep_sh_output=%d\n", omit_grep_sh_output); fputs(out_string, file_ptr); sprintf(out_string, "ping_c=%d\n", ping_c); fputs(out_string, file_ptr); sprintf(out_string, "ping_w=%d\n", ping_w); fputs(out_string, file_ptr); sprintf(out_string, "ping_i=%d\n", ping_i); fputs(out_string, file_ptr); sprintf(out_string, "use_traceroute_n=%d\n", use_traceroute_n); fputs(out_string, file_ptr); sprintf(out_string, "use_host_v=%d\n", use_host_v); fputs(out_string, file_ptr); sprintf(out_string, "finger_flag=%d\n", finger_flag); fputs(out_string, file_ptr); sprintf(out_string, "nslookup_retries=%d\n", nslookup_retries); fputs(out_string, file_ptr); sprintf(out_string, "nslookup_timeout=%d\n", nslookup_timeout); fputs(out_string, file_ptr); } fclose(file_ptr); return(0);}// ------------------------------------------------------------------------- //// -----> Fill Preferences Dialog with Values from Prefs File <------ //// ------------------------------------------------------------------------- //voidfill_prefs_dialog(){ // Get pointers to window widgets and Declare local variables GtkWidget * checkbutton_ts_files = lookup_widget(propertybox1, "checkbutton_ts_files"); GtkWidget * radiobutton_save_overwrite = lookup_widget(propertybox1, "radiobutton_save_overwrite"); GtkWidget * radiobutton_save_append = lookup_widget(propertybox1, "radiobutton_save_append"); GtkWidget * radiobutton_save_seq = lookup_widget(propertybox1, "radiobutton_save_seq"); GtkWidget * check_add_timestamp = lookup_widget(propertybox1, "check_add_timestamp"); GtkWidget * fontpicker1 = lookup_widget(propertybox1, "fontpicker1"); GtkWidget * radiobutton_units_m = lookup_widget(propertybox1, "radiobutton_units_m"); GtkWidget * radiobutton_units_k = lookup_widget(propertybox1, "radiobutton_units_k"); GtkWidget * optionmenu_toolbar = lookup_widget(propertybox1, "optionmenu_toolbar"); GtkWidget * ifconfig_arp = lookup_widget(propertybox1, "ifconfig_arp"); GtkWidget * ifconfig_promisc = lookup_widget(propertybox1, "ifconfig_promisc"); GtkWidget * ifconfig_allmulti = lookup_widget(propertybox1, "ifconfig_allmulti"); GtkWidget * check_df_a = lookup_widget(propertybox1, "check_df_a"); GtkWidget * check_df_h = lookup_widget(propertybox1, "check_df_h"); GtkWidget * check_df_T = lookup_widget(propertybox1, "check_df_T"); GtkWidget * netstat_u = lookup_widget(propertybox1, "netstat_u"); GtkWidget * netstat_M = lookup_widget(propertybox1, "netstat_M"); GtkWidget * netstat_i = lookup_widget(propertybox1, "netstat_i"); GtkWidget * netstat_p = lookup_widget(propertybox1, "netstat_p"); GtkWidget * ps_flag_none = lookup_widget(propertybox1, "ps_flag_none"); GtkWidget * ps_flag_e = lookup_widget(propertybox1, "ps_flag_e"); GtkWidget * ps_flag_eh = lookup_widget(propertybox1, "ps_flag_eh"); GtkWidget * ps_flag_efh = lookup_widget(propertybox1, "ps_flag_efh"); GtkWidget * checkbutton_grep_case = lookup_widget(propertybox1, "checkbutton_grep_case"); GtkWidget * checkbutton_omit_sh = lookup_widget(propertybox1, "checkbutton_omit_sh"); GtkWidget * spinbutton1 = lookup_widget(propertybox1, "spinbutton1"); GtkWidget * spinbutton2 = lookup_widget(propertybox1, "spinbutton2"); GtkWidget * spinbutton3 = lookup_widget(propertybox1, "spinbutton3"); GtkWidget * checkbutton_traceroute_n = lookup_widget(propertybox1, "checkbutton_traceroute_n"); GtkWidget * checkbutton_host_v = lookup_widget(propertybox1, "checkbutton_host_v"); GtkWidget * finger_s = lookup_widget(propertybox1, "finger_s"); GtkWidget * finger_l = lookup_widget(propertybox1, "finger_l"); GtkWidget * spinbutton4 = lookup_widget(propertybox1, "spinbutton4"); GtkWidget * spinbutton5 = lookup_widget(propertybox1, "spinbutton5"); GtkWidget * menu;// GtkWidget * apply = lookup_widget(propertybox1, "apply"); // NOTE: This function causes the "Apply" button to become active, we have to.. // Disconnect "Apply" button signal handler or else "Apply" comes on right away!// gtk_widget_set_sensitive((GtkWidget *) apply, FALSE);// Brent: 05/31/01 - i have no idea what the hell this widget is identified by.. or what else to do??? // ------------------------------------- // General Prefs Tab: File Save Options // ------------------------------------- if (file_save_flag == 0) { gtk_toggle_button_set_active((GtkToggleButton *) radiobutton_save_overwrite, 1); } else if (file_save_flag == 1) { gtk_toggle_button_set_active((GtkToggleButton *) radiobutton_save_append, 1); } else if (file_save_flag == 2) { gtk_toggle_button_set_active((GtkToggleButton *) radiobutton_save_seq, 1); } // General Prefs Tab: Fixed Font // ------------------------------------- if (strlen(fixed_font) >= 1) { gnome_font_picker_set_font_name((GnomeFontPicker *) fontpicker1, (gchar *)fixed_font); } // General Prefs Tab: Units Options // ------------------------------------- if (display_units == 0) { gtk_toggle_button_set_active((GtkToggleButton *) radiobutton_units_m, 1); } else if (display_units == 1) { gtk_toggle_button_set_active((GtkToggleButton *) radiobutton_units_k, 1); } // General Prefs Tab: Timestamp Options // ------------------------------------- gtk_toggle_button_set_active((GtkToggleButton *) checkbutton_ts_files, timestamp_saved_file); gtk_toggle_button_set_active((GtkToggleButton *) check_add_timestamp, timestamp_scn_output); // General Prefs Tab: Toolbar Setting // ------------------------------------- // Two Tasks are *required* here: // 1) set active menu item index - gives the menu widget desired index value // 2) set OptionMenu history index - shows the selected menu item on screen // If you leave out step 2 the value is correct, but it wont show on screen!! menu = GTK_OPTION_MENU(optionmenu_toolbar)->menu; gtk_menu_set_active(GTK_MENU(menu), toolbar_setting_int); gtk_option_menu_set_history(GTK_OPTION_MENU(optionmenu_toolbar), toolbar_setting_int);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -