2012-01-04 22:13:01 +00:00
|
|
|
/* main_window.cpp
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2012-01-04 22:13:01 +00:00
|
|
|
*/
|
|
|
|
|
2022-02-10 23:11:43 +00:00
|
|
|
#include "config.h"
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2022-02-10 23:11:43 +00:00
|
|
|
#include <glib.h>
|
2016-06-28 01:40:09 +00:00
|
|
|
|
2015-06-05 09:19:37 +00:00
|
|
|
#include "ui/preference_utils.h"
|
2012-01-14 00:16:16 +00:00
|
|
|
|
2022-02-10 23:11:43 +00:00
|
|
|
#include "main_window.h"
|
2017-01-24 16:34:07 +00:00
|
|
|
|
2020-12-27 04:15:24 +00:00
|
|
|
#include "funnel_statistics.h"
|
2022-02-10 23:11:43 +00:00
|
|
|
#include "packet_list.h"
|
|
|
|
#include "widgets/display_filter_combo.h"
|
2015-01-06 09:22:48 +00:00
|
|
|
|
2020-12-27 04:15:24 +00:00
|
|
|
// Packet Menu actions
|
|
|
|
static QList<QAction *> dynamic_packet_menu_actions;
|
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
2022-02-10 23:11:43 +00:00
|
|
|
main_stack_(nullptr),
|
|
|
|
welcome_page_(nullptr),
|
2015-02-06 18:36:27 +00:00
|
|
|
cur_layout_(QVector<unsigned>()),
|
2022-02-10 23:11:43 +00:00
|
|
|
packet_list_(nullptr),
|
|
|
|
proto_tree_(nullptr),
|
|
|
|
byte_view_tab_(nullptr),
|
|
|
|
packet_diagram_(nullptr),
|
|
|
|
df_combo_box_(nullptr),
|
|
|
|
main_status_bar_(nullptr)
|
2012-01-04 22:13:01 +00:00
|
|
|
{
|
|
|
|
|
2013-09-09 19:30:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 04:15:24 +00:00
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
clearAddedPacketMenus();
|
|
|
|
}
|
|
|
|
|
2022-02-10 23:11:43 +00:00
|
|
|
bool MainWindow::hasSelection()
|
2015-06-17 03:51:44 +00:00
|
|
|
{
|
2022-02-10 23:11:43 +00:00
|
|
|
if (packet_list_)
|
|
|
|
return packet_list_->multiSelectActive();
|
|
|
|
return false;
|
2015-06-17 03:51:44 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 23:11:43 +00:00
|
|
|
QList<int> MainWindow::selectedRows(bool useFrameNum)
|
2017-04-15 21:30:30 +00:00
|
|
|
{
|
2022-02-10 23:11:43 +00:00
|
|
|
if (packet_list_)
|
|
|
|
return packet_list_->selectedRows(useFrameNum);
|
|
|
|
return QList<int>();
|
2017-04-15 21:30:30 +00:00
|
|
|
}
|
|
|
|
|
2022-11-01 10:01:35 +00:00
|
|
|
frame_data* MainWindow::frameDataForRow(int row) const
|
|
|
|
{
|
|
|
|
if (packet_list_)
|
|
|
|
return packet_list_->getFDataForRow(row);
|
|
|
|
|
|
|
|
return Q_NULLPTR;
|
|
|
|
}
|
|
|
|
|
2022-02-10 23:11:43 +00:00
|
|
|
void MainWindow::insertColumn(QString name, QString abbrev, gint pos)
|
2017-04-15 21:30:30 +00:00
|
|
|
{
|
2022-02-10 23:11:43 +00:00
|
|
|
gint colnr = 0;
|
|
|
|
if (name.length() > 0 && abbrev.length() > 0)
|
|
|
|
{
|
|
|
|
colnr = column_prefs_add_custom(COL_CUSTOM, name.toStdString().c_str(), abbrev.toStdString().c_str(), pos);
|
|
|
|
packet_list_->columnsChanged();
|
|
|
|
packet_list_->resizeColumnToContents(colnr);
|
|
|
|
prefs_main_write();
|
2017-04-15 21:30:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-10 23:11:43 +00:00
|
|
|
void MainWindow::gotoFrame(int packet_num)
|
2012-08-31 22:25:51 +00:00
|
|
|
{
|
2022-02-10 23:11:43 +00:00
|
|
|
if (packet_num > 0) {
|
|
|
|
packet_list_->goToPacket(packet_num);
|
2012-08-31 22:25:51 +00:00
|
|
|
}
|
2012-08-23 02:59:31 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 23:11:43 +00:00
|
|
|
QString MainWindow::getFilter()
|
2019-06-13 17:25:19 +00:00
|
|
|
{
|
2022-02-10 23:11:43 +00:00
|
|
|
return df_combo_box_->currentText();
|
2013-10-30 22:39:52 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 23:11:43 +00:00
|
|
|
MainStatusBar *MainWindow::statusBar()
|
2015-06-14 18:04:51 +00:00
|
|
|
{
|
2022-02-10 23:11:43 +00:00
|
|
|
return main_status_bar_;
|
2015-06-14 18:04:51 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 23:11:43 +00:00
|
|
|
void MainWindow::setDisplayFilter(QString filter, FilterAction::Action action, FilterAction::ActionType filterType)
|
2015-06-14 18:04:51 +00:00
|
|
|
{
|
2022-02-10 23:11:43 +00:00
|
|
|
emit filterAction(filter, action, filterType);
|
2015-06-14 18:04:51 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 04:15:24 +00:00
|
|
|
/*
|
|
|
|
* Used for registering custom packet menus
|
|
|
|
*
|
|
|
|
* @param funnel_action a custom packet menu action
|
|
|
|
*/
|
|
|
|
void MainWindow::appendPacketMenu(QAction* funnel_action)
|
|
|
|
{
|
|
|
|
dynamic_packet_menu_actions.append(funnel_action);
|
|
|
|
connect(funnel_action, SIGNAL(triggered(bool)), funnel_action, SLOT(triggerPacketCallback()));
|
|
|
|
}
|
2021-04-14 13:47:07 +00:00
|
|
|
|
2020-12-27 04:15:24 +00:00
|
|
|
/*
|
|
|
|
* Returns the list of registered packet menu actions
|
|
|
|
*
|
|
|
|
* After ensuring that all stored custom packet menu actions
|
|
|
|
* are registered with the Wireshark GUI, it returns them as a list
|
|
|
|
* so that they can potentially be displayed to a user.
|
|
|
|
*
|
|
|
|
* @return the list of registered packet menu actions
|
|
|
|
*/
|
|
|
|
QList<QAction *> MainWindow::getPacketMenuActions()
|
|
|
|
{
|
|
|
|
if (funnel_statistics_packet_menus_modified()) {
|
|
|
|
// If the packet menus were modified, we need to clear the already
|
|
|
|
// loaded packet menus to avoid duplicates
|
|
|
|
this->clearAddedPacketMenus();
|
|
|
|
funnel_statistics_load_packet_menus();
|
|
|
|
}
|
|
|
|
return dynamic_packet_menu_actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clears the list of registered packet menu actions
|
|
|
|
*
|
|
|
|
* Clears the list of registered packet menu actions
|
|
|
|
* and frees all associated memory.
|
|
|
|
*/
|
|
|
|
void MainWindow::clearAddedPacketMenus()
|
|
|
|
{
|
|
|
|
for( int i=0; i<dynamic_packet_menu_actions.count(); ++i )
|
|
|
|
{
|
|
|
|
delete dynamic_packet_menu_actions[i];
|
|
|
|
}
|
|
|
|
dynamic_packet_menu_actions.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adds the custom packet menus to the supplied QMenu
|
|
|
|
*
|
|
|
|
* This method takes in QMenu and the selected packet's data
|
|
|
|
* and adds all applicable custom packet menus to it.
|
|
|
|
*
|
|
|
|
* @param ctx_menu The menu to add the packet menu entries to
|
|
|
|
* @param finfo_array The data in the selected packet
|
|
|
|
* @return true if a packet menu was added to the ctx_menu
|
|
|
|
*/
|
|
|
|
bool MainWindow::addPacketMenus(QMenu * ctx_menu, GPtrArray *finfo_array)
|
|
|
|
{
|
|
|
|
bool insertedPacketMenu = false;
|
|
|
|
QList<QAction *> myPacketMenuActions = this->getPacketMenuActions();
|
|
|
|
if (myPacketMenuActions.isEmpty()) {
|
|
|
|
return insertedPacketMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build a set of fields present for efficient lookups
|
|
|
|
QSet<QString> fieldsPresent = QSet<QString>();
|
|
|
|
for (guint fieldInfoIndex = 0; fieldInfoIndex < finfo_array->len; fieldInfoIndex++) {
|
|
|
|
field_info *fi = (field_info *)g_ptr_array_index (finfo_array, fieldInfoIndex);
|
|
|
|
fieldsPresent.insert(QString(fi->hfinfo->abbrev));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Place actions in the relevant (sub)menu
|
|
|
|
// The 'root' menu is the ctx_menu, so map NULL to that
|
|
|
|
QHash<QString, QMenu *> menuTextToMenus;
|
|
|
|
menuTextToMenus.insert(NULL, ctx_menu);
|
|
|
|
foreach (QAction * action, myPacketMenuActions) {
|
|
|
|
if (! qobject_cast<FunnelAction *>(action)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
FunnelAction * packetAction = qobject_cast<FunnelAction *>(action);
|
|
|
|
|
|
|
|
// Only display a menu if all required fields are present
|
|
|
|
if (!fieldsPresent.contains(packetAction->getPacketRequiredFields())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
packetAction->setPacketData(finfo_array);
|
|
|
|
packetAction->addToMenu(ctx_menu, menuTextToMenus);
|
|
|
|
insertedPacketMenu = true;
|
|
|
|
}
|
|
|
|
return insertedPacketMenu;
|
|
|
|
}
|