3 * Stratoshark - System call and event log analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
12 /** @defgroup main_window_group Main window
13 * The main window has the following submodules:
15 digraph main_dependencies {
16 node [shape=record, fontname=Helvetica, fontsize=10];
17 main [ label="main window" URL="\ref main.h"];
18 menu [ label="menubar" URL="\ref menus.h"];
19 toolbar [ label="toolbar" URL="\ref main_toolbar.h"];
20 packet_list [ label="packet list pane" URL="\ref packet_list.h"];
21 proto_draw [ label="packet details & bytes panes" URL="\ref main_proto_draw.h"];
22 recent [ label="recent user settings" URL="\ref recent.h"];
23 main -> menu [ arrowhead="open", style="solid" ];
24 main -> toolbar [ arrowhead="open", style="solid" ];
25 main -> packet_list [ arrowhead="open", style="solid" ];
26 main -> proto_draw [ arrowhead="open", style="solid" ];
27 main -> recent [ arrowhead="open", style="solid" ];
33 * The Stratoshark main window
34 * @ingroup main_window_group
35 * @ingroup windows_group
44 #include "ui/ws_ui_util.h"
45 #include "ui/iface_toolbar.h"
47 #include <epan/plugin_if.h>
48 #include <epan/timestamp.h>
51 #include "capture_opts.h"
53 #include <capture/capture_session.h>
55 #include <QMainWindow>
62 # include <QSocketNotifier>
65 #include "capture_file.h"
66 #include "capture_file_dialog.h"
67 #include "capture_file_properties_dialog.h"
68 #include <ui/qt/utils/field_information.h>
69 #include <ui/qt/widgets/display_filter_combo.h>
70 #include "main_window.h"
74 class CaptureOptionsDialog
;
78 class FunnelStatistics
;
80 class PacketCommentDialog
;
83 class FilterExpressionToolBar
;
84 class WiresharkApplication
;
90 class StratosharkMainWindow
;
93 Q_DECLARE_METATYPE(ts_type
)
94 Q_DECLARE_METATYPE(ts_precision
)
96 class StratosharkMainWindow
: public MainWindow
101 explicit StratosharkMainWindow(QWidget
*parent
= nullptr);
102 ~StratosharkMainWindow();
105 capture_session
*captureSession() { return &cap_session_
; }
106 info_data_t
*captureInfoData() { return &info_data_
; }
109 virtual QMenu
*createPopupMenu();
111 CaptureFile
*captureFile() { return &capture_file_
; }
113 void removeAdditionalToolbar(QString toolbarName
);
115 void addInterfaceToolbar(const iface_toolbar
*toolbar_entry
);
116 void removeInterfaceToolbar(const char *menu_title
);
118 QString
getMwFileName();
119 void setMwFileName(QString fileName
);
122 virtual bool eventFilter(QObject
*obj
, QEvent
*event
);
123 virtual bool event(QEvent
*event
);
124 virtual void keyPressEvent(QKeyEvent
*event
);
125 virtual void closeEvent(QCloseEvent
*event
);
126 virtual void dragEnterEvent(QDragEnterEvent
*event
);
127 virtual void dropEvent(QDropEvent
*event
);
128 virtual void changeEvent(QEvent
* event
);
131 // XXX Move to FilterUtils
133 MatchSelectedReplace
,
141 enum FileCloseContext
{
149 Ui::StratosharkMainWindow
*main_ui_
;
150 CaptureFile capture_file_
;
152 QMap
<QString
, QTextCodec
*> text_codec_map_
;
153 QWidget
*previous_focus_
;
154 FileSetDialog
*file_set_dialog_
;
155 QActionGroup
*show_hide_actions_
;
156 QActionGroup
*time_display_actions_
;
157 QActionGroup
*time_precision_actions_
;
158 FunnelStatistics
*funnel_statistics_
;
159 QList
<QPair
<QAction
*, bool> > freeze_actions_
;
160 QPointer
<QWidget
> freeze_focus_
;
161 QMap
<QAction
*, ts_type
> td_actions
;
162 QMap
<QAction
*, ts_precision
> tp_actions
;
165 /* the following values are maintained so that the capture file name and status
166 is available when there is no cf structure available */
169 bool capture_stopping_
;
170 bool capture_filter_valid_
;
171 bool use_capturing_title_
;
173 capture_session cap_session_
;
174 CaptureOptionsDialog
*capture_options_dialog_
;
175 info_data_t info_data_
;
178 #if defined(Q_OS_MAC)
182 #ifdef HAVE_SOFTWARE_UPDATE
183 QAction
*update_action_
;
186 QPoint dragStartPosition
;
191 void mergeCaptureFile();
192 void importCaptureFile();
193 bool saveCaptureFile(capture_file
*cf
, bool dont_reopen
);
194 bool saveAsCaptureFile(capture_file
*cf
, bool must_support_comments
= false, bool dont_reopen
= false);
195 void exportSelectedPackets();
196 void exportDissections(export_type_e export_type
);
199 void fileAddExtension(QString
&file_name
, int file_type
, wtap_compression_type compression_type
);
201 bool testCaptureFileClose(QString before_what
, FileCloseContext context
= Default
);
204 void findTextCodecs();
206 void initMainToolbarIcons();
207 void initShowHideMainWidgets();
208 void initTimeDisplayFormatMenu();
209 void initTimePrecisionFormatMenu();
210 void initFreezeActions();
212 void setTitlebarForCaptureInProgress();
213 void setMenusForCaptureFile(bool force_disable
= false);
214 void setMenusForCaptureInProgress(bool capture_in_progress
= false);
215 void setMenusForCaptureStopping();
216 void setForCapturedPackets(bool have_captured_packets
);
217 void setMenusForFileSet(bool enable_list_files
);
218 void setWindowIcon(const QIcon
&icon
);
219 QString
replaceWindowTitleVariables(QString title
);
220 void updateStyleSheet();
222 void externalMenuHelper(ext_menu_t
* menu
, QMenu
* subMenu
, int depth
);
224 void setForCaptureInProgress(bool capture_in_progress
= false, bool handle_toolbars
= false, GArray
*ifaces
= NULL
);
225 QMenu
* findOrAddMenu(QMenu
*parent_menu
, const QStringList
& menu_parts
);
227 void captureFileReadStarted(const QString
&action
);
229 void addMenuActions(QList
<QAction
*> &actions
, int menu_group
);
230 void removeMenuActions(QList
<QAction
*> &actions
, int menu_group
);
231 void goToConversationFrame(bool go_next
);
232 void colorizeWithFilter(QByteArray filter
, int color_number
= -1);
235 void setDissectedCaptureFile(capture_file
*cf
);
236 void closePacketDialogs();
238 void packetInfoChanged(struct _packet_info
*pinfo
);
239 void fieldFilterChanged(const QByteArray field_filter
);
241 void fieldHighlight(FieldInformation
*);
243 void captureActive(int);
246 void showExtcapOptions(QString
&device_name
, bool startCaptureOnClose
);
250 // in main_window_slots.cpp
252 * Open a capture file.
253 * @param cf_path Path to the file.
254 * @param display_filter Display filter to apply. May be empty.
255 * @param type File type.
256 * @param is_tempfile true/false.
257 * @return True on success, false on failure.
259 // XXX We might want to return a cf_read_status_t or a CaptureFile.
260 bool openCaptureFile(QString cf_path
, QString display_filter
, unsigned int type
, bool is_tempfile
= false);
261 bool openCaptureFile(QString cf_path
= QString(), QString display_filter
= QString()) { return openCaptureFile(cf_path
, display_filter
, WTAP_TYPE_AUTO
); }
262 void filterPackets(QString new_filter
= QString(), bool force
= false);
263 void updateForUnsavedChanges();
264 void layoutToolbars();
265 void updatePreferenceActions();
266 void updateRecentActions();
268 void setTitlebarForCaptureFile();
269 void setWSWindowTitle(QString title
= QString());
271 void showCaptureOptionsDialog();
274 void captureCapturePrepared(capture_session
*);
275 void captureCaptureUpdateStarted(capture_session
*);
276 void captureCaptureUpdateFinished(capture_session
*);
277 void captureCaptureFixedFinished(capture_session
*cap_session
);
278 void captureCaptureFailed(capture_session
*);
281 void captureFileOpened();
282 void captureFileReadFinished();
283 void captureFileClosing();
284 void captureFileClosed();
288 void captureEventHandler(CaptureEvent ev
);
290 // Manually connected slots (no "on_<object>_<signal>").
292 void initViewColorizeMenu();
293 void initConversationMenus();
294 static bool addFollowStreamMenuItem(const void *key
, void *value
, void *userdata
);
295 void initFollowStreamMenus();
297 // in main_window_slots.cpp
299 * @brief startCapture
300 * Start capturing from the selected interfaces using the capture filter
301 * shown in the main welcome screen.
303 void startCapture(QStringList
);
305 void pushLiveCaptureInProgress();
306 void popLiveCaptureInProgress();
309 void loadWindowGeometry();
310 void saveWindowGeometry();
311 void mainStackChanged(int);
312 void updateRecentCaptures();
313 void recentActionTriggered();
314 void addPacketComment();
315 void editPacketComment();
316 void deletePacketComment();
317 void deleteCommentsFromPackets();
318 QString
commentToMenuText(QString text
, int max_len
= 40);
319 void setEditCommentsMenu();
320 void setMenusForSelectedPacket();
321 void setMenusForSelectedTreeRow(FieldInformation
*fi
= NULL
);
322 void interfaceSelectionChanged();
323 void captureFilterSyntaxChanged(bool valid
);
324 void redissectPackets();
325 void checkDisplayFilter();
326 void fieldsChanged();
327 void reloadLuaPlugins();
328 void showAccordionFrame(AccordionFrame
*show_frame
, bool toggle
= false);
329 void showColumnEditor(int column
);
330 void showPreferenceEditor(); // module_t *, pref *
331 void addStatsPluginsToMenu();
332 void addDynamicMenus();
333 void reloadDynamicMenus();
334 void addPluginIFStructures();
335 QMenu
* searchSubMenu(QString objectName
);
336 void activatePluginIFToolbar(bool);
337 void updateTitlebar();
339 void startInterfaceCapture(bool valid
, const QString capture_filter
);
341 void applyGlobalCommandLineOptions();
342 void setFeaturesEnabled(bool enabled
= true);
344 void on_actionNewDisplayFilterExpression_triggered();
345 void onFilterSelected(QString
, bool);
346 void onFilterPreferences();
347 void onFilterEdit(int uatIndex
);
349 // Handle FilterAction signals
350 void queuedFilterAction(QString filter
, FilterAction::Action action
, FilterAction::ActionType type
);
352 /** Pass stat cmd arguments to a slot.
353 * @param menu_path slot Partial slot name, e.g. "StatisticsIOGraph".
354 * @param arg "-z" argument, e.g. "io,stat".
355 * @param userdata Optional user data.
357 void openStatCommandDialog(const QString
&menu_path
, const char *arg
, void *userdata
);
359 /** Pass tap parameter arguments to a slot.
360 * @param cfg_str slot Partial slot name, e.g. "StatisticsAFPSrt".
361 * @param arg "-z" argument, e.g. "afp,srt".
362 * @param userdata Optional user data.
364 void openTapParameterDialog(const QString cfg_str
, const QString arg
, void *userdata
);
365 void openTapParameterDialog();
367 #if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
368 void softwareUpdateRequested();
371 // Automatically connected slots ("on_<object>_<signal>").
373 // The slots below follow the naming conventaion described in
374 // https://doc.qt.io/archives/qt-4.8/qmetaobject.html#connectSlotsByName
375 // and are automatically connected at initialization time via
376 // main_ui_->setupUi, which in turn calls connectSlotsByName.
378 // If you're manually connecting a signal to a slot, don't prefix its name
379 // with "on_". Otherwise you'll get runtime warnings.
381 // We might want move these to main_window_actions.cpp similar to
382 // gtk/main_menubar.c
384 void connectFileMenuActions();
387 void connectEditMenuActions();
388 void copySelectedItems(StratosharkMainWindow::CopySelected selection_type
);
390 void editTimeShift();
391 void editConfigurationProfiles();
392 void editTimeShiftFinished(int);
393 void addPacketCommentFinished(PacketCommentDialog
* pc_dialog
, int result
);
394 void editPacketCommentFinished(PacketCommentDialog
* pc_dialog
, int result
, unsigned nComment
);
395 void deleteAllPacketComments();
396 void deleteAllPacketCommentsFinished(int result
);
397 void showPreferencesDialog(QString module_name
);
399 void connectViewMenuActions();
400 void showHideMainWidgets(QAction
*action
);
401 void setTimestampFormat(QAction
*action
);
402 void setTimestampPrecision(QAction
*action
);
403 void setTimeDisplaySecondsWithHoursAndMinutes(bool checked
);
404 void editResolvedName();
405 void setNameResolution();
407 void showColoringRulesDialog();
408 void colorizeConversation(bool create_rule
= false);
409 void colorizeActionTriggered();
410 void openPacketDialog(bool from_reference
= false);
411 void reloadCaptureFileAsFormatOrCapture();
412 void reloadCaptureFile();
414 void connectGoMenuActions();
416 void setPreviousFocus();
417 void resetPreviousFocus();
419 void connectCaptureMenuActions();
420 void startCaptureTriggered();
422 void connectAnalyzeMenuActions();
424 void matchFieldFilter(FilterAction::Action action
, FilterAction::ActionType filter_type
);
425 void applyFieldAsColumn();
427 void filterMenuAboutToShow();
429 void applyConversationFilter();
431 void openFollowStreamDialog(int proto_id
, unsigned stream_num
, unsigned sub_stream_num
, bool use_stream_index
= true);
432 void openFollowStreamDialog(int proto_id
);
434 void statCommandExpertInfo(const char *, void *);
436 void connectToolsMenuActions();
438 void connectHelpMenuActions();
440 #ifdef HAVE_SOFTWARE_UPDATE
441 void checkForUpdates();
444 void goToCancelClicked();
445 void goToGoClicked();
446 void goToLineEditReturnPressed();
448 void connectStatisticsMenuActions();
450 void showResolvedAddressesDialog();
451 void showConversationsDialog();
452 void showEndpointsDialog();
454 void openStatisticsTreeDialog(const char *abbr
);
455 void statCommandIOGraph(const char *, void *);
456 void showIOGraphDialog(io_graph_item_unit_t
, QString
);
458 void externalMenuItemTriggered();
460 void on_actionContextWikiProtocolPage_triggered();
461 void on_actionContextFilterFieldReference_triggered();
463 void extcap_options_finished(int result
);
464 void showExtcapOptionsDialog(QString
& device_name
, bool startCaptureOnClose
);
466 friend class MainApplication
;