1 /* capture_file_dialog.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 CAPTURE_FILE_DIALOG_H
11 #define CAPTURE_FILE_DIALOG_H
12
13 #include <ui/qt/widgets/wireshark_file_dialog.h>
14
15 #ifndef Q_OS_WIN
16 #include <ui/qt/widgets/display_filter_edit.h>
17 #include "packet_range_group_box.h"
18 #include "ui/help_url.h"
19 #endif // Q_OS_WIN
20
21 #include <ui/packet_range.h>
22
23 #include <ui/qt/models/packet_list_record.h>
24 #include "cfile.h"
25
26 #include "ui/file_dialog.h"
27
28 #include <QVBoxLayout>
29 #include <QLabel>
30 #include <QRadioButton>
CaptureEvent(Context ctx,EventType evt)31 #include <QCheckBox>
32 #include <QDialogButtonBox>
33 #include <QComboBox>
34
35 class CaptureFileDialog : public WiresharkFileDialog
36 {
37 // The GTK+ Open Capture File dialog has the following elements and features:
38 // - The ability to select a capture file from a list of known extensions
39 // - A display filter entry
40 // - Name resolution checkboxes
41 // - Capture file preview information
42 // Ideally we should provide similar functionality here.
43 //
44 // You can subclass QFileDialog (which we've done here) and add widgets as
45 // described at
46 // https://web.archive.org/web/20100528190736/http://developer.qt.nokia.com/faq/answer/how_can_i_add_widgets_to_my_qfiledialog_instance
47 // However, Qt's idea of what a file dialog looks like isn't what Microsoft
48 // and Apple think a file dialog looks like.
49 //
50 // On Windows Vista and later we should probably use IFileOpenDialog. On earlier
51 // versions of Windows (including XP) we should use GetOpenFileName, which is
52 // what we do in ui/win32/file_dlg_win32.c. macOS we should use NSOpenPanel. On
53 // other platforms we should fall back to QFileDialog.
54 //
55 // Yes, that's four implementations of the same window.
56 //
57 // If a plain native open file dialog is good enough we can just the static
58 // version of QFileDialog::getOpenFileName. (Commenting out Q_OBJECT and
59 // "explicit" below has the same effect.)
60
61 Q_OBJECT
62 public:
63 explicit CaptureFileDialog(QWidget *parent = NULL, capture_file *cf = NULL, QString &display_filter = *new QString());
64 static check_savability_t checkSaveAsWithComments(QWidget *
65 #if defined(Q_OS_WIN)
66 parent
67 #endif // Q_OS_WIN
68 , capture_file *cf, int file_type);
69
70 int mergeType();
71 int selectedFileType();
72 wtap_compression_type compressionType();
73
74 private:
75 capture_file *cap_file_;
76 QString &display_filter_;
77
78 #if !defined(Q_OS_WIN)
79 void addMergeControls(QVBoxLayout &v_box);
80 void addFormatTypeSelector(QVBoxLayout &v_box);
81 void addDisplayFilterEdit();
82 void addPreview(QVBoxLayout &v_box);
83 QString fileExtensionType(int et, bool extension_globs = true);
84 QString fileType(int ft, QStringList &suffixes);
85 QStringList buildFileOpenTypeList(void);
86
87 QVBoxLayout left_v_box_;
88 QVBoxLayout right_v_box_;
89
90 DisplayFilterEdit* display_filter_edit_;
91 int last_row_;
92
93 QLabel preview_format_;
94 QLabel preview_size_;
95 QLabel preview_first_elapsed_;
96 QList<QLabel *> preview_labels_;
97
98 QRadioButton merge_prepend_;
99 QRadioButton merge_chrono_;
100 QRadioButton merge_append_;
101
102 QComboBox format_type_;
103 QHash<QString, int> type_hash_;
104 QHash<QString, QStringList> type_suffixes_;
105
106 void addGzipControls(QVBoxLayout &v_box);
107 void addRangeControls(QVBoxLayout &v_box, packet_range_t *range, QString selRange = QString());
108 QDialogButtonBox *addHelpButton(topic_action_e help_topic);
109
110 QStringList buildFileSaveAsTypeList(bool must_support_comments);
111
112 int default_ft_;
113
114 QCheckBox compress_;
115
116 PacketRangeGroupBox packet_range_group_box_;
117 QPushButton *save_bt_;
118 topic_action_e help_topic_;
119
120 #else // Q_OS_WIN
121 int file_type_;
122 int merge_type_;
123 wtap_compression_type compression_type_;
124 #endif // Q_OS_WIN
125
126 signals:
127
128 public slots:
129
130 #ifndef Q_OS_WIN
131 void accept() Q_DECL_OVERRIDE;
132 #endif
133 int exec() Q_DECL_OVERRIDE;
134 int open(QString &file_name, unsigned int &type);
135 check_savability_t saveAs(QString &file_name, bool must_support_comments);
136 check_savability_t exportSelectedPackets(QString &file_name, packet_range_t *range, QString selRange = QString());
137 int merge(QString &file_name);
138
139 private slots:
140 #if !defined(Q_OS_WIN)
141 void fixFilenameExtension();
142 void preview(const QString & path);
143 void on_buttonBox_helpRequested();
144 #endif // Q_OS_WIN
145 };
146
147 #endif // CAPTURE_FILE_DIALOG_H
148