📄 callbacks.c
字号:
gtk_widget_show(about1);}// ------------------------------------------------------------------------- //// ------------------------------- Toolbar Buttons ------------------------- //// ------------------------------------------------------------------------- //voidon_button_save_clicked (GtkButton *button, gpointer user_data){ on_save1_activate(NULL, user_data);}voidon_button_saveas_clicked (GtkButton *button, gpointer user_data){ on_save_as1_activate(NULL, user_data);}voidon_button_copy_clicked (GtkButton *button, gpointer user_data){ on_copy1_activate(NULL, user_data);}voidon_button_paste_clicked (GtkButton *button, gpointer user_data){ on_paste1_activate(NULL, user_data);}voidon_button_print_clicked (GtkButton *button, gpointer user_data){ on_print1_activate(NULL, user_data);}// ------------------------------------------------------------------------- //// ------------------------------ App1 Tab Items --------------------------- //// ------------------------------------------------------------------------- //voidon_grep_button_clicked (GtkButton *button, gpointer user_data){ // Get pointers to window widgets and declare local variables GtkWidget * text_grep = lookup_widget(app1, "text_grep"); GtkWidget * entry10 = lookup_widget(app1, "entry10"); GtkWidget * checkbutton20 = lookup_widget(app1, "checkbutton20"); GtkWidget * checkbutton21 = lookup_widget(app1, "checkbutton21"); GtkWidget * checkbutton22 = lookup_widget(app1, "checkbutton22"); GdkFont * fixed_font_ptr; FILE * pipein_fp; char * substr_ptr; char grep_string[80] = ""; char readbuf[80] = ""; char timestamp_str[80] = ""; gchar * grep_text; // Read grep text from textbox grep_text = gtk_entry_get_text((GtkEntry *) entry10); // PREFS: grep flags to use if (grep_flag == 0) { strcpy(grep_string, "ps | grep "); } else if (grep_flag == 1) { strcpy(grep_string, "ps -e | grep "); } else if (grep_flag == 2) { strcpy(grep_string, "ps -eH | grep "); } else if (grep_flag == 3) { strcpy(grep_string, "ps -efH | grep "); } // PREFS: use grep case insensitive (-i) if (use_grep_i_flag == 1) { strcat(grep_string, "-i "); } // Create final grep string to pass to system (add user string) strcat(grep_string, grep_text); // Read user output options and perform appropriate action. if (GTK_TOGGLE_BUTTON(checkbutton20)->active) { gtk_text_backward_delete(GTK_TEXT(text_grep), gtk_text_get_length(GTK_TEXT(text_grep))); } if (GTK_TOGGLE_BUTTON(checkbutton21)->active) { // PREFS: Fixed Font Size fixed_font_ptr = gdk_font_load((gchar *)fixed_font); } else { fixed_font_ptr = NULL; } // Create one way pipe to system and process command thru loop, then close pipe. if ((pipein_fp = popen(grep_string, "r")) == NULL) { perror("popen"); exit(1); } while (fgets(readbuf, 80, pipein_fp)) { // PREFS: omit grep shell command if (omit_grep_sh_output == 1) { substr_ptr = strstr(readbuf, "grep"); if (!strlen((char *)&substr_ptr) >= 1) { gtk_text_insert(GTK_TEXT(text_grep), fixed_font_ptr, NULL, NULL, readbuf, -1); } } else { gtk_text_insert(GTK_TEXT(text_grep), fixed_font_ptr, NULL, NULL, readbuf, -1); } } pclose(pipein_fp); // PREFS: Timestamp Screen Output if (timestamp_scn_output) { strcpy(timestamp_str, get_timestamp() ); gtk_text_insert(GTK_TEXT(text_grep), fixed_font_ptr, NULL, NULL, timestamp_str, -1); } // Insert divider after above output, if checkbutton clicked by client. if (GTK_TOGGLE_BUTTON(checkbutton22)->active) { gtk_text_insert(GTK_TEXT(text_grep), fixed_font_ptr, NULL, NULL, "-------------------------------------------------------------------------------- \n", -1); }}// ------------------------------------------------------------------------- //// ---> All Buttons from NETWORK UTILS Notebook Page Follow! <--- //// ------------------------------------------------------------------------- ///*****************************************************************************/voidon_network_submit_clicked (GtkButton *button, gpointer user_data){ // Get pointers to window widgets and declare local variables GtkWidget * checkbutton24 = lookup_widget(app1, "checkbutton24"); GtkWidget * checkbutton25 = lookup_widget(app1, "checkbutton25"); GtkWidget * checkbutton26 = lookup_widget(app1, "checkbutton26"); GtkWidget * text_network = lookup_widget(app1, "text_network"); GtkWidget * entry6 = lookup_widget(app1, "entry6"); GtkWidget * entry_network = lookup_widget(app1, "entry_network"); GtkWidget * gentry_network = lookup_widget(app1, "gentry_network"); GdkFont * fixed_font_ptr; FILE * pipein_fp; gchar * menu_text; gchar * net_text; gchar cmdline[80]; char readbuf[80]; char timestamp_str[80]; int done = 0; int count = 0; // Read Text Boxes: TextEntry (host/ip) and OptionMenu (operation) menu_text = gtk_entry_get_text((GtkEntry *) entry6); net_text = gtk_entry_get_text((GtkEntry *) entry_network); // Read user output options and perform appropriate action. if (GTK_TOGGLE_BUTTON(checkbutton24)->active) { gtk_text_backward_delete(GTK_TEXT(text_network), gtk_text_get_length(GTK_TEXT(text_network))); } if (GTK_TOGGLE_BUTTON(checkbutton25)->active) { // PREFS: Fixed Font Size fixed_font_ptr = gdk_font_load((gchar *)fixed_font); } else { fixed_font_ptr = NULL; } // In order to display STDERR messages, add "2>&1" to the end of command strings (nice!!) if (strncmp(menu_text, "ping", 4) == 0) { sprintf(cmdline, "ping -c %d -i %d -w %d %s 2>&1", ping_c, ping_i, ping_w, net_text); // NOTE: pinging some hosts creates a lock situation - 'ping -w' should prevent this, // but it doesnt seem to work on my linux box (or maybe at all?). -- 02/10/2001 } else if (strncmp(menu_text, "whois", 5) == 0) { sprintf(cmdline, "whois %s 2>&1", net_text); } else if (strncmp(menu_text, "nslookup", 8) == 0) { sprintf(cmdline, "nslookup retry=%d timeout=%d %s 2>&1", nslookup_retries, nslookup_timeout, net_text); } else if (strncmp(menu_text, "traceroute", 10) == 0) { // PREFS: use traceroute -n flag if (use_traceroute_n) { sprintf(cmdline, "/usr/sbin/traceroute -n %s 2>&1", net_text); } else { sprintf(cmdline, "/usr/sbin/traceroute %s 2>&1", net_text); } } else if (strncmp(menu_text, "host", 4) == 0) { // PREFS: use host -v flag if (use_host_v) { sprintf(cmdline, "host -v %s 2>&1", net_text); } else { sprintf(cmdline, "host %s 2>&1", net_text); } } else if (strncmp(menu_text, "finger", 6) == 0) { // PREFS: Finger Flag if (finger_flag == 0) { sprintf(cmdline, "finger -s %s 2>&1", net_text); } else if (finger_flag == 1) { sprintf(cmdline, "finger -l %s 2>&1", net_text); } } else { sprintf(cmdline, "%s %s 2>&1", menu_text, net_text); } // Create one way pipe to system and process command thru loop, then close pipe. // Note: popen executes the command as a subprocess, then creates a pipe to it. if ((pipein_fp = popen(cmdline, "r")) == NULL) { perror("popen"); exit(1); } while (!done) { if (fgets(readbuf, 80, pipein_fp) != NULL) { gtk_text_insert(GTK_TEXT(text_network), fixed_font_ptr, NULL, NULL, readbuf, -1); } else if (readbuf != NULL) { done = TRUE; } else { sleep(2); count++; } if (count >= 3) { gtk_text_insert(GTK_TEXT(text_network), fixed_font_ptr, NULL, NULL, "Operation Timed Out.\n", -1); done = TRUE; } } pclose(pipein_fp); // PREFS: Timestamp Screen Output if (timestamp_scn_output) { strcpy(timestamp_str, get_timestamp() ); gtk_text_insert(GTK_TEXT(text_network), fixed_font_ptr, NULL, NULL, timestamp_str, -1); } // Insert divider after above output, if checkbutton clicked by client. if (GTK_TOGGLE_BUTTON(checkbutton26)->active) { gtk_text_insert(GTK_TEXT(text_network), fixed_font_ptr, NULL, NULL, "-------------------------------------------------------------------------------- \n", -1); } // Save users entry text to history list gnome_entry_append_history((GnomeEntry *) gentry_network, TRUE, (gchar*)net_text); gnome_entry_save_history((GnomeEntry *) gentry_network);}gbooleanon_entry_network_key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data){ // If <RETURN> (65293) or <ENTER> (65421) key pressed, consider it a Button Press Event. if ((event->keyval == 65293) || (event->keyval == 65421)) { on_network_submit_clicked(NULL, NULL); } // Else return FALSE and keep going return FALSE;}// ------------------------------------------------------------------------- //// ---> All Buttons from PROCESS CONTROL Notebook Page Follow! <--- //// ------------------------------------------------------------------------- //voidon_signal_apply_clicked (GtkButton *button, gpointer user_data){ // Get pointers to window widgets, declare local vars GtkWidget *signal_entry = lookup_widget(app1, "signal_entry");// GtkWidget *optionmenu_entry = lookup_widget(app1, "optionmenu_entry"); gchar error_str[80]; gchar *signal_name; // Get SIGNAL string from entry widget signal_name = gtk_entry_get_text(GTK_ENTRY(signal_entry)); // Caluclate the signal number to send to system if (!strcmp(signal_name,"SIGHUP")) { signum = 1; } else if (!strcmp(signal_name,"SIGTERM")) { signum = 15; } else if (!strcmp(signal_name,"SIGKILL")) { signum = 9; } // Execute KILL Command // Show Error Dialog if we encounter problems killing process if (kill(pid2kill,signum) == -1) { sprintf(error_str, "OOPS! could not kill pid %d with signal %d!\n", pid2kill, signum); gnome_dialog_run_and_close(GNOME_DIALOG(gnome_error_dialog(error_str))); return; } // Reset signum signum = 0; // Refresh Process List on_process_refresh_clicked(NULL, NULL);}/*****************************************************************************/voidon_process_refresh_clicked (GtkButton *button, gpointer user_data){ // Props to the ps2 application that provided some insight on procs. // Get pointers to window widgets, declare local vars GtkWidget *process_clist = lookup_widget(app1, "process_clist"); GtkWidget *signal_apply = lookup_widget(app1, "signal_apply"); GtkWidget *combo6 = lookup_widget(app1, "combo6"); GtkWidget *label_selected_pid = lookup_widget(app1, "label_selected_pid"); struct stat finfo; struct passwd *pinfo; struct dirent *dinfo; struct sysinfo info; FILE *pipein_fp; DIR *dir; char *dir_chr; char *proc_str_list[6]; char mem_str[80]; char proc_file_name[256]; char p_state; char st_buffer[128]; char st_buf2[32]; char st_buf3[32]; char st_buf4[32];// char readbuf[80];// char cpu_str[80]; float proc_cpu_usage; int proc_total_cputime1; // will hold sum of utime & stime (user+system), used for %CPU int proc_total_cputime2; // will hold sum of utime & stime (user+system), used for %CPU int st_utime; // # of jiffies sched in User Mode int st_stime; // # of jiffies sched in Kernel Mode int st_starttime; int st_vms; int st_pri; int p_parentpid;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -