* rename REGISTER_STAT_GROUP_E -> register_stat_group_t
authorLuis Ontanon <luis.ontanon@gmail.com>
Wed, 27 Sep 2006 17:12:42 +0000 (17:12 -0000)
committerLuis Ontanon <luis.ontanon@gmail.com>
Wed, 27 Sep 2006 17:12:42 +0000 (17:12 -0000)
* Add a "Tools" menu
* allow wslua's register_menu to register menu items into more menus

svn path=/trunk/; revision=19338

12 files changed:
epan/funnel.c
epan/funnel.h
epan/wslua/make-init-lua.pl
epan/wslua/template-init.lua
epan/wslua/wslua_gui.c
gtk/funnel_stat.c
gtk/gui_stat_menu.h
gtk/menu.c
gtk/tap_dfilter_dlg.c
stat_menu.h
tap-funnel.c
tap_dfilter_dlg.h

index 185fe3dc20b635445e29b0b0ac8749dee1aeb0bc..17ec6387ae2d64c55f027955d021a1785976d80d 100644 (file)
@@ -30,7 +30,7 @@
 
 typedef struct _funnel_menu_t {
     const char *name;
-    REGISTER_STAT_GROUP_E group;
+    register_stat_group_t group;
     void (*callback)(gpointer);
     gpointer callback_data;
     gboolean retap;
@@ -44,7 +44,7 @@ const funnel_ops_t* funnel_get_funnel_ops() { return ops;  }
 void funnel_set_funnel_ops(const funnel_ops_t* o) { ops = o; }
 
 void funnel_register_menu(const char *name,
-                          REGISTER_STAT_GROUP_E group,
+                          register_stat_group_t group,
                           void (*callback)(gpointer),
                           gpointer callback_data,
                           gboolean retap) {
index 16508af1249879924859f58a6c21ef1d839b5d8d..3cd7eb22ea7f93c21dda8d2794f8f4c9b70b8d00 100644 (file)
@@ -91,14 +91,14 @@ extern void funnel_set_funnel_ops(const funnel_ops_t*);
 
 
 extern void funnel_register_menu(const char *name,
-                                 REGISTER_STAT_GROUP_E group,
+                                 register_stat_group_t group,
                                  void (*callback)(gpointer),
                                  gpointer callback_data,
                                  gboolean retap);
 
 
 typedef void (*funnel_registration_cb_t)(const char *name,
-                                         REGISTER_STAT_GROUP_E group,
+                                         register_stat_group_t group,
                                          void (*callback)(gpointer),
                                          gpointer callback_data,
                                          gboolean retap);
index 23fbe3601b4b51db4a22834ffe71359b69fbf5ed..06dd7d41909ffe42913886a76261a19b951e4cfb 100755 (executable)
@@ -34,12 +34,14 @@ my $wtap_encaps_table = '';
 my $ft_types_table = '';
 my $bases_table = '';
 my $expert_pi = '';
+my $menu_groups = '';
 
 my %replacements = %{{
     WTAP_ENCAPS => \$wtap_encaps_table,
     FT_TYPES => \$ft_types_table,
        BASES => \$bases_table,
        EXPERT => \$expert_pi,
+       MENU_GROUPS => \$menu_groups,
 }};
 
 
@@ -110,6 +112,23 @@ while(<PROTO_H>) {
 }
 close PROTO_H;
 
+# register_stat_group_t
+
+
+$menu_groups .= "-- menu groups for register_menu \n";
+my $menu_i = 0;
+
+open STAT_MENU, "< $WSROOT/stat_menu.h";
+while(<STAT_MENU>) {
+       if (/REGISTER_([A-Z]+)_GROUP_([A-Z]+)/) {
+               $menu_groups .= "MENU_$1_$2 = $menu_i\n";
+               $menu_groups =~ s/_NONE//;
+               $menu_i++;
+       }
+}
+close STAT_MENU;
+
+
 $bases_table .= "}\n\n";
 $expert_pi .= "\n\n";
 
index 76d8c765437b97f7615707b8dbd973983e5d4b96..0541f741483af3067a11d1150a409bacfaa98a44 100644 (file)
@@ -51,8 +51,17 @@ end
 -- have print() call info() instead.
 print = info
 
+-- %WTAP_ENCAPS%
+
+-- %FT_TYPES%
+
+-- %BASES%
 
--- a Console to execute commands in lua
+-- %EXPERT%
+
+-- %MENU_GROUPS%
+
+-- Console to execute commands in lua
 function wslua_console()
        local w = TextWindow.new("Lua Console")
        w:set_editable(TRUE)
@@ -73,14 +82,5 @@ function wslua_console()
    w:add_button("Evaluate",eval)
 end
 
-register_menu("Lua Console",wslua_console)
-
-
--- %WTAP_ENCAPS%
-
--- %FT_TYPES%
-
--- %BASES%
-
--- %EXPERT%
+register_menu("Lua Console",wslua_console,MENU_TOOLS)
 
index 9c7c56391325db68f54fa69438025539f49dd6ee..bd174041b8b7d27dd4ccfb5746dc34a97d608a5b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  lua_gui.c
+ *  wslua_gui.c
  *  
  * (c) 2006, Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
  * 
@@ -31,7 +31,6 @@ static const funnel_ops_t* ops = NULL;
 struct _lua_menu_data {
     lua_State* L;
     int cb_ref;
-    int data_ref;
 };
 
 static int menu_cb_error_handler(lua_State* L) {
@@ -50,9 +49,9 @@ void lua_menu_callback(gpointer data) {
 
     lua_pushcfunction(md->L,menu_cb_error_handler);
     lua_rawgeti(md->L, LUA_REGISTRYINDEX, md->cb_ref);
-    lua_rawgeti(md->L, LUA_REGISTRYINDEX, md->data_ref);
-        
-    lua_pcall(md->L,1,0,1);
+       
+       /* XXX handle error */
+    lua_pcall(md->L,0,0,1);
     
     return;
 }
@@ -60,33 +59,31 @@ void lua_menu_callback(gpointer data) {
 WSLUA_FUNCTION wslua_register_menu(lua_State* L) { /*  Register a menu item in the Statistics menu. */
 #define WSLUA_ARG_register_menu_NAME 1 /* The name of the menu item. */
 #define WSLUA_ARG_register_menu_ACTION 2 /* The function to be called when the menu item is invoked. */
-#define WSLUA_OPTARG_register_menu_USERDATA 3 /* To be passed to the action. */
-       
+#define WSLUA_ARG_register_menu_GROUP 3 /* The menu group into which the menu item is to be inserted. */
+
     const gchar* name = luaL_checkstring(L,WSLUA_ARG_register_menu_NAME);
     struct _lua_menu_data* md;
     gboolean retap = FALSE;
-    
+       register_stat_group_t group = luaL_optnumber(L,WSLUA_ARG_register_menu_GROUP,REGISTER_STAT_GROUP_GENERIC);
+
+       if ( group > REGISTER_TOOLS_GROUP_NONE)
+               WSLUA_ARG_ERROR(register_menu,GROUP,"must be a defined MENU_* (see init.lua)");
+
        if(!name)
                WSLUA_ARG_ERROR(register_menu,NAME,"must be a string");
        
     if (!lua_isfunction(L,WSLUA_ARG_register_menu_ACTION)) 
                WSLUA_ARG_ERROR(register_menu,ACTION,"must be a function");
-    
+
     md = g_malloc(sizeof(struct _lua_menu_data));
     md->L = L;
-    
-    lua_pushvalue(L, 2);
-    md->cb_ref = luaL_ref(L, LUA_REGISTRYINDEX);
-    
-    if ( lua_gettop(L) > 2) {
-        lua_pushvalue(L, WSLUA_OPTARG_register_menu_USERDATA);
-        md->data_ref = luaL_ref(L, LUA_REGISTRYINDEX);
-    } else {
-        md->data_ref = LUA_NOREF;
-    }
+
+       lua_pushvalue(L, 2);
+       md->cb_ref = luaL_ref(L, LUA_REGISTRYINDEX);
+       lua_remove(L,2);
 
     funnel_register_menu(name,
-                         REGISTER_STAT_GROUP_GENERIC,
+                         group,
                          lua_menu_callback,
                          md,
                          retap);
index 77d13d711cf46243645b4f98853fb56297e00a59..506a549cd9eb41f2e890427a27cf65384bc99731 100644 (file)
@@ -544,7 +544,7 @@ static void our_menu_callback(void* unused _U_, gpointer data) {
 }
 
 static void register_menu_cb(const char *name,
-                             REGISTER_STAT_GROUP_E group,
+                             register_stat_group_t group,
                              void (*callback)(gpointer),
                              gpointer callback_data,
                              gboolean retap) {
index 595ed1348e1f65a4a4df4acd86af807fe459a3f2..40124c1d4952838e8688ae5c60595eb2cc3b5564 100644 (file)
@@ -63,7 +63,7 @@ extern "C" {
  */    
 extern void register_stat_menu_item(
     const char *name, 
-    REGISTER_STAT_GROUP_E group,
+    register_stat_group_t group,
     GtkItemFactoryCallback callback,
     gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *),
     gboolean (*selected_tree_row_enabled)(field_info *),
index fe9e5b2473e0c5316ec0b1c37527a56e6772efd3..3a821059062c4206b6700d7bc51395f7adf30791 100644 (file)
@@ -598,7 +598,8 @@ static GtkItemFactoryEntry menu_items[] =
                        init_conversation_notebook_cb, 0, WIRESHARK_STOCK_CONVERSATIONS),
     ITEM_FACTORY_STOCK_ENTRY("/Statistics/Endpoints", NULL,
                        init_hostlist_notebook_cb, 0, WIRESHARK_STOCK_ENDPOINTS),
-    ITEM_FACTORY_ENTRY("/_Help", NULL, NULL, 0, "<Branch>", NULL),
+    ITEM_FACTORY_ENTRY("/_Tools", NULL, NULL, 0, "<Branch>", NULL),
+   ITEM_FACTORY_ENTRY("/_Help", NULL, NULL, 0, "<Branch>", NULL),
     ITEM_FACTORY_STOCK_ENTRY("/Help/_Contents", "F1", topic_menu_cb, HELP_CONTENT, GTK_STOCK_HELP),
     ITEM_FACTORY_ENTRY("/Help/_Supported Protocols", NULL, supported_cb, 0, NULL, NULL),
 #if (GLIB_MAJOR_VERSION >= 2)
@@ -914,7 +915,7 @@ static GList * tap_menu_item_add(
 void
 register_stat_menu_item(
     const char *name,
-    REGISTER_STAT_GROUP_E group,
+    register_stat_group_t group,
     GtkItemFactoryCallback callback,
     gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *),
     gboolean (*selected_tree_row_enabled)(field_info *),
@@ -942,6 +943,7 @@ register_stat_menu_item(
     case(REGISTER_STAT_GROUP_TELEPHONY): toolspath = "/Statistics/"; break;
     case(REGISTER_STAT_GROUP_NONE): toolspath = "/Statistics/"; break;
     case(REGISTER_ANALYZE_GROUP_NONE): toolspath = "/Analyze/"; break;
+    case(REGISTER_TOOLS_GROUP_NONE): toolspath = "/Tools/"; break;
     default:
         g_assert(0);
         toolspath = NULL;
@@ -1067,6 +1069,8 @@ static guint merge_tap_menus_layered(GList *node, gint group) {
                 break;
             case(REGISTER_ANALYZE_GROUP_NONE):
                 break;
+            case(REGISTER_TOOLS_GROUP_NONE):
+                break;
             default:
                 g_assert_not_reached();
             }
@@ -1139,6 +1143,11 @@ void merge_all_tap_menus(GList *node) {
                entry->path = "/Analyze/";
         /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/
     }
+    if (merge_tap_menus_layered(node, REGISTER_TOOLS_GROUP_NONE)) {
+        /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/
+    }
+       
+
 }
 
 
index c94ff0a0ae1900dc6eef6736954a11909d674742..b6e32505a69a11f152e3550f66bda4c5d826b8cf 100644 (file)
@@ -71,7 +71,7 @@ tap_dfilter_dlg_cb(GtkWidget *w, gpointer data);
  */
 void
 register_dfilter_stat(tap_dfilter_dlg *info, const char *name,
-    REGISTER_STAT_GROUP_E group)
+    register_stat_group_t group)
 {
        char *full_name;
 
index ec3e6cda36ec299b117294140e8dba40a5e55777..1d9d0aab7963ce6beaf050328b04e26f34c8f79d 100644 (file)
@@ -50,8 +50,9 @@ typedef enum {
     REGISTER_STAT_GROUP_RESPONSE_TIME,
     REGISTER_STAT_GROUP_TELEPHONY,
     /* XXX - split into telephony and VoIP? */
-       REGISTER_ANALYZE_GROUP_NONE
-} REGISTER_STAT_GROUP_E;
+       REGISTER_ANALYZE_GROUP_NONE,
+       REGISTER_TOOLS_GROUP_NONE,
+} register_stat_group_t;
 
 #ifdef __cplusplus
 }
index 490a558a22965f7cee30a1eacacc752537e3517f..10711afc0c27d57aa22cba022683849361bd92f0 100644 (file)
@@ -1,6 +1,29 @@
 /*
  *  tap-funnel.c
- *  
+ *
+ * EPAN's GUI mini-API
+ *
+ * (c) 2006, Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
  */
 
 
@@ -126,7 +149,7 @@ static void  init_funnel_cmd(const char *optarg, void* data ) {
 }
 
 static void register_menu_cb(const char *name,
-                             REGISTER_STAT_GROUP_E group _U_,
+                             register_stat_group_t group _U_,
                              void (*callback)(gpointer),
                              gpointer callback_data,
                              gboolean retap _U_) {
index 18a75e982a624eba1bb2692e6e605f7134eb4f79..43fe396aadfdbd72bac419a4ae4dade8b0f816de 100644 (file)
@@ -67,7 +67,7 @@ typedef struct _tap_dfilter_dlg {
  * We register it both as a command-line stat and a menu item stat.
  */
 void register_dfilter_stat(tap_dfilter_dlg *info, const char *name,
-    REGISTER_STAT_GROUP_E group);
+    register_stat_group_t group);
 
 /* This will update the titles of the dialog windows when we load a new capture file. */
 void tap_dfilter_dlg_update (void);