Wireshark 4.5.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 };
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
168private:
169 bool initialized_;
170 bool is_reloading_lua_;
171 QFont mono_font_;
172 QFont zoomed_font_;
173 QTimer recent_timer_;
174 QTimer packet_data_timer_;
175 QTimer tap_update_timer_;
176 QList<QString> pending_open_files_;
177 QSocketNotifier *if_notifier_;
178 static QString window_title_separator_;
179 QList<AppSignal> app_signals_;
180 int active_captures_;
181 bool refresh_interfaces_pending_;
182
183#if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
184 bool software_update_ok_;
185#endif
186
187 void storeCustomColorsInRecent();
188 void clearDynamicMenuGroupItems();
189
190protected:
191 bool event(QEvent *event);
192 virtual void initializeIcons() = 0;
193
194 QIcon normal_icon_;
195 QIcon capture_icon_;
196#ifdef HAVE_LIBPCAP
197 GList *cached_if_list_;
198#endif
199
200signals:
201 void appInitialized();
202 void localInterfaceEvent(const char *ifname, int added, int up);
203 void scanLocalInterfaces(GList *filter_list = nullptr);
204 void localInterfaceListChanged();
205 void openCaptureFile(QString cf_path, QString display_filter, unsigned int type);
206 void openCaptureOptions();
207 void recentPreferencesRead();
208 void updateRecentCaptureStatus(const QString &filename, qint64 size, bool accessible);
209 void splashUpdate(register_action_e action, const char *message);
210 void profileChanging();
211 void profileNameChanged(const char *profile_name);
212
213 void freezePacketList(bool changing_profile);
214 void columnsChanged(); // XXX This recreates the packet list. We might want to rename it accordingly.
215 void captureFilterListChanged();
216 void displayFilterListChanged();
217 void filterExpressionsChanged();
218 void packetDissectionChanged();
219 void colorsChanged();
220 void preferencesChanged();
221 void addressResolutionChanged();
222 void columnDataChanged();
223 void checkDisplayFilter();
224 void fieldsChanged();
225 void reloadLuaPlugins();
226#if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
227 // Each of these are called from a separate thread.
228 void softwareUpdateRequested();
229 void softwareUpdateQuit();
230#endif
231
232 void openStatCommandDialog(const QString &menu_path, const char *arg, void *userdata);
233 void openTapParameterDialog(const QString cfg_str, const QString arg, void *userdata);
234
235 /* Signals activation and stop of a capture. The value provides the number of active captures */
236 void captureActive(int);
237
238 void zoomRegularFont(const QFont & font);
239 void zoomMonospaceFont(const QFont & font);
240
241public slots:
242 void clearRecentCaptures();
243 void refreshRecentCaptures();
244
245 void captureEventHandler(CaptureEvent);
246
247 // Flush queued app signals. Should be called from the main window after
248 // each dialog that calls queueAppSignal closes.
249 void flushAppSignals();
250
251 void reloadDisplayFilterMacros();
252
253 void itemStatusFinished(const QString filename = "", qint64 size = 0, bool accessible = false);
254
255private slots:
256 void updateTaps();
257
258 void cleanup();
259 void ifChangeEventsAvailable();
260 void refreshPacketData();
261#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) && defined(Q_OS_WIN)
262 void colorSchemeChanged();
263#endif
264};
265
266extern MainApplication *mainApp;
267
269extern void gather_wireshark_qt_compiled_info(feature_list l);
271extern void gather_wireshark_runtime_info(feature_list l);
272#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:235
void gather_wireshark_qt_compiled_info(feature_list l)
Definition main.cpp:194
Definition prefs.h:165
Definition main_application.h:43