Wireshark 4.5.0
The Wireshark network protocol analyzer
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
main_application.h
Go to the documentation of this file.
1
10#ifndef MAIN_APPLICATION_H
11#define MAIN_APPLICATION_H
12
13#include <config.h>
14
15#include "wsutil/feature_list.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
30struct _e_prefs;
31
32class QAction;
33class QSocketNotifier;
34
35class MainWindow;
36
37// Recent items:
38// - Read from prefs
39// - Add from open file
40// - Check current list
41// - Signal updated item
42// -
43typedef struct _recent_item_status {
44 QString filename;
45 qint64 size;
46 bool accessible;
47 bool in_thread;
49
50class MainApplication : public QApplication
51{
52 Q_OBJECT
53public:
54 explicit MainApplication(int &argc, char **argv);
56
57 enum AppSignal {
58 CaptureFilterListChanged,
59 ColorsChanged,
60 ColumnsChanged,
61 DisplayFilterListChanged,
62 FieldsChanged,
63 FilterExpressionsChanged,
64 LocalInterfacesChanged,
65 NameResolutionChanged,
66 PacketDissectionChanged,
67 PreferencesChanged,
68 ProfileChanging,
69 RecentCapturesChanged,
70 RecentPreferencesRead,
71 FreezePacketList
72 };
73
74 enum MainMenuItem {
75 FileOpenDialog,
76 CaptureOptionsDialog
77 };
78
79 enum StatusInfo {
80 FilterSyntax,
81 FieldStatus,
82 FileStatus,
83 BusyStatus,
84 ByteStatus,
85 TemporaryStatus
86 };
87
88 void registerUpdate(register_action_e action, const char *message);
89 void emitAppSignal(AppSignal signal);
90 // Emitting app signals (PacketDissectionChanged in particular) from
91 // dialogs on macOS can be problematic. Dialogs should call queueAppSignal
92 // instead.
93 // On macOS, nested event loops (e.g., calling a dialog with exec())
94 // that call processEvents (e.g., from PacketDissectionChanged, or
95 // anything with a ProgressFrame) caused issues off and on from 5.3.0
96 // until 5.7.1/5.8.0. It appears to be solved after some false starts:
97 // https://bugreports.qt.io/browse/QTBUG-53947
98 // https://bugreports.qt.io/browse/QTBUG-56746
99 // We also try to avoid exec / additional event loops as much as possible:
100 // e.g., commit f67eccedd9836e6ced1f57ae9889f57a5400a3d7
101 // (note it can show up in unexpected places, e.g. static functions like
102 // WiresharkFileDialog::getOpenFileName())
103 void queueAppSignal(AppSignal signal) { app_signals_ << signal; }
104 void emitStatCommandSignal(const QString &menu_path, const char *arg, void *userdata);
105 void emitTapParameterSignal(const QString cfg_abbr, const QString arg, void *userdata);
106 void addDynamicMenuGroupItem(int group, QAction *sg_action);
107 void appendDynamicMenuGroupItem(int group, QAction *sg_action);
108 void removeDynamicMenuGroupItem(int group, QAction *sg_action);
109 QList<QAction *> dynamicMenuGroupItems(int group);
110 QList<QAction *> addedMenuGroupItems(int group);
111 QList<QAction *> removedMenuGroupItems(int group);
112 void clearAddedMenuGroupItems();
113 void clearRemovedMenuGroupItems();
114
115 void allSystemsGo();
116 void emitLocalInterfaceEvent(const char *ifname, int added, int up);
117
118 virtual void refreshLocalInterfaces();
119#ifdef HAVE_LIBPCAP
120 // This returns a deep copy of the cached interface list that must
121 // be freed with free_interface_list.
122 GList * getInterfaceList() const;
123 // This set the cached interface list to a deep copy of if_list.
124 void setInterfaceList(GList *if_list);
125#endif
126
127 struct _e_prefs * readConfigurationFiles(bool reset);
128 QList<recent_item_status *> recentItems() const;
129 void addRecentItem(const QString filename, qint64 size, bool accessible);
130 void removeRecentItem(const QString &filename);
131 QDir openDialogInitialDir();
132 void setLastOpenDirFromFilename(QString file_name);
133 void helpTopicAction(topic_action_e action);
134 const QFont monospaceFont(bool zoomed = false) const;
135 void setMonospaceFont(const char *font_string);
136 int monospaceTextSize(const char *str);
137 void setConfigurationProfile(const char *profile_name, bool write_recent_file = true);
138 void reloadLuaPluginsDelayed();
139 bool isInitialized() { return initialized_; }
140 void setReloadingLua(bool is_reloading) { is_reloading_lua_ = is_reloading; }
141 bool isReloadingLua() { return is_reloading_lua_; }
142 const QIcon &normalIcon();
143 const QIcon &captureIcon();
144 const QString &windowTitleSeparator() const { return window_title_separator_; }
145 const QString windowTitleString(QStringList title_parts);
146 const QString windowTitleString(QString title_part) { return windowTitleString(QStringList() << title_part); }
147 void applyCustomColorsFromRecent();
148#if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
149 void rejectSoftwareUpdate() { software_update_ok_ = false; }
150 bool softwareUpdateCanShutdown();
151 void softwareUpdateShutdownRequest();
152#endif
153 MainWindow *mainWindow();
154
155 QTranslator translator;
156 QTranslator translatorQt;
157 void loadLanguage(const QString language);
158
159 void doTriggerMenuItem(MainMenuItem menuItem);
160
161 void zoomTextFont(int zoomLevel);
162
163 void pushStatus(StatusInfo sinfo, const QString &message, const QString &messagetip = QString());
164 void popStatus(StatusInfo sinfo);
165
166 void gotoFrame(int frameNum);
167 // Maximum nested menu depth.
168 int maxMenuDepth(void) { return 5; }
169
170private:
171 bool initialized_;
172 bool is_reloading_lua_;
173 QFont mono_font_;
174 QFont zoomed_font_;
175 QTimer recent_timer_;
176 QTimer packet_data_timer_;
177 QTimer tap_update_timer_;
178 QList<QString> pending_open_files_;
179 QSocketNotifier *if_notifier_;
180 static QString window_title_separator_;
181 QList<AppSignal> app_signals_;
182 int active_captures_;
183 bool refresh_interfaces_pending_;
184
185#if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
186 bool software_update_ok_;
187#endif
188
189 void storeCustomColorsInRecent();
190 void clearDynamicMenuGroupItems();
191
192protected:
193 bool event(QEvent *event);
194 virtual void initializeIcons() = 0;
195
196 QIcon normal_icon_;
197 QIcon capture_icon_;
198#ifdef HAVE_LIBPCAP
199 GList *cached_if_list_;
200#endif
201
202signals:
203 void appInitialized();
204 void localInterfaceEvent(const char *ifname, int added, int up);
205 void scanLocalInterfaces(GList *filter_list = nullptr);
206 void localInterfaceListChanged();
207 void openCaptureFile(QString cf_path, QString display_filter, unsigned int type);
208 void openCaptureOptions();
209 void recentPreferencesRead();
210 void updateRecentCaptureStatus(const QString &filename, qint64 size, bool accessible);
211 void splashUpdate(register_action_e action, const char *message);
212 void profileChanging();
213 void profileNameChanged(const char *profile_name);
214
215 void freezePacketList(bool changing_profile);
216 void columnsChanged(); // XXX This recreates the packet list. We might want to rename it accordingly.
217 void captureFilterListChanged();
218 void displayFilterListChanged();
219 void filterExpressionsChanged();
220 void packetDissectionChanged();
221 void colorsChanged();
222 void preferencesChanged();
223 void addressResolutionChanged();
224 void columnDataChanged();
225 void checkDisplayFilter();
226 void fieldsChanged();
227 void reloadLuaPlugins();
228#if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
229 // Each of these are called from a separate thread.
230 void softwareUpdateRequested();
231 void softwareUpdateQuit();
232#endif
233
234 void openStatCommandDialog(const QString &menu_path, const char *arg, void *userdata);
235 void openTapParameterDialog(const QString cfg_str, const QString arg, void *userdata);
236
237 /* Signals activation and stop of a capture. The value provides the number of active captures */
238 void captureActive(int);
239
240 void zoomRegularFont(const QFont & font);
241 void zoomMonospaceFont(const QFont & font);
242
243public slots:
244 void clearRecentCaptures();
245 void refreshRecentCaptures();
246
247 void captureEventHandler(CaptureEvent);
248
249 // Flush queued app signals. Should be called from the main window after
250 // each dialog that calls queueAppSignal closes.
251 void flushAppSignals();
252
253 void reloadDisplayFilterMacros();
254
255 void itemStatusFinished(const QString filename = "", qint64 size = 0, bool accessible = false);
256
257private slots:
258 void updateTaps();
259
260 void cleanup();
261 void ifChangeEventsAvailable();
262 void refreshPacketData();
263#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) && defined(Q_OS_WIN)
264 void colorSchemeChanged();
265#endif
266};
267
268extern MainApplication *mainApp;
269
271extern void gather_wireshark_qt_compiled_info(feature_list l);
273extern void gather_wireshark_runtime_info(feature_list l);
274#endif // MAIN_APPLICATION_H
Definition capture_event.h:21
Definition main_application.h:51
Definition main_window.h:46
void gather_wireshark_runtime_info(feature_list l)
Definition main.cpp:247
void gather_wireshark_qt_compiled_info(feature_list l)
Definition main.cpp:206
Definition prefs.h:165
Definition main_application.h:43