58b489badf4142283549a2e5b02cbd17053197ae
[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 "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
64     enum AppSignal {
65         CaptureFilterListChanged,
66         ColumnsChanged,
67         DisplayFilterListChanged,
68         FieldsChanged,
69         FilterExpressionsChanged,
70         LocalInterfacesChanged,
71         NameResolutionChanged,
72         PacketDissectionChanged,
73         PreferencesChanged,
74         RecentCapturesChanged,
75         RecentPreferencesRead
76     };
77
78     enum MainMenuItem {
79         FileOpenDialog,
80         CaptureOptionsDialog
81     };
82
83     void registerUpdate(register_action_e action, const char *message);
84     void emitAppSignal(AppSignal signal);
85     // Emitting app signals (PacketDissectionChanged in particular) from
86     // dialogs on OS X can be problematic. Dialogs should call queueAppSignal
87     // instead.
88     void queueAppSignal(AppSignal signal) { app_signals_ << signal; }
89     // Flush queued app signals. Should be called from the main window after
90     // each dialog that calls queueAppSignal closes.
91     void flushAppSignals();
92     void emitStatCommandSignal(const QString &menu_path, const char *arg, void *userdata);
93     void emitTapParameterSignal(const QString cfg_abbr, const QString arg, void *userdata);
94     void addDynamicMenuGroupItem(int group, QAction *sg_action);
95     void appendDynamicMenuGroupItem(int group, QAction *sg_action);
96     void removeDynamicMenuGroupItem(int group, QAction *sg_action);
97     QList<QAction *> dynamicMenuGroupItems(int group);
98     QList<QAction *> addedMenuGroupItems(int group);
99     QList<QAction *> removedMenuGroupItems(int group);
100     void clearAddedMenuGroupItems();
101     void clearRemovedMenuGroupItems();
102
103     void allSystemsGo();
104     void refreshLocalInterfaces();
105     struct _e_prefs * readConfigurationFiles(char **gdp_path, char **dp_path, bool reset);
106     QList<recent_item_status *> recentItems() const;
107     void addRecentItem(const QString filename, qint64 size, bool accessible);
108     void removeRecentItem(const QString &filename);
109     QDir lastOpenDir();
110     void setLastOpenDir(const char *dir_name);
111     void setLastOpenDir(QString *dir_str);
112     void helpTopicAction(topic_action_e action);
113     const QFont monospaceFont() const { return mono_font_; }
114     void setMonospaceFont(const char *font_string);
115     int monospaceTextSize(const char *str);
116     void setConfigurationProfile(const gchar *profile_name);
117     void reloadLuaPluginsDelayed();
118     bool isInitialized() { return initialized_; }
119     void setReloadingLua(bool is_reloading) { is_reloading_lua_ = is_reloading; }
120     bool isReloadingLua() { return is_reloading_lua_; }
121     const QIcon &normalIcon() const { return normal_icon_; }
122     const QIcon &captureIcon() const { return capture_icon_; }
123     const QString &windowTitleSeparator() const { return window_title_separator_; }
124     const QString windowTitleString(QStringList title_parts);
125     const QString windowTitleString(QString title_part) { return windowTitleString(QStringList() << title_part); }
126     void applyCustomColorsFromRecent();
127
128     QTranslator translator;
129     QTranslator translatorQt;
130     void loadLanguage(const QString language);
131
132     void doTriggerMenuItem(MainMenuItem menuItem);
133
134 private:
135     bool initialized_;
136     bool is_reloading_lua_;
137     QFont mono_font_;
138     QTimer recent_timer_;
139     QTimer addr_resolv_timer_;
140     QTimer tap_update_timer_;
141     QList<QString> pending_open_files_;
142     QSocketNotifier *if_notifier_;
143     QIcon normal_icon_;
144     QIcon capture_icon_;
145     static QString window_title_separator_;
146     QList<AppSignal> app_signals_;
147     int active_captures_;
148     void storeCustomColorsInRecent();
149
150 protected:
151     bool event(QEvent *event);
152
153 signals:
154     void appInitialized();
155     void localInterfaceListChanged();
156     void openCaptureFile(QString cf_path, QString display_filter, unsigned int type);
157     void openCaptureOptions();
158     void recentPreferencesRead();
159     void updateRecentCaptureStatus(const QString &filename, qint64 size, bool accessible);
160     void splashUpdate(register_action_e action, const char *message);
161     void profileChanging();
162     void profileNameChanged(const gchar *profile_name);
163
164     void columnsChanged(); // XXX This recreates the packet list. We might want to rename it accordingly.
165     void captureFilterListChanged();
166     void displayFilterListChanged();
167     void filterExpressionsChanged();
168     void packetDissectionChanged();
169     void preferencesChanged();
170     void addressResolutionChanged();
171     void checkDisplayFilter();
172     void fieldsChanged();
173     void reloadLuaPlugins();
174
175     void openStatCommandDialog(const QString &menu_path, const char *arg, void *userdata);
176     void openTapParameterDialog(const QString cfg_str, const QString arg, void *userdata);
177
178 public slots:
179     void clearRecentCaptures();
180     void captureFileReadStarted();
181     void captureStarted() { active_captures_++; }
182     void captureFinished() { active_captures_--; }
183     void updateTaps();
184
185 private slots:
186     void cleanup();
187     void ifChangeEventsAvailable();
188     void itemStatusFinished(const QString filename = "", qint64 size = 0, bool accessible = false);
189     void refreshRecentCaptures(void);
190     void refreshAddressResolution(void);
191 };
192
193 extern WiresharkApplication *wsApp;
194
195 /** Global compile time version string */
196 extern void get_wireshark_qt_compiled_info(GString *str);
197 extern void get_gui_compiled_info(GString *str);
198 /** Global runtime version string */
199 extern void get_wireshark_runtime_info(GString *str);
200 #endif // WIRESHARK_APPLICATION_H
201
202 /*
203  * Editor modelines
204  *
205  * Local Variables:
206  * c-basic-offset: 4
207  * tab-width: 8
208  * indent-tabs-mode: nil
209  * End:
210  *
211  * ex: set shiftwidth=4 tabstop=8 expandtab:
212  * :indentSize=4:tabSize=8:noTabs=true:
213  */