Kerberos: add kerberos_inject_longterm_key() helper function
[wireshark-sm.git] / ui / qt / wireshark_dialog.cpp
blobd7609f1b3c4bd2e9854f25f05a28059c912593f9
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
8 */
10 #include "config.h"
12 #include "cfile.h"
14 #include <epan/packet.h>
15 #include <epan/tap.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>
26 // To do:
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),
33 file_closed_(false),
34 retap_depth_(0),
35 dialog_closed_(false)
37 setWindowIcon(mainApp->normalIcon());
38 setWindowSubtitle(QString());
40 connect(&cap_file_, &CaptureFile::captureEvent, this, &WiresharkDialog::captureEvent);
43 void WiresharkDialog::accept()
45 QDialog::accept();
46 dialogCleanup(true);
49 // XXX Should we do this in WiresharkDialog?
50 void WiresharkDialog::reject()
52 QDialog::reject();
53 dialogCleanup(true);
56 void WiresharkDialog::setWindowSubtitle(const QString &subtitle)
58 subtitle_ = 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)
77 if (closeDialog)
79 // Cancel any taps in progress?
80 // cap_file_.setCaptureStopFlag();
81 removeTapListeners();
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);
88 deleteLater();
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);
101 if (error_string) {
102 QMessageBox::warning(this, tr("Failed to attach to tap \"%1\"").arg(tap_name),
103 error_string->str);
104 g_string_free(error_string, TRUE);
105 return false;
108 tap_listeners_ << tap_data;
109 return true;
112 void WiresharkDialog::captureEvent(CaptureEvent e)
114 switch (e.captureContext())
116 case CaptureEvent::Retap:
117 switch (e.eventType())
119 case CaptureEvent::Started:
120 beginRetapPackets();
121 break;
122 case CaptureEvent::Finished:
123 endRetapPackets();
124 break;
125 default:
126 break;
128 break;
129 case CaptureEvent::File:
130 switch (e.eventType())
132 case CaptureEvent::Closing:
133 captureFileClosing();
134 break;
135 case CaptureEvent::Closed:
136 file_closed_ = true;
137 captureFileClosed();
138 break;
139 default:
140 break;
142 break;
143 default:
144 break;
149 void WiresharkDialog::beginRetapPackets()
151 retap_depth_++;
154 void WiresharkDialog::endRetapPackets()
156 retap_depth_--;
157 dialogCleanup();
160 void WiresharkDialog::removeTapListeners()
162 while (!tap_listeners_.isEmpty()) {
163 remove_tap_listener(tap_listeners_.takeFirst());
167 void WiresharkDialog::captureFileClosing()
169 removeTapListeners();
170 updateWidgets();
173 void WiresharkDialog::captureFileClosed()
175 updateWidgets();