diff options
author | Roland Knall <roland.knall@br-automation.com> | 2015-12-29 07:57:36 +0100 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2016-02-01 12:12:41 +0000 |
commit | 927ffaa794d5fb24e0b4f3fba08c4c31f4dd7d63 (patch) | |
tree | 70676d0b7e00e0b10678d0f7f3ff7dd707eabcd2 /ui/qt/extcap_argument.cpp | |
parent | 5e89f9332228015c3e5c813939bf35dbcc5a105d (diff) |
extcap: Add Save functionality to options dialog
This patch creates the functionality of saving all parameters
for extcap devices in the general preference section.
For now, multiselect and fileselect do not save their values
but patches for this will be provided in the future
Also, all preferences are stored as strings to make handling
easier. This might change in the future, but for the first version
it will stick.
Restore to Defaults is not implemented as of yet, and will be
in a future version, once the preference storing is finalized
Bug: 11666
Change-Id: I178346405146d2e43f4f3481c05c92c0b3595af5
Reviewed-on: https://code.wireshark.org/review/13451
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt/extcap_argument.cpp')
-rw-r--r-- | ui/qt/extcap_argument.cpp | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/ui/qt/extcap_argument.cpp b/ui/qt/extcap_argument.cpp index 0c06107f3e..3200a7e1d6 100644 --- a/ui/qt/extcap_argument.cpp +++ b/ui/qt/extcap_argument.cpp @@ -40,9 +40,12 @@ #include <QStandardItem> #include <QStandardItemModel> #include <QItemSelectionModel> +#include <QRegExp> #include <glib.h> #include <log.h> + +#include <extcap.h> #include <epan/prefs.h> #include <color_utils.h> @@ -57,6 +60,7 @@ QWidget * ExtArgSelector::createEditor(QWidget * parent) { int counter = 0; int selected = -1; + QString stored = _argument->storeval ? QString(_argument->storeval) : QString(); boxSelection = new QComboBox(parent); @@ -67,7 +71,10 @@ QWidget * ExtArgSelector::createEditor(QWidget * parent) while ( iter != values.constEnd() ) { boxSelection->addItem((*iter).value(), (*iter).call()); - if ( (*iter).isDefault() ) + + if ( ! _argument->storeval && (*iter).isDefault() ) + selected = counter; + else if ( _argument->storeval && stored.compare((*iter).call()) == 0 ) selected = counter; counter++; @@ -135,7 +142,7 @@ QWidget * ExtArgRadio::createEditor(QWidget * parent) ExtcapValueList::const_iterator iter = values.constBegin(); while ( iter != values.constEnd() ) - { + { QRadioButton * radio = new QRadioButton((*iter).value()); QString callString = (*iter).call(); callStrings->append(callString); @@ -219,6 +226,15 @@ QWidget * ExtArgBool::createEditor(QWidget * parent) if ( _argument->tooltip != NULL ) boolBox->setToolTip(QString().fromUtf8(_argument->tooltip)); + if ( _argument->storeval ) + { + QRegExp regexp(EXTCAP_BOOLEAN_REGEX); + + bool savedstate = ( regexp.indexIn(QString(_argument->storeval[0]), 0) != -1 ); + if ( savedstate != state ) + state = savedstate; + } + boolBox->setCheckState(state ? Qt::Checked : Qt::Unchecked ); connect (boolBox, SIGNAL(stateChanged(int)), SLOT(onIntChanged(int))); @@ -244,6 +260,13 @@ QString ExtArgBool::value() return QString(boolBox->checkState() == Qt::Checked ? "true" : "false"); } +QString ExtArgBool::prefValue() +{ + if ( boolBox == NULL ) + return QString("false"); + return QString(boolBox->checkState() == Qt::Checked ? "true" : "false"); +} + bool ExtArgBool::isValid() { /* A bool is allways valid, but the base function checks on string length, @@ -279,8 +302,17 @@ ExtArgText::ExtArgText(extcap_arg * argument) : QWidget * ExtArgText::createEditor(QWidget * parent) { + QString storeValue; QString text = defaultValue(); + if ( _argument->storeval ) + { + QString storeValue = _argument->storeval; + + if ( storeValue.length() > 0 && storeValue.compare(text) != 0 ) + text = storeValue.trimmed(); + } + textBox = new QLineEdit(text, parent); if ( _argument->tooltip != NULL ) @@ -334,7 +366,17 @@ ExtArgNumber::ExtArgNumber(extcap_arg * argument) : QWidget * ExtArgNumber::createEditor(QWidget * parent) { + QString storeValue; QString text = defaultValue(); + + if ( _argument->storeval ) + { + QString storeValue = _argument->storeval; + + if ( storeValue.length() > 0 && storeValue.compare(text) != 0 ) + text = storeValue; + } + textBox = (QLineEdit *)ExtArgText::createEditor(parent); textBox->disconnect(SIGNAL(textChanged(QString))); @@ -525,6 +567,10 @@ QString ExtcapArgument::value() return QString(); } +QString ExtcapArgument::prefValue() +{ + return value(); +} bool ExtcapArgument::isValid() { @@ -544,10 +590,17 @@ QString ExtcapArgument::defaultValue() if ( str != 0 ) return QString(str); } - return QString(); } +QString ExtcapArgument::prefKey() +{ + if ( ! _argument->save ) + return QString(); + + return QString(_argument->call).replace("-", ""); +} + bool ExtcapArgument::isRequired() { if ( _argument != NULL ) |