diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
commit | e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch) | |
tree | 68cb5ef9081156392f1dd62a00c6ccc1451b93df /plugins/epan/pluginifdemo | |
parent | Initial commit. (diff) | |
download | wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.tar.xz wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.zip |
Adding upstream version 4.2.2.upstream/4.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'plugins/epan/pluginifdemo')
-rw-r--r-- | plugins/epan/pluginifdemo/AUTHORS | 2 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/CMakeLists.txt | 75 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/README | 2 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/pluginifdemo.c | 156 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/pluginifdemo.h | 11 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/ui/pluginifdemo_about.cpp | 49 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/ui/pluginifdemo_about.h | 53 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/ui/pluginifdemo_about.ui | 156 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/ui/pluginifdemo_main.cpp | 382 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/ui/pluginifdemo_main.h | 124 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/ui/pluginifdemo_main.ui | 369 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/ui/uiclasshandler.cpp | 116 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/ui/uihandler.cpp | 74 | ||||
-rw-r--r-- | plugins/epan/pluginifdemo/ui/uihandler.h | 89 |
14 files changed, 1658 insertions, 0 deletions
diff --git a/plugins/epan/pluginifdemo/AUTHORS b/plugins/epan/pluginifdemo/AUTHORS new file mode 100644 index 00000000..ca50630c --- /dev/null +++ b/plugins/epan/pluginifdemo/AUTHORS @@ -0,0 +1,2 @@ +Author : +Roland Knall <rknall@gmail.com> diff --git a/plugins/epan/pluginifdemo/CMakeLists.txt b/plugins/epan/pluginifdemo/CMakeLists.txt new file mode 100644 index 00000000..95c05a03 --- /dev/null +++ b/plugins/epan/pluginifdemo/CMakeLists.txt @@ -0,0 +1,75 @@ +# CMakeLists.txt +# +# Wireshark - Network traffic analyzer +# By Gerald Combs <gerald@wireshark.org> +# Copyright 1998 Gerald Combs +# +# SPDX-License-Identifier: GPL-2.0-or-later +# + +include(WiresharkPlugin) + +# Plugin name and version info (major minor micro extra) +set_module_info(pluginifdemo 0 0 2 0) + +SET(CMAKE_AUTOMOC ON) +SET(CMAKE_AUTOUIC ON) + +if(USE_qt6) + set(qtver "6") +else() + set(qtver "5") +endif() + +find_package(Qt${qtver}Core) +find_package(Qt${qtver}PrintSupport) +find_package(Qt${qtver}Widgets) + +set(DISSECTOR_SRC + pluginifdemo.c + ui/uihandler.cpp + ui/uiclasshandler.cpp + ui/pluginifdemo_main.cpp + ui/pluginifdemo_about.cpp + ${UI_SRC} +) + +set(PLUGIN_FILES + plugin.c + ${DISSECTOR_SRC} +) + +set_source_files_properties( + plugin.c + PROPERTIES + SKIP_AUTOGEN ON +) + +set_source_files_properties( + ${PLUGIN_FILES} + PROPERTIES + COMPILE_FLAGS "${WERROR_COMMON_FLAGS}" +) + +register_plugin_files(plugin.c + plugin + ${DISSECTOR_SRC} +) + +add_wireshark_plugin_library(pluginifdemo epan) + +target_link_libraries(pluginifdemo epan Qt${qtver}::Core Qt${qtver}::Widgets Qt${qtver}::PrintSupport) + +install_plugin(pluginifdemo epan) + +file(GLOB DISSECTOR_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h") +CHECKAPI( + NAME + pluginifdemo + SWITCHES + --group dissectors-prohibited + --group dissectors-restricted + SOURCES + ${DISSECTOR_SRC} + ${DISSECTOR_HEADERS} +) diff --git a/plugins/epan/pluginifdemo/README b/plugins/epan/pluginifdemo/README new file mode 100644 index 00000000..7aa753f7 --- /dev/null +++ b/plugins/epan/pluginifdemo/README @@ -0,0 +1,2 @@ +This plugin demonstrates a Qt integration using plugin_if and +menubar_ext functionality. diff --git a/plugins/epan/pluginifdemo/pluginifdemo.c b/plugins/epan/pluginifdemo/pluginifdemo.c new file mode 100644 index 00000000..e6c42b47 --- /dev/null +++ b/plugins/epan/pluginifdemo/pluginifdemo.c @@ -0,0 +1,156 @@ +/* pluginifdemo.c + * Routines for plugin_if demo capability + * Author: Roland Knall <rknall@gmail.com> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "config.h" + +#include <stdio.h> + +#include <epan/packet.h> +#include <epan/prefs.h> +#include <epan/tap.h> +#include <epan/plugin_if.h> +#include "pluginifdemo.h" + +#include "ui/uihandler.h" + +void proto_register_pluginifdemo(void); +void proto_reg_handoff_pluginifdemo(void); + +static int proto_pluginifdemo = -1; + +void toolbar_cb(gpointer object, gpointer item_data, gpointer user_data); + +void +menu_cb(ext_menubar_gui_type gui_type, gpointer gui_data, gpointer user_data _U_) +{ + pluginifdemo_ui_main(gui_type, gui_data); +} + +void +about_cb(ext_menubar_gui_type gui_type _U_, gpointer gui_data _U_, gpointer user_data _U_) +{ + pluginifdemo_ui_about(gui_type, gui_data); +} + +void +proto_register_pluginifdemo(void) +{ + +#if 0 + module_t *pluginif_module = NULL; +#endif + ext_menu_t * ext_menu = NULL; + + proto_pluginifdemo = proto_register_protocol("Plugin IF Demo Protocol", "Pluginifdemo", "pluginifdemo"); + + ext_menu = ext_menubar_register_menu ( proto_pluginifdemo, "Plugin IF Demonstration", TRUE ); + ext_menubar_set_parentmenu (ext_menu, "Tools"); + + ext_menubar_add_entry(ext_menu, "Toolbar Action Demonstrator", "Action demonstrator for the plugin toolbar", menu_cb, NULL); + ext_menubar_add_separator(ext_menu); + ext_menubar_add_website(ext_menu, "Wireshark Development", "See Wireshark Development", "https://www.wireshark.org/develop.html"); + ext_menubar_add_separator(ext_menu); + ext_menubar_add_entry(ext_menu, "&About Plugin IF Demonstration", "Further information", about_cb, NULL); +#if 0 + pluginif_module = prefs_register_protocol(proto_pluginifdemo, NULL); +#endif + + + ext_toolbar_t * tb = ext_toolbar_register_toolbar("Plugin Interface Demo Toolbar"); + + ext_toolbar_add_entry(tb, EXT_TOOLBAR_BUTTON, "Button 1", 0, "Button 1 to press", FALSE, 0, FALSE, 0, toolbar_cb, 0); + ext_toolbar_add_entry(tb, EXT_TOOLBAR_BUTTON, "Button 2", 0, "Button 2 to press", TRUE, 0, FALSE, 0, toolbar_cb, 0); + ext_toolbar_add_entry(tb, EXT_TOOLBAR_BOOLEAN, "Checkbox", 0, "Checkbox to Select", FALSE, 0, FALSE, 0, toolbar_cb, 0); + ext_toolbar_add_entry(tb, EXT_TOOLBAR_STRING, "String 1", "Default String", "String without validation", FALSE, 0, TRUE, 0, toolbar_cb, 0); + ext_toolbar_add_entry(tb, EXT_TOOLBAR_STRING, "String 2", "ABC", "String with validation", FALSE, 0, FALSE, "^[A-Z]+", toolbar_cb, 0); + GList * entries = 0; + entries = ext_toolbar_add_val( entries, "1", "ABCD", FALSE ); + entries = ext_toolbar_add_val(entries, "2", "EFG", FALSE ); + entries = ext_toolbar_add_val(entries, "3", "HIJ", TRUE ); + entries = ext_toolbar_add_val(entries, "4", "KLM", FALSE ); + entries = ext_toolbar_add_val(entries, "5", "NOP", FALSE ); + entries = ext_toolbar_add_val(entries, "6", "QRS", FALSE ); + entries = ext_toolbar_add_val(entries, "7", "TUVW", FALSE ); + entries = ext_toolbar_add_val(entries, "8", "XYZ", FALSE ); + ext_toolbar_add_entry(tb, EXT_TOOLBAR_SELECTOR, "Selector", 0, "Selector to choose from", FALSE, entries, FALSE, 0, toolbar_cb, 0); + + pluginifdemo_toolbar_register(tb); +} + +void* get_frame_data_cb(frame_data* fdata, void* user_data _U_) { + return GUINT_TO_POINTER(fdata->num); +} + +void* get_capture_file_cb(capture_file* cf, void* user_data _U_) { + return cf->filename; +} + +void toolbar_cb(gpointer toolbar_item, gpointer item_data, gpointer user_data _U_) +{ + if ( ! toolbar_item ) + return; + + gchar * message = 0; + ext_toolbar_t * entry = (ext_toolbar_t *)toolbar_item; + + if (entry->item_type == EXT_TOOLBAR_BUTTON) { + pluginifdemo_toolbar_log("Button pressed at toolbar"); + guint32 fnum = GPOINTER_TO_UINT(plugin_if_get_frame_data(get_frame_data_cb, NULL)); + if (fnum) { + message = ws_strdup_printf("Current frame is: %u", fnum); + pluginifdemo_toolbar_log(message); + } + const gchar* fnm = (const gchar*)plugin_if_get_capture_file(get_capture_file_cb, NULL); + if (fnm) { + message = ws_strdup_printf("Capture file name is: %s", fnm); + pluginifdemo_toolbar_log(message); + } + } + else if ( entry->item_type == EXT_TOOLBAR_BOOLEAN ) + { + gboolean data = *((gboolean *)item_data); + message = ws_strdup_printf( "Checkbox selected value: %d", (int) (data) ); + pluginifdemo_toolbar_log(message); + } + else if ( entry->item_type == EXT_TOOLBAR_STRING ) + { + gchar * data = (gchar *)item_data; + message = ws_strdup_printf( "String entered in toolbar: %s", data ); + pluginifdemo_toolbar_log(message); + } + else if ( entry->item_type == EXT_TOOLBAR_SELECTOR ) + { + ext_toolbar_value_t * data = (ext_toolbar_value_t *)item_data; + message = ws_strdup_printf( "Value from toolbar: %s", data->value ); + pluginifdemo_toolbar_log(message); + } + + g_free(message); +} + +void +proto_reg_handoff_pluginifdemo(void) +{ + +} + +/* + * Editor modelines - https://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/plugins/epan/pluginifdemo/pluginifdemo.h b/plugins/epan/pluginifdemo/pluginifdemo.h new file mode 100644 index 00000000..e928b7fc --- /dev/null +++ b/plugins/epan/pluginifdemo/pluginifdemo.h @@ -0,0 +1,11 @@ +/* pluginifdemo.h + * Definitions for plugin_if_demo structures and routines + * By Steve Limkemann <stevelim@dgtech.com> + * Copyright 1998 Steve Limkemann + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ diff --git a/plugins/epan/pluginifdemo/ui/pluginifdemo_about.cpp b/plugins/epan/pluginifdemo/ui/pluginifdemo_about.cpp new file mode 100644 index 00000000..63a69fb1 --- /dev/null +++ b/plugins/epan/pluginifdemo/ui/pluginifdemo_about.cpp @@ -0,0 +1,49 @@ +/* pluginifdemo_about.cpp + * + * Author: Roland Knall <rknall@gmail.com> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include <plugins/epan/pluginifdemo/ui/pluginifdemo_about.h> +#include <ui_pluginifdemo_about.h> + +#include <config.h> + +#include <QDialog> +#include <QWidget> +#include <QAbstractButton> + +PluginIFDemo_About::PluginIFDemo_About(QWidget *parent) : + QDialog(parent), + ui(new Ui::PluginIFDemo_About) +{ + ui->setupUi(this); +} + +PluginIFDemo_About::~PluginIFDemo_About() +{ + delete ui; +} + +void PluginIFDemo_About::on_buttonBox_clicked(QAbstractButton *) +{ + this->close(); +} + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/plugins/epan/pluginifdemo/ui/pluginifdemo_about.h b/plugins/epan/pluginifdemo/ui/pluginifdemo_about.h new file mode 100644 index 00000000..e7266849 --- /dev/null +++ b/plugins/epan/pluginifdemo/ui/pluginifdemo_about.h @@ -0,0 +1,53 @@ +/* pluginifdemo_about.h + * + * Author: Roland Knall <rknall@gmail.com> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef PLUGINIFDEMO_ABOUT_H_ +#define PLUGINIFDEMO_ABOUT_H_ + +#include <QWidget> +#include <QDialog> +#include <QAbstractButton> +#include <QPixmap> +#include <QGraphicsScene> + +namespace Ui { +class PluginIFDemo_About; +} + +class PluginIFDemo_About : public QDialog +{ + Q_OBJECT + +public: + explicit PluginIFDemo_About(QWidget *parent = 0); + ~PluginIFDemo_About(); + +private slots: + void on_buttonBox_clicked(QAbstractButton *button); + +private: + Ui::PluginIFDemo_About *ui; +}; + +#endif /* PLUGINIFDEMO_ABOUT_H_ */ + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/plugins/epan/pluginifdemo/ui/pluginifdemo_about.ui b/plugins/epan/pluginifdemo/ui/pluginifdemo_about.ui new file mode 100644 index 00000000..c31f0583 --- /dev/null +++ b/plugins/epan/pluginifdemo/ui/pluginifdemo_about.ui @@ -0,0 +1,156 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PluginIFDemo_About</class> + <widget class="QDialog" name="PluginIFDemo_About"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>545</width> + <height>401</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>545</width> + <height>401</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>545</width> + <height>401</height> + </size> + </property> + <property name="contextMenuPolicy"> + <enum>Qt::NoContextMenu</enum> + </property> + <property name="windowTitle"> + <string>About Plugin Interface Demonstrator</string> + </property> + <property name="modal"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <property name="spacing"> + <number>0</number> + </property> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>10</number> + </property> + <property name="leftMargin"> + <number>9</number> + </property> + <property name="topMargin"> + <number>9</number> + </property> + <property name="rightMargin"> + <number>9</number> + </property> + <property name="bottomMargin"> + <number>9</number> + </property> + <item> + <widget class="QLabel" name="lblAboutDialog"> + <property name="text"> + <string><html><head/><body><p><span style=" font-size:10pt;"><br/></span><span style=" font-size:10pt; font-weight:600;">PlugIn Interface Demonstration</span><span style=" font-size:10pt;"><br/>Version: </span><span style=" font-size:10pt; font-weight:600;">0.0.2 </span></p><p><span style=" font-size:10pt;">Copyright © </span><span style=" font-size:10pt; font-style:italic;">Wireshark Foundation</span><span style=" font-size:10pt;"><br/></span><a href="https://www.wireshark.org"><span style=" text-decoration: underline; color:#0000ff;">www.wireshark.org</span></a></p></body></html></string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QTabWidget" name="tabWidget"> + <widget class="QWidget" name="tab"> + <attribute name="title"> + <string>License Information</string> + </attribute> + <widget class="QLabel" name="lblLicense"> + <property name="geometry"> + <rect> + <x>10</x> + <y>0</y> + <width>511</width> + <height>102</height> + </rect> + </property> + <property name="text"> + <string><html><head/><body><p>This PlugIn demonstrates functionality of the interface API for plugins and extcap interfaces.</p></body></html></string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </widget> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Ok</set> + </property> + <property name="centerButtons"> + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/plugins/epan/pluginifdemo/ui/pluginifdemo_main.cpp b/plugins/epan/pluginifdemo/ui/pluginifdemo_main.cpp new file mode 100644 index 00000000..a4823817 --- /dev/null +++ b/plugins/epan/pluginifdemo/ui/pluginifdemo_main.cpp @@ -0,0 +1,382 @@ +/* pluginifdemo_main.cpp + * + * Author: Roland Knall <rknall@gmail.com> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include <plugins/epan/pluginifdemo/ui/pluginifdemo_main.h> +#include <ui_pluginifdemo_main.h> + +#include <config.h> + +#include "uihandler.h" + +#include <QWidget> +#include <QLineEdit> +#include <QListView> +#include <QStandardItemModel> + +PluginIfType::PluginIfType(const QString &label, const ext_toolbar_item_t &itemType) + : m_label(label), m_itemType(itemType) +{} + +QString PluginIfType::label() const { return m_label; } +ext_toolbar_item_t PluginIfType::itemType() const { return m_itemType; } + +PluginIfTypeModel::PluginIfTypeModel(QObject * parent) + :QAbstractListModel(parent) +{ +} + +void PluginIfTypeModel::addPluginIfType(const PluginIfType &ifType) +{ + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_pluginIfTypes << ifType; + endInsertRows(); +} + +int PluginIfTypeModel::rowCount(const QModelIndex &) const +{ + return static_cast<int>(m_pluginIfTypes.count()); +} + +QVariant PluginIfTypeModel::data(const QModelIndex & idx, int role) const +{ + if ( idx.row() < 0 || idx.row() >= m_pluginIfTypes.count() ) + return QVariant(); + + const PluginIfType &ifType = m_pluginIfTypes[idx.row()]; + if ( role == Qt::UserRole ) + { + return ifType.itemType(); + } else if ( role == Qt::DisplayRole ) { + return ifType.label(); + } + + return QVariant(); +} + +PluginIfTypeSortFilterProxyModel::PluginIfTypeSortFilterProxyModel(QObject * parent) +:QSortFilterProxyModel(parent) +{ + m_filterType = EXT_TOOLBAR_BOOLEAN; +} + +void PluginIfTypeSortFilterProxyModel::setFilterElement(ext_toolbar_item_t filterType) +{ + m_filterType = filterType; + invalidateFilter(); +} + +bool PluginIfTypeSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ + QModelIndex dataIndex = sourceModel()->index(sourceRow, 0, sourceParent); + QVariant varData = sourceModel()->data(dataIndex, Qt::UserRole); + if ( varData.isValid() && varData.toInt() == (int) m_filterType ) + return true; + + return false; +} + +PluginIFDemo_Main::PluginIFDemo_Main(QWidget *parent) : + QDialog(parent), + ui(new Ui::PluginIFDemo_Main) +{ + ui->setupUi(this); + + _toolbar = 0; + sourceModel = new PluginIfTypeModel(this); + proxyModel = new PluginIfTypeSortFilterProxyModel(this); + proxyModel->setSourceModel(sourceModel); + ui->cmbElements->setModel(proxyModel); + + listModel = new QStandardItemModel(this); + ui->lstItems->setModel(listModel); + + indexModel = new QStandardItemModel(this); + ui->cmbEntryIndex->setModel(indexModel); + + ui->logView->setModel(new QStandardItemModel(ui->logView)); + + ui->tabInterfaceTypes->setCurrentIndex(0); + + connect ( GuiHandler::getInstance(), SIGNAL(reset(void)), this, SLOT(closeDialog()) ); + connect ( GuiHandler::getInstance(), SIGNAL(logChanged(QString)), this, SLOT(logChanged(QString)) ); +} + +PluginIFDemo_Main::~PluginIFDemo_Main() +{ + delete ui; +} + +void PluginIFDemo_Main::setToolbar(ext_toolbar_t * &toolbar) +{ + _toolbar = toolbar; + + GList * walker = toolbar->children; + while ( walker && walker->data ) + { + ext_toolbar_t * entry = (ext_toolbar_t *)walker->data; + if ( entry && entry->type == EXT_TOOLBAR_ITEM && entry->name ) + sourceModel->addPluginIfType(PluginIfType(QString(entry->name), entry->item_type)); + walker = g_list_next(walker); + } +} + +void PluginIFDemo_Main::closeDialog() +{ + this->close(); +} + +void PluginIFDemo_Main::on_buttonBox_clicked(QAbstractButton *button _U_) +{ + this->close(); +} + +void PluginIFDemo_Main::logChanged(QString message) +{ + QStandardItemModel * model = (QStandardItemModel *) ui->logView->model(); + model->appendRow(new QStandardItem(message)); +} + +void PluginIFDemo_Main::on_btnSendButtonText_clicked() +{ + if ( ! _toolbar ) + return; + + ext_toolbar_t *item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str()); + if ( ! item ) + return; + + QString entryText = ui->txtButtonName->text(); + bool silent = ui->chkSilent->checkState() == Qt::Checked ? true : false; + + ext_toolbar_update_value(item, (gpointer) entryText.toStdString().c_str(), silent); +} + +void PluginIFDemo_Main::on_btnSendText_clicked() +{ + if ( ! _toolbar ) + return; + + ext_toolbar_t *item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str()); + if ( ! item ) + return; + + QString entryText = ui->txtEdit->text(); + bool silent = ui->chkSilent->checkState() == Qt::Checked ? true : false; + + ext_toolbar_update_value(item, (gpointer) entryText.toStdString().c_str(), silent); +} + +void PluginIFDemo_Main::on_chkTestCheckbox_stateChanged(int newState) +{ + if ( ! _toolbar ) + return; + + ext_toolbar_t * item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str()); + if ( ! item ) + return; + bool silent = ui->chkSilent->checkState() == Qt::Checked ? true : false; + + ext_toolbar_update_value(item, GINT_TO_POINTER(newState == Qt::Checked ? 1 : 0), silent); +} + +void PluginIFDemo_Main::on_tabInterfaceTypes_currentChanged(int newTab) +{ + proxyModel->setFilterElement((ext_toolbar_item_t) newTab); +} + +void PluginIFDemo_Main::on_cmbElements_currentTextChanged(const QString & newText) +{ + if ( ! _toolbar ) + return; + + ext_toolbar_t * item = ext_toolbar_entry_by_label(_toolbar, newText.toStdString().c_str()); + if ( ! item || item->item_type != EXT_TOOLBAR_SELECTOR ) + return; + + listModel->clear(); + indexModel->clear(); + + GList * walker = item->values; + while ( walker && walker->data ) + { + ext_toolbar_value_t * listItem = (ext_toolbar_value_t *)walker->data; + QString content = QString("%1: %2").arg(listItem->value).arg(listItem->display); + listModel->appendRow(new QStandardItem(content)); + indexModel->appendRow(new QStandardItem(listItem->value)); + + walker = g_list_next(walker); + } + +} + +void PluginIFDemo_Main::on_btnEnable_clicked() +{ + ext_toolbar_t * item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str()); + if ( ! item ) + return; + + ext_toolbar_update_data_set_active(item, true); +} + +void PluginIFDemo_Main::on_btnDisable_clicked() +{ + ext_toolbar_t * item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str()); + if ( ! item ) + return; + + ext_toolbar_update_data_set_active(item, false); +} + +void PluginIFDemo_Main::on_btnAddItem_clicked() +{ + if ( ui->txtNewItemDisplay->text().length() <= 0 || ui->txtNewItemValue->text().length() <= 0 ) + return; + + QString content = QString("%1: %2").arg(ui->txtNewItemValue->text()).arg(ui->txtNewItemDisplay->text()); + + QList<QStandardItem *> items = listModel->findItems(content); + if ( items.count() > 0 ) + return; + items = listModel->findItems(QString("%1: ").arg(ui->txtNewItemValue->text()), Qt::MatchStartsWith); + if ( items.count() > 0 ) + return; + + listModel->appendRow(new QStandardItem(content)); + + if ( ui->chkAddRemoveImmediate->checkState() == Qt::Checked ) + { + ext_toolbar_t * item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str()); + if ( ! item || item->item_type != EXT_TOOLBAR_SELECTOR ) + return; + + bool silent = ui->chkSilent->checkState() == Qt::Checked ? true : false; + + gchar * value = g_strdup(ui->txtNewItemValue->text().toUtf8().constData()); + gchar * display = g_strdup(ui->txtNewItemDisplay->text().toUtf8().constData()); + ext_toolbar_update_data_add_entry(item, display, value, silent); + g_free(value); + g_free(display); + } +} + +void PluginIFDemo_Main::on_btnRemoveItem_clicked() +{ + QItemSelectionModel * selModel = ui->lstItems->selectionModel(); + + if ( selModel->selectedIndexes().count() == 0 ) + return; + + QModelIndexList selIndeces = selModel-> selectedIndexes(); + foreach(QModelIndex idx, selIndeces) + { + if ( ui->chkAddRemoveImmediate->checkState() == Qt::Checked ) + { + ext_toolbar_t * item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str()); + if ( ! item || item->item_type != EXT_TOOLBAR_SELECTOR ) + return; + + bool silent = ui->chkSilent->checkState() == Qt::Checked ? true : false; + + QString content = listModel->data(idx).toString(); + int pos = static_cast<int>(content.indexOf(":")); + + gchar * value = g_strdup(content.left(pos).toUtf8().constData() ); + /* -2 because removal of : and space */ + gchar * display = g_strdup(content.right(content.size() - pos - 2).toUtf8().constData()); + ext_toolbar_update_data_remove_entry(item, display, value, silent); + g_free(value); + g_free(display); + } + + listModel->removeRow(idx.row()); + } +} + +void PluginIFDemo_Main::on_btnSendList_clicked() +{ + if ( ! _toolbar ) + return; + + ext_toolbar_t * item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str()); + if ( ! item || item->item_type != EXT_TOOLBAR_SELECTOR ) + return; + + GList * items = NULL; + + for( int i = 0; i < listModel->rowCount(); i++ ) + { + QString content = listModel->data(listModel->index(i, 0)).toString(); + int pos = static_cast<int>(content.indexOf(":")); + + ext_toolbar_value_t * valEntry = g_new0(ext_toolbar_value_t, 1); + valEntry->value = g_strdup(content.left(pos).toUtf8().constData()); + valEntry->display = g_strdup(content.right(content.size() - pos + 1).toUtf8().constData()); + + items = g_list_append(items, valEntry); + } + + bool silent = ui->chkSilent->checkState() == Qt::Checked ? true : false; + + ext_toolbar_update_data(item, items , silent); +} + +void PluginIFDemo_Main::on_btnSendUpdateItem_clicked() +{ + if ( ! _toolbar ) + return; + + ext_toolbar_t * item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str()); + if ( ! item || item->item_type != EXT_TOOLBAR_SELECTOR ) + return; + + QString cmbIndexText = ui->cmbEntryIndex->currentText(); + QString displayValue = ui->txtUpdateDisplayValue->text(); + if ( displayValue.length() == 0 ) + return; + + bool silent = ui->chkSilent->checkState() == Qt::Checked ? true : false; + + ext_toolbar_update_data_by_index(item, + (gpointer) displayValue.toStdString().c_str(), (gpointer) cmbIndexText.toStdString().c_str(), silent ); +} + +void PluginIFDemo_Main::on_lstItems_clicked(const QModelIndex &idx) +{ + if ( ! _toolbar || ! idx.isValid() ) + return; + + ext_toolbar_t * item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str()); + if ( ! item || item->item_type != EXT_TOOLBAR_SELECTOR ) + return; + + bool silent = ui->chkSilent->checkState() == Qt::Checked ? true : false; + + QString content = listModel->data(listModel->index(idx.row(), 0)).toString(); + int pos = static_cast<int>(content.indexOf(":")); + + gchar * idxData = g_strdup(content.left(pos).toUtf8().constData() ); + + ext_toolbar_update_value(item, idxData, silent); + g_free(idxData); + +} +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/plugins/epan/pluginifdemo/ui/pluginifdemo_main.h b/plugins/epan/pluginifdemo/ui/pluginifdemo_main.h new file mode 100644 index 00000000..e0bafaab --- /dev/null +++ b/plugins/epan/pluginifdemo/ui/pluginifdemo_main.h @@ -0,0 +1,124 @@ +/* pluginifdemo_main.h + * + * Author: Roland Knall <rknall@gmail.com> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef PLUGINIFDEMO_MAIN_H_ +#define PLUGINIFDEMO_MAIN_H_ + +#include <QWidget> +#include <QDialog> +#include <QAbstractButton> +#include <QListWidget> +#include <QAbstractListModel> +#include <QSortFilterProxyModel> +#include <QStandardItemModel> + +#include <epan/plugin_if.h> + +namespace Ui { +class PluginIFDemo_Main; +} + +class PluginIfType +{ +public: + PluginIfType(const QString &label, const ext_toolbar_item_t &itemType); + + QString label() const; + ext_toolbar_item_t itemType() const; +private: + QString m_label; + ext_toolbar_item_t m_itemType; +}; + +class PluginIfTypeModel : public QAbstractListModel +{ + Q_OBJECT +public: + PluginIfTypeModel(QObject * parent = 0); + + void addPluginIfType(const PluginIfType & pluginIfType); + + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & idx, int role = Qt::DisplayRole) const; + +private: + QList<PluginIfType> m_pluginIfTypes; + +}; + +class PluginIfTypeSortFilterProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT +public: + PluginIfTypeSortFilterProxyModel(QObject * parent = 0); + + bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; + + void setFilterElement(ext_toolbar_item_t filterType); + +private: + ext_toolbar_item_t m_filterType; +}; + +class PluginIFDemo_Main : public QDialog +{ + Q_OBJECT + +public: + explicit PluginIFDemo_Main(QWidget *parent = 0); + ~PluginIFDemo_Main(); + + void setToolbar(ext_toolbar_t * &toolbar); + +private slots: + void on_buttonBox_clicked(QAbstractButton *button); + void on_btnSendButtonText_clicked(); + void on_btnSendText_clicked(); + void on_btnSendUpdateItem_clicked(); + void on_chkTestCheckbox_stateChanged(int newState); + void on_tabInterfaceTypes_currentChanged(int newTab); + void on_btnAddItem_clicked(); + void on_btnRemoveItem_clicked(); + void on_btnSendList_clicked(); + void on_cmbElements_currentTextChanged(const QString & newText); + void on_lstItems_clicked(const QModelIndex &idx); + void on_btnEnable_clicked(); + void on_btnDisable_clicked(); + + void logChanged(QString message); + void closeDialog(); + +private: + Ui::PluginIFDemo_Main *ui; + + PluginIfTypeModel * sourceModel; + PluginIfTypeSortFilterProxyModel * proxyModel; + QStandardItemModel * listModel; + QStandardItemModel * indexModel; + + ext_toolbar_t * _toolbar; +}; + + +#endif /* PLUGINIFDEMO_MAIN_H_ */ + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/plugins/epan/pluginifdemo/ui/pluginifdemo_main.ui b/plugins/epan/pluginifdemo/ui/pluginifdemo_main.ui new file mode 100644 index 00000000..467ec85e --- /dev/null +++ b/plugins/epan/pluginifdemo/ui/pluginifdemo_main.ui @@ -0,0 +1,369 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PluginIFDemo_Main</class> + <widget class="QDialog" name="PluginIFDemo_Main"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>500</width> + <height>570</height> + </rect> + </property> + <property name="minimumSize"> + <size> + <width>500</width> + <height>570</height> + </size> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <widget class="QTabWidget" name="tabInterfaceTypes"> + <property name="currentIndex"> + <number>3</number> + </property> + <widget class="QWidget" name="tabBoolean"> + <attribute name="title"> + <string>Boolean</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QCheckBox" name="chkTestCheckbox"> + <property name="text"> + <string>Check the value in the toolbar checkbox</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <widget class="QWidget" name="tabButton"> + <attribute name="title"> + <string>Button</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_7"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_4" stretch="0,0"> + <item> + <widget class="QLineEdit" name="txtButtonName"> + <property name="placeholderText"> + <string>Text to be sent to toolbar</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btnSendButtonText"> + <property name="text"> + <string>Send Text</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer_4"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <widget class="QWidget" name="tabString"> + <attribute name="title"> + <string>String</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0"> + <item> + <widget class="QLineEdit" name="txtEdit"> + <property name="placeholderText"> + <string>Text to be sent to toolbar</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btnSendText"> + <property name="text"> + <string>Send Text</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer_3"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <widget class="QWidget" name="tabSelector"> + <attribute name="title"> + <string>Selector</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Display:</string> + </property> + <property name="buddy"> + <cstring>txtNewItemDisplay</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="txtNewItemDisplay"> + <property name="placeholderText"> + <string>Enter display text</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Value:</string> + </property> + <property name="buddy"> + <cstring>txtNewItemValue</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="txtNewItemValue"> + <property name="placeholderText"> + <string>Enter value text</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btnAddItem"> + <property name="text"> + <string>Add</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QListView" name="lstItems"/> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QPushButton" name="btnRemoveItem"> + <property name="text"> + <string>Remove</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="btnSendList"> + <property name="text"> + <string>Send List</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> + <widget class="QCheckBox" name="chkAddRemoveImmediate"> + <property name="text"> + <string>Add and remove will immediately be send to interface</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="chkSendSelect"> + <property name="text"> + <string>Update interface with selection</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_6"> + <item> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Update</string> + </property> + <property name="buddy"> + <cstring>cmbEntryIndex</cstring> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="cmbEntryIndex"/> + </item> + <item> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>with</string> + </property> + <property name="buddy"> + <cstring>txtUpdateDisplayValue</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="txtUpdateDisplayValue"> + <property name="placeholderText"> + <string>Enter value text</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btnSendUpdateItem"> + <property name="text"> + <string>Send</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </widget> + </item> + <item> + <widget class="Line" name="line"> + <property name="frameShadow"> + <enum>QFrame::Plain</enum> + </property> + <property name="lineWidth"> + <number>1</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Element to be updated</string> + </property> + <property name="buddy"> + <cstring>cmbElements</cstring> + </property> + </widget> + </item> + <item row="1" column="0"> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="1"> + <widget class="QPushButton" name="btnEnable"> + <property name="text"> + <string>Enable element</string> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QPushButton" name="btnDisable"> + <property name="text"> + <string>Disable element</string> + </property> + </widget> + </item> + <item row="0" column="1" colspan="2"> + <widget class="QComboBox" name="cmbElements"/> + </item> + </layout> + </item> + <item> + <widget class="QCheckBox" name="chkSilent"> + <property name="text"> + <string>Activate updates silently</string> + </property> + </widget> + </item> + <item> + <widget class="QListView" name="logView"/> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Close</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/plugins/epan/pluginifdemo/ui/uiclasshandler.cpp b/plugins/epan/pluginifdemo/ui/uiclasshandler.cpp new file mode 100644 index 00000000..6550bf2f --- /dev/null +++ b/plugins/epan/pluginifdemo/ui/uiclasshandler.cpp @@ -0,0 +1,116 @@ +/* uiclasshandler.cpp + * + * Author: Roland Knall <rknall@gmail.com> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include <config.h> + +#include <glib.h> + +#include <QObject> +#include <QApplication> +#include <QMutex> + +#include <epan/plugin_if.h> + +#if defined(_WIN32) +#define _WINSOCKAPI_ +#endif + +#include <ui/qt/main_window.h> + +#include "uihandler.h" +#include "pluginifdemo_main.h" +#include "pluginifdemo_about.h" + +QMutex * GuiHandler::singletonMutex = new QMutex(); + +GuiHandler::GuiHandler() +{ +} + +GuiHandler * GuiHandler::getInstance() +{ + static GuiHandler * instance = 0; + + QMutexLocker locker(singletonMutex); + + if ( instance == 0 ) + { + instance = new GuiHandler(); + } + + return instance; +} + +void GuiHandler::showAboutDialog(ext_menubar_gui_type gui_type _U_, gpointer gui_data _U_) +{ + PluginIFDemo_About * mainwindow = new PluginIFDemo_About(); + executeDialog((QDialog*)mainwindow); +} + +void GuiHandler::showMainDialog(ext_menubar_gui_type gui_type _U_, gpointer gui_data _U_) +{ + PluginIFDemo_Main * mainwindow = new PluginIFDemo_Main(); + mainwindow->setToolbar(_toolbar); + executeDialog((QDialog*)mainwindow); +} + +void GuiHandler::executeDialog(QDialog * dialog) +{ + bool hasGuiApp = (qobject_cast<QApplication*>(QCoreApplication::instance())!=0); + + if ( ! hasGuiApp ) + { + /* Necessity for creating the correct app context */ + int argc = 1; + char * argv = (char *) "Test"; + + /* In Gtk there is no application context, must be created and displayed */ + QApplication app(argc, &argv); + + dialog->show(); + + app.exec(); + } + else + { + /* With Wireshark Qt, an application context already exists, therefore just + * displaying the dialog using show to have it non-modal */ + dialog->show(); + } +} + +void GuiHandler::doReset() +{ + emit reset(); +} + +void GuiHandler::addLogMessage(QString message) +{ + emit logChanged(message); +} + +void GuiHandler::setToolbar(ext_toolbar_t * toolbar) +{ + _toolbar = toolbar; +} + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/plugins/epan/pluginifdemo/ui/uihandler.cpp b/plugins/epan/pluginifdemo/ui/uihandler.cpp new file mode 100644 index 00000000..34d9c68b --- /dev/null +++ b/plugins/epan/pluginifdemo/ui/uihandler.cpp @@ -0,0 +1,74 @@ +/* uihandler.cpp + * Author: Roland Knall <rknall@gmail.com> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include <config.h> + +#include <glib.h> + +#include <QObject> +#include <QApplication> + +#include <epan/plugin_if.h> +#include <epan/tap.h> + +#if defined(_WIN32) +#define _WINSOCKAPI_ +#endif + +#include <ui/qt/main_window.h> + +#include "uihandler.h" +#include <ui/simple_dialog.h> + +static void +reset_dialog(void *data _U_) +{ + GuiHandler::getInstance()->doReset(); +} + +void pluginifdemo_ui_main(ext_menubar_gui_type gui_type, gpointer gui_data) +{ + /* ensures, that the dialog is closing, if scm udid is set or a filter is applied */ + GString *error_string = register_tap_listener("frame", NULL, NULL, 0, reset_dialog, NULL, NULL, NULL); + + if (error_string != NULL) { + fprintf(stderr, "%s ", error_string->str); + g_string_free(error_string, TRUE); + } + GuiHandler::getInstance()->showMainDialog(gui_type, gui_data); +} + +void pluginifdemo_ui_about(ext_menubar_gui_type gui_type, gpointer gui_data) +{ + GuiHandler::getInstance()->showAboutDialog(gui_type, gui_data); +} + +void pluginifdemo_toolbar_log(const gchar * message) +{ + GuiHandler::getInstance()->addLogMessage(QString(message)); +} + +void pluginifdemo_toolbar_register(ext_toolbar_t * toolbar) +{ + GuiHandler::getInstance()->setToolbar(toolbar); +} + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/plugins/epan/pluginifdemo/ui/uihandler.h b/plugins/epan/pluginifdemo/ui/uihandler.h new file mode 100644 index 00000000..34536029 --- /dev/null +++ b/plugins/epan/pluginifdemo/ui/uihandler.h @@ -0,0 +1,89 @@ +/* uihandler.h + * Author: Roland Knall <rknall@gmail.com> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef PLUGINIFDEMO_UI_UIHANDLER_H_ +#define PLUGINIFDEMO_UI_UIHANDLER_H_ + +#ifdef __cplusplus + +#include <QObject> +#include <QDialog> +#include <QMutex> + +#include <epan/plugin_if.h> + +#include "ws_symbol_export.h" + +class GuiHandler : public QObject +{ + Q_OBJECT + +public: + + static GuiHandler * getInstance(); + + void showAboutDialog(ext_menubar_gui_type gui_type, gpointer gui_data); + void showMainDialog(ext_menubar_gui_type gui_type, gpointer gui_data); + + void doReset(); + + void addLogMessage(QString message); + + void setToolbar(ext_toolbar_t * toolbar); + ext_toolbar_t * toolBar(); + +signals: + void reset(); + void logChanged(QString newEntry); + +protected: + + GuiHandler(); + + // Stop the compiler generating methods of "copy the object" + GuiHandler(GuiHandler const& copy); // Not implemented + GuiHandler& operator=(GuiHandler const& copy); // Not implemented + +private: + + static QMutex * singletonMutex; + + ext_toolbar_t * _toolbar; + + void executeDialog(QDialog * object); +}; + +extern "C" { +#endif + +extern void pluginifdemo_ui_about(ext_menubar_gui_type gui_type, gpointer gui_data); +extern void pluginifdemo_ui_main(ext_menubar_gui_type gui_type, gpointer gui_data); +extern void pluginifdemo_toolbar_log(const gchar * message); + +extern void pluginifdemo_toolbar_register(ext_toolbar_t * toolbar); + +#ifdef __cplusplus +} +#endif + +#endif /* BURANALYZER_UI_UIHANDLER_H_ */ + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ |