summaryrefslogtreecommitdiffstats
path: root/ui/qt/widgets/traffic_tree.h
blob: 5bc87e91b0eb0e23555a7e24545a3e2402559aaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/** @file
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef TRAFFIC_TREE_H
#define TRAFFIC_TREE_H

#include "config.h"

#include <glib.h>

#include <ui/recent.h>

#include <ui/qt/models/atap_data_model.h>
#include <ui/qt/filter_action.h>

#include <QTreeView>
#include <QMenu>
#include <QHeaderView>
#include <QSortFilterProxyModel>

#include <QWidgetAction>
#include <QLineEdit>
#include <QActionGroup>

class MenuEditAction : public QWidgetAction
{
    Q_OBJECT
public:
    MenuEditAction(QString text, QString hintText, QObject * parent = nullptr);

    QString text() const;

protected:
    virtual QWidget * createWidget(QWidget *parent);
private:
    QString _hintText;
    QString _text;
    QLineEdit * _lineEdit;

private slots:
    void triggerEntry();
};


class TrafficTreeHeaderView : public QHeaderView
{
    Q_OBJECT
public:
    TrafficTreeHeaderView(GList ** recentColumnList, QWidget * parent = nullptr);
    ~TrafficTreeHeaderView();

    void applyRecent();

signals:
    void columnsHaveChanged(QList<int> visible);
    void filterOnColumn(int column, int filterOn, QString filterText);
private:
    GList ** _recentColumnList;
    QActionGroup * _actions;
    QString _filterText;

private slots:
    void headerContextMenu(const QPoint &pos);
    void columnTriggered(bool checked = false);
    void menuActionTriggered(QAction *);
    void filterColumn(bool checked = false);

};


class TrafficDataFilterProxy : public QSortFilterProxyModel
{
    Q_OBJECT
public:

    enum {
        TRAFFIC_DATA_LESS,
        TRAFFIC_DATA_GREATER,
        TRAFFIC_DATA_EQUAL,
    };

    TrafficDataFilterProxy(QObject *parent = nullptr);

    void setColumnVisibility(int column, bool visible);
    bool columnVisible(int column) const;

public slots:
    void filterForColumn(int column, int filterOn, QString filterText);

protected:
    virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
    virtual bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const;
    virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;

private:
    QList<int> hideColumns_;

    int _filterColumn;
    int _filterOn;
    QString _filterText;

    int mapToSourceColumn(int proxyColumn) const;

};


class TrafficTree : public QTreeView
{
    Q_OBJECT

public:
    /**
     * @brief Type for the selection of export
     * @see copyToClipboard
     */
    typedef enum {
        CLIPBOARD_CSV,  /* export as CSV */
        CLIPBOARD_YAML, /* export as YAML */
        CLIPBOARD_JSON  /* export as JSON */
    } eTrafficTreeClipboard;

    TrafficTree(QString baseName, GList ** recentColumnList, QWidget *parent = nullptr);

    /**
     * @brief Create a menu containing clipboard copy entries for this tab
     *
     * It will create all entries, including copying the content of the currently selected tab
     * to CSV, YAML and JSON
     *
     * @param parent the parent object or null
     * @return QMenu* the resulting menu or null
     */
    QMenu * createCopyMenu(QWidget * parent = nullptr);

    void applyRecentColumns();

    virtual void setModel(QAbstractItemModel *model) override;

signals:
    void filterAction(QString filter, FilterAction::Action action, FilterAction::ActionType type);
    void columnsHaveChanged(QList<int> columns);

public slots:
    void tapListenerEnabled(bool enable);
    void disableTap();
    void columnsChanged(QList<int> columns);

private:
    bool _tapEnabled;
    int _exportRole;
    bool _saveRaw;
    QString _baseName;

    TrafficTreeHeaderView * _header;

    ATapDataModel * dataModel();

    QMenu * createActionSubMenu(FilterAction::Action cur_action, QModelIndex idx, bool isConversation);
    void copyToClipboard(eTrafficTreeClipboard type);

    friend class TrafficTreeHeaderView;

private slots:
    void customContextMenu(const QPoint &pos);
    void useFilterAction();
    void clipboardAction();
    void resizeAction();
    void toggleSaveRawAction();
};

#endif // TRAFFIC_TREE_H