From 2b4fcae31f14d5c609530030b5375356db7e2b19 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Thu, 6 Oct 2022 13:43:53 -0700 Subject: [PATCH] Qt+extcap: Add editable extcap selectors. Add an "editselector" argument type, which lets the user override a predefined selection list with a custom value. --- doc/extcap.adoc | 1 + docbook/wsdg_src/WSDG_chapter_capture.adoc | 5 ++- extcap_parser.c | 2 + extcap_parser.h | 1 + ui/qt/extcap_argument.cpp | 45 ++++++++++++++++++++++ ui/qt/extcap_argument.h | 16 +++++++- 6 files changed, 66 insertions(+), 4 deletions(-) diff --git a/doc/extcap.adoc b/doc/extcap.adoc index d64a9edab4..0874dab6c4 100644 --- a/doc/extcap.adoc +++ b/doc/extcap.adoc @@ -71,6 +71,7 @@ Argument type for UI filtering for raw, or UI type for selector: long (may include scientific / special notation) float selector (display selector table, all values as strings) + editselector (selector table which can be overridden, all values as strings) boolean (display checkbox) radio (display group of radio buttons with provided values, all values as strings) fileselect (display a dialog to select a file from the filesystem, value as string) diff --git a/docbook/wsdg_src/WSDG_chapter_capture.adoc b/docbook/wsdg_src/WSDG_chapter_capture.adoc index a58df5c7f9..d7cf5368ea 100644 --- a/docbook/wsdg_src/WSDG_chapter_capture.adoc +++ b/docbook/wsdg_src/WSDG_chapter_capture.adoc @@ -285,10 +285,11 @@ When _mustexist=false_ is used, the GUI shows the user a file dialog for saving arg {number=3}{call=--logfile}{display=Logfile}{tooltip=A file for log messages}{type=fileselect}{mustexist=false} ---- -_selector_, _radio_, _multicheck_:: +_selector_, __editselector__, _radio_, _multicheck_:: Option fields where the user may choose from one or more options. If _parent_ is provided for the value items, the option fields for _multicheck_ and _selector_ are presented in a tree-like structure. -_selector_ and _radio_ values must present a default value, which will be the value provided to the extcap binary for this argument +_selector_ and _radio_ values must present a default value, which will be the value provided to the extcap binary for this argument. +_editselector_ option fields let the user select from a list of items or enter a custom value. + [source,python] ---- diff --git a/extcap_parser.c b/extcap_parser.c index 69e563a1a3..8a5e56ad57 100644 --- a/extcap_parser.c +++ b/extcap_parser.c @@ -519,6 +519,8 @@ static extcap_arg *extcap_parse_arg_sentence(GList *args, extcap_token_sentence target_arg->arg_type = EXTCAP_ARG_BOOLFLAG; } else if (g_ascii_strcasecmp(param_value, "selector") == 0) { target_arg->arg_type = EXTCAP_ARG_SELECTOR; + } else if (g_ascii_strcasecmp(param_value, "editselector") == 0) { + target_arg->arg_type = EXTCAP_ARG_EDIT_SELECTOR; } else if (g_ascii_strcasecmp(param_value, "radio") == 0) { target_arg->arg_type = EXTCAP_ARG_RADIO; } else if (g_ascii_strcasecmp(param_value, "string") == 0) { diff --git a/extcap_parser.h b/extcap_parser.h index 460af1d5fa..10aecbc9ae 100644 --- a/extcap_parser.h +++ b/extcap_parser.h @@ -39,6 +39,7 @@ typedef enum { EXTCAP_ARG_PASSWORD, /* Complex GUI types which are populated with value sentences */ EXTCAP_ARG_SELECTOR, + EXTCAP_ARG_EDIT_SELECTOR, EXTCAP_ARG_RADIO, EXTCAP_ARG_MULTICHECK, EXTCAP_ARG_FILESELECT, diff --git a/ui/qt/extcap_argument.cpp b/ui/qt/extcap_argument.cpp index f5b41aa481..c598120981 100644 --- a/ui/qt/extcap_argument.cpp +++ b/ui/qt/extcap_argument.cpp @@ -263,6 +263,49 @@ void ExtArgSelector::setDefaultValue() } +ExtArgEditSelector::ExtArgEditSelector(extcap_arg * argument, QObject * parent) : + ExtArgSelector(argument, parent) {} + +QWidget * ExtArgEditSelector::createEditor(QWidget * parent) +{ + QWidget *editor = ExtArgSelector::createEditor(parent); + + boxSelection->setEditable(true); + boxSelection->setInsertPolicy(QComboBox::NoInsert); + + return editor; +} + +QString ExtArgEditSelector::value() +{ + if (boxSelection == nullptr) { + return QString(); + } + + return boxSelection->currentText(); +} + +void ExtArgEditSelector::setDefaultValue() +{ + ExtArgSelector::setDefaultValue(); + + if (boxSelection == nullptr) { + return; + } + + const char *prefval = (_argument->pref_valptr && strlen(*_argument->pref_valptr)) ? *_argument->pref_valptr : NULL; + QString stored(prefval ? prefval : ""); + QVariant data = boxSelection->currentData(); + + if (data.toString() != stored) { + // Apparently createEditor hasn't been called at this point. + boxSelection->setEditable(true); + boxSelection->setInsertPolicy(QComboBox::NoInsert); + boxSelection->setEditText(stored); + } + +} + ExtArgRadio::ExtArgRadio(extcap_arg * argument, QObject * parent) : ExtcapArgument(argument, parent), selectorGroup(0), callStrings(0) {} @@ -943,6 +986,8 @@ ExtcapArgument * ExtcapArgument::create(extcap_arg * argument, QObject *parent) result = new ExtArgBool(argument, parent); else if (argument->arg_type == EXTCAP_ARG_SELECTOR) result = new ExtArgSelector(argument, parent); + else if (argument->arg_type == EXTCAP_ARG_EDIT_SELECTOR) + result = new ExtArgEditSelector(argument, parent); else if (argument->arg_type == EXTCAP_ARG_RADIO) result = new ExtArgRadio(argument, parent); else if (argument->arg_type == EXTCAP_ARG_FILESELECT) diff --git a/ui/qt/extcap_argument.h b/ui/qt/extcap_argument.h index 63f15c456f..2efa4e42f2 100644 --- a/ui/qt/extcap_argument.h +++ b/ui/qt/extcap_argument.h @@ -182,8 +182,7 @@ public: public Q_SLOTS: virtual void setDefaultValue(); -private: - +protected: QComboBox * boxSelection; private Q_SLOTS: @@ -192,6 +191,19 @@ private Q_SLOTS: }; +class ExtArgEditSelector : public ExtArgSelector +{ + Q_OBJECT + +public: + ExtArgEditSelector(extcap_arg * argument, QObject *parent = Q_NULLPTR); + virtual QWidget * createEditor(QWidget * parent); + virtual QString value(); + +public Q_SLOTS: + virtual void setDefaultValue(); +}; + class ExtArgRadio : public ExtcapArgument {