1 /* wireshark_application.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #ifndef WIRESHARK_APPLICATION_H
11 #define WIRESHARK_APPLICATION_H
12 
13 #include <config.h>
14 
15 #include <glib.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 
30 struct _e_prefs;
31 
32 class QAction;
33 class QSocketNotifier;
34 
35 // Recent items:
36 // - Read from prefs
37 // - Add from open file
38 // - Check current list
39 // - Signal updated item
40 // -
41 typedef struct _recent_item_status {
42     QString filename;
43     qint64 size;
44     bool accessible;
45     bool in_thread;
46 } recent_item_status;
47 
48 class WiresharkApplication : public QApplication
49 {
50     Q_OBJECT
51 public:
52     explicit WiresharkApplication(int &argc,  char **argv);
53     ~WiresharkApplication();
54 
55     enum AppSignal {
56         CaptureFilterListChanged,
57         ColumnsChanged,
58         DisplayFilterListChanged,
59         FieldsChanged,
60         FilterExpressionsChanged,
61         LocalInterfacesChanged,
62         NameResolutionChanged,
63         PacketDissectionChanged,
64         PreferencesChanged,
65         ProfileChanging,
66         RecentCapturesChanged,
67         RecentPreferencesRead
68     };
69 
70     enum MainMenuItem {
71         FileOpenDialog,
72         CaptureOptionsDialog
73     };
74 
75     enum StatusInfo {
76         FilterSyntax,
77         FieldStatus,
78         FileStatus,
79         BusyStatus,
80         ByteStatus,
81         TemporaryStatus
82     };
83 
84     void registerUpdate(register_action_e action, const char *message);
85     void emitAppSignal(AppSignal signal);
86     // Emitting app signals (PacketDissectionChanged in particular) from
87     // dialogs on macOS can be problematic. Dialogs should call queueAppSignal
88     // instead.
queueAppSignal(AppSignal signal)89     void queueAppSignal(AppSignal signal) { app_signals_ << signal; }
90     void emitStatCommandSignal(const QString &menu_path, const char *arg, void *userdata);
91     void emitTapParameterSignal(const QString cfg_abbr, const QString arg, void *userdata);
92     void addDynamicMenuGroupItem(int group, QAction *sg_action);
93     void appendDynamicMenuGroupItem(int group, QAction *sg_action);
94     void removeDynamicMenuGroupItem(int group, QAction *sg_action);
95     QList<QAction *> dynamicMenuGroupItems(int group);
96     QList<QAction *> addedMenuGroupItems(int group);
97     QList<QAction *> removedMenuGroupItems(int group);
98     void clearAddedMenuGroupItems();
99     void clearRemovedMenuGroupItems();
100 
101     void allSystemsGo();
102     void emitLocalInterfaceEvent(const char *ifname, int added, int up);
103     void refreshLocalInterfaces();
104     struct _e_prefs * readConfigurationFiles(bool reset);
105     QList<recent_item_status *> recentItems() const;
106     void addRecentItem(const QString filename, qint64 size, bool accessible);
107     void removeRecentItem(const QString &filename);
108     QDir lastOpenDir();
109     void setLastOpenDir(const char *dir_name);
110     void setLastOpenDirFromFilename(QString file_name);
111     void helpTopicAction(topic_action_e action);
112     const QFont monospaceFont(bool zoomed = false) const;
113     void setMonospaceFont(const char *font_string);
114     int monospaceTextSize(const char *str);
115     void setConfigurationProfile(const gchar *profile_name, bool write_recent_file = true);
116     void reloadLuaPluginsDelayed();
isInitialized()117     bool isInitialized() { return initialized_; }
setReloadingLua(bool is_reloading)118     void setReloadingLua(bool is_reloading) { is_reloading_lua_ = is_reloading; }
isReloadingLua()119     bool isReloadingLua() { return is_reloading_lua_; }
120     const QIcon &normalIcon();
121     const QIcon &captureIcon();
windowTitleSeparator()122     const QString &windowTitleSeparator() const { return window_title_separator_; }
123     const QString windowTitleString(QStringList title_parts);
windowTitleString(QString title_part)124     const QString windowTitleString(QString title_part) { return windowTitleString(QStringList() << title_part); }
125     void applyCustomColorsFromRecent();
126 #if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
rejectSoftwareUpdate()127     void rejectSoftwareUpdate() { software_update_ok_ = false; }
128     bool softwareUpdateCanShutdown();
129     void softwareUpdateShutdownRequest();
130 #endif
131     QWidget *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 
146 private:
147     bool initialized_;
148     bool is_reloading_lua_;
149     QFont mono_font_;
150     QFont zoomed_font_;
151     QTimer recent_timer_;
152     QTimer packet_data_timer_;
153     QTimer tap_update_timer_;
154     QList<QString> pending_open_files_;
155     QSocketNotifier *if_notifier_;
156     QIcon normal_icon_;
157     QIcon capture_icon_;
158     static QString window_title_separator_;
159     QList<AppSignal> app_signals_;
160     int active_captures_;
161 #if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
162     bool software_update_ok_;
163 #endif
164 
165     void storeCustomColorsInRecent();
166     void clearDynamicMenuGroupItems();
167     void initializeIcons();
168 
169 protected:
170     bool event(QEvent *event);
171 
172 signals:
173     void appInitialized();
174     void localInterfaceEvent(const char *ifname, int added, int up);
175     void localInterfaceListChanged();
176     void openCaptureFile(QString cf_path, QString display_filter, unsigned int type);
177     void openCaptureOptions();
178     void recentPreferencesRead();
179     void updateRecentCaptureStatus(const QString &filename, qint64 size, bool accessible);
180     void splashUpdate(register_action_e action, const char *message);
181     void profileChanging();
182     void profileNameChanged(const gchar *profile_name);
183 
184     void columnsChanged(); // XXX This recreates the packet list. We might want to rename it accordingly.
185     void captureFilterListChanged();
186     void displayFilterListChanged();
187     void filterExpressionsChanged();
188     void packetDissectionChanged();
189     void preferencesChanged();
190     void addressResolutionChanged();
191     void columnDataChanged();
192     void checkDisplayFilter();
193     void fieldsChanged();
194     void reloadLuaPlugins();
195 #if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
196     // Each of these are called from a separate thread.
197     void softwareUpdateRequested();
198     void softwareUpdateClose();
199     void softwareUpdateQuit();
200 #endif
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 
211 public slots:
212     void clearRecentCaptures();
213     void refreshRecentCaptures();
214 
215     void captureEventHandler(CaptureEvent);
216 
217     // Flush queued app signals. Should be called from the main window after
218     // each dialog that calls queueAppSignal closes.
219     void flushAppSignals();
220 
221 private slots:
222     void updateTaps();
223 
224     void cleanup();
225     void ifChangeEventsAvailable();
226     void itemStatusFinished(const QString filename = "", qint64 size = 0, bool accessible = false);
227     void refreshPacketData();
228 };
229 
230 extern WiresharkApplication *wsApp;
231 
232 /** Global compile time version string */
233 extern void get_wireshark_qt_compiled_info(GString *str);
234 extern void get_gui_compiled_info(GString *str);
235 /** Global runtime version string */
236 extern void get_wireshark_runtime_info(GString *str);
237 #endif // WIRESHARK_APPLICATION_H
238