📄 callbacks.c
字号:
/* gwcc/src/callbacks.c * * Copyright (C) 2000, 2001, 2002 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. *//* --------------------------------------------------------------------------- * Greetings From The Author: * --------------------------------------------------------------------------- * Hi there. Whether you are an Open Source advocate, curious academic, * a linux newbie, or Bill Gates himself (gag), you must surely recognize * the inherent power that lies in the ability to view the source code * of a program. Those of us who work in cubicles pounding out web * applications and Internet apps day-after-day are *used* to digging * through examples of HTML/Perl/JavaScripts. How can one really learn * to program without the ability to view other programs? * * Even in my CS undergrad classes we would have to run and analyze other * programs to really understand our own. And how is one supposed to continue * to learn without tutorials? I can view the API reference on * developer.gnome.org *all day long* and never know how i am supposed to * create and utilize preference files or setup/read a Save dialog! * * What about people with the abilty to visualize and code complex programs * but no access to a job at Oracle or Apple? How could one ever learn what * goes on inside programs like IE or Netscape (pre-mozilla)? We can all learn * to code simple C/C++ programs from books and tutorials, but how can me and * my friends ever hope to create the next Quake or SimCity without being able * to see and learn what goes on inside these projects and how to make such * monstrousities work? * * With the advent of Open Source - and in this case, GNOME - we can all * sharpen our learning curves dramatically. Being able to view the source * from programs that i find interesting really helps to bring my own projects * new strength and usability. Is this not what goes in on in science and * industry? If i want to build a bridge, i have to figure it all out myself? * No, there are open, accessable blue prints and diagrams for me to utilize. * * Bottom Line: i hope you find something in this program useful to your * next programming project. Some of my methods (preferences, for example) * may not conform to standard GNOME practices, but like, come on man, * coding is more of an art than a science! *lol* * * <soap box> * Support Open Source (GPL et. al.) and contribute where you can, * our children will be surfing the Net that we create today. * </soap box> * * Have fun and happy coding! * ..Brent (sfbrent@users.sourceforge.net) * <:-) * --------------------------------------------------------------------------- */#ifdef HAVE_CONFIG_H# include <config.h>#endif/*--- Include Libraries ---*/#include <gtk/gtk.h> /* gtk_widget_queue_resize */#include <gnome.h>#include <signal.h> /* for kill() */#include <sys/sysinfo.h> /* for sysinfo() *///#include <syscall.h> // Commented out for 0.9.8//#include <linux/kernel.h> // Commented out for 0.9.8//#include <linux/sys.h> // Commented out for 0.9.8#include <netdb.h> /* for gethostby* */#include <netinet/in.h> /* IP Address structures */#include <arpa/inet.h> /* for inet_ntoa() */#include <string.h> /* for string funcs */#include <dirent.h> /* for DIR and readdir */#include <time.h> /* for gettimeofday */#include <sys/stat.h> /* to stat(proc info) */#include <pwd.h> /* pwd */#include "callbacks.h" /* the .h for this file */#include "prefs.h" /* my PREFS functions */#include "interface.h" /* GLADE-generated UI */#include "support.h" /* GLADE-generated functs */#include "utils.h" /* my utility functions *//*--- Global Variables ---*/ // Declare refs to app1 and others so we can interact with our widgets! extern GtkWidget * app1; // The Main Application Window extern GtkWidget * proc_popmenu; // Popmenu - brought up by right-click in Process CList. GtkWidget * propertybox1; // Dialog - Preferences GtkWidget * dialog_print; // Dialog - "Print" int pid2kill = 0; int signum = 0; int compare_col = 0; // Global Preference Variables extern char timestamp_str[80]; // The timestamp_string used in utils.c extern int file_save_flag; extern int timestamp_saved_file; extern char fixed_font[240]; extern int display_units; extern int timestamp_scn_output; extern int toolbar_setting_int; extern int ifconfig_flag; extern int df_flag_a; extern int df_flag_h; extern int df_flag_t; extern int netstat_flag; extern int grep_flag; extern int use_grep_i_flag; extern int omit_grep_sh_output; extern int ping_c; extern int ping_w; extern int ping_i; extern int use_traceroute_n; extern int use_host_v; extern int finger_flag; extern int nslookup_retries; extern int nslookup_timeout;//***************************************************************************//// Function for Sorting Numeric Columns ////***************************************************************************//static gintcompare(GtkCList *clist, gconstpointer p1, gconstpointer p2){ GtkCell *cell1, *cell2; gchar *fn1, *fn2; cell1 = ((GtkCListRow *)p1)->cell; cell2 = ((GtkCListRow *)p2)->cell; // use the "+0" part to determine which column to get value from! fn1 = (cell1 + compare_col)->u.text; fn2 = (cell2 + compare_col)->u.text; if (atof(fn1) <= atof(fn2)) { return -1; } else { return 1; }}//***************************************************************************//// Program Functions... ////***************************************************************************//voidon_app1_destroy (GtkObject *object, gpointer user_data){ // The user closed the GWCC window - lets kill the app now. on_exit1_activate(NULL, NULL);}// ------------------------------------------------------------------------- //// ------------------------------- Menu Items ------------------------------ //// ------------------------------------------------------------------------- //voidon_save1_activate (GtkMenuItem *menuitem, gpointer user_data){ // Call file saving function. if (perform_file_save("home", NULL) != 0) { gnome_dialog_run_and_close(GNOME_DIALOG(gnome_error_dialog ("No File Created!\nThere is nothing to save."))); return; }}voidon_save_as1_activate (GtkMenuItem *menuitem, gpointer user_data){ // Get pointers to window widgets and declare local variables GtkWidget * file_dialog; // This opens the Standard GNOME File Selection dialog file_dialog = gtk_file_selection_new("Save As..."); // Associate dialog Buttons with Handlers gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(file_dialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(on_button_save_as_okay_clicked), file_dialog); gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(file_dialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC(on_button_save_as_cancel_clicked), file_dialog); gtk_window_set_modal(GTK_WINDOW(file_dialog), TRUE); gtk_widget_show(file_dialog);}voidon_button_save_as_okay_clicked (GtkButton *button, gpointer user_data){ // Get pointers to window widgets and declare local variables int result = 0; // Call GWCC file saving function (utils.c) result = perform_file_save("saveas", user_data); if (result == -2) { gnome_dialog_run_and_close(GNOME_DIALOG(gnome_error_dialog ("No File Created!\nYou must enter a filename to use Save As."))); } else if (result == -1) { gnome_dialog_run_and_close(GNOME_DIALOG(gnome_error_dialog ("No File Created!\nThere is nothing to save."))); }}voidon_button_save_as_cancel_clicked (GtkButton *button, gpointer user_data){ // <Cancel> button was clicked, so close "Save As" Dialog gtk_widget_destroy(GTK_WIDGET(user_data));}voidon_print1_activate (GtkMenuItem *menuitem, gpointer user_data){ // Create temp file to be Printed (via file_save function) // or ERROR out here (before even opening Print Dialog). if (perform_file_save("temp", NULL) != 0) { gnome_dialog_run_and_close(GNOME_DIALOG(gnome_error_dialog( "Operation Failed!\nThere is nothing to print."))); return; } // Create the "Print" Dialog dialog_print = create_dialog_print(); gtk_widget_show(dialog_print);}voidon_exit1_activate (GtkMenuItem *menuitem, gpointer user_data){ // Buh-bye! gtk_main_quit();}voidon_copy1_activate (GtkMenuItem *menuitem, gpointer user_data){ // Get pointers to window widgets and declare local variables GtkWidget * notebook1 = lookup_widget(app1, "notebook1"); GtkWidget * text_wsutils = lookup_widget(app1, "text_wsutils"); GtkWidget * entry_ipaddr = lookup_widget(app1, "entry_ipaddr"); GtkWidget * entry_to_copy = NULL; int notebook_page = 0; // Get the number (int) of current notebook page (0...n-1) notebook_page = gtk_notebook_get_current_page((GtkNotebook *) notebook1); // ..then pick appropriate textbox to copy from. if (notebook_page == 0) { entry_to_copy = text_wsutils; } else if (notebook_page == 1) { entry_to_copy = lookup_widget(app1, "text_grep"); } else if (notebook_page == 2) { entry_to_copy = lookup_widget(app1, "text_network"); } else if (notebook_page == 3) { return; } else if (notebook_page == 4) { // brent - need method for determining which text to copy - 02/08/01 gtk_entry_select_region(GTK_ENTRY(entry_ipaddr), 0, strlen(gtk_entry_get_text(GTK_ENTRY(entry_ipaddr)))); entry_to_copy = lookup_widget(app1, "entry_ipaddr"); } gtk_editable_copy_clipboard(GTK_EDITABLE(entry_to_copy));}voidon_paste1_activate (GtkMenuItem *menuitem, gpointer user_data){ // Get pointers to window widgets and declare local variables GtkWidget * notebook1 = lookup_widget(app1, "notebook1"); GtkWidget * entry_to_paste = NULL; int notebook_page = 0; // Get the number (int) of current notebook page (0...n-1) // ..then pick appropriate textbox to copy from. notebook_page = gtk_notebook_get_current_page((GtkNotebook *) notebook1); if (notebook_page == 0) { return; } else if (notebook_page == 1) { entry_to_paste = lookup_widget(app1, "entry_network"); } else if (notebook_page == 2) { entry_to_paste = lookup_widget(app1, "entry10"); } else if (notebook_page == 3) { return; } else if (notebook_page == 4) { return; } gtk_editable_paste_clipboard(GTK_EDITABLE(entry_to_paste));}voidon_preferences1_activate (GtkMenuItem *menuitem, gpointer user_data){ // Read prefs from disk and assign all global vars only done at startup. // read_prefs_from_disk() is called from main.c at startup, afterwords // all variables are set when user makes selection, then written to disk. // Create the Preferences PropertyBox propertybox1 = create_propertybox1(); gtk_widget_show(propertybox1); // Fill correct values into Prefs Dialog Widgets across all pages. fill_prefs_dialog();}voidon_about1_activate (GtkMenuItem *menuitem, gpointer user_data){ GtkWidget * about1; about1 = create_about1();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -