update epan/dissectors/pidl/drsuapi/drsuapi.idl from samba
[wireshark-sm.git] / ui / qt / packet_range_group_box.cpp
blob5836b3ebc1f0d58c70fe182e97fc3c0d2b694e84
1 /* packet_range_group_box.cpp
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 #include "packet_range_group_box.h"
11 #include <ui_packet_range_group_box.h>
12 #include <wsutil/ws_assert.h>
14 PacketRangeGroupBox::PacketRangeGroupBox(QWidget *parent) :
15 QGroupBox(parent),
16 pr_ui_(new Ui::PacketRangeGroupBox),
17 range_(NULL),
18 syntax_state_(SyntaxLineEdit::Empty)
20 pr_ui_->setupUi(this);
21 setFlat(true);
23 pr_ui_->displayedButton->setChecked(true);
24 pr_ui_->allButton->setChecked(true);
27 PacketRangeGroupBox::~PacketRangeGroupBox()
29 delete pr_ui_;
32 void PacketRangeGroupBox::initRange(packet_range_t *range, QString selRange) {
33 if (!range) return;
35 range_ = nullptr;
36 // Set this before setting range_ so that on_dependedCheckBox_toggled
37 // doesn't trigger an extra updateCounts().
38 // (We could instead manually connect and disconnect signals and slots
39 // after getting a range, instead of checking for range_ in all the
40 // slots.)
41 pr_ui_->dependedCheckBox->setChecked(range->include_dependents);
43 range_ = range;
45 if (range_->process_filtered) {
46 pr_ui_->displayedButton->setChecked(true);
47 } else {
48 pr_ui_->capturedButton->setChecked(true);
51 if (selRange.length() > 0)
52 packet_range_convert_selection_str(range_, selRange.toUtf8().constData());
54 if (range_->user_range) {
55 char* tmp_str = range_convert_range(NULL, range_->user_range);
56 pr_ui_->rangeLineEdit->setText(tmp_str);
57 wmem_free(NULL, tmp_str);
59 updateCounts();
62 bool PacketRangeGroupBox::isValid() {
63 if (pr_ui_->rangeButton->isChecked() && syntax_state_ != SyntaxLineEdit::Empty) {
64 return false;
66 return true;
69 void PacketRangeGroupBox::updateCounts() {
70 SyntaxLineEdit::SyntaxState orig_ss = syntax_state_;
71 bool displayed_checked = pr_ui_->displayedButton->isChecked();
72 bool can_select;
73 bool selected_packets;
74 int ignored_cnt = 0, displayed_ignored_cnt = 0;
75 int depended_cnt = 0, displayed_depended_cnt = 0;
76 int label_count;
78 if (!range_ || !range_->cf) return;
80 if (range_->displayed_cnt != 0) {
81 pr_ui_->displayedButton->setEnabled(true);
82 } else {
83 displayed_checked = false;
84 pr_ui_->capturedButton->setChecked(true);
85 pr_ui_->displayedButton->setEnabled(false);
88 // All / Captured
89 pr_ui_->allCapturedLabel->setEnabled(!displayed_checked);
90 label_count = range_->cf->count;
91 if (range_->remove_ignored) {
92 label_count -= range_->ignored_cnt;
94 pr_ui_->allCapturedLabel->setText(QStringLiteral("%1").arg(label_count));
96 // All / Displayed
97 pr_ui_->allDisplayedLabel->setEnabled(displayed_checked);
98 if (range_->include_dependents) {
99 label_count = range_->displayed_plus_dependents_cnt;
100 } else {
101 label_count = range_->displayed_cnt;
103 if (range_->remove_ignored) {
104 label_count -= range_->displayed_ignored_cnt;
106 pr_ui_->allDisplayedLabel->setText(QStringLiteral("%1").arg(label_count));
108 // Selected / Captured + Displayed
109 can_select = (range_->selection_range_cnt > 0 || range_->displayed_selection_range_cnt > 0);
110 if (can_select) {
111 pr_ui_->selectedButton->setEnabled(true);
112 pr_ui_->selectedCapturedLabel->setEnabled(!displayed_checked);
113 pr_ui_->selectedDisplayedLabel->setEnabled(displayed_checked);
115 if (range_->include_dependents) {
116 label_count = range_->selected_plus_depends_cnt;
117 } else {
118 label_count = range_->selection_range_cnt;
120 if (range_->remove_ignored) {
121 label_count -= range_->ignored_selection_range_cnt;
123 pr_ui_->selectedCapturedLabel->setText(QString::number(label_count));
124 if (range_->include_dependents) {
125 label_count = range_->displayed_selected_plus_depends_cnt;
126 } else {
127 label_count = range_->displayed_selection_range_cnt;
129 if (range_->remove_ignored) {
130 label_count -= range_->displayed_ignored_selection_range_cnt;
132 pr_ui_->selectedDisplayedLabel->setText(QString::number(label_count));
133 } else {
134 if (range_->process == range_process_selected) {
135 pr_ui_->allButton->setChecked(true);
137 pr_ui_->selectedButton->setEnabled(false);
138 pr_ui_->selectedCapturedLabel->setEnabled(false);
139 pr_ui_->selectedDisplayedLabel->setEnabled(false);
141 pr_ui_->selectedCapturedLabel->setText("0");
142 pr_ui_->selectedDisplayedLabel->setText("0");
145 // Marked / Captured + Displayed
146 if (displayed_checked) {
147 selected_packets = (range_->displayed_marked_cnt != 0);
148 } else {
149 selected_packets = (range_->cf->marked_count > 0);
151 if (selected_packets) {
152 pr_ui_->markedButton->setEnabled(true);
153 pr_ui_->markedCapturedLabel->setEnabled(!displayed_checked);
154 pr_ui_->markedDisplayedLabel->setEnabled(displayed_checked);
155 } else {
156 if (range_->process == range_process_marked) {
157 pr_ui_->allButton->setChecked(true);
159 pr_ui_->markedButton->setEnabled(false);
160 pr_ui_->markedCapturedLabel->setEnabled(false);
161 pr_ui_->markedDisplayedLabel->setEnabled(false);
163 if (range_->include_dependents) {
164 label_count = range_->marked_plus_depends_cnt;
165 } else {
166 label_count = range_->cf->marked_count;
168 if (range_->remove_ignored) {
169 label_count -= range_->ignored_marked_cnt;
171 pr_ui_->markedCapturedLabel->setText(QStringLiteral("%1").arg(label_count));
172 if (range_->include_dependents) {
173 label_count = range_->displayed_marked_plus_depends_cnt;
174 } else {
175 label_count = range_->displayed_marked_cnt;
177 if (range_->remove_ignored) {
178 label_count -= range_->displayed_ignored_marked_cnt;
180 pr_ui_->markedDisplayedLabel->setText(QStringLiteral("%1").arg(label_count));
182 // First to last marked / Captured + Displayed
183 if (displayed_checked) {
184 selected_packets = (range_->displayed_mark_range_cnt != 0);
185 } else {
186 selected_packets = (range_->mark_range_cnt != 0);
188 if (selected_packets) {
189 pr_ui_->ftlMarkedButton->setEnabled(true);
190 pr_ui_->ftlCapturedLabel->setEnabled(!displayed_checked);
191 pr_ui_->ftlDisplayedLabel->setEnabled(displayed_checked);
192 } else {
193 if (range_->process == range_process_marked_range) {
194 pr_ui_->allButton->setChecked(true);
196 pr_ui_->ftlMarkedButton->setEnabled(false);
197 pr_ui_->ftlCapturedLabel->setEnabled(false);
198 pr_ui_->ftlDisplayedLabel->setEnabled(false);
200 if (range_->include_dependents) {
201 label_count = range_->mark_range_plus_depends_cnt;
202 } else {
203 label_count = range_->mark_range_cnt;
205 if (range_->remove_ignored) {
206 label_count -= range_->ignored_mark_range_cnt;
208 pr_ui_->ftlCapturedLabel->setText(QStringLiteral("%1").arg(label_count));
209 if (range_->include_dependents) {
210 label_count = range_->displayed_mark_range_plus_depends_cnt;
211 } else {
212 label_count = range_->displayed_mark_range_cnt;
214 if (range_->remove_ignored) {
215 label_count -= range_->displayed_ignored_mark_range_cnt;
217 pr_ui_->ftlDisplayedLabel->setText(QStringLiteral("%1").arg(label_count));
219 // User specified / Captured + Displayed
221 pr_ui_->rangeButton->setEnabled(true);
222 pr_ui_->rangeCapturedLabel->setEnabled(!displayed_checked);
223 pr_ui_->rangeDisplayedLabel->setEnabled(displayed_checked);
225 packet_range_convert_str(range_, pr_ui_->rangeLineEdit->text().toUtf8().constData());
227 switch (packet_range_check(range_)) {
229 case CVT_NO_ERROR:
230 if (range_->include_dependents) {
231 label_count = range_->user_range_plus_depends_cnt;
232 } else {
233 label_count = range_->user_range_cnt;
235 if (range_->remove_ignored) {
236 label_count -= range_->ignored_user_range_cnt;
238 pr_ui_->rangeCapturedLabel->setText(QStringLiteral("%1").arg(label_count));
239 if (range_->include_dependents) {
240 label_count = range_->displayed_user_range_plus_depends_cnt;
241 } else {
242 label_count = range_->displayed_user_range_cnt;
244 if (range_->remove_ignored) {
245 label_count -= range_->displayed_ignored_user_range_cnt;
247 pr_ui_->rangeDisplayedLabel->setText(QStringLiteral("%1").arg(label_count));
248 syntax_state_ = SyntaxLineEdit::Empty;
249 break;
251 case CVT_SYNTAX_ERROR:
252 pr_ui_->rangeCapturedLabel->setText("<small><i>Bad range</i></small>");
253 pr_ui_->rangeDisplayedLabel->setText("-");
254 syntax_state_ = SyntaxLineEdit::Invalid;
255 break;
257 case CVT_NUMBER_TOO_BIG:
258 pr_ui_->rangeCapturedLabel->setText("<small><i>Number too large</i></small>");
259 pr_ui_->rangeDisplayedLabel->setText("-");
260 syntax_state_ = SyntaxLineEdit::Invalid;
261 break;
263 default:
264 ws_assert_not_reached();
265 return;
268 // Ignored
269 switch(range_->process) {
270 case(range_process_all):
271 ignored_cnt = range_->ignored_cnt;
272 displayed_ignored_cnt = range_->displayed_ignored_cnt;
273 break;
274 case(range_process_selected):
275 ignored_cnt = range_->ignored_selection_range_cnt;
276 displayed_ignored_cnt = range_->displayed_ignored_selection_range_cnt;
277 break;
278 case(range_process_marked):
279 ignored_cnt = range_->ignored_marked_cnt;
280 displayed_ignored_cnt = range_->displayed_ignored_marked_cnt;
281 break;
282 case(range_process_marked_range):
283 ignored_cnt = range_->ignored_mark_range_cnt;
284 displayed_ignored_cnt = range_->displayed_ignored_mark_range_cnt;
285 break;
286 case(range_process_user_range):
287 ignored_cnt = range_->ignored_user_range_cnt;
288 displayed_ignored_cnt = range_->displayed_ignored_user_range_cnt;
289 break;
290 default:
291 ws_assert_not_reached();
294 if (displayed_checked)
295 selected_packets = (displayed_ignored_cnt != 0);
296 else
297 selected_packets = (ignored_cnt != 0);
299 if (selected_packets) {
300 pr_ui_->ignoredCheckBox->setEnabled(true);
301 pr_ui_->ignoredCapturedLabel->setEnabled(!displayed_checked);
302 pr_ui_->ignoredDisplayedLabel->setEnabled(displayed_checked);
303 } else {
304 pr_ui_->ignoredCheckBox->setEnabled(false);
305 pr_ui_->ignoredCapturedLabel->setEnabled(false);
306 pr_ui_->ignoredDisplayedLabel->setEnabled(false);
308 pr_ui_->ignoredCapturedLabel->setText(QStringLiteral("%1").arg(ignored_cnt));
309 pr_ui_->ignoredDisplayedLabel->setText(QStringLiteral("%1").arg(displayed_ignored_cnt));
311 // Depended upon / Displayed + Captured
312 switch(range_->process) {
313 case(range_process_all):
314 depended_cnt = 0;
315 displayed_depended_cnt = range_->displayed_plus_dependents_cnt - range_->displayed_cnt;
316 break;
317 case(range_process_selected):
318 depended_cnt = range_->selected_plus_depends_cnt - range_->selection_range_cnt;
319 displayed_depended_cnt = range_->displayed_selected_plus_depends_cnt - range_->displayed_selection_range_cnt;
320 break;
321 case(range_process_marked):
322 depended_cnt = range_->marked_plus_depends_cnt - range_->cf->marked_count;
323 displayed_depended_cnt = range_->displayed_marked_plus_depends_cnt - range_->displayed_marked_cnt;
324 break;
325 case(range_process_marked_range):
326 depended_cnt = range_->mark_range_plus_depends_cnt - range_->mark_range_cnt;
327 displayed_depended_cnt = range_->displayed_mark_range_plus_depends_cnt - range_->displayed_mark_range_cnt;
328 break;
329 case(range_process_user_range):
330 depended_cnt = range_->user_range_plus_depends_cnt - range_->user_range_cnt;
331 displayed_depended_cnt = range_->displayed_user_range_plus_depends_cnt - range_->displayed_user_range_cnt;
332 break;
333 default:
334 depended_cnt = 0;
335 displayed_depended_cnt = 0;
336 break;
339 if (displayed_checked) {
340 selected_packets = (displayed_depended_cnt != 0);
341 } else {
342 selected_packets = (depended_cnt != 0);
345 if (selected_packets) {
346 pr_ui_->dependedCheckBox->setEnabled(true);
347 pr_ui_->dependedCapturedLabel->setEnabled(!displayed_checked);
348 pr_ui_->dependedDisplayedLabel->setEnabled(displayed_checked);
349 } else {
350 pr_ui_->dependedCheckBox->setEnabled(false);
351 pr_ui_->dependedCapturedLabel->setEnabled(false);
352 pr_ui_->dependedDisplayedLabel->setEnabled(false);
354 pr_ui_->dependedCapturedLabel->setText(QStringLiteral("%1").arg(depended_cnt));
355 pr_ui_->dependedDisplayedLabel->setText(QStringLiteral("%1").arg(displayed_depended_cnt));
357 if (orig_ss != syntax_state_) {
358 pr_ui_->rangeLineEdit->setSyntaxState(syntax_state_);
359 emit validityChanged(isValid());
361 emit rangeChanged();
364 // Slots
366 void PacketRangeGroupBox::on_rangeLineEdit_textChanged(const QString &)
368 if (!pr_ui_->rangeButton->isChecked()) {
369 pr_ui_->rangeButton->setChecked(true);
370 } else {
371 updateCounts();
375 void PacketRangeGroupBox::processButtonToggled(bool checked, packet_range_e process) {
376 if (checked && range_) {
377 range_->process = process;
379 updateCounts();
382 void PacketRangeGroupBox::on_allButton_toggled(bool checked)
384 processButtonToggled(checked, range_process_all);
387 void PacketRangeGroupBox::on_selectedButton_toggled(bool checked)
389 processButtonToggled(checked, range_process_selected);
392 void PacketRangeGroupBox::on_markedButton_toggled(bool checked)
394 processButtonToggled(checked, range_process_marked);
397 void PacketRangeGroupBox::on_ftlMarkedButton_toggled(bool checked)
399 processButtonToggled(checked, range_process_marked_range);
402 void PacketRangeGroupBox::on_rangeButton_toggled(bool checked)
404 processButtonToggled(checked, range_process_user_range);
407 void PacketRangeGroupBox::on_capturedButton_toggled(bool checked)
409 if (checked) {
410 if (range_) range_->process_filtered = false;
411 updateCounts();
415 void PacketRangeGroupBox::on_displayedButton_toggled(bool checked)
417 if (checked) {
418 if (range_) range_->process_filtered = true;
419 updateCounts();
423 void PacketRangeGroupBox::on_ignoredCheckBox_toggled(bool checked)
425 if (range_) range_->remove_ignored = checked ? true : false;
426 updateCounts();
429 void PacketRangeGroupBox::on_dependedCheckBox_toggled(bool checked)
431 if (range_) {
432 range_->include_dependents = checked ? true : false;
433 updateCounts();