3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #ifndef MAIN_APPLICATION_H
11 #define MAIN_APPLICATION_H
15 #include "wsutil/feature_list.h"
17 #include "epan/register.h"
19 #include "ui/help_url.h"
21 #include <QApplication>
26 #include <QTranslator>
28 #include "capture_event.h"
33 class QSocketNotifier
;
37 // - Add from open file
38 // - Check current list
39 // - Signal updated item
41 typedef struct _recent_item_status
{
48 class MainApplication
: public QApplication
52 explicit MainApplication(int &argc
, char **argv
);
56 CaptureFilterListChanged
,
59 DisplayFilterListChanged
,
61 FilterExpressionsChanged
,
62 LocalInterfacesChanged
,
63 NameResolutionChanged
,
64 PacketDissectionChanged
,
67 RecentCapturesChanged
,
68 RecentPreferencesRead
,
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
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();
114 void emitLocalInterfaceEvent(const char *ifname
, int added
, int up
);
116 virtual void refreshLocalInterfaces();
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
);
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();
151 QWidget
*mainWindow();
153 QTranslator translator
;
154 QTranslator translatorQt
;
155 void loadLanguage(const QString language
);
157 void doTriggerMenuItem(MainMenuItem menuItem
);
159 void zoomTextFont(int zoomLevel
);
161 void pushStatus(StatusInfo sinfo
, const QString
&message
, const QString
&messagetip
= QString());
162 void popStatus(StatusInfo sinfo
);
164 void gotoFrame(int frameNum
);
168 bool is_reloading_lua_
;
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 bool refresh_interfaces_pending_
;
181 #if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
182 bool software_update_ok_
;
185 void storeCustomColorsInRecent();
186 void clearDynamicMenuGroupItems();
189 bool event(QEvent
*event
);
190 virtual void initializeIcons() = 0;
195 GList
*cached_if_list_
;
199 void appInitialized();
200 void localInterfaceEvent(const char *ifname
, int added
, int up
);
201 void scanLocalInterfaces(GList
*filter_list
= nullptr);
202 void localInterfaceListChanged();
203 void openCaptureFile(QString cf_path
, QString display_filter
, unsigned int type
);
204 void openCaptureOptions();
205 void recentPreferencesRead();
206 void updateRecentCaptureStatus(const QString
&filename
, qint64 size
, bool accessible
);
207 void splashUpdate(register_action_e action
, const char *message
);
208 void profileChanging();
209 void profileNameChanged(const char *profile_name
);
211 void freezePacketList(bool changing_profile
);
212 void columnsChanged(); // XXX This recreates the packet list. We might want to rename it accordingly.
213 void captureFilterListChanged();
214 void displayFilterListChanged();
215 void filterExpressionsChanged();
216 void packetDissectionChanged();
217 void colorsChanged();
218 void preferencesChanged();
219 void addressResolutionChanged();
220 void columnDataChanged();
221 void checkDisplayFilter();
222 void fieldsChanged();
223 void reloadLuaPlugins();
224 #if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
225 // Each of these are called from a separate thread.
226 void softwareUpdateRequested();
227 void softwareUpdateQuit();
230 void openStatCommandDialog(const QString
&menu_path
, const char *arg
, void *userdata
);
231 void openTapParameterDialog(const QString cfg_str
, const QString arg
, void *userdata
);
233 /* Signals activation and stop of a capture. The value provides the number of active captures */
234 void captureActive(int);
236 void zoomRegularFont(const QFont
& font
);
237 void zoomMonospaceFont(const QFont
& font
);
240 void clearRecentCaptures();
241 void refreshRecentCaptures();
243 void captureEventHandler(CaptureEvent
);
245 // Flush queued app signals. Should be called from the main window after
246 // each dialog that calls queueAppSignal closes.
247 void flushAppSignals();
249 void reloadDisplayFilterMacros();
255 void ifChangeEventsAvailable();
256 void itemStatusFinished(const QString filename
= "", qint64 size
= 0, bool accessible
= false);
257 void refreshPacketData();
258 #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) && defined(Q_OS_WIN)
259 void colorSchemeChanged();
263 extern MainApplication
*mainApp
;
265 /** Global compile time version info */
266 extern void gather_wireshark_qt_compiled_info(feature_list l
);
267 /** Global runtime version info */
268 extern void gather_wireshark_runtime_info(feature_list l
);
269 #endif // MAIN_APPLICATION_H