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