1 /* display_filter_edit.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 DISPLAYFILTEREDIT_H
11 #define DISPLAYFILTEREDIT_H
12 
13 #include <QDrag>
14 #include <QActionGroup>
15 
16 #include <ui/qt/widgets/syntax_line_edit.h>
17 
18 class QEvent;
19 class StockIconToolButton;
20 
21 typedef enum {
22     DisplayFilterToApply,
23     DisplayFilterToEnter,
24     ReadFilterToApply
25 } DisplayFilterEditType;
26 
27 class DisplayFilterEdit : public SyntaxLineEdit
28 {
29     Q_OBJECT
30 public:
31     explicit DisplayFilterEdit(QWidget *parent = 0, DisplayFilterEditType type = DisplayFilterToEnter);
32 
33 protected:
34     void paintEvent(QPaintEvent *evt);
35     void resizeEvent(QResizeEvent *);
keyPressEvent(QKeyEvent * event)36     void keyPressEvent(QKeyEvent *event) { completionKeyPressEvent(event); }
focusInEvent(QFocusEvent * event)37     void focusInEvent(QFocusEvent *event) { completionFocusInEvent(event); }
38     void focusOutEvent(QFocusEvent *event);
39 
40     virtual void dragEnterEvent(QDragEnterEvent *event);
41     virtual void dragMoveEvent(QDragMoveEvent *event);
42     virtual void dropEvent(QDropEvent *event);
43     virtual void contextMenuEvent(QContextMenuEvent *menu);
44 
45 public slots:
46     bool checkFilter();
47     void updateBookmarkMenu();
48     void applyDisplayFilter();
49     void displayFilterSuccess(bool success);
50 
51 private slots:
52     void checkFilter(const QString &filter_text);
53     void clearFilter();
54     void changeEvent(QEvent* event);
55 
56     void displayFilterExpression();
57 
58     void saveFilter();
59     void removeFilter();
60     void showFilters();
61     void showExpressionPrefs();
62     void applyOrPrepareFilter();
63 
64     void triggerAlignementAction();
65 
66     void connectToMainWindow();
67 
68 private:
69     DisplayFilterEditType type_;
70     QString placeholder_text_;
71     QAction *save_action_;
72     QAction *remove_action_;
73     QActionGroup * actions_;
74     StockIconToolButton *bookmark_button_;
75     StockIconToolButton *clear_button_;
76     StockIconToolButton *apply_button_;
77     bool leftAlignActions_;
78     QString last_applied_;
79 
80     void setDefaultPlaceholderText();
81     void buildCompletionList(const QString& field_word);
82 
83     void createFilterTextDropMenu(QDropEvent *event, bool prepare, QString filterText = QString());
84 
85     void alignActionButtons();
86     void updateClearButton();
87 
88 signals:
89     void pushFilterSyntaxStatus(const QString&);
90     void popFilterSyntaxStatus();
91     void filterPackets(QString new_filter, bool force);
92     void showPreferencesDialog(QString pane_name);
93 
94 };
95 
96 #endif // DISPLAYFILTEREDIT_H
97