1 /* wireshark_dialog.cpp
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
14 #include <epan/packet.h>
17 #include "main_application.h"
18 #include "wireshark_dialog.h"
19 #include <ui/qt/utils/qt_ui_utils.h>
20 #include "ui/recent.h"
21 #include "ui/ws_ui_util.h"
23 #include <QMessageBox>
27 // - Use a dynamic property + Q_PROPERTY for the subtitle.
28 // - Make our nested event loop more robust. See tryDeleteLater for details.
30 WiresharkDialog::WiresharkDialog(QWidget
&parent
, CaptureFile
&capture_file
) :
31 GeometryStateDialog(&parent
, Qt::Window
),
32 cap_file_(capture_file
),
37 setWindowIcon(mainApp
->normalIcon());
38 setWindowSubtitle(QString());
40 connect(&cap_file_
, &CaptureFile::captureEvent
, this, &WiresharkDialog::captureEvent
);
43 void WiresharkDialog::accept()
49 // XXX Should we do this in WiresharkDialog?
50 void WiresharkDialog::reject()
56 void WiresharkDialog::setWindowSubtitle(const QString
&subtitle
)
60 QString title
= mainApp
->windowTitleString(QStringList() << subtitle_
<< cap_file_
.fileTitle());
61 QDialog::setWindowTitle(title
);
64 // See if we can destroy ourselves. The user may have clicked "Close" while
65 // we were deep in the bowels of a routine that retaps packets. Track our
66 // tapping state using retap_depth_ and our closed state using dialog_closed_.
68 // The Delta Object Rules page on nested event loops:
70 // https://jblog.andbit.net/2007/04/28/delta-object-rules/
72 // effectively says "don't do that." However, we don't really have a choice
73 // if we want to have a usable application that retaps packets.
75 void WiresharkDialog::dialogCleanup(bool closeDialog
)
79 // Cancel any taps in progress?
80 // cap_file_.setCaptureStopFlag();
82 dialog_closed_
= true;
85 if (retap_depth_
< 1 && dialog_closed_
) {
86 // Is this disconnection necessary?
87 disconnect(&cap_file_
, &CaptureFile::captureEvent
, this, &WiresharkDialog::captureEvent
);
92 void WiresharkDialog::updateWidgets()
94 setWindowSubtitle(subtitle_
);
97 bool WiresharkDialog::registerTapListener(const char *tap_name
, void *tap_data
, const char *filter
, unsigned flags
, tap_reset_cb tap_reset
, tap_packet_cb tap_packet
, tap_draw_cb tap_draw
)
99 GString
*error_string
= register_tap_listener(tap_name
, tap_data
, filter
, flags
,
100 tap_reset
, tap_packet
, tap_draw
, NULL
);
102 QMessageBox::warning(this, tr("Failed to attach to tap \"%1\"").arg(tap_name
),
104 g_string_free(error_string
, TRUE
);
108 tap_listeners_
<< tap_data
;
112 void WiresharkDialog::captureEvent(CaptureEvent e
)
114 switch (e
.captureContext())
116 case CaptureEvent::Retap
:
117 switch (e
.eventType())
119 case CaptureEvent::Started
:
122 case CaptureEvent::Finished
:
129 case CaptureEvent::File
:
130 switch (e
.eventType())
132 case CaptureEvent::Closing
:
133 captureFileClosing();
135 case CaptureEvent::Closed
:
149 void WiresharkDialog::beginRetapPackets()
154 void WiresharkDialog::endRetapPackets()
160 void WiresharkDialog::removeTapListeners()
162 while (!tap_listeners_
.isEmpty()) {
163 remove_tap_listener(tap_listeners_
.takeFirst());
167 void WiresharkDialog::captureFileClosing()
169 removeTapListeners();
173 void WiresharkDialog::captureFileClosed()