summaryrefslogtreecommitdiffstats
path: root/ui/qt/preference_editor_frame.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ui/qt/preference_editor_frame.cpp')
-rw-r--r--ui/qt/preference_editor_frame.cpp38
1 files changed, 29 insertions, 9 deletions
diff --git a/ui/qt/preference_editor_frame.cpp b/ui/qt/preference_editor_frame.cpp
index 4ebce5c9..eec2571a 100644
--- a/ui/qt/preference_editor_frame.cpp
+++ b/ui/qt/preference_editor_frame.cpp
@@ -9,8 +9,6 @@
#include "config.h"
-#include <glib.h>
-
#include <epan/prefs.h>
#include <epan/prefs-int.h>
#include <epan/decode_as.h>
@@ -49,6 +47,9 @@ PreferenceEditorFrame::PreferenceEditorFrame(QWidget *parent) :
#endif
connect(ui->preferenceBrowseButton, &QPushButton::clicked, this, &PreferenceEditorFrame::browsePushButtonClicked);
+
+ // Disconnect textChanged signal for DissectorSyntaxLineEdit.
+ disconnect(ui->preferenceLineEdit, &DissectorSyntaxLineEdit::textChanged, NULL, NULL);
}
PreferenceEditorFrame::~PreferenceEditorFrame()
@@ -80,14 +81,15 @@ void PreferenceEditorFrame::editPreference(preference *pref, pref_module *module
ui->preferenceLineEdit->clear();
ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Empty);
- disconnect(ui->preferenceLineEdit, 0, 0, 0);
+
+ // Disconnect previous textChanged signal.
+ disconnect(ui->preferenceLineEdit, &SyntaxLineEdit::textChanged, this, NULL);
bool show = false;
bool browse_button = false;
switch (prefs_get_type(pref_)) {
case PREF_UINT:
- case PREF_DECODE_AS_UINT:
connect(ui->preferenceLineEdit, &SyntaxLineEdit::textChanged,
this, &PreferenceEditorFrame::uintLineEditTextEdited);
show = true;
@@ -99,6 +101,7 @@ void PreferenceEditorFrame::editPreference(preference *pref, pref_module *module
// Fallthrough
case PREF_STRING:
case PREF_PASSWORD:
+ case PREF_DISSECTOR:
connect(ui->preferenceLineEdit, &SyntaxLineEdit::textChanged,
this, &PreferenceEditorFrame::stringLineEditTextEdited);
show = true;
@@ -114,6 +117,16 @@ void PreferenceEditorFrame::editPreference(preference *pref, pref_module *module
}
if (show) {
+ // Enable completion only for display filter search.
+ if (prefs_get_type(pref_) == PREF_DISSECTOR) {
+ ui->preferenceLineEdit->allowCompletion(true);
+ ui->preferenceLineEdit->updateDissectorNames();
+ ui->preferenceLineEdit->setDefaultPlaceholderText();
+ } else {
+ ui->preferenceLineEdit->allowCompletion(false);
+ ui->preferenceLineEdit->setPlaceholderText("");
+ }
+
ui->preferenceLineEdit->setText(gchar_free_to_qstring(prefs_pref_to_str(pref_, pref_stashed)).remove(QRegularExpression("\n\t")));
ui->preferenceBrowseButton->setHidden(!browse_button);
animatedShow();
@@ -143,8 +156,15 @@ void PreferenceEditorFrame::uintLineEditTextEdited(const QString &new_str)
void PreferenceEditorFrame::stringLineEditTextEdited(const QString &new_str)
{
+ bool ok = true;
new_str_ = new_str;
- ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
+
+ if (prefs_get_type(pref_) == PREF_DISSECTOR) {
+ ui->preferenceLineEdit->checkDissectorName(new_str_);
+ ok = (ui->preferenceLineEdit->syntaxState() != SyntaxLineEdit::Invalid);
+ }
+
+ ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
}
void PreferenceEditorFrame::browsePushButtonClicked()
@@ -220,13 +240,13 @@ void PreferenceEditorFrame::on_buttonBox_accepted()
unsigned int apply = 0;
switch(prefs_get_type(pref_)) {
case PREF_UINT:
- case PREF_DECODE_AS_UINT:
apply = prefs_set_uint_value(pref_, new_uint_, pref_stashed);
break;
case PREF_STRING:
case PREF_SAVE_FILENAME:
case PREF_OPEN_FILENAME:
case PREF_DIRNAME:
+ case PREF_DISSECTOR:
apply = prefs_set_string_value(pref_, new_str_.toStdString().c_str(), pref_stashed);
break;
case PREF_PASSWORD:
@@ -245,13 +265,13 @@ void PreferenceEditorFrame::on_buttonBox_accepted()
pref_unstash_data_t unstashed_data;
unstashed_data.module = module_;
- unstashed_data.handle_decode_as = TRUE;
+ unstashed_data.handle_decode_as = true;
pref_unstash(pref_, &unstashed_data);
prefs_apply(module_);
prefs_main_write();
- gchar* err = NULL;
+ char* err = NULL;
if (save_decode_as_entries(&err) < 0)
{
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err);
@@ -280,7 +300,7 @@ void PreferenceEditorFrame::on_buttonBox_rejected()
void PreferenceEditorFrame::keyPressEvent(QKeyEvent *event)
{
- if (event->modifiers() == Qt::NoModifier) {
+ if (pref_ && module_ && (event->modifiers() == Qt::NoModifier)) {
if (event->key() == Qt::Key_Escape) {
on_buttonBox_rejected();
} else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {