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