forked from osmocom/wireshark
PluginIF: Parent menu and goto frame
The developer may provide a given menu as parent menu for the sub menu. If the menu does not exist, the main menu will be used. Has been implemented for Qt as well as GTK. Change-Id: I3f26684862fd0b08f59eeb4d6f4a24ce7dc3d428 Reviewed-on: https://code.wireshark.org/review/9939 Reviewed-by: Roland Knall <rknall@gmail.com> Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com> Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
This commit is contained in:
parent
28128ca41c
commit
6f1c9fd432
|
@ -66,6 +66,8 @@ extern ext_menu_t * ext_menubar_register_menu(int proto_id, const gchar * menula
|
||||||
entry->proto = proto_id;
|
entry->proto = proto_id;
|
||||||
entry->is_plugin = is_plugin;
|
entry->is_plugin = is_plugin;
|
||||||
|
|
||||||
|
entry->parent_menu = 0;
|
||||||
|
|
||||||
/* Create a name for this submenu */
|
/* Create a name for this submenu */
|
||||||
entry->name = name;
|
entry->name = name;
|
||||||
entry->label = g_strdup(menulabel);
|
entry->label = g_strdup(menulabel);
|
||||||
|
@ -80,6 +82,17 @@ extern ext_menu_t * ext_menubar_register_menu(int proto_id, const gchar * menula
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern ext_menu_t * ext_menubar_set_parentmenu(ext_menu_t * menu, const gchar * parentmenu)
|
||||||
|
{
|
||||||
|
g_assert(menu != NULL && menu->parent == NULL);
|
||||||
|
|
||||||
|
g_assert(parentmenu != 0);
|
||||||
|
|
||||||
|
menu->parent_menu = g_strdup(parentmenu);
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
extern ext_menu_t * ext_menubar_add_submenu(ext_menu_t * parent, const gchar *menulabel)
|
extern ext_menu_t * ext_menubar_add_submenu(ext_menu_t * parent, const gchar *menulabel)
|
||||||
{
|
{
|
||||||
ext_menubar_t * entry = NULL;
|
ext_menubar_t * entry = NULL;
|
||||||
|
@ -212,6 +225,17 @@ extern void plugin_if_apply_filter(const char * filter_string, gboolean force)
|
||||||
plugin_if_call_gui_cb(actionType, dataSet);
|
plugin_if_call_gui_cb(actionType, dataSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern void plugin_if_goto_frame(guint32 framenr)
|
||||||
|
{
|
||||||
|
GHashTable * dataSet = NULL;
|
||||||
|
|
||||||
|
dataSet = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
|
|
||||||
|
g_hash_table_insert( dataSet, g_strdup("frame_nr"), GUINT_TO_POINTER(framenr) );
|
||||||
|
|
||||||
|
plugin_if_call_gui_cb(PLUGIN_IF_GOTO_FRAME, dataSet);
|
||||||
|
}
|
||||||
|
|
||||||
extern void plugin_if_save_preference(const char * pref_module, const char * pref_key, const char * pref_value)
|
extern void plugin_if_save_preference(const char * pref_module, const char * pref_key, const char * pref_value)
|
||||||
{
|
{
|
||||||
GHashTable * dataSet = NULL;
|
GHashTable * dataSet = NULL;
|
||||||
|
|
|
@ -81,7 +81,7 @@ struct _ext_menubar_t
|
||||||
|
|
||||||
ext_menubar_action_cb callback;
|
ext_menubar_action_cb callback;
|
||||||
|
|
||||||
|
gchar * parent_menu;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Registers a new main menu.
|
/* Registers a new main menu.
|
||||||
|
@ -97,6 +97,18 @@ struct _ext_menubar_t
|
||||||
WS_DLL_PUBLIC ext_menu_t * ext_menubar_register_menu(
|
WS_DLL_PUBLIC ext_menu_t * ext_menubar_register_menu(
|
||||||
int proto_id, const gchar * menulabel, gboolean is_plugin);
|
int proto_id, const gchar * menulabel, gboolean is_plugin);
|
||||||
|
|
||||||
|
/* Sets a parent menu for the user menu.
|
||||||
|
*
|
||||||
|
* This will set a parent menu, which allows this menu to be filtered underneath
|
||||||
|
* the given menu as a submenu. If the parent menu does not exist, the main menu
|
||||||
|
* will be used
|
||||||
|
*
|
||||||
|
* @param menu the menu for which to add the entry
|
||||||
|
* @param parentmenu a valid menu name for the parent menu
|
||||||
|
*/
|
||||||
|
WS_DLL_PUBLIC ext_menu_t * ext_menubar_set_parentmenu(
|
||||||
|
ext_menu_t * menu, const gchar * parentmenu);
|
||||||
|
|
||||||
/* Registers a new main menu.
|
/* Registers a new main menu.
|
||||||
*
|
*
|
||||||
* This will register a new sub menu entry, underneath the parent menu
|
* This will register a new sub menu entry, underneath the parent menu
|
||||||
|
@ -162,7 +174,10 @@ typedef enum
|
||||||
PLUGIN_IF_FILTER_ACTION_PREPARE,
|
PLUGIN_IF_FILTER_ACTION_PREPARE,
|
||||||
|
|
||||||
/* Saves a preference entry */
|
/* Saves a preference entry */
|
||||||
PLUGIN_IF_PREFERENCE_SAVE
|
PLUGIN_IF_PREFERENCE_SAVE,
|
||||||
|
|
||||||
|
/* Jumps to the provided frame number */
|
||||||
|
PLUGIN_IF_GOTO_FRAME
|
||||||
} plugin_if_callback_t;
|
} plugin_if_callback_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -176,6 +191,10 @@ WS_DLL_PUBLIC void plugin_if_apply_filter(const char * filter_string, gboolean f
|
||||||
/* Saves the given preference to the main preference storage */
|
/* Saves the given preference to the main preference storage */
|
||||||
WS_DLL_PUBLIC void plugin_if_save_preference(const char * pref_module, const char * pref_key, const char * pref_value);
|
WS_DLL_PUBLIC void plugin_if_save_preference(const char * pref_module, const char * pref_key, const char * pref_value);
|
||||||
|
|
||||||
|
/* Jumps to the given frame number */
|
||||||
|
WS_DLL_PUBLIC void plugin_if_goto_frame(guint32 framenr);
|
||||||
|
|
||||||
|
|
||||||
/* Private Method for retrieving the menubar entries
|
/* Private Method for retrieving the menubar entries
|
||||||
*
|
*
|
||||||
* Is only to be used by the UI interfaces to retrieve the menu entries
|
* Is only to be used by the UI interfaces to retrieve the menu entries
|
||||||
|
|
|
@ -55,6 +55,8 @@
|
||||||
#include "ui/gtk/packet_list.h"
|
#include "ui/gtk/packet_list.h"
|
||||||
#include "ui/capture_globals.h"
|
#include "ui/capture_globals.h"
|
||||||
|
|
||||||
|
#include <epan/plugin_if.h>
|
||||||
|
|
||||||
#include "ui/gtk/old-gtk-compat.h"
|
#include "ui/gtk/old-gtk-compat.h"
|
||||||
|
|
||||||
static gboolean toolbar_init = FALSE;
|
static gboolean toolbar_init = FALSE;
|
||||||
|
@ -263,6 +265,19 @@ toolbar_auto_scroll_live_changed(gboolean auto_scroll_live_lcl) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void plugin_if_maintoolbar_goto_frame(gconstpointer user_data)
|
||||||
|
{
|
||||||
|
if ( user_data != NULL )
|
||||||
|
{
|
||||||
|
GHashTable * dataSet = (GHashTable *) user_data;
|
||||||
|
gpointer framenr;
|
||||||
|
if ( g_hash_table_lookup_extended(dataSet, "frame_nr", NULL, &framenr ) )
|
||||||
|
{
|
||||||
|
if ( GPOINTER_TO_UINT(framenr) != 0 )
|
||||||
|
cf_goto_frame(&cfile, GPOINTER_TO_UINT(framenr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create all toolbars (currently only the main toolbar)
|
* Create all toolbars (currently only the main toolbar)
|
||||||
|
@ -398,6 +413,8 @@ toolbar_new(void)
|
||||||
/* make current preferences effective */
|
/* make current preferences effective */
|
||||||
toolbar_redraw_all();
|
toolbar_redraw_all();
|
||||||
|
|
||||||
|
plugin_if_register_gui_cb(PLUGIN_IF_GOTO_FRAME, plugin_if_maintoolbar_goto_frame);
|
||||||
|
|
||||||
return main_tb;
|
return main_tb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,21 @@ static void plugin_if_mainwindow_preference(gconstpointer user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void plugin_if_mainwindow_gotoframe(gconstpointer user_data)
|
||||||
|
{
|
||||||
|
if ( gbl_cur_main_window_ != NULL && user_data != NULL )
|
||||||
|
{
|
||||||
|
GHashTable * dataSet = (GHashTable *) user_data;
|
||||||
|
gpointer framenr;
|
||||||
|
|
||||||
|
if ( g_hash_table_lookup_extended(dataSet, "frame_nr", NULL, &framenr ) )
|
||||||
|
{
|
||||||
|
if ( GPOINTER_TO_UINT(framenr) != 0 )
|
||||||
|
gbl_cur_main_window_->gotoFrame(GPOINTER_TO_UINT(framenr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gpointer
|
gpointer
|
||||||
simple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, ...)
|
simple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, ...)
|
||||||
{
|
{
|
||||||
|
@ -568,6 +583,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
plugin_if_register_gui_cb(PLUGIN_IF_FILTER_ACTION_APPLY, plugin_if_mainwindow_apply_filter );
|
plugin_if_register_gui_cb(PLUGIN_IF_FILTER_ACTION_APPLY, plugin_if_mainwindow_apply_filter );
|
||||||
plugin_if_register_gui_cb(PLUGIN_IF_FILTER_ACTION_PREPARE, plugin_if_mainwindow_apply_filter );
|
plugin_if_register_gui_cb(PLUGIN_IF_FILTER_ACTION_PREPARE, plugin_if_mainwindow_apply_filter );
|
||||||
plugin_if_register_gui_cb(PLUGIN_IF_PREFERENCE_SAVE, plugin_if_mainwindow_preference);
|
plugin_if_register_gui_cb(PLUGIN_IF_PREFERENCE_SAVE, plugin_if_mainwindow_preference);
|
||||||
|
plugin_if_register_gui_cb(PLUGIN_IF_GOTO_FRAME, plugin_if_mainwindow_gotoframe);
|
||||||
|
|
||||||
main_ui_->mainStack->setCurrentWidget(main_welcome_);
|
main_ui_->mainStack->setCurrentWidget(main_welcome_);
|
||||||
}
|
}
|
||||||
|
@ -2203,6 +2219,25 @@ void MainWindow::externalMenuHelper(ext_menu_t * menu, QMenu * subMenu, gint de
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMenu * MainWindow::searchSubMenu(QString objectName)
|
||||||
|
{
|
||||||
|
QList<QMenu*> lst;
|
||||||
|
|
||||||
|
if ( objectName.length() > 0 )
|
||||||
|
{
|
||||||
|
QString searchName = QString("menu") + objectName;
|
||||||
|
|
||||||
|
lst = main_ui_->menuBar->findChildren<QMenu*>();
|
||||||
|
foreach (QMenu* m, lst)
|
||||||
|
{
|
||||||
|
if ( QString::compare( m->objectName(), searchName ) == 0 )
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::addExternalMenus()
|
void MainWindow::addExternalMenus()
|
||||||
{
|
{
|
||||||
QMenu * subMenu = NULL;
|
QMenu * subMenu = NULL;
|
||||||
|
@ -2224,7 +2259,15 @@ void MainWindow::addExternalMenus()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create main submenu and add it to the menubar */
|
/* Create main submenu and add it to the menubar */
|
||||||
subMenu = main_ui_->menuBar->addMenu(menu->label);
|
if ( menu->parent_menu != NULL )
|
||||||
|
{
|
||||||
|
QMenu * sortUnderneath = searchSubMenu(QString(menu->parent_menu));
|
||||||
|
if ( sortUnderneath != NULL)
|
||||||
|
subMenu = sortUnderneath->addMenu(menu->label);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( subMenu == NULL )
|
||||||
|
subMenu = main_ui_->menuBar->addMenu(menu->label);
|
||||||
|
|
||||||
/* This will generate the action structure for each menu. It is recursive,
|
/* This will generate the action structure for each menu. It is recursive,
|
||||||
* therefore a sub-routine, and we have a depth counter to prevent endless loops. */
|
* therefore a sub-routine, and we have a depth counter to prevent endless loops. */
|
||||||
|
|
|
@ -90,6 +90,8 @@ public:
|
||||||
|
|
||||||
virtual QMenu *createPopupMenu();
|
virtual QMenu *createPopupMenu();
|
||||||
|
|
||||||
|
void gotoFrame(int packet_num);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *obj, QEvent *event);
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
|
@ -273,6 +275,7 @@ private slots:
|
||||||
void addDynamicMenus();
|
void addDynamicMenus();
|
||||||
void reloadDynamicMenus();
|
void reloadDynamicMenus();
|
||||||
void addExternalMenus();
|
void addExternalMenus();
|
||||||
|
QMenu * searchSubMenu(QString objectName);
|
||||||
|
|
||||||
void startInterfaceCapture(bool valid);
|
void startInterfaceCapture(bool valid);
|
||||||
|
|
||||||
|
|
|
@ -3185,11 +3185,8 @@ void MainWindow::on_goToCancel_clicked()
|
||||||
|
|
||||||
void MainWindow::on_goToGo_clicked()
|
void MainWindow::on_goToGo_clicked()
|
||||||
{
|
{
|
||||||
int packet_num = main_ui_->goToLineEdit->text().toInt();
|
gotoFrame(main_ui_->goToLineEdit->text().toInt());
|
||||||
|
|
||||||
if (packet_num > 0) {
|
|
||||||
packet_list_->goToPacket(packet_num);
|
|
||||||
}
|
|
||||||
on_goToCancel_clicked();
|
on_goToCancel_clicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3343,6 +3340,14 @@ void MainWindow::externalMenuItem_triggered()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::gotoFrame(int packet_num)
|
||||||
|
{
|
||||||
|
if ( packet_num > 0 )
|
||||||
|
{
|
||||||
|
packet_list_->goToPacket(packet_num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_EXTCAP
|
#ifdef HAVE_EXTCAP
|
||||||
void MainWindow::extcap_options_finished(int result)
|
void MainWindow::extcap_options_finished(int result)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue