1 /* traffic_table_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 TRAFFIC_TABLE_DIALOG_H 11 #define TRAFFIC_TABLE_DIALOG_H 12 13 #include <config.h> 14 15 #include "file.h" 16 17 #include "epan/conversation_table.h" 18 19 #include "epan/follow.h" 20 21 #include "capture_file.h" 22 #include "filter_action.h" 23 #include "wireshark_dialog.h" 24 25 #include <QMenu> 26 #include <QTreeWidgetItem> 27 28 class QCheckBox; 29 class QDialogButtonBox; 30 class QPushButton; 31 class QTabWidget; 32 class QTreeWidget; 33 34 namespace Ui { 35 class TrafficTableDialog; 36 } 37 38 class TrafficTableTreeWidgetItem : public QTreeWidgetItem 39 { 40 public: TrafficTableTreeWidgetItem(QTreeWidget * tree)41 TrafficTableTreeWidgetItem(QTreeWidget *tree) : QTreeWidgetItem(tree) {} TrafficTableTreeWidgetItem(QTreeWidget * parent,const QStringList & strings)42 TrafficTableTreeWidgetItem(QTreeWidget *parent, const QStringList &strings) 43 : QTreeWidgetItem (parent, strings) {} 44 virtual QVariant colData(int col, bool resolve_names) const = 0; 45 }; 46 47 class TrafficTableTreeWidget : public QTreeWidget 48 { 49 Q_OBJECT 50 public: 51 explicit TrafficTableTreeWidget(QWidget *parent, register_ct_t* table); 52 53 // String, int, or double data for each column in a row. 54 // Passing -1 returns titles. 55 QList<QVariant> rowData(int row) const; 56 57 bool hasNameResolution() const; 58 59 public slots: 60 void setNameResolutionEnabled(bool enable); 61 62 // Title string plus optional count trafficTreeTitle()63 const QString &trafficTreeTitle() { return title_; } trafficTreeHash()64 conv_hash_t* trafficTreeHash() {return &hash_;} 65 66 protected: 67 register_ct_t* table_; 68 QString title_; 69 conv_hash_t hash_; 70 bool resolve_names_; 71 QMenu ctx_menu_; 72 73 // When adding rows, resize to contents up to this number. resizeThreshold()74 int resizeThreshold() const { return 200; } 75 void contextMenuEvent(QContextMenuEvent *event); 76 77 private: updateItems()78 virtual void updateItems() {} 79 80 private slots: 81 // Updates all items 82 void updateItemsForSettingChange(); 83 84 signals: 85 void titleChanged(QWidget *tree, const QString &text); 86 void filterAction(QString filter, FilterAction::Action action, FilterAction::ActionType type); 87 }; 88 89 class TrafficTableDialog : public WiresharkDialog 90 { 91 Q_OBJECT 92 Q_PROPERTY(bool absolute_start_time READ absoluteStartTime) 93 Q_PROPERTY(bool nanosecond_timestamps READ nanosecondTimestamps) 94 95 public: 96 /** Create a new conversation window. 97 * 98 * @param parent Parent widget. 99 * @param cf Capture file. No statistics will be calculated if this is NULL. 100 * @param filter Display filter to apply. 101 * @param table_name If valid, add this protocol and bring it to the front. 102 */ 103 explicit TrafficTableDialog(QWidget &parent, CaptureFile &cf, const char *filter = NULL, const QString &table_name = tr("Unknown")); 104 ~TrafficTableDialog(); 105 106 /** Use absolute start times. 107 * @return true if the "Absolute start time" checkbox is checked, false otherwise. 108 */ 109 bool absoluteStartTime(); 110 111 /** Use nanosecond timestamps. 112 * @return true if the current capture file uses nanosecond timestamps, false otherwise. 113 */ nanosecondTimestamps()114 bool nanosecondTimestamps() { return nanosecond_timestamps_; } 115 116 public slots: 117 118 signals: 119 void filterAction(QString filter, FilterAction::Action action, FilterAction::ActionType type); 120 void openFollowStreamDialog(follow_type_t type); 121 void openTcpStreamGraph(int graph_type); 122 123 protected: 124 Ui::TrafficTableDialog *ui; 125 126 // CaptureFile &cap_file_; 127 QString filter_; 128 QMenu traffic_type_menu_; 129 QPushButton *copy_bt_; 130 QMap<int, TrafficTableTreeWidget *> proto_id_to_tree_; 131 132 const QList<int> defaultProtos() const; 133 static gboolean fillTypeMenuFunc(const void *key, void *value, void *userdata); 134 void fillTypeMenu(QList<int> &enabled_protos); 135 // Adds a conversation tree. Returns true if the tree was freshly created, false if it was cached. addTrafficTable(register_ct_t *)136 virtual bool addTrafficTable(register_ct_t*) { return false; } 137 void addProgressFrame(QObject *parent); 138 139 // UI getters 140 QDialogButtonBox *buttonBox() const; 141 QTabWidget *trafficTableTabWidget() const; 142 QCheckBox *displayFilterCheckBox() const; 143 QCheckBox *nameResolutionCheckBox() const; 144 QCheckBox *absoluteTimeCheckBox() const; 145 QPushButton *enabledTypesPushButton() const; 146 147 protected slots: 148 virtual void currentTabChanged(); 149 void updateWidgets(); 150 151 private: 152 QString window_name_; 153 bool nanosecond_timestamps_; 154 155 QList<QVariant> curTreeRowData(int row) const; 156 157 158 private slots: 159 void on_nameResolutionCheckBox_toggled(bool checked); 160 void on_displayFilterCheckBox_toggled(bool checked); 161 void setTabText(QWidget *tree, const QString &text); 162 void toggleTable(); 163 void captureEvent(CaptureEvent e); 164 165 void copyAsCsv(); 166 void copyAsYaml(); 167 virtual void on_buttonBox_helpRequested() = 0; 168 }; 169 170 #endif // TRAFFIC_TABLE_DIALOG_H 171