aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorRoland Knall <roland.knall@br-automation.com>2018-03-02 15:41:00 +0100
committerRoland Knall <rknall@gmail.com>2018-04-05 09:31:23 +0000
commit6124ee2a1c06ccc96c3e9aa62c136f34085bfa61 (patch)
treea54fe1c4247e3f4519f71940d74c6a3f665d8a07 /ui
parentc2422d78281e10beb6ce4ebda1d61c9d0ca63a09 (diff)
extcap: Reload values on request
Allow certaing elements to be reloaded upon request. The way this works is, certain elements can be configured to be reloadable. By doing so, the extcap is asked once more just for the values list of this item, together with all already set options, and reloads the available options depending on the response. Only supported for selector. Radio and Multiselect will need additional patches, also moving those parts outside of extcap_argument.cpp might make sense before hand. Change-Id: I2e9e3d109b334bf878835a7cc9354f468bc22dee Reviewed-on: https://code.wireshark.org/review/26223 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/extcap_argument.cpp143
-rw-r--r--ui/qt/extcap_argument.h26
-rw-r--r--ui/qt/extcap_argument_file.cpp4
-rw-r--r--ui/qt/extcap_argument_file.h2
-rw-r--r--ui/qt/extcap_argument_multiselect.cpp4
-rw-r--r--ui/qt/extcap_argument_multiselect.h2
-rw-r--r--ui/qt/extcap_options_dialog.cpp71
-rw-r--r--ui/qt/extcap_options_dialog.h4
8 files changed, 212 insertions, 44 deletions
diff --git a/ui/qt/extcap_argument.cpp b/ui/qt/extcap_argument.cpp
index 1d97d47930..16eb2bb9ba 100644
--- a/ui/qt/extcap_argument.cpp
+++ b/ui/qt/extcap_argument.cpp
@@ -42,8 +42,10 @@
#include <extcap_argument_file.h>
#include <extcap_argument_multiselect.h>
-ExtArgTimestamp::ExtArgTimestamp(extcap_arg * argument) :
- ExtcapArgument(argument) {}
+#include <ui/qt/extcap_options_dialog.h>
+
+ExtArgTimestamp::ExtArgTimestamp(extcap_arg * argument, QObject * parent) :
+ ExtcapArgument(argument, parent) {}
QWidget * ExtArgTimestamp::createEditor(QWidget * parent)
{
@@ -102,8 +104,8 @@ QString ExtArgTimestamp::prefValue()
return value();
}
-ExtArgSelector::ExtArgSelector(extcap_arg * argument) :
- ExtcapArgument(argument), boxSelection(0) {}
+ExtArgSelector::ExtArgSelector(extcap_arg * argument, QObject * parent) :
+ ExtcapArgument(argument, parent), boxSelection(0) {}
QWidget * ExtArgSelector::createEditor(QWidget * parent)
{
@@ -112,7 +114,11 @@ QWidget * ExtArgSelector::createEditor(QWidget * parent)
const char *prefval = _argument->pref_valptr ? *_argument->pref_valptr : NULL;
QString stored(prefval ? prefval : "");
+ QWidget * editor = new QWidget(parent);
+ QHBoxLayout * layout = new QHBoxLayout();
+
boxSelection = new QComboBox(parent);
+ layout->addWidget(boxSelection);
if ( values.length() > 0 )
{
@@ -135,9 +141,64 @@ QWidget * ExtArgSelector::createEditor(QWidget * parent)
boxSelection->setCurrentIndex(selected);
}
+ if ( reload() )
+ {
+ QString btnText(tr("Reload data"));
+ if ( _argument->placeholder )
+ btnText = QString(_argument->placeholder);
+
+ QPushButton * reloadButton = new QPushButton(btnText, editor);
+ layout->addWidget(reloadButton);
+ reloadButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
+ boxSelection->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
+
+ connect(reloadButton, SIGNAL(clicked()), this, SLOT(onReloadTriggered()));
+ }
+
connect ( boxSelection, SIGNAL(currentIndexChanged(int)), SLOT(onIntChanged(int)) );
- return boxSelection;
+ editor->setLayout(layout);
+
+ return editor;
+}
+
+void ExtArgSelector::onReloadTriggered()
+{
+ int counter = 0;
+ int selected = -1;
+
+#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
+ QString call = boxSelection->currentData().toString();
+#else
+ QString call = boxSelection->itemData(boxSelection->currentIndex()).toString();
+#endif
+ const char *prefval = _argument->pref_valptr ? *_argument->pref_valptr : NULL;
+ QString stored(prefval ? prefval : "");
+ if ( call != stored )
+ stored = call;
+
+ if ( reloadValues() && values.length() > 0 )
+ {
+ boxSelection->clear();
+
+ ExtcapValueList::const_iterator iter = values.constBegin();
+
+ while ( iter != values.constEnd() )
+ {
+ boxSelection->addItem((*iter).value(), (*iter).call());
+
+ if ( stored.compare((*iter).call()) == 0 )
+ selected = counter;
+ else if ( (*iter).isDefault() && selected == -1 )
+ selected = counter;
+
+ counter++;
+ ++iter;
+ }
+
+ if ( selected > -1 && selected < boxSelection->count() )
+ boxSelection->setCurrentIndex(selected);
+ }
}
bool ExtArgSelector::isValid()
@@ -147,9 +208,12 @@ bool ExtArgSelector::isValid()
if ( value().length() == 0 && isRequired() )
valid = false;
- QString lblInvalidColor = ColorUtils::fromColorT(prefs.gui_text_invalid).name();
- QString cmbBoxStyle("QComboBox { background-color: %1; } ");
- boxSelection->setStyleSheet( cmbBoxStyle.arg(valid ? QString("") : lblInvalidColor) );
+ if ( boxSelection )
+ {
+ QString lblInvalidColor = ColorUtils::fromColorT(prefs.gui_text_invalid).name();
+ QString cmbBoxStyle("QComboBox { background-color: %1; } ");
+ boxSelection->setStyleSheet( cmbBoxStyle.arg(valid ? QString("") : lblInvalidColor) );
+ }
return valid;
}
@@ -168,8 +232,8 @@ QString ExtArgSelector::value()
return data.toString();
}
-ExtArgRadio::ExtArgRadio(extcap_arg * argument) :
- ExtcapArgument(argument), selectorGroup(0), callStrings(0) {}
+ExtArgRadio::ExtArgRadio(extcap_arg * argument, QObject * parent) :
+ ExtcapArgument(argument, parent), selectorGroup(0), callStrings(0) {}
QWidget * ExtArgRadio::createEditor(QWidget * parent)
{
@@ -260,8 +324,8 @@ bool ExtArgRadio::isValid()
return valid;
}
-ExtArgBool::ExtArgBool(extcap_arg * argument) :
- ExtcapArgument(argument), boolBox(0) {}
+ExtArgBool::ExtArgBool(extcap_arg * argument, QObject * parent) :
+ ExtcapArgument(argument, parent), boolBox(0) {}
QWidget * ExtArgBool::createLabel(QWidget * parent)
{
@@ -343,8 +407,8 @@ QString ExtArgBool::defaultValue()
return defaultBool() ? QString("true") : QString("false");
}
-ExtArgText::ExtArgText(extcap_arg * argument) :
- ExtcapArgument(argument), textBox(0)
+ExtArgText::ExtArgText(extcap_arg * argument, QObject * parent) :
+ ExtcapArgument(argument, parent), textBox(0)
{
}
@@ -411,8 +475,8 @@ bool ExtArgText::isValid()
return valid;
}
-ExtArgNumber::ExtArgNumber(extcap_arg * argument) :
- ExtArgText(argument) {}
+ExtArgNumber::ExtArgNumber(extcap_arg * argument, QObject * parent) :
+ ExtArgText(argument, parent) {}
QWidget * ExtArgNumber::createEditor(QWidget * parent)
{
@@ -600,6 +664,25 @@ ExtcapValueList ExtcapArgument::loadValues(QString parent)
return elements;
}
+bool ExtcapArgument::reloadValues()
+{
+ if ( ! qobject_cast<ExtcapOptionsDialog*> ( parent() ) )
+ return false;
+
+ ExtcapOptionsDialog * dialog = qobject_cast<ExtcapOptionsDialog*>(parent());
+ ExtcapValueList list = dialog->loadValuesFor(_argument->arg_num, _argument->call);
+
+ if ( list.size() > 0 )
+ {
+ values.clear();
+ values << list;
+
+ return true;
+ }
+
+ return false;
+}
+
ExtcapArgument::~ExtcapArgument() {
}
@@ -698,6 +781,14 @@ bool ExtcapArgument::isRequired()
return FALSE;
}
+bool ExtcapArgument::reload()
+{
+ if ( _argument != NULL )
+ return _argument->reload;
+
+ return false;
+}
+
bool ExtcapArgument::fileExists()
{
if ( _argument != NULL )
@@ -714,7 +805,7 @@ bool ExtcapArgument::isDefault()
return false;
}
-ExtcapArgument * ExtcapArgument::create(extcap_arg * argument)
+ExtcapArgument * ExtcapArgument::create(extcap_arg * argument, QObject *parent)
{
if ( argument == 0 || argument->display == 0 )
return 0;
@@ -722,26 +813,26 @@ ExtcapArgument * ExtcapArgument::create(extcap_arg * argument)
ExtcapArgument * result = 0;
if ( argument->arg_type == EXTCAP_ARG_STRING || argument->arg_type == EXTCAP_ARG_PASSWORD )
- result = new ExtArgText(argument);
+ result = new ExtArgText(argument, parent);
else if ( argument->arg_type == EXTCAP_ARG_INTEGER || argument->arg_type == EXTCAP_ARG_LONG ||
argument->arg_type == EXTCAP_ARG_UNSIGNED || argument->arg_type == EXTCAP_ARG_DOUBLE )
- result = new ExtArgNumber(argument);
+ result = new ExtArgNumber(argument, parent);
else if ( argument->arg_type == EXTCAP_ARG_BOOLEAN || argument->arg_type == EXTCAP_ARG_BOOLFLAG )
- result = new ExtArgBool(argument);
+ result = new ExtArgBool(argument, parent);
else if ( argument->arg_type == EXTCAP_ARG_SELECTOR )
- result = new ExtArgSelector(argument);
+ result = new ExtArgSelector(argument, parent);
else if ( argument->arg_type == EXTCAP_ARG_RADIO )
- result = new ExtArgRadio(argument);
+ result = new ExtArgRadio(argument, parent);
else if ( argument->arg_type == EXTCAP_ARG_FILESELECT )
- result = new ExtcapArgumentFileSelection(argument);
+ result = new ExtcapArgumentFileSelection(argument, parent);
else if ( argument->arg_type == EXTCAP_ARG_MULTICHECK )
- result = new ExtArgMultiSelect(argument);
+ result = new ExtArgMultiSelect(argument, parent);
else if ( argument->arg_type == EXTCAP_ARG_TIMESTAMP )
- result = new ExtArgTimestamp(argument);
+ result = new ExtArgTimestamp(argument, parent);
else
{
/* For everything else, we just print the label */
- result = new ExtcapArgument(argument);
+ result = new ExtcapArgument(argument, parent);
}
return result;
diff --git a/ui/qt/extcap_argument.h b/ui/qt/extcap_argument.h
index f7fd27ce37..fb2aef4022 100644
--- a/ui/qt/extcap_argument.h
+++ b/ui/qt/extcap_argument.h
@@ -70,8 +70,8 @@ class ExtcapArgument: public QObject
Q_OBJECT
public:
- ExtcapArgument(QObject *parent=0);
- ExtcapArgument(extcap_arg * argument, QObject *parent=0);
+ ExtcapArgument(QObject *parent = Q_NULLPTR);
+ ExtcapArgument(extcap_arg * argument, QObject *parent = Q_NULLPTR);
ExtcapArgument(const ExtcapArgument &obj);
virtual ~ExtcapArgument();
@@ -86,13 +86,14 @@ public:
bool isDefault();
virtual bool isValid();
bool isRequired();
+ bool reload();
QString prefKey(const QString & device_name);
virtual QString prefValue();
void resetValue();
- static ExtcapArgument * create(extcap_arg * argument = 0);
+ static ExtcapArgument * create(extcap_arg * argument = Q_NULLPTR, QObject * parent = Q_NULLPTR);
Q_SIGNALS:
void valueChanged();
@@ -102,6 +103,7 @@ protected:
bool fileExists();
ExtcapValueList loadValues(QString parent);
+ bool reloadValues();
ExtcapValueList values;
@@ -122,7 +124,7 @@ class ExtArgText : public ExtcapArgument
{
public:
- ExtArgText(extcap_arg * argument);
+ ExtArgText(extcap_arg * argument, QObject *parent = Q_NULLPTR);
virtual QWidget * createEditor(QWidget * parent);
virtual QString value();
@@ -136,7 +138,7 @@ protected:
class ExtArgNumber : public ExtArgText
{
public:
- ExtArgNumber(extcap_arg * argument);
+ ExtArgNumber(extcap_arg * argument, QObject *parent = Q_NULLPTR);
virtual QWidget * createEditor(QWidget * parent);
virtual QString defaultValue();
@@ -144,8 +146,10 @@ public:
class ExtArgSelector : public ExtcapArgument
{
+ Q_OBJECT
+
public:
- ExtArgSelector(extcap_arg * argument);
+ ExtArgSelector(extcap_arg * argument, QObject *parent = Q_NULLPTR);
virtual QWidget * createEditor(QWidget * parent);
virtual QString value();
@@ -154,12 +158,16 @@ public:
private:
QComboBox * boxSelection;
+
+private Q_SLOTS:
+ void onReloadTriggered();
+
};
class ExtArgRadio : public ExtcapArgument
{
public:
- ExtArgRadio(extcap_arg * argument);
+ ExtArgRadio(extcap_arg * argument, QObject *parent = Q_NULLPTR);
virtual QWidget * createEditor(QWidget * parent);
virtual QString value();
@@ -174,7 +182,7 @@ private:
class ExtArgBool : public ExtcapArgument
{
public:
- ExtArgBool(extcap_arg * argument);
+ ExtArgBool(extcap_arg * argument, QObject *parent = Q_NULLPTR);
virtual QWidget * createLabel(QWidget * parent);
virtual QWidget * createEditor(QWidget * parent);
@@ -197,7 +205,7 @@ class ExtArgTimestamp : public ExtcapArgument
Q_OBJECT
public:
- ExtArgTimestamp(extcap_arg * argument);
+ ExtArgTimestamp(extcap_arg * argument, QObject *parent = Q_NULLPTR);
virtual QWidget * createEditor(QWidget * parent);
virtual bool isValid();
diff --git a/ui/qt/extcap_argument_file.cpp b/ui/qt/extcap_argument_file.cpp
index 9a708cc347..0b7f5d9f1d 100644
--- a/ui/qt/extcap_argument_file.cpp
+++ b/ui/qt/extcap_argument_file.cpp
@@ -29,8 +29,8 @@
#include <extcap_parser.h>
-ExtcapArgumentFileSelection::ExtcapArgumentFileSelection (extcap_arg * argument) :
- ExtcapArgument(argument), textBox(0)
+ExtcapArgumentFileSelection::ExtcapArgumentFileSelection (extcap_arg * argument, QObject *parent) :
+ ExtcapArgument(argument, parent), textBox(0)
{
}
diff --git a/ui/qt/extcap_argument_file.h b/ui/qt/extcap_argument_file.h
index 5e8eeeedca..72a430756e 100644
--- a/ui/qt/extcap_argument_file.h
+++ b/ui/qt/extcap_argument_file.h
@@ -21,7 +21,7 @@ class ExtcapArgumentFileSelection : public ExtcapArgument
Q_OBJECT
public:
- ExtcapArgumentFileSelection(extcap_arg * argument);
+ ExtcapArgumentFileSelection(extcap_arg * argument, QObject * parent = Q_NULLPTR);
virtual ~ExtcapArgumentFileSelection();
virtual QWidget * createEditor(QWidget * parent);
diff --git a/ui/qt/extcap_argument_multiselect.cpp b/ui/qt/extcap_argument_multiselect.cpp
index 92c44eab45..46ea35b2f6 100644
--- a/ui/qt/extcap_argument_multiselect.cpp
+++ b/ui/qt/extcap_argument_multiselect.cpp
@@ -25,8 +25,8 @@
#include <extcap_parser.h>
#include <extcap_argument_multiselect.h>
-ExtArgMultiSelect::ExtArgMultiSelect(extcap_arg * argument) :
- ExtcapArgument(argument), treeView(0), viewModel(0) {}
+ExtArgMultiSelect::ExtArgMultiSelect(extcap_arg * argument, QObject *parent) :
+ ExtcapArgument(argument, parent), treeView(0), viewModel(0) {}
ExtArgMultiSelect::~ExtArgMultiSelect()
{
diff --git a/ui/qt/extcap_argument_multiselect.h b/ui/qt/extcap_argument_multiselect.h
index ef89445581..0f63d28f8f 100644
--- a/ui/qt/extcap_argument_multiselect.h
+++ b/ui/qt/extcap_argument_multiselect.h
@@ -23,7 +23,7 @@ class ExtArgMultiSelect : public ExtcapArgument
{
Q_OBJECT
public:
- ExtArgMultiSelect(extcap_arg * argument);
+ ExtArgMultiSelect(extcap_arg * argument, QObject *parent = Q_NULLPTR);
virtual ~ExtArgMultiSelect();
virtual QString value();
diff --git a/ui/qt/extcap_options_dialog.cpp b/ui/qt/extcap_options_dialog.cpp
index cd7e386e48..88b809317b 100644
--- a/ui/qt/extcap_options_dialog.cpp
+++ b/ui/qt/extcap_options_dialog.cpp
@@ -205,7 +205,7 @@ void ExtcapOptionsDialog::loadArguments()
item = g_list_first((GList *)(walker->data));
while ( item != NULL )
{
- argument = ExtcapArgument::create((extcap_arg *)(item->data));
+ argument = ExtcapArgument::create((extcap_arg *)(item->data), this);
if ( argument != NULL )
{
if ( argument->isRequired() )
@@ -253,7 +253,6 @@ void ExtcapOptionsDialog::updateWidgets()
/* Load all extcap arguments */
loadArguments();
-
ExtcapArgumentList::iterator iter = extcapArguments.begin();
while ( iter != extcapArguments.end() )
{
@@ -424,7 +423,7 @@ void ExtcapOptionsDialog::resetValues()
}
}
-void ExtcapOptionsDialog::storeValues()
+GHashTable *ExtcapOptionsDialog::getArgumentSettings(bool useCallsAsKey)
{
GHashTable * entries = g_hash_table_new(g_str_hash, g_str_equal);
ExtcapArgumentList::const_iterator iter;
@@ -476,6 +475,9 @@ void ExtcapOptionsDialog::storeValues()
value = (*iter)->prefValue();
QString key = argument->prefKey(device_name);
+ if ( useCallsAsKey )
+ key = argument->call();
+
if (key.length() > 0)
{
gchar * val = g_strdup(value.length() == 0 ? " " : value.toStdString().c_str());
@@ -484,6 +486,13 @@ void ExtcapOptionsDialog::storeValues()
}
}
+ return entries;
+}
+
+void ExtcapOptionsDialog::storeValues()
+{
+ GHashTable * entries = getArgumentSettings();
+
if ( g_hash_table_size(entries) > 0 )
{
if ( prefs_store_ext_multiple("extcap", entries) )
@@ -492,6 +501,62 @@ void ExtcapOptionsDialog::storeValues()
}
}
+ExtcapValueList ExtcapOptionsDialog::loadValuesFor(int argNum, QString argumentName, QString parent)
+{
+ ExtcapValueList elements;
+ GList * walker = 0, * values = 0;
+ extcap_value * v;
+
+ QList<QWidget *> children = findChildren<QWidget *>();
+ foreach ( QWidget * child, children )
+ child->setEnabled(false);
+
+ QString argcall = argumentName;
+ if ( argcall.startsWith("--") )
+ argcall = argcall.right(argcall.size()-2);
+
+ GHashTable * entries = getArgumentSettings(true);
+
+ values = extcap_get_if_configuration_values(this->device_name.toStdString().c_str(), argcall.toStdString().c_str(), entries);
+
+ for (walker = g_list_first((GList *)(values)); walker != NULL ; walker = walker->next)
+ {
+ v = (extcap_value *) walker->data;
+ if (v == NULL || v->display == NULL || v->call == NULL )
+ break;
+
+ /* Only accept values for this argument */
+ if ( v->arg_num != argNum )
+ break;
+
+ QString valParent = QString().fromUtf8(v->parent);
+
+ if ( parent.compare(valParent) == 0 )
+ {
+
+ QString display = QString().fromUtf8(v->display);
+ QString call = QString().fromUtf8(v->call);
+
+ ExtcapValue element = ExtcapValue(display, call,
+ v->enabled == (gboolean)TRUE, v->is_default == (gboolean)TRUE);
+
+#if 0
+ /* TODO: Disabled due to wrong parent handling. It leads to an infinite loop for now. To implement this properly, other things
+ will be needed, like new arguments for setting the parent in the call to the extcap utility*/
+ if (!call.isEmpty())
+ element.setChildren(this->loadValuesFor(argumentName, call));
+#endif
+
+ elements.append(element);
+ }
+ }
+
+ foreach ( QWidget * child, children )
+ child->setEnabled(true);
+
+ return elements;
+}
+
/*
* Editor modelines
*
diff --git a/ui/qt/extcap_options_dialog.h b/ui/qt/extcap_options_dialog.h
index a578528412..07ece9215d 100644
--- a/ui/qt/extcap_options_dialog.h
+++ b/ui/qt/extcap_options_dialog.h
@@ -36,6 +36,8 @@ public:
~ExtcapOptionsDialog();
static ExtcapOptionsDialog * createForDevice(QString &device_name, QWidget *parent = 0);
+ ExtcapValueList loadValuesFor(int argNum, QString call, QString parent = "");
+
private Q_SLOTS:
void on_buttonBox_accepted();
void on_buttonBox_rejected();
@@ -56,8 +58,10 @@ private:
void loadArguments();
bool saveOptionToCaptureInfo();
+ GHashTable * getArgumentSettings(bool useCallsAsKey = false);
void storeValues();
void resetValues();
+
};
#endif // EXTCAP_OPTIONS_DIALOG_H