Wireshark  4.3.0
The Wireshark network protocol analyzer
logray_main_window.h
Go to the documentation of this file.
1 
10 #ifndef LOGRAY_MAIN_WINDOW_H
11 #define LOGRAY_MAIN_WINDOW_H
12 
39 #include <stdio.h>
40 
41 #include <config.h>
42 
43 #include "file.h"
44 
45 #include "ui/ws_ui_util.h"
46 #include "ui/iface_toolbar.h"
47 
48 #include <epan/plugin_if.h>
49 #include <epan/timestamp.h>
50 
51 #ifdef HAVE_LIBPCAP
52 #include "capture_opts.h"
53 #endif
55 
56 #include <QMainWindow>
57 #include <QPointer>
58 #include <QTextCodec>
59 
60 #ifdef _WIN32
61 # include <QTimer>
62 #else
63 # include <QSocketNotifier>
64 #endif
65 
66 #include "capture_file.h"
67 #include "capture_file_dialog.h"
71 #include "main_window.h"
72 
73 class AccordionFrame;
74 class ByteViewTab;
75 class CaptureOptionsDialog;
76 class PrintDialog;
77 class FileSetDialog;
78 class FilterDialog;
79 class FunnelStatistics;
80 class WelcomePage;
82 class PacketList;
83 class ProtoTree;
86 
87 class QAction;
88 class QActionGroup;
89 
90 namespace Ui {
91  class LograyMainWindow;
92 }
93 
94 Q_DECLARE_METATYPE(ts_type)
95 Q_DECLARE_METATYPE(ts_precision)
96 
98 {
99  Q_OBJECT
100 
101 public:
102  explicit LograyMainWindow(QWidget *parent = nullptr);
103  ~LograyMainWindow();
104 
105 #ifdef HAVE_LIBPCAP
106  capture_session *captureSession() { return &cap_session_; }
107  info_data_t *captureInfoData() { return &info_data_; }
108 #endif
109 
110  virtual QMenu *createPopupMenu();
111 
112  CaptureFile *captureFile() { return &capture_file_; }
113 
114  void removeAdditionalToolbar(QString toolbarName);
115 
116  void addInterfaceToolbar(const iface_toolbar *toolbar_entry);
117  void removeInterfaceToolbar(const char *menu_title);
118 
119  QString getMwFileName();
120  void setMwFileName(QString fileName);
121 
122 protected:
123  virtual bool eventFilter(QObject *obj, QEvent *event);
124  virtual bool event(QEvent *event);
125  virtual void keyPressEvent(QKeyEvent *event);
126  virtual void closeEvent(QCloseEvent *event);
127  virtual void dragEnterEvent(QDragEnterEvent *event);
128  virtual void dropEvent(QDropEvent *event);
129  virtual void changeEvent(QEvent* event);
130 
131 private:
132  // XXX Move to FilterUtils
133  enum MatchSelected {
134  MatchSelectedReplace,
135  MatchSelectedAnd,
136  MatchSelectedOr,
137  MatchSelectedNot,
138  MatchSelectedAndNot,
139  MatchSelectedOrNot
140  };
141 
142  enum FileCloseContext {
143  Default,
144  Quit,
145  Restart,
146  Reload,
147  Update
148  };
149 
150  Ui::LograyMainWindow *main_ui_;
151  CaptureFile capture_file_;
152  QFont mono_font_;
153  QMap<QString, QTextCodec *> text_codec_map_;
154  QWidget *previous_focus_;
155  FileSetDialog *file_set_dialog_;
156  QActionGroup *show_hide_actions_;
157  QActionGroup *time_display_actions_;
158  QActionGroup *time_precision_actions_;
159  FunnelStatistics *funnel_statistics_;
160  QList<QPair<QAction *, bool> > freeze_actions_;
161  QPointer<QWidget> freeze_focus_;
162  QMap<QAction *, ts_type> td_actions;
163  QMap<QAction *, ts_precision> tp_actions;
164  bool was_maximized_;
165 
166  /* the following values are maintained so that the capture file name and status
167  is available when there is no cf structure available */
168  QString mwFileName_;
169 
170  bool capture_stopping_;
171  bool capture_filter_valid_;
172  bool use_capturing_title_;
173 #ifdef HAVE_LIBPCAP
174  capture_session cap_session_;
175  CaptureOptionsDialog *capture_options_dialog_;
176  info_data_t info_data_;
177 #endif
178 
179 #if defined(Q_OS_MAC)
180  QMenu *dock_menu_;
181 #endif
182 
183 #ifdef HAVE_SOFTWARE_UPDATE
184  QAction *update_action_;
185 #endif
186 
187  QPoint dragStartPosition;
188 
189  void freeze();
190  void thaw();
191 
192  void mergeCaptureFile();
193  void importCaptureFile();
194  bool saveCaptureFile(capture_file *cf, bool dont_reopen);
195  bool saveAsCaptureFile(capture_file *cf, bool must_support_comments = false, bool dont_reopen = false);
196  void exportSelectedPackets();
197  void exportDissections(export_type_e export_type);
198 
199 #ifdef Q_OS_WIN
200  void fileAddExtension(QString &file_name, int file_type, wtap_compression_type compression_type);
201 #endif // Q_OS_WIN
202  bool testCaptureFileClose(QString before_what, FileCloseContext context = Default);
203  void captureStop();
204 
205  void findTextCodecs();
206 
207  void initMainToolbarIcons();
208  void initShowHideMainWidgets();
209  void initTimeDisplayFormatMenu();
210  void initTimePrecisionFormatMenu();
211  void initFreezeActions();
212 
213  void setTitlebarForCaptureInProgress();
214  void setMenusForCaptureFile(bool force_disable = false);
215  void setMenusForCaptureInProgress(bool capture_in_progress = false);
216  void setMenusForCaptureStopping();
217  void setForCapturedPackets(bool have_captured_packets);
218  void setMenusForFileSet(bool enable_list_files);
219  void setWindowIcon(const QIcon &icon);
220  QString replaceWindowTitleVariables(QString title);
221 
222  void externalMenuHelper(ext_menu_t * menu, QMenu * subMenu, int depth);
223 
224  void setForCaptureInProgress(bool capture_in_progress = false, bool handle_toolbars = false, GArray *ifaces = NULL);
225  QMenu* findOrAddMenu(QMenu *parent_menu, QString& menu_text);
226 
227  void captureFileReadStarted(const QString &action);
228 
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);
233 
234 signals:
235  void setDissectedCaptureFile(capture_file *cf);
236  void closePacketDialogs();
237  void reloadFields();
238  void packetInfoChanged(struct _packet_info *pinfo);
239  void fieldFilterChanged(const QByteArray field_filter);
240 
241  void fieldHighlight(FieldInformation *);
242 
243  void captureActive(int);
244 
245 #ifdef HAVE_LIBPCAP
246  void showExtcapOptions(QString &device_name, bool startCaptureOnClose);
247 #endif
248 
249 public slots:
250  // in main_window_slots.cpp
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();
267 
268  void setTitlebarForCaptureFile();
269  void setWSWindowTitle(QString title = QString());
270 
271  void showCaptureOptionsDialog();
272 
273 #ifdef HAVE_LIBPCAP
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 *);
279 #endif
280 
281  void captureFileOpened();
282  void captureFileReadFinished();
283  void captureFileClosing();
284  void captureFileClosed();
285 
286 private slots:
287 
288  void captureEventHandler(CaptureEvent ev);
289 
290  // Manually connected slots (no "on_<object>_<signal>").
291 
292  void initViewColorizeMenu();
293  void initConversationMenus();
294  static bool addFollowStreamMenuItem(const void *key, void *value, void *userdata);
295  void initFollowStreamMenus();
296 
297  // in main_window_slots.cpp
303  void startCapture(QStringList);
304  void startCapture();
305  void popLiveCaptureInProgress();
306  void stopCapture();
307 
308  void loadWindowGeometry();
309  void saveWindowGeometry();
310  void mainStackChanged(int);
311  void updateRecentCaptures();
312  void recentActionTriggered();
313  void addPacketComment();
314  void editPacketComment();
315  void deletePacketComment();
316  void deleteCommentsFromPackets();
317  QString commentToMenuText(QString text, int max_len = 40);
318  void setEditCommentsMenu();
319  void setMenusForSelectedPacket();
320  void setMenusForSelectedTreeRow(FieldInformation *fi = NULL);
321  void interfaceSelectionChanged();
322  void captureFilterSyntaxChanged(bool valid);
323  void redissectPackets();
324  void checkDisplayFilter();
325  void fieldsChanged();
326  void reloadLuaPlugins();
327  void showAccordionFrame(AccordionFrame *show_frame, bool toggle = false);
328  void showColumnEditor(int column);
329  void showPreferenceEditor(); // module_t *, pref *
330  void addStatsPluginsToMenu();
331  void addDynamicMenus();
332  void reloadDynamicMenus();
333  void addPluginIFStructures();
334  QMenu * searchSubMenu(QString objectName);
335  void activatePluginIFToolbar(bool);
336  void updateTitlebar();
337 
338  void startInterfaceCapture(bool valid, const QString capture_filter);
339 
340  void applyGlobalCommandLineOptions();
341  void setFeaturesEnabled(bool enabled = true);
342 
343  void on_actionNewDisplayFilterExpression_triggered();
344  void onFilterSelected(QString, bool);
345  void onFilterPreferences();
346  void onFilterEdit(int uatIndex);
347 
348  // Handle FilterAction signals
349  void queuedFilterAction(QString filter, FilterAction::Action action, FilterAction::ActionType type);
350 
356  void openStatCommandDialog(const QString &menu_path, const char *arg, void *userdata);
357 
363  void openTapParameterDialog(const QString cfg_str, const QString arg, void *userdata);
364  void openTapParameterDialog();
365 
366 #if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
367  void softwareUpdateRequested();
368 #endif
369 
370  // Automatically connected slots ("on_<object>_<signal>").
371  //
372  // The slots below follow the naming conventaion described in
373  // https://doc.qt.io/archives/qt-4.8/qmetaobject.html#connectSlotsByName
374  // and are automatically connected at initialization time via
375  // main_ui_->setupUi, which in turn calls connectSlotsByName.
376  //
377  // If you're manually connecting a signal to a slot, don't prefix its name
378  // with "on_". Otherwise you'll get runtime warnings.
379 
380  // We might want move these to main_window_actions.cpp similar to
381  // gtk/main_menubar.c
382 
383  void connectFileMenuActions();
384  void printFile();
385 
386  void connectEditMenuActions();
387  void copySelectedItems(LograyMainWindow::CopySelected selection_type);
388  void findPacket();
389  void editTimeShift();
390  void editConfigurationProfiles();
391  void editTimeShiftFinished(int);
392  void addPacketCommentFinished(PacketCommentDialog* pc_dialog, int result);
393  void editPacketCommentFinished(PacketCommentDialog* pc_dialog, int result, unsigned nComment);
394  void deleteAllPacketComments();
395  void deleteAllPacketCommentsFinished(int result);
396  void showPreferencesDialog(QString module_name);
397 
398  void connectViewMenuActions();
399  void showHideMainWidgets(QAction *action);
400  void setTimestampFormat(QAction *action);
401  void setTimestampPrecision(QAction *action);
402  void setTimeDisplaySecondsWithHoursAndMinutes(bool checked);
403  void editResolvedName();
404  void setNameResolution();
405  void zoomText();
406  void showColoringRulesDialog();
407  void colorizeConversation(bool create_rule = false);
408  void colorizeActionTriggered();
409  void openPacketDialog(bool from_reference = false);
410  void reloadCaptureFileAsFormatOrCapture();
411  void reloadCaptureFile();
412 
413  void connectGoMenuActions();
414 
415  void setPreviousFocus();
416  void resetPreviousFocus();
417 
418  void connectCaptureMenuActions();
419  void startCaptureTriggered();
420 
421  void connectAnalyzeMenuActions();
422 
423  void matchFieldFilter(FilterAction::Action action, FilterAction::ActionType filter_type);
424  void applyFieldAsColumn();
425 
426  void filterMenuAboutToShow();
427 
428  void applyConversationFilter();
429 
430  void openFollowStreamDialog(int proto_id, unsigned stream_num, unsigned sub_stream_num, bool use_stream_index = true);
431  void openFollowStreamDialog(int proto_id);
432 
433  void statCommandExpertInfo(const char *, void *);
434 
435  void connectHelpMenuActions();
436 
437 #ifdef HAVE_SOFTWARE_UPDATE
438  void checkForUpdates();
439 #endif
440 
441  void goToCancelClicked();
442  void goToGoClicked();
443  void goToLineEditReturnPressed();
444 
445  void connectStatisticsMenuActions();
446 
447  void showResolvedAddressesDialog();
448  void showConversationsDialog();
449  void showEndpointsDialog();
450 
451  void openStatisticsTreeDialog(const char *abbr);
452  void statCommandIOGraph(const char *, void *);
453  void showIOGraphDialog(io_graph_item_unit_t, QString);
454 
455  void externalMenuItemTriggered();
456 
457  void on_actionContextWikiProtocolPage_triggered();
458  void on_actionContextFilterFieldReference_triggered();
459 
460  void extcap_options_finished(int result);
461  void showExtcapOptionsDialog(QString & device_name, bool startCaptureOnClose);
462 
463  friend class MainApplication;
464 };
465 
466 #endif // LOGRAY_MAIN_WINDOW_H
Definition: accordion_frame.h:18
Definition: byte_view_tab.h:29
Definition: capture_event.h:21
Definition: capture_file.h:21
Definition: field_information.h:23
Definition: file_set_dialog.h:29
Definition: filter_dialog.h:28
Definition: filter_expression_toolbar.h:18
Definition: funnel_statistics.h:32
Definition: logray_main_window.h:98
bool openCaptureFile(QString cf_path, QString display_filter, unsigned int type, bool is_tempfile=false)
Definition: logray_main_window_slots.cpp:157
Definition: main_application.h:49
Definition: main_window.h:44
Definition: packet_comment_dialog.h:20
Definition: packet_list.h:40
Definition: print_dialog.h:27
Definition: proto_tree.h:29
Definition: welcome_page.h:27
Definition: wireshark_application.h:16
Definition: cfile.h:67
Definition: capture_session.h:137
Definition: plugin_if.h:55
Definition: iface_toolbar.h:60
Definition: capture_info.h:40
Definition: packet_info.h:44