Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / ui / qt / module_preferences_scroll_area.cpp
blob0fdda6f1f410c478a04ed19171e32e36b875ab8a
1 /* module_preferences_scroll_area.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 "module_preferences_scroll_area.h"
11 #include <ui_module_preferences_scroll_area.h>
12 #include <ui/qt/widgets/syntax_line_edit.h>
13 #include <ui/qt/widgets/dissector_syntax_line_edit.h>
14 #include "ui/qt/widgets/wireshark_file_dialog.h"
15 #include <ui/qt/utils/qt_ui_utils.h>
16 #include "uat_dialog.h"
17 #include "main_application.h"
18 #include "ui/qt/main_window.h"
20 #include <ui/qt/utils/variant_pointer.h>
22 #include <epan/prefs-int.h>
24 #include <wsutil/utf8_entities.h>
26 #include <QAbstractButton>
27 #include <QButtonGroup>
28 #include <QCheckBox>
29 #include <QComboBox>
30 #include <QHBoxLayout>
31 #include <QLabel>
32 #include <QLineEdit>
33 #include <QMainWindow>
34 #include <QPushButton>
35 #include <QRadioButton>
36 #include <QScrollBar>
37 #include <QSpacerItem>
38 #include <QRegularExpression>
40 const char *pref_prop_ = "pref_ptr";
42 // Escape our ampersands so that Qt won't try to interpret them as
43 // mnemonics.
44 static const QString title_to_shortcut(const char *title) {
45 QString shortcut_str(title);
46 shortcut_str.replace('&', "&&");
47 return shortcut_str;
50 typedef struct
52 QVBoxLayout *layout;
53 QString moduleName;
54 } prefSearchData;
56 extern "C" {
57 // Callbacks prefs routines
59 /* Add a single preference to the QVBoxLayout of a preference page */
60 static unsigned
61 pref_show(pref_t *pref, void *user_data)
63 prefSearchData * data = static_cast<prefSearchData *>(user_data);
65 if (!pref || !data) return 0;
67 QVBoxLayout *vb = data->layout;
69 // Convert the pref description from plain text to rich text.
70 QString description = html_escape(prefs_get_description(pref));
71 QString name = QStringLiteral("%1.%2").arg(data->moduleName).arg(prefs_get_name(pref));
72 description.replace('\n', "<br/>");
73 QString tooltip = QStringLiteral("<span>%1</span><br/><br/>%2").arg(description).arg(name);
75 switch (prefs_get_type(pref)) {
76 case PREF_UINT:
78 QHBoxLayout *hb = new QHBoxLayout();
79 QLabel *label = new QLabel(prefs_get_title(pref));
80 label->setToolTip(tooltip);
81 hb->addWidget(label);
82 SyntaxLineEdit *uint_le = new SyntaxLineEdit();
83 uint_le->setToolTip(tooltip);
84 uint_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
85 uint_le->setMinimumWidth(uint_le->fontMetrics().height() * 8);
86 hb->addWidget(uint_le);
87 hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
88 vb->addLayout(hb);
89 break;
91 case PREF_BOOL:
93 QCheckBox *bool_cb = new QCheckBox(title_to_shortcut(prefs_get_title(pref)));
94 bool_cb->setToolTip(tooltip);
95 bool_cb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
96 vb->addWidget(bool_cb);
97 break;
99 case PREF_ENUM:
101 const enum_val_t *ev;
102 ev = prefs_get_enumvals(pref);
103 if (!ev || !ev->description)
104 return 0;
106 if (prefs_get_enum_radiobuttons(pref)) {
107 QLabel *label = new QLabel(prefs_get_title(pref));
108 label->setToolTip(tooltip);
109 vb->addWidget(label);
110 QButtonGroup *enum_bg = new QButtonGroup(vb);
111 while (ev->description) {
112 QRadioButton *enum_rb = new QRadioButton(title_to_shortcut(ev->description));
113 enum_rb->setToolTip(tooltip);
114 QStyleOption style_opt;
115 enum_rb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
116 enum_rb->setStyleSheet(QStringLiteral(
117 "QRadioButton {"
118 " margin-left: %1px;"
121 .arg(enum_rb->style()->subElementRect(QStyle::SE_CheckBoxContents, &style_opt).left()));
122 enum_bg->addButton(enum_rb, ev->value);
123 vb->addWidget(enum_rb);
124 ev++;
126 } else {
127 QHBoxLayout *hb = new QHBoxLayout();
128 QComboBox *enum_cb = new QComboBox();
129 enum_cb->setToolTip(tooltip);
130 enum_cb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
131 for (ev = prefs_get_enumvals(pref); ev && ev->description; ev++) {
132 enum_cb->addItem(ev->description, QVariant(ev->value));
134 QLabel * lbl = new QLabel(prefs_get_title(pref));
135 lbl->setToolTip(tooltip);
136 hb->addWidget(lbl);
137 hb->addWidget(enum_cb);
138 hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
139 vb->addLayout(hb);
141 break;
143 case PREF_STRING:
145 QHBoxLayout *hb = new QHBoxLayout();
146 QLabel *label = new QLabel(prefs_get_title(pref));
147 label->setToolTip(tooltip);
148 hb->addWidget(label);
149 QLineEdit *string_le = new QLineEdit();
150 string_le->setToolTip(tooltip);
151 string_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
152 string_le->setMinimumWidth(string_le->fontMetrics().height() * 20);
153 hb->addWidget(string_le);
154 hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
155 vb->addLayout(hb);
156 break;
158 case PREF_PASSWORD:
160 QHBoxLayout *hb = new QHBoxLayout();
161 QLabel *label = new QLabel(prefs_get_title(pref));
162 label->setToolTip(tooltip);
163 hb->addWidget(label);
164 QLineEdit *string_le = new QLineEdit();
165 string_le->setToolTip(tooltip);
166 string_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
167 string_le->setMinimumWidth(string_le->fontMetrics().height() * 20);
168 string_le->setEchoMode(QLineEdit::PasswordEchoOnEdit);
169 hb->addWidget(string_le);
170 hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
171 vb->addLayout(hb);
172 break;
174 case PREF_DISSECTOR:
176 QHBoxLayout *hb = new QHBoxLayout();
177 QLabel *label = new QLabel(prefs_get_title(pref));
178 label->setToolTip(tooltip);
179 hb->addWidget(label);
180 QLineEdit *string_le = new DissectorSyntaxLineEdit();
181 string_le->setToolTip(tooltip);
182 string_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
183 string_le->setMinimumWidth(string_le->fontMetrics().height() * 20);
184 hb->addWidget(string_le);
185 hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
186 vb->addLayout(hb);
187 break;
189 case PREF_DECODE_AS_RANGE:
190 case PREF_RANGE:
192 QHBoxLayout *hb = new QHBoxLayout();
193 QLabel *label = new QLabel(prefs_get_title(pref));
194 label->setToolTip(tooltip);
195 hb->addWidget(label);
196 SyntaxLineEdit *range_se = new SyntaxLineEdit();
197 range_se->setToolTip(tooltip);
198 range_se->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
199 range_se->setMinimumWidth(range_se->fontMetrics().height() * 20);
200 hb->addWidget(range_se);
201 hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
202 vb->addLayout(hb);
203 break;
205 case PREF_STATIC_TEXT:
207 QLabel *label = new QLabel(prefs_get_title(pref));
208 label->setToolTip(tooltip);
209 label->setWordWrap(true);
210 vb->addWidget(label);
211 break;
213 case PREF_UAT:
215 QHBoxLayout *hb = new QHBoxLayout();
216 QLabel *label = new QLabel(prefs_get_title(pref));
217 label->setToolTip(tooltip);
218 hb->addWidget(label);
219 QPushButton *uat_pb = new QPushButton(QObject::tr("Edit…"));
220 uat_pb->setToolTip(tooltip);
221 uat_pb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
222 hb->addWidget(uat_pb);
223 hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
224 vb->addLayout(hb);
225 break;
227 case PREF_SAVE_FILENAME:
228 case PREF_OPEN_FILENAME:
229 case PREF_DIRNAME:
231 QLabel *label = new QLabel(prefs_get_title(pref));
232 label->setToolTip(tooltip);
233 vb->addWidget(label);
234 QHBoxLayout *hb = new QHBoxLayout();
235 QLineEdit *path_le = new QLineEdit();
236 path_le->setToolTip(tooltip);
237 QStyleOption style_opt;
238 path_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
239 path_le->setMinimumWidth(path_le->fontMetrics().height() * 20);
240 path_le->setStyleSheet(QStringLiteral(
241 "QLineEdit {"
242 " margin-left: %1px;"
245 .arg(path_le->style()->subElementRect(QStyle::SE_CheckBoxContents, &style_opt).left()));
246 hb->addWidget(path_le);
247 QPushButton *path_pb = new QPushButton(QObject::tr("Browse…"));
248 path_pb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
249 hb->addWidget(path_pb);
250 hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
251 vb->addLayout(hb);
252 break;
254 case PREF_COLOR:
256 // XXX - Not needed yet. When it is needed we can add a label + QFrame which pops up a
257 // color picker similar to the Font and Colors prefs.
258 break;
260 case PREF_PROTO_TCP_SNDAMB_ENUM:
262 const enum_val_t *ev;
263 ev = prefs_get_enumvals(pref);
264 if (!ev || !ev->description)
265 return 0;
267 if (prefs_get_enum_radiobuttons(pref)) {
268 QLabel *label = new QLabel(prefs_get_title(pref));
269 label->setToolTip(tooltip);
270 vb->addWidget(label);
271 QButtonGroup *enum_bg = new QButtonGroup(vb);
272 while (ev->description) {
273 QRadioButton *enum_rb = new QRadioButton(title_to_shortcut(ev->description));
274 enum_rb->setToolTip(tooltip);
275 QStyleOption style_opt;
276 enum_rb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
277 enum_rb->setStyleSheet(QStringLiteral(
278 "QRadioButton {"
279 " margin-left: %1px;"
282 .arg(enum_rb->style()->subElementRect(QStyle::SE_CheckBoxContents, &style_opt).left()));
283 enum_bg->addButton(enum_rb, ev->value);
284 vb->addWidget(enum_rb);
285 ev++;
287 } else {
288 QHBoxLayout *hb = new QHBoxLayout();
289 QComboBox *enum_cb = new QComboBox();
290 enum_cb->setToolTip(tooltip);
291 enum_cb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
292 for (ev = prefs_get_enumvals(pref); ev && ev->description; ev++) {
293 enum_cb->addItem(ev->description, QVariant(ev->value));
295 QLabel * lbl = new QLabel(prefs_get_title(pref));
296 lbl->setToolTip(tooltip);
297 hb->addWidget(lbl);
298 hb->addWidget(enum_cb);
299 hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
300 vb->addLayout(hb);
302 break;
304 default:
305 break;
307 return 0;
310 } // extern "C"
312 ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidget *parent) :
313 QScrollArea(parent),
314 ui(new Ui::ModulePreferencesScrollArea),
315 module_(module)
317 ui->setupUi(this);
319 if (!module) return;
321 /* Show the preference's description at the top of the page */
322 QFont font;
323 font.setBold(true);
324 QLabel *label = new QLabel(module->description);
325 label->setFont(font);
326 ui->verticalLayout->addWidget(label);
328 prefSearchData searchData;
329 searchData.layout = ui->verticalLayout;
330 searchData.moduleName = module->name;
332 /* Add items for each of the preferences */
333 prefs_pref_foreach(module, pref_show, &searchData);
335 foreach (QLineEdit *le, findChildren<QLineEdit *>()) {
336 pref_t *pref = VariantPointer<pref_t>::asPtr(le->property(pref_prop_));
337 if (!pref) continue;
339 switch (prefs_get_type(pref)) {
340 case PREF_UINT:
341 connect(le, &QLineEdit::textEdited, this, &ModulePreferencesScrollArea::uintLineEditTextEdited);
342 break;
343 case PREF_STRING:
344 case PREF_SAVE_FILENAME:
345 case PREF_OPEN_FILENAME:
346 case PREF_DIRNAME:
347 case PREF_PASSWORD:
348 case PREF_DISSECTOR:
349 connect(le, &QLineEdit::textEdited, this, &ModulePreferencesScrollArea::stringLineEditTextEdited);
350 break;
351 case PREF_RANGE:
352 case PREF_DECODE_AS_RANGE:
353 connect(le, &QLineEdit::textEdited, this, &ModulePreferencesScrollArea::rangeSyntaxLineEditTextEdited);
354 break;
355 default:
356 break;
360 foreach (QCheckBox *cb, findChildren<QCheckBox *>()) {
361 pref_t *pref = VariantPointer<pref_t>::asPtr(cb->property(pref_prop_));
362 if (!pref) continue;
364 if (prefs_get_type(pref) == PREF_BOOL) {
365 connect(cb, &QCheckBox::toggled, this, &ModulePreferencesScrollArea::boolCheckBoxToggled);
369 foreach (QRadioButton *rb, findChildren<QRadioButton *>()) {
370 pref_t *pref = VariantPointer<pref_t>::asPtr(rb->property(pref_prop_));
371 if (!pref) continue;
373 if (prefs_get_type(pref) == PREF_ENUM && prefs_get_enum_radiobuttons(pref)) {
374 connect(rb, &QRadioButton::toggled, this, &ModulePreferencesScrollArea::enumRadioButtonToggled);
378 foreach (QComboBox *combo, findChildren<QComboBox *>()) {
379 pref_t *pref = VariantPointer<pref_t>::asPtr(combo->property(pref_prop_));
380 if (!pref) continue;
382 if (prefs_get_type(pref) == PREF_ENUM && !prefs_get_enum_radiobuttons(pref)) {
383 connect(combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
384 this, &ModulePreferencesScrollArea::enumComboBoxCurrentIndexChanged);
388 foreach (QComboBox *combo, findChildren<QComboBox *>()) {
389 pref_t *pref = VariantPointer<pref_t>::asPtr(combo->property(pref_prop_));
390 if (!pref) continue;
392 if (prefs_get_type(pref) == PREF_PROTO_TCP_SNDAMB_ENUM && !prefs_get_enum_radiobuttons(pref)) {
393 connect(combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
394 this, &ModulePreferencesScrollArea::enumComboBoxCurrentIndexChanged_PROTO_TCP);
398 foreach (QPushButton *pb, findChildren<QPushButton *>()) {
399 pref_t *pref = VariantPointer<pref_t>::asPtr(pb->property(pref_prop_));
400 if (!pref) continue;
402 switch (prefs_get_type(pref)) {
403 case PREF_UAT:
404 connect(pb, &QPushButton::clicked, this, &ModulePreferencesScrollArea::uatPushButtonClicked);
405 break;
406 case PREF_SAVE_FILENAME:
407 connect(pb, &QPushButton::clicked, this, &ModulePreferencesScrollArea::saveFilenamePushButtonClicked);
408 break;
409 case PREF_OPEN_FILENAME:
410 connect(pb, &QPushButton::clicked, this, &ModulePreferencesScrollArea::openFilenamePushButtonClicked);
411 break;
412 case PREF_DIRNAME:
413 connect(pb, &QPushButton::clicked, this, &ModulePreferencesScrollArea::dirnamePushButtonClicked);
414 break;
418 ui->verticalLayout->addSpacerItem(new QSpacerItem(10, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
421 ModulePreferencesScrollArea::~ModulePreferencesScrollArea()
423 delete ui;
426 void ModulePreferencesScrollArea::showEvent(QShowEvent *)
428 updateWidgets();
431 void ModulePreferencesScrollArea::resizeEvent(QResizeEvent *evt)
433 QScrollArea::resizeEvent(evt);
435 if (verticalScrollBar()->isVisible()) {
436 setFrameStyle(QFrame::StyledPanel);
437 } else {
438 setFrameStyle(QFrame::NoFrame);
442 void ModulePreferencesScrollArea::updateWidgets()
444 foreach (QLineEdit *le, findChildren<QLineEdit *>()) {
445 pref_t *pref = VariantPointer<pref_t>::asPtr(le->property(pref_prop_));
446 if (!pref) continue;
448 le->setText(gchar_free_to_qstring(prefs_pref_to_str(pref, pref_stashed)).remove(QRegularExpression("\n\t")));
451 foreach (QCheckBox *cb, findChildren<QCheckBox *>()) {
452 pref_t *pref = VariantPointer<pref_t>::asPtr(cb->property(pref_prop_));
453 if (!pref) continue;
455 if (prefs_get_type(pref) == PREF_BOOL) {
456 cb->setChecked(prefs_get_bool_value(pref, pref_stashed));
460 foreach (QRadioButton *enum_rb, findChildren<QRadioButton *>()) {
461 pref_t *pref = VariantPointer<pref_t>::asPtr(enum_rb->property(pref_prop_));
462 if (!pref) continue;
464 QButtonGroup *enum_bg = enum_rb->group();
465 if (!enum_bg) continue;
467 if (prefs_get_type(pref) == PREF_ENUM && prefs_get_enum_radiobuttons(pref)) {
468 if (prefs_get_enum_value(pref, pref_stashed) == enum_bg->id(enum_rb)) {
469 enum_rb->setChecked(true);
474 foreach (QComboBox *enum_cb, findChildren<QComboBox *>()) {
475 pref_t *pref = VariantPointer<pref_t>::asPtr(enum_cb->property(pref_prop_));
476 if (!pref) continue;
478 if (prefs_get_type(pref) == PREF_ENUM && !prefs_get_enum_radiobuttons(pref)) {
479 for (int i = 0; i < enum_cb->count(); i++) {
480 if (prefs_get_enum_value(pref, pref_stashed) == enum_cb->itemData(i).toInt()) {
481 enum_cb->setCurrentIndex(i);
486 if (prefs_get_type(pref) == PREF_PROTO_TCP_SNDAMB_ENUM && !prefs_get_enum_radiobuttons(pref)) {
487 if (prefs_get_list_value(pref, pref_stashed) == NULL) {
488 /* We haven't added a list of frames that could have their
489 * analysis changed. Set the current value to whatever the
490 * first selected frame has for its its TCP Sequence Analysis
491 * override.
493 MainWindow* topWidget = mainApp->mainWindow();
494 /* Ensure there is one unique or multiple selections. See issue 18642 */
495 if (topWidget->hasSelection() || topWidget->hasUniqueSelection()) {
496 frame_data * fdata = topWidget->frameDataForRow((topWidget->selectedRows()).at(0));
497 enum_cb->setCurrentIndex(enum_cb->findData(fdata->tcp_snd_manual_analysis));
498 QList<int> rows = topWidget->selectedRows();
499 foreach (int row, rows) {
500 frame_data * fdata = topWidget->frameDataForRow(row);
501 prefs_add_list_value(pref, fdata, pref_stashed);
504 } else {
505 /* The initial value was already set from the selected frames,
506 * use the current value from when the CB was changed. */
507 enum_cb->setCurrentIndex(enum_cb->findData(prefs_get_enum_value(pref, pref_current)));
513 void ModulePreferencesScrollArea::uintLineEditTextEdited(const QString &new_str)
515 SyntaxLineEdit *uint_le = qobject_cast<SyntaxLineEdit*>(sender());
516 if (!uint_le) return;
518 pref_t *pref = VariantPointer<pref_t>::asPtr(uint_le->property(pref_prop_));
519 if (!pref) return;
521 if (new_str.isEmpty()) {
522 /* Reset to default value; that is better than "whatever the last
523 * valid edited input was", and probably better than "empty means 0."
525 uint_le->setSyntaxState(SyntaxLineEdit::Empty);
526 reset_stashed_pref(pref);
527 return;
530 bool ok;
531 uint new_uint = new_str.toUInt(&ok, 0);
532 if (ok) {
533 uint_le->setSyntaxState(SyntaxLineEdit::Valid);
534 prefs_set_uint_value(pref, new_uint, pref_stashed);
535 } else {
536 uint_le->setSyntaxState(SyntaxLineEdit::Invalid);
537 /* Reset stashed value to the current real value, i.e., whatever it
538 * was when the dialog was opened. That's better than "whatever the
539 * last valid edited number was."
540 * XXX - The OK/Apply buttons should be disabled when a pref is invalid.
542 pref_stash(pref, NULL);
546 void ModulePreferencesScrollArea::boolCheckBoxToggled(bool checked)
548 QCheckBox *bool_cb = qobject_cast<QCheckBox*>(sender());
549 if (!bool_cb) return;
551 pref_t *pref = VariantPointer<pref_t>::asPtr(bool_cb->property(pref_prop_));
552 if (!pref) return;
554 prefs_set_bool_value(pref, checked, pref_stashed);
557 void ModulePreferencesScrollArea::enumRadioButtonToggled(bool checked)
559 if (!checked) return;
560 QRadioButton *enum_rb = qobject_cast<QRadioButton*>(sender());
561 if (!enum_rb) return;
563 QButtonGroup *enum_bg = enum_rb->group();
564 if (!enum_bg) return;
566 pref_t *pref = VariantPointer<pref_t>::asPtr(enum_rb->property(pref_prop_));
567 if (!pref) return;
569 if (enum_bg->checkedId() >= 0) {
570 prefs_set_enum_value(pref, enum_bg->checkedId(), pref_stashed);
574 void ModulePreferencesScrollArea::enumComboBoxCurrentIndexChanged(int index)
576 QComboBox *enum_cb = qobject_cast<QComboBox*>(sender());
577 if (!enum_cb) return;
579 pref_t *pref = VariantPointer<pref_t>::asPtr(enum_cb->property(pref_prop_));
580 if (!pref) return;
582 prefs_set_enum_value(pref, enum_cb->itemData(index).toInt(), pref_stashed);
585 void ModulePreferencesScrollArea::stringLineEditTextEdited(const QString &new_str)
587 QLineEdit *string_le = qobject_cast<QLineEdit*>(sender());
588 if (!string_le) return;
590 pref_t *pref = VariantPointer<pref_t>::asPtr(string_le->property(pref_prop_));
591 if (!pref) return;
593 prefs_set_string_value(pref, new_str.toStdString().c_str(), pref_stashed);
596 void ModulePreferencesScrollArea::rangeSyntaxLineEditTextEdited(const QString &new_str)
598 SyntaxLineEdit *range_se = qobject_cast<SyntaxLineEdit*>(sender());
599 if (!range_se) return;
601 pref_t *pref = VariantPointer<pref_t>::asPtr(range_se->property(pref_prop_));
602 if (!pref) return;
604 if (prefs_set_stashed_range_value(pref, new_str.toUtf8().constData())) {
605 if (new_str.isEmpty()) {
606 range_se->setSyntaxState(SyntaxLineEdit::Empty);
607 } else {
608 range_se->setSyntaxState(SyntaxLineEdit::Valid);
610 } else {
611 range_se->setSyntaxState(SyntaxLineEdit::Invalid);
615 void ModulePreferencesScrollArea::uatPushButtonClicked()
617 QPushButton *uat_pb = qobject_cast<QPushButton*>(sender());
618 if (!uat_pb) return;
620 pref_t *pref = VariantPointer<pref_t>::asPtr(uat_pb->property(pref_prop_));
621 if (!pref) return;
623 UatDialog *uat_dlg = new UatDialog(this, prefs_get_uat_value(pref));
624 uat_dlg->setWindowModality(Qt::ApplicationModal);
625 uat_dlg->setAttribute(Qt::WA_DeleteOnClose);
626 uat_dlg->show();
629 void ModulePreferencesScrollArea::saveFilenamePushButtonClicked()
631 QPushButton *filename_pb = qobject_cast<QPushButton*>(sender());
632 if (!filename_pb) return;
634 pref_t *pref = VariantPointer<pref_t>::asPtr(filename_pb->property(pref_prop_));
635 if (!pref) return;
637 QString filename = WiresharkFileDialog::getSaveFileName(this, mainApp->windowTitleString(prefs_get_title(pref)),
638 prefs_get_string_value(pref, pref_stashed));
640 if (!filename.isEmpty()) {
641 prefs_set_string_value(pref, QDir::toNativeSeparators(filename).toStdString().c_str(), pref_stashed);
642 updateWidgets();
646 void ModulePreferencesScrollArea::openFilenamePushButtonClicked()
648 QPushButton *filename_pb = qobject_cast<QPushButton*>(sender());
649 if (!filename_pb) return;
651 pref_t *pref = VariantPointer<pref_t>::asPtr(filename_pb->property(pref_prop_));
652 if (!pref) return;
654 QString filename = WiresharkFileDialog::getOpenFileName(this, mainApp->windowTitleString(prefs_get_title(pref)),
655 prefs_get_string_value(pref, pref_stashed));
656 if (!filename.isEmpty()) {
657 prefs_set_string_value(pref, QDir::toNativeSeparators(filename).toStdString().c_str(), pref_stashed);
658 updateWidgets();
662 void ModulePreferencesScrollArea::dirnamePushButtonClicked()
664 QPushButton *dirname_pb = qobject_cast<QPushButton*>(sender());
665 if (!dirname_pb) return;
667 pref_t *pref = VariantPointer<pref_t>::asPtr(dirname_pb->property(pref_prop_));
668 if (!pref) return;
670 QString dirname = WiresharkFileDialog::getExistingDirectory(this, mainApp->windowTitleString(prefs_get_title(pref)),
671 prefs_get_string_value(pref, pref_stashed));
673 if (!dirname.isEmpty()) {
674 prefs_set_string_value(pref, QDir::toNativeSeparators(dirname).toStdString().c_str(), pref_stashed);
675 updateWidgets();
680 * Dedicated event handling for TCP SEQ Analysis overriding.
682 void ModulePreferencesScrollArea::enumComboBoxCurrentIndexChanged_PROTO_TCP(int index)
684 QComboBox *enum_cb = qobject_cast<QComboBox*>(sender());
685 if (!enum_cb) return;
687 pref_t *pref = VariantPointer<pref_t>::asPtr(enum_cb->property(pref_prop_));
688 if (!pref) return;
690 // Store the index value in the current value, not the stashed value.
691 // We use the stashed value to store the frame data pointers.
692 prefs_set_enum_value(pref, enum_cb->itemData(index).toInt(), pref_current);
693 //prefs_set_enum_value(pref, enum_cb->itemData(index).toInt(), pref_stashed);