From dfd6dd53a491c4e7a878e005468090ec1a128442 Mon Sep 17 00:00:00 2001 From: Luis Ontanon Date: Mon, 11 Aug 2008 01:33:31 +0000 Subject: Add a slightly modified version of Paolo Abeni's funneled progress dialog (ref https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=2725) and its wslua interface. svn path=/trunk/; revision=25977 --- epan/wslua/wslua.h | 10 +++- epan/wslua/wslua_gui.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++ gtk/funnel_stat.c | 31 +++++++++++-- tap-funnel.c | 5 +- 4 files changed, 162 insertions(+), 7 deletions(-) diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index ec75205602..a5fcd87398 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -161,8 +161,7 @@ struct _wslua_cols { struct _wslua_treeitem { proto_item* item; proto_tree* tree; - gboolean expired; - + gboolean expired; }; typedef void (*tap_extractor_t)(lua_State*,const void*); @@ -188,7 +187,13 @@ struct _wslua_dir { DIRECTORY_T* dir; char* ext; GError** dummy; +}; +struct _wslua_progdlg { + funnel_progress_window_t* pw; + char* title; + char* task; + gboolean stopped; }; typedef struct { const char* name; tap_extractor_t extractor; } tappable_t; @@ -213,6 +218,7 @@ typedef header_field_info** Field; typedef field_info* FieldInfo; typedef struct _wslua_tap* Listener; typedef funnel_text_window_t* TextWindow; +typedef struct _wslua_progdlg* ProgDlg; typedef wtap_dumper* Dumper; typedef struct lua_pseudo_header* PseudoHeader; typedef tvbparse_t* Parser; diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c index 41cca57b14..a2b551b016 100644 --- a/epan/wslua/wslua_gui.c +++ b/epan/wslua/wslua_gui.c @@ -219,6 +219,129 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /* Pops up a new dialog */ +WSLUA_CLASS_DEFINE(ProgDlg,NOP,NOP); /* Manages a progress bar dialog. */ + +WSLUA_CONSTRUCTOR ProgDlg_new(lua_State* L) { /* Creates a new TextWindow. */ +#define WSLUA_OPTARG_ProgDlg_new_TITLE 2 /* Title of the new window, defaults to "Progress". */ +#define WSLUA_OPTARG_ProgDlg_new_TASK 3 /* Current task, defaults to "". */ + ProgDlg pd = g_malloc(sizeof(struct _wslua_progdlg)); + pd->title = g_strdup(luaL_optstring(L,WSLUA_OPTARG_ProgDlg_new_TITLE,"Progress")); + pd->task = g_strdup(luaL_optstring(L,WSLUA_OPTARG_ProgDlg_new_TASK,"")); + pd->stopped = FALSE; + + if (ops->new_progress_window) { + pd->pw = ops->new_progress_window(pd->title,pd->task,TRUE,&(pd->stopped)); + } + + pushProgDlg(L,pd); + + WSLUA_RETURN(1); /* The newly created TextWindow object. */ +} + +WSLUA_METHOD ProgDlg_update(lua_State* L) { /* Appends text */ +#define WSLUA_ARG_ProgDlg_update_PROGRESS 2 /* Part done ( e.g. 0.75 ). */ +#define WSLUA_OPTARG_ProgDlg_update_TASK 3 /* Current task, defaults to "". */ + ProgDlg pd = checkProgDlg(L,1); + double pr = lua_tonumber(L,WSLUA_ARG_ProgDlg_update_PROGRESS); + const gchar* task = luaL_optstring(L,WSLUA_OPTARG_ProgDlg_update_TASK,""); + + g_free(pd->task); + pd->task = g_strdup(task); + + if (!pd) { + WSLUA_ERROR(ProgDlg_update,"cannot be called for something not a ProgDlg"); + } + + if (pr >= 0.0 || pr <= 1.0) { + ops->update_progress(pd->pw, (float) pr, task); + } else { + WSLUA_ERROR(ProgDlg_update,"progress value out of range (0.0 <= pr <= 1.0)"); + } + + return 0; +} + +WSLUA_METHOD ProgDlg_stopped(lua_State* L) { /* Checks wheher the user has pressed the stop button. */ + ProgDlg pd = checkProgDlg(L,1); + + if (!pd) { + WSLUA_ERROR(ProgDlg_stopped,"cannot be called for something not a ProgDlg"); + } + + lua_pushboolean(L,pd->stopped); + + WSLUA_RETURN(1); /* true if the user has asked to stop the progress. */ +} + + + +WSLUA_METHOD ProgDlg_close(lua_State* L) { /* Appends text */ + ProgDlg pd = checkProgDlg(L,1); + + if (!pd) { + WSLUA_ERROR(ProgDlg_update,"cannot be called for something not a ProgDlg"); + } + + if (pd->pw) { + ops->destroy_progress_window(pd->pw); + pd->pw = NULL; + } + return 0; +} + + +static int ProgDlg__tostring(lua_State* L) { + ProgDlg pd = checkProgDlg(L,1); + + if (pd) { + lua_pushstring(L,ep_strdup_printf("%sstopped",pd->stopped?"":"not ")); + } else { + luaL_error(L, "ProgDlg__tostring has being passed something else!"); + } + + return 0; +} + +static int ProgDlg__gc(lua_State* L) { + ProgDlg pd = checkProgDlg(L,1); + + if (pd) { + if (pd->pw) ops->destroy_progress_window(pd->pw); + + g_free(pd); + } else { + luaL_error(L, "ProgDlg__gc has being passed something else!"); + } + + return 0; +} + + +WSLUA_METHODS ProgDlg_methods[] = { + {"new",ProgDlg_new}, + {"update",ProgDlg_update}, + {"stopped",ProgDlg_stopped}, + {"close",ProgDlg_close}, + {0, 0} +}; + +WSLUA_META ProgDlg_meta[] = { + {"__tostring", ProgDlg__tostring}, + {"__gc", ProgDlg__gc}, + {0, 0} +}; + +int ProgDlg_register(lua_State* L) { + + ops = funnel_get_funnel_ops(); + + WSLUA_REGISTER_CLASS(ProgDlg); + + return 1; +} + + + WSLUA_CLASS_DEFINE(TextWindow,NOP,NOP); /* Manages a text window. */ /* XXX: button and close callback data is being leaked */ diff --git a/gtk/funnel_stat.c b/gtk/funnel_stat.c index aad13364a1..b85063a2d2 100644 --- a/gtk/funnel_stat.c +++ b/gtk/funnel_stat.c @@ -52,6 +52,7 @@ #include "../globals.h" #include "../stat_menu.h" #include "../file.h" +#include "../progress_dlg.h" #include "gtk/gui_utils.h" #include "gtk/dlg_utils.h" @@ -227,7 +228,7 @@ static void text_window_append(funnel_text_window_t* tw, const char *str) int nchars = strlen(str); GtkTextBuffer *buf; GtkTextIter iter; - + if (! tw->win) return; txt = tw->txt; @@ -241,14 +242,13 @@ static void text_window_append(funnel_text_window_t* tw, const char *str) if (!g_utf8_validate(str, -1, NULL)) printf("Invalid utf8 encoding: %s\n", str); - + gtk_text_buffer_insert(buf, &iter, str, nchars); } static void text_window_set_text(funnel_text_window_t* tw, const gchar* text) { - if (! tw->win) return; text_window_clear(tw); @@ -523,6 +523,26 @@ static gboolean funnel_open_file(const char* fname, const char* filter, const ch return TRUE; } +typedef struct progdlg _funnel_progress_window_t; + +static funnel_progress_window_t* +funnel_new_progress_window(const gchar* label, const gchar* task, gboolean terminate_is_stop, gboolean *stop_flag) +{ + return (funnel_progress_window_t*)create_progress_dlg(label, task, terminate_is_stop, stop_flag); +} + +static void +funnel_update_progress(funnel_progress_window_t* win, float pr, const gchar* task) +{ + update_progress_dlg((progdlg_t*)win, pr, task); +} + +static void +funnel_destroy_progress_window(funnel_progress_window_t* win) +{ + destroy_progress_dlg((progdlg_t*)win); +} + static void funnel_reload(void) { if (cfile.state == FILE_READ_DONE) cf_reload(&cfile); } @@ -548,7 +568,10 @@ static const funnel_ops_t funnel_ops = { funnel_reload, funnel_apply_filter, browser_open_url, - browser_open_data_file + browser_open_data_file, + funnel_new_progress_window, + funnel_update_progress, + funnel_destroy_progress_window }; diff --git a/tap-funnel.c b/tap-funnel.c index 3d978e0c23..c06958b672 100644 --- a/tap-funnel.c +++ b/tap-funnel.c @@ -105,7 +105,10 @@ static const funnel_ops_t funnel_ops = { NULL, NULL, NULL, - NULL + NULL, + NULL, + NULL, + NULL }; -- cgit v1.2.3