Move the protocol registration routines back into libwireshark
[metze/wireshark/wip.git] / ui / qt / wireshark_application.h
1 /* wireshark_application.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef WIRESHARK_APPLICATION_H
23 #define WIRESHARK_APPLICATION_H
24
25 #include <config.h>
26
27 #include <glib.h>
28
29 #include "epan/register.h"
30
31 #include "ui/help_url.h"
32
33 #include <QApplication>
34 #include <QDir>
35 #include <QFont>
36 #include <QIcon>
37 #include <QTimer>
38 #include <QTranslator>
39
40 struct _e_prefs;
41
42 class QAction;
43 class QSocketNotifier;
44
45 // Recent items:
46 // - Read from prefs
47 // - Add from open file
48 // - Check current list
49 // - Signal updated item
50 // -
51 typedef struct _recent_item_status {
52     QString filename;
53     qint64 size;
54     bool accessible;
55     bool in_thread;
56 } recent_item_status;
57
58 class WiresharkApplication : public QApplication
59 {
60     Q_OBJECT
61 public:
62     explicit WiresharkApplication(int &argc,  char **argv);
63     ~WiresharkApplication();
64
65     enum AppSignal {
66         CaptureFilterListChanged,
67         ColumnsChanged,
68         DisplayFilterListChanged,
69         FieldsChanged,
70         FilterExpressionsChanged,
71         LocalInterfacesChanged,
72         NameResolutionChanged,
73         PacketDissectionChanged,
74         PreferencesChanged,
75         RecentCapturesChanged,
76         RecentPreferencesRead
77     };
78
79     enum MainMenuItem {
80         FileOpenDialog,
81         CaptureOptionsDialog
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.
89     void queueAppSignal(AppSignal signal) { app_signals_ << signal; }
90     // Flush queued app signals. Should be called from the main window after
91     // each dialog that calls queueAppSignal closes.
92     void flushAppSignals();
93     void emitStatCommandSignal(const QString &menu_path, const char *arg, void *userdata);
94     void emitTapParameterSignal(const QString cfg_abbr, const QString arg, void *userdata);
95     void addDynamicMenuGroupItem(int group, QAction *sg_action);
96     void appendDynamicMenuGroupItem(int group, QAction *sg_action);
97     void removeDynamicMenuGroupItem(int group, QAction *sg_action);
98     QList<QAction *> dynamicMenuGroupItems(int group);
99     QList<QAction *> addedMenuGroupItems(int group);
100     QList<QAction *> removedMenuGroupItems(int group);
101     void clearAddedMenuGroupItems();
102     void clearRemovedMenuGroupItems();
103
104     void allSystemsGo();
105     void refreshLocalInterfaces();
106     struct _e_prefs * readConfigurationFiles(bool reset);
107     QList<recent_item_status *> recentItems() const;
108     void addRecentItem(const QString filename, qint64 size, bool accessible);
109     void removeRecentItem(const QString &filename);
110     QDir lastOpenDir();
111     void setLastOpenDir(const char *dir_name);
112     void setLastOpenDir(QString *dir_str);
113     void helpTopicAction(topic_action_e action);
114     const QFont monospaceFont() const { return mono_font_; }
115     void setMonospaceFont(const char *font_string);
116     int monospaceTextSize(const char *str);
117     void setConfigurationProfile(const gchar *profile_name, bool write_recent = true);
118     void reloadLuaPluginsDelayed();
119     bool isInitialized() { return initialized_; }
120     void setReloadingLua(bool is_reloading) { is_reloading_lua_ = is_reloading; }
121     bool isReloadingLua() { return is_reloading_lua_; }
122     const QIcon &normalIcon();
123     const QIcon &captureIcon();
124     const QString &windowTitleSeparator() const { return window_title_separator_; }
125     const QString windowTitleString(QStringList title_parts);
126     const QString windowTitleString(QString title_part) { return windowTitleString(QStringList() << title_part); }
127     void applyCustomColorsFromRecent();
128 #ifdef HAVE_SOFTWARE_UPDATE
129     void rejectSoftwareUpdate() { software_update_ok_ = false; }
130     bool softwareUpdateCanShutdown();
131     void softwareUpdateShutdownRequest();
132 #endif
133     QWidget *mainWindow();
134
135     QTranslator translator;
136     QTranslator translatorQt;
137     void loadLanguage(const QString language);
138
139     void doTriggerMenuItem(MainMenuItem menuItem);
140
141     void zoomTextFont(int zoomLevel);
142
143 private:
144     bool initialized_;
145     bool is_reloading_lua_;
146     QFont mono_font_;
147     QTimer recent_timer_;
148     QTimer addr_resolv_timer_;
149     QTimer tap_update_timer_;
150     QList<QString> pending_open_files_;
151     QSocketNotifier *if_notifier_;
152     QIcon normal_icon_;
153     QIcon capture_icon_;
154     static QString window_title_separator_;
155     QList<AppSignal> app_signals_;
156     int active_captures_;
157 #ifdef HAVE_SOFTWARE_UPDATE
158     bool software_update_ok_;
159 #endif
160
161     void storeCustomColorsInRecent();
162 #ifdef _WIN32
163     unsigned int fileVersion(QString file_path);
164     void checkForDbar();
165 #endif
166     void clearDynamicMenuGroupItems();
167     void initializeIcons();
168
169 protected:
170     bool event(QEvent *event);
171
172 signals:
173     void appInitialized();
174     void localInterfaceListChanged();
175     void openCaptureFile(QString cf_path, QString display_filter, unsigned int type);
176     void openCaptureOptions();
177     void recentPreferencesRead();
178     void updateRecentCaptureStatus(const QString &filename, qint64 size, bool accessible);
179     void splashUpdate(register_action_e action, const char *message);
180     void profileChanging();
181     void profileNameChanged(const gchar *profile_name);
182
183     void columnsChanged(); // XXX This recreates the packet list. We might want to rename it accordingly.
184     void captureFilterListChanged();
185     void displayFilterListChanged();
186     void filterExpressionsChanged();
187     void packetDissectionChanged();
188     void preferencesChanged();
189     void addressResolutionChanged();
190     void checkDisplayFilter();
191     void fieldsChanged();
192     void reloadLuaPlugins();
193 #ifdef HAVE_SOFTWARE_UPDATE
194     // Each of these are called from a separate thread.
195     void softwareUpdateRequested();
196     void softwareUpdateClose();
197     void softwareUpdateQuit();
198 #endif
199
200     void openStatCommandDialog(const QString &menu_path, const char *arg, void *userdata);
201     void openTapParameterDialog(const QString cfg_str, const QString arg, void *userdata);
202
203     /* Signals activation and stop of a capture. The value provides the number of active captures */
204     void captureActive(int);
205
206     void zoomMonospaceFont(const QFont & font);
207
208 public slots:
209     void clearRecentCaptures();
210     void captureFileReadStarted();
211     void captureStarted();
212     void captureFinished();
213     void updateTaps();
214
215 private slots:
216     void cleanup();
217     void ifChangeEventsAvailable();
218     void itemStatusFinished(const QString filename = "", qint64 size = 0, bool accessible = false);
219     void refreshRecentCaptures(void);
220     void refreshAddressResolution(void);
221 };
222
223 extern WiresharkApplication *wsApp;
224
225 /** Global compile time version string */
226 extern void get_wireshark_qt_compiled_info(GString *str);
227 extern void get_gui_compiled_info(GString *str);
228 /** Global runtime version string */
229 extern void get_wireshark_runtime_info(GString *str);
230 #endif // WIRESHARK_APPLICATION_H
231
232 /*
233  * Editor modelines
234  *
235  * Local Variables:
236  * c-basic-offset: 4
237  * tab-width: 8
238  * indent-tabs-mode: nil
239  * End:
240  *
241  * ex: set shiftwidth=4 tabstop=8 expandtab:
242  * :indentSize=4:tabSize=8:noTabs=true:
243  */