PERFORCE change 125406 for review
dongmei
dongmei at FreeBSD.org
Mon Aug 20 06:35:43 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=125406
Change 125406 by dongmei at dongmei2007 on 2007/08/20 13:35:09
add the file reset functions
Affected files ...
.. //depot/projects/soc2007/dongmei-auditanalyzer/gtk/main.c#4 edit
.. //depot/projects/soc2007/dongmei-auditanalyzer/gtk/simple_dialog.h#1 add
.. //depot/projects/soc2007/dongmei-auditanalyzer/gtk/trail_file_dlg.c#2 edit
.. //depot/projects/soc2007/dongmei-auditanalyzer/tfile.c#4 edit
Differences ...
==== //depot/projects/soc2007/dongmei-auditanalyzer/gtk/main.c#4 (text+ko) ====
@@ -11,6 +11,8 @@
#include "tree_view.h"
#include "stdbool.h"
#include "toolbar.h"
+#include "simple_dialog.h"
+#include "compat_macros.h"
trailer_file cfile;
bool fstop=FALSE;
@@ -18,13 +20,88 @@
static GtkWidget *menubar, *main_vbox, *main_tb, *pkt_scrollw, *stat_hbox, *filter_tb;
static GtkWidget *main_pane_v1, *main_pane_v2, *main_pane_h1, *main_pane_h2,*vpaned;
+gboolean
+main_do_quit(void)
+{
+
+ /* Are we in the middle of reading a capture? */
+ if (cfile.state == FILE_READ_IN_PROGRESS) {
+ /* Yes, so we can't just close the file and quit, as
+ that may yank the rug out from under the read in
+ progress; instead, just set the state to
+ "FILE_READ_ABORTED" and return - the code doing the read
+ will check for that and, if it sees that, will clean
+ up and quit. */
+ cfile.state = FILE_READ_ABORTED;
+
+ /* Say that the window should *not* be deleted;
+ that'll be done by the code that cleans up. */
+ return TRUE;
+ } else {
+ /* Close any capture file we have open; on some OSes, you
+ can't unlink a temporary capture file if you have it
+ open.
+ "cf_close()" will unlink it after closing it if
+ it's a temporary file.
+
+ We do this here, rather than after the main loop returns,
+ as, after the main loop returns, the main window may have
+ been destroyed (if this is called due to a "destroy"
+ even on the main window rather than due to the user
+ selecting a menu item), and there may be a crash
+ or other problem when "cf_close()" tries to
+ clean up stuff in the main window.
+
+ XXX - is there a better place to put this?
+ Or should we have a routine that *just* closes the
+ capture file, and doesn't do anything with the UI,
+ which we'd call here, and another routine that
+ calls that routine and also cleans up the UI, which
+ we'd call elsewhere? */
+ tf_close(&cfile);
+ /* Exit by leaving the main loop, so that any quit functions
+ we registered get called. */
+ gtk_main_quit();
+
+ /* Say that the window should be deleted. */
+ return FALSE;
+ }
+}
+
+static void file_quit_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
+{
+ switch(btn) {
+ case(ESD_BTN_SAVE):
+ /* save file first */
+// file_save_as_cmd(after_save_exit, NULL);
+ break;
+ case(ESD_BTN_DONT_SAVE):
+ main_do_quit();
+ break;
+ case(ESD_BTN_CANCEL):
+ break;
+ default:
+ g_assert_not_reached();
+ }
+}
+
/* This function is connected to the Close button or
* closing the window from the WM */
gint file_quit_cmd_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
{
- gtk_main_quit ();
- return FALSE;
+ gpointer dialog;
+
+ if((cfile.state != FILE_CLOSED) && !cfile.user_saved ) {
+ /* user didn't saved his current file, ask him */
+ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
+ PRIMARY_TEXT_START "Save capture file before program quit?" PRIMARY_TEXT_END "\n\n"
+ "If you quit the program without saving, your capture data will be discarded.");
+ simple_dialog_set_cb(dialog, file_quit_answered_cb, NULL);
+ } else {
+ /* unchanged file, just exit */
+ main_do_quit();
+ }
}
static GtkWidget *create_toolbar(void)
{
==== //depot/projects/soc2007/dongmei-auditanalyzer/gtk/trail_file_dlg.c#2 (text+ko) ====
@@ -7,6 +7,7 @@
#include "gui_utils.h"
#include "../tfile.h"
#include "gtkglobals.h"
+#include "simple_dialog.h"
#define DEF_WIDTH 750
#define DEF_HEIGHT 550
@@ -119,8 +120,37 @@
else window_destroy(file_open_w);
}
+
+static void file_open_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
+{
+ switch(btn) {
+ case(ESD_BTN_SAVE):
+ /* save file first */
+// file_save_as_cmd(after_save_open_dialog, data);
+ break;
+ case(ESD_BTN_DONT_SAVE):
+ tf_close(&cfile);
+ file_open_cmd(data);
+ break;
+ case(ESD_BTN_CANCEL):
+ break;
+ default:
+ g_assert_not_reached();
+ }
+}
+
void
file_open_cmd_cb(GtkWidget *widget, gpointer data _U_) {
+ gpointer dialog;
+
+ if((cfile.state != FILE_CLOSED) && !cfile.user_saved){
+ /* user didn't saved his current file, ask him */
+ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
+ PRIMARY_TEXT_START "Save capture file before opening a new one?" PRIMARY_TEXT_END "\n\n"
+ "If you open a new capture file without saving, your capture data will be discarded.");
+ simple_dialog_set_cb(dialog, file_open_answered_cb, widget);
+ } else {
file_open_cmd(widget);
}
+}
==== //depot/projects/soc2007/dongmei-auditanalyzer/tfile.c#4 (text+ko) ====
@@ -47,15 +47,9 @@
static void
tf_reset_state(trailer_file *tf)
{
- g_assert(tf->state != FILE_READ_IN_PROGRESS);
-
/* ...which means we have nothing to save. */
tf->user_saved = FALSE;
- if (tf->rlist_chunk != NULL) {
- g_mem_chunk_destroy(tf->rlist_chunk);
- tf->rlist_chunk = NULL;
- }
tf->rlist = NULL;
tf->rlist_end = NULL;
tf->first_displayed = NULL;
@@ -64,14 +58,11 @@
/* No record selected. */
tf->current_record = NULL;
- /* Clear the packet list. */
-// record_list_freeze();
-// record_list_clear();
-// record_list_thaw();
-
tf->f_datalen = 0;
tf->count = 0;
-
+/*clear list*/
+ record_list_clear();
+ clear_tree_view_rows();
/* We have no file open. */
tf->state = FILE_CLOSED;
}
@@ -501,6 +492,8 @@
void
tf_close(trailer_file *tf)
{
- fclose(tf->ts->fd);
+ if (tf->state!=FILE_CLOSED){
+ tf_reset_state(tf);
+ }
}
More information about the p4-projects
mailing list