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
42 #include "ui/ws_ui_util.h"
43 #include "ui/iface_toolbar.h"
45 #include "ui/capture_opts.h"
48 #include <epan/plugin_if.h>
49 #include <epan/timestamp.h>
51 #include <capture/capture_session.h>
53 #include <QMainWindow>
60 # include <QSocketNotifier>
63 #include "capture_file.h"
64 #include "capture_file_dialog.h"
65 #include "capture_file_properties_dialog.h"
66 #include <ui/qt/utils/field_information.h>
67 #include <ui/qt/widgets/display_filter_combo.h>
68 #include "main_window.h"
72 class CaptureOptionsDialog
;
76 class FunnelStatistics
;
78 class PacketCommentDialog
;
81 class FilterExpressionToolBar
;
82 class WiresharkApplication
;
88 class StratosharkMainWindow
;
91 Q_DECLARE_METATYPE(ts_type
)
92 Q_DECLARE_METATYPE(ts_precision
)
94 class StratosharkMainWindow
: public MainWindow
99 explicit StratosharkMainWindow(QWidget
*parent
= nullptr);
100 ~StratosharkMainWindow();
103 capture_session
*captureSession() { return &cap_session_
; }
104 info_data_t
*captureInfoData() { return &info_data_
; }
107 virtual QMenu
*createPopupMenu();
109 CaptureFile
*captureFile() { return &capture_file_
; }
111 void removeAdditionalToolbar(QString toolbarName
);
113 void addInterfaceToolbar(const iface_toolbar
*toolbar_entry
);
114 void removeInterfaceToolbar(const char *menu_title
);
116 QString
getMwFileName();
117 void setMwFileName(QString fileName
);
120 virtual bool eventFilter(QObject
*obj
, QEvent
*event
);
121 virtual bool event(QEvent
*event
);
122 virtual void keyPressEvent(QKeyEvent
*event
);
123 virtual void closeEvent(QCloseEvent
*event
);
124 virtual void dragEnterEvent(QDragEnterEvent
*event
);
125 virtual void dropEvent(QDropEvent
*event
);
126 virtual void changeEvent(QEvent
* event
);
129 // XXX Move to FilterUtils
131 MatchSelectedReplace
,
139 enum FileCloseContext
{
147 Ui::StratosharkMainWindow
*main_ui_
;
148 CaptureFile capture_file_
;
150 QMap
<QString
, QTextCodec
*> text_codec_map_
;
151 QWidget
*previous_focus_
;
152 FileSetDialog
*file_set_dialog_
;
153 QActionGroup
*show_hide_actions_
;
154 QActionGroup
*time_display_actions_
;
155 QActionGroup
*time_precision_actions_
;
156 FunnelStatistics
*funnel_statistics_
;
157 QList
<QPair
<QAction
*, bool> > freeze_actions_
;
158 QPointer
<QWidget
> freeze_focus_
;
159 QMap
<QAction
*, ts_type
> td_actions
;
160 QMap
<QAction
*, ts_precision
> tp_actions
;
163 /* the following values are maintained so that the capture file name and status
164 is available when there is no cf structure available */
167 bool capture_stopping_
;
168 bool capture_filter_valid_
;
169 bool use_capturing_title_
;
171 capture_session cap_session_
;
172 CaptureOptionsDialog
*capture_options_dialog_
;
173 info_data_t info_data_
;
176 #if defined(Q_OS_MAC)
180 #ifdef HAVE_SOFTWARE_UPDATE
181 QAction
*update_action_
;
184 QPoint dragStartPosition
;
189 void mergeCaptureFile();
190 void importCaptureFile();
191 bool saveCaptureFile(capture_file
*cf
, bool dont_reopen
);
192 bool saveAsCaptureFile(capture_file
*cf
, bool must_support_comments
= false, bool dont_reopen
= false);
193 void exportSelectedPackets();
194 void exportDissections(export_type_e export_type
);
197 void fileAddExtension(QString
&file_name
, int file_type
, wtap_compression_type compression_type
);
199 bool testCaptureFileClose(QString before_what
, FileCloseContext context
= Default
);
202 void findTextCodecs();
204 void initMainToolbarIcons();
205 void initShowHideMainWidgets();
206 void initTimeDisplayFormatMenu();
207 void initTimePrecisionFormatMenu();
208 void initFreezeActions();
210 void setMenusForCaptureFile(bool force_disable
= false);
211 void setMenusForCaptureInProgress(bool capture_in_progress
= false);
212 void setMenusForCaptureStopping();
213 void setForCapturedPackets(bool have_captured_packets
);
214 void setMenusForFileSet(bool enable_list_files
);
215 void setWindowIcon(const QIcon
&icon
);
216 void updateStyleSheet();
218 void externalMenuHelper(ext_menu_t
* menu
, QMenu
* subMenu
, int depth
);
220 void setForCaptureInProgress(bool capture_in_progress
= false, bool handle_toolbars
= false, GArray
*ifaces
= NULL
);
221 QMenu
* findOrAddMenu(QMenu
*parent_menu
, const QStringList
& menu_parts
);
223 void captureFileReadStarted(const QString
&action
);
225 void addMenuActions(QList
<QAction
*> &actions
, int menu_group
);
226 void removeMenuActions(QList
<QAction
*> &actions
, int menu_group
);
227 void goToConversationFrame(bool go_next
, bool start_current
= true);
228 void colorizeWithFilter(QByteArray filter
, int color_number
= -1);
231 void setDissectedCaptureFile(capture_file
*cf
);
232 void closePacketDialogs();
234 void packetInfoChanged(struct _packet_info
*pinfo
);
235 void fieldFilterChanged(const QByteArray field_filter
);
238 void showExtcapOptions(QString
&device_name
, bool startCaptureOnClose
);
242 // Qt lets you connect signals and slots using functors (new, manual style)
243 // and strings (old style). Functors are preferred since they're connected at
244 // compile time and less error prone.
246 // If you're manually connecting a signal to a slot, don't prefix its name
247 // with "on_". Otherwise Qt will try to automatically connect it and you'll
248 // get runtime warnings.
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();
270 void showCaptureOptionsDialog();
273 void captureCapturePrepared(capture_session
*);
274 void captureCaptureUpdateStarted(capture_session
*);
275 void captureCaptureUpdateFinished(capture_session
*);
276 void captureCaptureFixedFinished(capture_session
*cap_session
);
277 void captureCaptureFailed(capture_session
*);
280 void captureFileOpened();
281 void captureFileReadFinished();
282 void captureFileClosing();
283 void captureFileClosed();
287 void captureEventHandler(CaptureEvent ev
);
289 void initViewColorizeMenu();
290 void initConversationMenus();
291 static bool addFollowStreamMenuItem(const void *key
, void *value
, void *userdata
);
292 void initFollowStreamMenus();
294 // in main_window_slots.cpp
296 * @brief startCapture
297 * Start capturing from the selected interfaces using the capture filter
298 * shown in the main welcome screen.
300 void startCapture(QStringList
);
302 void pushLiveCaptureInProgress();
303 void popLiveCaptureInProgress();
306 void loadWindowGeometry();
307 void saveWindowGeometry();
308 void mainStackChanged(int);
309 void updateRecentCaptures();
310 void recentActionTriggered();
311 void addPacketComment();
312 void editPacketComment();
313 void deletePacketComment();
314 void deleteCommentsFromPackets();
315 QString
commentToMenuText(QString text
, int max_len
= 40);
316 void setEditCommentsMenu();
317 void setMenusForSelectedPacket();
318 void setMenusForSelectedTreeRow(FieldInformation
*fi
= NULL
);
319 void interfaceSelectionChanged();
320 void captureFilterSyntaxChanged(bool valid
);
321 void redissectPackets();
322 void checkDisplayFilter();
323 void fieldsChanged();
324 void reloadLuaPlugins();
325 void showAccordionFrame(AccordionFrame
*show_frame
, bool toggle
= false);
326 void showColumnEditor(int column
);
327 void showPreferenceEditor(); // module_t *, pref *
328 void addStatsPluginsToMenu();
329 void addDynamicMenus();
330 void reloadDynamicMenus();
331 void addPluginIFStructures();
332 QMenu
* searchSubMenu(QString objectName
);
333 void activatePluginIFToolbar(bool);
335 void startInterfaceCapture(bool valid
, const QString capture_filter
);
337 void applyGlobalCommandLineOptions();
338 void setFeaturesEnabled(bool enabled
= true);
340 void on_actionNewDisplayFilterExpression_triggered();
341 void onFilterSelected(QString
, bool);
342 void onFilterPreferences();
343 void onFilterEdit(int uatIndex
);
345 // Handle FilterAction signals
346 void queuedFilterAction(QString filter
, FilterAction::Action action
, FilterAction::ActionType type
);
348 /** Pass stat cmd arguments to a slot.
349 * @param menu_path slot Partial slot name, e.g. "StatisticsIOGraph".
350 * @param arg "-z" argument, e.g. "io,stat".
351 * @param userdata Optional user data.
353 void openStatCommandDialog(const QString
&menu_path
, const char *arg
, void *userdata
);
355 /** Pass tap parameter arguments to a slot.
356 * @param cfg_str slot Partial slot name, e.g. "StatisticsAFPSrt".
357 * @param arg "-z" argument, e.g. "afp,srt".
358 * @param userdata Optional user data.
360 void openTapParameterDialog(const QString cfg_str
, const QString arg
, void *userdata
);
361 void openTapParameterDialog();
363 #if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
364 void softwareUpdateRequested();
367 void connectFileMenuActions();
370 void connectEditMenuActions();
371 void copySelectedItems(StratosharkMainWindow::CopySelected selection_type
);
373 void editTimeShift();
374 void editConfigurationProfiles();
375 void editTimeShiftFinished(int);
376 void addPacketCommentFinished(PacketCommentDialog
* pc_dialog
, int result
);
377 void editPacketCommentFinished(PacketCommentDialog
* pc_dialog
, int result
, unsigned nComment
);
378 void deleteAllPacketComments();
379 void deleteAllPacketCommentsFinished(int result
);
380 void showPreferencesDialog(QString module_name
);
382 void connectViewMenuActions();
383 void showHideMainWidgets(QAction
*action
);
384 void setTimestampFormat(QAction
*action
);
385 void setTimestampPrecision(QAction
*action
);
386 void setTimeDisplaySecondsWithHoursAndMinutes(bool checked
);
387 void editResolvedName();
388 void setNameResolution();
390 void showColoringRulesDialog();
391 void colorizeConversation(bool create_rule
= false);
392 void colorizeActionTriggered();
393 void openPacketDialog(bool from_reference
= false);
394 void reloadCaptureFileAsFormatOrCapture();
395 void reloadCaptureFile();
397 void connectGoMenuActions();
399 void setPreviousFocus();
400 void resetPreviousFocus();
402 void connectCaptureMenuActions();
403 void startCaptureTriggered();
405 void connectAnalyzeMenuActions();
407 void matchFieldFilter(FilterAction::Action action
, FilterAction::ActionType filter_type
);
408 void applyFieldAsColumn();
410 void filterMenuAboutToShow();
412 void applyConversationFilter();
414 void openFollowStreamDialog(int proto_id
, unsigned stream_num
, unsigned sub_stream_num
, bool use_stream_index
= true);
415 void openFollowStreamDialog(int proto_id
);
417 void statCommandExpertInfo(const char *, void *);
419 void connectToolsMenuActions();
421 void connectHelpMenuActions();
423 #ifdef HAVE_SOFTWARE_UPDATE
424 void checkForUpdates();
427 void goToCancelClicked();
428 void goToGoClicked();
429 void goToLineEditReturnPressed();
431 void connectStatisticsMenuActions();
433 void showResolvedAddressesDialog();
434 void showConversationsDialog();
435 void showEndpointsDialog();
437 void openStatisticsTreeDialog(const char *abbr
);
438 void statCommandIOGraph(const char *, void *);
439 void showIOGraphDialog(io_graph_item_unit_t
, QString
);
441 void externalMenuItemTriggered();
443 void on_actionContextWikiProtocolPage_triggered();
444 void on_actionContextFilterFieldReference_triggered();
446 void extcap_options_finished(int result
);
447 void showExtcapOptionsDialog(QString
& device_name
, bool startCaptureOnClose
);
449 friend class MainApplication
;