* add an option to funnel_register_menu to retap the packets right after been called
* add a set_close_cllback function to the textwindow mini-api to set a callback to be called when the window gets closed. * fix few issues regarding the closing of the window svn path=/trunk/; revision=17165
This commit is contained in:
parent
2826417ef7
commit
50d651fe5b
|
@ -33,6 +33,7 @@ typedef struct _funnel_menu_t {
|
|||
REGISTER_STAT_GROUP_E group;
|
||||
void (*callback)(gpointer);
|
||||
gpointer callback_data;
|
||||
gboolean retap;
|
||||
struct _funnel_menu_t* next;
|
||||
} funnel_menu_t;
|
||||
|
||||
|
@ -45,12 +46,14 @@ void funnel_set_funnel_ops(const funnel_ops_t* o) { ops = o; }
|
|||
void funnel_register_menu(const char *name,
|
||||
REGISTER_STAT_GROUP_E group,
|
||||
void (*callback)(gpointer),
|
||||
gpointer callback_data) {
|
||||
gpointer callback_data,
|
||||
gboolean retap) {
|
||||
funnel_menu_t* m = g_malloc(sizeof(funnel_menu_t));
|
||||
m->name = g_strdup(name);
|
||||
m->group = group;
|
||||
m->callback = callback;
|
||||
m->callback_data = callback_data;
|
||||
m->retap = retap;
|
||||
m->next = NULL;
|
||||
|
||||
if (!menus) {
|
||||
|
@ -65,7 +68,7 @@ void funnel_register_menu(const char *name,
|
|||
void funnel_register_all_menus(funnel_registration_cb_t r_cb) {
|
||||
funnel_menu_t* c;
|
||||
for (c = menus; c; c = c->next) {
|
||||
r_cb(c->name,c->group,c->callback,c->callback_data);
|
||||
r_cb(c->name,c->group,c->callback,c->callback_data,c->retap);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ typedef struct _funnel_tree_window_t funnel_tree_window_t ;
|
|||
typedef struct _funnel_node_t funnel_node_t ;
|
||||
typedef struct _funnel_dialog_t funnel_dialog_t;
|
||||
|
||||
typedef void (*text_win_close_cb_t)(void*);
|
||||
|
||||
typedef void (*funnel_dlg_cb_t)(const gchar** user_input);
|
||||
|
||||
typedef struct _funnel_ops_t {
|
||||
|
@ -49,6 +51,7 @@ typedef struct _funnel_ops_t {
|
|||
void (*prepend_text)(funnel_text_window_t* win, const gchar* text);
|
||||
void (*clear_text)(funnel_text_window_t* win);
|
||||
const gchar* (*get_text)(funnel_text_window_t* win);
|
||||
void (*set_close_cb)(funnel_text_window_t* win, text_win_close_cb_t cb, void* data);
|
||||
void (*destroy_text_window)(funnel_text_window_t* win);
|
||||
#if 0
|
||||
funnel_node_t* (*new_tree_window)(const gchar* title, gchar** columns);
|
||||
|
@ -72,15 +75,17 @@ extern void funnel_set_funnel_ops(const funnel_ops_t*);
|
|||
|
||||
|
||||
extern void funnel_register_menu(const char *name,
|
||||
REGISTER_STAT_GROUP_E group,
|
||||
void (*callback)(gpointer),
|
||||
gpointer callback_data);
|
||||
REGISTER_STAT_GROUP_E group,
|
||||
void (*callback)(gpointer),
|
||||
gpointer callback_data,
|
||||
gboolean retap);
|
||||
|
||||
|
||||
typedef void (*funnel_registration_cb_t)(const char *name,
|
||||
REGISTER_STAT_GROUP_E group,
|
||||
void (*callback)(gpointer),
|
||||
gpointer callback_data);
|
||||
gpointer callback_data,
|
||||
gboolean retap);
|
||||
|
||||
extern void funnel_register_all_menus(funnel_registration_cb_t r_cb);
|
||||
|
||||
|
|
|
@ -60,6 +60,9 @@
|
|||
struct _funnel_text_window_t {
|
||||
GtkWidget* win;
|
||||
GtkWidget* txt;
|
||||
GtkWidget* bt_close;
|
||||
text_win_close_cb_t close_cb;
|
||||
void* close_data;
|
||||
};
|
||||
|
||||
struct _funnel_tree_window_t {
|
||||
|
@ -80,14 +83,37 @@ static void text_window_cancel_button_cb(GtkWidget *bt _U_, gpointer data) {
|
|||
|
||||
window_destroy(GTK_WIDGET(tw->win));
|
||||
tw->win = NULL;
|
||||
|
||||
tw->close_cb(tw->close_data);
|
||||
}
|
||||
|
||||
static void unref_text_win_cancel_bt_cb(GtkWidget *bt _U_, gpointer data) {
|
||||
funnel_text_window_t* tw = data;
|
||||
|
||||
window_destroy(GTK_WIDGET(tw->win));
|
||||
tw->win = NULL;
|
||||
|
||||
tw->close_cb(tw->close_data);
|
||||
|
||||
g_free(tw);
|
||||
|
||||
}
|
||||
|
||||
static text_window_delete_event_cb(GtkWidget *win, GdkEvent *event _U_, gpointer user_data)
|
||||
{
|
||||
funnel_text_window_t* tw = user_data;
|
||||
window_destroy(win);
|
||||
tw->close_cb(tw->close_data);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static funnel_text_window_t* new_text_window(const gchar* title) {
|
||||
funnel_text_window_t* tw = g_malloc(sizeof(funnel_text_window_t));
|
||||
GtkWidget *txt_scrollw, *main_vb, *bbox, *bt_close;
|
||||
GtkWidget *txt_scrollw, *main_vb, *bbox;
|
||||
|
||||
tw->win = window_new(GTK_WINDOW_TOPLEVEL,title);
|
||||
SIGNAL_CONNECT(tw->win, "delete-event", text_window_delete_event_cb, tw);
|
||||
|
||||
txt_scrollw = scrolled_window_new(NULL, NULL);
|
||||
main_vb = gtk_vbox_new(FALSE, 3);
|
||||
gtk_container_border_width(GTK_CONTAINER(main_vb), 12);
|
||||
|
@ -124,9 +150,9 @@ static funnel_text_window_t* new_text_window(const gchar* title) {
|
|||
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
|
||||
gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
|
||||
|
||||
bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
|
||||
SIGNAL_CONNECT(bt_close, "clicked", text_window_cancel_button_cb, tw);
|
||||
gtk_widget_grab_default(bt_close);
|
||||
tw->bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
|
||||
SIGNAL_CONNECT(tw->bt_close, "clicked", text_window_cancel_button_cb, tw);
|
||||
gtk_widget_grab_default(tw->bt_close);
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(txt_scrollw), tw->txt);
|
||||
gtk_window_resize(GTK_WINDOW(tw->win),400,300);
|
||||
|
@ -153,6 +179,8 @@ http://www.gnome.org/mailing-lists/archives/gtk-devel-list/1999-October/0051.sht
|
|||
gtk_adjustment_set_value(txt->vadj, 0.0);
|
||||
gtk_text_forward_delete(txt, gtk_text_get_length(txt));
|
||||
#else
|
||||
if (! tw->win) return;
|
||||
|
||||
GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(tw->txt));
|
||||
|
||||
gtk_text_buffer_set_text(buf, "", 0);
|
||||
|
@ -218,6 +246,11 @@ static const gchar* text_window_get_text(funnel_text_window_t* tw) {
|
|||
return "";
|
||||
}
|
||||
|
||||
static void text_window_set_close_cb(funnel_text_window_t* tw, text_win_close_cb_t cb, void* data) {
|
||||
tw->close_cb = cb;
|
||||
tw->close_data = data;
|
||||
}
|
||||
|
||||
static void text_window_destroy(funnel_text_window_t* tw) {
|
||||
/*
|
||||
* XXX: This way Lua's garbage collector might destroy the window.
|
||||
|
@ -225,9 +258,18 @@ static void text_window_destroy(funnel_text_window_t* tw) {
|
|||
* the window can live after Lua has destroyed it and we do not leak the window object.
|
||||
*/
|
||||
if (tw->win) {
|
||||
window_destroy(tw->win);
|
||||
/*
|
||||
* the window is still there and its callbacks refer to this data structure
|
||||
* we need to change the callback so that they free tw.
|
||||
*/
|
||||
SIGNAL_CONNECT(tw->bt_close, "clicked", unref_text_win_cancel_bt_cb, tw);
|
||||
} else {
|
||||
/*
|
||||
* we have no window anymore a human user closed
|
||||
* the window already just free the container
|
||||
*/
|
||||
g_free(tw);
|
||||
}
|
||||
g_free(tw);
|
||||
}
|
||||
|
||||
static const funnel_ops_t ops = {
|
||||
|
@ -237,6 +279,7 @@ static const funnel_ops_t ops = {
|
|||
text_window_prepend,
|
||||
text_window_clear,
|
||||
text_window_get_text,
|
||||
text_window_set_close_cb,
|
||||
text_window_destroy
|
||||
};
|
||||
|
||||
|
@ -244,21 +287,25 @@ static const funnel_ops_t ops = {
|
|||
typedef struct _menu_cb_t {
|
||||
void (*callback)(gpointer);
|
||||
void* callback_data;
|
||||
gboolean retap;
|
||||
} menu_cb_t;
|
||||
|
||||
static void our_menu_callback(void* unused _U_, gpointer data) {
|
||||
menu_cb_t* mcb = data;
|
||||
mcb->callback(mcb->callback_data);
|
||||
if (mcb->retap) cf_retap_packets(&cfile, FALSE);
|
||||
}
|
||||
|
||||
static void register_menu_cb(const char *name,
|
||||
REGISTER_STAT_GROUP_E group,
|
||||
void (*callback)(gpointer),
|
||||
gpointer callback_data) {
|
||||
gpointer callback_data,
|
||||
gboolean retap) {
|
||||
menu_cb_t* mcb = g_malloc(sizeof(menu_cb_t));
|
||||
|
||||
mcb->callback = callback;
|
||||
mcb->callback_data = callback_data;
|
||||
mcb->retap = retap;
|
||||
|
||||
register_stat_menu_item(name, group, our_menu_callback, NULL, NULL, mcb);
|
||||
|
||||
|
|
Loading…
Reference in New Issue