From owner-p4-projects@FreeBSD.ORG Mon Aug 20 13:35:43 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7812516A419; Mon, 20 Aug 2007 13:35:43 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4D76D16A418 for ; Mon, 20 Aug 2007 13:35:43 +0000 (UTC) (envelope-from dongmei@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 3C16013C45A for ; Mon, 20 Aug 2007 13:35:43 +0000 (UTC) (envelope-from dongmei@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l7KDZhQ4082675 for ; Mon, 20 Aug 2007 13:35:43 GMT (envelope-from dongmei@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l7KDZgWC082672 for perforce@freebsd.org; Mon, 20 Aug 2007 13:35:42 GMT (envelope-from dongmei@FreeBSD.org) Date: Mon, 20 Aug 2007 13:35:42 GMT Message-Id: <200708201335.l7KDZgWC082672@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to dongmei@FreeBSD.org using -f From: dongmei To: Perforce Change Reviews Cc: Subject: PERFORCE change 125406 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Aug 2007 13:35:43 -0000 http://perforce.freebsd.org/chv.cgi?CH=125406 Change 125406 by dongmei@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); + } }