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