Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
wireshark_application.h
1 /* wireshark_application.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #ifndef WIRESHARK_APPLICATION_H
11 #define WIRESHARK_APPLICATION_H
12 
13 #include <config.h>
14 
15 #include <glib.h>
16 
17 #include "epan/register.h"
18 
19 #include "ui/help_url.h"
20 
21 #include <QApplication>
22 #include <QDir>
23 #include <QFont>
24 #include <QIcon>
25 #include <QTimer>
26 #include <QTranslator>
27 
28 #include "capture_event.h"
29 
30 struct _e_prefs;
31 
32 class QAction;
33 class QSocketNotifier;
34 
35 // Recent items:
36 // - Read from prefs
37 // - Add from open file
38 // - Check current list
39 // - Signal updated item
40 // -
41 typedef struct _recent_item_status {
42  QString filename;
43  qint64 size;
44  bool accessible;
45  bool in_thread;
47 
48 class WiresharkApplication : public QApplication
49 {
50  Q_OBJECT
51 public:
52  explicit WiresharkApplication(int &argc, char **argv);
54 
55  enum AppSignal {
56  CaptureFilterListChanged,
57  ColumnsChanged,
58  DisplayFilterListChanged,
59  FieldsChanged,
60  FilterExpressionsChanged,
61  LocalInterfacesChanged,
62  NameResolutionChanged,
63  PacketDissectionChanged,
64  PreferencesChanged,
65  ProfileChanging,
66  RecentCapturesChanged,
67  RecentPreferencesRead
68  };
69 
70  enum MainMenuItem {
71  FileOpenDialog,
72  CaptureOptionsDialog
73  };
74 
75  void registerUpdate(register_action_e action, const char *message);
76  void emitAppSignal(AppSignal signal);
77  // Emitting app signals (PacketDissectionChanged in particular) from
78  // dialogs on macOS can be problematic. Dialogs should call queueAppSignal
79  // instead.
80  void queueAppSignal(AppSignal signal) { app_signals_ << signal; }
81  // Flush queued app signals. Should be called from the main window after
82  // each dialog that calls queueAppSignal closes.
83  void flushAppSignals();
84  void emitStatCommandSignal(const QString &menu_path, const char *arg, void *userdata);
85  void emitTapParameterSignal(const QString cfg_abbr, const QString arg, void *userdata);
86  void addDynamicMenuGroupItem(int group, QAction *sg_action);
87  void appendDynamicMenuGroupItem(int group, QAction *sg_action);
88  void removeDynamicMenuGroupItem(int group, QAction *sg_action);
89  QList<QAction *> dynamicMenuGroupItems(int group);
90  QList<QAction *> addedMenuGroupItems(int group);
91  QList<QAction *> removedMenuGroupItems(int group);
92  void clearAddedMenuGroupItems();
93  void clearRemovedMenuGroupItems();
94 
95  void allSystemsGo();
96  void refreshLocalInterfaces();
97  struct _e_prefs * readConfigurationFiles(bool reset);
98  QList<recent_item_status *> recentItems() const;
99  void addRecentItem(const QString filename, qint64 size, bool accessible);
100  void removeRecentItem(const QString &filename);
101  QDir lastOpenDir();
102  void setLastOpenDir(const char *dir_name);
103  void setLastOpenDir(QString dir_str);
104  void helpTopicAction(topic_action_e action);
105  const QFont monospaceFont(bool zoomed = false) const;
106  void setMonospaceFont(const char *font_string);
107  int monospaceTextSize(const char *str);
108  void setConfigurationProfile(const gchar *profile_name, bool write_recent = true);
109  void reloadLuaPluginsDelayed();
110  bool isInitialized() { return initialized_; }
111  void setReloadingLua(bool is_reloading) { is_reloading_lua_ = is_reloading; }
112  bool isReloadingLua() { return is_reloading_lua_; }
113  const QIcon &normalIcon();
114  const QIcon &captureIcon();
115  const QString &windowTitleSeparator() const { return window_title_separator_; }
116  const QString windowTitleString(QStringList title_parts);
117  const QString windowTitleString(QString title_part) { return windowTitleString(QStringList() << title_part); }
118  void applyCustomColorsFromRecent();
119 #ifdef HAVE_SOFTWARE_UPDATE
120  void rejectSoftwareUpdate() { software_update_ok_ = false; }
121  bool softwareUpdateCanShutdown();
122  void softwareUpdateShutdownRequest();
123 #endif
124  QWidget *mainWindow();
125 
126  QTranslator translator;
127  QTranslator translatorQt;
128  void loadLanguage(const QString language);
129 
130  void doTriggerMenuItem(MainMenuItem menuItem);
131 
132  void zoomTextFont(int zoomLevel);
133 
134 private:
135  bool initialized_;
136  bool is_reloading_lua_;
137  QFont mono_font_;
138  QFont zoomed_font_;
139  QTimer recent_timer_;
140  QTimer packet_data_timer_;
141  QTimer tap_update_timer_;
142  QList<QString> pending_open_files_;
143  QSocketNotifier *if_notifier_;
144  QIcon normal_icon_;
145  QIcon capture_icon_;
146  static QString window_title_separator_;
147  QList<AppSignal> app_signals_;
148  int active_captures_;
149 #ifdef HAVE_SOFTWARE_UPDATE
150  bool software_update_ok_;
151 #endif
152 
153  void storeCustomColorsInRecent();
154 #ifdef _WIN32
155  unsigned int fileVersion(QString file_path);
156  void checkForDbar();
157 #endif
158  void clearDynamicMenuGroupItems();
159  void initializeIcons();
160 
161 protected:
162  bool event(QEvent *event);
163 
164 signals:
165  void appInitialized();
166  void localInterfaceListChanged();
167  void openCaptureFile(QString cf_path, QString display_filter, unsigned int type);
168  void openCaptureOptions();
169  void recentPreferencesRead();
170  void updateRecentCaptureStatus(const QString &filename, qint64 size, bool accessible);
171  void splashUpdate(register_action_e action, const char *message);
172  void profileChanging();
173  void profileNameChanged(const gchar *profile_name);
174 
175  void columnsChanged(); // XXX This recreates the packet list. We might want to rename it accordingly.
176  void captureFilterListChanged();
177  void displayFilterListChanged();
178  void filterExpressionsChanged();
179  void packetDissectionChanged();
180  void preferencesChanged();
181  void addressResolutionChanged();
182  void columnDataChanged();
183  void checkDisplayFilter();
184  void fieldsChanged();
185  void reloadLuaPlugins();
186 #ifdef HAVE_SOFTWARE_UPDATE
187  // Each of these are called from a separate thread.
188  void softwareUpdateRequested();
189  void softwareUpdateClose();
190  void softwareUpdateQuit();
191 #endif
192 
193  void openStatCommandDialog(const QString &menu_path, const char *arg, void *userdata);
194  void openTapParameterDialog(const QString cfg_str, const QString arg, void *userdata);
195 
196  /* Signals activation and stop of a capture. The value provides the number of active captures */
197  void captureActive(int);
198 
199  void zoomMonospaceFont(const QFont & font);
200 
201 public slots:
202  void clearRecentCaptures();
203  void refreshRecentCaptures();
204 
205  void captureEventHandler(CaptureEvent);
206 
207 private slots:
208  void updateTaps();
209 
210  void cleanup();
211  void ifChangeEventsAvailable();
212  void itemStatusFinished(const QString filename = "", qint64 size = 0, bool accessible = false);
213  void refreshPacketData();
214 };
215 
216 extern WiresharkApplication *wsApp;
217 
219 extern void get_wireshark_qt_compiled_info(GString *str);
220 extern void get_gui_compiled_info(GString *str);
222 extern void get_wireshark_runtime_info(GString *str);
223 #endif // WIRESHARK_APPLICATION_H
224 
225 /*
226  * Editor modelines
227  *
228  * Local Variables:
229  * c-basic-offset: 4
230  * tab-width: 8
231  * indent-tabs-mode: nil
232  * End:
233  *
234  * ex: set shiftwidth=4 tabstop=8 expandtab:
235  * :indentSize=4:tabSize=8:noTabs=true:
236  */
Definition: capture_event.h:19
gboolean write_recent(void)
Definition: recent.c:611
Definition: prefs.h:132
Definition: wireshark_application.h:48
Definition: wireshark_application.h:41