3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #ifndef WIRESHARK_DIALOG_H
11 #define WIRESHARK_DIALOG_H
14 * @file General dialog base class
16 * Base class which provides convenience methods for dialogs that handle
19 * This class attempts to destroy itself when closed. Doing this safely and
20 * properly can be a bit tricky while scanning and tapping packets since
23 // "General" is a misnomer but we already have a class named
24 // "CaptureFileDialog". Suggestions for a better name from
25 // https://code.wireshark.org/review/#/c/9739/:
26 // BaseCaptureDialog, CaptureHelperDialog (or rename CaptureFileDialog to something else - WiresharkFileDialog).
27 // TapDialog might make sense as well.
31 #include "capture_file.h"
32 #include "geometry_state_dialog.h"
34 class WiresharkDialog
: public GeometryStateDialog
39 // XXX Unlike the entire QWidget API, parent is mandatory here.
40 explicit WiresharkDialog(QWidget
&parent
, CaptureFile
&capture_file
);
43 * @brief true if the file has been closed, false otherwise.
45 bool fileClosed() const { return file_closed_
; }
48 virtual void keyPressEvent(QKeyEvent
*event
) { QDialog::keyPressEvent(event
); }
49 virtual void accept();
50 virtual void reject();
53 * @brief Mark the start of a code block that retaps packets. If the user
54 * closes the dialog while tapping, the dialog will not be destroyed until
55 * endRetapPackets is called.
57 * This is automatically called when tapping begins, but might need to be
58 * called explicilty if any member functions are called or variables are
59 * accessed after tapping is finished.
62 void beginRetapPackets();
64 * @brief Mark the end of a code block that retaps packets. If the user
65 * has closed the dialog it will be desroyed at this point.
67 * This is automatically called when tapping ends, but might need to be
68 * called explicilty if any member functions are called or variables are
69 * accessed after tapping is finished.
71 virtual void endRetapPackets();
74 * @brief Set the window subtitle, e.g. "Foo Timeouts". The subtitle and
75 * file name will be added to the dialog window title.
76 * @param subtitle The subtitle to add. It should be unique, short, and
79 void setWindowSubtitle(const QString
&subtitle
);
80 const QString
&windowSubtitle() { return subtitle_
; }
81 virtual void updateWidgets();
83 // Capture file and tapping
84 CaptureFile
&cap_file_
;
86 * @brief Convenience wrapper for register_tap_listener. Tap
87 * listeners registered via this function are automatically
88 * removed during destruction. They can also be explicitly
89 * removed using remove_tap_listener or removeTapListeners.
91 * Shows a warning dialog if registration is unsuccessful.
92 * @param tap_name A registered tap name.
93 * @param tap_data A unique pointer. Usually 'this'.
94 * @param filter A display filter.
95 * @param flags See register_tap_listener.
96 * @param tap_reset Reset callback.
97 * @param tap_packet Per-packet callback.
98 * @param tap_draw Draw callback.
100 bool registerTapListener(const char *tap_name
, void *tap_data
,
101 const char *filter
, unsigned flags
,
102 tap_reset_cb tap_reset
,
103 tap_packet_cb tap_packet
,
104 tap_draw_cb tap_draw
);
107 * @brief Remove all tap listeners registered via registerTapListener.
109 virtual void removeTapListeners();
111 // XXX - Move this to private, have subclasses use the getter?
115 * @brief Check to see if the user has closed (and not minimized) the dialog.
116 * @return true if the dialog has been closed, false otherwise.
118 bool dialogClosed() const { return dialog_closed_
; }
121 * @brief Check to see if we're currently retapping. If this is positive,
122 * tapping will fail in process_specified_records.
123 * @return The current retap depth. (In current implementation, 0 or 1.)
125 int retapDepth() const { return retap_depth_
; }
128 * @brief Called when the capture file is about to close. This can be
129 * used to disconnect taps and similar actions.
130 * updateWidgets() is called at the end.
131 * To enable/disable widgets captureFileClosed() is more suitable.
133 virtual void captureFileClosing();
136 * @brief Called when the capture file was closed. This can be
137 * used to enable or disable widgets according to the state of
139 * updateWidgets() is called at the end.
141 virtual void captureFileClosed();
144 void captureEvent(CaptureEvent
);
147 void dialogCleanup(bool closeDialog
= false);
150 QList
<void *> tap_listeners_
;
157 #endif // WIRESHARK_DIALOG_H