further work on the yet to come welcome page ...
[obnox/wireshark/wip.git] / gtk / main_menu.c
index e6dcdb1ccc9fb33f53db2560857d948d23af622f..c770e9edd8e419e61da08eadf899ba92433d590c 100644 (file)
@@ -87,6 +87,7 @@
 #include "gtk/main_menu.h"
 #include "gtk/main_packet_list.h"
 #include "gtk/main_toolbar.h"
+#include "gtk/main_welcome.h"
 
 
 typedef struct _menu_item {
@@ -698,7 +699,7 @@ static GtkItemFactoryEntry menu_items[] =
                        firewall_rule_cb, 0, NULL, NULL,},
     {"/_Help", NULL, NULL, 0, "<Branch>", NULL,},
     {"/Help/_Contents", "F1", GTK_MENU_FUNC(topic_menu_cb), HELP_CONTENT, "<StockItem>", GTK_STOCK_HELP,},
-    {"/Help/_Supported Protocols", NULL, GTK_MENU_FUNC(supported_cb), 0, NULL, NULL,},
+    {"/Help/FAQ's", NULL, GTK_MENU_FUNC(topic_menu_cb), ONLINEPAGE_FAQ, NULL, NULL,},
     {"/Help/Manual Pages", NULL, NULL, 0, "<Branch>", NULL,},
     {"/Help/Manual Pages/Wireshark", NULL, GTK_MENU_FUNC(topic_menu_cb), LOCALPAGE_MAN_WIRESHARK, NULL, NULL,},
     {"/Help/Manual Pages/Wireshark Filter", NULL, GTK_MENU_FUNC(topic_menu_cb), LOCALPAGE_MAN_WIRESHARK_FILTER, NULL, NULL,},
@@ -709,13 +710,13 @@ static GtkItemFactoryEntry menu_items[] =
     {"/Help/Manual Pages/Mergecap", NULL, GTK_MENU_FUNC(topic_menu_cb), LOCALPAGE_MAN_MERGECAP, NULL, NULL,},
     {"/Help/Manual Pages/Editcap", NULL, GTK_MENU_FUNC(topic_menu_cb), LOCALPAGE_MAN_EDITCAP, NULL, NULL,},
     {"/Help/Manual Pages/Text2pcap", NULL, GTK_MENU_FUNC(topic_menu_cb), LOCALPAGE_MAN_TEXT2PCAP, NULL, NULL,},
-    {"/Help/Wireshark Online", NULL, NULL, 0, "<Branch>", NULL,},
-    {"/Help/Wireshark Online/Home Page", NULL, GTK_MENU_FUNC(topic_menu_cb), ONLINEPAGE_HOME, "<StockItem>", GTK_STOCK_HOME,},
-    {"/Help/Wireshark Online/Wiki", NULL, GTK_MENU_FUNC(topic_menu_cb), ONLINEPAGE_WIKI, "<StockItem>", WIRESHARK_STOCK_WIKI,},
-    {"/Help/Wireshark Online/User's Guide", NULL, GTK_MENU_FUNC(topic_menu_cb), ONLINEPAGE_USERGUIDE, "<StockItem>", WIRESHARK_STOCK_WEB_SUPPORT,},
-    {"/Help/Wireshark Online/FAQ's", NULL, GTK_MENU_FUNC(topic_menu_cb), ONLINEPAGE_FAQ, NULL, NULL,},
-    {"/Help/Wireshark Online/Downloads", NULL, GTK_MENU_FUNC(topic_menu_cb), ONLINEPAGE_DOWNLOAD, NULL, NULL,},
-    {"/Help/Wireshark Online/Example Files", NULL, GTK_MENU_FUNC(topic_menu_cb), ONLINEPAGE_SAMPLE_FILES, NULL, NULL,},
+    {"/Help/<separator>", NULL, NULL, 0, "<Separator>", NULL,},
+    {"/Help/Website", NULL, GTK_MENU_FUNC(topic_menu_cb), ONLINEPAGE_HOME, "<StockItem>", GTK_STOCK_HOME,},
+    {"/Help/Wiki", NULL, GTK_MENU_FUNC(topic_menu_cb), ONLINEPAGE_WIKI, "<StockItem>", WIRESHARK_STOCK_WIKI,},
+    {"/Help/Downloads", NULL, GTK_MENU_FUNC(topic_menu_cb), ONLINEPAGE_DOWNLOAD, NULL, NULL,},
+    {"/Help/Sample Captures", NULL, GTK_MENU_FUNC(topic_menu_cb), ONLINEPAGE_SAMPLE_FILES, NULL, NULL,},
+    {"/Help/<separator>", NULL, NULL, 0, "<Separator>", NULL,},
+    {"/Help/_Supported Protocols (slow!)", NULL, GTK_MENU_FUNC(supported_cb), 0, NULL, NULL,},
     {"/Help/<separator>", NULL, NULL, 0, "<Separator>", NULL,},
     {"/Help/_About Wireshark", NULL, GTK_MENU_FUNC(about_wireshark_cb),
                        0, "<StockItem>", WIRESHARK_STOCK_ABOUT}
@@ -1261,7 +1262,9 @@ register_stat_menu_item_stock(
     case(REGISTER_STAT_GROUP_NONE): toolspath = "/Statistics/"; break;
     case(REGISTER_ANALYZE_GROUP_NONE): toolspath = "/Analyze/"; break;
     case(REGISTER_ANALYZE_GROUP_CONVERSATION_FILTER): toolspath = "/Analyze/Conversation Filter/"; break;
+#ifdef HAVE_LUA_5_1
     case(REGISTER_TOOLS_GROUP_NONE): toolspath = "/Tools/"; break;
+#endif
     default:
         g_assert(!"no such menu group");
         toolspath = NULL;
@@ -1407,8 +1410,10 @@ static guint merge_tap_menus_layered(GList *node, gint group) {
                 break;
             case(REGISTER_ANALYZE_GROUP_CONVERSATION_FILTER):
                 break;
+#ifdef HAVE_LUA_5_1
             case(REGISTER_TOOLS_GROUP_NONE):
                 break;
+#endif
             default:
                 g_assert_not_reached();
             }
@@ -1490,9 +1495,11 @@ void merge_all_tap_menus(GList *node) {
         sep_entry->path = "/Analyze/Conversation Filter/";
         /*gtk_item_factory_create_item(main_menu_factory, sep_entry, NULL, 2);*/
     }
+#ifdef HAVE_LUA_5_1
     if (merge_tap_menus_layered(node, REGISTER_TOOLS_GROUP_NONE)) {
         /*gtk_item_factory_create_item(main_menu_factory, sep_entry, NULL, 2);*/
     }
+#endif
 }
 
 
@@ -1588,6 +1595,8 @@ set_menu_object_data (const gchar *path, const gchar *key, gpointer data) {
 #define MENU_RECENT_FILES_PATH "/File/Open Recent"
 #define MENU_RECENT_FILES_KEY "Recent File Name"
 
+
+
 static void
 update_menu_recent_capture_file1(GtkWidget *widget, gpointer cnt) {
     gchar *widget_cf_name;
@@ -1597,15 +1606,20 @@ update_menu_recent_capture_file1(GtkWidget *widget, gpointer cnt) {
     /* if this menu item is a file, count it */
     if (widget_cf_name) {
         (*(guint *)cnt)++;
+        main_welcome_add_recent_capture_files(widget_cf_name);
     }
 }
 
 
+
 /* update the menu */
 static void
 update_menu_recent_capture_file(GtkWidget *submenu_recent_files) {
     guint cnt = 0;
 
+
+    main_welcome_reset_recent_capture_files();
+
     gtk_container_foreach(GTK_CONTAINER(submenu_recent_files),
                update_menu_recent_capture_file1, &cnt);
 
@@ -1614,6 +1628,40 @@ update_menu_recent_capture_file(GtkWidget *submenu_recent_files) {
 }
 
 
+
+/* remove the capture filename from the "Recent Files" menu */
+static void
+remove_menu_recent_capture_filename(gchar *cf_name) {
+    GtkWidget *submenu_recent_files;
+    GList* child_list;
+    GList* child_list_item;
+       GtkWidget *menu_item_child;
+       gchar     *menu_item_cf_name;
+    
+
+    /* get the submenu container item */
+    submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
+
+    /* find the corresponding menu item to be removed */
+    child_list = gtk_container_get_children(GTK_CONTAINER(submenu_recent_files));
+    child_list_item = child_list;
+    while(child_list_item) {
+           menu_item_child = (GTK_BIN(child_list_item->data))->child;
+           gtk_label_get(GTK_LABEL(menu_item_child), &menu_item_cf_name);
+        if(strcmp(menu_item_cf_name, cf_name) == 0) {
+            /* XXX: is this all we need to do, to free the menu item and its label?
+               The reference count of widget will go to 0, so it'll be freed;
+               will that free the label? */
+            gtk_container_remove(GTK_CONTAINER(submenu_recent_files), child_list_item->data);
+        }
+        child_list_item = g_list_next(child_list_item);
+    }
+    g_list_free(child_list);
+
+    update_menu_recent_capture_file(submenu_recent_files);
+}
+
+
 /* remove the capture filename from the "Recent Files" menu */
 static void
 remove_menu_recent_capture_file(GtkWidget *widget, gpointer unused _U_) {
@@ -1634,7 +1682,7 @@ remove_menu_recent_capture_file(GtkWidget *widget, gpointer unused _U_) {
 }
 
 
-/* callback, if the user pushed the <Clear File List> item */
+/* callback, if the user pushed the <Clear> menu item */
 static void
 clear_menu_recent_capture_file_cmd_cb(GtkWidget *w _U_, gpointer unused _U_) {
     GtkWidget *submenu_recent_files;
@@ -1649,6 +1697,29 @@ clear_menu_recent_capture_file_cmd_cb(GtkWidget *w _U_, gpointer unused _U_) {
 }
 
 
+/* Open a file by it's name
+   (Beware: will not ask to close existing capture file!) */
+void
+menu_open_filename(gchar *cf_name)
+{
+       GtkWidget *submenu_recent_files;
+       int       err;
+
+       submenu_recent_files = gtk_item_factory_get_widget(main_menu_factory, MENU_RECENT_FILES_PATH);
+
+       /* open and read the capture file (this will close an existing file) */
+       if (cf_open(&cfile, cf_name, FALSE, &err) == CF_OK) {
+               cf_read(&cfile);
+       } else {
+               /* the capture file isn't existing any longer, remove menu item */
+               /* XXX: ask user to remove item, it's maybe only a temporary problem */
+               remove_menu_recent_capture_filename(cf_name);
+       }
+
+       update_menu_recent_capture_file(submenu_recent_files);
+}
+
+
 /* callback, if the user pushed a recent file submenu item */
 void
 menu_open_recent_file_cmd(GtkWidget *w)
@@ -1676,7 +1747,7 @@ menu_open_recent_file_cmd(GtkWidget *w)
        update_menu_recent_capture_file(submenu_recent_files);
 }
 
-static void menu_open_recent_file_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
+static void menu_open_recent_file_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
 {
     switch(btn) {
     case(ESD_BTN_YES):