1 /* tap_parameter_dialog.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #ifndef TAP_PARAMETER_DIALOG_H
11 #define TAP_PARAMETER_DIALOG_H
12 
13 /*
14  * @file Base class for statistics and analysis dialogs.
15  * Provides convenience classes for command-line tap parameters ("-z ...")
16  * and general tapping.
17  */
18 
19 #include "config.h"
20 
21 #include <glib.h>
22 
23 #include <epan/stat_groups.h>
24 #include <epan/stat_tap_ui.h>
25 
26 #include <QMenu>
27 
28 #include "filter_action.h"
29 #include "wireshark_dialog.h"
30 
31 class QHBoxLayout;
32 class QLineEdit;
33 class QTreeWidget;
34 class QTreeWidgetItem;
35 class QVBoxLayout;
36 
37 namespace Ui {
38 class TapParameterDialog;
39 }
40 
41 class TapParameterDialog;
42 typedef TapParameterDialog* (*tpdCreator)(QWidget &parent, const QString cfg_str, const QString arg, CaptureFile &cf);
43 
44 class TapParameterDialog : public WiresharkDialog
45 {
46     Q_OBJECT
47 
48 public:
49     explicit TapParameterDialog(QWidget &parent, CaptureFile &cf, int help_topic = 0);
50     ~TapParameterDialog();
51 
actionName()52     static const QString &actionName() { return action_name_; }
53     static void registerDialog(const QString title, const char *cfg_abbr, register_stat_group_t group, stat_tap_init_cb tap_init_cb, tpdCreator creator);
54 
55     static TapParameterDialog *showTapParameterStatistics(QWidget &parent, CaptureFile &cf, const QString cfg_str, const QString arg, void *);
56     // Needed by static member functions in subclasses. Should we just make
57     // "ui" available instead?
58     QTreeWidget *statsTreeWidget();
59     QLineEdit *displayFilterLineEdit();
60     QPushButton *applyFilterButton();
61     QVBoxLayout *verticalLayout();
62     QHBoxLayout *filterLayout();
63 
64     void drawTreeItems();
65 
66 signals:
67     void filterAction(QString filter, FilterAction::Action action, FilterAction::ActionType type);
68     void updateFilter(QString filter);
69 
70 public slots:
71 
72 protected:
73     void contextMenuEvent(QContextMenuEvent *event);
74     void addFilterActions();
75     void addTreeCollapseAllActions();
76     QString displayFilter();
77     void setDisplayFilter(const QString &filter);
78     void setHint(const QString &hint);
79     // Retap packets on first display. RPC stats need to disable this.
80     void setRetapOnShow(bool retap);
81 
82 protected slots:
83     void filterActionTriggered();
84     void collapseAllActionTriggered();
85     void expandAllActionTriggered();
86     void updateWidgets();
87 
88 private:
89     Ui::TapParameterDialog *ui;
90     QMenu ctx_menu_;
91     QList<QAction *> filter_actions_;
92     int help_topic_;
93     static const QString action_name_;
94     QTimer *show_timer_;
95 
filterExpression()96     virtual const QString filterExpression() { return QString(); }
97     QString itemDataToPlain(QVariant var, int width = 0);
98     virtual QList<QVariant> treeItemData(QTreeWidgetItem *) const;
99     virtual QByteArray getTreeAsString(st_format_type format);
100 
101 private slots:
102     // Called by the constructor. The subclass should tap packets here.
103     virtual void fillTree() = 0;
104 
105     void on_applyFilterButton_clicked();
106     void on_actionCopyToClipboard_triggered();
107     void on_actionSaveAs_triggered();
108     void on_buttonBox_helpRequested();
109 };
110 
111 #endif // TAP_PARAMETER_DIALOG_H
112