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