aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/capture_file_dialog.cpp83
-rw-r--r--ui/qt/capture_file_dialog.h1
-rw-r--r--ui/win32/file_dlg_win32.c127
3 files changed, 158 insertions, 53 deletions
diff --git a/ui/qt/capture_file_dialog.cpp b/ui/qt/capture_file_dialog.cpp
index 450b471106..2ff11b190a 100644
--- a/ui/qt/capture_file_dialog.cpp
+++ b/ui/qt/capture_file_dialog.cpp
@@ -299,6 +299,36 @@ int CaptureFileDialog::mergeType() {
}
#else // not Q_OS_WINDOWS
+QString CaptureFileDialog::fileExtensionType(int et, bool extension_globs)
+{
+ QString filter;
+ GSList *extensions_list;
+ GSList *extension;
+
+ filter = wtap_get_file_extension_type_name(et);
+
+ if (!extension_globs) {
+ return filter;
+ }
+
+ filter += " (";
+
+ extensions_list = wtap_get_file_extension_type_extensions(et);
+
+ /* Construct the list of patterns. */
+ for (extension = extensions_list; extension != NULL;
+ extension = g_slist_next(extension)) {
+ if (!filter.endsWith('('))
+ filter += ' ';
+ filter += "*.";
+ filter += (char *)extension->data;
+ }
+ wtap_free_extensions_list(extensions_list);
+ filter += ')';
+ return filter;
+ /* XXX - does QStringList's destructor destroy the strings in the list? */
+}
+
QString CaptureFileDialog::fileType(int ft, bool extension_globs)
{
QString filter;
@@ -332,7 +362,7 @@ QString CaptureFileDialog::fileType(int ft, bool extension_globs)
filter += "*.";
filter += (char *)extension->data;
}
- wtap_free_file_extensions_list(extensions_list);
+ wtap_free_extensions_list(extensions_list);
}
filter += ')';
return filter;
@@ -341,17 +371,54 @@ QString CaptureFileDialog::fileType(int ft, bool extension_globs)
QStringList CaptureFileDialog::buildFileOpenTypeList() {
QStringList filters;
- int ft;
-
+ QString filter, sep;
+ GSList *extensions_list;
+ GSList *extension;
+ int et;
+
+ /*
+ * Microsoft's UI guidelines say, of the file filters in open and
+ * save dialogs:
+ *
+ * For meta-filters, remove the file extension list to eliminate
+ * clutter. Examples: "All files," "All pictures," "All music,"
+ * and "All videos."
+ *
+ * On both Windows XP and Windows 7, Wordpad doesn't do that, but
+ * Paint does.
+ *
+ * XXX - on Windows, does Qt do that here? For "All Capture Files",
+ * the filter will be a bit long, so it *really* shouldn't be shown.
+ * What about other platforms?
+ */
/* Add the "All Files" entry. */
filters << QString(tr("All Files (*.*)"));
- /* Include all the file types Wireshark supports. */
- for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) {
- if (ft == WTAP_FILE_UNKNOWN)
- continue; /* not a real file type */
+ /*
+ * Add an "All Capture Files" entry, with all the extensions we
+ * know about.
+ */
+ filter = "All Capture Files";
+
+ /*
+ * Construct its list of patterns from a list of all extensions
+ * we support.
+ */
+ extensions_list = wtap_get_all_file_extensions_list();
+ sep = " (";
+ for (extension = extensions_list; extension != NULL;
+ extension = g_slist_next(extension)) {
+ filter += sep;
+ filter += "*.";
+ filter += (char *)extension->data;
+ sep = " ";
+ }
+ filter += ")";
+ filters << filter;
- filters << fileType(ft);
+ /* Include all the file types Wireshark supports. */
+ for (et = 0; et < wtap_get_num_file_type_extensions(); et++) {
+ filters << fileExtensionType(et);
}
return filters;
diff --git a/ui/qt/capture_file_dialog.h b/ui/qt/capture_file_dialog.h
index fdfa51c7d0..54f9e1d341 100644
--- a/ui/qt/capture_file_dialog.h
+++ b/ui/qt/capture_file_dialog.h
@@ -89,6 +89,7 @@ private:
void addMergeControls(QVBoxLayout &v_box);
void addDisplayFilterEdit();
void addPreview(QVBoxLayout &v_box);
+ QString fileExtensionType(int et, bool extension_globs = true);
QString fileType(int ft, bool extension_globs = true);
QStringList buildFileOpenTypeList(void);
diff --git a/ui/win32/file_dlg_win32.c b/ui/win32/file_dlg_win32.c
index 1ceb2e451c..311b8fa3d1 100644
--- a/ui/win32/file_dlg_win32.c
+++ b/ui/win32/file_dlg_win32.c
@@ -1351,56 +1351,34 @@ open_file_hook_proc(HWND of_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
return 0;
}
-/* Generate a list of the file types we can save this file as.
-
- "g_filetype" is the type it has now.
-
- "encap" is the encapsulation for its packets (which could be
- "unknown" or "per-packet").
-
- "filtered" is TRUE if we're to save only the packets that passed
- the display filter (in which case we have to save it using Wiretap)
- and FALSE if we're to save the entire file (in which case, if we're
- saving it in the type it has already, we can just copy it).
-
- The same applies for sel_curr, sel_all, sel_m_only, sel_m_range and sel_man_range
-*/
+/* Generate a list of the file types we can filter for in the open dialog. */
static void
-append_file_type(GArray *sa, int ft)
+append_file_extension_type(GArray *sa, int et)
{
GString* pattern_str = g_string_new("");
GString* description_str = g_string_new("");
+ const struct file_extension_info *extension_info;
gchar sep;
GSList *extensions_list, *extension;
TCHAR *str16;
guint16 zero = 0;
- extensions_list = wtap_get_file_extensions_list(ft, TRUE);
- if (extensions_list == NULL) {
- /* This file type doesn't have any particular extension
- conventionally used for it, so we'll just use "*.*"
- as the pattern; on Windows, that matches all file names
- - even those with no extension - so we don't need to
- worry about compressed file extensions. (It does not
- do so on UN*X; the right pattern on UN*X would just
- be "*".) */
- g_string_printf(pattern_str, "*.*");
- } else {
- /* Construct the list of patterns. */
- g_string_printf(pattern_str, "");
- sep = '\0';
- for (extension = extensions_list; extension != NULL;
- extension = g_slist_next(extension)) {
- if (sep != '\0')
- g_string_append_c(pattern_str, sep);
- g_string_append_printf(pattern_str, "*.%s", (char *)extension->data);
- sep = ';';
- }
- wtap_free_file_extensions_list(extensions_list);
+ /* Construct the list of patterns. */
+ extensions_list = wtap_get_file_extension_type_extensions(et);
+ g_string_printf(pattern_str, "");
+ sep = '\0';
+ for (extension = extensions_list; extension != NULL;
+ extension = g_slist_next(extension)) {
+ if (sep != '\0')
+ g_string_append_c(pattern_str, sep);
+ g_string_append_printf(pattern_str, "*.%s", (char *)extension->data);
+ sep = ';';
}
+ wtap_free_extensions_list(extensions_list);
/* Construct the description. */
- g_string_printf(description_str, "%s (%s)", wtap_file_type_string(ft),
+ g_string_printf(description_str, "%s (%s)",
+ wtap_get_file_extension_type_name(et),
pattern_str->str);
str16 = utf_8to16(description_str->str);
sa = g_array_append_vals(sa, str16, (guint) strlen(description_str->str));
@@ -1472,17 +1450,14 @@ build_file_open_type_list(void) {
g_string_append_printf(pattern_str, "*.%s", (char *)extension->data);
sep = ';';
}
- wtap_free_file_extensions_list(extensions_list);
+ wtap_free_extensions_list(extensions_list);
str16 = utf_8to16(pattern_str->str);
sa = g_array_append_vals(sa, str16, (guint) strlen(pattern_str->str));
sa = g_array_append_val(sa, zero);
- /* Include all the file types Wireshark supports. */
- for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) {
- if (ft == WTAP_FILE_UNKNOWN)
- continue; /* not a real file type */
-
- append_file_type(sa, ft);
+ /* Include all the file type extensions Wireshark supports. */
+ for (et = 0; et < wtap_get_num_file_type_extensions; et++) {
+ append_file_extension_type(sa, et);
}
/* terminate the array */
@@ -1491,6 +1466,68 @@ build_file_open_type_list(void) {
return (TCHAR *) g_array_free(sa, FALSE /*free_segment*/);
}
+/* Generate a list of the file types we can save this file as.
+
+ "g_filetype" is the type it has now.
+
+ "encap" is the encapsulation for its packets (which could be
+ "unknown" or "per-packet").
+
+ "filtered" is TRUE if we're to save only the packets that passed
+ the display filter (in which case we have to save it using Wiretap)
+ and FALSE if we're to save the entire file (in which case, if we're
+ saving it in the type it has already, we can just copy it).
+
+ The same applies for sel_curr, sel_all, sel_m_only, sel_m_range and sel_man_range
+*/
+static void
+append_file_type(GArray *sa, int ft)
+{
+ GString* pattern_str = g_string_new("");
+ GString* description_str = g_string_new("");
+ gchar sep;
+ GSList *extensions_list, *extension;
+ TCHAR *str16;
+ guint16 zero = 0;
+
+ extensions_list = wtap_get_file_extensions_list(ft, TRUE);
+ if (extensions_list == NULL) {
+ /* This file type doesn't have any particular extension
+ conventionally used for it, so we'll just use "*.*"
+ as the pattern; on Windows, that matches all file names
+ - even those with no extension - so we don't need to
+ worry about compressed file extensions. (It does not
+ do so on UN*X; the right pattern on UN*X would just
+ be "*".) */
+ g_string_printf(pattern_str, "*.*");
+ } else {
+ /* Construct the list of patterns. */
+ g_string_printf(pattern_str, "");
+ sep = '\0';
+ for (extension = extensions_list; extension != NULL;
+ extension = g_slist_next(extension)) {
+ if (sep != '\0')
+ g_string_append_c(pattern_str, sep);
+ g_string_append_printf(pattern_str, "*.%s", (char *)extension->data);
+ sep = ';';
+ }
+ wtap_free_extensions_list(extensions_list);
+ }
+
+ /* Construct the description. */
+ g_string_printf(description_str, "%s (%s)", wtap_file_type_string(ft),
+ pattern_str->str);
+ str16 = utf_8to16(description_str->str);
+ sa = g_array_append_vals(sa, str16, (guint) strlen(description_str->str));
+ sa = g_array_append_val(sa, zero);
+ g_string_free(description_str, TRUE);
+
+ str16 = utf_8to16(pattern_str->str);
+ sa = g_array_append_vals(sa, str16, (guint) strlen(pattern_str->str));
+ sa = g_array_append_val(sa, zero);
+ g_string_free(pattern_str, TRUE);
+}
+
static TCHAR *
build_file_save_type_list(GArray *savable_file_types) {
guint i;